| Server IP : 151.101.66.159 / Your IP : 216.73.216.66 Web Server : Flywheel/5.1.0 System : Linux wordpress 6.12.113+ #1 SMP Thu Oct 22 02:38:20 UTC 2026 x86_64 User : root ( ) PHP Version : 7.4.33.18 Disable Function : disk_free_space,diskfreespace,dl,exec,fpassthru,getmypid,getmyuid,highlight_file,link,opcache_compile_file,opcache_get_configuration,opcache_is_script_cached,passthru,pcntl_alarm,pcntl_exec,pcntl_fork,pcntl_get_last_error,pcntl_getpriority,pcntl_setpriority,pcntl_signal,pcntl_signal_dispatch,pcntl_sigprocmask,pcntl_sigtimedwait,pcntl_sigwaitinfo,pcntl_strerror,pcntl_wait,pcntl_waitpid,pcntl_wexitstatus,pcntl_wifcontinued,pcntl_wifexited,pcntl_wifsignaled,pcntl_wifstopped,pcntl_wstopsig,pcntl_wtermsig,phpinfo,popen,posix_ctermid,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_times,posix_ttyname,posix_uname,proc_close,proc_get_status,proc_nice,proc_open,proc_terminate,shell_exec,show_source,socket_listen,source,system,virtual MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /www/flywheel-config/plugins/flywheel/direct-login/ |
Upload File : |
<?php
namespace FlywheelDirectLogin;
class Request {
private $id;
private $username;
private $email;
public function __construct($id = null, $username = null, $email = null) {
$this->id = $id;
$this->username = $username;
$this->email = $email;
}
public function getID() {
return $this->id;
}
public function getUsername() {
return $this->username;
}
public function getEmail() {
return $this->email;
}
/**
* Resets the request and generates a new request ID.
*/
public function regenerate() {
$this->id = self::generateRequestID();
$this->username = null;
$this->email = null;
return $this->id;
}
/**
* Decrypt the payload and populate the request object.
*/
public function decrypt($payload, $nonce, $key) {
$payload = sodium_crypto_secretbox_open($payload, $nonce, $key);
if( $payload === false ) {
throw new InvalidPayloadException("bad ciphertext");
}
$message = json_decode($payload, true);
if($message === null) {
throw new InvalidPayloadException("error decoding json");
}
$this->id = $message["request_id"];
$this->username = $message["username"];
$this->email = $message["email"];
}
/**
* Get the WordPress user for this request.
*
* The preference is an existing user, matched by email.
*
* Failing that, create one with the Flywheel username, or if taken,
* with the email as username.
*/
public function user() {
$user = get_user_by('email', $this->getEmail());
if(false === $user) {
$user_login = $this->getUsername();
$user = get_user_by("login", $this->getUsername());
if(false !== $user) {
$user_login = $this->getEmail();
}
$user_id = register_new_user($user_login, $this->getEmail());
if(is_wp_error($user_id)) {
throw new \Exception("unable to create user: " . $user_id->get_error_message());
}
$user = new \WP_User($user_id);
$user->set_role('administrator');
}
return $user;
}
/**
* Generate a secure, random request ID.
*
* This is 240 bits of entropy, base64 encoded.
* 30 bytes was chosen as large enough, would encode without padding.
*
* For reference, UUIDv4 are 128 bits.
*/
private static function generateRequestID() {
return base64_encode(random_bytes(30));
}
}
class InvalidPayloadException extends \Exception {
public function __toString() {
return "InvalidPayloadException: {$this->message}\n";
}
}