X-Git-Url: http://git.pjr.cc/?p=CBFWR.git;a=blobdiff_plain;f=libcbfwr%2Ffwui.php;h=adc95416a886aa96ab5a9c21287fe547ba1c89eb;hp=fb9ef70262b34f57bb47ecb0438f0dda88894dad;hb=13e5ebe14a18fb0d217fdc6fc4fc786a678889da;hpb=60673f4f00bab805471fcbb85c8816aebb3a9582 diff --git a/libcbfwr/fwui.php b/libcbfwr/fwui.php index fb9ef70..adc9541 100644 --- a/libcbfwr/fwui.php +++ b/libcbfwr/fwui.php @@ -16,12 +16,14 @@ function CBFWZonesPage($urls) $newname = $_REQUEST["zonename"]; $renewname = null; + error_log("comparing \"$oldname\" to \"$newname\""); if($oldname != $newname) { $renewname = " rename $newname"; } - $oldconf = $comms->getConfig(0); + $oldconf = getWebUserConfig(); $olddesc = $oldconf["zone"][$oldname]["description"]; + error_log("Comparing \"$olddesc\" and \"$desc\""); if($desc != $olddesc) { $newdesc = " # $desc"; } else $newdesc = null; @@ -31,6 +33,7 @@ function CBFWZonesPage($urls) if($renewname == null && $newdesc == null) { header("Location: $BASE_URL/zones"); + error_log("no changes?"); return; } @@ -55,15 +58,8 @@ function CBFWZonesPage($urls) case "delete": $zonetodelete = $urls[2]; - - $conf = $comms->getConfig(3); - $changes = $conf["status"]; - if($changes == "nochange") $conf["status"] = 1; - else $conf["status"] = $changes + 1; - $cnum = $conf["status"]; - - $conf[$cnum]["delete"] = "zone $zonetodelete"; - $comms->putConfig($conf, 3); + + addWebUserChange("delete zone name $zonetodelete"); header("Location: $BASE_URL/zones"); break; @@ -71,21 +67,16 @@ function CBFWZonesPage($urls) case "add": // UGLY - $cnum = 0; $nametoadd = $_REQUEST["toadd"]; $desc = $_REQUEST["desc"]; + $descbit = ""; if($desc != "") $descbit = " # $desc"; if($nametoadd == "" || $nametoadd == null) { return; } - $conf = $comms->getConfig(3); - $changes = $conf["status"]; - if($changes == "nochange") $conf["status"] = 1; - else $conf["status"] = $changes + 1; - $cnum = $conf["status"]; - $conf[$cnum]["add"] = "zone $nametoadd$descbit"; - $comms->putConfig($conf, 3); + + addWebUserChange("zone name $nametoadd $descbit"); header("Location: $BASE_URL/zones"); break; @@ -104,12 +95,7 @@ function CBFWZonesEditPage($urls) $zone = $urls[2]; - $comms = new Comms(); - $myconf = new Config(); - - $config = $comms->getConfig(); - $conf2 = $comms->getConfig(3); - $config = $myconf->mergeConfig($config, $conf2); + $config = getWebUserConfig(); echo "

Edit Zone $zone

"; @@ -124,16 +110,67 @@ function CBFWZonesEditPage($urls) echo ""; } -function CBFWZonesPageDisplay() +function addWebUserChange($change) { - global $BASE_URL, $MENU_ITEMS; + $comms = new Comms(); + $myconf = new Config(); + + $conf = $comms->getConfig(3); + + if(!isset($conf["status"])) { + $conf["status"] = "nochange"; + } + + $changes = $conf["status"]; + if($changes == "nochange") $conf["status"] = 1; + else $conf["status"] = $changes + 1; + $cnum = $conf["status"]; + $conf["changes"][$cnum] = "$change"; + $comms->putConfig($conf, 3); + +} + +// TODO: we need to really sit and think about this one +function getWebUserConfig() +{ $comms = new Comms(); $myconf = new Config(); - $config = $comms->getConfig(); + + // check to see if pre-cache config matches change level of config change buffer + $config = $comms->getConfig(5); $conf2 = $comms->getConfig(3); - $config = $myconf->mergeConfig($config, $conf2); + if(isset($config["status"])) { + if($config["status"] == $conf2["status"]) { + // it did, return the pre-cache + error_log("got pre-cache config"); + return $config; + } + } + + // it did not, do a new merge and cache + // TODO: need to do this part + $config = $comms->getConfig(); + $reconfig = $config; + $myconf->setConfig($config); + if(isset($conf2["changes"])) foreach($conf2["changes"] as $key => $var) { + error_log("Adding config line $key, $var"); + $myconf->addConfigLine($var); + } + $reconfig = $myconf->getConfig(); + $reconfig["status"] = $conf2["status"]; + error_log("put pre-cache config"); + $comms->putConfig($reconfig, 5); + + return $reconfig; +} + +function CBFWZonesPageDisplay() +{ + global $BASE_URL, $MENU_ITEMS; + + $config = getWebUserConfig(); echo "

Zones

"; echo ""; @@ -155,6 +192,31 @@ function CBFWZonesPageDisplay() } +function CBFWRoutingPage($urls) +{ + if(isset($urls[1])) { + switch($urls[1]) { + case "edit": + CBFWpageBuilder(null, "CBFWRoutingPageEdit", null, null, $urls[2]); + break; + case "change": + CBFWRoutingChange(); + break; + default: + CBFWpageBuilder(null, "CBFWRoutingPageDisplay"); + } + } else { + error_log("main interface page"); + CBFWpageBuilder(null, "CBFWRoutingPageDisplay"); + } + +} + +function CBFWRoutingPageDisplay() +{ + echo "

Routing

"; +} + function CBFWInterfacesPage($urls) { if(isset($urls[1])) { @@ -179,7 +241,6 @@ function CBFWInterfacesChange() global $BASE_URL, $MENU_ITEMS; $comms = new Comms(); - $comms->sendMessage("interface eth0 changename poof"); header("Location: $BASE_URL/interfaces"); } @@ -188,16 +249,51 @@ function CBFWInterfacesPageEdit($urls) global $BASE_URL, $MENU_ITEMS; $interface = $urls; + $comms = new Comms(); + + $config = getWebUserConfig(); + $boot_config = $comms->getConfig(1); + + if(isset($config["interface"]["dev"]["$interface"]["name"])) $name = $config["interface"]["dev"]["$interface"]["name"]; + else $name = ""; + + $extra2 = ""; + if(file_exists("/sys/class/net/$interface/address")) { + $extra2 = trim(file_get_contents("/sys/class/net/$interface/address")); + } + + $extra = ""; + if(isset($boot_config["hardware"]["netdev"]["$interface"]["hwaddress"])) { + $hwaddr = $boot_config["hardware"]["netdev"]["$interface"]["hwaddress"]; + $extra = " Original address: $hwaddr"; + if($hwaddr != $extra2 && $extra2 != "") { + $extra .= " Current Address: $hwaddr"; + } + } + if(isset($config["interface"]["dev"]["$interface"]["hwaddress"])) $hwaddr = $config["interface"]["dev"]["$interface"]["hwaddress"]; + + if(isset($config["interface"]["dev"]["$interface"]["zone"])) $zone = $config["interface"]["dev"]["$interface"]["zone"]; + + if(isset($config["interface"]["dev"]["$interface"]["address4"])) $ip4 = $config["interface"]["dev"]["$interface"]["address4"]; + + if(isset($config["interface"]["dev"]["$interface"]["address6"])) $ip6 = $config["interface"]["dev"]["$interface"]["address6"]; + + if(isset($boot_config["hardware"]["netdev"]["$interface"]["speed"])) $speed = $boot_config["hardware"]["netdev"]["$interface"]["speed"]; + if(isset($boot_config["hardware"]["netdev"]["$interface"]["duplex"])) $duplex = $boot_config["hardware"]["netdev"]["$interface"]["duplex"]; + if(isset($config["interface"]["dev"]["$interface"]["speed"])) $speed = $config["interface"]["dev"]["$interface"]["speed"]; + if(isset($config["interface"]["dev"]["$interface"]["duplex"])) $duplex = $config["interface"]["dev"]["$interface"]["duplex"]; + echo "

Edit Interface $interface


"; echo ""; echo "
ZoneInterfacesDescriptionEdit
"; - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; echo "
Name
HW Address
Zone
IPv4 Address
IPv6 Address
Speed
Duplex
Name
HW Address$extra
Zone
IPv4 Address
IPv6 Address
Speed
Duplex
"; echo "
"; //echo "Back"; @@ -209,9 +305,16 @@ function CBFWInterfacesPageDisplay() global $BASE_URL, $MENU_ITEMS; $comms = new Comms(); - $config = $comms->getConfig(0); + $config = getWebUserConfig(); $boot_config = $comms->getConfig(1); + // at the top, we put in the creation bits + echo "

Create Interface

"; + echo "
  • Link Aggregation Group (bonded/teamed interfaces)
    "; + echo "
  • VLAN Tagged Sub Interfaces
    "; + echo "
  • Bridged Interfaces
    "; + echo "
    "; + // now build an interface table $table = array(); foreach($boot_config["hardware"]["netdev"] as $key=>$val) { @@ -229,96 +332,207 @@ function CBFWInterfacesPageDisplay() // current mtu if(isset($val["mtu"])) $table[$key]["mtu"] = $val["mtu"]; - } - - foreach($config["hardware"]["netdev"] as $key=>$val) { - $ename = $key; - if(isset($config["interface"]["$key"]["name"])) $table[$key]["name"] = $config["interface"]["$key"]["name"]; - $table[$key]["address4"] = null; - $table[$key]["address6"] = null; - - if(isset($config["interface"][$table[$key]["name"]]["address4"])) { - $table[$key]["address4"] = $config["interface"][$table[$key]["name"]]["address4"]; - } - - if(isset($config["interface"][$table[$key]["name"]]["address6"])) { - $table[$key]["address6"] = $config["interface"][$table[$key]["name"]]["address6"]; - } - if(isset($config["interface"][$table[$key]["name"]]["mtu"])) { - $table[$key]["mtu"] = $config["interface"][$table[$key]["name"]]["mtu"]; - } else { - $table[$key]["mtu"] = "1500"; // TODO: this needs to actually come from somewhere - } - - if(isset($config["interface"][$table[$key]["name"]]["speed"])) { - $table[$key]["speed"] = $config["interface"][$table[$key]["name"]]["speed"]; - } else { - $table[$key]["speed"] = null; - } - - if(isset($config["interface"][$table[$key]["name"]]["duplex"])) { - $table[$key]["duplex"] = $config["interface"][$table[$key]["name"]]["duplex"]; - } else { - $table[$key]["duplex"] = null; - } + // speed + if(isset($val["speed"])) $table[$key]["speed"] = $val["speed"]; + else $table[$key]["speed"] = "default"; - if(isset($config["interface"][$table[$key]["name"]]["zone"])) { - $table[$key]["zone"] = $config["interface"][$table[$key]["name"]]["zone"]; - } else { - $table[$key]["zone"] = null; - } + // duplex + if(isset($val["duplex"])) $table[$key]["duplex"] = $val["duplex"]; + else $table[$key]["duplex"] = "default"; } + foreach($config["interface"]["dev"] as $key => $val) { + // TODO construction zone + error_log("doing $key"); + if(isset($val["name"])) $table[$key]["name"] = $val["name"]; + if(isset($val["address4"])) $table[$key]["address4"] = $val["address4"]; + if(isset($val["address6"])) $table[$key]["address6"] = $val["address6"]; + if(isset($val["description"])) $table[$key]["description"] = $val["description"]; + if(isset($val["zone"])) $table[$key]["zone"] = $val["zone"]; + } + - echo ""; + echo "

    Interfaces

    DeviceZoneTypeMAC AddressAddressMTUSpeed/DuplexControl
    "; foreach($table as $key =>$val) { if($val["realname"] == $val["name"]) $name = $val["name"]; else $name = $val["name"]." (".$val["realname"].")"; // zone - if($val["zone"] == null) $zone = "-"; - else $zone = $val["zone"]; + if(isset($val["zone"])) { + if($val["zone"] == null) $zone = "-"; + else $zone = $val["zone"]; + } else $zone = "-"; // mtu - $mtu = $val["mtu"]; + if(isset($val["mtu"])) { + $mtu = $val["mtu"]; + } else $mtu = "-"; // driver type - $type = $val["type"]; + if(isset($val["type"])) { + $type = $val["type"]; + } else $type = "-"; // hardware address - $mac = $val["hwaddress"]; + if(isset($val["hwaddress"])) { + $mac = $val["hwaddress"]; + } else $mac = "-"; // speed and duplex - if($val["duplex"] == null) $dup = "default"; - else $dup = $val["duplex"]; + if(isset($val["duplex"])) { + if($val["duplex"] == null) $dup = "default"; + else $dup = $val["duplex"]; + } //else $dup = "default"; // TODO: needs to go away in fav of hardware setting - if($val["speed"] == null) $spd = "default"; - else $spd = $val["speed"]; + if(isset($val["speed"])) { + if($val["speed"] == null) $spd = "default"; + else $spd = $val["speed"]; + } //else $spd = "default"; // TODO: needs to go away inf av of hardware setting $spanddu = "$spd/$dup"; // network address - if($val["address4"]!=null && $val["address6"]!=null) { + if(isset($val["address4"]) && isset($val["address6"])) { $address = $val["address4"]."
    ".$val["address6"]; - } else if($val["address4"] != null) { + } else if(isset($val["address4"])) { $address = $val["address4"]; - } else if($val["address6"] != null) { + } else if(isset($val["address6"])) { $address = $val["address6"]; } else { $address = "-"; } - echo ""; + if(isset($val["description"])) $desc = $val["description"]; + else $desc = "-"; + + echo ""; } echo "
    DeviceZoneTypeMAC AddressAddressMTUSpeed/DuplexDescriptionControl
    $name$zone$type$mac$address$mtu$spandduEdit
    $name$zone$type$mac$address$mtu$spanddu$descEdit
    "; + + // to test + echo "config:
    ";
    +	print_r($config);
    +	echo "
    "; } -function CBFWObjectsPage() +function CBFWObjectsPage($urls) { $comms = new Comms(); $config = $comms->getConfig(); + + CBFWpageBuilder(null, "CBFWObjectsDisplay"); +} + +function CBFWObjectsDisplay() +{ + global $BASE_URL, $MENU_ITEMS; + $config = getWebUserConfig(); + + echo "

    Objects

    "; + + if(isset($config["objects"])) { + echo ""; + echo ""; + echo "
    NetworksHostsServicesNetwork GroupsHost GroupsService Groups
    "; + foreach($config["objects"] as $key => $var) { + } + } else { + echo "No objects set\n"; + } + + echo "
    "; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + + + echo "
    "; + echo "

    Create Network


    "; + echo ""; + echo "Name
    "; + echo "IPv4 /
    "; + echo "IPv6 /
    "; + echo ""; + echo ""; + echo "
    "; + echo "

    Create Host


    "; + echo "
    "; + echo "Name
    "; + echo "IPv4
    "; + echo "IPv6
    "; + echo ""; + echo "
    "; + echo "
    "; + echo "

    Service


    "; + echo "
    "; + echo "Name
    "; + echo "Port "; + echo "
    "; + echo ""; + echo "
    "; + echo "
    "; + echo "

    Network Group

    "; + echo "
    "; + echo "Name
    "; + echo "
    "; + echo "
    "; + echo "

    Host Group

    "; + echo "
    "; + echo "Name
    "; + echo "
    "; + echo "
    "; + echo "

    Service Group

    "; + echo "
    "; + echo "Name
    "; + echo "
    "; + echo "
    "; + +} + +function CBFWChangesPage($urls) +{ + global $BASE_URL, $MENU_ITEMS; + + if(isset($urls[1])) { + switch($urls[1]) { + case "show": + CBFWpageBuilder(null, "CBFWChangesDisplay"); + break; + case "delete": + $delete = $urls[2]; + error_log("would delete change $delete"); + header("Location: $BASE_URL/changes/show"); + break; + } + } +} + +function CBFWChangesDisplay() +{ + global $BASE_URL, $MENU_ITEMS; + $comms = new Comms(); + + $config = $comms->getConfig(3); + + echo "

    Changes

    "; + echo "This page shows the changes on the web from the currently running configuration
    "; + if($config["status"] == "nochange") { + echo "There are currently no changes from the running configuraiton."; + } else { + echo ""; + echo ""; + foreach($config["changes"] as $key => $var) { + echo ""; + } + echo "
    Change NoChangeControl
    $key$varDelete
    "; + } } function CBFWRulesPage() @@ -328,6 +542,58 @@ function CBFWRulesPage() $config = $comms->getConfig(); } +function CBFWAdminPage($urls) +{ + $comms = new Comms(); + + $config = $comms->getConfig(); + + CBFWpageBuilder(null, "CBFWAdminDisplay"); +} + +function CBFWAdminDisplay() +{ +?> +

    Administration

    + + + + + +
    +

    Users

    + + + +
    UsernameDescriptionEnabled?
    AdminTwattleYes
    +
    +

    Add User

    +
    +Username
    +Password
    +Description
    +
    +
    +
    +

    Network Access

    + + + +
    FromInterfaceType
    Anytwaddlehttp,https,ssh
    +
    +

    Add Access

    +
    +From
    +Interface +Protocols HTTP HTTPS SSH
    +
    +
    +
    +