0 ORDER BY id");
if (!empty($first_auth) and !empty($first_auth['mac'])) {
$new['user_id']=$id;
$new['type']=2;
$new['rule']=$first_auth['mac'];
insert_record($db_link,"auth_rules",$new);
LOG_INFO($db_link,"Создано правило атоназначения юзеру id: ".$id." для мака ".$first_auth['mac']);
}
header("Location: " . $_SERVER["REQUEST_URI"]);
exit;
}
if (isset($_POST["delMacRule"])) {
run_sql($db_link,"DELETE FROM auth_rules WHERE user_id=".$id." AND type=2");
LOG_INFO($db_link,"Удалены все правила атоназначения юзеру id: $id по маку");
header("Location: " . $_SERVER["REQUEST_URI"]);
exit;
}
if (isset($_POST["showDevice"])) {
$device = get_record_sql($db_link,"SELECT * FROM devices WHERE user_id=".$id);
$auth = get_record_sql($db_link,"SELECT * FROM User_auth WHERE user_id=".$id);
if (empty($device) and !empty($auth)) {
$sSQL = "SELECT * FROM User_list WHERE id=$id";
$user_info = get_record_sql($db_link, $sSQL);
global $snmp_default_version;
global $snmp_default_community;
$new['user_id']=$id;
$new['device_name'] = $user_info['login'];
$new['device_type'] = 5;
$new['ip']=$auth['ip'];
$new['community'] = $snmp_default_community;
$new['snmp_version'] = $snmp_default_version;
$new_id=insert_record($db_link, "devices", $new);
unset($_POST);
if (!empty($new_id)) {
LOG_INFO($db_link, "Created device with id: $new_id for auth_id: $id");
header("Location: /admin/devices/editdevice.php?id={$new_id}");
exit;
} else {
header("Location: ".$_SERVER["REQUEST_URI"]);
exit;
}
}
header("Location: /admin/devices/editdevice.php?id=".$device['id']);
exit;
}
if (isset($_POST["addauth"])) {
$fip = substr(trim($_POST["newip"]), 0, 18);
if (isset($_POST["newmac"])) { $fmac = mac_dotted(substr(trim($_POST["newmac"]), 0, 17)); }
if ($fip) {
if (checkValidIp($fip)) {
$ip_aton = ip2long($fip);
//search mac
$mac_exists=find_mac_in_subnet($db_link,$fip,$fmac);
if (isset($mac_exists) and $mac_exists['count']>=1 and !in_array($id,$mac_exists['users_id'])) {
$dup_sql = "SELECT * FROM User_list WHERE id=".$mac_exists['users_id']['0'];
$dup_info = get_record_sql($db_link, $dup_sql);
$msg_error="Mac already exists at another user in this subnet! Skip creating $fip [$fmac].
Old user id: ".$dup_info['id']." login: ".$dup_info['login'];
$_SESSION[$page_url]['msg'] = $msg_error;
LOG_ERROR($db_link, $msg_error);
header("Location: " . $_SERVER["REQUEST_URI"]);
exit;
}
//disable dhcp for secondary ip
$f_dhcp = 1;
if (in_array($id,$mac_exists['users_id'])) { $f_dhcp = 0; }
//search ip
$dup_ip_record = get_record_sql($db_link, "SELECT * FROM User_auth WHERE `ip_int`=$ip_aton AND user_id<>".$id." AND deleted=0");
if (!empty($dup_ip_record)) {
$dup_info = get_record_sql($db_link, "SELECT * FROM User_list WHERE id=".$dup_ip_record['user_id']);
$msg_error = "$fip already exists. Skip creating $fip [$fmac].
Old user id: ".$dup_info['id']." login: ".$dup_info['login'];
$_SESSION[$page_url]['msg'] = $msg_error;
LOG_ERROR($db_link, $msg_error);
header("Location: " . $_SERVER["REQUEST_URI"]);
exit;
}
$fid = new_auth($db_link, $fip, $fmac, $id);
if (!empty($fid)) {
$new['dhcp']=$f_dhcp;
update_record($db_link,"User_auth","id=".$fid,$new);
apply_auth_rule($db_link,$fid,$id);
LOG_WARNING($db_link,"Создан новый адрес доступа: ip => $fip, mac => $fmac",$fid);
header("Location: /admin/users/editauth.php?id=".$fid);
exit;
}
header("Location: " . $_SERVER["REQUEST_URI"]);
exit;
} else {
$msg_error = "$msg_ip_error xxx.xxx.xxx.xxx";
$_SESSION[$page_url]['msg'] = $msg_error;
}
}
header("Location: " . $_SERVER["REQUEST_URI"]);
exit;
}
if (isset($_POST["removeauth"])) {
$auth_id = $_POST["f_auth_id"];
foreach ($auth_id as $key => $val) {
if ($val) {
run_sql($db_link, 'DELETE FROM connections WHERE auth_id='.$val);
run_sql($db_link, 'DELETE FROM User_auth_alias WHERE auth_id='.$val);
$auth["deleted"] = 1;
$changes = get_diff_rec($db_link,"User_auth","id='$val'", '', 0);
if (!empty($changes)) { LOG_WARNING($db_link,"Удалён адрес доступа: \r\n $changes",$val); }
update_record($db_link, "User_auth", "id=" . $val, $auth);
}
}
header("Location: " . $_SERVER["REQUEST_URI"]);
exit;
}
unset($_POST);
$sSQL = "SELECT * FROM User_list WHERE id=$id";
$user_info = get_record_sql($db_link, $sSQL);
require_once ($_SERVER["DOCUMENT_ROOT"]."/inc/header.php");
?>