Subversion Repositories uuid_mac_utils

Rev

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

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