First I must say the following:
I hold no responsability for what happens when you use this script. I do not claim it to be 100% perfect or secure in anyway.
Now, if you agree with the above then you may continue.
Since plesk has the ability to use custom buttons I decided that it would be a good way to insert modernbill into my control panel for the users. Now the first problem is that users have access to edit thier custom buttons. So I opened up
/usr/local/psa/admin/plib/templates/domains.tpl
and commented out {CBUTTONS_BUTTON} on line 22. This way users cannot have access to edit the buttons I create.
Next thing to do was create the buttons every time a client was created. So in the even manager I added a line to execute the following script.
Code:
#!/bin/bash
client=$1
# create the custom button under "Added Features" that will allow the client to see the stats page
/usr/local/psa/bin/custombutton.sh \
-c -owner $client \
-text "Account Home" \
-place client \
-url "https://<billing_url>/include/config/mblogin.php" \
-url_comp email \
-internal true \
-file /usr/local/psa/admin/htdocs/skins/winxp.silver/images/account_home.gif \
-sort_key 100;
/usr/local/psa/bin/custombutton.sh \
-c -owner $client \
-text "Account Info" \
-place client \
-url "https://<billing_url>/include/config/mblogin.php?op=menu&tile=myinfo_tab" \
-url_comp email \
-internal true \
-file /usr/local/psa/admin/htdocs/skins/winxp.silver/images/control-panel.gif \
-sort_key 101;
/usr/local/psa/bin/custombutton.sh \
-c -owner $client \
-text "Domains & Packages" \
-place client \
-url "https://<billing_url>/include/config/mblogin.php?op=menu&tile=mysites_tab" \
-url_comp email \
-internal true \
-file /usr/local/psa/admin/htdocs/skins/winxp.silver/images/internet.gif \
-sort_key 102;
/usr/local/psa/bin/custombutton.sh \
-c -owner $client \
-text "Account Billing" \
-place client \
-url "https://<billing_url>/include/config/mblogin.php?op=menu&tile=myfinance_tab" \
-url_comp email \
-internal true \
-file /usr/local/psa/admin/htdocs/skins/winxp.silver/images/dollar.gif \
-sort_key 103;
/usr/local/psa/bin/custombutton.sh \
-c -owner $client \
-text "Technical Support" \
-place client \
-url "https://<billing_url>/include/config/mblogin.php?op=menu&tile=getsupport_tab" \
-url_comp email \
-internal true \
-file /usr/local/psa/admin/htdocs/skins/winxp.silver/images/support.gif \
-sort_key 104;
Each line of this script creates a button to point to a different menu item in modernbill. Replace <billing_url> with the url and path to your modernbill installation.
After the buttons were created every link will point the user to the modernbill login. I decided I didn't like this so I decided to create a bridge that gets the users email from plesk using the "-url_comp email" arg.
I wrote this in PHP4, all info is submitted via secure socket layer ( SSL ) so nothing is in plain text.
PHP:
<?php
/* I added some security up here to make sure this script could not be accessed outside of plesk. I suggest you do the same. For my own security reasons I did not add it here */
// Check to see if modernbill cookies exist
$myip = $_COOKIE['myip'];
// Get the users remote ip address
$addr = $_SERVER['REMOTE_ADDR'];
// get the users email from the url
$user = $_GET['email'];
// Get the tile that modernbill will redirect to
$tile = $_GET['tile'];
// Get the op ( This is almost always menu
$op = $_GET['op'];
// If the user is not authenticaed the myip cookie doesn't exist. So query for the client_real_pass in the modernbill database, and log them in
if ( !isset($myip) ) {
$host = "localhost";
$user = "<database_user>"; /* replace with actual db username */
$pass = "<database_pass>"; /* replace with actual db password */
$db = "<database_name>"; /* replace with actual db name */
@mysql_connect($host,$user,$pass);
@mysql_select_db($db);
$sql = "SELECT client_real_pass FROM modernbill.client_info WHERE client_email = '" . $email . "'";
$res = @mysql_query($sql);
$pass = @mysql_fetch_row($res);
$pass = $pass['0'];
@mysql_close();
$formop = "login";
print ("<form name=\"form\" method=\"post\" action=\"https://<billing_url>/index.php\">");
print ("<input type=\"hidden\" name=\"username\" value=\"$user\">");
print ("<input type=\"hidden\" name=\"password\" value=\"$pass\">");
print ("<input type=\"hidden\" name=\"newtile\" value=\"$tile\">");
print ("<input type=\"hidden\" name=\"newop\" value=\"$op\">");
print ("<input type=\"hidden\" name=\"op\" value=\"$formop\">");
print ("</form>");
print ("<body onLoad=\"form.submit();\">");
}
// If the user already has the myip cookie, and is already authenticated then redirect them to the correct tile in modernbill.
elseif ( isset($myip) && $myip == $addr ) {
print ("<script language=\"Javascript\">document.location.href='https://<billing_url>/user.php?op=$op&tile=$tile';</script>");
}
?>
Again, replace <billing_url> with the url and path to your modernbill installation.
After this was completed, I added a couple of lines to index.php in my modernbill installation to make sure once they are logged in they get redirected to the correct tile
find the lines
PHP:
$r_op = cdsql($redirect_op);
$r_tile = cdsql($redirect_tile);
and replace with
PHP:
if ( isset($_REQUEST['newop']) && isset($_REQUEST['newtile']) ) {
$r_op = cdsql($_REQUEST['newop']);
$r_tile = cdsql($_REQUEST['newtile']);
} else {
$r_op = cdsql($redirect_op);
$r_tile = cdsql($redirect_tile);
}
That's it!
Once again I hold no responsability for what happens when you use this script. I do not claim it to be 100% perfect or secure in anyway.
Always make backups of files you edit, and never post anything with critical information.
Feedback is always encouraged. Improvments as well.
- Simplx