Menús de administrador, instructor y visitante.
[CLab.git] / instalar.php
blob2c84902603ec9e5531c3f0d4d9158dc501821064
1 <?php
2 /*Instalador de cLab.*/
3 ?>
4 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="es" lang="es">
6 <head>
7 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
8 <meta http-equiv="Content-Style-type" content="text/css" />
9 <meta http-equiv="Content-Script-type" content="text/javascript" />
10 <meta http-equiv="Content-Language" content="es" />
11 <link rel="StyleSheet" href="estilo.css" type="text/css" />
12 <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
13 <link rel="start" href="/" />
14 <title>Instalador de Control de Laboratorio</title>
15 </head>
16 <body>
17 <?php
18 function CREAR_TBL($TBL,$QUERY) {
19 global $link;
20 $x = @mysql_query("DROP TABLE IF EXISTS $TBL;", $link) or die('!->No se pudo eliminar la tabla "'.$TBL.'".<br /><pre>' . mysql_error() . '</pre>');
21 $x = @mysql_query($QUERY, $link) or die('!->No se pudo crear la tabla "'. $TBL .'".<br /><pre>' . mysql_error() . '</pre>');
22 if ($x) {echo "- Creada: '$TBL'<br />";}
25 if (!isset($_POST['instalar'])) {
26 echo '
27 <b>cLab - Instalador</b><br />
28 <form action="'. $_SERVER['PHP_SELF'] .'" method="post">
29 <table border=0>
30 <tr><td>Configuración MySQL</td></tr>
31 <tr>
32 <td>Dirección del servidor MySQL:</td>
33 <td><input type="text" name="motor" maxlength="50" size="20" value="localhost" /></td>
34 </tr>
35 <tr>
36 <td>Base de datos a utilizar:</td>
37 <td><input type="text" name="base" maxlength="10" size="20" value="" /></td>
38 </tr>
39 <tr>
40 <td>Usuario:</td>
41 <td><input type="text" name="usuario" maxlength="10" size="20" value="" /></td>
42 </tr>
43 <tr>
44 <td>Clave:</td>
45 <td><input type="password" name="clave" maxlength="20" size="20" value="" /></td>
46 </tr>
47 <tr><td><br />Administración</td></tr>
48 <tr>
49 <td>Nombre Administrador:</td>
50 <td><input type="text" name="admin" maxlength="30" size="20" value="" /></td>
51 </tr>
52 <tr>
53 <td>Correo electrónico:</td>
54 <td><input type="text" name="email" maxlength="50" size="20" value="" /></td>
55 </tr>
56 <tr>
57 <td>Clave:</td>
58 <td><input type="password" name="admin_clave" maxlength="20" size="20" value="" /></td>
59 </tr>
60 <tr>
61 <td>Clave (repetir):</td>
62 <td><input type="password" name="admin_clave2" maxlength="20" size="20" value="" /></td>
63 </tr>
64 </table>
65 <br />
66 <input type="submit" name="instalar" value="Instalar" />
67 </form>
69 } else {
70 echo '<b>cLab - Instalador : Instalando</b><br />';
71 echo '<h3>+Creando conexión a la base de datos...</h3><br />';
72 $link = @mysql_connect($_POST['motor'], $_POST['usuario'], $_POST['clave']) or die('Por favor revise sus datos, puesto que se produjo el siguiente error:<br /><pre>' . mysql_error() . '</pre>');
73 mysql_select_db($_POST['base'], $link) or die('!->La base de datos seleccionada "'.$_POST['base'].'" no existe');
74 echo '- Base de datos conectada...<br />';
75 echo '<h3>+Creando Archivo con datos de conexión...</h3><br />';
76 //touch("data.php");
77 //chmod("data.php", 0666);
78 $fh = @fopen("include/data.php", 'w') or die("No se pudo escribir 'data.php'.<br />");
79 if ($fh) {
80 $Datos = "<?php\n";
81 fwrite($fh, $Datos);
82 $Datos = '$motor = '. $_POST['motor'] .";\n" . '$usuario = '. $_POST['usuario'] .";\n". '$clave = '. $_POST['clave'] .";\n" . '$base = '. $_POST['base'] .";\n";
83 fwrite($fh, $Datos);
84 $Datos = "?>\n";
85 fwrite($fh, $Datos);
86 fclose($fh);
88 echo '- Creado<br />';
89 echo '<h3>+Creando Tablas...</h3><br />';
90 $q="CREATE TABLE users ( username varchar(10) primary key, password varchar(32), userid varchar(32), userlevel tinyint(1) unsigned not null, email varchar(50), timestamp int(11) unsigned not null, nombre varchar(100) not null, encargado varchar(100), catedratico varchar(100), tipo tinyint(1) unsigned not null, departamento tinyint(1) unsigned not null);";
91 CREAR_TBL("users", $q);
92 $q="CREATE TABLE active_users (username varchar(30) primary key, timestamp int(11) unsigned not null);";
93 CREAR_TBL("active_users", $q);
94 $q="CREATE TABLE active_guests (ip varchar(15) primary key, timestamp int(11) unsigned not null);";
95 CREAR_TBL("active_guests", $q);
96 $q="CREATE TABLE banned_users (username varchar(30) primary key, timestamp int(11) unsigned not null);";
97 CREAR_TBL("banned_users", $q);
99 echo '<h3>+Creando usuario Admin...</h3><br />';
100 $q = "INSERT INTO users VALUES ('".$_POST['admin'] . "', '" . md5($_POST['admin_clave']) . "', '0', '9', '" . $_POST['email'] . "', " . time() . ",0,0,0,0,0)";
101 @mysql_query($q, $link);
102 echo '- Creado<br />';
103 mysql_close($link);
104 echo '<br /><b>Instalación completa</b><br />';
107 </body>
108 </html>