diff --git a/copyright.txt b/LICENSE similarity index 100% rename from copyright.txt rename to LICENSE diff --git a/README.md b/README.md new file mode 100644 index 00000000..6537493b --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# Hedera + +Hedera is the main page for Verdnatura. diff --git a/debian/install b/debian/install index b709bf6e..4d5b3760 100644 --- a/debian/install +++ b/debian/install @@ -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 diff --git a/forms/ecomerce/catalog/catalog.js b/forms/ecomerce/catalog/catalog.js index 260eda30..272d47b4 100644 --- a/forms/ecomerce/catalog/catalog.js +++ b/forms/ecomerce/catalog/catalog.js @@ -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)); } } diff --git a/js/hedera/basket-checker.js b/js/hedera/basket-checker.js index d4a2494f..4f12ebb1 100644 --- a/js/hedera/basket-checker.js +++ b/js/hedera/basket-checker.js @@ -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)); } diff --git a/rest/core/account.php b/rest/core/account.php index 5071e16f..23ad5488 100755 --- a/rest/core/account.php +++ b/rest/core/account.php @@ -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 ); } diff --git a/rest/core/login.php b/rest/core/login.php index 4bafbcca..9aab4885 100755 --- a/rest/core/login.php +++ b/rest/core/login.php @@ -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'], diff --git a/rest/misc/access-version.php b/rest/misc/access-version.php index 2ccfd746..b8ac47a8 100755 --- a/rest/misc/access-version.php +++ b/rest/misc/access-version.php @@ -73,4 +73,3 @@ class AccessVersion extends Vn\Web\JsonRequest return TRUE; } } - diff --git a/rest/misc/sms.php b/rest/misc/sms.php index c31996e4..17f000cc 100644 --- a/rest/misc/sms.php +++ b/rest/misc/sms.php @@ -48,5 +48,3 @@ class Sms extends Vn\Web\JsonRequest return TRUE; } } - - diff --git a/rest/misc/visits-sync.php b/rest/misc/visits-sync.php index bf6951e6..61c10a5c 100644 --- a/rest/misc/visits-sync.php +++ b/rest/misc/visits-sync.php @@ -50,4 +50,3 @@ class VisitsSync extends Vn\Lib\Method $result->free (); } } - diff --git a/web/db-session-handler.php b/web/db-session-handler.php index cc53d2ce..72e563f1 100755 --- a/web/db-session-handler.php +++ b/web/db-session-handler.php @@ -54,4 +54,3 @@ class DbSessionHandler implements \SessionHandlerInterface return TRUE; } } - diff --git a/web/json-service.php b/web/json-service.php index e7da96e0..b8cb98ac 100644 --- a/web/json-service.php +++ b/web/json-service.php @@ -110,4 +110,3 @@ class JsonService extends RestService throw $e; } } - diff --git a/web/jwt.php b/web/jwt.php index b5b6ac70..2fb6c0dc 100755 --- a/web/jwt.php +++ b/web/jwt.php @@ -86,4 +86,3 @@ class Jwt return base64_decode (str_pad ($data, $remainder, '=', STR_PAD_RIGHT)); } } - diff --git a/web/report.php b/web/report.php index 5dcc4486..8a376c71 100755 --- a/web/report.php +++ b/web/report.php @@ -42,4 +42,3 @@ class Report $mailer->send ($mail, $this->html, $this->title); } } - diff --git a/web/rest-request.php b/web/rest-request.php index e2f1f0c9..e6ae3889 100644 --- a/web/rest-request.php +++ b/web/rest-request.php @@ -18,4 +18,3 @@ abstract class RestRequest extends \Vn\Lib\Method var $service; } - diff --git a/web/rest-service.php b/web/rest-service.php index 4faff395..68154412 100644 --- a/web/rest-service.php +++ b/web/rest-service.php @@ -107,4 +107,3 @@ class RestService extends Service throw $e; } } - diff --git a/web/service.php b/web/service.php index fb4f23f5..a74d4193 100755 --- a/web/service.php +++ b/web/service.php @@ -338,4 +338,3 @@ abstract class Service return "$proto://{$this->getUri()}"; } } - diff --git a/web/util.php b/web/util.php index b361ece8..bd502b0d 100644 --- a/web/util.php +++ b/web/util.php @@ -41,4 +41,3 @@ class Util } } } -