function restart_progress() { build_progress_rs("{checking_configuration}", 10); Checks(); build_progress_rs("{stopping_service}", 35); system("/etc/init.d/autofs stop"); build_progress_rs("{starting_service}", 40); system("/etc/init.d/autofs start"); build_progress_rs("{restarting_artica_status}", 50); system("/etc/init.d/artica-status restart --force"); build_progress_rs("{done}", 100); }
function GetMyIp(){ Checks(); $sock=new sockets(); if($sock->GET_INFO("DoNotResolvInternetIP")==1){ $ip=$sock->GET_INFO("PublicIPAddress"); if($ip<>null){return $ip;} } $time=file_time_min("/usr/share/artica-postfix/ressources/logs/web/myIP.conf"); if($time<60){ return trim(@file_get_contents("/usr/share/artica-postfix/ressources/logs/web/myIP.conf")); } @unlink("/usr/share/artica-postfix/ressources/logs/web/myIP.conf"); include_once("HTTP/Request.php"); include_once('Net/DNSBL.php'); $ini=new Bs_IniHandler(); $sock=new sockets(); $datas=$sock->GET_INFO("ArticaProxySettings"); $ini->loadString($datas); $ArticaProxyServerEnabled=$ini->_params["PROXY"]["ArticaProxyServerEnabled"]; $ArticaProxyServerName=$ini->_params["PROXY"]["ArticaProxyServerName"]; $ArticaProxyServerPort=$ini->_params["PROXY"]["ArticaProxyServerPort"]; $ArticaProxyServerUsername=$ini->_params["PROXY"]["ArticaProxyServerUsername"]; $ArticaProxyServerUserPassword=$ini->_params["PROXY"]["ArticaProxyServerUserPassword"]; $ArticaCompiledProxyUri=$ini->_params["PROXY"]["ArticaCompiledProxyUri"]; $req =new HTTP_Request("http://www.artica.fr/my-ip.php"); $req->setURL("http://www.artica.fr/my-ip.php"); $req->setMethod(HTTP_REQUEST_METHOD_GET); if($ArticaProxyServerEnabled=="yes"){ $req->setProxy($ArticaProxyServerName, $ArticaProxyServerPort, $ArticaProxyServerUsername, $ArticaProxyServerUserPassword); } $req->sendRequest(); $code = $req->getResponseCode(); $datas= trim($req->getResponseBody()); if(preg_match("#([0-9\.]+)#",$datas,$re)){ $myip=$re[1]; writelogs("http://www.artica.fr/my-ip.php -> $code ($datas)"); } if($myip<>null){ @file_put_contents("/usr/share/artica-postfix/ressources/logs/web/myIP.conf",$myip); @chmod("/usr/share/artica-postfix/ressources/logs/web/myIP.conf",775); $sock->SET_INFO("PublicIPAddress",$myip); } }
function build() { $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $pid = @file_get_contents($pidfile); $unix = new unix(); if ($unix->process_exists($pid)) { echo "Starting......: " . date("H:i:s") . " Already process exists pid {$pid}\n"; return; } @file_put_contents($pidfile, getmypid()); $php = $unix->LOCATE_PHP5_BIN(); if (system_is_overloaded()) { $unix->THREAD_COMMAND_SET("{$php} " . __FILE__ . " --build"); return; } patch_grub_default(); $sock = new sockets(); $q = new mysql(); $sql = "SELECT * FROM users_containers WHERE created=0 AND onerror=0"; $results = $q->QUERY_SQL($sql, "artica_backup"); $count = mysql_num_rows($results); if (!$q->ok) { echo "Starting......: " . date("H:i:s") . " users_containers {$q->mysql_error}\n"; return; } echo "Starting......: " . date("H:i:s") . " {$count} containers to build\n"; if ($count > 0) { while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) { $directory = trim($ligne["directory"]); $ID = $ligne["container_id"]; if ($directory == null) { users_containers_error($ID, "No specified main directory..."); continue; } $directory_size_avai = $unix->DIRECTORY_FREEM($directory); if ($directory_size_avai == 0) { users_containers_error($ID, "no space left on specified directory"); continue; } @mkdir($directory, 0755, true); if (!is_dir($directory)) { users_containers_error($ID, "Permission denied on specified directory"); continue; } $ContainerFullPath = $directory . "/{$ID}.disk"; $size = $ligne["container_size"]; if ($size > $directory_size_avai) { users_containers_error($ID, "{$size}MB will exceed space on main storage"); continue; } $label = "{$ID}_disk"; echo "Starting......: " . date("H:i:s") . " Verify {$ContainerFullPath} with a size of {$size}MB\n"; if (!stat_system($ContainerFullPath)) { echo "Starting......: " . date("H:i:s") . " buil_dd {$ContainerFullPath} {$size}MB\n"; if (!build_dd($ContainerFullPath, $size)) { users_containers_error($ID, "Unable to build the virtual disk (ERR." . __LINE__ . ")"); continue; } } $GetLoops = GetLoops(); if (!stat_system($ContainerFullPath)) { users_containers_error($ID, "Unable to build the virtual disk (ERR." . __LINE__ . ")"); continue; } if ($GetLoops[$ContainerFullPath] == null) { echo "Starting......: " . date("H:i:s") . " {$ContainerFullPath} no such loop\n"; if (!build_loop($ContainerFullPath)) { echo "`{$ContainerFullPath}` unable to create loop\n"; echo "Starting......: " . date("H:i:s") . " Re-check the loop list...\n"; $GetLoops = GetLoops(); if ($GetLoops[$ContainerFullPath] == null) { users_containers_error($ID, "Loop error (ERR." . __LINE__ . ")"); continue; } } } echo "Starting......: " . date("H:i:s") . " {$ContainerFullPath} loop={$GetLoops[$ContainerFullPath]}\n"; $sql = "UPDATE users_containers SET loop_dev='{$GetLoops[$ContainerFullPath]}' WHERE `container_id`='{$ID}'"; $q->QUERY_SQL($sql, 'artica_backup'); if (!$q->ok) { echo "{$q->mysql_error}\n"; continue; } $dev = $GetLoops[$ContainerFullPath]; echo "Starting......: " . date("H:i:s") . " {$ContainerFullPath} is {$dev}\n"; if (!ifFileSystem($dev)) { if (!mke2fs($dev, $label)) { users_containers_error($ID, "mke2fs error (ERR." . __LINE__ . ")"); continue; } } $uuid = Getuuid($dev); echo "Starting......: " . date("H:i:s") . " {$dev} uuid={$uuid}\n"; $q->QUERY_SQL("UPDATE users_containers SET uuid='{$uuid}' WHERE `container_id`='{$ID}'", 'artica_backup'); if ($uuid == null) { continue; } $q->QUERY_SQL("UPDATE users_containers SET created='1' WHERE `container_id`='{$ID}'", 'artica_backup'); } } @mkdir("/media/artica_containers/membersdisks", 0755, true); $q = new mysql(); $sql = "SELECT * FROM users_containers WHERE created=1 AND onerror=0"; $results = $q->QUERY_SQL($sql, "artica_backup"); $count = mysql_num_rows($results); $mount = $unix->find_program("mount"); $umount = $unix->find_program("umount"); while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) { $directory = trim($ligne["directory"]); $mkfs_ext4 = $unix->find_program("mkfs.ext4"); $typ = "ext4"; if (!is_file($mkfs_ext4)) { $typ = "ext3"; } $ID = $ligne["container_id"]; $ContainerFullPath = $directory . "/{$ID}.disk"; if (!is_file($ContainerFullPath)) { echo "Starting......: " . date("H:i:s") . " {$ContainerFullPath} no such file\n"; } $autofs[] = "disk{$ID}\t-fstype={$typ},loop\t:{$ContainerFullPath}"; } echo "Starting......: " . date("H:i:s") . " Saving /etc/auto.members\n"; @file_put_contents("/etc/auto.members", implode("\n", $autofs) . "\n"); @unlink("/etc/init.d/artica-containers"); patch_auto_master(); shell_exec("/etc/init.d/autofs reload"); $unix = new unix(); $php5 = $unix->LOCATE_PHP5_BIN(); $SquidPerformance = intval($sock->GET_INFO("SquidPerformance")); shell_exec("{$php5} /usr/share/artica-postfix/exec.initslapd.php --iscsi"); if (is_file("/etc/init.d/iscsitarget")) { $unix->THREAD_COMMAND_SET("/etc/init.d/iscsitarget restart"); } Checks(true); }
function GetMyIp() { $sock = new sockets(); $unix = new unix(); $EnableArticaMetaClient = intval($sock->GET_INFO("EnableArticaMetaClient")); if ($EnableArticaMetaClient == 1) { return; } if ($sock->GET_INFO("DoNotResolvInternetIP") == 1) { $ip = $sock->GET_INFO("PublicIPAddress"); if ($ip != null) { return $ip; } } if (!$GLOBALS["FORCE"]) { $time = $unix->file_time_min("/usr/share/artica-postfix/ressources/logs/web/myIP.conf"); if ($time < 60) { return trim(@file_get_contents("/usr/share/artica-postfix/ressources/logs/web/myIP.conf")); } } Checks(); $URIBASE = $unix->MAIN_URI(); @unlink("/usr/share/artica-postfix/ressources/logs/web/myIP.conf"); $curl = new ccurl("{$URIBASE}/my-ip.php"); $curl->NoHTTP_POST = true; if (!$curl->get()) { system_admin_events("Curl error {$curl->error}", __FUNCTION__, __FILE__, __LINE__, "system"); return; } $datas = explode("\n", $curl->data); $myip = null; writelogs("http://www.articatech.net/my-ip.php -> ({$datas})", __FUNCTION__, __FILE__, __LINE__); while (list($num, $val) = each($datas)) { if (preg_match("#^(.*?):#", $val, $re)) { continue; } if (preg_match("#([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+)#", $val, $re)) { $myip = "{$re[1]}.{$re[2]}.{$re[3]}.{$re[4]}"; break; } } if ($myip == null) { system_admin_events("!!! Unable to preg_match datas....", __FUNCTION__, __FILE__, __LINE__, "system"); return; } writelogs("FOUND \"{$myip}\" -> {$URIBASE}/my-ip.php -> {$code} (" . count($datas) . " lines)", __FUNCTION__, __FILE__, __LINE__); @file_put_contents("/usr/share/artica-postfix/ressources/logs/web/myIP.conf", $myip); @chmod("/usr/share/artica-postfix/ressources/logs/web/myIP.conf", 775); system_admin_events("Public IP Address: {$myip}", __FUNCTION__, __FILE__, __LINE__, "system"); $sock->SET_INFO("PublicIPAddress", $myip); }