2
0

request.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <?php
  2. session_start();
  3. if(!$domain_name)
  4. {
  5. include("index.php");
  6. die;
  7. }
  8. ?>
  9. <html>
  10. <head>
  11. </head>
  12. <body bgcolor=#0099cc>
  13. <br>
  14. <center><h1>Prefix Domain Translation -- UserInterface</h1></center>
  15. <br>
  16. <?php
  17. $database="pdt";
  18. $table="admin";
  19. $input_file = "/tmp/ser_fifo";
  20. #datbase hostname
  21. $host="127.0.0.1";
  22. # database user
  23. $user="root";
  24. # database user password
  25. $pass="";
  26. $authorized="0";
  27. if(!strcasecmp($admin, "Anonymous") || !strcmp($admin,""))
  28. $authorized = "0";
  29. else
  30. {
  31. if(!strcmp($passwd,""))
  32. {
  33. echo "<h2>No password supplied</h2>";
  34. exit;
  35. }
  36. $link = mysql_connect($host, $user, $pass)
  37. or die("Could not connect to mysql");
  38. mysql_select_db($database) or die("Could not select database");
  39. $query = "SELECT * FROM ".$table." WHERE name=\"".$admin."\" and passwd=\"".$passwd."\"";
  40. $result = mysql_query($query) or die("Query failed: ".mysql_error());
  41. $num_rows = mysql_num_rows($result);
  42. if($num_rows>0)
  43. $authorized="1";
  44. else
  45. echo "<h2>Authentication failed. No right to register a new domain.</h2>";
  46. mysql_free_result($result);
  47. mysql_close($link);
  48. }
  49. $response_file = "rf".session_id();
  50. $reply = "/tmp/".$response_file;
  51. @system("mkfifo -m 666 ".$reply);
  52. $new_line ="\n";
  53. $fifo_command = ":get_domainprefix:";
  54. $fifo_command = $fifo_command.$response_file.$new_line;
  55. $fifo_command = $fifo_command.$domain_name;
  56. if($domain_port)
  57. $fifo_command = $fifo_command.":".$domain_port;
  58. $fifo_command = $fifo_command.$new_line;
  59. $fifo_command = $fifo_command.$authorized.$new_line.$new_line;
  60. $fp = fopen($input_file, "w");
  61. if(!$fp)
  62. {
  63. echo "Cannot open fifo<br>";
  64. exit;
  65. }
  66. if( fwrite($fp, $fifo_command) == -1)
  67. {
  68. @unlink($reply);
  69. @fclose($fp);
  70. echo "fifo writing error<br>";
  71. exit;
  72. }
  73. fclose($fp);
  74. $fr = fopen($reply, "r");
  75. if(!$fr)
  76. {
  77. @unlink($reply);
  78. echo "Cannot open reply file";
  79. exit;
  80. }
  81. $count = 1000;
  82. $str = fread($fr, $count);
  83. if(!$str)
  84. {
  85. @fclose($fr);
  86. @unlink($reply);
  87. echo "response fifo reading error";
  88. exit;
  89. }
  90. $domain_code = "";
  91. list($return_code, $description) = explode("|", $str);
  92. if(!strcmp("$return_code","400 "))
  93. {
  94. echo "<h2>ERROR: Cannot read from fifo. Try again.</h2>";
  95. exit;
  96. }
  97. list($garbage1, $garbage2, $domain_code) = explode("=", $str);
  98. list($domain_code, $garbage3) = explode("\n", $domain_code);
  99. fclose($fr);
  100. @unlink("/tmp/".$response_file);
  101. if(!strcmp("$return_code","204 "))
  102. {
  103. $domain_code = "registration failed";
  104. }
  105. if(!strcmp("$return_code","203 "))
  106. {
  107. $domain_code = "not registered";
  108. }
  109. ?>
  110. <table border=1 align="center" cellspacing="40" cellpadding="10">
  111. <tr>
  112. <td>
  113. <font size=4>Domain Name</font>
  114. </td>
  115. <td>
  116. <b><font size=5><?php echo $domain_name;?></font></b>
  117. </td>
  118. </tr>
  119. <tr>
  120. <td>
  121. <font size=4>Domain Code</font>
  122. </td>
  123. <td>
  124. <b><font size=5><?php echo $domain_code;?></font></b>
  125. </td>
  126. </tr>
  127. </table>
  128. </body>
  129. </html>