PDA

View Full Version : THT - The Hosting Tool



JonnyH
October 27th, 2008, 03:35
http://img139.imageshack.us/img139/6284/tht03xb3.png

From the creator of cP Creator brings you The Hosting Tool, this totally free script, released under the GNU-GPL takes all my past mistakes and rectifies them in a completely new script that will provide superb features in a free box.

This script is currently in development, please follow it below.

JonnyH
October 27th, 2008, 03:49
In cP Creator, there was just one class, it wasn't really supported or organised, just a bunch of functions in a file that did certain things when you wanted it to. Well if it did those things.

In THT the script is broke up into three main areas. Order, Admin, Client. They're split up into three different folders along with includes and themes.

There is also three main classes so far and a compiler. The compiler defines the script, creates all the classes in the folder and automatically any new ones. It also contains validation like PHP Version, because this is a PHP 5 only script.

The 4 main classes so far are DB, Style, Server, Main. Database contains all the db queries, fetch array, num rows, query. It also creates the connection on construct. Style contains all the template functions, header and footers. Server has yet to be made but contains all the server code, that will call another peice of code depending what control panel it is. WHM etc.

An example of one of these classes are:

<?php
//////////////////////////////
// The Hosting Tool
// Database (mySQL) Class
// By Jonny H
// Released under the GNU-GPL
//////////////////////////////

//Check if called by script
if(THT != 1){die();}

//Create the class
class db {
private $sql = array(), $con, $prefix, $db; #Variables, only accesible in class

# Start the functions #

public function __construct() { # Connect SQL as class is called
include(LINK."conf.inc.php"); # Get the config
$this->sql = $sql; # Assign the settings to DB Class
$this->con = @mysql_connect($this->sql['host'], $this->sql['user'], $this->sql['pass']); #Connect to SQL
if(!$this->con) { # If SQL didn't connect
die("Fatal: Coudn't connect to mySQL, please check your details!");
}
else {
$this->db = @mysql_select_db($this->sql['db'], $this->con); # Select the mySQL DB
if(!$this->db) {
die("Fatal: Couldn't select the database, check your db setting!");
}
else {
$this->prefix = $this->sql['pre'];
}
}
}

private function error($name, $mysqlerror, $func) { #Shows a SQL error from main class
$error['Error'] = $name;
$error['Function'] = $func;
$error['mySQL Error'] = $mysqlerror;
global $main;
$main->error($error);
}

public function query($sql) { # Run any query and return the results
$sql = preg_replace("/<PRE>/si", $this->prefix, $sql); #Replace prefix variable with right value
$sql = @mysql_query($sql, $this->con); # Run query
if(!$sql) {
$this->error("mySQL Query Failed", mysql_error(), __FUNCTION__); # Call Error
}
return $sql; # Return SQL
}

public function num_rows($sql) { # Runs a query and returns the rows
$sql = @mysql_num_rows($sql); # Run query
if(!$sql) {
$this->error("mySQL Num Rows Failed", mysql_error(), __FUNCTION__); # Call Error
}
return $sql; # Return SQL
}

public function fetch_array($sql) { # Gets a query and returns the rows/columns as array
$sql = @mysql_fetch_array($sql); # Fetch the SQL Array, all the data
if(!$sql) {
$this->error("mySQL Fetch Array Failed", mysql_error(), __FUNCTION__); # Call Error
}
return $sql; # Return SQL
}

public function strip($value) { # Gets a string and returns a value without SQL Injection
if(get_magic_quotes_gpc()) { # Check if Magid Quotes are on
$value = stripslashes($value);
}
if(function_exists("mysql_real_escape_string")) { # Does mysql real escape string exist?
$value = mysql_real_escape_string($value);
}
else { # If all else fails..
$value = addslashes($value);
}
return $value;
}
}
//End SQL
?>

Tracker
October 27th, 2008, 04:23
Great job Jonny` I cant wait to see how quick this grows!

fnixws
October 27th, 2008, 04:56
Good to see you back in action :)

What happend to not having time anyway?

Dan
October 27th, 2008, 04:59
Good one Jonny' Glad to see you coding stuff like this again.
Will keep a close eye on it.

Tracker
October 27th, 2008, 04:59
Good to see you back in action :)

What happend to not having time anyway?

I would guess that like most once he had nothing to do he got bored and then it started driving him nuts so he started coding :P

Thats my guess anyway

JonnyH
October 27th, 2008, 05:06
I've got a week off. I've finished all the assignments I needed to do in that time.. So I decided to through together the ideas I had. I said in a previous post in cP Creator I wanted to get this out by the end of the week. When college starts again, work flows in.

Cheers for the replies guys. Makes it worthwhile.

Also, would anyone be able to provide a free account, I need a home for this place. Would it be possible to have around 500mb space and 5GB Bandwidth with dev WHM access?

PM me if interested. I can have your banner on the homepage.

Dan
October 27th, 2008, 05:15
Also, would anyone be able to provide a free account, I need a home for this place. Would it be possible to have around 500mb space and 5GB Bandwidth with dev WHM access?

PM me if interested. I can have your banner on the homepage.

Jonny' I would be happy to sponsor this project.
Hook up with me. :)

JonnyH
October 27th, 2008, 05:17
I was going to use an old account but Dan, that's an offer I can't turn down. You got MSN?

Dan
October 27th, 2008, 05:19
I was going to use an old account but Dan, that's an offer I can't turn down. You got MSN?

Sure man. I will PM it to you.

TechDudeDan
October 27th, 2008, 06:20
:) Can't wait to see this all up and running.

iBrightDev
October 27th, 2008, 08:18
Jonny, more than interested in hooking up with you and Dan on this. you both have my msn. get at me.

david432111
October 27th, 2008, 08:26
This is great Jonny.

JonnyH
October 27th, 2008, 08:37
6 Hard hours of straight development time have officially fried my mind. I've been working constantly on the ACP alone and managed to get its system up and running. Here's some screens. Keep in mind this is VERY early on in development. Most things may change:
http://img55.imageshack.us/img55/1363/acploginoj6.png (http://imageshack.us)
http://img55.imageshack.us/img55/7062/acphomeip6.png (http://imageshack.us)
http://img55.imageshack.us/img55/4242/acppackagespm4.png (http://imageshack.us)

As you can see really, I tried to go for the basic iPanel look, basic boxes, basic text but does the job. Like before it's easy to integrate with headers and footers, unlike cP Creator this doesn't work with wrappers. One thing that is noticeably different in the ACP is the addition of the sub side menu.

Dan
October 27th, 2008, 08:53
Looks excellent Jonny'

TechDudeDan
October 27th, 2008, 08:54
Looks good, can't wait to see a full release.

krakjoe
October 27th, 2008, 09:12
Sounds like a good project Johnny.

No one likes to see global used in OO programming, it's one of those things that causes errors later during development. To avoid this, you have a couple of options, I would say the best is to have a tht class, my suggested methods would be ...



<?php
final class tht
{
/**
* @var array
* A SQL safe COPY of _REQUEST
**/
private $request = array( ) ;
/**
* @var resource
* MySQL connection
**/
private $mysql = null ;
/**
* @var array
* Internal errors
**/
private $errors = array( ) ;
/**
* @var integer
* Number of queries so far
**/
private $count = 0 ;
/**
* @param array configuration loaded from disk
* Although methods/variables are static, __constructing allows
* for population of the objects static member variables with useful data
**/
function __construct( &$config )
{
// Do whatever you normally would with request to make it sql safe
if( $_REQUEST )
{
if( get_magic_quotes_gpc( ) )
{
self::$request = self::apply( $_REQUEST, 'stripslashes' );
}
else self::$request = $_REQUEST ;

// now tht::request( 'key' ); will return _REQUEST['key'] SQL safe
}
// Connect to MySQL with config loaded from disk
if( ( self::$mysql = mysql_connect( $config['hostname'], $config['username'], $config['password'] ) ) )
{
// Make sure we have the required database available
if( mysql_select_db( $config['database'], self::$mysql ) )
{
// start filling other members with useful data
// config was passed by reference, so you could be useful and fill it with configuration data
// from the database, then you can keep passing this config array by reeference to other objects
// used in execution
}
else self::error( __METHOD__, "Failed to select %s on %s, MySQL said: %s", __FILE__, __LINE__, $config['database'], $config['hostname'], mysql_error( self::$mysql ) );
}
else self::error( __METHOD__, "Failed to connect to %s as %s with password supplied, MySQL said: %s", __FILE__, __LINE__, $config['hostname'], $config['username'], mysql_error( ) );
}
/**
* @param array the array to apply the callback too
* @param string the name of the callback to apply to array
* Recursively applies a callback to every member in an array and returns a COPY
**/
static function apply( $array, $callback = null )
{
$clean = array( );

foreach( $array as $key => $value )
{
if( is_array( $value ) )
{
$clean[$key] = self::apply( $value, $callback );
}
else $clean[$key] = call_user_func( $callback, $value );
}

return $clean ;
}
/**
* @param string the name of the member to fetch
* If key is omitted return the whole request array ( for templates perhaps )
**/
static function request( $key = null )
{
switch( is_null( $key ) )
{
case true: return self::$request; break;
case false: return self::$request[$key]; break;
}
return $key ;
}
/**
* @param string method the error occured in
* @param string message describing the error ( sprintf compatible )
* @param string file the error occured in
* @param line line the error occured in
* @param format variable number of parameters to format message with ( see __construct )
* Set an internal error, and format it too ...
**/
static function error( $method, $message, $file, $line, $format = null )
{
if( ( $format = func_get_args( ) ) )
{
if( ( $method = array_shift( $format ) ) )
{
if( ( $message = array_shift( $format ) ) )
{
if( ( $file = array_shift( $format ) ) )
{
if( ( $line = array_shift( $format ) ) )
{
return ( $this->errors[] = vsprintf
(
"{$method}: {$message} in {$file} on line {$line}",
$format
) );
}
}
}
}
}
}
/**
* @param boolean delete errors where true and errors exist
* Return all the formatted errors, optionally delete them before returning
**/
static function errors( $delete = false )
{
$errors = array( );

if( count( self::$errors ) )
{
$errors = self::$errors ;

switch( $delete )
{
case true: self::$errors = array( ); break;
}
}

return $errors ;
}
/**
* @param string the SQL to send
* @param mixed variable length list of things to escape and format sql with
* tht::query( "SELECT * FROM settings" );
* tht::query( "SELECT * FROM table WHERE column = '%d'", tht::request('key') );
* returns MySQL resource, sets errors and escapes anything after sql
**/
static function & query( $sql, $format = null )
{
if( self::$mysql )
{
if( ( $format = func_get_args( ) ) )
{
if( ( $sql = array_shift( $format ) ) )
{
$result = null ;

if( $format )
{
foreach( $format as $key => $value )
{
if( $value )
{
$format[$key] = mysql_real_escape_string( $value, self::$mysql );
}
}

if( !( $sql = vsprintf( $sql, $format ) ) )
{
return self::error( __METHOD__, "Failed to format SQL with %d parameters", __FILE__, __LINE__, count( $format ) );
}
}

if( ( $result = mysql_query( $sql, self::$mysql ) ) )
{
self::$count++;
}
else self::error( __METHOD__, "Failed to execute query, MySQL said: %s", __FILE__, __LINE__, mysql_error( self::$mysql ) );

return $result ;
}
else self::error( __METHOD__, "Method called improperly", __FILE__, __LINE__ );
}
else self::error( __METHOD__, "Method called improperly", __FILE__, __LINE__ );
}
else self::error( __METHOD__, "An attempt was made to execute SQL on an invalid connection", __FILE__, __LINE__ );
}
/**
* @param resource MySQL result from tht::query
* wrap of mysql_fetch_assoc for uniform code
* don't try to error handle tht::next because while $x = tht::next($result)
* will cause errors when there are none except no more results
**/
static function next( &$result )
{
if( $result )
{
return mysql_fetch_assoc( $result );
}
}
/**
* @param resource MySQL result from tht::query
* wrap of mysql_fetch_assoc for uniform code
* you could beef it up some with error handling on non-existent results etc
**/
static function field( &$result, $index = 0, $column = null )
{
if( $result )
{
return mysql_fetch_result( $result, $index, $column );
}
}
/**
* @param tht|resource|null what to count ??
* tht::count( 'tht' ) = number of queries executed so far
* tht::count( $result ) = number of rows contained by $result
* tht::count( ) = number of rows affected by the execution of $result
**/
static function count( $what = null )
{
switch( $what )
{
case __CLASS__: return self::$count; break;
case null; return mysql_affected_rows( self::$mysql ); break;
default: return mysql_num_rows( $what ); break;
}
}
/**
* wrap of mysql_close for uniform code
**/
static function close( )
{
if( self::$mysql )
{
@mysql_close( self::$mysql );
}
self::$mysql = null ;
}
}
?>


This way all the objects you create like Server, Client, Admin, Plugins etc will all have static access to the database, to error reporting, to SQL safe user input and whatever else you include ... that code is not tested, I didn't even read it twice, but you can see where it's going though ...

Just a suggestion, good luck with the new project :)

JonnyH
October 28th, 2008, 06:20
Packages & Servers
One of the main parts for a hosting script is obviously the packages & servers. Without these, it wouldn't be a hosting script, just a normal purchasing form with no hook on the end. That's why I'm putting a lot of effort to make the package and servers part as functional, flexible and bug free as I can possible create.

In THT the packages work in a similar way as cP Creator with slight differences to the modules as they were in cP Creator. Now types. The types are called only in 4 areas. Order, Admin, Client, Cron. The areas you expect them to really. They have one function a peice. In order it's signup, so the script could check posts for example. In Admin it's the acpArea, this displays for example a users forum username and monthly posts. In client, it's the clientPage hooked with a two sidebar variables. In Cron, it's a call that checks monthly posts and suspends if low. Here's a screenshot of the add packages:
http://img412.imageshack.us/img412/3034/acppackagesaddgc1.th.png (http://img412.imageshack.us/my.php?image=acppackagesaddgc1.png)

Servers look the same as the do in cP Creator but backend they're very different. Even though I'm only doing this for cPanel/WHM to start off with, the base for adding more control panels is there and fully functional. They're set up in the way types are set up. The class retrieves the server type then calls the function assigned to that server type. There's 4 functions: create, suspend, unsuspend, terminate.

david432111
October 28th, 2008, 07:45
This looks really nice Jonny :)

DanTheMan
October 28th, 2008, 18:55
Hey hey hey nice to see you back in the game!!!! If you need any help with anything let me know! WHM account I can spare :D but looks like Dan beat me to you ah lol

iBrightDev
October 28th, 2008, 22:23
Jonny, let me know when you want to go over more things for improvement. :D

david432111
November 2nd, 2008, 10:16
Any updates?

JonnyH
November 2nd, 2008, 12:06
I've been working really really really hard on the order form. Sorry but it won't be out by today. It's going to be a project spanning a couple of weeks now.

JonnyH
November 2nd, 2008, 12:26
Right, I'm going to dish out a few preview looks at the Order Form for feedback, anyone interested send me a PM.

iBrightDev
November 2nd, 2008, 12:49
ill be on msn if you need me.

david432111
November 4th, 2008, 08:46
The order form's looking great. :)
Loving the effects :D

JonnyH
November 11th, 2008, 03:16
Dev Diary - Order Form
I've just written up a very long explanation and detailed diary on the order form. This has images and very detailed explanations of the order form:
http://thehostingtool.com/forum/thread-9.html

stuffradio
November 11th, 2008, 13:34
Who did the design? I like it :)

JonnyH
November 11th, 2008, 16:24
The myBB or the script?

stuffradio
November 12th, 2008, 01:29
The Script.

Dan
November 12th, 2008, 06:10
Looking great Jonny' Keep up the good work mate. :)

JonnyH
November 12th, 2008, 10:22
I did it stuff. Pretty basic lmao.

jimmie32
November 12th, 2008, 13:33
Jonny, I want to get into the talk also :)
I'm Jimmie, I help Jonny to work on THT, but he does 99% of the job, I'm just the one that stays talking with him on msn and say "Jonny, this is bugged", "Jonny, fix this, do this, do that" :p
Also if you noticed, I'm an administrator at the THT Community ;)

DanTheMan
November 12th, 2008, 13:57
Will this program have forced ads?

And nice to see you around again Jimmie32!

JonnyH
November 12th, 2008, 14:44
Dan;1035610']Will this program have forced ads?

And nice to see you around again Jimmie32!
Maybe at a later date, if I can get the access.

JonnyH
November 22nd, 2008, 06:09
Been a while since I updated this thread. So here goes.

THT is burning through development, I won't reach the ETA I wanted but it's sure close to release. I can't exactly give you a date or timeframe because the time I've set aside to do development like this has gone crazy in the past couple of days.

Well, the order form a client area are near final. All the backend code for basic signup, the html, the style, the JS is complete basically. I'll compile the finishing touches on that when I come to that stage. So far, the things missing out of it so far are the admin validation and post 2 host. They won't be hard to do really.

The client area in the final version really will be what I like to call 'lacking'. It's got a very nice base to work on really. In the first version it will have edit details, delete account and view package along side the P2H tools. There is no support centre in THT at this version. That will come at a future date. Also upgrade/downgrade won't be in this version yet.

The admin control panel is the main area of my development time at the minute. I'm currently working on the client area part that includes some nice AJAX search etc. There's not much compared to my previous work but I've included all the important features really. Like admin validation for all types of packages. P2H or Free or Paid for future versions.

So what am I working on now?
The Clients section is ACP.

What to do:
Admin Validation
Post 2 Host
cP Creator Import
Clean Code
Install Script

If you've got any questions on The Hosting Tool, feel free to PM me or ask a question on the forums. Also:
If you want to test the Order Form and Client Area to give feedback get in touch!

jimmie32
November 22nd, 2008, 11:43
Also, I wanted to give out more updates ;)
The THT Default style is now updated with a Tabbed-Browsing Feature (Written by Jimmie, which is me) and with several UI enhancements ;)

Also I worked on several Security Features, so be sure to get in touch with Jonny to get a preview and to see how it looks :D

I'm not doing any big job, Jonny is :D So if you want to suggest something big, post here or at the THT Community. If I can do it, I will, if I can't, I will call Jonny to do so :p

~Jimmie, THT Community Team Leader

stuffradio
November 22nd, 2008, 13:02
Good luck guys! :P

Schmarvin
November 22nd, 2008, 13:14
This actually sounds better than cP Creator. xD Maybe even all the automated systems out there!

jimmie32
November 23rd, 2008, 04:09
Another Update:

~Security Settings
Security is the most important part of all software. THT also cares about it ;)
I just worked on three small security switches:

- Show THT Version in Copyright? [Default: Yes]
- Show AdminCP Link in Tabbed Menu? [Default: Yes]*
- Show Page Generation Time? [Default: Yes]*

* Warning: These will only work if you're running the THT Default Style or Styles based off it. BlueVision Style, THT-Legacy Style won't show any difference, as the triggers won't work there.

To show the page Generation time, you just need to use <PAGEGEN> anywhere in the header/footer.tpl, and it will show the page generation time!
The Tabbed menu can be customized using CSS, and you can use <MENU> to show it.

;)

david432111
November 23rd, 2008, 04:42
Great work guys!

Dynash
November 23rd, 2008, 05:07
I love the AJAX, sweet work. :D

jimmie32
November 24th, 2008, 13:11
More updates :)

Jonny just finished the Admin Validation System, and he is working now on p2h. We are almost there!

My updates:
~ Admin Notepad
A simple, easy and fun Admin Notepad is now working.
~ Client Area Announcements
Now you can show announcements in the client area, in a separate page. After you configure this feature in Client Area settings, just go to the Client Area -> Announcements and you can see the announcements that you wrote!

:)

iBrightDev
November 24th, 2008, 13:25
now he just needs to get on the ibd-cms plugin ;)

jimmie32
November 26th, 2008, 13:46
Even more updates :D

~ Post-2-Host Finished
Jonny finished the p2h system! :D





Yes, it works only for the signup, not monthly posts. Now he just needs to:
~ Work on the Monthly Cron System
~ Release the Script Beta/Alpha/Final Version

:)

stuffradio
November 26th, 2008, 18:18
Great stuff!

JonnyH
November 27th, 2008, 06:27
Quick Update
I thought I'll post this before Jimmie gets round to it ;)

All Post 2 Host is now completed, this means the release to THT is coming so much closer.

Looking forward to it.

JonnyH
November 27th, 2008, 08:12
Another Update
The cP Creator importer is now complete! The script is reaching final stages of development.

jimmie32
November 27th, 2008, 11:40
Why I can't post announcements before you? :p

Jonny`, make a iPanel/WHMCS/ClientExec client importer :D

JonnyH
December 4th, 2008, 09:07
The Hosting Tool v1 Final is now released!
The Hosting Tool version 1 is now released to the public and it's FINAL! This means that anyone and their server can use it. You can upgrade from Public Beta v1 with the version 1. Changes from public beta Patch 2:
1) THT Updates & News layout made more eye friendly
2) ACP Home rearranged and cleaned code
3) Admin Notepad now switched to TinyMCE
4) Server Footer Information now an option in Security Settings
5) Remote icons fixed

http://www.freewebspace.net/forums/showthread.php?t=2215570

Thanks,
Jonny

JohnN
December 4th, 2008, 13:44
great work Jonny, keep it up!

jimmie32
December 16th, 2008, 11:36
By the way, the patch 1 for v1.0 is released. It contains a few fixes. (big ones.)

JonnyH
December 16th, 2008, 14:11
Jimmie, it's v1.01 and it contains one fix ;)

jimmie32
December 21st, 2008, 06:20
One? I thought that there were a few more.
By the way, 1.1 is coming. With support area, resellers and client domain search. Sorry Jonny if I gave too much details. :P

krakjoe
December 21st, 2008, 06:21
It'd be much better for everyone if one of you posted about updates ...

JonnyH
December 21st, 2008, 14:15
It'd be much better for everyone if one of you posted about updates ...
If you're on about only one person posting about updates, I'll keep Jimmie under wraps. If you're on about the lack of recent updates. There hasn't been any really.

stuffradio
December 21st, 2008, 15:12
If you're on about only one person posting about updates, I'll keep Jimmie under wraps. If you're on about the lack of recent updates. There hasn't been any really.

I think he means only one of you to post updates, most likely you ;)

Jan
December 21st, 2008, 18:53
jimmie32 appears to like bumping the thread.

JonnyH
December 23rd, 2008, 04:47
v1.1 is now released!
Welcome to the HUGE version of THT. The almighty THT v1.1, in this version the main new features are:

Direct Admin Support
Full Support Center
Full Reseller Support
WHM Import Tool


Download (http://thehostingtool.com/forum/attachment.php?aid=23)

Full Changelog:
1) Client Tables now work with id's left, right
2) Errors appearing more than once, fixed
3) Client/Admin CP now works off a global login system
4) Navbar works with DB
5) Site Name removed from front of link
6) WHM Username exists error tweaked
7) Full reseller support added
8) Packages backend DB limit lifted to 50
9) WHM Import Tool Added
10) CLient Email, Dev area link fixed
11) Client Email, %BOX% doesn't show
12) ACP Change Password works
13) Search Client modified and changed
14) Domain added to client details
15) Domain search added into the search clients
16) Order Form Packages now displayed in boxes
17) Fixed cron to stop showing session warnings
18) Server host char limit switched to 50
19) WHM Server Class switched to the XML API
20) Removed the redirect message from the delete account
21) IE Order Form bug fixed
22) Credits Added
23) Full Direct Admin support added
24) Server OS Added in Server Status
25) Full Support Center Added, includes Tickets & Knowledge Base
26) Client Announcements now work