Subversion Repositories uuid_mac_utils

Rev

Rev 43 | Rev 82 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. <?php
  2.  
  3. /*
  4.  * UUID interpreter for PHP
  5.  * Copyright 2017 - 2023 Daniel Marschall, ViaThinkSoft
  6.  * Version 2023-07-13
  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. if (!is_numeric($version) || (strlen($version)!=1)) $version = 1; // default: Version 1 / time based
  25.  
  26. if ($uuid == 'CREATE') {
  27.         $title = 'Generate a UUIDv'.$version;
  28. } else {
  29.         $title = 'Interprete a UUID';
  30. }
  31.  
  32. ?><html>
  33.  
  34. <head>
  35.         <meta charset="iso-8859-1">
  36.         <link rel="stylesheet" type="text/css" href="style.css">
  37.         <title><?php echo htmlentities($title); ?></title>
  38.         <meta name=viewport content="width=device-width, initial-scale=1">
  39. </head>
  40.  
  41. <body>
  42.  
  43. <h1><?php echo htmlentities($title); ?></h1>
  44.  
  45. <p><a href="index.php">Back</a></p>
  46.  
  47. <?php
  48.  
  49. if ($uuid != 'CREATE') {
  50.         echo '<form method="GET" action="interprete_uuid.php">';
  51.         echo '  UUID: <input style="font-family:Courier,Courier New,Serif;width:325px" type="text" name="uuid" value="'.htmlentities($uuid).'"> <input type="submit" value="Interprete">';
  52.         echo '</form>';
  53. } else if (($version!=3) && ($version!=5) && ($version!=8)) {
  54.         echo '<p><i>Reload the page to receive another UUID.</i></p>';
  55. }
  56.  
  57. echo '<pre>';
  58.  
  59. require_once __DIR__ . '/includes/uuid_utils.inc.php';
  60.  
  61. try {
  62.         if ($uuid == 'CREATE') {
  63.                 if ($version == '1') {
  64.                         $uuid = gen_uuid_timebased();
  65.                 } else if ($version == '2') {
  66.                         $uuid = gen_uuid_dce(trim($_REQUEST['dce_domain']??''), trim($_REQUEST['dce_id']??''));
  67.                 } else if ($version == '3') {
  68.                         $uuid = gen_uuid_md5_namebased(trim($_REQUEST['nb_ns']??''), trim($_REQUEST['nb_val']??''));
  69.                 } else if ($version == '4') {
  70.                         $uuid = gen_uuid_random();
  71.                 } else if ($version == '5') {
  72.                         $uuid = gen_uuid_sha1_namebased(trim($_REQUEST['nb_ns']??''), trim($_REQUEST['nb_val']??''));
  73.                 } else if ($version == '6') {
  74.                         $uuid = gen_uuid_reordered();
  75.                 } else if ($version == '7') {
  76.                         $uuid = gen_uuid_unix_epoch();
  77.                 } else if ($version == '8') {
  78.                         $uuid = gen_uuid_custom(trim($_REQUEST['block1']??'0'), trim($_REQUEST['block2']??'0'), trim($_REQUEST['block3']??'0'), trim($_REQUEST['block4']??'0'), trim($_REQUEST['block5']??'0'));
  79.                 } else {
  80.                         throw new Exception("Unexpected version number");
  81.                 }
  82.         }
  83.         if (is_uuid_oid($uuid)) {
  84.                 $uuid = oid_to_uuid($uuid);
  85.         }
  86.  
  87.         if (!uuid_valid($uuid)) {
  88.                 echo 'This is not a valid UUID.';
  89.         } else {
  90.                 uuid_info($uuid);
  91.         }
  92. } catch (Exception $e) {
  93.     echo "Error: " . htmlentities($e->getMessage());
  94. }
  95.  
  96. ?></pre>
  97.  
  98. <br>
  99.  
  100. </body>
  101.  
  102. </html>
  103.