public static function action_update($pAction)
 {
     $postId = $_POST['postId'];
     $websiteIdEnc = $_POST['websiteId'];
     $post_data = $_POST['post_data'];
     if (!MainWPUtility::ctype_digit($postId)) {
         die('FAIL');
     }
     $websiteId = $websiteIdEnc;
     if (!MainWPUtility::ctype_digit($websiteId)) {
         die('FAIL');
     }
     $website = MainWPDB::Instance()->getWebsiteById($websiteId);
     if (!MainWPUtility::can_edit_website($website)) {
         die('FAIL');
     }
     try {
         $information = MainWPUtility::fetchUrlAuthed($website, 'post_action', array('action' => $pAction, 'id' => $postId, 'post_data' => $post_data));
     } catch (MainWPException $e) {
         die('FAIL');
     }
     if (!isset($information['status']) || $information['status'] != 'SUCCESS') {
         die('FAIL');
     }
 }
 public static function upgradePluginTheme($id, $type, $list)
 {
     if (isset($id) && MainWPUtility::ctype_digit($id)) {
         $website = MainWPDB::Instance()->getWebsiteById($id);
         if (MainWPUtility::can_edit_website($website)) {
             $information = MainWPUtility::fetchUrlAuthed($website, 'upgradeplugintheme', array('type' => $type, 'list' => urldecode($list)));
             if (isset($information['upgrades'])) {
                 $tmp = array();
                 //todo: 20130718: the syncing in else branch may be removed in the future, it now works with the sync below (just here for older childs..)
                 if (isset($information['sync'])) {
                     foreach ($information['upgrades'] as $k => $v) {
                         $tmp[urlencode($k)] = $v;
                     }
                 } else {
                     $decodedPluginUpgrades = json_decode($website->plugin_upgrades, true);
                     $decodedThemeUpgrades = json_decode($website->theme_upgrades, true);
                     $decodedPremiumUpgrades = json_decode(MainWPDB::Instance()->getWebsiteOption($website, 'premium_upgrades'), true);
                     if (is_array($decodedPremiumUpgrades)) {
                         foreach ($decodedPremiumUpgrades as $crrSlug => $premiumUpgrade) {
                             if ($premiumUpgrade['type'] == 'plugin') {
                                 if (!is_array($decodedPluginUpgrades)) {
                                     $decodedPluginUpgrades = array();
                                 }
                                 $decodedPluginUpgrades[$crrSlug] = $premiumUpgrade;
                             } else {
                                 if ($premiumUpgrade['type'] == 'theme') {
                                     if (!is_array($decodedThemeUpgrades)) {
                                         $decodedThemeUpgrades = array();
                                     }
                                     $decodedThemeUpgrades[$crrSlug] = $premiumUpgrade;
                                 }
                             }
                         }
                     }
                     foreach ($information['upgrades'] as $k => $v) {
                         $tmp[urlencode($k)] = $v;
                         if ($v == 1) {
                             if ($type == 'plugin') {
                                 if (isset($decodedPluginUpgrades[$k])) {
                                     unset($decodedPluginUpgrades[$k]);
                                 }
                             }
                             if ($type == 'theme') {
                                 if (isset($decodedThemeUpgrades[$k])) {
                                     unset($decodedThemeUpgrades[$k]);
                                 }
                             }
                         }
                     }
                     if ($type == 'plugin') {
                         MainWPDB::Instance()->updateWebsiteValues($website->id, array('plugin_upgrades' => json_encode($decodedPluginUpgrades)));
                     }
                     if ($type == 'theme') {
                         MainWPDB::Instance()->updateWebsiteValues($website->id, array('theme_upgrades' => json_encode($decodedThemeUpgrades)));
                     }
                 }
                 return $tmp;
             } else {
                 if (isset($information['error'])) {
                     throw new MainWPException('WPERROR', $information['error']);
                 } else {
                     throw new MainWPException('ERROR', 'Invalid response from site');
                 }
             }
         }
     }
     throw new MainWPException('ERROR', __('Invalid request', 'mainwp'));
 }
 public static function updateWebsite()
 {
     if (!isset($_POST['websiteid']) || !isset($_POST['offline_check'])) {
         return '0';
     }
     $website = MainWPDB::Instance()->getWebsiteById($_POST['websiteid']);
     if ($website == null) {
         return 0;
     }
     if (!MainWPUtility::can_edit_website($website)) {
         return '0';
     }
     MainWPDB::Instance()->updateWebsiteOfflineCheckSetting($website->id, $_POST['offline_check']);
     return '1';
 }
 public static function action($pAction)
 {
     $plugin = $_POST['plugin'];
     $websiteIdEnc = $_POST['websiteId'];
     if (empty($plugin)) {
         die(json_encode(array('error' => 'Invalid Request.')));
     }
     $websiteId = $websiteIdEnc;
     if (!MainWPUtility::ctype_digit($websiteId)) {
         die(json_encode(array('error' => 'Invalid Request.')));
     }
     $website = MainWPDB::Instance()->getWebsiteById($websiteId);
     if (!MainWPUtility::can_edit_website($website)) {
         die(json_encode(array('error' => 'You can not edit this website.')));
     }
     try {
         $information = MainWPUtility::fetchUrlAuthed($website, 'plugin_action', array('action' => $pAction, 'plugin' => $plugin));
     } catch (MainWPException $e) {
         die(json_encode(array('error' => $e->getMessage())));
     }
     if (!isset($information['status']) || $information['status'] != 'SUCCESS') {
         die(json_encode(array('error' => 'Unexpected error.')));
     }
 }
Beispiel #5
0
 public static function getPostMeta($postId, $keys, $value, $websiteId)
 {
     if (!MainWPUtility::ctype_digit($postId)) {
         return;
     }
     if (!MainWPUtility::ctype_digit($websiteId)) {
         return;
     }
     $website = MainWPDB::Instance()->getWebsiteById($websiteId);
     if (!MainWPUtility::can_edit_website($website)) {
         return;
     }
     try {
         $results = MainWPUtility::fetchUrlAuthed($website, 'get_post_meta', array('id' => base64_encode($postId), 'keys' => base64_encode($keys), 'value' => base64_encode($value)));
     } catch (MainWPException $e) {
         return;
     }
     return $results;
 }
 public static function _reconnectSite($website)
 {
     if (MainWPUtility::can_edit_website($website)) {
         try {
             //Try to refresh stats first;
             if (MainWPSync::syncSite($website, true)) {
                 return true;
             }
             //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()), true, $website->verify_certificate, $website->http_user, $website->http_pass);
             if (isset($information['error']) && $information['error'] != '') {
                 throw new Exception($information['error']);
             } else {
                 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'] : ''));
                     MainWPSync::syncInformationArray($website, $information);
                     return true;
                 } else {
                     throw new Exception(__('Undefined error', 'mainwp'));
                 }
             }
         } catch (MainWPException $e) {
             if ($e->getMessage() == 'HTTPERROR') {
                 throw new Exception('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');
                     throw new Exception($error);
                 }
             }
         }
     } else {
         throw new Exception(__('Not allowed this operation.', 'mainwp'));
     }
     return false;
 }
Beispiel #7
0
 public function updateWebsite($websiteid, $userid, $name, $siteadmin, $groupids, $groupnames, $offlineChecks, $pluginDir, $maximumFileDescriptorsOverride, $maximumFileDescriptorsAuto, $maximumFileDescriptors, $verifyCertificate = 1, $archiveFormat, $uniqueId = "", $http_user = null, $http_pass = null)
 {
     if (MainWPUtility::ctype_digit($websiteid) && MainWPUtility::ctype_digit($userid)) {
         $website = MainWPDB::Instance()->getWebsiteById($websiteid);
         if (MainWPUtility::can_edit_website($website)) {
             //update admin
             $this->wpdb->query('UPDATE ' . $this->tableName('wp') . ' SET name="' . $this->escape($name) . '", adminname="' . $this->escape($siteadmin) . '",offline_checks="' . $this->escape($offlineChecks) . '",pluginDir="' . $this->escape($pluginDir) . '",maximumFileDescriptorsOverride = ' . ($maximumFileDescriptorsOverride ? 1 : 0) . ',maximumFileDescriptorsAuto= ' . ($maximumFileDescriptorsAuto ? 1 : 0) . ',maximumFileDescriptors = ' . $maximumFileDescriptors . ', verify_certificate="' . intval($verifyCertificate) . '", uniqueId="' . $this->escape($uniqueId) . '", http_user="******", http_pass="******"  WHERE id=' . $websiteid);
             $this->wpdb->query('UPDATE ' . $this->tableName('wp_settings_backup') . ' SET archiveFormat = "' . $this->escape($archiveFormat) . '" WHERE wpid=' . $websiteid);
             //remove groups
             $this->wpdb->query('DELETE FROM ' . $this->tableName('wp_group') . ' WHERE wpid=' . $websiteid);
             //Remove GA stats
             $showErrors = $this->wpdb->hide_errors();
             do_action('mainwp_ga_delete_site', $websiteid);
             if ($showErrors) {
                 $this->wpdb->show_errors();
             }
             //add groups with groupnames
             foreach ($groupnames as $groupname) {
                 if ($this->wpdb->insert($this->tableName('group'), array('userid' => $userid, 'name' => $this->escape($groupname)))) {
                     $groupids[] = $this->wpdb->insert_id;
                 }
             }
             //add groupids
             foreach ($groupids as $groupid) {
                 $this->wpdb->insert($this->tableName('wp_group'), array('wpid' => $websiteid, 'groupid' => $groupid));
             }
             return true;
         }
     }
     return false;
 }
    public static function fetchChildServerInformation($siteId)
    {
        try {
            $website = MainWPDB::Instance()->getWebsiteById($siteId);
            if (!MainWPUtility::can_edit_website($website)) {
                return 'This is not your website.';
            }
            $serverInformation = MainWPUtility::fetchUrlAuthed($website, 'serverInformation');
            ?>

        <h2><i class="fa fa-server"></i> <strong><?php 
            echo stripslashes($website->name);
            ?>
</strong>&nbsp;<?php 
            _e('Server Information');
            ?>
</h2>
        <?php 
            echo $serverInformation['information'];
            ?>
        <h2><i class="fa fa-server"></i> <strong><?php 
            echo stripslashes($website->name);
            ?>
</strong>&nbsp;<?php 
            _e('Cron Schedules');
            ?>
</h2>
        <?php 
            echo $serverInformation['cron'];
            ?>
        <?php 
            if (isset($serverInformation['wpconfig'])) {
                ?>
        <h2><i class="fa fa-server"></i> <strong><?php 
                echo stripslashes($website->name);
                ?>
</strong>&nbsp;<?php 
                _e('WP-Config File');
                ?>
</h2>
        <?php 
                echo $serverInformation['wpconfig'];
                ?>
        <h2><i class="fa fa-server"></i> <strong><?php 
                echo stripslashes($website->name);
                ?>
</strong>&nbsp;<?php 
                _e('Error Log');
                ?>
</h2>
        <?php 
                echo $serverInformation['error'];
                ?>
        <?php 
            }
            ?>
            <?php 
        } catch (MainWPException $e) {
            die(MainWPErrorHelper::getErrorMessage($e));
        } catch (Exception $e) {
            die('Something went wrong processing your request.');
        }
        die;
    }
 public static function hookGetSites($pluginFile, $key, $websiteid, $for_manager = false)
 {
     if (!self::hookVerify($pluginFile, $key)) {
         return false;
     }
     if ($for_manager && (!defined("MWP_TEAMCONTROL_PLUGIN_SLUG") || !mainwp_current_user_can("extension", dirname(MWP_TEAMCONTROL_PLUGIN_SLUG)))) {
         return false;
     }
     if (isset($websiteid) && $websiteid != null) {
         $website = MainWPDB::Instance()->getWebsiteById($websiteid);
         if (!MainWPUtility::can_edit_website($website)) {
             return false;
         }
         if (!mainwp_current_user_can("site", $websiteid)) {
             return false;
         }
         return array(array('id' => $websiteid, 'url' => MainWPUtility::getNiceURL($website->url, true), 'name' => $website->name, 'totalsize' => $website->totalsize));
     }
     $websites = MainWPDB::Instance()->query(MainWPDB::Instance()->getSQLWebsitesForCurrentUser(false, null, 'wp.url', false, false, null, $for_manager));
     $output = array();
     while ($websites && ($website = @MainWPDB::fetch_object($websites))) {
         $output[] = array('id' => $website->id, 'url' => MainWPUtility::getNiceURL($website->url, true), 'name' => $website->name, 'totalsize' => $website->totalsize);
     }
     @MainWPDB::free_result($websites);
     return $output;
 }
Beispiel #10
0
 function upgradePluginTheme()
 {
     try {
         $websiteId = $type = null;
         $slugs = array();
         if (isset($_POST['websiteId'])) {
             $websiteId = $_POST['websiteId'];
         }
         if (isset($_POST['slugs'])) {
             $slugs = $_POST['slugs'];
         }
         if (isset($_POST['type'])) {
             $type = $_POST['type'];
         }
         $error = "";
         if ($type == "plugin" && !mainwp_current_user_can("dashboard", "update_plugins")) {
             $error = mainwp_do_not_have_permissions("Update Plugins", false);
         } else {
             if ($type == "theme" && !mainwp_current_user_can("dashboard", "update_themes")) {
                 $error = mainwp_do_not_have_permissions("Update Themes", false);
             }
         }
         if (!empty($error)) {
             die(json_encode(array('error' => $error)));
         }
         if (MainWPUtility::ctype_digit($websiteId)) {
             $website = MainWPDB::Instance()->getWebsiteById($websiteId);
             if (MainWPUtility::can_edit_website($website)) {
                 $information = MainWPUtility::fetchUrlAuthed($website, 'upgradeplugintheme', array('type' => $type, 'list' => urldecode(implode(',', $slugs))));
                 die(json_encode($information));
             }
         }
     } catch (MainWPException $e) {
         die(json_encode(array('error' => $e->getMessage())));
     }
     die;
 }
 public static function unfixSecurityIssue()
 {
     if (!isset($_REQUEST['id']) || !MainWPUtility::ctype_digit($_REQUEST['id'])) {
         return "";
     }
     $website = MainWPDB::Instance()->getWebsiteById($_REQUEST['id']);
     if (!MainWPUtility::can_edit_website($website)) {
         return '';
     }
     $information = MainWPUtility::fetchUrlAuthed($website, 'securityUnFix', array('feature' => $_REQUEST['feature']));
     if (isset($information['sync']) && !empty($information['sync'])) {
         MainWPSync::syncInformationArray($website, $information['sync']);
         unset($information['sync']);
     }
     return $information;
 }
Beispiel #12
0
 public static function ignoreUpdates()
 {
     $websiteIdEnc = $_POST['websiteId'];
     $websiteId = $websiteIdEnc;
     if (!MainWPUtility::ctype_digit($websiteId)) {
         die('FAIL');
     }
     $website = MainWPDB::Instance()->getWebsiteById($websiteId);
     if (!MainWPUtility::can_edit_website($website)) {
         die('FAIL');
     }
     $themes = $_POST['themes'];
     $names = $_POST['names'];
     $decodedIgnoredThemes = json_decode($website->ignored_themes, true);
     if (!is_array($decodedIgnoredThemes)) {
         $decodedIgnoredThemes = array();
     }
     if (is_array($themes)) {
         for ($i = 0; $i < count($themes); $i++) {
             $slug = $themes[$i];
             $name = $names[$i];
             if (!isset($decodedIgnoredThemes[$slug])) {
                 $decodedIgnoredThemes[$slug] = urldecode($name);
             }
         }
         MainWPDB::Instance()->updateWebsiteValues($website->id, array('ignored_themes' => json_encode($decodedIgnoredThemes)));
     }
     die(json_encode(array('result' => true)));
 }
Beispiel #13
0
 public static function unIgnorePluginThemeConflict($type, $name, $siteid)
 {
     if ($siteid != '') {
         //For the sites..
         if ($siteid == '_ALL_') {
             $websites = MainWPDB::Instance()->query(MainWPDB::Instance()->getSQLWebsitesForCurrentUser());
         } else {
             $websites = MainWPDB::Instance()->query(MainWPDB::Instance()->getSQLWebsiteById($siteid));
         }
         while ($websites && ($website = @MainWPDB::fetch_object($websites))) {
             if (MainWPUtility::can_edit_website($website)) {
                 $name = urldecode($name);
                 if ($type == 'plugin') {
                     $decodedIgnoredPlugins = json_decode($website->ignored_pluginConflicts, true);
                     if (!is_array($decodedIgnoredPlugins)) {
                         $decodedIgnoredPlugins = array();
                     }
                     if ($name == '') {
                         MainWPDB::Instance()->updateWebsiteValues($website->id, array('ignored_pluginConflicts' => json_encode(array())));
                     } else {
                         if (in_array($name, $decodedIgnoredPlugins)) {
                             $idx = array_search($name, $decodedIgnoredPlugins);
                             array_splice($decodedIgnoredPlugins, $idx, 1);
                             MainWPDB::Instance()->updateWebsiteValues($website->id, array('ignored_pluginConflicts' => json_encode($decodedIgnoredPlugins)));
                         }
                     }
                 } else {
                     if ($type == 'theme') {
                         $decodedIgnoredThemes = json_decode($website->ignored_themeConflicts, true);
                         if (!is_array($decodedIgnoredThemes)) {
                             $decodedIgnoredThemes = array();
                         }
                         if ($name == '') {
                             MainWPDB::Instance()->updateWebsiteValues($website->id, array('ignored_themeConflicts' => json_encode(array())));
                         } else {
                             if (in_array($name, $decodedIgnoredThemes)) {
                                 $idx = array_search($name, $decodedIgnoredThemes);
                                 array_splice($decodedIgnoredThemes, $idx, 1);
                                 MainWPDB::Instance()->updateWebsiteValues($website->id, array('ignored_themeConflicts' => json_encode($decodedIgnoredThemes)));
                             }
                         }
                     }
                 }
             }
         }
         @MainWPDB::free_result($websites);
     } else {
         //unignore globally
         $userExtension = MainWPDB::Instance()->getUserExtension();
         $name = urldecode($name);
         if ($type == 'plugin') {
             $globalIgnoredPluginConflicts = json_decode($userExtension->ignored_pluginConflicts, true);
             if (!is_array($globalIgnoredPluginConflicts)) {
                 $globalIgnoredPluginConflicts = array();
             }
             if ($name == '') {
                 //Unignore all
                 $globalIgnoredPluginConflicts = array();
                 $userExtension->ignored_pluginConflicts = json_encode($globalIgnoredPluginConflicts);
                 MainWPDB::Instance()->updateUserExtension($userExtension);
             } else {
                 if (in_array($name, $globalIgnoredPluginConflicts)) {
                     $idx = array_search($name, $globalIgnoredPluginConflicts);
                     array_splice($globalIgnoredPluginConflicts, $idx, 1);
                     $userExtension->ignored_pluginConflicts = json_encode($globalIgnoredPluginConflicts);
                     MainWPDB::Instance()->updateUserExtension($userExtension);
                 }
             }
         } else {
             if ($type == 'theme') {
                 $globalIgnoredThemeConflicts = json_decode($userExtension->ignored_themeConflicts, true);
                 if (!is_array($globalIgnoredThemeConflicts)) {
                     $globalIgnoredThemeConflicts = array();
                 }
                 if ($name == '') {
                     $globalIgnoredThemeConflicts = array();
                     $userExtension->ignored_themeConflicts = json_encode($globalIgnoredThemeConflicts);
                     MainWPDB::Instance()->updateUserExtension($userExtension);
                 } else {
                     if (in_array($name, $globalIgnoredThemeConflicts)) {
                         $idx = array_search($name, $globalIgnoredThemeConflicts);
                         array_splice($globalIgnoredThemeConflicts, $idx, 1);
                         $userExtension->ignored_themeConflicts = json_encode($globalIgnoredThemeConflicts);
                         MainWPDB::Instance()->updateUserExtension($userExtension);
                     }
                 }
             }
         }
     }
     return 'success';
 }
 public static function updateGroup()
 {
     if (isset($_POST['groupId']) && MainWPUtility::ctype_digit($_POST['groupId'])) {
         $group = MainWPDB::Instance()->getGroupById($_POST['groupId']);
         if (MainWPUtility::can_edit_group($group)) {
             MainWPDB::Instance()->clearGroup($group->id);
             if (isset($_POST['websiteIds'])) {
                 foreach ($_POST['websiteIds'] as $websiteId) {
                     $website = MainWPDB::Instance()->getWebsiteById($websiteId);
                     if (MainWPUtility::can_edit_website($website)) {
                         MainWPDB::Instance()->updateGroupSite($group->id, $website->id);
                     }
                 }
             }
             die(json_encode(array('result' => true)));
         }
     }
     die(json_encode(array('result' => false)));
 }
 public static function updateChildsiteValue()
 {
     if (isset($_POST['site_id']) && MainWPUtility::ctype_digit($_POST['site_id'])) {
         $website = MainWPDB::Instance()->getWebsiteById($_POST['site_id']);
         if (MainWPUtility::can_edit_website($website)) {
             $error = '';
             $uniqueId = isset($_POST['unique_id']) ? $_POST['unique_id'] : "";
             try {
                 $information = MainWPUtility::fetchUrlAuthed($website, 'update_values', array('uniqueId' => $uniqueId));
             } catch (MainWPException $e) {
                 $error = $e->getMessage();
             }
             if ($error != '') {
                 die(json_encode(array('error' => $error)));
             } else {
                 if (isset($information['result']) && $information['result'] == 'ok') {
                     die(json_encode(array('result' => 'SUCCESS')));
                 } else {
                     die(json_encode(array('undefined_error' => true)));
                 }
             }
         }
     }
     die(json_encode(array('error' => 'NO_SIDE_ID')));
 }
 function mainwp_force_destroy_sessions()
 {
     $this->secure_request('mainwp_force_destroy_sessions');
     $website_id = isset($_POST['website_id']) ? (int) $_POST['website_id'] : 0;
     if (!MainWPDB::Instance()->getWebsiteById($website_id)) {
         die(json_encode(array('error' => array('message' => __("This website does not exist", 'mainwp')))));
     }
     $website = MainWPDB::Instance()->getWebsiteById($website_id);
     if (!MainWPUtility::can_edit_website($website)) {
         die(json_encode(array('error' => array('message' => __("You cannot edit this website", 'mainwp')))));
     }
     try {
         $information = MainWPUtility::fetchUrlAuthed($website, 'settings_tools', array('action' => 'force_destroy_sessions'));
         global $mainWP;
         if ($mainWP->getVersion() == '2.0.22' || $mainWP->getVersion() == '2.0.23') {
             if (get_option('mainwp_fixed_security_2022') != 1) {
                 update_option('mainwp_fixed_security_2022', 1);
             }
         }
     } catch (Exception $e) {
         $information = array('error' => __("fetchUrlAuthed exception", 'mainwp'));
     }
     die(json_encode($information));
 }
 public static function getSiteDirectories()
 {
     $websites = array();
     if (isset($_REQUEST['site']) && $_REQUEST['site'] != '') {
         $siteId = $_REQUEST['site'];
         $website = MainWPDB::Instance()->getWebsiteById($siteId);
         if (MainWPUtility::can_edit_website($website)) {
             $websites[] = $website;
         }
     } else {
         if (isset($_REQUEST['sites']) && $_REQUEST['sites'] != '') {
             $siteIds = explode(',', urldecode($_REQUEST['sites']));
             $siteIdsRequested = array();
             foreach ($siteIds as $siteId) {
                 $siteId = $siteId;
                 if (!MainWPUtility::ctype_digit($siteId)) {
                     continue;
                 }
                 $siteIdsRequested[] = $siteId;
             }
             $websites = MainWPDB::Instance()->getWebsitesByIds($siteIdsRequested);
         } else {
             if (isset($_REQUEST['groups']) && $_REQUEST['groups'] != '') {
                 $groupIds = explode(',', urldecode($_REQUEST['groups']));
                 $groupIdsRequested = array();
                 foreach ($groupIds as $groupId) {
                     $groupId = $groupId;
                     if (!MainWPUtility::ctype_digit($groupId)) {
                         continue;
                     }
                     $groupIdsRequested[] = $groupId;
                 }
                 $websites = MainWPDB::Instance()->getWebsitesByGroupIds($groupIdsRequested);
             }
         }
     }
     if (count($websites) == 0) {
         die('<i><strong>Select a site or group first</strong></i>');
     }
     //Nothing selected!
     $allFiles = array();
     $excludedBackupFiles = array();
     $excludedCacheFiles = array();
     $excludedNonWPFiles = array();
     foreach ($websites as $website) {
         $files = null;
         $result = json_decode($website->directories, TRUE);
         $dir = urldecode($_POST['dir']);
         if ($dir == '') {
             if (is_array($result)) {
                 $files = array_keys($result);
                 self::addExcludedBackups($result, $excludedBackupFiles);
                 self::addExcludedCache($result, $excludedCacheFiles);
                 self::addExcludedNonWP($files, $excludedNonWPFiles);
             }
         } else {
             $dirExploded = explode('/', $dir);
             $tmpResult = $result;
             foreach ($dirExploded as $innerDir) {
                 if ($innerDir == '') {
                     continue;
                 }
                 if (isset($tmpResult[$innerDir])) {
                     $tmpResult = $tmpResult[$innerDir];
                 } else {
                     $tmpResult = null;
                     break;
                 }
             }
             if ($tmpResult != null && is_array($tmpResult)) {
                 $files = array_keys($tmpResult);
             } else {
                 $files = null;
             }
         }
         if ($files != null && count($files) > 0) {
             $allFiles = array_unique(array_merge($allFiles, $files));
         }
     }
     if ($allFiles != null && count($allFiles) > 0) {
         natcasesort($allFiles);
         echo "<ul class=\"jqueryFileTree\" style=\"display: none;\">";
         // All dirs
         foreach ($allFiles as $file) {
             echo "<li class=\"directory collapsed\"><a href=\"#\" rel=\"" . htmlentities($_POST['dir'] . $file) . "/\">" . htmlentities($file) . "<div title=\"Exclude form backup\" class=\"exclude_folder_control\"><img src=\"" . plugins_url('images/exclude.png', dirname(__FILE__)) . "\" /></div></a></li>";
         }
         echo "</ul>";
         if (count($excludedBackupFiles) > 0) {
             echo '<div id="excludedBackupFiles" style="display:none">';
             foreach ($excludedBackupFiles as $excludedBackupFile) {
                 echo $excludedBackupFile . "\n";
             }
             echo '</div>';
         }
         if (count($excludedCacheFiles) > 0) {
             echo '<div id="excludedCacheFiles" style="display:none">';
             foreach ($excludedCacheFiles as $excludedCacheFile) {
                 echo $excludedCacheFile . "\n";
             }
             echo '</div>';
         }
         if (count($excludedNonWPFiles) > 0) {
             echo '<div id="excludedNonWPFiles" style="display:none">';
             foreach ($excludedNonWPFiles as $excludedNonWPFile) {
                 echo $excludedNonWPFile . "\n";
             }
             echo '</div>';
         }
     }
 }
Beispiel #18
0
 public static function action($pAction, $extra = '')
 {
     $userId = $_POST['userId'];
     $userName = $_POST['userName'];
     $websiteIdEnc = $_POST['websiteId'];
     $pass = $_POST['update_password'];
     if (!MainWPUtility::ctype_digit($userId)) {
         die(json_encode(array('error' => 'Invalid Request.')));
     }
     $websiteId = $websiteIdEnc;
     if (!MainWPUtility::ctype_digit($websiteId)) {
         die(json_encode(array('error' => 'Invalid Request.')));
     }
     $website = MainWPDB::Instance()->getWebsiteById($websiteId);
     if (!MainWPUtility::can_edit_website($website)) {
         die(json_encode(array('error' => 'You can not edit this website.')));
     }
     if ($pAction == 'delete' && $website->adminname == $userName) {
         die(json_encode(array('error' => __('This user is used for our secure link, it can not be deleted.'))));
     }
     if ($pAction == 'changeRole' && $website->adminname == $userName) {
         die(json_encode(array('error' => __('This user is used for our secure link, you can not change the role.'))));
     }
     try {
         $information = MainWPUtility::fetchUrlAuthed($website, 'user_action', array('action' => $pAction, 'id' => $userId, 'extra' => $extra, 'user_pass' => $pass));
     } catch (MainWPException $e) {
         die(json_encode(array('error' => $e->getMessage())));
     }
     if (!isset($information['status']) || $information['status'] != 'SUCCESS') {
         die(json_encode(array('error' => 'Unexpected error.')));
     }
 }
Beispiel #19
0
 public static function renderRestore()
 {
     if (!isset($_GET['websiteid'])) {
         exit;
     }
     $id = $_GET['websiteid'];
     $website = MainWPDB::Instance()->getWebsiteById($id);
     if (!MainWPUtility::can_edit_website($website)) {
         exit;
     }
     $file = "";
     if (isset($_GET['f'])) {
         $file = base64_decode($_GET['f']);
     }
     MainWPSiteOpen::openSiteRestore($website, $file, $_GET['size']);
 }