示例#1
0
function port_save()
{
    $ID = $_POST["ID"];
    $shore = new mysql_shorewall();
    $ip = new IP();
    if (!$ip->isIPAddress($_POST["gateway"])) {
        $_POST["gateway"] = "";
    }
    if (!$ip->isIPAddress($_POST["ipaddr"])) {
        echo "{$_POST["ipaddr"]} -> FALSE\n";
        return;
    }
    if (!preg_match("#(.+?)\\/(.+)#", $_POST["cdir"])) {
        $_POST["cdir"] = "";
    }
    $q = new mysql();
    if (!$q->FIELD_EXISTS("nics_switch", "vlan", "artica_backup")) {
        $sql = "ALTER TABLE `nics_switch` ADD `vlan` smallint( 2 ) NOT NULL,ADD INDEX(`vlan`)";
        $q->QUERY_SQL($sql, 'artica_backup');
    }
    if (!$q->FIELD_EXISTS("nics_switch", "netzone", "artica_backup")) {
        $sql = "ALTER TABLE `nics_switch` ADD `netzone` VARCHAR( 10 ) NOT NULL,ADD UNIQUE KEY `netzone` (`netzone`)";
        $q->QUERY_SQL($sql, 'artica_backup');
    }
    if ($_POST["netzone"] == null) {
        echo "Network Zone must be defined\n";
        return;
    }
    if ($_POST["netzone"] != null) {
        if (strlen($_POST["netzone"]) > 5) {
            echo "NetZone {$_POST["netzone"]} at most 5 characters long\n";
            return;
        }
        if (is_numeric(substr($_POST["netzone"], 0, 1))) {
            echo "Network Zone Must start with a letter\n";
            return;
        }
        if ($ID == 0) {
            $ligne = @mysql_fetch_array($q->QUERY_SQL("SELECT netzone FROM nics_switch WHERE netzone='{$_POST["netzone"]}'", "artica_backup"));
            if ($ligne["netzone"] != null) {
                echo "Network Zone {$ligne["netzone"]} already defined\n";
                return;
            }
        }
    }
    if ($_POST["netzone"] == null) {
        if ($ID > 0) {
            $_POST["netzone"] = "virt{$ID}";
        }
    }
    $sql = "INSERT INTO nics_switch (`nic`,`netzone`, `ipaddr`,`netmask`,`cdir`,`gateway`,`metric`,`port`,`vlan`) \n\tVALUES\n\t('{$_POST["nic"]}','{$_POST["netzone"]}','{$_POST["ipaddr"]}','{$_POST["netmask"]}','{$_POST["cdir"]}',\n\t'{$_POST["gateway"]}','{$_POST["metric"]}','{$_POST["port"]}','{$_POST["vlan"]}')";
    $sql_edit = "UPDATE nics_switch SET `nic`='{$_POST["nic"]}',\n\t`ipaddr`='{$_POST["ipaddr"]}',\n\t`netzone`='{$_POST["netzone"]}',\n\t`netmask`='{$_POST["netmask"]}',\n\t`cdir`='{$_POST["cdir"]}',\n\t`gateway`='{$_POST["gateway"]}',\n\t`port`='{$_POST["port"]}',\n\t`vlan`='{$_POST["vlan"]}',\n\t`metric`='{$_POST["metric"]}' WHERE ID='{$_POST["ID"]}'";
    if ($_POST["ID"] > 0) {
        $sql = $sql_edit;
    }
    $q->QUERY_SQL($sql, "artica_backup");
    if (!$q->ok) {
        echo $q->mysql_error;
        return;
    }
    if ($_POST["netzone"] == null) {
        $_POST["netzone"] = "virt{$q->last_id}";
        $q->QUERY_SQL("UPDATE nics_switch SET netzone='{$_POST["netzone"]}' WHERE ID={$q->last_id}");
    }
    if ($_POST["ID"] > 0) {
        $shore->NIC_UPDATE("virt{$_POST["ID"]}");
    } else {
        $shore->NIC_UPDATE("virt{$q->last_id}");
    }
    if ($_POST["ID"] > 0) {
        $ID = $_POST["ID"];
    } else {
        $ID = $q->last_id;
    }
    $sock = new sockets();
    $sock->getFrameWork("vde.php?port-reconfigure={$ID}");
}