Esempio n. 1
0
 public static function build($data, $allowCallbacks = true)
 {
     //  Check it's being called with AJAX
     //  But only if we tell it to
     if (!self::validOrigin()) {
         Error::log('Invalid origin');
         exit;
     }
     //  I do love a bit of json
     Response::set(200);
     //  Store our encoded data as a variable
     $json = json_encode($data);
     //  Just make sure
     if (!$json) {
         return;
     }
     //  Do we allow ?callback=test parameters?
     if ($allowCallbacks === true) {
         $callback = preg_replace('/[^0-9a-z\\-_\\d]/i', '', Input::get('callback'));
         if ($callback) {
             $json = $callback . '(' . $json . ');';
         }
     }
     //  Give 'em what they wanted
     return $json;
 }
Esempio n. 2
0
 /**
  * @return \SimpleXMLElement
  *
  * Handle the retrieval of the XML data
  */
 public function getXMLFromCache()
 {
     try {
         //Check cache file exists
         if (is_dir(ROOT . '/cache')) {
             $this->localXMLpath = ROOT . '/cache/' . $this->stateAbbrev . '.xml';
             //Check if the local file exists and when last modified
             if (is_file($this->localXMLpath)) {
                 $stats = stat($this->localXMLpath);
                 $timeLastAccessed = $stats[8] + TIMER;
                 //60 sec * 30 = 30 Mins = 1800 sec
                 if (time() > $timeLastAccessed) {
                     //Compare the modified file times and download if needed
                     $this->compareTimestamps();
                 }
             } else {
                 //File does not exist, download file
                 $this->downloadFile();
             }
             //Return true the file is up to date
             return @simplexml_load_file($this->localXMLpath);
         } else {
             Error::log('Cache folder does not exist at /src/cache.');
             throw new \Exception('Cache folder does not exist at /src/cache.');
         }
     } catch (\Exception $e) {
         echo 'Exception thrown! ', $e->getMessage(), "\n";
     }
 }
Esempio n. 3
0
function log($s)
{
    static $error;
    if (is_null($error)) {
        $error = new Error();
    }
    $error->log($s);
}
Esempio n. 4
0
 public function __construct()
 {
     $object = Storage::get('db', false);
     //  Sanity check
     if ($object === false) {
         return Error::log('Could not get Database class');
     }
     $this->db = $this->database = $object;
 }
Esempio n. 5
0
 /**
  * Stamps the current datestamp and ip_address.
  */
 public static function stampResource(\Resource $resource, $action)
 {
     $activity = new Activity();
     $activity->class_name = $resource->getNamespace();
     $activity->resource_id = $resource->getId();
     $activity->action = $action;
     if (\User\Current::isLoggedIn()) {
         $activity->user_id = \User\Current::getUserId();
     }
     try {
         $activity->ip_address = \Server::getUserIp();
     } catch (Exception $e) {
         $activity->ip_address = '0.0.0.0';
         \Error::log($e);
     }
     \ResourceFactory::saveResource($activity);
 }
Esempio n. 6
0
 public function Run()
 {
     //        set_exception_handler(array($this, "_exceptionHendler"));
     $this->_startTime = microtime(true);
     Log::setDebug();
     // init Session
     if (Settings::$sessionAutostart) {
         self::$_oSession = new Settings::$sessionType();
     }
     // init DB
     if (Settings::$dbEnable) {
         self::$_oDb = new Settings::$dbDriver();
     }
     // init cache
     if (Settings::$cacheEnable) {
         self::$_oCache = new Settings::$cacheDriver();
     }
     $this->startSystemLog();
     Error::log();
     $this->oView = new View();
     $this->oRouter = new Router();
     $this->run = true;
 }
Esempio n. 7
0
/**
 * Helpers
 */
require APP . 'helpers' . EXT;
/**
 * Anchor setup
 */
try {
    Anchor::setup();
} catch (Exception $e) {
    if (ini_get('display_errors') != "1") {
        echo "<h1>Something went wrong, please notify the owner of the site</h1>";
    } else {
        Error::exception($e);
    }
    Error::log($e);
    die;
}
/**
 * Import defined routes
 */
if (is_admin()) {
    // Set posts per page for admin
    Config::set('admin.posts_per_page', 6);
    require APP . 'routes/admin' . EXT;
    require APP . 'routes/categories' . EXT;
    require APP . 'routes/comments' . EXT;
    require APP . 'routes/fields' . EXT;
    require APP . 'routes/menu' . EXT;
    require APP . 'routes/metadata' . EXT;
    require APP . 'routes/pages' . EXT;
Esempio n. 8
0
 /**
  * Updated: 19 Feb 2010
  * Boost used to allow pausing for entering information. This was removed.
  * @param $inBoost
  * @param $inBranch
  * @param $home_dir
  * @return unknown_type
  */
 public function install($inBoost = true, $inBranch = false, $home_dir = NULL)
 {
     $content = array();
     $dir_content = array();
     if ($inBranch && !empty($home_dir)) {
         $GLOBALS['boost_branch_dir'] = $home_dir;
     }
     if (!$this->checkDirectories($dir_content, null, false)) {
         return implode('<br />', $dir_content);
     }
     if (!$this->isModules()) {
         return PHPWS_Error::get(BOOST_NO_MODULES_SET, 'boost', 'install');
     }
     $last_mod = end($this->modules);
     foreach ($this->modules as $title => $mod) {
         $title = trim($title);
         if ($this->getStatus($title) == BOOST_DONE) {
             continue;
         }
         if ($this->getCurrent() != $title && $this->getStatus($title) == BOOST_NEW) {
             $this->setCurrent($title);
             $this->setStatus($title, BOOST_START);
         }
         $content[] = dgettext('boost', 'Installing') . ' - ' . $mod->getProperName();
         if ($this->getStatus($title) == BOOST_START && $mod->isImportSQL()) {
             $content[] = dgettext('boost', 'Importing SQL install file.');
             $db = new PHPWS_DB();
             $result = $db->importFile($mod->getDirectory() . 'boost/install.sql');
             if (PHPWS_Error::isError($result)) {
                 PHPWS_Error::log($result);
                 $this->addLog($title, dgettext('boost', 'Database import failed.'));
                 $content[] = dgettext('boost', 'An import error occurred.');
                 $content[] = dgettext('boost', 'Check your logs for more information.');
                 return implode('<br />', $content) . '<br />' . implode('<br />', $content);
             } else {
                 $content[] = dgettext('boost', 'Import successful.');
             }
         }
         try {
             $result = $this->onInstall($mod, $content);
             if ($result === true) {
                 $this->setStatus($title, BOOST_DONE);
                 $this->createDirectories($mod, $content, $home_dir);
                 $this->registerModule($mod, $content);
                 $continue = true;
             } elseif ($result === -1) {
                 // No installation file (install.php) was found.
                 $this->setStatus($title, BOOST_DONE);
                 $this->createDirectories($mod, $content, $home_dir);
                 $this->registerModule($mod, $content);
                 $continue = true;
             } elseif (PHPWS_Error::isError($result)) {
                 $content[] = dgettext('boost', 'There was a problem in the installation file:');
                 $content[] = '<b>' . $result->getMessage() . '</b>';
                 $content[] = '<br />';
                 PHPWS_Error::log($result);
                 $continue = false;
             }
         } catch (\Exception $e) {
             $content[] = implode('<br />', $content);
             $content[] = dgettext('boost', 'There was a problem in the installation file:');
             $content[] = '<b>' . $e->getMessage() . '</b>';
             $content[] = '<br />';
             \Error::log($e);
             $continue = false;
         }
         // in case install changes translate directory
     }
     if ($last_mod->title == $title) {
         // H0120
         $content[] = dgettext('boost', 'Installation complete!');
         $this->addLog($title, str_replace("\n\n\n", "\n", implode("\n", str_replace('<br />', "\n", $content))));
     }
     return implode('<br />', $content);
 }
Esempio n. 9
0
	/**
	 * Replaces Kohana's `Kohana::exception_handler()` method. This does the
	 * same thing, but also adds email functionality and the ability to perform
	 * an action in response to the exception. These actions and emails are
	 * customizable per type in the config file for this module.
	 *
	 * @uses		Kohana::exception_text
	 * @param \Exception $e
	 * @internal param \exception $object object
	 * @return	boolean
	 */
	public static function handler(Exception $e)
	{
		try
		{
			$error = new Error();

			// Get the exception information
			$error->exception = $e;
			$error->type = get_class($e);
			$error->code = $e->getCode();
			$error->message = $e->getMessage();
			$error->file = $e->getFile();
			$error->line = $e->getLine();
			$error->request_initial = Request::initial();

			// Create a text version of the exception
			$error->text = Kohana_Exception::text($e);

			if (Kohana::$is_cli)
			{
				// Display the text of the exception
				echo "\n{$error->text}\n";
			}

			// Get the exception backtrace
			$error->trace = $e->getTrace();

			if ($e instanceof ErrorException)
			{
				if (version_compare(PHP_VERSION, '5.3', '<'))
				{
					// Workaround for a bug in ErrorException::getTrace() that exists in
					// all PHP 5.2 versions. @see http://bugs.php.net/bug.php?id=45895
					for ($i = count($error->trace) - 1;$i > 0;--$i)
					{
						if (isset($error->trace[$i - 1]['args']))
						{
							// Re-position the args
							$error->trace[$i]['args'] = $error->trace[$i - 1]['args'];

							// Remove the args
							unset($error->trace[$i - 1]['args']);
						}
					}
				}
			}

			if (!headers_sent() and (Kohana::$is_cli === false))
			{
				// Make sure the proper content type is sent with a 500 status
				header('Content-Type: text/html; charset=' . Kohana::$charset, true, 500);
			}

			// Get the contents of the output buffer
			$error->display = $error->render();

			// Log the error
			$error->log();

			// Email the error
			$error->email();

			// Respond to the error
			$error->action();

			return true;
		}
		catch (Exception $e)
		{
			// Log an error.
			if (is_object(Kohana::$log))
			{
				// Create a text version of the exception
				$error = Kohana_Exception::text($e);

				// Add this exception to the log
				Kohana::$log->add(Log::ERROR, $error);

				// Make sure the logs are written
				Kohana::$log->write();
			}

			// Clean the output buffer if one exists
			ob_get_level() and ob_clean();

			// Display the exception text
			header('HTTP/1.1 500 Internal Server Error');
			echo "Unknown Error - Exception thrown in Error::handler()";

			// Exit with an error status
			exit(1);
		}
	}
Esempio n. 10
0
 /**
  * 登录操作
  */
 public function act_login()
 {
     $username = isset($_POST['username']) ? hy_check($_POST['username'], 'un', 15) : '';
     $password = isset($_POST['password']) ? hy_check($_POST['password'], '', 20) : '';
     $captcha = isset($_POST['captcha']) ? $_POST['captcha'] : '';
     $check_vali = $this->validator($captcha);
     if (!$check_vali || $captcha == '') {
         $this->showMsg('验证码错误', 'index.php?g=admin&m=index&a=login');
     }
     if ($username == '#@_error' || $password == '#@_error') {
         Error::log('[后台登录错误]' . $_POST['username'] . '--' . hy_getIP(), ADMIN_LOG);
         $this->showMsg(Lang('账号或者密码错误'), '/qq_admin.php');
     }
     if (Model('index')->check_user($username, $password)) {
         header("Location:index.php?g=admin&m=index&a=index");
     } else {
         Error::log('[后台登录错误]' . $_POST['username'] . '--' . hy_getIP(), ADMIN_LOG);
         $this->showMsg(Lang('账号或者密码错误'), 'index.php?g=admin&m=index&a=login');
     }
 }
Esempio n. 11
0
 public function setPath($path)
 {
     if (file_exists($path)) {
         return self::$templatepath = $path;
     }
     Error::log('Path ' . $path . ' not found');
 }
Esempio n. 12
0
 /**
  * Set the $defaultSuburb
  *********************************************************************/
 public function setDefaultSuburb($stateAbbrev)
 {
     $stateAbbrev = strtolower($stateAbbrev);
     switch ($stateAbbrev) {
         case 'vic':
             return 'Melbourne';
         case 'nsw':
             return 'Sydney';
         case 'qld':
             return 'Brisbane';
         case 'sa':
             return 'Adelaide';
         case 'wa':
             return 'Perth';
         case 'tas':
             return 'Tasmania';
         case 'nt':
             return 'Darwin';
         case 'act':
             return 'Canberra';
         default:
             Error::log('No default match for state, please use vic, nsw, etc');
             return false;
     }
 }
Esempio n. 13
0
    private function submitManagerApplication()
    {
        $request = \Server::getCurrentRequest();
        $vars = $request->getVars();
        $username = $request->getVar('managerUsername');
        $password = $request->getVar('managerPassword');
        $first_name = $request->getVar('contactFirstName');
        $last_name = $request->getVar('contactLastName');
        $email = $request->getVar('emailAddress');
        $phone = $request->getVar('phoneNumber');
        $hours = $request->getVar('contactHours');
        $company_name = $request->getVar('companyName');
        $company_url = $request->getVar('companyUrl');
        $company_address = $request->getVar('companyAddress');
        $private = $request->getVar('managerType');
        $contact = new Contact();
        try {
            $contact->setUsername($username);
            $contact->setPassword($password);
            $contact->setFirstName($first_name);
            $contact->setLastName($last_name);
            $contact->setEmailAddress($email);
            $contact->setPhone($phone);
            $contact->setTimesAvailable($hours);
            if ($private == 'false') {
                $contact->setPrivate(false);
                if (empty($company_name)) {
                    throw \Exception('Missing company name');
                } else {
                    $contact->setCompanyName($company_name);
                }
                if (empty($company_address)) {
                    throw \Exception('Missing company address');
                } else {
                    $contact->setCompanyAddress($company_address);
                }
                $contact->setCompanyUrl($company_url);
            } else {
                $contact->setPrivate(true);
                $contact->setCompanyName('Private Renter');
            }
            $contact->setApproved(false);
            $contact->save();
            $this->emailApprovalNeeded();
        } catch (\Exception $ex) {
            $address = \PHPWS_Settings::get('properties', 'email');
            \Error::log($ex);
            $this->title = 'Sorry!';
            $this->content = <<<EOF
<p>Your manager submission could not be processed. Please email <a href="mailto:{$address}">{$address}</a> to inform them of your problem.</p>
EOF;
            $this->content .= $ex->getMessage();
            return;
        }
        // success
        $this->title = 'Thank you';
        $this->content = <<<EOF
<p>We will review your manager application and email your confirmation.</p>
                <p><a href="./">Return to the home page</a></p>
EOF;
    }