Jump to content
[MUST READ] Forum Rules ×

Suspend Hosting Account with PHP Script


smallhost

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 comment
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 comment
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 comment
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 comment
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 comment
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 comment
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 comment
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 comment
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 comment
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 comment
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 comment
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 comment
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 comment
Share on other sites

1 hour ago, BastelPichi2 said:

This is wrong!

How? Just use the API to delete the account.

 

From InfinityFree's API wrapper:

  • suspend
    • username: The unique, 8 character identifier of the account.
    • reason: A string with information about why you are suspending the account.
    • linked: If true, related accounts will be suspended as well.

 

The API will suspend accounts, same thing as deleting them.

Link to comment
Share on other sites

21 hours ago, BastelPichi2 said:

On the signup form, this Main domain is really the domain you signed up with and has a function.

For the API, you need this 8 character unique identifier. The normal username wont work.

a.png

That's a great way of explaining! The problem is that I can't suspend an account without the 8 character UI (unique identifier), which needs the API. 

I have another idea, but it would involve a Python server (which might take awhile for me to afford). There's a thing called ChromeDriver where basically Python can control a Chromium-based browser (such as Chrome or Brave). I can potentially make a code where when a request is made to the server it will login to panel.myownfreehost.net, find the account and suspend it. This might take a LOT of time to do, and it might not even work (I'm not that good with Python).

21 hours ago, BastelPichi2 said:

For the MOFH panel, I may publish an API that allows you to do this from your code - stay tuned.

That sounds awesome, I'd definitely credit you if I implement that into SmallHost!

 

20 hours ago, TinkerMan said:

From InfinityFree's API wrapper:

  • suspend
    • username: The unique, 8 character identifier of the account.

The API is incorrect. It doesn't need the username, it needs the 8 character code that @BastelPichi2 was talking about.

Link to comment
Share on other sites

5 hours ago, smallhost said:

That's a great way of explaining! The problem is that I can't suspend an account without the 8 character UI (unique identifier), which needs the API. 

I have another idea, but it would involve a Python server (which might take awhile for me to afford). There's a thing called ChromeDriver where basically Python can control a Chromium-based browser (such as Chrome or Brave). I can potentially make a code where when a request is made to the server it will login to panel.myownfreehost.net, find the account and suspend it. This might take a LOT of time to do, and it might not even work (I'm not that good with Python).

That sounds awesome, I'd definitely credit you if I implement that into SmallHost!

 

The API is incorrect. It doesn't need the username, it needs the 8 character code that @BastelPichi2 was talking about.

Why python ? In PHP it is largely possible and easier with CURL.

Link to comment
Share on other sites

17 hours ago, MS-DOS said:

Why python ? In PHP it is largely possible and easier with CURL.

I can't suspend an account in PHP without an eight-character identifier that I don't even have. Without this identifier, it's impossible to do it with PHP. I'm considering using Python and ChromeDriver, however it would take some time to implement. Basically a request is made to the Python server and Python controls my either my computer or a server to login to panel.myownfreehost.net for me and suspend an account. I'm not that good with Python, but if there is a way to login to panel.myownfreehost.net with PHP that would be amazing.

Link to comment
Share on other sites

So by connecting not to the API but to the panel directly, making a kind of bot is possible and you can have the unique identifier by doing a search with the domain.
You can use the link: https://panel.myownfreehost.net/panel/index2.php?option=drilldowndom&domain_name=DOMAIN then search in the HTML code received the identifier to access the page of the username: https://panel.myownfreehost.net/panel/index2.php?option=drilldown&username=USERNAME and finally with a POST fill in the reason for the suspension and suspend the account is largely feasible.

Edited by MS-DOS
Link to comment
Share on other sites

30 minutes ago, MS-DOS said:

So by connecting not to the API but to the panel directly, making a kind of bot is possible and you can have the unique identifier by doing a search with the domain.
You can use the link: https://panel.myownfreehost.net/panel/index2.php?option=drilldowndom&domain_name=DOMAIN then search in the HTML code received the identifier to access the page of the username: https://panel.myownfreehost.net/panel/index2.php?option=drilldown&username=USERNAME and finally with a POST fill in the reason for the suspension and suspend the account is largely feasible.

That sounds possible...the problem is I'd need to code a Python bot to do that or find a way to do it in PHP with cURL. I'd also need to add a user agent header to make it look like its a browser sending the requests because it might not allow automated requests. This will take some time to do...

 

Edit: Here's what I see that the bot needs to do (in this order).

Edited by smallhost
Link to comment
Share on other sites

7 minutes ago, BastelPichi2 said:

For the Server, just buy an 2$ vps, and you can make such code in under 50 lines. So this shouldn't be a problem. For the Server, I would reccomend to use Flask. Its super easy to learn.

I'm working on making a program to do this in Python, however SmallHost doesn't have any funding to spend on a VPS server. As soon as I set up ads or get a job (whatever comes first), I'll see what I can do in regards to buying a VPS server.

Also, a $2 VPS server is very inexpensive. Are you sure that isn't a monthly charge? Even if it is monthly, that's still cheap. Where did you find that VPS server?

Link to comment
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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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...