Subversion Repositories uuid_mac_utils

Rev

Rev 82 | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. <?php
  2.  
  3. /*
  4.  * UUID interpreter for PHP
  5.  * Copyright 2017 - 2024 Daniel Marschall, ViaThinkSoft
  6.  * Version 2024-03-09
  7.  *
  8.  * Licensed under the Apache License, Version 2.0 (the "License");
  9.  * you may not use this file except in compliance with the License.
  10.  * You may obtain a copy of the License at
  11.  *
  12.  *     http://www.apache.org/licenses/LICENSE-2.0
  13.  *
  14.  * Unless required by applicable law or agreed to in writing, software
  15.  * distributed under the License is distributed on an "AS IS" BASIS,
  16.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17.  * See the License for the specific language governing permissions and
  18.  * limitations under the License.
  19.  */
  20.  
  21. $uuid = isset($_GET['uuid']) ? trim($_GET['uuid']) : 'CREATE';
  22.  
  23. $version = $_REQUEST['version'] ?? null;
  24. $v8_sqlserver_version = null;
  25. $v8_hash_algo = null;
  26. if (!is_null($version)) {
  27.         if (preg_match('@^(8)_sqlserver_v(.+)$@', $version, $m)) {
  28.                 $version = $m[1];
  29.                 $v8_sqlserver_version = $m[2];
  30.         } else if (preg_match('@^(8)_namebased_(.+)$@', $version, $m)) {
  31.                 $version = $m[1];
  32.                 $v8_hash_algo = $m[2];
  33.         }
  34. }
  35. if (!is_numeric($version) || (strlen($version)!=1)) $version = 1; // default: Version 1 / time based
  36.  
  37. if ($uuid == 'CREATE') {
  38.         $title = 'Generate a UUIDv'.$version;
  39. } else {
  40.         $title = 'Interprete a UUID';
  41. }
  42.  
  43. ?><html>
  44.  
  45. <head>
  46.         <meta charset="iso-8859-1">
  47.         <link rel="stylesheet" type="text/css" href="style.css">
  48.         <title><?php echo htmlentities($title); ?></title>
  49.         <meta name=viewport content="width=device-width, initial-scale=1">
  50. </head>
  51.  
  52. <body>
  53.  
  54. <h1><?php echo htmlentities($title); ?></h1>
  55.  
  56. <p><a href="index.php">Back</a></p>
  57.  
  58. <?php
  59.  
  60. if ($uuid != 'CREATE') {
  61.         echo '<form method="GET" action="interprete_uuid.php">';
  62.         echo '  UUID: <input style="font-family:Courier,Courier New,Serif;width:325px" type="text" name="uuid" value="'.htmlentities($uuid).'"> <input type="submit" value="Interprete">';
  63.         echo '</form>';
  64. } else if (($version!=3) && ($version!=5) && (($version!=8) || ($v8_sqlserver_version!=null))) {
  65.         echo '<p><i>Reload the page to receive another UUID.</i></p>';
  66. }
  67.  
  68. echo '<pre>';
  69.  
  70. require_once __DIR__ . '/includes/uuid_utils.inc.php';
  71.  
  72. try {
  73.         if ($uuid == 'CREATE') {
  74.                 if ($version == '1') {
  75.                         $uuid = gen_uuid_timebased();
  76.                 } else if ($version == '2') {
  77.                         $uuid = gen_uuid_dce(trim($_REQUEST['dce_domain']??''), trim($_REQUEST['dce_id']??''));
  78.                 } else if ($version == '3') {
  79.                         $uuid = gen_uuid_md5_namebased(trim($_REQUEST['nb_ns']??''), trim($_REQUEST['nb_val']??''));
  80.                 } else if ($version == '4') {
  81.                         $uuid = gen_uuid_random();
  82.                 } else if ($version == '5') {
  83.                         $uuid = gen_uuid_sha1_namebased(trim($_REQUEST['nb_ns']??''), trim($_REQUEST['nb_val']??''));
  84.                 } else if ($version == '6') {
  85.                         $uuid = gen_uuid_reordered();
  86.                 } else if ($version == '7') {
  87.                         $uuid = gen_uuid_unix_epoch();
  88.                 } else if ($version == '8') {
  89.                         if ($v8_sqlserver_version != null) {
  90.                                 $uuid = gen_uuid_v8_sqlserver_sortable(intval($v8_sqlserver_version));
  91.                         } else if ($v8_hash_algo != null) {
  92.                                 $uuid = gen_uuid_v8_namebased($v8_hash_algo, trim($_REQUEST['nb_ns']??''), trim($_REQUEST['nb_val']??''));
  93.                         } else {
  94.                                 $uuid = gen_uuid_custom(trim($_REQUEST['block1']??'0'), trim($_REQUEST['block2']??'0'), trim($_REQUEST['block3']??'0'), trim($_REQUEST['block4']??'0'), trim($_REQUEST['block5']??'0'));
  95.                         }
  96.                 } else {
  97.                         throw new Exception("Unexpected version number");
  98.                 }
  99.         }
  100.         if (is_uuid_oid($uuid)) {
  101.                 $uuid = oid_to_uuid($uuid);
  102.         }
  103.  
  104.         if (!uuid_valid($uuid)) {
  105.                 echo 'This is not a valid UUID.';
  106.         } else {
  107.                 uuid_info($uuid);
  108.         }
  109. } catch (Exception $e) {
  110.     echo "Error: " . htmlentities($e->getMessage());
  111. }
  112.  
  113. ?></pre>
  114.  
  115. <br>
  116.  
  117. </body>
  118.  
  119. </html>
  120.