10 defined(
'JPATH_PLATFORM') or die;
33 public static function getCredentials($client, $force =
false)
35 static $credentials = array();
37 $client = strtolower($client);
39 if (!isset($credentials[$client]) || $force)
48 'enabled' => $config->get(
'ftp_enable'),
49 'host' => $config->get(
'ftp_host'),
50 'port' => $config->get(
'ftp_port'),
51 'user' => $config->get(
'ftp_user'),
52 'pass' => $config->get(
'ftp_pass'),
53 'root' => $config->get(
'ftp_root'));
57 $options = array(
'enabled' =>
false,
'host' =>
'',
'port' =>
'',
'user' =>
'',
'pass' =>
'',
'root' =>
'');
62 if ($options[
'enabled'] ==
true && ($options[
'user'] ==
'' || $options[
'pass'] ==
''))
65 $options[
'user'] = $session->get($client .
'.user', null,
'JClientHelper');
66 $options[
'pass'] = $session->get($client .
'.pass', null,
'JClientHelper');
70 if ($options[
'user'] ==
'' || $options[
'pass'] ==
'')
72 $options[
'enabled'] =
false;
76 $credentials[$client] = $options;
79 return $credentials[$client];
93 public static function setCredentials($client, $user, $pass)
96 $client = strtolower($client);
103 $options = array(
'enabled' => $config->get(
'ftp_enable'),
'host' => $config->get(
'ftp_host'),
'port' => $config->get(
'ftp_port'));
105 if ($options[
'enabled'])
110 if ($ftp->isConnected())
112 if ($ftp->login($user, $pass))
129 $session->set($client .
'.user', $user,
'JClientHelper');
130 $session->set($client .
'.pass', $pass,
'JClientHelper');
133 self::getCredentials($client,
true);
148 public static function hasCredentials($client)
151 $client = strtolower($client);
158 $options = array(
'enabled' => $config->get(
'ftp_enable'),
'user' => $config->get(
'ftp_user'),
'pass' => $config->get(
'ftp_pass'));
162 $options = array(
'enabled' =>
false,
'user' =>
'',
'pass' =>
'');
166 if ($options[
'enabled'] ==
false)
171 elseif ($options[
'user'] !=
'' && $options[
'pass'] !=
'')
180 $user = $session->get($client .
'.user', null,
'JClientHelper');
181 $pass = $session->get($client .
'.pass', null,
'JClientHelper');
183 if ($user !=
'' && $pass !=
'')
206 public static function setCredentialsFromRequest($client)
210 $user = $input->post->getString(
'username', null);
211 $pass = $input->post->getString(
'password', null);
213 if ($user !=
'' && $pass !=
'')
216 if (self::setCredentials($client, $user, $pass))
222 if (class_exists(
'JError'))
228 throw new InvalidArgumentException(
'Invalid user credentials');
235 $return = !self::hasCredentials(
'ftp');