Example #1
0
 /**
  * Uninstaller::preUninstall()
  * 
  * @return
  */
 public function preUninstall()
 {
     // Get the module details
     $module = WebApp::get('ns');
     // Get the module ID
     $mod_query = $this->mySQL_r->prepare("SELECT `namespace`, `module_id` FROM `core_modules` WHERE `namespace`=?");
     $mod_query->bind_param('s', $module);
     $mod_query->execute();
     $mod_query->store_result();
     if ($mod_query->num_rows == 1) {
         $mod_query->bind_result($namespace, $module_id);
         // Workout the module dir
         while ($mod_query->fetch()) {
             $mod_dir = __MODULE__ . '/' . strtolower($namespace);
             $mod_id = $module_id;
         }
         // Generate a reference hash
         $hash = ranString(4);
         // Set the session variables
         Session::set($this::name_space, 'uninstall_from_' . $hash . '_ns', $namespace);
         Session::set($this::name_space, 'uninstall_from_' . $hash . '_dir', $mod_dir);
         Session::set($this::name_space, 'uninstall_from_' . $hash . '_id', $mod_id);
         // Navigate to the uninstall page
         $this->parent->parent->addHeader('Location', '/admin/modules/uninstall/' . $hash);
         return new ActionResult($this, '/admin/modules/uninstall/' . $hash, 1, '', B_T_SUCCESS);
     } else {
         // We couldn't find the module
         $msg = 'Failed to find module, please ask the administrator to perform a manual uninstall. (MOD_NS: ' . $module . ')';
         Session::set($this::name_space, 'msg', $msg);
         $this->parent->parent->addHeader('Location', '/admin/modules/uninstall/');
         return new ActionResult($this, '/admin/modules/uninstall/', 0, $msg, B_T_FAIL);
     }
 }
Example #2
0
 /**
  * Debugger::debug()
  * 
  * @param mixed $text
  * @return
  */
 public function debug($text, $shift = 0, $cli_print = false)
 {
     $space = '';
     $spaces = 80 - strlen($text);
     for ($s = 1; $s <= $spaces; $s++) {
         $space .= ' ';
     }
     if (version_compare(PHP_VERSION, '5.3.6', '>=')) {
         $bt = debug_backtrace(~DEBUG_BACKTRACE_PROVIDE_OBJECT & DEBUG_BACKTRACE_IGNORE_ARGS);
     } else {
         $bt = debug_backtrace(false);
     }
     $caller = array_shift($bt);
     if (strpos($caller['file'], 'autoload.php') === false) {
         $caller = array_shift($bt);
     }
     if ($shift != 0 && count($bt) > 1) {
         for ($i = 0; $i < abs($shift); $i++) {
             if (count($bt) <= abs($shift)) {
                 break;
             }
             $caller = array_shift($bt);
         }
     }
     $file = '';
     if (array_key_exists('file', $caller)) {
         $file = str_replace(__EXECDIR__, '', $caller['file']);
     } else {
         $caller['file'] = 'Unknown';
         $caller['line'] = '-';
     }
     $file = str_replace(DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'modules', '_MODULE_', $file);
     $file = str_replace(DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'plugins', '_PLUGIN_', $file);
     $file = str_replace(DIRECTORY_SEPARATOR . 'lib', '_LIB_', $file);
     $file = str_replace(DIRECTORY_SEPARATOR . 'class.', DIRECTORY_SEPARATOR, $file);
     if ($spaces < 16 || strlen($file) > 30) {
         $file = explode(DIRECTORY_SEPARATOR, $caller['file']);
         $file = $file[count($file) - 1];
     }
     $msg = $text . $space . '(' . $file . ', ' . $caller['line'] . ')';
     $this->debugLog[ranString(2, 2) . microtime(false)] = $msg;
     if (is_CLI() && $cli_print) {
         echo ' # ' . $msg . PHP_EOL;
     }
 }
Example #3
0
 private function _checkBackupDir()
 {
     if (!file_exists($this->location)) {
         return mkdir($this->location, 0775, true);
     }
     if (!is_dir($this->location)) {
         return mkdir($this->location . '_' . ranString(4, 2), 0775, true);
     }
     return true;
 }
Example #4
0
 /**
  * Installer::preInstall()
  * 
  * @return
  */
 public function preInstall()
 {
     // Get the details from post
     $mode = WebApp::post('method');
     // Check which mode we are operating in
     if ($mode == 'zip') {
         // Get the zip file
         $file = $this->parent->parent->files('zip_file');
         // Deal with upload errors
         switch ($file) {
             // Failed to upload (we couldn't find it)
             case _ACTION_FAIL_1:
                 $this->parent->parent->debug($this::name_space . ': Module package failed to upload.');
                 Session::set($this::name_space, 'msg', 'Module package failed to upload.');
                 $this->parent->parent->addHeader('Location', '/admin/modules/install/');
                 return new ActionResult($this, '/admin/modules/install', 0, 'Module package failed to upload.', B_T_FAIL);
                 break;
                 // No file was uploaded
             // No file was uploaded
             case _ACTION_FAIL_2:
                 $this->parent->parent->debug($this::name_space . ': No module package was uploaded to install!');
                 Session::set($this::name_space, 'msg', 'No module package was uploaded to install!');
                 $this->parent->parent->addHeader('Location', '/admin/modules/install/');
                 return new ActionResult($this, '/admin/modules/install', 0, 'No module package was uploaded to install!', B_T_FAIL);
                 break;
                 // Upload was too large
             // Upload was too large
             case _ACTION_FAIL_3:
                 $this->parent->parent->debug($this::name_space . ': Module was larger than the max upload size');
                 Session::set($this::name_space, 'msg', 'Module was larger than the max upload size!');
                 $this->parent->parent->addHeader('Location', '/admin/modules/install/');
                 return new ActionResult($this, '/admin/modules/install', 0, 'Module was larger than the max upload size!', B_T_FAIL);
                 break;
                 // File wasn't in whitelist/was in blacklist
             // File wasn't in whitelist/was in blacklist
             case _ACTION_FAIL_4:
                 $this->parent->parent->debug($this::name_space . ': Incorrect module format!');
                 Session::set($this::name_space, 'msg', 'Incorrect module format!');
                 $this->parent->parent->addHeader('Location', '/admin/modules/install/');
                 return new ActionResult($this, '/admin/modules/install', 0, 'Incorrect module format!', B_T_FAIL);
                 break;
                 // For some reason we couldn't move the uploaded file from the system temp dir to our temp dir
             // For some reason we couldn't move the uploaded file from the system temp dir to our temp dir
             case _ACTION_FAIL_5:
                 $this->parent->parent->debug($this::name_space . ': Could not access module package.');
                 Session::set($this::name_space, 'msg', 'Could not access module package!');
                 $this->parent->parent->addHeader('Location', '/admin/modules/install/');
                 return new ActionResult($this, '/admin/modules/install', 0, 'Could not access module package.', B_T_FAIL);
                 break;
                 // Something else went wrong with the uplaod - probably left for future php updates
             // Something else went wrong with the uplaod - probably left for future php updates
             case _ACTION_UNSPEC:
                 $this->parent->parent->debug($this::name_space . ': Something went wrong with the upload, try again');
                 Session::set($this::name_space, 'msg', 'Something went wrong with the upload, try again!');
                 $this->parent->parent->addHeader('Location', '/admin/modules/install/');
                 return new ActionResult($this, '/admin/modules/install', 0, 'Something went wrong with the upload, try again', B_T_FAIL);
                 break;
                 // There were no erros so we can continue
             // There were no erros so we can continue
             default:
                 // Extract the zip file
                 $file = $this->extractZip($file);
                 // Use the temp dir (from the extraction)
                 if ($file !== false) {
                     // Generate a reference hash
                     $hash = ranString(4);
                     // Set the session reference
                     Session::set($this::name_space, 'install_from' . $hash, $file);
                     //Navigate to the instal page
                     $this->parent->parent->addHeader('Location', '/admin/modules/install/' . $hash);
                     // We still need to return an ActionResult object to the controller, otherwise it'll get its knickers in a twist
                     return new ActionResult($this, '/admin/modules/install/' . $hash, 1, '', B_T_INFO);
                 } else {
                     // The uploaded file wasn't a zip, so give the user a message to see when they navigate
                     Session::set($this::name_space, 'msg', 'Failed to extract zip file!');
                     $this->parent->parent->addHeader('Location', '/admin/modules/install/');
                     // Yet again we need to return an ActionResult object as stated above ^^
                     return new ActionResult($this, '/admin/modules/install/', 0, 'Failed to extract zip file!', B_T_FAIL);
                 }
         }
         // We are installing from a directory, so we can skip the zip stuff and get straight to busines
     } elseif ($mode == 'dir') {
         // Get the full directory path
         $file = __EXECDIR__ . WebApp::post('directory');
         // Generate a reference hash
         $hash = ranString(4);
         // Set the install sesion stuff
         Session::set($this::name_space, 'install_from' . $hash, $file);
         // Navigate to the install page
         $this->parent->parent->addHeader('Location', '/admin/modules/install/' . $hash);
         // Yup, we are returning an ActionResult again... are you getting the message yet?
         return new ActionResult($this, '/admin/modules/install/' . $hash, 1, 'Installing module&hellip;', B_T_SUCCESS);
     }
 }
Example #5
0
 function add_Comp_events($MID, $events)
 {
     global $user;
     if ($user->accessPage(62)) {
         $query = $this->mySQL['r']->prepare("SELECT `ID` from `comp_meet` WHERE `ID`=?");
         $query->bind_param('s', $MID);
         $query->execute();
         $query->store_result();
         if ($query->num_rows == 1) {
             $this->mySQL['w']->autocommit(false);
             $update_m = $this->mySQL['w']->prepare("UPDATE `comp_meet` SET `events`=`events`+1,`wizStat`=5 WHERE `ID`=?");
             $update_s = $this->mySQL['w']->prepare("UPDATE `comp_session` SET `events`=`events`+1 WHERE `MID`=? AND `SID`=?");
             $insert = $this->mySQL['w']->prepare("INSERT INTO `comp_event` (`MID`,`SID`,`EID`,`number`,`num`,`prefix`,`e_g`,`e_d`,`e_s`,`e_r`,`e_al`,`e_au`) VALUES(?,?,?,?,?,0,?,?,?,?,?,?)");
             $ids = $this->mySQL['r']->prepare("SELECT `EID` FROM `comp_event` WHERE `EID`=?");
             if ($insert !== false && $ids !== false && $update_m !== false && $update_s !== false) {
                 $numRows = 0;
                 foreach ($events as $num => $event) {
                     $EID = ranString(6);
                     $ids->bind_param('s', $EID);
                     $ids->execute();
                     $ids->store_result();
                     while ($ids->num_rows != 0) {
                         $EID = ranString(6);
                         $ids->bind_param('s', $EID);
                         $ids->execute();
                         $ids->store_result();
                     }
                     $update_m->bind_param('s', $MID);
                     $update_m->execute();
                     $update_s->bind_param('ss', $MID, $event['n']['s']);
                     $update_s->execute();
                     $insert->bind_param('sssiissssii', $MID, $event['n']['s'], $EID, $num, $event['n']['e'], $event['g'], $event['d'], $event['s'], $event['r'], $event['a']['l'], $event['a']['u']);
                     $insert->execute();
                     $numRows = $numRows + $insert->affected_rows;
                 }
                 $select = $this->mySQL['r']->prepare("SELECT `events` FROM `comp_meet` WHERE `ID`=?");
                 $select->bind_param('s', $MID);
                 $select->execute();
                 $select->bind_result($comp_evts);
                 $select->store_result();
                 $select->fetch();
                 if ($numRows == $comp_evts && $comp_evts == count($events)) {
                     $this->mySQL['w']->commit();
                     $this->mySQL['w']->autocommit(true);
                     return array('res' => 0, 'id' => $MID);
                 } else {
                     $this->mySQL['w']->rollback();
                     $this->mySQL['w']->autocommit(true);
                     return 1;
                 }
             } else {
                 $this->mySQL['w']->autocommit(true);
                 return 2;
             }
         } else {
             return 3;
         }
     } else {
         return 4;
     }
 }
 /**
  * WebApp::mkTmpDir()
  * 
  * @return
  */
 public static function mkTmpDir()
 {
     $dirname = ranString(8);
     if (mkdir(__EXECDIR__ . '/temp/' . $dirname)) {
         if (is_dir(__EXECDIR__ . '/temp/' . $dirname)) {
             return __EXECDIR__ . '/temp/' . $dirname;
         }
     }
     return false;
 }
Example #7
0
 /**
  * Updater::preUpdate()
  * 
  * @return
  */
 public function preUpdate()
 {
     $conf = WebApp::post('conf');
     $module = WebApp::post('mod');
     $page = WebApp::post('page');
     $mode = WebApp::post('method');
     if ($conf != 1) {
         Session::set($this::name_space, 'msg', 'You haven\'t confirmed this action!');
         $this->parent->parent->addHeader('Location', '/admin/modules/update/' . $module);
         return new ActionResult($this, '/admin/modules/update/' . $module, 0, '', B_T_FAIL);
     }
     // Check which mode we are operating in
     if ($mode == 'zip') {
         // Get the ZIP file
         $file = $this->parent->parent->files('zip_file');
         // Deal with upload errors
         switch ($file) {
             // Failed to upload (we couldn't find it)
             case _ACTION_FAIL_1:
                 $this->parent->parent->debug($this::name_space . ': Module package failed to upload.');
                 Session::set($this::name_space, 'msg', 'Module package failed to upload.');
                 $this->parent->parent->addHeader('Location', '/admin/modules/update/' . $module);
                 return new ActionResult($this, '/admin/modules/update/' . $module, 0, 'Module package failed to upload.', B_T_FAIL);
                 break;
                 // No file was uploaded
             // No file was uploaded
             case _ACTION_FAIL_2:
                 $this->parent->parent->debug($this::name_space . ': No module package was uploaded to update!');
                 Session::set($this::name_space, 'msg', 'No module package was uploaded to update!');
                 $this->parent->parent->addHeader('Location', '/admin/modules/update/' . $module);
                 return new ActionResult($this, '/admin/modules/update/' . $module, 0, 'No module package was uploaded to update!', B_T_FAIL);
                 break;
                 // Uploade was too large
             // Uploade was too large
             case _ACTION_FAIL_3:
                 $this->parent->parent->debug($this::name_space . ': Module was larger than the max upload size');
                 Session::set($this::name_space, 'msg', 'Module was larger than the max upload size!');
                 $this->parent->parent->addHeader('Location', '/admin/modules/update/' . $module);
                 return new ActionResult($this, '/admin/modules/update/' . $module, 0, 'Module was larger than the max upload size!', B_T_FAIL);
                 break;
                 // File wasn't in whitelist/was in blacklist
             // File wasn't in whitelist/was in blacklist
             case _ACTION_FAIL_4:
                 $this->parent->parent->debug($this::name_space . ': Incorrect module format!');
                 $this->parent->parent->addHeader('Location', '/admin/modules/update/' . $module);
                 return new ActionResult($this, '/admin/modules/update/' . $module, 0, 'Incorrect module format!', B_T_FAIL);
                 break;
                 // For some reason we couldn't move the uploaded file from the system temp dir into our temp dir (__EXECDIR__/temp)
             // For some reason we couldn't move the uploaded file from the system temp dir into our temp dir (__EXECDIR__/temp)
             case _ACTION_FAIL_5:
                 $this->parent->parent->debug($this::name_space . ': Could not access module package.');
                 Session::set($this::name_space, 'msg', 'Could not access module package!');
                 $this->parent->parent->addHeader('Location', '/admin/modules/update/' . $module);
                 return new ActionResult($this, '/admin/modules/update/' . $module, 0, 'Could not access module package.', B_T_FAIL);
                 break;
                 // Something else went wrong with the upload - probably left for future php updates
             // Something else went wrong with the upload - probably left for future php updates
             case _ACTION_UNSPEC:
                 $this->parent->parent->debug($this::name_space . ': Something went wrong with the upload, try again');
                 Session::set($this::name_space, 'msg', 'Something went wrong with the upload, try again!');
                 $this->parent->parent->addHeader('Location', '/admin/modules/update/' . $module);
                 return new ActionResult($this, '/admin/modules/update/' . $module, 0, 'Something went wrong with the upload, try again', B_T_FAIL);
                 break;
                 // There were no errors so we can continue
             // There were no errors so we can continue
             default:
                 // Extract the zip file
                 $file = $this->extractZip($file);
                 // Use the temp dir (from the extraction)
                 if ($file === false) {
                     // The uploaded wasn't a zip, so give the user a message to say so
                     Session::set($this::name_space, 'msg', 'Failed to extract zip file!');
                     // Now we send them back to the update page so they can select the correct file (hopefully)
                     $this->parent->parent->addHeader('Location', '/admin/modules/update/' . $module);
                     return new ActionResult($this, '/admin/modules/update/' . $module, 0, 'Failed to extract zip file!', B_T_FAIL);
                 }
                 // Create a random reference hash
                 $hash = ranString(4);
                 // Set the session variables
                 Session::set($this::name_space, 'update_from_' . $hash . '_dir', $file);
                 Session::set($this::name_space, 'update_from_' . $hash . '_ns', $module);
                 Session::set($this::name_space, 'update_from_' . $hash . '_page', $page);
                 // Navigate to the new page
                 $this->parent->parent->addHeader('Location', '/admin/modules/update/' . $module . '/' . $hash);
                 // We still need to return what we are doing to the controller (don't remove... took ages to work out why it crashed here!)
                 return new ActionResult($this, '/admin/modules/update/' . $module . '/' . $hash, 1, '', B_T_SUCCESS);
         }
         // We are updating from a directory so we can bypass the zip extraction bits and bobs
     } elseif ($mode == 'dir') {
         // Get the full directory path
         $file = __EXECDIR__ . WebApp::post('directory');
         // Create a random reference hash
         $hash = ranString(4);
         // Set the session variables
         Session::set($this::name_space, 'update_from_' . $hash . '_dir', $file);
         Session::set($this::name_space, 'update_from_' . $hash . '_ns', $module);
         Session::set($this::name_space, 'update_from_' . $hash . '_page', $page);
         // Navigate to the new page
         $this->parent->parent->addHeader('Location', '/admin/modules/update/' . $module . '/' . $hash);
         // We still need to return what we are doing to the controller [don't remove... yup, same mistake twice :-)]
         return new ActionResult($this, '/admin/modules/update/' . $module . '/' . $hash, 1, '', B_T_SUCCESS);
     }
 }