Beispiel #1
0
 public function send($supress = true)
 {
     // Build the email header
     $this->build_header();
     // Disable error reporting
     if ($supress = true) {
         \Debug::silent_mode(true);
     }
     // Send the email
     $sent = mail($this->to, $this->subject, $this->message, $this->header);
     // Re-enable errors and return
     if ($supress = true) {
         \Debug::silent_mode(false);
     }
     return $sent;
 }
Beispiel #2
0
 public function connect($server, $port, $user, $pass, $urn = NULL)
 {
     // Determine our URI based on our core if one isnt provided
     if ($urn == NULL) {
         $e = config('emulator');
         switch ($e) {
             case "mangos":
                 $uri = "urn:MaNGOS";
                 break;
             case "trinity":
                 $uri = "urn:TC";
                 break;
             default:
                 $uri = "";
                 break;
         }
     } else {
         $uri = "urn:" . $urn;
     }
     // Disable error reporting
     \Debug::silent_mode(true);
     // Open the handle
     $test = fsockopen($server, $port, $errno, $errstr, 3);
     // Re-enable error reporting
     \Debug::silent_mode(false);
     // Check if we connected successfully
     if ($test) {
         // Build our connection params
         $params = array("location" => "http://" . $server . ":" . $port . "/", "uri" => $uri, "style" => SOAP_RPC, "login" => $user, "password" => $pass);
         // Open the handle
         try {
             $this->handle = new \SoapClient(NULL, $params);
             $return = TRUE;
         } catch (\Exception $e) {
             $this->console_return = $this->debug[] = 'Failed to initiate SOAP Connection: ' . $e->getMessage();
             $this->write_log();
             $return = FALSE;
         }
     } else {
         $this->console_return = $this->debug[] = 'Connection to ' . $server . ':' . $port . ' Failed!';
         $this->write_log();
         $return = FALSE;
     }
     // Return our success or failure
     return $return;
 }
Beispiel #3
0
 public function connect($host, $port, $user, $pass)
 {
     // Disable error reporting
     \Debug::silent_mode(true);
     // Open the handle
     $this->handle = fsockopen($host, $port, $errno, $errstr, 3);
     // Re-enable error reporting
     \Debug::silent_mode(false);
     // Check if we connected successfully
     if ($this->handle) {
         // get the Login prompt
         $auth_prompt = $this->get_response();
         // Uppercase Username
         $user = strtoupper($user);
         // Write username and password to command window
         $send1 = $this->send($user);
         $send2 = $this->send($pass);
         // If our writing is successful
         if ($send1 == TRUE && $send2 == TRUE) {
             // Get the motd OR auth error, 1 of the 2
             $response = $this->get_response();
             if (strpos($response, "failed") !== FALSE) {
                 $this->console_return = $this->debug[] = 'Authorization Failed.';
                 $this->write_log();
                 $this->disconnect();
                 return FALSE;
             }
             return TRUE;
         } else {
             $this->debug[] = 'Writing to console failed!';
         }
     } else {
         $this->console_return = $this->debug[] = 'Connection to ' . $host . ':' . $port . ' Failed!';
     }
     // If we are here, we had errors :(
     $this->write_log();
     return FALSE;
 }
Beispiel #4
0
 public function realm_status()
 {
     // Load our config class
     $Config = load_class('Config');
     $Cache = $this->load->library('Cache');
     $Ajax = get_instance();
     // See if we have cached results
     $result = $Cache->get('ajax_realm_status');
     if ($result == FALSE) {
         // Set the result to array, and load time helper
         $result = array();
         $this->load->helper('Time');
         // Fetch the array of realms
         $query = "SELECT `id`, `name`, `type`, `address`, `port`, `max_players` FROM `pcms_realms`";
         $realms = $this->DB->query($query)->fetchAll();
         if ($realms == FALSE) {
             $realms = array();
         }
         // Loop through each realm, and get its status
         foreach ($realms as $key => $realm) {
             // Dont show warning produced by fsockopen
             \Debug::silent_mode(true);
             $handle = fsockopen($realm['address'], $realm['port'], $errno, $errstr, 2);
             \Debug::silent_mode(false);
             // Set our status var
             $handle == FALSE ? $status = 0 : ($status = 1);
             // Load the wowlib for this realm
             $wowlib = $this->load->wowlib($realm['id']);
             // Build our realms return
             if ($status == 1 && is_object($wowlib) && is_object($wowlib->characters)) {
                 // Get our realm uptime
                 $uptime = $this->realm->uptime($realm['id']);
                 $uptime == FALSE ? $uptime = 'Unavailable' : ($uptime = format_time($uptime));
                 // Determine population
                 $ally = $wowlib->characters->getOnlineCount(1);
                 $horde = $wowlib->characters->getOnlineCount(2);
                 $online = $ally + $horde;
                 $space = $realm['max_players'] - $online;
                 $percent = $space < 0 ? 100 : $space / $realm['max_players'];
                 // Get our population text
                 if ($percent < 40) {
                     $pop = '<span id="realm_population_low">Low</span>';
                 } elseif ($percent < 75) {
                     $pop = '<span id="realm_population_medium">Medium</span>';
                 } else {
                     $pop = $percent > 98 ? '<span id="realm_population_full">Full</span>' : '<span id="realm_population_high">High</span>';
                 }
                 // Build our realm info array
                 $result[] = array('success' => true, 'id' => $realm['id'], 'name' => $realm['name'], 'type' => $realm['type'], 'status' => $status, 'population' => $pop, 'online' => $online, 'alliance' => $ally, 'horde' => $horde, 'uptime' => $uptime);
             } else {
                 $result[] = array('success' => true, 'id' => $realm['id'], 'name' => $realm['name'], 'type' => $realm['type'], 'status' => $status, 'population' => '<span id="realm_population_low">Low</span>', 'online' => 0, 'alliance' => 0, 'horde' => 0, 'uptime' => 'Offline');
             }
         }
         // Cache the results for 2 minutes
         $Cache->save('ajax_realm_status', $result, 120);
     }
     // Push the output in json format
     echo json_encode($result);
 }
Beispiel #5
0
 public function update()
 {
     // Make sure user is super admin for ajax
     if ($this->user['is_super_admin'] != 1) {
         $this->show_403();
         return;
     }
     // Build our page title / desc, then load the view
     $data = array('page_title' => "Remote Updater", 'page_desc' => "This script allows you to update your CMS with just a click of a button.");
     //Try cURL first.
     if (!extension_loaded("curl")) {
         $ssl = true;
         $fopen = true;
         //Fall back on OpenSSL and allow_url_fopen before failing.
         if (!extension_loaded("openssl") || !in_array("https", stream_get_wrappers())) {
             $ssl = false;
         }
         if (ini_get("allow_url_fopen") != 1) {
             $fopen = false;
         }
         if (!$ssl || !$fopen) {
             $Message = "The Plexis remote updater requires either cURL or OpenSSL and allow_url_fopen, please enable cURL or OpenSSL and allow_url_fopen.<br /><br />cURL: Disabled";
             $Message .= "<br />OpenSSL: " . $ssl ? "Enabled" : "Disabled";
             $Message .= "<br />allow_url_fopen" . $fopen ? "Enabled" : "Disabled";
             output_message("warning", $Message);
             $this->load->view("blank", $data);
             return;
         }
     }
     // Include the URL helper
     $this->load->helper('Url');
     // Get the file changes from github
     $start = microtime(1);
     \Debug::silent_mode(true);
     $page = getPageContents('https://api.github.com/repos/Plexis/Plexis/commits?per_page=30');
     \Debug::silent_mode(false);
     $stop = microtime(1);
     // Granted we have page contents
     if ($page) {
         // Decode the results
         $commits = json_decode($page, TRUE);
         // Defaults
         $count = 0;
         $latest = 0;
         // Get the latest build
         $message = $commits[0]['commit']['message'];
         if (preg_match('/([0-9]+)/', $message, $latest)) {
             $latest = $latest[0];
             if (CMS_BUILD < $latest) {
                 $count = $latest - CMS_BUILD;
                 if ($count > 29) {
                     output_message('warning', 'Your cms is out of date by more than 30 updates. You will need to manually update.');
                     $this->load->view('blank', $data);
                     return;
                 }
             }
         } else {
             output_message('warning', 'Unable to determine latest build');
             $this->load->view('blank', $data);
             return;
         }
         // Simple
         $count == 0 ? $next = $commits[0] : ($next = $commits[$count - 1]);
         $d = new DateTime($next['commit']['author']['date']);
         $date = $d->format("M j, Y - g:i a");
         // Set JS vars
         $this->Template->setjs('update_sha', $next['sha']);
         $this->Template->setjs('update_url', $next['url']);
         // Build our page data
         $data['time'] = round($stop - $start, 5);
         $data['count'] = $count;
         $data['latest'] = $latest;
         $data['message'] = preg_replace('/([\\[0-9\\]]+)/', '', htmlspecialchars($next['commit']['message']), 1);
         $data['date'] = $date;
         $data['author'] = '<a href="https://github.com/' . $next['author']['login'] . '" target="_blank">' . ucfirst($next['author']['login']) . '</a>';
         $data['more_info'] = "https://github.com/Plexis/Plexis/commit/" . $next['sha'];
         $data['CMS_BUILD'] = CMS_BUILD;
         unset($commits);
         // No updates has a different view
         if ($count == 0) {
             $this->load->view('no_updates', $data);
         } else {
             // Add the progress bar
             $this->Template->add_script('progressbar_mini.js');
             $this->Template->add_css('progressbar.css');
             $this->load->view('updates', $data);
         }
     } else {
         output_message('warning', 'Unable to fetch updates from Github.');
         $this->load->view('blank', $data);
         return;
     }
 }
Beispiel #6
0
function show_error($err_message = 'none', $args = null, $lvl = E_ERROR, $fatal = false)
{
    // Let get a backtrace for deep debugging
    $backtrace = debug_backtrace();
    $calling = $backtrace[0];
    // Load language
    $lang = load_class('Language');
    $lang->load('core_errors');
    $message = $lang->get($err_message);
    // Allow custom messages
    if ($message === FALSE) {
        $message = $err_message;
    }
    // Do replacing
    if (is_array($args)) {
        $message = vsprintf($message, $args);
    }
    // Let the debugger take over from here
    if ($fatal) {
        \Debug::silent_mode(false);
    }
    \Debug::trigger_error($lvl, $message, $calling['file'], $calling['line']);
}
Beispiel #7
0
 protected function _initWowlib()
 {
     // Include the wowlib file
     require path(ROOT, 'third_party', 'wowlib', 'Wowlib.php');
     // Add Trace
     \Debug::trace('Initializing Wowlib...', __FILE__, __LINE__);
     // Try to init the wowlib
     try {
         \Wowlib::Init(config('emulator'));
         \Debug::trace('Wowlib Initialized successfully', __FILE__, __LINE__);
     } catch (Exception $e) {
         \Debug::silent_mode(false);
         \Debug::trace('Wowlib failed to initialize. Message thrown was: ' . $e->getMessage(), __FILE__, __LINE__);
         show_error('Wowlib Error: ' . $e->getMessage(), false, E_ERROR);
     }
 }
Beispiel #8
0
 public function update()
 {
     // Make sure we arent directly accessed and the user has perms
     $this->check_access('sa');
     // Process action
     if (isset($_POST['action'])) {
         $action = trim($this->Input->post('action'));
         switch ($action) {
             case "get_latest":
                 // cURL exist? If not we need to verify the user has openssl installed and https support
                 $curl = function_exists('curl_exec');
                 if (!$curl) {
                     // Make sure the Openssl extension is loaded
                     if (!extension_loaded('openssl')) {
                         echo json_encode(array('success' => false, 'message' => 'Openssl extension not found. Please enable the openssl extension in your php.ini file'));
                         return;
                     }
                     // Check for https support
                     if (!in_array('https', stream_get_wrappers())) {
                         echo json_encode(array('success' => false, 'message' => 'Unable to find the stream wrapper "https" - did you forget to enable it when you configured PHP?'));
                         return;
                     }
                 }
                 // Make sure the client server allows fopen of urls
                 if (ini_get('allow_url_fopen') == 1 || $curl == true) {
                     // Get the file changes from github
                     $start = microtime(1);
                     \Debug::silent_mode(true);
                     $page = getPageContents('https://api.github.com/repos/Plexis/Plexis/commits?per_page=1', false);
                     \Debug::silent_mode(false);
                     $stop = microtime(1);
                     if ($page == FALSE || empty($page)) {
                         echo json_encode(array('success' => false, 'message' => 'Unable to connect to the update server'));
                         return;
                     }
                     // Decode the results
                     $commits = json_decode($page, TRUE);
                     // Defaults
                     $count = 0;
                     $latest = 0;
                     echo json_encode(array('success' => true, 'message' => $commits));
                     return;
                 } else {
                     echo json_encode(array('success' => false, 'message' => 'allow_url_fopen not enabled in php.ini'));
                     return;
                 }
                 break;
             case "init":
                 config_set('site_updating', 1);
                 config_save('app');
                 break;
             case "finish":
                 // Enable the site again
                 config_set('site_updating', 0);
                 config_save('app');
                 break;
             case "next":
                 // Load the commit.info file
                 $sha = $type = trim($this->Input->post('sha'));
                 $url = 'https://raw.github.com/Plexis/Plexis/' . $sha . '/commit.info';
                 // Get the file changes from github
                 $start = microtime(1);
                 \Debug::silent_mode(true);
                 $page = trim(getPageContents($url, false));
                 \Debug::silent_mode(false);
                 $stop = microtime(1);
                 if ($page == FALSE || empty($page)) {
                     echo json_encode(array('success' => false, 'data' => 'Error fetching updates'));
                     return;
                 }
                 echo json_encode(array('success' => true, 'data' => json_decode($page)));
                 break;
             case "update":
                 // Grab POSTS
                 $type = trim($this->Input->post('status'));
                 $sha = trim($this->Input->post('sha'));
                 $file = trim(str_replace(array('/', '\\'), '/', $this->Input->post('filename')));
                 $url = 'https://raw.github.com/Plexis/Plexis/' . $sha . '/' . $file;
                 $filename = ROOT . DS . str_replace('/', DS, $file);
                 $dirname = dirname($filename);
                 // Load our Filesystem Class
                 $Fs = $this->load->library('Filesystem');
                 // Build our default Json return
                 $return = array();
                 $success = TRUE;
                 $removed = FALSE;
                 // Hush errors
                 \Debug::silent_mode(true);
                 // Get file contents
                 $contents = trim(getPageContents($url, false));
                 $mod = substr($type, 0, 1);
                 switch ($mod) {
                     case "A":
                     case "M":
                         // Make sure the Directory exists!
                         if (!is_dir($dirname)) {
                             // Ignore install files if the install directory doesnt exist
                             if (strpos($dirname, ROOT . DS . 'install') !== false) {
                                 $this->output(true, '');
                                 return;
                             }
                             // Create the directory for the new file if it doesnt exist
                             if (!$Fs->create_dir($dirname)) {
                                 $this->output(false, 'Error creating directory "' . $dirname . '"');
                                 return;
                             }
                         }
                         // Create cache file of modified files to prevent update errors
                         if ($mod == 'M') {
                             if (!$this->addfileids($sha, 'M', $filename)) {
                                 \Debug::write_debuglog('updater.xml');
                                 $this->output(false, 'Error creating/writting to the updater.cache file. A Detailed trace log has been generated "system/logs/debug/updater.xml"');
                                 return;
                             }
                             // Set cache filename
                             $filename = $filename . '.tmp';
                         }
                         // Now attempt to write to the file, create it if it doesnt exist
                         if (!$Fs->create_file($filename, $contents)) {
                             $this->output(false, 'Error creating/opening file "' . $filename . '"');
                             return;
                         }
                         // Add file to modify list
                         break;
                     case "D":
                         if (!$this->addfileids($sha, 'D', $filename)) {
                             \Debug::write_debuglog('updater.xml');
                             $this->output(false, 'Error creating/writting to the updater.cache file. A Detailed trace log has been generated "system/logs/debug/updater.xml"');
                             return;
                         }
                         break;
                 }
                 // Output success
                 $this->output(true, '');
                 break;
             case 'finalize':
                 // Load our Filesystem Class
                 $Fs = $this->load->library('Filesystem');
                 // Add trace for debugging
                 \Debug::trace('Finalizing updates...', __FILE__, __LINE__);
                 // We need to rename all modified files from thier cache version, and remove deleted files
                 $cfile = path(SYSTEM_PATH, 'cache', 'updater.cache');
                 if (file_exists($cfile)) {
                     $data = unserialize(file_get_contents($cfile));
                     unset($data['sha']);
                     foreach ($data['files'] as $file) {
                         // If we are missing a file name or mode, then continue to the next loop
                         if (!isset($file['mode']) || !isset($file['filename'])) {
                             continue;
                         }
                         // Modified file
                         if ($file['mode'] == 'M') {
                             $tmp = $file['filename'] . '.tmp';
                             if (!$Fs->copy($tmp, $file['filename'])) {
                                 // Add trace for debugging
                                 \Debug::trace('Failed to copy {' . $tmp . '} to {' . $file['filename'] . '}', __FILE__, __LINE__);
                                 \Debug::write_debuglog('updater.xml');
                                 $this->output(false, 'Error copying cache contents of file ' . $file['filename'] . '. Update failed.');
                                 die;
                             }
                             $Fs->delete_file($tmp);
                         } else {
                             // Deleted file / dir
                             $Fs->delete($data['filename']);
                             // Re-read the directory
                             clearstatcache();
                             $files = $Fs->read_dir($dirname);
                             // If empty, delete .DS / .htaccess files and remove dir!
                             if (empty($files) || sizeof($files) == 1 && $files[0] == '.htaccess') {
                                 $Fs->remove_dir($dirname);
                             }
                         }
                     }
                     // Remove the updater cache file
                     $Fs->delete_file($cfile);
                     // Output success
                     $this->output(true, '');
                 } else {
                     // Add trace for debugging
                     \Debug::trace('updater.cache file doesnt exist. Update failed.', __FILE__, __LINE__);
                     \Debug::write_debuglog('updater.xml');
                     $this->output(false, 'Unable to open the updater.cache file. Update failed.');
                 }
                 break;
         }
         // End Swicth $action
     } else {
         $this->output(false, 'Invalid Post Action');
     }
 }