Server creation script

Status
Not open for further replies.

Norvik

Retired Staff
Contributor
Jul 18, 2015
635
588
157
Just made this because I was bored and ye idk.

Page: Home
qM2UejE.png

Page: Serverlist
YI9sLWY.png

Page: Create Server
R9lkwIO.png
You definitely shouldn't use it without making any changes. It's meant to give you an idea on how to code such stuff and it's highly recommended to add some kind of captcha before using it on a public website since users could create unlimited servers otherwise. You should also put the config file outside of your website root since it's insecure to keep it where it is right now.

b3Cn9ng.png
ntevPrK.png
 

Norvik

Retired Staff
Contributor
Jul 18, 2015
635
588
157
I think he means to limit servers being created by ones IP address.
lmao I'm retarded.

Take a look at the following script to see an example of getting the users IP. You can simple copy the auth stuff from that script.
PHP:
<?php
    /* Give your Session a name to break Session cookie stealers - and be cool :^) */
    session_name('MySecretSession');

    /* Start the Session */
    session_start();

    /* Define maximum attempts of failed logins */
    $maxFails = 3;

    /* Absolute path to the IP log file */
    $ipLog = __DIR__ . '/ips.txt';

    /* Declare an numeric array with passwords in it */
    $passwords = [
    'Cake',
    'Cookie'
    ];

    /* Create IP log file if it doesn't exist */
    if (!file_exists($ipLog)) {
        touch($ipLog);
    }

    /* Get the user's IP address - Source: http://stackoverflow.com/a/55790/5794450*/
    if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
        $userIp = $_SERVER['HTTP_CLIENT_IP'];
        } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
        $userIp = $_SERVER['HTTP_X_FORWARDED_FOR'];
        } else {
        $userIp = $_SERVER['REMOTE_ADDR'];
    }

    /* If fail variable does not exist, create it */
    if (!isset($_SESSION['fails'])) {
        $_SESSION['fails'] = 0;
    }

    /* If the user failed three times */
    if ($_SESSION['fails'] == 3 && !strstr(file_get_contents($ipLog), $userIp)) {
        /* Add the user's IP to a list of banned IPs if it doesn't already contain it */
        $myfile = file_put_contents('ips.txt', $userIp.PHP_EOL , FILE_APPEND | LOCK_EX);
    }

    /* If user exceeded the count of maximal login attempts */
    if (isset($_SESSION['fails']) && $_SESSION['fails'] >= 3 || strpos(file_get_contents($ipLog), $userIp) !== false) {
        /* Kill the script and display error message to user */
        die('<font color="red">Your login tries exceeded the maximum count of of failed logins allowed.</font>');
    }

    /* If logout is requested */
    if (isset($_GET['logout'])) {
        /* Destroy the Session */
        session_destroy();
   
        /* Redirect the user */
        header('Location: /protected.php');
   
        /* Kill the script to prevent code being executed after the redirect */
        die();
    }

    /* If action is set */
    if (isset($_POST["action"]) && !empty($_POST['action'])) {
        /* If authentication was requested */
        if ($_POST['action'] == 'auth') {
       
            /* Set password variable for easier use */
            $password = $_POST['password'];
       
            /* If password list doesn't include the user's one */
            if (!(in_array($password, $passwords))) {
                /* Increase fail variable */
                $_SESSION['fails']++;
           
                /* Set authentication error message */
                $triesLeft = ($maxFails - $_SESSION['fails']);
                $_SESSION['authError'] = "The password you have entered is invalid. You have $triesLeft tries left.";
           
                /* Redirect the user */
                header('Location: /protected.php');
           
                /* Kill the script to prevent code being executed after the redirect */
                die();
            }
       
            /* If login was successful */
            unset($_SESSION['fails']);
       
            /* Set Session auth variable */
            $_SESSION['auth'] = $password;
       
            /* Redirect the user */
            header('Location: /protected.php');
       
            /* Kill the script to prevent code being executed after the redirect */
            die();
       
        }
    }

    /* If user is authenticated */
    if (isset($_SESSION['auth'])) {
        /* If password expired while the user was logged in */
        if (!in_array($_SESSION['auth'], $passwords)) {
            /* Set authentication error message */
            $_SESSION['authError'] = 'Your password expired.';
       
            /* Unset the auth parameter */
            unset($_SESSION['auth']);
       
            /* Redirect the user */
            header('Location: /protected.php');
       
            /* Kill the script to prevent code being executed after the redirect */
            die();
        }
    }

    /* If user is not authenticated */
    if (!isset($_SESSION['auth'])):
?>
<div>
    <?php /* If authError is set, display and unset it */
    if (isset($_SESSION['authError'])): ?>
    <font color="red"><?=$_SESSION['authError']?></font><br>
    <?php endif; unset($_SESSION['authError']); ?>
    Verify your identity:
    <form action="/protected.php" method="post">
        <input type="hidden" name="action" value="auth">
        <input type="password" name="password">
        <input type="submit" value="Authenticate">
    </form>
</div>
<?php else: ?>
<div>
    You are authenticated with this password: <?=$_SESSION['auth']?><br>
    <a href="/protected.php?logout">Logout</a>
</div>  
<?php endif; ?>
 

ZorialCorn28

Member
Mar 19, 2016
6
0
33
Code:
<?php
return (object) array(
  'appInfo' => (object) array(
    'pageTitle' => 'Kreator serwerow TS3',
    'pageHeader' => 'Kreator serwerow TS3',
    'pageSubHeader' => 'Stworz swoj serwer TeamSpeak3 za darmo!'
  ),
  'appSettings' => (object) array(
    'maxSlots' => 150
  ),
  'teamspeakInfo' => (object) array(
    'host' => 'hostserv.pl',
    'username' => 'serveradmin',
    'password' => '12345',
    'portQuery' => '10011'
  )
);
?>
 

ZorialCorn28

Member
Mar 19, 2016
6
0
33
@Ridicc
Config.php ? This is the code
Code:
<?php
return (object) array(
  'appInfo' => (object) array(
    'pageTitle' => 'Kreator serwerow TS3',
    'pageHeader' => 'Kreator serwerow TS3',
    'pageSubHeader' => 'Stworz swoj serwer TeamSpeak3 za darmo!'
  ),
  'appSettings' => (object) array(
    'maxSlots' => 150
  ),
  'teamspeakInfo' => (object) array(
    'host' => 'hostserv.pl',
    'username' => 'serveradmin',
    'password' => '12345',
    'portQuery' => '10011'
  )
);
?>
 

ULDIN

Well-Known Member
Mar 14, 2016
95
33
108
You may not talk in other languages than English.
what do you need?
Maks. teamspeak3 create limited (IP) options + captche add please ?

TR : aynı IP üzerinden 1 tane ts açılabilecek ek olarak recatche (doğrulama) ekleyebilecek isen güzel olur.
 

foufos

New Member
Jan 5, 2017
31
2
20
Just made this because I was bored and ye idk.

Page: Home
qM2UejE.png

Page: Serverlist
YI9sLWY.png

Page: Create Server
R9lkwIO.png
You definitely shouldn't use it without making any changes. It's meant to give you an idea on how to code such stuff and it's highly recommended to add some kind of captcha before using it on a public website since users could create unlimited servers otherwise. You should also put the config file outside of your website root since it's insecure to keep it where it is right now.

i have edited this to include a register and a login page thanks

@Ridicc heres the preview of my site:
Register module i made: https://gyazo.com/792b73a379e5dadd552b5961a36c87e0
login module: https://gyazo.com/b44e98ce3f870adb9b105ef77aa365e2
once u login u can use create a server tab :)
thanks again for the script
 
Last edited by a moderator:
Status
Not open for further replies.
Top