PluginProbe
WebTotem Security / 2.4.14
WebTotem Security v2.4.14
3.0.2 3.0.1 3.0.0 trunk 1.0 1.1 1.2 1.3 1.3.1 1.3.2 1.3.3 2.0 2.1 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.1 2.2.2 2.2.3 All 110 releases
← All changes | lib/Option.php +30 -171 trunk2.4.14 View file →
@@ -22,9 +22,9 @@
22 22 * Returns saved data by option name.
23 23 */
24 24 public static function getOption($option) {
25 25 $data = WebTotemDB::getData([ 'name' => $option ],'settings');
26 - return (array_key_exists('value', $data)) ? $data['value'] : '';
26 + return $data['value'];
27 27 }
28 28
29 29 /**
30 30 * Save multiple configuration options.
@@ -175,16 +175,14 @@
175 175 * @return string
176 176 * Returns TRUE after setting the options.
177 177 */
178 178 public static function login(array $params) {
179 - $parts = explode('.', $params['token']);
180 - $token_data = json_decode(WebTotem::base64UrlDecode($parts[1]), true);
181 - $token_expired = $token_data['exp'] - 60;
179 + $token_expired = time() + $params['token']['expiresIn'] - 60;
182 180
183 181 self::setOptions([
184 182 'activated' => TRUE,
185 183 'auth_token_expired' => $token_expired,
186 - 'auth_token' => $params['token'],
184 + 'auth_token' => $params['token']['value'],
187 185 'api_key' => $params['api_key'],
188 186 'multisite_options' => WebTotem::isMultiSite()
189 187 ]);
190 188
@@ -190,31 +188,9 @@
190 188
191 189 return TRUE;
192 190 }
193 191
194 - /**
195 - * Save authentication token and token expiration dates in settings.
196 - *
197 - * @param string $token
198 - * Parameters for authorization.
199 - *
200 - * @return bool
201 - * Returns TRUE after setting the options.
202 - */
203 - public static function refreshToken(string $token) {
204 - $parts = explode('.', $token);
205 - $token_data = json_decode(WebTotem::base64UrlDecode($parts[1]), true);
206 - $token_expired = $token_data['exp'] - 60;
207 -
208 - self::setOptions([
209 - 'auth_token_expired' => $token_expired,
210 - 'auth_token' => $token,
211 - ]);
212 -
213 - return TRUE;
214 - }
215 -
216 - /**
192 + /**
217 193 * Checks whether the user has activated the plugin using the API key.
218 194 *
219 195 * @return bool
220 196 * Returns the module activation status.
@@ -242,33 +218,8 @@
242 218 ]);
243 219 return TRUE;
244 220 }
245 221
246 - /**
247 - * Return the current API access token, authorizing only when necessary.
248 - *
249 - * The token is reused until it actually expires; a new sign-in happens only
250 - * when there is no token or the stored one is past its expiry.
251 - *
252 - * @return string
253 - * Access token, or an empty string when authorization failed.
254 - */
255 - public static function getAuthToken() {
256 - $token = self::getOption('auth_token');
257 - $expired_at = (int) self::getOption('auth_token_expired');
258 -
259 - if ($token && $expired_at > time()) {
260 - return $token;
261 - }
262 -
263 - $api_key = self::getOption('api_key');
264 - if ($api_key && WebTotemAPI::auth($api_key) === 'success') {
265 - return self::getOption('auth_token');
266 - }
267 -
268 - return $token ?: '';
269 - }
270 -
271 222 /**
272 223 * Set notification.
273 224 *
274 225 * @param string $type
@@ -331,22 +282,18 @@
331 282 add_blog_option($blog_id, 'wtotem_host_id', $host_id);
332 283 add_blog_option($blog_id, 'wtotem_host_name', $host_name);
333 284
334 285 if(!is_main_site($blog_id)){
335 - $all_hosts = json_decode(self::getOption('all_hosts'), true) ?: [];
286 + $all_hosts = self::getOption('all_hosts') ?: [];
336 287 $all_hosts[$host_name] = $host_id;
337 288
338 289 self::setOptions([
339 290 'all_hosts' => $all_hosts,
340 291 ]);
341 - } else {
342 - self::setOptions([
343 - 'host_id' => $host_id,
344 - 'host_name' => $host_name,
345 - ]);
346 292 }
347 293
348 - } else {
294 + }
295 + else {
349 296 self::setOptions([
350 297 'host_id' => $host_id,
351 298 'host_name' => $host_name,
352 299 ]);
@@ -399,12 +346,19 @@
399 346 * Main host data.
400 347 */
401 348 public static function getMainHost() {
402 349
403 - return [
404 - 'id' => self::getOption('host_id'),
405 - 'name' => self::getOption('host_name'),
406 - ];
350 + if(WebTotem::isMultiSite()){
351 + return [
352 + 'id' => get_blog_option(0, 'wtotem_host_id'),
353 + 'name' => get_blog_option(0, 'wtotem_host_name'),
354 + ];
355 + } else{
356 + return [
357 + 'id' => self::getOption('host_id'),
358 + 'name' => self::getOption('host_name'),
359 + ];
360 + }
407 361
408 362 }
409 363
410 364 /**
@@ -413,14 +367,12 @@
413 367 * @return void
414 368 */
415 369 public static function clearAllHosts() {
416 370
417 - $hosts = WebTotemAPI::getSites(1, 1000000);
418 - foreach ($hosts as $site) {
419 - if (empty($site['name'])) {
420 - continue;
421 - }
422 - $blog_id = self::getBlogId($site['name']);
371 + $data = WebTotemAPI::getSites();
372 + foreach ($data['edges'] as $site) {
373 + $site = $site['node'];
374 + $blog_id = self::getBlogId($site['hostname']);
423 375 delete_blog_option($blog_id, 'wtotem_host_id');
424 376 delete_blog_option($blog_id, 'wtotem_host_name');
425 377 }
426 378
@@ -454,19 +406,15 @@
454 406 *
455 407 * @return integer
456 408 * Blog id.
457 409 */
458 - public static function getBlogId($host_name){
459 - $local_sites = get_sites();
410 + public static function getBlogId($host_name){
411 + $current_network = get_network();
412 + $patterns = [ '/' . $current_network->domain . '/', '/\./', '/\//', ];
460 413
461 - foreach ($local_sites as $site){
462 - $domain = untrailingslashit($site->domain . $site->path);
463 - if($host_name == $domain){
464 - return $site->blog_id;
465 - }
466 - }
467 - return 0;
468 - }
414 + $slug = preg_replace( $patterns, '', $host_name );
415 + return ($slug) ? get_id_from_blogname($slug) : 0;
416 + }
469 417
470 418 /**
471 419 * Get all config options name.
472 420 *
@@ -611,9 +559,9 @@
611 559 * @return bool
612 560 */
613 561 public static function hideReadme($readmeFile = null) {
614 562 if ($readmeFile === null) {
615 - $readmeFile = ABSPATH . 'readme.html';
563 + $readmeFile = ABSPATH . '/readme.html';
616 564 }
617 565
618 566 if (file_exists($readmeFile)) {
619 567 $readmePathInfo = pathinfo($readmeFile);
@@ -631,9 +579,9 @@
631 579 * @return bool
632 580 */
633 581 public static function restoreReadme($readmeFile = null) {
634 582 if ($readmeFile === null) {
635 - $readmeFile = ABSPATH . 'readme.html';
583 + $readmeFile = ABSPATH . '/readme.html';
636 584 }
637 585 $readmePathInfo = pathinfo($readmeFile);
638 586 require_once(ABSPATH . WPINC . '/pluggable.php');
639 587 $hiddenReadmeFile = $readmePathInfo['dirname'] . '/' . $readmePathInfo['filename'] . '.' . wp_hash('readme') . '.' . $readmePathInfo['extension'];
@@ -686,94 +634,5 @@
686 634 public static function replaceVersionCallback($matches) {
687 635 global $wp_version;
688 636 return $matches[1] . '=' . ($wp_version === $matches[2] ? wp_hash($matches[2]) : $matches[2]) . $matches[3];
689 637 }
690 -
691 - /**
692 - * Check the nonce comming from any of the settings pages.
693 - *
694 - * @return bool True if the nonce is valid, false otherwise.
695 - */
696 - public static function checkOptionsNonce() {
697 - // Create the option_page value if permalink submission.
698 - if (!isset($_POST['option_page']) && isset($_POST['permalink_structure'])) {
699 - $_POST['option_page'] = 'permalink';
700 - }
701 -
702 - /* check if the option_page has an allowed value */
703 - $option_page = WebTotemRequest::post('option_page');
704 -
705 - if (!$option_page) {
706 - return false;
707 - }
708 -
709 - $action = '';
710 - $nonce = '_wpnonce';
711 -
712 - switch ($option_page) {
713 - case 'general':
714 - case 'writing':
715 - case 'reading':
716 - case 'discussion':
717 - case 'media':
718 - case 'options':
719 - $action = $option_page . '-options';
720 - break;
721 - case 'permalink':
722 - $action = 'update-permalink';
723 - break;
724 - }
725 -
726 - /* check the nonce validity */
727 - return (bool) (
728 - !empty($action)
729 - && isset($_REQUEST[$nonce])
730 - && wp_verify_nonce($_REQUEST[$nonce], $action)
731 - );
732 - }
733 -
734 - /**
735 - * Retrieve all the options stored by Wordpress in the database.
736 - *
737 - * @return array All the options stored by Wordpress in the database.
738 - */
739 - private static function getSiteOptions() {
740 - $settings = array();
741 -
742 - if (array_key_exists('wpdb', $GLOBALS)) {
743 - $results = $GLOBALS['wpdb']->get_results(
744 - 'SELECT * FROM ' . $GLOBALS['wpdb']->options . ' WHERE option_name NOT LIKE "%_transient_%" ORDER BY option_id ASC'
745 - );
746 -
747 - foreach ($results as $row) {
748 - $settings[$row->option_name] = $row->option_value;
749 - }
750 - }
751 -
752 - return $settings;
753 - }
754 -
755 - /**
756 - * Check what Wordpress options were changed comparing the values in the database
757 - * with the values sent through a simple request using a GET or POST method.
758 - *
759 - * @param array $request The content of the global variable GET or POST considering SERVER[REQUEST_METHOD].
760 - * @return array A list of all the options that were changes through this request.
761 - */
762 - public static function whatOptionsWereChanged($request = array())
763 - {
764 - $options_changed = [ 'original' => [], 'changed' => [] ];
765 -
766 - $site_options = self::getSiteOptions();
767 -
768 - foreach ($request as $req_name => $req_value) {
769 - if (array_key_exists($req_name, $site_options) && $site_options[ $req_name ] != $req_value ) {
770 - $options_changed['original'][ $req_name ] = $site_options[ $req_name ];
771 - $options_changed['changed'][ $req_name ] = $req_value;
772 - }
773 - }
774 -
775 - return $options_changed;
776 - }
777 -
778 -
779 638 }