Exemplo n.º 1
0
HTTP headers:</br>
FORWARDED_PROTO: <?php 
echo $_SERVER['HTTP_X_FORWARDED_PROTO'];
?>
<br/>
PERMISSIONS: <?php 
echo $_SERVER['HTTP_X_SANDSTORM_PERMISSIONS'];
?>
<br/>
<br/>
Amount of users: <?php 
echo User::all()->count();
?>
<br/>
Amount of notebooks: <?php 
echo Notebook::all()->count();
?>
<br/>
Amount of tags: <?php 
echo Tag::all()->count();
?>
<br/>
Amount of notes: <?php 
echo Note::all()->count();
?>
<br/>
<br/>
Amount of Init Steps: <?php 
echo DB::table('migrations')->where('batch', '=', 1)->count();
?>
<br/>
Exemplo n.º 2
0
 public function checkSandstormUsers()
 {
     if (Config::get('paperwork.emergency_export') && DB::table('migrations')->where('batch', '=', 1)->count() == Config::get('paperwork.emergency_export_count')) {
         $credentials = ["username" => "sandstorm_dummy", "password" => "sandstorm_dummy"];
         if (Auth::attempt($credentials)) {
             $settings = Setting::where('user_id', '=', Auth::user()->id)->first();
             Session::put('ui_language', $settings->ui_language);
             return View::make('user.emergency_export');
         }
     } else {
         // get permission via HTTP_X_SANDSTORM header
         $sandstorm_permissions = $_SERVER['HTTP_X_SANDSTORM_PERMISSIONS'];
         // Only when we are admin, we check and create users
         if ($sandstorm_permissions == "admin,write,read") {
             // check for admin user
             if (User::where('username', '=', 'sandstorm_admin')->count() == 0) {
                 $sandstorm_admin = User::create(Input::except('_token', 'password_confirmation', 'ui_language'));
                 if ($sandstorm_admin) {
                     //make the first user an admin
                     $sandstorm_admin->firstname = "sandstorm_admin";
                     $sandstorm_admin->lastname = " ";
                     $sandstorm_admin->username = "******";
                     $sandstorm_admin->password = "******";
                     $sandstorm_admin->is_admin = 1;
                     $sandstorm_admin->save();
                     $setting_sandstorm_admin = Setting::create(['ui_language' => 'en', 'user_id' => $sandstorm_admin->id]);
                 }
             } else {
                 $sandstorm_admin = User::where('username', '=', 'sandstorm_admin');
             }
             // Then the read & write  user
             if (User::where('username', '=', 'sandstorm_readwrite')->count() == 0) {
                 $sandstorm_readwrite = User::create(Input::except('_token', 'password_confirmation', 'ui_language'));
                 if ($sandstorm_readwrite) {
                     $sandstorm_readwrite->firstname = "sandstorm_readwrite";
                     $sandstorm_readwrite->lastname = " ";
                     $sandstorm_readwrite->username = "******";
                     $sandstorm_readwrite->password = "******";
                     $sandstorm_readwrite->save();
                     $setting_sandstorm_readwrite = Setting::create(['ui_language' => 'en', 'user_id' => $sandstorm_readwrite->id]);
                 }
             } else {
                 $sandstorm_readwrite = User::where('username', '=', 'sandstorm_readwrite');
             }
             // Then the read only  user
             if (User::where('username', '=', 'sandstorm_readonly')->count() == 0) {
                 $sandstorm_readonly = User::create(Input::except('_token', 'password_confirmation', 'ui_language'));
                 if ($sandstorm_readonly) {
                     $sandstorm_readonly->firstname = "sandstorm_readonly";
                     $sandstorm_readonly->lastname = " ";
                     $sandstorm_readonly->username = "******";
                     $sandstorm_readonly->password = "******";
                     $sandstorm_readonly->save();
                     $setting_sandstorm_readonly = Setting::create(['ui_language' => 'en', 'user_id' => $sandstorm_readonly->id]);
                 }
             } else {
                 $sandstorm_readonly = User::where('username', '=', 'sandstorm_readonly');
             }
         }
         // Now that the required users are there we create the default
         if (Notebook::all()->count() == 0 && Tag::all()->count() == 0 && Note::all()->count() == 0) {
             // Notebook ...
             $notebookCreate = new Notebook();
             $notebookCreate->title = Lang::get('notebooks.welcome_notebook_title');
             $notebookCreate->save();
             $notebookCreate->users()->attach($sandstorm_readonly->id, ['umask' => PaperworkHelpers::UMASK_READONLY]);
             $notebookCreate->users()->attach($sandstorm_readwrite->id, ['umask' => PaperworkHelpers::UMASK_READWRITE]);
             $notebookCreate->users()->attach($sandstorm_admin->id, ['umask' => PaperworkHelpers::UMASK_OWNER]);
             // Tag ...
             $tagCreate = new Tag();
             $tagCreate->title = Lang::get('notebooks.welcome_note_tag');
             $tagCreate->visibility = 1;
             $tagCreate->user_id = $sandstorm_admin->id;
             $tagCreate->save();
             // Note ...
             $noteCreate = new Note();
             $versionCreate = new Version(['title' => Lang::get('notebooks.welcome_note_title'), 'content' => Lang::get('notebooks.welcome_note_content'), 'content_preview' => mb_substr(strip_tags(Lang::get('notebooks.welcome_note_content')), 0, 255), 'user_id' => $sandstorm_admin->id]);
             $versionCreate->save();
             $noteCreate->version()->associate($versionCreate);
             $noteCreate->notebook_id = $notebookCreate->id;
             $noteCreate->save();
             $noteCreate->users()->attach($sandstorm_readonly->id, ['umask' => PaperworkHelpers::UMASK_READONLY]);
             $noteCreate->users()->attach($sandstorm_readwrite->id, ['umask' => PaperworkHelpers::UMASK_READWRITE]);
             $noteCreate->users()->attach($sandstorm_admin->id, ['umask' => PaperworkHelpers::UMASK_OWNER]);
             $noteCreate->tags()->sync([$tagCreate->id]);
         }
         // login
         if ($sandstorm_permissions == "read") {
             $credentials = ["username" => "sandstorm_readonly", "password" => "sandstorm_readonly"];
         }
         if ($sandstorm_permissions == "write,read") {
             $credentials = ["username" => "sandstorm_readwrite", "password" => "sandstorm_readwrite"];
         }
         if ($sandstorm_permissions == "admin,write,read") {
             $credentials = ["username" => "sandstorm_admin", "password" => "sandstorm_admin"];
         }
         if (Auth::attempt($credentials)) {
             $settings = Setting::where('user_id', '=', Auth::user()->id)->first();
             Session::put('ui_language', $settings->ui_language);
             return Redirect::route("/");
         }
     }
 }