Automatic disconnection of users in ISPManager5 lite without BILLmanager

Given:

  1. VPS Server with ispmanager lite 5 perpetual license
  2. 10-20 users per server
  3. Google Calendar with regular reminders of who has run out of hosting
  4. Choking toad to 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 they need to pay for hosting. Rid yourself of “let him work a little more, he will soon pay” “somehow it’s not convenient to turn it off”, and entrust this to a soulless machine to solve.

Of course, at first I googled and searched, but I didn’t find solutions. It all boiled down to the fact that you need to take a BILLmanager subscription, but item number 4 is very important and serious for me, I won’t get rid of it. And the solution turned out to be not so difficult.

So what do we do.

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

  1. pay_date
  2. uwemail

This will instruct the panel to create in the database
/usr/local/mgr5/etc/ispmgr.db
in the users table there are two corresponding fields where values ​​from the admin panel will be written.

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

<?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 on the user's edit form.

Reloading the panel:

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

Get:

Automatic disconnection of users in ISPManager5 lite without BILLmanager

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

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

I'm close to php on it and wrote a script.

<?php
$adminemail = "[email protected]"; // 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 we want, add a task to cron to call it once a day. All is ready.

Now the conscience is clear, the toad is satisfied, no additional costs incurred.

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

Glad if someone can help.

Source: habr.com

Add a comment