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); $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 = $_POST['verify_certificate']; $addUniqueId = $_POST['managesites_add_uniqueId']; $http_user = $_POST['managesites_add_http_user']; $http_pass = $_POST['managesites_add_http_pass']; $information = MainWPUtility::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); 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 = MainWPDB::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 = $_POST['managesites_add_http_user']; $http_pass = $_POST['managesites_add_http_pass']; global $current_user; $id = MainWPDB::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); $message = sprintf(__('Site successfully added - Visit the Site\'s <a href="admin.php?page=managesites&dashboard=%d" style="text-decoration: none;" title="Dashboard">Dashboard</a> now.', 'mainwp'), $id); $website = MainWPDB::Instance()->getWebsiteById($id); MainWPSync::syncInformationArray($website, $information); } else { $error = 'Undefined error'; } } } catch (MainWPException $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 .= __('test your connection <a href="' . admin_url('admin.php?page=managesites&do=test&site=' . urlencode($e->getMessageExtra())) . '">here</a> or ', 'mainwp'); } $error .= __('post as much information as possible on the error in the <a href="https://mainwp.com/forum/">support forum</a>.', 'mainwp'); } else { $error = $e->getMessage(); } } } } return array($message, $error); }
public static function performAllChecks() { $websites = MainWPDB::Instance()->getOfflineChecks(); foreach ($websites as $website) { if ($website->sync_errors != '') { try { //Add if (function_exists('openssl_pkey_new')) { $conf = array('private_key_bits' => 384); $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 = MainWPUtility::fetchUrlNotAuthed($website->url, $website->adminname, 'register', array('pubkey' => $pubkey, 'server' => get_admin_url()), false, $website->verify_certificate, $website->http_user, $website->http_pass); if (!isset($information['error']) || $information['error'] == '') { if (isset($information['register']) && $information['register'] == 'OK') { //Update website MainWPDB::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'; MainWPSync::syncInformationArray($website, $information); } } } catch (Exception $e) { } } self::performCheck($website); } }
public static function checkSite() { $website = MainWPDB::Instance()->getWebsitesByUrl($_POST['url']); $ret = array(); if (MainWPUtility::can_edit_website($website)) { //Already added to the database - so exists. $ret['response'] = 'ERROR You already added your site to MainWP'; } else { try { $http_user = isset($_POST['http_user']) ? $_POST['http_user'] : ''; $http_pass = isset($_POST['http_pass']) ? $_POST['http_pass'] : ''; $information = MainWPUtility::fetchUrlNotAuthed($_POST['url'], $_POST['admin'], 'stats', null, false, null, $http_user, $http_pass); //Fetch the stats with the given admin name if (isset($information['wpversion'])) { //Version found - able to add $ret['response'] = 'OK'; } else { if (isset($information['error'])) { //Error $ret['response'] = 'ERROR ' . $information['error']; } else { //Should not occur? $ret['response'] = 'ERROR'; } } } catch (MainWPException $e) { //Exception - error $ret['response'] = $e->getMessage(); } } $ret['check_me'] = isset($_POST['check_me']) ? $_POST['check_me'] : null; die(json_encode($ret)); }