Exemple #1
0
 public function action_index()
 {
     // Set up custom error view
     Kohana_Exception::$error_view = 'error/data-provider';
     if ($this->request->method() != 'GET') {
         // Only GET is allowed as FrontlineSms does only GET request
         throw HTTP_Exception::factory(405, 'The :method method is not supported. Supported methods are :allowed_methods', array(':method' => $this->request->method(), ':allowed_methods' => Http_Request::GET))->allowed(Http_Request::GET);
     }
     $provider = DataProvider::factory('frontlinesms');
     // Authenticate the request
     $options = $provider->options();
     if (!isset($options['key']) or empty($options['key'])) {
         throw HTTP_Exception::factory(403, 'Key value has not been configured');
     }
     if (!$this->request->query('key') or $this->request->query('key') != $options['key']) {
         throw HTTP_Exception::factory(403, 'Incorrect or missing key');
     }
     if (!$this->request->query('m')) {
         throw HTTP_Exception::factory(403, 'Missing message');
     }
     // Remove Non-Numeric characters because that's what the DB has
     $from = preg_replace('/\\D+/', "", $this->request->post('from'));
     $message_text = $this->request->query('m');
     // If receiving an SMS Message
     if ($from and $message_text) {
         $provider->receive(Message_Type::SMS, $from, $message_text, $to);
     }
     $json = array('payload' => array('success' => TRUE, 'error' => NULL));
     // Set the correct content-type header
     $this->response->headers('Content-Type', 'application/json');
     $this->response->body(json_encode($json));
 }
Exemple #2
0
 public function action_index()
 {
     // Set up custom error view
     Kohana_Exception::$error_view = 'error/data-provider';
     //Check if data provider is available
     $providers_available = Kohana::$config->load('features.data-providers');
     if (!$providers_available['smssync']) {
         throw HTTP_Exception::factory(403, 'The SMS Sync data source is not currently available. It can be accessed by upgrading to a higher Ushahidi tier.');
     }
     $methods_with_http_request = [Http_Request::POST, Http_Request::GET];
     if (!in_array($this->request->method(), $methods_with_http_request)) {
         // Only POST or GET is allowed
         throw HTTP_Exception::factory(405, 'The :method method is not supported. Supported methods are :allowed_methods', array(':method' => $this->request->method(), ':allowed_methods' => implode(',', $methods_with_http_request)))->allowed($methods_with_http_request);
     }
     $this->_provider = DataProvider::factory('smssync');
     $this->options = $this->_provider->options();
     // Ensure we're always returning a payload..
     // This will be overwritten later if incoming or task methods are run
     $this->_json['payload'] = ['success' => TRUE, 'error' => NULL];
     // Process incoming messages from SMSSync only if the request is POST
     if ($this->request->method() == 'POST') {
         $this->_incoming();
     }
     // Attempt Task if request is GET and task type is 'send'
     if ($this->request->method() == 'GET' and $this->request->query('task') == 'send') {
         $this->_task();
     }
     // Set the response
     $this->_set_response();
 }
Exemple #3
0
 /**
  * Inline exception handler.
  *
  * @param   Exception  exception object
  * @return  string
  * @uses    Arr::get
  * @uses    Kohana::find_file
  * @uses    Kohana_Exception::handler
  * @uses    Kohana_Exception::text
  */
 function kandler(Exception $e)
 {
     try {
         // Get error code
         $code = $e->getCode();
         // Retrieve Kandler's config
         $config = Kohana::$config->load('kandler');
         // Use views defined by user or use default
         $view = Arr::get($config->errors, $code, $code);
         // Create path to error view
         $path = $config->path . DIRECTORY_SEPARATOR . $view;
         if (Kohana::find_file('views', $path)) {
             // Set an exception view
             Kohana_Exception::$error_view = $path;
         }
         // Handle an exception using Kohana's handler
         Kohana_Exception::handler($e);
     } catch (Exception $e) {
         return Kohana_Exception::text($e);
     }
 }
Exemple #4
0
 public function action_index()
 {
     // Set up custom error view
     Kohana_Exception::$error_view = 'error/data-provider';
     $methods_with_http_request = [Http_Request::POST, Http_Request::GET];
     if (!in_array($this->request->method(), $methods_with_http_request)) {
         // Only POST or GET is allowed
         throw HTTP_Exception::factory(405, 'The :method method is not supported. Supported methods are :allowed_methods', array(':method' => $this->request->method(), ':allowed_methods' => implode(',', $methods_with_http_request)))->allowed($methods_with_http_request);
     }
     $this->_provider = DataProvider::factory('smssync');
     $this->options = $this->_provider->options();
     // Process incoming messages from SMSSync only if the request is POST
     if ($this->request->method() == 'POST') {
         $this->_incoming();
     }
     // Attempt Task if request is GET and task type is 'send'
     if ($this->request->method() == 'GET' and $this->request->query('task') == 'send') {
         $this->_task();
     }
     // Set the response
     $this->_set_response();
 }
Exemple #5
0
/**
 * Set Kohana::$environment if a 'KOHANA_ENV' environment variable has been supplied.
 *
 * Note: If you supply an invalid environment name, a PHP warning will be thrown
 * saying "Couldn't find constant Kohana::<INVALID_ENV_NAME>"
 */
if (strpos($_SERVER['HTTP_HOST'], 'savvyled.pl') !== false || $_SERVER['HTTP_HOST'] == 'localhost') {
    Kohana::$environment = Kohana::DEVELOPMENT;
} else {
    Kohana::$environment = Kohana::PRODUCTION;
}
if (isset($_SERVER['KOHANA_ENV'])) {
    Kohana::$environment = constant('Kohana::' . strtoupper($_SERVER['KOHANA_ENV']));
}
if (Kohana::$environment == Kohana::PRODUCTION) {
    Kohana_Exception::$error_view = 'Exception';
}
/**
 * Initialize Kohana, setting the default options.
 *
 * The following options are available:
 *
 * - string   base_url    path, and optionally domain, of your application   NULL
 * - string   index_file  name of your index file, usually "index.php"       index.php
 * - string   charset     internal character set used for input and output   utf-8
 * - string   cache_dir   set the internal cache directory                   APPPATH/cache
 * - integer  cache_life  lifetime, in seconds, of items cached              60
 * - boolean  errors      enable or disable error handling                   TRUE
 * - boolean  profile     enable or disable internal profiling               TRUE
 * - boolean  caching     enable or disable internal caching                 FALSE
 * - boolean  expose      set the X-Powered-By header                        FALSE
Exemple #6
0
<?php

if (PHP_SAPI == 'cli') {
    Kohana_Exception::$error_view = 'errors/cli_generic_error';
} elseif (Kohana::$environment < Kohana::DEVELOPMENT) {
    // By default, friendlier error with sanitised trace
    Kohana_Exception::$error_view = 'errors/web_generic_error';
}
Exemple #7
0
 * - integer  cache_life  lifetime, in seconds, of items cached              60
 * - boolean  errors      enable or disable error handling                   TRUE
 * - boolean  profile     enable or disable internal profiling               TRUE
 * - boolean  caching     enable or disable internal caching                 FALSE
 * - boolean  expose      set the X-Powered-By header                        FALSE
 */
if (in_array(@$_SERVER['SERVER_NAME'], array('127.0.0.1', 'fe80::1', '::1', 'localhost', '192.168.2.164', '192.168.0.123', '10.48.176.31', '155.133.44.94')) || strpos($_SERVER['SERVER_NAME'], 'ngrok.io')) {
    $init = array('base_url' => "/michales", 'index_file' => "index.php", 'errors' => TRUE, 'profile' => Kohana::$environment === Kohana::DEVELOPMENT);
    Kohana::$environment = Kohana::DEVELOPMENT;
} elseif ($_SERVER['SERVER_NAME'] == "michal.es" || $_SERVER['SERVER_NAME'] == "rookgaard.pl") {
    $init = array('base_url' => "/serwis", 'index_file' => "index.php", 'errors' => TRUE, 'profile' => Kohana::$environment === Kohana::PRODUCTION);
    //	Kohana_Exception::$error_view = 'errors/general';
    Kohana::$environment = Kohana::PRODUCTION;
} else {
    $init = array('base_url' => "/", 'index_file' => FALSE, 'errors' => FALSE, 'profile' => Kohana::$environment === Kohana::PRODUCTION);
    Kohana_Exception::$error_view = 'errors/general';
    Kohana::$environment = Kohana::PRODUCTION;
}
Kohana::init($init);
/**
 * Setting Cookie::$salt
 */
Cookie::$salt = '29961408e9a1bbbf0456dd913a12d31fffa587cc';
/**
 * Attach the file write to logging. Multiple writers are supported.
 */
Kohana::$log->attach(new Log_File(APPPATH . 'logs'));
/**
 * Attach a file reader to config. Multiple readers are supported.
 */
Kohana::$config->attach(new Config_File());