EDI update bugs solved, PHP linting
This commit is contained in:
parent
063d9b92e8
commit
a57498548f
|
@ -1,4 +1,4 @@
|
||||||
hedera-web (1.406.02) stable; urgency=low
|
hedera-web (1.406.03) stable; urgency=low
|
||||||
|
|
||||||
* Initial Release.
|
* Initial Release.
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "hedera-web",
|
"name": "hedera-web",
|
||||||
"version": "1.406.02",
|
"version": "1.406.03",
|
||||||
"description": "Verdnatura web page",
|
"description": "Verdnatura web page",
|
||||||
"license": "GPL-3.0",
|
"license": "GPL-3.0",
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
class Account
|
class Account {
|
||||||
{
|
static function trySync($db, $userName, $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 = #',
|
||||||
[$userName]
|
[$userName]
|
||||||
|
@ -15,8 +13,7 @@ class Account
|
||||||
self::sync($db, $userName, $password);
|
self::sync($db, $userName, $password);
|
||||||
}
|
}
|
||||||
|
|
||||||
static function sync ($db, $userName, $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
|
||||||
|
@ -25,8 +22,7 @@ class Account
|
||||||
[$userName]
|
[$userName]
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($hasAccount)
|
if ($hasAccount) {
|
||||||
{
|
|
||||||
self::ldapSync($db, $userName, $password);
|
self::ldapSync($db, $userName, $password);
|
||||||
self::sambaSync($db, $userName, $password);
|
self::sambaSync($db, $userName, $password);
|
||||||
}
|
}
|
||||||
|
@ -40,8 +36,7 @@ class Account
|
||||||
/**
|
/**
|
||||||
* Synchronizes the user credentials in the LDAP server.
|
* Synchronizes the user credentials in the LDAP server.
|
||||||
*/
|
*/
|
||||||
static function ldapSync ($db, $userName, $password)
|
static function ldapSync($db, $userName, $password) {
|
||||||
{
|
|
||||||
// Gets LDAP configuration parameters
|
// Gets LDAP configuration parameters
|
||||||
|
|
||||||
$conf = $db->getObject(
|
$conf = $db->getObject(
|
||||||
|
@ -110,28 +105,24 @@ class Account
|
||||||
|
|
||||||
$classes = ldap_get_values($ds, $entry, 'objectClass');
|
$classes = ldap_get_values($ds, $entry, 'objectClass');
|
||||||
|
|
||||||
if (!in_array ('inetOrgPerson', $classes))
|
if (!in_array('inetOrgPerson', $classes)) {
|
||||||
{
|
|
||||||
ldap_delete($ds, $dn);
|
ldap_delete($ds, $dn);
|
||||||
$entry = NULL;
|
$entry = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($entry)
|
if ($entry) {
|
||||||
{
|
|
||||||
$modifs = [];
|
$modifs = [];
|
||||||
$curAttrs = ldap_get_attributes($ds, $entry);
|
$curAttrs = ldap_get_attributes($ds, $entry);
|
||||||
|
|
||||||
foreach($attrs as $attribute => $value)
|
foreach($attrs as $attribute => $value)
|
||||||
if (!empty ($value))
|
if (!empty($value)) {
|
||||||
{
|
|
||||||
$modifs[] = [
|
$modifs[] = [
|
||||||
'attrib' => $attribute,
|
'attrib' => $attribute,
|
||||||
'modtype' => LDAP_MODIFY_BATCH_REPLACE,
|
'modtype' => LDAP_MODIFY_BATCH_REPLACE,
|
||||||
'values' => [$value]
|
'values' => [$value]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
elseif (isset ($curAttrs[$attribute]))
|
elseif (isset($curAttrs[$attribute])) {
|
||||||
{
|
|
||||||
$modifs[] = [
|
$modifs[] = [
|
||||||
'attrib' => $attribute,
|
'attrib' => $attribute,
|
||||||
'modtype' => LDAP_MODIFY_BATCH_REMOVE_ALL
|
'modtype' => LDAP_MODIFY_BATCH_REMOVE_ALL
|
||||||
|
@ -140,8 +131,7 @@ class Account
|
||||||
|
|
||||||
$updated = ldap_modify_batch($ds, $dn, $modifs);
|
$updated = ldap_modify_batch($ds, $dn, $modifs);
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
$addAttrs = [];
|
$addAttrs = [];
|
||||||
|
|
||||||
foreach($attrs as $attribute => $value)
|
foreach($attrs as $attribute => $value)
|
||||||
|
@ -158,8 +148,7 @@ class Account
|
||||||
if (!$updated)
|
if (!$updated)
|
||||||
throw new Exception("Can't update the LDAP entry: ". ldapError($ds));
|
throw new Exception("Can't update the LDAP entry: ". ldapError($ds));
|
||||||
}
|
}
|
||||||
catch (Exception $e)
|
catch (Exception $e) {
|
||||||
{
|
|
||||||
ldap_unbind($ds);
|
ldap_unbind($ds);
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
|
@ -168,8 +157,7 @@ class Account
|
||||||
/**
|
/**
|
||||||
* Synchronizes the user credentials in the Samba server.
|
* Synchronizes the user credentials in the Samba server.
|
||||||
*/
|
*/
|
||||||
static function sambaSync ($db, $userName, $password)
|
static function sambaSync($db, $userName, $password) {
|
||||||
{
|
|
||||||
$conf = $db->getObject(
|
$conf = $db->getObject(
|
||||||
'SELECT host, sshUser, sshPass, uidBase
|
'SELECT host, sshUser, sshPass, uidBase
|
||||||
FROM account.sambaConfig'
|
FROM account.sambaConfig'
|
||||||
|
@ -207,21 +195,18 @@ class Account
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function ldapError ($ds)
|
function ldapError($ds) {
|
||||||
{
|
|
||||||
return ldap_errno($ds) .': '. ldap_error($ds);
|
return ldap_errno($ds) .': '. ldap_error($ds);
|
||||||
}
|
}
|
||||||
|
|
||||||
function sshaEncode ($value)
|
function sshaEncode($value) {
|
||||||
{
|
|
||||||
mt_srand((double) microtime() * 1000000);
|
mt_srand((double) microtime() * 1000000);
|
||||||
$salt = pack('CCCC', mt_rand(), mt_rand(), mt_rand(), mt_rand());
|
$salt = pack('CCCC', mt_rand(), mt_rand(), mt_rand(), mt_rand());
|
||||||
$hash = '{SSHA}' . base64_encode(pack('H*', sha1($value . $salt)) . $salt);
|
$hash = '{SSHA}' . base64_encode(pack('H*', sha1($value . $salt)) . $salt);
|
||||||
return $hash;
|
return $hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
function sshaVerify ($hash, $value)
|
function sshaVerify($hash, $value) {
|
||||||
{
|
|
||||||
$ohash = base64_decode(substr($hash, 6));
|
$ohash = base64_decode(substr($hash, 6));
|
||||||
$osalt = substr($ohash, 20);
|
$osalt = substr($ohash, 20);
|
||||||
$ohash = substr($ohash, 0, 20);
|
$ohash = substr($ohash, 0, 20);
|
||||||
|
@ -229,15 +214,13 @@ function sshaVerify ($hash, $value)
|
||||||
return $ohash == $nhash;
|
return $ohash == $nhash;
|
||||||
}
|
}
|
||||||
|
|
||||||
class SshConnection
|
class SshConnection {
|
||||||
{
|
|
||||||
var $connection;
|
var $connection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abrebiated method to make SSH connections.
|
* Abrebiated method to make SSH connections.
|
||||||
*/
|
*/
|
||||||
function __construct ($host, $user, $password)
|
function __construct($host, $user, $password) {
|
||||||
{
|
|
||||||
$this->connection = $connection = ssh2_connect($host);
|
$this->connection = $connection = ssh2_connect($host);
|
||||||
|
|
||||||
if (!$connection)
|
if (!$connection)
|
||||||
|
@ -254,8 +237,7 @@ class SshConnection
|
||||||
/**
|
/**
|
||||||
* Executes a command on the host.
|
* Executes a command on the host.
|
||||||
*/
|
*/
|
||||||
function exec ()
|
function exec() {
|
||||||
{
|
|
||||||
$nargs = func_num_args();
|
$nargs = func_num_args();
|
||||||
$args = func_get_args();
|
$args = func_get_args();
|
||||||
|
|
||||||
|
@ -269,8 +251,7 @@ class SshConnection
|
||||||
/**
|
/**
|
||||||
* Escapes the double quotes from an string.
|
* Escapes the double quotes from an string.
|
||||||
*/
|
*/
|
||||||
static function escape ($str)
|
static function escape($str) {
|
||||||
{
|
|
||||||
return '"'. str_replace('"', '\\"', $str) .'"';
|
return '"'. str_replace('"', '\\"', $str) .'"';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,10 +3,8 @@
|
||||||
require_once('PEAR.php');
|
require_once('PEAR.php');
|
||||||
require_once('Text/CAPTCHA.php');
|
require_once('Text/CAPTCHA.php');
|
||||||
|
|
||||||
class Captcha extends Vn\Web\RestRequest
|
class Captcha extends Vn\Web\RestRequest {
|
||||||
{
|
function run($db) {
|
||||||
function run ($db)
|
|
||||||
{
|
|
||||||
$options =
|
$options =
|
||||||
[
|
[
|
||||||
'width' => 130
|
'width' => 130
|
||||||
|
|
|
@ -5,12 +5,10 @@ include __DIR__.'/account.php';
|
||||||
/**
|
/**
|
||||||
* Updates the user password.
|
* Updates the user password.
|
||||||
**/
|
**/
|
||||||
class ChangePassword extends Vn\Web\JsonRequest
|
class ChangePassword extends Vn\Web\JsonRequest {
|
||||||
{
|
|
||||||
const PARAMS = ['newPassword'];
|
const PARAMS = ['newPassword'];
|
||||||
|
|
||||||
function run ($db)
|
function run($db) {
|
||||||
{
|
|
||||||
$newPassword = $_REQUEST['newPassword'];
|
$newPassword = $_REQUEST['newPassword'];
|
||||||
$oldPassword = $_REQUEST['oldPassword'];
|
$oldPassword = $_REQUEST['oldPassword'];
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
class Log extends Vn\Web\JsonRequest
|
class Log extends Vn\Web\JsonRequest {
|
||||||
{
|
|
||||||
const PARAMS = [
|
const PARAMS = [
|
||||||
'file'
|
'file'
|
||||||
,'line'
|
,'line'
|
||||||
|
@ -9,8 +8,7 @@ class Log extends Vn\Web\JsonRequest
|
||||||
,'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"
|
error_log(sprintf("Javascript: User: %s: %s(%d): %s.\n%s"
|
||||||
,$user
|
,$user
|
||||||
|
|
|
@ -2,18 +2,15 @@
|
||||||
|
|
||||||
include __DIR__.'/account.php';
|
include __DIR__.'/account.php';
|
||||||
|
|
||||||
class Login extends Vn\Web\JsonRequest
|
class Login extends Vn\Web\JsonRequest {
|
||||||
{
|
function run($db) {
|
||||||
function run ($db)
|
|
||||||
{
|
|
||||||
try {
|
try {
|
||||||
Account::trySync($db
|
Account::trySync($db
|
||||||
,strtolower($_POST['user'])
|
,strtolower($_POST['user'])
|
||||||
,$_POST['password']
|
,$_POST['password']
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
catch (Exception $e)
|
catch (Exception $e) {
|
||||||
{
|
|
||||||
error_log($e->getMessage());
|
error_log($e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
class Logout extends Vn\Web\JsonRequest
|
class Logout extends Vn\Web\JsonRequest {
|
||||||
{
|
function run($db) {
|
||||||
function run ($db)
|
|
||||||
{
|
|
||||||
$this->service->logout();
|
$this->service->logout();
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,13 +4,11 @@ use Vn\Lib;
|
||||||
use Vn\Web\Security;
|
use Vn\Web\Security;
|
||||||
use Vn\Lib\Type;
|
use Vn\Lib\Type;
|
||||||
|
|
||||||
class Query extends Vn\Web\JsonRequest
|
class Query extends Vn\Web\JsonRequest {
|
||||||
{
|
|
||||||
const PARAMS = ['sql'];
|
const PARAMS = ['sql'];
|
||||||
const SECURITY = Security::INVOKER;
|
const SECURITY = Security::INVOKER;
|
||||||
|
|
||||||
function run ($db)
|
function run($db) {
|
||||||
{
|
|
||||||
$results = [];
|
$results = [];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -19,8 +17,7 @@ class Query extends Vn\Web\JsonRequest
|
||||||
do {
|
do {
|
||||||
$result = $db->storeResult();
|
$result = $db->storeResult();
|
||||||
|
|
||||||
if ($result !== FALSE)
|
if ($result !== FALSE) {
|
||||||
{
|
|
||||||
$results[] = $this->transformResult($result);
|
$results[] = $this->transformResult($result);
|
||||||
$result->free();
|
$result->free();
|
||||||
}
|
}
|
||||||
|
@ -32,13 +29,11 @@ class Query extends Vn\Web\JsonRequest
|
||||||
// Checks for warnings
|
// Checks for warnings
|
||||||
|
|
||||||
if ($db->checkWarnings()
|
if ($db->checkWarnings()
|
||||||
&& ($result = $db->query ('SHOW WARNINGS')))
|
&&($result = $db->query('SHOW WARNINGS'))) {
|
||||||
{
|
|
||||||
$sql = 'SELECT `description`, @warn `code`
|
$sql = 'SELECT `description`, @warn `code`
|
||||||
FROM `message` WHERE `code` = @warn';
|
FROM `message` WHERE `code` = @warn';
|
||||||
|
|
||||||
while ($row = $result->fetch_object ())
|
while ($row = $result->fetch_object()) {
|
||||||
{
|
|
||||||
if ($row->Code == 1265
|
if ($row->Code == 1265
|
||||||
&&($warning = $db->getObject($sql)))
|
&&($warning = $db->getObject($sql)))
|
||||||
trigger_error("{$warning->code}: {$warning->description}", E_USER_WARNING);
|
trigger_error("{$warning->code}: {$warning->description}", E_USER_WARNING);
|
||||||
|
@ -51,10 +46,8 @@ class Query extends Vn\Web\JsonRequest
|
||||||
|
|
||||||
$db->checkError();
|
$db->checkError();
|
||||||
}
|
}
|
||||||
catch (Vn\Db\Exception $e)
|
catch (Vn\Db\Exception $e) {
|
||||||
{
|
if ($e->getCode() == 1644) {
|
||||||
if ($e->getCode () == 1644)
|
|
||||||
{
|
|
||||||
$dbMessage = $e->getMessage();
|
$dbMessage = $e->getMessage();
|
||||||
$sql = 'SELECT `description` FROM `message` WHERE `code` = #';
|
$sql = 'SELECT `description` FROM `message` WHERE `code` = #';
|
||||||
$message = $db->getValue($sql, [$dbMessage]);
|
$message = $db->getValue($sql, [$dbMessage]);
|
||||||
|
@ -72,8 +65,7 @@ class Query extends Vn\Web\JsonRequest
|
||||||
/**
|
/**
|
||||||
* Transforms the database result into a JSON parseable object.
|
* Transforms the database result into a JSON parseable object.
|
||||||
**/
|
**/
|
||||||
function transformResult ($result)
|
function transformResult($result) {
|
||||||
{
|
|
||||||
$tableMap = [];
|
$tableMap = [];
|
||||||
$columns = $result->fetch_fields();
|
$columns = $result->fetch_fields();
|
||||||
|
|
||||||
|
@ -84,12 +76,10 @@ class Query extends Vn\Web\JsonRequest
|
||||||
'tables' => []
|
'tables' => []
|
||||||
];
|
];
|
||||||
|
|
||||||
for ($i = 0; $i < $result->field_count; $i++)
|
for ($i = 0; $i < $result->field_count; $i++) {
|
||||||
{
|
|
||||||
$column = $columns[$i];
|
$column = $columns[$i];
|
||||||
|
|
||||||
switch ($column->type)
|
switch ($column->type) {
|
||||||
{
|
|
||||||
case MYSQLI_TYPE_BIT:
|
case MYSQLI_TYPE_BIT:
|
||||||
$type = Type::BOOLEAN;
|
$type = Type::BOOLEAN;
|
||||||
break;
|
break;
|
||||||
|
@ -118,8 +108,7 @@ class Query extends Vn\Web\JsonRequest
|
||||||
$type = Type::STRING;
|
$type = Type::STRING;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset ($tableMap[$column->table]))
|
if (!isset($tableMap[$column->table])) {
|
||||||
{
|
|
||||||
$resultMap['tables'][] =
|
$resultMap['tables'][] =
|
||||||
[
|
[
|
||||||
'name' => $column->table,
|
'name' => $column->table,
|
||||||
|
@ -151,8 +140,7 @@ class Query extends Vn\Web\JsonRequest
|
||||||
|
|
||||||
$columns = $resultMap['columns'];
|
$columns = $resultMap['columns'];
|
||||||
|
|
||||||
while ($row = $result->fetch_row ())
|
while ($row = $result->fetch_row()) {
|
||||||
{
|
|
||||||
for ($j = 0; $j < $result->field_count; $j++)
|
for ($j = 0; $j < $result->field_count; $j++)
|
||||||
$row[$j] = $this->castValue($row[$j], $columns[$j]['type']);
|
$row[$j] = $this->castValue($row[$j], $columns[$j]['type']);
|
||||||
|
|
||||||
|
@ -165,11 +153,9 @@ class Query extends Vn\Web\JsonRequest
|
||||||
/**
|
/**
|
||||||
* Transforms the database value into a JSON parseable value.
|
* Transforms the database value into a JSON parseable value.
|
||||||
**/
|
**/
|
||||||
function castValue ($value, $type)
|
function castValue($value, $type) {
|
||||||
{
|
|
||||||
if ($value !== NULL)
|
if ($value !== NULL)
|
||||||
switch ($type)
|
switch ($type) {
|
||||||
{
|
|
||||||
case Type::BOOLEAN:
|
case Type::BOOLEAN:
|
||||||
return (bool) $value;
|
return (bool) $value;
|
||||||
case Type::INTEGER:
|
case Type::INTEGER:
|
||||||
|
@ -178,8 +164,7 @@ class Query extends Vn\Web\JsonRequest
|
||||||
return (float) $value;
|
return (float) $value;
|
||||||
case Type::DATE:
|
case Type::DATE:
|
||||||
case Type::DATE_TIME:
|
case Type::DATE_TIME:
|
||||||
return mktime
|
return mktime(
|
||||||
(
|
|
||||||
substr($value, 11 , 2)
|
substr($value, 11 , 2)
|
||||||
,substr($value, 14 , 2)
|
,substr($value, 14 , 2)
|
||||||
,substr($value, 17 , 2)
|
,substr($value, 17 , 2)
|
||||||
|
|
|
@ -2,12 +2,10 @@
|
||||||
|
|
||||||
use Vn\Web;
|
use Vn\Web;
|
||||||
|
|
||||||
class RecoverPassword extends Vn\Web\JsonRequest
|
class RecoverPassword extends Vn\Web\JsonRequest {
|
||||||
{
|
|
||||||
const PARAMS = ['recoverUser'];
|
const PARAMS = ['recoverUser'];
|
||||||
|
|
||||||
function run ($db)
|
function run($db) {
|
||||||
{
|
|
||||||
$user = $db->getRow(
|
$user = $db->getRow(
|
||||||
'SELECT email, active FROM account.user WHERE name = #',
|
'SELECT email, active FROM account.user WHERE name = #',
|
||||||
[$_REQUEST['recoverUser']]
|
[$_REQUEST['recoverUser']]
|
||||||
|
@ -31,8 +29,7 @@ class RecoverPassword extends Vn\Web\JsonRequest
|
||||||
const DIGITS = '1234567890';
|
const DIGITS = '1234567890';
|
||||||
const SYMBOLS = '!$%&()=.';
|
const SYMBOLS = '!$%&()=.';
|
||||||
|
|
||||||
function genPassword ($db)
|
function genPassword($db) {
|
||||||
{
|
|
||||||
$restrictions = $db->getRow(
|
$restrictions = $db->getRow(
|
||||||
'SELECT length, nUpper, nDigits, nPunct FROM account.userPassword');
|
'SELECT length, nUpper, nDigits, nPunct FROM account.userPassword');
|
||||||
|
|
||||||
|
@ -49,8 +46,7 @@ class RecoverPassword extends Vn\Web\JsonRequest
|
||||||
$this->genRands($pass, self::DIGITS, $restrictions['nDigits']);
|
$this->genRands($pass, self::DIGITS, $restrictions['nDigits']);
|
||||||
$this->genRands($pass, self::SYMBOLS, $restrictions['nPunct']);
|
$this->genRands($pass, self::SYMBOLS, $restrictions['nPunct']);
|
||||||
|
|
||||||
for ($i = count ($pass) - 1; $i >= 0; $i--)
|
for ($i = count($pass) - 1; $i >= 0; $i--) {
|
||||||
{
|
|
||||||
$rand = rand(0, $i);
|
$rand = rand(0, $i);
|
||||||
$newPass .= $pass[$rand];
|
$newPass .= $pass[$rand];
|
||||||
array_splice($pass, $rand, 1);
|
array_splice($pass, $rand, 1);
|
||||||
|
@ -59,8 +55,7 @@ class RecoverPassword extends Vn\Web\JsonRequest
|
||||||
return $newPass;
|
return $newPass;
|
||||||
}
|
}
|
||||||
|
|
||||||
function genRands (&$pass, $chars, $max)
|
function genRands(&$pass, $chars, $max) {
|
||||||
{
|
|
||||||
$len = strlen($chars) - 1;
|
$len = strlen($chars) - 1;
|
||||||
|
|
||||||
for ($i = 0; $i < $max; $i++)
|
for ($i = 0; $i < $max; $i++)
|
||||||
|
|
|
@ -5,15 +5,13 @@ include __DIR__.'/account.php';
|
||||||
/**
|
/**
|
||||||
* Sets the user password.
|
* Sets the user password.
|
||||||
**/
|
**/
|
||||||
class SetPassword extends Vn\Web\JsonRequest
|
class SetPassword extends Vn\Web\JsonRequest {
|
||||||
{
|
|
||||||
const PARAMS = [
|
const PARAMS = [
|
||||||
'setUser'
|
'setUser'
|
||||||
,'setPassword'
|
,'setPassword'
|
||||||
];
|
];
|
||||||
|
|
||||||
function run ($db)
|
function run($db) {
|
||||||
{
|
|
||||||
$setUser = $_REQUEST['setUser'];
|
$setUser = $_REQUEST['setUser'];
|
||||||
$setPassword = $_REQUEST['setPassword'];
|
$setPassword = $_REQUEST['setPassword'];
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
class Supplant extends Vn\Web\JsonRequest
|
class Supplant extends Vn\Web\JsonRequest {
|
||||||
{
|
|
||||||
const PARAMS = ['supplantUser'];
|
const PARAMS = ['supplantUser'];
|
||||||
|
|
||||||
function run ($db)
|
function run($db) {
|
||||||
{
|
|
||||||
return $this->service->createToken($_REQUEST['supplantUser']);
|
return $this->service->createToken($_REQUEST['supplantUser']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,12 +6,10 @@ include __DIR__.'/account.php';
|
||||||
* Updates the user credentials on external systems like Samba, create
|
* Updates the user credentials on external systems like Samba, create
|
||||||
* home directory, create mailbox, etc.
|
* home directory, create mailbox, etc.
|
||||||
**/
|
**/
|
||||||
class SyncUser extends Vn\Web\JsonRequest
|
class SyncUser extends Vn\Web\JsonRequest {
|
||||||
{
|
|
||||||
const PARAMS = ['syncUser'];
|
const PARAMS = ['syncUser'];
|
||||||
|
|
||||||
function run ($db)
|
function run($db) {
|
||||||
{
|
|
||||||
Account::sync($db, $_REQUEST['syncUser'], NULL);
|
Account::sync($db, $_REQUEST['syncUser'], NULL);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,10 +5,8 @@ use Vn\Lib;
|
||||||
/**
|
/**
|
||||||
* Adds a document to the Document Management System.
|
* Adds a document to the Document Management System.
|
||||||
**/
|
**/
|
||||||
class Add extends Vn\Web\JsonRequest
|
class Add extends Vn\Web\JsonRequest {
|
||||||
{
|
function run($db) {
|
||||||
function run ($db)
|
|
||||||
{
|
|
||||||
// XXX: Uncomment only to test the script
|
// XXX: Uncomment only to test the script
|
||||||
//$_REQUEST['description'] = 'description';
|
//$_REQUEST['description'] = 'description';
|
||||||
|
|
||||||
|
@ -58,10 +56,8 @@ class Add extends Vn\Web\JsonRequest
|
||||||
$dirLevels = $db->getValue(
|
$dirLevels = $db->getValue(
|
||||||
'SELECT dir_levels FROM dms_config FOR UPDATE');
|
'SELECT dir_levels FROM dms_config FOR UPDATE');
|
||||||
|
|
||||||
if ($dirLevels < $neededLevels)
|
if ($dirLevels < $neededLevels) {
|
||||||
{
|
if (is_dir($docsDir)) {
|
||||||
if (is_dir ($docsDir))
|
|
||||||
{
|
|
||||||
$dif =($neededLevels - $dirLevels) - 1;
|
$dif =($neededLevels - $dirLevels) - 1;
|
||||||
$newDir = $docsDir;
|
$newDir = $docsDir;
|
||||||
|
|
||||||
|
@ -101,8 +97,7 @@ class Add extends Vn\Web\JsonRequest
|
||||||
|
|
||||||
return $docId;
|
return $docId;
|
||||||
}
|
}
|
||||||
catch (Exception $e)
|
catch (Exception $e) {
|
||||||
{
|
|
||||||
$db->query('ROLLBACK');
|
$db->query('ROLLBACK');
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,13 +4,11 @@ use Vn\Web\Security;
|
||||||
use Vn\Web\Util;
|
use Vn\Web\Util;
|
||||||
use Vn\Lib;
|
use Vn\Lib;
|
||||||
|
|
||||||
class Invoice extends Vn\Web\RestRequest
|
class Invoice extends Vn\Web\RestRequest {
|
||||||
{
|
|
||||||
const PARAMS = ['invoice'];
|
const PARAMS = ['invoice'];
|
||||||
const SECURITY = Security::INVOKER;
|
const SECURITY = Security::INVOKER;
|
||||||
|
|
||||||
function run ($db)
|
function run($db) {
|
||||||
{
|
|
||||||
$pdfPath = $db->getValueFromFile(__DIR__ .'/invoice',
|
$pdfPath = $db->getValueFromFile(__DIR__ .'/invoice',
|
||||||
['invoice' =>(int) $_GET['invoice']]);
|
['invoice' =>(int) $_GET['invoice']]);
|
||||||
|
|
||||||
|
|
|
@ -2,10 +2,8 @@
|
||||||
|
|
||||||
require_once __DIR__.'/lib/method.php';
|
require_once __DIR__.'/lib/method.php';
|
||||||
|
|
||||||
class Clean extends Edi\Method
|
class Clean extends Edi\Method {
|
||||||
{
|
function ediRun($db) {
|
||||||
function ediRun ($db)
|
|
||||||
{
|
|
||||||
$imap = $this->imap;
|
$imap = $this->imap;
|
||||||
|
|
||||||
$cleanPeriod = $db->getValue('SELECT clean_period FROM imap_config');
|
$cleanPeriod = $db->getValue('SELECT clean_period FROM imap_config');
|
||||||
|
@ -21,10 +19,8 @@ class Clean extends Edi\Method
|
||||||
];
|
];
|
||||||
|
|
||||||
foreach($folders as $folder)
|
foreach($folders as $folder)
|
||||||
if (imap_reopen ($imap, "{$this->mailbox}$folder"))
|
if (imap_reopen($imap, "{$this->mailbox}$folder")) {
|
||||||
{
|
if ($messages = imap_search($imap, $filter)) {
|
||||||
if ($messages = imap_search ($imap, $filter))
|
|
||||||
{
|
|
||||||
foreach($messages as $message)
|
foreach($messages as $message)
|
||||||
imap_delete($imap, $message);
|
imap_delete($imap, $message);
|
||||||
|
|
||||||
|
|
|
@ -4,19 +4,16 @@ namespace Edi;
|
||||||
|
|
||||||
require_once(__DIR__.'/section.php');
|
require_once(__DIR__.'/section.php');
|
||||||
|
|
||||||
class SectionInfo
|
class SectionInfo {
|
||||||
{
|
|
||||||
var $schema;
|
var $schema;
|
||||||
var $parentInfo;
|
var $parentInfo;
|
||||||
var $section;
|
var $section;
|
||||||
}
|
}
|
||||||
|
|
||||||
class Message
|
class Message {
|
||||||
{
|
|
||||||
var $section;
|
var $section;
|
||||||
|
|
||||||
static function loadSchema ($schemaName)
|
static function loadSchema($schemaName) {
|
||||||
{
|
|
||||||
$ediSchemaStr = file_get_contents(__DIR__."/$schemaName.json", TRUE);
|
$ediSchemaStr = file_get_contents(__DIR__."/$schemaName.json", TRUE);
|
||||||
|
|
||||||
if ($ediSchemaStr !== FALSE)
|
if ($ediSchemaStr !== FALSE)
|
||||||
|
@ -25,13 +22,11 @@ class Message
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static function isEdiString (&$string)
|
static function isEdiString(&$string) {
|
||||||
{
|
|
||||||
return substr($string, 0, 4) == 'UNB+';
|
return substr($string, 0, 4) == 'UNB+';
|
||||||
}
|
}
|
||||||
|
|
||||||
function parse (&$string, &$schema = NULL)
|
function parse(&$string, &$schema = NULL) {
|
||||||
{
|
|
||||||
global $delimiters;
|
global $delimiters;
|
||||||
|
|
||||||
if (!self::isEdiString($string))
|
if (!self::isEdiString($string))
|
||||||
|
@ -50,8 +45,7 @@ class Message
|
||||||
$topInfo = $info;
|
$topInfo = $info;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
while (TRUE)
|
while (TRUE) {
|
||||||
{
|
|
||||||
$segment = $this->parseSegment($string, $pos);
|
$segment = $this->parseSegment($string, $pos);
|
||||||
|
|
||||||
if (!$segment &&(!$endTag || !$info))
|
if (!$segment &&(!$endTag || !$info))
|
||||||
|
@ -60,16 +54,13 @@ class Message
|
||||||
if (!$segment ||($segment && !$info))
|
if (!$segment ||($segment && !$info))
|
||||||
throw new \Exception();
|
throw new \Exception();
|
||||||
|
|
||||||
if ($firstLoop)
|
if ($firstLoop) {
|
||||||
{
|
|
||||||
if ($segment->name != $info->schema['mainTag'])
|
if ($segment->name != $info->schema['mainTag'])
|
||||||
throw new \Exception();
|
throw new \Exception();
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
for ($i = $info; $i; $i = $i->parentInfo)
|
for ($i = $info; $i; $i = $i->parentInfo)
|
||||||
if (isset ($i->schema['childs'][$segment->name]))
|
if (isset($i->schema['childs'][$segment->name])) {
|
||||||
{
|
|
||||||
$info = new SectionInfo();
|
$info = new SectionInfo();
|
||||||
$info->schema = $i->schema['childs'][$segment->name];
|
$info->schema = $i->schema['childs'][$segment->name];
|
||||||
$info->parentInfo = $i;
|
$info->parentInfo = $i;
|
||||||
|
@ -78,14 +69,12 @@ class Message
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($newSection)
|
if ($newSection) {
|
||||||
{
|
|
||||||
$section = new Section();
|
$section = new Section();
|
||||||
$section->name = $segment->name;
|
$section->name = $segment->name;
|
||||||
$info->section = $section;
|
$info->section = $section;
|
||||||
|
|
||||||
if ($info->parentInfo)
|
if ($info->parentInfo) {
|
||||||
{
|
|
||||||
$section->parent = $info->parentInfo->section;
|
$section->parent = $info->parentInfo->section;
|
||||||
$section->parent->childs[$segment->name][] = $section;
|
$section->parent->childs[$segment->name][] = $section;
|
||||||
}
|
}
|
||||||
|
@ -96,14 +85,12 @@ class Message
|
||||||
$newSection = FALSE;
|
$newSection = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($endTag && $endTag->schema['endTag'] == $segment->name)
|
if ($endTag && $endTag->schema['endTag'] == $segment->name) {
|
||||||
{
|
|
||||||
$endTag->section->segments[] = $segment;
|
$endTag->section->segments[] = $segment;
|
||||||
$info = $endTag->parentInfo;
|
$info = $endTag->parentInfo;
|
||||||
|
|
||||||
for ($i = $info; $i; $i = $i->parentInfo)
|
for ($i = $info; $i; $i = $i->parentInfo)
|
||||||
if (isset ($i->schema['endTag']))
|
if (isset($i->schema['endTag'])) {
|
||||||
{
|
|
||||||
$endTag = $i;
|
$endTag = $i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -113,8 +100,7 @@ class Message
|
||||||
|
|
||||||
$firstLoop = FALSE;
|
$firstLoop = FALSE;
|
||||||
}}
|
}}
|
||||||
catch (\Exception $e)
|
catch (\Exception $e) {
|
||||||
{
|
|
||||||
throw new \Exception(sprintf('Parse error, something is wrong near "%s"',
|
throw new \Exception(sprintf('Parse error, something is wrong near "%s"',
|
||||||
substr($string, $pos, 10)));
|
substr($string, $pos, 10)));
|
||||||
}
|
}
|
||||||
|
@ -122,27 +108,22 @@ class Message
|
||||||
$this->section = $topInfo->section;
|
$this->section = $topInfo->section;
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseSegment (&$string, &$pos)
|
function parseSegment(&$string, &$pos) {
|
||||||
{
|
|
||||||
$empty = TRUE;
|
$empty = TRUE;
|
||||||
$values = [];
|
$values = [];
|
||||||
|
|
||||||
while (TRUE)
|
while (TRUE) {
|
||||||
{
|
|
||||||
if (!isset($string{$pos}))
|
if (!isset($string{$pos}))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (in_array ($string{$pos}, ['+', ':', '\'']))
|
if (in_array($string{$pos}, ['+', ':', '\''])) {
|
||||||
{
|
if (!$empty) {
|
||||||
if (!$empty)
|
|
||||||
{
|
|
||||||
$values[] =
|
$values[] =
|
||||||
trim(substr($string, $start, $pos - $start));
|
trim(substr($string, $start, $pos - $start));
|
||||||
$empty = TRUE;
|
$empty = TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
elseif ($empty)
|
elseif ($empty) {
|
||||||
{
|
|
||||||
$start = $pos;
|
$start = $pos;
|
||||||
$empty = FALSE;
|
$empty = FALSE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,16 +2,14 @@
|
||||||
|
|
||||||
namespace Edi;
|
namespace Edi;
|
||||||
|
|
||||||
abstract class Method extends \Vn\Lib\Method
|
abstract class Method extends \Vn\Lib\Method {
|
||||||
{
|
|
||||||
protected $imap;
|
protected $imap;
|
||||||
protected $imapConf;
|
protected $imapConf;
|
||||||
protected $mailbox;
|
protected $mailbox;
|
||||||
|
|
||||||
abstract function ediRun($db);
|
abstract function ediRun($db);
|
||||||
|
|
||||||
function run ($db)
|
function run($db) {
|
||||||
{
|
|
||||||
$db->selectDb('edi');
|
$db->selectDb('edi');
|
||||||
|
|
||||||
$imapConf = $db->getRow(
|
$imapConf = $db->getRow(
|
||||||
|
@ -28,8 +26,7 @@ abstract class Method extends \Vn\Lib\Method
|
||||||
$this->imap = $imap;
|
$this->imap = $imap;
|
||||||
$this->imapConf = $imapConf;
|
$this->imapConf = $imapConf;
|
||||||
|
|
||||||
if ($imap)
|
if ($imap) {
|
||||||
{
|
|
||||||
$this->ediRun($db);
|
$this->ediRun($db);
|
||||||
imap_expunge($imap);
|
imap_expunge($imap);
|
||||||
imap_close($imap);
|
imap_close($imap);
|
||||||
|
|
|
@ -4,15 +4,13 @@ namespace Edi;
|
||||||
|
|
||||||
require_once(__DIR__.'/segment.php');
|
require_once(__DIR__.'/segment.php');
|
||||||
|
|
||||||
class Section
|
class Section {
|
||||||
{
|
|
||||||
var $name;
|
var $name;
|
||||||
var $parent = NULL;
|
var $parent = NULL;
|
||||||
var $segments = [];
|
var $segments = [];
|
||||||
var $childs = [];
|
var $childs = [];
|
||||||
|
|
||||||
function getValue ($name, $key, $type = NULL, $subname = NULL)
|
function getValue($name, $key, $type = NULL, $subname = NULL) {
|
||||||
{
|
|
||||||
foreach($this->segments as $segment)
|
foreach($this->segments as $segment)
|
||||||
if ($segment->name == $name
|
if ($segment->name == $name
|
||||||
&&(!$subname || $segment->values[1] == $subname))
|
&&(!$subname || $segment->values[1] == $subname))
|
||||||
|
|
|
@ -6,20 +6,17 @@ use Vn\Lib\Type;
|
||||||
use Vn\Lib\Date;
|
use Vn\Lib\Date;
|
||||||
use Vn\Lib\Time;
|
use Vn\Lib\Time;
|
||||||
|
|
||||||
class Segment
|
class Segment {
|
||||||
{
|
|
||||||
var $name;
|
var $name;
|
||||||
var $values = [];
|
var $values = [];
|
||||||
|
|
||||||
function getValue ($key, $type = NULL)
|
function getValue($key, $type = NULL) {
|
||||||
{
|
|
||||||
if ($key < 0 || $key >= count($this->values))
|
if ($key < 0 || $key >= count($this->values))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
$v = $this->values[$key];
|
$v = $this->values[$key];
|
||||||
|
|
||||||
switch ($type)
|
switch ($type) {
|
||||||
{
|
|
||||||
case Type::DATE:
|
case Type::DATE:
|
||||||
$tmp = new Date();
|
$tmp = new Date();
|
||||||
$tmp->setDate(substr($v, 0, 4), substr($v, 4, 2), substr($v, 6, 2));
|
$tmp->setDate(substr($v, 0, 4), substr($v, 4, 2), substr($v, 6, 2));
|
||||||
|
|
|
@ -5,10 +5,8 @@ require_once (__DIR__.'/lib/message.php');
|
||||||
|
|
||||||
use Vn\Lib\Type;
|
use Vn\Lib\Type;
|
||||||
|
|
||||||
class Load extends Edi\Method
|
class Load extends Edi\Method {
|
||||||
{
|
function ediRun($db) {
|
||||||
function ediRun ($db)
|
|
||||||
{
|
|
||||||
$this->ediSchema = Edi\Message::loadSchema('CLOCKT');
|
$this->ediSchema = Edi\Message::loadSchema('CLOCKT');
|
||||||
|
|
||||||
if (!$this->ediSchema)
|
if (!$this->ediSchema)
|
||||||
|
@ -19,8 +17,7 @@ class Load extends Edi\Method
|
||||||
|
|
||||||
$inbox = imap_search($this->imap, 'ALL');
|
$inbox = imap_search($this->imap, 'ALL');
|
||||||
|
|
||||||
if ($inbox)
|
if ($inbox) {
|
||||||
{
|
|
||||||
foreach($inbox as $msg)
|
foreach($inbox as $msg)
|
||||||
$this->loadMail($db, $msg);
|
$this->loadMail($db, $msg);
|
||||||
|
|
||||||
|
@ -31,8 +28,7 @@ class Load extends Edi\Method
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadMail ($db, $msg)
|
function loadMail($db, $msg) {
|
||||||
{
|
|
||||||
$imap = $this->imap;
|
$imap = $this->imap;
|
||||||
|
|
||||||
// Gets EKT messages from email
|
// Gets EKT messages from email
|
||||||
|
@ -60,13 +56,11 @@ class Load extends Edi\Method
|
||||||
$error = NULL;
|
$error = NULL;
|
||||||
|
|
||||||
foreach($result as $msgSection)
|
foreach($result as $msgSection)
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
$part = imap_bodystruct($imap, $msg, $msgSection);
|
$part = imap_bodystruct($imap, $msg, $msgSection);
|
||||||
$ediString = imap_fetchbody($imap, $msg, $msgSection);
|
$ediString = imap_fetchbody($imap, $msg, $msgSection);
|
||||||
|
|
||||||
switch ($part->encoding)
|
switch ($part->encoding) {
|
||||||
{
|
|
||||||
case ENCBASE64:
|
case ENCBASE64:
|
||||||
$ediString = imap_base64($ediString);
|
$ediString = imap_base64($ediString);
|
||||||
break;
|
break;
|
||||||
|
@ -94,18 +88,15 @@ class Load extends Edi\Method
|
||||||
$unhs = $unb->childs['UNH'];
|
$unhs = $unb->childs['UNH'];
|
||||||
|
|
||||||
foreach($unhs as $unh)
|
foreach($unhs as $unh)
|
||||||
foreach ($lins = $unh->childs['LIN'] as $lin)
|
foreach($lins = $unh->childs['LIN'] as $lin) {
|
||||||
{
|
|
||||||
$ediValues = [];
|
$ediValues = [];
|
||||||
|
|
||||||
// Gets the exchange params
|
// Gets the exchange params
|
||||||
|
|
||||||
$this->params->data_seek(0);
|
$this->params->data_seek(0);
|
||||||
|
|
||||||
while ($row = $this->params->fetch_assoc ())
|
while ($row = $this->params->fetch_assoc()) {
|
||||||
{
|
switch ($row['type']) {
|
||||||
switch ($row['type'])
|
|
||||||
{
|
|
||||||
case 'INTEGER':
|
case 'INTEGER':
|
||||||
$type = Type::INTEGER;
|
$type = Type::INTEGER;
|
||||||
break;
|
break;
|
||||||
|
@ -144,8 +135,7 @@ class Load extends Edi\Method
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($res)
|
if ($res)
|
||||||
while ($row = $res->fetch_assoc ())
|
while ($row = $res->fetch_assoc()) {
|
||||||
{
|
|
||||||
$value = $lin->getValue('IMD', 2, Type::INTEGER, $row['feature']);
|
$value = $lin->getValue('IMD', 2, Type::INTEGER, $row['feature']);
|
||||||
$ediValues['s'.$row['presentation_order']] = $value;
|
$ediValues['s'.$row['presentation_order']] = $value;
|
||||||
}
|
}
|
||||||
|
@ -168,8 +158,7 @@ class Load extends Edi\Method
|
||||||
|
|
||||||
$db->query('COMMIT');
|
$db->query('COMMIT');
|
||||||
}
|
}
|
||||||
catch (Exception $e)
|
catch (Exception $e) {
|
||||||
{
|
|
||||||
$db->query('ROLLBACK');
|
$db->query('ROLLBACK');
|
||||||
$error = $e->getMessage();
|
$error = $e->getMessage();
|
||||||
break;
|
break;
|
||||||
|
@ -180,13 +169,11 @@ class Load extends Edi\Method
|
||||||
|
|
||||||
// Logs information of realized operations
|
// Logs information of realized operations
|
||||||
|
|
||||||
if (!$error)
|
if (!$error) {
|
||||||
{
|
|
||||||
$folder = $this->imapConf['success_folder'];
|
$folder = $this->imapConf['success_folder'];
|
||||||
echo "Mail loaded with $count lines.\n";
|
echo "Mail loaded with $count lines.\n";
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
$folder = $this->imapConf['error_folder'];
|
$folder = $this->imapConf['error_folder'];
|
||||||
echo "Mail error: $error\n";
|
echo "Mail error: $error\n";
|
||||||
}
|
}
|
||||||
|
@ -202,18 +189,15 @@ class Load extends Edi\Method
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function imapFindParts (&$part, &$matchTypes, $section, &$result)
|
function imapFindParts(&$part, &$matchTypes, $section, &$result) {
|
||||||
{
|
if (in_array($part->type, $matchTypes)) {
|
||||||
if (in_array ($part->type, $matchTypes))
|
|
||||||
{
|
|
||||||
if (count($section) > 0)
|
if (count($section) > 0)
|
||||||
$result[] = implode('.', $section);
|
$result[] = implode('.', $section);
|
||||||
else
|
else
|
||||||
$result[] = '1';
|
$result[] = '1';
|
||||||
}
|
}
|
||||||
elseif ($part->type == TYPEMULTIPART)
|
elseif ($part->type == TYPEMULTIPART)
|
||||||
foreach ($part->parts as $i => $subpart)
|
foreach($part->parts as $i => $subpart) {
|
||||||
{
|
|
||||||
array_push($section, $i + 1);
|
array_push($section, $i + 1);
|
||||||
$this->imapFindParts($subpart, $matchTypes, $section, $result);
|
$this->imapFindParts($subpart, $matchTypes, $section, $result);
|
||||||
array_pop($section);
|
array_pop($section);
|
||||||
|
|
|
@ -1,15 +1,13 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
class Update extends Vn\Lib\Method
|
class Update extends Vn\Lib\Method {
|
||||||
{
|
function run($db) {
|
||||||
function run ($db)
|
|
||||||
{
|
|
||||||
$db->selectDb('edi');
|
$db->selectDb('edi');
|
||||||
//$db->options(MYSQLI_OPT_LOCAL_INFILE, TRUE);
|
//$db->options(MYSQLI_OPT_LOCAL_INFILE, TRUE);
|
||||||
|
|
||||||
$tmpDir = '/tmp/floricode';
|
$tmpDir = '/tmp/floricode';
|
||||||
|
|
||||||
// Establece una conexi<78>n FTP
|
// Establish the FTP connection
|
||||||
|
|
||||||
$ftpConf = $db->getRow('SELECT host, user, password FROM ftp_config');
|
$ftpConf = $db->getRow('SELECT host, user, password FROM ftp_config');
|
||||||
|
|
||||||
|
@ -22,7 +20,7 @@ class Update extends Vn\Lib\Method
|
||||||
if (!ftp_login($ftpConn, $ftpConf['user'], $ftpConf['password']))
|
if (!ftp_login($ftpConn, $ftpConf['user'], $ftpConf['password']))
|
||||||
throw new Exception('Can not login to '. $ftpConf['user'] .'@'. $ftpConf['host']);
|
throw new Exception('Can not login to '. $ftpConf['user'] .'@'. $ftpConf['host']);
|
||||||
|
|
||||||
// Obtiene el listado de tablas a actualizar
|
// Gets the list with the tables to update
|
||||||
|
|
||||||
set_time_limit(0);
|
set_time_limit(0);
|
||||||
|
|
||||||
|
@ -40,8 +38,10 @@ class Update extends Vn\Lib\Method
|
||||||
$table = $row['to_table'];
|
$table = $row['to_table'];
|
||||||
$baseName = $row['file_name'];
|
$baseName = $row['file_name'];
|
||||||
|
|
||||||
if ($row['updated'])
|
if ($row['updated']) {
|
||||||
$updated = DateTime::createFromFormat('Y-m-d', $row['updated']);
|
$updated = DateTime::createFromFormat('Y-m-d', $row['updated']);
|
||||||
|
$updated->setTime(0, 0, 0, 0);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
$updated = NULL;
|
$updated = NULL;
|
||||||
|
|
||||||
|
@ -49,10 +49,9 @@ class Update extends Vn\Lib\Method
|
||||||
$zipFile = "$tmpDir/$file.zip";
|
$zipFile = "$tmpDir/$file.zip";
|
||||||
$ucDir = "$tmpDir/$file";
|
$ucDir = "$tmpDir/$file";
|
||||||
|
|
||||||
// Intenta descargar y descomprimir el fichero con los datos
|
// Downloads and decompress the file with the data
|
||||||
|
|
||||||
if (!isset ($dwFiles[$file]))
|
if (!isset($dwFiles[$file])) {
|
||||||
{
|
|
||||||
$dwFiles[$file] = TRUE;
|
$dwFiles[$file] = TRUE;
|
||||||
|
|
||||||
echo "Downloading $remoteFile\n";
|
echo "Downloading $remoteFile\n";
|
||||||
|
@ -79,35 +78,30 @@ class Update extends Vn\Lib\Method
|
||||||
if (!$fileName)
|
if (!$fileName)
|
||||||
throw new Exception("Import file for table $table does not exist");
|
throw new Exception("Import file for table $table does not exist");
|
||||||
|
|
||||||
// Si los datos están actualizados omite la tabla
|
// If data is updated, omits the table
|
||||||
|
|
||||||
$lastUpdated = substr($fileName, -10, 6);
|
$lastUpdated = substr($fileName, -10, 6);
|
||||||
$lastUpdated = DateTime::createFromFormat('dmy', $lastUpdated);
|
$lastUpdated = DateTime::createFromFormat('dmy', $lastUpdated);
|
||||||
|
$lastUpdated->setTime(0, 0, 0, 0);
|
||||||
|
|
||||||
if ($updated && $lastUpdated <= $updated)
|
if (isset($updated) && $lastUpdated <= $updated) {
|
||||||
|
echo "Table $table is updated, omitted\n";
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// Actualiza los datos de la tabla
|
// Updates the table
|
||||||
|
|
||||||
echo "Dumping data to table $table\n";
|
echo "Dumping data to table $table\n";
|
||||||
$importQuery = $db->loadFromFile (__DIR__."/sql/$table", ['file' => $fileName]);
|
|
||||||
|
|
||||||
$db->multiQuery (
|
$db->query("START TRANSACTION");
|
||||||
"START TRANSACTION;
|
$db->query("DELETE FROM {$db->quote($table)}");
|
||||||
DELETE FROM $table;
|
$db->queryFromFile(__DIR__."/sql/$table", ['file' => $fileName]);
|
||||||
$importQuery;
|
$db->query("UPDATE file_config SET updated = # WHERE file_name = #",
|
||||||
UPDATE file_config SET updated = # WHERE file_name = #;
|
|
||||||
COMMIT;",
|
|
||||||
[$lastUpdated, $baseName]
|
[$lastUpdated, $baseName]
|
||||||
);
|
);
|
||||||
|
$db->query("COMMIT");
|
||||||
do {
|
|
||||||
$db->storeResult ();
|
|
||||||
}
|
}
|
||||||
while ($db->moreResults () && $db->nextResult ());
|
catch (Exception $e) {
|
||||||
}
|
|
||||||
catch (Exception $e)
|
|
||||||
{
|
|
||||||
$db->query('ROLLBACK');
|
$db->query('ROLLBACK');
|
||||||
error_log($e->getMessage());
|
error_log($e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,20 +2,17 @@
|
||||||
|
|
||||||
use Vn\Lib\UserException;
|
use Vn\Lib\UserException;
|
||||||
|
|
||||||
class Image
|
class Image {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* Creates an image resource from a valid image file.
|
* Creates an image resource from a valid image file.
|
||||||
*
|
*
|
||||||
* @param string $srcFile The source file name
|
* @param string $srcFile The source file name
|
||||||
**/
|
**/
|
||||||
static function create ($srcFile)
|
static function create($srcFile) {
|
||||||
{
|
|
||||||
$imageType = exif_imagetype($srcFile);
|
$imageType = exif_imagetype($srcFile);
|
||||||
|
|
||||||
if ($imageType !== FALSE)
|
if ($imageType !== FALSE)
|
||||||
switch ($imageType)
|
switch ($imageType) {
|
||||||
{
|
|
||||||
case IMAGETYPE_JPEG:
|
case IMAGETYPE_JPEG:
|
||||||
$image = imagecreatefromjpeg($srcFile);
|
$image = imagecreatefromjpeg($srcFile);
|
||||||
break;
|
break;
|
||||||
|
@ -44,8 +41,7 @@ class Image
|
||||||
* @param boolean $crop Wether to crop the image
|
* @param boolean $crop Wether to crop the image
|
||||||
* @param boolean $symbolicSrc If it is not necessary to resize the image creates a symbolic link using the passed path as source
|
* @param boolean $symbolicSrc If it is not necessary to resize the image creates a symbolic link using the passed path as source
|
||||||
**/
|
**/
|
||||||
static function resizeSave ($image, $dstFile, $maxHeight, $maxWidth, $crop = FALSE, $symbolicSrc = NULL)
|
static function resizeSave($image, $dstFile, $maxHeight, $maxWidth, $crop = FALSE, $symbolicSrc = NULL) {
|
||||||
{
|
|
||||||
$width = imagesx($image);
|
$width = imagesx($image);
|
||||||
$height = imagesy($image);
|
$height = imagesy($image);
|
||||||
|
|
||||||
|
@ -59,8 +55,7 @@ class Image
|
||||||
|
|
||||||
// Check if it is necessary to resize the image
|
// Check if it is necessary to resize the image
|
||||||
|
|
||||||
if ($height > $maxHeight || $width > $maxWidth)
|
if ($height > $maxHeight || $width > $maxWidth) {
|
||||||
{
|
|
||||||
$srcX = 0;
|
$srcX = 0;
|
||||||
$srcY = 0;
|
$srcY = 0;
|
||||||
$srcWidth = $width;
|
$srcWidth = $width;
|
||||||
|
@ -68,43 +63,36 @@ class Image
|
||||||
$dstWidth = $width;
|
$dstWidth = $width;
|
||||||
$dstHeight = $height;
|
$dstHeight = $height;
|
||||||
|
|
||||||
if (!$crop) // Resize
|
if (!$crop) // Resize {
|
||||||
{
|
|
||||||
$ratio = NULL;
|
$ratio = NULL;
|
||||||
|
|
||||||
if ($dstWidth > $maxWidth)
|
if ($dstWidth > $maxWidth) {
|
||||||
{
|
|
||||||
$ratio = $dstWidth / $maxWidth;
|
$ratio = $dstWidth / $maxWidth;
|
||||||
$dstWidth = $maxWidth;
|
$dstWidth = $maxWidth;
|
||||||
$dstHeight =(int)($dstHeight / $ratio);
|
$dstHeight =(int)($dstHeight / $ratio);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($dstHeight > $maxHeight)
|
if ($dstHeight > $maxHeight) {
|
||||||
{
|
|
||||||
$ratio = $dstHeight / $maxHeight;
|
$ratio = $dstHeight / $maxHeight;
|
||||||
$dstHeight = $maxHeight;
|
$dstHeight = $maxHeight;
|
||||||
$dstWidth =(int)($dstWidth / $ratio);
|
$dstWidth =(int)($dstWidth / $ratio);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else // Cut & resize
|
else // Cut & resize {
|
||||||
{
|
|
||||||
if ($width > $maxWidth)
|
if ($width > $maxWidth)
|
||||||
$dstWidth = $maxWidth;
|
$dstWidth = $maxWidth;
|
||||||
if ($height > $maxWidth)
|
if ($height > $maxWidth)
|
||||||
$dstHeight = $maxHeight;
|
$dstHeight = $maxHeight;
|
||||||
|
|
||||||
if ($width <= $maxWidth)
|
if ($width <= $maxWidth) {
|
||||||
{
|
|
||||||
if ($height > $srcHeight)
|
if ($height > $srcHeight)
|
||||||
$srcHeight = $maxHeight;
|
$srcHeight = $maxHeight;
|
||||||
}
|
}
|
||||||
elseif ($height <= $maxHeight)
|
elseif ($height <= $maxHeight) {
|
||||||
{
|
|
||||||
if ($width > $maxWidth)
|
if ($width > $maxWidth)
|
||||||
$srcWidth = $maxWidth;
|
$srcWidth = $maxWidth;
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
$srcWidth =(int)($maxWidth *($height / $maxHeight));
|
$srcWidth =(int)($maxWidth *($height / $maxHeight));
|
||||||
$srcHeight =(int)($maxHeight *($width / $maxWidth));
|
$srcHeight =(int)($maxHeight *($width / $maxWidth));
|
||||||
|
|
||||||
|
@ -129,12 +117,10 @@ class Image
|
||||||
$saved = imagepng($resizedImage, $dstFile);
|
$saved = imagepng($resizedImage, $dstFile);
|
||||||
imagedestroy($resizedImage);
|
imagedestroy($resizedImage);
|
||||||
}
|
}
|
||||||
elseif (isset ($symbolicSrc))
|
elseif (isset($symbolicSrc)) {
|
||||||
{
|
|
||||||
$saved = symlink($symbolicSrc, $dstFile);
|
$saved = symlink($symbolicSrc, $dstFile);
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
imagesavealpha($image, TRUE);
|
imagesavealpha($image, TRUE);
|
||||||
$saved = imagepng($image, $dstFile);
|
$saved = imagepng($image, $dstFile);
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,8 +11,7 @@ require_once (__DIR__.'/lib.php');
|
||||||
* @param integer $maxWidth The maximum width of resized image in pixels
|
* @param integer $maxWidth The maximum width of resized image in pixels
|
||||||
* @param boolean $rewrite Wether to rewrite the destination file if it exits
|
* @param boolean $rewrite Wether to rewrite the destination file if it exits
|
||||||
*/
|
*/
|
||||||
class Resize extends Vn\Lib\Method
|
class Resize extends Vn\Lib\Method {
|
||||||
{
|
|
||||||
const PARAMS = [
|
const PARAMS = [
|
||||||
'srcDir'
|
'srcDir'
|
||||||
,'dstDir'
|
,'dstDir'
|
||||||
|
@ -23,8 +22,7 @@ class Resize extends Vn\Lib\Method
|
||||||
,'symbolic'
|
,'symbolic'
|
||||||
];
|
];
|
||||||
|
|
||||||
function run ()
|
function run() {
|
||||||
{
|
|
||||||
$options = getopt('', $params);
|
$options = getopt('', $params);
|
||||||
|
|
||||||
if (!$this->checkParams($options, self::PARAMS))
|
if (!$this->checkParams($options, self::PARAMS))
|
||||||
|
@ -45,14 +43,12 @@ class Resize extends Vn\Lib\Method
|
||||||
|
|
||||||
if ($dir)
|
if ($dir)
|
||||||
while ($fileName = readdir($dir))
|
while ($fileName = readdir($dir))
|
||||||
if (!in_array ($fileName, ['.', '..']))
|
if (!in_array($fileName, ['.', '..'])) {
|
||||||
{
|
|
||||||
$srcFile = "$srcDir/$fileName";
|
$srcFile = "$srcDir/$fileName";
|
||||||
$dstFile = "$dstDir/". substr($fileName, 0, -4).'.png';
|
$dstFile = "$dstDir/". substr($fileName, 0, -4).'.png';
|
||||||
|
|
||||||
if (!file_exists($dstFile) || $rewrite)
|
if (!file_exists($dstFile) || $rewrite)
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
$symbolicSrc =($symbolic) ? $srcFile : NULL;
|
$symbolicSrc =($symbolic) ? $srcFile : NULL;
|
||||||
|
|
||||||
$image = Image::create($srcFile);
|
$image = Image::create($srcFile);
|
||||||
|
|
|
@ -6,20 +6,17 @@ require_once (__DIR__.'/util.php');
|
||||||
* Syncronizes the data directory with the database, this may take
|
* Syncronizes the data directory with the database, this may take
|
||||||
* some time.
|
* some time.
|
||||||
*/
|
*/
|
||||||
class Sync extends Vn\Lib\Method
|
class Sync extends Vn\Lib\Method {
|
||||||
{
|
|
||||||
private $trashSubdir;
|
private $trashSubdir;
|
||||||
private $util;
|
private $util;
|
||||||
|
|
||||||
function __construct ($app)
|
function __construct($app) {
|
||||||
{
|
|
||||||
parent::__construct($app);
|
parent::__construct($app);
|
||||||
$this->util = new Util($app);
|
$this->util = new Util($app);
|
||||||
$this->dataDir = $this->util->dataDir;
|
$this->dataDir = $this->util->dataDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
function run ($db)
|
function run($db) {
|
||||||
{
|
|
||||||
$db = $this->getSysConn();
|
$db = $this->getSysConn();
|
||||||
|
|
||||||
set_time_limit(0);
|
set_time_limit(0);
|
||||||
|
@ -33,15 +30,13 @@ class Sync extends Vn\Lib\Method
|
||||||
|
|
||||||
if ($dir)
|
if ($dir)
|
||||||
while ($schema = readdir($dir))
|
while ($schema = readdir($dir))
|
||||||
if (!in_array ($schema, ['.', '..']))
|
if (!in_array($schema, ['.', '..'])) {
|
||||||
{
|
|
||||||
$info = $this->loadInfo($schema);
|
$info = $this->loadInfo($schema);
|
||||||
$schemaPath = "{$this->dataDir}/$schema";
|
$schemaPath = "{$this->dataDir}/$schema";
|
||||||
|
|
||||||
// Deletes unreferenced schemas.
|
// Deletes unreferenced schemas.
|
||||||
|
|
||||||
if (!isset ($info))
|
if (!isset($info)) {
|
||||||
{
|
|
||||||
$this->moveTrash($schema);
|
$this->moveTrash($schema);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -69,8 +64,7 @@ class Sync extends Vn\Lib\Method
|
||||||
|
|
||||||
$map = [];
|
$map = [];
|
||||||
|
|
||||||
while ($row = $result->fetch_row ())
|
while ($row = $result->fetch_row()) {
|
||||||
{
|
|
||||||
$map[$row[0]] = TRUE;
|
$map[$row[0]] = TRUE;
|
||||||
$checkCount++;
|
$checkCount++;
|
||||||
}
|
}
|
||||||
|
@ -88,8 +82,7 @@ class Sync extends Vn\Lib\Method
|
||||||
echo "Syncronization finished.\n";
|
echo "Syncronization finished.\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
function cleanImages ($schema, $size, &$map)
|
function cleanImages($schema, $size, &$map) {
|
||||||
{
|
|
||||||
$sizePath = "{$this->dataDir}/$schema/$size";
|
$sizePath = "{$this->dataDir}/$schema/$size";
|
||||||
|
|
||||||
if (!is_dir($sizePath))
|
if (!is_dir($sizePath))
|
||||||
|
@ -98,8 +91,7 @@ class Sync extends Vn\Lib\Method
|
||||||
$iter = new DirectoryIterator($sizePath);
|
$iter = new DirectoryIterator($sizePath);
|
||||||
|
|
||||||
for (; $iter->valid(); $iter->next())
|
for (; $iter->valid(); $iter->next())
|
||||||
if (!$iter->isDir () && strripos ($iter->getFilename (), '.png', -4) !== FALSE)
|
if (!$iter->isDir() && strripos($iter->getFilename(), '.png', -4) !== FALSE) {
|
||||||
{
|
|
||||||
$name = substr($iter->getFilename(), 0, -4);
|
$name = substr($iter->getFilename(), 0, -4);
|
||||||
|
|
||||||
if (!isset($map[$name]))
|
if (!isset($map[$name]))
|
||||||
|
@ -112,8 +104,7 @@ class Sync extends Vn\Lib\Method
|
||||||
*
|
*
|
||||||
* @param string $file The file to move to the trash
|
* @param string $file The file to move to the trash
|
||||||
*/
|
*/
|
||||||
function moveTrash ($file)
|
function moveTrash($file) {
|
||||||
{
|
|
||||||
$trashBasedir = "{$this->dataDir}/.trash/". $this->$trashSubdir;
|
$trashBasedir = "{$this->dataDir}/.trash/". $this->$trashSubdir;
|
||||||
$trashdir = "$trashBasedir/". dirname($file);
|
$trashdir = "$trashBasedir/". dirname($file);
|
||||||
|
|
||||||
|
|
|
@ -10,10 +10,8 @@ require_once (__DIR__.'/util.php');
|
||||||
* @param integer $width The width of the thumb
|
* @param integer $width The width of the thumb
|
||||||
* @param integer $height The height of the thumb
|
* @param integer $height The height of the thumb
|
||||||
*/
|
*/
|
||||||
class Thumb extends Vn\Web\RestRequest
|
class Thumb extends Vn\Web\RestRequest {
|
||||||
{
|
function run() {
|
||||||
function run ()
|
|
||||||
{
|
|
||||||
// XXX: Uncomment only to test the script
|
// XXX: Uncomment only to test the script
|
||||||
//$_SERVER['REQUEST_URI'] = 'catalog/200x200/e_cinerea.png';
|
//$_SERVER['REQUEST_URI'] = 'catalog/200x200/e_cinerea.png';
|
||||||
|
|
||||||
|
@ -84,8 +82,7 @@ class Thumb extends Vn\Web\RestRequest
|
||||||
|
|
||||||
$useXsendfile = $db->getValue('SELECT useXsendfile FROM imageConfig');
|
$useXsendfile = $db->getValue('SELECT useXsendfile FROM imageConfig');
|
||||||
|
|
||||||
if ($useXsendfile)
|
if ($useXsendfile) {
|
||||||
{
|
|
||||||
header("X-Sendfile: $dstFile");
|
header("X-Sendfile: $dstFile");
|
||||||
header("Content-Type: image/png");
|
header("Content-Type: image/png");
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,15 +8,13 @@ use Vn\Lib\UserException;
|
||||||
/**
|
/**
|
||||||
* Uploads a file creating its corresponding sizes.
|
* Uploads a file creating its corresponding sizes.
|
||||||
*/
|
*/
|
||||||
class Upload extends Vn\Web\JsonRequest
|
class Upload extends Vn\Web\JsonRequest {
|
||||||
{
|
|
||||||
const PARAMS = [
|
const PARAMS = [
|
||||||
'name',
|
'name',
|
||||||
'schema'
|
'schema'
|
||||||
];
|
];
|
||||||
|
|
||||||
function run ($db)
|
function run($db) {
|
||||||
{
|
|
||||||
$util = new Util($this->app);
|
$util = new Util($this->app);
|
||||||
|
|
||||||
$schema = $_REQUEST['schema'];
|
$schema = $_REQUEST['schema'];
|
||||||
|
@ -39,10 +37,8 @@ class Upload extends Vn\Web\JsonRequest
|
||||||
if (empty($_FILES['image']['name']))
|
if (empty($_FILES['image']['name']))
|
||||||
throw new UserException(s('File not choosed'));
|
throw new UserException(s('File not choosed'));
|
||||||
|
|
||||||
if ($_FILES['image']['error'] != 0)
|
if ($_FILES['image']['error'] != 0) {
|
||||||
{
|
switch ($_FILES['image']['error']) {
|
||||||
switch ($_FILES['image']['error'])
|
|
||||||
{
|
|
||||||
case UPLOAD_ERR_INI_SIZE:
|
case UPLOAD_ERR_INI_SIZE:
|
||||||
$message = 'ErrIniSize';
|
$message = 'ErrIniSize';
|
||||||
break;
|
break;
|
||||||
|
@ -88,8 +84,7 @@ class Upload extends Vn\Web\JsonRequest
|
||||||
$image = Image::create($tmpName);
|
$image = Image::create($tmpName);
|
||||||
Image::resizeSave($image, $fullFile, $info['maxHeight'], $info['maxWidth']);
|
Image::resizeSave($image, $fullFile, $info['maxHeight'], $info['maxWidth']);
|
||||||
|
|
||||||
foreach ($info['sizes'] as $size => $i)
|
foreach($info['sizes'] as $size => $i) {
|
||||||
{
|
|
||||||
$dstFile = "$schemaPath/$size/$fileName";
|
$dstFile = "$schemaPath/$size/$fileName";
|
||||||
Image::resizeSave($image, $dstFile, $i['height'], $i['width'], $i['crop'], $symbolicSrc);
|
Image::resizeSave($image, $dstFile, $i['height'], $i['width'], $i['crop'], $symbolicSrc);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,13 +5,11 @@ require_once (__DIR__.'/image.php');
|
||||||
/**
|
/**
|
||||||
* Base class for image methods.
|
* Base class for image methods.
|
||||||
*/
|
*/
|
||||||
class Util
|
class Util {
|
||||||
{
|
|
||||||
var $app;
|
var $app;
|
||||||
var $dataDir;
|
var $dataDir;
|
||||||
|
|
||||||
function __construct ($app)
|
function __construct($app) {
|
||||||
{
|
|
||||||
$this->app = $app;
|
$this->app = $app;
|
||||||
$this->dataDir = _DATA_DIR .'/'. $app->getName() .'/image-db';
|
$this->dataDir = _DATA_DIR .'/'. $app->getName() .'/image-db';
|
||||||
}
|
}
|
||||||
|
@ -21,8 +19,7 @@ class Util
|
||||||
*
|
*
|
||||||
* @param string $schema The schema name
|
* @param string $schema The schema name
|
||||||
*/
|
*/
|
||||||
function loadInfo ($schema)
|
function loadInfo($schema) {
|
||||||
{
|
|
||||||
$db = $this->app->getSysConn();
|
$db = $this->app->getSysConn();
|
||||||
|
|
||||||
$info = $db->getRow(
|
$info = $db->getRow(
|
||||||
|
@ -42,8 +39,7 @@ class Util
|
||||||
|
|
||||||
$info['sizes'] = [];
|
$info['sizes'] = [];
|
||||||
|
|
||||||
while ($r = $res->fetch_assoc ())
|
while ($r = $res->fetch_assoc()) {
|
||||||
{
|
|
||||||
$size = "{$r['width']}x{$r['height']}";
|
$size = "{$r['width']}x{$r['height']}";
|
||||||
$info['sizes'][$size] = [
|
$info['sizes'][$size] = [
|
||||||
'width' => $r['width'],
|
'width' => $r['width'],
|
||||||
|
|
|
@ -6,15 +6,13 @@ use Vn\Lib\UserException;
|
||||||
/**
|
/**
|
||||||
* Uploads a access module.
|
* Uploads a access module.
|
||||||
*/
|
*/
|
||||||
class AccessVersion extends Vn\Web\JsonRequest
|
class AccessVersion extends Vn\Web\JsonRequest {
|
||||||
{
|
|
||||||
const PARAMS = [
|
const PARAMS = [
|
||||||
'appName'
|
'appName'
|
||||||
,'newVersion'
|
,'newVersion'
|
||||||
];
|
];
|
||||||
|
|
||||||
function run ($db)
|
function run($db) {
|
||||||
{
|
|
||||||
// Checks for file errors.
|
// Checks for file errors.
|
||||||
|
|
||||||
$moduleFile = $_FILES['moduleFile'];
|
$moduleFile = $_FILES['moduleFile'];
|
||||||
|
@ -22,10 +20,8 @@ class AccessVersion extends Vn\Web\JsonRequest
|
||||||
if (empty($moduleFile['name']))
|
if (empty($moduleFile['name']))
|
||||||
throw new UserException(s('File not choosed'));
|
throw new UserException(s('File not choosed'));
|
||||||
|
|
||||||
if ($moduleFile['error'] != 0)
|
if ($moduleFile['error'] != 0) {
|
||||||
{
|
switch ($_FILES['image']['error']) {
|
||||||
switch ($_FILES['image']['error'])
|
|
||||||
{
|
|
||||||
case UPLOAD_ERR_INI_SIZE:
|
case UPLOAD_ERR_INI_SIZE:
|
||||||
$message = 'ErrIniSize';
|
$message = 'ErrIniSize';
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -4,8 +4,7 @@ require_once ('libphp-phpmailer/PHPMailerAutoload.php');
|
||||||
|
|
||||||
use Vn\Lib;
|
use Vn\Lib;
|
||||||
|
|
||||||
class Contact extends Vn\Web\JsonRequest
|
class Contact extends Vn\Web\JsonRequest {
|
||||||
{
|
|
||||||
const PARAMS = [
|
const PARAMS = [
|
||||||
'name'
|
'name'
|
||||||
,'pc'
|
,'pc'
|
||||||
|
@ -15,8 +14,7 @@ class Contact extends Vn\Web\JsonRequest
|
||||||
,'captcha'
|
,'captcha'
|
||||||
];
|
];
|
||||||
|
|
||||||
function run ($db)
|
function run($db) {
|
||||||
{
|
|
||||||
// Checks the antispam code
|
// Checks the antispam code
|
||||||
|
|
||||||
$lastCaptcha = $_SESSION['captcha'];
|
$lastCaptcha = $_SESSION['captcha'];
|
||||||
|
@ -40,8 +38,7 @@ class Contact extends Vn\Web\JsonRequest
|
||||||
$mail->isSMTP();
|
$mail->isSMTP();
|
||||||
$mail->Host = $conf->host;
|
$mail->Host = $conf->host;
|
||||||
|
|
||||||
if (!empty ($conf->user))
|
if (!empty($conf->user)) {
|
||||||
{
|
|
||||||
$mail->SMTPAuth = TRUE;
|
$mail->SMTPAuth = TRUE;
|
||||||
$mail->Username = $conf->user;
|
$mail->Username = $conf->user;
|
||||||
$mail->Password = base64_decode($conf->password);
|
$mail->Password = base64_decode($conf->password);
|
||||||
|
@ -49,8 +46,7 @@ class Contact extends Vn\Web\JsonRequest
|
||||||
else
|
else
|
||||||
$mail->SMTPAuth = FALSE;
|
$mail->SMTPAuth = FALSE;
|
||||||
|
|
||||||
if ($conf->secure)
|
if ($conf->secure) {
|
||||||
{
|
|
||||||
$mail->SMTPSecure = 'ssl';
|
$mail->SMTPSecure = 'ssl';
|
||||||
$mail->Port = 465;
|
$mail->Port = 465;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,10 +4,8 @@
|
||||||
* Ejemplo:
|
* Ejemplo:
|
||||||
* <Cube><Cube time="2010-12-10"><Cube currency="USD" rate="1.3244"/>
|
* <Cube><Cube time="2010-12-10"><Cube currency="USD" rate="1.3244"/>
|
||||||
*/
|
*/
|
||||||
class ExchangeRate extends Vn\Lib\Method
|
class ExchangeRate extends Vn\Lib\Method {
|
||||||
{
|
function run($db) {
|
||||||
function run ($db)
|
|
||||||
{
|
|
||||||
$db->selectDb('vn2008');
|
$db->selectDb('vn2008');
|
||||||
|
|
||||||
// Indica la URL del archivo
|
// Indica la URL del archivo
|
||||||
|
@ -18,16 +16,14 @@ class ExchangeRate extends Vn\Lib\Method
|
||||||
$date = $db->getValue("SELECT MAX(date) fecha FROM reference_rate");
|
$date = $db->getValue("SELECT MAX(date) fecha FROM reference_rate");
|
||||||
$maxDate = $date ? DateTime::createFromFormat('Y-m-d', $date) : NULL;
|
$maxDate = $date ? DateTime::createFromFormat('Y-m-d', $date) : NULL;
|
||||||
|
|
||||||
foreach ($xml->Cube[0]->Cube as $cube)
|
foreach($xml->Cube[0]->Cube as $cube) {
|
||||||
{
|
|
||||||
$xmlDate = new DateTime($cube['time']);
|
$xmlDate = new DateTime($cube['time']);
|
||||||
|
|
||||||
// Si existen datos más recientes de la máxima fecha los añade
|
// Si existen datos más recientes de la máxima fecha los añade
|
||||||
|
|
||||||
if ($maxDate <= $xmlDate)
|
if ($maxDate <= $xmlDate)
|
||||||
foreach($cube->Cube as $subCube)
|
foreach($cube->Cube as $subCube)
|
||||||
if ($subCube['currency'] == 'USD')
|
if ($subCube['currency'] == 'USD') {
|
||||||
{
|
|
||||||
$params = [
|
$params = [
|
||||||
'date' => $xmlDate,
|
'date' => $xmlDate,
|
||||||
'rate' => $subCube['rate']
|
'rate' => $subCube['rate']
|
||||||
|
|
|
@ -2,10 +2,8 @@
|
||||||
|
|
||||||
require_once('libphp-phpmailer/PHPMailerAutoload.php');
|
require_once('libphp-phpmailer/PHPMailerAutoload.php');
|
||||||
|
|
||||||
class Mail extends Vn\Lib\Method
|
class Mail extends Vn\Lib\Method {
|
||||||
{
|
function run($db) {
|
||||||
function run ($db)
|
|
||||||
{
|
|
||||||
$db->selectDb('vn2008');
|
$db->selectDb('vn2008');
|
||||||
$db->query('START TRANSACTION');
|
$db->query('START TRANSACTION');
|
||||||
|
|
||||||
|
@ -16,8 +14,7 @@ class Mail extends Vn\Lib\Method
|
||||||
|
|
||||||
$count = 0;
|
$count = 0;
|
||||||
|
|
||||||
while ($row = $res->fetch_object ())
|
while ($row = $res->fetch_object()) {
|
||||||
{
|
|
||||||
$sent = 1;
|
$sent = 1;
|
||||||
$status = 'OK';
|
$status = 'OK';
|
||||||
|
|
||||||
|
@ -25,8 +22,7 @@ class Mail extends Vn\Lib\Method
|
||||||
$mail = $mailer->createObject($row->to, $row->text, $row->subject);
|
$mail = $mailer->createObject($row->to, $row->text, $row->subject);
|
||||||
$mail->AddReplyTo($row->reply_to, $row->reply_to);
|
$mail->AddReplyTo($row->reply_to, $row->reply_to);
|
||||||
|
|
||||||
if (!empty ($row->path))
|
if (!empty($row->path)) {
|
||||||
{
|
|
||||||
$attachment = '/mnt/cluster/pdfs/'. $row->path;
|
$attachment = '/mnt/cluster/pdfs/'. $row->path;
|
||||||
|
|
||||||
if (file_exists($attachment))
|
if (file_exists($attachment))
|
||||||
|
@ -40,8 +36,7 @@ class Mail extends Vn\Lib\Method
|
||||||
|
|
||||||
$count++;
|
$count++;
|
||||||
}
|
}
|
||||||
catch (Exception $e)
|
catch (Exception $e) {
|
||||||
{
|
|
||||||
$sent = 2;
|
$sent = 2;
|
||||||
$status = $e->getMessage();
|
$status = $e->getMessage();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
class Production extends Vn\Web\JsonRequest
|
class Production extends Vn\Web\JsonRequest {
|
||||||
{
|
|
||||||
const PARAMS = ['deviceId'];
|
const PARAMS = ['deviceId'];
|
||||||
|
|
||||||
function run ($db)
|
function run($db) {
|
||||||
{
|
|
||||||
$row = $db->getObject(
|
$row = $db->getObject(
|
||||||
'SELECT displayText, status
|
'SELECT displayText, status
|
||||||
FROM vn.routeGate WHERE deviceId = #',
|
FROM vn.routeGate WHERE deviceId = #',
|
||||||
|
|
|
@ -2,8 +2,7 @@
|
||||||
|
|
||||||
use Vn\Lib;
|
use Vn\Lib;
|
||||||
|
|
||||||
class Sms extends Vn\Web\JsonRequest
|
class Sms extends Vn\Web\JsonRequest {
|
||||||
{
|
|
||||||
const PARAMS = [
|
const PARAMS = [
|
||||||
'destination'
|
'destination'
|
||||||
,'message'
|
,'message'
|
||||||
|
@ -14,8 +13,7 @@ class Sms extends Vn\Web\JsonRequest
|
||||||
200 // Processing
|
200 // Processing
|
||||||
];
|
];
|
||||||
|
|
||||||
function run ($db)
|
function run($db) {
|
||||||
{
|
|
||||||
$smsConfig = $db->getObject('SELECT uri, user, password, title FROM vn.smsConfig');
|
$smsConfig = $db->getObject('SELECT uri, user, password, title FROM vn.smsConfig');
|
||||||
|
|
||||||
$sClient = new SoapClient($smsConfig->uri);
|
$sClient = new SoapClient($smsConfig->uri);
|
||||||
|
|
|
@ -1,17 +1,14 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
class VisitsSync extends Vn\Lib\Method
|
class VisitsSync extends Vn\Lib\Method {
|
||||||
{
|
function run($db) {
|
||||||
function run ($db)
|
|
||||||
{
|
|
||||||
$result = $db->query("SELECT id, agent FROM visit_agent
|
$result = $db->query("SELECT id, agent FROM visit_agent
|
||||||
WHERE version = '0.0' OR platform = 'unknown' OR cookies IS NULL ORDER BY id DESC");
|
WHERE version = '0.0' OR platform = 'unknown' OR cookies IS NULL ORDER BY id DESC");
|
||||||
|
|
||||||
$stmt = $db->prepare('UPDATE visit_agent
|
$stmt = $db->prepare('UPDATE visit_agent
|
||||||
SET platform = ?, browser = ?, version = ?, javascript = ?, cookies = ? WHERE id = ?');
|
SET platform = ?, browser = ?, version = ?, javascript = ?, cookies = ? WHERE id = ?');
|
||||||
|
|
||||||
if ($result && $stmt)
|
if ($result && $stmt) {
|
||||||
{
|
|
||||||
set_time_limit(0);
|
set_time_limit(0);
|
||||||
|
|
||||||
$stmt->bind_param('sssiii'
|
$stmt->bind_param('sssiii'
|
||||||
|
@ -27,8 +24,7 @@ class VisitsSync extends Vn\Lib\Method
|
||||||
|
|
||||||
$count = 0;
|
$count = 0;
|
||||||
|
|
||||||
while ($row = $result->fetch_assoc ())
|
while ($row = $result->fetch_assoc()) {
|
||||||
{
|
|
||||||
$info = get_browser($row['agent']);
|
$info = get_browser($row['agent']);
|
||||||
$platform = $info->platform;
|
$platform = $info->platform;
|
||||||
$browser = $info->browser;
|
$browser = $info->browser;
|
||||||
|
|
|
@ -5,10 +5,8 @@ require_once (__DIR__.'/tpv.php');
|
||||||
/**
|
/**
|
||||||
* Gets transaction confirmations from the IMAP mailbox.
|
* Gets transaction confirmations from the IMAP mailbox.
|
||||||
**/
|
**/
|
||||||
class ConfirmMail extends Vn\Lib\Method
|
class ConfirmMail extends Vn\Lib\Method {
|
||||||
{
|
function run($db) {
|
||||||
function run ($db)
|
|
||||||
{
|
|
||||||
$imap = NULL;
|
$imap = NULL;
|
||||||
$imapConf = $db->getObject(
|
$imapConf = $db->getObject(
|
||||||
'SELECT host, user, pass, cleanPeriod, successFolder, errorFolder
|
'SELECT host, user, pass, cleanPeriod, successFolder, errorFolder
|
||||||
|
@ -32,16 +30,14 @@ class ConfirmMail extends Vn\Lib\Method
|
||||||
$inbox = imap_search($imap, 'ALL');
|
$inbox = imap_search($imap, 'ALL');
|
||||||
|
|
||||||
if ($inbox)
|
if ($inbox)
|
||||||
foreach ($inbox as $msg)
|
foreach($inbox as $msg) {
|
||||||
{
|
|
||||||
// Decodes the mail body
|
// Decodes the mail body
|
||||||
|
|
||||||
$params = [];
|
$params = [];
|
||||||
$body = imap_fetchbody($imap, $msg, '1');
|
$body = imap_fetchbody($imap, $msg, '1');
|
||||||
$strings = explode(';', $body);
|
$strings = explode(';', $body);
|
||||||
|
|
||||||
foreach ($strings as $string)
|
foreach($strings as $string) {
|
||||||
{
|
|
||||||
$x = explode(':', $string);
|
$x = explode(':', $string);
|
||||||
$params[trim($x[0])] = trim($x[1]);
|
$params[trim($x[0])] = trim($x[1]);
|
||||||
}
|
}
|
||||||
|
@ -53,8 +49,7 @@ class ConfirmMail extends Vn\Lib\Method
|
||||||
try {
|
try {
|
||||||
$success = Tpv::confirm($db, $params);
|
$success = Tpv::confirm($db, $params);
|
||||||
}
|
}
|
||||||
catch (\Exception $e)
|
catch (\Exception $e) {
|
||||||
{
|
|
||||||
trigger_error($e->getMessage(), E_USER_WARNING);
|
trigger_error($e->getMessage(), E_USER_WARNING);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,8 +72,7 @@ class ConfirmMail extends Vn\Lib\Method
|
||||||
|
|
||||||
$deleted = 0;
|
$deleted = 0;
|
||||||
|
|
||||||
if (rand (1, 20) == 1)
|
if (rand(1, 20) == 1) {
|
||||||
{
|
|
||||||
$folders = array(
|
$folders = array(
|
||||||
$imapConf->successFolder
|
$imapConf->successFolder
|
||||||
,$imapConf->errorFolder
|
,$imapConf->errorFolder
|
||||||
|
@ -90,8 +84,7 @@ class ConfirmMail extends Vn\Lib\Method
|
||||||
|
|
||||||
foreach($folders as $folder)
|
foreach($folders as $folder)
|
||||||
if (imap_reopen($imap, $mailbox.'.'.$folder))
|
if (imap_reopen($imap, $mailbox.'.'.$folder))
|
||||||
if ($messages = imap_search ($imap, $filter))
|
if ($messages = imap_search($imap, $filter)) {
|
||||||
{
|
|
||||||
foreach($messages as $message)
|
foreach($messages as $message)
|
||||||
imap_delete($imap, $message);
|
imap_delete($imap, $message);
|
||||||
|
|
||||||
|
|
|
@ -5,10 +5,8 @@ require_once (__DIR__.'/tpv.php');
|
||||||
/**
|
/**
|
||||||
* Gets transaction confirmation from HTTP POST.
|
* Gets transaction confirmation from HTTP POST.
|
||||||
**/
|
**/
|
||||||
class ConfirmPost extends Vn\Web\RestRequest
|
class ConfirmPost extends Vn\Web\RestRequest {
|
||||||
{
|
function run($db) {
|
||||||
function run ($db)
|
|
||||||
{
|
|
||||||
Tpv::confirm($db, $_POST);
|
Tpv::confirm($db, $_POST);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,10 +6,8 @@ require_once (__DIR__.'/tpv.php');
|
||||||
/**
|
/**
|
||||||
* Gets transaction confirmation from SOAP service.
|
* Gets transaction confirmation from SOAP service.
|
||||||
**/
|
**/
|
||||||
class ConfirmSoap extends Vn\Web\RestRequest
|
class ConfirmSoap extends Vn\Web\RestRequest {
|
||||||
{
|
function run($db) {
|
||||||
function run ($db)
|
|
||||||
{
|
|
||||||
global $tpvConfirmSoap;
|
global $tpvConfirmSoap;
|
||||||
|
|
||||||
$tpvConfirmSoap = $this;
|
$tpvConfirmSoap = $this;
|
||||||
|
@ -21,8 +19,7 @@ class ConfirmSoap extends Vn\Web\RestRequest
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function procesaNotificacionSIS ($XML)
|
function procesaNotificacionSIS($XML) {
|
||||||
{
|
|
||||||
global $tpvConfirmSoap;
|
global $tpvConfirmSoap;
|
||||||
|
|
||||||
$db = $tpvConfirmSoap->app->getSysConn();
|
$db = $tpvConfirmSoap->app->getSysConn();
|
||||||
|
@ -61,8 +58,7 @@ function procesaNotificacionSIS ($XML)
|
||||||
|
|
||||||
Tpv::confirm($db, $params);
|
Tpv::confirm($db, $params);
|
||||||
}
|
}
|
||||||
catch (Exception $e)
|
catch (Exception $e) {
|
||||||
{
|
|
||||||
$status = 'KO';
|
$status = 'KO';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
if (isset ($_POST['key']))
|
if (isset($_POST['key'])) {
|
||||||
{
|
|
||||||
ini_set('soap.wsdl_cache_enabled', FALSE);
|
ini_set('soap.wsdl_cache_enabled', FALSE);
|
||||||
|
|
||||||
$requestString = file_get_contents(__DIR__.'/soap-request.xml');
|
$requestString = file_get_contents(__DIR__.'/soap-request.xml');
|
||||||
|
@ -22,8 +21,7 @@ if (isset ($_POST['key']))
|
||||||
|
|
||||||
$isValid = $xml->{'Signature'} == $shaHash;
|
$isValid = $xml->{'Signature'} == $shaHash;
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
$key = '';
|
$key = '';
|
||||||
$result = '';
|
$result = '';
|
||||||
$shaHash = '';
|
$shaHash = '';
|
||||||
|
|
|
@ -1,12 +1,10 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
class Tpv
|
class Tpv {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* Tryes to confirm a transaction with the given params.
|
* Tryes to confirm a transaction with the given params.
|
||||||
**/
|
**/
|
||||||
static function confirm ($db, $params)
|
static function confirm($db, $params) {
|
||||||
{
|
|
||||||
if (!(isset($params['Ds_Amount'])
|
if (!(isset($params['Ds_Amount'])
|
||||||
&& isset($params['Ds_Order'])
|
&& isset($params['Ds_Order'])
|
||||||
&& isset($params['Ds_MerchantCode'])
|
&& isset($params['Ds_MerchantCode'])
|
||||||
|
|
|
@ -3,12 +3,10 @@
|
||||||
/**
|
/**
|
||||||
* Starts a new TPV transaction and returns the params.
|
* Starts a new TPV transaction and returns the params.
|
||||||
*/
|
*/
|
||||||
class Transaction extends Vn\Web\JsonRequest
|
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'];
|
||||||
|
|
||||||
|
|
15
web/app.php
15
web/app.php
|
@ -8,8 +8,7 @@ namespace Vn\Web;
|
||||||
* Format for $_REQUEST['srv'] variable:
|
* Format for $_REQUEST['srv'] variable:
|
||||||
* - [serviceName]:[requestDir]/[requestFile]
|
* - [serviceName]:[requestDir]/[requestFile]
|
||||||
**/
|
**/
|
||||||
class App extends \Vn\Lib\App
|
class App extends \Vn\Lib\App {
|
||||||
{
|
|
||||||
protected $conn = NULL;
|
protected $conn = NULL;
|
||||||
private $allowedServices =
|
private $allowedServices =
|
||||||
[
|
[
|
||||||
|
@ -18,8 +17,7 @@ class App extends \Vn\Lib\App
|
||||||
'json'
|
'json'
|
||||||
];
|
];
|
||||||
|
|
||||||
function run ()
|
function run() {
|
||||||
{
|
|
||||||
$this->init();
|
$this->init();
|
||||||
|
|
||||||
$srv = empty($_REQUEST['srv']) ? '' : $_REQUEST['srv'];
|
$srv = empty($_REQUEST['srv']) ? '' : $_REQUEST['srv'];
|
||||||
|
@ -32,8 +30,7 @@ class App extends \Vn\Lib\App
|
||||||
|
|
||||||
$service = empty($_REQUEST['service']) ? 'html' : $_REQUEST['service'];
|
$service = empty($_REQUEST['service']) ? 'html' : $_REQUEST['service'];
|
||||||
|
|
||||||
if (in_array ($service, $this->allowedServices, TRUE))
|
if (in_array($service, $this->allowedServices, TRUE)) {
|
||||||
{
|
|
||||||
$includeFile = __DIR__."/$service-service.php";
|
$includeFile = __DIR__."/$service-service.php";
|
||||||
require_once($includeFile);
|
require_once($includeFile);
|
||||||
|
|
||||||
|
@ -53,11 +50,9 @@ class App extends \Vn\Lib\App
|
||||||
*
|
*
|
||||||
* @return string The config file name
|
* @return string The config file name
|
||||||
**/
|
**/
|
||||||
function getConfigFile ()
|
function getConfigFile() {
|
||||||
{
|
|
||||||
if (!empty($_SERVER['SERVER_NAME'])
|
if (!empty($_SERVER['SERVER_NAME'])
|
||||||
&& preg_match ('/^[\w\-\.]+$/', $_SERVER['SERVER_NAME']))
|
&& preg_match('/^[\w\-\.]+$/', $_SERVER['SERVER_NAME'])) {
|
||||||
{
|
|
||||||
$hostSplit = explode('.', $_SERVER['SERVER_NAME']);
|
$hostSplit = explode('.', $_SERVER['SERVER_NAME']);
|
||||||
array_splice($hostSplit, -2);
|
array_splice($hostSplit, -2);
|
||||||
$subdomain = implode('.', $hostSplit);
|
$subdomain = implode('.', $hostSplit);
|
||||||
|
|
|
@ -2,34 +2,28 @@
|
||||||
|
|
||||||
namespace Vn\Web;
|
namespace Vn\Web;
|
||||||
|
|
||||||
class DbSessionHandler implements \SessionHandlerInterface
|
class DbSessionHandler implements \SessionHandlerInterface {
|
||||||
{
|
|
||||||
private $db;
|
private $db;
|
||||||
|
|
||||||
function __construct ($db)
|
function __construct($db) {
|
||||||
{
|
|
||||||
$this->db = $db;
|
$this->db = $db;
|
||||||
}
|
}
|
||||||
|
|
||||||
function open ($savePath, $name)
|
function open($savePath, $name) {
|
||||||
{
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
function close ()
|
function close() {
|
||||||
{
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
function read ($sessionId)
|
function read($sessionId) {
|
||||||
{
|
|
||||||
$sessionData = $this->db->getValue(
|
$sessionData = $this->db->getValue(
|
||||||
'SELECT data FROM userSession WHERE ssid = #', [$sessionId]);
|
'SELECT data FROM userSession WHERE ssid = #', [$sessionId]);
|
||||||
return isset($sessionData) ? $sessionData : '';
|
return isset($sessionData) ? $sessionData : '';
|
||||||
}
|
}
|
||||||
|
|
||||||
function write ($sessionId, $sessionData)
|
function write($sessionId, $sessionData) {
|
||||||
{
|
|
||||||
$this->db->query(
|
$this->db->query(
|
||||||
'INSERT INTO userSession SET
|
'INSERT INTO userSession SET
|
||||||
ssid = #, data = #, lastUpdate = NOW()
|
ssid = #, data = #, lastUpdate = NOW()
|
||||||
|
@ -39,14 +33,12 @@ class DbSessionHandler implements \SessionHandlerInterface
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
function destroy ($sessionId)
|
function destroy($sessionId) {
|
||||||
{
|
|
||||||
$this->db->query('DELETE FROM userSession WHERE ssid = #', [$sessionId]);
|
$this->db->query('DELETE FROM userSession WHERE ssid = #', [$sessionId]);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
function gc ($maxLifeTime)
|
function gc($maxLifeTime) {
|
||||||
{
|
|
||||||
$this->db->query('DELETE FROM userSession
|
$this->db->query('DELETE FROM userSession
|
||||||
WHERE lastUpdate < TIMESTAMPADD(SECOND, -#, NOW())',
|
WHERE lastUpdate < TIMESTAMPADD(SECOND, -#, NOW())',
|
||||||
[$maxLifeTime]
|
[$maxLifeTime]
|
||||||
|
|
|
@ -7,10 +7,8 @@ use Vn\Lib\Locale;
|
||||||
/**
|
/**
|
||||||
* Base class for services that sends response as HTML format.
|
* Base class for services that sends response as HTML format.
|
||||||
*/
|
*/
|
||||||
class HtmlService extends Service
|
class HtmlService extends Service {
|
||||||
{
|
function run() {
|
||||||
function run ()
|
|
||||||
{
|
|
||||||
$eFlag =
|
$eFlag =
|
||||||
E_ERROR
|
E_ERROR
|
||||||
| E_USER_ERROR;
|
| E_USER_ERROR;
|
||||||
|
@ -22,8 +20,7 @@ class HtmlService extends Service
|
||||||
$db = $this->db;
|
$db = $this->db;
|
||||||
|
|
||||||
if (!$this->isHttps()
|
if (!$this->isHttps()
|
||||||
&& $db->getValue ('SELECT https FROM config') && !_DEV_MODE)
|
&& $db->getValue('SELECT https FROM config') && !_DEV_MODE) {
|
||||||
{
|
|
||||||
header("Location: https://{$this->getUri()}");
|
header("Location: https://{$this->getUri()}");
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
@ -39,14 +36,12 @@ class HtmlService extends Service
|
||||||
|
|
||||||
// Checking the browser version
|
// Checking the browser version
|
||||||
|
|
||||||
if (!isset ($_SESSION['skipBrowser']) && $page != 'update-browser')
|
if (!isset($_SESSION['skipBrowser']) && $page != 'update-browser') {
|
||||||
{
|
|
||||||
$updateBrowser = FALSE;
|
$updateBrowser = FALSE;
|
||||||
|
|
||||||
if (!isset($_GET['skipBrowser'])
|
if (!isset($_GET['skipBrowser'])
|
||||||
&& isset($_SERVER['HTTP_USER_AGENT'])
|
&& isset($_SERVER['HTTP_USER_AGENT'])
|
||||||
&& ($browser = get_browser ($_SERVER['HTTP_USER_AGENT'])))
|
&&($browser = get_browser($_SERVER['HTTP_USER_AGENT']))) {
|
||||||
{
|
|
||||||
$browserVersion =(double) $browser->version;
|
$browserVersion =(double) $browser->version;
|
||||||
$minVersion = $db->getValue(
|
$minVersion = $db->getValue(
|
||||||
'SELECT version FROM browser WHERE name = #', [$browser->browser]);
|
'SELECT version FROM browser WHERE name = #', [$browser->browser]);
|
||||||
|
@ -54,8 +49,7 @@ class HtmlService extends Service
|
||||||
&& isset($minVersion) && $browserVersion < $minVersion;
|
&& isset($minVersion) && $browserVersion < $minVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($updateBrowser)
|
if ($updateBrowser) {
|
||||||
{
|
|
||||||
header('Location: ?method=update-browser');
|
header('Location: ?method=update-browser');
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
@ -66,8 +60,7 @@ class HtmlService extends Service
|
||||||
// If enabled, requests the user to choose between two web versions
|
// If enabled, requests the user to choose between two web versions
|
||||||
|
|
||||||
if (!isset($_SESSION['skipVersionMenu'])
|
if (!isset($_SESSION['skipVersionMenu'])
|
||||||
&& $db->getValue ('SELECT testDomain FROM config'))
|
&& $db->getValue('SELECT testDomain FROM config')) {
|
||||||
{
|
|
||||||
$_SESSION['skipVersionMenu'] = TRUE;
|
$_SESSION['skipVersionMenu'] = TRUE;
|
||||||
header('Location: ?method=version-menu');
|
header('Location: ?method=version-menu');
|
||||||
}
|
}
|
||||||
|
@ -80,8 +73,7 @@ class HtmlService extends Service
|
||||||
|
|
||||||
$basePath = "pages/$page";
|
$basePath = "pages/$page";
|
||||||
|
|
||||||
if (file_exists ($basePath))
|
if (file_exists($basePath)) {
|
||||||
{
|
|
||||||
Locale::addPath($basePath);
|
Locale::addPath($basePath);
|
||||||
|
|
||||||
$phpFile = "./$basePath/$page.php";
|
$phpFile = "./$basePath/$page.php";
|
||||||
|
@ -98,14 +90,12 @@ class HtmlService extends Service
|
||||||
header('Location: ./');
|
header('Location: ./');
|
||||||
}
|
}
|
||||||
|
|
||||||
function printHeader ()
|
function printHeader() {
|
||||||
{
|
|
||||||
header('Content-Type: text/html; charset=UTF-8');
|
header('Content-Type: text/html; charset=UTF-8');
|
||||||
//header("Content-Security-Policy: default-src *; img-src *;");
|
//header("Content-Security-Policy: default-src *; img-src *;");
|
||||||
}
|
}
|
||||||
|
|
||||||
function errorHandler ($err)
|
function errorHandler($err) {
|
||||||
{
|
|
||||||
error_log("{$err->getMessage()} {$err->getTraceAsString()}");
|
error_log("{$err->getMessage()} {$err->getTraceAsString()}");
|
||||||
$this->printHeader();
|
$this->printHeader();
|
||||||
include(__DIR__.'/unavailable.html');
|
include(__DIR__.'/unavailable.html');
|
||||||
|
@ -113,8 +103,7 @@ class HtmlService extends Service
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
function isMobile ()
|
function isMobile() {
|
||||||
{
|
|
||||||
$re = '/(Android|webOS|iPhone|iPad|iPod|BlackBerry|Windows Phone)/i';
|
$re = '/(Android|webOS|iPhone|iPad|iPod|BlackBerry|Windows Phone)/i';
|
||||||
return preg_match($re, $_SERVER['HTTP_USER_AGENT']);
|
return preg_match($re, $_SERVER['HTTP_USER_AGENT']);
|
||||||
}
|
}
|
||||||
|
|
18
web/html.php
18
web/html.php
|
@ -3,8 +3,7 @@
|
||||||
$lang = isset($_SESSION['lang']) ? $_SESSION['lang'] : 'en';
|
$lang = isset($_SESSION['lang']) ? $_SESSION['lang'] : 'en';
|
||||||
$version = $this->getVersion();
|
$version = $this->getVersion();
|
||||||
|
|
||||||
function getUrl ($fileName)
|
function getUrl($fileName) {
|
||||||
{
|
|
||||||
global $version;
|
global $version;
|
||||||
|
|
||||||
if (file_exists($fileName))
|
if (file_exists($fileName))
|
||||||
|
@ -15,18 +14,15 @@ function getUrl ($fileName)
|
||||||
return "$fileName?$fileVersion";
|
return "$fileName?$fileVersion";
|
||||||
}
|
}
|
||||||
|
|
||||||
function js ($fileName)
|
function js($fileName) {
|
||||||
{
|
|
||||||
return '<script type="text/javascript" src="'. getUrl("$fileName.js") .'"></script>'."\n";
|
return '<script type="text/javascript" src="'. getUrl("$fileName.js") .'"></script>'."\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
function css ($fileName)
|
function css($fileName) {
|
||||||
{
|
|
||||||
return '<link rel="stylesheet" type="text/css" href="'. getUrl("$fileName.css") .'"/>'."\n";
|
return '<link rel="stylesheet" type="text/css" href="'. getUrl("$fileName.css") .'"/>'."\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
function getWebpackAssets ()
|
function getWebpackAssets() {
|
||||||
{
|
|
||||||
$wpConfig = json_decode(file_get_contents('webpack.config.json'));
|
$wpConfig = json_decode(file_get_contents('webpack.config.json'));
|
||||||
$buildDir = $wpConfig->buildDir;
|
$buildDir = $wpConfig->buildDir;
|
||||||
$devServerPort = $wpConfig->devServerPort;
|
$devServerPort = $wpConfig->devServerPort;
|
||||||
|
@ -34,8 +30,7 @@ function getWebpackAssets ()
|
||||||
$host = $_SERVER['SERVER_NAME'];
|
$host = $_SERVER['SERVER_NAME'];
|
||||||
$assets = new stdClass();
|
$assets = new stdClass();
|
||||||
|
|
||||||
if (!_DEV_MODE)
|
if (!_DEV_MODE) {
|
||||||
{
|
|
||||||
$wpAssets = json_decode(file_get_contents("$buildDir/webpack-assets.json"));
|
$wpAssets = json_decode(file_get_contents("$buildDir/webpack-assets.json"));
|
||||||
|
|
||||||
$manifestJs = $wpAssets->manifest->js;
|
$manifestJs = $wpAssets->manifest->js;
|
||||||
|
@ -47,8 +42,7 @@ function getWebpackAssets ()
|
||||||
if (property_exists($asset, 'js'))
|
if (property_exists($asset, 'js'))
|
||||||
$assets->$name = $asset->js;
|
$assets->$name = $asset->js;
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
$devServerPath = "http://$host:$devServerPort/$buildDir";
|
$devServerPath = "http://$host:$devServerPort/$buildDir";
|
||||||
$manifestJs = "$devServerPath/manifest.js";
|
$manifestJs = "$devServerPath/manifest.js";
|
||||||
$mainJs = "$devServerPath/main.js";
|
$mainJs = "$devServerPath/main.js";
|
||||||
|
|
|
@ -9,8 +9,7 @@ namespace Vn\Web;
|
||||||
* @property string $message The message string
|
* @property string $message The message string
|
||||||
* @property string $code The code of message
|
* @property string $code The code of message
|
||||||
**/
|
**/
|
||||||
class JsonException
|
class JsonException {
|
||||||
{
|
|
||||||
var $exception = NULL;
|
var $exception = NULL;
|
||||||
var $message;
|
var $message;
|
||||||
var $code = NULL;
|
var $code = NULL;
|
||||||
|
|
|
@ -8,8 +8,7 @@ namespace Vn\Web;
|
||||||
* @property Object $data The returned data
|
* @property Object $data The returned data
|
||||||
* @property array $warnings Array with warning messages
|
* @property array $warnings Array with warning messages
|
||||||
**/
|
**/
|
||||||
class JsonReply
|
class JsonReply {
|
||||||
{
|
|
||||||
var $data = NULL;
|
var $data = NULL;
|
||||||
var $warnings = NULL;
|
var $warnings = NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,12 +7,10 @@ use Vn\Lib;
|
||||||
/**
|
/**
|
||||||
* Base class for JSON application.
|
* Base class for JSON application.
|
||||||
*/
|
*/
|
||||||
class JsonService extends RestService
|
class JsonService extends RestService {
|
||||||
{
|
|
||||||
private $warnings = NULL;
|
private $warnings = NULL;
|
||||||
|
|
||||||
function run ()
|
function run() {
|
||||||
{
|
|
||||||
ini_set('display_errors', FALSE);
|
ini_set('display_errors', FALSE);
|
||||||
set_error_handler([$this, 'errorHandler'], E_ALL);
|
set_error_handler([$this, 'errorHandler'], E_ALL);
|
||||||
set_exception_handler([$this, 'exceptionHandler']);
|
set_exception_handler([$this, 'exceptionHandler']);
|
||||||
|
@ -25,8 +23,7 @@ class JsonService extends RestService
|
||||||
$this->replyJson($json);
|
$this->replyJson($json);
|
||||||
}
|
}
|
||||||
|
|
||||||
function replyJson ($jsonData)
|
function replyJson($jsonData) {
|
||||||
{
|
|
||||||
$reply = new JsonReply();
|
$reply = new JsonReply();
|
||||||
$reply->data = $jsonData;
|
$reply->data = $jsonData;
|
||||||
$reply->warnings = $this->warnings;
|
$reply->warnings = $this->warnings;
|
||||||
|
@ -35,8 +32,7 @@ class JsonService extends RestService
|
||||||
echo json_encode($reply);
|
echo json_encode($reply);
|
||||||
}
|
}
|
||||||
|
|
||||||
function errorHandler ($errno, $message, $file, $line, $context)
|
function errorHandler($errno, $message, $file, $line, $context) {
|
||||||
{
|
|
||||||
$eUserWarn =
|
$eUserWarn =
|
||||||
E_USER_NOTICE
|
E_USER_NOTICE
|
||||||
| E_USER_WARNING
|
| E_USER_WARNING
|
||||||
|
@ -56,22 +52,19 @@ class JsonService extends RestService
|
||||||
else
|
else
|
||||||
$json->message = s('Something went wrong');
|
$json->message = s('Something went wrong');
|
||||||
|
|
||||||
if (_ENABLE_DEBUG)
|
if (_ENABLE_DEBUG) {
|
||||||
{
|
|
||||||
$json->code = $errno;
|
$json->code = $errno;
|
||||||
$json->file = $file;
|
$json->file = $file;
|
||||||
$json->line = $line;
|
$json->line = $line;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($errno & $eWarn)
|
if ($errno & $eWarn) {
|
||||||
{
|
|
||||||
if (!isset($this->warnings))
|
if (!isset($this->warnings))
|
||||||
$this->warnings = [];
|
$this->warnings = [];
|
||||||
|
|
||||||
$this->warnings[] = $json;
|
$this->warnings[] = $json;
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
http_response_code(500);
|
http_response_code(500);
|
||||||
$this->replyJson($json);
|
$this->replyJson($json);
|
||||||
exit();
|
exit();
|
||||||
|
@ -80,23 +73,19 @@ class JsonService extends RestService
|
||||||
return !($errno & $eUser);
|
return !($errno & $eUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
function exceptionHandler ($e)
|
function exceptionHandler($e) {
|
||||||
{
|
|
||||||
$json = new JsonException();
|
$json = new JsonException();
|
||||||
|
|
||||||
if (_ENABLE_DEBUG || $e instanceof Lib\UserException)
|
if (_ENABLE_DEBUG || $e instanceof Lib\UserException) {
|
||||||
{
|
|
||||||
$json->exception = get_class($e);
|
$json->exception = get_class($e);
|
||||||
$json->message = $e->getMessage();
|
$json->message = $e->getMessage();
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
$json->exception = 'Exception';
|
$json->exception = 'Exception';
|
||||||
$json->message = s('Something went wrong');
|
$json->message = s('Something went wrong');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_ENABLE_DEBUG)
|
if (_ENABLE_DEBUG) {
|
||||||
{
|
|
||||||
$json->code = $e->getCode();
|
$json->code = $e->getCode();
|
||||||
$json->file = $e->getFile();
|
$json->file = $e->getFile();
|
||||||
$json->line = $e->getLine();
|
$json->line = $e->getLine();
|
||||||
|
|
24
web/jwt.php
24
web/jwt.php
|
@ -8,8 +8,7 @@ use Exception;
|
||||||
* Basic class to encode, decode and verify JWT tokens. It implements the HS256
|
* Basic class to encode, decode and verify JWT tokens. It implements the HS256
|
||||||
* algorithm from the RFC 7519 standard.
|
* algorithm from the RFC 7519 standard.
|
||||||
**/
|
**/
|
||||||
class Jwt
|
class Jwt {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* Creates a new JWT token with the passed $payload and $key.
|
* Creates a new JWT token with the passed $payload and $key.
|
||||||
*
|
*
|
||||||
|
@ -17,8 +16,7 @@ class Jwt
|
||||||
* @param {string} $key The key used to sign the token
|
* @param {string} $key The key used to sign the token
|
||||||
* @return {string} The new JWT token
|
* @return {string} The new JWT token
|
||||||
**/
|
**/
|
||||||
static function encode ($payload, $key)
|
static function encode($payload, $key) {
|
||||||
{
|
|
||||||
$header = [
|
$header = [
|
||||||
'alg' => 'HS256',
|
'alg' => 'HS256',
|
||||||
'typ' => 'JWT'
|
'typ' => 'JWT'
|
||||||
|
@ -38,8 +36,7 @@ class Jwt
|
||||||
* @param {string} $key The key used to validate the token
|
* @param {string} $key The key used to validate the token
|
||||||
* @return {string} The JWT validated and decoded data
|
* @return {string} The JWT validated and decoded data
|
||||||
**/
|
**/
|
||||||
static function decode ($token, $key)
|
static function decode($token, $key) {
|
||||||
{
|
|
||||||
$parts = explode('.', $token);
|
$parts = explode('.', $token);
|
||||||
|
|
||||||
if (count($parts) !== 3)
|
if (count($parts) !== 3)
|
||||||
|
@ -58,29 +55,24 @@ class Jwt
|
||||||
return $payload;
|
return $payload;
|
||||||
}
|
}
|
||||||
|
|
||||||
static function getSignature ($b64Header, $b64Payload, $key)
|
static function getSignature($b64Header, $b64Payload, $key) {
|
||||||
{
|
|
||||||
$signature = hash_hmac('sha256', "$b64Header.$b64Payload", $key, TRUE);
|
$signature = hash_hmac('sha256', "$b64Header.$b64Payload", $key, TRUE);
|
||||||
return self::base64UrlEncode($signature);
|
return self::base64UrlEncode($signature);
|
||||||
}
|
}
|
||||||
|
|
||||||
static function jsonB64Encode ($data)
|
static function jsonB64Encode($data) {
|
||||||
{
|
|
||||||
return self::base64UrlEncode(json_encode($data));
|
return self::base64UrlEncode(json_encode($data));
|
||||||
}
|
}
|
||||||
|
|
||||||
static function jsonB64Decode ($data)
|
static function jsonB64Decode($data) {
|
||||||
{
|
|
||||||
return json_decode(self::base64UrlDecode($data), TRUE);
|
return json_decode(self::base64UrlDecode($data), TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static function base64UrlEncode ($data)
|
static function base64UrlEncode($data) {
|
||||||
{
|
|
||||||
return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
|
return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
|
||||||
}
|
}
|
||||||
|
|
||||||
static function base64UrlDecode ($data)
|
static function base64UrlDecode($data) {
|
||||||
{
|
|
||||||
$remainder = strlen($data) % 4;
|
$remainder = strlen($data) % 4;
|
||||||
$data = strtr($data, '-_', '+/');
|
$data = strtr($data, '-_', '+/');
|
||||||
return base64_decode(str_pad($data, $remainder, '=', STR_PAD_RIGHT));
|
return base64_decode(str_pad($data, $remainder, '=', STR_PAD_RIGHT));
|
||||||
|
|
|
@ -6,28 +6,24 @@ require_once 'libphp-phpmailer/PHPMailerAutoload.php';
|
||||||
|
|
||||||
use Vn\Lib\UserException;
|
use Vn\Lib\UserException;
|
||||||
|
|
||||||
class Mailer
|
class Mailer {
|
||||||
{
|
|
||||||
private $conf;
|
private $conf;
|
||||||
|
|
||||||
function __construct ($db)
|
function __construct($db) {
|
||||||
{
|
|
||||||
$this->conf = $db->getObject(
|
$this->conf = $db->getObject(
|
||||||
'SELECT host, port, secure, sender, senderName, user, password
|
'SELECT host, port, secure, sender, senderName, user, password
|
||||||
FROM hedera.mailConfig'
|
FROM hedera.mailConfig'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
if (!empty ($conf->user))
|
if (!empty($conf->user)) {
|
||||||
{
|
|
||||||
$mail->SMTPAuth = TRUE;
|
$mail->SMTPAuth = TRUE;
|
||||||
$mail->Username = $conf->user;
|
$mail->Username = $conf->user;
|
||||||
$mail->Password = base64_decode($conf->password);
|
$mail->Password = base64_decode($conf->password);
|
||||||
|
@ -35,8 +31,7 @@ class Mailer
|
||||||
else
|
else
|
||||||
$mail->SMTPAuth = FALSE;
|
$mail->SMTPAuth = FALSE;
|
||||||
|
|
||||||
if ($conf->secure)
|
if ($conf->secure) {
|
||||||
{
|
|
||||||
$mail->SMTPSecure = 'ssl';
|
$mail->SMTPSecure = 'ssl';
|
||||||
$mail->Port = 465;
|
$mail->Port = 465;
|
||||||
}
|
}
|
||||||
|
@ -55,8 +50,7 @@ class Mailer
|
||||||
return $mail;
|
return $mail;
|
||||||
}
|
}
|
||||||
|
|
||||||
function send ($mailTo, $body, $subject)
|
function send($mailTo, $body, $subject) {
|
||||||
{
|
|
||||||
$mail = $this->createObject($mailTo, $body, $subject);
|
$mail = $this->createObject($mailTo, $body, $subject);
|
||||||
|
|
||||||
if (!$mail->Send())
|
if (!$mail->Send())
|
||||||
|
|
|
@ -2,14 +2,12 @@
|
||||||
|
|
||||||
namespace Vn\Web;
|
namespace Vn\Web;
|
||||||
|
|
||||||
class Report
|
class Report {
|
||||||
{
|
|
||||||
var $db;
|
var $db;
|
||||||
var $name;
|
var $name;
|
||||||
var $html;
|
var $html;
|
||||||
|
|
||||||
function __construct ($db, $reportName, $params)
|
function __construct($db, $reportName, $params) {
|
||||||
{
|
|
||||||
$this->db = $db;
|
$this->db = $db;
|
||||||
$this->name = $reportName;
|
$this->name = $reportName;
|
||||||
|
|
||||||
|
@ -26,18 +24,15 @@ class Report
|
||||||
$this->title = $title;
|
$this->title = $title;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getTitle ()
|
function getTitle() {
|
||||||
{
|
|
||||||
return $this->title;
|
return $this->title;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getHtml ()
|
function getHtml() {
|
||||||
{
|
|
||||||
return $this->html;
|
return $this->html;
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendMail ($mail)
|
function sendMail($mail) {
|
||||||
{
|
|
||||||
$mailer = new Mailer($this->db);
|
$mailer = new Mailer($this->db);
|
||||||
$mailer->send($mail, $this->html, $this->title);
|
$mailer->send($mail, $this->html, $this->title);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,7 @@
|
||||||
|
|
||||||
namespace Vn\Web;
|
namespace Vn\Web;
|
||||||
|
|
||||||
class Security
|
class Security {
|
||||||
{
|
|
||||||
const DEFINER = 1;
|
const DEFINER = 1;
|
||||||
const INVOKER = 2;
|
const INVOKER = 2;
|
||||||
}
|
}
|
||||||
|
@ -11,8 +10,7 @@ class Security
|
||||||
/**
|
/**
|
||||||
* Base class for REST services.
|
* Base class for REST services.
|
||||||
**/
|
**/
|
||||||
abstract class RestRequest extends \Vn\Lib\Method
|
abstract class RestRequest extends \Vn\Lib\Method {
|
||||||
{
|
|
||||||
const PARAMS = NULL;
|
const PARAMS = NULL;
|
||||||
const SECURITY = Security::DEFINER;
|
const SECURITY = Security::DEFINER;
|
||||||
|
|
||||||
|
|
|
@ -9,10 +9,8 @@ use Vn\Lib\UserException;
|
||||||
/**
|
/**
|
||||||
* Base class for REST application.
|
* Base class for REST application.
|
||||||
*/
|
*/
|
||||||
class RestService extends Service
|
class RestService extends Service {
|
||||||
{
|
function run() {
|
||||||
function run ()
|
|
||||||
{
|
|
||||||
ini_set('display_errors', _ENABLE_DEBUG);
|
ini_set('display_errors', _ENABLE_DEBUG);
|
||||||
set_error_handler([$this, 'errorHandler'], E_ALL);
|
set_error_handler([$this, 'errorHandler'], E_ALL);
|
||||||
set_exception_handler([$this, 'exceptionHandler']);
|
set_exception_handler([$this, 'exceptionHandler']);
|
||||||
|
@ -25,8 +23,7 @@ class RestService extends Service
|
||||||
/**
|
/**
|
||||||
* Runs a REST method.
|
* Runs a REST method.
|
||||||
*/
|
*/
|
||||||
function loadMethod ($class)
|
function loadMethod($class) {
|
||||||
{
|
|
||||||
$db = $this->db;
|
$db = $this->db;
|
||||||
$this->login();
|
$this->login();
|
||||||
|
|
||||||
|
@ -34,8 +31,7 @@ class RestService extends Service
|
||||||
$_REQUEST['method'], $class, './rest');
|
$_REQUEST['method'], $class, './rest');
|
||||||
$method->service = $this;
|
$method->service = $this;
|
||||||
|
|
||||||
if ($method::SECURITY == Security::DEFINER)
|
if ($method::SECURITY == Security::DEFINER) {
|
||||||
{
|
|
||||||
$isAuthorized = $db->getValue('SELECT userCheckRestPriv(#)',
|
$isAuthorized = $db->getValue('SELECT userCheckRestPriv(#)',
|
||||||
[$_REQUEST['method']]);
|
[$_REQUEST['method']]);
|
||||||
|
|
||||||
|
@ -57,8 +53,7 @@ class RestService extends Service
|
||||||
try {
|
try {
|
||||||
$res = $method->run($methodDb);
|
$res = $method->run($methodDb);
|
||||||
}
|
}
|
||||||
catch (Db\Exception $e)
|
catch (Db\Exception $e) {
|
||||||
{
|
|
||||||
if ($e->getCode() == 1644)
|
if ($e->getCode() == 1644)
|
||||||
throw new UserException(s($e->getMessage()));
|
throw new UserException(s($e->getMessage()));
|
||||||
}
|
}
|
||||||
|
@ -71,25 +66,19 @@ class RestService extends Service
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
function statusFromException ($e)
|
function statusFromException($e) {
|
||||||
{
|
|
||||||
try {
|
try {
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
catch (SessionExpiredException $e)
|
catch (SessionExpiredException $e) { $status = 401; }
|
||||||
{ $status = 401; }
|
catch (BadLoginException $e) { $status = 401; }
|
||||||
catch (BadLoginException $e)
|
catch (Lib\UserException $e) { $status = 400; }
|
||||||
{ $status = 401; }
|
catch (\Exception $e) { $status = 500; }
|
||||||
catch (Lib\UserException $e)
|
|
||||||
{ $status = 400; }
|
|
||||||
catch (\Exception $e)
|
|
||||||
{ $status = 500; }
|
|
||||||
|
|
||||||
http_response_code($status);
|
http_response_code($status);
|
||||||
}
|
}
|
||||||
|
|
||||||
function errorHandler ($errno, $message, $file, $line, $context)
|
function errorHandler($errno, $message, $file, $line, $context) {
|
||||||
{
|
|
||||||
$eFlag =
|
$eFlag =
|
||||||
E_USER_NOTICE
|
E_USER_NOTICE
|
||||||
| E_USER_WARNING
|
| E_USER_WARNING
|
||||||
|
@ -104,8 +93,7 @@ class RestService extends Service
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
function exceptionHandler ($e)
|
function exceptionHandler($e) {
|
||||||
{
|
|
||||||
$this->statusFromException($e);
|
$this->statusFromException($e);
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,27 +29,23 @@ class OutdatedVersionException extends UserException {}
|
||||||
/**
|
/**
|
||||||
* Main class for web applications.
|
* Main class for web applications.
|
||||||
*/
|
*/
|
||||||
abstract class Service
|
abstract class Service {
|
||||||
{
|
|
||||||
protected $app;
|
protected $app;
|
||||||
protected $db;
|
protected $db;
|
||||||
protected $userDb = NULL;
|
protected $userDb = NULL;
|
||||||
|
|
||||||
function __construct ($app)
|
function __construct($app) {
|
||||||
{
|
|
||||||
$this->app = $app;
|
$this->app = $app;
|
||||||
}
|
}
|
||||||
|
|
||||||
function init ()
|
function init() {
|
||||||
{
|
|
||||||
$this->db = $this->app->getSysConn();
|
$this->db = $this->app->getSysConn();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts the user session.
|
* Starts the user session.
|
||||||
*/
|
*/
|
||||||
function startSession ()
|
function startSession() {
|
||||||
{
|
|
||||||
$db = $this->app->getSysConn();
|
$db = $this->app->getSysConn();
|
||||||
|
|
||||||
ini_set('session.cookie_secure', $this->isHttps());
|
ini_set('session.cookie_secure', $this->isHttps());
|
||||||
|
@ -62,16 +58,14 @@ abstract class Service
|
||||||
|
|
||||||
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE']))
|
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE']))
|
||||||
if (!isset($_SESSION['httpLanguage'])
|
if (!isset($_SESSION['httpLanguage'])
|
||||||
|| $_SESSION['httpLanguage'] != $_SERVER['HTTP_ACCEPT_LANGUAGE'])
|
|| $_SESSION['httpLanguage'] != $_SERVER['HTTP_ACCEPT_LANGUAGE']) {
|
||||||
{
|
|
||||||
$_SESSION['httpLanguage'] = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
|
$_SESSION['httpLanguage'] = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
|
||||||
$regexp = '/([a-z]{1,4})(?:-[a-z]{1,4})?\s*(?:;\s*q\s*=\s*(?:1|0\.[0-9]+))?,?/i';
|
$regexp = '/([a-z]{1,4})(?:-[a-z]{1,4})?\s*(?:;\s*q\s*=\s*(?:1|0\.[0-9]+))?,?/i';
|
||||||
|
|
||||||
preg_match_all($regexp, $_SERVER['HTTP_ACCEPT_LANGUAGE'], $languages);
|
preg_match_all($regexp, $_SERVER['HTTP_ACCEPT_LANGUAGE'], $languages);
|
||||||
|
|
||||||
foreach($languages[1] as $lang)
|
foreach($languages[1] as $lang)
|
||||||
if (TRUE || stream_resolve_include_path ("locale/$lang"))
|
if (TRUE || stream_resolve_include_path("locale/$lang")) {
|
||||||
{
|
|
||||||
$_SESSION['lang'] = $lang;
|
$_SESSION['lang'] = $lang;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -94,8 +88,7 @@ abstract class Service
|
||||||
$agent = $_SERVER['HTTP_USER_AGENT'];
|
$agent = $_SERVER['HTTP_USER_AGENT'];
|
||||||
$browser = get_browser($agent, TRUE);
|
$browser = get_browser($agent, TRUE);
|
||||||
|
|
||||||
if (!empty ($browser['crawler']))
|
if (!empty($browser['crawler'])) {
|
||||||
{
|
|
||||||
$_SESSION['skipVisit'] = TRUE;
|
$_SESSION['skipVisit'] = TRUE;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -118,8 +111,7 @@ abstract class Service
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
if (isset ($row['access']))
|
if (isset($row['access'])) {
|
||||||
{
|
|
||||||
setcookie('vnVisit', $row['visit'], time() + 31536000); // 1 Year
|
setcookie('vnVisit', $row['visit'], time() + 31536000); // 1 Year
|
||||||
$_SESSION['access'] = $row['access'];
|
$_SESSION['access'] = $row['access'];
|
||||||
}
|
}
|
||||||
|
@ -137,23 +129,19 @@ abstract class Service
|
||||||
*
|
*
|
||||||
* return Db\Conn The database connection
|
* return Db\Conn The database connection
|
||||||
*/
|
*/
|
||||||
function login ()
|
function login() {
|
||||||
{
|
|
||||||
$db = $this->db;
|
$db = $this->db;
|
||||||
$anonymousUser = FALSE;
|
$anonymousUser = FALSE;
|
||||||
|
|
||||||
if (isset ($_POST['user']) && isset ($_POST['password']))
|
if (isset($_POST['user']) && isset($_POST['password'])) {
|
||||||
{
|
|
||||||
$user = strtolower($_POST['user']);
|
$user = strtolower($_POST['user']);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$db->query('CALL account.userLogin(#, #)',
|
$db->query('CALL account.userLogin(#, #)',
|
||||||
[$user, $_POST['password']]);
|
[$user, $_POST['password']]);
|
||||||
}
|
}
|
||||||
catch (Db\Exception $e)
|
catch (Db\Exception $e) {
|
||||||
{
|
if ($e->getMessage() == 'INVALID_CREDENTIALS') {
|
||||||
if ($e->getMessage () == 'INVALID_CREDENTIALS')
|
|
||||||
{
|
|
||||||
sleep(3);
|
sleep(3);
|
||||||
throw new BadLoginException();
|
throw new BadLoginException();
|
||||||
}
|
}
|
||||||
|
@ -161,10 +149,8 @@ abstract class Service
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
if (isset($_POST['token']) || isset($_GET['token'])) {
|
||||||
if (isset ($_POST['token']) || isset ($_GET['token']))
|
|
||||||
{
|
|
||||||
if (isset($_POST['token']))
|
if (isset($_POST['token']))
|
||||||
$token = $_POST['token'];
|
$token = $_POST['token'];
|
||||||
if (isset($_GET['token']))
|
if (isset($_GET['token']))
|
||||||
|
@ -175,8 +161,7 @@ abstract class Service
|
||||||
try {
|
try {
|
||||||
$jwtPayload = Jwt::decode($token, $key);
|
$jwtPayload = Jwt::decode($token, $key);
|
||||||
}
|
}
|
||||||
catch (\Exception $e)
|
catch (\Exception $e) {
|
||||||
{
|
|
||||||
throw new BadLoginException($e->getMessage());
|
throw new BadLoginException($e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,8 +179,7 @@ abstract class Service
|
||||||
[$user]
|
[$user]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
$user = $db->getValue('SELECT guestUser FROM config');
|
$user = $db->getValue('SELECT guestUser FROM config');
|
||||||
$anonymousUser = TRUE;
|
$anonymousUser = TRUE;
|
||||||
}
|
}
|
||||||
|
@ -220,8 +204,7 @@ abstract class Service
|
||||||
/**
|
/**
|
||||||
* Logouts the current user. Cleans the last saved used credentials.
|
* Logouts the current user. Cleans the last saved used credentials.
|
||||||
*/
|
*/
|
||||||
function logout ()
|
function logout() {
|
||||||
{
|
|
||||||
unset($_SESSION['user']);
|
unset($_SESSION['user']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -231,8 +214,7 @@ abstract class Service
|
||||||
*
|
*
|
||||||
* @return {Db\Conn} The database connection
|
* @return {Db\Conn} The database connection
|
||||||
*/
|
*/
|
||||||
function getUserDb ($user)
|
function getUserDb($user) {
|
||||||
{
|
|
||||||
if ($this->userDb)
|
if ($this->userDb)
|
||||||
return $this->userDb;
|
return $this->userDb;
|
||||||
|
|
||||||
|
@ -262,8 +244,7 @@ abstract class Service
|
||||||
* @param {boolean} $recover Wether to enable recovery mode on login
|
* @param {boolean} $recover Wether to enable recovery mode on login
|
||||||
* @return {string} The JWT generated token
|
* @return {string} The JWT generated token
|
||||||
*/
|
*/
|
||||||
function createToken ($user, $remember = FALSE, $recover = FALSE)
|
function createToken($user, $remember = FALSE, $recover = FALSE) {
|
||||||
{
|
|
||||||
if ($remember)
|
if ($remember)
|
||||||
$tokenLife = WEEK;
|
$tokenLife = WEEK;
|
||||||
else
|
else
|
||||||
|
@ -287,15 +268,12 @@ abstract class Service
|
||||||
*
|
*
|
||||||
* @return string The version number
|
* @return string The version number
|
||||||
*/
|
*/
|
||||||
function getVersion ()
|
function getVersion() {
|
||||||
{
|
|
||||||
$appName = $this->app->getName();
|
$appName = $this->app->getName();
|
||||||
$version = apc_fetch("$appName.version", $success);
|
$version = apc_fetch("$appName.version", $success);
|
||||||
|
|
||||||
if (!$success)
|
if (!$success) {
|
||||||
{
|
if (file_exists('package.json')) {
|
||||||
if (file_exists ('package.json'))
|
|
||||||
{
|
|
||||||
$package = json_decode(file_get_contents('package.json'));
|
$package = json_decode(file_get_contents('package.json'));
|
||||||
$version = $package->version;
|
$version = $package->version;
|
||||||
}
|
}
|
||||||
|
@ -311,8 +289,7 @@ abstract class Service
|
||||||
/**
|
/**
|
||||||
* Checks the client version.
|
* Checks the client version.
|
||||||
*/
|
*/
|
||||||
function checkVersion ()
|
function checkVersion() {
|
||||||
{
|
|
||||||
if (!empty($_COOKIE['vnVersion']))
|
if (!empty($_COOKIE['vnVersion']))
|
||||||
$clientVersion = $_COOKIE['vnVersion'];
|
$clientVersion = $_COOKIE['vnVersion'];
|
||||||
|
|
||||||
|
@ -326,8 +303,7 @@ abstract class Service
|
||||||
*
|
*
|
||||||
* @return boolean Return %TRUE if its secure, %FALSE otherwise
|
* @return boolean Return %TRUE if its secure, %FALSE otherwise
|
||||||
*/
|
*/
|
||||||
function isHttps ()
|
function isHttps() {
|
||||||
{
|
|
||||||
return isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on';
|
return isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -336,8 +312,7 @@ abstract class Service
|
||||||
*
|
*
|
||||||
* @return string The current URI
|
* @return string The current URI
|
||||||
*/
|
*/
|
||||||
function getUri ()
|
function getUri() {
|
||||||
{
|
|
||||||
return "{$_SERVER['SERVER_NAME']}{$_SERVER['REQUEST_URI']}";
|
return "{$_SERVER['SERVER_NAME']}{$_SERVER['REQUEST_URI']}";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -346,8 +321,7 @@ abstract class Service
|
||||||
*
|
*
|
||||||
* @return string The current URL
|
* @return string The current URL
|
||||||
*/
|
*/
|
||||||
function getUrl ()
|
function getUrl() {
|
||||||
{
|
|
||||||
$proto = $this->isHttps() ? 'https' : 'http';
|
$proto = $this->isHttps() ? 'https' : 'http';
|
||||||
return "$proto://{$this->getUri()}";
|
return "$proto://{$this->getUri()}";
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,13 +5,11 @@
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
||||||
<title>Not available - Verdnatura</title>
|
<title>Not available - Verdnatura</title>
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
body
|
body {
|
||||||
{
|
|
||||||
font-size: 16pt;
|
font-size: 16pt;
|
||||||
font-family: Sans;
|
font-family: Sans;
|
||||||
}
|
}
|
||||||
div
|
div {
|
||||||
{
|
|
||||||
position: absolute;
|
position: absolute;
|
||||||
width: 32em;
|
width: 32em;
|
||||||
margin-top: -7em;
|
margin-top: -7em;
|
||||||
|
@ -20,12 +18,10 @@
|
||||||
left: 50%;
|
left: 50%;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
div h2
|
div h2 {
|
||||||
{
|
|
||||||
font-weight: normal;
|
font-weight: normal;
|
||||||
}
|
}
|
||||||
div a
|
div a {
|
||||||
{
|
|
||||||
color: #2962FF;
|
color: #2962FF;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
}
|
}
|
||||||
|
|
15
web/util.php
15
web/util.php
|
@ -2,18 +2,15 @@
|
||||||
|
|
||||||
namespace Vn\Web;
|
namespace Vn\Web;
|
||||||
|
|
||||||
class Util
|
class Util {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* Reads a file and writes it to the output buffer.
|
* Reads a file and writes it to the output buffer.
|
||||||
*
|
*
|
||||||
* @param string file The file path
|
* @param string file The file path
|
||||||
* @param boolean useXsendfile Wether to use the apache module Xsendfile
|
* @param boolean useXsendfile Wether to use the apache module Xsendfile
|
||||||
*/
|
*/
|
||||||
static function printFile ($file, $useXsendfile = FALSE)
|
static function printFile($file, $useXsendfile = FALSE) {
|
||||||
{
|
if (!file_exists($file)) {
|
||||||
if (!file_exists ($file))
|
|
||||||
{
|
|
||||||
http_response_code(404);
|
http_response_code(404);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -21,13 +18,11 @@ class Util
|
||||||
$finfo = new \finfo(FILEINFO_MIME_TYPE);
|
$finfo = new \finfo(FILEINFO_MIME_TYPE);
|
||||||
$mimeType = $finfo->file($file);
|
$mimeType = $finfo->file($file);
|
||||||
|
|
||||||
if ($useXsendfile)
|
if ($useXsendfile) {
|
||||||
{
|
|
||||||
header("X-Sendfile: $file");
|
header("X-Sendfile: $file");
|
||||||
header("Content-Type: $mimeType");
|
header("Content-Type: $mimeType");
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
header('Content-Description: File Transfer');
|
header('Content-Description: File Transfer');
|
||||||
header("Content-Type: $mimeType");
|
header("Content-Type: $mimeType");
|
||||||
header('Content-Disposition: attachment; filename="'. basename($file) .'"');
|
header('Content-Disposition: attachment; filename="'. basename($file) .'"');
|
||||||
|
|
Loading…
Reference in New Issue