Automatic disconnection of users in ISPManager5 lite without BILLmanager

Given:



  1. VPS Server with ispmanager lite 5 perpetual license
  2. 10-20 users on the server
  3. Google Calendar with regular reminders who has run out of hosting
  4. The choking toad pay for anything else, especially on a subscription


The goal is to get rid of the google calendar and manual reminders to the client that he needs to pay for hosting. To rid yourself of β€œlet him work a little more, he will soon pay” β€œas it is not convenient to turn it off,” and entrust it to a soulless machine.



Of course, at first I searched for it, but did not find solutions, it all came down to the fact that you need to take a BILLmanager subscription, but I have item number 4 very important and serious, I will not get rid of it. And the decision turned out to be not so difficult.



So what do we do.



Create the users.addon folder, in the / usr / local / mgr5 / etc / sql / directory, two empty files:



  1. pay_date
  2. uwemail


This will give the panel command to create two corresponding fields in the

/usr/local/mgr5/etc/ispmgr.db database

in the users table where the values ​​from the admin panel will be written.



Create a file ispmgr_mod_pay_data.xml in the / usr / local / mgr5 / etc / xml folder with the contents



<?xml version="1.0" encoding="UTF-8"?>
<mgrdata>
	<metadata name="user.edit">
		<form>
			<page name="main">
				<field name="pay_date">
					<input type="text" name="pay_date"/>
				</field>
				<field name="uwemail">
					<input type="text" name="uwemail"/>
				</field>
			</page>
		</form>
	</metadata>
	<lang name="ru">
		<messages name="user.edit">
			<msg name="pay_date" sqlname="pay_date"> </msg>
			<msg name="uwemail" sqlname="uwemail"> email</msg>
		</messages>
	</lang>	
	<lang name="en">
		<messages name="user.edit">
			<msg name="pay_date" sqlname="pay_date">Paid before</msg>
			<msg name="uwemail" sqlname="uwemail">User email</msg>
		</messages>
	</lang>
</mgrdata>


This gives the panel rule that our fields are displayed in the user edit form.



Reload the panel:



/usr/local/mgr5/sbin/mgrctl -m ispmgr exit


We receive:



image



In the fields we write up to what day the hosting should work, and which email of the user, where to send reminders that the hosting will end soon.



Now you need to create a script that will remind users that hosting ends with a certain frequency. Notify the admin that hosting is about to end. Notify user and admin that the user is disabled.



I am close to php on it and wrote a script.



<?php
$adminemail = "admin@gmail.com"; // email 
$day_send_message = [30,7,5,3,1]; //             
$db = new SQLite3('/usr/local/mgr5/etc/ispmgr.db');
$results = $db->query('SELECT * FROM users WHERE active == "on" AND pay_date IS NOT NULL');
while ($user = $results->fetchArray()) {
		$days_left=floor( ( strtotime($user['pay_date']) - time() ) / (60 * 60 * 24));
		if(in_array($days_left, $day_send_message)){
			if($user['uwemail'] != ""){
				mail($user['uwemail'], 'ISPMANAGER    '.$days_left.' \', "         ");
			}
		}
		if( $days_left == 3 ) {
			mail($adminemail, 'ISPMANAGER USER '.$user['name'], $user['name'] . "    ".$days_left." ");
		}
		if($days_left <= 0){
			mail($adminemail, 'ISPMANAGER USER '.$user['name'].' DISABLED', $user['name'].' ');
			exec("/usr/local/mgr5/sbin/mgrctl -m ispmgr user.suspend elid=".$user["name"]);
			if( $user['uwemail'] != "" ) {
				mail($user['uwemail'], 'ISPMANAGER  ', '     '); 
			}
		}
		//       IF       ,     
}


We save this script anywhere and call it whatever you like, add a task to the cron to call it once a day. Everything is ready.



Now the conscience is clear, the toad is satisfied, he hasn't incurred additional expenses.



It remains to fill in the data in users by what date the hosting was paid, and email users where to send reminders to users.



Glad if it helps someone.



All Articles