lychee/php/api.php

76 lines
1.9 KiB
PHP
Raw Normal View History

<?php
2014-04-12 12:10:08 +00:00
###
2014-04-27 13:24:51 +00:00
# @name API
2015-02-01 21:08:37 +00:00
# @copyright 2015 by Tobias Reich
2014-04-12 12:10:08 +00:00
###
2016-01-19 15:09:06 +00:00
# Define the called function
if (isset($_POST['function'])) $fn = $_POST['function'];
else if (isset($_GET['function'])) $fn = $_GET['function'];
else $fn = null;
2016-01-19 15:09:06 +00:00
# Check if a function has been specified
if (!empty($fn)) {
# Start the session and set the default timezone
session_start();
2014-02-09 18:21:55 +00:00
date_default_timezone_set('UTC');
2014-08-29 14:36:38 +00:00
# Load required files
2014-04-13 12:08:18 +00:00
require(__DIR__ . '/define.php');
2014-04-09 18:07:25 +00:00
require(__DIR__ . '/autoload.php');
2016-01-24 21:30:37 +00:00
require(__DIR__ . '/misc.php');
2014-02-17 16:01:46 +00:00
2016-01-19 15:09:06 +00:00
# Validate parameters
if (isset($_POST['albumIDs'])&&preg_match('/^[0-9\,]{1,}$/', $_POST['albumIDs'])!==1) exit('Error: Wrong parameter type for albumIDs!');
if (isset($_POST['photoIDs'])&&preg_match('/^[0-9\,]{1,}$/', $_POST['photoIDs'])!==1) exit('Error: Wrong parameter type for photoIDs!');
if (isset($_POST['albumID'])&&preg_match('/^[0-9sfr]{1,}$/', $_POST['albumID'])!==1) exit('Error: Wrong parameter type for albumID!');
if (isset($_POST['photoID'])&&preg_match('/^[0-9]{14}$/', $_POST['photoID'])!==1) exit('Error: Wrong parameter type for photoID!');
# Check if a configuration exists
if (Config::exists()===false) {
2014-04-27 13:24:51 +00:00
###
# Installation Access
# Limited access to configure Lychee. Only available when the config.php file is missing.
###
$installation = new Installation();
$installation->check($fn);
2014-04-30 09:10:31 +00:00
exit();
}
2016-01-19 15:09:06 +00:00
# Check if user is logged
if ((isset($_SESSION['login'])&&$_SESSION['login']===true)&&
(isset($_SESSION['identifier'])&&$_SESSION['identifier']===Settings::get()['identifier'])) {
2014-04-27 13:24:51 +00:00
###
# Admin Access
# Full access to Lychee. Only with correct password/session.
###
2014-02-17 16:01:46 +00:00
$admin = new Admin();
2014-04-30 08:56:04 +00:00
$admin->check($fn);
} else {
2014-04-27 13:24:51 +00:00
###
# Guest Access
# Access to view all public folders and photos in Lychee.
###
$guest = new Guest();
2014-04-30 08:56:04 +00:00
$guest->check($fn);
}
} else {
2016-01-19 15:09:06 +00:00
exit('Error: No API function specified!');
}
2016-01-19 15:09:06 +00:00
?>