Ejemplo n.º 1
0
 /**
  * Display the rights on website, and let
  * the admin edit them.
  * 
  * @author Thibaud Rohmer
  */
 public function toHTML()
 {
     echo "<div class='adminrights'>\n";
     echo "<h3>Infos</h3>";
     echo $this->infos;
     echo "<h3>Access</h3>";
     if ($this->public) {
         echo "<div class='pure-g'><div class='pure-u-1-3'>";
         echo "<a href='?t=Pri{$this->webpath}'class='button-round button-success'><i class='fa fa-unlock'></i></a></div>";
         echo "<div class='pure-u-2-3'>" . Settings::_("judge", "public") . "</div></div>";
     } else {
         echo "<div class='pure-g'><div class='pure-u-1-3'>";
         echo "<a href='?t=Pub{$this->webpath}'class='button-round button-error'><i class='fa fa-lock'></i></a></div>";
         echo "<div class='pure-u-2-3'>" . Settings::_("judge", "priv") . "</div></div>";
     }
     echo "<form action='?t=Rig{$this->webpath}' method='post' class='pure-form pure-form-aligned'>";
     if (!$this->public) {
         echo "<h3>" . Settings::_("judge", "accounts") . "</h3>";
         echo "<ul>";
         foreach (Account::findAll() as $account) {
             if (in_array($account['login'], $this->users)) {
                 $checked = "checked";
             } else {
                 $checked = "";
             }
             echo "<label class='pure-checkbox'><input type='checkbox'  value='" . $account['login'] . "' name='users[]' {$checked} > " . htmlentities($account['login'], ENT_QUOTES, 'UTF-8') . "</label>";
         }
         echo "</ul>";
         echo "<h3>" . Settings::_("judge", "groups") . "</h3>";
         echo "<ul>";
         foreach (Group::findAll() as $group) {
             if ($group['name'] == "root") {
                 continue;
             }
             if (in_array($group['name'], $this->groups)) {
                 $checked = "checked";
             } else {
                 $checked = "";
             }
             echo "<label class='pure-checkbox'><input type='checkbox'   value='" . $group['name'] . "' name='groups[]' {$checked} > " . htmlentities($group['name'], ENT_QUOTES, 'UTF-8') . " </label>";
         }
         echo "<input type='submit' class='pure-button pure-button-primary button-small' value='" . Settings::_("judge", "set") . "'>\n";
         echo "</ul>";
         echo "<h3>Guest Tokens</h3>";
         if (!$this->multi) {
             // Token creation
             $tokens = GuestToken::find_for_path($this->file);
             if ($tokens && !empty($tokens)) {
                 echo "<ul>";
                 $i = 0;
                 foreach ($tokens as $token) {
                     $i++;
                     echo "<a class='pure-button button-small button-warning' href='" . GuestToken::get_url($token['key']) . "' >Guest Token {$i}</a><br />\n";
                 }
                 echo "</ul>";
             }
             echo "<ul><a href='?t=CTk{$this->webpath}' class='pure-button button-secondary button-small'>" . Settings::_("token", "createtoken") . "</a></ul>";
         }
     }
     echo "</form>\n";
     echo "</div>\n";
 }
Ejemplo n.º 2
0
 /**
  * Test the create feature
  * @test
  * @depends test_generate_key
  */
 public function test_create()
 {
     // From scratch
     self::delete_tokens_file();
     self::login_as_admin();
     $folder1 = Settings::$photos_dir . "tokenfolder";
     $ret = GuestToken::create($folder1);
     $this->assertTrue($ret);
     $tokens = GuestToken::findAll();
     $this->assertCount(1, $tokens);
     $this->assertArrayHasKey('key', $tokens[0]);
     $this->assertArrayHasKey('path', $tokens[0]);
     $this->assertEquals(File::a2r($folder1), $tokens[0]['path']);
     $this->assertRegexp('/.{10}.*/', $tokens[0]['key']);
     // we shouldn't create key for non-existing folders
     try {
         $folder2 = Settings::$photos_dir . "tokenfolder2";
         if (file_exists($folder2)) {
             rmdir($folder2);
         }
         $ret = GuestToken::create($folder2);
     } catch (Exception $e) {
         $this->assertCount(1, GuestToken::findAll());
         mkdir($folder2);
         $ret = GuestToken::create($folder2);
         $this->assertTrue($ret);
         $this->assertCount(2, GuestToken::findAll());
         $this->assertCount(1, GuestToken::find_for_path($folder2));
         $tokens2 = GuestToken::find_for_path($folder2);
         $this->assertEquals(File::a2r($folder2), $tokens2[0]['path']);
         $ret = GuestToken::exist($tokens[0]['key']);
         $this->assertTrue($ret);
         $ret = GuestToken::delete($tokens[0]['key']);
         $this->assertTrue($ret);
         $this->assertCount(1, GuestToken::findAll());
         return;
     }
     $this->fail('Token has been creating on an inexisting folder');
 }
Ejemplo n.º 3
0
 /**
  * create a token and give you the ouput
  * actually it's a bit of cheating
  * if a token already exist for the given path we return it
  * otherwise, we create a new one
  */
 public function create_token($path = NULL)
 {
     // default path is the token folder
     if (!isset($path)) {
         $path = Settings::$photos_dir . "/tokenfolder";
     }
     // do we already have a token ?
     $tokens = GuestToken::find_for_path(File::a2r($path), true);
     if (!empty($tokens)) {
         return $tokens[0]['key'];
     }
     // No token found, Creating a token to allow guest view for the given path
     $key = Guesttoken::generate_key();
     if (!GuestToken::create($path, $key)) {
         throw new Exception("Cannot create token for path " . $path . "\n");
     }
     return $key;
 }