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 index.php usr/share/hedera-web
package.json usr/share/hedera-web package.json usr/share/hedera-web
manifest.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 webpack.config.json usr/share/hedera-web
build usr/share/hedera-web build usr/share/hedera-web

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -86,4 +86,3 @@ class Jwt
return base64_decode (str_pad ($data, $remainder, '=', STR_PAD_RIGHT)); 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); $mailer->send ($mail, $this->html, $this->title);
} }
} }

View File

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

View File

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

View File

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

View File

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