0
1
Fork 0

PHP 7.3 upgrade, bugs fixed, improved JS log

This commit is contained in:
Juan Ferrer 2019-09-05 18:16:10 +02:00
parent d04ba0695a
commit ccfbdbd9f5
13 changed files with 126 additions and 147 deletions

2
debian/changelog vendored
View File

@ -1,4 +1,4 @@
hedera-web (1.406.61) stable; urgency=low hedera-web (1.406.62) stable; urgency=low
* Initial Release. * Initial Release.

2
debian/control vendored
View File

@ -9,7 +9,7 @@ Vcs-Git: https://git.verdnatura.es/hedera-web
Package: hedera-web Package: hedera-web
Architecture: all Architecture: all
Depends: apache2 | httpd, nodejs, php-cli, php-vn-lib, php-apcu, php-ldap, php-ssh2, php-mcrypt, php-imap Depends: apache2 | httpd, nodejs, php-cli, php-vn-lib, php-apcu, php-ldap, php-ssh2, php-imap
Suggests: php-text-captcha, php-soap, libphp-phpmailer, php-gd Suggests: php-text-captcha, php-soap, libphp-phpmailer, php-gd
Section: misc Section: misc
Priority: optional Priority: optional

2
debian/postinst vendored
View File

@ -10,6 +10,6 @@ then
apache2_invoke enconf hedera-web.conf apache2_invoke enconf hedera-web.conf
fi fi
service php7.0-fpm restart #service php7.3-fpm restart
service cron restart service cron restart

View File

@ -1,11 +1,9 @@
Hedera.Home = new Class Hedera.Home = new Class({
({
Extends: Hedera.Form Extends: Hedera.Form
,onStartOrderClick: function () ,onStartOrderClick: function() {
{ this.hash.set({'form': 'ecomerce/catalog'});
this.hash.set ({'form': 'ecomerce/catalog'});
} }
}); });

View File

@ -1,225 +1,199 @@
var Login = require ('./login'); var Login = require('./login');
var Gui = require ('./gui'); var Gui = require('./gui');
module.exports = new Class module.exports = new Class({
({
Extends: Vn.Object, Extends: Vn.Object,
Properties: Properties:
{ {
conn: conn:
{ {
type: Db.Connection type: Db.Connection
,get: function () ,get: function() {
{
return this._conn; return this._conn;
} }
} }
} }
,initialize: function () ,initialize: function() {
{ window.onerror = this._onWindowError.bind(this);
window.onerror = this._onWindowError.bind (this); window.onunload = this._onWindowUnload.bind(this);
window.onunload = this._onWindowUnload.bind (this); Vn.Hash.initialize();
Vn.Hash.initialize ();
var conn = new Db.Connection (); var conn = new Db.Connection();
this.link ({_conn: conn}, {'error': this._onConnError}); this.link({_conn: conn}, {'error': this._onConnError});
this.initAutoLogin (); this.initAutoLogin();
} }
,run: function () ,run: function() {
{ if (this.tryAutoLogin())
if (this.tryAutoLogin ())
return; return;
var login = this._login = new Login ({conn: this._conn}); var login = this._login = new Login({conn: this._conn});
login.on ('login', this._onLogin, this); login.on('login', this._onLogin, this);
login.show (); login.show();
} }
,_onLogin: function () ,_onLogin: function() {
{ this._freeLogin();
this._freeLogin ();
if (this._gui) if (this._gui)
return; return;
var gui = this._gui = new Gui ({conn: this._conn}); var gui = this._gui = new Gui({conn: this._conn});
gui.on ('logout', this._onLogout, this); gui.on('logout', this._onLogout, this);
gui.show (); gui.show();
} }
,_onLogout: function () ,_onLogout: function() {
{ this.clearAutoLogin();
this.clearAutoLogin (); this._freeGui();
this._freeGui (); this.run();
this.run ();
} }
,_onWindowUnload: function () ,_onWindowUnload: function() {
{ this.unref();
this.unref ();
} }
,_onWindowError: function (message, file, line, col, err) ,_onWindowError: function(message, file, line, col, err) {
{ var error = new Error(message);
var error = new Error (message);
error.fileName = file; error.fileName = file;
error.lineNumber = line; error.lineNumber = line;
this._notifyError (error); this._notifyError(error);
} }
,_onConnError: function (conn, error) ,_onConnError: function(conn, error) {
{
if (error instanceof Vn.JsonException) if (error instanceof Vn.JsonException)
switch (error.exception) switch (error.exception) {
{
case 'BadLogin': case 'BadLogin':
Htk.Toast.showError (_('Invalid login')); Htk.Toast.showError(_('Invalid login'));
this._logout (); this._logout();
break; break;
case 'SessionExpired': case 'SessionExpired':
Htk.Toast.showError (_('You\'ve been too idle')); Htk.Toast.showError(_('You\'ve been too idle'));
this._logout (); this._logout();
break; break;
case 'OutdatedVersion': case 'OutdatedVersion':
this._newVersion (error); this._newVersion(error);
break; break;
default: default:
Htk.Toast.showError (error.message); Htk.Toast.showError(error.message);
} }
else else {
{ console.error(error);
console.error (error); this._notifyError(error);
this._notifyError (error);
} }
} }
,_logout: function () ,_logout: function() {
{
if (this._gui) if (this._gui)
this._gui.logout (); this._gui.logout();
} }
,_newVersion: function () ,_newVersion: function() {
{
if (this.ignoreVersion) if (this.ignoreVersion)
return; return;
this.ignoreVersion = true; this.ignoreVersion = true;
var dialog = new Htk.Dialog ({ var dialog = new Htk.Dialog({
message: _('New version available') message: _('New version available')
,buttons: Htk.Dialog.Button.ACCEPT ,buttons: Htk.Dialog.Button.ACCEPT
,icon: 'warning' ,icon: 'warning'
}); });
dialog.on ('response', this._onNewVersionResponse, this); dialog.on('response', this._onNewVersionResponse, this);
dialog.open (); dialog.open();
} }
,_onNewVersionResponse: function () ,_onNewVersionResponse: function() {
{ location.reload();
location.reload ();
} }
,_notifyError: function (error) ,_notifyError: function(error) {
{ Htk.Toast.showError(_('Something went wrong'));
Htk.Toast.showError (_('Something went wrong'));
var params = { var params = {
file: error.fileName file: error.fileName
,line: error.lineNumber ,line: error.lineNumber
,message: error.message ,message: error.message
,stack: error.stack ,stack: error.stack
,agent: navigator.userAgent
,location: location.href
}; };
this._conn.send ('core/log', params); this._conn.send('core/log', params);
} }
,_freeLogin: function () ,_freeLogin: function() {
{ if (this._login) {
if (this._login) this._login.disconnectByInstance(this);
{ this._login.hide();
this._login.disconnectByInstance (this); this._login.unref();
this._login.hide ();
this._login.unref ();
this._login = null; this._login = null;
} }
} }
,_freeGui: function () ,_freeGui: function() {
{ if (this._gui) {
if (this._gui) this._gui.disconnectByInstance(this);
{ this._gui.hide();
this._gui.disconnectByInstance (this); this._gui.unref();
this._gui.hide ();
this._gui.unref ();
this._gui = null; this._gui = null;
} }
} }
,_destroy: function () ,_destroy: function() {
{ this._freeLogin();
this._freeLogin (); this._freeGui();
this._freeGui (); this.deinitAutoLogin();
this.deinitAutoLogin (); this._conn.unref();
this._conn.unref ();
} }
// Auto login functionality // Auto login functionality
,_firstLogin: true ,_firstLogin: true
,initAutoLogin: function () ,initAutoLogin: function() {
{ var isGuest = new Vn.HashParam({
var isGuest = new Vn.HashParam
({
type: Boolean, type: Boolean,
key: 'guest' key: 'guest'
}); });
this.link ({_isGuest: isGuest}, {'changed': this._onGuestChange}); this.link({_isGuest: isGuest}, {'changed': this._onGuestChange});
var token = new Vn.HashParam var token = new Vn.HashParam({
({
type: String, type: String,
key: 'token' key: 'token'
}); });
this.link ({_token: token}, {'changed': this._onTokenChange}); this.link({_token: token}, {'changed': this._onTokenChange});
} }
,_onGuestChange: function () ,_onGuestChange: function() {
{
if (this._isGuest.value) if (this._isGuest.value)
setTimeout (this.tryAutoLogin.bind (this)); setTimeout(this.tryAutoLogin.bind(this));
} }
,_onTokenChange: function () ,_onTokenChange: function() {
{
if (this._token.value) if (this._token.value)
setTimeout (this.tryAutoLogin.bind (this)); setTimeout(this.tryAutoLogin.bind(this));
} }
,deinitAutoLogin: function () ,deinitAutoLogin: function() {
{ this._isGuest.unref();
this._isGuest.unref (); this._token.unref();
this._token.unref ();
} }
,autoLogin: function () ,autoLogin: function() {
{ var guest = localStorage.getItem('hederaGuest');
var guest = localStorage.getItem ('hederaGuest');
if (this._isGuest.value || guest) if (this._isGuest.value || guest) {
{ localStorage.setItem('hederaGuest', true);
localStorage.setItem ('hederaGuest', true);
return true; return true;
} }
if (this._token.value) if (this._token.value)
this._conn.token = this._token.value; this._conn.token = this._token.value;
else else
this._conn.fetchToken (); this._conn.fetchToken();
if (this._conn.token) if (this._conn.token)
return true; return true;
@ -227,9 +201,8 @@ module.exports = new Class
return false; return false;
} }
,tryAutoLogin: function () ,tryAutoLogin: function() {
{ var ok = this.autoLogin();
var ok = this.autoLogin ();
this._firstLogin = false; this._firstLogin = false;
this._isGuest.value = undefined; this._isGuest.value = undefined;
@ -238,13 +211,12 @@ module.exports = new Class
if (!ok) if (!ok)
return false; return false;
this._onLogin (); this._onLogin();
return true; return true;
} }
,clearAutoLogin: function () ,clearAutoLogin: function() {
{ localStorage.removeItem('hederaGuest');
localStorage.removeItem ('hederaGuest');
} }
}); });

View File

@ -1,6 +1,6 @@
{ {
"name": "hedera-web", "name": "hedera-web",
"version": "1.406.61", "version": "1.406.62",
"description": "Verdnatura web page", "description": "Verdnatura web page",
"license": "GPL-3.0", "license": "GPL-3.0",
"repository": { "repository": {

View File

@ -1,5 +0,0 @@
{
"InvalidAction": "Invalid action"
,"EmptyQuery": "Empty query"
}

View File

@ -2,21 +2,30 @@
class Log extends Vn\Web\JsonRequest { class Log extends Vn\Web\JsonRequest {
const PARAMS = [ const PARAMS = [
'file' 'message'
,'file'
,'line' ,'line'
,'message' ,'location'
,'agent'
,'stack' ,'stack'
]; ];
function run($db) { function run($db) {
$user = isset($_SESSION['user']) ? $_SESSION['user'] : 'guest'; $user = isset($_SESSION['user']) ? $_SESSION['user'] : 'guest';
error_log(sprintf("Javascript: User: %s: %s(%d): %s.\n%s" $message = $_REQUEST['message'];
,$user $file = $_REQUEST['file'];
,$_REQUEST['file'] $line = $_REQUEST['line'];
,$_REQUEST['line'] $location = $_REQUEST['location'];
,$_REQUEST['message'] $agent = $_REQUEST['agent'];
,$_REQUEST['stack'] $stack = $_REQUEST['stack'];
));
error_log(
"Javascript: $message in $file($line)"
."\nLocation: $location"
."\nAgent: $agent"
."\nUser: $user"
."\nStack: $stack"
);
return TRUE; return TRUE;
} }
} }

View File

@ -4,6 +4,9 @@ include __DIR__.'/account.php';
class Login extends Vn\Web\JsonRequest { class Login extends Vn\Web\JsonRequest {
function run($db) { function run($db) {
if (!$_POST['user'])
throw new Vn\Web\BadLoginException();
try { try {
Account::trySync($db Account::trySync($db
,strtolower($_POST['user']) ,strtolower($_POST['user'])

View File

@ -1,8 +1,9 @@
<?php <?php
require_once('libphp-phpmailer/PHPMailerAutoload.php'); require_once('libphp-phpmailer/autoload.php');
use Vn\Lib; use Vn\Lib;
use PHPMailer\PHPMailer\PHPMailer;
class Contact extends Vn\Web\JsonRequest { class Contact extends Vn\Web\JsonRequest {
const PARAMS = [ const PARAMS = [

View File

@ -1,6 +1,6 @@
<?php <?php
require_once('libphp-phpmailer/PHPMailerAutoload.php'); require_once('libphp-phpmailer/autoload.php');
class Mail extends Vn\Lib\Method { class Mail extends Vn\Lib\Method {
function run($db) { function run($db) {

View File

@ -7,7 +7,7 @@ class Transaction extends Vn\Web\JsonRequest {
const PARAMS = ['amount']; const PARAMS = ['amount'];
function run($db) { function run($db) {
$amount =(int) $_REQUEST['amount']; $amount = (int) $_REQUEST['amount'];
$companyId = empty($_REQUEST['company']) ? NULL : $_REQUEST['company']; $companyId = empty($_REQUEST['company']) ? NULL : $_REQUEST['company'];
$row = $db->getObject('CALL myTpvTransaction_start(#, #)', $row = $db->getObject('CALL myTpvTransaction_start(#, #)',

View File

@ -2,9 +2,10 @@
namespace Vn\Web; namespace Vn\Web;
require_once 'libphp-phpmailer/PHPMailerAutoload.php'; require_once 'libphp-phpmailer/autoload.php';
use Vn\Lib\UserException; use Vn\Lib\UserException;
use PHPMailer\PHPMailer\PHPMailer;
class Mailer { class Mailer {
private $conf; private $conf;
@ -19,7 +20,7 @@ class Mailer {
function createObject($mailTo, $body, $subject) { function createObject($mailTo, $body, $subject) {
$conf = $this->conf; $conf = $this->conf;
$mail = new \PHPMailer(); $mail = new PHPMailer();
$mail->isSMTP(); $mail->isSMTP();
$mail->Host = $conf->host; $mail->Host = $conf->host;