LDAP sync bugs solved, production bugs solved

This commit is contained in:
Juan Ferrer Toribio 2017-12-05 12:49:05 +01:00
parent 3032850d58
commit a0cf0fe0dd
10 changed files with 124 additions and 90 deletions

2
debian/changelog vendored
View File

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

View File

@ -54,9 +54,9 @@ module.exports = new Class
if (user !== null && user !== undefined) if (user !== null && user !== undefined)
{ {
var params = { var params = {
'user': user user: user
,'password': pass ,password: pass
,'remember': remember ,remember: remember
}; };
} }
else else
@ -125,7 +125,7 @@ module.exports = new Class
**/ **/
,supplantUser: function (user, callback) ,supplantUser: function (user, callback)
{ {
var params = {'supplantUser': user}; var params = {supplantUser: user};
this.send ('core/supplant', params, this.send ('core/supplant', params,
this._onUserSupplant.bind (this, callback)); this._onUserSupplant.bind (this, callback));
} }
@ -160,9 +160,9 @@ module.exports = new Class
if (!params) if (!params)
params = {}; params = {};
params['srv'] = 'json:'+ restService; params.srv = 'json:'+ restService;
this.sendWithUrl (params, callback, 'post', '.'); this.sendWithUrl (params, callback, 'POST', '.');
} }
,sendForm: function (form, callback) ,sendForm: function (form, callback)
@ -174,7 +174,7 @@ module.exports = new Class
if (elements[i].name) if (elements[i].name)
params[elements[i].name] = elements[i].value; params[elements[i].name] = elements[i].value;
this.sendWithUrl (params, callback, 'post', form.action); this.sendWithUrl (params, callback, 'POST', form.action);
} }
,sendFormMultipart: function (form, callback) ,sendFormMultipart: function (form, callback)
@ -185,7 +185,7 @@ module.exports = new Class
formData.append ('token', this.token); formData.append ('token', this.token);
var request = new XMLHttpRequest (); var request = new XMLHttpRequest ();
request.open ('post', form.action, true); request.open ('POST', form.action, true);
request.onreadystatechange = request.onreadystatechange =
this._onStateChange.bind (this, request, callback); this._onStateChange.bind (this, request, callback);
request.send (formData); request.send (formData);
@ -199,7 +199,7 @@ module.exports = new Class
formData.append ('token', this.token); formData.append ('token', this.token);
var request = new XMLHttpRequest (); var request = new XMLHttpRequest ();
request.open ('post', '', true); request.open ('POST', '', true);
request.onreadystatechange = request.onreadystatechange =
this._onStateChange.bind (this, request, callback); this._onStateChange.bind (this, request, callback);
request.send (formData); request.send (formData);

View File

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

View File

@ -5,9 +5,15 @@
var INTERVAL = 5; var INTERVAL = 5;
var requestInterval = INTERVAL; var requestInterval = INTERVAL;
var failedRequests = 0;
var timeoutId = null; var timeoutId = null;
var request = null; var request = null;
function onBodyLoad ()
{
updateText ();
}
function onSettingsClick () function onSettingsClick ()
{ {
var deviceId = localStorage.getItem ('hederaDeviceId'); var deviceId = localStorage.getItem ('hederaDeviceId');
@ -36,11 +42,6 @@ function onSettingsClick ()
updateText (); updateText ();
} }
function onBodyLoad ()
{
updateText ();
}
function updateText () function updateText ()
{ {
var deviceId = localStorage.getItem ('hederaDeviceId'); var deviceId = localStorage.getItem ('hederaDeviceId');
@ -56,7 +57,7 @@ function updateText ()
formData.append ('deviceId', deviceId); formData.append ('deviceId', deviceId);
request = new XMLHttpRequest(); request = new XMLHttpRequest();
request.open ('post', '', true); request.open ('POST', '', true);
request.onreadystatechange = request.onreadystatechange =
onRequestChange.bind (null, request); onRequestChange.bind (null, request);
request.send (formData); request.send (formData);
@ -74,6 +75,7 @@ function onRequestChange (request)
var json = JSON.parse (request.responseText); var json = JSON.parse (request.responseText);
display (json.data); display (json.data);
requestInterval = INTERVAL; requestInterval = INTERVAL;
failedRequests = 0;
break; break;
case 400: case 400:
var json = JSON.parse (request.responseText); var json = JSON.parse (request.responseText);
@ -86,8 +88,9 @@ function onRequestChange (request)
{ {
display (e.message, true); display (e.message, true);
console.error (e.message); console.error (e.message);
failedRequests++;
if (requestInterval < 60) if (failedRequests > 10 && requestInterval < 60)
{ {
requestInterval += parseInt (Math.random() * 10) + 1; requestInterval += parseInt (Math.random() * 10) + 1;
console.warn ('Request interval increased to %d seconds.', requestInterval); console.warn ('Request interval increased to %d seconds.', requestInterval);

View File

@ -23,7 +23,7 @@ body
#text #text
{ {
color: white; color: white;
font-size: 20em; font-size: 15em;
text-align: center; text-align: center;
font-weight: bold; font-weight: bold;
text-overflow: ellipsis; text-overflow: ellipsis;

View File

@ -4,16 +4,14 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=no"/> <meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=no"/>
<meta name="mobile-web-app-capable" content="yes"/> <meta name="mobile-web-app-capable" content="yes"/>
<meta name="content-language" content="<?=$lang?>"/>
<meta name="theme-color" content="#009688"/>
<link rel="shortcut icon" href="image/favicon/favicon.ico"/> <link rel="shortcut icon" href="image/favicon/favicon.ico"/>
<link rel="icon" type="image/png" href="image/favicon/favicon.png"/> <link rel="icon" type="image/png" href="image/favicon/favicon.png"/>
<link rel="icon" type="image/svg+xml" href="image/icon.svg" sizes="any"/> <link rel="icon" type="image/svg+xml" href="image/icon.svg" sizes="any"/>
<link rel="manifest" href="manifest.json"/> <link rel="manifest" href="manifest.json"/>
<meta name="theme-color" content="#009688"/> <?=js("$dir/main.js")?>
<meta name="content-language" content="<?=$lang?>"/> <?=css("$dir/style.css")?>
<script type="text/javascript" src="<?=$dir?>/main.js?<?=$version?>"></script>
<link rel="stylesheet" type="text/css" href="<?=$dir?>/style.css?<?=$version?>"/>
<title>Production</title> <title>Production</title>
</head> </head>
<body onload="onBodyLoad()"> <body onload="onBodyLoad()">

View File

@ -3,8 +3,9 @@
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta name="viewport" content="user-scalable=no"/> <meta name="viewport" content="user-scalable=no"/>
<meta name="content-language" content="<?=$lang?>"/>
<link href="//fonts.googleapis.com/css?family=Roboto" rel="stylesheet" type="text/css"/> <link href="//fonts.googleapis.com/css?family=Roboto" rel="stylesheet" type="text/css"/>
<link rel="stylesheet" type="text/css" href="<?=$dir?>/style.css?<?=$version?>"/> <?=css("$dir/style.css")?>
<title>Verdnatura</title> <title>Verdnatura</title>
</head> </head>
<body> <body>

View File

@ -3,8 +3,9 @@
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta name="viewport" content="user-scalable=no"/> <meta name="viewport" content="user-scalable=no"/>
<meta name="content-language" content="<?=$lang?>"/>
<link href="//fonts.googleapis.com/css?family=Roboto" rel="stylesheet" type="text/css"/> <link href="//fonts.googleapis.com/css?family=Roboto" rel="stylesheet" type="text/css"/>
<link rel="stylesheet" type="text/css" href="<?=$dir?>/style.css?<?=$version?>"/> <?=css("$dir/style.css")?>
<title>Verdnatura</title> <title>Verdnatura</title>
</head> </head>
<body> <body>

View File

@ -42,9 +42,6 @@ class Account
*/ */
static function ldapSync ($db, $userName, $password) static function ldapSync ($db, $userName, $password)
{ {
if (empty ($password))
return;
// Gets LDAP configuration parameters // Gets LDAP configuration parameters
$conf = $db->getObject ( $conf = $db->getObject (
@ -58,6 +55,7 @@ class Account
if (!$ds) if (!$ds)
throw new Exception ("Can't connect to LDAP server: ". ldapError ($ds)); throw new Exception ("Can't connect to LDAP server: ". ldapError ($ds));
try {
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3); ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
$bind = ldap_bind ($ds, $conf->rdn, base64_decode ($conf->password)); $bind = ldap_bind ($ds, $conf->rdn, base64_decode ($conf->password));
@ -75,6 +73,8 @@ class Account
[$userName] [$userName]
); );
$cn = empty ($user->nickname) ? $userName : $user->nickname;
$nameArgs = explode (' ', $user->nickname); $nameArgs = explode (' ', $user->nickname);
$givenName = $nameArgs[0]; $givenName = $nameArgs[0];
@ -83,8 +83,8 @@ class Account
if (empty ($sn)) if (empty ($sn))
$sn = 'Empty'; $sn = 'Empty';
$info = [ $attrs = [
'cn' => $user->nickname, 'cn' => $cn,
'displayName' => $user->nickname, 'displayName' => $user->nickname,
'givenName' => $givenName, 'givenName' => $givenName,
'sn' => $sn, 'sn' => $sn,
@ -118,21 +118,51 @@ class Account
if ($entry) if ($entry)
{ {
$updated = ldap_modify ($ds, $dn, $info); $modifs = [];
$curAttrs = ldap_get_attributes ($ds, $entry);
foreach ($attrs as $attribute => $value)
if (!empty ($value))
{
$modifs[] = [
'attrib' => $attribute,
'modtype' => LDAP_MODIFY_BATCH_REPLACE,
'values' => [$value]
];
}
elseif (isset ($curAttrs[$attribute]))
{
$modifs[] = [
'attrib' => $attribute,
'modtype' => LDAP_MODIFY_BATCH_REMOVE_ALL
];
}
$updated = ldap_modify_batch ($ds, $dn, $modifs);
} }
else else
{ {
$info = array_merge ($info, [ $addAttrs = [];
foreach ($attrs as $attribute => $value)
if (!empty ($value))
$addAttrs[$attribute] = $value;
$addAttrs = array_merge ($addAttrs, [
'objectClass' => ['inetOrgPerson'], 'objectClass' => ['inetOrgPerson'],
'uid' => $userName 'uid' => $userName
]); ]);
$updated = ldap_add ($ds, $dn, $info); $updated = ldap_add ($ds, $dn, $addAttrs);
} }
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)
{
ldap_unbind ($ds); ldap_unbind ($ds);
throw $e;
}
} }
/** /**

View File

@ -1,15 +1,16 @@
<?php <?php
$lang = isset($_SESSION['lang']) ? $_SESSION['lang'] : 'en';
$version = $this->getVersion(); $version = $this->getVersion();
function getUrl ($fileName) function getUrl ($fileName)
{ {
if (file_exists ($fileName)) if (file_exists ($fileName))
$mTime = '?'. strftime ('%G%m%d%H%M%S', filemtime ($fileName)); $fileVersion = strftime ('%G%m%d%H%M%S', filemtime ($fileName));
else else
$mTime = '?'. $this->getVersion (); $fileVersion = $version;
return $fileName.$mTime; return "$fileName?$fileVersion";
} }
function js ($fileName) function js ($fileName)