<?php
/**
 * @package embed-sharepoint-onedrive-documents
 * @author miniOrange
 * @link https://plugins.miniorange.com
 */


namespace MoSharePointObjectSync\Controller;

use MoSharePointObjectSync\MOsps;
use MoSharePointObjectSync\API\CustomerMOSPS;
use MoSharePointObjectSync\Wrappers\wpWrapper;
use MoSharePointObjectSync\LicenseLibrary\Mo_License_Service;
class accountSetup
{
    private static $user;
    public static function getController()
    {
        if (isset(self::$user)) {
            goto cb;
        }
        self::$user = new accountSetup();
        cb:
        return self::$user;
    }
    public function mo_sps_save_settings()
    {
        $lN = sanitize_text_field($_POST["\x6f\160\164\151\x6f\x6e"]);
        switch ($lN) {
            case "\155\x6f\137\163\x70\x73\137\141\x63\143\157\165\x6e\x74\x5f\x73\145\164\x75\160\137\157\160\x74\x69\157\x6e":
                $this->mo_sps_account_setup();
                goto uq;
            case "\x6d\x6f\x5f\x73\x70\x73\x5f\166\145\x72\151\146\171\x5f\x6c\151\143\x65\x6e\x73\x65\137\157\160\x74\x69\157\156":
                $this->mo_sps_verify_license();
                goto uq;
            case "\155\157\137\163\160\163\137\x67\157\137\142\141\x63\x6b\137\x66\162\x6f\155\x5f\154\x69\x63\x65\x6e\163\145\137\160\141\147\x65\137\x6f\160\x74\151\x6f\156":
                $this->mo_sps_go_back_from_license_page();
                goto uq;
            case "\x6d\157\x5f\163\x70\x73\x5f\162\145\155\x6f\166\x65\x5f\x61\x63\x63\x6f\x75\x6e\x74\137\x6f\160\164\x69\157\x6e":
                $this->mo_sps_remove_account();
                goto uq;
            case "\x6d\157\x5f\x73\x70\163\x5f\163\171\156\143\137\x6c\x69\x63\145\x6e\163\145\137\x6f\x70\x74\151\157\x6e":
                $this->mo_sps_sync_license();
                goto uq;
        }
        N_:
        uq:
    }
    private function mo_sps_is_extension_installed($DQ)
    {
        if (in_array($DQ, get_loaded_extensions())) {
            goto Yt;
        }
        return 0;
        goto nn;
        Yt:
        return 1;
        nn:
    }
    private function mo_sps_sync_license()
    {
        check_admin_referer("\155\157\137\163\x70\163\x5f\163\x79\x6e\143\137\x6c\x69\143\x65\x6e\x73\145\x5f\157\x70\164\151\x6f\156");
        Mo_License_Service::refresh_license_expiry();
    }
    private function mo_sps_account_setup()
    {
        check_admin_referer("\155\x6f\137\x73\160\x73\x5f\x61\143\x63\x6f\x75\x6e\164\137\163\x65\164\x75\x70\137\157\160\x74\x69\157\156");
        if ($this->mo_sps_is_extension_installed("\143\x75\162\154")) {
            goto JG;
        }
        wpWrapper::mo_sps__show_error_notice("\105\x52\x52\117\122\x3a\40\x50\110\120\40\143\125\x52\114\40\x65\x78\164\x65\156\x73\x69\157\x6e\x20\x69\163\40\x6e\x6f\164\x20\x69\156\x73\x74\141\x6c\154\145\144\x20\x6f\x72\40\x64\x69\163\x61\142\154\x65\x64\56\x20\x4c\x6f\147\x69\156\40\x66\x61\151\154\x65\144\x2e");
        return;
        JG:
        $w6 = '';
        $bA = '';
        if (empty($_POST["\141\x63\x63\x6f\x75\156\164\137\x65\x6d\141\151\x6c"]) || empty($_POST["\x61\143\x63\157\x75\156\164\137\160\x77\x64"])) {
            goto EF;
        }
        if (wpWrapper::mo_sps__checkPasswordPattern(strip_tags($_POST["\141\x63\143\157\165\x6e\164\x5f\160\167\144"]))) {
            goto R7;
        }
        $w6 = sanitize_email($_POST["\141\143\x63\157\165\156\164\x5f\145\155\x61\151\154"]);
        $bA = stripslashes(strip_tags($_POST["\x61\x63\x63\157\x75\x6e\x74\137\160\x77\144"]));
        goto eQ;
        R7:
        wpWrapper::mo_sps__show_error_notice("\x4d\x69\156\151\155\x75\x6d\x20\66\x20\143\150\141\162\141\143\x74\x65\162\163\40\163\x68\x6f\x75\x6c\x64\40\x62\x65\x20\160\162\x65\x73\145\156\164\x2e\x20\115\141\170\151\155\x75\x6d\x20\x31\x35\x20\x63\150\x61\162\x61\143\x74\x65\162\x73\x20\163\x68\x6f\x75\x6c\x64\40\x62\x65\x20\x70\x72\x65\x73\x65\156\x74\x2e\40\x4f\x6e\154\171\40\146\157\154\x6c\x6f\167\151\156\147\40\x73\171\155\x62\x6f\154\163\x20\50\41\x40\43\56\x24\x25\x5e\x26\52\x2d\137\x29\x20\x73\150\x6f\x75\154\144\x20\142\x65\40\160\162\145\163\x65\156\x74\x2e");
        return;
        eQ:
        goto kp;
        EF:
        wpWrapper::mo_sps__show_error_notice("\101\154\x6c\x20\x74\x68\x65\x20\146\x69\x65\x6c\x64\163\40\141\162\x65\x20\162\x65\161\165\151\x72\145\x64\56\40\x50\154\x65\141\x73\x65\x20\145\156\164\145\x72\x20\x76\141\154\x69\x64\40\145\156\164\162\x69\145\x73\56");
        return;
        kp:
        update_option("\x6d\157\x5f\x73\160\163\137\x61\x64\155\151\x6e\x5f\145\155\x61\151\154", $w6);
        update_option("\155\x6f\x5f\163\160\163\x5f\141\144\155\x69\156\x5f\160\x61\x73\x73\x77\x6f\162\144", $bA);
        $za = new CustomerMOSPS();
        $ZJ = $za->mo_sps_get_customer_key();
        if ($ZJ) {
            goto T5;
        }
        return;
        T5:
        $wH = json_decode($ZJ, true);
        if (json_last_error() == JSON_ERROR_NONE) {
            goto ub;
        }
        $w6 = sanitize_email($_POST["\x61\143\x63\157\x75\156\x74\x5f\x65\155\141\x69\154"]);
        update_option("\155\157\137\163\x70\x73\137\x61\x64\155\x69\156\x5f\145\x6d\x61\151\x6c", $w6);
        wpWrapper::mo_sps__show_error_notice("\x49\x6e\x76\141\x6c\x69\x64\40\165\x73\x65\162\156\x61\155\145\40\x6f\162\x20\x70\x61\x73\163\x77\x6f\162\144\x2e\40\120\154\145\141\x73\x65\x20\164\162\171\x20\141\x67\141\x69\156\56");
        goto H_;
        ub:
        update_option("\x6d\157\137\x73\x70\x73\x5f\141\144\155\151\x6e\x5f\x63\x75\x73\164\x6f\155\x65\162\137\x6b\145\x79", $wH["\151\x64"]);
        update_option("\155\157\137\163\160\163\137\141\x64\x6d\x69\x6e\137\x61\160\151\137\153\145\x79", $wH["\x61\x70\x69\113\145\171"]);
        update_option("\155\x6f\137\163\160\163\137\x63\x75\163\x74\x6f\x6d\x65\x72\137\x74\157\x6b\x65\x6e", $wH["\x74\157\x6b\x65\156"]);
        if (empty($wH["\x70\x68\157\156\145"])) {
            goto wj;
        }
        update_option("\155\x6f\137\x73\160\x73\x5f\x61\144\155\151\156\137\160\150\157\x6e\x65", $wH["\x70\x68\157\156\x65"]);
        wj:
        update_option("\x6d\x6f\137\163\x70\163\137\141\x64\155\151\156\137\x70\x61\x73\163\167\x6f\162\x64", '');
        update_option("\x6d\x6f\x5f\x73\160\163\137\162\145\147\151\163\x74\x72\141\x74\151\157\x6e\x5f\x73\x74\x61\164\165\163", "\x45\x78\151\163\x74\151\x6e\x67\x20\125\x73\145\x72");
        delete_option("\x6d\157\x5f\163\160\163\137\166\145\x72\151\146\x79\x5f\143\x75\x73\164\x6f\x6d\145\x72");
        if (get_option("\x73\160\x73\137\154\153")) {
            goto FB;
        }
        wpWrapper::mo_sps__show_success_notice("\103\165\x73\164\157\155\x65\162\x20\162\x65\164\x72\151\x65\x76\x65\144\40\x73\x75\x63\x63\x65\x73\163\x66\165\154\154\x79");
        goto th;
        FB:
        $cD = get_option("\155\x6f\x5f\163\x70\x73\x5f\x63\x75\x73\x74\157\x6d\x65\162\x5f\x74\157\x6b\x65\156");
        $Cf = wpWrapper::mo_sps_decrypt_data(get_option("\x73\x70\x73\x5f\154\x6b"), $cD);
        $ZJ = $za->mo_sps_vl($Cf, false);
        if ($ZJ) {
            goto f0;
        }
        return;
        f0:
        $ZJ = json_decode($ZJ, true);
        update_option("\x6d\157\x5f\163\x70\x73\137\x76\x6c\x5f\143\x68\145\x63\x6b\x5f\x74", time());
        if (strcasecmp($ZJ["\163\164\141\164\x75\x73"], "\123\x55\103\103\105\x53\x53") == 0) {
            goto WS;
        }
        delete_option("\163\160\163\x5f\x6c\153");
        wpWrapper::mo_sps__show_error_notice("\x4c\151\143\145\156\x73\145\40\153\145\x79\x20\x66\157\x72\40\164\150\151\x73\x20\x69\156\x73\164\141\x6e\x63\145\40\x69\x73\40\151\156\x63\157\x72\162\145\x63\x74\x2e\x20\x4d\x61\153\145\x20\x73\x75\162\x65\40\x79\157\x75\40\150\141\166\x65\40\x6e\x6f\164\40\164\x61\x6d\160\145\x72\x65\x64\x20\167\x69\164\x68\40\151\x74\x20\x61\x74\40\141\x6c\154\x2e\40\x50\154\x65\141\x73\x65\x20\145\x6e\x74\x65\162\x20\141\x20\x76\x61\154\151\144\40\154\x69\143\145\x6e\x73\x65\x20\153\x65\x79\x2e");
        goto F2;
        WS:
        $nJ = plugin_dir_path(__FILE__);
        $Mc = home_url();
        $Mc = trim($Mc, "\x2f");
        if (preg_match("\x23\136\150\x74\164\160\50\x73\51\77\x3a\x2f\57\43", $Mc)) {
            goto H1;
        }
        $Mc = "\x68\x74\x74\160\72\57\57" . $Mc;
        H1:
        $vD = parse_url($Mc);
        $HP = preg_replace("\57\x5e\x77\x77\167\134\56\x2f", '', $vD["\x68\157\163\164"]);
        $Lf = wp_upload_dir();
        $R5 = $HP . "\x2d" . $Lf["\x62\141\x73\x65\144\151\162"];
        $yp = hash_hmac("\x73\150\x61\x32\x35\x36", $R5, "\64\104\110\x66\x6a\x67\146\x6a\x61\x73\x6e\x64\x66\163\141\x6a\146\110\107\x4a");
        $AM = wpWrapper::djkasjdksa();
        $a6 = round(strlen($AM) / rand(2, 20));
        $AM = substr_replace($AM, $yp, $a6, 0);
        $qe = base64_decode($AM);
        if (is_writable($nJ . "\x6c\151\x63\145\x6e\163\145")) {
            goto DJ;
        }
        $AM = str_rot13($AM);
        $pC = base64_decode("\x62\x47\116\x6b\x61\155\164\x68\x63\x32\160\153\141\63\116\x68\131\x32\x77\75");
        update_option($pC, $AM);
        goto F_;
        DJ:
        file_put_contents($nJ . "\x6c\x69\x63\x65\156\163\145", $qe);
        F_:
        update_option("\x6c\x63\x77\162\x74\154\x66\163\x61\155\x6c", true);
        wpWrapper::mo_sps__show_success_notice("\x43\165\163\164\x6f\x6d\145\162\40\x72\145\164\162\x69\145\x76\145\x64\x20\x73\165\x63\x63\x65\x73\163\x66\x75\154\x6c\171");
        F2:
        th:
        H_:
        update_option("\155\157\137\163\160\163\x5f\x61\x64\x6d\151\x6e\137\x70\141\163\x73\x77\x6f\x72\144", '');
    }
    private function mo_sps_verify_license()
    {
        check_admin_referer("\155\157\137\x73\160\x73\x5f\x76\145\x72\151\x66\x79\x5f\x6c\x69\x63\145\x6e\163\x65\x5f\x6f\x70\164\151\157\156");
        if (!empty($_POST["\x6d\x6f\x5f\x73\160\163\x5f\x6c\151\143\145\156\143\145\137\153\x65\171"])) {
            goto A3;
        }
        wpWrapper::mo_sps__show_error_notice("\x41\x6c\x6c\40\164\150\x65\x20\146\x69\145\154\x64\163\x20\x61\162\145\x20\162\x65\161\165\x69\x72\x65\x64\x2e\x20\120\x6c\145\x61\163\145\x20\145\x6e\x74\145\x72\x20\x76\x61\154\151\x64\40\154\x69\x63\145\x6e\163\145\40\x6b\x65\171\56");
        return;
        A3:
        $Cf = htmlspecialchars(trim($_POST["\x6d\x6f\x5f\x73\160\163\x5f\x6c\151\x63\x65\x6e\143\x65\x5f\x6b\145\171"]));
        $za = new CustomerMOSPS();
        $ZJ = $za->mo_sps_check_customer_ln();
        if ($ZJ) {
            goto Yo;
        }
        return;
        Yo:
        $ZJ = json_decode($ZJ, true);
        if (strcasecmp($ZJ["\x73\164\x61\164\x75\163"], "\123\x55\x43\x43\x45\x53\x53") == 0) {
            goto GD;
        }
        $cD = get_option("\x6d\157\137\x73\x70\163\x5f\x63\165\x73\164\x6f\155\145\162\x5f\x74\x6f\x6b\x65\x6e");
        update_option("\163\x69\164\x65\x5f\x63\x6b\x5f\x6c", wpWrapper::mo_sps_encrypt_data("\146\141\154\x73\x65", $cD));
        wpWrapper::mo_sps__show_error_notice("\x59\x6f\165\x20\x68\141\x76\x65\x20\156\x6f\x74\x20\x75\x70\147\x72\x61\144\145\x64\40\171\145\x74\56");
        goto ks;
        GD:
        $f2 = 0;
        if (!array_key_exists("\156\x6f\117\x66\125\163\145\x72\163", $ZJ)) {
            goto tC;
        }
        $f2 = $ZJ["\156\x6f\117\146\x55\x73\145\x72\x73"];
        tC:
        $ZJ = $za->mo_sps_vl($Cf, false);
        if ($ZJ) {
            goto vn;
        }
        return;
        vn:
        $ZJ = json_decode($ZJ, true);
        update_option("\x6d\x6f\x5f\x73\160\163\x5f\x76\154\137\x63\x68\x65\143\x6b\x5f\164", time());
        if (is_array($ZJ) and strcasecmp($ZJ["\x73\x74\x61\x74\x75\x73"], "\123\x55\103\103\x45\x53\123") == 0) {
            goto oQ;
        }
        if (is_array($ZJ) and strcasecmp($ZJ["\163\x74\x61\164\x75\163"], "\106\x41\x49\114\105\x44") == 0) {
            goto hN;
        }
        wpWrapper::mo_sps__show_error_notice("\x41\x6e\40\x65\162\162\x6f\162\x20\x6f\143\x63\165\162\x72\145\144\x20\x77\x68\151\x6c\145\40\160\x72\x6f\x63\145\x73\163\151\156\x67\x20\x79\x6f\x75\x72\40\162\x65\161\x75\145\163\x74\x2e\40\120\154\x65\141\163\145\40\124\x72\x79\x20\141\x67\141\x69\156\x2e");
        goto dk;
        hN:
        if (strcasecmp($ZJ["\155\145\x73\163\141\147\x65"], "\x43\x6f\144\145\40\150\141\163\40\105\170\x70\151\x72\x65\x64") == 0) {
            goto yB;
        }
        wpWrapper::mo_sps__show_error_notice("\131\x6f\x75\40\150\x61\x76\145\40\145\x6e\164\x65\x72\145\x64\x20\x61\x6e\40\151\x6e\x76\x61\x6c\x69\x64\40\154\151\x63\145\x6e\x73\x65\x20\x6b\x65\171\x2e\x20\120\154\145\x61\163\145\40\x65\156\x74\145\x72\x20\x61\x20\166\x61\x6c\x69\x64\x20\x6c\x69\143\x65\x6e\163\145\40\x6b\x65\x79\x2e");
        goto Pk;
        yB:
        wpWrapper::mo_sps__show_error_notice("\114\x69\143\x65\156\163\145\x20\153\x65\171\x20\171\x6f\165\40\x68\141\166\x65\40\x65\x6e\164\x65\x72\x65\144\40\150\141\163\x20\x61\x6c\x72\145\141\x64\171\x20\x62\x65\x65\x6e\40\x75\x73\x65\144\x2e\x20\120\x6c\x65\141\163\145\x20\145\x6e\x74\x65\x72\40\x61\40\x6b\145\x79\x20\167\150\151\143\150\x20\x68\141\x73\40\156\157\x74\40\x62\x65\x65\x6e\40\x75\163\145\x64\x20\x62\145\x66\x6f\162\x65\x20\x6f\156\x20\x61\x6e\x79\x20\x6f\x74\x68\145\162\x20\x69\x6e\x73\x74\141\x6e\x63\x65\40\x6f\x72\40\x69\x66\40\x79\157\165\x20\x68\141\x76\x65\x20\145\170\x61\165\x73\x74\x65\x64\x20\141\x6c\154\40\x79\x6f\x75\x72\x20\x6b\145\x79\x73\40\x74\150\145\156\40\143\157\156\x74\141\143\x74\x20\165\x73\40\x61\164\40\x6f\146\146\x69\143\145\63\66\x35\x73\165\x70\160\x6f\162\164\100\x78\145\x63\x75\x72\x69\146\171\56\143\x6f\x6d\40\164\x6f\x20\142\x75\171\x20\x6d\x6f\162\x65");
        Pk:
        dk:
        goto Wn;
        oQ:
        $cD = get_option("\155\x6f\x5f\163\160\x73\x5f\x63\x75\163\x74\x6f\155\x65\x72\137\164\x6f\x6b\x65\x6e");
        update_option("\163\160\x73\137\x6c\x6b", wpWrapper::mo_sps_encrypt_data($Cf, $cD));
        update_option("\x73\x69\164\145\x5f\143\153\x5f\x6c", wpWrapper::mo_sps_encrypt_data("\x74\x72\x75\145", $cD));
        wpWrapper::mo_sps_set_option("\155\x6f\x5f\x73\x70\163\x5f\165\163\x65\162\x73\137\x63\157\x75\x6e\164", wpWrapper::mo_sps_encrypt_data($f2, $cD));
        update_option("\x74\x5f\x73\x69\164\145\x5f\x73\164\141\164\x75\x73", wpWrapper::mo_sps_encrypt_data("\146\141\x6c\x73\x65", $cD));
        $nJ = plugin_dir_path(__FILE__);
        $Mc = home_url();
        $Mc = trim($Mc, "\57");
        if (preg_match("\x23\x5e\150\x74\x74\160\50\x73\51\x3f\72\57\x2f\x23", $Mc)) {
            goto Xn;
        }
        $Mc = "\150\164\164\160\72\x2f\x2f" . $Mc;
        Xn:
        $vD = parse_url($Mc);
        $HP = preg_replace("\x2f\136\167\x77\167\134\x2e\x2f", '', $vD["\150\x6f\163\164"]);
        $Lf = wp_upload_dir();
        $R5 = $HP . "\55" . $Lf["\142\141\x73\x65\x64\x69\x72"];
        $yp = hash_hmac("\x73\150\x61\x32\65\66", $R5, "\64\104\110\x66\152\x67\146\x6a\x61\x73\x6e\144\146\x73\141\152\x66\110\x47\112");
        $AM = wpWrapper::djkasjdksa();
        $a6 = round(strlen($AM) / rand(2, 20));
        $AM = substr_replace($AM, $yp, $a6, 0);
        $qe = base64_decode($AM);
        if (is_writable($nJ . "\x6c\151\143\x65\x6e\163\145")) {
            goto AI;
        }
        $AM = str_rot13($AM);
        $pC = base64_decode("\x62\107\x4e\x6b\141\155\164\150\x63\x32\x70\x6b\141\63\x4e\150\x59\x32\167\x3d");
        update_option($pC, $AM);
        goto oK;
        AI:
        file_put_contents($nJ . "\x6c\151\x63\145\156\163\145", $qe);
        oK:
        update_option("\154\143\167\x72\164\x6c\146\x73\141\155\154", true);
        $xr = add_query_arg(array("\164\x61\142" => "\147\145\156\145\x72\x61\154"), $_SERVER["\122\105\121\x55\x45\x53\124\137\125\x52\111"]);
        Mo_License_Service::refresh_license_expiry();
        wpWrapper::mo_sps__show_success_notice("\131\x6f\165\x72\40\154\x69\x63\x65\x6e\163\x65\40\151\x73\x20\x76\145\x72\151\x66\x69\x65\x64\x2e\40\x59\x6f\x75\40\x63\x61\156\x20\156\x6f\167\40\163\145\x74\165\x70\x20\164\x68\x65\x20\160\x6c\165\x67\151\156\56");
        Wn:
        ks:
    }
    private function mo_sps_go_back_from_license_page()
    {
        check_admin_referer("\155\x6f\137\x73\160\x73\137\147\x6f\x5f\142\x61\143\153\x5f\146\x72\157\155\137\x6c\x69\x63\145\156\163\145\137\160\141\x67\145\x5f\x6f\x70\x74\151\157\x6e");
        MOsps::mo_sps_deactivate();
        add_option("\x6d\x6f\x5f\163\x70\163\x5f\x72\145\147\151\x73\x74\162\141\164\151\157\x6e\x5f\163\x74\141\x74\165\163", "\162\145\x6d\x6f\x76\x65\144\137\x61\143\143\157\165\156\x74");
    }
    private function mo_sps_remove_account()
    {
        check_admin_referer("\x6d\157\x5f\163\x70\x73\137\162\145\x6d\157\x76\x65\137\141\x63\143\157\165\156\164\137\157\160\x74\x69\x6f\156");
        MOsps::mo_sps_deactivate();
        Mo_License_Service::reset_license_values();
        add_option("\x6d\x6f\x5f\163\x70\x73\137\x72\145\147\151\x73\x74\x72\x61\164\x69\157\x6e\x5f\x73\164\x61\x74\x75\163", "\x72\145\155\157\x76\145\144\137\141\x63\x63\157\x75\x6e\x74");
    }
}
