function winbindd_ping() { $smbcontrol = $GLOBALS["CLASS_UNIX"]->find_program('smbcontrol'); shell_exec2("{$GLOBALS["CHMOD"]} 0750 /var/lib/samba/winbindd_privileged >/dev/null 2>&1"); $results = exec("{$smbcontrol} winbindd ping 2>&1"); if (preg_match("#No replies received#i", $results)) { Winbindd_events("Winbindd service ping failed", "winbindd_ping", "winbindd_ping", __LINE__); $GLOBALS["CLASS_UNIX"]->send_email_events("Winbindd service ping failed", "Winbindd failed to answer with error: {$results}\nArtica will try to restart it", "samba"); shell_exec2("{$GLOBALS["nohup"]} /etc/init.d/winbind restart --force >/dev/null 2>&1 &"); } }
function restart() { if (!is_run()) { echo "Starting......: " . date("H:i:s") . " WINBIND (restart) not running, start it...\n"; Winbindd_events("Winbindd (restart) not running, start it", __FUNCTION__, __LINE__); start(true); return; } $unix = new unix(); $php5 = $unix->LOCATE_PHP5_BIN(); $filetime = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time"; $time = $unix->file_time_min($filetime); Winbindd_events("Winbindd ask to restart since {$time}Mn", __FUNCTION__, __LINE__); if (!$GLOBALS["FORCE"]) { if ($time < 59) { $pid = WINBIND_PID(); if ($unix->process_exists($pid)) { $timepid = $unix->PROCESS_TTL($pid); echo "Starting......: " . date("H:i:s") . " WINBIND ask to restart need to wait 60Mn pid:{$pid} {$timepid}\n"; Winbindd_events("Winbindd ask to restart need to wait 60Mn pid:{$pid} {$timepid}", __FUNCTION__, __LINE__); return; } else { echo "Starting......: " . date("H:i:s") . " WINBIND (restart) not running, start it...\n"; shell_exec("{$php5} /usr/share/artica-postfix/exec.winbindd.php --start"); } } } @unlink($filetime); @file_put_contents($filetime, time()); $smbcontrol = $unix->find_program("smbcontrol"); $chmod = $unix->find_program("chmod"); $settings = new settings_inc(); DirsPrivileges(); if (!$GLOBALS["FORCE"]) { if (is_file($smbcontrol)) { Winbindd_events("Winbindd reloading", __FUNCTION__, __LINE__); echo "Starting......: " . date("H:i:s") . " WINBIND reloading...\n"; shell_exec("{$smbcontrol} winbindd reload-config"); shell_exec("{$smbcontrol} winbindd offline"); shell_exec("{$smbcontrol} winbindd online"); setfacl_squid(); return; } } Winbindd_events("Winbindd stop", __FUNCTION__, __LINE__); stop(); Winbindd_events("Winbindd ask to start", __FUNCTION__, __LINE__); start(true); }
function winbindd() { if (!$GLOBALS["CLASS_USERS"]->WINBINDD_INSTALLED) { if ($GLOBALS["VERBOSE"]) { echo __FUNCTION__ . " not installed\n"; } return null; } if (is_file("/etc/artica-postfix/WORDPRESS_APPLIANCE")) { $master_pid = winbind_pid(); if (!$GLOBALS["CLASS_UNIX"]->process_exists($master_pid)) { shell_exec("/etc/init.d/winbind stop"); } } if (!$GLOBALS["CLASS_USERS"]->SAMBA_INSTALLED) { if ($GLOBALS["VERBOSE"]) { echo __FUNCTION__ . " not installed\n"; } $master_pid = winbind_pid(); if (!$GLOBALS["CLASS_UNIX"]->process_exists($master_pid)) { shell_exec("/etc/init.d/winbind stop"); } return null; } $enabled = $GLOBALS["CLASS_SOCKETS"]->GET_INFO("SambaEnabled"); $DisableWinbindd = $GLOBALS["CLASS_SOCKETS"]->GET_INFO("DisableWinbindd"); $DisableSambaFileSharing = $GLOBALS["CLASS_SOCKETS"]->GET_INFO("DisableSambaFileSharing"); $EnableSambaActiveDirectory = $GLOBALS["CLASS_SOCKETS"]->GET_INFO("EnableSambaActiveDirectory"); $AsCategoriesAppliance = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/AsCategoriesAppliance")); $squid = $GLOBALS["CLASS_UNIX"]->LOCATE_SQUID_BIN(); if (is_file($squid)) { $EnableKerbAuth = $GLOBALS["CLASS_SOCKETS"]->GET_INFO("EnableKerbAuth"); $EnableKerberosAuthentication = $GLOBALS["CLASS_SOCKETS"]->GET_INFO("EnableKerberosAuthentication"); if (!is_numeric("{$EnableKerberosAuthentication}")) { $EnableKerberosAuthentication = 0; } if (!is_numeric($EnableKerbAuth)) { $EnableKerbAuth = 0; } if ($EnableKerbAuth == 1) { $DisableWinbindd = 0; } } if (!is_numeric($EnableSambaActiveDirectory)) { $EnableSambaActiveDirectory = 0; } if (!is_numeric($DisableWinbindd)) { $DisableWinbindd = 0; } if (!is_numeric($enabled)) { $enabled = 1; } if ($AsCategoriesAppliance == 1) { $DisableWinbindd = 1; $enabled = 0; } if ($GLOBALS["VERBOSE"]) { echo "enabled.................................: {$enabled}\n"; echo "DisableWinbindd.........................: {$DisableWinbindd}\n"; echo "EnableSambaActiveDirectory..............: {$EnableSambaActiveDirectory}\n"; } if (!$GLOBALS["DISABLE_WATCHDOG"]) { shell_exec2("{$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.samba.php --ping-ads &"); } if ($EnableSambaActiveDirectory == 1) { $DisableWinbindd = 0; } $smbcontrol = $GLOBALS["CLASS_UNIX"]->find_program('smbcontrol'); if ($DisableWinbindd == 1) { $enabled = 0; } if ($DisableSambaFileSharing == 1) { if ($EnableSambaActiveDirectory == 0) { $enabled = 0; } } $pid_path = $GLOBALS["CLASS_UNIX"]->LOCATE_WINBINDD_PID(); $master_pid = winbind_pid(); if (!$GLOBALS["CLASS_UNIX"]->process_exists($master_pid)) { $nmbd_bin = $GLOBALS["CLASS_UNIX"]->find_program("winbindd"); if ($GLOBALS["VERBOSE"]) { echo "pid path \"{$pid_path}\" no pid found\n"; } $master_pid = $GLOBALS["CLASS_UNIX"]->PIDOF($nmbd_bin); if ($GLOBALS["VERBOSE"]) { echo "pid:{$master_pid} after pidof\n"; } if (is_file($pid_path)) { if (!$GLOBALS["DISABLE_WATCHDOG"]) { if ($GLOBALS["VERBOSE"]) { echo "write {$master_pid} in \"{$pid_path}\"\n"; } if ($master_pid > 1) { @file_put_contents($pid_path, $master_pid); } } } } if ($GLOBALS["VERBOSE"]) { echo "enabled.................................: {$enabled}\n"; echo "DisableWinbindd.........................: {$DisableWinbindd}\n"; echo "EnableSambaActiveDirectory..............: {$EnableSambaActiveDirectory}\n"; } $l[] = "[SAMBA_WINBIND]"; $l[] = "service_name=APP_SAMBA_WINBIND"; $l[] = "master_version=" . samba_version(); $l[] = "service_cmd=samba"; $l[] = "service_disabled={$enabled}"; $l[] = "pid_path={$pid_path}"; $l[] = "remove_cmd=--samba-remove"; $l[] = "family=storage"; if (!$GLOBALS["CLASS_UNIX"]->process_exists($master_pid)) { if ($enabled == 1) { Winbindd_events("Winbindd service Failed -> start it", __FUNCTION__, __LINE__); if (!$GLOBALS["DISABLE_WATCHDOG"]) { shell_exec2("{$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.winbindd.php --start"); } } $l[] = "running=0\ninstalled=1"; $l[] = ""; return implode("\n", $l); return; } if (!$GLOBALS["DISABLE_WATCHDOG"]) { if ($enabled == 1) { if (strlen($smbcontrol) > 3) { winbindd_ping(); } } } $l[] = "running=1"; $l[] = GetMemoriesOf($master_pid); $l[] = ""; shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["PHP5"]} " . dirname(__FILE__) . "/exec.adusers.php --computers schedule-id=0 >/dev/null 2>&1 &"); return implode("\n", $l); return; }