Merge with master

This commit is contained in:
Juan Ferrer Toribio 2017-11-29 11:29:08 +01:00
commit 6829bb5a83
18 changed files with 81 additions and 40 deletions

3
README.md Normal file
View File

@ -0,0 +1,3 @@
# Hedera
Hedera is the main page for Verdnatura.

2
debian/install vendored
View File

@ -11,5 +11,7 @@ rest usr/share/hedera-web
index.php usr/share/hedera-web
package.json usr/share/hedera-web
manifest.json usr/share/hedera-web
LICENSE usr/share/hedera-web
README.md usr/share/hedera-web
webpack.config.json usr/share/hedera-web
build usr/share/hedera-web

View File

@ -39,7 +39,7 @@ Hedera.Catalog = new Class
}
else
{
var query = 'CALL basket_configure_for_guest ()';
var query = 'CALL basketConfigureForGuest';
this.conn.execQuery (query, this.loadUi.bind (this));
}
}

View File

@ -4,7 +4,7 @@ module.exports =
check: function (conn, hash, callback)
{
this.hash = hash;
conn.execQuery ('CALL basketCheck ()',
conn.execQuery ('CALL basketCheck',
this._onBasketCheck.bind (this, callback));
}

View File

@ -2,45 +2,45 @@
class Account
{
static function trySync ($db, $user, $password = NULL)
static function trySync ($db, $userName, $password = NULL)
{
$isSync = $db->getValue (
'SELECT sync FROM account.user WHERE name = #',
[$user]
[$userName]
);
if ($isSync)
return;
self::sync ($db, $user, $password);
self::sync ($db, $userName, $password);
}
static function sync ($db, $user, $password = NULL, $force = TRUE)
static function sync ($db, $userName, $password = NULL, $force = TRUE)
{
$hasAccount = $db->getValue (
'SELECT COUNT(*) > 0
FROM account.user u
JOIN account.account a ON u.id = a.id
WHERE u.name = #',
[$user]
[$userName]
);
if ($hasAccount)
{
self::ldapSync ($db, $user, $password);
self::sambaSync ($db, $user, $password);
self::ldapSync ($db, $userName, $password);
self::sambaSync ($db, $userName, $password);
}
$db->query (
'UPDATE account.user SET sync = TRUE WHERE name = #',
[$user]
[$userName]
);
}
/**
* Synchronizes the user credentials in the LDAP server.
*/
static function ldapSync ($db, $user, $password)
static function ldapSync ($db, $userName, $password)
{
if (empty ($password))
return;
@ -64,43 +64,88 @@ class Account
if (!$bind)
throw new Exception ("Authentication failed on LDAP server: ". ldapError ($ds));
// Prepares the data
$domain = $db->getValue ('SELECT domain FROM account.mailConfig');
$user = $db->getObject (
'SELECT id, nickname, lang
FROM account.user
WHERE name = #',
[$userName]
);
$nameArgs = explode (' ', $user->nickname);
$givenName = $nameArgs[0];
if (count ($nameArgs) > 1)
$sn = $nameArgs[1];
if (empty ($sn))
$sn = 'Empty';
$info = [
'cn' => $user->nickname,
'displayName' => $user->nickname,
'givenName' => $givenName,
'sn' => $sn,
'mail' => "$userName@{$domain}",
'userPassword' => sshaEncode ($password),
'preferredLanguage' => $user->lang
];
// Search the user entry
$res = ldap_search ($ds, $conf->baseDn, "(&(uid=$user)($conf->filter))");
$filter = "uid=$userName";
if (!empty($conf->filter))
$filter = "(&($filter)($conf->filter))";
$res = ldap_search ($ds, $conf->baseDn, $filter);
if (!$res)
throw new Exception ("Can't get the LDAP entry: ". ldapError ($ds));
$dn = "uid=$user,{$conf->baseDn}";
$dn = "uid=$userName,{$conf->baseDn}";
$entry = ldap_first_entry ($ds, $res);
$classes = ldap_get_values ($ds, $entry, 'objectClass');
if (!in_array ('inetOrgPerson', $classes))
{
ldap_delete ($ds, $dn);
$entry = NULL;
}
if ($entry)
{
$info = ['userPassword' => sshaEncode ($password)];
ldap_modify ($ds, $dn, $info);
$updated = ldap_modify ($ds, $dn, $info);
}
else
{
$info = [
'objectClass' => ['account', 'simpleSecurityObject', 'top'],
'uid' => $user,
'userPassword' => sshaEncode ($password)
];
ldap_add ($ds, $dn, $info);
$info = array_merge ($info, [
'objectClass' => ['inetOrgPerson'],
'uid' => $userName
]);
$updated = ldap_add ($ds, $dn, $info);
}
if (!$updated)
throw new Exception ("Can't update the LDAP entry: ". ldapError ($ds));
ldap_unbind ($ds);
}
/**
* Synchronizes the user credentials in the Samba server.
*/
static function sambaSync ($db, $user, $password)
static function sambaSync ($db, $userName, $password)
{
$conf = $db->getObject (
'SELECT host, sshUser, sshPass, domain, uidBase
'SELECT host, sshUser, sshPass, uidBase
FROM account.sambaConfig'
);
$domain = $db->getValue ('SELECT domain FROM account.mailConfig');
$samba = new SshConnection ($conf->host
,$conf->sshUser
@ -112,12 +157,12 @@ class Account
// Creates the Samba user and initializes it's home directory
$userId = $db->getValue (
'SELECT id FROM account.user WHERE name = #', [$user]);
'SELECT id FROM account.user WHERE name = #', [$userName]);
$samba->exec ("$scriptDir/create-user.sh %s %s %s"
,$user
,$userName
,$conf->uidBase + $userId
,"$user@{$conf->domain}"
,"$userName@{$domain}"
);
// Syncronizes the Samba password
@ -126,7 +171,7 @@ class Account
return;
$samba->exec ("$scriptDir/set-password.sh %s %s"
,$user
,$userName
,$password
);
}

View File

@ -12,7 +12,10 @@ class Login extends Vn\Web\JsonRequest
,$_POST['password']
);
}
catch (Exception $e) {}
catch (Exception $e)
{
error_log ($e->getMessage());
}
$token = $this->service->createToken (
$_SESSION['user'],

View File

@ -73,4 +73,3 @@ class AccessVersion extends Vn\Web\JsonRequest
return TRUE;
}
}

View File

@ -48,5 +48,3 @@ class Sms extends Vn\Web\JsonRequest
return TRUE;
}
}

View File

@ -50,4 +50,3 @@ class VisitsSync extends Vn\Lib\Method
$result->free ();
}
}

View File

@ -54,4 +54,3 @@ class DbSessionHandler implements \SessionHandlerInterface
return TRUE;
}
}

View File

@ -110,4 +110,3 @@ class JsonService extends RestService
throw $e;
}
}

View File

@ -86,4 +86,3 @@ class Jwt
return base64_decode (str_pad ($data, $remainder, '=', STR_PAD_RIGHT));
}
}

View File

@ -42,4 +42,3 @@ class Report
$mailer->send ($mail, $this->html, $this->title);
}
}

View File

@ -18,4 +18,3 @@ abstract class RestRequest extends \Vn\Lib\Method
var $service;
}

View File

@ -107,4 +107,3 @@ class RestService extends Service
throw $e;
}
}

View File

@ -338,4 +338,3 @@ abstract class Service
return "$proto://{$this->getUri()}";
}
}

View File

@ -41,4 +41,3 @@ class Util
}
}
}