function build($nopid = false) { if (isset($GLOBALS["BUILD_EXECUTED"])) { progress_logs(20, "{continue}", "Already executed"); return; } $GLOBALS["BUILD_EXECUTED"] = true; $unix = new unix(); $sock = new sockets(); $function = __FUNCTION__; $EnableKerbAuth = $sock->GET_INFO("EnableKerbAuth"); if (!is_numeric($EnableKerbAuth)) { $EnableKerbAuth = 0; } if ($EnableKerbAuth == 0) { progress_logs(110, "{authentication_via_activedirectory_is_disabled}", "{authentication_via_activedirectory_is_disabled}"); if (is_file("/etc/monit/conf.d/winbindd.monitrc")) { @unlink("/etc/monit/conf.d/winbindd.monitrc"); } return; } if (!$nopid) { $timefile = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".time"; $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".pid"; $pid = $unix->get_pid_from_file($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { $timeExec = intval($unix->PROCCESS_TIME_MIN($pid)); if ($GLOBALS["OUTPUT"]) { progress_logs(20, "{join_activedirectory_domain}", "Process {$pid} already exists since {$timeExec}Mn"); } writelogs("Process {$pid} already exists since {$timeExec}Mn", __FUNCTION__, __FILE__, __LINE__); if ($timeExec > 5) { $kill = $unix->find_program("kill"); progress_logs(20, "{join_activedirectory_domain}", "killing old pid {$pid} (already exists since {$timeExec}Mn)"); unix_system_kill_force($pid); } else { return; } } $time = $unix->file_time_min($timefile); if ($time < 2) { if ($GLOBALS["OUTPUT"]) { progress_logs(20, "{join_activedirectory_domain}", "2mn minimal to run this script currently ({$time}Mn)"); } writelogs("2mn minimal to run this script currently ({$time}Mn)", __FUNCTION__, __FILE__, __LINE__); return; } } pinglic(true); $mypid = getmypid(); @file_put_contents($pidfile, $mypid); progress_logs(20, "{join_activedirectory_domain} Running PID {$mypid}", "Running PID {$mypid}", __LINE__); writelogs("Running PID {$mypid}", __FUNCTION__, __FILE__, __LINE__); $wbinfo = $unix->find_program("wbinfo"); $nohup = $unix->find_program("nohup"); $tar = $unix->find_program("tar"); $ntpdate = $unix->find_program("ntpdate"); $php5 = $unix->LOCATE_PHP5_BIN(); if (!is_file($wbinfo)) { shell_exec("{$php5} /usr/share/artica-postfix exec.apt-get.php --sources-list"); shell_exec("{$nohup} /usr/share/artica-postfix/bin/setup-ubuntu --check-samba >/dev/null 2>&1 &"); $wbinfo = $unix->find_program("wbinfo"); } if (!is_file($wbinfo)) { progress_logs(20, "{join_activedirectory_domain}", "Auth Winbindd, samba is not installed"); progress_logs(100, "{finish}", "Auth Winbindd, samba is not installed"); return; } if (!checkParams()) { progress_logs(20, "{join_activedirectory_domain} {failed}", "Auth Winbindd, misconfiguration failed"); progress_logs(100, "{finish}", "Auth Winbindd, misconfiguration failed"); return; } $unix = new unix(); $chmod = $unix->find_program("chmod"); $msktutil = check_msktutil(); $kdb5_util = $unix->find_program("kdb5_util"); $kadmin_bin = $unix->find_program("kadmin"); $netbin = $unix->LOCATE_NET_BIN_PATH(); if (!is_file($msktutil)) { return; } @mkdir("/var/log/samba", 0755, true); @mkdir("/var/run/samba", 0755, true); $uname = posix_uname(); $mydomain = $uname["domainname"]; $myFullHostname = $unix->hostname_g(); $myNetBiosName = $unix->hostname_simple(); $enctype = null; $sock = new sockets(); $array = unserialize(base64_decode($sock->GET_INFO("KerbAuthInfos"))); $hostname = strtolower(trim($array["WINDOWS_SERVER_NETBIOSNAME"])) . "." . strtolower(trim($array["WINDOWS_DNS_SUFFIX"])); $domainUp = strtoupper($array["WINDOWS_DNS_SUFFIX"]); $domaindow = strtolower($array["WINDOWS_DNS_SUFFIX"]); $kinitpassword = $array["WINDOWS_SERVER_PASS"]; $kinitpassword = $unix->shellEscapeChars($kinitpassword); $ipaddr = trim($array["ADNETIPADDR"]); $UseADAsNameServer = $sock->GET_INFO("UseADAsNameServer"); if (!is_numeric($UseADAsNameServer)) { $UseADAsNameServer = 0; } if ($UseADAsNameServer == 1) { if (preg_match("#[0-9\\.]+#", $ipaddr)) { progress_logs(8, "{apply_settings}", "Patching Resolv.conf"); PatchResolvConf($ipaddr); } } if ($ipaddr != null) { $ipaddrZ = explode(".", $ipaddr); while (list($num, $a) = each($ipaddrZ)) { $ipaddrZ[$num] = intval($a); } $ipaddr = @implode(".", $ipaddrZ); } progress_logs(9, "{apply_settings} Synchronize time", "Synchronize time" . " in line " . __LINE__); sync_time(); progress_logs(10, "{apply_settings} Check kerb5", "Check kerb5..in line " . __LINE__); if (!krb5conf(12)) { progress_logs(110, "{apply_settings} Check kerb5 {failed}", "Check kerb5..in line " . __LINE__); return; } progress_logs(15, "{apply_settings} Check mskt", "Check msktutils in line " . __LINE__); if (!run_msktutils()) { progress_logs(110, "{apply_settings} Check mskt {failed}", "Check mskt..in line " . __LINE__); return; } progress_logs(15, "{apply_settings} netbin", "netbin -> {$netbin} in line " . __LINE__); if (is_file($netbin)) { try { progress_logs(15, "{apply_settings} netbin", "netbin -> SAMBA_PROXY() in line " . __LINE__); SAMBA_PROXY(); } catch (Exception $e) { progress_logs(15, "{failed}", "Exception Error: Message: " . $e->getMessage()); } } progress_logs(19, "{apply_settings} [kadmin_bin]", $kadmin_bin); progress_logs(19, "{apply_settings} [netbin]", $netbin); if (is_file("{$netbin}")) { progress_logs(20, "{join_activedirectory_domain}", "netbin -> JOIN_ACTIVEDIRECTORY() "); JOIN_ACTIVEDIRECTORY(); // 29% } progress_logs(51, "{restarting_winbind} 1", "winbind_priv();"); winbind_priv(false, 52); progress_logs(60, "{restarting_winbind} 2", "winbind_priv();"); winbindd_monit(); progress_logs(65, "{restarting_winbind} 3", "winbind_priv();"); $php5 = $unix->LOCATE_PHP5_BIN(); if (!is_file("/etc/init.d/winbind")) { shell_exec("{$php5} /usr/share/artica-postfix/exec.initslapd.php --winbind"); } progress_logs(65, "{restarting_winbind}", "winbind_priv();"); system("/etc/init.d/winbind restart --force"); return true; }
exit; } if (isset($_GET["rotate-progress"])) { rotate_progress(); exit; } if (isset($_GET["rebuild-sslcrtd"])) { rebuild_ssl_crtd(); exit; } if (isset($_GET["test-smtp-watchdog"])) { test_smtp_watchdog(); exit; } if (isset($_GET["krb5conf"])) { krb5conf(); exit; } if (isset($_GET["weberror-cache-remove"])) { weberror_cache_remove(); exit; } if (isset($_GET["devshmsize"])) { devshmsize(); exit; } if (isset($_GET["aclgroup-content"])) { aclgroup_content(); exit; } if (isset($_GET["disable-adurgency"])) {