-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprojectors.php
More file actions
200 lines (133 loc) · 5.31 KB
/
Copy pathprojectors.php
File metadata and controls
200 lines (133 loc) · 5.31 KB
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
<?php
echo "<html>";
echo "<meta http-equiv=refresh content=30; url=http://AutoNet.visionaire.net/AutoNet//projectors.php>";
echo "<head>";
echo "<title>AutoNet\\ Projector Control</title>";
echo "</head>";
echo "<body bgcolor=#009999 lang=EN-US style='tab-interval:.5in'>";
echo "<P fontsize=15 align=center> AutoNet\\ Projector Control </p>";
echo "<br>";
echo "<br>";
$community_string_private="private";
ini_set( "display_errors", 0);
$func=$_POST['func'];
$ip=$_POST['ip'];
//echo "<BR><BR> POST VALUE func=!$func!<BR><BR>";
//echo "<BR><BR> POST VALUE ip=!$ip!<BR><BR>";
if ($func=='RefreshThePage') ;
if ($func=='TurnOn') ProjectorSetState($ip,1,$community_string_private);
if ($func=='TurnOff') ProjectorSetState($ip,2,$community_string_private);
if ($func=='TurnOnAllProjectors') ProjectorSetBulk(1,$community_string_private);
if ($func=='TurnOffAllProjectors') ProjectorSetBulk(2,$community_string_private);
start();
function start(){
echo "<BR><BR><table border=1 align = center>";
echo "<p>";
echo "<tr>";
echo "<form method=post>";
echo "<td><input type=Submit name=func value=RefreshThePage></td>";
echo "</tr>";
echo "</form>";
echo "</table>";
echo "</p>";
echo "<BR><BR><table border=1 align = center>";
echo "<p>";
echo "<tr>";
echo "<form name=form1 method=post>";
echo "<td><input type=Submit name=func value=TurnOnAllProjectors></td>";
echo "<td><input type=Submit name=func value=TurnOffAllProjectors></td>";
echo "</form>";
echo "</table>";
echo "</tr>";
echo "</p>";
echo "<BR>";
echo "<table border=1 align = center>";
echo "<p>";
echo "<tr>";
echo "<td><font color=LIGHTGREEN>Building</td><td><font color=LIGHTGREEN>ClassRoom</td><td><font color=LIGHTGREEN>Projector Name</td><td><font color=LIGHTGREEN>Current Power State</td><td><font color=LIGHTGREEN>IP Address</td><td><font color=LIGHTGREEN>TurnOn</td><td><font color=LIGHTGREEN>TurnOff</td>";
echo "</tr>";
echo "</p>";
$host="127.0.0.1";
$user="root";
$password="rezasql";
# Connect to MySQL server
$conn = mysql_connect($host,$user,$password)
or die(mysql_error());
# Select the database
mysql_select_db("", $conn)
or die(mysql_error());
# Send SQL query
$sql="select bld,ip,room_name,projector_name from projectors order by bld,room_name,projector_name";
// echo "<R> $sql<BR>";
$result = mysql_query($sql)
or die(mysql_error());
while ($row=mysql_fetch_assoc($result)){
$ip_address=$row['ip'];
echo "<tr><td>".$row['bld']."</td><td>".$row['room_name']."</td><td>Projector #".$row['projector_name']."</td>";
$community_string_public="public";
$state=ProjectorReadState($ip_address,$community_string_public);
echo "<td align=center>".$state."</td><td>".$ip_address."</td>";
echo "<form name=form method=POST>";
echo "<input type=hidden name=ip value=$ip_address>";
if ($state!="<font color=RED><B>projector OFFLINE") {
echo "<td> <input type=submit name=func value=TurnOn> </td>";
echo "<td> <input type=submit name=func value=TurnOff> </td>";
$sql5="update projectors set status=1 where ip='".$ip_address."'";
// echo "<R> $sql5<BR>";
$result5 = mysql_query($sql5)
or die(mysql_error());
}
else {
echo "<td> </td>";
echo "<td> </td>";
}
echo "</form>";
echo "</tr>";
}
echo "</table>";
}
function ProjectorReadState($ip,$community_string_public) {
$oid=".1.3.6.1.4.1.29485.3.2.3.1.0";
$state_int=snmpget($ip,$community_string_public,$oid,1000000,0);
// echo "<BR><BR> VALUE IS ::::: !$state_int!<BR><BR>";
if (!$state_int) $state="<font color=RED><B>projector OFFLINE";
if ($state_int=="INTEGER: 1") $state="<font color=GREEN><B>On";
if ($state_int=="INTEGER: 2") $state="<font color=RED><B>Off";
if ($state_int=="INTEGER: 3") $state="<font color=PURPLE><B>Powering On";
if ($state_int=="INTEGER: 4") $state="<font color=BROWN><B>Turning Off , Cooling";
if ($state_int=="INTEGER: 5") $state="<font color=WHITE><B>Waiting for Confirm Off State";
return($state);
}
function ProjectorSetState($ip,$value,$community_string_private) {
$oid=".1.3.6.1.4.1.29485.3.2.3.1.0";
$oid_type="i";
// echo "<BR><BR> function is snmpset($ip,$community_string_private,$oid,$oid_type,$value) <BR><BR>";
$state_int=snmpset($ip,$community_string_private,$oid,$oid_type,$value);
}
function ProjectorSetBulk($value,$community_string_private){
$host="127.0.0.1";
$user="root";
$password="rezasql";
# Connect to MySQL server
$conn = mysql_connect($host,$user,$password)
or die(mysql_error());
# Select the database
mysql_select_db("", $conn)
or die(mysql_error());
# Send SQL query
$sql="select ip from projectors where status=1";
// echo "<R> $sql<BR>";
$result2 = mysql_query($sql)
or die(mysql_error());
while ($row2=mysql_fetch_assoc($result2)){
$ip_address=$row2['ip'];
// echo "<br> working for this IP:$ip_address!<BR>";
$oid=".1.3.6.1.4.1.29485.3.2.3.1.0";
$oid_type="i";
$state_int=snmpset($ip_address,$community_string_private,$oid,$oid_type,$value);
// echo "<BR><BR> function is snmpset($ip_address,$community_string_private,$oid,$oid_type,$value)";
}//end of while
}//end of function
echo "</body>";
echo "</html>";
?>