本文整理汇总了PHP中unix::shellEscapeChars方法的典型用法代码示例。如果您正苦于以下问题:PHP unix::shellEscapeChars方法的具体用法?PHP unix::shellEscapeChars怎么用?PHP unix::shellEscapeChars使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unix
的用法示例。
在下文中一共展示了unix::shellEscapeChars方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: PushToRepo
function PushToRepo($filepath)
{
$curl = "/usr/bin/curl";
$unix = new unix();
$ftpass5 = trim(@file_get_contents("/root/ftp-password5"));
$uri = "ftp://mirror.articatech.net/www.artica.fr/WebfilterDBS";
$size = round(filesize($filepath) / 1024);
$ftpass5 = $unix->shellEscapeChars($ftpass5);
echo "Push {$filepath} ( {$size} KB ) to {$uri}\n";
system("{$curl} -T {$filepath} {$uri}/ --user {$ftpass5}");
}
示例2: DbAttachConverter
function DbAttachConverter(){
$unix=new unix();
$nohup=$unix->find_program("nohup");
$perl=$unix->find_program("perl");
$sqladm=base64_decode($_GET["sqladm"]);
$sqlpass=base64_decode($_GET["mysqlpass"]);
$sqlpass=$unix->shellEscapeChars($sqlpass);
$path=$_GET["path"];
if(!is_dir($path)){@mkdir($path,644,true);}
$cmd="$nohup $perl /usr/share/doc/zarafa/db-convert-attachments-to-files $sqladm $sqlpass zarafa $path delete >/dev/null 2>&1 &";
writelogs_framework($cmd,__FUNCTION__,__FILE__,__LINE__);
shell_exec($cmd);
}
示例3: test_auth
function test_auth()
{
$unix = new unix();
$username = base64_decode($_GET["username"]);
$password = base64_decode($_GET["password"]);
$radtest = $unix->find_program("radtest");
$username = $unix->shellEscapeChars($username);
$password = $unix->shellEscapeChars($password);
$resultsA = "\t\t*********************************\n\t\t*********** FAILED *******************\n\t\t*********************************\n";
$mainpassword = @file_get_contents("/etc/artica-postfix/ldap_settings/password");
$mainpassword = $unix->shellEscapeChars($mainpassword);
$cmdline = "{$radtest} {$username} {$password} localhost 0 {$mainpassword} 2>&1";
writelogs_framework("{$cmdline}", __FUNCTION__, __FILE__, __LINE__);
exec($cmdline, $results);
while (list($num, $ligne) = each($results)) {
if (preg_match("#User-Password#", $ligne, $re)) {
}
if (preg_match("#Access-Accept#", $ligne)) {
$resultsA = "\t\t*********************************\n\t\t*********** SUCCESS ******************\n\t\t*********************************\n";
}
}
$resultsA = str_replace("*", " * ", $resultsA);
echo "<articadatascgi>" . base64_encode($resultsA . @implode("\n", $results)) . "</articadatascgi>";
}
示例4: ChangeRootPassword
function ChangeRootPassword()
{
$unix = new unix();
echo "Give the root password:\n";
$answer = trim(fgets(STDIN));
if ($answer == null) {
echo "No password set\n";
echo "Type Enter key to exit.\n";
$answer = trim(strtolower(fgets(STDIN)));
menu();
return;
}
$password = $unix->shellEscapeChars($answer);
$cmd = "/usr/share/artica-postfix/bin/artica-install --change-mysqlroot --inline \"root\" \"{$password}\"";
echo "Running {$cmd}\n";
system($cmd);
echo "Refresh settings...\n";
system("/usr/share/artica-postfix/bin/process1 --force");
echo "\n\nType Enter key to exit.\n";
$answer = trim(strtolower(fgets(STDIN)));
}
示例5: databasesize
function databasesize($force = false)
{
$unix = new unix();
$sock = new sockets();
$arrayfile = "/usr/share/artica-postfix/ressources/logs/web/{$GLOBALS["SERV_NAME"]}.size.db";
$pidfile = "/etc/artica-postfix/pids/{$GLOBALS["SERV_NAME"]}-databasesize.pid";
if (!$force) {
$pid = $unix->get_pid_from_file($pidfile);
if ($unix->process_exists($pid, basename(__FILE__))) {
$time = $unix->PROCCESS_TIME_MIN($pid);
return;
}
@file_put_contents($pidfile, getmypid());
$time = $unix->file_time_min($arrayfile);
if ($time < 20) {
return;
}
}
$ArticaDBPath = "/home/artica/categories_databases";
$GLOBALS["WORKDIR"] = $ArticaDBPath;
$dir = $GLOBALS["WORKDIR"];
if (is_link($dir)) {
$dir = readlink($dir);
}
$unix = new unix();
$sizbytes = $unix->DIRSIZE_BYTES($dir);
$dir = $unix->shellEscapeChars($dir);
$df = $unix->find_program("df");
$array["DBSIZE"] = $sizbytes / 1024;
exec("{$df} -B K {$dir} 2>&1", $results);
while (list($num, $ligne) = each($results)) {
if (preg_match("#^.*?\\s+([0-9A-Z\\.]+)K\\s+([0-9A-Z\\.]+)K\\s+([0-9A-Z\\.]+)K\\s+([0-9\\.]+)%\\s+(.+)#", $ligne, $re)) {
$array["SIZE"] = $re[1];
$array["USED"] = $re[2];
$array["AIVA"] = $re[3];
$array["POURC"] = $re[4];
$array["MOUNTED"] = $re[5];
break;
}
}
$results = array();
exec("{$df} -i {$dir} 2>&1", $results);
while (list($num, $ligne) = each($results)) {
if (preg_match("#^.*?\\s+([0-9A-Z\\.]+)\\s+([0-9A-Z\\.]+)\\s+([0-9A-Z\\.]+)\\s+([0-9\\.]+)%\\s+(.+)#", $ligne, $re)) {
$array["ISIZE"] = $re[1];
$array["IUSED"] = $re[2];
$array["IAIVA"] = $re[3];
$array["IPOURC"] = $re[4];
break;
}
}
if ($GLOBALS["VERBOSE"]) {
print_r($array);
}
@unlink($arrayfile);
@file_put_contents($arrayfile, serialize($array));
if ($GLOBALS["VERBOSE"]) {
echo "Saving {$arrayfile}...\n";
}
@chmod($arrayfile, 0755);
}
示例6: unix
$T[] = $ligne;
}
@file_put_contents("/root/milter-greylist-database.txt", @implode("\n", $T));
$unix = new unix();
if (!$unix->compress("/root/milter-greylist-database.txt", "/root/milter-greylist-database.gz")) {
die;
}
@unlink("/root/milter-greylist-database.txt");
$md5 = md5_file("/root/milter-greylist-database.gz");
$MAIN["PATTERN"]["TIME"] = time();
$MAIN["PATTERN"]["MD5"] = $md5;
@file_put_contents("/root/milter-greylist-database.txt", serialize($MAIN));
$ftp_serv = @file_get_contents("/root/ftp-hostname");
$ftp_passw = @file_get_contents("/root/ftp-password");
$curl = $unix->find_program("curl");
$ftp_passw = $unix->shellEscapeChars($ftp_passw);
echo "\n ************** FTP WWWW **************\n";
echo "Push to ftp://mirror.articatech.net/www.artica.fr/WebfilterDBS/\n";
$cmdline = "{$curl} -T /root/milter-greylist-database.txt ftp://mirror.articatech.net/www.artica.fr/WebfilterDBS/ --user {$ftp_passw}\n";
echo $cmdline . "\n";
shell_exec("{$curl} -T /root/milter-greylist-database.txt ftp://mirror.articatech.net/www.artica.fr/WebfilterDBS/ --user {$ftp_passw}");
shell_exec("{$curl} -T /root/milter-greylist-database.gz ftp://mirror.articatech.net/www.artica.fr/WebfilterDBS/ --user {$ftp_passw}");
echo "*****************************************************\n";
$q = new mysql();
$sql = "SELECT description,pattern FROM miltergreylist_acls WHERE `method`='blacklist' AND `type`='domain'";
$results = $q->QUERY_SQL($sql, "artica_backup");
while ($ligne = mysql_fetch_assoc($results)) {
$domain = $ligne["pattern"];
if (preg_match("#regex:\\s+#", $domain)) {
continue;
}
示例7: restore_squidlogs
function restore_squidlogs($sourceDir)
{
if (!($handle = opendir("{$sourceDir}/squidlogs"))) {
echo "Failed open {$sourceDir}/squidlogs\n";
return;
}
$password = null;
$unix = new unix();
if (!$unix->is_socket("/var/run/mysqld/squid-db.sock")) {
system_admin_events("Error,/var/run/mysqld/squid-db.sock no such socket", __FUNCTION__, __FILE__, __LINE__);
return false;
}
$sock = new sockets();
$gunzip = $unix->find_program("gunzip");
$mysql = $unix->find_program("mysql");
$BLACKLIST = array();
$nice = $unix->EXEC_NICE();
$q = new mysql_squid_builder();
$sock = new sockets();
$BackupArticaRestoreNetwork = intval($sock->GET_INFO("BackupArticaRestoreNetwork"));
if ($GLOBALS["NOT_RESTORE_NETWORK"]) {
$BackupArticaRestoreNetwork = 0;
}
if ($BackupArticaRestoreNetwork == 0) {
$BLACKLIST["dns_servers.gz"] = true;
$BLACKLIST["dnsmasq_records.gz"] = true;
}
if ($q->mysql_password != null) {
$password = " -p" . $unix->shellEscapeChars($q->mysql_password);
}
$prefix = trim("{$mysql} --force -S /var/run/mysqld/squid-db.sock -u {$q->mysql_admin}{$password} squidlogs");
while (false !== ($filename = readdir($handle))) {
if ($filename == ".") {
continue;
}
if ($filename == "..") {
continue;
}
if (isset($BLACKLIST[$filename])) {
continue;
}
$SourceFile = "{$sourceDir}/squidlogs/{$filename}";
if (is_dir($SourceFile)) {
continue;
}
echo "Restoring Proxy database/{$filename}\n";
$cmd = trim("{$nice} {$gunzip} -c {$SourceFile} |{$prefix}");
system($cmd);
}
}
示例8: disconnect
function disconnect()
{
$unix = new unix();
$user = new settings_inc();
$netbin = $unix->LOCATE_NET_BIN_PATH();
$kdestroy = $unix->find_program("kdestroy");
$sock = new sockets();
$nohup = $unix->find_program("nohup");
$array = unserialize(base64_decode($sock->GET_INFO("KerbAuthInfos")));
if (!isset($array["USE_AUTORID"])) {
$array["USE_AUTORID"] = 1;
}
if (!is_numeric($array["USE_AUTORID"])) {
$array["USE_AUTORID"] = 1;
}
$domainUp = strtoupper($array["WINDOWS_DNS_SUFFIX"]);
$domain_lower = strtolower($array["WINDOWS_DNS_SUFFIX"]);
$adminpassword = $array["WINDOWS_SERVER_PASS"];
$adminpassword = $unix->shellEscapeChars($adminpassword);
$adminpassword = str_replace("'", "", $adminpassword);
$adminname = $array["WINDOWS_SERVER_ADMIN"];
$ad_server = $array["WINDOWS_SERVER_NETBIOSNAME"];
$kdb5_util = $unix->find_program("kdb5_util");
$function = __FUNCTION__;
if (!is_file($netbin)) {
progress_logs(100, "{join_activedirectory_domain}", " net, no such binary");
return;
}
if (!$user->SAMBA_INSTALLED) {
progress_logs(100, "{join_activedirectory_domain}", " Samba, no such software");
return;
}
build_progress_disconnect("Flush Keytab...", 5);
exec("{$netbin} ads keytab flush 2>&1", $results);
build_progress_disconnect("Leave Active Directory...", 10);
exec("{$netbin} ads leave -U {$adminname}%{$adminpassword} 2>&1", $results);
build_progress_disconnect("Destroy Kerberos ticket", 10);
exec("{$kdestroy} 2>&1", $results);
build_progress_disconnect("Destroy Kerberos ticket", 15);
system("{$kdb5_util} -r {$domainUp} -P {$adminpassword} destroy -f");
build_progress_disconnect("Destroy Kerberos ticket", 20);
@unlink("/etc/squid3/PROXY.keytab");
squid_admin_mysql(0, "Active directory disconnected", "An order as been sent to disconnect Active Directory", __FILE__, __LINE__);
build_progress_disconnect("Stamp to not use Active Directory", 50);
$sock->SET_INFO("EnableKerbAuth", 0);
@unlink("/etc/cron.d/artica-ads-watchdog");
@unlink("/etc/cron.daily/msktutil");
build_progress_disconnect("Remove the system from Active Directory", 70);
exec("/usr/share/artica-postfix/bin/artica-install --nsswitch 2>&1", $results);
build_progress_disconnect("Restarting SMB Engine", 70);
exec("/etc/init.d/artica-postfix restart samba 2>&1", $results);
while (list($num, $ligne) = each($results)) {
echo "Leave......: {$ligne}\n";
progress_logs(90, "{join_activedirectory_domain}", "Leave......: {$ligne}");
}
build_progress_disconnect("{reconfiguring_proxy_service}", 80);
$php5 = $unix->LOCATE_PHP5_BIN();
system("{$php5} /usr/share/artica-postfix/exec.squid.php --build --force");
build_progress_disconnect("{done}", 100);
}
示例9: activedirectory_ping
function activedirectory_ping(){
$sock=new sockets();
$unix=new unix();
$filetime="/etc/artica-postfix/pids/".basename(__FILE__).".".__FUNCTION__.".time";
$EnableSambaActiveDirectory=$sock->GET_INFO("EnableSambaActiveDirectory");
if(!is_numeric($EnableSambaActiveDirectory)){return;}
if($EnableSambaActiveDirectory<>1){return;}
$ping_dc=false;
$time=$unix->file_time_min($filetime);
if($time<120){
if(!$GLOBALS["VERBOSE"]){return;}
echo "$filetime ({$time}Mn)\n";
}
$kinit=$unix->find_program("kinit");
$echo=$unix->find_program("echo");
$net=$unix->LOCATE_NET_BIN_PATH();
$wbinfo=$unix->find_program("wbinfo");
$config=unserialize(base64_decode($sock->GET_INFO("SambaAdInfos")));
$domain=strtoupper($config["ADDOMAIN"]);
$domain_lower=strtolower($config["ADDOMAIN"]);
$ADSERVER_IP=$config["ADSERVER_IP"];
$ad_server=strtolower($config["ADSERVER"]);
$kinitpassword=$config["PASSWORD"];
$kinitpassword=$unix->shellEscapeChars($kinitpassword);
$clock_explain="The clock on you system (Linux/UNIX) is too far off from the correct time.\nYour machine needs to be within 5 minutes of the Kerberos servers in order to get any tickets.\nYou will need to run ntp, or a similar service to keep your clock within the five minute window";
$cmd="$echo $kinitpassword|$kinit {$config["ADADMIN"]}@$domain 2>&1";
echo "$cmd\n";
exec("$cmd",$kinit_results);
while (list ($num, $ligne) = each ($kinit_results) ){
if(preg_match("#Clock skew too great while getting initial credentials#", $ligne)){$unix->send_email_events("Active Directory connection clock issue", "kinit program claim\n$ligne\n$clock_explain", "system");}
if($GLOBALS["VERBOSE"]){echo "kinit: $ligne\n";}
}
exec("$wbinfo --ping-dc 2>&1",$ping_dc_results);
while (list ($num, $ligne) = each ($ping_dc_results) ){
if($GLOBALS["VERBOSE"]){echo "ping-dc: $ligne\n";}
if(preg_match("#succeeded#", $ligne)){$ping_dc=true;}
}
@unlink($filetime);
@file_put_contents($filetime, time());
}
示例10: backuptable
function backuptable()
{
$PARAMS = unserialize(base64_decode($_GET["backuptable"]));
$unix = new unix();
$mysqldump = $unix->find_program("mysqldump");
if (!is_file($mysqldump)) {
echo "<articadatascgi>" . base64_encode("ERROR: mysqldump no such binary") . "</articadatascgi>";
return;
}
$t = time();
$tfile = "{$PARAMS["PATH"]}/{$PARAMS["DB"]}.{$PARAMS["TABLE"]}.{$t}.sql";
if (!is_numeric($PARAMS["PORT"])) {
$PARAMS["PORT"] = 3306;
}
$PARAMS["PASS"] = $unix->shellEscapeChars($PARAMS["PASS"]);
@mkdir($PARAMS["PATH"], 0755, true);
$cmd = "{$mysqldump} --user={$PARAMS["ROOT"]} --password={$PARAMS["PASS"]} --port={$PARAMS["PORT"]} --host={$PARAMS["HOST"]} {$PARAMS["DB"]} {$PARAMS["TABLE"]} > {$tfile} 2>&1";
writelogs_framework("{$cmd}", __FUNCTION__, __FILE__, __LINE__);
exec($cmd, $results);
if (!is_file($tfile)) {
echo "<articadatascgi>" . base64_encode("ERROR: mysqldump {$tfile} no such file") . "</articadatascgi>";
return;
}
$filesize = $unix->file_size($tfile);
$filesize = round($filesize / 1024);
echo "<articadatascgi>" . base64_encode("{$tfile} ({$filesize} K) done\n" . @implode("\n", $results)) . "</articadatascgi>";
}
示例11: databasesize
function databasesize($force = false)
{
$sock = new sockets();
$unix = new unix();
$arrayfile = $GLOBALS["DBCACHE_PATH"];
if (!$force) {
$pidfile = $GLOBALS["DATABASE_STATS_PID"];
$pid = $unix->get_pid_from_file($pidfile);
if ($unix->process_exists($pid, basename(__FILE__))) {
$time = $unix->PROCCESS_TIME_MIN($pid);
return;
}
@file_put_contents($pidfile, getmypid());
$time = $unix->file_time_min($arrayfile);
if ($time < 20) {
return;
}
}
$WORKDIR = $sock->GET_INFO($GLOBALS["WORK_DIR_TOKEN"]);
if ($WORKDIR == null) {
$WORKDIR = $GLOBALS["WORK_DIR_DEFAULT"];
}
$dir = $WORKDIR;
if (is_link($dir)) {
$dir = readlink($dir);
}
$unix = new unix();
$sizbytes = $unix->DIRSIZE_BYTES($dir);
$dir = $unix->shellEscapeChars($dir);
$df = $unix->find_program("df");
$array["DBSIZE"] = $sizbytes / 1024;
exec("{$df} -B K {$dir} 2>&1", $results);
while (list($num, $ligne) = each($results)) {
if (preg_match("#^.*?\\s+([0-9A-Z\\.]+)K\\s+([0-9A-Z\\.]+)K\\s+([0-9A-Z\\.]+)K\\s+([0-9\\.]+)%\\s+(.+)#", $ligne, $re)) {
$array["SIZE"] = $re[1];
$array["USED"] = $re[2];
$array["AIVA"] = $re[3];
$array["POURC"] = $re[4];
$array["MOUNTED"] = $re[5];
break;
}
}
$results = array();
exec("{$df} -i {$dir} 2>&1", $results);
while (list($num, $ligne) = each($results)) {
if (preg_match("#^.*?\\s+([0-9A-Z\\.]+)\\s+([0-9A-Z\\.]+)\\s+([0-9A-Z\\.]+)\\s+([0-9\\.]+)%\\s+(.+)#", $ligne, $re)) {
$array["ISIZE"] = $re[1];
$array["IUSED"] = $re[2];
$array["IAIVA"] = $re[3];
$array["IPOURC"] = $re[4];
break;
}
}
if ($GLOBALS["VERBOSE"]) {
print_r($array);
}
@unlink($arrayfile);
@file_put_contents($arrayfile, serialize($array));
if ($GLOBALS["VERBOSE"]) {
echo "Saving {$arrayfile}...\n";
}
@chmod($arrayfile, 0755);
}
示例12: CheckGroup
function CheckGroup($groupname)
{
$unix = new unix();
$wbinfo = $unix->find_program("wbinfo");
$net = $unix->find_program("net");
$groupanecmd = $unix->shellEscapeChars($groupname);
$cmd = "{$net} cache flush";
if ($GLOBALS["VERBOSE"]) {
echo "{$cmd}\n";
}
shell_exec($cmd);
$cmd = "{$wbinfo} --group-info={$groupanecmd} 2>&1";
if ($GLOBALS["VERBOSE"]) {
echo "{$cmd}\n";
}
exec($cmd, $results);
$line = trim(@implode(" ", $results));
if (preg_match("#Could not get info for group#", $line, $re)) {
ufdbguard_admin_events("Failed to lookup users, {$groupname}: {$line}", __FUNCTION__, __FILE__, __LINE__, "activedirectory");
return;
}
if (!preg_match("#^.+?:x:([0-9]+):(.*)#", $line, $re)) {
ufdbguard_admin_events("Failed to lookup users, {$groupname}: {$line}", __FUNCTION__, __FILE__, __LINE__, "activedirectory");
return;
}
$gpid = $re[1];
$userslist = $re[2];
$sql = "DELETE FROM adgroups WHERE gpid={$gpid}";
$q = new mysql();
$q->QUERY_SQL($sql, "artica_backup");
if (!$q->ok) {
ufdbguard_admin_events("Failed to manage, {$groupname}: {$q->mysql_error}", __FUNCTION__, __FILE__, __LINE__, "activedirectory");
return;
}
$groupname = utf8_encode($groupname);
$groupname = addslashes($groupname);
$q->QUERY_SQL("INSERT IGNORE INTO adgroups (gpid,groupname) VALUES ('{$gpid}','{$groupname}')", "artica_backup");
if (!$q->ok) {
ufdbguard_admin_events("Failed to manage, {$groupname}: {$q->mysql_error}", __FUNCTION__, __FILE__, __LINE__, "activedirectory");
return;
}
$q->QUERY_SQL("DELETE FROM adusers WHERE gpid={$gpid}", "artica_backup");
$c = 0;
$f = array();
$usersTR = explode(",", $userslist);
while (list($num, $line) = each($usersTR)) {
if (trim($line) == null) {
continue;
}
$line = utf8_encode($line);
$line = addslashes($line);
$f[] = "('{$gpid}','{$line}')";
$c++;
}
if (count($f) > 0) {
$sql = "INSERT IGNORE INTO adusers(`gpid`,`uid`) VALUES " . @implode(",", $f);
$q->QUERY_SQL($sql, "artica_backup");
if (!$q->ok) {
ufdbguard_admin_events("Failed to import users on {$groupname}: {$q->mysql_error}", __FUNCTION__, __FILE__, __LINE__, "activedirectory");
return;
}
}
$GLOBALS["xxxCOUNT"] = $GLOBALS["xxxCOUNT"] + $c;
}
示例13: loadavg_notif
function loadavg_notif()
{
$array_load = sys_getloadavg();
$internal_load = $array_load[0];
$unix = new unix();
$pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "/pids/" . __FUNCTION__ . ".pid";
$pidTime = "/etc/artica-postfix/pids/" . basename(__FILE__) . "/pids/" . __FUNCTION__ . ".time";
$pid = @file_get_contents($pidfile);
if ($unix->process_exists($pid, basename(__FILE__))) {
writelogs("Already process {$pid} exists", __FUNCTION__, __FILE__, __LINE__);
return;
}
@file_put_contents($pidfile, getmypid());
$time = $unix->file_time_min($pidTime);
if ($time < 5) {
writelogs("Max 1 report each 5 minutes (current {$time}Mn)", __FUNCTION__, __FILE__, __LINE__);
return;
}
@file_put_contents($pidTime, time());
$ps = $unix->find_program("ps");
$tail = $unix->find_program("tail");
$lsof = $unix->find_program("lsof");
$wc = $unix->find_program("wc");
$awk = $unix->find_program("awk");
$grep = $unix->find_program("grep");
$iostat = $unix->find_program("iostat");
exec("{$lsof}|{$wc} -l 2>&1", $locfa);
$lsof_text = "Number of opened files: " . @implode("", $locfa);
exec("{$ps} -elf | {$awk} '{print \$2}' | {$grep} ^Z | {$wc} -l 2>&1", $locfa2);
$zombies_text = "Number of zombies processes: " . @implode("", $locfa2);
if (is_file($iostat)) {
exec("{$iostat} -tmdx 2>&1", $iostata);
$iostata[] = "\nCpu:\n------------------------------\n";
exec("{$iostat} -tmcx 2>&1", $iostata);
$iostat_text = "\n\nIostat report:\n--------------------------\n" . @implode("\n", $iostata);
}
exec("{$ps} aux --sort %cpu|{$tail} -n 20 2>&1", $psaux);
krsort($psaux);
$mysql = new mysql();
$mysqladmin = $unix->find_program("mysqladmin");
if (is_file($mysqladmin)) {
if ($mysql->mysql_server == "localhost" or $mysql->mysql_server == "127.0.0.1") {
$serv = " --socket=/var/run/mysqld/mysqld.sock";
$servtext = "Local";
} else {
$serv = " --host={$mysql->mysql_server} --port={$mysql->mysql_port}";
$servtext = "{$mysql->mysql_server}:{$mysql->mysql_port}";
}
if ($mysql->mysql_password != null) {
$password = " --password=" . $unix->shellEscapeChars($mysql->mysql_password);
}
exec("{$mysqladmin}{$serv} --user={$mysql->mysql_admin}{$password} processlist 2>&1", $mysqladmin_results);
$mysqladmin_text = "Mysql ({$servtext}) processes report:\n---------------------------\n" . @implode("\n", $mysqladmin_results);
}
$text[] = "This is a report that provide system informations about a suspicous system load ({$internal_load})";
$text[] = $lsof_text;
$text[] = "Processes that consume CPU:";
$text[] = "---------------------------";
$text[] = @implode("\n", $psaux);
$text[] = $iostat_text;
$text[] = $mysqladmin_text;
$textfinal = @implode("\n", $text);
$subject = "System notification: Load exceed rule: [{$internal_load}]";
if ($GLOBALS["VERBOSE"]) {
echo "{$subject}\n{$textfinal}\n";
return;
}
$unix->send_email_events($subject, $textfinal, "system");
}
示例14: importActivedirectoryusers
function importActivedirectoryusers()
{
$sock = new sockets();
$EnableKerbAuth = $sock->GET_INFO("EnableKerbAuth");
if (!is_numeric($EnableKerbAuth)) {
$EnableKerbAuth = 0;
}
if ($EnableKerbAuth == 0) {
return;
}
$unix = new unix();
$user = new settings_inc();
$pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".pid";
$pidTime = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".time";
$pid = $unix->get_pid_from_file($pidfile);
if ($unix->process_exists($pid, basename(__FILE__))) {
WriteMyLogs("Process {$pid} already exists", __FUNCTION__, __FILE__, __LINE__);
return;
}
if (system_is_overloaded(basename(__FILE__))) {
WriteMyLogs("Overloaded system, aborting", __FUNCTION__, __FILE__, __LINE__);
return;
}
@file_put_contents($pidfile, getmypid());
$TImeStamp = $unix->file_time_min($pidTime);
if (!$GLOBALS["FORCE"]) {
if ($TImeStamp < 20) {
WriteMyLogs("Need 20mn, current={$TImeStamp}Mn executed by:{$GLOBALS["EXECUTOR"]} Params:{$GLOBALS["PARAMS"]}", __FUNCTION__, __FILE__, __LINE__);
return;
}
}
@unlink($pidTime);
@file_put_contents($pidTime, time());
$netbin = $unix->LOCATE_NET_BIN_PATH();
$usermod = $unix->find_program("usermod");
$chmod = $unix->find_program("chmod");
if (!is_file($netbin)) {
WriteMyLogs("net no such binary, aborting", __FUNCTION__, __FILE__, __LINE__);
return;
}
if (is_dir("/var/run/samba/winbindd_privileged")) {
shell_exec("{$usermod} -G winbindd_priv squid >/dev/null 2>&1");
shell_exec("{$chmod} 0750 /var/run/samba/winbindd_privileged/ >/dev/null 2>&1");
}
$array = unserialize(base64_decode($sock->GET_INFO("KerbAuthInfos")));
$domainUp = strtoupper($array["WINDOWS_DNS_SUFFIX"]);
$domain_lower = strtolower($array["WINDOWS_DNS_SUFFIX"]);
$adminpassword = $array["WINDOWS_SERVER_PASS"];
$adminpassword = $unix->shellEscapeChars($adminpassword);
$adminname = $array["WINDOWS_SERVER_ADMIN"];
$ad_server = $array["WINDOWS_SERVER_NETBIOSNAME"];
$GLOBALS["AUTHCMD"] = " -U {$adminname}%{$adminpassword}";
getNetInfos();
if (!isset($GLOBALS["LDAP_HOST"])) {
WriteMyLogs("Unable to get ldap infos, aborting", __FUNCTION__, __FILE__, __LINE__);
return;
}
GetUsersArray();
}
示例15: RestoreFromBackup
//.........这里部分代码省略.........
RestoreFromBackup_progress("zarafa-db.sock no such socket", 100);
return;
}
echo "Action: /var/run/mysqld/zarafa-db.sock OK\n";
echo "Action: create a freshed Zarafa database\n";
$ZarafaIndexPath = $sock->GET_INFO("ZarafaIndexPath");
if ($ZarafaIndexPath == null) {
$ZarafaIndexPath = "/var/lib/zarafa/index";
}
RestoreFromBackup_progress("Cleaning/Stopping Zarafa search DBs", 50);
if (is_dir($ZarafaIndexPath)) {
recursive_remove_directory("{$ZarafaIndexPath}");
shell_exec("/etc/init.d/zarafa-search stop");
}
RestoreFromBackup_progress("Create a freshed Zarafa database", 50);
$results = array();
$cmd = "{$mysql} --socket=/var/run/mysqld/zarafa-db.sock --protocol=socket --user=root --batch --debug-info --execute=\"CREATE DATABASE zarafa\" 2>&1";
$results = array();
exec("{$cmd}", $results);
while (list($num, $ligne) = each($results)) {
echo "MySQL: (Create Database) {$ligne}\n";
}
RestoreFromBackup_progress("Testing Database...", 51);
if (!is_dir("{$WORKDIR}/data/zarafa")) {
echo "Action: FAILED TO create a freshed Zarafa database: ABORT!!\n";
echo "Action: {$WORKDIR}/data/zarafa no such directory\n";
RestoreFromBackup_progress("FAILED to create a freshed Zarafa database", 100);
return;
}
RestoreFromBackup_progress("Checks Database size", 53);
databasesize(true);
$gunzip = $unix->find_program("gunzip");
$SourceFileBase = basename($backuppath);
$file_ext = $unix->file_ext($SourceFileBase);
$tStart = time();
$nohup = $unix->find_program("nohup");
$backuppath1 = $unix->shellEscapeChars($backuppath);
$cmd = "{$nohup} {$mysql} --show-warnings --socket=/var/run/mysqld/zarafa-db.sock --protocol=socket --user=root --batch --debug-info --database=zarafa < {$backuppath1} >/root/mysqllog.txt 2>&1 &";
echo "Action: {$SourceFileBase} extension {$file_ext}\n";
echo "Action: Restoring From {$backuppath1}\n";
if ($file_ext == "gz") {
echo "Action: Restoring From {$backuppath1} with uncompress..\n";
$cmd = "{$nohup} {$gunzip} -c {$backuppath1} |{$mysql} --show-warnings --socket=/var/run/mysqld/zarafa-db.sock --protocol=socket --user=root --batch --debug-info --database=zarafa >/root/mysqllog.txt 2>&1 &";
}
$size = @filesize($backuppath);
$size = FormatBytes($size / 1024);
echo "Action: Please wait, it should take time...\nAction: Do not shutdown the computer or restart the MySQL service!\n";
$results = array();
RestoreFromBackup_progress("{restoring_data} {$size} {please_wait} !", 70);
$lastmd5 = null;
$continue = true;
shell_exec($cmd);
$ALRDLO = array();
while ($continue) {
$fileMD5 = @md5_file("/root/mysqllog.txt");
if ($fileMD5 != $lastmd5) {
$LOGS = explode("\n", @file_get_contents("/root/mysqllog.txt"));
while (list($num, $ligne) = each($LOGS)) {
if (trim($ligne) == null) {
continue;
}
if (isset($ALRDLO[md5($ligne)])) {
continue;
}
$ALRDLO[md5($ligne)] = true;
if (preg_match("#ERROR\\s+([0-9]+)\\s+\\(#", $ligne, $re)) {
echo date("Y-m-d H:i:s") . " MySQL: FAILED !!! {$ligne}\n";
RestoreFromBackup_progress("{failed} {error} {$re[1]} ", 100);
return;
}
echo date("Y-m-d H:i:s") . " MySQL: {$ligne}\n";
}
$lastmd5 = $fileMD5;
}
$pid = $unix->PIDOF_PATTERN("{$mysql}\\s+.*?--socket=/var/run/mysqld/zarafa-db.sock.*?database=zarafa");
echo "Action: PID: {$pid}\n";
if (!$unix->process_exists($pid)) {
echo "Action: injection stopped running since " . $unix->distanceOfTimeInWords($tStart, time(), true) . "\n";
$continue = false;
break;
}
echo "Action: PID {$pid} running since " . $unix->distanceOfTimeInWords($tStart, time(), true) . ", please wait...\n";
RestoreFromBackup_progress($unix->distanceOfTimeInWords($tStart, time(), true) . " {please_wait} !", 71);
$continue = true;
sleep(30);
continue;
}
echo "Action: Done, took: " . $unix->distanceOfTimeInWords($tStart, time(), true) . "\n";
echo "Action: Please wait, Checks Database size\n";
RestoreFromBackup_progress("Checks Database size", 75);
databasesize(true);
RestoreFromBackup_progress("{restoring_data} {success}", 80);
echo "Action: restart_services\n";
RestoreFromBackup_progress("{restart_services}", 90);
$unix->THREAD_COMMAND_SET("/etc/init.d/zarafa-server restart");
echo "Action: Restore task done...\n";
echo "Action: You can close the windows now...\n";
RestoreFromBackup_progress("{done}", 100);
die;
}