User Tools

Site Tools


using_api

This is an old revision of the document!


Using API

If you are a .NET programmer, you can easily use a simple API to create your own database backend and billing software. Just create a .NET DLL with a specific name, which exposes a required Class. Evolynx RADIUS server expects to find a Class Library DLL file, named “BusLayer.dll”, in the same directory as “EvolynxRadius.exe” is located. This DLL should expose a Public Class name “Business” which implements the “IBusiness” interface. This interface is defined in the “Common.dll” and is used to make sure that you create a Business class which has all methods required by Evolynx RADIUS.

Business Class
When creating the DLL, you must at least create one class named Business. This Class is the bridge between Evolynx RADIUS and your billing software. Evolynx RADIUS will call specific methods of this Class to exchange information with database. A typical Business Class will look like this:

Imports System
Imports Evolynx.RADIUS.Common
 
Public Class Business
    Implements IBusiness
 
    Public Sub AccountingOther(ByVal Packet As RadiusPacket) Implements IBusiness.AccountingOther
        Throw New NotImplementedException()
    End Sub
 
    Public Sub AccountingStart(ByVal Packet As RadiusPacket) Implements IBusiness.AccountingStart
        Throw New NotImplementedException()
    End Sub
 
    Public Sub AccountingStop(ByVal Packet As RadiusPacket) Implements IBusiness.AccountingStop
        Throw New NotImplementedException()
    End Sub
 
    Public Function Authenticate(ByVal Packet As RadiusPacket) As Integer Implements IBusiness.Authenticate
        Throw New NotImplementedException()
    End Function
 
    Public Function LoadClients() As ClientCollection Implements IBusiness.LoadClients
        Throw New NotImplementedException()
    End Function
 
    Public Sub NotifyByEmail(ByVal State As Object) Implements IBusiness.NotifyByEmail
        Throw New NotImplementedException()
    End Sub
 
    Public Sub OnForwardAccounting(ByVal Packet As RadiusPacket, ByVal TargetIP As String) Implements IBusiness.OnForwardAccounting
        Throw New NotImplementedException()
    End Sub
 
    Public Sub OnForwardRequest(ByVal Packet As RadiusPacket, ByVal TargetIP As String) Implements IBusiness.OnForwardRequest
        Throw New NotImplementedException()
    End Sub
 
    Public Sub OnForwardToNAS(ByVal Packet As RadiusPacket, ByVal TargetIP As String) Implements IBusiness.OnForwardToNAS
        Throw New NotImplementedException()
    End Sub
 
    Public Sub ScheduledMaintenance(ByVal State As Object) Implements IBusiness.ScheduledMaintenance
        Throw New NotImplementedException()
    End Sub
 
    Public Function WriteError(ByVal Message As String, ByVal ErrorID As Long) As Long Implements IBusiness.WriteError
        Throw New NotImplementedException()
    End Function
End Class
using System;
using Evolynx.RADIUS.Common;
 
namespace BusLayer
{
    public class Business : IBusiness
    {
 
        public void AccountingOther(RadiusPacket Packet)
        {
            throw new NotImplementedException();
        }
 
        public void AccountingStart(RadiusPacket Packet)
        {
            throw new NotImplementedException();
        }
 
        public void AccountingStop(RadiusPacket Packet)
        {
            throw new NotImplementedException();
        }
 
        public int Authenticate(RadiusPacket Packet)
        {
            throw new NotImplementedException();
        }
 
        public ClientCollection LoadClients()
        {
            throw new NotImplementedException();
        }
 
        public void NotifyByEmail(object State)
        {
            throw new NotImplementedException();
        }
 
        public void OnForwardAccounting(RadiusPacket Packet, string TargetIP)
        {
            throw new NotImplementedException();
        }
 
        public void OnForwardRequest(RadiusPacket Packet, string TargetIP)
        {
            throw new NotImplementedException();
        }
 
        public void OnForwardToNAS(RadiusPacket Packet, string TargetIP)
        {
            throw new NotImplementedException();
        }
 
        public void ScheduledMaintenance(object State)
        {
            throw new NotImplementedException();
        }
 
        public long WriteError(string Message, long ErrorID)
        {
            throw new NotImplementedException();
        }
 
    }
}

API Details

Step by Step: How to create BusLayer.dll
Now that we know what we need to create, lets see how it should be created. The following steps summarize how you can create the DLL using Visual Studio 2008 and C -:

  1. . Create a new Class Library Project and name it BusLayer
  2. . In Solution Explorer, right click on References and select “Add Reference”
  3. . On Browse tab, select “Evolynx.RADIUS.Common.dll” which is located in Evolynx RADIUS directory, and click ok
  4. . Copy the code from the box above (Depending the language you chose) to your project
  5. . Add code to any of the methods you want
  6. . When you are finished debugging your DLL, Build and copy your bug free DLL to Evolynx RADIUS directory (RADIUS Service should be stopped)

How to debug BusLayer.dll
In order to debug your DLL in Visual Studio .NET environment follow these steps:

  1. . Set the “Output Path” of your DLL project to the Evolynx RADIUS directory
  2. . Make sure EvolynxRADIUS service is stopped
  3. . Build your DLL in Debug mode
  4. . Start the EvolynxRADIUS service
  5. . From Debug menu select Processes
  6. . In the list of available Processes select EvolynxRadius.exe and then Click on Attach button
  7. . On the next window make sure “Common Language Runtime” is selected then click OK
  8. . Close the Processes window
  9. . Use breakpoints to stop execution in any part of your code
  10. . Use a RADIUS client (or Evolynx RADIUS Load Test Tool) to send requests to RADIUS Server and test your DLL

Note:
Set the “Output Path” of your DLL project to the Evolynx RADIUS directory:

  • In Solution Explorer window, right click on project and select Properties
  • From the folders list at the left side select “Configuration Properties/Build”
  • Use the browse button (…) to browse to the Evolynx RADIUS directory
  • Click OK

Sample Code
We have prepared a very simple example with minimum functionality to show how you can use the Evolynx API to create a DLL which authenticates users with a MS-Access database. In order to run this example, you need to re-define the Reference to “Definitions.dll” and set the “Output Path” in Project Properties. The mdb file must be placed in Evolynx RADIUS directory.

API Example (Visual Studio 2008, C - source code)

How to control Evolynx RADIUS Service
Evolynx RADIUS runs as a Windows service. With some .NET programming you can control some of the internal functions of this service. To do this, you need to create a ServiceController object and connect it to Evolynx Service. Then you can start and Stop the service or run a Custom command. The following sample code shows how to Start the service and run a Custom Command:

DIM myService As New ServiceProcess.ServiceController()
myService.MachineName = "server-1"
myService.ServiceName = "EvolynxRADIUS"
myService.Start()
myService.ExecuteCommand(131)

Currently there are 4 custom commands defined. These commands are used to reload settings and information without re-starting the service:

  • 130 = Reloads the settings from Config file or from API
  • 131 = Reloads the Clients from “clients.txt” file or from API
  • 132 = Reloads the Proxy information from “proxy.txt” file
  • 133 = Reloads the Dictionary information from “radius.txt” file
  • 134 = Clears the logs, both RADIUS.LOG and the database log
using_api.1404255255.txt.gz · Last modified: 2023/08/14 06:41 (external edit)