This repository has been archived by the owner on Nov 25, 2020. It is now read-only.
/
class.ftpAuthDriver.php
163 lines (146 loc) · 5.24 KB
/
class.ftpAuthDriver.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
152
153
154
155
156
157
158
159
160
161
162
163
<?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/>.
*/
defined('AJXP_EXEC') or die( 'Access not allowed');
require_once(AJXP_INSTALL_PATH."/".AJXP_PLUGINS_FOLDER."/access.ftp/class.ftpAccessWrapper.php");
class ftpSonWrapper extends ftpAccessWrapper {
public function initUrl($url){
$this->parseUrl($url, true);
}
}
/**
* Authenticate users against an FTP server
* @package AjaXplorer_Plugins
* @subpackage Auth
*/
class ftpAuthDriver extends AbstractAuthDriver {
var $driverName = "ftp";
protected function parseSpecificContributions(&$contribNode){
parent::parseSpecificContributions($contribNode);
if($contribNode->nodeName != "actions") return ;
$actionXpath=new DOMXPath($contribNode->ownerDocument);
if(!isset($this->options["FTP_LOGIN_SCREEN"]) || $this->options["FTP_LOGIN_SCREEN"] != "TRUE" || $this->options["FTP_LOGIN_SCREEN"] === false){
// Remove "ftp_login" && "ftp_set_data" actions
$nodeList = $actionXpath->query('action[@name="dynamic_login"]', $contribNode);
if(!$nodeList->length) return ;
unset($this->actions["dynamic_login"]);
$contribNode->removeChild($nodeList->item(0));
$nodeList = $actionXpath->query('action[@name="ftp_set_data"]', $contribNode);
if(!$nodeList->length) return ;
unset($this->actions["ftp_set_data"]);
$contribNode->removeChild($node = $nodeList->item(0));
}else{
// Replace "login" by "dynamic_login"
$loginList = $actionXpath->query('action[@name="login"]', $contribNode);
if($loginList->length && $loginList->item(0)->getAttribute("auth_ftp_impl") == null){
$contribNode->removeChild($loginList->item(0));
}
$dynaLoginList = $actionXpath->query('action[@name="dynamic_login"]', $contribNode);
if($dynaLoginList->length){
$dynaLoginList->item(0)->setAttribute("name", "login");
$dynaLoginList->item(0)->setAttribute("auth_ftp_impl", "true");
}
}
}
function listUsers(){
$adminUser = $this->options["AJXP_ADMIN_LOGIN"];
if(isSet($this->options["ADMIN_USER"])) {
$adminUser = $this->options["AJXP_ADMIN_LOGIN"];
}
return array($adminUser => $adminUser);
}
function userExists($login){
return true ;
}
function logoutCallback($actionName, $httpVars, $fileVars){
$safeCredentials = AJXP_Safe::loadCredentials();
$crtUser = $safeCredentials["user"];
if(isSet($_SESSION["AJXP_DYNAMIC_FTP_DATA"])){
unset($_SESSION["AJXP_DYNAMIC_FTP_DATA"]);
}
AJXP_Safe::clearCredentials();
$adminUser = $this->options["AJXP_ADMIN_LOGIN"];
if(isSet($this->options["ADMIN_USER"])) {
$adminUser = $this->options["AJXP_ADMIN_LOGIN"];
}
$subUsers = array();
if($crtUser != $adminUser && $crtUser!=""){
ConfService::getConfStorageImpl()->deleteUser($crtUser, $subUsers);
}
AuthService::disconnect();
session_destroy();
session_write_close();
AJXP_XMLWriter::header();
AJXP_XMLWriter::loggingResult(2);
AJXP_XMLWriter::close();
}
function setFtpDataCallback($actionName, $httpVars, $fileVars){
$options = array("CHARSET", "FTP_DIRECT", "FTP_HOST", "FTP_PORT", "FTP_SECURE", "PATH");
$ftpOptions = array();
foreach ($options as $option){
if(isSet($httpVars[$option])){
$ftpOptions[$option] = $httpVars[$option];
}
}
$_SESSION["AJXP_DYNAMIC_FTP_DATA"] = $ftpOptions;
}
function testParameters($params){
AJXP_Logger::debug("TESTING", $params);
$repositoryId = $params["REPOSITORY_ID"];
$wrapper = new ftpSonWrapper();
try{
$wrapper->initUrl("ajxp.ftp://fake:fake@$repositoryId/");
}catch (Exception $e){
if($e->getMessage() == "Cannot login to FTP server with user fake"){
return "SUCCESS: FTP server successfully contacted.";
}else{
return "ERROR: ".$e->getMessage();
}
}
return "SUCCESS: Could succesfully connect to the FTP server!";
}
function checkPassword($login, $pass, $seed){
$wrapper = new ftpSonWrapper();
$repoId = $this->options["REPOSITORY_ID"];
try{
$wrapper->initUrl("ajxp.ftp://".rawurlencode($login).":".rawurlencode($pass)."@$repoId/");
AJXP_Safe::storeCredentials($login, $pass);
}catch(Exception $e){
return false;
}
return true;
}
function usersEditable(){
return false;
}
function passwordsEditable(){
return false;
}
function createUser($login, $passwd){
}
function changePassword($login, $newPass){
}
function deleteUser($login){
}
function getUserPass($login){
return "";
}
}
?>