summaryrefslogtreecommitdiff
path: root/polux/application/boa/spc200/cgi-bin/changeIP.html
diff options
context:
space:
mode:
Diffstat (limited to 'polux/application/boa/spc200/cgi-bin/changeIP.html')
-rwxr-xr-xpolux/application/boa/spc200/cgi-bin/changeIP.html316
1 files changed, 316 insertions, 0 deletions
diff --git a/polux/application/boa/spc200/cgi-bin/changeIP.html b/polux/application/boa/spc200/cgi-bin/changeIP.html
new file mode 100755
index 0000000000..10a4d5699e
--- /dev/null
+++ b/polux/application/boa/spc200/cgi-bin/changeIP.html
@@ -0,0 +1,316 @@
+#!/bin/uphp
+<?php
+function add_gateway($c_counter,$gat_string){
+ $i=0;
+ do {
+ if ($i==$c_counter){
+ $help=linije[$c_counter+1];
+ linije[$c_counter+1]=$gat_string;
+ for ($k=$c;$k>$c_counter+1;$k--){
+ linije[$k+1]=linije[$k];
+ }
+ $linije[$c_counter+2]=$help;
+ }
+ $i++;
+ } while ($i<$c);
+ $c=$c+1;
+}
+
+function take_IPb($a){
+ $filet=popen('/sbin/ifconfig br0|grep "inet ad"',"r");
+ $l=fgets($filet);
+ pclose($filet);
+ if(ereg("([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})",$l,$reg)) {
+ $IPb1=$reg[1];
+ $IPb2=$reg[2];
+ $IPb3=$reg[3];
+ $IPb4=$reg[4];
+ $IPb="$IPb1".".$IPb2".".$IPb3".".$IPb4";
+ }
+}
+
+
+//Checking whether DHCP is ON
+$dhcp=0;
+filet=popen("ps","r");
+while(!feof(filet)) {
+l=fgets(filet);
+if(ereg("dhcpc",l,reg)) $dhcp=1;
+}
+pclose(filet);
+
+// Setting up the variables
+c=0;
+$ge_flag=0;
+$gp_flag=0;
+$gb_flag=0;
+$gb_space=0;
+
+//If gateway fields are empty set appropriate flags to 2
+if (empty($gtewaye1) || empty($gtewaye2) || empty($gtewaye3) || empty($gtewaye4)) $ge_flag=2;
+if (empty($gtewayp1) || empty($gtewayp2) || empty($gtewayp3) || empty($gtewayp4)) $gp_flag=2;
+if (empty($gtewayb1) || empty($gtewayb2) || empty($gtewayb3) || empty($gtewayb4)) $gb_flag=2;
+
+// counters used to specify the line on which resides netmask
+// On counters+1 gateway field is placed
+$ce_counter=100;$cp_counter=100;$cb_counter=100;
+
+
+//search the structure of 'interface' file
+filet=fopen("/usr/local/etc/network/interfaces","r");
+for(c=0;!feof(filet);c++) {
+ linije[c]=fread(filet);
+ caka=trim(linije[c]);
+ checksx=substr(caka,0,10);
+ if (checksx=="iface "."$choice") {
+ do {
+ c++;
+ linije[c]=fread(filet);
+ caka=trim(linije[c]);
+ check=substr(caka,0,7);
+ if (check=="address") {
+ if ($choice=="eth0")
+ linije[c]=" address $IPe1".".$IPe2".".$IPe3".".$IPe4"."\n";
+ if ($choice=="plc0")
+ linije[c]=" address $IPp1".".$IPp2".".$IPp3".".$IPp4"."\n";
+ if ($choice=="br0 "){
+ linije[c]=" address $IPb1".".$IPb2".".$IPb3".".$IPb4"."\n";
+ $IPb="$IPb1".".$IPb2".".$IPb3".".$IPb4";
+ }
+ }
+ if (check=="netmask") {
+ if ($choice=="eth0") {
+ linije[c]=" netmask $NETe1".".$NETe2".".$NETe3".".$NETe4"."\n";
+ $ce_counter=c;
+ }
+ if ($choice=="plc0") {
+ linije[c]=" netmask $NETp1".".$NETp2".".$NETp3".".$NETp4"."\n";
+ $cp_counter=c;
+ }
+ if ($choice=="br0 ") {
+ linije[c]=" netmask $NETb1".".$NETb2".".$NETb3".".$NETb4"."\n";
+ $cb_counter=c;
+ }
+ $NET="$NETb1".".$NETb2".".$NETb3".".$NETb4";
+ }
+ if (check=="gateway") {
+ if ($choice=="eth0") {
+ if ($ge_flag!=2) {
+ linije[c]=" gateway $gtewaye1".".$gtewaye2".".$gtewaye3".".$gtewaye4"."\n";
+ $ge_flag=1;
+ } else c--;
+ }
+
+ if ($choice=="plc0") {
+ if ($gp_flag!=2) {
+ linije[c]=" gateway $gtewayp1".".$gtewayp2".".$gtewayp3".".$gtewayp4"."\n";
+ $gp_flag=1;
+ } else c--;
+ }
+ if ($choice=="br0 ") {
+ if ($gb_flag!=2){
+ linije[c]=" gateway $gtewayb1".".$gtewayb2".".$gtewayb3".".$gtewayb4"."\n";
+ $gb_flag=1;
+ } else c--;
+ }
+ }
+ } while (!empty(caka));
+ }
+}
+
+if ($gb_flag==0) {
+ $gt_string=" gateway $gtewayb1".".$gtewayb2".".$gtewayb3".".$gtewayb4"."\n";
+ add_gateway($cb_counter, $gt_string);
+}
+
+if ($gp_flag==0) {
+ $gt_string=" gateway $gtewayp1".".$gtewayp2".".$gtewayp3".".$gtewayp4"."\n";
+ add_gateway($cp_counter, $gt_string);
+}
+
+if ($ge_flag==0) {
+ $gt_string=" gateway $gtewaye1".".$gtewaye2".".$gtewaye3".".$gtewaye4"."\n";
+ add_gateway($ce_counter, $gt_string);
+}
+
+fclose(filet);
+
+// Write data to network 'interface' file
+if($dhcp==0){
+$filet=fopen("/usr/local/etc/network/interfaces","w");
+for(i=0;i<$c;i++) {
+ fwrite($filet,linije[i]);
+}
+ fclose($filet);
+};
+
+
+$GT="$gtewayb1".".$gtewayb2".".$gtewayb3".".$gtewayb4";
+// IF dhcp is OFF but is requested to be ON
+if ($dhcp_r=="ON") {
+ if ($dhcp==0){
+ // Getting values for the bridge IP address //
+ $filet=popen("/bin/udhcpc &","r");
+ while(!feof($filet)) {
+ $l=fgets($filet);
+ if(ereg("obtained IP = ([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})",$l,$reg)) {
+ $IPb=$reg[0];
+ $IPb1=$reg[1];
+ $IPb2=$reg[2];
+ $IPb3=$reg[3];
+ $IPb4=$reg[4];
+ $IPb="$IPb1".".$IPb2".".$IPb3".".$IPb4";
+ header("Location: http://$IPb/index.html");
+ die("");
+ }
+ }
+ pclose($filet);
+ }
+}
+
+// If DHCP is ON but requested to be OFF
+if ($dhcp_r=="OFF") {
+ if ($dhcp==1) {
+ system("kill $pdhcp");
+ // take_IPb($dhcp);
+ $IPb=$IPxb;
+ $NET=$Nb;
+ $dhcp=0;
+ $GT=$GTb;
+ }
+}
+
+// IF dhcp is ON
+if ($dhcp_r=="ON") {
+ if ($dhcp==1){
+ // Getting values for the bridge IP address //
+ take_IPb($dhcp);
+ header("Location: http://$IPb/index.html");
+ die("");
+ }
+}
+
+// if bridging was altered
+if (($BRIDGING_r == "OFF" && $BRIDGING == "yes") || ($BRIDGING_r == "ON" && $BRIDGING == "no")) {
+ $filet = fopen("/usr/local/etc/config/network", "r");
+ for ($i = 0; !feof($filet); $i++) {
+ $lines[i] = fgets($filet);
+ $l = trim($lines[i]);
+ if (ereg("BRIDGING", l, $regs)) {
+ if ($BRIDGING_r == "OFF")
+ $lines[i] = "BRIDGING=no\n";
+ else
+ $lines[i] = "BRIDGING=yes\n";
+ }
+ }
+ fclose($filet);
+
+ $filet = fopen("/usr/local/etc/config/network", "w");
+ for ($j = 0; $j < $i; $j++)
+ fwrite($filet, $lines[j]);
+ fclose($filet);
+
+ header("Location: http://$IPb/cgi-bin/message.html?IPb=$IPb");
+ die("");
+}
+
+// Monitoring and control traffic on plc device //
+if ($tc_cont=="ACTIVE"){
+//system("echo $tc_rate $tc_rate_unit >>/usr/share/cgi-bin/temp");
+ system("tc qdisc del dev plc0 root");
+ $string="tc qdisc add dev plc0 root tbf rate $tc_rate".$tc_rate_unit." limit 1m burst 1mbit";
+system("echo $string >>/usr/share/cgi-bin/temp");
+ system("$string");
+ }
+ else if ($tc_cont=="INACTIVE") {
+ system("tc qdisc del dev plc0 root");
+ };
+
+// Monitoring and control traffic on eth0 device //
+if ($etc_cont=="ACTIVE"){
+ system("tc qdisc del dev eth0 root");
+//system("echo $etc_rate $etc_rate_unit >>/usr/share/cgi-bin/temp");
+ $string="tc qdisc add dev eth0 root tbf rate $etc_rate".$etc_rate_unit." limit 1m burst 1mbit";
+system("echo $string >>/usr/share/cgi-bin/temp");
+ system("$string");
+ }
+ else if ($etc_cont=="INACTIVE") {
+ system("tc qdisc del dev eth0 root");
+ };
+
+?>
+<script language="JavaScript1.2">
+function getgoing()
+{
+ var xIP="http://<?php print($IPb); ?>/index.html";
+ top.location=xIP;
+}
+//if (top.frames.length==0)
+//{
+ setTimeout('getgoing()',1000);
+//}
+</script>
+<?php
+
+ //Part of the code dealing with modes of PLC device - MASTER, SLAVE, AD_HOC
+system("echo $modex > /proc/sys/net/plc/mode");
+if ($modex=="MASTER"){
+ system('echo "master" > /proc/sys/net/plc/mode');
+ system('echo "0" > /proc/sys/net/plc/bssid');
+ system('echo " " > /proc/sys/net/plc/preferred_bssid');
+ $modef=fopen("/etc/sysctl.conf","r");
+ i=0;
+ while(!feof($modef)) {
+ l = trim(fread($modef));
+ if(ereg("net.plc.mode[ ]*=[ ]*slave",l,$regs)){
+ linije[i]="net.plc.mode = master\n";
+ } else
+ if(ereg("net.plc.preferred_bssid[]*=[ ]*0",l,$regs)){
+ linije[i]="net.plc.bssid = 0\n";
+ } else linije[i]=l."\n";
+ i++;
+ }
+ filet=fopen("/etc/sysctl.conf","w");
+ for(j=0;j<i-1;j++) {
+ fwrite(filet,linije[j]);
+ }
+ fclose(filet);
+}
+
+if ($modex=="SLAVE"){
+ system('echo "slave" > /proc/sys/net/plc/mode');
+ system('echo "0" > /proc/sys/net/plc/preferred_bssid');
+ system('echo " " > /proc/sys/net/plc/bssid');
+ $modef=fopen("/etc/sysctl.conf","r");
+ i=0;
+ while(!feof($modef)) {
+ l = trim(fread($modef));
+ if(ereg("net.plc.mode[ ]*=[ ]*master",l,$regs)){
+ linije[i]="net.plc.mode = slave\n";
+ } else
+ if(ereg("net.plc.bssid[]*=[ ]*0",l,$regs)){
+ linije[i]="net.plc.preferred_bssid = 0\n";
+ } else linije[i]=l."\n";
+ i++;
+ }
+ filet=fopen("/etc/sysctl.conf","w");
+ for(j=0;j<i-1;j++) {
+ fwrite(filet,linije[j]);
+ }
+ fclose(filet);
+ }
+
+if ($modex=="AD-HOC"){
+ system('echo "ad-hoc" > /proc/sys/net/plc/mode');
+}
+if (($choice=="br0 ") && ($dhcp==0)) {
+system('echo "#! /bin/sh" > /usr/share/cgi-bin/execute');
+system('echo "/sbin/ifconfig br0 $IPb netmask $NET &" >> /usr/share/cgi-bin/execute');
+system('echo "/sbin/route add default gw $GT &" >> /usr/share/cgi-bin/execute');
+system("chmod 777 /usr/share/cgi-bin/execute");
+system("/usr/share/cgi-bin/execute &");
+ }
+
+/* Make sure that code below does not get executed when we redirect. */
+?>
+