Compare commits

...

2 Commits

Author SHA1 Message Date
Thomas Hooge 5e605692dd Add missing LDAP code to login 2 years ago
Thomas Hooge 1c8021c325 Added counter to assetclass and assetclassgroup views 2 years ago
  1. 12
      assetclass.php
  2. 10
      assetclassgroup.php
  3. 2
      lang/de.php
  4. 2
      lang/en.php
  5. 2
      lib.php
  6. 43
      login.php
  7. 1
      options.php
  8. 12
      tpl/assetclass.tpl
  9. 6
      tpl/assetclassgroup.tpl
  10. 8
      tpl/options.tpl

@ -10,10 +10,14 @@ SPDX-License-Identifier: GPL-3.0-or-later
include("includes.php"); include("includes.php");
include("header.php"); include("header.php");
$sql = "SELECT a.assetclass_id, a.assetclass_name, g.assetclassgroup_id, $sql = "SELECT c.assetclass_id AS id, c.assetclass_name AS name, c.assetclassgroup_id AS group_id,
g.assetclassgroup_name, g.assetclassgroup_color g.assetclassgroup_name AS group_name, g.assetclassgroup_color AS color,
FROM assetclass AS a LEFT OUTER JOIN assetclassgroup AS g USING (assetclassgroup_id) COUNT(a.asset_id) AS count_asset
ORDER BY a.assetclass_name"; FROM assetclass AS c
LEFT JOIN assetclassgroup AS g USING (assetclassgroup_id)
LEFT JOIN asset AS a USING (assetclass_id)
GROUP BY id, name, group_id, group_name, color
ORDER BY c.assetclass_name";
$sth = $dbh->query($sql); $sth = $dbh->query($sql);
$smarty->assign("assetclasses", $sth->fetchAll(PDO::FETCH_ASSOC)); $smarty->assign("assetclasses", $sth->fetchAll(PDO::FETCH_ASSOC));

@ -10,10 +10,12 @@ SPDX-License-Identifier: GPL-3.0-or-later
include("includes.php"); include("includes.php");
include("header.php"); include("header.php");
$sql = "SELECT assetclassgroup_id AS id, assetclassgroup_name AS name, $sql = "SELECT g.assetclassgroup_id AS id, g.assetclassgroup_name AS name,
assetclassgroup_color AS color, assetclassgroup_description AS description g.assetclassgroup_color AS color, g.assetclassgroup_description AS description,
FROM assetclassgroup COUNT(c.assetclass_id) AS count_class
ORDER BY assetclassgroup_name"; FROM assetclassgroup AS g LEFT JOIN assetclass AS c USING (assetclassgroup_id)
GROUP BY id, name, color, description
ORDER BY g.assetclassgroup_name";
$sth = $dbh->query($sql); $sth = $dbh->query($sql);
$smarty->assign('assetclassgroups', $sth->fetchAll(PDO::FETCH_ASSOC)); $smarty->assign('assetclassgroups', $sth->fetchAll(PDO::FETCH_ASSOC));

@ -66,12 +66,14 @@ $lang = array(
'lang_assetclass_del' => 'Objektklasse löschen', 'lang_assetclass_del' => 'Objektklasse löschen',
'lang_assetclass_edit' => 'Objektklasse ändern', 'lang_assetclass_edit' => 'Objektklasse ändern',
'lang_assetclass_name' => 'Objektklassenname', 'lang_assetclass_name' => 'Objektklassenname',
'lang_assetclass_count' => '# Objekte',
'lang_assetclass_none' => 'Es sind keine Objektklassen vorhanden', 'lang_assetclass_none' => 'Es sind keine Objektklassen vorhanden',
'lang_assetclassgroup_add' => 'Objektklassengruppe hinzufügen', 'lang_assetclassgroup_add' => 'Objektklassengruppe hinzufügen',
'lang_assetclassgroup_del' => 'Objektklassengruppe löschen', 'lang_assetclassgroup_del' => 'Objektklassengruppe löschen',
'lang_assetclassgroup_edit' => 'Objektklassengruppe ändern', 'lang_assetclassgroup_edit' => 'Objektklassengruppe ändern',
'lang_assetclassgroup_name' => 'Objektklassengruppenname', 'lang_assetclassgroup_name' => 'Objektklassengruppenname',
'lang_assetclassgroup_count' => '# Klassen',
'lang_assetclassgroup_none' => 'Es sind keine Objektklassengruppen vorhanden', 'lang_assetclassgroup_none' => 'Es sind keine Objektklassengruppen vorhanden',
'lang_assignnodetoasset' => 'Knoten zu Objekt hinzufügen', 'lang_assignnodetoasset' => 'Knoten zu Objekt hinzufügen',

@ -66,12 +66,14 @@ $lang = array(
'lang_assetclass_del' => 'Delete assetclass', 'lang_assetclass_del' => 'Delete assetclass',
'lang_assetclass_edit' => 'Mofidy assetclass', 'lang_assetclass_edit' => 'Mofidy assetclass',
'lang_assetclass_name' => 'Assetclass name', 'lang_assetclass_name' => 'Assetclass name',
'lang_assetclass_count' => '# Assets',
'lang_assetclass_none' => 'There are no assetclasses defined', 'lang_assetclass_none' => 'There are no assetclasses defined',
'lang_assetclassgroup_add' => 'Add assetclassgroup', 'lang_assetclassgroup_add' => 'Add assetclassgroup',
'lang_assetclassgroup_del' => 'Delete assetclassgroup', 'lang_assetclassgroup_del' => 'Delete assetclassgroup',
'lang_assetclassgroup_edit' => 'Modify assetclassgroup', 'lang_assetclassgroup_edit' => 'Modify assetclassgroup',
'lang_assetclassgroup_name' => 'Assetclassgroup Name', 'lang_assetclassgroup_name' => 'Assetclassgroup Name',
'lang_assetclassgroup_count' => '# Classes',
'lang_assetclassgroup_none' => 'There are no assetclassegroups defined', 'lang_assetclassgroup_none' => 'There are no assetclassegroups defined',
'lang_assignnodetoasset' => 'Assign node to asset', 'lang_assignnodetoasset' => 'Assign node to asset',

@ -168,6 +168,8 @@ function db_load_enum($table, $column) {
WHERE table_name=? AND column_name=?"; WHERE table_name=? AND column_name=?";
$sth = $dbh->prepare($sql); $sth = $dbh->prepare($sql);
$sth->execute([$table, $column]); $sth->execute([$table, $column]);
// Für PHP < 7.4
// return array_map(function($x) { return trim($x, "'"); }, explode(',', $sth->fetchColumn()));
return array_map(fn($x) => trim($x, "'"), explode(',', $sth->fetchColumn())); return array_map(fn($x) => trim($x, "'"), explode(',', $sth->fetchColumn()));
} }

@ -22,6 +22,36 @@ $dbh->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
include("lib.php"); // only for get_language from browser. TODO: simplify include("lib.php"); // only for get_language from browser. TODO: simplify
function check_ldap_bind($user_name, $user_pass) {
global $config_ldap_host;
global $config_ldap_port;
global $config_ldap_base_dn;
global $config_ldap_bind_dn;
global $config_ldap_bind_pass;
global $config_ldap_login_attr;
$ldap_conn = NULL;
foreach ($config_ldap_host as $server) {
if ($ldap_conn = ldap_connect($server, $config_ldap_port)) {
if ($res = ldap_bind($ldap_conn, $config_ldap_bind_dn, $config_ldap_bind_pass)) {
ldap_set_option($ldap_conn, LDAP_OPT_REFERRALS, 0);
ldap_set_option($ldap_conn, LDAP_OPT_PROTOCOL_VERSION, 3);
$filter = "(&(objectClass=user)($config_ldap_login_attr=$user_name))";
$res = ldap_search($ldap_conn, $config_ldap_base_dn, $filter, ['dn']);
if ($res) {
$info = ldap_get_entries($ldap_conn, $res);
$user_dn = $info[0]['dn'];
$res = ldap_bind($ldap_conn, $user_dn, $user_pass);
if ($res) {
return TRUE;
}
}
}
return FALSE;
}
}
return FALSE;
}
function user_login ($user_name, $user_pass) { function user_login ($user_name, $user_pass) {
global $dbh; global $dbh;
@ -36,7 +66,7 @@ function user_login ($user_name, $user_pass) {
$sql = "SELECT user_id, user_pass, user_displayname, user_language, $sql = "SELECT user_id, user_pass, user_displayname, user_language,
user_imagesize, user_imagecount, user_mac, user_dateformat, user_imagesize, user_imagecount, user_mac, user_dateformat,
user_dns1suffix, user_dns2suffix, user_tooltips, user_dns1suffix, user_dns2suffix, user_tooltips,
user_menu, user_role, user_flags user_menu, user_role, user_flags, user_realm
FROM user FROM user
WHERE user_name=?"; WHERE user_name=?";
$sth = $dbh->prepare($sql); $sth = $dbh->prepare($sql);
@ -47,6 +77,14 @@ function user_login ($user_name, $user_pass) {
return FALSE; return FALSE;
} }
if ($user->user_realm == 'ldap') {
// check LDAP auth
if (! check_ldap_bind($user_name, $user_pass)) {
return FALSE;
}
// TODO sync LDAP data to local
{ else {
// compare local passwords
if (strcmp(md5($user_pass), rtrim($user->user_pass)) != 0) { if (strcmp(md5($user_pass), rtrim($user->user_pass)) != 0) {
// password does not match with md5, check if new hash matches // password does not match with md5, check if new hash matches
// For future expansion: $pwd_peppered = hash_hmac('sha256', $user_pass, $config_pepper); // For future expansion: $pwd_peppered = hash_hmac('sha256', $user_pass, $config_pepper);
@ -59,10 +97,11 @@ function user_login ($user_name, $user_pass) {
$newhash = password_hash($user_pass, PASSWORD_BCRYPT); $newhash = password_hash($user_pass, PASSWORD_BCRYPT);
$sth->execute([$newhash, $user->user_id]); $sth->execute([$newhash, $user->user_id]);
} }
}
// all ok: user is logged in, register session data // all ok: user is logged in, register session data
$_SESSION['suser_id'] = $user->user_id; $_SESSION['suser_id'] = $user->user_id;
$_SESSION['suser_realm'] = $user->user_realm;
$_SESSION['suser_displayname'] = $user->user_displayname; $_SESSION['suser_displayname'] = $user->user_displayname;
$_SESSION['suser_language'] = $user->user_language; $_SESSION['suser_language'] = $user->user_language;
$_SESSION['suser_imagesize'] = $user->user_imagesize; $_SESSION['suser_imagesize'] = $user->user_imagesize;

@ -10,6 +10,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
include("includes.php"); include("includes.php");
include("header.php"); include("header.php");
$smarty->assign('realm', $_SESSION['suser_realm']);
$smarty->assign('role_add', $_SESSION['suser_role_add']); $smarty->assign('role_add', $_SESSION['suser_role_add']);
$smarty->assign('role_edit', $_SESSION['suser_role_edit']); $smarty->assign('role_edit', $_SESSION['suser_role_edit']);
$smarty->assign('role_delete', $_SESSION['suser_role_delete']); $smarty->assign('role_delete', $_SESSION['suser_role_delete']);

@ -20,15 +20,21 @@
<td class="header"> <td class="header">
{$lang_assetclassgroup_name} {$lang_assetclassgroup_name}
</td> </td>
<td class="header">
{$lang_assetclass_count}
</td>
</tr> </tr>
{foreach item=assetclass from=$assetclasses} {foreach item=assetclass from=$assetclasses}
<tr> <tr>
<td class="label"> <td class="label">
<a href="assetclassview.php?assetclass_id={$assetclass.assetclass_id}">{$assetclass.assetclass_name}</a> <a href="assetclassview.php?assetclass_id={$assetclass.id}">{$assetclass.name}</a>
</td> </td>
<td class="value"> <td class="value">
<img src="image.php?color={$assetclass.assetclassgroup_color}" alt="#{$assetclass.assetclassgroup_color}"> <img src="image.php?color={$assetclass.color}" alt="#{$assetclass.color}">
<a href="assetclassgroupview.php?assetclassgroup_id={$assetclass.assetclassgroup_id}">{$assetclass.assetclassgroup_name}</a> <a href="assetclassgroupview.php?assetclassgroup_id={$assetclass.group_id}">{$assetclass.group_name}</a>
</td>
<td class="label">
{$assetclass.count_asset}
</td> </td>
</tr> </tr>
{foreachelse} {foreachelse}

@ -20,6 +20,9 @@
<td class="header"> <td class="header">
{$lang_description} {$lang_description}
</td> </td>
<td class="header">
{$lang_assetclassgroup_count}
</td>
</tr> </tr>
{foreach item=acg from=$assetclassgroups} {foreach item=acg from=$assetclassgroups}
<tr> <tr>
@ -30,6 +33,9 @@
<td> <td>
{$acg.description} {$acg.description}
</td> </td>
<td>
{$acg.count_class}
</td>
</tr> </tr>
{foreachelse} {foreachelse}
<tr> <tr>

@ -63,4 +63,12 @@
{/if} {/if}
</td> </td>
</tr> </tr>
<tr>
<td class="label">
{$lang_user_realm}
</td>
<td class="label">
{$realm}
</td>
</tr>
</table> </table>