function register_lic()
{
    ini_set('html_errors', 0);
    ini_set('display_errors', 1);
    ini_set('error_reporting', E_ALL);
    $sock = new sockets();
    $unix = new unix();
    $ini = new Bs_IniHandler();
    $function_ghost = base64_decode("Y2hlY2tsaWNlbnNlLmJpbg==");
    $error1 = base64_decode("e2dlbmVyaWNfaHR0cF9lcnJvcn0=");
    $textGhost = base64_decode("Q29ycG9yYXRlIExpY2Vuc2UgZXhwaXJlZCAtIHJldHVybiBiYWNrIHRvIENvbW11bml0eSBsaWNlbnNl");
    $verifailed = base64_decode("Q29ycG9yYXRlIExpY2Vuc2UgZXhwaXJlZCAtIHJldHVybiBiYWNrIHRvIENvbW11bml0eSBsaWNlbnNl");
    $licexpir = base64_decode("e2xpY2Vuc2VfZXhwaXJlZH0=");
    $line_ghost = base64_decode("MTA4NDM=");
    $datas = $sock->GET_INFO("ArticaProxySettings");
    $squidbin = $unix->LOCATE_SQUID_BIN();
    $php = $unix->LOCATE_PHP5_BIN();
    $ArticaProxyServerEnabled = null;
    if (trim($datas) != null) {
        $ini->loadString($datas);
        $ArticaProxyServerEnabled = $ini->_params["PROXY"]["ArticaProxyServerEnabled"];
        if ($ArticaProxyServerEnabled == 1) {
            $ArticaProxyServerEnabled == "yes";
        }
    }
    echo "Use a Proxy server: {$ArticaProxyServerEnabled}\n";
    $WORKDIR = base64_decode("L3Vzci9sb2NhbC9zaGFyZS9hcnRpY2E=");
    $WORKFILE = base64_decode('LmxpYw==');
    $WORKPATH = "{$WORKDIR}/{$WORKFILE}";
    $nohup = $unix->find_program("nohup");
    if ($GLOBALS["VERBOSE"]) {
        echo __FUNCTION__ . "::" . __LINE__ . "\n";
    }
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $cachetime = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time";
    $pid = @file_get_contents($pidfile);
    if ($unix->process_exists($pid)) {
        build_progress("License information: Already executed PID:{$pid}, die()", 100);
        die;
    }
    build_progress("Building informations...", 10);
    $EnableRemoteStatisticsAppliance = $sock->GET_INFO("EnableRemoteStatisticsAppliance");
    if (!is_numeric($EnableRemoteStatisticsAppliance)) {
        $EnableRemoteStatisticsAppliance = 0;
    }
    $cmdADD = null;
    if ($EnableRemoteStatisticsAppliance == 1) {
        $cmdADD = "{$nohup} " . $unix->LOCATE_PHP5_BIN() . " " . dirname(__FILE__) . "/exec.netagent.php >/dev/null 2>&1 &";
    }
    $WizardSavedSettings = unserialize(base64_decode($sock->GET_INFO("WizardSavedSettings")));
    if ($GLOBALS["VERBOSE"]) {
        echo __FUNCTION__ . "::" . __LINE__ . "\n";
    }
    $LicenseInfos = unserialize(base64_decode($sock->GET_INFO("LicenseInfos")));
    if (!isset($LicenseInfos["COMPANY"])) {
        $LicenseInfos["COMPANY"] = null;
    }
    if (!isset($LicenseInfos["GoldKey"])) {
        $LicenseInfos["GoldKey"] = null;
    }
    if (!isset($LicenseInfos["REGISTER"])) {
        $LicenseInfos["REGISTER"] = null;
    }
    if (!isset($LicenseInfos["GoldKey"])) {
        $LicenseInfos["GoldKey"] = null;
    }
    if (!isset($WizardSavedSettings["GoldKey"])) {
        $WizardSavedSettings["GoldKey"] = null;
    }
    $LicenseInfos["STATS_APPLIANCE"] = 0;
    $LicenseInfos["COMPANY"] = str_replace("%uFFFD", "é", $LicenseInfos["COMPANY"]);
    if ($WizardSavedSettings["GoldKey"] != null) {
        if ($sock->IsGoldKey($WizardSavedSettings["GoldKey"])) {
            if ($LicenseInfos["GoldKey"] == null) {
                echo "Gold Key: {$WizardSavedSettings["GoldKey"]}\n";
                $LicenseInfos["GoldKey"] = $WizardSavedSettings["GoldKey"];
            }
        }
    }
    build_progress("Check information {$LicenseInfos["COMPANY"]}", 20);
    if ($GLOBALS["VERBOSE"]) {
        echo __FUNCTION__ . "::" . __LINE__ . "\n";
    }
    $uuid = $unix->GetUniqueID();
    build_progress("Check information {$uuid}", 30);
    echo " *************** \n\n UUID : {$uuid} \n\n ***************\n";
    if ($uuid == null) {
        build_progress("No system ID !", 110);
        return;
    }
    if (!is_numeric($LicenseInfos["REGISTER"])) {
        echo "License information: server is not registered\n";
    }
    if ($LicenseInfos["REGISTER"] != 1) {
        echo "License information: server is not registered\n";
        register();
        build_progress("License information: server is not registered", 110);
        echo "Please, restart again...";
        die;
    }
    $LicenseInfos["UUID"] = $uuid;
    $LicenseInfos["ARTICAVERSION"] = @file_get_contents("/usr/share/artica-postfix/VERSION");
    if (is_file("/etc/artica-postfix/STATS_APPLIANCE")) {
        $LicenseInfos["STATS_APPLIANCE"] = 1;
    }
    //if($GLOBALS["VERBOSE"]){$curl->parms["VERBOSE"]="yes";}
    if ($GLOBALS["VERBOSE"]) {
        echo __FUNCTION__ . "::" . __LINE__ . "\n";
    }
    if (!isset($LicenseInfos["license_number"])) {
        $LicenseInfos["license_number"] = null;
    }
    if ($LicenseInfos["license_number"] == "--") {
        $LicenseInfos["license_number"] = null;
    }
    if (strpos($LicenseInfos["license_number"], "(") > 0) {
        $LicenseInfos["license_number"] = null;
    }
    echo "License number:{$LicenseInfos["license_number"]}\n";
    @mkdir($WORKDIR, 640, true);
    if (isset($LicenseInfos["UNLOCKLIC"])) {
        if (strlen($LicenseInfos["UNLOCKLIC"]) > 4) {
            if (isset($LicenseInfos["license_number"])) {
                if (strlen($LicenseInfos["license_number"]) > 4) {
                    $manulic = aef00vh567($uuid) . "-" . aef00vh567($LicenseInfos["license_number"]);
                    if ($manulic == $LicenseInfos["UNLOCKLIC"]) {
                        @file_put_contents($WORKPATH, "TRUE");
                        $LicenseInfos["license_status"] = "{license_active}";
                        $LicenseInfos["TIME"] = time();
                        $sock->SaveConfigFile(base64_encode(serialize($LicenseInfos)), "LicenseInfos");
                        if ($cmdADD != null) {
                            shell_exec($cmdADD);
                        }
                        build_progress("{license_active}", 80);
                        CheckLic($LicenseInfos, $WizardSavedSettings);
                        return;
                    }
                }
            }
        }
    }
    $unix = new unix();
    $URIBASE = $unix->MAIN_URI();
    $URIBASE = str_replace("articatech.net", "artica.fr", $URIBASE);
    $verbosed = "?VERBOSE=yes&time=" . time();
    build_progress("Checking license on the cloud server...", 40);
    echo "Contacting {$URIBASE}\n";
    $curl = new ccurl("{$URIBASE}/shalla-orders.php", false, null);
    if ($ArticaProxyServerEnabled != "yes") {
        echo "* * * Set to not use Local proxy * * *\n";
        $curl->NoLocalProxy();
    }
    if ($GLOBALS["VERBOSE"]) {
        $curl->parms["VERBOSE"] = yes;
    }
    $curl->parms["REGISTER-LIC"] = base64_encode(serialize($LicenseInfos));
    $curl->parms["REGISTER-OLD"] = base64_encode(serialize($WizardSavedSettings));
    echo "Send request... please wait...\n";
    if (!$curl->get()) {
        build_progress("Failed to contact cloud server", 110);
        echo "Error: " . $curl->error . "\n";
        echo @implode("\n", $curl->errors);
        $LicenseInfos["TIME"] = time();
        $LicenseInfos["license_status"] = "{registration_failed} {$curl->error}";
        $sock->SaveConfigFile(base64_encode(serialize($LicenseInfos)), "LicenseInfos");
        if (!is_file("/etc/artica-postfix/REGISTRATION_FAILED_TIME")) {
            @file_put_contents("/etc/artica-postfix/REGISTRATION_FAILED_TIME", time());
            $sock->SaveConfigFile(base64_encode(serialize($LicenseInfos)), "LicenseInfos");
            return;
        }
        $LastTime = intval(@file_get_contents("/etc/artica-postfix/REGISTRATION_FAILED_TIME"));
        if ($LastTime == 0) {
            @file_put_contents("/etc/artica-postfix/REGISTRATION_FAILED_TIME", time());
            $sock->SaveConfigFile(base64_encode(serialize($LicenseInfos)), "LicenseInfos");
            return;
        }
        $TimeMin = $unix->time_min($LastTime);
        if ($TimeMin > 10080) {
            if (is_file($WORKPATH)) {
                @unlink($WORKPATH);
                squid_admin_mysql(0, base64_decode("Q2Fubm90IGNvbnRhY3QgY2xvdWQgc2VydmVyIHNpbmNlIDcgZGF5cywgdHVybiB0byBDb21tdW5pdHkgRWRpdGlvbg=="), $function_ghost, $line_ghost);
                $LicenseInfos["license_status"] = $error1;
                $LicenseInfos["license_number"] = "";
                $LicenseInfos["TIME"] = time();
                $sock->SaveConfigFile(base64_encode(serialize($LicenseInfos)), "LicenseInfos");
                shell_exec("/usr/share/artica-postfix/bin/process1 --force --verbose " . time() . " >/dev/null 2>&1");
            }
        }
        return;
    }
    @file_put_contents("/etc/artica-postfix/REGISTRATION_FAILED_TIME", 0);
    echo "OK....\n";
    build_progress("{checkiccloud1}", 50);
    //if($GLOBALS["VERBOSE"]){echo "***** $curl->data ****\n";}
    $finaltime = 0;
    if (preg_match("#<FINALTIME>([0-9]+)</FINALTIME>#s", $curl->data, $re)) {
        $finaltime = $re[1];
    }
    if ($finaltime > 0) {
        if (time() > $finaltime) {
            if (is_file($WORKPATH)) {
                @unlink($WORKPATH);
                build_progress($verifailed, 110);
                $array1["license_status"] = $licexpir;
                $array1["license_number"] = null;
                $array1["UNLOCKLIC"] = null;
                $array1["TIME"] = time();
                if ($finaltime > 0) {
                    $LicenseInfos["FINAL_TIME"] = $finaltime;
                }
                $sock->SaveConfigFile(base64_encode(serialize($LicenseInfos)), "LicenseInfos");
                squid_admin_mysql(0, $textGhost, null, $function_ghost, $line_ghost);
                shell_exec("/usr/share/artica-postfix/bin/process1 --force --verbose");
                if (is_file($squidbin)) {
                    shell_exec("{$php} /usr/share/artica-postfix/exec.squid.php --build");
                    shell_exec("{$php} /usr/share/artica-postfix/exec.kerbauth.php --disconnect");
                    shell_exec("/etc/init.d/squid restart {$GLOBALS["SCRIPT_SUFFIX"]}");
                }
                $sock->SaveConfigFile(base64_encode(serialize($array1)), "LicenseInfos");
            }
            return;
        }
    }
    if (preg_match("#<BADMAIL>(0|1)</BADMAIL>#s", $curl->data, $re)) {
        echo "***** EMAIL *****\n";
        $sock->SET_INFO("RegisterCloudBadEmail", $re[1]);
    }
    if (preg_match("#REGISTRATION_OK:\\[(.+?)\\]#s", $curl->data, $re)) {
        build_progress("{waiting_approval} {success}", 100);
        $LicenseInfos["license_status"] = "{waiting_approval}";
        $LicenseInfos["license_number"] = $re[1];
        $LicenseInfos["TIME"] = time();
        if ($finaltime > 0) {
            $LicenseInfos["FINAL_TIME"] = $finaltime;
        }
        $sock->SaveConfigFile(base64_encode(serialize($LicenseInfos)), "LicenseInfos");
        @unlink($WORKPATH);
        if ($cmdADD != null) {
            shell_exec($cmdADD);
        }
        shell_exec("/usr/share/artica-postfix/bin/process1 --force --verbose " . time() . " >/dev/null 2>&1");
        return;
    }
    if (preg_match("#LICENSE_OK:\\[(.+?)\\]#s", $curl->data, $re)) {
        echo "***** LICENSE_OK ****\n";
        @file_put_contents($WORKPATH, "TRUE");
        if ($finaltime > 0) {
            $LicenseInfos["FINAL_TIME"] = $finaltime;
        }
        $LicenseInfos["license_status"] = "{license_active}";
        $LicenseInfos["TIME"] = time();
        $sock->SaveConfigFile(base64_encode(serialize($LicenseInfos)), "LicenseInfos");
        if ($cmdADD != null) {
            shell_exec($cmdADD);
        }
        build_progress("{license_active} {refresh}", 100);
        system("/usr/share/artica-postfix/bin/process1 --force --verbose --" . time());
        build_progress("{license_active} {success}", 100);
        return;
    }
    if (preg_match("#REGISTRATION_INVALID#s", $curl->data, $re)) {
        @unlink($WORKPATH);
        echo "***** REGISTRATION_INVALID ****\n";
        $LicenseInfos["license_status"] = "{community_license}";
        $LicenseInfos["license_number"] = null;
        $LicenseInfos["UNLOCKLIC"] = null;
        $LicenseInfos["TIME"] = time();
        if ($finaltime > 0) {
            $LicenseInfos["FINAL_TIME"] = $finaltime;
        }
        build_progress("Community Edition - limited...", 100);
        $sock->SaveConfigFile(base64_encode(serialize($LicenseInfos)), "LicenseInfos");
        if ($cmdADD != null) {
            shell_exec($cmdADD);
        }
        $unix->Process1(true);
        return;
    }
    if (preg_match("#REGISTRATION_DELETE_NOW#s", $curl->data, $re)) {
        echo "***** REGISTRATION_DELETE_NOW ****\n";
        @unlink($WORKPATH);
        $LicenseInfos["license_status"] = "Community Edition - limited";
        $LicenseInfos["license_number"] = null;
        $LicenseInfos["UNLOCKLIC"] = null;
        $LicenseInfos["TIME"] = time();
        if ($finaltime > 0) {
            $LicenseInfos["FINAL_TIME"] = $finaltime;
        }
        $unix->Process1(true);
        $sock->SaveConfigFile(base64_encode(serialize($LicenseInfos)), "LicenseInfos");
        shell_exec("/usr/share/artica-postfix/bin/process1 --force --verbose " . time() . " >/dev/null 2>&1");
        build_progress("Community Edition - limited", 110);
        return;
    }
    if ($curl->error != null) {
        system_admin_events("License registration failed with error {$curl->error}", "GetLicense", "license", 0, "license");
    }
    build_progress("Unknown registration?", 110);
    if (!is_file($WORKPATH)) {
        build_progress("{waiting_order}", 110);
        echo "***** Registration_failed ****\n";
        $LicenseInfos["TIME"] = time();
        if ($LicenseInfos["license_number"] == null) {
            $LicenseInfos["license_status"] = "{registration_failed} {$curl->error}";
        }
        $sock->SaveConfigFile(base64_encode(serialize($LicenseInfos)), "LicenseInfos");
    }
    if ($cmdADD != null) {
        shell_exec($cmdADD);
    }
}
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 register_lic()
{
    ini_set('html_errors', 0);
    ini_set('display_errors', 1);
    ini_set('error_reporting', E_ALL);
    $sock = new sockets();
    $unix = new unix();
    $WORKDIR = base64_decode("L3Vzci9sb2NhbC9zaGFyZS9hcnRpY2E=");
    $WORKFILE = base64_decode('LmxpYw==');
    $WORKPATH = "{$WORKDIR}/{$WORKFILE}";
    $nohup = $unix->find_program("nohup");
    if ($GLOBALS["VERBOSE"]) {
        echo __FUNCTION__ . "::" . __LINE__ . "\n";
    }
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $cachetime = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time";
    $pid = @file_get_contents($pidfile);
    if ($unix->process_exists($pid)) {
        build_progress("License information: Already executed PID:{$pid}, die()", 100);
        die;
    }
    build_progress("Building informations...", 10);
    $EnableRemoteStatisticsAppliance = $sock->GET_INFO("EnableRemoteStatisticsAppliance");
    if (!is_numeric($EnableRemoteStatisticsAppliance)) {
        $EnableRemoteStatisticsAppliance = 0;
    }
    $cmdADD = null;
    if ($EnableRemoteStatisticsAppliance == 1) {
        $cmdADD = "{$nohup} " . $unix->LOCATE_PHP5_BIN() . " " . dirname(__FILE__) . "/exec.netagent.php >/dev/null 2>&1 &";
    }
    $WizardSavedSettings = unserialize(base64_decode($sock->GET_INFO("WizardSavedSettings")));
    if ($GLOBALS["VERBOSE"]) {
        echo __FUNCTION__ . "::" . __LINE__ . "\n";
    }
    $LicenseInfos = unserialize(base64_decode($sock->GET_INFO("LicenseInfos")));
    if (!isset($LicenseInfos["GoldKey"])) {
        $LicenseInfos["GoldKey"] = null;
    }
    $LicenseInfos["COMPANY"] = str_replace("%uFFFD", "é", $LicenseInfos["COMPANY"]);
    if ($WizardSavedSettings["GoldKey"] != null) {
        if ($sock->IsGoldKey($WizardSavedSettings["GoldKey"])) {
            if ($LicenseInfos["GoldKey"] == null) {
                echo "Gold Key: {$WizardSavedSettings["GoldKey"]}\n";
                $LicenseInfos["GoldKey"] = $WizardSavedSettings["GoldKey"];
            }
        }
    }
    build_progress("Check information {$LicenseInfos["COMPANY"]}", 20);
    if ($GLOBALS["VERBOSE"]) {
        echo __FUNCTION__ . "::" . __LINE__ . "\n";
    }
    $uuid = $unix->GetUniqueID();
    build_progress("Check information {$uuid}", 30);
    echo " *************** \n\n UUID : {$uuid} \n\n ***************\n";
    if ($uuid == null) {
        build_progress("No system ID !", 110);
        return;
    }
    if (!is_numeric($LicenseInfos["REGISTER"])) {
        echo "License information: server is not registered\n";
    }
    if ($LicenseInfos["REGISTER"] != 1) {
        echo "License information: server is not registered\n";
        build_progress("License information: server is not registered", 110);
        die;
    }
    $LicenseInfos["UUID"] = $uuid;
    //if($GLOBALS["VERBOSE"]){$curl->parms["VERBOSE"]="yes";}
    if ($GLOBALS["VERBOSE"]) {
        echo __FUNCTION__ . "::" . __LINE__ . "\n";
    }
    if (!isset($LicenseInfos["license_number"])) {
        $LicenseInfos["license_number"] = null;
    }
    if ($LicenseInfos["license_number"] == "--") {
        $LicenseInfos["license_number"] = null;
    }
    if (strpos($LicenseInfos["license_number"], "(") > 0) {
        $LicenseInfos["license_number"] = null;
    }
    echo "License number:{$LicenseInfos["license_number"]}\n";
    @mkdir($WORKDIR, 640, true);
    if (isset($LicenseInfos["UNLOCKLIC"])) {
        if (strlen($LicenseInfos["UNLOCKLIC"]) > 4) {
            if (isset($LicenseInfos["license_number"])) {
                if (strlen($LicenseInfos["license_number"]) > 4) {
                    $manulic = aef00vh567($uuid) . "-" . aef00vh567($LicenseInfos["license_number"]);
                    if ($manulic == $LicenseInfos["UNLOCKLIC"]) {
                        @file_put_contents($WORKPATH, "TRUE");
                        $LicenseInfos["license_status"] = "{license_active}";
                        $LicenseInfos["TIME"] = time();
                        $sock->SaveConfigFile(base64_encode(serialize($LicenseInfos)), "LicenseInfos");
                        if ($cmdADD != null) {
                            shell_exec($cmdADD);
                        }
                        build_progress("{license_active}", 80);
                        CheckLic($LicenseInfos, $WizardSavedSettings);
                        return;
                    }
                }
            }
        }
    }
    $unix = new unix();
    $URIBASE = $unix->MAIN_URI();
    $URIBASE = str_replace("articatech.net", "artica.fr", $URIBASE);
    $verbosed = "?VERBOSE=yes&time=" . time();
    build_progress("Checking license on the cloud server...", 40);
    echo "Contacting {$URIBASE}\n";
    $curl = new ccurl("{$URIBASE}/shalla-orders.php", false, null, true);
    echo "Set to not use Local proxy\n";
    $curl->NoLocalProxy();
    if ($GLOBALS["VERBOSE"]) {
        $curl->parms["VERBOSE"] = yes;
    }
    $curl->parms["REGISTER-LIC"] = base64_encode(serialize($LicenseInfos));
    $curl->parms["REGISTER-OLD"] = base64_encode(serialize($WizardSavedSettings));
    echo "Send request... please wait...\n";
    if (!$curl->get()) {
        build_progress("Failed to contact cloud server", 110);
        echo "Error: " . $curl->error . "\n";
        echo @implode("\n", $curl->errors);
        $LicenseInfos["TIME"] = time();
        $LicenseInfos["license_status"] = "{registration_failed} {$curl->error}";
        $sock->SaveConfigFile(base64_encode(serialize($LicenseInfos)), "LicenseInfos");
        return;
    }
    echo "Request passed\n";
    build_progress("Cheking license on the cloud server done.", 50);
    if ($GLOBALS["VERBOSE"]) {
        echo "***** {$curl->data} ****\n";
    }
    if (preg_match("#REGISTRATION_OK:\\[(.+?)\\]#s", $curl->data, $re)) {
        build_progress("{waiting_approval} {success}", 100);
        $LicenseInfos["license_status"] = "{waiting_approval}";
        $LicenseInfos["license_number"] = $re[1];
        $LicenseInfos["TIME"] = time();
        $sock->SaveConfigFile(base64_encode(serialize($LicenseInfos)), "LicenseInfos");
        @unlink($WORKPATH);
        if ($cmdADD != null) {
            shell_exec($cmdADD);
        }
        shell_exec("/usr/share/artica-postfix/bin/process1 --force --verbose " . time() . " >/dev/null 2>&1");
        return;
    }
    if (preg_match("#LICENSE_OK:\\[(.+?)\\]#s", $curl->data, $re)) {
        echo "***** LICENSE_OK ****\n";
        @file_put_contents($WORKPATH, "TRUE");
        $LicenseInfos["license_status"] = "{license_active}";
        $LicenseInfos["TIME"] = time();
        $sock->SaveConfigFile(base64_encode(serialize($LicenseInfos)), "LicenseInfos");
        if ($cmdADD != null) {
            shell_exec($cmdADD);
        }
        build_progress("{license_active} {refresh}", 100);
        system("/usr/share/artica-postfix/bin/process1 --force --verbose --" . time());
        build_progress("{license_active} {success}", 100);
        return;
    }
    if (preg_match("#REGISTRATION_INVALID#s", $curl->data, $re)) {
        @unlink($WORKPATH);
        echo "***** REGISTRATION_INVALID ****\n";
        $LicenseInfos["license_status"] = "{community_license}";
        $LicenseInfos["license_number"] = null;
        $LicenseInfos["UNLOCKLIC"] = null;
        $LicenseInfos["TIME"] = time();
        build_progress("Community Edition - limited...", 100);
        $sock->SaveConfigFile(base64_encode(serialize($LicenseInfos)), "LicenseInfos");
        if ($cmdADD != null) {
            shell_exec($cmdADD);
        }
        $unix->Process1(true);
        return;
    }
    if (preg_match("#REGISTRATION_DELETE_NOW#s", $curl->data, $re)) {
        echo "***** REGISTRATION_DELETE_NOW ****\n";
        @unlink($WORKPATH);
        $LicenseInfos["license_status"] = "Community Edition - limited";
        $LicenseInfos["license_number"] = null;
        $LicenseInfos["UNLOCKLIC"] = null;
        $LicenseInfos["TIME"] = time();
        $unix->Process1(true);
        $sock->SaveConfigFile(base64_encode(serialize($LicenseInfos)), "LicenseInfos");
        shell_exec("/usr/share/artica-postfix/bin/process1 --force --verbose " . time() . " >/dev/null 2>&1");
        build_progress("Community Edition - limited", 110);
        return;
    }
    if ($curl->error != null) {
        system_admin_events("License registration failed with error {$curl->error}", "GetLicense", "license", 0, "license");
    }
    build_progress("Unknown registration?", 110);
    if (!is_file($WORKPATH)) {
        build_progress("{registration_failed} {failed}", 110);
        echo "***** Registration_failed ****\n";
        $LicenseInfos["TIME"] = time();
        if ($LicenseInfos["license_number"] == null) {
            $LicenseInfos["license_status"] = "{registration_failed} {$curl->error}";
        }
        $sock->SaveConfigFile(base64_encode(serialize($LicenseInfos)), "LicenseInfos");
    }
    if ($cmdADD != null) {
        shell_exec($cmdADD);
    }
}