parent
c500face92
commit
be9610cd98
@ -1,170 +1,157 @@ |
|||||||
<?php |
<?php |
||||||
/***************************************************************************** |
/***************************************************************************** |
||||||
IP Reg, a PHP/MySQL IPAM tool |
IP Reg, a PHP/MySQL IPAM tool |
||||||
Copyright (C) 2007-2009 Wietse Warendorff |
Copyright (C) 2007-2009 Wietse Warendorff (up to v0.5) |
||||||
|
Copyright (C) 2011-2023 Thomas Hooge |
||||||
This program is free software: you can redistribute it and/or modify |
|
||||||
it under the terms of the GNU General Public License as published by |
SPDX-License-Identifier: GPL-3.0-or-later |
||||||
the Free Software Foundation, either version 3 of the License, or |
*****************************************************************************/ |
||||||
(at your option) any later version. |
|
||||||
|
// strip mac address to 12 char string |
||||||
This program is distributed in the hope that it will be useful, |
function strip_mac($mac) { |
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
// strip chars we don't need |
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
$mac = preg_replace("|[^a-fA-F0-9]|", "", $mac); |
||||||
GNU General Public License for more details. |
|
||||||
|
// capitalize (just because it looks better eh) |
||||||
You should have received a copy of the GNU General Public License |
$mac = strtoupper($mac); |
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
||||||
|
// and return |
||||||
For more information, visit http://sourceforge.net/projects/ipreg, |
return ($mac); |
||||||
or contact me at wietsew@users.sourceforge.net |
} |
||||||
*****************************************************************************/ |
|
||||||
|
// 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 |
// get user preference |
||||||
function strip_mac($mac) { |
$user_mac = $_SESSION['suser_mac']; |
||||||
// strip chars we don't need |
|
||||||
$mac = preg_replace("|[^a-fA-F0-9]|", "", $mac); |
|
||||||
|
|
||||||
// capitalize (just because it looks better eh) |
// count to 12 again... |
||||||
$mac = strtoupper($mac); |
for($i=0; $i<12; $i++) { |
||||||
|
// ... and replace user preference with pieces |
||||||
|
$user_mac = preg_replace("/x/", ${"mac".$i}, $user_mac, 1); |
||||||
|
} |
||||||
|
|
||||||
// and return |
// and return |
||||||
return ($mac); |
return $user_mac; |
||||||
} |
} |
||||||
|
} |
||||||
|
|
||||||
// rebuild mac address |
// redirect page |
||||||
function write_mac($mac) { |
function header_location($location) { |
||||||
// check string length |
// send header |
||||||
if (strlen($mac)!=12) { |
header("location: " . $location); |
||||||
// 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}; |
|
||||||
} |
|
||||||
|
|
||||||
// get user preference |
// exit to be sure |
||||||
$user_mac = $_SESSION['suser_mac']; |
exit; |
||||||
|
} |
||||||
|
|
||||||
// count to 12 again... |
// sanitize input |
||||||
for($i=0;$i<12;$i++) { |
function sanitize($input) { |
||||||
// ... and replace user preference with pieces |
global $dblink; |
||||||
$user_mac = preg_replace("/x/", ${"mac".$i}, $user_mac, 1); |
|
||||||
} |
|
||||||
|
|
||||||
// and return |
// trim whitespaces |
||||||
return $user_mac; |
$input = @trim($input); |
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
// redirect page |
// magic quotes enabled? |
||||||
function header_location($location) { |
if(get_magic_quotes_gpc()) { |
||||||
// send header |
// strip slashes |
||||||
header("location: " . $location); |
$input = stripslashes($input); |
||||||
|
|
||||||
// exit to be sure |
|
||||||
exit; |
|
||||||
} |
} |
||||||
|
|
||||||
// sanitize input |
// convert to utf-8 |
||||||
function sanitize($input) { |
iconv("UTF-8", "UTF-8", $input); |
||||||
global $dblink; |
|
||||||
|
|
||||||
// trim whitespaces |
|
||||||
$input = @trim($input); |
|
||||||
|
|
||||||
// magic quotes enabled? |
// convert special chars |
||||||
if(get_magic_quotes_gpc()) { |
$input = htmlentities($input,ENT_QUOTES,'UTF-8'); |
||||||
// strip slashes |
|
||||||
$input = stripslashes($input); |
|
||||||
} |
|
||||||
|
|
||||||
// convert to utf-8 |
|
||||||
iconv("UTF-8", "UTF-8", $input); |
|
||||||
|
|
||||||
// convert special chars |
// make sql ready |
||||||
$input = htmlentities($input,ENT_QUOTES,'UTF-8'); |
$input = mysqli_real_escape_string($dblink, $input); |
||||||
|
|
||||||
// make sql ready |
// and return |
||||||
$input = mysqli_real_escape_string($dblink, $input); |
return $input; |
||||||
|
} |
||||||
|
|
||||||
// and return |
function mysql_nullstring($input) { |
||||||
|
if (isset($input)) { |
||||||
return $input; |
return $input; |
||||||
|
} else { |
||||||
|
return ''; |
||||||
} |
} |
||||||
|
} |
||||||
|
|
||||||
function mysql_nullstring($input) { |
function lang_getfrombrowser ($allowed_languages, $default_language, $lang_variable = null, $strict_mode = true) { |
||||||
if (isset($input)) { |
if ($lang_variable === null) { |
||||||
return $input; |
$lang_variable = $_SERVER['HTTP_ACCEPT_LANGUAGE']; |
||||||
} else { |
|
||||||
return ''; |
|
||||||
} |
|
||||||
} |
} |
||||||
|
if (empty($lang_variable)) { |
||||||
function lang_getfrombrowser ($allowed_languages, $default_language, $lang_variable = null, $strict_mode = true) { |
return $default_language; |
||||||
if ($lang_variable === null) { |
} |
||||||
$lang_variable = $_SERVER['HTTP_ACCEPT_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)) { |
$lang_code = explode ('-', $matches[1]); |
||||||
return $default_language; |
if (isset($matches[2])) { |
||||||
|
$lang_quality = (float)$matches[2]; |
||||||
|
} else { |
||||||
|
$lang_quality = 1.0; |
||||||
} |
} |
||||||
$accepted_languages = preg_split('/,\s*/', $lang_variable); |
while (count ($lang_code)) { |
||||||
$current_lang = $default_language; |
if (in_array (strtolower (join ('-', $lang_code)), $allowed_languages)) { |
||||||
$current_q = 0; |
if ($lang_quality > $current_q) { |
||||||
foreach ($accepted_languages as $accepted_language) { |
$current_lang = strtolower (join ('-', $lang_code)); |
||||||
$res = preg_match ('/^([a-z]{1,8}(?:-[a-z]{1,8})*)(?:;\s*q=(0(?:\.[0-9]{1,3})?|1(?:\.0{1,3})?))?$/i', |
$current_q = $lang_quality; |
||||||
$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; |
break; |
||||||
} |
} |
||||||
array_pop ($lang_code); |
|
||||||
} |
} |
||||||
} |
if ($strict_mode) { |
||||||
return $current_lang; |
break; |
||||||
} |
|
||||||
|
|
||||||
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['children']) { |
|
||||||
$output .= "\n" . print_tree_rec($node['children'], $level+1); |
|
||||||
} |
} |
||||||
$output .= "</li>\n"; |
array_pop ($lang_code); |
||||||
} |
} |
||||||
$output .= "</ul>\n"; |
|
||||||
return $output; |
|
||||||
} |
} |
||||||
|
return $current_lang; |
||||||
function print_tree ($params, &$smarty) { |
} |
||||||
if (empty($params['level'])) { |
|
||||||
$level = 0; |
function print_tree_rec($tree, $level) { |
||||||
} else { |
$output = '<ul class="treelvl' . $level. '">' . "\n"; |
||||||
$level = $params['level']; |
foreach ($tree as $node) { |
||||||
} |
$output .= '<li><a href="' . $node['href'] . '">' . $node['value'] . '</a>'; |
||||||
if (empty($params['tree'])) { |
if ($node['children']) { |
||||||
return ''; |
$output .= "\n" . print_tree_rec($node['children'], $level+1); |
||||||
} else { |
|
||||||
return print_tree_rec($params['tree'], $level); |
|
||||||
} |
} |
||||||
|
$output .= "</li>\n"; |
||||||
|
} |
||||||
|
$output .= "</ul>\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); |
||||||
} |
} |
||||||
|
} |
||||||
|
|
||||||
?> |
?> |
||||||
|
Reference in new issue