User Tools

Site Tools


using_api

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
using_api [2014/08/22 19:50]
using_api [2023/08/14 06:41] (current)
Line 1: Line 1:
 +=== 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:
 +
 +<code c#>
 +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();​
 +        }
 +
 +        public long WriteError(LogEvent le, long ErrorID)
 +        {
 +            throw new NotImplementedException();​
 +        }
 +    }
 +}
 +</​code>​
 +
 +[[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  -:
 +
 +  -. Create a new Class Library Project and name it BusLayer
 +  -. In Solution Explorer, right click on References and select "Add Reference"​
 +  -. On Browse tab, select "​Evolynx.RADIUS.Common.dll"​ which is located in Evolynx RADIUS directory, and click ok
 +  -. Copy the code from the box above (which is in C#, modify for your target language) to your project
 +  -. Add code to any of the methods you need to implement
 +  -. 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: \\
 +  -. Set the "​Output Path" of your DLL project to the Evolynx RADIUS directory
 +  -. Make sure EvolynxRADIUS service is stopped
 +  -. Build your DLL in Debug mode
 +  -. Start the EvolynxRADIUS service
 +  -. From Debug menu select Processes
 +  -. In the list of available Processes select EvolynxRadius.exe and then Click on Attach button
 +  -. On the next window make sure "​Common Language Runtime"​ is selected then click OK
 +  -. Close the Processes window
 +  -. Use breakpoints to stop execution in any part of your code
 +  -. 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.
 +
 +[[http://​www.evolynx.com/​download/​ApiSample.zip|API Example (Visual Studio 2019, 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:
 +
 +<code vb>
 +DIM myService As New ServiceProcess.ServiceController()
 +myService.MachineName = "​server-1"​
 +myService.ServiceName = "​EvolynxRADIUS"​
 +myService.Start()
 +myService.ExecuteCommand(131)
 +</​code>​
 +
 +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