Ejemplo n.º 1
0
 /**
  * Get HTML template for email
  * NOTE: Email needs to be set in config/config.ini when using CLI
  * @param string $path path to template
  * @return string $html
  */
 public function getHtmlTemplate($path = null)
 {
     // Default path
     if (!$path) {
         $template = conf::getMainIni('template');
         $path = conf::getTemplatePath($template) . '/mail/template.html';
     }
     if (!file_exists($path)) {
         log::error('mailer/markdown: path does not exists: ' . $path);
         die;
     }
     $email = file_get_contents($path);
     return $email;
 }
Ejemplo n.º 2
0
    public static function init()
    {
        $m = new modules();
        $m->autoloadRegister();
        // Define all system constants
        conf::defineCommon();
        // Set include path - based on config.ini
        conf::setIncludePath();
        // Load config file
        conf::load();
        // Set log level - based on config.ini
        log::setErrorLog();
        log::setLogLevel();
        // Set locales
        intl::setLocale();
        // Set default timezone
        intl::setTimezone();
        // Load language
        $l = new lang();
        $base = conf::pathBase();
        $l->setDirsInsideDir("{$base}/modules/");
        $l->setDirsInsideDir("{$base}/htdocs/templates/");
        $l->setSingleDir("{$base}/vendor/diversen/simple-php-classes");
        $l->loadLanguage(conf::getMainIni('lang'));
        // Init parent with base commands
        parent::init();
        self::$parser->description = <<<EOF
                    _ _       _     
  ___ ___  ___  ___| (_)  ___| |__  
 / __/ _ \\/ __|/ __| | | / __| '_ \\ 
| (_| (_) \\__ \\ (__| | |_\\__ \\ | | |
 \\___\\___/|___/\\___|_|_(_)___/_| |_|

    Modulized Command line program

EOF;
        self::$parser->version = '0.0.1';
        // Adding a main option for setting domain
        self::$parser->addOption('domain', array('short_name' => '-d', 'long_name' => '--domain', 'description' => 'Domain to use if using multi hosts. If not set we will use default domain', 'action' => 'StoreString', 'default' => 'default'));
        self::beforeParse();
    }
Ejemplo n.º 3
0
 function findPart($id, $type = 'text/plain')
 {
     $foundPart = null;
     foreach (new RecursiveIteratorIterator($this->mail->getMessage($id)) as $part) {
         try {
             if (strtok($part->contentType, ';') == $type) {
                 $foundPart = $part;
                 return $foundPart;
                 break;
             }
         } catch (Exception $e) {
             log::error($e->getMessage());
         }
     }
 }
 /**
  * Images are stored in database. 
  * @param type $url
  * @return boolean
  */
 public function saveImage($url)
 {
     $id = direct::fragment(2, $url);
     $title = direct::fragment(3, $url);
     $title = rawurlencode($title);
     $path = "/images/{$id}/{$title}";
     $save_path = conf::getFullFilesPath($path);
     $web_path = conf::getSchemeWithServerName() . conf::getWebFilesPath($path);
     $code = headers::getReturnCode($web_path);
     if ($code != '200') {
         log::error("Could not get file content (image). Got: {$code} " . $web_path . ' in ' . __CLASS__);
         return false;
     }
     return $save_path;
 }
Ejemplo n.º 5
0
 /**
  * Run the system 
  */
 public function run()
 {
     // Register an autoloader for loading modules from mopdules dir
     $m = new modules();
     $m->autoloadRegister();
     // define HTML constants
     common::defineConstants();
     // define global constants - based on base path
     conf::defineCommon();
     // set include paths
     conf::setIncludePath();
     // load config file
     conf::load();
     if (conf::getMainIni('debug')) {
         log::enableDebug();
     }
     // set public file folder in file class
     file::$basePath = conf::getFullFilesPath();
     // utf-8
     ini_set('default_charset', 'UTF-8');
     // load config/config.ini
     // check if there exists a shared ini file
     // shared ini is used if we want to enable settings between hosts
     // which share same code base.
     // e.g. when updating all sites, it is a good idea to set the following flag
     // site_update = 1
     // this flag will send correct 503 headers, when we are updating our site.
     // if site is being updaing we send temporarily headers
     // and display an error message
     if (conf::getMainIni('site_update')) {
         http::temporarilyUnavailable();
     }
     // set a unified server_name if not set in config file.
     $server_name = conf::getMainIni('server_name');
     if (!$server_name) {
         conf::setMainIni('server_name', $_SERVER['SERVER_NAME']);
     }
     // redirect to uniform server name is set in config.ini
     // e.g. www.testsite.com => testsite.com
     $server_redirect = conf::getMainIni('server_redirect');
     if (isset($server_redirect)) {
         http::redirectHeaders($server_redirect);
     }
     // redirect to https is set in config.ini
     // force anything into ssl mode
     $server_force_ssl = conf::getMainIni('server_force_ssl');
     if (isset($server_force_ssl)) {
         http::sslHeaders();
     }
     // catch all output
     ob_start();
     // Create a db connection
     $db_conn = array('url' => conf::getMainIni('url'), 'username' => conf::getMainIni('username'), 'password' => conf::getMainIni('password'), 'db_init' => conf::getMainIni('db_init'));
     // Other options
     // db_dont_persist = 0
     // dont_die = 0 // Set to one and the connection don't die because of
     // e.g. no database etc. This will return NO_DB_CONN as string
     //$url = conf::getMainIni('url');
     connect::connect($db_conn);
     // init module loader.
     $ml = new moduleloader();
     // initiate uri
     uri::getInstance();
     // runlevel 1: merge db config
     $ml->runLevel(1);
     // select all db settings and merge them with ini file settings
     $db_Settings = [];
     if (moduleloader::moduleExists('settings')) {
         $db_settings = q::select('settings')->filter('id =', 1)->fetchSingle();
     }
     // merge db settings with config/config.ini settings
     // db settings override ini file settings
     conf::$vars['coscms_main'] = array_merge(conf::$vars['coscms_main'], $db_settings);
     // run level 2: set locales
     $ml->runLevel(2);
     // set locales
     intl::setLocale();
     // set default timezone
     intl::setTimezone();
     // runlevel 3 - init session
     $ml->runLevel(3);
     // start session
     session::initSession();
     // Se if user is logged in with SESSION
     if (!session::isUser()) {
         // If not logged in check system cookie
         // This will start the session, if an appropiate cookie exists
         session::checkSystemCookie();
     }
     // Check account
     $res = session::checkAccount();
     if (!$res) {
         // Redirect to main page if user is not allowed
         // With current SESSION or COOKIE
         http::locationHeader('/');
     }
     // set account timezone if enabled - can only be done after session
     // as user needs to be logged in
     intl::setAccountTimezone();
     // run level 4 - load language
     $ml->runLevel(4);
     // load all language files
     $l = new lang();
     $base = conf::pathBase();
     $htdocs = conf::pathHtdocs();
     $l->setDirsInsideDir("{$base}/modules/");
     $l->setDirsInsideDir("{$htdocs}/templates/");
     $l->setSingleDir("{$base}/vendor/diversen/simple-php-classes");
     $l->setSingleDir("{$base}/vendor/diversen/simple-pager");
     $l->loadLanguage(conf::getMainIni('lang'));
     // runlevel 5
     $ml->runLevel(5);
     // load routes if any
     dispatch::setDbRoutes();
     // check db routes or load defaults
     $db_route = dispatch::getMatchRoutes();
     if (!$db_route) {
         $ml->setModuleInfo();
         $ml->initModule();
     } else {
         dispatch::includeModule($db_route['method']);
     }
     // After module has been loaded.
     // You can e.g. override module ini settings
     $ml->runLevel(6);
     // Init layout. Sets template name
     // load correct CSS. St menus if any. Etc.
     $layout = new layout();
     // we first load menus here so we can se what happened when we
     // init our module. In case of a 404 not found error we don't want
     // to load module menus
     $layout->loadMenus();
     // init blocks
     $layout->initBlocks();
     // if any matching route was found we check for a method or function
     if ($db_route) {
         $str = dispatch::call($db_route['method']);
     } else {
         // or we use default module parsing
         $str = $ml->getParsedModule();
     }
     // set view vars
     $vars['content'] = $str;
     // run level 7
     $ml->runLevel(7);
     // echo module content
     echo $str = \mainTemplate::view($vars);
     conf::$vars['final_output'] = ob_get_contents();
     ob_end_clean();
     // Last divine intervention
     // e.g. Dom or Tidy
     $ml->runLevel(8);
     echo conf::$vars['final_output'];
 }
Ejemplo n.º 6
0
 public function deleteAll()
 {
     $connect = array('host' => conf::getMainIni('imap_host'), 'port' => conf::getMainIni('imap_port'), 'user' => conf::getMainIni('imap_user'), 'password' => conf::getMainIni('imap_password'), 'ssl' => conf::getMainIni('imap_ssl'));
     $i = new imap();
     $i->connect($connect);
     $c = $i->countMessages();
     log::error("Parse bounces. Num messages: {$c}\n");
     $i->mail->noop();
     // reverse - we start with latest message = $c
     for ($x = $c; $x >= 1; $x--) {
         log::error("Pasing num: {$x}");
         $i->mail->noop();
         // keep alive
         $i->mail->removeMessage($x);
         $i->mail->noop();
         // keep alive
         sleep(1);
     }
 }
Ejemplo n.º 7
0
 /**
  * checks if if size is allowed
  * @param string $filename the name of the file
  * @param int $maxsize bytes
  * @return boolean $res
  */
 public static function checkMaxSize($file, $maxsize = null)
 {
     if (!$maxsize) {
         $maxsize = self::$options['maxsize'];
     }
     if ($file['size'] > $maxsize) {
         $error = lang::translate('File is too large.') . ' ';
         $error .= lang::translate('Max size is ') . ' ' . bytes::bytesToGreek($maxsize);
         log::error($error);
         self::$errors[] = $error;
         return false;
     }
     return true;
 }
Ejemplo n.º 8
0
 /**
  * method to execute a query, insert update or delte. 
  * @return boolean true on success and false on failure. 
  */
 public static function exec()
 {
     self::$debug[] = self::$query;
     self::$stmt = self::$dbh->prepare(self::$query);
     try {
         self::prepare();
         $res = self::$stmt->execute();
     } catch (Exception $e) {
         $message = $e->getMessage();
         $message .= $e->getTraceAsString();
         log::debug($message);
         $last = self::getLastDebug();
         log::debug($last);
         die;
     }
     self::unsetVars();
     return $res;
 }
 /**
  * Checks broken media
  * @param type $url
  * @return boolean
  */
 protected function isImage($url)
 {
     $type = file::getExtension($url);
     if ($type == 'mp4') {
         log::error($url);
         return false;
     }
     return true;
 }
Ejemplo n.º 10
0
 /**
  * Validates a csrf enabled form
  */
 public static function csrfValidate()
 {
     if (class_exists('\\Riimu\\Kit\\CSRF\\CSRFHandler')) {
         $csrf = new \Riimu\Kit\CSRF\CSRFHandler(false);
         try {
             $csrf->validateRequest(true);
         } catch (\Riimu\Kit\CSRF\InvalidCSRFTokenException $ex) {
             log::error($ex->getMessage());
             http::locationHeader('/error/accessdenied', 'Bad request');
             return false;
         }
     }
     return true;
 }
Ejemplo n.º 11
0
 /**
  * Mail using smtp 
  * @param string $to
  * @param string $subject
  * @param string $text
  * @param string $html
  * @param array $attachments filenames
  * @return boolean
  */
 public static function mail($to, $subject, $text = null, $html = null, $attachments = array())
 {
     $mail = self::getPHPMailer();
     $mail->addAddress($to);
     $mail->Subject = $subject;
     if ($html) {
         $mail->isHTML(true);
         $mail->Body = $html;
         if ($text) {
             $mail->AltBody = $text;
         }
     } else {
         $mail->isHTML(false);
         $mail->Body = $text;
     }
     foreach ($attachments as $val) {
         $mail->addAttachment($val);
     }
     if (!$mail->send()) {
         self::$log = $mail->ErrorInfo;
         log::error(self::$log);
         return false;
     } else {
         return true;
     }
 }
Ejemplo n.º 12
0
 protected function saveImage($url)
 {
     $id = direct::fragment(2, $url);
     $title = direct::fragment(3, $url);
     $path = "/images/{$id}/{$title}";
     $save_path = conf::getFullFilesPath($path);
     $web_path = conf::getWebFilesPath($path);
     $image_url = conf::getSchemeWithServerName() . $url;
     $code = headers::getReturnCode($image_url);
     if ($code != 200) {
         log::error("Could not get file content (image). Got: {$code} " . $image_url);
         return '';
     } else {
         $file = file_get_contents($image_url);
     }
     // make dir
     $dir = dirname($path);
     file::mkdir($dir);
     file_put_contents($save_path, $file);
     return $web_path;
 }
Ejemplo n.º 13
0
 public function run()
 {
     // Register an autoloader for loading modules from mopdules dir
     $m = new modules();
     $m->autoloadRegister();
     // define HTML constants
     common::defineConstants();
     // define global constants - based on base path
     conf::defineCommon();
     // set include paths
     conf::setIncludePath();
     // load config file
     conf::load();
     // set log level - based on config.ini
     log::setLogLevel();
     // utf-8
     ini_set('default_charset', 'UTF-8');
     // load config/config.ini
     // check if there exists a shared ini file
     // shared ini is used if we want to enable settings between hosts
     // which share same code base.
     // e.g. when updating all sites, it is a good idea to set the following flag
     // site_update = 1
     // this flag will send correct 503 headers, when we are updating our site.
     // if site is being updaing we send temporarily headers
     // and display an error message
     if (conf::getMainIni('site_update')) {
         http::temporarilyUnavailable();
     }
     // set a unified server_name if not set in config file.
     $server_name = conf::getMainIni('server_name');
     if (!$server_name) {
         conf::setMainIni('server_name', $_SERVER['SERVER_NAME']);
     }
     // redirect to uniform server name is set in config.ini
     // e.g. www.testsite.com => testsite.com
     $server_redirect = conf::getMainIni('server_redirect');
     if (isset($server_redirect)) {
         http::redirectHeaders($server_redirect);
     }
     // redirect to https is set in config.ini
     // force anything into ssl mode
     $server_force_ssl = conf::getMainIni('server_force_ssl');
     if (isset($server_force_ssl)) {
         http::sslHeaders();
     }
     // catch all output
     ob_start();
     // Create a db connection
     $db = new db();
     // init module loader.
     $ml = new moduleloader();
     // initiate uri
     uri::getInstance();
     // runlevel 1: merge db config
     $ml->runLevel(1);
     // select all db settings and merge them with ini file settings
     $db_settings = $db->selectOne('settings', 'id', 1);
     // merge db settings with config/config.ini settings
     // db settings override ini file settings
     conf::$vars['coscms_main'] = array_merge(conf::$vars['coscms_main'], $db_settings);
     // run level 2: set locales
     $ml->runLevel(2);
     // set locales
     intl::setLocale();
     // set default timezone
     intl::setTimezone();
     // runlevel 3 - init session
     $ml->runLevel(3);
     // start session
     session::initSession();
     $res = session::checkAccount();
     if (!$res) {
         // To prevent
         http::locationHeader('/');
     }
     // set account timezone if enabled - can only be done after session
     // as user needs to be logged in
     intl::setAccountTimezone();
     // run level 4 - load language
     $ml->runLevel(4);
     // load all language files
     $l = new lang();
     $base = conf::pathBase();
     $htdocs = conf::pathHtdocs();
     $l->setDirsInsideDir("{$base}/modules/");
     $l->setDirsInsideDir("{$htdocs}/templates/");
     $l->setSingleDir("{$base}/vendor/diversen/simple-php-classes");
     $l->setSingleDir("{$base}/vendor/diversen/simple-pager");
     $l->loadLanguage(conf::getMainIni('language'));
     // runlevel 5
     $ml->runLevel(5);
     // load routes if any
     dispatch::setDbRoutes();
     // runlevel 6
     $ml->runLevel(6);
     // check db routes or load by defaults
     $db_route = dispatch::getMatchRoutes();
     if (!$db_route) {
         $ml->setModuleInfo();
         $ml->initModule();
     }
     // Init layout. Sets template name
     // load correct CSS. St menus if any. Etc.
     $layout = new layout();
     // we first load menus here so we can se what happened when we
     // init our module. In case of a 404 not found error we don't want
     // to load module menus
     $layout->loadMenus();
     // init blocks
     $layout->initBlocks();
     // if any matching route was found we check for a method or function
     if ($db_route) {
         $str = dispatch::call($db_route['method']);
     } else {
         // or we use default module parsing
         $str = $ml->getParsedModule();
     }
     // set view vars
     $vars['content'] = $str;
     // run level 7
     $ml->runLevel(7);
     // echo module content
     echo $str = \mainTemplate::view($vars);
     conf::$vars['final_output'] = ob_get_contents();
     ob_end_clean();
     // Last divine intervention
     // e.g. Dom or Tidy
     $ml->runLevel(8);
     echo conf::$vars['final_output'];
 }
Ejemplo n.º 14
0
 /**
  * Images are stored in database. 
  * @param type $url
  * @return boolean
  */
 public function checkImage($url)
 {
     $id = direct::fragment(2, $url);
     $title = direct::fragment(3, $url);
     $path = "/images/{$id}/{$title}";
     $save_path = conf::getFullFilesPath($path);
     $web_path = conf::getWebFilesPath($path);
     $image_url = conf::getSchemeWithServerName() . $url;
     $code = headers::getReturnCode($image_url);
     if ($code != 200) {
         log::error("Could not get file content (image). Got: {$code} " . $image_url);
         return false;
     }
     return $url;
 }
Ejemplo n.º 15
0
function dev_log($options = null)
{
    log::error('Hello world');
}
Ejemplo n.º 16
0
 protected function uploadImage($url)
 {
     // Array ( [name] => Angus_cattle_18.jpg [type] => image/jpeg [tmp_name] => /tmp/php5lPQZT [error] => 0 [size] => 52162 )
     $ary = [];
     $name = file::getFilename($url) . "." . file::getExtension($url);
     $ary['name'] = $name;
     $ary['abstract'] = file::getFilename($url);
     $ary['type'] = file::getMime($url);
     $ary['tmp_name'] = $url;
     $ary['error'] = 0;
     $ary['size'] = 0;
     $i = new \modules\image\uploadBlob();
     $res = $i->insertFileDirect($ary, $this->reference, $this->parentId, $this->userId);
     if ($res) {
         $id = q::lastInsertId();
         $row = $i->getSingleFileInfo($id);
         return $i->getFullWebPath($row);
     } else {
         log::error("Could not upload image: {$name}");
         return false;
     }
 }
Ejemplo n.º 17
0
 /**
  * remove single file or array of files
  * @param string|array $files
  */
 public static function remove($files)
 {
     if (is_string($files)) {
         unlink($files);
     }
     if (is_array($files)) {
         foreach ($files as $val) {
             $res = unlink($val);
             if (!$res) {
                 log::error("Could not remove file: {$val}");
             }
         }
     }
 }