Advertisement
AyrA

Bitmessage resolver

Jul 30th, 2013
344
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.80 KB | None | 0 0
  1. <?php
  2.     //here we could theoretically validate the DNS name.
  3.     $last="bm.ayra.ch";
  4.     if(isset($_GET["DNS"]))
  5.     {
  6.         $last=$_GET["DNS"];
  7.     }
  8. ?>
  9. <html>
  10.     <head>
  11.         <title>Bitmessage resolver</title>
  12.         <style type="text/css">
  13.             body
  14.             {
  15.                 font-family:Sans-Serif;
  16.             }
  17.             a
  18.             {
  19.                 color:#0000FF;
  20.                 font-weight:bold;
  21.             }
  22.             a:hover
  23.             {
  24.                 background-color:#FFFF00;
  25.             }
  26.             i
  27.             {
  28.                 font-size:8pt;
  29.                 margin-top:50px;
  30.                 display:block;
  31.             }
  32.             td
  33.             {
  34.                 padding-right:10px;
  35.             }
  36.         </style>
  37.     </head>
  38.     <body>
  39.         <h1>Simple PHP Bitmessage address resolver</h1>
  40.         This tool converts DNS records from
  41.         <a href="https://bitmessage.org/forum/index.php/topic,2767.0.html">this proposal</a>
  42.         into links from
  43.         <a href="https://bitmessage.org/forum/index.php/topic,2704.0.html">this proposal</a>.<br />
  44.         <br />
  45.         <form method="get" action="dns.php">
  46.             <input type="text" name="DNS" value="<?php echo $last; ?>" />
  47.             <input type="submit" value="Get Addresses" />
  48.         </form>
  49.         <h2>Result:</h2>
  50.         <table>
  51. <?php
  52.     //We check, if a TXT Record is present.
  53.     if($txt=dns_get_record($last,DNS_TXT))
  54.     {
  55.         //Multiple records can exist
  56.         foreach($txt as $txtentry)
  57.         {
  58.             //We split an entry up into pieces.
  59.             //This actually does not tests,
  60.             //if the domain name starts with "bm."
  61.             //since it does not matters for parsing anyway.
  62.             $entries=explode(";",$txtentry["txt"]);
  63.             foreach($entries as $value)
  64.             {
  65.                 //Very nasty check, if a Bitmessage address is present
  66.                 if(strpos($value,'BM-') !== false)
  67.                 {
  68.                     //Check, if a label is present.
  69.                     if(count(explode("=",$value))==1)
  70.                     {
  71.                         //no label, just print address.
  72.                         echo "<tr><td><a href=\"bitmsg:".urlencode($value)."\">".htmlspecialchars($value)."</a></td>";
  73.                         echo "<td><a href=\"bitmsg:".urlencode($value)."?action=subscribe\">subscribe</a>";
  74.                         echo "&nbsp;&nbsp;&nbsp;<a href=\"bitmsg:".urlencode($value)."?action=unsubscribe\">unsubscribe</a>";
  75.                         echo "&nbsp;&nbsp;&nbsp;<a href=\"bitmsg:".urlencode($value)."?action=add\">save</a>";
  76.                         echo "&nbsp;&nbsp;&nbsp;<a href=\"bitmsg:".urlencode($value)."?action=remove\">remove</a></td></tr>";
  77.                     }
  78.                     else
  79.                     {
  80.                         //label present, print address and label.
  81.                         $parts=explode("=",$value);
  82.                         echo "<tr><td><a href=\"bitmsg:".urlencode($parts[1])."?label=".urlencode($parts[0])."\">".htmlspecialchars("$parts[0] ($parts[1])")."</a></td>";
  83.                         echo "<td><a href=\"bitmsg:".urlencode($parts[1])."?label=".urlencode($parts[0])."&action=subscribe\">subscribe</a>";
  84.                         echo "&nbsp;&nbsp;&nbsp;<a href=\"bitmsg:".urlencode($parts[1])."?label=".urlencode($parts[0])."&action=unsubscribe\">unsubscribe</a>";
  85.                         echo "&nbsp;&nbsp;&nbsp;<a href=\"bitmsg:".urlencode($parts[1])."?label=".urlencode($parts[0])."&action=add\">save</a>";
  86.                         echo "&nbsp;&nbsp;&nbsp;<a href=\"bitmsg:".urlencode($parts[1])."?label=".urlencode($parts[0])."&action=remove\">remove</a>";
  87.                         //Since a label is present, it could be a DML address.
  88.                         echo "&nbsp;&nbsp;&nbsp;<a href=\"bitmsg:".urlencode($parts[1])."?label=".urlencode($parts[0])."&action=join\">join DML</a>";
  89.                         echo "&nbsp;&nbsp;&nbsp;<a href=\"bitmsg:".urlencode($parts[1])."?label=".urlencode($parts[0])."&action=leave\">leave DML</a></td></tr>";
  90.                     }
  91.                 }
  92.                 else
  93.                 {
  94.                     //Non BM Record. We print it for diagnostic reasons.
  95.                     echo "<tr><td colspan=\"2\">non BM TXT Record: ".htmlspecialchars($value)."</td></tr>";
  96.                 }
  97.             }
  98.         }
  99.     }
  100.     else
  101.     {
  102.         //No TXT record at all.
  103.         echo "<tr><td><i>no value found.</i></td></tr>";
  104.     }
  105. ?>
  106.         </table>
  107.        
  108.         <i>
  109.             Copyright by <a href="https://ayra.ch">AyrA</a>.
  110.             This page is provied as is and serves only as proof of concept.
  111.             If you use it in a productive environment
  112.             you are helplessly lost anyways.
  113.         </i>
  114.     </body>
  115. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement