Exemple #1
0
function restart_eventlog($enable, $new_dev, $wifi_intru, $new_fw)
{
    if ($enable == "1") {
        $param = "-l ";
        $dact = "-x ";
        $dact_mem = "";
        if ($new_dev != "1") {
            $dact_mem = $dact_mem . "NEW_DEVICE";
        }
        if ($wifi_intru != "1") {
            if ($dact_mem != "") {
                $dact_mem = $dact_mem . ",";
            }
            $dact_mem = $dact_mem . "WIFI_INTRU";
        }
        if ($new_fw != "1") {
            if ($dact_mem != "") {
                $dact_mem = $dact_mem . ",";
            }
            $dact_mem = $dact_mem . "NEW_FW";
        }
        if ($dact_mem != "") {
            $param = $param . $dact . $dact_mem;
        }
        startcmd("mydlinkeventd " . $param . " &\n");
    }
    stopcmd("killall mydlinkeventd\n");
}
Exemple #2
0
function netbios_setup($name)
{
    $infp = XNODE_getpathbytarget("", "inf", "uid", $name, 0);
    $stsp = XNODE_getpathbytarget("/runtime", "inf", "uid", $name, 0);
    if ($infp == "" || $stsp == "") {
        SHELL_info($_GLOBALS["START"], "infsvcs_setup: (" . $name . ") not exist.");
        SHELL_info($_GLOBALS["STOP"], "infsvcs_setup: (" . $name . ") not exist.");
        return;
    }
    $addrtype = query($stsp . "/inet/addrtype");
    $ipaddr = query($stsp . "/inet/ipv4/ipaddr");
    $devnam = query($stsp . "/devnam");
    $hostname = query("device/hostname");
    startcmd("hostname " . $hostname . "\n");
    if ($ipaddr == "" || $devnam == "") {
        return;
    }
    if ($addrtype == "ipv4" || $addrtype == "ipv6") {
        //jef add +   for support use shareport.local to access shareportmobile
        $web_file_access = query("/webaccess/enable");
        if ($web_file_access == 1) {
            startcmd("netbios -i " . $devnam . " -r " . $hostname . " -r shareport.local -r shareport &\n");
            startcmd("llmnresp -i " . $devnam . " -r " . $hostname . "  -r shareport.local -r shareport &\n");
        } else {
            //jef add -
            startcmd("netbios -i " . $devnam . " -r " . $hostname . " &\n");
            startcmd("llmnresp -i " . $devnam . " -r " . $hostname . " &\n");
        }
        stopcmd("killall netbios");
        stopcmd("killall llmnresp");
    }
}
Exemple #3
0
function dhcpc6setup($inf)
{
    $hlp = "/var/servd/" . $inf . "-dhcp6c.sh";
    $pid = "/var/servd/" . $inf . "-dhcp6c.pid";
    $cfg = "/var/servd/" . $inf . "-dhcp6c.cfg";
    /* DHCP over PPP session ? */
    //$previnf = XNODE_get_var($inf."_PREVINF");
    //XNODE_del_var($inf."_PREVINF");
    $infp = XNODE_getpathbytarget("", "inf", "uid", $inf, 0);
    $previnf = query($infp . "/infprevious");
    $phyinf = query($infp . "/phyinf");
    $inet = query($infp . "/inet");
    $inetp = XNODE_getpathbytarget("/inet", "entry", "uid", $inet, 0);
    $devnam = PHYINF_getifname($phyinf);
    /* dslite ? */
    $nextinf = query($infp . "/infnext");
    //if ($mode=="PPPDHCP" && $_GLOBALS["PREVINF"]!="")
    //msg("mode is ".$mode.", previnf is ".$previnf);
    startcmd('# dhcpc6setup(' . $inf . ',' . $inetp . ')');
    startcmd("previnf is " . $previnf . ", nextinf is " . $nextinf);
    //if ($mode=="PPPDHCP" && $previnf!="")
    //{
    //	$pppdev = PHYINF_getruntimeifname($previnf);
    //	if ($pppdev=="") return error("no PPP device.");
    //}
    /* Gererate DHCP-IAID from 32-bit of mac address*/
    $mac = PHYINF_getphymac($inf);
    $mac1 = cut($mac, 3, ":");
    $mac2 = cut($mac, 0, ":");
    $mac3 = cut($mac, 1, ":");
    $mac4 = cut($mac, 2, ":");
    $iaidstr = $mac1 . $mac2 . $mac3 . $mac4;
    $iaid = strtoul($iaidstr, 16);
    /* Generate configuration file. */
    $send = "\tinformation-only;\n";
    $idas = "";
    //if($mode=="PPPDHCP") $dname = $pppdev;
    //else $dname = $devnam;
    $dname = $devnam;
    $nextinfp = XNODE_getpathbytarget("", "inf", "uid", $nextinf, 0);
    $nextinet = query($nextinfp . "/inet");
    $nextinetp = XNODE_getpathbytarget("inet", "entry", "uid", $nextinet, 0);
    $nextmode = query($nextinetp . "/ipv4/ipv4in6/mode");
    if ($nextinf != "" && $nextmode == "dslite") {
        $rqstmsg = "\trequest aftr-server-domain-name;\n";
    } else {
        $rqstmsg = "";
    }
    fwrite(w, $cfg, "interface " . $dname . " {\n" . $send . $rqstmsg . "\tscript \"" . $hlp . "\";\n" . "};\n" . $idas);
    /* generate callback script */
    fwrite(w, $hlp, "#!/bin/sh\n" . "phpsh /etc/services/INET/inet6_dhcpc_helper.php" . " INF=" . $inf . " MODE=INFOONLY" . " DEVNAM=" . $dname . " GATEWAY=" . "" . " DHCPOPT=" . "" . ' "NAMESERVERS=$new_domain_name_servers"' . ' "NEW_ADDR=$new_addr"' . ' "NEW_PD_PREFIX=$new_pd_prefix"' . ' "NEW_PD_PLEN=$new_pd_plen"' . ' "DNS=' . "" . '"' . ' "NEW_AFTR_NAME=$new_aftr_name"' . ' "NTPSERVER=$new_ntp_servers"' . "\n");
    /* Start DHCP client */
    startcmd("chmod +x " . $hlp);
    //if ($pppdev=="")
    startcmd("dhcp6c -c " . $cfg . " -p " . $pid . " -t LL " . $devnam);
    //else startcmd("dhcp6c -c ".$cfg." -p ".$pid." -t LL -o ".$devnam." ".$pppdev);
    stopcmd("/etc/scripts/killpid.sh /var/servd/" . $inf . "-dhcp6c.pid");
}
Exemple #4
0
function phyinf_setmedia($layout, $ifname, $media)
{
    /* Only support for WAN port now. CONFIG_WAN_AT_P4=y */
    $port = query("/device/router/wanindex");
    if ($port == "") {
        if ($layout == "1W1L" && $ifname == "ETH-2") {
            $port = 4;
        } else {
            if ($layout == "1W2L" && $ifname == "ETH-3") {
                $port = 4;
            } else {
                return;
            }
        }
    }
    if ($media == "") {
        $media = "AUTO";
    }
    startcmd("slinktype -i " . $port . " -d " . $media);
    stopcmd("slinktype -i " . $port . " -d AUTO");
    startcmd("sleep 1");
}
Exemple #5
0
function phyinf_setmedia($layout, $ifname, $media)
{
    /* Only support for WAN port now. */
    $wanindex = query("/device/router/wanindex");
    if ($wanindex == "") {
        TRACE_error("you do not assigned /device/router/wanindex using default 0\n");
        $wanindex = 0;
    }
    if ($layout == "1W1L" && $ifname == "ETH-2") {
        $port = $wanindex;
    } else {
        if ($layout == "1W2L" && $ifname == "ETH-3") {
            $port = $wanindex;
        } else {
            return;
        }
    }
    if ($media == "") {
        $media = "AUTO";
    }
    startcmd("slinktype -i " . $port . " -d " . $media);
    stopcmd("slinktype -i " . $port . " -d AUTO");
    startcmd("sleep 1");
}
Exemple #6
0
<?php

include "/htdocs/phplib/trace.php";
include "/htdocs/phplib/xnode.php";
function startcmd($cmd)
{
    fwrite(a, $_GLOBALS["START"], $cmd . "\n");
}
function stopcmd($cmd)
{
    fwrite(a, $_GLOBALS["STOP"], $cmd . "\n");
}
fwrite(w, $_GLOBALS["START"], "#!/bin/sh\n");
fwrite(w, $_GLOBALS["STOP"], "#!/bin/sh\n");
startcmd("service UPNPAV start");
startcmd("service ITUNES start");
startcmd("service SAMBA start");
stopcmd("service UPNPAV stop");
stopcmd("service ITUNES stop");
stopcmd("service SAMBA stop");
Exemple #7
0
function error($errno)
{
    startcmd("exit " . $errno);
    stopcmd("exit " . $errno);
}
Exemple #8
0
<?php

include "/htdocs/phplib/xnode.php";
function startcmd($cmd)
{
    fwrite(a, $_GLOBALS["START"], $cmd . "\n");
}
function stopcmd($cmd)
{
    fwrite(a, $_GLOBALS["STOP"], $cmd . "\n");
}
fwrite("w", $START, "#!/bin/sh\n");
fwrite("w", $STOP, "#!/bin/sh\n");
$http_forward = query("/miiicasa/http_forward");
if ($http_forward == "1") {
    //miiicasa agent will use miiicasa.cgi to update information, so
    //we just enable miiicasa agent
    startcmd("/usr/sbin/miiicasa_agent &\n");
    stopcmd("killall miiicasa_agent\n");
} else {
    //if miiicasa agent is disabled, we need to update information by ourself
    startcmd("/usr/sbin/miiicasa.cgi -action update_status noretry &\n");
}
Exemple #9
0
function phyinf_setup($ifname)
{
    $phyinf = XNODE_getpathbytarget("", "phyinf", "uid", $ifname, 0);
    if ($phyinf == "") {
        error("9");
        return;
    }
    if (query($phyinf . "/active") != "1") {
        error("8");
        return;
    }
    /* Set media */
    $media = query($phyinf . "/media/linktype");
    if ($media == "") {
        $media = "AUTO";
    }
    phyinf_setmedia($mode, $ifname, $media);
    startcmd("# PHYINF." . $ifname . ": media=" . $media . ", VID=" . $vid);
    /* Set IPv6 */
    if (isfile("/proc/net/if_inet6") == 1) {
        /* IPv6 is disabled by default (we modified the kernel code).
         * Enable IPv6 here. */
        $dev = PHYINF_getifname($ifname);
        if ($dev != "") {
            startcmd("echo 0 > /proc/sys/net/ipv6/conf/" . $dev . "/disable_ipv6");
            stopcmd("echo 1 > /proc/sys/net/ipv6/conf/" . $dev . "/disable_ipv6");
        }
    }
    /* Set the MAC address */
    $stsp = XNODE_getpathbytarget("/runtime", "phyinf", "uid", $ifname, 0);
    if ($stsp == "") {
        /* The LAYOUT service should be start before PHYINF.XXX.
         * We should never reach here !! */
        fwrite("w", "/dev/console", "PHYINF: The LAYOUT service should be start before PHYINF !!!\n");
    } else {
        $mac = query($phyinf . "/macaddr");
        if ($mac == "") {
            $mac = XNODE_get_var("MACADDR_" . $ifname);
        }
        $mac = tolower($mac);
        $curr = tolower(query($stsp . "/macaddr"));
        startcmd("# MAC: currrent " . $curr . ", target " . $mac);
        if ($mac != $curr) {
            SHELL_info($_GLOBALS["START"], "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n" . "!!! Bad MAC address. Device may work abnormally. !!!\n" . "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
        }
    }
}
Exemple #10
0
function inet_ipv4_dslite($inf, $ifname, $inet, $inetp, $infprev)
{
    startcmd("# inet_start_ipv4_dslite(" . $inf . "," . $ifname . "," . $inet . "," . $inetp . "," . $infprev . ")");
    startcmd("echo \$\$ > /var/run/dslite_start.pid");
    /* Get INET setting */
    $b4addr = query($inetp . "/ipv4/ipaddr");
    anchor($inetp . "/ipv4/ipv4in6");
    $remote = query("remote");
    $stsp = XNODE_getpathbytarget("/runtime", "inf", "uid", $inf, 0);
    if ($b4addr != "") {
        set($stsp . "/inet/ipv4/ipaddr", $b4addr);
    } else {
        set($stsp . "/inet/ipv4/ipaddr", "");
    }
    $devnam = "ip4ip6." . $inf;
    //if($local!="")  $lcmd = " local ".$local;
    $mtu = query($inetp . "/ipv4/mtu");
    if ($mtu == "") {
        $mtu = 1452;
    }
    set($stsp . "/inet/ipv4/mtu", $mtu);
    if ($remote != "") {
        if ($infprev != "") {
            $local = INF_getcurripaddr($infprev);
            if ($local != "") {
                $lcmd = " local " . $local;
            }
        }
        $rcmd = " remote " . $remote;
        startcmd("ip -6 tunnel add " . $devnam . " mode ip4ip6" . $rcmd . $lcmd);
        set($stsp . "/inet/ipv4/ipv4in6/remote", $remote);
        startcmd("ip link set dev " . $devnam . " up");
        if ($b4addr != "") {
            startcmd("ip -4 addr add " . $b4addr . " dev " . $devnam);
        }
        startcmd("ip route add default dev " . $devnam);
        $uptime = query("/runtime/device/uptime");
        set($stsp . "/inet/uptime", query("/runtime/device/uptime"));
        set($stsp . "/inet/ipv4/valid", "1");
        startcmd("event " . $inf . ".UP");
        startcmd("echo 1 > /var/run/" . $inf . ".UP");
        stopcmd("ip -6 tunnel del " . $devnam);
        stopcmd("ip route del default dev " . $devnam);
        stopcmd("xmldbc -s " . $stsp . "/inet/ipv4/valid 0");
        stopcmd("event " . $inf . ".DOWN");
        stopcmd("rm -f /var/run/" . $inf . ".UP");
    } else {
        /* Get the IPv6 address of the previous interface */
        if ($infprev != "") {
            $local = INF_getcurripaddr($infprev);
            if ($local != "") {
                $lcmd = " local " . $local;
            }
            $prevstsp = XNODE_getpathbytarget("/runtime", "inf", "uid", $infprev, 0);
            $remote = query($prevstsp . "/inet/ipv4/ipv4in6/remote");
            startcmd("sip=`gethostip -6 " . $remote . "`");
            /* check if remote is acquired */
            startcmd("if [ \"{$remote}\" == \"\" ]; then");
            startcmd("\tsleep 1");
            startcmd("\tremote=`xmldbc -w " . $prevstsp . "/inet/ipv4/ipv4in6/remote`");
            startcmd("\twhile [ \"{$remote}\" == \"\" ]; do");
            startcmd("\t\tsleep 1");
            startcmd("\t\tremote=`xmldbc -w " . $prevstsp . "/inet/ipv4/ipv4in6/remote`");
            startcmd("\tdone");
            startcmd("\tsip=`gethostip -6 {$remote}`");
            startcmd("fi");
            //startcmd("sip=`gethostip -6 ".$remote."`");
        }
        startcmd("b4addr=`xmldbc -w " . $inetp . "/ipv4/ipaddr`");
        startcmd("if [ \"{$sip}\" != \"\" ]; then");
        startcmd("\tip -6 tunnel add " . $devnam . " mode ip4ip6 remote {$sip}" . $lcmd);
        startcmd("\txmldbc -s " . $stsp . "/inet/ipv4/ipv4in6/remote {$sip}");
        startcmd("\tip link set dev " . $devnam . " up");
        startcmd("\tif [ \"{$b4addr}\" != \"\" ]; then");
        startcmd("\t\tip -4 addr add {$b4addr} dev " . $devnam);
        startcmd("\tfi");
        startcmd("\tip route add default dev " . $devnam);
        $uptime = query("/runtime/device/uptime");
        startcmd("\txmldbc -s " . $stsp . "/inet/uptime " . $uptime);
        startcmd("\txmldbc -s " . $stsp . "/inet/ipv4/valid 1");
        startcmd("\tevent " . $inf . ".UP");
        startcmd("\techo 1 > /var/run/" . $inf . ".UP");
        startcmd("else");
        startcmd("\techo Cannot resolve aftr server name > /dev/console");
        startcmd("\txmldbc -s " . $stsp . "/inet/ipv4/valid 0");
        startcmd("fi");
        /* Start script */
        /*
        startcmd("phpsh /etc/scripts/IPV4.INET.php ACTION=ATTACH".
        	" STATIC=1".
        	" INF=".$inf.
        	" DEVNAM=".$ifname.
        	" IPADDR=".$ipaddr.
        	" MASK=".$mask.
        	" GATEWAY=".$gw.
        	" MTU=".$mtu.
        	' "DNS='.$dns.'"'
        );
        */
        //startcmd("event ".$inf.".UP");
        //startcmd("echo 1 > /var/run/".$inf.".UP");
        //startcmd("fi");
        /* Stop script */
        stopcmd("if [ -e /var/run/" . $inf . ".UP ]; then");
        stopcmd("\tip -6 tunnel del " . $devnam);
        stopcmd("\tip route del default dev " . $devnam);
        stopcmd("\txmldbc -s " . $stsp . "/inet/ipv4/valid 0");
        stopcmd("\tevent " . $inf . ".DOWN");
        stopcmd("\trm -f /var/run/" . $inf . ".UP");
        stopcmd("fi");
        //stopcmd("phpsh /etc/scripts/IPV4.INET.php ACTION=DETACH INF=".$inf);
    }
    stopcmd("if [ -f /var/run/dslite_start.pid ]; then");
    stopcmd("\tpid=`pfile -f /var/run/dslite_start.pid`");
    stopcmd("\t[ \"{$pid}\" != \"0\" ] && kill {$pid} > /dev/console 2>&1");
    stopcmd("\trm -rf /var/run/dslite_start.pid");
    stopcmd("fi");
}
Exemple #11
0
<?php

include "/htdocs/phplib/trace.php";
include "/htdocs/phplib/xnode.php";
function startcmd($cmd)
{
    fwrite(a, $_GLOBALS["START"], $cmd . "\n");
}
function stopcmd($cmd)
{
    fwrite(a, $_GLOBALS["STOP"], $cmd . "\n");
}
fwrite(w, $_GLOBALS["START"], "#!/bin/sh\n");
fwrite(w, $_GLOBALS["STOP"], "#!/bin/sh\n");
stopcmd("service UPNPAV stop");
stopcmd("service ITUNES stop");
stopcmd("service NETATALK stop");
stopcmd("service SAMBA stop");
//startcmd("phpsh /etc/scripts/webaccess_map.php");
stopcmd("service WEBACCESS stop");
startcmd("service UPNPAV start");
startcmd("service ITUNES start");
startcmd("service NETATALK start");
startcmd("service SAMBA start");
/* when usb mount/umount need to update web file access map table, UI don't need */
startcmd("phpsh /etc/scripts/webaccess_map.php");
startcmd("service WEBACCESS start");
Exemple #12
0
function ifinetsetupall($prefix)
{
    $i = 1;
    while ($i > 0) {
        $ifname = $prefix . "-" . $i;
        startcmd('# ' . $ifname);
        stopcmd('# ' . $ifname);
        fwrite("a", $_GLOBALS["START"], "rm -f /var/run/" . $ifname . ".UP\n");
        $ifpath = XNODE_getpathbytarget("", "inf", "uid", $ifname, 0);
        if ($ifpath == "") {
            $i = 0;
            break;
        }
        /* If this INF has previous, do not start it now,
         * the previous interface will bring it up. */
        if (query($ifpath . "/infprevious") == "") {
            ifinetsetup($ifname, $ifpath);
        }
        $i++;
    }
}
Exemple #13
0
function layout_router($mode)
{
    SHELL_info($START, "LAYOUT: Start router layout ...");
    $Wan_index_number = query("/device/router/wanindex");
    /* Start .......................................................................... */
    /* Config RTL8367 as router mode layout. (1 WAN + 4 LAN) */
    setup_switch("router");
    //+++ hendry, for wifi topology
    $p = XNODE_getpathbytarget("", "phyinf", "uid", "ETH-1", 0);
    set($p . "/bridge/ports/entry:1/uid", "MBR-1");
    set($p . "/bridge/ports/entry:1/phyinf", "BAND24G-1.1");
    set($p . "/bridge/ports/entry:2/uid", "MBR-2");
    set($p . "/bridge/ports/entry:2/phyinf", "BAND5G-1.1");
    $p = XNODE_getpathbytarget("", "phyinf", "uid", "ETH-2", 0);
    set($p . "/bridge/ports/entry:1/uid", "MBR-1");
    set($p . "/bridge/ports/entry:1/phyinf", "BAND24G-1.2");
    set($p . "/bridge/ports/entry:2/uid", "MBR-2");
    set($p . "/bridge/ports/entry:2/phyinf", "BAND5G-1.2");
    //--- hendry
    /* Setup MAC address */
    $wanmac = PHYINF_getmacsetting("WAN-1");
    $lanmac = PHYINF_getmacsetting("LAN-1");
    setup_vlaninf("eth2", "1", $lanmac);
    setup_vlaninf("eth2", "2", $wanmac);
    /* set smaller tx queue len */
    startcmd("ifconfig eth2 txqueuelen 200");
    /* Create bridge interface. */
    startcmd("brctl addbr br0; brctl stp br0 off; brctl setfd br0 0");
    startcmd("brctl addif br0 eth2.1");
    //startcmd("brctl addif br0 wifig0");
    //startcmd("brctl addif br0 wifig0.1");
    startcmd("ip link set br0 up");
    if ($mode == "1W2L") {
        startcmd("brctl addbr br1; brctl stp br1 off; brctl setfd br1 0");
        //hendry, we let guestzone to bring br1 up
        //startcmd("ip link set br1 up");;
    }
    /* Setup the runtime nodes. */
    if ($mode == "1W1L") {
        PHYINF_setup("ETH-1", "eth", "br0");
        PHYINF_setup("ETH-2", "eth", "eth2.2");
        /* set Service Alias */
        startcmd('service PHYINF.ETH-1 alias PHYINF.LAN-1');
        startcmd('service PHYINF.ETH-2 alias PHYINF.WAN-1');
        /* WAN: set extension nodes for linkstatus */
        $path = XNODE_getpathbytarget("/runtime", "phyinf", "uid", "ETH-2", 0);
        startcmd('xmldbc -x ' . $path . '/linkstatus "get:psts -i ' . $Wan_index_number . '"');
    } else {
        if ($mode == "1W2L") {
            PHYINF_setup("ETH-1", "eth", "br0");
            PHYINF_setup("ETH-2", "eth", "br1");
            PHYINF_setup("ETH-3", "eth", "eth2.2");
            /* set Service Alias */
            startcmd('service PHYINF.ETH-1 alias PHYINF.LAN-1');
            startcmd('service PHYINF.ETH-2 alias PHYINF.LAN-2');
            startcmd('service PHYINF.ETH-3 alias PHYINF.WAN-1');
            /* WAN: set extension nodes for linkstatus */
            $path = XNODE_getpathbytarget("/runtime", "phyinf", "uid", "ETH-3", 0);
            startcmd('xmldbc -x ' . $path . '/linkstatus "get:psts -i ' . $Wan_index_number . '"');
        }
    }
    //+++ hendry
    $p = XNODE_getpathbytarget("/runtime", "phyinf", "uid", "ETH-1", 0);
    add($p . "/bridge/port", "BAND24G-1.1");
    add($p . "/bridge/port", "BAND5G-1.1");
    $p = XNODE_getpathbytarget("/runtime", "phyinf", "uid", "ETH-2", 0);
    add($p . "/bridge/port", "BAND24G-1.2");
    add($p . "/bridge/port", "BAND5G-1.2");
    //--- hendry
    /* LAN: set extension nodes for linkstatus */
    $path = XNODE_getpathbytarget("/runtime", "phyinf", "uid", "ETH-1", 0);
    startcmd('xmldbc -x ' . $path . '/linkstatus:1 "get:psts -i 4"');
    startcmd('xmldbc -x ' . $path . '/linkstatus:2 "get:psts -i 3"');
    startcmd('xmldbc -x ' . $path . '/linkstatus:3 "get:psts -i 2"');
    startcmd('xmldbc -x ' . $path . '/linkstatus:4 "get:psts -i 1"');
    /* Done */
    startcmd("xmldbc -s /runtime/device/layout router");
    startcmd("xmldbc -s /runtime/device/router/mode " . $mode);
    startcmd("usockc /var/gpio_ctrl ROUTER");
    startcmd("service PHYINF.ETH-1 start");
    startcmd("service PHYINF.ETH-2 start");
    if ($mode == "1W2L") {
        startcmd("service PHYINF.ETH-3 start");
    }
    /* Stop ........................................................................... */
    SHELL_info($STOP, "LAYOUT: Stop router layout ...");
    if ($mode == "1W2L") {
        stopcmd("service PHYINF.ETH-3 stop");
        stopcmd('service PHYINF.LAN-2 delete');
    }
    stopcmd("service PHYINF.ETH-2 stop");
    stopcmd("service PHYINF.ETH-1 stop");
    stopcmd('service PHYINF.WAN-1 delete');
    stopcmd('service PHYINF.LAN-1 delete');
    stopcmd('xmldbc -s /runtime/device/layout ""');
    stopcmd('/etc/scripts/delpathbytarget.sh /runtime phyinf uid ETH-1');
    stopcmd('/etc/scripts/delpathbytarget.sh /runtime phyinf uid ETH-2');
    stopcmd('/etc/scripts/delpathbytarget.sh /runtime phyinf uid ETH-3');
    //stopcmd('brctl delif br0 wifig0');
    stopcmd('brctl delif br0 eth2.1');
    //stopcmd('brctl delif br1 wifig0.1');
    stopcmd('ip link set eth2.1 down');
    stopcmd('ip link set eth2.2 down');
    stopcmd('brctl delbr br0; brctl delbr br1');
    stopcmd('vconfig rem eth2.1; vconfig rem eth2.2');
    return 0;
}
Exemple #14
0
if ($lanif == "") {
    $lanif = "br0";
}
$proxyd_port = "48723";
$config_file = "/var/run/miiicasa_proxyd.conf";
fwrite("w", $config_file, "CONTROL\n{\n");
fwrite("a", $config_file, "\tTIMEOUT_CONNECT\t120\n");
fwrite("a", $config_file, "\tTIMEOUT_READ\t120\n");
fwrite("a", $config_file, "\tTIMEOUT_WRITE\t120\n");
fwrite("a", $config_file, "\tMAX_CLIENT\t128\n");
fwrite("a", $config_file, "}\n\n");
fwrite("a", $config_file, "HTTP\n{\n");
fwrite("a", $config_file, "\tINTERFACE\t" . $lanif . "\n");
fwrite("a", $config_file, "\tPORT\t" . $proxyd_port . "\n");
fwrite("a", $config_file, "\tALLOW_TYPE\t{ gif jpg css png }\n");
fwrite("a", $config_file, "\tERROR_PAGE\n\t{\n");
fwrite("a", $config_file, "\t\tdefault\t/var/run/blocked.html\n");
fwrite("a", $config_file, "\t\t403\t/var/run/blocked.html\n");
fwrite("a", $config_file, "\t\t404\t/none_exist_file\n");
fwrite("a", $config_file, "\t}\n}\n\n");
$config_url_file = "/var/run/miiicasa_proxyd_url.conf";
fwrite("w", $config_url_file, "0\n");
// Allow to access,
if ($http_forward == "1") {
    startcmd("/usr/sbin/miiicasa_proxyd -f " . $config_file . " -u " . $config_url_file . " & > /dev/console\n");
    startcmd("iptables -t nat -N MIIICASA_PROXYD\n");
    startcmd("iptables -t nat -I PREROUTING -i " . $lanif . " -p tcp ! -d " . $lanip . " --dport 80 -j MIIICASA_PROXYD\n");
    stopcmd("iptables -t nat -D PREROUTING -i " . $lanif . " -p tcp ! -d " . $lanip . " --dport 80 -j MIIICASA_PROXYD\n");
    stopcmd("iptables -t nat -X MIIICASA_PROXYD\n");
    stopcmd("killall miiicasa_proxyd\n");
}
Exemple #15
0
function ipv6_child($child)
{
    /* Get the config */
    $infp = XNODE_getpathbytarget("", "inf", "uid", $child, 0);
    if ($infp == "") {
        echo "# " . $child . " is not found !!!\n";
        return;
    }
    $phyinf = query($infp . "/phyinf");
    $defrt = query($infp . "/defaultroute");
    /* Create the runtime nodes. */
    $stsp = XNODE_getpathbytarget("/runtime", "inf", "uid", $child, 1);
    set($stsp . "/phyinf", $phyinf);
    set($stsp . "/defaultroute", $defrt);
    /* Get the config. */
    $ipaddr = XNODE_get_var($child . "_IPADDR");
    $prefix = XNODE_get_var($child . "_PREFIX");
    $devnam = PHYINF_getphyinf($child);
    $phyinfv = XNODE_get_var($child . "_PHYINF");
    if ($phyinfv != "") {
        $phyinf = $phyinfv;
        $devnam = PHYINF_getifname($phyinf);
        set($stsp . "/phyinf", $phyinf);
    }
    /* Get dhcp-pd config. */
    $pdnetwork = XNODE_get_var($child . "_PDNETWORK");
    $pdprefix = XNODE_get_var($child . "_PDPREFIX");
    //$enablepd = query($stsp."/dhcps6/pd/enable");
    echo "# pdnetwork :" . $pdnetwork . "\n";
    echo "# pdprefix :" . $pdprefix . "\n";
    if ($pdnetwork != "" && $pdprefix != "") {
        set($stsp . "/dhcps6/pd/network", $pdnetwork);
        set($stsp . "/dhcps6/pd/prefix", $pdprefix);
    }
    $pdplft = XNODE_get_var($child . "_PDPLFT");
    $pdvlft = XNODE_get_var($child . "_PDVLFT");
    echo "# pdplft :" . $pdplft . "\n";
    echo "# pdvlft :" . $pdvlft . "\n";
    if ($pdplft != "") {
        set($stsp . "/dhcps6/pd/preferlft", $pdplft);
    }
    if ($pdvlft != "") {
        set($stsp . "/dhcps6/pd/validlft", $pdvlft);
    }
    /* Clear the variables. */
    /*
    	XNODE_del_var($child."_IPADDR");
    	XNODE_del_var($child."_PREFIX");
    	XNODE_del_var($child."_ADDRTYPE");
    	XNODE_del_var($child."_PHYINF");
    	XNODE_del_var($child."_PDNETWORK");
    	XNODE_del_var($child."_PDPREFIX");
    	XNODE_del_var($child."_PDPLFT");
    	XNODE_del_var($child."_PDVLFT");
    */
    /* enable IPv6 */
    fwrite(w, "/proc/sys/net/ipv6/conf/" . $devnam . "/disable_ipv6", 0);
    $path_eth = XNODE_getpathbytarget("/runtime", "phyinf", "uid", $phyinf, 0);
    $val_eth = query($path_eth . "/ipv6/link/ipaddr");
    if ($path_eth == "") {
        return;
    } else {
        if ($val_eth != "") {
            stopcmd("phpsh /etc/scripts/IPV6.INET.php ACTION=DETACH INF=" . $child);
            startcmd("phpsh /etc/scripts/IPV6.INET.php ACTION=ATTACH INF=" . $child . " MODE=CHILD DEVNAM=" . $devnam . " IPADDR=" . $ipaddr . " PREFIX=" . $prefix);
        } else {
            return 0;
        }
    }
    /* Start/Stop scripts */
    //stopcmd( "phpsh /etc/scripts/IPV6.INET.php ACTION=DETACH INF=".$child);
    //startcmd("phpsh /etc/scripts/IPV6.INET.php ACTION=ATTACH INF=".$child.
    //			" MODE=CHILD DEVNAM=".$devnam." IPADDR=".$ipaddr." PREFIX=".$prefix);
    /* record */
    stopcmd("rm -f /var/run/CHILD." . $child . ".UP");
    startcmd("echo 1 > /var/run/CHILD." . $child . ".UP");
    /* delay 2s to wait ipv6 address take effect before HTTP service */
    //startcmd("sleep 2");
}
Exemple #16
0
function phyinf_setup($ifname)
{
    $phyinf = XNODE_getpathbytarget("", "phyinf", "uid", $ifname, 0);
    if ($phyinf == "") {
        error("9");
        return;
    }
    if (query($phyinf . "/active") != "1") {
        error("8");
        return;
    }
    /* Get layout mode */
    $layout = query("/runtime/device/layout");
    if ($layout == "bridge") {
        $mode = "1BRIDGE";
    } else {
        if ($layout == "router") {
            $mode = query("/runtime/device/router/mode");
        } else {
            error("10");
            return;
        }
    }
    if ($mode == "") {
        $mode = "1W1L";
    }
    /* Set media */
    $media = query($phyinf . "/media/linktype");
    if ($media == "") {
        $media = "AUTO";
    }
    phyinf_setmedia($mode, $ifname, $media);
    startcmd("# PHYINF." . $ifname . ": media=" . $media . ", VID=" . $vid);
    /* Set IPv6 */
    if (isfile("/proc/net/if_inet6") == 1) {
        if ($layout == "router") {
            /**********************************************************************************
             * only enable ipv6 function at br0(LAN) and eth1(WAN), other disable by default
             *********************************************************************************/
            phyinf_setipv6($mode, $ifname);
        } else {
            $dev = PHYINF_getifname($ifname);
            if ($dev != "") {
                startcmd("echo 0 > /proc/sys/net/ipv6/conf/" . $dev . "/disable_ipv6");
                stopcmd("echo 1 > /proc/sys/net/ipv6/conf/" . $dev . "/disable_ipv6");
            }
        }
    }
    /* Set the MAC address */
    $stsp = XNODE_getpathbytarget("/runtime", "phyinf", "uid", $ifname, 0);
    if ($stsp == "") {
        /* The LAYOUT service should be start before PHYINF.XXX.
         * We should never reach here !! */
        fwrite("w", "/dev/console", "PHYINF: The LAYOUT service should be start before PHYINF !!!\n");
    } else {
        $mac = query($phyinf . "/macaddr");
        if ($mac == "") {
            $mac = XNODE_get_var("MACADDR_" . $ifname);
        }
        $mac = tolower($mac);
        $curr = tolower(query($stsp . "/macaddr"));
        startcmd("# MAC: currrent " . $curr . ", target " . $mac);
        if ($mac != $curr) {
            SHELL_info($_GLOBALS["START"], "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n" . "!!! Bad MAC address. Device may work abnormally. !!!\n" . "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
        }
    }
}