Esempio n. 1
0
function postfix_mem_disk_status()
{
    $hostname = $_GET["postfix-mem-disk-status"];
    if ($hostname == "master") {
        $directory = "/var/spool/postfix";
    } else {
        $directory = "/var/spool/postfix-{$hostname}";
    }
    $unix = new unix();
    $mem = $unix->MOUNTED_TMPFS_MEM($directory);
    $TOTAL_MEMORY_MB = $unix->TOTAL_MEMORY_MB();
    $TOTAL_MEMORY_MB_FREE = $unix->TOTAL_MEMORY_MB_USED();
    $array = array("MOUTED" => $mem, "TOTAL_MEMORY_MB" => $TOTAL_MEMORY_MB, "TOTAL_MEMORY_MB_FREE" => $TOTAL_MEMORY_MB_FREE);
    echo "<articadatascgi>" . base64_encode(serialize($array)) . "</articadatascgi>";
}
Esempio n. 2
0
function ufdbdatabases_in_mem()
{
    $sock = new sockets();
    $unix = new unix();
    $UfdbDatabasesInMemory = $sock->GET_INFO("UfdbDatabasesInMemory");
    if (!is_numeric($UfdbDatabasesInMemory)) {
        $UfdbDatabasesInMemory = 0;
    }
    if ($UfdbDatabasesInMemory == 0) {
        echo "Starting URLfilterDB Database in memory feature is disabled\n";
        $MOUNTED_DIR_MEM = $unix->MOUNTED_TMPFS_MEM("/var/lib/ufdbguard-memory");
        if ($MOUNTED_DIR_MEM > 0) {
            echo "Starting URLfilterDB Database unmounting...\n";
            $umount = $unix->find_program("umount");
            shell_exec("{$umount} -l /var/lib/ufdbguard-memory");
        }
        return;
    }
    $POSSIBLEDIRS[] = "/var/lib/ufdbartica";
    $POSSIBLEDIRS[] = "/var/lib/squidguard";
    $POSSIBLEDIRS[] = "/var/lib/ftpunivtlse1fr";
    $ufdbartica_size = $unix->DIRSIZE_BYTES("/var/lib/ufdbartica");
    $ufdbartica_size = round($ufdbartica_size / 1024 / 1000) + 5;
    $squidguard_size = $unix->DIRSIZE_BYTES("/var/lib/squidguard");
    $squidguard_size = round($squidguard_size / 1024 / 1000) + 5;
    $ftpunivtlse1fr_size = $unix->DIRSIZE_BYTES("/var/lib/ftpunivtlse1fr");
    $ftpunivtlse1fr_size = round($ftpunivtlse1fr_size / 1024 / 1000) + 5;
    echo "Starting URLfilterDB ufdbartica DB....: about {$ufdbartica_size}MB\n";
    echo "Starting URLfilterDB squidguard DB....: about {$squidguard_size}MB\n";
    echo "Starting URLfilterDB ftpunivtlse1fr DB: about {$ftpunivtlse1fr_size}MB\n";
    $total = $ufdbartica_size + $squidguard_size + $ftpunivtlse1fr_size + 10;
    echo "Starting URLfilterDB require {$total}MB\n";
    $mount = $unix->find_program("mount");
    $MOUNTED_DIR_MEM = $unix->MOUNTED_TMPFS_MEM("/var/lib/ufdbguard-memory");
    if ($MOUNTED_DIR_MEM == 0) {
        $system_mem = $unix->TOTAL_MEMORY_MB();
        echo "Starting URLfilterDB system memory {$system_mem}MB\n";
        if ($system_mem < $total) {
            $require = $total - $system_mem;
            echo "Starting URLfilterDB not engough memory require at least {$require}MB\n";
            return;
        }
        $system_free = $unix->TOTAL_MEMORY_MB_FREE();
        echo "Starting URLfilterDB system memory available {$system_free}MB\n";
        if ($system_free < $total) {
            $require = $total - $system_free;
            echo "Starting URLfilterDB not engough memory require at least {$require}MB\n";
            return;
        }
    }
    $idbin = $unix->find_program("id");
    $mount = $unix->find_program("mount");
    $umount = $unix->find_program("umount");
    $rm = $unix->find_program("rm");
    $cp = $unix->find_program("cp");
    $chown = $unix->find_program("chown");
    if ($MOUNTED_DIR_MEM > 0) {
        if ($MOUNTED_DIR_MEM < $total) {
            echo "Starting URLfilterDB: umounting from memory\n";
            shell_exec("{$umount} -l /var/lib/ufdbguard-memory");
            $MOUNTED_DIR_MEM = $unix->MOUNTED_TMPFS_MEM("/var/lib/ufdbguard-memory");
        }
    }
    if ($MOUNTED_DIR_MEM == 0) {
        if (strlen($idbin) < 3) {
            echo "Starting URLfilterDB: tmpfs `id` no such binary\n";
            return;
        }
        if (strlen($mount) < 3) {
            echo "Starting URLfilterDB: tmpfs `mount` no such binary\n";
            return;
        }
        exec("{$idbin} squid 2>&1", $results);
        if (!preg_match("#uid=([0-9]+).*?gid=([0-9]+)#", @implode("", $results), $re)) {
            echo "Starting......: " . date("H:i:s") . "MySQL mysql no such user...\n";
            return;
        }
        $uid = $re[1];
        $gid = $re[2];
        echo "Starting URLfilterDB: tmpfs uid/gid ={$uid}:{$gid} for {$total}M\n";
        @mkdir("/var/lib/ufdbguard-memory");
        $cmd = "{$mount} -t tmpfs -o rw,uid={$uid},gid={$gid},size={$total}M,nr_inodes=10k,mode=0700 tmpfs \"/var/lib/ufdbguard-memory\"";
        shell_exec($cmd);
        $MOUNTED_DIR_MEM = $unix->MOUNTED_TMPFS_MEM("/var/lib/ufdbguard-memory");
        if ($MOUNTED_DIR_MEM == 0) {
            echo "Starting URLfilterDB: tmpfs failed...\n";
            return;
        }
    }
    echo "Starting URLfilterDB: mounted as {$MOUNTED_DIR_MEM}MB\n";
    reset($POSSIBLEDIRS);
    while (list($index, $directory) = each($POSSIBLEDIRS)) {
        $directoryname = basename($directory);
        @mkdir("/var/lib/ufdbguard-memory/{$directoryname}", 0755, true);
        if (!is_dir("/var/lib/ufdbguard-memory/{$directoryname}")) {
            echo "Starting URLfilterDB: {$directoryname} permission denied\n";
            return;
        }
        @chown("/var/lib/ufdbguard-memory/{$directoryname}", "squid");
        echo "Starting URLfilterDB: replicating {$directoryname}\n";
        shell_exec("{$cp} -rfu {$directory}/* /var/lib/ufdbguard-memory/{$directoryname}/");
    }
    $ufdbguardConfs[] = "/etc/ufdbguard/ufdbGuard.conf";
    $ufdbguardConfs[] = "/etc/squid3/ufdbGuard.conf";
    echo "Starting URLfilterDB: setup privileges\n";
    shell_exec("{$chown} -R squid:squid /var/lib/ufdbguard-memory >/dev/null 2>&1");
    echo "Starting URLfilterDB: modify configuration files\n";
    while (list($index, $configfile) = each($ufdbguardConfs)) {
        $f = explode("\n", @file_get_contents($configfile));
        while (list($indexLine, $line) = each($f)) {
            reset($POSSIBLEDIRS);
            while (list($index, $directory) = each($POSSIBLEDIRS)) {
                $directoryname = basename($directory);
                $line = str_replace($directory, "/var/lib/ufdbguard-memory/{$directoryname}", $line);
                $f[$indexLine] = $line;
            }
        }
        @file_put_contents($configfile, @implode("\n", $f));
        echo "Starting URLfilterDB: {$configfile} success...\n";
    }
}
Esempio n. 3
0
function memory()
{
    $unix = new unix();
    $sock = new sockets();
    if ($GLOBALS["VERBOSE"]) {
        $cmd_verbose = " --verbose";
    }
    $PostFixEnableQueueInMemory = $sock->GET_INFO("PostFixEnableQueueInMemory");
    $PostFixQueueInMemory = $sock->GET_INFO("PostFixQueueInMemory");
    $directory = "/var/spool/postfix";
    if ($PostFixEnableQueueInMemory == 1) {
        echo "Starting......: Postfix Queue in memory is enabled for {$PostFixQueueInMemory}M\n";
        echo "Starting......: Postfix executing exec.postfix-multi.php\n";
        shell_exec(LOCATE_PHP5_BIN() . " " . dirname(__FILE__) . "/exec.postfix-multi.php --instance-memory master {$PostFixQueueInMemory}{$cmd_verbose}");
        return;
    } else {
        $MOUNTED_TMPFS_MEM = $unix->MOUNTED_TMPFS_MEM($directory);
        if ($MOUNTED_TMPFS_MEM > 0) {
            shell_exec(LOCATE_PHP5_BIN() . " " . dirname(__FILE__) . "/exec.postfix-multi.php --instance-memory-kill master{$cmd_verbose}");
            return;
        }
        echo "Starting......: Postfix Queue in memory is not enabled\n";
    }
}
Esempio n. 4
0
function _start_instance($hostname)
{
    if ($hostname == "master") {
        return;
    }
    if (trim($hostname) == null) {
        return;
    }
    $unix = new unix();
    $main = new maincf_multi($hostname);
    $PostFixEnableQueueInMemory = $main->GET("PostFixEnableQueueInMemory");
    $PostFixQueueInMemory = $main->GET("PostFixQueueInMemory");
    $ifconfig = $unix->find_program("ifconfig");
    $ln = $unix->find_program("ln");
    $route = $unix->find_program("route");
    $directory = "/var/spool/postfix-{$hostname}";
    $postfixbin = $unix->find_program("postfix");
    if ($PostFixEnableQueueInMemory == 1) {
        reconfigure_instance_tmpfs($hostname, $PostFixQueueInMemory);
    } else {
        $MOUNTED_TMPFS_MEM = $unix->MOUNTED_TMPFS_MEM($directory);
        if ($MOUNTED_TMPFS_MEM > 0) {
            reconfigure_instance_tmpfs_umount($hostname);
        }
    }
    if (!is_file("/etc/postfix-{$hostname}/main.cf")) {
        echo "Starting......: " . date("H:i:s") . " Postfix \"{$hostname}\" /etc/postfix-{$hostname}/main.cf no such file (reconfigure)\n";
        ConfigureMainCF($hostname, true);
    }
    $pidfile = "/var/spool/postfix-{$hostname}/pid/master.pid";
    if ($GLOBALS["postmulti"] == null) {
        $GLOBALS["postmulti"] = $unix->find_program("postmulti");
    }
    $pid = $unix->get_pid_from_file($pidfile);
    writelogs("{$hostname}:: Checking directories IP address={$main->ip_addr}", __FUNCTION__, __FILE__, __LINE__);
    $q = new mysql();
    $sql = "SELECT * FROM nics_virtuals WHERE ipaddr='{$main->ip_addr}'";
    $ligne = mysql_fetch_array($q->QUERY_SQL($sql, "artica_backup"));
    echo "Starting......: " . date("H:i:s") . " Postfix \"{$hostname}\" {$main->ip_addr} on {$ligne["nic"]}:{$ligne["ID"]}\n";
    if ($ligne["ipv6"] == 0) {
        if ($ligne["ID"] > 0) {
            shell_exec("{$ifconfig} {$ligne["nic"]}:{$ligne["ID"]} {$main->ip_addr} >/dev/null 2>&1");
            shell_exec("{$route} add -host {$main->ip_addr} dev {$ligne["nic"]}:{$ligne["ID"]} >/dev/null 2>&1");
        }
    }
    $main->CheckDirectories($hostname);
    writelogs("{$hostname}:: {$pidfile}={$pid}", __FUNCTION__, __FILE__, __LINE__);
    if ($unix->process_exists($pid)) {
        echo "Starting......: " . date("H:i:s") . " Postfix \"{$hostname}\" reloading\n";
        writelogs("{$hostname}::reloading postfix {$GLOBALS["postmulti"]} -i postfix-{$hostname} -p reload", __FUNCTION__, __FILE__, __LINE__);
        exec("{$GLOBALS["postmulti"]} -i postfix-{$hostname} -p reload 2>&1", $results);
        while (list($num, $line) = each($results)) {
            if (preg_match("#unused parameter#", $line)) {
                continue;
            }
            writelogs("{$line}", __FUNCTION__, __FILE__, __LINE__);
            echo "Starting......: " . date("H:i:s") . " Postfix \"{$hostname}\" {$line}\n";
            if (preg_match("#fatal: open /etc/postfix-(.+?)\\/main\\.cf#", $line, $re)) {
                echo "Starting......: " . date("H:i:s") . " Postfix reconfigure \"{$re[1]}\"\n";
                reconfigure_instance($re[1]);
            }
        }
        return;
    }
    echo "Starting......: " . date("H:i:s") . " Postfix starting \"{$hostname}\"\n";
    writelogs("{$hostname}::Starting postfix {$GLOBALS["postmulti"]} -i postfix-{$hostname} -p start", __FUNCTION__, __FILE__, __LINE__);
    exec("{$GLOBALS["postmulti"]} -i postfix-{$hostname} -p start 2>&1", $results);
    writelogs("{$hostname}::Starting LOG=" . count($results) . " lines", __FUNCTION__, __FILE__, __LINE__);
    while (list($num, $line) = each($results)) {
        if (preg_match("#unused parameter:#", $line)) {
            continue;
        }
        writelogs("{$line}", __FUNCTION__, __FILE__, __LINE__);
        echo "Starting......: " . date("H:i:s") . " Postfix \"{$hostname}\" {$line}\n";
        if (preg_match("#fatal: open /etc/postfix-(.+?)\\/main\\.cf#", $line, $re)) {
            echo "Starting......: " . date("H:i:s") . " Postfix reconfigure \"{$re[1]}\"\n";
            reconfigure_instance($re[1]);
        }
    }
    $pid = $unix->get_pid_from_file($pidfile);
    for ($i = 0; $i < 10; $i++) {
        if ($GLOBALS["VERBOSE"]) {
            echo "Starting......: " . date("H:i:s") . " Postfix \"{$hostname}\" DEBUG open \"{$pidfile}\"\n";
        }
        if ($unix->process_exists($pid)) {
            break;
        }
        echo "Starting......: " . date("H:i:s") . " Postfix \"{$hostname}\" waiting run ({$pid})\n";
        sleep(1);
        $pid = $unix->get_pid_from_file($pidfile);
    }
    $pid = $unix->get_pid_from_file($pidfile);
    if ($unix->process_exists($pid)) {
        echo "Starting......: " . date("H:i:s") . " Postfix \"{$hostname}\" SUCCESS with PID={$pid}\n";
        writelogs("{$hostname}::DONE", __FUNCTION__, __FILE__, __LINE__);
        return;
    }
    echo "Starting......: " . date("H:i:s") . " Postfix \"{$hostname}\" FAILED\n";
    writelogs("{$hostname}::FAILED", __FUNCTION__, __FILE__, __LINE__);
}
Esempio n. 5
0
function _start_instance($hostname){
	if($hostname=="master"){return;}
	if(trim($hostname)==null){return;}
	$unix=new unix();
	$main=new maincf_multi($hostname);
	$PostFixEnableQueueInMemory=$main->GET("PostFixEnableQueueInMemory");
	$PostFixQueueInMemory=$main->GET("PostFixQueueInMemory");
	$directory="/var/spool/postfix-$hostname";
	if($PostFixEnableQueueInMemory==1){
		reconfigure_instance_tmpfs($hostname,$PostFixQueueInMemory);
	}else{
		$MOUNTED_TMPFS_MEM=$unix->MOUNTED_TMPFS_MEM($directory);
		if($MOUNTED_TMPFS_MEM>0){
			reconfigure_instance_tmpfs_umount($hostname);
		}
	}
	
		
	
	
	$pidfile="/var/spool/postfix-$hostname/pid/master.pid";
	
	if($GLOBALS["postmulti"]==null){$GLOBALS["postmulti"]=$unix->find_program("postmulti");}
	$pid=$unix->get_pid_from_file($pidfile);
	
	writelogs("$hostname:: Checking directories",__FUNCTION__,__FILE__,__LINE__);
	$main->CheckDirectories($hostname);
	writelogs("$hostname:: $pidfile=$pid",__FUNCTION__,__FILE__,__LINE__);
	
	if($unix->process_exists($pid)){
		echo "Starting......: Postfix \"$hostname\" reloading\n";
		writelogs("$hostname::reloading postfix {$GLOBALS["postmulti"]} -i postfix-$hostname -p reload",__FUNCTION__,__FILE__,__LINE__);
		exec("{$GLOBALS["postmulti"]} -i postfix-$hostname -p reload 2>&1",$results);
		while (list ($num, $line) = each ($results) ){
			writelogs("$line",__FUNCTION__,__FILE__,__LINE__);
			echo "Starting......: Postfix \"$hostname\" $line\n";
			
			if(preg_match("#fatal: open /etc/postfix-(.+?)\/main\.cf#",$line,$re)){
				echo "Starting......: Postfix reconfigure \"{$re[1]}\"\n";
				reconfigure_instance($re[1]);
			}
			
		}
		
		return;
	}	
	
	echo "Starting......: Postfix starting \"$hostname\"\n";
	writelogs("$hostname::Starting postfix {$GLOBALS["postmulti"]} -i postfix-$hostname -p start",__FUNCTION__,__FILE__,__LINE__);
	exec("{$GLOBALS["postmulti"]} -i postfix-$hostname -p start 2>&1",$results);
	writelogs("$hostname::Starting LOG=".count($results)." lines",__FUNCTION__,__FILE__,__LINE__);
	
		while (list ($num, $line) = each ($results) ){
			writelogs("$line",__FUNCTION__,__FILE__,__LINE__);
			echo "Starting......: Postfix \"$hostname\" $line\n";
			if(preg_match("#fatal: open /etc/postfix-(.+?)\/main\.cf#",$line,$re)){
				echo "Starting......: Postfix reconfigure \"{$re[1]}\"\n";
				reconfigure_instance($re[1]);
			}			
	}

	
	$pid=$unix->get_pid_from_file($pidfile);
	for($i=0;$i<10;$i++){
		if($unix->process_exists($pid)){break;}
		echo "Starting......: Postfix \"$hostname\" waiting run ($pid)\n";
		sleep(1);
	}
	
	
	if($unix->process_exists($pid)){
		echo "Starting......: Postfix \"$hostname\" SUCCESS with PID=$pid\n";
		writelogs("$hostname::DONE",__FUNCTION__,__FILE__,__LINE__);
		return;
	}
	echo "Starting......: Postfix \"$hostname\" FAILED\n";
	writelogs("$hostname::FAILED",__FUNCTION__,__FILE__,__LINE__);
	
	
	
	
}