{"id":5058,"date":"2014-11-06T15:03:08","date_gmt":"2014-11-06T21:03:08","guid":{"rendered":"http:\/\/gregsowell.com\/?p=5058"},"modified":"2014-11-06T15:03:08","modified_gmt":"2014-11-06T21:03:08","slug":"radiusmanager-time-expiration-update-script","status":"publish","type":"post","link":"https:\/\/gregsowell.com\/?p=5058","title":{"rendered":"RadiusManager Time Expiration Update Script"},"content":{"rendered":"<p>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&#8217;t the greatest.  You occasionally have to do some hacking on your own.<\/p>\n<p>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&#8230;it does nothing.  It doesn&#8217;t extend their expiration date&#8230;nor does it add credits.  It just eats their money.  Needless to say, users aren&#8217;t happy about it.<\/p>\n<p>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.<\/p>\n<pre class=\"gs-code\"><code class=\"language-plaintext\">&lt;?php\r\n$servername = &quot;localhost&quot;;\r\n$username = &quot;username&quot;;\r\n$password = &quot;password&quot;;\r\n$dbname = &quot;radius&quot;;\r\n\r\n\/\/ Create connection\r\n$conn = new mysqli($servername, $username, $password, $dbname);\r\n\/\/ Check connection\r\nif ($conn-&gt;connect_error) {\r\n    die(&quot;Connection failed: &quot; . $conn-&gt;connect_error);\r\n} \r\necho &quot;Connected successfully&quot;;\r\n\r\n\/\/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.  \r\n$sql = &quot;SELECT username, date, days, expiration, DATE_ADD(expiration, INTERVAL amount * 4 WEEK) as expirationNew, amount, price FROM rm_invoices WHERE days=&#039;0&#039; AND date=CURDATE()&quot;;\r\n$result = $conn-&gt;query($sql);\r\n$message = &quot;&quot;;\r\nif ($result-&gt;num_rows &gt; 0) {\r\n    \/\/ output data of each row if there were 1 or more\r\n    while($row = $result-&gt;fetch_assoc()) {\r\n\t$sql2 = &quot;UPDATE rm_users set expiration = &#039;&quot; . $row[&quot;expirationNew&quot;]. &quot; 00:00:00&#039; WHERE username=&#039;&quot; . $row[&quot;username&quot;]. &quot;&#039;&quot;;\/\/update the users with their new expiration date.\r\n\/\/\techo $sql2;\r\n\tif ($conn-&gt;query($sql2) === TRUE) {\r\n\t    echo &quot;Record updated successfully&quot;. &quot;\\r\\n&quot;;\r\n\t} else {\r\n\t    echo &quot;Error updating record: &quot; . $conn-&gt;error. &quot;\\r\\n&quot;;\r\n\t}\/\/message to be added to the email.\r\n\t$message = $message . &quot;username: &quot; . $row[&quot;username&quot;]. &quot; - date: &quot; . $row[&quot;date&quot;]. &quot; - days: &quot; . $row[&quot;days&quot;]. &quot; - Original expiration: &quot; . $row[&quot;expiration&quot;]. &quot; - New expiration: &quot; . $row[&quot;expirationNew&quot;]. &quot; - amount: &quot; . $row[&quot;amount&quot;]. &quot; - price: &quot; . $row[&quot;price&quot;]. &quot;\\r\\n&quot;;\r\n\r\n       echo &quot;username: &quot; . $row[&quot;username&quot;]. &quot; - date: &quot; . $row[&quot;date&quot;]. &quot; - days: &quot; . $row[&quot;days&quot;]. &quot; - expiration: &quot; . $row[&quot;expiration&quot;]. &quot; - expirationNew: &quot; . $row[&quot;expirationNew&quot;]. &quot; - amount: &quot; . $row[&quot;amount&quot;]. &quot; - price: &quot; . $row[&quot;price&quot;]. &quot;\\r\\n&quot;;\r\n    }\r\n    $eSubject = &quot;Radius Expire Update - &quot; . $result-&gt;num_rows;\r\n} else {\r\n    echo &quot;0 results&quot;. &quot;\\r\\n&quot;;\r\n    $eSubject = &quot;Radius Expire Update - 0&quot;;\r\n}\r\n$headers = &#039;From: radius@myserver.com&#039;;\/\/setup from address\r\nmail(&#039;whoever@gregsowell.com&#039;, $eSubject, $message, $headers);\/\/send the email\r\n\r\n$conn-&gt;close();\r\n\r\n?&gt;<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>RadiusManager by DMASoftlabs is a cheap, easy to use radius front end that will authenticate pppoe, hotspot, whatever accounts. One downside is the support\u2026<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14,29,13],"tags":[],"class_list":["post-5058","post","type-post","status-publish","format-standard","hentry","category-linux","category-mysql","category-server"],"_links":{"self":[{"href":"https:\/\/gregsowell.com\/index.php?rest_route=\/wp\/v2\/posts\/5058","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gregsowell.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gregsowell.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gregsowell.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/gregsowell.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5058"}],"version-history":[{"count":3,"href":"https:\/\/gregsowell.com\/index.php?rest_route=\/wp\/v2\/posts\/5058\/revisions"}],"predecessor-version":[{"id":5080,"href":"https:\/\/gregsowell.com\/index.php?rest_route=\/wp\/v2\/posts\/5058\/revisions\/5080"}],"wp:attachment":[{"href":"https:\/\/gregsowell.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5058"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gregsowell.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5058"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gregsowell.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5058"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}