Ejemplo n.º 1
0
 public function __construct()
 {
     parent::__construct();
     // Load argc and argv
     $argc = Arr::get($_SERVER, 'argc') - 3;
     $argv = array_slice(Arr::get($_SERVER, 'argv'), 3);
     if ($argc > 0) {
         $extends = CLI::options('i');
         $extends = Arr::get($extends, 'i');
         $generate_all = CLI::options('i');
         for ($i = 0; $i < $argc; $i++) {
             if (strpos($argv[$i], '--') !== FALSE) {
                 unset($argv[$i]);
             }
         }
         $filename = Arr::get($argv, 0);
         $methods = array_slice($argv, 1);
         $this->generate($filename, $methods, $extends);
         if ($generate_all) {
             new Terminal_Model();
             new Terminal_View();
         }
     } else {
         $str = 'Missing controller name.';
         echo Terminal::color($str, 'red') . PHP_EOL;
     }
 }
Ejemplo n.º 2
0
 public function before()
 {
     if (!Kohana::$is_cli) {
         Request::instance()->redirect('/');
         exit;
     }
     $auth = CLI::options('username', 'password');
     $user = ORM::factory('user');
     $status = $user->login($auth);
     if (!$status) {
         echo "You did not authenticate.\n";
         exit;
     }
 }
Ejemplo n.º 3
0
 /**
  * Prevent Minion from being run over http
  */
 public function before()
 {
     if (!Kohana::$is_cli) {
         throw new Kohana_Exception("Minion can only be ran from the cli");
     }
     $this->_task = $this->request->param('task');
     $options = CLI::options('help', 'task');
     if (array_key_exists('help', $options)) {
         $this->request->action('help');
     }
     if (!empty($options['task'])) {
         $this->_task = $options['task'];
     }
     return parent::before();
 }
Ejemplo n.º 4
0
 public function __construct()
 {
     parent::__construct();
     // Load argc and argv
     $argc = Arr::get($_SERVER, 'argc') - 3;
     $argv = array_slice(Arr::get($_SERVER, 'argv'), 3);
     if ($argc > 0) {
         // Get model file
         $filename = Arr::get($argv, 0);
         // Get model extends
         $extends = CLI::options('e');
         $extends = Arr::get($extends, 'e');
         $this->generate($filename, $extends);
     } else {
         $str = 'Missing model name.';
         echo Terminal::color($str, 'red') . PHP_EOL;
     }
 }
Ejemplo n.º 5
0
 /**
  * Creates a new request object for the given URI. New requests should be
  * created using the [Request::instance] or [Request::factory] methods.
  *
  *     $request = Request::factory($uri);
  *
  * If $cache parameter is set, the response for the request will attempt to
  * be retrieved from the cache.
  *
  * @param   string  $uri URI of the request
  * @param   Cache   $cache
  * @param   array   $injected_routes an array of routes to use, for testing
  * @return  void
  * @throws  Request_Exception
  * @uses    Route::all
  * @uses    Route::matches
  */
 public static function factory($uri = TRUE, HTTP_Cache $cache = NULL, $injected_routes = array())
 {
     // If this is the initial request
     if (!Request::$initial) {
         if (Kohana::$is_cli) {
             // Default protocol for command line is cli://
             $protocol = 'cli';
             // Get the command line options
             $options = CLI::options('uri', 'method', 'get', 'post', 'referrer');
             if (isset($options['uri'])) {
                 // Use the specified URI
                 $uri = $options['uri'];
             } elseif ($uri === TRUE) {
                 $uri = '';
             }
             if (isset($options['method'])) {
                 // Use the specified method
                 $method = strtoupper($options['method']);
             } else {
                 // Default to GET requests
                 $method = HTTP_Request::GET;
             }
             if (isset($options['get'])) {
                 // Overload the global GET data
                 parse_str($options['get'], $_GET);
             }
             if (isset($options['post'])) {
                 // Overload the global POST data
                 parse_str($options['post'], $_POST);
             }
             if (isset($options['referrer'])) {
                 $referrer = $options['referrer'];
             }
         } else {
             if (isset($_SERVER['SERVER_PROTOCOL'])) {
                 $protocol = $_SERVER['SERVER_PROTOCOL'];
             } else {
                 $protocol = HTTP::$protocol;
             }
             if (isset($_SERVER['REQUEST_METHOD'])) {
                 // Use the server request method
                 $method = $_SERVER['REQUEST_METHOD'];
             } else {
                 // Default to GET requests
                 $method = HTTP_Request::GET;
             }
             if (!empty($_SERVER['HTTPS']) and filter_var($_SERVER['HTTPS'], FILTER_VALIDATE_BOOLEAN)) {
                 // This request is secure
                 $secure = TRUE;
             }
             if (isset($_SERVER['HTTP_REFERER'])) {
                 // There is a referrer for this request
                 $referrer = $_SERVER['HTTP_REFERER'];
             }
             if (isset($_SERVER['HTTP_USER_AGENT'])) {
                 // Browser type
                 Request::$user_agent = $_SERVER['HTTP_USER_AGENT'];
             }
             if (isset($_SERVER['HTTP_X_REQUESTED_WITH'])) {
                 // Typically used to denote AJAX requests
                 $requested_with = $_SERVER['HTTP_X_REQUESTED_WITH'];
             }
             if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) and isset($_SERVER['REMOTE_ADDR']) and in_array($_SERVER['REMOTE_ADDR'], Request::$trusted_proxies)) {
                 // Use the forwarded IP address, typically set when the
                 // client is using a proxy server.
                 // Format: "X-Forwarded-For: client1, proxy1, proxy2"
                 $client_ips = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
                 Request::$client_ip = array_shift($client_ips);
                 unset($client_ips);
             } elseif (isset($_SERVER['HTTP_CLIENT_IP']) and isset($_SERVER['REMOTE_ADDR']) and in_array($_SERVER['REMOTE_ADDR'], Request::$trusted_proxies)) {
                 // Use the forwarded IP address, typically set when the
                 // client is using a proxy server.
                 $client_ips = explode(',', $_SERVER['HTTP_CLIENT_IP']);
                 Request::$client_ip = array_shift($client_ips);
                 unset($client_ips);
             } elseif (isset($_SERVER['REMOTE_ADDR'])) {
                 // The remote IP address
                 Request::$client_ip = $_SERVER['REMOTE_ADDR'];
             }
             if ($method !== HTTP_Request::GET) {
                 // Ensure the raw body is saved for future use
                 $body = file_get_contents('php://input');
             }
             if ($uri === TRUE) {
                 // Attempt to guess the proper URI
                 $uri = Request::detect_uri();
             }
         }
         // Create the instance singleton
         Request::$initial = $request = new Request($uri, $cache);
         // Store global GET and POST data in the initial request only
         $request->protocol($protocol)->query($_GET)->post($_POST);
         if (isset($secure)) {
             // Set the request security
             $request->secure($secure);
         }
         if (isset($method)) {
             // Set the request method
             $request->method($method);
         }
         if (isset($referrer)) {
             // Set the referrer
             $request->referrer($referrer);
         }
         if (isset($requested_with)) {
             // Apply the requested with variable
             $request->requested_with($requested_with);
         }
         if (isset($body)) {
             // Set the request body (probably a PUT type)
             $request->body($body);
         }
     } else {
         $request = new Request($uri, $cache, $injected_routes);
     }
     return $request;
 }
Ejemplo n.º 6
0
 public function test_options()
 {
     $expect = array('unittest' => NULL, 'test' => 'foo');
     $this->assert_equal(CLI::options('unittest', 'test'), $expect);
 }
Ejemplo n.º 7
0
 /**
  * Arguments enclosed with quote marks should be allowed to contain
  * spaces
  *
  * @test
  */
 public function test_value_includes_spaces_when_enclosed_with_quotes()
 {
     $options = CLI::options('name');
     $this->assertSame(array('name' => 'Jeremy Taylor'), $options);
 }
Ejemplo n.º 8
0
 /**
  * Main request singleton instance. If no URI is provided, the URI will
  * be automatically detected using PATH_INFO, REQUEST_URI, or PHP_SELF.
  *
  *     $request = Request::instance();
  *
  * @param   string   URI of the request
  * @return  Request
  */
 public static function instance(&$uri = TRUE)
 {
     if (!Request::$instance) {
         if (Kohana::$is_cli) {
             // Default protocol for command line is cli://
             Request::$protocol = 'cli';
             // Get the command line options
             $options = CLI::options('uri', 'method', 'get', 'post');
             if (isset($options['uri'])) {
                 // Use the specified URI
                 $uri = $options['uri'];
             }
             if (isset($options['method'])) {
                 // Use the specified method
                 Request::$method = strtoupper($options['method']);
             }
             if (isset($options['get'])) {
                 // Overload the global GET data
                 parse_str($options['get'], $_GET);
             }
             if (isset($options['post'])) {
                 // Overload the global POST data
                 parse_str($options['post'], $_POST);
             }
         } else {
             if (isset($_SERVER['REQUEST_METHOD'])) {
                 // Use the server request method
                 Request::$method = $_SERVER['REQUEST_METHOD'];
             }
             if (!empty($_SERVER['HTTPS']) and filter_var($_SERVER['HTTPS'], FILTER_VALIDATE_BOOLEAN)) {
                 // This request is secure
                 Request::$protocol = 'https';
             }
             if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) and strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest') {
                 // This request is an AJAX request
                 Request::$is_ajax = TRUE;
             }
             if (isset($_SERVER['HTTP_REFERER'])) {
                 // There is a referrer for this request
                 Request::$referrer = $_SERVER['HTTP_REFERER'];
             }
             if (isset($_SERVER['HTTP_USER_AGENT'])) {
                 // Set the client user agent
                 Request::$user_agent = $_SERVER['HTTP_USER_AGENT'];
             }
             if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
                 // Use the forwarded IP address, typically set when the
                 // client is using a proxy server.
                 Request::$client_ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
             } elseif (isset($_SERVER['HTTP_CLIENT_IP'])) {
                 // Use the forwarded IP address, typically set when the
                 // client is using a proxy server.
                 Request::$client_ip = $_SERVER['HTTP_CLIENT_IP'];
             } elseif (isset($_SERVER['REMOTE_ADDR'])) {
                 // The remote IP address
                 Request::$client_ip = $_SERVER['REMOTE_ADDR'];
             }
             if (Request::$method !== 'GET' and Request::$method !== 'POST') {
                 // Methods besides GET and POST do not properly parse the form-encoded
                 // query string into the $_POST array, so we overload it manually.
                 parse_str(file_get_contents('php://input'), $_POST);
             }
             if ($uri === TRUE) {
                 if (!empty($_SERVER['PATH_INFO'])) {
                     // PATH_INFO does not contain the docroot or index
                     $uri = $_SERVER['PATH_INFO'];
                 } else {
                     // REQUEST_URI and PHP_SELF include the docroot and index
                     if (isset($_SERVER['REQUEST_URI'])) {
                         // REQUEST_URI includes the query string, remove it
                         $uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
                     } elseif (isset($_SERVER['PHP_SELF'])) {
                         $uri = $_SERVER['PHP_SELF'];
                     } elseif (isset($_SERVER['REDIRECT_URL'])) {
                         $uri = $_SERVER['REDIRECT_URL'];
                     } else {
                         // If you ever see this error, please report an issue at and include a dump of $_SERVER
                         // http://dev.kohanaphp.com/projects/kohana3/issues
                         throw new Kohana_Exception('Unable to detect the URI using PATH_INFO, REQUEST_URI, or PHP_SELF');
                     }
                     // Get the path from the base URL, including the index file
                     $base_url = parse_url(Kohana::$base_url, PHP_URL_PATH);
                     if (strpos($uri, $base_url) === 0) {
                         // Remove the base URL from the URI
                         $uri = substr($uri, strlen($base_url));
                     }
                     if (Kohana::$index_file and strpos($uri, Kohana::$index_file) === 0) {
                         // Remove the index file from the URI
                         $uri = substr($uri, strlen(Kohana::$index_file));
                     }
                 }
             }
         }
         // Reduce multiple slashes to a single slash
         $uri = preg_replace('#//+#', '/', $uri);
         // Remove all dot-paths from the URI, they are not valid
         $uri = preg_replace('#\\.[\\s./]*/#', '', $uri);
         // Create the instance singleton
         Request::$instance = Request::$current = new Request($uri);
         // Add the default Content-Type header
         Request::$instance->headers['Content-Type'] = 'text/html; charset=' . Kohana::$charset;
     }
     return Request::$instance;
 }
Ejemplo n.º 9
0
 /**
  * 
  * @test
  * @covers CLI::options
  * @ticket 2642
  */
 function testCliOnlySplitsOnTheFirstEquals()
 {
     $options = CLI::options('important');
     $this->assertSame(1, count($options));
     $this->assertSame('something=true', reset($options));
 }
Ejemplo n.º 10
0
	/**
	 * Main request singleton instance. If no URI is provided, the URI will
	 * be automatically detected.
	 *
	 *     $request = Request::instance();
	 *
	 * @param   string   URI of the request
	 * @return  Request
	 * @uses    Request::detect_uri
	 */
	public static function instance( & $uri = TRUE)
	{
		if ( ! Request::$instance)
		{
			if (Kohana::$is_cli)
			{
				// Default protocol for command line is cli://
				Request::$protocol = 'cli';

				// Get the command line options
				$options = CLI::options('uri', 'method', 'get', 'post');

				if (isset($options['uri']))
				{
					// Use the specified URI
					$uri = $options['uri'];
				}

				if (isset($options['method']))
				{
					// Use the specified method
					Request::$method = strtoupper($options['method']);
				}

				if (isset($options['get']))
				{
					// Overload the global GET data
					parse_str($options['get'], $_GET);
				}

				if (isset($options['post']))
				{
					// Overload the global POST data
					parse_str($options['post'], $_POST);
				}
			}
			else
			{
				if (isset($_SERVER['REQUEST_METHOD']))
				{
					// Use the server request method
					Request::$method = $_SERVER['REQUEST_METHOD'];
				}

				if ( ! empty($_SERVER['HTTPS']) AND filter_var($_SERVER['HTTPS'], FILTER_VALIDATE_BOOLEAN))
				{
					// This request is secure
					Request::$protocol = 'https';
				}

				if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) AND strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest')
				{
					// This request is an AJAX request
					Request::$is_ajax = TRUE;
				}

				if (isset($_SERVER['HTTP_REFERER']))
				{
					// There is a referrer for this request
					Request::$referrer = $_SERVER['HTTP_REFERER'];
				}

				if (isset($_SERVER['HTTP_USER_AGENT']))
				{
					// Set the client user agent
					Request::$user_agent = $_SERVER['HTTP_USER_AGENT'];
				}

				if (isset($_SERVER['HTTP_X_FORWARDED_FOR']))
				{
					// Use the forwarded IP address, typically set when the
					// client is using a proxy server.
					Request::$client_ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
				}
				elseif (isset($_SERVER['HTTP_CLIENT_IP']))
				{
					// Use the forwarded IP address, typically set when the
					// client is using a proxy server.
					Request::$client_ip = $_SERVER['HTTP_CLIENT_IP'];
				}
				elseif (isset($_SERVER['REMOTE_ADDR']))
				{
					// The remote IP address
					Request::$client_ip = $_SERVER['REMOTE_ADDR'];
				}

				if (Request::$method !== 'GET' AND Request::$method !== 'POST')
				{
					// Methods besides GET and POST do not properly parse the form-encoded
					// query string into the $_POST array, so we overload it manually.
					parse_str(file_get_contents('php://input'), $_POST);
				}

				if ($uri === TRUE)
				{
					$uri = Request::detect_uri();
				}
			}

			// Reduce multiple slashes to a single slash
			$uri = preg_replace('#//+#', '/', $uri);

			// Remove all dot-paths from the URI, they are not valid
			$uri = preg_replace('#\.[\s./]*/#', '', $uri);

			// Create the instance singleton
			Request::$instance = Request::$current = new Request($uri);

			// Add the default Content-Type header
			Request::$instance->headers['Content-Type'] = 'text/html; charset='.Kohana::$charset;
		}

		return Request::$instance;
	}
Ejemplo n.º 11
0
 /**
  * It will send notifications to users if their search params match
  * 1000 emails at a time.
  */
 public function action_send_notifications()
 {
     // Get CLI params
     $options = CLI::options('frequency');
     // Die if no --frequency= param is not found or not a number
     if (!isset($options['frequency']) || !is_numeric($options['frequency'])) {
         die("Insuficient params.\n");
     }
     // Get all users with the correct frequency number
     if ($options['frequency'] == 0) {
         $time_interval = strtotime("-1 day");
         $title = 'Daily';
         $frequency_type = 'day';
     } else {
         $time_interval = strtotime("-1 week");
         $title = 'Weekly';
         $frequency_type = 'week';
     }
     // Execute query
     $rows = ORM::factory('mailinglist')->where('frequency', '=', $options['frequency'])->where(DB::expr('UNIX_TIMESTAMP(last_checked)'), '<=', $time_interval)->limit(1000)->find_all();
     // If no rows found die
     if (!count($rows) > 0) {
         die("No rows to process.\n");
     }
     // Updates all rows tothe current date, to avoid sending duplication
     // from other cron workers
     foreach ($rows as $row) {
         $current_row = ORM::factory('mailinglist', $row->id);
         $current_row->last_checked = date("Y-m-d h:i:s", strtotime("now"));
         $current_row->save();
     }
     // Start fetching data and send to users
     foreach ($rows as $row) {
         // Tries to unserialize search string, if something's wrong
         // the row will be deleted
         try {
             // Conver string into an array
             $search_array = unserialize($row->saved_search);
         } catch (Exception $e) {
             echo 'Invalid search_array: ' . $e->getMessage() . "\n";
             $row->delete();
             continue;
         }
         // Tries to fetch ads from search engine
         try {
             // Fetch data from database
             $ads = Model_Ad::search(array('search_string' => arr::get($search_array, 'search_string'), 'offset' => 0, 'created_after' => $time_interval, 'telecommute' => arr::get($search_array, 'telecommute'), 'jobboard_id' => arr::get($search_array, 'jobtype_id'), 'category_id' => arr::get($search_array, 'category_id'), 'jobtype_id' => arr::get($search_array, 'jobtype_id'), 'fields' => array('id', 'title', 'telecommute', 'jobtype_id', 'description', 'company_name', 'company_logo', 'highlight', 'location', 'created_at', 'jobboard_id')));
         } catch (Exception $e) {
             echo 'Could not get any data from search server: ' . $e->getMessage() . "\n";
         }
         // Prepares the email
         if ($ads['total'] > 0) {
             foreach ($ads['rows'] as $key => $ad) {
                 $ads['rows'][$key]['link'] = $ads['rows'][$key]['url'];
                 $ads['rows'][$key]['description'] = $ads['rows'][$key]['description'];
                 unset($ads['rows'][$key]['url']);
             }
             $filter = arr::get($search_array, 'search_string');
             if (arr::get($search_array, 'telecommute')) {
                 $filter .= ", Telecommute";
             }
             if (arr::get($search_array, 'jobtype_id')) {
                 $jobtype = ORM::factory('jobtype', arr::get($search_array, 'jobtype_id'));
                 $filter .= ", " . $jobtype->name;
             }
             if (arr::get($search_array, 'category_id')) {
                 $category = ORM::factory('category', arr::get($search_array, 'category_id'));
                 $filter .= ", " . $category->name;
             }
             $template = View::factory('emails/mailing', array('ads' => $ads, 'title' => $title . " Report", 'frequency_type' => $frequency_type, 'filter' => $filter, 'unsubscribe_link' => "http://" . Helper_Utils::get_server_domain() . "/mailinglist/remove/?email=" . $row->email . "&id=" . $row->id))->render();
             // Send it to user
             $this->config = Kohana::$config->load('application');
             $this->config['global']['email_feed'];
             Email::send($row->email, $this->config['global']['email_feed'], $title . " Report", $template, TRUE);
         }
     }
     exit(0);
 }
Ejemplo n.º 12
0
 /**
  * If the argument contains an equals sign then it shouldn't be split
  *
  * @test
  * @ticket 2642
  */
 function test_cli_only_splits_on_the_first_equals()
 {
     $options = CLI::options('important');
     $this->assertSame(1, count($options));
     $this->assertSame('something=true', reset($options));
 }
Ejemplo n.º 13
0
 public static function factory($uri = TRUE, Cache $cache = NULL)
 {
     // If this is the initial request
     if (!Request::$initial) {
         if (Kohana::$is_cli) {
             // Default protocol for command line is cli://
             $protocol = 'cli';
             // Get the command line options
             $options = CLI::options('uri', 'method', 'get', 'post', 'referrer');
             if (isset($options['uri'])) {
                 // Use the specified URI
                 $uri = $options['uri'];
             }
             if (isset($options['method'])) {
                 // Use the specified method
                 $method = strtoupper($options['method']);
             } else {
                 $method = 'GET';
             }
             if (isset($options['get'])) {
                 // Overload the global GET data
                 parse_str($options['get'], $_GET);
             }
             if (isset($options['post'])) {
                 // Overload the global POST data
                 parse_str($options['post'], $_POST);
             }
             if (isset($options['referrer'])) {
                 $referrer = $options['referrer'];
             } else {
                 $referrer = NULL;
             }
         } else {
             if (isset($_SERVER['REQUEST_METHOD'])) {
                 // Use the server request method
                 $method = $_SERVER['REQUEST_METHOD'];
             } else {
                 // Default to GET
                 $method = Http_Request::GET;
             }
             if (!empty($_SERVER['HTTPS']) and filter_var($_SERVER['HTTPS'], FILTER_VALIDATE_BOOLEAN)) {
                 // This request is secure
                 $protocol = 'https';
             } else {
                 $protocol = 'http';
             }
             if (isset($_SERVER['HTTP_REFERER'])) {
                 // There is a referrer for this request
                 $referrer = $_SERVER['HTTP_REFERER'];
             } else {
                 $referrer = NULL;
             }
             if (isset($_SERVER['HTTP_USER_AGENT'])) {
                 // Set the client user agent
                 Request::$user_agent = $_SERVER['HTTP_USER_AGENT'];
             }
             if (isset($_SERVER['HTTP_X_REQUESTED_WITH'])) {
                 $requested_with = $_SERVER['HTTP_X_REQUESTED_WITH'];
             }
             if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
                 // Use the forwarded IP address, typically set when the
                 // client is using a proxy server.
                 Request::$client_ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
             } elseif (isset($_SERVER['HTTP_CLIENT_IP'])) {
                 // Use the forwarded IP address, typically set when the
                 // client is using a proxy server.
                 Request::$client_ip = $_SERVER['HTTP_CLIENT_IP'];
             } elseif (isset($_SERVER['REMOTE_ADDR'])) {
                 // The remote IP address
                 Request::$client_ip = $_SERVER['REMOTE_ADDR'];
             }
             if ($method !== 'GET') {
                 // Ensure the raw body is saved for future use
                 $body = file_get_contents('php://input');
             }
             if ($uri === TRUE) {
                 $uri = Request::detect_uri();
             }
         }
         // Create the instance singleton
         $request = new Request($uri, $cache);
         $request->protocol($protocol)->method($method)->referrer($referrer);
         // Apply the requested with variable
         isset($requested_with) and $request->requested_with($requested_with);
         // If there is a body, set it to the model
         isset($body) and $request->body($body);
     } else {
         $request = new Request($uri, $cache);
     }
     // Create the initial request if it does not exist
     if (!Request::$initial) {
         Request::$initial = $request;
         $request->query($_GET)->post($_POST);
     }
     return $request;
 }
Ejemplo n.º 14
0
 public function action_manual()
 {
     if (!Kohana::$is_cli) {
         $this->request->redirect('/');
     }
     if (!file_exists(APPPATH . 'classes/beans/config.php') or filesize(APPPATH . 'classes/beans/config.php') < 1) {
         die("Error: Missing config.php\n");
     }
     $config_permissions = str_split(substr(decoct(fileperms(APPPATH . 'classes/beans/config.php')), 2));
     if (intval($config_permissions[count($config_permissions) - 3]) > 6 or intval($config_permissions[count($config_permissions) - 2]) > 6 or intval($config_permissions[count($config_permissions) - 1]) > 0) {
         die("Please change the mode on application/classes/beans/config.php to be at least as restrictive as 0660.");
     }
     // Check for required parameters.
     $auth_options = CLI::options('name', 'email', 'password', 'accounts', 'overwritedb', 'temppassword');
     if (!isset($auth_options['name']) || !$auth_options['name']) {
         die("Error: missing required option 'name'\n");
     }
     if (!isset($auth_options['email']) || !$auth_options['email']) {
         die("Error: missing required option 'email'\n");
     }
     if (!isset($auth_options['password']) || !$auth_options['password']) {
         die("Error: missing required option 'password'\n");
     }
     if (!isset($auth_options['accounts']) || !$auth_options['accounts']) {
         $auth_options['accounts'] = "full";
         echo "No default account set option provided, assuming full.\n";
     }
     $tables = DB::query(Database::SELECT, 'SHOW TABLES;')->execute()->as_array();
     if (count($tables) and isset($auth_options['overwritedb']) and $auth_options['overwritedb'] == "yes") {
         $this->_remove_sql_progress();
     } else {
         if (count($tables)) {
             die("Error: database table is not empty.\n");
         }
     }
     // Create Table Structure
     $database_tables_sql = file_get_contents(DOCROOT . 'install_files/database_structure.sql');
     $database_tables = explode(';', $database_tables_sql);
     foreach ($database_tables as $database_table) {
         strlen(trim($database_table)) ? DB::query(NULL, $database_table)->execute() : NULL;
     }
     $beans_setup_init = new Beans_Setup_Init((object) array('auth_uid' => "INSTALL", 'auth_key' => "INSTALL", 'auth_expiration' => "INSTALL", 'default_account_set' => $auth_options['accounts']));
     $beans_setup_init_result = $beans_setup_init->execute();
     if (!$beans_setup_init_result->success) {
         $this->_remove_sql_progress();
         die("Error setting up initial table entries: " . $beans_setup_init_result->auth_error . $beans_setup_init_result->error . "\n");
     }
     // Create Admin Account
     $beans_create_user = new Beans_Auth_User_Create((object) array('auth_uid' => "INSTALL", 'auth_key' => "INSTALL", 'auth_expiration' => "INSTALL", 'name' => $auth_options['name'], 'email' => $auth_options['email'], 'password' => $auth_options['password'], 'password_change' => isset($auth_options['temppassword']) && $auth_options['temppassword'] ? TRUE : FALSE, 'role_code' => 'admin'));
     $beans_create_user_result = $beans_create_user->execute();
     if (!$beans_create_user_result->success) {
         $this->_remove_sql_progress();
         die("Error setting up user account: " . $beans_create_user_result->auth_error . $beans_create_user_result->error);
     }
     die("Success.\n");
 }
Ejemplo n.º 15
0
 /**
  * Main request singleton instance. If no URI is provided, the URI will
  * be automatically detected using PATH_INFO, REQUEST_URI, or PHP_SELF.
  *
  * @param   string   URI of the request
  * @return  Request
  */
 public static function instance($uri = TRUE)
 {
     static $instance;
     if ($instance === NULL) {
         if (Ko::$is_cli) {
             // Default protocol for command line is cli://
             self::$protocol = 'cli';
             // Get the command line options
             $options = CLI::options('uri', 'method', 'get', 'post');
             if (isset($options['uri'])) {
                 // Use the specified URI
                 $uri = $options['uri'];
             }
             if (isset($options['method'])) {
                 // Use the specified method
                 self::$method = strtoupper($options['method']);
             }
             if (isset($options['get'])) {
                 // Overload the global GET data
                 parse_str($options['get'], $_GET);
             }
             if (isset($options['post'])) {
                 // Overload the global POST data
                 parse_str($options['post'], $_POST);
             }
         } else {
             if (isset($_SERVER['REQUEST_METHOD'])) {
                 // Use the server request method
                 self::$method = $_SERVER['REQUEST_METHOD'];
             }
             if (!empty($_SERVER['HTTPS']) and filter_var($_SERVER['HTTPS'], FILTER_VALIDATE_BOOLEAN)) {
                 // This request is secure
                 self::$protocol = 'https';
             }
             if (self::$method !== 'GET' && self::$method !== 'POST') {
                 // Methods besides GET and POST do not properly parse the form-encoded
                 // query string into the $_POST array, so we overload it manually.
                 parse_str(file_get_contents('php://input'), $_POST);
             }
             if ($uri === TRUE) {
                 if (isset($_SERVER['PATH_INFO'])) {
                     $uri = $_SERVER['PATH_INFO'];
                 } else {
                     if (isset($_SERVER['REQUEST_URI'])) {
                         $uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
                     } elseif (isset($_SERVER['PHP_SELF'])) {
                         $uri = $_SERVER['PHP_SELF'];
                     } else {
                         throw new KoException('Unable to detect the URI using PATH_INFO, REQUEST_URI, or PHP_SELF');
                     }
                     // Get the path from the base URL, including the index file
                     $base_url = parse_url(Ko::$base_url, PHP_URL_PATH);
                     if (strpos($uri, $base_url) === 0) {
                         $uri = substr($uri, strlen($base_url));
                     }
                     if (Ko::$index_file && strpos($uri, Ko::$index_file) === 0) {
                         $uri = substr($uri, strlen(Ko::$index_file));
                     }
                 }
             }
         }
         // Reduce multiple slashes to a single slash
         $uri = preg_replace('#//+#', '/', $uri);
         // Remove all dot-paths from the URI, they are not valid
         $uri = preg_replace('#\\.[\\s./]*/#', '', $uri);
         // Create the instance singleton
         $instance = new self($uri);
         // Add the Content-Type header
         $instance->headers['Content-Type'] = 'text/html; charset=' . Ko::$charset;
     }
     return $instance;
 }