Community Forums Today's Posts     Member List     Archive    
Results 1 to 2 of 2
  1. #1
    Maniac Guest

    Server automated creation script

    I have noticed a lot of people looking for a way to provide there users with a way to create there own servers. I have made the following script (with help from other already made functions I found here). Basically the way my script works is I use Hsphere for my billing. When the payment has been verified there is a link to this php page contained in the thank you email confirmation that they click on. That link contains there account information and certain options they selected when they signed up. The script then asks them a few more questions concerning there server then logs in via httptcpquery and makes the server for them. Then it displays the results. I also have some security stuff that checks the hsphere database to ensure they have paid to stop unwanted servers being made and it also checks another database to ensure that the user has not already signed up which I did not include here. I also have a simple database that keeps track of what the next port is. The code is a little messy as I have not had time to refine it so if anyone wants to add to it please feel free.

    This part is the header:
    <?php

    $hostname_PGH = "xxx.xxx.xxx.xxx"; // replace with your server IP
    $database_PGH = "xxxxxxxx"; // this is the database for keeping track of next port.
    $username_PGH = "xxxxxx"; // nextport username
    $password_PGH = "xxxxxx";// nextport password
    $PGH = mysql_pconnect($hostname_PGH, $username_PGH, $password_PGH) or trigger_error(mysql_error(),E_USER_ERROR);
    // this requests variables.
    $user = $_REQUEST['user'];
    $pw = $_REQUEST['pw'];
    $plan = $_REQUEST['plan'];
    $newpass = $_REQUEST['newpass'];
    $newname = $_REQUEST['newname'];
    $welcome = $_REQUEST['welcome'];
    $mod = $_REQUEST['mod'];

    $colname_Recordset1 = "1";
    mysql_select_db($database_PGH, $PGH);
    $query_Recordset1 = sprintf("SELECT * FROM port", $colname_Recordset1);
    $Recordset1 = mysql_query($query_Recordset1, $PGH) or die(mysql_error());
    $row_Recordset1 = mysql_fetch_assoc($Recordset1);
    $totalRows_Recordset1 = mysql_num_rows($Recordset1);

    $newport = mysql_result($Recordset1, 0, "nextport");

    // teamspeak server info
    $host = "xxx.xxx.xxx.xxx"; //server address
    $port = "xxxxx"; // server tcpquery port
    $sadmin = "xxxxxxx"; // sadmin login
    $spw = "xxxxxxx"; // sadmin password

    // The following determines how many slots they have paid for based on the plan passed from the welcome email.
    if($plan = "TS10")
    {
    $numusers = 10;
    }

    else if($plan == "TS25" || $plan == "Linux Basic w/ TS25" || $plan == "Linux Pro w/ TS25" || $plan == "Linux Plus w/ TS25")
    {
    $numusers = 25;
    }

    else if($plan == "TS50" || $plan == "Linux Basic w/ TS50" || $plan == "Linux Pro w/ TS50" || $plan == "Linux Plus w/ TS50")
    {
    $numusers = 50;
    }

    else if($plan == "TS100" || $plan == "Linux Basic w/ TS100" || $plan == "Linux Pro w/ TS100" || $plan == "Linux Plus w/ TS100")
    {
    $numusers = 100;
    }

    else
    {
    $numusers = 0;
    }

    # FUNCTION TO READ DATA FROM SERVER
    function tcpquery($data)
    # Send a string $data to the server and read
    # answer from the server (including echo and
    # ok or error at the end!
    {
    global $handle;
    fputs($handle, $data."\n");
    $data="";
    $newdata=" ";
    while ($newdata!="")
    {
    $newdata="";
    $newdata=fgets($handle,51234);
    $data.=$newdata;
    }
    return $data;
    }


    ?>

    This code is contained in the body. It accepts user input then sends the info back to itself and displays the server information. Like I said this still needs to be refined. Also you must leave the sleep command in so as to let the tcpquery keep up with you otherwise the script will execute really fast and tcpquery will only perform 3 or 4 actions before it times out.

    <?php
    if($mod == "add")
    {
    $handle=fsockopen($host, $port, $errno, $errstr, 10);
    if (!$handle)
    die ("Error, Please email info@progamerhosting.com with this error information:\n($errno) $errstr");
    socket_set_blocking($handle, 0);

    tcpquery("");
    tcpquery("sel 8800\n");
    tcpquery("slogin $sadmin $spw\n");
    tcpquery("serveradd $newport\n");
    sleep(3);
    tcpquery("sel $newport\n");
    sleep(3);
    tcpquery("slogin $sadmin $spw\n");
    sleep(3);
    tcpquery("dbuseradd $user $pw $pw 1\n");
    sleep(3);
    tcpquery("serverset server_maxusers $numusers\n");
    sleep(3);
    tcpquery("serverset server_password $newpass\n");
    sleep(3);
    tcpquery("serverset server_name $newname\n");
    sleep(3);
    tcpquery("serverset server_welcomemessage $welcome\n");
    sleep(3);
    tcpquery("quit\n");
    fclose($handle);

    ?>
    <strong>Server created sucessfully!</strong></p>
    <p align="left" class="style1">Please write this information down and keep it in a safe place as this is your server connection info:</p>
    <p align="left" class="style1">Server IP: 206.51.230.233:<?php echo $newport; ?></p>
    <p align="left" class="style1">Admin Username: <?php echo $user; ?></p>
    <p align="left" class="style1">Admin Password: <?php echo $pw; ?></p>
    <p align="left" class="style1">Server Password: <?php echo $newpass; ?> </p>
    <?php
    mysql_query("DELETE FROM port");
    $newport++;
    mysql_query("INSERT INTO port (nextport) VALUES('$newport')");
    }
    else
    {

    ?>
    </p>
    <form name="form1" method="post" action="tscreate.php">
    <p><strong>Please enter the following information:</strong></p>
    <table width="50%" border="0">
    <tr>
    <td class="style1">Server password: </td>
    <td><input name="newpass" type="text" id="newpass"></td>
    </tr>
    <tr>
    <td class="style1">Server name: </td>
    <td><input name="newname" type="text" id="newname"></td>
    </tr>
    <tr>
    <td class="style1">Server welcome message: </td>
    <td><input name="welcome" type="text" id="welcome"></td>
    </tr>
    </table>
    <p>
    <input name="mod" type="hidden" id="mod" value="add">
    <input name="user" type="hidden" id="username" value="<?php echo $user; ?>">
    <input name="pw" type="hidden" id="pw" value="<?php echo $pw; ?>">
    <input name="plan" type="hidden" id="plan" value="<?php echo $plan; ?>">
    <input name="Submit" type="submit" class="button" value="Create server"><BR>
    Please note: It will take about 30 seconds to process your request. DO NOT click submit more then once as it may result in recharging your card!!!
    </p>
    </form>
    <p align="left" class="style1">&nbsp;</p>
    <p align="left" class="style1">
    <?php
    }
    ?>
    Also, the link from the email is:

    Well hope you can make sense of what I did here, I will be happy to answer any questions you may have. One last note, its setup to create an admin user with the same username/password as they used for there billing profile. It helps keep tech support/billing easy.

  2. #2
    Join Date
    Jun 2004
    Location
    England
    Posts
    22

    Sql?

    Erm, this is using a mysql database. Wheres the sql to start it off? =/

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Router problems
    By bigteam0385 in forum [TeamSpeak 2] Server Support
    Replies: 4
    Last Post: 24-05-2011, 10:53
  2. Administration page
    By bigteam0385 in forum [TeamSpeak 2] Server Support
    Replies: 5
    Last Post: 16-01-2006, 22:00
  3. Server
    By lars-andre-petersen in forum [TeamSpeak 2] Server Support
    Replies: 70
    Last Post: 26-09-2005, 11:54
  4. RC2 Server Crashing For No Reason
    By Aww You Dead in forum [TeamSpeak 2] Server Support
    Replies: 6
    Last Post: 08-03-2003, 00:49
  5. TeamSpeak Server won't report Statistics to your Webserver/PHP Script
    By T. Boonstra in forum [TeamSpeak Classic] General Questions
    Replies: 0
    Last Post: 21-06-2002, 21:00

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •