function start() { $unix = new unix(); $sock = new sockets(); if (!isset($GLOBALS["MYSQL_BIN_PATH"])) { $GLOBALS["MYSQL_BIN_PATH"] = null; } if (!isset($GLOBALS["mysql_install_db"])) { $GLOBALS["mysql_install_db"] = true; } $pidfile = $GLOBALS["MYPID"]; $WORKDIR = $GLOBALS["WORKDIR"]; $SERV_NAME = $GLOBALS["SERV_NAME"]; $mysql_pid_file = $GLOBALS["MYSQL_PID"]; $MYSQL_SOCKET = $GLOBALS["MYSQL_SOCKET"]; $ArticaDBPath = $sock->GET_INFO("ArticaDBPath"); if ($ArticaDBPath == null) { $ArticaDBPath = "/opt/articatech"; } $GLOBALS["WORKDIR"] = $ArticaDBPath; $GLOBALS["MYSQL_BIN_PATH"] = "{$GLOBALS["WORKDIR"]}/bin/articadb"; $OutputBinLog = $unix->FILE_TEMP(); $mysqlserv = new mysql_services(); $mysqlserv->WORKDIR = $GLOBALS["WORKDIR"]; $mysqlserv->MYSQL_PID_FILE = $mysql_pid_file; $mysqlserv->MYSQL_SOCKET = $MYSQL_SOCKET; $mysqlserv->SERV_NAME = $SERV_NAME; $mysqlserv->TokenParams = "MySQLCatzParams"; $mysqlserv->INSTALL_DATABASE = $GLOBALS["mysql_install_db"]; $mysqlserv->MYSQL_BIN_DAEMON_PATH = $GLOBALS["MYSQL_BIN_PATH"]; $mysqlserv->MYSQL_ERRMSG = $GLOBALS["MYSQL_ERRMSG"]; $mysqlserv->InnoDB = false; $mysqlserv->OutputBinLog = $OutputBinLog; $pid = $unix->get_pid_from_file($pidfile); $EnableWebProxyStatsAppliance = $sock->GET_INFO("EnableWebProxyStatsAppliance"); $DisableArticaProxyStatistics = $sock->GET_INFO("DisableArticaProxyStatistics"); $EnableRemoteStatisticsAppliance = $sock->GET_INFO("EnableRemoteStatisticsAppliance"); $SquidActHasReverse = $sock->GET_INFO("SquidActHasReverse"); if (!is_numeric($EnableWebProxyStatsAppliance)) { $EnableWebProxyStatsAppliance = 0; } if (!is_numeric($EnableRemoteStatisticsAppliance)) { $EnableRemoteStatisticsAppliance = 0; } if (!is_numeric($EnableRemoteStatisticsAppliance)) { $EnableRemoteStatisticsAppliance = 0; } if (!is_numeric($SquidActHasReverse)) { $SquidActHasReverse = 0; } if ($unix->isNGnx()) { $SquidActHasReverse = 0; } $EnableArticaDB = 1; if (is_file('/etc/artica-postfix/WEBSTATS_APPLIANCE')) { $EnableWebProxyStatsAppliance = 1; } if (is_file('/etc/artica-postfix/SQUID_REVERSE_APPLIANCE')) { $EnableArticaDB = 0; } if ($DisableArticaProxyStatistics == 1) { $EnableArticaDB = 0; } if ($EnableRemoteStatisticsAppliance == 1) { $EnableArticaDB = 0; } if ($EnableWebProxyStatsAppliance == 1) { $EnableArticaDB = 1; } if ($SquidActHasReverse == 1) { $EnableArticaDB = 0; } if ($unix->process_exists($pid, basename(__FILE__))) { $time = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Starting Task Already running PID {$pid} since {$time}mn\n"; } return; } @file_put_contents($pidfile, getmypid()); $mysql_install_db = $unix->find_program("mysql_install_db"); if ($EnableArticaDB == 0) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]:{$SERV_NAME} is disabled...\n"; } stop(); die(0); } if ($GLOBALS["MYSQL_BIN_PATH"] != null) { $mysqld = $GLOBALS["MYSQL_BIN_PATH"]; } else { $mysqld = $unix->find_program("mysqld"); } if (!is_file($mysqld)) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]:{$SERV_NAME} is not installed...\n"; } return; } if ($GLOBALS["mysql_install_db"]) { if (!is_file($mysql_install_db)) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]:{$SERV_NAME} mysql_install_db no such binary...\n"; } return; } } $pid = DBPID(); if ($unix->process_exists($pid)) { $time = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]:{$SERV_NAME} MySQL Database Engine already running pid {$pid} since {$time}mn\n"; } return; } if (!is_file("{$GLOBALS["WORKDIR"]}/VERSION")) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$SERV_NAME} Corrupted database, launch updates...\n"; } } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]:{$SERV_NAME} writing init.d\n"; } initd(); $TMP = $unix->FILE_TEMP(); $cmdline = $mysqlserv->BuildParams(); $nohup = $unix->find_program("nohup"); if ($GLOBALS["VERBOSE"]) { echo $cmdline . "\n"; } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]:{$SERV_NAME} Starting MySQL daemon ({$SERV_NAME})\n"; } shell_exec("{$nohup} {$cmdline} >{$TMP} 2>&1 &"); sleep(1); for ($i = 0; $i < 5; $i++) { $pid = DBPID(); if ($unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]:{$SERV_NAME} MySQL daemon ({$SERV_NAME}) started pid .{$pid}..\n"; } break; } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$SERV_NAME} MySQL daemon wait {$i}/5\n"; } sleep(1); } sleep(1); $pid = DBPID(); if (!$unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]:{$SERV_NAME} MySQL daemon ({$SERV_NAME}) failed to start\n"; } $f = explode("\n", @file_get_contents($TMP)); $repair = false; while (list($num, $ligne) = each($f)) { if (trim($ligne) == null) { continue; } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]:{$SERV_NAME} {$ligne}\n"; } } $mysqlserv->CheckOutputErrors($TMP); } else { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]:{$SERV_NAME} MySQL daemon ({$SERV_NAME}) success\n"; } } if (!$unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]:{$SERV_NAME} {$cmdline}\n"; } } $unix->THREAD_COMMAND_SET($unix->LOCATE_PHP5_BIN() . " " . __FILE__ . " --databasesize"); }
function changemysqldir($dir) { $unix = new unix(); $pidfile = "/etc/artica-postfix/pids/squiddbstart.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]: Already task running PID {$pid} since {$time}mn\n"; } return; } @file_put_contents($pidfile, getmypid()); initd(); $dirCMD = $unix->shellEscapeChars($dir); if ($dir == "/opt/squidsql/data") { return; } @mkdir($dir, 0755, true); echo "Stopping Squid-db"; shell_exec("/etc/init.d/squid-db stop"); $Size = $unix->DIRSIZE_BYTES("/opt/squidsql/data"); echo "Copy /home/zarafa-db content to next dir size={$Size}"; $cp = $unix->find_program("cp"); $rm = $unix->find_program("rm"); $ln = $unix->find_program("ln"); shell_exec("{$cp} -rf /opt/squidsql/data/* {$dirCMD}/"); $Size2 = $unix->DIRSIZE_BYTES($dir); if ($Size2 < $Size) { echo "Copy error {$Size2} is less than original size ({$Size})\n"; } echo "Removing old data\n"; shell_exec("{$rm} -rf /opt/squidsql/data"); echo "Create a new symbolic link...\n"; shell_exec("{$ln} -s {$dirCMD} /opt/squidsql/data"); echo "Starting MySQL database engine...\n"; shell_exec("/etc/init.d/squid-db start"); $unix->THREAD_COMMAND_SET($unix->LOCATE_PHP5_BIN() . " " . __FILE__ . " --databasesize"); }
exit; } if (isset($_GET["search-interfaces"])) { interfaces_search(); exit; } if (isset($_GET["ifconfig"])) { ifconfig(); exit; } if (isset($_GET["current"])) { tab_current(); exit; } if (isset($_GET["initd"])) { initd(); exit; } if (isset($_GET["initdajax"])) { initdajax(); exit; } if (isset($_POST["initdcontent"])) { initdcontent(); exit; } tabs(); function tabs() { $users = new usersMenus(); $page = CurrentPageName();
function start($nopid = false) { $unix = new unix(); $SERV_NAME = $GLOBALS["SRV_NAME"]; $pidfile = $GLOBALS["MYPID_PATH"]; if (!$nopid) { $pid = $unix->get_pid_from_file($pidfile); $sock = new sockets(); if ($unix->process_exists($pid, basename(__FILE__))) { $time = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Starting Task Already running PID {$pid} since {$time}mn\n"; } return; } } @file_put_contents($pidfile, getmypid()); if (!is_dir($unix->LOCATE_ROUNDCUBE_WEBFOLDER())) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$SERV_NAME} RoundCube not installed...\n"; } } $sock = new sockets(); $RoundCubeDedicateMySQLServer = $sock->GET_INFO("RoundCubeDedicateMySQLServer"); if (!is_numeric($RoundCubeDedicateMySQLServer)) { $RoundCubeDedicateMySQLServer = 0; } if ($RoundCubeDedicateMySQLServer == 0) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$SERV_NAME} is not Enabled...\n"; } return; } $mysqld = $unix->find_program("mysqld"); if (!is_file($mysqld)) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$SERV_NAME} mysqld no such binary\n"; } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$SERV_NAME} is not installed...\n"; } return; } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$SERV_NAME} writing init.d\n"; } initd(); $WORKDIR = $sock->GET_INFO($GLOBALS["WORK_DIR_TOKEN"]); if ($WORKDIR == null) { $WORKDIR = $GLOBALS["WORK_DIR_DEFAULT"]; } $mysqlserv = new mysql_services(); $mysqlserv->WORKDIR = $WORKDIR; $mysqlserv->MYSQL_PID_FILE = $GLOBALS["PID_PATH"]; $mysqlserv->MYSQL_SOCKET = $GLOBALS["MYSQL_SOCKET"]; $mysqlserv->SERV_NAME = $SERV_NAME; $mysqlserv->TokenParams = $GLOBALS["MYSQL_TOKENS"]; $mysqlserv->InnoDB = false; $TMP = $unix->FILE_TEMP(); $cmdline = $mysqlserv->BuildParams(); $nohup = $unix->find_program("nohup"); if ($GLOBALS["VERBOSE"]) { echo $cmdline . "\n"; } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$SERV_NAME} Starting MySQL daemon\n"; } shell_exec("{$nohup} {$cmdline} >/dev/null 2>&1 &"); sleep(1); for ($i = 0; $i < 10; $i++) { $pid = SERVICEDB_PID(); if ($unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$SERV_NAME} MySQL daemon started pid .{$pid}..\n"; } break; } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$SERV_NAME} MySQL daemon wait {$i}/10\n"; } sleep(1); } $pid = SERVICEDB_PID(); if (!$unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$SERV_NAME} MySQL daemon failed to start\n"; } $f = explode("\n", @file_get_contents($TMP)); while (list($num, $ligne) = each($TMP)) { if (trim($ligne) == null) { continue; } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$SERV_NAME} {$ligne}\n"; } } } if (!$unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$SERV_NAME} {$cmdline}\n"; } } $unix->THREAD_COMMAND_SET($unix->LOCATE_PHP5_BIN() . " " . __FILE__ . " --databasesize"); }
function changemysqldir($dir = null) { if ($dir == "--verbose") { $dir = null; } $sock = new sockets(); $unix = new unix(); $pidfile = "/etc/artica-postfix/pids/squiddbstart.pid"; $pid = $unix->get_pid_from_file($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { $time = $unix->PROCCESS_TIME_MIN($pid); build_progress_changedir("Moving......: [INIT]: Already task running PID {$pid} since {$time}mn", 100); if ($GLOBALS["OUTPUT"]) { echo "Moving......: [INIT]: Already task running PID {$pid} since {$time}mn\n"; } return; } @file_put_contents($pidfile, getmypid()); if ($dir == null) { $dir = $sock->GET_INFO("SquidStatsDatabasePath_change"); } $cp = $unix->find_program("cp"); $rm = $unix->find_program("rm"); $ln = $unix->find_program("ln"); $php = $unix->find_program("php"); echo "Moving......: [INIT]: Change to directory `{$dir}`\n"; if ($dir == null) { build_progress_changedir("No directory specified", 100); return; } $SourceDataPath = $sock->GET_INFO("SquidStatsDatabasePath"); if ($SourceDataPath == null) { $SourceDataPath = "/opt/squidsql"; } $LinkSourceDB = $SourceDataPath . "/data"; $SourceDataPath = "{$SourceDataPath}/data"; if (is_link($SourceDataPath)) { $LinkedSource = @readlink($SourceDataPath); if ($GLOBALS["VERBOSE"]) { echo "LINKED SourceDataPath = {$LinkedSource}\n"; } if (!is_dir("{$LinkedSource}")) { if ($GLOBALS["VERBOSE"]) { echo "{$LinkedSource} No such directory...\n"; } shell_exec("{$rm} -f {$SourceDataPath}"); } else { $SourceDataPath = $LinkedSource; } } build_progress_changedir("Moving to {$dir}", 100); initd(); $dirCMD = $unix->shellEscapeChars($dir); if ($dir == "{$SourceDataPath}/data") { build_progress_changedir("Moving to {$dir} - Not permited", 100); return; } if ($dir == $SourceDataPath) { build_progress_changedir("Moving to {$dir} - Not permited", 100); return; } @mkdir($dir, 0755, true); build_progress_changedir("Calculate disk size", 20); echo "Moving......: [INIT]: Calculate disk size\n"; $Size = $unix->DIRSIZE_BYTES("{$SourceDataPath}"); build_progress_changedir("Squid-db Size: {$Size}", 25); echo "Moving......: [INIT]: Stopping Squid-db Size: {$Size}\n"; build_progress_changedir("Stopping service", 30); system("/etc/init.d/squid-db stop"); build_progress_changedir("Copy data service", 50); echo "Moving......: [INIT]: Copy {$SourceDataPath} content to next dir size={$Size}\n"; if ($GLOBALS["VERBOSE"]) { echo "EXECUTE: {$cp} -rfv {$SourceDataPath}/* {$dirCMD}/\n"; } system("{$cp} -rfv {$SourceDataPath}/* {$dirCMD}/"); $Size2 = $unix->DIRSIZE_BYTES($dir); build_progress_changedir("Next size: {$Size2}", 55); if ($Size2 < $Size) { build_progress_changedir("Copy error {$Size2} is less than original size ({$Size})", 110); echo "Moving......: [INIT]: Copy error {$Size2} is less than original size ({$Size})\n"; return; } build_progress_changedir("Removing old data...", 60); echo "Moving......: [INIT]: Removing old data\n"; if ($GLOBALS["VERBOSE"]) { echo "EXECUTE:{$rm} -rf {$SourceDataPath}\n"; } system("{$rm} -rf {$SourceDataPath}"); if (is_link($LinkSourceDB)) { if ($GLOBALS["VERBOSE"]) { echo "EXECUTE:{$rm} -f {$LinkSourceDB}\n"; } system("{$rm} -f {$LinkSourceDB}"); } build_progress_changedir("Create a new symbolic link", 70); echo "Moving......: [INIT]: Create a new symbolic link...\n"; if ($GLOBALS["VERBOSE"]) { echo "EXECUTE:{$ln} -s {$dirCMD} {$LinkSourceDB}\n"; } system("{$ln} -s {$dirCMD} {$LinkSourceDB}"); build_progress_changedir("Starting MySQL database engine", 80); echo "Moving......: [INIT]: Starting MySQL database engine...\n"; system("/etc/init.d/squid-db start --force"); build_progress_changedir("Calculating size...", 80); $unix->THREAD_COMMAND_SET("{$php} " . __FILE__ . " --databasesize --force"); build_progress_changedir("{done}", 100); }