public static function addSite($website)
 {
     $error = '';
     $message = '';
     if ($website) {
         $error = __('Your site is already added to MainWP', 'mainwp');
     } else {
         try {
             //Add
             if (function_exists('openssl_pkey_new')) {
                 $conf = array('private_key_bits' => 384);
                 $conf_loc = MainWP_System::get_openssl_conf();
                 if (!empty($conf_loc)) {
                     $conf['config'] = $conf_loc;
                 }
                 $res = openssl_pkey_new($conf);
                 @openssl_pkey_export($res, $privkey, null, $conf);
                 $pubkey = openssl_pkey_get_details($res);
                 $pubkey = $pubkey['key'];
             } else {
                 $privkey = '-1';
                 $pubkey = '-1';
             }
             $url = $_POST['managesites_add_wpurl'];
             $pluginConflicts = get_option('mainwp_pluginConflicts');
             if ($pluginConflicts !== false) {
                 $pluginConflicts = array_keys($pluginConflicts);
             }
             $themeConflicts = get_option('mainwp_themeConflicts');
             if ($themeConflicts !== false) {
                 $themeConflicts = array_keys($themeConflicts);
             }
             // to fix bug
             if (is_array($pluginConflicts)) {
                 $pluginConflicts = array_filter($pluginConflicts);
             }
             if (is_array($themeConflicts)) {
                 $themeConflicts = array_filter($themeConflicts);
             }
             $verifyCertificate = !isset($_POST['verify_certificate']) || empty($_POST['verify_certificate']) ? null : $_POST['verify_certificate'];
             $sslVersion = MainWP_Utility::getCURLSSLVersion(!isset($_POST['ssl_version']) || empty($_POST['ssl_version']) ? null : $_POST['ssl_version']);
             $addUniqueId = isset($_POST['managesites_add_uniqueId']) ? $_POST['managesites_add_uniqueId'] : '';
             $http_user = isset($_POST['managesites_add_http_user']) ? $_POST['managesites_add_http_user'] : '';
             $http_pass = isset($_POST['managesites_add_http_pass']) ? $_POST['managesites_add_http_pass'] : '';
             $information = MainWP_Utility::fetchUrlNotAuthed($url, $_POST['managesites_add_wpadmin'], 'register', array('pubkey' => $pubkey, 'server' => get_admin_url(), 'uniqueId' => $addUniqueId, 'pluginConflicts' => json_encode($pluginConflicts), 'themeConflicts' => json_encode($themeConflicts)), false, $verifyCertificate, $http_user, $http_pass, $sslVersion);
             if (isset($information['error']) && $information['error'] != '') {
                 $error = $information['error'];
             } else {
                 if (isset($information['register']) && $information['register'] == 'OK') {
                     //Add website to database
                     $groupids = array();
                     $groupnames = array();
                     if (isset($_POST['groupids'])) {
                         foreach ($_POST['groupids'] as $group) {
                             $groupids[] = $group;
                         }
                     }
                     if (isset($_POST['groupnames']) && $_POST['groupnames'] != '' || isset($_POST['groupnames_import']) && $_POST['groupnames_import'] != '') {
                         if ($_POST['groupnames']) {
                             $tmpArr = explode(',', $_POST['groupnames']);
                         } else {
                             if ($_POST['groupnames_import']) {
                                 $tmpArr = explode(';', $_POST['groupnames_import']);
                             }
                         }
                         foreach ($tmpArr as $tmp) {
                             $group = MainWP_DB::Instance()->getGroupByNameForUser(trim($tmp));
                             if ($group) {
                                 if (!in_array($group->id, $groupids)) {
                                     $groupids[] = $group->id;
                                 }
                             } else {
                                 $groupnames[] = trim($tmp);
                             }
                         }
                     }
                     if (!isset($information['uniqueId']) || empty($information['uniqueId'])) {
                         $addUniqueId = '';
                     }
                     $http_user = isset($_POST['managesites_add_http_user']) ? $_POST['managesites_add_http_user'] : '';
                     $http_pass = isset($_POST['managesites_add_http_pass']) ? $_POST['managesites_add_http_pass'] : '';
                     global $current_user;
                     $id = MainWP_DB::Instance()->addWebsite($current_user->ID, $_POST['managesites_add_wpname'], $_POST['managesites_add_wpurl'], $_POST['managesites_add_wpadmin'], base64_encode($pubkey), base64_encode($privkey), $information['nossl'], isset($information['nosslkey']) ? $information['nosslkey'] : null, $groupids, $groupnames, $verifyCertificate, $addUniqueId, $http_user, $http_pass, $sslVersion);
                     $message = sprintf(__('Site successfully added - Visit the Site\'s %sDashboard%s now.', 'mainwp'), '<a href="admin.php?page=managesites&dashboard=' . $id . '" style="text-decoration: none;" title="' . __('Dashboard', 'mainwp') . '">', '</a>');
                     $website = MainWP_DB::Instance()->getWebsiteById($id);
                     MainWP_Sync::syncInformationArray($website, $information);
                 } else {
                     $error = __('Undefined error.', 'mainwp');
                 }
             }
         } catch (MainWP_Exception $e) {
             if ($e->getMessage() == 'HTTPERROR') {
                 $error = 'HTTP error' . ($e->getMessageExtra() != null ? ' - ' . $e->getMessageExtra() : '');
             } else {
                 if ($e->getMessage() == 'NOMAINWP') {
                     $error = __('No MainWP Child plugin detected, first install and activate the plugin and add your site to MainWP afterwards. If you continue experiencing this issue please ', 'mainwp');
                     if ($e->getMessageExtra() != null) {
                         $error .= sprintf(__('test your connection %shere%s or ', 'mainwp'), '<a href="' . admin_url('admin.php?page=managesites&do=test&site=' . urlencode($e->getMessageExtra())) . '">', '</a>');
                     }
                     $error .= sprintf(__('post as much information as possible on the error in the %ssupport forum%s.', 'mainwp'), '<a href="https://mainwp.com/forum/">', '</a>');
                 } else {
                     $error = $e->getMessage();
                 }
             }
         }
     }
     return array($message, $error);
 }
 public static function performAllChecks()
 {
     $websites = MainWP_DB::Instance()->getOfflineChecks();
     foreach ($websites as $website) {
         if ($website->sync_errors != '') {
             try {
                 //Add
                 if (function_exists('openssl_pkey_new')) {
                     $conf = array('private_key_bits' => 384);
                     $conf_loc = MainWP_System::get_openssl_conf();
                     if (!empty($conf_loc)) {
                         $conf['config'] = $conf_loc;
                     }
                     $res = openssl_pkey_new($conf);
                     @openssl_pkey_export($res, $privkey, null, $conf);
                     $pubkey = openssl_pkey_get_details($res);
                     $pubkey = $pubkey['key'];
                 } else {
                     $privkey = '-1';
                     $pubkey = '-1';
                 }
                 $information = MainWP_Utility::fetchUrlNotAuthed($website->url, $website->adminname, 'register', array('pubkey' => $pubkey, 'server' => get_admin_url(), 'uniqueId' => $website->uniqueId), false, $website->verify_certificate, $website->http_user, $website->http_pass, $website->ssl_version);
                 if (!isset($information['error']) || $information['error'] == '') {
                     if (isset($information['register']) && $information['register'] == 'OK') {
                         //Update website
                         MainWP_DB::Instance()->updateWebsiteValues($website->id, array('pubkey' => base64_encode($pubkey), 'privkey' => base64_encode($privkey), 'nossl' => $information['nossl'], 'nosslkey' => isset($information['nosslkey']) ? $information['nosslkey'] : '', 'uniqueId' => isset($information['uniqueId']) ? $information['uniqueId'] : ''));
                         $message = 'Site successfully reconnected';
                         MainWP_Sync::syncInformationArray($website, $information);
                     }
                 }
             } catch (Exception $e) {
             }
         }
         self::performCheck($website);
     }
 }
 protected static function getSSLWarning()
 {
     $conf = array('private_key_bits' => 384);
     $conf_loc = MainWP_System::get_openssl_conf();
     if (!empty($conf_loc)) {
         $conf['config'] = $conf_loc;
     }
     $res = @openssl_pkey_new($conf);
     @openssl_pkey_export($res, $privkey);
     $str = openssl_error_string();
     return stristr($str, 'NCONF_get_string:no value') ? '' : $str;
 }