Subversion Repositories uuid_mac_utils

Rev

Rev 25 | Rev 29 | 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-11
  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. if ($uuid == 'CREATE') {
  24.         $title = 'Generate an UUID';
  25. } else {
  26.         $title = 'Interprete an UUID';
  27. }
  28.  
  29. ?><html>
  30.  
  31. <head>
  32.         <meta charset="iso-8859-1">
  33.         <link rel="stylesheet" type="text/css" href="style.css">
  34.         <title><?php echo $title; ?></title>
  35. </head>
  36.  
  37. <body>
  38.  
  39. <h1><?php echo $title; ?></h1>
  40.  
  41. <p><a href="index.php">Back</a></p>
  42.  
  43. <pre><?php
  44.  
  45. require_once __DIR__ . '/includes/uuid_utils.inc.php';
  46. require_once __DIR__ . '/includes/mac_utils.inc.php';
  47. require_once __DIR__ . '/includes/OidDerConverter.class.php';
  48.  
  49. if ($uuid == 'CREATE') {
  50.         if (!isset($_REQUEST['version'])) $_REQUEST['version'] = '1'; // default: Version 1 / time based
  51.  
  52.         if ($_REQUEST['version'] == '1') {
  53.                 $uuid = gen_uuid_timebased();
  54.         }
  55.  
  56.         if ($_REQUEST['version'] == '2') {
  57.  
  58.                 if (!isset($_REQUEST['dce_domain'])) die("Domain ID missing");
  59.                 if ($_REQUEST['dce_domain'] == '') die("Domain ID missing");
  60.                 $domain = $_REQUEST['dce_domain'];
  61.                 if (!is_numeric($domain)) die("Invalid Domain ID");
  62.                 if (($domain < 0) || ($domain > 255)) die("Domain ID must be in range 0..255");
  63.  
  64.                 if (!isset($_REQUEST['dce_id'])) die("ID value missing");
  65.                 if ($_REQUEST['dce_id'] == '') die("ID value missing");
  66.                 $id = $_REQUEST['dce_id'];
  67.                 if (!is_numeric($id)) die("Invalid ID value");
  68.                 if (($id < 0) || ($id > 4294967295)) die("ID value must be in range 0..4294967295");
  69.  
  70.                 $uuid = gen_uuid_dce($domain, $id);
  71.         }
  72.  
  73.         if (($_REQUEST['version'] == '3') || ($_REQUEST['version'] == '5')) {
  74.                 if (!isset($_REQUEST['nb_ns'])) die("Namespace UUID missing");
  75.                 if ($_REQUEST['nb_ns'] == '') die("Namespace UUID missing");
  76.                 $ns = $_REQUEST['nb_ns'];
  77.                 if (!uuid_valid($ns)) die("Invalid namespace UUID '".htmlentities($ns)."'");
  78.                 if (!isset($_REQUEST['nb_val'])) $_REQUEST['nb_val'] = '';
  79.                 if ($_REQUEST['version'] == '3') {
  80.                         $uuid = gen_uuid_md5_namebased($ns, $_REQUEST['nb_val']);
  81.                 } else {
  82.                         $uuid = gen_uuid_sha1_namebased($ns, $_REQUEST['nb_val']);
  83.                 }
  84.         }
  85.  
  86.         if ($_REQUEST['version'] == '4') {
  87.                 $uuid = gen_uuid_random();
  88.         }
  89. }
  90. if (is_uuid_oid($uuid)) {
  91.         $uuid = oid_to_uuid($uuid);
  92. }
  93.  
  94. if (!uuid_valid($uuid)) {
  95.         echo 'This is not a valid UUID.';
  96. } else {
  97.         $oid  = uuid_to_oid($uuid);
  98.         echo sprintf("%-32s %s\n", "Your input:", $uuid);
  99.         echo "\n";
  100.         echo sprintf("%-32s %s\n", "URN:", 'urn:uuid:'.strtolower(oid_to_uuid(uuid_to_oid($uuid))));
  101.         echo sprintf("%-32s %s\n", "URI:", 'uuid:'.strtolower(oid_to_uuid(uuid_to_oid($uuid))));
  102.         echo sprintf("%-32s %s\n", "Microsoft GUID syntax:", '{'.strtoupper(oid_to_uuid(uuid_to_oid($uuid))).'}');
  103.         echo sprintf("%-32s %s\n", "C++ struct syntax:", uuid_c_syntax($uuid));
  104.         echo "\n";
  105.         echo sprintf("%-32s %s\n", "As OID:", $oid);
  106.         echo sprintf("%-32s %s\n", "DER encoding of OID:", OidDerConverter::hexarrayToStr(OidDerConverter::oidToDER($oid)));
  107.         echo "\n";
  108.         echo "Interpration of the UUID:\n\n";
  109.         uuid_info($uuid);
  110. }
  111.  
  112. ?></pre>
  113.  
  114. <br>
  115.  
  116. </body>
  117.  
  118. </html>
  119.