Esempio n. 1
0
function build_rules()
{
    $q = new mysql_squid_builder();
    $unix = new unix();
    $SQUID_BIN = $unix->LOCATE_SQUID_BIN();
    build_progress("{IT_charter}", 25);
    $sql = "SELECT ID,title FROM itcharters WHERE enabled=1";
    $results = $q->QUERY_SQL($sql);
    if (!$q->ok) {
        build_progress("{IT_charter} {mysql_error}", 110);
        echo $q->mysql_error;
        return;
    }
    if (mysql_num_rows($results) == 0) {
        @unlink("/etc/squid3/itCharts.enabled.db");
        squid_admin_mysql(1, "Reloading Proxy service (itCharts)", null, __FILE__, __LINE__);
        build_progress("{IT_charter} {reload_proxy_service}", 90);
        system("{$SQUID_BIN} -f /etc/squid3/squid.conf -k reconfigure");
        build_progress("{IT_charter} {done} 0 {item}", 100);
        return;
    }
    while ($ligne = mysql_fetch_assoc($results)) {
        build_progress("{$ligne["title"]}", 50);
        echo "{$ligne["ID"]}: {$ligne["title"]}\n";
        $MAIN[$ligne["ID"]] = $ligne["title"];
    }
    @file_put_contents("/etc/squid3/itCharts.enabled.db", serialize($MAIN));
    squid_admin_mysql(1, "Reloading Proxy service (itCharts)", null, __FILE__, __LINE__);
    build_progress("{IT_charter} {reload_proxy_service}", 90);
    system("{$SQUID_BIN} -f /etc/squid3/squid.conf -k reconfigure");
    build_progress("{IT_charter} {done} " . count($MAIN) . " {items}", 100);
}
function xdisable()
{
    $unix = new unix();
    $sock = new sockets();
    $php = $unix->LOCATE_PHP5_BIN();
    build_progress("{checking} Join to the Active Directory Domain", 15);
    system("{$php} /usr/share/artica-postfix/exec.kerbauth.php --join");
    for ($i = 1; $i < 4; $i++) {
        build_progress("{checking} {waiting} {$i}/3 {seconds}", 20);
        sleep(1);
    }
    build_progress("{checking} Active Directory with wbinfo...", 25);
    $php = $unix->LOCATE_PHP5_BIN();
    wbinfo_if_available();
    if (!wbinfo(true)) {
        build_progress("{checking} Active Directory {failed}", 110);
        return;
    }
    build_progress("{checking} Active Directory...", 30);
    if (!testjoin()) {
        build_progress("{checking} Active Directory {failed}", 110);
        return;
    }
    build_progress("Active Directory...", 50);
    $sock->SET_INFO("KerbAuthWatchEv", 0);
    $sock->SET_INFO("ActiveDirectoryEmergency", 0);
    $sock->SET_INFO("ActiveDirectoryEmergencyReboot", 0);
    $sock->SET_INFO("ActiveDirectoryEmergencyNone", 0);
    build_progress("{reconfigure}...", 80);
    system("{$php} /usr/share/artica-postfix/exec.squid.php --build --force");
    build_progress("{done}...", 100);
    if ($GLOBALS["META"]) {
        $unix->THREAD_COMMAND_SET("{$php} /usr/share/artica-postfix/exec.artica-meta-client.php --ping --force");
    }
}
function xdisable()
{
    $unix = new unix();
    $sock = new sockets();
    $php = $unix->LOCATE_PHP5_BIN();
    build_progress("{checking} Active Directory with wbinfo...", 20);
    if (!wbinfo(true)) {
        build_progress("{checking} Active Directory {failed}", 110);
        return;
    }
    build_progress("{checking} Active Directory...", 30);
    if (!testjoin()) {
        build_progress("{checking} Active Directory {failed}", 110);
        return;
    }
    build_progress("Active Directory...", 50);
    $sock->SET_INFO("KerbAuthWatchEv", 0);
    $sock->SET_INFO("ActiveDirectoryEmergency", 0);
    $sock->SET_INFO("ActiveDirectoryEmergencyReboot", 0);
    $sock->SET_INFO("ActiveDirectoryEmergencyNone", 0);
    build_progress("{reconfigure}...", 80);
    build_progress("{done}...", 100);
    if ($GLOBALS["META"]) {
        $unix->THREAD_COMMAND_SET("{$php} /usr/share/artica-postfix/exec.artica-meta-client.php --ping --force");
    }
}
Esempio n. 4
0
function xstart()
{
    $sock = new sockets();
    $unix = new unix();
    $php = $unix->LOCATE_PHP5_BIN();
    $SquidAllow80Port = intval($sock->GET_INFO("SquidAllow80Port"));
    build_progress("{starting} {allow_80443_port}", 15);
    if ($SquidAllow80Port == 1) {
        build_progress("{stopping} {web_service}", 20);
        system("/etc/init.d/apache2 stop");
        build_progress("{stopping} Reverse Proxy", 30);
        system("/etc/init.d/nginx stop");
    } else {
        build_progress("{remove} 80/443 ports", 20);
        $q = new mysql_squid_builder();
        $q->QUERY_SQL("DELETE FROM proxy_ports WHERE `port`='80'");
        build_progress("{remove} 80/443 ports", 25);
        $q->QUERY_SQL("DELETE FROM proxy_ports WHERE `port`='443'");
        build_progress("{reconfigure_proxy_service}", 30);
        $php = $unix->LOCATE_PHP5_BIN();
        shell_exec("{$php} /usr/share/artica-postfix/exec.squid.php --build --force");
    }
    build_progress("{restarting_artica_status}", 80);
    system("/etc/init.d/artica-status restart --force");
    build_progress("{done}", 100);
}
Esempio n. 5
0
function startx()
{
    $unix = new unix();
    build_progress(50, "{refresh} CPUS");
    @unlink("/etc/artica-postfix/CPU_NUMBER");
    build_progress(55, "{refresh} CPUS");
    @unlink("/usr/share/artica-postfix/ressources/interface-cache/CPU_NUMBER");
    build_progress(60, "{rescan-disk-system}");
    $dirs = $unix->dirdir("/sys/class/scsi_host");
    $echo = $unix->find_program("echo");
    $udevadm = $unix->find_program("udevadm");
    $php = $unix->LOCATE_PHP5_BIN();
    while (list($dirpath, $line) = each($dirs)) {
        $basename = basename($dirpath);
        if (!preg_match("#host[0-9]+#", $basename)) {
            continue;
        }
        $cmd = "{$echo} \"- - -\" >{$dirpath}/scan";
        build_progress(65, "{rescan-disk-system}" . dirname($dirpath));
        shell_exec($cmd);
    }
    build_progress(70, "{rescan-disk-system}");
    $cmdline = "{$php} /usr/share/artica-postfix/exec.usb.scan.write.php --verbose";
    system($cmd);
    build_progress(80, "{rescan-network-system}");
    system("{$udevadm} control --reload-rules");
    system("{$udevadm} trigger --attr-match=subsystem=net");
    sleep(3);
    system("/usr/share/artica-postfix/bin/process1 --force --verbose --" . time());
    build_progress(100, "{refresh} {done}");
}
Esempio n. 6
0
function start()
{
    $EnableStopPostfix = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/EnableStopPostfix"));
    if ($EnableStopPostfix == 1) {
        build_progress("{stop_messaging} {restarting_watchdog}", 15);
        system("/etc/init.d/artica-status restart --force");
        build_progress("{stop_messaging}", 20);
        system("/etc/init.d/postfix stop");
        build_progress("{stop_messaging}", 30);
        system("/etc/init.d/amavis stop");
        build_progress("{stop_messaging}", 40);
        system("/etc/init.d/milter-greylist stop");
        build_progress("{stop_messaging} {success}", 100);
        return;
    }
    build_progress("{start_messaging} {restarting_watchdog}", 15);
    system("/etc/init.d/artica-status restart --force");
    build_progress("{start_messaging}", 20);
    system("/etc/init.d/postfix start");
    build_progress("{start_messaging}", 30);
    system("/etc/init.d/amavis start");
    build_progress("{start_messaging}", 40);
    system("/etc/init.d/milter-greylist start");
    build_progress("{start_messaging} {success}", 100);
}
function xstart()
{
    $unix = new unix();
    $php = $unix->LOCATE_PHP5_BIN();
    $tar = $unix->find_program("tar");
    build_progress("{downloading} roundcubeemail-1.1.2.tar.gz", 20);
    $tmpfile = $unix->FILE_TEMP();
    $curl = new ccurl("http://articatech.net/download/postfix-debian7/roundcubeemail-1.1.2.tar.gz");
    if (!$curl->GetFile($tmpfile)) {
        echo "Failed: " . $curl->error . "\n";
        @unlink($tmpfile);
        build_progress("{failed} roundcubeemail-1.1.2.tar.gz", 110);
        return;
    }
    build_progress("{uncompressing} roundcubeemail-1.1.2.tar.gz", 50);
    system("{$tar} xf {$tmpfile} -C /");
    @unlink($tmpfile);
    if (!is_file("/usr/share/roundcube/index.php")) {
        build_progress("{uncompressing} roundcubeemail-1.1.2.tar.gz {failed}", 110);
        return;
    }
    build_progress("{verify_database}", 60);
    system("{$php} /usr/share/artica-postfix/exec.roundcube.php --database");
    build_progress("{restarting_service}", 70);
    system("{$php} /usr/share/artica-postfix/exec.roundcube.php --restart");
    system("/etc/init.d/artica-status restart");
    build_progress("{installing} roundcubeemail-1.1.2.tar.gz {success}", 100);
}
function restore($filename)
{
    $unix = new unix();
    $sock = new sockets();
    $TMP = $unix->FILE_TEMP();
    $filenameBase = basename($filename);
    if (!is_file($filename)) {
        echo "{$filename} no such file\n";
        build_progress("{failed}", 110);
    }
    $tmpf = $unix->FILE_TEMP();
    build_progress("{uncompress} {$filenameBase}", 10);
    if (!$unix->uncompress($filename, $tmpf)) {
        @unlink($filename);
        build_progress("{uncompress} {$filenameBase} {failed}", 110);
        return;
    }
    @unlink($filename);
    build_progress("{importing} {$tmpf}", 50);
    $q = new mysql_squid_builder();
    $nice = $unix->EXEC_NICE();
    $mysql = $unix->find_program("mysql");
    $gzip = $unix->find_program("gzip");
    $nohup = $unix->find_program("nohup");
    $echo = $unix->find_program("echo");
    $rm = $unix->find_program("rm");
    $php = $unix->LOCATE_PHP5_BIN();
    $sh[] = "#!/bin/sh";
    $sh[] = "{$echo} \"{$mysql} -> {$filenameBase}\"";
    $sh[] = "{$nice} {$mysql} {$q->MYSQL_CMDLINES} -f squidlogs < {$tmpf}";
    $sh[] = "{$rm} {$TMP}.sh";
    $sh[] = "\n";
    @file_put_contents("{$TMP}.sh", @implode("\n", $sh));
    @chmod("{$TMP}.sh", 0755);
    build_progress(10, "Starting restore {$filenameBase} - " . basename("{$TMP}.sh") . " ");
    system("{$nohup} {$TMP}.sh >{$TMP}.txt 2>&1 &");
    sleep(1);
    $PID = $unix->PIDOF_PATTERN("{$TMP}.sh");
    echo "Running PID {$PID}\n";
    while ($unix->process_exists($PID)) {
        build_progress(50, "Starting restoring {$filenameBase}");
        sleep(3);
        $PID = $unix->PIDOF_PATTERN("{$TMP}.sh");
        echo "Running PID {$PID}\n";
    }
    echo @file_get_contents("{$TMP}.txt") . "\n";
    @unlink("{$TMP}.sh");
    @unlink("{$TMP}.txt");
    build_progress(50, "{restore} {done} {$filenameBase}");
    build_progress(50, "{restore} Analyze Hourly tables");
    system("{$php} /usr/share/artica-postfix/exec.squid.stats.hours.php --force --verbose");
    build_progress(60, "{restore} Repair Hourly tables");
    system("{$php} /usr/share/artica-postfix/exec.squid.stats.hours.php --repair --force --verbose");
    build_progress(70, "{restore} Repair Table days");
    system("{$php} /usr/share/artica-postfix/exec.squid.stats.repair.php --tables-day --repair --force --verbose");
    build_progress(80, "{restore} Repair sums");
    system("{$php} /usr/share/artica-postfix/exec.squid.stats.totals.php --repair --force --verbose");
    build_progress(100, "{restore} Done");
}
function install($filename)
{
    $GLOBALS["PROGRESS_FILE"] = "/usr/share/artica-postfix/ressources/logs/squid.install.progress";
    $GLOBALS["LOG_FILE"] = "/usr/share/artica-postfix/ressources/logs/web/squid.install.progress.txt";
    $unix = new unix();
    $LINUX_CODE_NAME = $unix->LINUX_CODE_NAME();
    $LINUX_DISTRIBUTION = $unix->LINUX_DISTRIBUTION();
    $LINUX_VERS = $unix->LINUX_VERS();
    $LINUX_ARCHITECTURE = $unix->LINUX_ARCHITECTURE();
    $APACHEUSER = $unix->APACHE_SRC_ACCOUNT();
    $DebianVer = "debian{$LINUX_VERS[0]}";
    $TMP_DIR = $unix->TEMP_DIR();
    $ORGV = @file_get_contents("/usr/share/artica-postfix/VERSION");
    $PATCH_VER = null;
    $tarballs_file = "/usr/share/artica-postfix/ressources/conf/upload/{$filename}";
    echo "Package {$tarballs_file}\n";
    $size = filesize($tarballs_file);
    echo "Size....................: " . FormatBytes($size / 1024) . "\n";
    build_progress("Analyze...", 10);
    echo "Current system..........: {$LINUX_CODE_NAME} {$LINUX_DISTRIBUTION} {$LINUX_VERS[0]}/{$LINUX_VERS[1]} {$LINUX_ARCHITECTURE}\n";
    echo "Package.................: {$filename}\n";
    echo "Temp dir................: {$TMP_DIR}\n";
    if (!is_file($tarballs_file)) {
        echo "{$tarballs_file} no such file...\n";
        build_progress("No such file...", 110);
        return;
    }
    echo "Uncompressing {$tarballs_file}...\n";
    build_progress("{extracting} {$filename}...", 20);
    $chown = $unix->find_program("chown");
    $chmod = $unix->find_program("chmod");
    $tar = $unix->find_program("tar");
    $rm = $unix->find_program("rm");
    $nohup = $unix->find_program("nohup");
    $php = $unix->LOCATE_PHP5_BIN();
    $squid = $unix->LOCATE_SQUID_BIN();
    build_progress("{extracting} {$filename}...", 50);
    system("{$tar} xf {$tarballs_file} -C /");
    echo "Removing {$tarballs_file}...\n";
    @unlink($tarballs_file);
    shell_exec("{$rm} -rf /usr/share/artica-postfix/ressources/conf/upload/*");
    @unlink(dirname(__FILE__) . "/ressources/logs/squid.compilation.params");
    build_progress("{restarting} Squid-cache...", 60);
    system("/etc/init.d/squid restart --force");
    build_progress("{reconfiguring} Squid-cache...", 65);
    system("{$php} /usr/share/artica-postfix/exec.squid.php --build --force");
    build_progress("{reconfiguring} {APP_UFDBGUARD}...", 70);
    system("{$php} /usr/share/artica-postfix/exec.squidguard.php --build --force");
    build_progress("{restarting} {APP_C_ICAP}...", 80);
    system("/etc/init.d/c-icap restart");
    build_progress("Refresh local versions...", 90);
    system('/usr/share/artica-postfix/bin/process1 --force --verbose --' . time());
    $squid_version = x_squid_version();
    build_progress("{success} v.{$squid_version}...", 100);
    echo "Starting......: " . date("H:i:s") . " Done you can close the screen....\n";
}
Esempio n. 10
0
function startx()
{
    build_progress(50, "{refresh} CPUS");
    @unlink("/etc/artica-postfix/CPU_NUMBER");
    build_progress(60, "{refresh} CPUS");
    @unlink("/usr/share/artica-postfix/ressources/interface-cache/CPU_NUMBER");
    build_progress(70, "{refresh} CPUS");
    sleep(3);
    system("/usr/share/artica-postfix/bin/process1 --force --verbose --" . time());
    build_progress(100, "{refresh} {done}");
}
Esempio n. 11
0
function script_startfile()
{
    $unix = new unix();
    $sock = new sockets();
    $GLOBALS["echobin"] = $unix->find_program("echo");
    $php = $unix->LOCATE_PHP5_BIN();
    $sh = array();
    $SquidWCCPEnabled = $sock->GET_INFO("SquidWCCPEnabled");
    $hasProxyTransparent = $sock->GET_INFO("hasProxyTransparent");
    $EnableArticaHotSpot = $sock->GET_INFO("EnableArticaHotSpot");
    if (!is_numeric($SquidWCCPEnabled)) {
        $SquidWCCPEnabled = 0;
    }
    if (!is_numeric($hasProxyTransparent)) {
        $hasProxyTransparent = 0;
    }
    if (!is_numeric($EnableArticaHotSpot)) {
        $EnableArticaHotSpot = 0;
    }
    $sh[] = "#!/bin/sh -e";
    $sh[] = "### BEGIN INIT INFO";
    $sh[] = "# Builded on " . date("Y-m-d H:i:s");
    $sh[] = "# Provides:          tproxy";
    $sh[] = "# Required-Start:    \$local_fs";
    $sh[] = "# Required-Stop:     \$local_fs";
    $sh[] = "# Should-Start:\t\t";
    $sh[] = "# Should-Stop:\t\t";
    $sh[] = "# Default-Start:     S";
    $sh[] = "# Default-Stop:      0 6";
    $sh[] = "# Short-Description: start and stop the tproxy";
    $sh[] = "# Description:       Artica tproxy service Raise transparent proxy";
    $sh[] = "### END INIT INFO";
    $sh[] = "case \"\$1\" in";
    $sh[] = "start)";
    $sh[] = "{$GLOBALS["echobin"]} \"TProxy: Removing Iptables rules\"";
    $sh[] = $php . " " . dirname(__FILE__) . "/exec.squid.transparent.delete.php >/dev/null || true";
    $sh[] = "{$GLOBALS["echobin"]} \"TProxy: hasProxyTransparent key ({$hasProxyTransparent})...\"";
    $sh[] = "{$GLOBALS["echobin"]} \"TProxy: SquidWCCPEnabled key ({$SquidWCCPEnabled})...\"";
    $sh[] = "{$GLOBALS["echobin"]} \"TProxy: EnableArticaHotSpot key ({$EnableArticaHotSpot})...\"";
    $sh[] = script_tproxy();
    $sh[] = script_endfile();
    @file_put_contents("/etc/init.d/tproxy", @implode("\n", $sh));
    @chmod("/etc/init.d/tproxy", 0755);
    build_progress("Installing default script...", 40);
    script_install();
    build_progress("Default script...{done}", 50);
}
function xinstall()
{
    $unix = new unix();
    $curl = new ccurl();
    $tmpfile = $unix->FILE_TEMP();
    $tmpdir = $unix->TEMP_DIR();
    build_progress("{downloading} v3.1.0-25", 15);
    $curl = new ccurl("http://articatech.net/download/UpdateUtility/updateutility-3.1.0-25.tar.gz");
    if (!$curl->GetFile($tmpfile)) {
        @unlink($tmpfile);
        build_progress("{downloading} {failed}", 110);
        return;
    }
    $tar = $unix->find_program("tar");
    $rm = $unix->find_program("rm");
    @mkdir("{$tmpdir}/updateutility", 0755);
    build_progress("{uncompress}", 20);
    shell_exec("{$tar} -xf {$tmpfile} -C {$tmpdir}/updateutility/");
    build_progress("{find_source_directory}", 25);
    $dirs = $unix->dirdir("{$tmpdir}/updateutility");
    $SOURCE_DIRECTORY = null;
    while (list($num, $ligne) = each($dirs)) {
        build_progress("{scanning} {$ligne}", 25);
        if (is_file("{$ligne}/UpdateUtility-Console")) {
            $SOURCE_DIRECTORY = $ligne;
            break;
        }
    }
    if ($SOURCE_DIRECTORY == null) {
        echo "Unable to find source directory\n";
        build_progress("{installing} {failed}", 110);
        shell_exec("{$rm} -rf {$tmpdir}/updateutility");
        return;
    }
    echo "Using directory {$SOURCE_DIRECTORY}\n";
    build_progress("{installing}...", 80);
    $cp = $unix->find_program("cp");
    @mkdir("/etc/UpdateUtility", 0755, true);
    shell_exec("{$cp} -rfv {$SOURCE_DIRECTORY}/* /etc/UpdateUtility/");
    shell_exec("{$rm} -rf {$tmpdir}/updateutility");
    if (!is_file("/etc/UpdateUtility/UpdateUtility-Console")) {
        echo "/etc/UpdateUtility/UpdateUtility-Console no such binary\n";
        build_progress("{installing} {failed}", 110);
    }
    build_progress("{installing} {success}", 100);
}
Esempio n. 13
0
function compile_progress()
{
    $unix = new unix();
    build_progress(10, "{build_init_script}");
    initScriptDebian();
    etc_default();
    build_progress(15, "{configure}");
    ParseMimeDefangFilter();
    build_progress(50, "{restarting_artica_status}");
    system("/etc/init.d/artica-status restart --force");
    build_progress(50, "{stopping_service}");
    system("/etc/init.d/mimedefang stop");
    build_progress(80, "{starting_service}");
    system("/etc/init.d/mimedefang start");
    build_progress(90, "{reconfigure_mta}");
    $php = $unix->LOCATE_PHP5_BIN();
    system("{$php} /usr/share/artica-postfix/exec.postfix.maincf.php --milters");
    build_progress(100, "{done}");
}
Esempio n. 14
0
function Start_sync()
{
    build_progress("{restarting}: Saslauthd", 20);
    system('/etc/init.d/saslauthd restart');
    sleep(2);
    build_progress("{restarting}: Cyrus-Imap", 50);
    system('/etc/init.d/cyrus-imapd restart');
    sleep(2);
    build_progress("{restarting}: Postfix", 80);
    system('/etc/init.d/postfix restart');
    sleep(2);
    build_progress("{listing_mailboxes}", 90);
    $cyrus = new cyrus();
    $mbx = $cyrus->ListMailboxes($cn);
    while (list($num, $box) = each($mbx)) {
        echo "Found Mailbox \"{$num}\"\n";
    }
    sleep(10);
    build_progress("{done}", 100);
}
Esempio n. 15
0
function xrun()
{
    $unix = new unix();
    build_progress("{enable_service}", 15);
    $vpn = new openvpn();
    $vpn->main_array["GLOBAL"]["ENABLE_SERVER"] = 1;
    @file_put_contents("/etc/artica-postfix/settings/Daemons/EnableOPenVPNServerMode", 1);
    $vpn->Save(true);
    build_progress("{building_configuration}", 50);
    $php = $unix->LOCATE_PHP5_BIN();
    system("{$php} /usr/share/artica-postfix/exec.openvpn.php --server-conf");
    system("{$php} /usr/share/artica-postfix/exec.initslapd.php --openvpn-server");
    build_progress("{restart_service}", 90);
    system("/etc/init.d/openvpn-server restart");
    $pid = PID_NUM();
    if ($unix->process_exists($pid)) {
        build_progress("{done}", 100);
    } else {
        build_progress("{failed}", 100);
    }
}
function start()
{
    $sock = new sockets();
    $array = unserialize(base64_decode($sock->GET_INFO("WebSiteAnalysis")));
    if (!isset($array["website-analysis"])) {
        $array["website-analysis"] = "http://www.articatech.com";
    }
    build_progress("{website_analysis}:", 20);
    echo "Website: {$array["website-analysis"]}\n";
    if (!is_numeric($array["website-analysis-timeout"])) {
        $array["website-analysis-timeout"] = 2;
    }
    if ($array["website-analysis-timeout"] == 0) {
        $array["website-analysis-timeout"] = 2;
    }
    if ($array["website-analysis-timeout"] > 30) {
        $array["website-analysis-timeout"] = 15;
    }
    $unix = new unix();
    $curl = $unix->find_program("curl");
    $CMDS[] = $curl;
    $CMDS[] = "--show-error --trace-time --trace-ascii /usr/share/artica-postfix/ressources/logs/web/curl.trace";
    $CMDS[] = "--connect-timeout {$array["website-analysis-timeout"]}";
    $urls = parse_url($array["website-analysis"]);
    $scheme = $urls["scheme"];
    if ($scheme == "https") {
    }
    if ($array["website-analysis-address"] != null) {
        $CMDS[] = "--interface {$array["website-analysis-address"]}";
    }
    if ($array["website-analysis-proxy"] != null) {
        $CMDS[] = "--proxy {$array["website-analysis-proxy"]}";
    }
    $CMDS[] = "{$array["website-analysis"]}";
    $cmd = @implode(" ", $CMDS);
    build_progress("{website_analysis}: {connecting}", 50);
    system($cmd);
    build_progress("{website_analysis}: {done}", 100);
    @chmod("/usr/share/artica-postfix/ressources/logs/web/curl.trace", 0755);
}
function run_func()
{
    $unix = new unix();
    $sock = new sockets();
    $SquidNetworkSwitch = $sock->GET_INFO("SquidNetworkSwitch");
    if ($SquidNetworkSwitch == null) {
        run_remove();
        return;
    }
    $unix = new unix();
    if (!$unix->NETWORK_INTERFACE_OK($SquidNetworkSwitch)) {
        echo "{$SquidNetworkSwitch} unavailable\n";
        build_progress("{$SquidNetworkSwitch} {failed}", 110);
        return;
    }
    $NETWORK_ALL_INTERFACES = $unix->NETWORK_ALL_INTERFACES();
    $ipaddr = $NETWORK_ALL_INTERFACES[$SquidNetworkSwitch]["IPADDR"];
    if (!$unix->NETWORK_IS_LISTEN_ADDR_EXISTS($ipaddr)) {
        echo "{$SquidNetworkSwitch} / {$ipaddr} unavailable\n";
        build_progress("{$SquidNetworkSwitch} / {$ipaddr} {failed}", 110);
        return;
    }
    build_progress("{reconfiguring_proxy_service}", 80);
    $f = explode("\n", @file_get_contents("/etc/squid3/squid.conf"));
    while (list($num, $ligne) = each($f)) {
        if (preg_match("#tcp_outgoing_address#", $ligne)) {
            echo "Remove line {$ligne}\n";
            continue;
        }
        $newF[] = $ligne;
    }
    echo "{$SquidNetworkSwitch} -> {$ipaddr}\n";
    $newF[] = "#  Quick Network switch Interface: [{$SquidNetworkSwitch}] [" . date("Y-m-d H:i:s") . "]";
    $newF[] = "tcp_outgoing_address {$ipaddr} all";
    $newF[] = "";
    @file_put_contents("/etc/squid3/squid.conf", @implode("\n", $newF));
    build_progress("{reloading_proxy_service}", 90);
    system("/etc/init.d/squid reload --force --script=" . basename(__FILE__));
    build_progress("{done}", 100);
}
Esempio n. 18
0
function squid_reconfigure_exe()
{
    $unix = new unix();
    $squidbin = $unix->LOCATE_SQUID_BIN();
    build_progress("Reloading Proxy service...", 10);
    $pid = SQUID_PID();
    if ($unix->process_exists($pid)) {
        build_progress("Reloading Proxy service...", 50);
        system("/etc/init.d/squid reload --force --script=exec.squid.reconfigure.php/" . __LINE__);
        sleep(2);
        $sock = new sockets();
        $EnableTransparent27 = intval($sock->GET_INFO("EnableTransparent27"));
        if ($EnableTransparent27 == 1) {
            build_progress("Reloading Proxy NAT service...", 60);
            system("/etc/init.d/squid-nat reload --script=" . basename(__FILE__));
        }
        build_progress("Reloading Proxy service...{done}", 100);
        return;
    }
    echo "Not running !\n";
    build_progress("Reloading Proxy service {failed}...", 110);
}
function startx()
{
    if ($GLOBALS["VERBOSE"]) {
        $GLOBALS["FORCE"] = true;
    }
    $pidFile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $unix = new unix();
    $pid = $unix->get_pid_from_file($pidFile);
    if ($unix->process_exists($pid)) {
        build_progress("Process already running PID {$pid}", 110);
        return;
    }
    @file_put_contents($pidFile, getmypid());
    $php = $unix->LOCATE_PHP5_BIN();
    build_progress("Reconfiguring Proxy service", 10);
    system("{$php} /usr/share/artica-postfix/exec.squid.php --build --force");
    build_progress("{stopping_proxy_service},{please_wait}", 50);
    system("{$php} /usr/share/artica-postfix/exec.squid.watchdog.php --stop --force");
    build_progress("{starting_proxy_service},{please_wait}", 95);
    system("{$php} /usr/share/artica-postfix/exec.squid.watchdog.php --start --force");
    build_progress("{done}", 100);
}
Esempio n. 20
0
function start($aspid = false)
{
    $unix = new unix();
    $sock = new sockets();
    $Masterbin = $unix->find_program("freshclam");
    if (!is_file($Masterbin)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, clamd 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->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;
    }
    $EnableFreshClam = $sock->GET_INFO("EnableFreshClam");
    if (!is_numeric($EnableFreshClam)) {
        $EnableFreshClam = 0;
    }
    if ($EnableFreshClam == 0) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service disabled (see EnableFreshClam/EnableClamavDaemon)\n";
        }
        build_progress(110, "{starting} {APP_FRESHCLAM} {disabled}");
        return;
    }
    $php5 = $unix->LOCATE_PHP5_BIN();
    $nohup = $unix->find_program("nohup");
    $aa_complain = $unix->find_program('aa-complain');
    if (is_file($aa_complain)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} add {$Masterbin} Profile to AppArmor..\n";
        }
        shell_exec("{$aa_complain} {$Masterbin} >/dev/null 2>&1");
    }
    $ClamUser = $unix->ClamUser();
    @chmod("/usr/share/artica-postfix/ressources/logs/web", 0777);
    @mkdir("/var/clamav", 0755, true);
    @mkdir("/var/run/clamav", 0755, true);
    @mkdir("/var/lib/clamav", 0755, true);
    @mkdir("/var/log/clamav", 0755, true);
    $unix->chown_func("{$ClamUser}", "{$ClamUser}", "/var/clamav");
    $unix->chown_func("{$ClamUser}", "{$ClamUser}", "/var/run/clamav");
    $unix->chown_func("{$ClamUser}", "{$ClamUser}", "/var/lib/clamav");
    $unix->chown_func("{$ClamUser}", "{$ClamUser}", "/var/log/clamav");
    if (is_file("/var/log/clamav/freshclam.log")) {
        $unix->chown_func("{$ClamUser}", "{$ClamUser}", "/var/log/clamav/freshclam.log");
    }
    build_progress(71, "{starting} {APP_FRESHCLAM}");
    build();
    build_progress(72, "{starting} {APP_FRESHCLAM}");
    $cmd = "{$nohup} {$Masterbin} --daemon  --config-file=/etc/clamav/freshclam.conf --pid=/var/run/clamav/freshclam.pid --user={$ClamUser} --log=/var/log/clamav/freshclam.log --on-update-execute=/usr/share/artica-postfix/exec.freshclam.updated.php >/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++) {
        build_progress(72 + $i, "{starting} {APP_FRESHCLAM}");
        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;
        }
    }
    build_progress(80, "{starting} {APP_FRESHCLAM}");
    $pid = PID_NUM();
    if ($unix->process_exists($pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Success PID {$pid}\n";
        }
        return true;
    } 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";
        }
        build_progress(110, "{starting} {APP_FRESHCLAM} {failed}");
        return false;
    }
    $pid = PID_NUM();
    if (!$unix->process_exists($pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Failed..\n";
        }
        build_progress(110, "{starting} {APP_FRESHCLAM} {failed}");
    }
}
Esempio n. 21
0
function restore_tables($filename)
{
    $unix = new unix();
    $sock = new sockets();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".restore_tables." . __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]: Nginx Already Artica task running PID {$pid} since {$time}mn\n";
        }
        return;
    }
    $filepath = dirname(__FILE__) . "/ressources/conf/upload/{$filename}";
    if (!is_file($filename)) {
        build_progress("{failed} {$filename} no such file", 110);
        return;
    }
    $tmpf = $unix->FILE_TEMP();
    build_progress("{uncompress} {$filename}", 10);
    if (!$unix->uncompress($filename, $tmpf)) {
        build_progress("{uncompress} {$filename} {failed}", 110);
        return;
    }
    @unlink($filename);
    build_progress("{importing} {$tmpf}", 50);
    $mysql = $unix->find_program("mysql");
    $q = new mysql_squid_builder();
    $cmd = "{$mysql} {$q->MYSQL_CMDLINES} -f squidlogs < {$tmpf}";
    system($cmd);
    build_progress("{done}", 100);
    @unlink($tmpf);
}
Esempio n. 22
0
function build()
{
    $sock = new sockets();
    $q = new mysql();
    $unix = new unix();
    $cntlm = $unix->find_program("cntlm");
    $CnTLMPORT = $sock->GET_INFO("CnTLMPORT");
    $SquidBinIpaddr = $sock->GET_INFO("SquidBinIpaddr");
    $configfile = "/etc/cntlm.conf";
    if ($SquidBinIpaddr == null) {
        $SquidBinIpaddr = "0.0.0.0";
    }
    if (!is_numeric($CnTLMPORT)) {
        $CnTLMPORT = 0;
    }
    if ($CnTLMPORT == 0) {
        $CnTLMPORT = rand(35000, 64000);
        $sock->SET_INFO("CnTLMPORT", $CnTLMPORT);
    }
    $SquidListen = get_squid_listen_ports();
    if (preg_match("#([0-9\\.]+):([0-9]+)#", $SquidListen, $re)) {
        if ($re[2] == $CnTLMPORT) {
            $CnTLMPORT = 0;
        }
    }
    if (preg_match("#([0-9]+)\$#", $SquidListen, $re)) {
        if ($re[2] == $CnTLMPORT) {
            $CnTLMPORT = 0;
        }
    }
    if ($CnTLMPORT == 0) {
        $CnTLMPORT = rand(35000, 64000);
        $sock->SET_INFO("CnTLMPORT", $CnTLMPORT);
    }
    build_progress("Listen port {$CnTLMPORT} -> {$SquidListen}", 60);
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Listen Port...: `{$CnTLMPORT}`\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Proxy to......: `{$SquidListen}`\n";
    }
    if (!is_file("/etc/cntlm.conf.bak")) {
        @copy("/etc/cntlm.conf", "/etc/cntlm.conf.bak");
    }
    $f[] = "{$cntlm} -l 0.0.0.0:{$CnTLMPORT}";
    $f[] = "-g";
    $f[] = "-B";
    $f[] = "-P /var/run/cntlm.pid";
    @file_put_contents("/etc/cntlm.conf", "#\n");
    $f[] = $SquidListen;
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} command line done\n";
    }
    return @implode(" ", $f);
}
Esempio n. 23
0
function xstart()
{
    build_progress("Change settings...", 10);
    $sock = new sockets();
    $unix = new unix();
    $sock->SET_INFO("Enablentopng", 0);
    build_progress("Stopping service..", 15);
    system("/etc/init.d/ntopng stop");
    build_progress("Restarting Artica-Status..", 20);
    system("/etc/init.d/artica-status restart --force");
    build_progress("Remove history..", 50);
    $rm = $unix->find_program("rm");
    system("{$rm} -rf /home/ntopng/*");
    build_progress("{done}", 100);
}
function disk_build_unique_partition($dev, $label, $fs_type = null)
{
    $filelogs = "/usr/share/artica-postfix/ressources/logs/web/system.partition.txt";
    $GLOBALS["FILELOG"] = $filelogs;
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . md5($dev . $label);
    $pid = $unix->get_pid_from_file($pidfile);
    if ($unix->process_exists($pid, basename(__FILE__))) {
        events("Already PID {$pid} exists, aborting...");
        build_progress("Already PID {$pid} exists, aborting", 110);
        return;
    }
    build_progress("{checking}", 5);
    events("***********************************");
    events("Dev.........: {$dev}");
    events("Label.......: {$label}");
    events("FileSystem..: {$fs_type}");
    $mount = $unix->find_program("mount");
    $disk_label = str_replace(" ", "_", $label);
    $targetMountPoint = $unix->isDirInFsTab("/media/{$disk_label}");
    events("Target Mount.: {$targetMountPoint}");
    build_progress("Target Mount point = {$targetMountPoint}", 10);
    events("***********************************");
    if ($targetMountPoint != null) {
        events("/media/{$disk_label} already set in fstab!! remove entry in fstab first...");
        events("Mounting the new media");
        build_progress("Mounting the new media = /media/{$disk_label}", 15);
        $cmd = "{$mount} /media/{$disk_label} 2>&1";
        $results = array();
        exec($cmd, $results);
        while (list($num, $val) = each($results)) {
            events($val);
        }
        build_progress("{success}", 100);
        return;
    }
    $tmpfile = $unix->FILE_TEMP();
    build_progress("Creating disk configuration", 20);
    events("Writing to {$tmpfile}");
    @file_put_contents($tmpfile, ",,L\n");
    if (!is_file($tmpfile)) {
        build_progress("Creating disk configuration {$tmpfile} {failed}", 110);
        return;
    }
    events("Cleaning {$dev}..., please wait...");
    $dd = $unix->find_program("dd");
    $sfdisk = $unix->find_program("sfdisk");
    $mkfs = $unix->find_program("mkfs.ext4");
    $btrfs = $unix->find_program("mkfs.btrfs");
    $xfs = $unix->find_program("mkfs.xfs");
    $mount = $unix->find_program("mount");
    events("{$dev} filesystem {$fs_type}");
    $extV = $fs_type;
    $e2label = $unix->find_program("e2label");
    $e2label_EX = true;
    $MKFS["ext3"] = "-b 4096 -L \"{$disk_label}\"";
    $MKFS["ext4"] = "-L \"{$disk_label}\" -i 8096 -I 256 -Tlargefile4";
    $MKFS["btrfs"] = "--label \"{$disk_label}\"";
    $MKFS["xfs"] = "-f -L \"{$disk_label}\"";
    $MKFS["reiserfs"] = "-q --label \"{$disk_label}\"";
    if ($fs_type == null) {
        $fs_type = "ext4";
    }
    $pgr = $unix->find_program("mkfs.{$fs_type}");
    events("mkfs.{$fs_type} = {$pgr}");
    if (is_file($pgr)) {
        $mkfs = "{$pgr} {$MKFS[$fs_type]} ";
        $extV = "{$fs_type}";
        $e2label_EX = false;
    }
    build_progress("Cleaning {$dev}..., {please_wait}", 30);
    events("Cleaning {$dev}..., please wait...");
    $cmd = "{$sfdisk} -f {$dev} <{$tmpfile} 2>&1";
    events($cmd);
    $results = array();
    exec($cmd, $results);
    while (list($num, $val) = each($results)) {
        events($val);
    }
    $FindFirstPartition = FindFirstPartition($dev);
    events("First partition = `{$FindFirstPartition}`");
    build_progress("First partition {$FindFirstPartition}", 50);
    if ($FindFirstPartition == null) {
        build_progress("Find first partition failed", 110);
        events("First partition = FAILED");
        return;
    }
    build_progress("Building {$FindFirstPartition}..., {please_wait}", 40);
    $cmd = "{$dd} if=/dev/zero of={$FindFirstPartition} bs=512 count=1 2>&1";
    events($cmd);
    $results = array();
    exec($cmd, $results);
    while (list($num, $val) = each($results)) {
        events($val);
    }
    build_progress("Formating {$FindFirstPartition}", 60);
    $cmd = "{$mkfs} {$FindFirstPartition} 2>&1";
    events("Formatting  {$FindFirstPartition}, please wait....");
    events($cmd);
    $results = array();
    exec($cmd, $results);
    while (list($num, $val) = each($results)) {
        events($val);
    }
    if ($e2label_EX) {
        build_progress("Set label to {$disk_label}", 70);
        events("Set label to {$disk_label}");
        $cmd = "{$e2label} {$FindFirstPartition} {$disk_label} 2>&1";
        events($cmd);
        $results = array();
        exec($cmd, $results);
        while (list($num, $val) = each($results)) {
            events($val);
        }
    }
    build_progress("Change fstab {$FindFirstPartition} to /media/{$disk_label}", 80);
    events("Change fstab to include new media {$FindFirstPartition} to /media/{$disk_label}");
    disk_change_fstab($FindFirstPartition, $extV, "/media/{$disk_label}");
    build_progress("Mounting the new media", 90);
    events("Mounting the new media");
    $cmd = "{$mount} {$FindFirstPartition} 2>&1";
    events($cmd);
    $results = array();
    exec($cmd, $results);
    while (list($num, $val) = each($results)) {
        events($val);
    }
    $php = $unix->LOCATE_PHP5_BIN();
    build_progress("Rebuild caches", 95);
    shell_exec("{$php} /usr/share/artica-postfix/exec.usb.scan.write.php");
    build_progress("{success}", 100);
    events("done...");
}
Esempio n. 25
0
function BuildReverse($ligne, $backupBefore = false)
{
    $T1 = time();
    $q = new mysql_squid_builder();
    $unix = new unix();
    $ligne["servername"] = trim($ligne["servername"]);
    $GLOBALS["IPADDRS"] = $unix->NETWORK_ALL_INTERFACES(true);
    $IPADDRS = $GLOBALS["IPADDRS"];
    $DenyConf = $ligne["DenyConf"];
    $ligne["servername"] = trim($ligne["servername"]);
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: [" . __LINE__ . "]  ************* {$ligne["servername"]}:{$ligne["port"]} / {$DenyConf} ************* \n";
    }
    if ($ligne["port"] == 82) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: [" . __LINE__ . "] 82 port is an apache port, SKIP\n";
        build_progress("Bad port {$ligne["servername"]}:82", 110);
        return;
    }
    if ($GLOBALS["REMOVE_LOCAL_ADDR"]) {
        if (isset($IPADDRS[$ligne["servername"]])) {
            build_progress("{$IPADDRS[$ligne["servername"]]} *** SKIPPED ***", 110);
            echo "Starting......: " . date("H:i:s") . " [INIT]: [" . __LINE__ . "]  {$ligne["servername"]} *** SKIPPED ***\n";
            return;
        }
    }
    if ($DenyConf == 1) {
        build_progress("Denied config *** SKIPPED ***", 110);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: [" . __LINE__ . "]  Local web site `{$ligne["servername"]}`, DenyConf = 1,skipped\n";
        }
        return;
    }
    if (isset($ALREADYSET[$ligne["servername"]])) {
        build_progress("Already setup", 110);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: [" . __LINE__ . "]  `{$ligne["servername"]}` Already defined, abort\n";
        }
        return;
    }
    $ListenPort = $ligne["port"];
    $SSL = $ligne["ssl"];
    $certificate = $ligne["certificate"];
    echo "Starting......: " . date("H:i:s") . " [INIT]:  ListenPort..............:{$ListenPort}\n";
    echo "Starting......: " . date("H:i:s") . " [INIT]:  SSL.....................:{$SSL}\n";
    echo "Starting......: " . date("H:i:s") . " [INIT]:  Certificate.............:{$certificate}\n";
    echo "Starting......: " . date("H:i:s") . " [INIT]:  OWA.....................:{$ligne["owa"]}\n";
    if ($ligne["owa"] == 1) {
        $GLOBALS["OUTPUT"] = true;
        $nginx_exchange = new nginx_exchange($ligne["servername"]);
        build_progress("{$ligne["servername"]}: {building} Microsoft Exchange Configuration", 50);
        $nginx_exchange->buildConfig();
        build_progress("{$ligne["servername"]}: {building} Microsoft Exchange Configuration {done}", 70);
        $Took = distanceOfTimeInWords($T1, time(), true);
        nginx_admin_mysql(2, "Success build Microsoft Exchange Configuration configuration for {$ligne["servername"]} took: {$Took}", "Took: {$Took}", __FILE__, __LINE__);
        build_progress("{$ligne["servername"]}: Microsoft Exchange Configuration {done}", 80);
        return true;
    }
    build_progress("{$ligne["servername"]}:{$ListenPort} [SSL:{$SSL}]", 20);
    echo "Starting......: " . date("H:i:s") . " [INIT]: Protect remote web site `{$ligne["servername"]}:{$ListenPort} [SSL:{$SSL}]`\n";
    if ($ligne["servername"] == null) {
        echo "Starting......: " . date("H:i:s") . " [INIT]:  skip it...\n";
        return;
    }
    $cache_peer_id = $ligne["cache_peer_id"];
    if ($cache_peer_id > 0) {
        $ligne2 = mysql_fetch_array($q->QUERY_SQL("SELECT * FROM `reverse_sources` WHERE `ID`='{$cache_peer_id}'"));
    }
    $host = new nginx($ligne["servername"]);
    if ($ListenPort == 80 && $SSL == 1) {
        build_progress("{$ligne["servername"]}: Building HTTP", 40);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]:  HTTP/HTTPS Enabled [" . __LINE__ . "]...\n";
        }
        $host->set_RedirectQueries($ligne["RedirectQueries"]);
        $host->set_forceddomain($ligne2["forceddomain"]);
        $host->set_ssl(0);
        $host->set_mixed_ssl(1);
        $host->set_proxy_port($ligne2["port"]);
        $host->set_listen_port(80);
        $host->set_poolid($ligne["poolid"]);
        $host->set_owa($ligne["owa"]);
        $host->set_storeid($ligne["cacheid"]);
        $host->set_cache_peer_id($cache_peer_id);
        $host->BackupBefore = $backupBefore;
        build_progress("{$ligne["servername"]}: HTTP/HTTPS Enabled", 50);
        $GLOBALS["NGINX_FATAL_ERRORS"] = array();
        if (!$host->build_proxy()) {
            if ($GLOBALS["NGINX_FATAL_ERROR"] != null) {
                nginx_admin_mysql(0, "Fatal error on {$ligne["servername"]} <{$GLOBALS["NGINX_FATAL_ERROR"]}>", "{$GLOBALS["NGINX_FATAL_ERROR"]}\n" . @implode("\n", $GLOBALS["NGINX_FATAL_ERRORS"]));
                echo "***                                             ***\n";
                echo "*** Fatal error {$GLOBALS["NGINX_FATAL_ERROR"]} ***\n";
                echo "***                                             ***\n";
                build_progress("{$ligne["servername"]}: {failed} {$GLOBALS["NGINX_FATAL_ERROR"]}", 110);
                return;
            }
            build_progress("{$ligne["servername"]}: {failed}", 110);
            return;
        }
        if (!$GLOBALS["NO_RELOAD"]) {
            build_progress("{$ligne["servername"]}: {done}", 80);
            return true;
        }
    }
    if ($ligne["ssl"] == 1) {
        echo "Starting......: " . date("H:i:s") . " [INIT]:  SSL Enabled...\n";
        $ligne2["ssl"] = 1;
    }
    if ($ligne["port"] == 443) {
        $ligne2["ssl"] = 1;
    }
    build_progress("{$ligne["servername"]}", 50);
    $host->BackupBefore = $backupBefore;
    $host->set_owa($ligne["owa"]);
    $host->set_RedirectQueries($ligne["RedirectQueries"]);
    $host->set_ssl_certificate($certificate);
    $host->set_ssl_certificate($ligne2["ssl_commname"]);
    $host->set_forceddomain($ligne2["forceddomain"]);
    $host->set_ssl($ligne2["ssl"]);
    $host->set_proxy_port($ligne2["port"]);
    $host->set_listen_port($ligne["port"]);
    $host->set_poolid($ligne["poolid"]);
    $host->set_owa($ligne["owa"]);
    $host->set_storeid($ligne["cacheid"]);
    $host->set_cache_peer_id($cache_peer_id);
    $host->build_proxy();
    if ($GLOBALS["NGINX_FATAL_ERROR"] != null) {
        nginx_admin_mysql(0, "Fatal error on {$ligne["servername"]} <{$GLOBALS["NGINX_FATAL_ERROR"]}>", "{$GLOBALS["NGINX_FATAL_ERROR"]}\n" . @implode("\n", $GLOBALS["NGINX_FATAL_ERRORS"]), __FILE__, __LINE__);
        echo "*** Fatal error {$GLOBALS["NGINX_FATAL_ERROR"]} ***\n";
        build_progress("{$ligne["servername"]}: {failed}", 110);
        return;
    }
    $Took = distanceOfTimeInWords($T1, time(), true);
    nginx_admin_mysql(2, "Success build configuration for {$ligne["servername"]} took: {$Took}", "Took: {$Took}", __FILE__, __LINE__);
    build_progress("{$ligne["servername"]}: {done}", 80);
    return true;
}
function xstart()
{
    $unix = new unix();
    $php = $unix->LOCATE_PHP5_BIN();
    build_progress("{starting} {GLOBAL_ACCESS_CENTER}", 15);
    $extern = new external_acls_squid();
    $extern->Build();
    if (!checkIntegrated()) {
        build_progress("{starting} {GLOBAL_ACCESS_CENTER}", 30);
        $squid_access_manager = new squid_access_manager();
        $squid_access_manager->build_all();
        build_progress("{starting} {GLOBAL_ACCESS_CENTER}", 40);
        $squid = new squidbee();
        $icap = new icap();
        $icap->build_services();
        build_progress("{starting} {reconfigure_proxy_service}", 50);
        system("{$php} /usr/share/artica-postfix/exec.squid.php --build --force");
        if (!checkIntegrated()) {
            build_progress("Missing CONF files:{failed}", 110);
            return;
        }
        build_progress("{done} {GLOBAL_ACCESS_CENTER}", 100);
        return;
    }
    build_progress("{starting} {GLOBAL_ACCESS_CENTER}", 20);
    $external_acls_squid = new external_acls_squid();
    $external_acls_squid->Build();
    build_progress("{starting} {GLOBAL_ACCESS_CENTER}", 30);
    $GLOBALS["aclGen"] = new squid_acls();
    $GLOBALS["aclGen"]->Build_Acls(true);
    $ACLS_TO_ADD = @implode("\n", $GLOBALS["aclGen"]->acls_array);
    @file_put_contents("/etc/squid3/acls_center.conf", $ACLS_TO_ADD);
    build_progress("{starting} {GLOBAL_ACCESS_CENTER}", 50);
    $squid_access_manager = new squid_access_manager();
    $squid_access_manager->build_all();
    build_progress("{starting} {GLOBAL_ACCESS_CENTER}", 55);
    $squid_childs = new squid_childs();
    $squid_childs->build();
    build_progress("{starting} {GLOBAL_ACCESS_CENTER}", 60);
    $squid = new squidbee();
    $q = new squid_freewebs();
    $icap = new icap();
    $icap->build_services();
    build_progress("{starting} {GLOBAL_ACCESS_CENTER}", 60);
    if ($GLOBALS["NOCHECK"]) {
        return true;
    }
    if (!Test_config()) {
        build_progress("{failed}", 90);
        @file_put_contents("/etc/squid3/GlobalAccessManager_auth.conf", "\n");
        @file_put_contents("/etc/squid3/GlobalAccessManager_url_rewrite.conf", "\n");
        @file_put_contents("/etc/squid3/GlobalAccessManager_deny_cache.conf", "\n");
        @file_put_contents("/etc/squid3/icap.conf", "\n");
        build_progress("{failed}", 110);
        return;
    }
    build_progress("{done} {reloading_proxy_service}", 100);
    $squidbin = $unix->find_program("squid");
    system("{$squidbin} -f /etc/squid3/squid.conf -k reconfigure");
}
Esempio n. 27
0
function reconfigure_all()
{
    if ($GLOBALS["VERBOSE"]) {
        echo __FUNCTION__ . "." . __LINE__ . ": OK...\n";
    }
    $unix = new unix();
    $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);
        build_progress("Already executed", 110);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx Already Artica task running PID {$pid} since {$time}mn\n";
        }
        return;
    }
    $php = $unix->LOCATE_PHP5_BIN();
    build_progress("{cleaning_old_configs}...", 5);
    system("{$php} /usr/share/artica-postfix/exec.nginx.wizard.php --check-http");
    if ($GLOBALS["VERBOSE"]) {
        echo __FUNCTION__ . "." . __LINE__ . ": OK...\n";
    }
    build(false);
    $sql = "SELECT servername FROM reverse_www WHERE enabled=1";
    $q = new mysql_squid_builder();
    $results = $q->QUERY_SQL($sql, 'artica_backup');
    if (!$q->ok) {
        build_progress("MySQL Error", 110);
        echo $q->mysql_error . "\n";
        return;
    }
    $start = 10;
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        $start++;
        if ($start > 50) {
            $start = 50;
        }
        $servername = $ligne["servername"];
        build_progress("{$servername}...", $start);
        system("{$php} /usr/share/artica-postfix/exec.nginx.single.php \"{$servername}\" --no-reload --output --no-buildmain");
    }
    $sql = "SELECT servername FROM freeweb WHERE enabled=1";
    $q = new mysql();
    $results = $q->QUERY_SQL($sql, 'artica_backup');
    if (!$q->ok) {
        build_progress("MySQL Error", 110);
        echo $q->mysql_error . "\n";
        return;
    }
    $start = 50;
    $php = $unix->LOCATE_PHP5_BIN();
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        $start++;
        if ($start > 80) {
            $start = 80;
        }
        $servername = $ligne["servername"];
        build_progress("{$servername}...", $start);
        system("{$php} /usr/share/artica-postfix/exec.nginx.single.php \"{$servername}\" --no-reload --output --no-buildmain");
    }
    if ($GLOBALS["VERBOSE"]) {
        echo __FUNCTION__ . "." . __LINE__ . ": OK...\n";
    }
    build_progress("{stopping_service}", 80);
    if ($GLOBALS["VERBOSE"]) {
        echo __FUNCTION__ . "." . __LINE__ . ": OK...\n";
    }
    stop(true);
    build_progress("{starting_service}", 90);
    start(true);
    build_progress("{done}", 100);
    nginx_admin_mysql(2, "Reconfiguring all Web sites done [action=start]", null, __FILE__, __LINE__);
}
Esempio n. 28
0
function xtart()
{
    if (!isset($GLOBALS["ARTICALOGDIR"])) {
        $GLOBALS["ARTICALOGDIR"] = @file_get_contents("/etc/artica-postfix/settings/Daemons/ArticaLogDir");
        if ($GLOBALS["ARTICALOGDIR"] == null) {
            $GLOBALS["ARTICALOGDIR"] = "/var/log/artica-postfix";
        }
    }
    $unix = new unix();
    $binfile = "/usr/share/artica-postfix/bin/seeker";
    if (!is_file($binfile)) {
        build_progress("{failed}", 110);
        events("Unable to stat {$binfile}");
        return;
    }
    $php = $unix->LOCATE_PHP5_BIN();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $pidTime = "/etc/artica-postfix/pids/exec.seeker.php.xtart.time";
    $pid = $unix->get_pid_from_file($pidfile);
    if ($unix->process_exists($pid, basename(__FILE__))) {
        events("Already process executed pid {$pid}");
        return;
    }
    if (system_is_overloaded(basename(__FILE__))) {
        events("Overloaded system, schedule it later", __LINE__);
        $unix->THREAD_COMMAND_SET("{$php} " . __FILE__);
        build_progress("{failed} Overloaded", 110);
        return;
    }
    @file_put_contents($pidfile, getmypid());
    $timefile = $unix->file_time_min($pidTime);
    $DisksBenchs = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/DisksBenchs"));
    $DisksBenchs = $DisksBenchs * 60;
    if (!$GLOBALS["FORCE"]) {
        if ($timefile < $DisksBenchs) {
            events("{$timefile}mn, require at least {$DisksBenchs}mn", __LINE__);
            return;
        }
    }
    @unlink($pidTime);
    @file_put_contents($pidTime, time());
    build_progress("{scanning} {disks}", 10);
    $fdisk = $unix->find_program("fdisk");
    exec("{$fdisk} -l 2>&1", $results);
    $DISKS = array();
    while (list($index, $line) = each($results)) {
        $line = trim($line);
        if ($line == null) {
            continue;
        }
        if (preg_match("#^(Disque|Disk)\\s+\\/([a-zA-Z0-9\\-\\_\\/\\.]+).*?:\\s+[0-9]+.*?(bytes|octets)#", $line, $re)) {
            $DISKS["/" . $re[2]] = true;
        }
    }
    if (count($DISKS) == 0) {
        build_progress("{scanning} {disks} {failed}", 110);
        events("Unable to detect disks");
        $unix->ToSyslog("Unable to detect disks");
        system_admin_events("Unable to detect disks\n" . @implode("\n", $results), __FUNCTION__, __FILE__, __LINE__, "system");
        return;
    }
    $RUN = false;
    while (list($disk, $line) = each($DISKS)) {
        $results = array();
        @chmod("{$binfile}", 0755);
        $cmd = "{$binfile} \"" . trim($disk) . "\" 2>&1";
        build_progress("{scanning} {$disk}", 60);
        events("{$cmd}");
        exec($cmd, $results);
        while (list($index, $line) = each($results)) {
            $line = trim($line);
            echo "***: {$line}\n";
            $md5 = md5("{$disk}" . time());
            if ($line == null) {
                continue;
            }
            if (!preg_match("#^Results:\\s+([0-9]+)\\s+seeks.*?,\\s+([0-9\\.]+)\\s+ms#", $line, $re)) {
                continue;
            }
            $seeks = $re[1];
            $ms = $re[2];
            events("{$disk} {$seeks} seeks, {$ms} ms", __LINE__);
            $array = array();
            @mkdir("{$GLOBALS["ARTICALOGDIR"]}/seeker-queue", 0755, true);
            $array["SEEKS"] = $seeks;
            $array["DISK"] = $disk;
            $array["MS"] = $ms;
            $array["time"] = time();
            $unix->ToSyslog("Bench disk {$disk} {$ms} ms for {$seeks} seeks");
            events("{$GLOBALS["ARTICALOGDIR"]}/seeker-queue/{$md5}.ay", __LINE__);
            @file_put_contents("{$GLOBALS["ARTICALOGDIR"]}/seeker-queue/{$md5}.ay", serialize($array));
            $RUN = true;
            break;
        }
    }
    if ($RUN) {
        $php = $unix->LOCATE_PHP5_BIN();
        $nohup = $unix->find_program("nohup");
        build_progress("{analyze}", 90);
        $cmd = "{$php} " . dirname(__FILE__) . "/exec.syslog-engine.php --seeker";
        events($cmd);
        system($cmd);
    }
    build_progress("{done}", 100);
}
function xstart()
{
    $unix = new unix();
    build_progress("Stamp emergencies to off", 20);
    @file_put_contents("/etc/artica-postfix/settings/Daemons/SquidUrgency", 0);
    @file_put_contents("/etc/artica-postfix/settings/Daemons/SquidUFDBUrgency", 0);
    @file_put_contents("/etc/artica-postfix/settings/Daemons/SquidSSLUrgency", 0);
    @file_put_contents("/etc/artica-postfix/settings/Daemons/LogsWarninStop", 0);
    @file_put_contents("/etc/artica-postfix/settings/Daemons/ActiveDirectoryEmergency", 0);
    @chmod("/etc/artica-postfix/settings/Daemons/SquidUrgency", 0755);
    build_progress("{reconfiguring}", 30);
    $php = $unix->LOCATE_PHP5_BIN();
    system("{$php} /usr/share/artica-postfix/exec.squid.php --build --noreload");
    build_progress("{restarting} {APP_SQUID}", 50);
    system("{$php} /usr/share/artica-postfix/exec.squid.watchdog.php --restart --force --urgency");
    build_progress("{starting} {webfiltering}", 60);
    system("/etc/init.d/ufdb start");
    build_progress("{restarting} Status service", 70);
    system("/etc/init.d/artica-status restart");
    if (is_file("/usr/share/artica-postfix/ressources/databases/ALL_SQUID_STATUS")) {
        @unlink("/usr/share/artica-postfix/ressources/databases/ALL_SQUID_STATUS");
    }
    @unlink("/usr/share/artica-postfix/ressources/logs/web/ufdb.rules_toolbox_left.html");
    build_progress("{done} {APP_SQUID}", 100);
    if ($GLOBALS["META"]) {
        shell_exec("{$php} /usr/share/artica-postfix/exec.artica-meta-client.php --ping --force");
    }
}
Esempio n. 30
0
function stop($aspid = false)
{
    $unix = new unix();
    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 "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service Already Artica task running PID {$pid} since {$time}mn\n";
            }
            return;
        }
        @file_put_contents($pidfile, getmypid());
    }
    $pid = PID_NUM();
    if (!$unix->process_exists($pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service already stopped...\n";
        }
        return;
    }
    $pid = PID_NUM();
    $nohup = $unix->find_program("nohup");
    $php5 = $unix->LOCATE_PHP5_BIN();
    $kill = $unix->find_program("kill");
    if ($GLOBALS["OUTPUT"]) {
        echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service Shutdown pid {$pid}...\n";
    }
    unix_system_kill($pid);
    build_progress("{stopping_service}", 20);
    for ($i = 0; $i < 5; $i++) {
        $pid = PID_NUM();
        if (!$unix->process_exists($pid)) {
            break;
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service waiting pid:{$pid} {$i}/5...\n";
        }
        build_progress("{stopping_service} {$i}/5", 25);
        sleep(1);
    }
    $pid = PID_NUM();
    if (!$unix->process_exists($pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service success...\n";
        }
        return;
    }
    build_progress("{stopping_service}", 30);
    if ($GLOBALS["OUTPUT"]) {
        echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service shutdown - force - pid {$pid}...\n";
    }
    unix_system_kill_force($pid);
    for ($i = 0; $i < 5; $i++) {
        $pid = PID_NUM();
        if (!$unix->process_exists($pid)) {
            break;
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service waiting pid:{$pid} {$i}/5...\n";
        }
        build_progress("{stopping_service} {$i}/5", 35);
        sleep(1);
    }
    if ($unix->process_exists($pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service failed...\n";
        }
        return;
    }
}