From 5b50b3cc64cf99c45018a7ba4fc86e65d9cf1fc6 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Mon, 22 May 2017 09:49:05 +0200 Subject: [PATCH 1/6] =?UTF-8?q?Email=20de=20recuperaci=C3=B3n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- debian/changelog | 2 +- forms/account/conf/ui.xml | 3 +-- rest/core/recover-password.php | 9 +++------ web/service.php | 2 ++ 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/debian/changelog b/debian/changelog index c7967439..afbb328e 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,4 @@ -hedera-web (1.405.1) stable; urgency=low +hedera-web (1.405.2) stable; urgency=low * Initial Release. diff --git a/forms/account/conf/ui.xml b/forms/account/conf/ui.xml index 84f1344a..f2bd29b4 100755 --- a/forms/account/conf/ui.xml +++ b/forms/account/conf/ui.xml @@ -11,8 +11,7 @@ - SELECT u.id, u.name, u.recoverPass, - c.email, c.mail, c.user_id + SELECT u.id, u.name, u.email, u.recoverPass, c.mail, c.user_id FROM account.userView u LEFT JOIN customer_view c ON u.id = c.user_id diff --git a/rest/core/recover-password.php b/rest/core/recover-password.php index 9c2c2307..18bf11ce 100755 --- a/rest/core/recover-password.php +++ b/rest/core/recover-password.php @@ -9,14 +9,11 @@ class RecoverPassword extends Vn\Web\JsonRequest function run ($db) { $user = $db->getRow ( - 'SELECT c.`e-mail` mail, u.active - FROM vn2008.Clientes c - JOIN account.user u ON u.id = c.Id_Cliente - WHERE u.name = #', + 'SELECT email, active FROM account.user WHERE name = #', [$_REQUEST['recoverUser']] ); - if (!($user['active'] && $user['mail'])) + if (!($user['active'] && $user['email'])) return TRUE; $service = $this->service; @@ -24,7 +21,7 @@ class RecoverPassword extends Vn\Web\JsonRequest $url = $service->getUrl () ."#!form=account/conf&token=$token"; $report = new Vn\Web\Report ($db, 'recover-password', ['url' => $url]); - $report->sendMail ($user['mail']); + $report->sendMail ($user['email']); return TRUE; } diff --git a/web/service.php b/web/service.php index 8ec6e3ab..88381a45 100755 --- a/web/service.php +++ b/web/service.php @@ -290,6 +290,8 @@ abstract class Service Locale::addPath ('rest/'. dirname ($_REQUEST['method'])); + $res = NULL; + try { $res = $method->run ($methodDb); } From 400fa1787d5c2397468fe8274dfdfc9f75c461a7 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Tue, 30 May 2017 15:27:49 +0200 Subject: [PATCH 2/6] =?UTF-8?q?Sincronizaci=C3=B3n=20con=20LDAP?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- debian/changelog | 2 +- debian/control | 2 +- rest/core/account.php | 170 +++++++++++++++++++++++++++++++++--------- rest/core/login.php | 10 +++ 4 files changed, 148 insertions(+), 36 deletions(-) diff --git a/debian/changelog b/debian/changelog index afbb328e..6182d01a 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,4 @@ -hedera-web (1.405.2) stable; urgency=low +hedera-web (1.405.3) stable; urgency=low * Initial Release. diff --git a/debian/control b/debian/control index 87ac690d..a3a71323 100644 --- a/debian/control +++ b/debian/control @@ -9,7 +9,7 @@ Vcs-Git: git://www.verdnatura.es/var/git/hedera-web Package: hedera-web Architecture: all -Depends: apache2, php5-mysql, php5-mcrypt, php5-ssh2, php-vn-lib, nodejs +Depends: apache2, php5-mysql, php5-mcrypt, php5-ldap, php5-ssh2, php-vn-lib, nodejs Suggests: php-text-captcha, php5-imap, tinymce Section: misc Priority: optional diff --git a/rest/core/account.php b/rest/core/account.php index 1984e7ba..68188ef5 100755 --- a/rest/core/account.php +++ b/rest/core/account.php @@ -2,7 +2,20 @@ class Account { - static function sync ($db, $user, $password = NULL) + static function trySync ($db, $user, $password = NULL) + { + $isSync = $db->getValue ( + 'SELECT sync FROM account.user WHERE name = #', + [$user] + ); + + if ($isSync) + return; + + self::sync ($db, $user, $password); + } + + static function sync ($db, $user, $password = NULL, $force = TRUE) { $hasAccount = $db->getValue ( 'SELECT COUNT(*) > 0 @@ -12,61 +25,142 @@ class Account [$user] ); - if (!$hasAccount) + if ($hasAccount) + { + self::ldapSync ($db, $user, $password); + self::sambaSync ($db, $user, $password); + } + + $db->query ( + 'UPDATE account.user SET sync = TRUE WHERE name = #', + [$user] + ); + } + + /** + * Synchronizes the user credentials in the LDAP server. + */ + static function ldapSync ($db, $user, $password) + { + if (empty ($password)) return; - $conf = $db->getRow ( - 'SELECT sambaHost, homesHost, sshUser, sshPass - FROM account.accountConfig' - ); - $sshPass = base64_decode ($conf['sshPass']); - - $samba = new SshConnection ($conf['sambaHost'] - ,$conf['sshUser'] - ,$sshPass - ); - $homes = new SshConnection ($conf['homesHost'] - ,$conf['sshUser'] - ,$sshPass + // Gets LDAP configuration parameters + + $conf = $db->getObject ( + 'SELECT host, rdn, password, baseDn, filter + FROM account.ldapConfig'); + + // Connects an authenticates against server + + $ds = ldap_connect ($conf->host); + + if (!$ds) + throw new Exception ("Can't connect to LDAP server: ". ldapError ($ds)); + + ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3); + $bind = ldap_bind ($ds, $conf->rdn, base64_decode ($conf->password)); + + if (!$bind) + throw new Exception ("Authentication failed on LDAP server: ". ldapError ($ds)); + + // Search the user entry + + $res = ldap_search ($ds, $conf->baseDn, "(&(uid=$user)($conf->filter))"); + + if (!$res) + throw new Exception ("Can't get the LDAP entry: ". ldapError ($ds)); + + $dn = "uid=$user,{$conf->baseDn}"; + $entry = ldap_first_entry ($ds, $res); + + if ($entry) + { + $info = ['userPassword' => sshaEncode ($password)]; + ldap_modify ($ds, $dn, $info); + } + else + { + $info = [ + 'objectClass' => ['account', 'simpleSecurityObject', 'top'], + 'uid' => $user, + 'userPassword' => sshaEncode ($password) + ]; + ldap_add ($ds, $dn, $info); + } + + ldap_unbind ($ds); + } + + /** + * Synchronizes the user credentials in the Samba server. + */ + static function sambaSync ($db, $user, $password) + { + $conf = $db->getObject ( + 'SELECT host, sshUser, sshPass, domain, uidBase + FROM account.sambaConfig' ); - $escUser = SshConnection::escape ($user); + $samba = new SshConnection ($conf->host + ,$conf->sshUser + ,base64_decode ($conf->sshPass) + ); + + $scriptDir = '/mnt/cluster/scripts'; // Creates the Samba user and initializes it's home directory $userId = $db->getValue ( 'SELECT id FROM account.user WHERE name = #', [$user]); - $accConf = $db->getRow ( - 'SELECT uidBase, domain FROM account.accountConfig'); - $escUid = SshConnection::escape ($accConf['uidBase'] + $userId); - $escMail = SshConnection::escape ("$user@{$accConf['domain']}"); - - $samba->exec ( - "/mnt/cluster/scripts/create-user.sh $escUser $escUid $escMail"); - $homes->exec ( - "/mnt/storage/scripts/create-user.sh $escUser"); + $samba->exec ("$scriptDir/create-user.sh %s %s %s" + ,$user + ,$conf->uidBase + $userId + ,"$user@{$conf->domain}" + ); // Syncronizes the Samba password if (empty ($password)) return; - $escPassword = SshConnection::escape ($password); - $samba->exec ( - "/mnt/cluster/scripts/set-password.sh $escUser $escPassword"); - - new SshConnection ($conf['homesHost'], $user, $password); + $samba->exec ("$scriptDir/set-password.sh %s %s" + ,$user + ,$password + ); } } +function ldapError ($ds) +{ + return ldap_errno ($ds) .': '. ldap_error ($ds); +} + +function sshaEncode ($value) +{ + mt_srand ((double) microtime () * 1000000); + $salt = pack ('CCCC', mt_rand (), mt_rand (), mt_rand (), mt_rand ()); + $hash = '{SSHA}' . base64_encode (pack ('H*', sha1 ($value . $salt)) . $salt); + return $hash; +} + +function sshaVerify ($hash, $value) +{ + $ohash = base64_decode (substr ($hash, 6)); + $osalt = substr ($ohash, 20); + $ohash = substr ($ohash, 0, 20); + $nhash = pack ('H*', sha1 ($value . $osalt)); + return $ohash == $nhash; +} + class SshConnection { var $connection; /** * Abrebiated method to make SSH connections. - **/ + */ function __construct ($host, $user, $password) { $this->connection = $connection = ssh2_connect ($host); @@ -84,15 +178,23 @@ class SshConnection /** * Executes a command on the host. - **/ - function exec ($command) + */ + function exec () { + $nargs = func_num_args (); + $args = func_get_args (); + + for ($i = 1; $i < $nargs; $i++) + $args[$i] = self::escape ($args[$i]); + + $command = call_user_func_array ('sprintf', $args); + error_log ($command); return ssh2_exec ($this->connection, $command); } /** * Escapes the double quotes from an string. - **/ + */ static function escape ($str) { return '"'. str_replace ('"', '\\"', $str) .'"'; diff --git a/rest/core/login.php b/rest/core/login.php index c1c02bb0..c0b58b31 100755 --- a/rest/core/login.php +++ b/rest/core/login.php @@ -1,9 +1,19 @@ service->createToken ( $_SESSION['user'], !empty ($_POST['remember']) From e9c870b47342603ecd239cea2929f6d85730491b Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Wed, 31 May 2017 13:43:12 +0200 Subject: [PATCH 3/6] =?UTF-8?q?Sincroniza=20usuario=20en=20min=C3=BAsculas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- debian/changelog | 2 +- rest/core/login.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/debian/changelog b/debian/changelog index 6182d01a..de89af2a 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,4 @@ -hedera-web (1.405.3) stable; urgency=low +hedera-web (1.405.4) stable; urgency=low * Initial Release. diff --git a/rest/core/login.php b/rest/core/login.php index c0b58b31..4bafbcca 100755 --- a/rest/core/login.php +++ b/rest/core/login.php @@ -8,7 +8,7 @@ class Login extends Vn\Web\JsonRequest { try { Account::trySync ($db - ,$_POST['user'] + ,strtolower ($_POST['user']) ,$_POST['password'] ); } From 8b6c765af19d54b86d08315c697a3ede68ec2c65 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Wed, 7 Jun 2017 14:19:20 +0200 Subject: [PATCH 4/6] Relevancia --- .gitignore | 1 + debian/changelog | 2 +- forms/ecomerce/catalog/locale/ca.json | 1 + forms/ecomerce/catalog/locale/en.json | 1 + forms/ecomerce/catalog/locale/es.json | 3 ++- forms/ecomerce/catalog/locale/fr.json | 1 + forms/ecomerce/catalog/locale/mn.json | 1 + forms/ecomerce/catalog/locale/pt.json | 1 + forms/ecomerce/catalog/ui.xml | 7 +++++-- 9 files changed, 14 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 3c3629e6..25871d04 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ node_modules +build/ diff --git a/debian/changelog b/debian/changelog index de89af2a..7e4d431b 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,4 @@ -hedera-web (1.405.4) stable; urgency=low +hedera-web (1.405.5) stable; urgency=low * Initial Release. diff --git a/forms/ecomerce/catalog/locale/ca.json b/forms/ecomerce/catalog/locale/ca.json index 0589742e..583e5a50 100755 --- a/forms/ecomerce/catalog/locale/ca.json +++ b/forms/ecomerce/catalog/locale/ca.json @@ -31,6 +31,7 @@ ,"Origin": "Origen" ,"Category": "Categoria" ,"Remove filters": "Esborrar filtres" + ,"Relevancy": "Rellevància" ,"Price": "Precio" ,"Amount": "Quantitat" diff --git a/forms/ecomerce/catalog/locale/en.json b/forms/ecomerce/catalog/locale/en.json index 981bc119..d93ab1f9 100755 --- a/forms/ecomerce/catalog/locale/en.json +++ b/forms/ecomerce/catalog/locale/en.json @@ -31,6 +31,7 @@ ,"Origin": "Origin" ,"Category": "Category" ,"Remove filters": "Remove filters" + ,"Relevancy": "Relevance" ,"Price": "Price" ,"Amount": "Amount" diff --git a/forms/ecomerce/catalog/locale/es.json b/forms/ecomerce/catalog/locale/es.json index 4a588d82..012354e2 100755 --- a/forms/ecomerce/catalog/locale/es.json +++ b/forms/ecomerce/catalog/locale/es.json @@ -40,8 +40,9 @@ ,"Higher price": "Precio más alto" ,"Lower size": "Medida más pequeña" ,"Higher size": "Medida más grande" + ,"Relevancy": "Relevancia" + ,", %.0d Units": ", %.0d Unidades" - ,"from": "desde" ,"from %.2d€": "desde %.2d€" ,"AddToBasket": "Añadir artículo" diff --git a/forms/ecomerce/catalog/locale/fr.json b/forms/ecomerce/catalog/locale/fr.json index 9c9b99eb..4bbdc865 100755 --- a/forms/ecomerce/catalog/locale/fr.json +++ b/forms/ecomerce/catalog/locale/fr.json @@ -31,6 +31,7 @@ ,"Origin": "Origine" ,"Category": "Catégorie" ,"Remove filters": "Retirer les filtres" + ,"Relevancy": "Pertinence" ,"Price": "Prix" ,"Amount": "Quantité" diff --git a/forms/ecomerce/catalog/locale/mn.json b/forms/ecomerce/catalog/locale/mn.json index 981bc119..1c6d8df8 100755 --- a/forms/ecomerce/catalog/locale/mn.json +++ b/forms/ecomerce/catalog/locale/mn.json @@ -31,6 +31,7 @@ ,"Origin": "Origin" ,"Category": "Category" ,"Remove filters": "Remove filters" + ,"Relevancy": "хамаарал" ,"Price": "Price" ,"Amount": "Amount" diff --git a/forms/ecomerce/catalog/locale/pt.json b/forms/ecomerce/catalog/locale/pt.json index bfe501f8..9003febb 100644 --- a/forms/ecomerce/catalog/locale/pt.json +++ b/forms/ecomerce/catalog/locale/pt.json @@ -31,6 +31,7 @@ ,"Origin": "Orígem" ,"Category": "Categoria" ,"Remove filters": "Eliminar filtros" + ,"Relevancy": "Relevância" ,"Price": "Preço" ,"Amount": "Quantidade" diff --git a/forms/ecomerce/catalog/ui.xml b/forms/ecomerce/catalog/ui.xml index baabdb05..2125b998 100755 --- a/forms/ecomerce/catalog/ui.xml +++ b/forms/ecomerce/catalog/ui.xml @@ -78,7 +78,7 @@ LEFT JOIN vn_locale.color_view c ON c.color_id = a.Color LEFT JOIN vn_locale.origin_view o ON o.origin_id = a.id_origen WHERE b.available > 0 - ORDER BY a.Article, a.Medida + ORDER BY a.relevancy, a.Article, a.Medida LIMIT 400; @@ -366,7 +366,10 @@

Order by

-