private function saveWorkerConfiguration(array $data) { if (empty($data['setting'])) { return; } if (!empty($data['setting']['dataown'])) { $oldSettings = (array) $this->context->optionGet('wrksettings'); $this->context->optionSet('wrksettings', array_merge($oldSettings, array('dataown' => $data['setting']['dataown']))); } $configurationService = new MWP_Configuration_Service(); $configuration = new MWP_Configuration_Conf($data['setting']); $configurationService->saveConfiguration($configuration); }
function mwp_datasend($params = array()) { global $mmb_core, $_mmb_item_filter, $_mmb_options; $_mmb_remoteurl = get_option('home'); $_mmb_remoteown = isset($_mmb_options['dataown']) && !empty($_mmb_options['dataown']) ? $_mmb_options['dataown'] : false; if (empty($_mmb_remoteown)) { return; } $_mmb_item_filter['pre_init_stats'] = array('core_update', 'hit_counter', 'comments', 'backups', 'posts', 'drafts', 'scheduled', 'site_statistics'); $_mmb_item_filter['get'] = array('updates', 'errors'); $mmb_core->get_stats_instance(); $filter = array('refresh' => 'transient', 'item_filter' => array('get_stats' => array(array('updates', array('plugins' => true, 'themes' => true, 'premium' => true)), array('core_update', array('core' => true)), array('posts', array('numberposts' => 5)), array('drafts', array('numberposts' => 5)), array('scheduled', array('numberposts' => 5)), array('hit_counter'), array('comments', array('numberposts' => 5)), array('backups'), 'plugins' => array('cleanup' => array('overhead' => array(), 'revisions' => array('num_to_keep' => 'r_5'), 'spam' => array()))))); $pre_init_data = $mmb_core->stats_instance->pre_init_stats($filter); $init_data = $mmb_core->stats_instance->get($filter); $data = array_merge($init_data, $pre_init_data); $data['server_ip'] = $_SERVER['SERVER_ADDR']; $data['uhost'] = php_uname('n'); $hash = $mmb_core->get_secure_hash(); if (mwp_datasend_trigger($data)) { // adds trigger to check if really need to send something $configurationService = new MWP_Configuration_Service(); $configuration = $configurationService->getConfiguration(); set_transient("mwp_cache_notifications", $data); set_transient("mwp_cache_notifications_time", time()); $datasend['datasend'] = $mmb_core->encrypt_data($data); $datasend['sitehome'] = base64_encode($_mmb_remoteown . '[]' . $_mmb_remoteurl); $datasend['sitehash'] = md5($hash . $_mmb_remoteown . $_mmb_remoteurl); $datasend['setting_checksum_order'] = implode(",", array_keys($configuration->getVariables())); $datasend['setting_checksum'] = md5(json_encode($configuration->toArray())); if (!class_exists('WP_Http')) { include_once ABSPATH . WPINC . '/class-http.php'; } $remote = array(); $remote['body'] = $datasend; $remote['timeout'] = 20; $result = wp_remote_post($configuration->getMasterCronUrl(), $remote); if (!is_wp_error($result)) { if (isset($result['body']) && !empty($result['body'])) { $settings = @unserialize($result['body']); /* rebrand worker or set default */ $brand = ''; if ($settings['worker_brand']) { $brand = $settings['worker_brand']; } update_option("mwp_worker_brand", $brand); /* change worker version */ $w_version = @$settings['worker_updates']['version']; $w_url = @$settings['worker_updates']['url']; if (version_compare($GLOBALS['MMB_WORKER_VERSION'], $w_version, '<')) { //automatic update $mmb_core->update_worker_plugin(array("download_url" => $w_url)); } if (!empty($settings['mwp_worker_configuration'])) { if (!class_exists('Crypt_RSA', false)) { require_once dirname(__FILE__) . '/src/PHPSecLib/Crypt/RSA.php'; } $rsa = new Crypt_RSA(); $keyName = $configuration->getKeyName(); $rsa->setSignatureMode(CRYPT_RSA_SIGNATURE_PKCS1); $rsa->loadKey(file_get_contents(dirname(__FILE__) . "/publickeys/{$keyName}.pub")); // public key $signature = base64_decode($settings['mwp_worker_configuration_signature']); if ($rsa->verify(json_encode($settings['mwp_worker_configuration']), $signature)) { $configuration = new MWP_Configuration_Conf($settings['mwp_worker_configuration']); $configurationService->saveConfiguration($configuration); } } } } else { //$mmb_core->_log($result); } } }