Main Page | Modules | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

request.php

Go to the documentation of this file.
00001 <?php
00002 session_start();
00003 
00004 if(!$domain_name)
00005 {
00006     include("index.php");
00007     die;
00008 }    
00009 ?>
00010 
00011 <html>
00012 <head>
00013 </head>
00014 <body bgcolor=#0099cc>
00015 <br>
00016 <center><h1>Prefix Domain Translation -- UserInterface</h1></center>
00017 <br>
00018 
00019 <?php
00020 $database="pdt";
00021 $table="admin";
00022 $input_file = "/tmp/ser_fifo";
00023 
00024 #datbase hostname
00025 $host="127.0.0.1";
00026 
00027 # database user
00028 $user="root";
00029 
00030 # database user password
00031 $pass="";
00032 
00033                 
00034         $authorized="0";
00035         
00036         if(!strcasecmp($admin, "Anonymous") || !strcmp($admin,""))
00037             $authorized = "0";
00038         else
00039         {
00040             if(!strcmp($passwd,""))
00041             {
00042                 echo "<h2>No password supplied</h2>";
00043                 exit;
00044             }
00045             
00046             $link = mysql_connect($host, $user, $pass)
00047                 or die("Could not connect to mysql");
00048 
00049             mysql_select_db($database) or die("Could not select database");       
00050         
00051             $query = "SELECT * FROM ".$table." WHERE name=\"".$admin."\" and passwd=\"".$passwd."\"";
00052         
00053             $result = mysql_query($query) or die("Query failed: ".mysql_error());       
00054         
00055             $num_rows = mysql_num_rows($result);
00056             if($num_rows>0)
00057                 $authorized="1";
00058             else
00059                 echo "<h2>Authentication failed. No right to register a new domain.</h2>";      
00060         
00061             mysql_free_result($result);
00062 
00063             mysql_close($link);
00064             
00065         }       
00066             
00067         $response_file = "rf".session_id();
00068         $reply = "/tmp/".$response_file;
00069         @system("mkfifo -m 666 ".$reply);
00070         
00071         $new_line ="\n";        
00072         $fifo_command = ":get_domainprefix:";   
00073         $fifo_command = $fifo_command.$response_file.$new_line;
00074         $fifo_command = $fifo_command.$domain_name;
00075         if($domain_port)
00076             $fifo_command = $fifo_command.":".$domain_port;
00077         $fifo_command = $fifo_command.$new_line;
00078         $fifo_command = $fifo_command.$authorized.$new_line.$new_line;
00079 
00080         $fp = fopen($input_file, "w");
00081         if(!$fp)
00082         {
00083             echo "Cannot open fifo<br>";
00084             exit;
00085         }
00086             
00087         if( fwrite($fp, $fifo_command) == -1)
00088         {
00089             @unlink($reply);
00090             @fclose($fp);
00091             echo "fifo writing error<br>";
00092             exit;
00093         }
00094         fclose($fp);
00095 
00096         $fr = fopen($reply, "r");
00097         if(!$fr)
00098         {
00099             @unlink($reply);
00100             echo "Cannot open reply file";
00101             exit;
00102         }
00103         $count = 1000;
00104         $str = fread($fr, $count);
00105         if(!$str)
00106         {
00107             @fclose($fr);
00108             @unlink($reply);
00109             echo "response fifo reading error";
00110             exit;
00111         }
00112         $domain_code = "";
00113         list($return_code, $description) = explode("|", $str);
00114         if(!strcmp("$return_code","400 "))      
00115         {
00116             echo "<h2>ERROR: Cannot read from fifo. Try again.</h2>";
00117             exit;
00118         }
00119         list($garbage1, $garbage2, $domain_code) = explode("=", $str);
00120         list($domain_code, $garbage3) = explode("\n", $domain_code);
00121         fclose($fr);
00122         @unlink("/tmp/".$response_file);
00123         
00124         
00125         if(!strcmp("$return_code","204 "))
00126         {
00127             $domain_code = "registration failed"; 
00128         }
00129         
00130         if(!strcmp("$return_code","203 "))
00131         {
00132             $domain_code = "not registered";
00133         }
00134                 
00135 ?>
00136 
00137 <table border=1 align="center" cellspacing="40" cellpadding="10">
00138 <tr>
00139         <td>
00140                 <font size=4>Domain Name</font>
00141         </td>
00142         <td>
00143                 <b><font size=5><?php echo $domain_name;?></font></b>
00144         </td>
00145 </tr>
00146 <tr>
00147         <td>
00148                 <font size=4>Domain Code</font>
00149         </td>
00150         <td>
00151                 <b><font size=5><?php echo $domain_code;?></font></b>
00152         </td>
00153 </tr>
00154 </table>
00155 
00156 </body>
00157 </html>

Generated on Tue Sep 7 04:16:04 2010 for SIPExpressRouter by  doxygen 1.3.9.1