Ejemplo n.º 1
0
 /**
  * Create the database and write system files
  * @throws \Exception
  */
 public function up()
 {
     /**
      * @var \stack\Context $context
      */
     $context = \lean\Registry::instance()->get('stack.context');
     $shell = $context->getShell();
     $context->pushSecurity(new \stack\security\PriviledgedSecurity());
     // LOGIN
     $file = $shell->readFile(\stack\Root::ROOT_PATH);
     $file->setModule(new \stack\module\web\Login());
     $file->addPermission(new \stack\security\Permission_All(\stack\Security_Priviledge::READ));
     $file->addPermission(new \stack\security\Permission_All(\stack\Security_Priviledge::EXECUTE));
     $shell->writeFile($file);
     // STATIC FILES
     $path = '/static';
     $file = new \stack\filesystem\File($path, \stack\Root::ROOT_UNAME);
     $file->setModule(new \stack\module\web\StaticFiles());
     $file->addPermission(new \stack\security\Permission_All(\stack\Security_Priviledge::READ));
     $file->addPermission(new \stack\security\Permission_All(\stack\Security_Priviledge::EXECUTE));
     $shell->writeFile($file);
     // ROOT HOME FILE
     $file = $shell->readFile(Root::ROOT_PATH_HOME . '/' . Root::ROOT_UNAME);
     $file->setModule(new \stack\module\web\Browser());
     $shell->writeFile($file);
     $context->pullSecurity();
 }
Ejemplo n.º 2
0
 /**
  * Create the database and write system files
  * @throws \Exception
  */
 public function up()
 {
     /**
      * @param Context $context
      */
     $context = \lean\Registry::instance()->get('stack.context');
     $shell = $context->getShell();
     $shell->init();
     // create initial files
     $files = array(Root::ROOT_PATH_SYSTEM, Root::ROOT_PATH_RUN, Root::ROOT_PATH_USERS, Root::ROOT_PATH_GROUPS, Root::ROOT_PATH_HOME, Root::ROOT_PATH_HOME . '/' . Root::ROOT_UNAME);
     $context->pushSecurity(new \stack\security\PriviledgedSecurity());
     $file = new \stack\filesystem\File(Root::ROOT_PATH, Root::ROOT_UNAME);
     $shell->writeFile($file);
     $file->addPermission(new \stack\security\Permission_All(Security_Priviledge::READ));
     try {
         foreach ($files as $path) {
             $file = new \stack\filesystem\File($path, Root::ROOT_UNAME);
             $shell->writeFile($file);
         }
         // create root user file + module
         $file = new \stack\filesystem\File(Root::ROOT_PATH_USERS_ROOT, Root::ROOT_UNAME);
         $user = new \stack\module\User(Root::ROOT_UNAME, Root::ROOT_PATH_HOME . '/' . Root::ROOT_UNAME);
         $password = sha1(uniqid());
         $user->changePassword($password);
         $file->setModule($user);
         $shell->writeFile($file);
         file_put_contents(APPLICATION_ROOT_PATH . '/rootpw', $password);
         // create system run files
         $modules = array('adduser' => new \stack\module\run\AddUser($shell), 'deluser' => new \stack\module\run\DelUser($shell), 'addgroup' => new \stack\module\run\AddGroup($shell), 'delgroup' => new \stack\module\run\DelGroup($shell));
         foreach ($modules as $name => $module) {
             $path = Root::ROOT_PATH_RUN . "/{$name}";
             $file = new \stack\filesystem\File($path, Root::ROOT_UNAME);
             $file->setModule($module);
             $shell->writeFile($file);
         }
     } catch (\Exception $e) {
         $context->pullSecurity();
         throw $e;
     }
     $context->pullSecurity();
 }