Compare commits

..

2 Commits

  1. 27
      asset.php
  2. 3
      header.php
  3. BIN
      images/key_add.png
  4. 2
      includes.php
  5. 14
      install/mysql_sample.sql
  6. 4
      lang/de.php
  7. 4
      lang/en.php
  8. 95
      lib.php
  9. 94
      lib/functions.php
  10. 3
      location.php
  11. 3
      login.php
  12. 20
      options.php
  13. 2
      tpl/asset.tpl
  14. 6
      tpl/options.tpl
  15. 6
      tpl/optionseditdisplay.tpl
  16. 6
      tpl/useredit.tpl
  17. 24
      tpl/userview.tpl
  18. 34
      user.php

@ -106,32 +106,39 @@ if ($action == ACT_DEFAULT):
// ========== VARIANT: default behavior =======================================
// create letter links
$sql = "SELECT DISTINCT SUBSTRING(UPPER(asset_name),1,1) AS asset_letter
$sql = "SELECT DISTINCT SUBSTRING(UPPER(asset_name),1,1) AS bst
FROM asset
ORDER BY asset_letter";
ORDER BY bst";
$sth = $dbh->query($sql);
$alphabet = $sth->fetchAll();
$alphabet[] = ['bst' => '*'];
$smarty->assign("alphabet", $alphabet);
// total asset count
$sth = $dbh->query("SELECT COUNT(*) FROM asset");
$smarty->assign("assetcount", $sth->fetchColumn());
$assetcount = $sth->fetchColumn();
$smarty->assign("assetcount", $sassetcount);
// assets for current letter
if (isset($_GET['asset_letter'])) {
$asset_letter = sanitize($_GET['asset_letter']);
if (isset($_GET['bst'])) {
$bst = sanitize($_GET['bst']);
} else {
$asset_letter = $alphabet[0]['asset_letter'];
$bst = $alphabet[0]['bst'];
}
$sql = "SELECT a.asset_id, IF(LENGTH(a.asset_name)>0, a.asset_name, '...') AS asset_name,
a.asset_info, c.assetclass_id, c.assetclass_name
FROM asset AS a LEFT OUTER JOIN assetclass AS c USING (assetclass_id)
WHERE SUBSTRING(a.asset_name,1,1)=?
ORDER BY a.asset_name";
FROM asset AS a LEFT OUTER JOIN assetclass AS c USING (assetclass_id)";
if ($bst != '*') {
$sql .= " WHERE SUBSTRING(a.asset_name,1,1)=?";
$p = array($bst);
} else {
$p = array();
}
$sql .= " ORDER BY a.asset_name";
$sth = $dbh->prepare($sql);
$sth->execute([$asset_letter]);
$sth->execute($p);
$smarty->assign("assets", $sth->fetchAll());
$smarty->display("asset.tpl");

@ -43,6 +43,9 @@ if ($_SESSION['suser_menu_locations']) {
if ($_SESSION['suser_menu_nodes']) {
$menu[] = '<a href="node.php">' . $lang['lang_nodes'] . "</a>\n";
}
if ($_SESSION['suser_menu_nats']) {
$menu[] = '<a href="nat.php">' . $lang['lang_nats'] . "</a>\n";
}
if ($_SESSION['suser_menu_subnets']) {
$menu[] = '<a href="subnet.php">' . $lang['lang_subnets'] . "</a>\n";
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 703 B

@ -32,4 +32,4 @@ $dbh->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
include("lib.php");
$language = lang_getfrombrowser($config_lang, $config_lang_default, null, false);
// $language = lang_getfrombrowser($config_lang, $config_lang_default);

@ -1,8 +1,11 @@
INSERT INTO asset (asset_name, assetclass_id) VALUES
('Computer', 1),
('Computer Alice', 1),
('Computer Bob', 1),
('Computer Admin', 1),
('Server', 3),
('Printer', 4),
('Firewall', 6);
('Firewall', 6),
('Air Condition System', 8);
INSERT INTO assetclass (assetclassgroup_id, assetclass_name) VALUES
(1, 'Desktop'),
@ -11,7 +14,8 @@ INSERT INTO assetclass (assetclassgroup_id, assetclass_name) VALUES
(3, 'Printer'),
(4, 'Switch'),
(4, 'Firewall'),
(5, 'Scanner');
(5, 'Scanner'),
(5, 'Other');
INSERT INTO assetclassgroup (assetclassgroup_name, assetclassgroup_color) VALUES
('Personal Computer', '000000'),
@ -54,7 +58,9 @@ INSERT INTO user (user_name, user_pass, user_displayname) VALUES
('bob', '$2y$10$hl4NN4lOyuz7KN0ZjLHbOuCqGi08GVaTvl/RiMcL1mbFqGmtzDN76', 'Bob');
INSERT INTO vlan (vlan_number, vlan_name) VALUES
(1, 'DEFAULT_VLAN');
(1, 'DEFAULT_VLAN'),
(2, 'WLAN'),
(3, 'DMZ');
INSERT INTO zone (zone_soa, zone_origin, zone_hostmaster, zone_serial, zone_ns1) VALUES
('ns1.example.com.', 'example.com.', 'hostmaster.example.com.', '2023021301', 'ns1.example.com');

@ -14,6 +14,8 @@ $lang = array(
'lang_location' => 'Standort',
'lang_locations' => 'Standorte',
'lang_menu' => 'Menü',
'lang_nat' => 'NAT',
'lang_nats' => 'NATs',
'lang_node' => 'Knoten',
'lang_nodes' => 'Knoten',
'lang_user' => 'Benutzer',
@ -40,6 +42,7 @@ $lang = array(
'lang_logout' => 'Abmelden',
'lang_options' => 'Optionen',
'lang_option_none' => '(kein)',
'lang_pass_set' => 'Neues Kennwort einstellen',
'lang_reset' => 'Zur&uuml;cksetzen',
'lang_search' => 'Suche',
'lang_statistics' => 'Statistik',
@ -128,7 +131,6 @@ $lang = array(
'lang_mac' => 'MAC-Adresse',
'lang_proto_vers' => 'Protokollversion',
'lang_nat' => 'NAT',
'lang_nat_add' => 'NAT hinzufügen',
'lang_nat_del' => 'NAT löschen',
'lang_nat_edit' => 'NAT ändern',

@ -14,6 +14,8 @@ $lang = array(
'lang_location' => 'Location',
'lang_locations' => 'Locations',
'lang_menu' => 'Menu',
'lang_nat' => 'NAT',
'lang_nats' => 'NATs',
'lang_node' => 'Node',
'lang_nodes' => 'Nodes',
'lang_user' => 'User',
@ -40,6 +42,7 @@ $lang = array(
'lang_logout' => 'Logout',
'lang_options' => 'Options',
'lang_option_none' => '(none)',
'lang_pass_set' => 'Set new password',
'lang_reset' => 'Reset',
'lang_search' => 'Search',
'lang_statistics' => 'Statistics',
@ -128,7 +131,6 @@ $lang = array(
'lang_mac' => 'MAC Address',
'lang_proto_vers' => 'Protocol version',
'lang_nat' => 'NAT',
'lang_nat_add' => 'Add NAT',
'lang_nat_del' => 'Delete NAT',
'lang_nat_edit' => 'Modify NAT',

@ -30,7 +30,7 @@ define ('ACT_PASSWORD', 14);
// ========== GLOBAL PAGE START CODE ==========================================
// global version string
$config_version = 'v0.9';
$config_version = 'v0.9.1';
// available languages
$config_lang = array('de', 'en');
@ -60,6 +60,42 @@ $g_error = new MessageError;
$action = ACT_DEFAULT;
// ========== LANGUAGE FUNCTIONS ==============================================
function lang_getfrombrowser($allowed, $default) {
// get browser most preferred language if possible
if (empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
return $default;
}
$accepted = preg_split('/,\s*/', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
$current_lang = $default;
$current_q = 0;
foreach ($accepted as $lang) {
$res = preg_match ('/^([a-z]{1,8}(?:-[a-z]{1,8})*)(?:;\s*q=(0(?:\.[0-9]{1,3})?|1(?:\.0{1,3})?))?$/i',
$lang, $matches);
if (!$res) {
continue;
}
$lang_code = explode ('-', $matches[1]);
if (isset($matches[2])) {
$lang_quality = (float)$matches[2];
} else {
$lang_quality = 1.0;
}
while (count($lang_code)) {
if (in_array(strtolower(join ('-', $lang_code)), $allowed)) {
if ($lang_quality > $current_q) {
$current_lang = strtolower (join ('-', $lang_code));
$current_q = $lang_quality;
break;
}
}
array_pop($lang_code);
}
}
return $current_lang;
}
// ========== FEEDBACK FUNCTIONS ==============================================
class Message {
@ -136,6 +172,13 @@ class MessageError extends Message {
}
}
function msgout(array $parameters, Smarty_Internal_Template $smarty) {
// This is just a quick hack around missing {php} in Smarty3
$GLOBALS['g_error']->PrintOut();
$GLOBALS['g_warning']->PrintOut();
$GLOBALS['g_message']->PrintOut();
}
// ========== FORM FUNCTIONS ==================================================
function form_get_action() {
@ -159,7 +202,7 @@ function submit_error($action) {
function by default. An exit() is conscious here *not* installed,
since it could be that despite such an error the program
execution should be continued. */
return sprintf('The action "%s" is unknown. It is probably a program error.<br /> Please inform your administrator of the exact circumstances of how this situation came about.', strtoupper($action));
return sprintf('The action "%s" is unknown. It is probably a program error.<br> Please inform your administrator of the exact circumstances of how this situation came about.', strtoupper($action));
}
// ========== DATABASE FUCTIONS ===============================================
@ -261,3 +304,51 @@ function db_get_options_zone($default = NULL) {
}
return $options;
}
// ========== MISC FUCTIONS ===================================================
function strip_mac($mac, $caps=true) {
// strip mac address to 12 char string
// strip chars we don't need
$mac = preg_replace('/[^a-fA-F0-9]/', '', $mac);
if ($caps) {
$mac = strtoupper($mac);
} else {
$mac = strtolower($mac);
}
return $mac;
}
function write_mac($mac, $user_mac='xx:xx:xx:xx:xx:xx') {
// rebuild mac address using user supplied format
if (strlen($mac) != 12) {
// if the MAC is empty, or for whatever reason incorrect, just return
return $mac;
}
// check format of user mac: count upper or lower char
$chars = count_chars($user_mac, 1);
if (array_key_exists(88, $chars) and $chars[88] == 12) {
$pattern = '/X/';
$mac = strtoupper($mac);
} elseif (array_key_exists(120, $chars) and $chars[120] == 12) {
$pattern = '/x/';
$mac = strtolower($mac);
} else {
// invalid format
return $mac;
}
for($i=0; $i<12; $i++) {
$user_mac = preg_replace($pattern, $mac[$i], $user_mac, 1);
}
return $user_mac;
}
function header_location($location) {
// redirect page
header('location:' . $location);
exit;
}

@ -7,52 +7,6 @@ Copyright (C) 2011-2023 Thomas Hooge
SPDX-License-Identifier: GPL-3.0-or-later
*****************************************************************************/
function strip_mac($mac, $caps=true) {
// strip mac address to 12 char string
// strip chars we don't need
$mac = preg_replace('/[^a-fA-F0-9]/', '', $mac);
if ($caps) {
$mac = strtoupper($mac);
} else {
$mac = strtolower($mac);
}
return $mac;
}
function write_mac($mac, $user_mac='xx:xx:xx:xx:xx:xx') {
// rebuild mac address using user supplied format
if (strlen($mac) != 12) {
// if the MAC is empty, or for whatever reason incorrect, just return
return $mac;
}
// check format of user mac: count upper or lower char
$chars = count_chars($user_mac, 1);
if (array_key_exists(88, $chars) and $chars[88] == 12) {
$pattern = '/X/';
$mac = strtoupper($mac);
} elseif (array_key_exists(120, $chars) and $chars[120] == 12) {
$pattern = '/x/';
$mac = strtolower($mac);
} else {
// invalid format
return $mac;
}
for($i=0; $i<12; $i++) {
$user_mac = preg_replace($pattern, $mac[$i], $user_mac, 1);
}
return $user_mac;
}
function header_location($location) {
// redirect page
header('location:' . $location);
exit;
}
// sanitize input
function sanitize($input) {
global $dblink;
@ -76,49 +30,13 @@ function sanitize($input) {
return $input;
}
function lang_getfrombrowser ($allowed_languages, $default_language, $lang_variable = null, $strict_mode = true) {
if ($lang_variable === null) {
$lang_variable = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
}
if (empty($lang_variable)) {
return $default_language;
}
$accepted_languages = preg_split('/,\s*/', $lang_variable);
$current_lang = $default_language;
$current_q = 0;
foreach ($accepted_languages as $accepted_language) {
$res = preg_match ('/^([a-z]{1,8}(?:-[a-z]{1,8})*)(?:;\s*q=(0(?:\.[0-9]{1,3})?|1(?:\.0{1,3})?))?$/i',
$accepted_language, $matches);
if (!$res) {
continue;
}
$lang_code = explode ('-', $matches[1]);
if (isset($matches[2])) {
$lang_quality = (float)$matches[2];
} else {
$lang_quality = 1.0;
}
while (count ($lang_code)) {
if (in_array (strtolower (join ('-', $lang_code)), $allowed_languages)) {
if ($lang_quality > $current_q) {
$current_lang = strtolower (join ('-', $lang_code));
$current_q = $lang_quality;
break;
}
}
if ($strict_mode) {
break;
}
array_pop ($lang_code);
}
}
return $current_lang;
}
function print_tree_rec($tree, $level) {
$output = '<ul class="treelvl' . $level. '">' . "\n";
foreach ($tree as $node) {
$output .= '<li><a href="' . $node['href'] . '">' . $node['value'] . '</a>';
if ($node['info']) {
$output .= ' - ' . $node['info'];
}
if ($node['children']) {
$output .= "\n" . print_tree_rec($node['children'], $level+1);
}
@ -141,9 +59,3 @@ function print_tree($params, Smarty_Internal_Template $template) {
}
}
function msgout(array $parameters, Smarty_Internal_Template $smarty) {
// This is just a quick hack around missing {php} in Smarty3
$GLOBALS['g_error']->PrintOut();
$GLOBALS['g_warning']->PrintOut();
$GLOBALS['g_message']->PrintOut();
}

@ -142,7 +142,8 @@ include("header.php");
if ($action == ACT_DEFAULT):
// ========== VARIANT: default behavior =======================================
$sql = "SELECT location_id AS id, location_name AS value, location_parent AS parent_id
$sql = "SELECT location_id AS id, location_name AS value, location_parent AS parent_id,
CONCAT(LEFT(location_info,40), IF(CHAR_LENGTH(location_info)>40,'...','')) AS info
FROM location
ORDER BY location_parent, location_sort, location_name";
$sth = $dbh->query($sql);

@ -136,6 +136,7 @@ function user_login ($user_name, $user_pass) {
$_SESSION['suser_menu_cables'] = in_array('cable', $menu);
$_SESSION['suser_menu_locations'] = in_array('location', $menu);
$_SESSION['suser_menu_nodes'] = in_array('node', $menu);
$_SESSION['suser_menu_nats'] = in_array('nat', $menu);
$_SESSION['suser_menu_subnets'] = in_array('subnet', $menu);
$_SESSION['suser_menu_vlans'] = in_array('vlan', $menu);
$_SESSION['suser_menu_zones'] = in_array('zone', $menu);
@ -147,7 +148,7 @@ function user_login ($user_name, $user_pass) {
// ========== LOGIN: HERE BE DRAGONS ==========================================
$language = lang_getfrombrowser($config_lang, $config_lang_default, null, false);
$language = lang_getfrombrowser($config_lang, $config_lang_default);
include('lang/' . $language . '.php');
if ($_SERVER['REQUEST_METHOD'] == "POST" ) {

@ -34,6 +34,7 @@ switch ($submit = form_get_action()) {
$menu_cables = sanitize($_POST['user_menu_cables']);
$menu_locations = sanitize($_POST['user_menu_locations']);
$menu_nodes = sanitize($_POST['user_menu_nodes']);
$menu_nats = sanitize($_POST['user_menu_nats']);
$menu_subnets = sanitize($_POST['user_menu_subnets']);
$menu_vlans = sanitize($_POST['user_menu_vlans']);
$menu_zones = sanitize($_POST['user_menu_zones']);
@ -46,6 +47,7 @@ switch ($submit = form_get_action()) {
if ($menu_cables) $menu[] = 'cable';
if ($menu_locations) $menu[] = 'location';
if ($menu_nodes) $menu[] = 'node';
if ($menu_nats) $menu[] = 'nat';
if ($menu_subnets) $menu[] = 'subnet';
if ($menu_vlans) $menu[] = 'vlan';
if ($menu_zones) $menu[] = 'zone';
@ -76,6 +78,7 @@ switch ($submit = form_get_action()) {
$_SESSION['suser_menu_cables'] = $menu_cables;
$_SESSION['suser_menu_locations'] = $menu_locations;
$_SESSION['suser_menu_nodes'] = $menu_nodes;
$_SESSION['suser_menu_nats'] = $menu_nats;
$_SESSION['suser_menu_subnets'] = $menu_subnets;
$_SESSION['suser_menu_vlans'] = $menu_vlans;
$_SESSION['suser_menu_zones'] = $menu_zones;
@ -133,7 +136,15 @@ $smarty->display("options.tpl");
elseif ($action == ACT_EDIT):
// ========== VARIANT: edit display options ===================================
$smarty->assign("language", $language);
$smarty->assign("language", lang_getfrombrowser($config_lang, $config_lang_default));
// available languages
$lang_options = array();
foreach ($config_lang as $lang) {
$lang_options[$lang] = $lang;
}
$smarty->assign("lang_options", $lang_options);
if($_SESSION['suser_menu_assets']=='on') {
$user_menu_assets_checked = 'checked';
@ -170,6 +181,12 @@ if($_SESSION['suser_menu_nodes']=='on') {
} else {
$user_menu_nodes_checked = '';
}
// nats
if($_SESSION['suser_menu_nats']=='on') {
$user_menu_nats_checked = 'checked';
} else {
$user_menu_nats_checked = '';
}
// subnets
if($_SESSION['suser_menu_subnets']=='on') {
$user_menu_subnets_checked = 'checked';
@ -209,6 +226,7 @@ $smarty->assign("user_menu_assetclassgroups_checked", $user_menu_assetclassgroup
$smarty->assign("user_menu_cables_checked", $user_menu_cables_checked);
$smarty->assign("user_menu_locations_checked", $user_menu_locations_checked);
$smarty->assign("user_menu_nodes_checked", $user_menu_nodes_checked);
$smarty->assign("user_menu_nats_checked", $user_menu_nats_checked);
$smarty->assign("user_menu_subnets_checked", $user_menu_subnets_checked);
$smarty->assign("user_menu_vlans_checked", $user_menu_vlans_checked);
$smarty->assign("user_menu_zones_checked", $user_menu_zones_checked);

@ -16,7 +16,7 @@
<tr>
{foreach item=letter from=$alphabet}
<td>
<a href="asset.php?asset_letter={$letter.asset_letter}">{$letter.asset_letter}</a>&nbsp;
<a href="asset.php?bst={$letter.bst}">{$letter.bst}</a>&nbsp;
</td>
{/foreach}
</tr>

@ -47,13 +47,13 @@
</td>
<td class="label">
{if $role_add}
<img src="images/page_add.png" alt="[Add]"> {$lang_user_role_add} <br>
<img src="images/add.png" alt="[Add]"> {$lang_user_role_add}<br>
{/if}
{if $role_edit}
<img src="images/page_edit.png" alt="[Edit]"> {$lang_user_role_edit} <br>
<img src="images/edit.png" alt="[Edit]"> {$lang_user_role_edit}<br>
{/if}
{if $role_edit}
<img src="images/page_delete.png" alt="[Del]"> {$lang_user_role_delete} <br>
<img src="images/delete.png" alt="[Del]"> {$lang_user_role_delete}<br>
{/if}
{if $role_manage}
<img src="images/manage.png" alt="[Manage]"> {$lang_user_role_manage}<br>

@ -27,7 +27,7 @@
<span class="help" title="{$lang_options_language_help}">{$lang_user_language}</span>
</td>
<td class="value">
<input type="text" name="user_language" value="{$user_language}" size="2">
{html_options name=user_language options=$lang_options selected={$user_language}}
({$language})
</td>
</tr>
@ -53,6 +53,7 @@
</td>
<td class="value">
<input type="text" name="user_mac" value="{$user_mac}">
(xx:xx:xx:xx:xx:xx)
</td>
</tr>
<tr>
@ -92,6 +93,9 @@
{/if}
<input type="checkbox" name="user_menu_locations" {$user_menu_locations_checked}>{$lang_locations}<br />
<input type="checkbox" name="user_menu_nodes" {$user_menu_nodes_checked}>{$lang_nodes}<br />
{if $suser_admin}
<input type="checkbox" name="user_menu_nats" {$user_menu_nats_checked}>{$lang_nats}<br />
{/if}
<input type="checkbox" name="user_menu_subnets" {$user_menu_subnets_checked}>{$lang_subnets}<br />
<input type="checkbox" name="user_menu_vlans" {$user_menu_vlans_checked}>{$lang_vlans}<br />
<input type="checkbox" name="user_menu_zones" {$user_menu_zones_checked}>{$lang_zones}

@ -60,7 +60,7 @@
{$lang_user_role_add}
</td>
<td class="value">
<img src="images/page_add.png" alt="[Add]">
<img src="images/add.png" alt="[Add]">
<input type="checkbox" name="role_add" {if in_array('add', $user->role)} checked="checked"{/if}
</td>
</tr>
@ -69,7 +69,7 @@
{$lang_user_role_edit}
</td>
<td class="value">
<img src="images/page_edit.png" alt="[Edit]">
<img src="images/edit.png" alt="[Edit]">
<input type="checkbox" name="role_edit" {if in_array('edit', $user->role)} checked="checked"{/if}
</td>
</tr>
@ -79,7 +79,7 @@
{$lang_user_role_delete}
</td>
<td class="value">
<img src="images/page_delete.png" alt="[Delete]">
<img src="images/delete.png" alt="[Delete]">
<input type="checkbox" name="role_delete" {if in_array('delete', $user->role)} checked="checked"{/if}
</td>
</tr>

@ -50,13 +50,13 @@
</td>
<td class="value">
{if in_array('add', $user->role)}
<img src="images/page_add.png" alt="{$lang_user_role_add}"{if $suser_tooltips} title="{$lang_user_role_add}"{/if} />
<img src="images/add.png" alt="{$lang_user_role_add}"{if $suser_tooltips} title="{$lang_user_role_add}"{/if} />
{/if}
{if in_array('edit', $user->role)}
<img src="images/page_edit.png" alt="{$lang_user_role_edit}"{if $suser_tooltips} title="{$lang_user_role_edit}"{/if} />
<img src="images/edit.png" alt="{$lang_user_role_edit}"{if $suser_tooltips} title="{$lang_user_role_edit}"{/if} />
{/if}
{if in_array('delete', $user->role)}
<img src="images/page_delete.png" alt="{$lang_user_role_delete}"{if $suser_tooltips} title="{$lang_user_role_delete}"{/if} />
<img src="images/delete.png" alt="{$lang_user_role_delete}"{if $suser_tooltips} title="{$lang_user_role_delete}"{/if} />
{/if}
{if in_array('manage', $user->role)}
<img src="images/manage.png" alt="{$lang_user_role_manage}"{if $suser_tooltips} title="{$lang_user_role_manage}"{/if} />
@ -66,4 +66,22 @@
{/if}
</td>
</tr>
{if $suser_manage}
<tr>
<td class="label">
{if $newpass}
{$lang_options_newpassword1}
{else}
{$lang_pass_set}
{/if}
</td>
<td class="value">
{if $newpass}
{$newpass}
{else}
<a href="{$g_scriptname}?f=pass&amp;id={$user->id}"><img src="images/key_add.png" alt="{$lang_reset}"{if $suser_tooltips} title="{$lang_pass_set}"{/if} /></a>
{/if}
</td>
</tr>
{/if}
</table>

@ -18,6 +18,23 @@ if (isset($_REQUEST['id'])) {
$id = (int) $_REQUEST['id'] or $id = 0;
}
function makepwd($length) {
mt_srand((double) microtime() * 1000000);
$digits = "0123456789";
$chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
$umlauts = "ÄÖÜäöüß";
$specials = "!§$%&/()=?[]{}+~*#.,;:<>|";
$vocals = "AEIOUaeiou";
$consonants = "BCDFGHJKLMNPQRSTVWXYZbcdfghjklmnpqrstvwxyz";
$passwd = '';
$possible = $chars . $digits;
$l = strlen($possible)-1;
for ($k = 0; $k < $length; $k += 1) {
$passwd .= $possible[mt_rand(0, $l)];
}
return $passwd;
}
// ========== ACTIONS START ===================================================
switch ($submit = form_get_action()) {
@ -28,6 +45,22 @@ switch ($submit = form_get_action()) {
case 'edit': $action = ACT_EDIT; break;
case 'del': $action = ACT_DELETE; break;
case 'pass':
// Create new random password to display once
$newpass = makepwd(8);
$sql = "UPDATE user SET user_pass=:pass WHERE user_id=:id";
$sth = $dbh->prepare($sql);
$sth->bindValue(':id', $id, PDO::PARAM_INT);
$sth->bindValue(':pass', password_hash($newpass, PASSWORD_BCRYPT), PDO::PARAM_STR);
try {
$sth->execute();
} catch (PDOException $e) {
$g_warning->Add($e->getMessage());
}
$smarty->assign('newpass', $newpass);
$action = ACT_VIEW;
break;
case 'insert':
$user_name = strtolower(sanitize($_POST['user_name']));
$user_displayname = sanitize($_POST['user_displayname']);
@ -156,6 +189,7 @@ $user = $sth->fetch(PDO::FETCH_OBJ);
$user->role = explode(',', $user->role);
$smarty->assign("user", $user);
// auth realms
$smarty->assign("realm_ids", ['local', 'ldap']);
$smarty->assign("realm_names", ['Local', 'LDAP']);