Ejemplo n.º 1
0
 /**
  * Set HTTP Status Header
  *
  * @param	int	the status code
  * @param	string
  * @return	void
  */
 function set_status_header($code = 200, $text = '')
 {
     if (is_cli()) {
         return;
     }
     if (empty($code) or !is_numeric($code)) {
         show_error('Status codes must be numeric', 500);
     }
     if (empty($text)) {
         is_int($code) or $code = (int) $code;
         $stati = [100 => 'Continue', 101 => 'Switching Protocols', 200 => 'OK', 201 => 'Created', 202 => 'Accepted', 203 => 'Non-Authoritative Information', 204 => 'No Content', 205 => 'Reset Content', 206 => 'Partial Content', 300 => 'Multiple Choices', 301 => 'Moved Permanently', 302 => 'Found', 303 => 'See Other', 304 => 'Not Modified', 305 => 'Use Proxy', 307 => 'Temporary Redirect', 400 => 'Bad Request', 401 => 'Unauthorized', 402 => 'Payment Required', 403 => 'Forbidden', 404 => 'Not Found', 405 => 'Method Not Allowed', 406 => 'Not Acceptable', 407 => 'Proxy Authentication Required', 408 => 'Request Timeout', 409 => 'Conflict', 410 => 'Gone', 411 => 'Length Required', 412 => 'Precondition Failed', 413 => 'Request Entity Too Large', 414 => 'Request-URI Too Long', 415 => 'Unsupported Media Type', 416 => 'Requested Range Not Satisfiable', 417 => 'Expectation Failed', 422 => 'Unprocessable Entity', 500 => 'Internal Server Error', 501 => 'Not Implemented', 502 => 'Bad Gateway', 503 => 'Service Unavailable', 504 => 'Gateway Timeout', 505 => 'HTTP Version Not Supported'];
         if (isset($stati[$code])) {
             $text = $stati[$code];
         } else {
             $ex = new Core\MyException();
             $ex->show_error('No status text available. Please check your status code number or supply your own message text.', 500);
         }
     }
     if (strpos(PHP_SAPI, 'cgi') === 0) {
         header('Status: ' . $code . ' ' . $text, TRUE);
     } else {
         $server_protocol = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1';
         header($server_protocol . ' ' . $code . ' ' . $text, TRUE, $code);
     }
 }
Ejemplo n.º 2
0
 /**
  * check is cli
  */
 public function __construct()
 {
     parent::__construct();
     if (!is_cli()) {
         return;
     }
 }
Ejemplo n.º 3
0
 /**
  * 404 Error Handler
  *
  * @uses    CI_Exceptions::show_error()
  *
  * @param   string  $page       Page URI
  * @param   bool    $log_error  Whether to log the error
  * @return  void
  */
 public function show_404($page = '', $log_error = TRUE)
 {
     if (is_cli()) {
         $heading = 'Not Found';
         $message = 'The controller/method pair you requested was not found.';
     } else {
         $heading = lang('404_title');
         $message = lang('404_text');
     }
     // By default we log this, but allow a dev to skip it
     if ($log_error) {
         log_message('error', $heading . ': ' . $page);
     }
     $CI =& get_instance();
     $CI->output->set_status_header('404');
     $settings = $CI->settings_model->getValues(array('home_title', 'home_header', 'home_video', 'home_text', 'home_end_text'));
     $data['title'] = lang('404_title');
     $data['header'] = lang('404_title');
     $data['text'] = lang('404_text');
     $CI->load->helper('URL');
     $views = array('_head', '_header', 'site/error', '_footer');
     foreach ($views as $key => $view) {
         echo $CI->load->view('frontend/' . $view, $data, TRUE);
     }
     exit(4);
     // EXIT_UNKNOWN_FILE
 }
Ejemplo n.º 4
0
 public function __construct()
 {
     parent::__construct();
     // Load common used language
     // $this->load->language('base::app_common');
     // Load common used helpers
     $this->load->helper(['url', 'html']);
     if (!is_cli()) {
         // Load libraries & drivers
         $this->load->library('base::auths');
         // Use Redis cache
         // $this->load->driver('cache', [
         //     'adapter'    => 'redis',
         //     'backup'     => 'file',
         //     'key_prefix' => 'creasi_'
         // ]);
     }
     // Set default data keys
     $this->views->add_data(['page_name' => 'Aplikasi', 'path_name' => '/']);
     if ($this->load->config('base::lang_codes', true, true)) {
         $codes = $this->config->item('base::lang_codes', 'lang_codes');
         $lang = $this->config->item('language');
         $code = array_search($lang, $codes) ?: 'en';
     } else {
         $code = 'en';
     }
     $this->views->add_data(['lang' => $code, 'charset' => strtolower($this->config->item('charset'))]);
 }
Ejemplo n.º 5
0
 public function perform_scheduled_tasks()
 {
     if (is_cli()) {
         $this->update_pending_projects();
         $this->update_closed_projects();
         if (date('Y-m-d') === date('Y-m-01')) {
             $this->generate_worker_salaries();
             $this->generate_vendor_salaries();
             $this->generate_worker_instalments();
             $this->generate_admin_salaries();
         }
         if (date('Y-m-d') === date('Y-m-t')) {
             $this->projects_closed_end_month_warning();
         }
         $this->non_payment_after_week();
         $this->non_payment_after_fortnight();
         $this->insufficient_payment_after_fortnight();
         $this->without_resources_three_days_before();
         $this->without_resources_fortnight_before();
         $this->project_start_week_before();
         $this->pending_selection_first_warning();
         $this->pending_selection_second_warning();
         $this->pending_selection_third_warning();
         $this->fortnightly_schedule();
     }
 }
Ejemplo n.º 6
0
 /**
  * Запрет на исполнение вне комендной строки
  */
 public function __construct()
 {
     parent::__construct();
     if (!is_cli()) {
         die('Only command line access');
     }
 }
Ejemplo n.º 7
0
 /**
  * check is cli
  *
  * @params
  */
 public function __construct()
 {
     if (!is_cli()) {
         return;
     }
     set_time_limit(0);
 }
Ejemplo n.º 8
0
 public static function create()
 {
     if (is_cli()) {
         return Sabel_Cookie_InMemory::create();
     } else {
         return Sabel_Cookie_Http::create();
     }
 }
Ejemplo n.º 9
0
 /**
  * Constructor
  *
  * @access    public
  */
 public function __construct()
 {
     parent::__construct();
     // Prevent access via web. Uncomment when enough people have changed.
     if (!is_cli()) {
         die("Not Allowed");
     }
 }
Ejemplo n.º 10
0
function echo_title($title)
{
    if (is_cli()) {
        echo "\n** {$title} **\n\n";
    } else {
        echo "<h2>{$title}</h2>";
    }
}
 /**
  * Method to authenticate users before allowing install
  */
 protected function authenticate()
 {
     if (is_cli() === FALSE) {
         header('HTTP/1.1 401 Unauthorized.', TRUE, 401);
         echo 'This script can only be accessed via CLI.';
         exit(EXIT_ERROR);
     }
 }
Ejemplo n.º 12
0
 public function __construct()
 {
     parent::__construct();
     // allow execution from CLI only
     if (!is_cli()) {
         show_404();
     }
 }
Ejemplo n.º 13
0
 public function __construct()
 {
     parent::__construct();
     $this->load->library('migration');
     if (!is_cli()) {
         exit('CLI mode only!');
     }
 }
Ejemplo n.º 14
0
 public function sendToValidateEmails()
 {
     if (!is_cli()) {
         return;
     }
     $fodaURL = base_url() . "fodaStrategy";
     $metricURL = base_url() . "validar";
     $positions = ['coordinador', 'director'];
     $users = $this->getUsers($positions);
     $result = true;
     foreach ($users as $user) {
         $this->load->helper('email');
         if (!valid_email($user->email)) {
             echo "email de " . $user->name . ": " . $user->email . " no válido" . PHP_EOL;
             $result = false;
             continue;
         }
         $message = "Hola " . $user->name . ", se requiere su validación de los siguientes elementos:" . PHP_EOL;
         if (stristr($user->short_name, $positions[0])) {
             $this->load->model('Foda_model');
             $this->load->model('Strategy_model');
             $fodas = $this->getToValidate($this->Foda_model, 'getFoda', $user->org);
             $plans = $this->getToValidate($this->Strategy_model, 'getStrategicPlan', $user->org);
             $metric = $this->areMetricsToValidate([$user->org], ['proposed_value!=' => [null]]);
         } else {
             if (stristr($user->short_name, $positions[1])) {
                 $this->load->model('Organization_model');
                 $fodas = [];
                 $plans = [];
                 $metric = $this->areMetricsToValidate($this->Organization_model->getAllIds(), ['proposed_x_value!=' => [''], 'proposed_target!=' => [null], 'proposed_expected!=' => [null]]);
             }
         }
         if (!count($plans) && !count($fodas) && !$metric) {
             continue;
         }
         if (count($plans)) {
             $message .= " - Plan Estratégico: Tienes información que validar de " . $user->org_name . " (" . $this->getComaSeparatedYears($plans) . ")" . PHP_EOL;
         }
         if (count($fodas)) {
             $message .= " - FODA : Tienes información que validar de " . $user->org_name . " (" . $this->getComaSeparatedYears($fodas) . ")" . PHP_EOL;
         }
         if ($metric) {
             $message .= " - Tienes valores de métricas que validar." . PHP_EOL;
             $message .= "Los valores de las métricas se validan en " . $metricURL . PHP_EOL;
         }
         if (count($plans) || count($fodas)) {
             $message .= "El FODA y el plan estratégico se validan en " . $fodaURL . PHP_EOL;
         }
         $this->load->library('email');
         $this->email->from("*****@*****.**", "U-Dashboard");
         $this->email->to($user->email);
         $this->email->subject("Validaciones pendientes U-Dashboard");
         $this->email->message($message);
         $result = $this->email->send(false) && $result;
         echo $this->email->print_debugger();
     }
     echo PHP_EOL . ($result ? 1 : 0) . PHP_EOL;
 }
 function __construct()
 {
     parent::__construct();
     if (!is_cli()) {
         show_error('CLI request only.');
     }
     $this->load->helper('cron');
     echo 'Process notification queue' . PHP_EOL;
 }
Ejemplo n.º 16
0
 public function __construct()
 {
     parent::__construct();
     // This controller should not be called from a browser
     if (!is_cli()) {
         show_404();
     }
     $this->load->model('queue_model')->model('submit_model');
 }
Ejemplo n.º 17
0
 /**
  * Check session status
  *
  * @return bool
  */
 function is_session_started()
 {
     if (!is_cli()) {
         $result = session_status() === PHP_SESSION_ACTIVE ? TRUE : FALSE;
     } else {
         $result = FALSE;
     }
     return $result;
 }
Ejemplo n.º 18
0
 /**
  * This returns the base uri of the current module, if passed an argument
  * it automatically appended as uri.
  *
  * @param $extend_path To provide uri
  * @return string
  */
 function base_uri($extend_path = null)
 {
     if (is_cli()) {
         return;
     }
     $url = url()->getHost();
     $scheme = url()->getScheme();
     return url_trimmer($scheme . '/' . $url . '/' . $extend_path);
 }
Ejemplo n.º 19
0
 /**
  * Debuging purposes
  *
  * @param   resource  $debug  Object or array
  * @return  string
  */
 function dd($debug = null)
 {
     if (!empty($debug)) {
         if (is_cli()) {
             $cli = new Projek\CI\Common\Console();
             return $cli->dump($debug);
         }
         echo '<pre>' . print_r($debug, true) . '</pre>';
     }
 }
Ejemplo n.º 20
0
 /**
  * Ensures that we are running on the CLI, and collects basic settings
  * like collecting our command line arguments into a pretty array.
  */
 public function __construct()
 {
     parent::__construct();
     // Restrict usage to the command line.
     if (!is_cli()) {
         show_error(lang('cli_required'));
     }
     // Make sure the CLI library is loaded and ready.
     //        CLI::_init();
 }
Ejemplo n.º 21
0
 /**
  * {@inheridoc}.
  */
 public function register()
 {
     $app = new ConsoleApplication(self::DESCRIPTION, self::VERSION);
     if (is_cli()) {
         foreach (config()->consoles as $console) {
             $app->add(new $console());
         }
     }
     return $app;
 }
Ejemplo n.º 22
0
 public function __construct()
 {
     parent::__construct();
     $this->load->library('tvdb');
     $this->load->library('email');
     // Only allow running from cli
     if (!is_cli()) {
         exit('Only available from cli...');
     }
 }
Ejemplo n.º 23
0
 /**
  * Magic Method __construct
  */
 public function __construct()
 {
     parent::__construct();
     // Only allow Command-Line-Interface-requests, no external requests
     if (!is_cli()) {
         show_404();
         die;
         // for safety reasons if show_404() won't work as expected or properly.
     }
 }
Ejemplo n.º 24
0
 function __construct()
 {
     parent::__construct();
     if (!is_cli()) {
         show_error('CLI request only.');
     }
     $this->load->helper('cron');
     echo 'Scheduled Message' . PHP_EOL;
     $this->load->library('lib_request_scheduled');
 }
Ejemplo n.º 25
0
 /**
  * {@inheritdoc}
  */
 public function __construct($options)
 {
     parent::__construct($options);
     if (!is_cli()) {
         if (isset($options['session_storage']) === false) {
             $options['session_storage'] = url_trimmer(config()->path->storage . '/session');
         }
         session_save_path($options['session_storage']);
         session_set_cookie_params($options['lifetime'], $options['path'], $options['domain'], $options['secure'], $options['httponly']);
     }
 }
Ejemplo n.º 26
0
 public function __construct()
 {
     $test = CI_TestCase::instance();
     $cls =& $test->ci_core_class('cfg');
     // set predictable config values
     $test->ci_set_config(array('index_page' => 'index.php', 'base_url' => 'http://example.com/', 'subclass_prefix' => 'MY_', 'enable_query_strings' => FALSE, 'permitted_uri_chars' => 'a-z 0-9~%.:_\\-'));
     $this->config = new $cls();
     if ($this->config->item('enable_query_strings') !== TRUE or is_cli()) {
         $this->_permitted_uri_chars = $this->config->item('permitted_uri_chars');
     }
 }
Ejemplo n.º 27
0
 protected function getRequestUri($bus)
 {
     $uri = isset($_SERVER["REQUEST_URI"]) ? $_SERVER["REQUEST_URI"] : "/";
     if (!is_cli() && isset($_SERVER["SCRIPT_NAME"]) && $_SERVER["SCRIPT_NAME"] !== "/index.php") {
         $bus->set("NO_VIRTUAL_HOST", true);
         $pubdir = substr(RUN_BASE . DS . "public", strlen($_SERVER["DOCUMENT_ROOT"]));
         define("URI_PREFIX", $pubdir);
         $uri = substr(str_replace("/index.php", "", $uri), strlen($pubdir));
     }
     return normalize_uri($uri);
 }
Ejemplo n.º 28
0
 public function pull_project()
 {
     if (!is_cli()) {
         echo 'This controller must run from command line interface only.' . PHP_EOL;
         return;
     }
     exec('git pull');
     exec('chown ' . getmyuid() . ':' . getmygid() . ' ' . FCPATH . '.. -R');
     exec('chmod 0777 ' . APPPATH . 'cache');
     exec('chmod 0777 ' . APPPATH . 'logs');
 }
Ejemplo n.º 29
0
 public function execute(Sabel_Bus $bus)
 {
     Sabel_Db_Config::initialize($bus->getConfig("database"));
     if (!is_cli() && ($session = $bus->get("session")) !== null) {
         $session->start();
         l("START SESSION: " . $session->getName() . "=" . $session->getId());
     }
     // default page title.
     if ($response = $bus->get("response")) {
         $response->setResponse("pageTitle", "Sabel");
     }
 }
Ejemplo n.º 30
0
 /**
  * Class constructor
  *
  * @param	array	$params	Configuration parameters
  * @return	void
  */
 public function __construct(array $params = array())
 {
     // No sessions under CLI
     if (is_cli()) {
         log_message('debug', 'Session: Initialization under CLI aborted.');
         return;
     } elseif ((bool) ini_get('session.auto_start')) {
         log_message('error', 'Session: session.auto_start is enabled in php.ini. Aborting.');
         return;
     } elseif (!empty($params['driver'])) {
         $this->_driver = $params['driver'];
         unset($params['driver']);
     } elseif ($driver = config_item('sess_driver')) {
         $this->_driver = $driver;
     } elseif (config_item('sess_use_database')) {
         log_message('debug', 'Session: "sess_driver" is empty; using BC fallback to "sess_use_database".');
         $this->_driver = 'database';
     }
     $class = $this->_ci_load_classes($this->_driver);
     // Configuration ...
     $this->_configure($params);
     $this->_config['_sid_regexp'] = $this->_sid_regexp;
     $class = new $class($this->_config);
     if ($class instanceof SessionHandlerInterface) {
         if (is_php('5.4')) {
             session_set_save_handler($class, TRUE);
         } else {
             session_set_save_handler(array($class, 'open'), array($class, 'close'), array($class, 'read'), array($class, 'write'), array($class, 'destroy'), array($class, 'gc'));
             register_shutdown_function('session_write_close');
         }
     } else {
         log_message('error', "Session: Driver '" . $this->_driver . "' doesn't implement SessionHandlerInterface. Aborting.");
         return;
     }
     // Sanitize the cookie, because apparently PHP doesn't do that for userspace handlers
     if (isset($_COOKIE[$this->_config['cookie_name']]) && (!is_string($_COOKIE[$this->_config['cookie_name']]) or !preg_match('#\\A' . $this->_sid_regexp . '\\z#', $_COOKIE[$this->_config['cookie_name']]))) {
         unset($_COOKIE[$this->_config['cookie_name']]);
     }
     session_start();
     // Is session ID auto-regeneration configured? (ignoring ajax requests)
     if ((empty($_SERVER['HTTP_X_REQUESTED_WITH']) or strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) !== 'xmlhttprequest') && ($regenerate_time = config_item('sess_time_to_update')) > 0) {
         if (!isset($_SESSION['__ci_last_regenerate'])) {
             $_SESSION['__ci_last_regenerate'] = time();
         } elseif ($_SESSION['__ci_last_regenerate'] < time() - $regenerate_time) {
             $this->sess_regenerate((bool) config_item('sess_regenerate_destroy'));
         }
     } elseif (isset($_COOKIE[$this->_config['cookie_name']]) && $_COOKIE[$this->_config['cookie_name']] === session_id()) {
         setcookie($this->_config['cookie_name'], session_id(), empty($this->_config['cookie_lifetime']) ? 0 : time() + $this->_config['cookie_lifetime'], $this->_config['cookie_path'], $this->_config['cookie_domain'], $this->_config['cookie_secure'], TRUE);
     }
     $this->_ci_init_vars();
     log_message('info', "Session: Class initialized using '" . $this->_driver . "' driver.");
 }