[PHP] DH Chat 0.5

Iniciado por BigBear, Diciembre 04, 2015, 12:23:37 PM

Tema anterior - Siguiente tema

0 Miembros y 1 Visitante están viendo este tema.

Un simple chat que hice en PHP que tiene las siguientes opciones :

  • Solo permite 10 mensajes por lo que borra por antiguedad
  • Filtra malas palabras
  • Se pueden borrar comentarios desde el administrador

    Una imagen :



    Los codigos :

    index.php

    Código: php

    <?php

    // DH Chat 0.5
    // (C) Doddy Hackman 2015

    // Login

    $username = "admin"; // Edit
    $password = "21232f297a57a5a743894a0e4a801fc3"; // Edit

    //

    $index = "admin.php"; // Edit

    if (isset($_GET['poraca'])) {
       
        echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
       <head>
          <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
          <title>Login</title>
          <link rel="shortcut icon" href="images/icono.png">
          <link href="style.css" rel="stylesheet" type="text/css" />
       </head>
       <body>
          <center><br>
             <div class="post">
                <h3>Login</h3>
                <div class="post_body">
                   <img src="images/login.jpg" width="562" height="440" />
                   <br />
                   <form action="" method=POST>
                      Username : <input type=text size=30 name=username /><br /><br />
                      Password : <input type=password size=30 name=password /><br /><br />
                      <input type=submit name=login style="width: 100px;" value=Login /><br /><br />
                   </form>
                </div>
             </div>
          </center>
       </body>
    </html>';
       
        if (isset($_POST['login'])) {
           
            $test_username = $_POST['username'];
            $test_password = md5($_POST['password']);
           
            if ($test_username == $username && $test_password == $password) {
                setcookie("login", base64_encode($test_username . "@" . $test_password));
                echo "<script>alert('Welcome idiot');</script>";
                $ruta = "http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/" . $index;
                echo '<meta http-equiv="refresh" content="0; url=' . htmlentities($ruta) . '" />';
            } else {
                echo "<script>alert('Fuck You');</script>";
            }
        }
       
    } else {
        echo '<meta http-equiv="refresh" content="0; url=http://www.petardas.com" />';
    }

    // The End ?

    ?>


    admin.php

    Código: php

    <?php

    // DH Chat 0.5
    // (C) Doddy Hackman 2015

    error_reporting(0);

    // Login

    $username = "admin"; // Edit
    $password = "21232f297a57a5a743894a0e4a801fc3"; // Edit

    // DB

    $host  = "localhost"; // Edit
    $userw = "root"; // Edit
    $passw = ""; // Edit
    $db    = "chat"; // Edit

    if (isset($_COOKIE['login'])) {
       
        $st = base64_decode($_COOKIE['login']);
       
        $plit = explode("@", $st);
        $user = $plit[0];
        $pass = $plit[1];
       
        if ($user == $username and $pass == $password) {
           
            echo '
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
       <head>
          <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
          <title>DH Chat 0.5</title>
          <link rel="shortcut icon" href="images/icono.png">
          <link href="style.css" rel="stylesheet" type="text/css" />
       </head>
       <body>
       <center>
       ';
           
            mysql_connect($host, $userw, $passw);
            mysql_select_db($db);
           
            echo '         <br><img src="images/chat.png" /><br>';
           
            if (isset($_POST['instalar'])) {
               
                $todo = "create table mensajes (
    id_comentario int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
    mensaje TEXT NOT NULL,
    apodo VARCHAR(255) NOT NULL,
    PRIMARY KEY (id_comentario));
    ";
               
                $todo2 = "create table insultos (
    id_insulto int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
    mensaje TEXT NOT NULL,
    PRIMARY KEY (id_insulto));
    ";
               
                if (mysql_query($todo)) {
                    if (mysql_query($todo2)) {
                       
                        $insultos = array(
                            "lammer",
                            "lamer",
                            "maricon",
                            "noob"
                        );
                       
                        foreach ($insultos as $con) {
                            @mysql_query("INSERT INTO insultos(id_insulto,mensaje)values(NULL,'$con')");
                        }
                       
                        echo "<script>alert('Installed');</script>";
                        echo '<meta http-equiv="refresh" content=0;URL=>';
                    }
                } else {
                    echo "<script>alert('Error');</script>";
                }
            }
           
            if (mysql_num_rows(mysql_query("show tables like 'mensajes'"))) {
               
                //
               
                $re = mysql_query("select * from mensajes order by id_comentario ASC");
               
                if (isset($_GET['id'])) {
                    if (is_numeric($_GET['id'])) {
                        if (@mysql_query("delete from mensajes where id_comentario='" . $_GET['id'] . "'")) {
                            echo "<script>alert('Comment deleted');</script>";
                        } else {
                            echo "<script>alert('Error');</script>";
                        }
                    }
                }
               
                $sql       = "select id_comentario from mensajes";
                $resultado = mysql_query($sql);
                $cantidad  = mysql_num_rows($resultado);
               
                echo '
                <div class="post">
                    <h3>Comments : ' . $cantidad . '</h3>
                       <div class="post_body"><br>';
                if ($cantidad <= 0) {
                    echo '<b>No entries found</b><br>';
                } else {
                    echo "<table>";
                    echo "<td><b>ID</b></td><td><b>Nick</b></td><td><b>Text</b></td><td><b>Option</b></td><tr>";
                   
                    while ($ver = mysql_fetch_array($re)) {
                        echo "<td>" . htmlentities($ver[0]) . "</td><td>" . htmlentities($ver[2]) . "</td><td>" . htmlentities($ver[1]) . "</td><td><a href=?id=" . htmlentities($ver[0]) . ">Delete</a></td><tr>";
                    }
                   
                    echo "</table>";
                   
                }
               
                echo '                <br></div>
                </div>';
               
                if (isset($_POST['new_word'])) {
                    $in = $_POST['word'];
                    if (@mysql_query("INSERT INTO insultos(id_insulto,mensaje)values(NULL,'$in')")) {
                        echo "<script>alert('Word added');</script>";
                    } else {
                        echo "<script>alert('Error');</script>";
                    }
                }
               
                if (isset($_GET['del_word'])) {
                    if (is_numeric($_GET['del_word'])) {
                        if (@mysql_query("delete from insultos where id_insulto='" . $_GET['del_word'] . "'")) {
                            echo "<script>alert('Word deleted');</script>";
                        } else {
                            echo "<script>alert('Error');</script>";
                        }
                    }
                }
               
                echo '
             <div class="post">
                <h3>Block words</h3>
                <div class="post_body"><br>
                ';
               
                echo "
    <form action='' method=POST>
    <b>Word : </b><input type=text name=word>
    <input type=submit name=new_word style='width: 100px;' value=Add>
    </form>";
               
                echo '
                <br>
                </div>
             </div>
             ';
               
               
                $sql       = "select id_insulto from insultos";
                $resultado = mysql_query($sql);
                $cantidad  = mysql_num_rows($resultado);
               
                echo '
             <div class="post">
                <h3>Words blocked : ' . $cantidad . '</h3>
                <div class="post_body"><br>
                ';
               
                $rea = mysql_query("select * from insultos order by id_insulto ASC");
               
                if ($cantidad <= 0) {
                    echo '<b>No entries found</b><br>';
                } else {
                    echo "<table>";
                    echo "<td>ID</td><td>Word</td><td>Option</td><tr>";
                    while ($ver = mysql_fetch_array($rea)) {
                        echo "<td>" . htmlentities($ver[0]) . "</td><td>" . htmlentities($ver[1]) . "</td><td><a href=?del_word=" . htmlentities($ver[0]) . ">Delete</a></td><tr>";
                    }
                   
                    echo "</table>";
                   
                }
               
                echo '
                <br>
                </div>
             </div>
             ';
               
            } else {
               
                echo '
                <div class="post">
                    <h3>Installer</h3>
                       <div class="post_body">';
               
                echo "
    <form action='' method=POST>
    <h2>Do you want install DH Chat 0.5 ?</h2><br>
    <input type=submit name=instalar style='width: 100px;' value=Install>
    </form><br>";
                echo '                </div>
                </div>';
            }
           
            echo ' 
       <br><h3>(C) Doddy Hackman 2015</h3><br>
       </center>
       </body>
    </html>';
           
            mysql_close();
            exit(1);
           
        } else {
            echo "<script>alert('Fuck You');</script>";
        }
       
    } else {
        echo '<meta http-equiv="refresh" content="0; url=http://www.petardas.com" />';
    }

    // The End ?

    ?>


    style.css

    Código: css

    /*

    ==-----------------------------------==
    || Name : DH Theme                   ||
    || Version : 0.8                     || 
    || Author : Doddy H                  ||
    || Description: Templante            ||
    || Date : 14/1/2015                  ||
    ==-----------------------------------==

    */

    body {
    background:transparent url("images/fondo.jpg") repeat scroll 0 0;
    color:gray;
    font-family:helvetica,arial,sans-serif;
    font-size:14px;
    text-align:center;
    }

    a:link {
    text-decoration:none;
    color:orange;
    }
    a:visited {
    color:orange;
    }
    a:hover {
    color:orange;
    }

    td,tr {
    border-style:solid;
    border-color: gray;
    border-width: 1px;
    background: black;
    border: solid #222 2px;
    color:gray;
    font-family:helvetica,arial,sans-serif;
    font-size:14px;
    text-align:center;

    word-wrap: break-word;
    word-break:break-all;
    }

    input {
    border-style:solid;
    border-color: gray;
    border-width: 1px;
    background: black;
    border: solid #222 2px;
    color:gray;
    font-family:helvetica,arial,sans-serif;
    font-size:14px;
    }

    .post {
    background-color:black;
    color:gray;
    margin-bottom:10px;
    width:600px;
    word-wrap: break-word;
    }

    .post h3 {
    background-color:black;
    color:orange;
    background-color:#000;
    border: solid #222 2px;
    -webkit-border-radius: 4px;
    -moz-border-radius: 4px;
    border-radius: 4px;
    padding:5px 10px;
    }

    .post_body {
    background-color:black;
    margin:-20px 0 0 0;
    color:white;
    background-color:#000;
    border: solid #222 2px;
    -webkit-border-radius: 4px;
    -moz-border-radius: 4px;
    border-radius: 4px;
    padding:5px 10px;
    }

    /* The End ? */


    chat.php

    Código: php

    <?php

    //DH Chat 0.5
    //(C) Doddy Hackman 2015

    // DB

    $host = "localhost"; // Edit
    $user = "root"; // Edit
    $pass = ""; // Edit
    $db   = "chat"; // Edit

    //

    error_reporting(0);

    mysql_connect($host, $user, $pass);
    mysql_select_db($db);

    echo '<link href="chat.css" rel="stylesheet" type="text/css" />';

    echo "<table border=0 width='210' style='table-layout: fixed'>";
    echo "<td><b>DH Chat 0.5</b></td><tr>";


    $sumo = mysql_query("SELECT MAX(id_comentario) FROM mensajes");

    $s = mysql_fetch_row($sumo);

    foreach ($s as $d) {
        $total = $d;
    }

    $test = $total - 10;

    if ($test <= 0) {
        next;
    } else {
        $resto = $test;
       
        for ($i = 1; $i <= $resto; $i++) {
            @mysql_query("DELETE FROM mensajes where id_comentario='$i'");
        }
    }

    $re = @mysql_query("select * from mensajes order by id_comentario DESC");

    while ($ver = @mysql_fetch_array($re)) {
        echo "<td><b>" . htmlentities($ver[2]) . "</b> : " . htmlentities($ver[1]) . "</td><tr>";
    }


    echo "<br><br><td><br><b>Comment</b><br><br>   
    <form action='' method=POST>
    Nick : <input type=text name=apodo size=20><br><br>
    Text : <input type=text name=msg size=20><br><br>
    <input type=submit name=chatentro style='width: 100px;' value=Send>
    </form>
    <tr>
    <td><b>Coded By Doddy H</b></td><tr>
    </table>";


    if (isset($_POST['chatentro'])) {
       
        $sumo = mysql_query("SELECT MAX(id_comentario) FROM mensajes");
       
        $s = mysql_fetch_row($sumo);
       
        foreach ($s as $d) {
            $x_id = $d + 1;
        }
       
        $apodo   = htmlentities(addslashes($_POST['apodo']));
        $mensaje = htmlentities(addslashes($_POST['msg']));
       
        $apodo   = substr($apodo, 0, 70);
        $mensaje = substr($mensaje, 0, 70);
       
        $rex = mysql_query("select mensaje from insultos");
       
        while ($con = mysql_fetch_array($rex)) {
            $mensaje = str_replace($con[0], "#$!*", $mensaje);
            $apodo   = str_replace($con[0], "#$!*", $apodo);
        }
       
        if (is_numeric($x_id)) {
            @mysql_query("INSERT INTO mensajes(id_comentario,apodo,mensaje)values('$x_id','$apodo','$mensaje')");
        }
       
        echo '<meta http-equiv="refresh" content=0;URL=>';
       
    }

    mysql_close();

    // The End ?

    ?>


    chat.css

    Código: css

    /*

    ==-----------------------------------==
    || Name : DH Theme                   ||
    || Version : 0.8                     || 
    || Author : Doddy H                  ||
    || Description: Templante            ||
    || Date : 14/1/2015                  ||
    ==-----------------------------------==

    */

    body {
    color:gray;
    font-family:helvetica,arial,sans-serif;
    font-size:14px;
    text-align:center;
    }

    a:link {
    text-decoration:none;
    color:orange;
    }
    a:visited {
    color:orange;
    }
    a:hover {
    color:orange;
    }

    td,tr {
    border-style:solid;
    border-color: gray;
    border-width: 1px;
    background: black;
    border: solid #222 2px;
    color:gray;
    font-family:helvetica,arial,sans-serif;
    font-size:14px;
    text-align:center;

    word-wrap: break-word;
    word-break:break-all;
    }

    input {
    border-style:solid;
    border-color: gray;
    border-width: 1px;
    background: black;
    border: solid #222 2px;
    color:gray;
    font-family:helvetica,arial,sans-serif;
    font-size:14px;
    }

    .post {
    background-color:black;
    color:gray;
    margin-bottom:10px;
    width:600px;
    word-wrap: break-word;
    }

    .post h3 {
    background-color:black;
    color:orange;
    background-color:#000;
    border: solid #222 2px;
    -webkit-border-radius: 4px;
    -moz-border-radius: 4px;
    border-radius: 4px;
    padding:5px 10px;
    }

    .post_body {
    background-color:black;
    margin:-20px 0 0 0;
    color:white;
    background-color:#000;
    border: solid #222 2px;
    -webkit-border-radius: 4px;
    -moz-border-radius: 4px;
    border-radius: 4px;
    padding:5px 10px;
    }

    /* The End ? */


    test.php

    Código: php

    <body background="test.jpg">

    <?php

    include("chat.php");

    ?>


    Si quieren bajar el programa lo pueden hacer de No tienes permitido ver los links. Registrarse o Entrar a mi cuenta.

    Cualquier sugerencia para mejorar este proyecto diganla para mejorar.

    Saludos.

Es mi sistema de seguridad personal xD.

HOLA!!!

@No tienes permitido ver los links. Registrarse o Entrar a mi cuenta , lee el codigo, redirige cuando Login Falla. por ende si hay alguien que esta intentando entrar va a ser redireccionado a esa web en cada intento fallido.

GRACIAS POR LEER!!!
"Algunos creen que soy un bot, puede que tengan razon"
"Como no se puede igualar a Dios, ya he decidido que hacer, ¡SUPERARLO!"
"La peor de las ignorancias es no saber corregirlas"

*Shadow Scouts Team*                                                No tienes permitido ver los links. Registrarse o Entrar a mi cuenta

Diciembre 14, 2015, 08:02:48 PM #3 Ultima modificación: Diciembre 14, 2015, 08:04:24 PM por Doddy
Es para sorprender al atacante.

Diciembre 14, 2015, 09:01:20 PM #4 Ultima modificación: Diciembre 14, 2015, 09:16:52 PM por Doddy
No tienes permitido ver los links. Registrarse o Entrar a mi cuenta
No tienes permitido ver los links. Registrarse o Entrar a mi cuenta
Es para sorprender al atacante.

Buena website para los necesitados XD

Saludos.

Sino te gusta te puedo poner una pagina de negros musculosos , si queres edito el link y queda como tu version privada xD.

Igual deja de desviar el tema y habla sobre el codigo.

Saludos.

A mi no me interesa editar nada , deja de desviar el tema central del post.

@No tienes permitido ver los links. Registrarse o Entrar a mi cuenta si te molesta que el script te redirija a ese tipo de webs edita la linea 59 y listo.
Cierro el post para evitar que se siga desvirtuando.

Saludos!