public function init() { parent::init(); AuthController::getInstance()->requireLogin(); ErrorHandler::getInstance()->getUrlErrorMessage(); $this->setSmarty(); }
function sendEmail($recipient, $content, $subject = 'Notification', $includeStandardFooter = true) { $subject = 'lanlist.org - ' . $subject; if (empty($content)) { throw new Exception('Cannot send a blank email'); } $content = wordwrap($content); if ($includeStandardFooter) { $content .= "\n\n- lanlist.org"; } ErrorHandler::getInstance()->beLazy(); require_once 'Mail.php'; require_once 'Mail/smtp.php'; $host = 'ssl://smtp.gmail.com'; $username = '******'; $password = '******'; $smtp = new Mail_smtp(array('host' => $host, 'port' => 465, 'auth' => true, 'username' => $username, 'password' => $password)); $headers = array('From' => '"lanlist.org" <*****@*****.**>', 'To' => '<' . $recipient . '>', 'Subject' => $subject, 'Content-Type' => 'text/html'); $smtp->send('<' . $recipient . '>', $headers, $content); ErrorHandler::getInstance()->beGreedy(); Logger::messageDebug('Sending email to ' . $recipient . ', subject: ' . $subject); $sql = 'INSERT INTO email_log (subject, emailAddress, sent) VALUES (:subject, :emailAddress, now())'; $stmt = DatabaseFactory::getInstance()->prepare($sql); $stmt->bindValue(':emailAddress', $recipient); $stmt->bindValue(':subject', $subject); $stmt->execute(); }
/** * Verifies a recaptcha * * @param $priv_key private recaptcha key * @return true on success */ public function verify() { $error = ErrorHandler::getInstance(); $conf = RecaptchaConfig::getInstance(); if (empty($_POST['recaptcha_challenge_field']) || empty($_POST['recaptcha_response_field'])) { $error->add('No captcha answer given.'); return false; } if (!$conf->getPublicKey() || !$conf->getPrivateKey()) { die('ERROR - Get Recaptcha API key at http://recaptcha.net/api/getkey'); } $params = array('privatekey' => $conf->getPrivateKey(), 'remoteip' => client_ip(), 'challenge' => $_POST['recaptcha_challenge_field'], 'response' => $_POST['recaptcha_response_field']); $http = new HttpClient($this->api_url_verify); $res = $http->post($params); $answers = explode("\n", $res); if (trim($answers[0]) == 'true') { return true; } switch ($answers[1]) { case 'incorrect-captcha-sol': $e = 'Incorrect captcha solution'; break; default: $e = 'untranslated error: ' . $answers[1]; } $error->add($e); return false; }
/** * Looks up user supplied email address / alias and sends a mail * * @param $email email address or username */ function sendMail($in) { $in = trim($in); if (is_email($in)) { $user_id = UserFinder::byEmail($in); } else { $user_id = UserFinder::byUsername($in); } $error = ErrorHandler::getInstance(); if (!$user_id) { $error->add('Invalid email address or username'); return false; } $email = UserSetting::getEmail($user_id); if (!$email) { throw new \Exception('entered email not found'); } $code = Token::generate($user_id, 'activation_code'); $pattern = array('/@USERNAME@/', '/@IP@/', '/@URL@/', '/@EXPIRETIME@/'); $user = User::get($user_id); $page = XmlDocumentHandler::getInstance(); $url = $page->getUrl() . 'u/reset_pwd/' . $code; $replacement = array($user->getName(), client_ip(), $url, shortTimePeriod($this->expire_time_email)); $msg = preg_replace($pattern, $replacement, $this->password_msg); //d($msg); $mail = SendMail::getInstance(); $mail->addRecipient($email); $mail->setSubject('Forgot password'); $mail->send($msg); return true; }
function onSubmit($p) { $error = ErrorHandler::getInstance(); $res = base64_decode($p['data'], true); if ($res === false) { $error->add('Input is not base64 encoded'); return false; } echo dh($res); }
function uploadSubmit($p) { if (!is_url($p['url'])) { $error = ErrorHandler::getInstance(); $error->add('Not an url'); return false; } $eventId = TaskQueue::addTask(TASK_FETCH, $p['url']); echo '<div class="okay">URL to process has been enqueued.</div><br/>'; echo ahref('queue/show/' . $eventId, 'Click here') . ' to perform further actions on this file.'; }
function register($username, $pwd1, $pwd2) { $error = ErrorHandler::getInstance(); $username = trim($username); $pwd1 = trim($pwd1); if (strlen($username) < $this->username_minlen) { $error->add('Username must be at least ' . $this->username_minlen . ' characters long'); return false; } if (strlen($username) > $this->username_maxlen) { $error->add('Username cant be longer than ' . $this->username_maxlen . ' characters long'); return false; } if (strlen($pwd1) < $this->password_minlen) { $error->add('Password must be at least ' . $this->password_minlen . ' characters long'); return false; } if ($pwd1 != $pwd2) { $error->add('Passwords dont match'); return false; } if ($username == $pwd1) { $error->add('Username and password must be different'); return false; } if (User::getByName($username)) { $error->add('Username taken'); return false; } if (ReservedWord::isReservedUsername($username)) { $error->add('Username is reserved'); return false; } if (Password::isForbidden($pwd1)) { $error->add('Your password is a very weak one and is forbidden to use'); return false; } $user_id = self::create($username, $pwd1); if (!$user_id) { $error->add('Failed to create user'); return false; } if ($this->post_reg_callback) { call_user_func($this->post_reg_callback, $user_id); } return $user_id; }
/** * Initialize the application */ public function init() { // Load the application configuration $this->singleton('conf', Conf::getInstance()); // Load the application error Handler $this->singleton('errorHandler', ErrorHandler::getInstance()); // Load the application logger $this->singleton('logger', Logger::getInstance()); // Load the filesystem library $this->singleton('fs', FileSystem::getInstance()); // Load the application session $this->singleton('session', Session::getInstance()); // Load the application router $this->singleton('router', Router::getInstance()); // Load the application HTTP request $this->singleton('request', Request::getInstance()); // Load the application HTTP response $this->singleton('response', Response::getInstance()); // Load the application cache $this->singleton('cache', Cache::getInstance()); }
function handleSubmit($p) { $session = SessionHandler::getInstance(); $error = ErrorHandler::getInstance(); if (empty($p['comment'])) { return false; } if (!$session->id) { $error->add('Unauthorized submit'); return false; } $c = new Comment(); $c->type = $p['type']; $c->msg = $p['comment']; $c->private = 0; $c->time_created = sql_datetime(time()); $c->owner = $p['owner']; $c->creator = $session->id; $c->creator_ip = client_ip(); $c->store(); redir($_SERVER['REQUEST_URI']); }
public function render() { //available variables in the scope of the view if (class_exists('\\cd\\ErrorHandler')) { $error = ErrorHandler::getInstance(); } if (class_exists('\\cd\\SessionHandler')) { $session = SessionHandler::getInstance(); } if (class_exists('\\cd\\SqlHandler')) { $db = SqlHandler::getInstance(); } if (class_exists('\\cd\\XhtmlHeader')) { $header = XhtmlHeader::getInstance(); } if (class_exists('\\cd\\XmlDocumentHandler')) { $page = XmlDocumentHandler::getInstance(); } if (class_exists('\\cd\\LocaleHandler')) { $locale = LocaleHandler::getInstance(); } if (class_exists('\\cd\\TempStore')) { $temp = TempStore::getInstance(); } // make reference to calling object available in the namespace of the view $caller = $this->caller; $file = $page->getCoreDevPath() . $this->template; if (!file_exists($file)) { // if not built in view, look in app dir $file = $this->template; if (!file_exists($file)) { throw new \Exception('cannot find ' . $this->template); } } ob_start(); require $file; return ob_get_clean(); }
/** * Retrieve main settings for application * @return array */ public function loadSettings() { $cache = Cacher::getInstance(); if (($settings = $cache->load("settings")) === null) { $settings = array(); foreach ($this->setting->findAll(new Criteria(), "`key`, `value`") as $row) { $settings[$row['key']] = $row['value']; } $cache->save($settings, null, null, array("setting")); } foreach ($settings as $key => $value) { Config::set($key, $value); } $rawUrl = parse_url(Config::get("siteRootUrl")); Config::set("siteDomainUrl", "http://" . $rawUrl['host']); $errorHandler = ErrorHandler::getInstance(); if (!Config::get('errorHandlerSaveToFileEnabled')) { $errorHandler->setOption('saveToFile', false); } if (!Config::get('errorHandlerDisplayErrorEnabled')) { $errorHandler->setOption('displayError', false); } }
/** * Added informations for debug purposes only. In case the error it will showed and the result a node called "debug" will be added. * * @param string $key * @param mixed $string */ public function writeDebug($key, $string) { if (is_null($this->responseDebug)) { $this->responseDebug = new ResponseBag(); $this->response->add($this->responseDebug); } $this->responseDebug->add(['debug' => [$key => $string]]); ErrorHandler::getInstance()->addExtraInfo($key, serialize($string)); }
<?php /** * Arfooo * * @package Arfooo * @copyright Copyright (c) Arfooo Annuaire (fr) and Arfooo Directory (en) * by Guillaume Hocine (c) 2007 - 2010 * http://www.arfooo.com/ (fr) and http://www.arfooo.net/ (en) * @author Guillaume Hocine & Adrian Galewski * @license http://creativecommons.org/licenses/by/2.0/fr/ Creative Commons */ $scriptStartTime = microtime(true); ini_set("display_errors", "on"); ini_set("url_rewriter.tags", ""); error_reporting(E_ALL); require_once CODE_ROOT_DIR . "config/main.php"; require_once Config::get('CORE_PATH') . "Core.php"; ErrorHandler::getInstance();
/** * Helper function that imports a image file and shrinks it to max allowed dimensions */ public static function importImage($type, &$key, $category = 0, $blind = false, $max_width = 800, $max_height = 800) { $error = ErrorHandler::getInstance(); if (!file_exists($key['tmp_name'])) { throw new \Exception('file ' . $key['tmp_name'] . ' dont exist!'); } $info = getimagesize($key['tmp_name']); switch ($info['mime']) { case 'image/jpeg': break; case 'image/png': break; case 'image/gif': break; default: $error->add('Uploaded file ' . $key['name'] . ' is not an image (mimetype ' . $info['mime'] . ')'); return false; } $fileId = self::import($type, $key, $category, $blind); if (!$fileId) { return false; } $im = new ImageResizer(File::get($fileId)); if ($im->width >= $max_width || $im->height >= $max_height) { $im->resizeAspect($max_width, $max_height); $im->render($im->mimetype, self::getUploadPath($fileId)); self::sync($fileId); //updates tblFiles.size } return $fileId; }
/** * return the user interface error or succes messages */ public function get_hint_messages() { $error_hints = ErrorHandler::getInstance(); $error_hints->show_hint_messages(); }
/** Renders the form in XHTML */ function render() { // if (!function_exists($this->post_handler) && !$this->js_onsubmit) // throw new \Exception ('FATAL: XhtmlForm no post handler or js handler set'); if (!$this->name) { throw new \Exception('need a form name'); } if (!$this->handled) { $this->handle(); } $res = ''; $error = ErrorHandler::getInstance(); if ($error->getErrorCount()) { $res .= $error->render(true); } $header = XhtmlHeader::getInstance(); if ($this->focus_element) { $header->embedJsOnload('document.' . $this->name . '.' . $this->focus_element . '.focus();'); } $res .= '<form' . ' action="' . $this->url_handler . '"' . ' method="post"' . ' name="' . $this->name . '"' . (!$this->autocomplete ? ' autocomplete="off"' : '') . ($this->id ? ' id="' . $this->id . '"' : '') . ($this->title ? ' title="' . $this->title . '"' : '') . ($this->file_upload ? ' enctype="multipart/form-data"' : '') . ($this->js_onsubmit ? ' onsubmit="' . $this->js_onsubmit . '"' : '') . '>' . '<table' . ' style="padding: 6px;' . $this->css_table . '"' . '>'; $hidden = ''; // fills in form with previous entered data XXXXX merge some code with handle() foreach ($this->elems as $e) { if (!isset($e['obj'])) { throw new \Exception('ehjohohohoh: ' . $e['obj']); } if (!$e['obj'] instanceof XhtmlComponent) { throw new \Exception('obj not a XhtmlComponent'); } if ($e['obj2'] && !$e['obj2'] instanceof XhtmlComponent) { throw new \Exception('obj2 not a XhtmlComponent'); } if (isset($e['obj']->value)) { $e['obj']->value = htmlspecialchars($e['obj']->value); } if ($e['obj'] instanceof XhtmlComponentHidden) { $hidden .= $e['obj']->render(); continue; } if ($e['obj'] instanceof XhtmlComponentCheckbox) { if (isset($this->form_data[$e['obj']->name])) { $e['obj']->checked = $this->form_data[$e['obj']->name]; } else { if (!empty($this->form_data[$e['obj']->name]) && property_exists($e['obj'], 'value')) { $e['obj']->value = $this->form_data[$e['obj']->name]; } } } $res .= '<tr>' . ($e['str'] ? '<td>' . $e['str'] . '</td><td>' : '<td colspan="2">') . $e['obj']->render() . ($e['obj2'] instanceof XhtmlComponent ? $e['obj2']->render() : '') . '</td>' . '</tr>'; } $res .= '</table>' . $hidden . '</form>'; return $res; }
function handleEditPassword($p) { $error = ErrorHandler::getInstance(); $session = SessionHandler::getInstance(); $u = User::getExact($session->type, $session->id, $session->username, $p['curr_pwd']); if (!$u) { $error->add('Current password is not correct'); return false; } if ($p['new_pwd'] != $p['new_pwd2']) { $error->add('passwords dont match'); return false; } if (!$p['new_pwd']) { $error->add('no password entered'); return false; } UserHandler::setPassword($session->id, $p['new_pwd']); js_redirect('u/edit'); }
/** * Locks out everyone except for super-admin from certain pages */ function requireSuperAdmin() { if ($this->isSuperAdmin) { return; } $error = ErrorHandler::getInstance(); $error->add('The page you requested requires superadmin rights to view.'); $this->showErrorPage(); }
public function __errorHandler($iErrorNumber, $sErrorMessage, $sErrorFile, $iErrorLine) { $oHandler = ErrorHandler::getInstance(); $bDie = false; $sText = ""; switch ($iErrorNumber) { case E_ERROR: $sText .= 'Error'; $bDie = true; break; case E_WARNING: $sText .= 'Warning'; break; case E_PARSE: $sText .= 'Parsing Error'; break; case E_NOTICE: $sText .= 'Notice'; break; case E_CORE_ERROR: $sText .= 'Core Error'; $bDie = true; break; case E_CORE_WARNING: $sText .= 'Core Warning'; break; case E_COMPILE_ERROR: $sText .= 'Compile Error'; $bDie = true; break; case E_COMPILE_WARNING: $sText .= 'Compile Warning'; break; case E_USER_ERROR: $sText .= 'User Error'; $bDie = true; break; case E_USER_WARNING: $sText .= 'User Warning'; break; case E_USER_NOTICE: $sText .= 'User Notice'; break; case E_STRICT: $sText .= 'Strict Standards'; break; case E_RECOVERABLE_ERROR: $sText .= 'Catchable Fatal Error'; $bDie = true; break; default: $sText .= 'Unkown Error'; } $sText .= ': ' . $sErrorMessage . ' in file "' . $sErrorFile . '" on line ' . $iErrorLine . "\n"; $aDebugInfo = debug_backtrace(); for ($i = count($aDebugInfo) - 1; $i > 0; $i--) { $aDebugRecord = $aDebugInfo[$i]; if (!empty($aDebugRecord['file'])) { $sText .= "\tCalled from "; $sText .= $aDebugRecord['file'] . ' [line ' . $aDebugRecord['line'] . '] '; $sText .= '(' . (!empty($aDebugRecord['class']) ? $aDebugRecord['class'] . $aDebugRecord['type'] : ''); $sText .= !empty($aDebugRecord['function']) ? $aDebugRecord['function'] : ''; $sText .= ")\n"; } } Daemon::log(trim($sText), Daemon::PHP_MESSAGE); if ($bDie) { Daemon::removePIDFile(); // see Daemon::destructor die; } return true; }
/** * Creates a instance of requested controller and invokes requested method on that controller */ public function route() { $page = XmlDocumentHandler::getInstance(); $error = ErrorHandler::getInstance(); // automatically resumes session unless it is blacklisted if (class_exists('\\cd\\SessionHandler') && !in_array($this->_controller, $this->exclude_session)) { $session = SessionHandler::getInstance(); if ($session->getName()) { $session->start(); } } switch ($this->_controller) { case 'a': $file = $page->getCoreDevPath() . 'views/admin/' . $this->_view . '.php'; break; case 'u': $file = $page->getCoreDevPath() . 'views/user/' . $this->_view . '.php'; break; case 'c': $file = $page->getCoreDevPath() . 'views/core/' . $this->_view . '.php'; break; case 't': $file = $page->getCoreDevPath() . 'views/tools/' . $this->_view . '.php'; break; default: $file = 'views/' . $this->_controller . '.php'; } if (!file_exists($file)) { $file = 'views/error/404.php'; } // expose request params for the view $view = new ViewModel($file); // XXX BUG: naming should be set correctly according to the hierarchy of the url, in reverse, // like: views/user/upload.php takes album/id parameters // so then in upload.php, "album" should be in the view param, and id in the owner param // -- now "album" is in owner, and "id" in child $view->view = $this->_view; $view->owner = $this->_owner; $view->child = $this->_child; $view->child2 = $this->_child2; $view->child3 = $this->_child3; $page->attach($view); // this must be done last, so that errors that was created during the view render can be displayed if ($error->getErrorCount()) { $page->attach($error); } }
<?php include_once 'class.ErrorHandler.php'; $errorObj = ErrorHandler::getInstance(); $errorObj->enableHandler();