return false if profile name is invalid, fixed regular expressions for profile names

This commit is contained in:
uid108615 2003-10-23 19:31:17 +00:00
parent 40aa825088
commit c72729730c
2 changed files with 22 additions and 11 deletions

View File

@ -86,7 +86,7 @@ function getHostProfiles() {
// $profile: name of the profile (without .pru)
// the return value is an account object
function loadUserProfile($profile) {
if (!eregi("^([0-9]|[a-z]|-|_)*$", $profile)) exit;
if (!eregi("^[0-9a-z_\\-]+$", $profile)) return false;
$acc = new account();
$file = substr(__FILE__, 0, strlen(__FILE__) - 17) . "/config/profiles/users/" . $profile . ".pru";
if (is_file($file) == True) {
@ -262,7 +262,7 @@ function loadUserProfile($profile) {
// $profile: name of the group profile (without .prg)
// the return value is an account object
function loadGroupProfile($profile) {
if (!eregi("^([0-9]|[a-z]|-|_)*$", $profile)) exit;
if (!eregi("^[0-9a-z_\\-]+$", $profile)) return false;
$acc = new account();
$file = substr(__FILE__, 0, strlen(__FILE__) - 17) . "/config/profiles/groups/" . $profile . ".prg";
if (is_file($file) == True) {
@ -329,7 +329,7 @@ function loadGroupProfile($profile) {
// $profile: name of the host profile (without .prh)
// the return value is an account object
function loadHostProfile($profile) {
if (!eregi("^([0-9]|[a-z]|-|_)*$", $profile)) exit;
if (!eregi("^[0-9a-z_\\-]+$", $profile)) return false;
$acc = new account();
$file = substr(__FILE__, 0, strlen(__FILE__) - 17) . "/config/profiles/hosts/" . $profile . ".prh";
if (is_file($file) == True) {
@ -386,7 +386,8 @@ function loadHostProfile($profile) {
// $profile: name of the user profile (without .pru)
// $account: account object which is saved
function saveUserProfile($account, $profile) {
if (!eregi("^([0-9]|[a-z]|-|_)*$", $profile)) exit;
// check profile name
if (!eregi("^[0-9a-z_\\-]+$", $profile)) return false;
if (!is_object($account)) {
StatusMessage("ERROR", "", _("saveUserProfile: account has wrong type!"));
exit;
@ -457,7 +458,8 @@ function saveUserProfile($account, $profile) {
// $profile: name of the group profile (without .prg)
// $account: account object which is saved
function saveGroupProfile($account, $profile) {
if (!eregi("^([0-9]|[a-z]|-|_)*$", $profile)) exit;
// check profile name
if (!eregi("^[0-9a-z_\\-]+$", $profile)) return false;
if (!is_object($account)) {
StatusMessage("ERROR", "", _("saveGroupProfile: account has wrong type!"));
exit;
@ -490,7 +492,8 @@ function saveGroupProfile($account, $profile) {
// $profile: name of the host profile (without .prh)
// $account: account object which is saved
function saveHostProfile($account, $profile) {
if (!eregi("^[0-9a-z\\-_]+$", $profile)) exit;
// check profile name
if (!eregi("^[0-9a-z_\\-]+$", $profile)) return false;
if (!is_object($account)) {
StatusMessage ("ERROR", "", _("saveHostProfile: account has wrong type!"));
exit;
@ -513,7 +516,7 @@ function saveHostProfile($account, $profile) {
// deletes a user profile
function delUserProfile($file) {
if (!eregi("^([0-9]|[a-z]|-|_)*$", $profile)) exit;
if (!eregi("^[0-9a-z_\\-]+$", $profile)) exit;
$prof = substr(__FILE__, 0, strlen(__FILE__) - 16) . "config/profiles/users/".$file.".pru";
if (is_file($prof)) {
return @unlink($prof);
@ -522,7 +525,7 @@ function delUserProfile($file) {
// deletes a group profile
function delGroupProfile($file) {
if (!eregi("^([0-9]|[a-z]|-|_)*$", $profile)) exit;
if (!eregi("^[0-9a-z_\\-]+$", $profile)) exit;
$prof = substr(__FILE__, 0, strlen(__FILE__) - 16) . "config/profiles/groups/".$file.".prg";
if (is_file($prof)) {
return @unlink($prof);
@ -531,7 +534,7 @@ function delGroupProfile($file) {
// deletes a host profile
function delHostProfile($file) {
if (!eregi("^([0-9]|[a-z]|-|_)*$", $profile)) exit;
if (!eregi("^[0-9a-z_\\-]+$", $profile)) exit;
$prof = substr(__FILE__, 0, strlen(__FILE__) - 16) . "config/profiles/hosts/".$file.".prh";
if (is_file($prof)) {
return @unlink($prof);

View File

@ -271,7 +271,7 @@ if ($_GET['type'] == "user") {
}
}
if ($_POST['profname'] && eregi("^[0-9a-z\\-_]+$", $_POST['profname'])) {
if ($_POST['profname'] && eregi("^[0-9a-z_\\-]+$", $_POST['profname'])) {
$profname = $_POST['profname'];
}
else {
@ -336,7 +336,7 @@ elseif ($_GET['type'] == "group") {
}
}
if ($_POST['profname'] && eregi("^[0-9a-z\\-_]+$", $_POST['profname'])) {
if ($_POST['profname'] && eregi("^[0-9a-z_\\-]+$", $_POST['profname'])) {
$profname = $_POST['profname'];
}
else {
@ -375,6 +375,14 @@ elseif ($_GET['type'] == "host") {
echo ("<br><br><a href=\"javascript:history.back()\">" . _("Back to Profile Editor") . "</a>");
exit;
}
if ($_POST['profname'] && eregi("^[0-9a-z_\\-]+$", $_POST['profname'])) {
$profname = $_POST['profname'];
}
else {
StatusMessage("ERROR", _("Invalid profile name!"), $_POST['profname']);
echo ("<br><br><a href=\"javascript:history.back()\">" . _("Back to Profile Editor") . "</a>");
exit;
}
// save profile
if (saveHostProfile($acct, $profname)) {
echo StatusMessage("INFO", _("Profile was saved."), $profname);