function finish() { $company_name = $_GET["company_name"]; $hook = $_GET["nic_hook"]; $tpl = new templates(); if ($hook == null) { echo $tpl->_ENGINE_parse_body('{error}: {no} {inet_interfaces_title}'); return null; } if ($company_name == null) { echo $tpl->_ENGINE_parse_body('{error}: {no} {company_name}'); return null; } $ldap = new clladp(); $ldap->AddOrganization($company_name); include_once "ressources/class.sockets.inc"; $sock = new sockets(); $sock->getfile('PostFixChangeAutoInterface:' . $_GET["nic_hook"]); }
function create_ou() { $ldap = new clladp(); $tpl = new templates(); $page = CurrentPageName(); $q = new mysql(); $sql = "SELECT * FROM register_orgs WHERE `zmd5`='{$_GET["key"]}'"; $ligne = mysql_fetch_array($q->QUERY_SQL($sql, "artica_backup")); $ou = $ligne["ou"]; if ($ligne["ou"] == null) { echo $tpl->_ENGINE_parse_body("{please_register_first}"); return; } if (!$ldap->AddOrganization($ou)) { $html = "\n\t\t<table style='width:100%'>\n\t\t<tr>\n\t\t\t<td width=1%><img src='img/42-red.png'></td>\n\t\t\t<td valign='top' style='font-size:16px'>{organization}: {$ligne["ou"]} {failed}</td>\n\t\t</tr>\n\t\t</table>\n\t\t"; echo $tpl->_ENGINE_parse_body($html); return; } $html = "\n\t\t<table style='width:100%'>\n\t\t<tr>\n\t\t\t<td width=1%><img src='img/42-green.png'></td>\n\t\t\t<td valign='top' style='font-size:16px'>{organization}: {$ligne["ou"]} {success}</td>\n\t\t</tr>\n\t\t</table>\n\t\t<div id='step-2'></div>\n\t\t<script>\n\t\t\tLoadAjax('step-2','{$page}?create-domain=yes&key={$_GET["key"]}');\n\t\t</script>\t\t\n\t\t\n\t\t\n\t\t"; echo $tpl->_ENGINE_parse_body($html); return; }
function main_fetchmail_build(){ include_once('ressources/class.user.inc'); include_once('ressources/class.main_cf.inc'); include_once('ressources/class.fetchmail.inc'); $failed=false; $isp_address_mail=$_GET["isp_address_mail"]; $isp_pop3_server=$_GET["isp_pop3_server"]; $isp_smtp_server=$_GET["isp_smtp_server"]; $isp_account=$_GET["isp_account"]; $isp_password=$_GET["isp_password"]; $local_email=$_GET["local_email"]; $local_password=$_GET["local_password"]; $isp_smtp_account=$_GET["isp_smtp_account"]; $isp_smtp_password=$_GET["isp_smtp_password"]; $relay_server=$_GET["relay_server"]; if($local_email==null){ echo main_fetchmail_build_results(true,'local mail (False)'); exit; } $ldap=new clladp(); writelogs("i try to found if user exists",__FUNCTION__,__FILE__); $uid=$ldap->uid_from_email($local_email); if($uid<>null){ $user=new user($local_email); $ou=$user->ou; }else{ writelogs("no user found, create it",__FUNCTION__,__FILE__); $tb=explode("@",$local_email); $local_domain=$tb[1]; $user=new user($tb[0]); $ou=$ldap->ou_by_smtp_domain($local_domain); if($ou==null){ $ou=$local_domain; writelogs("Adding new organization $ou",__FUNCTION__,__FILE__); $ldap->AddOrganization($ou); } } writelogs("Creating user",__FUNCTION__,__FILE__); $user=new user($local_email); $user->mail=$local_email; $user->password=$local_password; $user->ou=$ou; $user->SenderCanonical=$isp_address_mail; if(!$user->add_user()){ echo main_fetchmail_build_results(true,$user->ldap_error); exit; } if($isp_smtp_account<>null){ writelogs("Creating SMTP authentification for $isp_smtp_server width $isp_smtp_account",__FUNCTION__,__FILE__); $sasl=new smtp_sasl_password_maps(); $sasl->add($isp_address_mail,$isp_smtp_account,$isp_password); $main=new main_cf(); writelogs("Enable sasl engine in postfix",__FUNCTION__,__FILE__); $main->smtp_sasl_password_maps_enable_2(); } writelogs("Creating sender_dependent_relayhost_maps -> $isp_smtp_server",__FUNCTION__,__FILE__); $sender=new sender_dependent_relayhost_maps(); if(!$sender->Add($isp_address_mail,$isp_smtp_server)){ echo main_fetchmail_build_results(true,"sender_dependent_relayhost_maps:$sender->ldap_error"); exit; } $fetchmail=new Fetchmail_settings(); $array["poll"]=$isp_pop3_server; $array["proto"]="auto"; $array["keep"]="yes"; $array["user"]=$isp_account; $array["pass"]=$isp_password; $array["is"]=$local_email; $array["fetchall"]="yes"; $line=$fetchmail->compile($array); if(!$user->fetchmail_add_rule($line)){ echo main_fetchmail_build_results(true,"fetchmail rule:$user->ldap_error"); exit; } $relay=new Routing($ou); if($relay_server<>null){ if(!$relay->create_relay_server($local_domain,$relay_server,$ou)){ echo main_fetchmail_build_results(true,"relay:$relay->ldap_error"); } }else{ if(!$relay->create_localdomain($ou,$local_domain)){ echo main_fetchmail_build_results(true,"local domain:$relay->ldap_error"); } } $fetchmail=new fetchmail(); $fetchmail->Save(); $main=new main_cf(); $main->save_conf(); $main->save_conf_to_server(); $info="<table style='width:100%'> <tr> <td width=1%><img src='img/fw_bold.gif'></td> <td nowrap align='right'><strong>{organization}</strong>:</td> <td nowrap><strong>$ou</strong></td> </tr> <tr> <td width=1%><img src='img/fw_bold.gif'></td> <td nowrap align='right'><strong>{local_mail}</strong>:</td> <td nowrap><strong>$local_email</strong></td> </tr> <tr> <td width=1%><img src='img/fw_bold.gif'></td> <td nowrap align='right'><strong>{isp_address_mail}</strong>:</td> <td nowrap><strong>$isp_address_mail</strong></td> </tr> </table> "; echo main_fetchmail_build_results(false,$info); }
function SaveSettings() { echo "<div><code>"; $ldap = new clladp(); $usersMenus = new usersMenus(); $ldap->AddOrganization($_COOKIE["company"]); echo "</div></code>"; echo "<div><code>"; if (!$usersMenus->cyrus_imapd_installed) { $ldap->AddRelayDomain($_COOKIE["company"], $_COOKIE["smtp_domain"], $_COOKIE["smtp_relay"], 25); } else { $ldap->AddDomainEntity($_COOKIE["company"], $_COOKIE["smtp_domain"]); } echo "</div></code>"; echo "<div><code>"; $users = new user($_COOKIE["username"]); $users->mail = "{$_COOKIE["username"]}@{$_COOKIE["smtp_domain"]}"; $users->password = $_COOKIE["password"]; $users->ou = $_COOKIE["company"]; $users->add_user(); $users->add_alias("root"); $users->add_alias("mailflt3"); $users->add_alias("*****@*****.**"); $users->add_alias("root@{$usersMenus->fqdn}"); $users->add_alias("postmaster@{$usersMenus->fqdn}"); $users->add_alias("*****@*****.**"); $users->add_alias("postmaster"); echo "</div></code>"; $sock = new sockets(); $sock->SET_INFO("PostmasterAdress", $users->mail); $sock->SET_INFO("MasterSMTPDomainName", $_COOKIE["smtp_domain"]); $sock->SET_INFO("SmtpWizardFinish", 1); if ($usersMenus->AMAVIS_INSTALLED) { echo "<div><code>"; include_once "ressources/class.amavis.inc"; $amavis = new amavis(); $amavis->Save(); $sock->SET_INFO("EnableAmavisDaemon", "1"); $sock->getFrameWork("cmd.php?artica-filter-reload=yes"); $amavis->SaveToServer(); echo "</div></code>"; } if ($usersMenus->BIND9_INSTALLED) { include_once "ressources/class.bind9.inc"; include_once "ressources/class.system.network.inc"; $net = new networking(); if (is_array($net->arrayNameServers)) { $dns = implode("\n", $net->arrayNameServers); $sock->SaveConfigFile($dns, "PostfixBind9DNSList"); $sock->SET_INFO('PostfixEnabledInBind9', 1); } } echo "<div><code>"; $main = new main_cf(); $main->save_conf(); $main->save_conf_to_server(); echo "</div></code>"; }
function TreeAddNewOrganisation() { $usr = new usersMenus(); $tpl = new templates(); if ($usr->AsArticaAdministrator == false) { echo $tpl->_ENGINE_parse_body('{no_privileges}'); exit; } $ou = $_GET["TreeAddNewOrganisation"]; if ($ou == "_Global") { echo "Reserved!"; exit; } $ldap = new clladp(); $ldap->AddOrganization($ou); if ($ldap->ldap_last_error != null) { if ($ldap->ldap_last_error_num != 68) { echo "\n****************************************\nAdding Organization \"{$ou}\"\n********************\n"; echo $ldap->ldap_last_error; exit; } } $ldap->ldap_close(); REMOVE_CACHED("domains.index.php"); $sock = new sockets(); $sock->getFrameWork("status.php?force-front-end=yes"); }
function TASK_USER_EDIT($zmd5) { $meta = new artica_meta(true); include_once dirname(__FILE__) . '/ressources/class.user.inc'; events("Get user informations from {$zmd5}", __FUNCTION__, __FILE__, __LINE__); $http = new httpget(); $datasToSend = base64_encode(serialize($meta->GLOBAL_ARRAY)); $body = $http->send("{$meta->ArticaMetaHostname}/lic.query.server.php", "post", array("DATAS" => $datasToSend, "GET_USER_INFO" => $zmd5)); if (preg_match("#<RESULTS>(.+?)</RESULTS>#", $body, $re)) { $array = unserialize(base64_decode($re[1])); } if (!is_array($array)) { events("Get user informations ERROR not an Array", __FUNCTION__, __FILE__, __LINE__); send_email_events("Failed to add user task id \"{$zmd5}\"", "Error detected\nGet user informations ERROR not an Array", "CLOUD"); return true; } foreach ($array as $key => $value) { $userArray[$key] = $value; } $user = new user($userArray["uid"]); $user->ou = $userArray["ou"]; events("Get user informations {$userArray["uid"]} done", __FUNCTION__, __FILE__, __LINE__); $ldap = new clladp(); $ldap->AddOrganization($user->ou); $user->password = $userArray["userpassword"]; $user->mail = $userArray["mail"]; $user->DisplayName = $userArray["displayname"]; $user->homeDirectory = $userArray["homedirectory"]; $user->sn = $userArray["sn"]; $user->group_id = $userArray["gidnumber"]; $user->FTPDownloadBandwidth = $userArray["ftpdownloadbandwidth"]; $user->FTPDownloadRatio = $userArray["ftpdownloadratio"]; $user->FTPQuotaFiles = $userArray["ftpquotafiles"]; $user->FTPQuotaMBytes = $userArray["ftpquotambytes"]; $user->FTPUploadRatio = $userArray["ftpuploadratio"]; $user->postalCode = $userArray["postalcode"]; $user->postalAddress = $userArray["postaladdress"]; $user->street = $userArray["street"]; $user->givenName = $userArray["givenname"]; $user->mobile = $userArray["mobile"]; $user->telephoneNumber = $userArray["telephonenumber"]; $user->zarafaQuotaHard = $userArray["zarafaQuotaHard"]; $user->zarafaQuotaWarn = $userArray["zarafaQuotaWarn"]; $user->zarafaQuotaSoft = $userArray["zarafaQuotaSoft"]; if (trim($userArray["mailboxsecurityparameters"]) == null) { $userArray["mailboxsecurityparameters"] = "[mailbox]\nl=1\nr=1\ns=1\nw=1\ni=1\np=1\nc=1\nd=1\na=1"; } if (trim($userArray["mailboxactive"]) == null) { $userArray["mailboxactive"] = "TRUE"; } if ($userArray["mailboxactive"] == 1) { $userArray["mailboxactive"] = "TRUE"; } else { $userArray["mailboxactive"] = "FALSE"; } $user->MailboxSecurityParameters = $userArray["mailboxsecurityparameters"]; $user->MailboxActive = $userArray["mailboxactive"]; $user->MailBoxMaxSize = $userArray["mailboxmaxsize"]; events("Saving user information...", __FUNCTION__, __FILE__, __LINE__); if (!$user->add_user()) { events("Failed to add user {$userArray["uid"]}", __FUNCTION__, __FILE__, __LINE__); send_email_events("Failed to add {$userArray["uid"]}", "reason {$user->error}", "CLOUD"); return false; } else { events("Call to unlock user", __FUNCTION__, __FILE__, __LINE__); $http = new httpget(); send_email_events("Success to add {$userArray["uid"]}", "Adding this user:\n{$userArray["mail"]}\nOrganization:{$userArray["ou"]}\n", "CLOUD"); $body = $http->send("{$meta->ArticaMetaHostname}/lic.query.server.php", "post", array("DATAS" => $datasToSend, "UNLOCK_USER" => $zmd5)); return true; } }
function WizardExecute($aspid = false) { $unix = new unix(); $sock = new sockets(); @chmod("/usr/share/artica-postfix/bin/process1", 0755); @mkdir("/etc/artica-postfix/settings/Daemons", 0755, true); if (!$aspid) { $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".pid"; $pid = @file_get_contents($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { die; } $pid = $unix->PIDOF_PATTERN(basename(__FILE__)); if ($pid != getmypid()) { return; } } @file_put_contents($pidfile, getmypid()); $unix->CREATE_NEW_UUID(); $uuid = $unix->GetUniqueID(); $php5 = $unix->LOCATE_PHP5_BIN(); $php = $php5; $nohup = $unix->find_program("nohup"); $squidbin = $unix->LOCATE_SQUID_BIN(); $DEBUG_LOG = "/var/log/artica-wizard.log"; @mkdir("/etc/artica-postfix/ldap_settings", 0755, true); @mkdir("/var/lib/ldap", 0755, true); $rmbin = $unix->find_program("rm"); writeprogress(5, "{set_permissions}..."); shell_exec("{$php} /usr/share/artica-postfix/exec.checkfolder-permissions.php --force --wizard"); writeprogress(10, "{uuid}: {$uuid}"); sleep(2); $savedsettings = unserialize(base64_decode(file_get_contents("/etc/artica-postfix/settings/Daemons/WizardSavedSettings"))); if (!is_array($savedsettings)) { writeprogress(110, "No saved settings Corrupted Array..."); die; } if (count($savedsettings) < 4) { writeprogress(110, "No saved settings no enough element..."); die; } $smtp_domainname = trim($savedsettings["smtp_domainname"]); if ($smtp_domainname == null) { if (isset($savedsettings["domain"])) { $smtp_domainname = $savedsettings["domain"]; } } if (strlen($smtp_domainname) < 3) { $smtp_domainname = "my-domain.com"; } if ($smtp_domainname == ".") { $smtp_domainname = "my-domain.com"; } if ($smtp_domainname == null) { $smtp_domainname = "my-domain.com"; } if (strpos($smtp_domainname, ".") == 0) { $smtp_domainname = "my-domain.com"; } writeprogress(12, "Using `{$smtp_domainname}` as LDAP suffix"); if (strpos($smtp_domainname, ".") > 0) { $smtp_domainname_exploded = explode(".", $smtp_domainname); writeprogress(12, "{$smtp_domainname} " . count($smtp_domainname_exploded) . " items"); $suffix = "dc=" . @implode(",dc=", $smtp_domainname_exploded); } else { $suffix = "dc={$smtp_domainname}"; } $SQUIDEnable = 1; $AsCategoriesAppliance = intval($savedsettings["AsCategoriesAppliance"]); $AsTransparentProxy = intval($savedsettings["AsTransparentProxy"]); $AsReverseProxyAppliance = intval($savedsettings["AsReverseProxyAppliance"]); $AsMetaServer = intval($savedsettings["AsMetaServer"]); $WizardWebFilteringLevel = $sock->GET_INFO("WizardWebFilteringLevel"); if (is_numeric($WizardWebFilteringLevel)) { $WizardSavedSettings["EnableWebFiltering"] = 1; } @file_put_contents("/etc/artica-postfix/settings/Daemons/DisableBWMng", 1); @file_put_contents("/etc/artica-postfix/settings/Daemons/SquidDatabasesUtlseEnable", 1); @file_put_contents("/etc/artica-postfix/settings/Daemons/AsMetaServer", $AsMetaServer); @file_put_contents("/etc/artica-postfix/settings/Daemons/AsCategoriesAppliance", $AsCategoriesAppliance); if ($AsCategoriesAppliance == 1) { $savedsettings["EnableWebFiltering"] = 0; @file_put_contents("/etc/artica-postfix/settings/Daemons/EnableUfdbGuard", 0); @file_put_contents("/etc/artica-postfix/settings/Daemons/SQUIDEnable", 0); @file_put_contents("/etc/artica-postfix/settings/Daemons/ProxyUseArticaDB", 0); @file_put_contents("/etc/artica-postfix/settings/Daemons/EnableArpDaemon", 0); @file_put_contents("/etc/artica-postfix/settings/Daemons/EnableFreeWeb", 0); @file_put_contents("/etc/artica-postfix/settings/Daemons/SlapdThreads", 2); @file_put_contents("/etc/artica-postfix/settings/Daemons/DisableBWMng", 1); @file_put_contents("/etc/artica-postfix/settings/Daemons/DisableNetDiscover", 1); @file_put_contents("/etc/artica-postfix/settings/Daemons/SambaEnabled", 0); $SQUIDEnable = 0; } if ($AsMetaServer == 1) { $savedsettings["EnableWebFiltering"] = 0; @file_put_contents("/etc/artica-postfix/settings/Daemons/EnableUfdbGuard", 0); @file_put_contents("/etc/artica-postfix/settings/Daemons/SQUIDEnable", 0); @file_put_contents("/etc/artica-postfix/settings/Daemons/ProxyUseArticaDB", 0); @file_put_contents("/etc/artica-postfix/settings/Daemons/EnableArpDaemon", 0); @file_put_contents("/etc/artica-postfix/settings/Daemons/EnableFreeWeb", 0); @file_put_contents("/etc/artica-postfix/settings/Daemons/SlapdThreads", 2); @file_put_contents("/etc/artica-postfix/settings/Daemons/DisableBWMng", 1); @file_put_contents("/etc/artica-postfix/settings/Daemons/DisableNetDiscover", 1); @file_put_contents("/etc/artica-postfix/settings/Daemons/SambaEnabled", 0); $SQUIDEnable = 0; } if ($AsReverseProxyAppliance == 1) { $AsCategoriesAppliance = 0; $AsTransparentProxy = 0; $savedsettings["EnableWebFiltering"] = 0; $savedsettings["adminwebserver"] = null; $savedsettings["second_webadmin"] = null; $SQUIDEnable = 0; @file_put_contents("/etc/artica-postfix/settings/Daemons/EnableUfdbGuard", 0); @file_put_contents("/etc/artica-postfix/settings/Daemons/SQUIDEnable", 0); @file_put_contents("/etc/artica-postfix/settings/Daemons/ProxyUseArticaDB", 0); @file_put_contents("/etc/artica-postfix/settings/Daemons/EnableArpDaemon", 0); @file_put_contents("/etc/artica-postfix/settings/Daemons/EnableFreeWeb", 0); @file_put_contents("/etc/artica-postfix/settings/Daemons/SlapdThreads", 2); @file_put_contents("/etc/artica-postfix/settings/Daemons/DisableNetDiscover", 1); @file_put_contents("/etc/artica-postfix/settings/Daemons/SambaEnabled", 0); @file_put_contents("/etc/artica-postfix/settings/Daemons/EnableFreeWeb", 0); @file_put_contents("/etc/artica-postfix/settings/Daemons/EnableNginx", 1); } if ($savedsettings["administrator"] != null) { writeprogress(13, "{creating_accounts} {artica_manager}: {$savedsettings["administrator"]}"); sleep(2); @mkdir("/etc/artica-postfix/ldap_settings", 0755, true); @file_put_contents("/etc/artica-postfix/ldap_settings/admin", $savedsettings["administrator"]); @file_put_contents("/etc/artica-postfix/ldap_settings/password", $savedsettings["administratorpass"]); sleep(1); @unlink("/etc/artica-postfix/no-ldap-change"); @chmod("/usr/share/artica-postfix/bin/artica-install", 0755); writeprogress(14, "{building_openldap_configuration_file}"); system("/usr/share/artica-postfix/bin/artica-install --slapdconf >>{$DEBUG_LOG} 2>&1"); } else { writeprogress(13, "{creating_accounts} {artica_manager}: {default} Manager"); sleep(2); } writeprogress(15, "{creating_domain} LDAP {suffix}:{$suffix} "); @file_put_contents("/etc/artica-postfix/ldap_settings/suffix", $suffix); sleep(3); shell_exec("{$rmbin} -rf /var/lib/ldap/*"); @file_put_contents("/etc/artica-postfix/WIZARD_INSTALL_EXECUTED", time()); writeprogress(16, "{reconfigure}: {openldap_server}"); @unlink("/etc/artica-postfix/no-ldap-change"); @chmod("/usr/share/artica-postfix/bin/artica-install", 0755); @chmod("/usr/share/artica-postfix/bin/process1", 0755); writeprogress(17, "{building_openldap_configuration_file}"); system("/usr/share/artica-postfix/bin/artica-install --slapdconf >>{$DEBUG_LOG} 2>&1"); writeprogress(18, "{restarting_service} {openldap_server} [{$suffix}] (1/3)"); shell_exec("{$php5} /usr/share/artica-postfix/exec.initslapd.php --ldapd-conf --verbose >>{$DEBUG_LOG} 2>&1"); system("/etc/init.d/slapd restart --force --framework=" . basename(__FILE__) . "-" . __LINE__ . " >>{$DEBUG_LOG} 2>&1"); usleep(800); writeprogress(19, "{restarting_service} {openldap_server} [{$suffix}] (2/3)"); system("/etc/init.d/slapd restart --force --framework=" . basename(__FILE__) . "-" . __LINE__ . " >>{$DEBUG_LOG} 2>&1"); usleep(800); writeprogress(20, "{restarting_service} {openldap_server} [{$suffix}] (3/3)"); system("/etc/init.d/slapd restart --force --framework=" . basename(__FILE__) . "-" . __LINE__ . " >>{$DEBUG_LOG} 2>&1"); sleep(2); writeprogress(22, "{refresh_global_settings}"); system('/usr/share/artica-postfix/bin/process1 --checkout --force --verbose ' . time()); writeprogress(23, "{scanning_hardware_software}"); system('/usr/share/artica-postfix/bin/process1 --force --verbose ' . time()); $SUBNIC = null; FINAL___(); @file_get_contents($pidfile, getmypid()); writeprogress(24, "{restarting_service}: {mysql_server}"); system('/etc/init.d/mysql restart --force'); sleep(1); $users = new usersMenus(); $q = new mysql(); writeprogress(25, "{creating_databases}"); sleep(1); $q->BuildTables(); $sock = new sockets(); $CPU_NUMBERS = $unix->CPU_NUMBER(); if ($CPU_NUMBERS == 0) { $CPU_NUMBERS = 4; } $MEMORY = $unix->MEM_TOTAL_INSTALLEE(); $MEMORY_TEXT = FormatBytes($MEMORY); $INTEL_CELERON = FALSE; writeprogress(25, "CPUs {$CPU_NUMBERS} - {memory}: {$MEMORY_TEXT}"); sleep(2); if ($MEMORY > 1) { if ($unix->MEM_TOTAL_INSTALLEE() < 624288) { @file_put_contents("/etc/artica-postfix/settings/Daemons/EnableIntelCeleron", 1); @file_put_contents("/etc/artica-postfix/settings/Daemons/SquidPerformance", 3); writeprogress(25, "{$MEMORY_TEXT} = Enable Intel Celeron mode...."); shell_exec("{$php5} /usr/share/artica-postfix/exec.intel.celeron.php"); $INTEL_CELERON = true; } } if (!$INTEL_CELERON) { if ($CPU_NUMBERS < 2) { @file_put_contents("/etc/artica-postfix/settings/Daemons/EnableIntelCeleron", 1); @file_put_contents("/etc/artica-postfix/settings/Daemons/SquidPerformance", 3); writeprogress(25, "CPUs:{$CPU_NUMBERS} = Intel Celeron mode...."); shell_exec("{$php5} /usr/share/artica-postfix/exec.intel.celeron.php"); $INTEL_CELERON = true; } } if (!$INTEL_CELERON) { if ($CPU_NUMBERS < 3) { @file_put_contents("/etc/artica-postfix/settings/Daemons/SquidPerformance", 2); writeprogress(25, "CPUs:{$CPU_NUMBERS} = {features}: {no_statistics}"); sleep(1); } } writeprogress(26, "{creating_services}"); shell_exec("{$nohup} {$php5} /usr/share/artica-postfix/exec.initslapd.php --force >/dev/null 2>&1 &"); if (is_file($squidbin)) { writeprogress(27, "{RestartingProxyStatisticsDatabase}"); shell_exec("/etc/init.d/squid-db restart >>{$DEBUG_LOG} 2>&1"); } $cyrus = $unix->LOCATE_CYRUS_DAEMON(); if (is_file($cyrus)) { writeprogress(28, "{restarting_service} SaslAuthd Daemon"); shell_exec("/etc/init.d/saslauthd restart"); writeprogress(29, "{restarting_service} Cyrus IMAP Daemon"); shell_exec("/etc/init.d/cyrus-imapd restart"); writeprogress(30, "{restarting_service} Postfix Daemon"); shell_exec("/etc/init.d/postfix restart"); } if (isset($savedsettings["GoldKey"])) { if (!$sock->IsGoldKey($savedsettings["GoldKey"])) { unset($savedsettings["GoldKey"]); } } if (isset($savedsettings["GoldKey"])) { if ($sock->IsGoldKey($savedsettings["GoldKey"])) { $WORKDIR = base64_decode("L3Vzci9sb2NhbC9zaGFyZS9hcnRpY2E="); $WORKFILE = base64_decode('LmxpYw=='); $WORKPATH = "{$WORKDIR}/{$WORKFILE}"; @file_put_contents($WORKPATH, "TRUE"); $LicenseInfos = unserialize(base64_decode($sock->GET_INFO("LicenseInfos"))); $LicenseInfos["UUID"] = $savedsettings["UUID_FIRST"]; $LicenseInfos["TIME"] = time(); $sock->SaveConfigFile(base64_encode(serialize($LicenseInfos)), "LicenseInfos"); writeprogress(31, "{register_license}"); shell_exec("{$php5} /usr/share/artica-postfix/exec.web-community-filter.php --register >/dev/null 2>&1"); writeprogress(32, "{saving_license}"); shell_exec("{$php5} /usr/share/artica-postfix/exec.web-community-filter.php --register-lic >/dev/null 2>&1"); } } $ldap = new clladp(); writeprogress(40, "{building_organization} {$savedsettings["organization"]}"); if (!$ldap->AddOrganization($savedsettings["organization"])) { debug_logs("Building organization failed {$ldap->ldap_last_error}"); sleep(2); if (!$ldap->AddOrganization($savedsettings["organization"])) { debug_logs("Building organization failed 2/2 {$ldap->ldap_last_error}"); } } sleep(2); writeprogress(40, "{creating_domain} {$savedsettings["smtp_domainname"]}"); if (!$ldap->AddDomainEntity($savedsettings["organization"], $savedsettings["smtp_domainname"])) { debug_logs("AddDomainEntity failed {$ldap->ldap_last_error}"); } sleep(2); $timezone = $savedsettings["timezones"]; $sourcefile = "/usr/share/zoneinfo/{$timezone}"; if (is_file($sourcefile)) { writeprogress(60, "{timezone} {$timezone}"); @unlink("/etc/localtime"); @copy($sourcefile, "/etc/localtime"); @file_put_contents("/etc/timezone", $timezone); } else { writeprogress(60, "{$sourcefile} no such file"); } sleep(2); BUILD_NETWORK(); shell_exec("{$nohup} /etc/init.d/artica-status restart >/dev/null 2>&1 &"); shell_exec("{$nohup} /etc/init.d/monit restart >/dev/null 2>&1 &"); $unix->THREAD_COMMAND_SET("{$php5} /usr/share/artica-postfix/exec.postfix.maincf.php --reconfigure"); $unix->THREAD_COMMAND_SET("/usr/share/artica-postfix/bin/artica-install --reconfigure-cyrus"); $FreeWebAdded = false; sleep(3); if (!is_file("/etc/artica-postfix/WIZARD_INSTALL_EXECUTED")) { if (!$GLOBALS["NOREBOOT"]) { $reboot = true; } $rebootWarn = null; } if (is_file($squidbin)) { include_once dirname(__FILE__) . "/ressources/class.squid.inc"; if ($SQUIDEnable == 1) { $squid = new squidbee(); if ($AsTransparentProxy == 1) { $squid->hasProxyTransparent = 1; } @file_put_contents("/etc/artica-postfix/settings/Daemons/HyperCacheStoreID", 1); $q = new mysql(); if ($q->COUNT_ROWS("squid_caches_center", "artica_backup") == 0) { $cachename = basename($squid->CACHE_PATH); $q->QUERY_SQL("INSERT IGNORE INTO `squid_caches_center` (cachename,cpu,cache_dir,cache_type,cache_size,cache_dir_level1,cache_dir_level2,enabled,percentcache,usedcache,remove)\n\t\t\t\tVALUES('{$cachename}',1,'{$squid->CACHE_PATH}','{$squid->CACHE_TYPE}','2000','128','256',1,0,0,0)", "artica_backup"); } $zipfile = "/usr/share/artica-postfix/ressources/conf/upload/squid-zip-import.zip"; if (is_file($zipfile)) { writeprogress(63, "Analyze old squid.conf"); system("{$php5} /usr/share/artica-postfix/exec.squid.import.conf.php --zip"); } $squid->SaveToLdap(true); writeprogress(65, "{ReconfiguringProxy} {please_wait} 1/2"); shell_exec("{$php5} /usr/share/artica-postfix/exec.squid.php --build --force"); } else { writeprogress(63, "{stopping} {proxy_service}"); shell_exec("/etc/init.d/squid stop"); } } if ($AsCategoriesAppliance == 1) { writeprogress(65, "{starting} Categories service"); shell_exec("/etc/init.d/ufdbcat start"); } if ($AsReverseProxyAppliance == 1) { writeprogress(65, "{starting} Reverse Proxy service..."); system("{$php5} /usr/share/artica-postfix/exec.nginx.php --build"); shell_exec("/etc/init.d/nginx restart"); } if (isset($savedsettings["EnablePDNS"])) { $sock->SET_INFO("EnablePDNS", $savedsettings["EnablePDNS"]); } if (isset($savedsettings["EnableDHCPServer"])) { $sock->SET_INFO("EnableDHCPServer", $savedsettings["EnableDHCPServer"]); } if (isset($savedsettings["EnableFreeRadius"])) { $sock->SET_INFO("EnableFreeRadius", $savedsettings["EnableFreeRadius"]); $sock->getFrameWork("freeradius.php?restart=yes"); } $restart_artica_status = false; if ($savedsettings["adminwebserver"] != null) { writeprogress(67, "{creating_webservices}{$rebootWarn}"); $sock->SET_INFO("EnableFreeWeb", 1); writeprogress(60, "{restarting_artica_status}"); $restart_artica_status = true; restart_artica_status(); writeprogress(68, "{restarting_webservices}"); restart_apache_src(); writeprogress(69, "{creating_default_website} {$savedsettings["adminwebserver"]}"); include_once dirname(__FILE__) . "/ressources/class.freeweb.inc"; $free = new freeweb($savedsettings["adminwebserver"]); $free->servername = $savedsettings["adminwebserver"]; $free->groupware = "ARTICA_MINIADM"; $free->CreateSite(); writeprogress(69, "{creating_default_website} {$savedsettings["adminwebserver"]}"); rebuild_vhost($savedsettings["adminwebserver"]); } if ($savedsettings["second_webadmin"] != null) { $sock->SET_INFO("EnableFreeWeb", 1); if (!$restart_artica_status) { writeprogress(70, "{creating_webservices}{$rebootWarn}"); restart_artica_status(); restart_apache_src(); } include_once dirname(__FILE__) . "/ressources/class.freeweb.inc"; $free = new freeweb($savedsettings["second_webadmin"]); $free->servername = $savedsettings["second_webadmin"]; $free->groupware = "ARTICA_ADM"; $free->CreateSite(); rebuild_vhost($savedsettings["second_webadmin"]); } if ($savedsettings["statsadministrator"] != null) { $ligne = mysql_fetch_array($q->QUERY_SQL("SELECT id FROM radgroupcheck WHERE groupname='WebStatsAdm' LIMIT 0,1", "artica_backup")); $gpid = $ligne["id"]; if (!is_numeric($gpid)) { $gpid = 0; } if ($gpid == 0) { $sql = "INSERT IGNORE INTO radgroupcheck (`groupname`, `attribute`,`op`, `value`) VALUES ('WebStatsAdm', 'Auth-Type',':=', 'Accept');"; $q->QUERY_SQL($sql, "artica_backup"); if (!$q->ok) { $gpid = 0; } else { $gpid = $q->last_id; } if ($gpid > 0) { $savedsettings["statsadministrator"] = mysql_escape_string2($savedsettings["statsadministrator"]); $administratorpass = mysql_escape_string2(url_decode_special_tool($savedsettings["statsadministratorpass"])); $ligne = mysql_fetch_array($q->QUERY_SQL("SELECT value FROM radcheck WHERE username='******' LIMIT 0,1", "artica_backup")); if (trim($ligne["value"]) == null) { $sql = "INSERT IGNORE INTO radcheck (`username`, `attribute`, `value`) VALUES ('{$savedsettings["statsadministrator"]}', 'Cleartext-Password', '{$savedsettings["statsadministratorpass"]}');"; $q->QUERY_SQL($sql, "artica_backup"); } else { $sql = "UPDATE radcheck SET `value`='{$savedsettings["statsadministratorpass"]}' WHERE username='******'"; $q->QUERY_SQL($sql, "artica_backup"); if (!$q->ok) { echo $q->mysql_error; } } $ligne = mysql_fetch_array($q->QUERY_SQL("SELECT username FROM radcheck WHERE username='******' AND groupname='WebStatsAdm' LIMIT 0,1", "artica_backup")); if (trim($ligne["username"]) == null) { $sql = "insert into radusergroup (username, groupname, priority,gpid) VALUES ('{$savedsettings["statsadministrator"]}', 'WebStatsAdm', 1,{$gpid});"; $q->QUERY_SQL($sql, "artica_backup"); if (!$q->ok) { echo $q->mysql_error; } } } } } $reboot = false; writeprogress(80, "{checking_parameters}{$rebootWarn}"); if (!is_file("/etc/artica-postfix/WIZARD_INSTALL_EXECUTED")) { @file_put_contents("/etc/artica-postfix/WIZARD_INSTALL_EXECUTED", time()); } $unix->THREAD_COMMAND_SET("{$php5} /usr/share/artica-postfix/exec.initslapd.php"); $EnableKerbAuth = $sock->GET_INFO("EnableKerbAuth"); if (!is_numeric($EnableKerbAuth)) { $EnableKerbAuth = 0; } if ($EnableKerbAuth == 1) { writeprogress(82, "{LaunchActiveDirectoryConnection}..."); system("{$php5} /usr/share/artica-postfix/exec.kerbauth.php --build --force --verbose >>{$DEBUG_LOG} 2>&1"); } $WizardWebFilteringLevel = $sock->GET_INFO("WizardWebFilteringLevel"); if (is_numeric($WizardWebFilteringLevel)) { $savedsettings["EnableWebFiltering"] = 1; } if ($savedsettings["EnableWebFiltering"] == 1) { writeprogress(82, "{activate_webfiltering_service}..."); sleep(2); EnableWebFiltering(); } else { writeprogress(82, "{no_web_filtering}"); sleep(2); } if ($users->POSTFIX_INSTALLED) { $unix->THREAD_COMMAND_SET("{$php5} /usr/share/artica-postfix/exec.postfix.maincf.php --build --force >>{$DEBUG_LOG} 2>&1"); } writeprogress(83, "{RestartingArticaStatus}"); system("/etc/init.d/artica-status restart --force"); $serverbin = $unix->find_program("zarafa-server"); if (is_file($serverbin)) { writeprogress(85, "{restarting_zarafa_services}{$rebootWarn}"); shell_exec("{$php5} /usr/share/artica-postfix/exec.initdzarafa.php"); shell_exec("{$php5} /usr/share/artica-postfix/exec.zarafa-db.php --init"); shell_exec("/etc/init.d/zarafa-db restart"); shell_exec("/etc/init.d/zarafa-server restart"); shell_exec("/etc/init.d/zarafa-web restart"); } writeprogress(90, "{restarting_services}{$rebootWarn}"); shell_exec("{$nohup} /etc/init.d/artica-status reload >/dev/null 2>&1 &"); shell_exec("{$nohup} /etc/init.d/monit restart >/dev/null 2>&1 &"); shell_exec("{$nohup} {$php5} /usr/share/artica-postfix/exec.monit.php --build >/dev/null 2>&1"); shell_exec("{$nohup} /usr/share/artica-postfix/exec.web-community-filter.php --register >/dev/null 2>&1 &"); $EnableArticaMetaClient = intval($sock->GET_INFO("EnableArticaMetaClient")); if ($EnableArticaMetaClient == 1) { shell_exec("{$nohup} {$php5} /usr/share/artica-postfix/exec.artica-meta-client.php --ping --force >/dev/null 2>&1 &"); } if (is_file($squidbin)) { if ($SQUIDEnable == 1) { $q = new mysql_squid_builder(); if ($q->COUNT_ROWS("proxy_ports") == 0) { $WizardSqlWait = unserialize(@file_get_contents("/etc/artica-postfix/settings/Daemons/WizardSqlWait")); while (list($none, $sql) = each($WizardSqlWait)) { $q->QUERY_SQL($sql); } } writeprogress(95, "{ReconfiguringProxy} {please_wait} 2/2"); shell_exec("{$php5} /usr/share/artica-postfix/exec.squid.php --build --force"); writeprogress(97, "{checking_hypercache_feature} {please_wait}"); shell_exec("{$php5} /usr/share/artica-postfix/exec.hypercache-dedup.php --wizard"); } } writeprogress(98, "{empty_watchdog_events} {please_wait}"); $q = new mysql(); $q->QUERY_SQL("TRUNCATE TABLE squid_admin_mysql", "artica_events"); $time = $unix->file_time_min("/etc/artica-postfix/WIZARD_INSTALL_EXECUTED"); if (!$reboot) { writeprogress(100, "{done}"); FINAL___(); return; } writeprogress(100, "Rebooting"); FINAL___(); sleep(10); shell_exec($unix->find_program("reboot")); }
function COMPILE() { $sock = new sockets(); $sock->SET_INFO("KasxFilterEnabled", 1); $sock->SET_INFO("kavmilterEnable", 1); $domain = trim(strtolower($_SESSION["WIZARD"]["ORGANIZATION"])); $ou = $_SESSION["WIZARD"]["ORGANIZATION"]; $ou = str_replace(" ", "_", $ou); $ldap = new clladp(); $ldap->AddOrganization($_SESSION["WIZARD"]["ORGANIZATION"]); $hashdoms = $ldap->hash_get_all_domains(); if ($hashdoms[$domain] == null) { $ldap->AddRelayDomain($ou, $domain, $_SESSION["WIZARD"]["MAILBOX_IP"], 25); } $kas = new kas_mysql($ou); $kas->SET_VALUE("OPT_FILTRATION_ON", 1); $main = new main_cf(); $main->add_my_networks($_SESSION["WIZARD"]["SMTP_NET"]); $main->save_conf_to_server(); $sock->getFrameWork("cmd.php?kas-reconfigure=yes"); $sock->getFrameWork("cmd.php?kavmilter-configure"); $tpl = new templates(); $html = "\n\t\t\n\t\t<H3>{success}</H3><center>" . button("{close}", "CloseTimeOut()") . "</center>"; echo $tpl->_ENGINE_parse_body("{success}"); }
function TreeAddNewOrganisation() { $usr = new usersMenus(); $tpl = new templates(); if ($usr->AsArticaAdministrator == false) { echo $tpl->_ENGINE_parse_body('{no_privileges}'); exit; } $ou = $_GET["TreeAddNewOrganisation"]; if ($ou == "_Global") { echo "Reserved!"; exit; } $ldap = new clladp(); $ldap->AddOrganization($ou); if ($ldap->ldap_last_error != null) { if ($ldap->ldap_last_error_num != 68) { echo $ldap->ldap_last_error; exit; } } $ldap->ldap_close(); REMOVE_CACHED("domains.index.php"); }
function import($ou, $path) { $usersM = new usersMenus(); $unix = new unix(); if (!is_file($path)) { echo "{$path}, no such file\n"; die; } $ldap = new clladp(); $oudn = "ou={$ou},dc=organizations,{$ldap->suffix}"; if (!$ldap->ExistsDN($oudn)) { $ldap->AddOrganization($ou); } $tmpfile = $unix->FILE_TEMP(); uncompress($path, $tmpfile); $datas = unserialize(base64_decode(@file_get_contents($tmpfile))); if (!is_array($datas)) { if ($GLOBALS["VERBOSE"]) { echo "Unable to import {$ou} {$path}, no such array\n"; return; } $unix->send_email_events(basename(__FILE__) . "::Unable to import {$ou} {$path}, no such array", null, "import"); die; } $usersArray = $datas["USERS"]; $groupsArray = $datas["GROUPS"]; unset($datas); echo "Creating groups in `{$ou}`"; while (list($num, $hash) = each($groupsArray)) { $ORG_GID = $hash["main_array"]["gid"]; $gp = new groups(); $gpid = $gp->GroupIDFromName($ou, $hash["groupName"]); if (!is_numeric($gpid)) { $gp->groupName = $hash["groupName"]; $gp->add_new_group($hash["groupName"], $ou); $gpid = $gp->GroupIDFromName($ou, $hash["groupName"]); } $gp = new groups($gpid); $members = $hash["members"]; while (list($a, $b) = each($members)) { echo "Insert {$b} user to {$hash["groupName"]}/{$gpid}\n"; $gp->AddUsertoThisGroup($b); } $gp->saveDescription($hash["main_array"]["description"]); $gp->ArticaGroupPrivileges = $hash["main_array"]["ArticaGroupPrivileges"]; $gp->Privileges_array = $hash["Privileges_array"]; $gp->SavePrivileges(); $GROUPSORGS[$ORG_GID] = $gpid; } while (list($num, $hash) = each($usersArray)) { $array_groups = $hash["array_groups"]; unset($hash["dn"]); unset($hash["UserExists"]); unset($hash["ou"]); unset($hash["local_sid"]); unset($hash["objectClass_array"]); unset($hash["group_id"]); unset($hash["sambaPrimaryGroupSID"]); unset($hash["accountGroup"]); unset($hash["uidNumber"]); unset($hash["sambaSID"]); unset($hash["sambaPrimaryGroupGID"]); unset($hash["gidNumber_array"]); $samba_groups = $hash["samba_groups"]; unset($hash["ldapClass"]); unset($hash["attributs_array"]); unset($hash["samba_groups"]); $users = new user($hash["uid"]); $users->ou = $ou; $users->group_id = $GROUPSORGS[$array_groups[0]]; while (list($a, $orgd) = each($hash)) { $users->a = $orgd; } $users->add_user(); if ($usersM->SAMBA_INSTALLED) { if (!$hash["NotASambaUser"]) { $users->Samba_edit_user(); } } } }
function verif_organization() { $unix = new unix(); $EnableOpenLDAP = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/EnableOpenLDAP")); if ($EnableOpenLDAP == 0) { return; } if (!isset($GLOBALS["SQUID_INSTALLED"])) { $squidbin = $unix->LOCATE_SQUID_BIN(); if (is_file($squidbin)) { $GLOBALS["SQUID_INSTALLED"] = true; } else { $GLOBALS["SQUID_INSTALLED"] = false; } } $timeStamp = "/etc/artica-postfix/pids/exec.verifldap.php.verif_organization.time"; if ($GLOBALS["VERBOSE"]) { echo "{$timeStamp}\n"; } $pidFile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $pid = $unix->get_pid_from_file($pidFile); if ($unix->process_exists($pid, basename(__FILE__))) { return; } @unlink($pidFile); @file_put_contents($pidFile, getmypid()); if (!$GLOBALS["FORCE"]) { $TimeEx = $unix->file_time_min($timeStamp); if ($TimeEx < 240) { return; } } @unlink($timeStamp); @file_put_contents($timeStamp, time()); $sock = new sockets(); if ($sock->EnableIntelCeleron == 1) { die; exit; } $WizardSavedSettings = unserialize(base64_decode(@file_get_contents("/etc/artica-postfix/settings/Daemons/WizardSavedSettings"))); if (!isset($WizardSavedSettings["organization"])) { return; } $organization = $WizardSavedSettings["organization"]; if ($organization == null) { return; } $ldap = new clladp(); if ($GLOBALS["VERBOSE"]) { echo "Loading LDAP\n"; } if ($ldap->ldapFailed) { if ($GLOBALS["VERBOSE"]) { echo "Unable to connect to the LDAP server {$ldap->ldap_host}!\n"; } if ($ldap->ldap_host == "127.0.0.1") { $unix->ToSyslog("LDAP error {$ldap->ldap_last_error}", false, basename(__FILE__)); if ($GLOBALS["SQUID_INSTALLED"]) { squid_admin_mysql(1, "Connecting to local LDAP server failed [action=restart LDAP]", "Error: {$ldap->ldap_last_error}\nLdap host:{$ldap->ldap_host}", __FILE__, __LINE__); } system_admin_events("Error, Connecting to local LDAP server failed [action=restart LDAP]", __FUNCTION__, __FILE__, __LINE__); shell_exec("/etc/init.d/slapd restart --framework=" . basename(__FILE__)); $ldap = new clladp(); if ($GLOBALS["VERBOSE"]) { echo "Loading LDAP\n"; } if ($ldap->ldapFailed) { echo $unix->ToSyslog("Unable to connect to the LDAP server {$ldap->ldap_host}! -> Abort..", false, __FILE__); return; } } else { return; } } $hash = $ldap->hash_get_ou(false); $CountDeOU = count($hash); if ($GLOBALS["VERBOSE"]) { echo "{$CountDeOU} Organization(s)\n"; } if (count($hash) > 0) { return; } system_admin_events("Error, no organization found, create the first one {$organization}", __FUNCTION__, __FILE__, __LINE__); if (!$ldap->AddOrganization($organization)) { system_admin_events("Error, unable to create first organization {$organization}\n{$ldap->ldap_last_error}", __FUNCTION__, __FILE__, __LINE__); if ($GLOBALS["SQUID_INSTALLED"]) { squid_admin_mysql(0, "Error, unable to create first organization {$organization}", $ldap->ldap_last_error, __FILE__, __LINE__); } } }
function IMPORT_OUS() { $me = $_SERVER["SERVER_NAME"]; $error = array(); $ldap = new clladp(); $ous = unserialize(base64_decode($_POST["OUS"])); while (list($num, $org) = each($ous)) { if (trim($org) == null) { continue; } if (!$ldap->AddOrganization($org)) { $error[] = "Unable to add {$org} in LDAP database\n {$ldap->ldap_last_error}"; continue; } else { $success[] = "Success adding {$org} in LDAP database"; } } if (count($error) > 0) { echo "<ERROR>" . @implode("\n", $error) . "</ERROR>"; } if (count($success) > 0) { echo "<SUCCESS>" . @implode("\n", $success) . "</SUCCESS>"; } }
function CreateOU() { $ldap = new clladp(); $ldap->AddOrganization($_GET["ou"]); $tpl = new templates(); if ($ldap->ldap_last_error != null) { if ($ldap->ldap_last_error_num != 68) { echo $ldap->ldap_last_error; exit; } } echo $tpl->_ENGINE_parse_body("{$_GET["ou"]} {added}"); }
function import($ligne) { $unix = new unix(); $Tmpdir = $unix->TEMP_DIR(); $connection = $ligne["connection"]; $username = $ligne["username"]; $password = $ligne["password"]; $folder = $ligne["folder"]; $filename = $ligne["filename"]; $ID = $ligne["ID"]; $folder = str_replace("\\", "/", $folder); if (strpos($folder, "/") > 0) { $FF = explode("/", $folder); $SharedDir = $FF[0]; unset($FF[0]); $folder = @implode("/", $FF); } $mountpoint = "{$Tmpdir}/{$ligne["ID"]}"; if ($folder != null) { $targetdir = "{$mountpoint}/{$folder}"; } else { $targetdir = $mountpoint; } if (!is_file("{$targetdir}/{$filename}")) { system_admin_events("{$connection}: {$targetdir}/{$filename}, no such file", __FUNCTION__, __FILE__, __LINE__, "import", $GLOBALS["SCHEDULE_ID"]); $mount = new mount(); $mount->umount($mountpoint); return false; } if (is_file("{$targetdir}/{$filename}.scanned")) { $SCANNED = unserialize(@file_get_contents("{$targetdir}/{$filename}.scanned")); } $md5file = md5_file("{$targetdir}/{$filename}"); if ($md5file == $ligne["lastmd5"]) { return true; } $handle = @fopen("{$targetdir}/{$filename}", "r"); if (!$handle) { system_admin_events("{$connection}: {$targetdir}/{$filename}, fatal error", __FUNCTION__, __FILE__, __LINE__, "import", $GLOBALS["SCHEDULE_ID"]); return; } $c = 0; $ldap = new clladp(); $OUS = $ldap->hash_get_ou(true); $defaultgroup = $ligne["ldapgroup"]; if ($defaultgroup > 0) { $gp = new groups($defaultgroup); $DefaultOu = $gp->ou; $defaultGroupName = $gp->groupName; if ($GLOBALS["VERBOSE"]) { echo "Default group: {$defaultgroup}/ {$gp->groupName}/{$DefaultOu}\n"; } } $t1 = time(); $c = 0; $d = 0; while (!feof($handle)) { $line = trim(fgets($handle, 1024)); $line = str_replace("\"", "", $line); if ($line == null) { continue; } if (strpos($line, ";") == 0) { continue; } $SCANMD = md5($line); $tr = explode(";", $line); $account = $tr[0]; $password = $tr[1]; $email = $tr[2]; $groupname = $tr[3]; $organization = $tr[4]; if ($organization == "organization") { continue; } if ($account == "account") { continue; } $Telephon = $tr[5]; $mobile = $tr[6]; $d++; if (isset($SCANNED[$SCANMD])) { continue; } if ($GLOBALS["VERBOSE"]) { echo "--------------- {$d} ----------------- {$SCANMD}\n"; } if ($organization == null) { if ($defaultgroup == 0) { continue; } } if ($organization == null) { if ($DefaultOu != null) { $organization = $DefaultOu; } } if ($groupname == null) { $groupname = $defaultGroupName; } if ($groupname == null) { if ($GLOBALS["VERBOSE"]) { echo "{$organization} NO GroupName !!\n"; } continue; } if (!isset($OUS[$organization])) { if (!$ldap->AddOrganization($organization)) { system_admin_events("fatal error failed to create entry {$organization}", __FUNCTION__, __FILE__, __LINE__, "import", $GLOBALS["SCHEDULE_ID"]); return; } $OUS = $ldap->hash_get_ou(true); } if (!isset($GLOBALS["GROUPS"][$organization])) { $GLOBALS["GROUPS"][$organization] = $ldap->hash_groups($organization); } if (!isset($GLOBALS["GROUPS"][$organization][$groupname])) { $gp = new groups(); $gp->ou = $organization; $gp->groupName = $groupname; if (!$gp->add_new_group($groupname, $organization)) { system_admin_events("fatal error failed to create entry {$groupname}/{$organization}", __FUNCTION__, __FILE__, __LINE__, "import", $GLOBALS["SCHEDULE_ID"]); return; } $GLOBALS["GROUPS"][$organization] = $ldap->hash_groups($organization); } if (!isset($GLOBALS["GROUPS"][$organization][$groupname]["gid"])) { if ($GLOBALS["VERBOSE"]) { echo "{$groupname}/{$organization} NO GID!!\n"; } continue; } $gid = $GLOBALS["GROUPS"][$organization][$groupname]["gid"]; if ($password == null) { $password = $account; } $UPDATE = FALSE; $user = new user($account); if (!is_numeric($user->uidNumber)) { $UPDATE = true; } if ($email != null) { if ($user->mail != $email) { if ($GLOBALS["VERBOSE"]) { echo "mail {$email}\n"; } $user->mail = $email; $UPDATE = true; } } if ($password != null) { if ($user->password != $password) { if ($GLOBALS["VERBOSE"]) { echo "password {$password}\n"; } $user->password = $password; $UPDATE = true; } } if ($Telephon != null) { if ($user->telephoneNumber != $Telephon) { if ($GLOBALS["VERBOSE"]) { echo "telephoneNumber {$Telephon}\n"; } $user->telephoneNumber = $Telephon; $UPDATE = true; } } if ($mobile != null) { if ($user->mobile != $mobile) { if ($GLOBALS["VERBOSE"]) { echo "mobile {$mobile}\n"; } $user->mobile = $mobile; $UPDATE = true; } } if ($user->ou != $organization) { if ($GLOBALS["VERBOSE"]) { echo "ou {$organization}\n"; } $user->ou = $organization; $UPDATE = true; } $user->group_id = $gid; if ($UPDATE) { $c++; if (!$user->SaveUser()) { continue; } } $SCANNED[$SCANMD] = time(); @file_put_contents("{$targetdir}/{$filename}.scanned", serialize($SCANNED)); if ($d > 500) { if (system_is_overloaded()) { system_admin_events("{$connection}: Overloaded system, aborting task", __FUNCTION__, __FILE__, __LINE__); return false; } $distance = $unix->distanceOfTimeInWords($t1, time(), true); system_admin_events("{$connection}: {$c} lines processed in {$distance}", __FUNCTION__, __FILE__, __LINE__); $d = 0; } } $date = date("Y-m-d H:i:s"); $q = new mysql(); $q->QUERY_SQL("UPDATE `texttoldap` SET `lastmd5`='{$md5file}',`lastscan`='{$date}' WHERE ID='{$ID}'", "artica_backup"); $distance = $unix->distanceOfTimeInWords($t1, time(), true); system_admin_events("{$connection}: {$c} lines processed in {$distance}", __FUNCTION__, __FILE__, __LINE__); $umount = $unix->find_program("umount"); shell_exec("{$umount} -l {$mountpoint}"); return true; }
function finish() { include_once 'ressources/class.artica.inc'; $company_name = $_GET["company_name"]; $domain_name = $_GET["domain_name"]; $relay_behavior = $_GET["relay"]; $relay_infos = $_GET["relay_infos"]; $artica = new artica_general(); $artica->RelayType = $relay_behavior; $artica->Save(); $ldap = new clladp(); $ldap->AddOrganization($company_name); if ($relay_behavior == "single") { if ($relay_infos == null) { $relay_infos = "127.0.0.1"; } $ldap->AddDomainTransport($company_name, $domain_name, $relay_infos, '25', 'smtp'); } else { $ldap->AddDomainEntity($company_name, $domain_name); } $html = "<div style='padding:5px;margin:5px'>\n\t\t<H2>{finish}</H2>\n\t<table>\n\t<tr>\n\t<td><img src='img/150-org.jpg'></td>\n\t<td valign='top'>\t\n\t<table>\n\t<tr>\n\t\t<td width=60% class='caption' nowrap align='right'><strong>{all_settings_saved}:</strong></td >\n\t\t\n\t</tr>\t\n\t</table>\n\t</div>"; $tpl = new templates(); echo $tpl->_ENGINE_parse_body($html); }