Esempio n. 1
0
 public function dosetupAction()
 {
     $this->view->headTitle('Configuration');
     $_user_config_file = APPLICATION_PATH . '/configs/config.ini';
     // Create the config ini from session
     $setup_session = new Zend_Session_Namespace('gd_setup_session');
     if (!$setup_session->complete) {
         $config = new Zend_Config(array(), true);
         $config->database = array();
         $config->database->adapter = "PDO_MYSQL";
         $config->database->host = $setup_session->database->host;
         $config->database->username = $setup_session->database->username;
         $config->database->password = $setup_session->database->password;
         $config->database->dbname = $setup_session->database->dbname;
         $writer_opts = array('config' => $config, 'filename' => $_user_config_file);
         $writer = new Zend_Config_Writer_Ini($writer_opts);
         try {
             $writer->write();
         } catch (Exception $ex) {
             if (strpos($ex->getMessage(), 'Could not write to file') !== false) {
                 $setup_session->ini_string = $writer->render();
             }
         }
         // Load the database manually
         Zend_Db_Table::setDefaultAdapter(Zend_Db::factory($config->database->adapter, $config->database->toArray()));
         // Run the appropriate database setup script
         $db_adm = new GD_Db_Admin($config->database->host, $config->database->username, $config->database->password, $config->database->dbname);
         $db_adm->installDatabase();
         // Set the other config values into database
         GD_Config::set("language", $setup_session->language ? $setup_session->language : "english");
         GD_Config::set("setup_complete", "1");
         GD_Config::set("cryptkey", md5(microtime() . $setup_session->admin->username . $setup_session->admin->password));
         GD_Config::set("install_date", date("d/m/Y H:i:s"));
         // Create the first user in the database
         $userMapper = new GD_Model_UsersMapper();
         $crypt = new GD_Crypt();
         $user = new GD_Model_User();
         $user->setName($setup_session->admin->username)->setPassword($crypt->makeHash($setup_session->admin->password))->setDateAdded(date('Y-m-d H:i:s'))->setAdmin(1)->enableUser();
         $userMapper->save($user);
         // Setup the SSH keypair
         $ssh_key = new GD_Model_SSHKey();
         $ssh_key->setSSHKeyTypesId(1);
         $ssh_key->generateKeyPair();
         //$ssh_key->setId(1);
         $ssh_keys_map = new GD_Model_SSHKeysMapper();
         $ssh_key_id = $ssh_keys_map->save($ssh_key);
         GD_Config::set("ssh_key_id", $ssh_key_id);
         $setup_session->complete = true;
     }
     if (isset($setup_session->ini_string)) {
         $this->view->ini = $setup_session->ini_string;
     } else {
         $this->_redirect("/setup/complete");
     }
 }
Esempio n. 2
0
 /**
  * Implement this by setting $obj values (e.g. $obj->setId($row->Id) from a DB row
  * @param GD_Model_User $obj
  * @param Zend_Db_Table_Row_Abstract $row
  */
 protected function populateObjectFromRow(&$obj, Zend_Db_Table_Row_Abstract $row)
 {
     $obj->setId($row->id)->setName($row->name)->setPassword($row->password)->setDateAdded($row->date_added)->setDateUpdated($row->date_updated)->setDateDisabled($row->date_disabled)->setAdmin($row->admin)->setActive($row->active);
 }