Skip to content
Nov 6 / Greg

RadiusManager Time Expiration Update Script

RadiusManager by DMASoftlabs is a cheap, easy to use radius front end that will authenticate pppoe, hotspot, whatever accounts. One downside is the support isn’t the greatest. You occasionally have to do some hacking on your own.

The particular fix I made with this script is that if you have date expiration customers(as in they have access for a month at a time), and they add credits before they expire…it does nothing. It doesn’t extend their expiration date…nor does it add credits. It just eats their money. Needless to say, users aren’t happy about it.

So this script is meant to be run once a day around 11:57PM. It will look in the financials for anyone who made a purchase that day, but had 0 days added to their total. It will then take the number of months they purchased, and that to their existing expiration date. It then emails you the list.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "radius";
 
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 
echo "Connected successfully";
 
//days is the number of days the transaction added.  Expiration is the date currently set as expiration.  Amount is the number of months they just purchased.  
$sql = "SELECT username, date, days, expiration, DATE_ADD(expiration, INTERVAL amount * 4 WEEK) as expirationNew, amount, price FROM rm_invoices WHERE days='0' AND date=CURDATE()";
$result = $conn->query($sql);
$message = "";
if ($result->num_rows > 0) {
    // output data of each row if there were 1 or more
    while($row = $result->fetch_assoc()) {
	$sql2 = "UPDATE rm_users set expiration = '" . $row["expirationNew"]. " 00:00:00' WHERE username='" . $row["username"]. "'";//update the users with their new expiration date.
//	echo $sql2;
	if ($conn->query($sql2) === TRUE) {
	    echo "Record updated successfully". "\r\n";
	} else {
	    echo "Error updating record: " . $conn->error. "\r\n";
	}//message to be added to the email.
	$message = $message . "username: " . $row["username"]. " - date: " . $row["date"]. " - days: " . $row["days"]. " - Original expiration: " . $row["expiration"]. " - New expiration: " . $row["expirationNew"]. " - amount: " . $row["amount"]. " - price: " . $row["price"]. "\r\n";
 
       echo "username: " . $row["username"]. " - date: " . $row["date"]. " - days: " . $row["days"]. " - expiration: " . $row["expiration"]. " - expirationNew: " . $row["expirationNew"]. " - amount: " . $row["amount"]. " - price: " . $row["price"]. "\r\n";
    }
    $eSubject = "Radius Expire Update - " . $result->num_rows;
} else {
    echo "0 results". "\r\n";
    $eSubject = "Radius Expire Update - 0";
}
$headers = 'From: [email protected]';//setup from address
mail('[email protected]', $eSubject, $message, $headers);//send the email
 
$conn->close();
 
?>

One Comment

leave a comment
  1. Zenon / Mar 31 2015

    Thanks for the radius script.. saving it as I plan to use DMA soon.

Leave a Comment

 

*