forked from verdnatura/hedera-web
LDAP sync bugs solved, production bugs solved
This commit is contained in:
parent
3032850d58
commit
a0cf0fe0dd
|
@ -1,4 +1,4 @@
|
|||
hedera-web (1.405.26) stable; urgency=low
|
||||
hedera-web (1.405.27) stable; urgency=low
|
||||
|
||||
* Initial Release.
|
||||
|
||||
|
|
|
@ -54,9 +54,9 @@ module.exports = new Class
|
|||
if (user !== null && user !== undefined)
|
||||
{
|
||||
var params = {
|
||||
'user': user
|
||||
,'password': pass
|
||||
,'remember': remember
|
||||
user: user
|
||||
,password: pass
|
||||
,remember: remember
|
||||
};
|
||||
}
|
||||
else
|
||||
|
@ -125,7 +125,7 @@ module.exports = new Class
|
|||
**/
|
||||
,supplantUser: function (user, callback)
|
||||
{
|
||||
var params = {'supplantUser': user};
|
||||
var params = {supplantUser: user};
|
||||
this.send ('core/supplant', params,
|
||||
this._onUserSupplant.bind (this, callback));
|
||||
}
|
||||
|
@ -160,9 +160,9 @@ module.exports = new Class
|
|||
if (!params)
|
||||
params = {};
|
||||
|
||||
params['srv'] = 'json:'+ restService;
|
||||
params.srv = 'json:'+ restService;
|
||||
|
||||
this.sendWithUrl (params, callback, 'post', '.');
|
||||
this.sendWithUrl (params, callback, 'POST', '.');
|
||||
}
|
||||
|
||||
,sendForm: function (form, callback)
|
||||
|
@ -174,7 +174,7 @@ module.exports = new Class
|
|||
if (elements[i].name)
|
||||
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)
|
||||
|
@ -185,7 +185,7 @@ module.exports = new Class
|
|||
formData.append ('token', this.token);
|
||||
|
||||
var request = new XMLHttpRequest ();
|
||||
request.open ('post', form.action, true);
|
||||
request.open ('POST', form.action, true);
|
||||
request.onreadystatechange =
|
||||
this._onStateChange.bind (this, request, callback);
|
||||
request.send (formData);
|
||||
|
@ -199,7 +199,7 @@ module.exports = new Class
|
|||
formData.append ('token', this.token);
|
||||
|
||||
var request = new XMLHttpRequest ();
|
||||
request.open ('post', '', true);
|
||||
request.open ('POST', '', true);
|
||||
request.onreadystatechange =
|
||||
this._onStateChange.bind (this, request, callback);
|
||||
request.send (formData);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "hedera-web",
|
||||
"version": "1.405.26",
|
||||
"version": "1.405.27",
|
||||
"description": "Verdnatura web page",
|
||||
"license": "GPL-3.0",
|
||||
"repository": {
|
||||
|
|
|
@ -5,9 +5,15 @@
|
|||
var INTERVAL = 5;
|
||||
|
||||
var requestInterval = INTERVAL;
|
||||
var failedRequests = 0;
|
||||
var timeoutId = null;
|
||||
var request = null;
|
||||
|
||||
function onBodyLoad ()
|
||||
{
|
||||
updateText ();
|
||||
}
|
||||
|
||||
function onSettingsClick ()
|
||||
{
|
||||
var deviceId = localStorage.getItem ('hederaDeviceId');
|
||||
|
@ -36,11 +42,6 @@ function onSettingsClick ()
|
|||
updateText ();
|
||||
}
|
||||
|
||||
function onBodyLoad ()
|
||||
{
|
||||
updateText ();
|
||||
}
|
||||
|
||||
function updateText ()
|
||||
{
|
||||
var deviceId = localStorage.getItem ('hederaDeviceId');
|
||||
|
@ -56,7 +57,7 @@ function updateText ()
|
|||
formData.append ('deviceId', deviceId);
|
||||
|
||||
request = new XMLHttpRequest();
|
||||
request.open ('post', '', true);
|
||||
request.open ('POST', '', true);
|
||||
request.onreadystatechange =
|
||||
onRequestChange.bind (null, request);
|
||||
request.send (formData);
|
||||
|
@ -74,6 +75,7 @@ function onRequestChange (request)
|
|||
var json = JSON.parse (request.responseText);
|
||||
display (json.data);
|
||||
requestInterval = INTERVAL;
|
||||
failedRequests = 0;
|
||||
break;
|
||||
case 400:
|
||||
var json = JSON.parse (request.responseText);
|
||||
|
@ -86,8 +88,9 @@ function onRequestChange (request)
|
|||
{
|
||||
display (e.message, true);
|
||||
console.error (e.message);
|
||||
failedRequests++;
|
||||
|
||||
if (requestInterval < 60)
|
||||
if (failedRequests > 10 && requestInterval < 60)
|
||||
{
|
||||
requestInterval += parseInt (Math.random() * 10) + 1;
|
||||
console.warn ('Request interval increased to %d seconds.', requestInterval);
|
||||
|
|
|
@ -23,7 +23,7 @@ body
|
|||
#text
|
||||
{
|
||||
color: white;
|
||||
font-size: 20em;
|
||||
font-size: 15em;
|
||||
text-align: center;
|
||||
font-weight: bold;
|
||||
text-overflow: ellipsis;
|
||||
|
|
|
@ -4,16 +4,14 @@
|
|||
<meta charset="UTF-8">
|
||||
<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="content-language" content="<?=$lang?>"/>
|
||||
<meta name="theme-color" content="#009688"/>
|
||||
<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/svg+xml" href="image/icon.svg" sizes="any"/>
|
||||
<link rel="manifest" href="manifest.json"/>
|
||||
<meta name="theme-color" content="#009688"/>
|
||||
<meta name="content-language" content="<?=$lang?>"/>
|
||||
|
||||
<script type="text/javascript" src="<?=$dir?>/main.js?<?=$version?>"></script>
|
||||
<link rel="stylesheet" type="text/css" href="<?=$dir?>/style.css?<?=$version?>"/>
|
||||
|
||||
<?=js("$dir/main.js")?>
|
||||
<?=css("$dir/style.css")?>
|
||||
<title>Production</title>
|
||||
</head>
|
||||
<body onload="onBodyLoad()">
|
||||
|
|
|
@ -3,8 +3,9 @@
|
|||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
||||
<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 rel="stylesheet" type="text/css" href="<?=$dir?>/style.css?<?=$version?>"/>
|
||||
<?=css("$dir/style.css")?>
|
||||
<title>Verdnatura</title>
|
||||
</head>
|
||||
<body>
|
||||
|
|
|
@ -3,8 +3,9 @@
|
|||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
||||
<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 rel="stylesheet" type="text/css" href="<?=$dir?>/style.css?<?=$version?>"/>
|
||||
<?=css("$dir/style.css")?>
|
||||
<title>Verdnatura</title>
|
||||
</head>
|
||||
<body>
|
||||
|
|
|
@ -42,9 +42,6 @@ class Account
|
|||
*/
|
||||
static function ldapSync ($db, $userName, $password)
|
||||
{
|
||||
if (empty ($password))
|
||||
return;
|
||||
|
||||
// Gets LDAP configuration parameters
|
||||
|
||||
$conf = $db->getObject (
|
||||
|
@ -58,81 +55,114 @@ class Account
|
|||
if (!$ds)
|
||||
throw new Exception ("Can't connect to LDAP server: ". ldapError ($ds));
|
||||
|
||||
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
|
||||
$bind = ldap_bind ($ds, $conf->rdn, base64_decode ($conf->password));
|
||||
try {
|
||||
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
|
||||
$bind = ldap_bind ($ds, $conf->rdn, base64_decode ($conf->password));
|
||||
|
||||
if (!$bind)
|
||||
throw new Exception ("Authentication failed on LDAP server: ". ldapError ($ds));
|
||||
if (!$bind)
|
||||
throw new Exception ("Authentication failed on LDAP server: ". ldapError ($ds));
|
||||
|
||||
// Prepares the data
|
||||
// Prepares the data
|
||||
|
||||
$domain = $db->getValue ('SELECT domain FROM account.mailConfig');
|
||||
$domain = $db->getValue ('SELECT domain FROM account.mailConfig');
|
||||
|
||||
$user = $db->getObject (
|
||||
'SELECT id, nickname, lang
|
||||
FROM account.user
|
||||
WHERE name = #',
|
||||
[$userName]
|
||||
);
|
||||
$user = $db->getObject (
|
||||
'SELECT id, nickname, lang
|
||||
FROM account.user
|
||||
WHERE name = #',
|
||||
[$userName]
|
||||
);
|
||||
|
||||
$nameArgs = explode (' ', $user->nickname);
|
||||
$givenName = $nameArgs[0];
|
||||
$cn = empty ($user->nickname) ? $userName : $user->nickname;
|
||||
|
||||
if (count ($nameArgs) > 1)
|
||||
$sn = $nameArgs[1];
|
||||
if (empty ($sn))
|
||||
$sn = 'Empty';
|
||||
$nameArgs = explode (' ', $user->nickname);
|
||||
$givenName = $nameArgs[0];
|
||||
|
||||
$info = [
|
||||
'cn' => $user->nickname,
|
||||
'displayName' => $user->nickname,
|
||||
'givenName' => $givenName,
|
||||
'sn' => $sn,
|
||||
'mail' => "$userName@{$domain}",
|
||||
'userPassword' => sshaEncode ($password),
|
||||
'preferredLanguage' => $user->lang
|
||||
];
|
||||
if (count ($nameArgs) > 1)
|
||||
$sn = $nameArgs[1];
|
||||
if (empty ($sn))
|
||||
$sn = 'Empty';
|
||||
|
||||
// Search the user entry
|
||||
$attrs = [
|
||||
'cn' => $cn,
|
||||
'displayName' => $user->nickname,
|
||||
'givenName' => $givenName,
|
||||
'sn' => $sn,
|
||||
'mail' => "$userName@{$domain}",
|
||||
'userPassword' => sshaEncode ($password),
|
||||
'preferredLanguage' => $user->lang
|
||||
];
|
||||
|
||||
$filter = "uid=$userName";
|
||||
// Search the user entry
|
||||
|
||||
if (!empty($conf->filter))
|
||||
$filter = "(&($filter)($conf->filter))";
|
||||
$filter = "uid=$userName";
|
||||
|
||||
$res = ldap_search ($ds, $conf->baseDn, $filter);
|
||||
if (!empty($conf->filter))
|
||||
$filter = "(&($filter)($conf->filter))";
|
||||
|
||||
if (!$res)
|
||||
throw new Exception ("Can't get the LDAP entry: ". ldapError ($ds));
|
||||
$res = ldap_search ($ds, $conf->baseDn, $filter);
|
||||
|
||||
$dn = "uid=$userName,{$conf->baseDn}";
|
||||
$entry = ldap_first_entry ($ds, $res);
|
||||
if (!$res)
|
||||
throw new Exception ("Can't get the LDAP entry: ". ldapError ($ds));
|
||||
|
||||
$classes = ldap_get_values ($ds, $entry, 'objectClass');
|
||||
$dn = "uid=$userName,{$conf->baseDn}";
|
||||
$entry = ldap_first_entry ($ds, $res);
|
||||
|
||||
if (!in_array ('inetOrgPerson', $classes))
|
||||
{
|
||||
ldap_delete ($ds, $dn);
|
||||
$entry = NULL;
|
||||
$classes = ldap_get_values ($ds, $entry, 'objectClass');
|
||||
|
||||
if (!in_array ('inetOrgPerson', $classes))
|
||||
{
|
||||
ldap_delete ($ds, $dn);
|
||||
$entry = NULL;
|
||||
}
|
||||
|
||||
if ($entry)
|
||||
{
|
||||
$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
|
||||
{
|
||||
$addAttrs = [];
|
||||
|
||||
foreach ($attrs as $attribute => $value)
|
||||
if (!empty ($value))
|
||||
$addAttrs[$attribute] = $value;
|
||||
|
||||
$addAttrs = array_merge ($addAttrs, [
|
||||
'objectClass' => ['inetOrgPerson'],
|
||||
'uid' => $userName
|
||||
]);
|
||||
$updated = ldap_add ($ds, $dn, $addAttrs);
|
||||
}
|
||||
|
||||
if (!$updated)
|
||||
throw new Exception ("Can't update the LDAP entry: ". ldapError ($ds));
|
||||
}
|
||||
|
||||
if ($entry)
|
||||
catch (Exception $e)
|
||||
{
|
||||
$updated = ldap_modify ($ds, $dn, $info);
|
||||
ldap_unbind ($ds);
|
||||
throw $e;
|
||||
}
|
||||
else
|
||||
{
|
||||
$info = array_merge ($info, [
|
||||
'objectClass' => ['inetOrgPerson'],
|
||||
'uid' => $userName
|
||||
]);
|
||||
$updated = ldap_add ($ds, $dn, $info);
|
||||
}
|
||||
|
||||
if (!$updated)
|
||||
throw new Exception ("Can't update the LDAP entry: ". ldapError ($ds));
|
||||
|
||||
ldap_unbind ($ds);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
<?php
|
||||
|
||||
$lang = isset($_SESSION['lang']) ? $_SESSION['lang'] : 'en';
|
||||
$version = $this->getVersion();
|
||||
|
||||
function getUrl ($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
|
||||
$mTime = '?'. $this->getVersion ();
|
||||
$fileVersion = $version;
|
||||
|
||||
return $fileName.$mTime;
|
||||
return "$fileName?$fileVersion";
|
||||
}
|
||||
|
||||
function js ($fileName)
|
||||
|
|
Loading…
Reference in New Issue