Skip to content

Commit

Permalink
Validate A MAC Address and strip separator (#164)
Browse files Browse the repository at this point in the history
Validate A MAC Address and strip separator
  • Loading branch information
dcec authored May 11, 2020
1 parent bfd9132 commit 909ec0a
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions mng-new.php
Original file line number Diff line number Diff line change
Expand Up @@ -460,20 +460,27 @@ function addAttributes($dbSocket, $username) {
}

} elseif ($authType == "macAuth") {

// insert username/password
$sql = "INSERT INTO ".$configValues['CONFIG_DB_TBL_RADCHECK']." (id,Username,Attribute,op,Value) ".

$macaddress = preg_replace("/:|\.|\-/", "", trim($macaddress));

if (preg_match('/[a-fA-F0-9]/', $macaddress) == 1 && strlen($macaddress) == 12){
// insert username/password
$sql = "INSERT INTO ".$configValues['CONFIG_DB_TBL_RADCHECK']." (id,Username,Attribute,op,Value) ".
" VALUES (0, '".$dbSocket->escapeSimple($macaddress)."', 'Auth-Type', ':=', 'Accept')";
$res = $dbSocket->query($sql);
$logDebugSQL .= $sql . "\n";
$res = $dbSocket->query($sql);
$logDebugSQL .= $sql . "\n";

addGroups($dbSocket, $macaddress, $group_macaddress);
addUserInfo($dbSocket, $macaddress);
addUserBillInfo($dbSocket, $username);
addAttributes($dbSocket, $macaddress);

$successMsg = "Added to database new mac auth user: <b> $macaddress </b>";
$logAction .= "Successfully added new mac auth user [$macaddress] on page: ";
addGroups($dbSocket, $macaddress, $group_macaddress);
addUserInfo($dbSocket, $macaddress);
addUserBillInfo($dbSocket, $username);
addAttributes($dbSocket, $macaddress);

$successMsg = "Added to database new mac auth user: <b> $macaddress </b>";
$logAction .= "Successfully added new mac auth user [$macaddress] on page: ";
} else {
$failureMsg = "Invalid Mac address format: <b> $username </b>";
$logAction .= "Failed adding new user invalid mac address format [$username] on page: ";
}

} elseif ($authType == "pincodeAuth") {

Expand Down

0 comments on commit 909ec0a

Please sign in to comment.