function qos_containers_tab() { $tpl = new templates(); $users = new usersMenus(); $page = CurrentPageName(); $fontsize = 18; $ID = $_GET["ID"]; $q = new mysql(); $ligne = mysql_fetch_array($q->QUERY_SQL("SELECT eth FROM `qos_containers` WHERE ID='{$ID}'", "artica_backup")); $eth = $ligne["eth"]; $p = new system_nic(); $eth = $p->NicToOther($eth); $array["container-popup"] = "{Q.O.S} mark {$ID}"; $array["container-status"] = "{status} {$eth}"; $t = time(); while (list($num, $ligne) = each($array)) { $html[] = $tpl->_ENGINE_parse_body("<li><a href=\"{$page}?{$num}={$t}&ID={$ID}ð={$eth}\" style='font-size:{$fontsize};font-weight:normal'><span>{$ligne}</span></a></li>\n"); } $html = build_artica_tabs($html, 'main_qos_eth' . $eth) . "<script>// LeftDesign('qos-256-white.png');</script>"; echo $html; }
function build_qos() { $q = new mysql(); $unix = new unix(); $sock = new sockets(); $tc = $unix->find_program("tc"); if (!is_file($tc)) { return "# tc No such binary"; } $F = array(); $nic = new system_nic(); $F[] = "# Remove rules on any interfaces"; $results = $q->QUERY_SQL("SELECT Interface FROM nics ORDER BY Interface", "artica_backup"); while ($ligne = mysql_fetch_assoc($results)) { $Interface = $ligne["Interface"]; $Interface = $nic->NicToOther($Interface); $INT[$Interface] = $Interface; } while (list($Interface, $ligne) = each($INT)) { $F[] = "{$tc} qdisc del dev {$Interface} root"; } $EnableQOS = intval($sock->GET_INFO("EnableQOS")); if ($EnableQOS == 0) { return @implode("\n", $F); } $results = $q->QUERY_SQL("SELECT Interface,QOSMAX FROM nics WHERE QOS=1 ORDER BY Interface", "artica_backup"); if (mysql_num_rows($results) == 0) { return "# No interface defined for QOS"; } $ID_ROOT = 0; $classid = 0; while ($ligne = mysql_fetch_assoc($results)) { $Interface = $ligne["Interface"]; $results2 = $q->QUERY_SQL("SELECT * FROM qos_containers WHERE enabled=1 AND eth='{$Interface}' ORDER BY prio", "artica_backup"); if (mysql_num_rows($results2) == 0) { $F[] = "# {$Interface} no container defined or enabled"; continue; } $Interface = $nic->NicToOther($Interface); $F[] = "# *********** {$ligne["Interface"]} -> {$Interface} ***********"; $ID_ROOT++; $classid++; $F[] = "# {$Interface} Capacity of {$ligne["QOSMAX"]}Mbits Level {$ID_ROOT}"; $F[] = "{$tc} qdisc add dev {$Interface} root handle {$ID_ROOT}: htb default {$ID_ROOT}00"; $F[] = "{$tc} class add dev {$Interface} parent {$ID_ROOT}:0 classid {$ID_ROOT}:{$classid} htb rate {$ligne["QOSMAX"]}Mbit ceil {$ligne["QOSMAX"]}Mbit"; while ($ligne = mysql_fetch_assoc($results2)) { $id = $ligne["ID"]; $gar = "{$ligne["rate"]}{$ligne["rate_unit"]}"; $band = "{$ligne["ceil"]}{$ligne["ceil_unit"]}"; if (intval($ligne["rate"]) == 0) { $F[] = "# {$Interface}: Container {$ligne["name"]} Guaranteed Rate invalid"; continue; } if (intval($ligne["ceil"]) == 0) { $F[] = "# {$Interface}: Container {$ligne["name"]} Bandwidth invalid"; continue; } $F[] = "# {$Interface}: Container {$ligne["name"]} Guaranteed Rate of {$gar} , Bandwidth of {$band} Level Prio {$ligne["prio"]}"; $F[] = "{$tc} class add dev {$Interface} parent {$ID_ROOT}:{$classid} classid {$classid}:{$id} htb rate {$gar} ceil {$band}"; $F[] = "# {$Interface}: Container {$ligne["name"]} add policy for mark {$id}"; $F[] = "{$tc} filter add dev {$Interface} parent {$ID_ROOT}: protocol ip prio {$ligne["prio"]} handle {$id} fw flowid {$classid}:{$id}"; } } return @implode("\n", $F); }
function routes() { $unix = new unix(); $NetBuilder = new system_nic(); $route = $unix->find_program("route"); $ip = $unix->find_program("ip"); $types[1] = "{network_nic}"; $types[2] = "{host}"; $array = array(); $q = new mysql(); $f = explode("\n", @file_get_contents("/etc/iproute2/rt_tables")); while (list($eth, $ligne) = each($f)) { if (preg_match("#^([0-9]+)\\s+(.+)#", $ligne, $re)) { $tableID = $re[1]; if ($tableID == 255) { continue; } if ($tableID == 254) { continue; } if ($tableID == 253) { continue; } if ($tableID == 0) { continue; } $array[$tableID] = $re[2]; } } if (count($array) > 0) { while (list($id, $ligne) = each($array)) { echo "Starting......: " . date("H:i:s") . " Building routes, flush table `{$ligne}`\n"; shell_exec("{$ip} route flush table {$ligne}"); } } $sql = "SELECT * FROM iproute_table WHERE enable=1 ORDER BY routename"; $results = $q->QUERY_SQL($sql, "artica_backup"); if (!$q->ok) { echo "Starting......: " . date("H:i:s") . " Building routes, {$q->mysql_error}\n"; routes_fromfile(); return; } $rtid = 0; $countOfRoutes = mysql_num_rows($results); if ($GLOBALS["VERBOSE"]) { echo "Line:" . __LINE__ . " {$countOfRoutes} routes\n"; } if ($countOfRoutes == 0) { return; } while ($ligne = mysql_fetch_assoc($results)) { $rtname = $ligne["routename"]; $rtid++; $eth = $ligne["interface"]; $gw = $ligne["gateway"]; $eth = $NetBuilder->NicToOther($eth); if ($gw != null) { $NEXT[] = "{$ip} route add {$gw} dev {$eth}"; } $TABLES[] = $rtname; echo "Starting......: " . date("H:i:s") . " Building routes, Group {$ligne["ID"]}\n"; $sql = "SELECT * FROM iproute_rules WHERE ruleid={$ligne["ID"]} AND enable=1 ORDER BY priority"; $results2 = $q->QUERY_SQL($sql, "artica_backup"); $tt[] = array(); while ($ligne2 = mysql_fetch_assoc($results2)) { $src = PARSECDR($ligne2["src"]); $destination = PARSECDR($ligne2["destination"]); $priority = $ligne2["priority"]; echo "Starting......: " . date("H:i:s") . " Building routes, source={$src}, dest={$destination}, GW={$gw}\n"; $POS = route_between_subnet($src, $destination, $priority, $eth, $rtname); if ($POS != null) { $NEXT[] = "{$ip} {$POS}"; continue; } $POS = route_from($src, $destination, $priority, $eth, $rtname); if ($POS != null) { $NEXT[] = "{$ip} {$POS}"; continue; } $POS = route_desc($src, $destination, $priority, $eth, $rtname, $gw); if ($POS != null) { $NEXT[] = "{$ip} {$POS}"; continue; } } } $f = array(); $f[] = "255\tlocal"; $f[] = "254\tmain"; $f[] = "253\tdefault"; $f[] = "299\tproxy"; $f[] = "0\tunspec"; $c = 1; if (count($TABLES) > 0) { while (list($id, $ligne) = each($TABLES)) { $f[] = "{$c}\t{$ligne}"; shell_exec("{$ip} route flush table {$ligne}"); } @file_put_contents("/etc/iproute2/rt_tables", @implode("\n", $f)); while (list($id, $cmdline) = each($NEXT)) { shell_exec("{$cmdline} >/dev/null 2>&1"); } } reset($TABLES); reset($NEXT); $FINAL["TABLES"] = $TABLES; $FINAL["NEXT"] = $NEXT; @file_put_contents("/etc/artica-postfix/ROUTES.CACHES.TABLES", serialize($FINAL)); }
function qos_containers_tab() { $tpl = new templates(); $users = new usersMenus(); $page = CurrentPageName(); $fontsize = 18; $ID = $_GET["ID"]; $q = new mysql(); $ligne = mysql_fetch_array($q->QUERY_SQL("SELECT name,eth FROM `qos_containers` WHERE ID='{$ID}'", "artica_backup")); $suffix["in"] = "{inbound}"; $suffix["out"] = "{outbound}"; $eth = $ligne["eth"]; if (preg_match("#(.*?)-(.+)\$#", $eth, $re)) { $eth_text = $re[1] . " " . $suffix[$re[2]]; } $p = new system_nic(); $eth = $p->NicToOther($eth); $array["container-popup"] = "{Q.O.S} {$ligne["name"]}"; $array["container-rules"] = "{rules}"; $array["container-DSCP"] = "TOS"; $t = time(); while (list($num, $ligne) = each($array)) { if ($num == "container-rules") { $html[] = $tpl->_ENGINE_parse_body("<li><a href=\"system.qos.container.rules.php?aclid={$ID}\" style='font-size:{$fontsize};font-weight:normal'><span>{$ligne}</span></a></li>\n"); continue; } if ($num == "container-DSCP") { $html[] = $tpl->_ENGINE_parse_body("<li><a href=\"system.qos.container.DSCP.php?aclid={$ID}\" style='font-size:{$fontsize};font-weight:normal'><span>{$ligne}</span></a></li>\n"); continue; } $html[] = $tpl->_ENGINE_parse_body("<li><a href=\"{$page}?{$num}={$t}&ID={$ID}ð={$eth}\" style='font-size:{$fontsize};font-weight:normal'><span>{$ligne}</span></a></li>\n"); } $html = build_artica_tabs($html, 'main_qos_eth' . $eth) . "<script>// LeftDesign('qos-256-white.png');</script>"; echo $html; }
function start($aspid = false) { $unix = new unix(); $sock = new sockets(); $Masterbin = $unix->find_program("arpd"); if (!is_file($Masterbin)) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, arpd not installed\n"; } return; } if (!$aspid) { $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $pid = $unix->get_pid_from_file($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { $time = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Already Artica task running PID {$pid} since {$time}mn\n"; } return; } @file_put_contents($pidfile, getmypid()); } $pid = PID_NUM(); if ($unix->MEM_TOTAL_INSTALLEE() < 624288) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} not enough memory\n"; } if ($unix->process_exists($pid)) { stop(); } return; } if ($unix->process_exists($pid)) { $timepid = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Service already started {$pid} since {$timepid}Mn...\n"; } return; } $EnableArpDaemon = $sock->GET_INFO("EnableArpDaemon"); $ArpdKernelLevel = $sock->GET_INFO("ArpdKernelLevel"); if (!is_numeric($EnableArpDaemon)) { $EnableArpDaemon = 1; } if (!is_numeric($ArpdKernelLevel)) { $ArpdKernelLevel = 0; } if ($EnableArpDaemon == 0) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service disabled (see EnableArpDaemon)\n"; } return; } $php5 = $unix->LOCATE_PHP5_BIN(); $sysctl = $unix->find_program("sysctl"); $echo = $unix->find_program("echo"); $nohup = $unix->find_program("nohup"); if ($ArpdKernelLevel > 0) { $ArpdKernelLevel_string = " -a {$ArpdKernelLevel}"; } $Interfaces = $unix->NETWORK_ALL_INTERFACES(); $nic = new system_nic(); while (list($Interface, $ligne) = each($Interfaces)) { if ($Interface == "lo") { continue; } if ($ligne["IPADDR"] == "0.0.0.0") { continue; } $Interface = $nic->NicToOther($Interface); $TRA[$Interface] = $Interface; } while (list($Interface, $ligne) = each($TRA)) { $TR[] = $Interface; } @mkdir('/var/lib/arpd', 0755, true); $f[] = "{$Masterbin} -b /var/lib/arpd/arpd.db"; $f[] = $ArpdKernelLevel; if (count($TR) > 0) { $f[] = "-k " . @implode($TR, " "); } $cmd = @implode(" ", $f) . " >/dev/null 2>&1 &"; if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service\n"; } shell_exec($cmd); for ($i = 1; $i < 5; $i++) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} waiting {$i}/5\n"; } sleep(1); $pid = PID_NUM(); if ($unix->process_exists($pid)) { break; } } $pid = PID_NUM(); if ($unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Success PID {$pid}\n"; } } else { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Failed\n"; } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} {$cmd}\n"; } } }