Attachment 'index.php'
Download 1 <?php
2 function cleanup($str)
3 {
4 return(substr(stripslashes($str), 1, -1));
5 }
6
7 $validcountries = array("AU" => "Australia", "TH" => "Thailand", "IL" => "Israel", "JO" => "Jordan", "CN" => "China",
8 "JP" => "Japan", "US" => "USA/Canada/New Zealand", "DE" => "Europe", "All" => "All channels");
9 $gmodes = array(0 => "802.11b Only", 1 => "Auto", 2 => "802.11g only", 3 => "802.11b Deferred", 4 => "Performance", 5 => "Limited Rate Support");
10
11 $proto = trim(`/usr/sbin/nvram get wan_proto`);
12 $ip = trim(`/usr/sbin/nvram get wan_ipaddr`);
13 $netmask = trim(`/usr/sbin/nvram get wan_netmask`);
14 $gateway = trim(`/usr/sbin/nvram get wan_gateway`);
15 $dns = trim(`/usr/sbin/nvram get wan_dns`);
16 $username = trim(`/usr/sbin/nvram get ppp_username`);
17 $password = trim(`/usr/sbin/nvram get ppp_passwd`);
18 $wanif = trim(`/usr/sbin/nvram get wan_ifname`);
19 $ssid = trim(`/usr/sbin/nvram get wl0_ssid`);
20
21 $closed = intval(trim(`/usr/sbin/nvram get wl0_closed`));
22 $gmode = intval(trim(`/usr/sbin/nvram get wl0_gmode`));
23 $channel = intval(trim(`/usr/sbin/nvram get wl0_channel`));
24 $radio = intval(trim(`/usr/sbin/nvram get wl0_radio`));
25 $country_code = trim(`/usr/sbin/nvram get wl0_country_code`);
26 $antdiv = intval(trim(`/usr/sbin/nvram get wl0_antdiv`));
27 $txant = intval(trim(`/usr/sbin/nvram get wl0_txant`));
28 $txpwr1 = intval(trim(`/usr/sbin/nvram get wl0_txpwr1`));
29
30 if($country_code == "")
31 $country_code = "All";
32
33 $fp = fopen("/etc/openvpn/access-control.txt", "r");
34 while(!feof($fp))
35 {
36 $line = trim(fgets($fp, 4096));
37 if($line == "")
38 continue;
39 if($subjects != "")
40 $subjects .= "\n";
41 $subjects .= $line;
42 }
43 fclose($fp);
44
45 if($_REQUEST['reboot'] == "Reboot")
46 {
47 $do = `/sbin/reboot`;
48 $errmsg = "Please wait while the router is rebooted";
49 }
50
51 if($_REQUEST['process'] == "1")
52 {
53 $wanifnew = escapeshellarg(trim($_REQUEST['wanif']));
54
55
56 if(trim($_REQUEST['ssid']) != $ssid)
57 {
58 $ssid = escapeshellarg(trim($_REQUEST['ssid']));
59 $do = `/usr/sbin/nvram set wl0_ssid=$ssid`;
60 $ssid = cleanup($ssid);
61 }
62
63 if(cleanup($wanifnew) != $wanif)
64 {
65 if(cleanup($wanifnew) == "vlan1")
66 {
67 $channel = escapeshellarg(trim($_REQUEST['channel']));
68 $do = `/usr/sbin/nvram set lan_ifnames=vlan0`;
69 $do = `/usr/sbin/nvram set wan_ifname=vlan1`;
70 $do = `/usr/sbin/nvram set wan_proto=dhcp`;
71 $do = `/usr/sbin/nvram set wifi_proto=static`;
72 $do = `/usr/sbin/nvram set wl0_mode=ap`;
73 $do = `/usr/sbin/nvram set wl0_channel=$channel`;
74 $do = `ln -sf /etc/init.d/openvpn /etc/init.d/S75openvpn`;
75 $proto = "dhcp";
76 $wanif = "vlan1";
77 $channel = cleanup($channel);
78 }
79
80 if(cleanup($wanifnew) == "tap0")
81 {
82 $do = `/usr/sbin/nvram set lan_ifnames='vlan0 vlan1'`;
83 $do = `/usr/sbin/nvram set wan_ifname=tap0`;
84 $do = `/usr/sbin/nvram set wan_proto=dhcp`;
85 $do = `/usr/sbin/nvram set wifi_proto=dhcp`;
86 $do = `/usr/sbin/nvram set wl0_mode=sta`;
87 $do = `/usr/sbin/nvram unset wl0_channel`;
88 $do = `ln -sf /etc/init.d/openvpn-client /etc/init.d/S75openvpn`;
89 $proto = "dhcp";
90 $wanif = "tap0";
91 }
92 }
93
94 if(trim($_REQUEST['subjects']) != $subjects)
95 {
96 $subjects = trim($_REQUEST['subjects']);
97 $fp = fopen("/etc/openvpn/access-control.txt", "r");
98 fputs($fp, $subjects);
99 fclose($fp);
100 }
101
102 if($_REQUEST['proto'] != "")
103 {
104 $proto = escapeshellarg(trim($_REQUEST['proto']));
105 $do = `/usr/sbin/nvram set wan_proto=$proto`;
106 $proto = cleanup($proto);
107 }
108 if($_REQUEST['proto'] == "pppoe")
109 {
110 $username = escapeshellarg(trim($_REQUEST['username']));
111 $password = escapeshellarg(trim($_REQUEST['password']));
112 $do = `/usr/sbin/nvram set wan_ifname=ppp0`;
113 $do = `/usr/sbin/nvram set ppp_mtu=1492`;
114 $do = `/usr/sbin/nvram set ppp_redialperiod=30`;
115 $do = `/usr/sbin/nvram set ppp_username=$username`;
116 $do = `/usr/sbin/nvram set ppp_passwd=$password`;
117 $do = `/usr/sbin/nvram set pppoe_ifname=$wanifnew`;
118 $do = `/usr/sbin/nvram set pppoe_username=$username`;
119 $do = `/usr/sbin/nvram set pppoe_passwd=$password`;
120 $username = cleanup($username);
121 $password = cleanup($password);
122 $do = `ln -sf /etc/init.d/pppoe-client /etc/init.d/S51pppoe-client`;
123 } else {
124 $do = `/usr/sbin/nvram set wan_ifname=$wanifnew`;
125 $do = `rm -f /etc/init.d/S51pppoe-client`;
126 }
127
128 if($_REQUEST['proto'] == "static")
129 {
130 $ip = escapeshellarg(trim($_REQUEST['IP']));
131 $netmask = escapeshellarg(trim($_REQUEST['netmask']));
132 $gateway = escapeshellarg(trim($_REQUEST['gateway']));
133 $dns = escapeshellarg(trim($_REQUEST['dns']));
134
135 $do = `/usr/sbin/nvram set wan_ipaddr=$ip`;
136 $do = `/usr/sbin/nvram set wan_netmask=$netmask`;
137 $do = `/usr/sbin/nvram set wan_gateway=$gateway`;
138 $do = `/usr/sbin/nvram set wan_dns=$dns`;
139
140 $ip = cleanup($ip);
141 $netmask = cleanup($netmask);
142 $gateway = cleanup($gateway);
143 $dns = cleanup($dns);
144 }
145
146 if($wanif == "vlan1" && $channel != trim($_REQUEST['channel']))
147 {
148 $channel = escapeshellarg(trim($_REQUEST['channel']));
149 $do = `/usr/sbin/nvram set wl0_channel=$channel`;
150 $channel = cleanup($channel);
151 }
152
153 if($closed != trim($_REQUEST['closed']))
154 {
155 $closed = escapeshellarg(trim($_REQUEST['closed']));
156 $do = `/usr/sbin/nvram set wl0_closed=$closed`;
157 $closed = cleanup($closed);
158 }
159
160 if($gmode != trim($_REQUEST['gmode']))
161 {
162 $gmode = escapeshellarg(trim($_REQUEST['gmode']));
163 $do = `/usr/sbin/nvram set wl0_gmode=$gmode`;
164 $gmode = cleanup($gmode);
165 }
166
167 if($radio != trim($_REQUEST['radio']))
168 {
169 $radio = escapeshellarg(trim($_REQUEST['radio']));
170 $do = `/usr/sbin/nvram set wl0_radio=$radio`;
171 $radio = cleanup($radio);
172 }
173
174 if($country_code != trim($_REQUEST['country_code']))
175 {
176 $country_code = escapeshellarg(trim($_REQUEST['country_code']));
177 $do = `/usr/sbin/nvram set wl0_country_code=$country_code`;
178 $country_code = cleanup($country_code);
179 }
180
181 if($antdiv != trim($_REQUEST['antdiv']))
182 {
183 $antdiv = escapeshellarg(trim($_REQUEST['antdiv']));
184 $do = `/usr/sbin/nvram set wl0_antdiv=$antdiv`;
185 $antdiv = cleanup($antdiv);
186 }
187
188 if($txant != trim($_REQUEST['txant']))
189 {
190 $txant = escapeshellarg(trim($_REQUEST['txant']));
191 $do = `/usr/sbin/nvram set wl0_txant=$txant`;
192 $txant = cleanup($txant);
193 }
194
195 if($txpwr1 != trim($_REQUEST['txpwr1']))
196 {
197
198 $txpwr1 = intval(trim($_REQUEST['txpwr1']));
199 if($txpwr1 < 1)
200 $txpwr1 = 1;
201 if($txpwr1 > 255)
202 $txpwr1 = 255;
203 $do = `/usr/sbin/nvram set wl0_txpwr1=$txpwr1`;
204 $txpwr2 = $txpwr1;
205 if($txpwr1 > 251)
206 $txpwr2 = -1;
207 $do = `/usr/sbin/wl txpwr1 -m $txpwr2`;
208 }
209
210 $do = `/usr/sbin/nvram commit`;
211 $errmsg = "Updates commited, please reboot to make changes active";
212 }
213 ?>
214 <html>
215 <style>
216 table.stat th, table.stat td {
217 font-family: Verdana, Geneva, sans-serif;
218 font-size : 11px;
219 color: blue;
220 border: 0px solid;
221 white-space: nowrap;
222 }
223 .inputw{
224 font-family: Verdana, Geneva, sans-serif;
225 font-size : 11px;
226 border : 0px;
227 color : darkblue;
228 }
229
230 .inputc {
231 font-family: Verdana, Geneva, sans-serif;
232 font-size : 11px;
233 border : 0px;
234 color : darkblue;
235 }
236
237 .swalft {
238 font-family : Arial;
239 font-size : 9px;
240 color : blue;
241 }
242
243 .swdlft {
244 font-family : Arial;
245 font-size : 9px;
246 color : black;
247 }
248
249 .labelft {
250 font-family: Verdana, Geneva, sans-serif;
251 font-size : 12px;
252 color : #990000;
253 }
254
255 .cpft {
256 font-family : Arial;
257 font-size : 9px;
258 color : black;
259 }
260
261 .navbar .tab {
262 font-family: Verdana, Geneva, sans-serif;
263 font-size: 12px;
264 display: inline;
265 margin: 1px -5px 1px 5px;
266 float: left;
267 padding: 3px 6px 3px 6px;
268 background: rgb(234,242,255);
269 border: 1px solid;
270 border-color: rgb(120,172,255);
271 border-left: 0;
272 border-bottom: 0;
273 border-top: 0;
274
275 z-index: 1;
276 position: relative;
277 top: 0;
278 font-weight: normal;
279 }
280 .navbar .tab.selected {
281 border: 1px solid rgb(120,172,255);
282 border-bottom: 0;
283 z-index: 3;
284 padding: 2px 6px 11px 6px;
285 margin: 1px -6px -2px 0px;
286 top: -2px;
287 background: white;
288 font-weight: bold;
289 }
290 .navbar .tab a {
291 font-family: Verdana, Geneva, sans-serif;
292 font-size: 13px;
293 color: rgb(153,0,0);
294 text-decoration: none;
295 cursor: hand;
296 }
297 .navbar .hover a {
298 color: rgb(0,73,150);
299 }
300 .tab-page {
301 clear: both;
302 border: 1px solid rgb(120,172,255);
303 background: White;
304 z-index: 2;
305 position: relative;
306 top: -2px;
307 color: Blue;
308 font-family: Verdana, Geneva, sans-serif;
309 font-size: 11px;
310 padding: 0px;
311 width: 100%;
312 height: 400px;
313 min-height: 400px;
314 }
315 .navbar {
316 z-index: 1;
317 white-space: nowrap;
318 background: rgb(234,242,255);
319 height: 30px;
320 width: 100%;
321 }
322
323 .tablayout {
324 position: relative;
325 top: 10px;
326 height: 370px;
327 background: #dcdcdc;
328 padding: 10px;
329 }
330 </style>
331 <script type="text/javascript">
332 var check = false;
333 var currentPage = null;
334 var ns4 = false;
335 var ie4 = false;
336 var dom = false;
337 var hideStr = "";
338 var showStr = "";
339
340 function init()
341 {
342 styleStr=".style.display";
343 hideStr="='none'";
344 showStr="='block'";
345 check = true;
346 if (document.getElementById){
347 dom = true;
348 }
349 else if (document.all){
350 ie4 = true;
351 }
352 else if (document.layers) {
353 ns4 = true;
354 styleStr=".visibility";
355 hideStr="='hide'";
356 showStr="='show'";
357 }
358 else check=false;
359 }
360
361 function getAllTags(tags)
362 {
363 if (check){
364 if (document.getElementsByTagName)
365 return document.getElementsByTagName(tags);
366 if (document.document.all)
367 return document.all.tags(tags);
368 if (document.layers)
369 return document.lalyers;
370 if (document.divs)
371 return document.divs;
372 }
373 return null;
374 }
375
376 function getElement(tabName)
377 {
378 if (check){
379 if (dom)
380 return document.getElementById(tabName);
381 if (ie4)
382 return document.all[tabName];
383 if (ns4)
384 return document.layers[tabName];
385 }
386 return null;
387 }
388
389
390 function onMouseOver(tabName)
391 {
392 var el;
393
394 el = getElement("nav"+tabName);
395 if (el==null)
396 return;
397
398 el.className = el.className + " hover";
399 }
400
401 function onMouseOut(tabName)
402 {
403 var el;
404
405 el = getElement("nav"+tabName);
406 if (el==null)
407 return;
408
409 el.className = el.className.replace(/ hover/g, "");
410 }
411
412 function showTab(tabName)
413 {
414 var el;
415
416 el = getElement(tabName);
417 if (el==null)
418 return;
419
420 eval("el"+styleStr+showStr);
421
422 el = getElement("nav"+tabName);
423 if (el==null)
424 return;
425
426 el.className = el.className.replace(/tab/g, "tab selected");
427 }
428 function hideTab(tabName)
429 {
430 var el;
431
432 el = getElement(tabName);
433 if (el==null)
434 return;
435
436 eval("el"+styleStr+hideStr);
437
438 el = getElement("nav"+tabName);
439 if (el==null)
440 return;
441
442 el.className = el.className.replace(/ selected/g, "");
443 }
444 function switchPage(newpage)
445 {
446 if (currentPage!=null)
447 hideTab(currentPage);
448 currentPage=newpage;
449 showTab(newpage);
450 }
451 function hideOthers()
452 {
453 var all;
454 var i;
455 var first=1;
456
457 all = getAllTags("div");
458 if (all==null)
459 return;
460 for (i=0; i<all.length; i++){
461 if (all[i].className=="tab-page"){
462 if (first==1){
463 first=0;
464 switchPage(all[i].id);
465 }
466 else eval("all[i]"+styleStr+hideStr);
467 }
468 }
469 }
470
471 function ict_change(dobj)
472 {
473 var si_obj;
474
475 si_obj = getElement("si_obj");
476 if (si_obj==null)
477 return;
478 if (dobj.value=='0'){
479 eval("si_obj"+styleStr+showStr);
480 }
481 else
482 eval("si_obj"+styleStr+hideStr);
483 }
484
485 function onLoad()
486 {
487 init();
488 hideOthers();
489 ict_change(getElement("30383"));
490 }
491 </script>
492 <head>
493 <title>OpenWRT/OpenVPN Web Interface</title>
494 </head>
495 <body>
496 <?php if($errmsg != "") { ?><div id="errmsg"><?php echo $errmsg; ?></div><?php } ?>
497 <form method="post" action="index.php">
498 <input type="hidden" name="process" value="1">
499
500 <div class="navbar">
501 <h2 class="tab" id="navConnection" onclick="switchPage('Connection');"><a href="#" onmouseover="onMouseOver('Connection');" onmouseout="onMouseOut('Connection');" onclick="return false;">Uplink Connection</a></h2>
502 <h2 class="tab" id="navWifiSettings" onclick="switchPage('WifiSettings');"><a href="#" onmouseover="onMouseOver('WifiSettings');" onmouseout="onMouseOut('WifiSettings');" onclick="return false;">WIFI Settings</a></h2>
503 <h2 class="tab" id="navOpenVPN" onclick="switchPage('OpenVPN');"><a href="#" onmouseover="onMouseOver('OpenVPN');" onmouseout="onMouseOut('OpenVPN');" onclick="return false;">OpenVPN</a></h2>
504 <h2 class="tab" id="navSysLog" onclick="switchPage('SysLog');"><a href="#" onmouseover="onMouseOver('SysLog');" onmouseout="onMouseOut('SysLog');" onclick="return false;">SysLog</a></h2>
505 <p align=right>OpenWRT/OpenVPN Web Interface</p>
506 </div>
507
508 <div class="tab-page" id="Connection">
509 <div class="tablayout">
510 <input <?php if($proto == "dhcp") { echo "checked "; } ?>type="radio" name="proto" value="dhcp"><strong>Automatic - DHCP</strong><br />
511 WAN Interface: <input type="radio" name="wanif" value="vlan1" <?php if($wanif == "vlan1") { echo "checked "; } ?>/> WAN Port <input type="radio" name="wanif" value="tap0" <?php if($wanif == "tap0") { echo "checked "; } ?>/> Wifi Port<br />
512 (The WAN port will be another LAN port when you use Wifi for uplink connectivity - 5 instead of 4 LAN ports)<br />
513 <hr />
514 <input <?php if($proto == "static") { echo "checked "; } ?>type="radio" name="proto" value="static"><strong>Static IP</strong><br />
515 IP: <input type="text" name="IP" value="<?php echo $ip; ?>" style="margin-bottom: 0.4em"><br />
516 Netmask: <input type="text" name="netmask" value="<?php echo $netmask; ?>" style="margin-bottom: 0.4em"><br />
517 Gateway: <input type="text" name="gateway" value="<?php echo $gateway; ?>" style="margin-bottom: 0.4em"><br />
518 DNS: <input type="text" name="dns" value="<?php echo $dns; ?>" style="margin-bottom: 0.4em"><br />
519 <hr />
520 <input <?php if($proto == "pppoe") { echo "checked "; } ?>type="radio" name="proto" value="pppoe"><strong>PPPoE</strong><br />
521 Username: <input type="text" name="username" value="<?php echo $username; ?>" style="margin-bottom: 0.4em"><br />
522 Password: <input type="text" name="password" value="<?php echo $password; ?>" style="margin-bottom: 0.4em"><br />
523 </div>
524 </div>
525 <div class="tab-page" id="WifiSettings">
526 <div class="tablayout">
527 Radio Enabled: <input <?php if($radio == "1") { echo "checked "; } ?>type="radio" name="radio" value="1">Enable
528 <input <?php if($radio == "0") { echo "checked "; } ?>type="radio" name="radio" value="0">Disable<br />
529 WIFI channel: <select name="channel">
530 <option value="0">Auto Selection</option>
531 <?php
532 for($i = 1; $i <= 14; $i++)
533 {
534 echo "<option value='$i'";
535 if($i == $channel)
536 echo " selected";
537 echo ">$i</option>\n";
538 }
539 ?></select><br />
540 WIFI SSID: <input type="text" name="ssid" value="<?php echo $ssid?>" /><br />
541 SSID broadcasts: <input <?php if($closed == "1") { echo "checked "; } ?>type="radio" name="closed" value="1">Disable
542 <input <?php if($closed == "0") { echo "checked "; } ?>type="radio" name="closed" value="0">Enable<br />
543 G-Mode: <select name="gmode">
544 <?php
545 foreach($gmodes as $key => $val)
546 {
547 echo "<option value='$key'";
548 if($key == $gmode)
549 echo " selected";
550 echo ">$val</option>\n";
551 }
552 ?></select><br />
553 Country Selection: <select name="country_code">
554 <?php
555 foreach($validcountries as $key => $val)
556 {
557 echo "<option value='$key'";
558 if($key == $country_code)
559 echo " selected";
560 echo ">$val</option>\n";
561 }
562 ?></select><br />
563 RX Antenna Diversity: <select name="antdiv">
564 <option value="3"<?php if($antdiv == 3) echo "selected"; ?>>Auto Selection</option>
565 <option value="0"<?php if($antdiv == 0) echo "selected"; ?>>Antenna near Power</option>
566 <option value="1"<?php if($antdiv == 1) echo "selected"; ?>>Opposite Antenna</option>
567 </select><br />
568 TX Antenna Diversity: <select name="txant">
569 <option value="3"<?php if($txant == 3) echo "selected"; ?>>Use RX Selection</option>
570 <option value="0"<?php if($txant == 0) echo "selected"; ?>>Antenna near Power</option>
571 <option value="1"<?php if($txant == 1) echo "selected"; ?>>Opposite Antenna</option>
572 </select><br />
573 TX Power: <input type="text" name="txpwr1" value="<?php echo $txpwr1?>" /> (1-255mW)<br />
574 </div>
575 </div>
576 <div class="tab-page" id="OpenVPN">
577 <div class="tablayout">
578 Certificate Subjects Allowed to Connect:<br />
579 <textarea name="subjects" rows="10" cols="80"><?php echo $subjects."\n"; ?></textarea><br />
580 Connection Requests:<br />
581 <textarea name="connreq" rows="10" cols="80"><?php
582 $lines = explode("\n", trim(`grep "VERIFY SCRIPT OK: depth=0" /tmp/openvpn.log`));
583 foreach($lines as $line)
584 {
585 $bits = explode(",", $line, 2);
586 echo trim($bits['1'])."\n";
587 }
588 ?></textarea>
589 </div>
590 </div>
591 <div class="tab-page" id="SysLog">
592 <div class="tablayout">
593 <textarea name="syslog" rows="23" cols="150"><?php echo trim(`/sbin/logread 2>&1`); ?></textarea>
594 </div>
595 </div>
596 <div class="submitreboot">
597 <input type="submit" class="submit" name="submit" value="Sumit All Changes">
598 <input type="submit" class="submit" name="reboot" value="Reboot">
599 </div>
600 </form>
601 </center>
602 </body>
603 <script type="text/javascript">
604 onLoad();
605 </script>
606 </form>
607 </body>
608 </html>
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.