Exemplo n.º 1
0
 /**
  * Sends the email with the contents of the object (Body etc. set using the parant calls in phpMailer!)
  * @author Bobby Allen (ballen@bobbyallen.me)
  * @return boolean 
  */
 public function SendEmail()
 {
     $this->Mailer = ctrl_options::GetSystemOption('mailer_type');
     $this->From = ctrl_options::GetSystemOption('email_from_address');
     $this->FromName = ctrl_options::GetSystemOption('email_from_name');
     if (ctrl_options::GetSystemOption('email_smtp') != 'false') {
         $this->IsSMTP();
         if (ctrl_options::GetSystemOption('smtp_auth') != 'false') {
             $this->SMTPAuth = true;
             $this->Username = ctrl_options::GetSystemOption('smtp_username');
             $this->Password = ctrl_options::GetSystemOption('smtp_password');
         }
         if (ctrl_options::GetSystemOption('smtp_secure') != 'false') {
             $this->SMTPSecure = ctrl_options::GetSystemOption('smtp_secure');
         }
         $this->Host = ctrl_options::GetSystemOption('smtp_server');
         $this->Port = ctrl_options::GetSystemOption('smtp_port');
     }
     ob_start();
     $send_resault = $this->Send();
     $error = ob_get_contents();
     ob_clean();
     if ($send_resault) {
         runtime_hook::Execute('OnSuccessfulSendEmail');
         return true;
     } else {
         $logger = new debug_logger();
         $logger->method = ctrl_options::GetSystemOption('logmode');
         $logger->logcode = "061";
         $logger->detail = 'Error sending email (using sys_email): ' . $error . '';
         $logger->writeLog();
         runtime_hook::Execute('OnFailedSendEmail');
         return false;
     }
 }
Exemplo n.º 2
0
 /**
  * Retourne le dossier base(ROOT) de Magix CMS
  */
 public static function basePath()
 {
     try {
         return filter_path::basePath(array('lib', 'magepattern'));
     } catch (Exception $e) {
         $logger = new debug_logger(MP_LOG_DIR);
         $logger->log('php', 'error', 'An error has occured : ' . $e->getMessage(), debug_logger::LOG_MONTH);
     }
 }
Exemplo n.º 3
0
 /**
  * Instance la classe DateTime
  * @param  $time
  * @return \DateTime
  * @throws Exception
  */
 private function _datetime($time)
 {
     try {
         $datetime = self::create($time);
         if ($datetime instanceof DateTime) {
             return $datetime;
         } else {
             throw new Exception('not instantiate the class: DateTime');
         }
     } catch (Exception $e) {
         $logger = new debug_logger(MP_LOG_DIR);
         $logger->log('php', 'error', 'An error has occured : ' . $e->getMessage(), debug_logger::LOG_MONTH);
     }
 }
 /**
  * Provides very basic way of retrieving a result as a string from a given URL (RAW) this does not need to be a 'true' web service.
  * @author Bobby Allen (ballen@bobbyallen.me)
  * @param string $requestURL The URL to the resource.
  * @return mixed If the request was successful it will return the contents of the requested URL otherwise will return 'false'.
  */
 static function ReadURLRequestResult($requestURL)
 {
     ob_start();
     @readfile($requestURL);
     $reqcontent = ob_get_contents();
     ob_clean();
     if ($reqcontent) {
         return $reqcontent;
     }
     $ws_log = new debug_logger();
     $ws_log->logcode = "903";
     $ws_log->detail = "Unable to connect to webservice URL (" . $requestURL . ") as requested in ws_generic::ReadURLRequestResult()";
     $ws_log->writeLog();
     return false;
 }
 /**
  * Executes a hook file at the called position.
  * @author Bobby Allen (ballen@bobbyallen.me)
  * @param string $name The name of the hook of which to execute.
  */
 static function Execute($name)
 {
     $hook_log = new debug_logger();
     $mod_folder = "modules/*/hooks/{" . $name . ".hook.php}";
     $hook_log->method = ctrl_options::GetSystemOption('logmode');
     $hook_log->logcode = "861";
     foreach (glob($mod_folder, GLOB_BRACE) as $hook_file) {
         if (file_exists($hook_file)) {
             $hook_log->detail = "Execute hook file (" . $hook_file . ")";
             try {
                 include $hook_file;
             } catch (Exception $e) {
                 $hook_log->detail .= ' -> Exception(' . $e->getMessage() . ') :(';
             }
             $hook_log->writeLog();
         }
     }
 }
Exemplo n.º 6
0
 /**
  * Envoi du message avec la méthode batch send
  * @param string $message
  * @param bool $failures
  * @param bool $log
  * @internal param void $mailer
  * @internal param void $failed
  * @internal param string $logger
  */
 public function batch_send_mail($message, $failures = false, $log = false)
 {
     if (!$this->_mailer->send($message)) {
         debug_firephp::dump("Failures: ", $failures);
     }
     if ($log) {
         $echologger = new Swift_Plugins_Loggers_EchoLogger();
         $this->_mailer->registerPlugin(new Swift_Plugins_LoggerPlugin($echologger));
         debug_firephp::dump("Failures: ", $echologger->dump());
         $logger = new debug_logger(MP_LOG_DIR);
         $logger->log('mail', 'Failures', 'Failures : ' . $echologger->dump(), debug_logger::LOG_VOID);
     }
 }
Exemplo n.º 7
0
 /**
  * Chargement du fichier SQL pour la lecture du fichier
  * @param $sqlfile
  * @throws Exception
  * @return array|bool|string
  */
 private function load_sql_file($sqlfile)
 {
     try {
         $db_structure = "";
         $structureFile = $sqlfile;
         if (!file_exists($structureFile)) {
             throw new Exception("Error : Not File exist .sql");
         } else {
             $db_structure = preg_split("/;\\s*[\r\n]+/", file_get_contents($structureFile));
             if ($db_structure != null) {
                 $tables = $db_structure;
             } else {
                 debug_firephp::error("Error : SQL File is empty");
                 return false;
             }
         }
         return $tables;
     } catch (Exception $e) {
         $logger = new debug_logger(MP_LOG_DIR);
         $logger->log('php', 'error', 'An error has occured : ' . $e->getMessage(), debug_logger::LOG_MONTH);
     }
 }
Exemplo n.º 8
0
 /**
  * @access public
  * Check si le domaine est disponible
  * @param $url
  * @param bool $ssl
  * @param bool $debug
  * @internal param string $domain
  * @return bool
  */
 public function isDomainAvailible($url, $ssl = false, $debug = false)
 {
     try {
         if (self::curl_exist()) {
             //check, if a valid url is provided
             if (!filter_var($url, FILTER_VALIDATE_URL)) {
                 return false;
             }
             //initialize curl
             $curlInit = curl_init($url);
             curl_setopt($curlInit, CURLOPT_CONNECTTIMEOUT, 10);
             curl_setopt($curlInit, CURLOPT_HEADER, true);
             curl_setopt($curlInit, CURLOPT_NOBODY, true);
             curl_setopt($curlInit, CURLOPT_RETURNTRANSFER, true);
             if ($ssl) {
                 /*Vérification SSL*/
                 curl_setopt($curlInit, CURLOPT_SSL_VERIFYPEER, false);
             }
             //get answer
             $response = curl_exec($curlInit);
             curl_close($curlInit);
             if ($debug) {
                 $firephp = new debug_firephp();
                 $firephp->log($response);
             }
             if ($response) {
                 return true;
             }
             return false;
         }
     } catch (Exception $e) {
         $logger = new debug_logger(MP_LOG_DIR);
         $logger->log('error', 'php', 'An error has occured : ' . $e->getMessage(), debug_logger::LOG_VOID);
     }
 }
Exemplo n.º 9
0
 /**
 * Select Field
 *
 * Return HTML CODE for SELECT MENU
 * @static
 * @param string|array    $nid            Element ID and name
 * @param array $arrayOption
 * @param bool $arrInput
 * @throws Exception
 * @return string
 *
 * @example :
 * #### BASE #####
 *
     $form->select(
    'myselect',
    array(1=>'opt1',2=>'opt2'),
    'maclass'
     );
 * ##### WITH Database #######
     $fetch = $db->fetchAll($sql); //ASSOCIATIVE DATA
     $option = '';
     foreach($fetch as $value){
    $id[] = $value['id'];
    $color[] = $value['color'];
     }
     $selectcolor = array_combine($id,$color);
     $form->select(
    'monselect',
    $selectcolor,
    'maclass'
     );
 *
 * Return Source :
     <select name="myselect" id="myselect" class="myclass">
     <option value="1">couleur verte</option>
     <option value="2">couleur rouge</option>
     </select>
 */
 public static function select($nid, $arrayOption, $arrInput = false)
 {
     try {
         self::getNameAndId($nid, $name, $id);
         $getInput = self::setInputConfig($arrInput);
         if (is_array($arrayOption)) {
             $res = '<select name="' . $name . '" ';
             $res .= $id ? 'id="' . $id . '"' : '';
             $res .= $getInput['class'] ? ' class="' . $getInput['class'] . '"' : '';
             $res .= '>' . "\n";
             foreach ($arrayOption as $key => $value) {
                 $selected = null;
                 if (isset($getInput['default']) and $getInput['default'] != '') {
                     if (array_key_exists($getInput['default'], $arrayOption)) {
                         $selected = $getInput['default'] == $key ? ' selected="selected"' : null;
                     }
                 }
                 $res .= '<option' . $selected . ' value="' . $key . '">';
                 $res .= $value;
                 $res .= '</option>' . "\n";
             }
             $res .= '</select>' . "\n";
             return $res;
         } else {
             throw new Exception(sprintf('%s is not array in ' . __METHOD__, $arrayOption));
         }
     } catch (Exception $e) {
         $logger = new debug_logger(MP_LOG_DIR);
         $logger->log('php', 'error', 'An error has occured : ' . $e->getMessage(), debug_logger::LOG_MONTH);
     }
 }
Exemplo n.º 10
0
 /**
  * function truncate table
  *
  * @param void $table
  * @param bool $setOption
  * @throws Exception
  */
 public function truncateTable($table, $setOption = false)
 {
     try {
         /**
          * Charge la configuration
          */
         $sql = 'TRUNCATE TABLE ' . $table;
         $setConfig = $this->setConfig($sql, $setOption = false);
         $prepare = $this->prepare($sql);
         if (is_object($prepare)) {
             $prepare->execute();
             $setConfig['debugParams'] ? $prepare->debugDumpParams() : '';
             $setConfig['closeCursor'] ? $prepare->closeCursor() : '';
         } else {
             throw new Exception('showTable Error with SQL prepare');
         }
     } catch (PDOException $e) {
         $logger = new debug_logger(MP_LOG_DIR);
         $logger->log('statement', 'db', 'An error has occured : ' . $e->getMessage(), debug_logger::LOG_MONTH);
     }
 }
Exemplo n.º 11
0
 /**
  * This function rename files and dir
  *
  * @access public
  * @param $files
  * @throws Exception
  */
 public function rename($files)
 {
     try {
         if (is_array($files)) {
             foreach ($files as $origin => $target) {
                 // we check that target does not exist
                 if (is_readable($target)) {
                     throw new Exception(sprintf('Cannot rename because the target "%s" already exist.', $origin));
                 }
                 if (!file_exists($origin)) {
                     continue;
                 }
                 if (true !== @rename($origin, $target)) {
                     throw new Exception(sprintf('Failed to rename %s', $origin));
                 }
             }
         } else {
             throw new Exception(sprintf('%s is not array', $files));
         }
     } catch (Exception $e) {
         $logger = new debug_logger(MP_LOG_DIR);
         $logger->log('php', 'error', 'An error has occured : ' . $e->getMessage(), debug_logger::LOG_MONTH);
     }
 }
Exemplo n.º 12
0
 /**
 * @static
 * @param array|bool $tabsearch
 * @throws Exception
 * @internal param array $tabreplace
 * @return mixed|string
 * @example :
    filesystem_path::basePath(
        array('component','filesystem')
    );
 */
 public static function basePath($tabsearch = false)
 {
     try {
         $default_path = array('component', 'filter');
         if ($tabsearch != false) {
             if (is_array($tabsearch)) {
                 $search = array_merge($tabsearch, $default_path, array(DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR));
             } else {
                 throw new Exception(__METHOD__ . ' params "tabsearch" is not array');
             }
         } else {
             //$search = array_merge(explode(DIRECTORY_SEPARATOR,__DIR__),array(DIRECTORY_SEPARATOR));
             $search = array_merge($default_path, array(DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR));
         }
         /*if($tabreplace != false){
                         if(is_array($tabreplace)){
                             $replace = array_merge($tabreplace,array('',''));
         
                         }else{
                             throw new Exception(__METHOD__.' params "tabreplace" is not array');
                         }
                     }else{
                         $replace = array_fill(0,count($search),'');
                     }*/
         if (count($search) > 0) {
             $replace = array_fill(0, count($search), '');
         } else {
             throw new Exception('Error replace : internal params is null');
         }
         $pathreplace = str_replace($search, $replace, __DIR__);
         if (strrpos($pathreplace, DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR)) {
             $pathclean = substr($pathreplace, -1);
         } else {
             $pathclean = $pathreplace;
         }
         if (strrpos($pathclean, DIRECTORY_SEPARATOR, strlen($pathclean) - 1)) {
             $path = $pathclean;
             //$path = substr($pathclean,0, -1);
         } else {
             $path = $pathclean . DIRECTORY_SEPARATOR;
         }
         return $path;
     } catch (Exception $e) {
         $logger = new debug_logger(MP_LOG_DIR);
         $logger->log('php', 'error', 'An error has occured : ' . $e->getMessage(), debug_logger::LOG_MONTH);
     }
 }
Exemplo n.º 13
0
// ====================================================================
// Load Saved Preferences
if (file_exists('prefs/prefs')) {
    // Convert old-style prefs file
    include "utils/convertprefs.php";
} else {
    if (file_exists('prefs/prefs.var')) {
        // Else, load new-style prefs file
        loadPrefs();
    }
}
if ($prefs['debug_enabled'] === true) {
    // Convert old-style debug pref
    $prefs['debug_enabled'] = 7;
}
$logger = new debug_logger($prefs['custom_logfile'], $prefs['debug_enabled']);
if (!array_key_exists('multihosts', $prefs)) {
    $prefs['multihosts'] = new stdClass();
    $prefs['multihosts']->Default = (object) ['host' => $prefs['mpd_host'], 'port' => $prefs['mpd_port'], 'password' => $prefs['mpd_password'], 'socket' => $prefs['unix_socket']];
    setcookie('currenthost', 'Default', time() + 365 * 24 * 60 * 60 * 10);
    $prefs['currenthost'] = 'Default';
    savePrefs();
}
// Prefs can be overridden by cookies
foreach ($_COOKIE as $a => $v) {
    if (array_key_exists($a, $prefs)) {
        $prefs[$a] = $v;
        if ($a == 'debug_enabled') {
            $logger->setLevel($v);
        }
        debuglog("Pref " . $a . " overridden by Cookie  - Value : " . $v, "COOKIE", 9);
Exemplo n.º 14
0
 /**
  * Used in hooks to communicate with the modules controller.ext.php
  * @author Bobby Allen (ballen@bobbyallen.me)
  * @param string $module_path The full path to the module.
  */
 static function ModuleControllerCode($module_path)
 {
     $raw_path = str_replace("\\", "/", $module_path);
     $module_path = str_replace("/hooks", "/code/", $raw_path);
     $rawroot_path = str_replace("\\", "/", dirname(__FILE__));
     $root_path = str_replace("/dryden/runtime", "/", $rawroot_path);
     require_once $root_path . 'dryden/loader.inc.php';
     require_once $root_path . 'cnf/db.php';
     require_once $root_path . 'inc/dbc.inc.php';
     if (file_exists($module_path . 'controller.ext.php')) {
         require_once $module_path . 'controller.ext.php';
     } else {
         $hook_log = new debug_logger();
         $hook_log->method = ctrl_options::GetSystemOption('logmode');
         $hook_log->logcode = "611";
         $hook_log->detail = "No hook controller.ext.php avaliable to import in (" . $root_path . 'controller.ext.php' . ")";
         $hook_log->writeLog();
     }
 }
Exemplo n.º 15
0
 /**
  * @access public
  * Initialise la session ou renouvelle la session
  * @param $session_tabs
  * @param bool $setOption
  * @internal param array $session
  * @internal param bool $debug
  */
 public function run($session_tabs = false, $setOption = false)
 {
     try {
         if ($setOption != false) {
             $setOption;
         }
         if ($session_tabs != false) {
             $this->iniSessionVar($session_tabs);
         }
     } catch (Exception $e) {
         $logger = new debug_logger(MP_LOG_DIR);
         $logger->log('php', 'error', 'An error has occured : ' . $e->getMessage(), debug_logger::LOG_VOID);
     }
 }
Exemplo n.º 16
0
 /**
  * Retourne l'extension du fichier image
  * @param $filename
  * @return size
  */
 public static function imageAnalyze($filename)
 {
     try {
         $size = getimagesize($filename);
         switch ($size['mime']) {
             case "image/gif":
                 $imgtype = '.gif';
                 break;
             case "image/jpeg":
                 $imgtype = '.jpg';
                 break;
             case "image/png":
                 $imgtype = '.png';
                 break;
             case false:
                 break;
         }
         return $imgtype;
     } catch (Exception $e) {
         $logger = new debug_logger(MP_LOG_DIR);
         $logger->log('php', 'error', 'An error has occured : ' . $e->getMessage(), debug_logger::LOG_MONTH);
     }
 }
Exemplo n.º 17
0
 /**
  * Charge le theme selectionné ou le theme par défaut
  */
 public function load_theme()
 {
     $db = self::$collectionsSetting->fetch('theme');
     if ($db['setting_value'] != null) {
         if ($db['setting_value'] == 'default') {
             $theme = $db['setting_value'];
         } elseif (file_exists(magixglobal_model_system::base_path() . '/skin/' . $db['setting_value'] . '/')) {
             $theme = $db['setting_value'];
         } else {
             try {
                 $theme = 'default';
                 throw new Exception('template ' . $db['setting_value'] . ' is not found');
             } catch (Exception $e) {
                 $logger = new debug_logger(MP_LOG_DIR);
                 $logger->log('php', 'error', 'An error has occured : ' . $e->getMessage(), debug_logger::LOG_MONTH);
             }
         }
     } else {
         $theme = 'default';
     }
     return $theme;
 }
Exemplo n.º 18
0
 * @copyright ZPanel Project (http://www.zpanelcp.com/)
 * @link http://www.zpanelcp.com/
 * @license GPL (http://www.gnu.org/licenses/gpl.html)
 *
 * Changes P.Peyremorte
 * - added timestamp of begin and end of dameon run for logfile
 * - corrected OnDaemonHour that occured on each cron run (5 min,)
 */
set_time_limit(0);
$rawPath = str_replace("\\", "/", dirname(__FILE__));
$rootPath = str_replace("/bin", "/", $rawPath);
chdir($rootPath);
require_once 'dryden/loader.inc.php';
require_once 'cnf/db.php';
require_once 'inc/dbc.inc.php';
$daemonLog = new debug_logger();
$daemonLog->method = "file";
$daemonLog->logcode = "001";
$dateformat = ctrl_options::GetSystemOption('MADmin_df');
if (!runtime_controller::IsCLI()) {
    echo "<pre>";
}
echo "Daemon is now running... (" . date($dateformat) . ")\n";
$daemonLog->detail = "Daemon execution started...";
$daemonLog->writeLog();
runtime_hook::Execute("OnStartDaemonRun");
runtime_hook::Execute("OnDaemonRun");
runtime_hook::Execute("OnEndDaemonRun");
if (time() >= ctrl_options::GetSystemOption('daemon_hourrun') + 3600) {
    ctrl_options::SetSystemOption('daemon_hourrun', time());
    runtime_hook::Execute("OnStartDaemonHour");
Exemplo n.º 19
0
 /**
  * filterFiles => filter files with extension
  * $t = new magixcjquery_files_makefiles();
  * var_dump($t->filterFiles('mydir',array('gif','png','jpe?g')));
  * or
  * var_dump($t->filterFiles('mydir','php'));
  * @param $directory
  * @param $extension
  * @internal param $dir
  * @return string
  */
 public function filterFiles($directory, $extension)
 {
     try {
         $filterfiles = new filterFiles($directory, $extension);
         $filter = '';
         foreach ($filterfiles as $file) {
             if ($file->isDot() || $file->isDir()) {
                 continue;
             }
             $filter[] .= $file;
         }
         return $filter;
     } catch (Exception $e) {
         $logger = new debug_logger(MP_LOG_DIR);
         $logger->log('error', 'php', 'An error has occured : ' . $e->getMessage(), debug_logger::LOG_VOID);
     }
 }