Rewritten Access for Admin

This commit is contained in:
Tobias Reich 2014-04-28 11:23:18 +02:00
parent d2bfaa29a0
commit 43ff1d06f4
2 changed files with 286 additions and 128 deletions

View File

@ -1,175 +1,303 @@
<?php <?php
/** ###
* @name Admin Access # @name Admin Access
* @author Tobias Reich # @author Tobias Reich
* @copyright 2014 by Tobias Reich # @copyright 2014 by Tobias Reich
*/ ###
if (!defined('LYCHEE')) exit('Error: Direct access is not allowed!'); if (!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
if (!defined('LYCHEE_ACCESS_ADMIN')) exit('Error: You are not allowed to access this area!'); if (!defined('LYCHEE_ACCESS_ADMIN')) exit('Error: You are not allowed to access this area!');
switch ($_POST['function']) { class Admin extends Access {
// Album Functions public function check($fn) {
case 'getAlbums': $album = new Album($database, $plugins, $settings, null); switch ($fn) {
echo json_encode($album->getAll(false));
break;
case 'getAlbum': Module::dependencies(isset($_POST['albumID'])); # Album functions
$album = new Album($database, $plugins, $settings, $_POST['albumID']); case 'getAlbums': $this->getAlbums(); break;
echo json_encode($album->get()); case 'getAlbum': $this->getAlbum(); break;
break; case 'addAlbum': $this->addAlbum(); break;
case 'setAlbumTitle': $this->setAlbumTitle(); break;
case 'setAlbumDescription': $this->setAlbumDescription(); break;
case 'setAlbumPublic': $this->setAlbumPublic(); break;
case 'setAlbumPassword': $this->setAlbumPassword(); break;
case 'deleteAlbum': $this->deleteAlbum(); break;
case 'addAlbum': Module::dependencies(isset($_POST['title'])); # Photo functions
$album = new Album($database, $plugins, $settings, null); case 'getPhoto': $this->getPhoto(); break;
echo $album->add($_POST['title']); case 'setPhotoTitle': $this->setPhotoTitle(); break;
break; case 'setPhotoDescription': $this->setPhotoDescription(); break;
case 'setPhotoStar': $this->setPhotoStar(); break;
case 'setPhotoPublic': $this->setPhotoPublic(); break;
case 'setPhotoAlbum': $this->setPhotoAlbum(); break;
case 'setPhotoTags': $this->setPhotoTags(); break;
case 'deletePhoto': $this->deletePhoto(); break;
case 'setAlbumTitle': Module::dependencies(isset($_POST['albumIDs'], $_POST['title'])); # Add functions
$album = new Album($database, $plugins, $settings, $_POST['albumIDs']); case 'upload': $this->upload(); break;
echo $album->setTitle($_POST['title']); case 'importUrl': $this->importUrl(); break;
break; case 'importServer': $this->importServer(); break;
case 'setAlbumDescription': Module::dependencies(isset($_POST['albumID'], $_POST['description'])); # Search functions
$album = new Album($database, $plugins, $settings, $_POST['albumID']); case 'search': $this->search(); break;
echo $album->setDescription($_POST['description']);
break;
case 'setAlbumPublic': Module::dependencies(isset($_POST['albumID'], $_POST['password'])); # Session functions
$album = new Album($database, $plugins, $settings, $_POST['albumID']); case 'init': $this->init(); break;
echo $album->setPublic($_POST['password']); case 'login': $this->login(); break;
break; case 'logout': $this->logout(); break;
case 'setAlbumPassword': Module::dependencies(isset($_POST['albumID'], $_POST['password'])); # Settings functions
$album = new Album($database, $plugins, $settings, $_POST['albumID']); case 'setLogin': $this->setLogin(); break;
echo $album->setPassword($_POST['password']); case 'setSorting': $this->setSorting(); break;
break; case 'setDropboxKey': $this->setDropboxKey(); break;
case 'deleteAlbum': Module::dependencies(isset($_POST['albumIDs'])); # $_GET functions
$album = new Album($database, $plugins, $settings, $_POST['albumIDs']); case 'getAlbumArchive': $this->getAlbumArchive(); break;
echo $album->delete($_POST['albumIDs']); case 'getPhotoArchive': $this->getPhotoArchive(); break;
break;
// Photo Functions # Error
default: exit('Error: Function not found! Please check the spelling of the called function.'); break;
case 'getPhoto': Module::dependencies(isset($_POST['photoID'], $_POST['albumID'])); }
$photo = new Photo($database, $plugins, null, $_POST['photoID']);
echo json_encode($photo->get($_POST['albumID']));
break;
case 'setPhotoTitle': Module::dependencies(isset($_POST['photoIDs'], $_POST['title'])); }
$photo = new Photo($database, $plugins, null, $_POST['photoIDs']);
echo $photo->setTitle($_POST['title']);
break;
case 'setPhotoDescription': Module::dependencies(isset($_POST['photoID'], $_POST['description'])); # Album functions
$photo = new Photo($database, $plugins, null, $_POST['photoID']);
echo $photo->setDescription($_POST['description']);
break;
case 'setPhotoStar': Module::dependencies(isset($_POST['photoIDs'])); private function getAlbums() {
$photo = new Photo($database, $plugins, null, $_POST['photoIDs']);
echo $photo->setStar();
break;
case 'setPhotoPublic': Module::dependencies(isset($_POST['photoID'])); $album = new Album($this->database, $this->plugins, $this->settings, null);
$photo = new Photo($database, $plugins, null, $_POST['photoID']); echo json_encode($album->getAll(false));
echo $photo->setPublic();
break;
case 'setPhotoAlbum': Module::dependencies(isset($_POST['photoIDs'], $_POST['albumID'])); }
$photo = new Photo($database, $plugins, null, $_POST['photoIDs']);
echo $photo->setAlbum($_POST['albumID']);
break;
case 'setPhotoTags': Module::dependencies(isset($_POST['photoIDs'], $_POST['tags'])); private function getAlbum() {
$photo = new Photo($database, $plugins, null, $_POST['photoIDs']);
echo $photo->setTags($_POST['tags']);
break;
case 'deletePhoto': Module::dependencies(isset($_POST['photoIDs'])); Module::dependencies(isset($_POST['albumID']));
$photo = new Photo($database, $plugins, null, $_POST['photoIDs']); $album = new Album($this->database, $this->plugins, $this->settings, $_POST['albumID']);
echo $photo->delete(); echo json_encode($album->get());
break;
// Add Functions }
case 'upload': Module::dependencies(isset($_FILES, $_POST['albumID'])); private function addAlbum() {
$photo = new Photo($database, $plugins, $settings, null);
echo $photo->add($_FILES, $_POST['albumID']);
break;
case 'importUrl': Module::dependencies(isset($_POST['url'], $_POST['albumID'])); Module::dependencies(isset($_POST['title']));
echo Import::url($_POST['url'], $_POST['albumID']); $album = new Album($this->database, $this->plugins, $this->settings, null);
break; echo $album->add($_POST['title']);
case 'importServer': Module::dependencies(isset($_POST['albumID'])); }
echo Import::server($_POST['albumID'], null);
break;
// Search Function private function setAlbumTitle() {
case 'search': Module::dependencies(isset($_POST['term'])); Module::dependencies(isset($_POST['albumIDs'], $_POST['title']));
echo json_encode(search($database, $settings, $_POST['term'])); $album = new Album($this->database, $this->plugins, $this->settings, $_POST['albumIDs']);
break; echo $album->setTitle($_POST['title']);
// Session Function }
case 'init': Module::dependencies(isset($_POST['version'])); private function setAlbumDescription() {
$session = new Session($plugins, $settings);
echo json_encode($session->init($database, $dbName, false, $_POST['version']));
break;
case 'login': Module::dependencies(isset($_POST['user'], $_POST['password'])); Module::dependencies(isset($_POST['albumID'], $_POST['description']));
$session = new Session($plugins, $settings); $album = new Album($this->database, $this->plugins, $this->settings, $_POST['albumID']);
echo $session->login($_POST['user'], $_POST['password']); echo $album->setDescription($_POST['description']);
break;
case 'logout': $session = new Session($plugins, $settings); }
echo $session->logout();
break;
// Settings Function private function setAlbumPublic() {
case 'setLogin': Module::dependencies(isset($_POST['username'], $_POST['password'])); Module::dependencies(isset($_POST['albumID'], $_POST['password']));
if (!isset($_POST['oldPassword'])) $_POST['oldPassword'] = ''; $album = new Album($this->database, $this->plugins, $this->settings, $_POST['albumID']);
$settings = new Settings($database); echo $album->setPublic($_POST['password']);
echo $settings->setLogin($_POST['oldPassword'], $_POST['username'], $_POST['password']);
break;
case 'setSorting': Module::dependencies(isset($_POST['type'], $_POST['order'])); }
$settings = new Settings($database);
echo $settings->setSorting($_POST['type'], $_POST['order']);
break;
case 'setDropboxKey': Module::dependencies(isset($_POST['key'])); private function setAlbumPassword() {
$settings = new Settings($database);
echo $settings->setDropboxKey($_POST['key']);
break;
// Miscellaneous Module::dependencies(isset($_POST['albumID'], $_POST['password']));
$album = new Album($this->database, $this->plugins, $this->settings, $_POST['albumID']);
echo $album->setPassword($_POST['password']);
default: switch ($_GET['function']) { }
case 'getAlbumArchive': Module::dependencies(isset($_GET['albumID'])); private function deleteAlbum() {
$album = new Album($database, $plugins, $settings, $_GET['albumID']);
$album->getArchive();
break;
case 'getPhotoArchive': Module::dependencies(isset($_GET['photoID'])); Module::dependencies(isset($_POST['albumIDs']));
$photo = new Photo($database, $plugins, null, $_GET['photoID']); $album = new Album($this->database, $this->plugins, $this->settings, $_POST['albumIDs']);
$photo->getArchive(); echo $album->delete($_POST['albumIDs']);
break;
default: exit('Error: Function not found! Please check the spelling of the called function.'); }
break;
} # Photo functions
break; private function getPhoto() {
} Module::dependencies(isset($_POST['photoID'], $_POST['albumID']));
$photo = new Photo($this->database, $this->plugins, null, $_POST['photoID']);
echo json_encode($photo->get($_POST['albumID']));
?> }
private function setPhotoTitle() {
Module::dependencies(isset($_POST['photoIDs'], $_POST['title']));
$photo = new Photo($this->database, $this->plugins, null, $_POST['photoIDs']);
echo $photo->setTitle($_POST['title']);
}
private function setPhotoDescription() {
Module::dependencies(isset($_POST['photoID'], $_POST['description']));
$photo = new Photo($this->database, $this->plugins, null, $_POST['photoID']);
echo $photo->setDescription($_POST['description']);
}
private function setPhotoStar() {
Module::dependencies(isset($_POST['photoIDs']));
$photo = new Photo($this->database, $this->plugins, null, $_POST['photoIDs']);
echo $photo->setStar();
}
private function setPhotoPublic() {
Module::dependencies(isset($_POST['photoID']));
$photo = new Photo($this->database, $this->plugins, null, $_POST['photoID']);
echo $photo->setPublic();
}
private function setPhotoAlbum() {
Module::dependencies(isset($_POST['photoIDs'], $_POST['albumID']));
$photo = new Photo($this->database, $this->plugins, null, $_POST['photoIDs']);
echo $photo->setAlbum($_POST['albumID']);
}
private function setPhotoTags() {
Module::dependencies(isset($_POST['photoIDs'], $_POST['tags']));
$photo = new Photo($this->database, $this->plugins, null, $_POST['photoIDs']);
echo $photo->setTags($_POST['tags']);
}
private function deletePhoto() {
Module::dependencies(isset($_POST['photoIDs']));
$photo = new Photo($this->database, $this->plugins, null, $_POST['photoIDs']);
echo $photo->delete();
}
# Add functions
private function upload() {
Module::dependencies(isset($_FILES, $_POST['albumID']));
$photo = new Photo($this->database, $this->plugins, $this->settings, null);
echo $photo->add($_FILES, $_POST['albumID']);
}
private function importUrl() {
Module::dependencies(isset($_POST['url'], $_POST['albumID']));
echo Import::url($_POST['url'], $_POST['albumID']);
}
private function importServer() {
Module::dependencies(isset($_POST['albumID']));
echo Import::server($_POST['albumID'], null);
}
# Search function
private function search() {
Module::dependencies(isset($_POST['term']));
echo json_encode(search($this->database, $this->settings, $_POST['term']));
}
# Session functions
private function init() {
global $dbName;
Module::dependencies(isset($_POST['version']));
$session = new Session($this->plugins, $this->settings);
echo json_encode($session->init($this->database, $dbName, false, $_POST['version']));
}
private function login() {
Module::dependencies(isset($_POST['user'], $_POST['password']));
$session = new Session($this->plugins, $this->settings);
echo $session->login($_POST['user'], $_POST['password']);
}
private function logout() {
$session = new Session($this->plugins, $this->settings);
echo $session->logout();
}
# Settings functions
private function setLogin() {
Module::dependencies(isset($_POST['username'], $_POST['password']));
if (!isset($_POST['oldPassword'])) $_POST['oldPassword'] = '';
$this->settings = new Settings($this->database);
echo $this->settings->setLogin($_POST['oldPassword'], $_POST['username'], $_POST['password']);
}
private function setSorting() {
Module::dependencies(isset($_POST['type'], $_POST['order']));
$this->settings = new Settings($this->database);
echo $this->settings->setSorting($_POST['type'], $_POST['order']);
}
private function setDropboxKey() {
Module::dependencies(isset($_POST['key']));
$this->settings = new Settings($this->database);
echo $this->settings->setDropboxKey($_POST['key']);
}
# Get functions
private function getAlbumArchive() {
Module::dependencies(isset($_GET['albumID']));
$album = new Album($this->database, $this->plugins, $this->settings, $_GET['albumID']);
$album->getArchive();
}
private function getPhotoArchive() {
Module::dependencies(isset($_GET['photoID']));
$photo = new Photo($this->database, $this->plugins, null, $_GET['photoID']);
$photo->getArchive();
}
}

30
php/modules/Access.php Normal file
View File

@ -0,0 +1,30 @@
<?php
###
# @name Access
# @author Tobias Reich
# @copyright 2014 by Tobias Reich
###
if (!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
class Access {
protected $database = null;
protected $plugins = null;
protected $settings = null;
public function __construct($database, $plugins, $settings) {
# Init vars
$this->database = $database;
$this->plugins = $plugins;
$this->settings = $settings;
return true;
}
}
?>