diff --git a/debian/changelog b/debian/changelog index 48dd67f4..421f8d85 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,4 @@ -hedera-web (1.379-deb8) stable; urgency=low +hedera-web (1.381-deb8) stable; urgency=low * Initial Release. diff --git a/debian/cron.d b/debian/cron.d index d4b0bc1b..8b976597 100644 --- a/debian/cron.d +++ b/debian/cron.d @@ -1,8 +1,8 @@ MAILTO=webmaster -*/4 * * * * root /usr/share/hedera-web/cli.php -m tpv/confirm-mail -*/2 * * * * root /usr/share/hedera-web/cli.php -m edi/load -0 23 * * * root /usr/share/hedera-web/cli.php -m edi/clean -0 5 * * * root /usr/share/hedera-web/cli.php -m edi/update -*/1 * * * * root /usr/share/hedera-web/cli.php -m misc/mail -0 5 * * * root /usr/share/hedera-web/cli.php -m misc/exchange-rate -45 14 20 11 * root /usr/share/hedera-web/cli.php -m misc/exchange-rate +*/4 * * * * root hedera-web.php -m tpv/confirm-mail +*/2 * * * * root hedera-web.php -m edi/load +0 23 * * * root hedera-web.php -m edi/clean +0 5 * * * root hedera-web.php -m edi/update +*/1 * * * * root hedera-web.php -m misc/mail +0 5 * * * root hedera-web.php -m misc/exchange-rate +45 14 20 11 * root hedera-web.php -m misc/exchange-rate diff --git a/debian/install b/debian/install index 4150dcdc..a66ac084 100644 --- a/debian/install +++ b/debian/install @@ -1,6 +1,7 @@ conf/* etc/hedera-web web usr/share/php/vn doc/* usr/share/doc/hedera-web +hedera-web.php usr/bin forms usr/share/hedera-web image usr/share/hedera-web js usr/share/hedera-web @@ -9,6 +10,5 @@ pages usr/share/hedera-web reports usr/share/hedera-web rest usr/share/hedera-web index.php usr/share/hedera-web -cli.php usr/share/hedera-web package.json usr/share/hedera-web build usr/share/hedera-web diff --git a/env.php b/env.php index 528ae42a..b20e31ba 100644 --- a/env.php +++ b/env.php @@ -11,4 +11,3 @@ const _CONFIG_DIR = __DIR__.'/../../.config'; const _LOG_DIR = '/tmp'; const _DATA_DIR = '/tmp'; -?> diff --git a/forms/account/conf/conf.js b/forms/account/conf/conf.js index e3e0f205..0e7246d6 100644 --- a/forms/account/conf/conf.js +++ b/forms/account/conf/conf.js @@ -37,14 +37,12 @@ Hedera.Conf = new Class if (newPassword !== repeatedPassword) throw new Error (_('Passwords doesn\'t match')); - var batch = new Sql.Batch (); - batch.addValues ({ + var params = { 'oldPassword': oldPassword, 'newPassword': newPassword - }); - - var query = 'CALL account.userChangePassword (#oldPassword, #newPassword)'; - this.conn.execQuery (query, this.onPasswordUpdate.bind (this), batch); + }; + this.conn.send ('core/change-password', params, + this._onPassChange.bind (this)); } catch (e) { @@ -52,15 +50,15 @@ Hedera.Conf = new Class } } - ,onPasswordUpdate: function (resultSet) + ,_onPassChange: function (json, error) { - try { - resultSet.fetchResult (); + if (json) + { this.$('change-password').hide (); Htk.Toast.showMessage (_('Password changed!')); this.$('user-form').refresh (); } - catch (e) + else { Htk.Toast.showError (_('Password doesn\'t meet the requirements')); this.$('old-password').select (); diff --git a/forms/admin/connections/ui.xml b/forms/admin/connections/ui.xml index f47a4c6d..ecc8761d 100755 --- a/forms/admin/connections/ui.xml +++ b/forms/admin/connections/ui.xml @@ -22,7 +22,7 @@ - SELECT s.id, vu.user userId, vu.stamp, c.Cliente, s.lastUpdate, + SELECT vu.user userId, vu.stamp, c.Cliente, s.lastUpdate, a.platform, a.browser, a.version, u.name user FROM userSession s JOIN visitUser vu ON vu.id = s.userVisit diff --git a/forms/ecomerce/ticket/ticket.js b/forms/ecomerce/ticket/ticket.js index c0d1a5cf..859bc98a 100644 --- a/forms/ecomerce/ticket/ticket.js +++ b/forms/ecomerce/ticket/ticket.js @@ -3,6 +3,16 @@ Hedera.Ticket = new Class ({ Extends: Hedera.Form + ,onTicketChange: function (ticket) + { + if (!ticket.value) + return; + + var batch = new Sql.Batch (); + batch.addValue ('ticket', ticket.value); + this.conn.execQuery ('CALL ticketLog (#ticket)', null, batch); + } + ,onPrintClick: function (event) { var batch = new Sql.Batch (); diff --git a/forms/ecomerce/ticket/ui.xml b/forms/ecomerce/ticket/ui.xml index 153b16a4..8732530e 100755 --- a/forms/ecomerce/ticket/ui.xml +++ b/forms/ecomerce/ticket/ui.xml @@ -1,9 +1,9 @@ - + - + SELECT t.id, date, a.Agencia, note, p.name province, zip_code, city, c.name, consignee, invoice, delivery diff --git a/cli.php b/hedera-web.php similarity index 78% rename from cli.php rename to hedera-web.php index 372a5850..90d013e9 100755 --- a/cli.php +++ b/hedera-web.php @@ -1,7 +1,7 @@ #!/usr/bin/php -q getRow ( + 'SELECT sambaHost, homesHost, sshUser, sshPass FROM account.accountConfig'); + $sshPass = base64_decode ($conf['sshPass']); + + $hasAccount = $db->getValue ( + 'SELECT COUNT(*) > 0 + FROM account.user u + JOIN account.account a ON u.id = a.id + WHERE u.name = #', + [$user] + ); + + if (!$hasAccount) + return; + + $sambaSsh = new SshConnection ($conf['sambaHost'] + ,$conf['sshUser'] + ,$sshPass + ); + + if ($sync & self::USER) + { + $userId = $db->getValue ('SELECT id FROM account.user WHERE name = #', [$user]); + $accConf = $db->getRow ('SELECT uidBase, domain FROM account.accountConfig'); + + $escUser = SshConnection::escape ($user); + $escUid = SshConnection::escape ($accConf['uidBase'] + $userId); + $escMail = SshConnection::escape ("$user@{$accConf['domain']}"); + + $sambaSsh->exec ( + "/mnt/cluster/scripts/create-user.sh $escUser $escUid $escMail"); + + $homesSsh = new SshConnection ($conf['homesHost'] + ,$conf['sshUser'] + ,$sshPass + ); + $homesSsh->exec ( + "/mnt/storage/scripts/create-user.sh $escUser"); + } + + if ($sync & self::PASS && !empty ($password)) + { + $escUser = SshConnection::escape ($user); + $escPassword = SshConnection::escape ($password); + $sambaSsh->exec ( + "/mnt/cluster/scripts/set-password.sh $escUser $escPassword"); + + new SshConnection ($conf['homesHost'], $user, $password); + } + } +} + +class SshConnection +{ + var $connection; + + /** + * Abrebiated method to make SSH connections. + **/ + function __construct ($host, $user, $password) + { + $this->connection = $connection = ssh2_connect ($host); + + if (!$connection) + throw new Exception ("Can't connect to SSH server $host"); + + $authOk = ssh2_auth_password ($connection, $user, $password); + + if (!$authOk) + throw new Exception ("SSH authentication failed on server $host"); + + return $connection; + } + + /** + * Executes a command on the host. + **/ + function exec ($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/change-password.php b/rest/core/change-password.php new file mode 100755 index 00000000..1d3d1d63 --- /dev/null +++ b/rest/core/change-password.php @@ -0,0 +1,23 @@ +query ('CALL account.userChangePassword (#, #)', + [$oldPassword, $newPassword]); + Account::sync ($db, $_SESSION['user'], $newPassword, Account::PASS); + return TRUE; + } +} + diff --git a/rest/core/login.php b/rest/core/login.php index 7299cb18..c1c02bb0 100755 --- a/rest/core/login.php +++ b/rest/core/login.php @@ -4,15 +4,6 @@ class Login extends Vn\Web\JsonRequest { function run ($db) { - try { - $this->updateCredentials ($db); - //$this->updateCredentialsLdap ($db); - } - catch (Exception $e) - { - error_log ($e->getMessage ()); - } - $token = $this->service->createToken ( $_SESSION['user'], !empty ($_POST['remember']) @@ -23,71 +14,5 @@ class Login extends Vn\Web\JsonRequest 'token' => $token ]; } - - /** - * Updates the user credentials in other user databases like Samba - * LDAP . - **/ - function updateCredentialsLdap ($db) - { - $host = $ldapConf['host']; - - if ($ldapConf->secure) - $ldapHost = "ldaps://$host"; - else - $ldapHost = "ldap://$host"; - - $ldap = ldap_connect ($ldapHost, $ldapConf['port']); - - if (!ldap_bind ($ldap, $ldapConf['user'], $ldapConf['password'])) - throw new Exception ('LDAP authentication failed'); - - error_log ('Connected to LDAP!'); - } - - /** - * Updates the user credentials in other user databases like Samba. - **/ - function updateCredentials ($db) - { - if (empty ($_POST['password'])) - return; - - $hasAccount = $db->getValue ( - 'SELECT COUNT(*) > 0 - FROM account.user u - JOIN account.account a ON u.id = a.id - WHERE u.name = #', - [$_SESSION['user']] - ); - - if (!$hasAccount) - return; - - $sshConf = $db->getRow ('SELECT host, user, password FROM ssh_config'); - - $ssh = ssh2_connect ($sshConf['host']); - - if (!$ssh) - throw new Exception ("Can't connect to SSH server {$sshConf['host']}"); - - $sshAuth = ssh2_auth_password ($ssh, - $sshConf['user'], base64_decode ($sshConf['password'])); - - if (!$sshAuth) - throw new Exception ("SSH authentication failed"); - - $user = $this->escape ($_SESSION['user']); - $pass = $this->escape ($_POST['password']); - $stream = ssh2_exec ($ssh, "samba-tool user create \"$user\" \"$pass\""); - } - - /** - * Escapes the double quotes from an string. - **/ - function escape ($str) - { - return str_replace ('"', '\\"', $str); - } } diff --git a/rest/core/set-password.php b/rest/core/set-password.php new file mode 100755 index 00000000..446390c3 --- /dev/null +++ b/rest/core/set-password.php @@ -0,0 +1,26 @@ +query ('CALL account.userSetPassword (#, #)', + [$setUser, $setPassword]); + Account::sync ($db, $setUser, $setPassword, Account::PASS); + return TRUE; + } +} + diff --git a/rest/core/sync-user.php b/rest/core/sync-user.php new file mode 100755 index 00000000..21b0abd1 --- /dev/null +++ b/rest/core/sync-user.php @@ -0,0 +1,19 @@ +query ( - 'SELECT presentation_order, feature ' - .'FROM item_feature WHERE item_id = #ref ' - .'AND expiry_date IS NULL' + 'SELECT presentation_order, feature + FROM item_feature + WHERE item_id = #ref + AND entry_date <= CURDATE() + AND (expiry_date IS NULL OR expiry_date >= CURDATE()) + GROUP BY presentation_order' ,$ediValues ); diff --git a/web/html-service.php b/web/html-service.php index b0745f9d..0b196b96 100644 --- a/web/html-service.php +++ b/web/html-service.php @@ -103,7 +103,12 @@ class HtmlService extends Service function getUrl ($fileName) { - return $fileName .'?'. $this->getVersion (); + if (file_exists ($fileName)) + $mTime = '?'. strftime ('%G%m%d%H%M%S', filemtime ($fileName)); + else + $mTime = '?'. $this->getVersion (); + + return $fileName.$mTime; } function includeJs ($fileName) diff --git a/web/service.php b/web/service.php index 61ec5444..985d4101 100755 --- a/web/service.php +++ b/web/service.php @@ -267,7 +267,7 @@ abstract class Service { $isAuthorized = $db->getValue ('SELECT userCheckRestPriv (#)', [$_REQUEST['method']]); - + if (!$isAuthorized) throw new UserException (s('You don\'t have enough privileges'));