Jump to content

Suspend Hosting Account with PHP Script


Recommended Posts

Hello, SmallHost here!

I want to add a button where a user can deactivate (suspend) their SmallHost account. Due to US data laws, I can't make deleting an account harder than creating one, so I'm thinking of adding a button on the site where a user logged into my client panel can suspend their account by clicking it and re-entering their password.

There are two ways I can go about this...

  • Use the MOFH API. This is probably the best method, however I don't know how to read XML with PHP and I need to know the site's IP address in order for this to work.
  • Upload a page with a META redirect to their site and redirect them to that page with PHP. iFastNet's system seems to be suspending accounts that contain META redirects (it happened to me once on accident!). This would be easier, but idk if this would work well in the long run.

How should I go about adding this feature?

Link to post
Share on other sites
1 hour ago, smallhost said:

Hello, SmallHost here!

I want to add a button where a user can deactivate (suspend) their SmallHost account. Due to US data laws, I can't make deleting an account harder than creating one, so I'm thinking of adding a button on the site where a user logged into my client panel can suspend their account by clicking it and re-entering their password.

There are two ways I can go about this...

  • Use the MOFH API. This is probably the best method, however I don't know how to read XML with PHP and I need to know the site's IP address in order for this to work.
  • Upload a page with a META redirect to their site and redirect them to that page with PHP. iFastNet's system seems to be suspending accounts that contain META redirects (it happened to me once on accident!). This would be easier, but idk if this would work well in the long run.

How should I go about adding this feature?

For using the API, InfintyFree has a great client. To my knowledge, normal users cant suspend acounts. So you need to use the API. The Client by InfinityFree has a option to check if the request was successfull, so this shouldnt be an problem.

Link to post
Share on other sites
15 minutes ago, BastelPichi2 said:

For using the API, InfintyFree has a great client. To my knowledge, normal users cant suspend acounts. So you need to use the API. The Client by InfinityFree has a option to check if the request was successfull, so this shouldnt be an problem.

I'm trying to find out how I can integrate the API into the site. I need to find out the site's IP address, then I need to find how to integrate it (as I can't use Composer on the cPanel). I'm also looking into using the official API, however I don't know how to read XML in PHP and I still need to find the site's IP.

Link to post
Share on other sites

Hello,

Myownfreehost contains a JSON and XML API you can use the one in JSON if you can't do it moreover it's not necessary to know the IP address you put panel.myownfreehost.net:2087 in host and the user's domain.

 

I made a WHMCS script where you can see an example of how to use the API and the call to the suspend script that can help you.

https://github.com/MS-DOS2/mofh-server-module/blob/main/myownfreehost/myownfreehost.php

 

Link to post
Share on other sites
5 hours ago, MS-DOS said:

Hello,

Myownfreehost contains a JSON and XML API you can use the one in JSON if you can't do it moreover it's not necessary to know the IP address you put panel.myownfreehost.net:2087 in host and the user's domain.

 

I made a WHMCS script where you can see an example of how to use the API and the call to the suspend script that can help you.

https://github.com/MS-DOS2/mofh-server-module/blob/main/myownfreehost/myownfreehost.php

 

Thanks for responding!

SmallHost doesn't use WHMCS as I don't have a license for it (maybe I can find it in Softaculous, idk), however I think I can deconstruct the script and make it work. I'll test it later and see what happens. Thank you :)

Link to post
Share on other sites
18 hours ago, smallhost said:

I'm trying to find out how I can integrate the API into the site. I need to find out the site's IP address, then I need to find how to integrate it (as I can't use Composer on the cPanel). I'm also looking into using the official API, however I don't know how to read XML in PHP and I still need to find the site's IP.

For the IP, simply do an DNS lookup with dig or https://who.is. You can also just print the error log for debugging, the MOFH api will tell you what IP you are calling from.

Link to post
Share on other sites

Here's what I've done...

<link rel="stylesheet" type="text/css" href="https://smallhost.us.to/theme.css" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<center>
<h1>Account Deactivation</h1>
<p>Your SmallHost account has been sent for deactivation. The return log is listed below, for your convienience. If there's an error in the log and your account has not been deactivated or the box below is blank, contact SmallHost immediately with a copy of this log.</p>
<textarea rows="20" cols="75" disabled>
<?php
if(!isset($_COOKIE['userAuth'])) {
    header("Location: https://smallhost.us.to/clients/login.php");
    die();
}else{
    $decodedB64 = base64_decode($_COOKIE['userAuth']);
    $decodedJson = json_decode($decodedB64);
    $username = urlencode($decodedJson->user);
    $reason = urlencode('REQUESTED');
    $url = "https://panel.myownfreehost.net:2087/xml-api/suspendacct.php?api.version=1&user=".$username."&reason=".$reason;
$fields = [
    'username '      => 'MOFH API Username',
    'password' => 'MOFH API Password',
];
$fields_string = http_build_query($fields);
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, true);
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true); 
$result = curl_exec($ch);
echo $result;
}
?>
</textarea>
<p><a href="https://smallhost.us.to/clients/p/logout.php">Please log out immediately</a>, your account will be inactive shortly and control panel features won't work for this account.</p>
<p>(c)2021-Present SmallHost. Powered by <a href="https://ifastnet.com/">iFastNet</a>. Subdomain from <a href="https://freedns.afraid.org/">FreeDNS</a>.</p>
</center>

And here's the result...

Screenshot-1.png

The box should contain the XML log that looks something like this (according to the API)...

<suspendacct>
    <result>
        <status>1</status>
        <statusmsg>
            <script>if (self['clear_ui_status']) { clear_ui_status(); }</script>
            Changing Shell to /bin/false...Changing shell for username.
            Shell changed.
            Locking Password...Locking password for user username.
            marking user vhosts / databases for suspension.
            ..
            ..
            Completed, this account will be fully suspended in 2 minutes.
        </statusmsg>
    </result>
</suspendacct>

The box doesn't even return an error message, so it can't be an error. What did I do wrong?

Link to post
Share on other sites
1 hour ago, smallhost said:

Here's what I've done...


<link rel="stylesheet" type="text/css" href="https://smallhost.us.to/theme.css" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<center>
<h1>Account Deactivation</h1>
<p>Your SmallHost account has been sent for deactivation. The return log is listed below, for your convienience. If there's an error in the log and your account has not been deactivated or the box below is blank, contact SmallHost immediately with a copy of this log.</p>
<textarea rows="20" cols="75" disabled>
<?php
if(!isset($_COOKIE['userAuth'])) {
    header("Location: https://smallhost.us.to/clients/login.php");
    die();
}else{
    $decodedB64 = base64_decode($_COOKIE['userAuth']);
    $decodedJson = json_decode($decodedB64);
    $username = urlencode($decodedJson->user);
    $reason = urlencode('REQUESTED');
    $url = "https://panel.myownfreehost.net:2087/xml-api/suspendacct.php?api.version=1&user=".$username."&reason=".$reason;
$fields = [
    'username '      => 'MOFH API Username',
    'password' => 'MOFH API Password',
];
$fields_string = http_build_query($fields);
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, true);
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true); 
$result = curl_exec($ch);
echo $result;
}
?>
</textarea>
<p><a href="https://smallhost.us.to/clients/p/logout.php">Please log out immediately</a>, your account will be inactive shortly and control panel features won't work for this account.</p>
<p>(c)2021-Present SmallHost. Powered by <a href="https://ifastnet.com/">iFastNet</a>. Subdomain from <a href="https://freedns.afraid.org/">FreeDNS</a>.</p>
</center>

And here's the result...

Screenshot-1.png

The box should contain the XML log that looks something like this (according to the API)...


<suspendacct>
    <result>
        <status>1</status>
        <statusmsg>
            <script>if (self['clear_ui_status']) { clear_ui_status(); }</script>
            Changing Shell to /bin/false...Changing shell for username.
            Shell changed.
            Locking Password...Locking password for user username.
            marking user vhosts / databases for suspension.
            ..
            ..
            Completed, this account will be fully suspended in 2 minutes.
        </statusmsg>
    </result>
</suspendacct>

The box doesn't even return an error message, so it can't be an error. What did I do wrong?

^^

Link to post
Share on other sites
5 minutes ago, BastelPichi2 said:

First, remove the port. Just use https://myownfreehost.net. Then again, you can only suspend accounts created by the API. So this wont be able to work.

The API needs the port in order to work, here's the docs. I don't think that's the issue, nor do I think the code's the issue. Maybe cURL is disabled for some odd reason?

Link to post
Share on other sites

My reseller account got flagged...again.

PSA: DO NOT UPLOAD ANY FILES WITH FILE_PUT_CONTENTS FOR NOW, JUST TO STAY SAFE!

UPDATE: MY ACCOUNT IS UNSUSPENDED NOW. YES, UPLOADING VIA FTP WITH FILE_PUT_CONTENTS IS NOT ALLOWED (AT LEAST ON RESELLER HOSTING, THAT I'M AWARE OF).

Since that didn't work, I opted to my other idea--uploading a file to their site with a META redirect. Since that apparently suspends accounts (it happened to me once accidentally), I thought it would be easier to do that than to deal with the API. Apparently uploading a file using file_put_contents is bannable. (This is just an assumption, however I think this might be it. Just made a ticket with iFastNet.) Now my account has been suspended again. Contacting iFastNet to hopefully get this resolved... 

Edited by smallhost
Link to post
Share on other sites

Be careful the accounts suspended by the anti abuse blocks the possibility to remove the suspension of the account it is better to explicitly indicate the suspension of the account with the API try to retrieve the response with print_r otherwise use the JSON version of the API or try to parse it based on my script there are different ways to solve your problem

Link to post
Share on other sites
4 minutes ago, MS-DOS said:

Be careful the accounts suspended by the anti abuse blocks the possibility to remove the suspension of the account it is better to explicitly indicate the suspension of the account with the API try to retrieve the response with print_r otherwise use the JSON version of the API or try to parse it based on my script there are different ways to solve your problem

That's what I'm saying, my account is suspended and I can't unsuspend it on the MOFH panel.

Since the API wasn't working (the code I used is above), I resorted to uploading a HTML file to the user's website via FTP. The file would contain a META redirect (which suspends the users account) and the user would go to that page to deactivate their account. Apparently, using file_put_contents with the FTP tag is not okay.

I sent a ticket to iFastNet last night and all I received was a canned response saying that the file "wasn't allowed on free hosting". I kindly responded asking to be transferred to a live representative. My clients can no longer access the SmallHost client panel and users can no longer make SmallHost accounts since the site is inaccessible.

Let's hope I can get this resolved...

Link to post
Share on other sites
23 hours ago, smallhost said:

The API needs the port in order to work, here's the docs. I don't think that's the issue, nor do I think the code's the issue. Maybe cURL is disabled for some odd reason?

The API works perfectly on free hosting. Also using curl shoudlnt be a problem. The docs are wrong. It works without the port too, on the port you have an expired ssl! and AGAIN: To suspend an account, you need the 8 char unique identifier. Not the vPanel login username! This identifier only exists if you created the account via the API!

Link to post
Share on other sites
2 hours ago, BastelPichi2 said:

To suspend an account, you need the 8 char unique identifier. Not the vPanel login username! This identifier only exists if you created the account via the API!

Users create their account with the form at https://smallhost.us.to/register.php, not the API. Is there any other way to find this identifier, or do I have to manually deactivate a user's account?

Link to post
Share on other sites
13 minutes ago, smallhost said:

Users create their account with the form at https://smallhost.us.to/register.php, not the API.

But that form is contacting the API, otherwise it would not work. You need to contact the API again and tell it to suspend the account. Also, I have many (2) free sites on free hosting that use meta-redirects, and nither has been suspended.

 

Also, if a email address has too many suspended accounts, they will be permanently suspended. 

 

 

You need to contact the API, do not employ any other tricks or iFastNet may suspended your reseller privileges. You can use the InfinityFree PHP API wrapper to make this a lot easier. 

Link to post
Share on other sites

That's the thing, I don't have this eight-digit identifier required to suspend the account via the API. I tried the API prior to trying an FTP upload, however it returned blank (not even an error message). Here's the code I used...

<link rel="stylesheet" type="text/css" href="https://smallhost.us.to/theme.css" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<center>
<h1>Account Deactivation</h1>
<p>Your SmallHost account has been sent for deactivation. The return log is listed below, for your convienience. If there's an error in the log and your account has not been deactivated or the box below is blank, contact SmallHost immediately with a copy of this log.</p>
<textarea rows="20" cols="75" disabled>
<?php
if(!isset($_COOKIE['userAuth'])) {
    header("Location: https://smallhost.us.to/clients/login.php");
    die();
}else{
    $decodedB64 = base64_decode($_COOKIE['userAuth']);
    $decodedJson = json_decode($decodedB64);
    $username = urlencode($decodedJson->user);
    $reason = urlencode('REQUESTED');
    $url = "https://panel.myownfreehost.net:2087/xml-api/suspendacct.php?api.version=1&user=".$username."&reason=".$reason;
$fields = [
    'username '      => 'MOFH API Username',
    'password' => 'MOFH API Password',
];
$fields_string = http_build_query($fields);
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, true);
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true); 
$result = curl_exec($ch);
echo $result;
}
?>
</textarea>
<p><a href="https://smallhost.us.to/clients/p/logout.php">Please log out immediately</a>, your account will be inactive shortly and control panel features won't work for this account.</p>
<p>(c)2021-Present SmallHost. Powered by <a href="https://ifastnet.com/">iFastNet</a>. Subdomain from <a href="https://freedns.afraid.org/">FreeDNS</a>.</p>
</center>

I learned better after trying to upload a file with a META redirect via FTP and will either have to figure out what's wrong with my code or just have to manually suspend accounts (which would be a pain).

As for InfinityFree's wrapper, I looked at it. It needs Docker, which isn't an option on the cPanel. The wrapper also needs this eight-digit identifier that I don't have.

Right now, my best bet is to leave a message saying to email me for account deactivation.

Link to post
Share on other sites
12 hours ago, TinkerMan said:

But that form is contacting the API, otherwise it would not work. You need to contact the API again and tell it to suspend the account. Also, I have many (2) free sites on free hosting that use meta-redirects, and nither has been suspended.

 

Also, if a email address has too many suspended accounts, they will be permanently suspended. 

 

 

You need to contact the API, do not employ any other tricks or iFastNet may suspended your reseller privileges. You can use the InfinityFree PHP API wrapper to make this a lot easier. 

If it works if the customers create the accounts via the API and not the form the two usernames work if I take example of my WHMCS modules they use the identifier generated by this one during the creation of the account and not the complete one.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...