GRAYBYTE WORDPRESS FILE MANAGER3750

Server IP : 162.213.255.40 / Your IP : 216.73.216.121
System : Linux server146.web-hosting.com 4.18.0-513.18.1.lve.el8.x86_64 #1 SMP Thu Feb 22 12:55:50 UTC 2024 x86_64
PHP Version : 8.0.30
Disable Function : NONE
cURL : ON | WGET : ON | Sudo : OFF | Pkexec : OFF

HOME

/home/hellrfbn/public_html/wp-content/plugins/updraftplus/includes/
Upload Files :
Current_dir [ Writeable ] Document_root [ Writeable ]

Command :


Current File : /home/hellrfbn/public_html/wp-content/plugins/updraftplus/includes//class-updraft-semaphore.php
<?php

if (!defined('ABSPATH')) die('No direct access.');

/**
 * Class Updraft_Semaphore_3_0
 *
 * This class is much simpler to use than the the previous series, as it has dropped support for complicated cases that were not being used. It also now only uses a single row in the options database, and takes care of creating it itself internally.
 *
 * Logging, though, may be noisier, unless your loggers are taking note of the log level and only registering what is required.
 *
 * Example of use (a lock that will expire if not released within 300 seconds)
 * 
 * See test.php for a longer example (including logging).
 *
 * $my_lock = new Updraft_Semaphore_3_0('my_lock_name', 300);
 * // If getting the lock does not succeed first time, try again up to twice
 * if ($my_lock->lock(2)) {
 *   try {
 *     // do stuff ...
 *   } catch (Exception $e) {
 *     // We are making sure we release the lock in case of an error
 *   } catch (Error $e) {
 *     // We are making sure we release the lock in case of an error
 *   }
 *   $my_lock->release();
 * } else {
 *   error_log("Sorry, could not get the lock");
 * }
 */
class Updraft_Semaphore_3_0 {

	// Time after which the lock will expire (in seconds)
	protected $locked_for;
	
	// Name for the lock in the WP options table
	protected $option_name;
	
	// Lock status - a boolean
	protected $acquired = false;
	
	// An array of loggers
	protected $loggers = array();

	/**
	 * Constructor. Instantiating does not lock anything, but sets up the details for future operations.
	 *
	 * @param String  $name		  - a unique (across the WP site) name for the lock. Should be no more than 51 characters in length (because of the use of the WP options table, with some further characters used internally)
	 * @param Integer $locked_for - time (in seconds) after which the lock will expire if not released. This needs to be positive if you don't want bad things to happen.
	 * @param Array	  $loggers	  - an array of loggers
	 */
	public function __construct($name, $locked_for = 300, $loggers = array()) {
		$this->option_name = 'updraft_lock_'.$name;
		$this->locked_for = $locked_for;
		$this->loggers = $loggers;
	}

	/**
	 * Internal function to make sure that the lock is set up in the database
	 *
	 * @return Integer - 0 means 'failed' (which could include that someone else concurrently created it); 1 means 'already existed'; 2 means 'exists, because we created it). The intention is that non-zero results mean that the lock exists.
	 */
	private function ensure_database_initialised() {
	
		global $wpdb;
		
		$sql = $wpdb->prepare("SELECT COUNT(*) FROM {$wpdb->options} WHERE option_name = %s", $this->option_name);
		
		if (1 === (int) $wpdb->get_var($sql)) {
			$this->log('Lock option ('.$this->option_name.', '.$wpdb->options.') already existed in the database', 'debug');
			return 1;
		}
		
		$sql = $wpdb->prepare("INSERT INTO {$wpdb->options} (option_name, option_value, autoload) VALUES(%s, '0', 'no');", $this->option_name);
		
		$rows_affected = $wpdb->query($sql);
		
		if ($rows_affected > 0) {
			$this->log('Lock option ('.$this->option_name.', '.$wpdb->options.') was created in the database', 'debug');
		} else {
			$this->log('Lock option ('.$this->option_name.', '.$wpdb->options.') failed to be created in the database (could already exist)', 'notice');
		}
		
		return ($rows_affected > 0) ? 2 : 0;
	}

	/**
	 * Attempt to acquire the lock. If it was already acquired, then nothing extra will be done (the method will be a no-op).
	 *
	 * @param Integer $retries - how many times to retry (after a 1 second sleep each time)
	 *
	 * @return Boolean - whether the lock was successfully acquired or not
	 */
	public function lock($retries = 0) {
	
		if ($this->acquired) return true;
		
		global $wpdb;
		
		$time_now = time();
		$acquire_until = $time_now + $this->locked_for;
		
		$sql = $wpdb->prepare("UPDATE {$wpdb->options} SET option_value = %s WHERE option_name = %s AND option_value < %d", $acquire_until, $this->option_name, $time_now);
		
		if (1 === $wpdb->query($sql)) {
			$this->log('Lock ('.$this->option_name.', '.$wpdb->options.') acquired', 'info');
			$this->acquired = true;
			return true;
		}
		
		// See if the failure was caused by the row not existing (we check this only after failure, because it should only occur once on the site)
		if (!$this->ensure_database_initialised()) return false;
		
		do {
			// Now that the row has been created, try again
			if (1 === $wpdb->query($sql)) {
				$this->log('Lock ('.$this->option_name.', '.$wpdb->options.') acquired after initialising the database', 'info');
				$this->acquired = true;
				return true;
			}
			$retries--;
			if ($retries >=0) {
				$this->log('Lock ('.$this->option_name.', '.$wpdb->options.') not yet acquired; sleeping', 'debug');
				sleep(1);
				// As a second has passed, update the time we are aiming for
				$time_now = time();
				$acquire_until = $time_now + $this->locked_for;
				$sql = $wpdb->prepare("UPDATE {$wpdb->options} SET option_value = %s WHERE option_name = %s AND option_value < %d", $acquire_until, $this->option_name, $time_now);
			}
		} while ($retries >= 0);
		
		$this->log('Lock ('.$this->option_name.', '.$wpdb->options.') could not be acquired (it is locked)', 'info');
		
		return false;
	}

	/**
	 * Release the lock
	 *
	 * N.B. We don't attempt to unlock it unless we locked it. i.e. Lost locks are left to expire rather than being forced. (If we want to force them, we'll need to introduce a new parameter).
	 *
	 * @return Boolean - if it returns false, then the lock was apparently not locked by us (and the caller will most likely therefore ignore the result, whatever it is). 
	 */
	public function release() {
		if (!$this->acquired) return false;
		global $wpdb;
		$sql = $wpdb->prepare("UPDATE {$wpdb->options} SET option_value = '0' WHERE option_name = %s", $this->option_name);
		
		$this->log('Lock option ('.$this->option_name.', '.$wpdb->options.') released', 'info');
		
		$result = (int) $wpdb->query($sql) === 1;
		
		$this->acquired = false;
		
		return $result;
	}
	
	/**
	 * Cleans up the DB of any residual data. This should not be used as part of ordinary unlocking; only as part of deinstalling, or if you otherwise know that the lock will not be used again. If calling this, it's redundant to first unlock (and a no-op to attempt to do so afterwards).
	 */
	public function delete() {
		$this->acquired = false;
	
		global $wpdb;
		$wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->options} WHERE option_name = %s", $this->option_name));

		$this->log('Lock option ('.$this->option_name.', '.$wpdb->options.') was deleted from the database');
	}
	
	/**
	 * Captures and logs any given messages
	 *
	 * @param String $message - the error message
	 * @param String $level	  - the message level (debug, notice, info, warning, error)
	 */
	public function log($message, $level = 'info') {
		if (isset($this->loggers)) {
			foreach ($this->loggers as $logger) {
				$logger->log($message, $level);
			}
		}
	}
	
	/**
	 * Sets the list of loggers for this instance (removing any others).
	 *
	 * @param Array $loggers - the loggers for this task
	 */
	public function set_loggers($loggers) {
		$this->loggers = array();
		foreach ($loggers as $logger) {
			$this->add_logger($logger);
		}
	}

	/**
	 * Add a logger to loggers list
	 *
	 * @param Callable $logger - a logger (a method with a callable function 'log', taking string parameters $level $message)
	 */
	public function add_logger($logger) {
		$this->loggers[] = $logger;
	}

	/**
	 * Return the current list of loggers
	 *
	 * @return Array
	 */
	public function get_loggers() {
		return $this->loggers;
	}
}

[ Back ]
Name
Size
Last Modified
Owner / Group
Permissions
Options
..
--
July 23 2025 07:38:28
hellrfbn / hellrfbn
0755
Dropbox2
--
July 23 2025 07:38:28
hellrfbn / hellrfbn
0755
Google
--
July 23 2025 07:38:28
hellrfbn / hellrfbn
0755
blockui
--
July 23 2025 07:38:28
hellrfbn / hellrfbn
0755
checkout-embed
--
July 23 2025 07:38:28
hellrfbn / hellrfbn
0755
cloudfiles
--
July 23 2025 07:38:28
hellrfbn / hellrfbn
0755
handlebars
--
July 23 2025 07:38:28
hellrfbn / hellrfbn
0755
images
--
July 23 2025 07:38:28
hellrfbn / hellrfbn
0755
jquery-ui.dialog.extended
--
July 23 2025 07:38:28
hellrfbn / hellrfbn
0755
jquery.serializeJSON
--
July 23 2025 07:38:28
hellrfbn / hellrfbn
0755
jstree
--
July 23 2025 07:38:28
hellrfbn / hellrfbn
0755
labelauty
--
July 23 2025 07:38:28
hellrfbn / hellrfbn
0755
pcloud
--
July 23 2025 07:38:28
hellrfbn / hellrfbn
0755
tether
--
July 23 2025 07:38:28
hellrfbn / hellrfbn
0755
tether-shepherd
--
July 23 2025 07:38:28
hellrfbn / hellrfbn
0755
updraftclone
--
July 23 2025 07:38:28
hellrfbn / hellrfbn
0755
.htaccess
0.41 KB
July 23 2025 07:38:28
hellrfbn / hellrfbn
0644
S3.php
76.423 KB
February 05 2025 15:45:31
hellrfbn / hellrfbn
0644
S3compat.php
30.841 KB
February 05 2025 15:45:31
hellrfbn / hellrfbn
0644
cacert.pem
216.279 KB
February 05 2025 15:45:31
hellrfbn / hellrfbn
0644
class-backup-history.php
39.482 KB
February 05 2025 15:45:31
hellrfbn / hellrfbn
0644
class-commands.php
48.606 KB
February 05 2025 15:45:31
hellrfbn / hellrfbn
0644
class-database-utility.php
36.452 KB
February 05 2025 15:45:31
hellrfbn / hellrfbn
0644
class-filesystem-functions.php
40.292 KB
February 05 2025 15:45:31
hellrfbn / hellrfbn
0644
class-http-error-descriptions.php
11.396 KB
February 05 2025 15:45:31
hellrfbn / hellrfbn
0644
class-job-scheduler.php
10.305 KB
February 05 2025 15:45:31
hellrfbn / hellrfbn
0644
class-manipulation-functions.php
16.737 KB
February 05 2025 15:45:31
hellrfbn / hellrfbn
0644
class-partialfileservlet.php
7.381 KB
February 05 2025 15:45:31
hellrfbn / hellrfbn
0644
class-remote-send.php
30.175 KB
February 05 2025 15:45:31
hellrfbn / hellrfbn
0644
class-search-replace.php
20.088 KB
February 05 2025 15:45:31
hellrfbn / hellrfbn
0644
class-semaphore.php
6.273 KB
February 05 2025 15:45:31
hellrfbn / hellrfbn
0644
class-storage-methods-interface.php
18.227 KB
February 05 2025 15:45:31
hellrfbn / hellrfbn
0644
class-updraft-dashboard-news.php
8.049 KB
February 05 2025 15:45:31
hellrfbn / hellrfbn
0644
class-updraft-semaphore.php
7.513 KB
February 05 2025 15:45:31
hellrfbn / hellrfbn
0644
class-updraftcentral-updraftplus-commands.php
1.813 KB
February 05 2025 15:45:31
hellrfbn / hellrfbn
0644
class-updraftplus-encryption.php
13.635 KB
February 05 2025 15:45:31
hellrfbn / hellrfbn
0644
class-wpadmin-commands.php
36.302 KB
February 05 2025 15:45:31
hellrfbn / hellrfbn
0644
class-zip.php
17.876 KB
February 05 2025 15:45:31
hellrfbn / hellrfbn
0644
ftp.class.php
6.503 KB
February 05 2025 15:45:31
hellrfbn / hellrfbn
0644
get-cpanel-quota-usage.pl
0.398 KB
February 05 2025 15:45:31
hellrfbn / hellrfbn
0644
google-extensions.php
9.274 KB
February 05 2025 15:45:31
hellrfbn / hellrfbn
0644
jquery-ui.custom-v1.11.4-1-25-1.min.css
37.843 KB
February 05 2025 15:45:31
hellrfbn / hellrfbn
0644
jquery-ui.custom-v1.11.4-1-25-1.min.css.map
57.006 KB
February 05 2025 15:45:31
hellrfbn / hellrfbn
0644
jquery-ui.custom-v1.11.4.css
42.181 KB
February 05 2025 15:45:31
hellrfbn / hellrfbn
0644
jquery-ui.custom-v1.12.1-1-25-1.min.css
39.548 KB
February 05 2025 15:45:31
hellrfbn / hellrfbn
0644
jquery-ui.custom-v1.12.1-1-25-1.min.css.map
59.413 KB
February 05 2025 15:45:31
hellrfbn / hellrfbn
0644
jquery-ui.custom-v1.12.1.css
44.033 KB
February 05 2025 15:45:31
hellrfbn / hellrfbn
0644
migrator-lite.php
52.476 KB
February 05 2025 15:45:31
hellrfbn / hellrfbn
0644
updraft-admin-common-1-25-1.min.js
153.627 KB
February 05 2025 15:45:31
hellrfbn / hellrfbn
0644
updraft-admin-common.js
254.165 KB
February 05 2025 15:45:31
hellrfbn / hellrfbn
0644
updraft-restorer-skin-compatibility.php
0.441 KB
February 05 2025 15:45:31
hellrfbn / hellrfbn
0644
updraft-restorer-skin.php
1.683 KB
February 05 2025 15:45:31
hellrfbn / hellrfbn
0644
updraftcentral.php
2.743 KB
February 05 2025 15:45:31
hellrfbn / hellrfbn
0644
updraftplus-clone.php
7.018 KB
February 05 2025 15:45:31
hellrfbn / hellrfbn
0644
updraftplus-login.php
4.266 KB
February 05 2025 15:45:31
hellrfbn / hellrfbn
0644
updraftplus-notices.php
20.961 KB
February 05 2025 15:45:31
hellrfbn / hellrfbn
0644
updraftplus-tour.php
13.077 KB
February 05 2025 15:45:31
hellrfbn / hellrfbn
0644
updraftvault.php
1.992 KB
February 05 2025 15:45:31
hellrfbn / hellrfbn
0644

GRAYBYTE WORDPRESS FILE MANAGER @ 2025
CONTACT ME
Static GIF