File: request.php

package info (click to toggle)
openser 1.1.0-9etch1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 9,828 kB
  • ctags: 11,809
  • sloc: ansic: 120,528; sh: 5,249; yacc: 1,716; makefile: 1,261; php: 656; perl: 205; sql: 190
file content (157 lines) | stat: -rw-r--r-- 3,052 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<?php
session_start();

if(!$domain_name)
{
    include("index.php");
    die;
}    
?>

<html>
<head>
</head>
<body bgcolor=#0099cc>
<br>
<center><h1>Prefix Domain Translation -- UserInterface</h1></center>
<br>

<?php
$database="pdt";
$table="admin";
$input_file = "/tmp/ser_fifo";

#datbase hostname
$host="127.0.0.1";

# database user
$user="root";

# database user password
$pass="";

		
	$authorized="0";
	
	if(!strcasecmp($admin, "Anonymous") || !strcmp($admin,""))
	    $authorized = "0";
	else
	{
	    if(!strcmp($passwd,""))
	    {
		echo "<h2>No password supplied</h2>";
		exit;
	    }
	    
	    $link = mysql_connect($host, $user, $pass)
		or die("Could not connect to mysql");

	    mysql_select_db($database) or die("Could not select database");       
	
	    $query = "SELECT * FROM ".$table." WHERE name=\"".$admin."\" and passwd=\"".$passwd."\"";
	
	    $result = mysql_query($query) or die("Query failed: ".mysql_error());	
	
	    $num_rows = mysql_num_rows($result);
	    if($num_rows>0)
		$authorized="1";
	    else
    		echo "<h2>Authentication failed. No right to register a new domain.</h2>";	
	
	    mysql_free_result($result);

	    mysql_close($link);
	    
	}    	
	    
	$response_file = "rf".session_id();
	$reply = "/tmp/".$response_file;
	@system("mkfifo -m 666 ".$reply);
	
	$new_line ="\n";	
	$fifo_command = ":get_domainprefix:";	
	$fifo_command = $fifo_command.$response_file.$new_line;
	$fifo_command = $fifo_command.$domain_name;
	if($domain_port)
	    $fifo_command = $fifo_command.":".$domain_port;
	$fifo_command = $fifo_command.$new_line;
	$fifo_command = $fifo_command.$authorized.$new_line.$new_line;

	$fp = fopen($input_file, "w");
	if(!$fp)
	{
	    echo "Cannot open fifo<br>";
	    exit;
	}
	    
	if( fwrite($fp, $fifo_command) == -1)
	{
	    @unlink($reply);
	    @fclose($fp);
	    echo "fifo writing error<br>";
	    exit;
	}
	fclose($fp);

	$fr = fopen($reply, "r");
	if(!$fr)
	{
	    @unlink($reply);
	    echo "Cannot open reply file";
	    exit;
	}
	$count = 1000;
	$str = fread($fr, $count);
	if(!$str)
	{
	    @fclose($fr);
	    @unlink($reply);
	    echo "response fifo reading error";
	    exit;
	}
	$domain_code = "";
	list($return_code, $description) = explode("|", $str);
	if(!strcmp("$return_code","400 "))	
	{
	    echo "<h2>ERROR: Cannot read from fifo. Try again.</h2>";
	    exit;
	}
	list($garbage1, $garbage2, $domain_code) = explode("=", $str);
	list($domain_code, $garbage3) = explode("\n", $domain_code);
	fclose($fr);
	@unlink("/tmp/".$response_file);
	
	
	if(!strcmp("$return_code","204 "))
	{
	    $domain_code = "registration failed"; 
	}
	
	if(!strcmp("$return_code","203 "))
	{
	    $domain_code = "not registered";
	}
		
?>

<table border=1 align="center" cellspacing="40" cellpadding="10">
<tr>
	<td>
		<font size=4>Domain Name</font>
	</td>
	<td>
		<b><font size=5><?php echo $domain_name;?></font></b>
	</td>
</tr>
<tr>
	<td>
		<font size=4>Domain Code</font>
	</td>
	<td>
		<b><font size=5><?php echo $domain_code;?></font></b>
	</td>
</tr>
</table>

</body>
</html>