You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
GeekQu_sspanel/app/Utils/Radius.php

134 lines
4.0 KiB
PHTML

9 years ago
<?php
namespace App\Utils;
use App\Models\User;
use App\Models\RadiusRadCheck;
use App\Models\RadiusRadUserGroup;
use App\Models\RadiusNas;
use App\Models\RadiusBan;
use App\Services\Config;
class Radius
{
/**
* 添加或者更新密码信息
*/
public static function Add($user, $pwd)
{
8 years ago
if (Config::get('enable_radius') == 'true') {
$email = $user->email;
8 years ago
$email = str_replace(array('@', '.'), '', $email);
9 years ago
8 years ago
$exists = RadiusRadCheck::where('username', $email)->first();
9 years ago
8 years ago
if ($exists == null) {
9 years ago
$rb = RadiusBan::where('userid', $user->id)->first();
if ($rb != null) {
return;
}
8 years ago
$newRad = new RadiusRadCheck();
$newRad->username = $email;
8 years ago
$newRad->attribute = 'Cleartext-Password';
$newRad->op = ':=';
8 years ago
$newRad->value = $pwd;
9 years ago
$newRad->save();
8 years ago
$newRad = new RadiusRadUserGroup();
$newRad->username = $email;
8 years ago
$newRad->groupname = 'user';
$newRad->priority = '0';
9 years ago
$newRad->save();
} else {
8 years ago
$exists->value = $pwd;
9 years ago
$exists->save();
}
}
}
public static function Delete($email)
{
8 years ago
if (Config::get('enable_radius') == 'true') {
8 years ago
$email = str_replace(array('@', '.'), '', $email);
9 years ago
8 years ago
$exists = RadiusRadCheck::where('username', $email)->first();
9 years ago
8 years ago
if ($exists != null) {
8 years ago
RadiusRadCheck::where('username', $email)->delete();
RadiusRadUserGroup::where('username', $email)->delete();
9 years ago
}
}
}
public static function ChangeUserName($origin_email, $new_email, $passwd)
{
8 years ago
if (Config::get('enable_radius') == 'true') {
8 years ago
$email1 = str_replace(array('@', '.'), '', $origin_email);
$email2 = str_replace(array('@', '.'), '', $new_email);
9 years ago
8 years ago
$exists = RadiusRadCheck::where('username', $email1)->first();
9 years ago
8 years ago
if ($exists != null) {
$exists->username = $email2;
$exists->value = $passwd;
9 years ago
$exists->save();
8 years ago
$exists = RadiusRadUserGroup::where('username', $email1)->first();
8 years ago
$exists->username = $email2;
9 years ago
$exists->save();
} else {
$user = User::where('email', '=', $origin_email)->first();
$rb = RadiusBan::where('userid', $user->id)->first();
if ($rb != null) {
return;
}
8 years ago
$newRad = new RadiusRadCheck();
$newRad->username = $email2;
8 years ago
$newRad->attribute = 'Cleartext-Password';
$newRad->op = ':=';
8 years ago
$newRad->value = $passwd;
9 years ago
$newRad->save();
8 years ago
$newRad = new RadiusRadUserGroup();
$newRad->username = $email2;
8 years ago
$newRad->groupname = 'user';
$newRad->priority = '0';
9 years ago
$newRad->save();
}
}
}
public static function AddNas($ip, $name)
{
8 years ago
if (Config::get('enable_radius') == 'true') {
8 years ago
$exists = RadiusNas::where('shortname', $ip)->first();
8 years ago
if ($exists == null) {
$exists = new RadiusNas();
$exists->nasname = $ip;
$exists->shortname = $ip;
8 years ago
$exists->type = 'other';
8 years ago
$exists->secret = Config::get('radius_secret');
$exists->description = $ip;
9 years ago
$exists->save();
}
}
}
public static function DelNas($ip)
{
8 years ago
if (Config::get('enable_radius') == 'true') {
8 years ago
RadiusNas::where('shortname', $ip)->delete();
9 years ago
}
}
public static function GetUserName($email)
{
8 years ago
return str_replace(array('@', '.'), '', $email);
9 years ago
}
}