-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
151 lines (139 loc) · 6.21 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?php
/*
* Copyright 2007-2011 Charles du Jeu <contact (at) cdujeu.me>
* This file is part of AjaXplorer.
*
* AjaXplorer is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* AjaXplorer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with AjaXplorer. If not, see <http://www.gnu.org/licenses/>.
*
* The latest code can be found at <http://www.ajaxplorer.info/>.
*
* Description : main access point of the application, this script is called by any Ajax query.
* Will dispatch the actions on the plugins.
*/
include_once("base.conf.php");
if( !isSet($_GET["action"]) && !isSet($_GET["get_action"])
&& !isSet($_POST["action"]) && !isSet($_POST["get_action"])
&& defined("AJXP_FORCE_SSL_REDIRECT") && AJXP_FORCE_SSL_REDIRECT === true
&& $_SERVER['SERVER_PORT'] != 443) {
header("HTTP/1.1 301 Moved Permanently");
header("Location: https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
exit();
}
if(isSet($_GET["ajxp_sessid"]))
{
// Don't overwrite cookie
if (!isSet($_COOKIE["AjaXplorer"]))
$_COOKIE["AjaXplorer"] = $_GET["ajxp_sessid"];
}
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
require_once(AJXP_BIN_FOLDER."/class.AJXP_Logger.php");
if(is_file(TESTS_RESULT_FILE)){
set_error_handler(array("AJXP_XMLWriter", "catchError"), E_ALL & ~E_NOTICE & ~E_STRICT );
set_exception_handler(array("AJXP_XMLWriter", "catchException"));
}
$pServ = AJXP_PluginsService::getInstance();
ConfService::init();
$confPlugin = ConfService::getInstance()->confPluginSoftLoad($pServ);
$pServ->loadPluginsRegistry(AJXP_INSTALL_PATH."/plugins", $confPlugin);
ConfService::start();
$confStorageDriver = ConfService::getConfStorageImpl();
require_once($confStorageDriver->getUserClassFileName());
session_name("AjaXplorer");
session_start();
if(isSet($_GET["tmp_repository_id"])){
ConfService::switchRootDir($_GET["tmp_repository_id"], true);
}else if(isSet($_SESSION["SWITCH_BACK_REPO_ID"])){
ConfService::switchRootDir($_SESSION["SWITCH_BACK_REPO_ID"]);
unset($_SESSION["SWITCH_BACK_REPO_ID"]);
}
$action = "get_boot_gui";
if(isSet($_GET["action"]) || isSet($_GET["get_action"])) $action = (isset($_GET["get_action"])?$_GET["get_action"]:$_GET["action"]);
else if(isSet($_POST["action"]) || isSet($_POST["get_action"])) $action = (isset($_POST["get_action"])?$_POST["get_action"]:$_POST["action"]);
$pluginsUnSecureActions = ConfService::getDeclaredUnsecureActions();
$unSecureActions = array_merge($pluginsUnSecureActions, array("get_secure_token"));
if(!in_array($action, $unSecureActions) && AuthService::getSecureToken()){
$token = "";
if(isSet($_GET["secure_token"])) $token = $_GET["secure_token"];
else if(isSet($_POST["secure_token"])) $token = $_POST["secure_token"];
if( $token == "" || !AuthService::checkSecureToken($token)){
throw new Exception("You are not allowed to access this resource.");
}
}
if(AuthService::usersEnabled())
{
$httpVars = array_merge($_GET, $_POST);
AuthService::logUser(null, null);
// Check that current user can access current repository, try to switch otherwise.
$loggedUser = AuthService::getLoggedUser();
if($loggedUser == null)
{
// Try prelogging user if the session expired but the logging data is in fact still present
// For example, for basic_http auth.
AuthService::preLogUser((isSet($httpVars["remote_session"])?$httpVars["remote_session"]:""));
$loggedUser = AuthService::getLoggedUser();
if($loggedUser == null) $requireAuth = true;
}
if($loggedUser != null)
{
$res = ConfService::switchUserToActiveRepository($loggedUser, (isSet($httpVars["tmp_repository_id"])?$httpVars["tmp_repository_id"]:"-1"));
if(!$res){
AuthService::disconnect();
$requireAuth = true;
}
}
}else{
AJXP_Logger::debug(ConfService::getCurrentRootDirIndex());
}
//Set language
$loggedUser = AuthService::getLoggedUser();
if($loggedUser != null && $loggedUser->getPref("lang") != "") ConfService::setLanguage($loggedUser->getPref("lang"));
else if(isSet($_COOKIE["AJXP_lang"])) ConfService::setLanguage($_COOKIE["AJXP_lang"]);
//------------------------------------------------------------
// SPECIAL HANDLING FOR FANCY UPLOADER RIGHTS FOR THIS ACTION
//------------------------------------------------------------
if(AuthService::usersEnabled())
{
$loggedUser = AuthService::getLoggedUser();
if($action == "upload" && ($loggedUser == null || !$loggedUser->canWrite(ConfService::getCurrentRootDirIndex()."")) && isSet($_FILES['Filedata']))
{
header('HTTP/1.0 ' . '410 Not authorized');
die('Error 410 Not authorized!');
}
}
// THIS FIRST DRIVERS DO NOT NEED ID CHECK
$ajxpDriver = AJXP_PluginsService::findPlugin("gui", "ajax");
$ajxpDriver->init(ConfService::getRepository());
$authDriver = ConfService::getAuthDriverImpl();
// DRIVERS BELOW NEED IDENTIFICATION CHECK
if(!AuthService::usersEnabled() || ConfService::getCoreConf("ALLOW_GUEST_BROWSING", "auth") || AuthService::getLoggedUser()!=null){
$confDriver = ConfService::getConfStorageImpl();
$Driver = ConfService::loadRepositoryDriver();
}
ConfService::initActivePlugins();
require_once(AJXP_BIN_FOLDER."/class.AJXP_Controller.php");
$xmlResult = AJXP_Controller::findActionAndApply($action, array_merge($_GET, $_POST), $_FILES);
if($xmlResult !== false && $xmlResult != ""){
AJXP_XMLWriter::header();
print($xmlResult);
AJXP_XMLWriter::close();
}else if(isset($requireAuth) && AJXP_Controller::$lastActionNeedsAuth){
AJXP_XMLWriter::header();
AJXP_XMLWriter::requireAuth();
AJXP_XMLWriter::close();
}
session_write_close();
?>