Automatic User Disconnection in ISPManager5 Lite without BILLmanager

Given:

  1. VPS Server with a perpetual ispmanager lite 5 license
  2. 10-20 users on the server
  3. Google Calendar with regular reminders for those who are due hosting
  4. It's frustrating to pay for anything else, especially on a subscription

The goal is to eliminate Google Calendar and manual reminders to clients about hosting payments. To free myself from thinking ā€˜let them work a little longer, they will pay soon’ or ā€˜it’s awkward to disconnect’, and delegate this to a soulless machine.

Of course, I searched on Google first, but found no solutions; everything boiled down to needing a BILLmanager subscription. However, point number 4 is very important and serious for me, and I won’t get rid of it. Moreover, the solution turned out to be not so complicated.

So, what do we do.

Create a directory users.addon in the /usr/local/mgr5/etc/sql/ directory, and 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 two corresponding fields where values from the admin panel will be written.

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

Paid until
			User email
		
	
	
		
			Paid before
			User email

This gives instructions to the panel for displaying our fields in the user editing form.

Reload the panel:

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

We obtain:

Automatic User Disconnection in ISPManager5 Lite without BILLmanager

In the fields, enter until what date the hosting should work, and which user email to send reminders to that hosting will soon expire.

Now we need to create a script that will remind users that hosting is about to expire periodically. Notify the admin that hosting is coming to an end. Notify the user and admin that the user has been disabled.

I am comfortable with PHP and wrote the script.

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 hosting will expire in '.$days_left.' days', "Message for the user about how many days are left");
			}
		}
		if( $days_left == 3 ) {
			mail($adminemail, 'ISPMANAGER USER '.$user['name'], $user['name'] . " Hosting will expire in ".$days_left." days");
		}
		if($days_left <= 0){
			mail($adminemail, 'ISPMANAGER USER '.$user['name'].' DISABLED', $user['name'].' Disabled');
			exec("/usr/local/mgr5/sbin/mgrctl -m ispmgr user.suspend elid=".$user["name"]);
			if( $user['uwemail'] != "" ) {
				mail($user['uwemail'], 'ISPMANAGER hosting disabled', 'Message for the user that the hosting has expired'); 
			}
		}
		// optionally, you can write a small IF statement to delete data after some time, but I don’t need that
}

Save this script anywhere and name it whatever you like, then add it to a cron job to call it once a day. All set.

Now the conscience is clear, the burden is lifted, and no additional expenses have been incurred.

All that's left is to fill in the data on which users have paid for hosting by which date, and the email addresses of the users to send reminders to.

I’m glad if this helps someone.

Source: habr.com

Buy reliable website hosting with DDoS protection, VPS VDS servers šŸ”„ Buy reliable website hosting with DDoS protection, VPS VDS servers | ProHoster