diff --git a/lib/functions.php b/lib/functions.php index 486ceea..96cb7e3 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -1,170 +1,157 @@ . - - For more information, visit http://sourceforge.net/projects/ipreg, - or contact me at wietsew@users.sourceforge.net - *****************************************************************************/ +/***************************************************************************** +IP Reg, a PHP/MySQL IPAM tool +Copyright (C) 2007-2009 Wietse Warendorff (up to v0.5) +Copyright (C) 2011-2023 Thomas Hooge + +SPDX-License-Identifier: GPL-3.0-or-later +*****************************************************************************/ + +// strip mac address to 12 char string +function strip_mac($mac) { + // strip chars we don't need + $mac = preg_replace("|[^a-fA-F0-9]|", "", $mac); + + // capitalize (just because it looks better eh) + $mac = strtoupper($mac); + + // and return + return ($mac); +} + +// rebuild mac address +function write_mac($mac) { + // check string length + if (strlen($mac)!=12) { + // if the MAC is empty, or for whatever reason incorrect, just return + return $mac; + } else { + // count to 12... + for ($i=0; $i<12; $i++) { + // ... and strip mac to pieces + ${"mac".$i} = $mac{$i}; + } - // strip mac address to 12 char string - function strip_mac($mac) { - // strip chars we don't need - $mac = preg_replace("|[^a-fA-F0-9]|", "", $mac); + // get user preference + $user_mac = $_SESSION['suser_mac']; - // capitalize (just because it looks better eh) - $mac = strtoupper($mac); + // count to 12 again... + for($i=0; $i<12; $i++) { + // ... and replace user preference with pieces + $user_mac = preg_replace("/x/", ${"mac".$i}, $user_mac, 1); + } // and return - return ($mac); + return $user_mac; } +} - // rebuild mac address - function write_mac($mac) { - // check string length - if (strlen($mac)!=12) { - // if the MAC is empty, or for whatever reason incorrect, just return - return $mac; - } else { - // count to 12... - for($i=0;$i<12;$i++) { - // ... and strip mac to pieces - ${"mac".$i} = $mac{$i}; - } +// redirect page +function header_location($location) { + // send header + header("location: " . $location); - // get user preference - $user_mac = $_SESSION['suser_mac']; + // exit to be sure + exit; +} - // count to 12 again... - for($i=0;$i<12;$i++) { - // ... and replace user preference with pieces - $user_mac = preg_replace("/x/", ${"mac".$i}, $user_mac, 1); - } +// sanitize input +function sanitize($input) { + global $dblink; - // and return - return $user_mac; - } - } + // trim whitespaces + $input = @trim($input); - // redirect page - function header_location($location) { - // send header - header("location: " . $location); - - // exit to be sure - exit; + // magic quotes enabled? + if(get_magic_quotes_gpc()) { + // strip slashes + $input = stripslashes($input); } - // sanitize input - function sanitize($input) { - global $dblink; - - // trim whitespaces - $input = @trim($input); + // convert to utf-8 + iconv("UTF-8", "UTF-8", $input); - // magic quotes enabled? - if(get_magic_quotes_gpc()) { - // strip slashes - $input = stripslashes($input); - } - - // convert to utf-8 - iconv("UTF-8", "UTF-8", $input); + // convert special chars + $input = htmlentities($input,ENT_QUOTES,'UTF-8'); - // convert special chars - $input = htmlentities($input,ENT_QUOTES,'UTF-8'); + // make sql ready + $input = mysqli_real_escape_string($dblink, $input); - // make sql ready - $input = mysqli_real_escape_string($dblink, $input); + // and return + return $input; +} - // and return +function mysql_nullstring($input) { + if (isset($input)) { return $input; + } else { + return ''; } +} - function mysql_nullstring($input) { - if (isset($input)) { - return $input; - } else { - return ''; - } +function lang_getfrombrowser ($allowed_languages, $default_language, $lang_variable = null, $strict_mode = true) { + if ($lang_variable === null) { + $lang_variable = $_SERVER['HTTP_ACCEPT_LANGUAGE']; } - - 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; } - if (empty($lang_variable)) { - return $default_language; + $lang_code = explode ('-', $matches[1]); + if (isset($matches[2])) { + $lang_quality = (float)$matches[2]; + } else { + $lang_quality = 1.0; } - $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) { + 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; } - array_pop ($lang_code); } - } - return $current_lang; - } - - function print_tree_rec($tree, $level) { - $output = '\n"; - return $output; } - - function print_tree ($params, &$smarty) { - if (empty($params['level'])) { - $level = 0; - } else { - $level = $params['level']; - } - if (empty($params['tree'])) { - return ''; - } else { - return print_tree_rec($params['tree'], $level); + return $current_lang; +} + +function print_tree_rec($tree, $level) { + $output = '\n"; + return $output; +} + +function print_tree($params, &$smarty) { + if (empty($params['level'])) { + $level = 0; + } else { + $level = $params['level']; + } + if (empty($params['tree'])) { + return ''; + } else { + return print_tree_rec($params['tree'], $level); } +} ?> diff --git a/tpl/header.tpl b/tpl/header.tpl index d88e0dc..0e30e12 100644 --- a/tpl/header.tpl +++ b/tpl/header.tpl @@ -6,12 +6,16 @@ +{if isset($styles)} {foreach item=style from=$styles} {/foreach} +{/if} +{if isset($scripts)} {foreach item=script from=$scripts} {/foreach} +{/if}