ictsolutions/codeigniter-freeradius 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ictsolutions/codeigniter-freeradius

Composer 安装命令:

composer require ictsolutions/codeigniter-freeradius

包简介

CodeIgniter4 FreeRadius wrapper library.

README 文档

README

The CodeIgniter FreeRADIUS library provides a suite of tools designed to manage and interact with a FreeRADIUS server through the CodeIgniter framework. It offers functionality for database handling, configuring FreeRADIUS tables, manipulating username realms and characteristics, modifying PPPoE group settings, and managing IP ranges for Carrier-Grade NAT (CGNAT). This library significantly simplifies the process of working with a FreeRADIUS server by offering pre-defined and easily configurable settings.

Moreover, its seamless integration with the CodeIgniter framework makes it an exemplary toolset for developers requiring remote authentication and accounting in their PHP applications. This allows developers to focus more on their application's core features, assured in the knowledge that their FreeRADIUS server interaction is handled proficiently by this library.

PHP CodeIgniter

Installation

Installation is done through Composer.

composer require ictsolutions/codeigniter-freeradius

Configuration

Tables: The FreeRADIUS tables are named as radacct, radcheck, radgroupcheck, radgroupreply, radreply, radusergroup, radpostauth, nas, nasreload, and userinfo. These are typically created when installing and configuring a FreeRADIUS server and are used to manage RADIUS accounts, user groups, authentication, and servers.

usernameRealm: The realm that's used to construct usernames is set to null by default, meaning that there's no realm added to the username.

usernameCharacters & usernameLength: Usernames are generated using the characters '0-9' and 'A-Z' and they have a length of 6 characters.

passwordCharacters & passwordLength: Passwords are generated using the characters '0-9' and 'A-Z' and they have a length of 12 characters.

pppoeGroupName & pppoeGroupPriority: The default Point-to-Point Protocol over Ethernet (PPPoE) group name is 'PPPoE' and it has a priority of 0.

ipStart & ipEnd: The IP address range for Carrier-Grade NAT (CGNAT) starts from '100.64.0.0' to '100.64.63.255'.

Enumerations

Attribute Enumeration

The Attribute enumeration consists of the following Enums, representing different RADIUS protocol attributes that can be used within this CodeIgniter FreeRADIUS Library:

namespace IctSolutions\CodeIgniterFreeRadius\Enums;

enum Attribute: string
{
    case CleartextPassword = 'Cleartext-Password';
    case FallThrough = 'Fall-Through';
    case SimultaneousUse = 'Simultaneous-Use';
    case ServiceType = 'Service-Type';
    case FramedIPAddress = 'Framed-IP-Address';
    case FramedIPNetmask = 'Framed-IP-Netmask';
    case FramedProtocol = 'Framed-Protocol';
    case FramedMTU = 'Framed-MTU';
    case CiscoAVPair = 'Cisco-AVPair';
    case CiscoNASPort = 'Cisco-NAS-Port';
    case CiscoFramedRoute = 'Cisco-Framed-Route';
}

Each Enum accompanies a comment, describing its purpose or function in the RADIUS protocol.

Operator Enumeration

The Operator enumeration consists of different operators that can be applied to the CodeIgniter FreeRADIUS Library attributes:

namespace IctSolutions\CodeIgniterFreeRadius\Enums;

enum Operator: string
{
    case Equals = '=';
    case Assign = ':=';
    case Check = '==';
    case Add = '+=';
    case NotEquals = '!=';
    case Greater = '>';
    case GreaterEquals = '>=';
    case Less = '<';
    case LessEquals = '<=';
    case Matches = '=~';
    case NotMatches = '!~';
    case Exists = '=*';
    case NotExists = '!*';
}

Each Enum is annotated with a comment, providing additional insights into the use of operators with attributes in RADIUS protocol.

Usage

Initialization

Instantiate your FreeRADIUS library using the provided services class. The CodeIgniter's service class provides a unified and direct way to access the library.

$freeRadiusLibrary = \IctSolutions\CodeIgniterFreeRadius\Config\Services::freeradius();

Bind A User

For example, if you want to bind a user with an attribute 'FramedIPAddress' in the RADIUS server:

use IctSolutions\CodeIgniterFreeRadius\Enums\Operator;
use IctSolutions\CodeIgniterFreeRadius\Enums\Attribute;

// ... ...

$attributeValue = '192.0.2.1'; // Provided framed IP address for the user
$freeRadiusLibrary->bindUser(Attribute::FramedIPAddress, Operator::Equals, $attributeValue);

This will bind the user to the provided IP address using the RADIUS protocol attribute for framed IP.

Check User's Binding

You can also check the user's binding status:

$status = $freeRadiusLibrary->checkUserBinding(Attribute::FramedIPAddress, $attributeValue);

This method will check if the user has the 'Framed-IPAddress' correctly bound with the provided value.

Other Features

There are other features that allow you to work with FreeRADIUS server's advanced configurations. Set fall-through behavior, allow simultaneous logins, set service type, and other configurations via a simple syntax:

$config = [
    Attribute::FallThrough => ['operator' => Operator::NotEquals, 'value' => 'YES'],
    Attribute::SimultaneousUse => ['operator' => Operator::LessEquals, 'value' => 1],
    Attribute::ServiceType => ['operator' => Operator::Equals, 'value' => 'Framed-User'],
];

$freeRadiusLibrary->applyConfigs($config);

This will configure the FreeRADIUS server to not allow fall-through, limit simultaneous logins to one, and set the service type to 'Framed-User'.

Please note that for actual deployment, all attribute value, operator, user details etc. should be carefully managed and sanitized.

Example: Creating a CodeIgniter Project with FreeRADIUS

Step 1: Create New CodeIgniter Project

Start by creating a new CodeIgniter project if you haven't already. You can initiate a project using Composer:

composer create-project codeigniter4/appstarter myProject

Navigate to the newly created project:

cd myProject

Step 2: Install CodeIgniter FreeRADIUS library

Add the FreeRADIUS library to your project:

composer require ictsolutions/codeigniter-freeradius

Step 3: Run the Migration

Now you can run your migration. This will create the necessary tables in your database for the FreeRADIUS to work:

php spark migrate

Check your database to verify that the tables were created.

Step 5: Using the Library in Your Code

After the setup, you can utilize the FreeRadius library in the CodeIgniter project. For example, in your controller:

use IctSolutions\CodeIgniterFreeRadius\Enums\Attribute;
use IctSolutions\CodeIgniterFreeRadius\Enums\Operator;

public function index(){
    $freeRadius = \IctSolutions\CodeIgniterFreeRadius\Config\Services::freeradius();

    // Let's bind a user 'john' with a Cleartext-Password
    $freeRadius->bindUser('john', Attribute::CleartextPassword, Operator::Equals, 'JohnsPassword123');
}

Please, ensure you replace 'JohnsPassword123' with a safe and hashed version of the password in a real-life scenario.

License

This project is licensed under the MIT License - see the LICENSE file for details.

ictsolutions/codeigniter-freeradius 适用场景与选型建议

ictsolutions/codeigniter-freeradius 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 13.78k 次下载、GitHub Stars 达 5, 最近一次更新时间为 2024 年 03 月 14 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「codeigniter」 「freeradius」 「codeigniter4」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 ictsolutions/codeigniter-freeradius 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 ictsolutions/codeigniter-freeradius 我们能提供哪些服务?
定制开发 / 二次开发

基于 ictsolutions/codeigniter-freeradius 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 13.78k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 15
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 5
  • Watchers: 0
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-03-14