function inet_interfaces() { $newarray = array(); include_once dirname(__FILE__) . "/ressources/class.system.network.inc"; if (!isset($GLOBALS["CLASS_SOCKET"])) { $GLOBALS["CLASS_SOCKET"] = new sockets(); $sock = $GLOBALS["CLASS_SOCKET"]; } else { $sock = $GLOBALS["CLASS_SOCKET"]; } if ($sock->GET_INFO("EnablePostfixMultiInstance") == 1) { return; } $table = explode("\n", $sock->GET_INFO("PostfixBinInterfaces")); $unix = new unix(); $interfacesexists = $unix->NETWORK_ALL_INTERFACES(); while (list($num, $myarray) = each($interfacesexists)) { $INTERFACE[$myarray["IPADDR"]] = $myarray["IPADDR"]; } while (list($num, $val) = each($table)) { $val = trim($val); if ($val == null) { continue; } if ($val == "all") { echo "Starting......: " . date("H:i:s") . " Postfix skip {$val}\n"; continue; } if (isset($already[$val])) { continue; } echo "Starting......: " . date("H:i:s") . " Postfix checking interface : `{$val}`\n"; if ($val == "127.0.0.1") { $newarray[] = $val; $already[$val] = true; continue; } if (preg_match("#^[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+#", $val)) { if (!isset($INTERFACE[$val])) { echo "Starting......: " . date("H:i:s") . " Postfix {$val} interface not found\n"; continue; } } $already[$val] = true; if (preg_match("#[a-zA-Z]+[0-9]+#", $val)) { $ipsaddrs = LoadIpAddresses($val); while (list($a, $b) = each($ipsaddrs)) { echo "Starting......: " . date("H:i:s") . " Postfix found interface '{$b}'\n"; $newarray[] = $b; } continue; } if ($val == "all") { continue; } echo "Starting......: " . date("H:i:s") . " Postfix add {$val} interface in settings\n"; $newarray[] = $val; } if (count($newarray) > 0) { while (list($a, $b) = each($newarray)) { $testinets[$b] = $b; } $users = new usersMenus(); if ($users->roundcube_installed or $users->ZARAFA_INSTALLED) { if (!isset($testinets["127.0.0.1"])) { echo "Starting......: " . date("H:i:s") . " Postfix Listen interface Roundcube or Zarafa installed, force to listen 127.0.0.1\n"; $newarray[] = "127.0.0.1"; } } } if (count($newarray) > 0) { $finale = implode(",", $newarray); $finale = str_replace(',,', ',', $finale); } else { $unix = new unix(); $INT = $unix->NETWORK_ALL_INTERFACES(true); $INT["127.0.0.1"] = "127.0.0.1"; while (list($a, $b) = each($INT)) { $INTS[] = $a; } $finale = @implode(",", $INTS); } echo "Starting......: " . date("H:i:s") . " Postfix Listen interface(s) \"{$finale}\"\n"; postconf("inet_interfaces", $finale); postconf("inet_protocols", "ipv4"); postconf("smtp_bind_address6", ""); $smtp_bind_address6 = $sock->GET_INFO("smtp_bind_address6"); $PostfixEnableIpv6 = $sock->GET_INFO("PostfixEnableIpv6"); if ($PostfixEnableIpv6 == null) { $PostfixEnableIpv6 = 0; } if ($PostfixEnableIpv6 = 1) { if (trim($smtp_bind_address6) != null) { echo "Starting......: " . date("H:i:s") . " Postfix Listen ipv6 \"{$smtp_bind_address6}\"\n"; postconf("inet_protocols", "all"); postconf("smtp_bind_address6", $smtp_bind_address6); } } }
function inet_interfaces() { $newarray = array(); include_once dirname(__FILE__) . "/ressources/class.system.network.inc"; if (!isset($GLOBALS["CLASS_SOCKET"])) { $GLOBALS["CLASS_SOCKET"] = new sockets(); $sock = $GLOBALS["CLASS_SOCKET"]; } else { $sock = $GLOBALS["CLASS_SOCKET"]; } if ($sock->GET_INFO("EnablePostfixMultiInstance") == 1) { return; } $table = explode("\n", $sock->GET_INFO("PostfixBinInterfaces")); if (!is_array($table)) { $table[] = "all"; } while (list($num, $val) = each($table)) { $val = trim($val); if ($val == null) { continue; } if (preg_match("#[a-zA-Z]+[0-9]+#", $val)) { $ipsaddrs = LoadIpAddresses($val); while (list($a, $b) = each($ipsaddrs)) { echo "Starting......: Postfix {$nic} found interface '{$b}'\n"; $newarray[] = $b; } continue; } $newarray[] = $val; } if (count($newarray) == 0) { $newarray[] = "all"; } else { while (list($a, $b) = each($newarray)) { $testinets[$b] = $b; } $users = new usersMenus(); if ($users->roundcube_installed or $users->ZARAFA_INSTALLED) { if (!isset($testinets["127.0.0.1"])) { echo "Starting......: Postfix Listen interface Roundcube or Zarafa installed, force to listen 127.0.0.1\n"; $newarray[] = "127.0.0.1"; } } } $finale = implode(",", $newarray); $finale = str_replace(',,', ',', $finale); echo "Starting......: Postfix Listen interface(s) \"{$finale}\"\n"; postconf("inet_interfaces", $finale); postconf("artica-filter_destination_recipient_limit", 1); postconf("inet_protocols", "ipv4"); postconf("smtp_bind_address6", ""); $smtp_bind_address6 = $sock->GET_INFO("smtp_bind_address6"); $PostfixEnableIpv6 = $sock->GET_INFO("PostfixEnableIpv6"); if ($PostfixEnableIpv6 == null) { $PostfixEnableIpv6 = 0; } if ($PostfixEnableIpv6 = 1) { if (trim($smtp_bind_address6) != null) { echo "Starting......: Postfix Listen ipv6 \"{$smtp_bind_address6}\"\n"; postconf("inet_protocols", "all"); postconf("smtp_bind_address6", $smtp_bind_address6); } } }
function multiples_start() { $GLOBALS["CLASS_UNIX"] = new unix(); $xr = $GLOBALS["CLASS_UNIX"]->find_program("xr"); if (!is_file($xr)) { if ($GLOBALS["VERBOSE"]) { echo "Starting......: Crossroads multiple xr no such binary\n"; } return; } LoadIpAddresses(); $sql = "SELECT * FROM crossroads_smtp"; $q = new mysql(); $results = $q->QUERY_SQL($sql, "artica_backup"); if (!$q->ok) { echo "Starting......: Crossroads multiple {$q->mysql_error}\n"; return; } if (mysql_num_rows($results) == 0) { echo "Starting......: Crossroads multiple no interfaces set\n"; return; } $nohup = $GLOBALS["CLASS_UNIX"]->find_program("nohup"); while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) { $arrayConf = unserialize($ligne["parameters"]); $ipaddr = $ligne["ipaddr"]; $pidsuffix = str_replace(".", "", $ipaddr); $pidfile = "/var/run/crossroads-{$pidsuffix}.pid"; $instancesParams = $arrayConf["INSTANCES_PARAMS"]; $cd = array(); $cd[] = $xr; if (count($arrayConf["INSTANCES"]) == 0) { echo "Starting......: Crossroads multiple \"{$ipaddr}\" No clients set\n"; continue; } $pid = multiples_pid($ipaddr); if ($pid == 0) { $cd[] = "--server tcp:{$ipaddr}:25 --dispatch-mode round-robin"; //$cd[]="--pidfile $pidfile"; while (list($ip, $none) = each($arrayConf["INSTANCES"])) { if (!is_numeric($instancesParams["MAXCONS"][$ip])) { $instancesParams["MAXCONS"][$ip] = 0; } if (!is_numeric($instancesParams["WEIGTH"][$ip])) { $instancesParams["WEIGTH"][$ip] = 1; } echo "Starting......: Crossroads multiple round-robbin to {$ip}:25{$instancesParams["MAXCONS"][$ip]}:{$instancesParams["WEIGTH"][$ip]}...\n"; $cd[] = "--backend {$ip}:25:{$instancesParams["MAXCONS"][$ip]}:{$instancesParams["WEIGTH"][$ip]}"; } echo "Starting......: Crossroads multiple \"{$ipaddr}\"...\n"; $cmdline = trim($nohup . " " . @implode(" ", $cd) . " >/dev/null 2>&1 &"); if ($GLOBALS["VERBOSE"]) { echo $cmdline . "\n"; } shell_exec($cmdline); for ($i = 0; $i < 5; $i++) { sleep(1); $pid = multiples_pid($ipaddr); if ($pid > 0) { echo "Starting......: Crossroads multiple \"{$ipaddr}\" Success PID {$pid}...\n"; break; } } if (multiples_pid($ipaddr) == 0) { echo "Starting......: Crossroads multiple \"{$ipaddr}\" Failed...\n"; if (!isset($GLOBALS["INET_I"][$ipaddr])) { echo "Starting......: Crossroads multiple \"{$ipaddr}\" seems not exists on this system, remove it...\n"; $sql = "DELETE FROM crossroads_smtp WHERE ipaddr='{$ipaddr}'"; $q->QUERY_SQL($sql, "artica_backup"); } echo "Starting......: Crossroads multiple \"{$cmdline}\"\n"; } } else { echo "Starting......: Crossroads multiple {$ipaddr} Already running PID: {$pid}\n"; } } }