forked from verdnatura/hedera-web
59 lines
1.1 KiB
PHP
Executable File
59 lines
1.1 KiB
PHP
Executable File
<?php
|
|
|
|
require_once ('vn/web/json-request.php');
|
|
|
|
class Login extends Vn\Web\JsonRequest
|
|
{
|
|
function run ()
|
|
{
|
|
$this->login ();
|
|
$this->updateCredentials ();
|
|
return TRUE;
|
|
}
|
|
|
|
/**
|
|
* Updates the user credentials in other user databases like Samba.
|
|
**/
|
|
function updateCredentials ()
|
|
{
|
|
$db = $this->getSysConn ();
|
|
|
|
$hasAccount = $db->getValue (
|
|
'SELECT COUNT(*) > 0
|
|
FROM account.user u
|
|
JOIN account.account a ON u.id = a.user_id
|
|
WHERE u.name = #',
|
|
[$_SESSION['user']]
|
|
);
|
|
|
|
if (!$hasAccount)
|
|
return;
|
|
|
|
$sshConf = $db->getRow ('SELECT host, user, password FROM ssh_config');
|
|
|
|
$ssh = ssh2_connect ($sshConf['host']);
|
|
$sshOk = $ssh && ssh2_auth_password ($ssh,
|
|
$sshConf['user'], base64_decode ($sshConf['password']));
|
|
|
|
if (!$sshOk)
|
|
{
|
|
error_log ("Can't connect to SSH server {$sshConf['host']}");
|
|
return;
|
|
}
|
|
|
|
$user = $this->escape ($_SESSION['user']);
|
|
$pass = $this->escape ($_SESSION['password']);
|
|
ssh2_exec ($ssh, "samba-tool user add \"$user\" \"$pass\"");
|
|
}
|
|
|
|
/**
|
|
* Escapes the double cuotes from an string.
|
|
**/
|
|
function escape ($str)
|
|
{
|
|
return str_replace ('"', '\\"', $str);
|
|
}
|
|
}
|
|
|
|
?>
|