Beispiel #1
0
 public function action_apibuild()
 {
     $random_password = $this->_generate_random_string();
     $api_email = "*****@*****.**";
     // Create User
     $auth_user_create = new Beans_Auth_User_Create($this->_beans_data_auth((object) array('name' => "API Access", 'email' => $api_email, 'role_code' => "api", 'password' => $random_password)));
     $auth_user_create_result = $auth_user_create->execute();
     if (!$auth_user_create_result->success) {
         return $this->_return_error($this->_beans_result_get_error($auth_user_create_result));
     }
     $auth_login = new Beans_Auth_Login((object) array('email' => $api_email, 'password' => $random_password));
     $auth_login_result = $auth_login->execute();
     if (!$auth_login_result->success) {
         return $this->_return_error($this->_beans_result_get_error($auth_login_result));
     }
     $html = new View_Partials_Setup_Users_Api();
     $html->auth = $auth_login_result->data->auth;
     $auth_login_result->data->auth->html = $html->render();
     $this->_return_object->data->auth = $auth_login_result->data->auth;
 }
Beispiel #2
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");
 }