-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstalar.php
executable file
·292 lines (283 loc) · 11.6 KB
/
instalar.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
<?php
/**
* Archivo de instalación de TrackYourPenguin
*
* @author Zerquix18
* @link http://trackyourpenguin.com/
* @since 0.1.0
*
**/
require_once( dirname(__FILE__) . "/typ-load.php"); // Requerimos todo.
if( version_compare(PHP_VERSION, '5.2.0', '<' ) )
typ_die( __("I'm sorry! TrackYourPenguin needs a PHP version greater than 5.2.0 :(") );
if( file_exists( PATH . 'README.md') )
unlink( PATH . 'README.md');
$paso = (isset($_GET['paso']) && is_string($_GET['paso'])) ? $_GET['paso'] : ''; // El paso por el que vamos.
/* Construye la cabecera */
function construir_cabecera() {
?>
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<title><?php _e("Installation") ?> - TrackYourPenguin</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="<?php echo INC . CSS . 'cyborg.css' ?>" rel="stylesheet">
<style type="text/css">
body { padding-top: 60px;
padding-bottom: 40px;
}
</style>
<link href="<?php echo INC . CSS . 'cyborg.min.css' ?>" rel="stylesheet">
<!--[if lt IE 9]>
<script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body>
<div class="container">
<div class="hero-unit">
<?php
}
function construir_pies() { global $v;
?>
</div>
<hr>
<footer>
<p>© <a href="//trackyourpenguin.com" target="_blank">TrackYourPenguin, <?php _e("version") ?> <strong><?php echo $v ?></strong></a></p>
</footer>
</div>
</body>
</html>
<?php
}
function error_renombrar() {
echo __('There was an error when renaming the file. It seems like your hosting does not allow it. Please rename "<strong>typ-config-sample.php</strong>" to "<strong>typ-config.php</strong>"');
}
/* ¿Ya hemos instalado */
function comp() {
if( comprobar_instalacion() ) {
agregar_error( __("<h2><strong>You already installated.</strong></h2><hr> TrackYourPenguin was already installed, and there's not need to install it again."), false, false);
construir_pies();
exit();
}
}
construir_cabecera();
switch( $paso ) {
case "1":
comp();
$file = 'typ-config-sample.php';
$file2 = 'typ-config.php';
if( !file_exists($file) && !file_exists($file2) )
typ_die( __("Missing both files: typ-config.php and typ-config-sample.php") );
if( !file_exists( PATH . $file2 ) ) : //si no existe typ-config.php
require_once("./" . $file);
$test = new zerdb(DB_HOST, DB_USUARIO, DB_CLAVE, DB_NOMBRE);
if( $test->ready ) :
if( @rename( PATH . $file, PATH . $file2) )
header("Location: " . url() . 'instalar.php?paso=2');
else
agregar_error( error_renombrar() );
else:
$post = "POST" == getenv('REQUEST_METHOD');
if( $post ) {
if( comprobar_args($_POST['language']) && $_POST['language'] !== TYP_LANG )
actualizar_lenguaje( $_POST['language'] );
$test = new zerdb( @$_POST['host'], @$_POST['usuario'], @$_POST['clave'], @$_POST['db']);
if( $test && $test->ready ) {
$data = file_get_contents($file);
$reemplazar = array(
"dbhost" => trim($_POST['host']),
"dbname" => trim($_POST['db']),
"dbuser" => trim($_POST['usuario']),
"dbpass" => trim($_POST['clave'])
);
$actualizar = str_replace( array_keys($reemplazar), array_values($reemplazar), $data); // aquí el nuevo archivo (typ-config.php)
if( false == ($f = @fopen($file, "w") ) ):
agregar_error( sprintf( __("Can't open file :/, please replace <strong>typ-config-sample.php</strong> for the code below and rename it to <strong>typ-config.php</strong>") ) );
echo '<br><br><textarea rows="25" readonly="readonly" style="width:100%">' . $actualizar . '</textarea>';
construir_pies();
exit;
else:
$write = @fwrite($f, $actualizar);
$renombrar = @rename( PATH . $file, PATH . $file2);
fclose($f);
if( ! $write ) :
agregar_error( __("Can't rewrite file :/, please replace <strong>typ-config-sample.php</strong> by the code below and rename it to <strong>typ-config.php</strong>, or, or if it already exists <strong>typ-config.php</strong>, update it with this:") . '<br><br><textarea rows="25" readonly="readonly">' . $actualizar . '</textarea>');
construir_pies();
exit;
elseif( ! $renombrar ) :
agregar_error( error_renombrar() );
else:
exit( header("Location: instalar.php?paso=2") );
endif;
endif;
}else{
agregar_error( sprintf( __("MySQL connect failed. Error MySQL: %s "), $test->error ) );
}
}
?>
<h2><?php _e("There was an error connecting to the database") ?></h2>
<p><?php _e("There was an error while connectiong to the database. You can make the connection from here. The data you will type here will be provided by your hosting.") ?></p><br>
<form class="form-horizontal" method="POST">
<div class="control-group">
<label class="control-label">
<?php _e("Host") ?>
</label>
<div class="controls">
<input type="text" name="host" required="required" <?php if($post) : ?>value="<?php echo $_POST['host'] ?>"<?php endif ?>>
<span class="help-block"><?php _e("MySQL database host, most of the time it is localhost") ?></span>
</div>
</div>
<div class="control-group">
<label class="control-label">
<?php _e("Name") ?>
</label>
<div class="controls">
<input type="text" name="db" required="required" <?php if($post) : ?>value="<?php echo $_POST['db'] ?>"<?php endif ?>>
<span class="help-block"><?php _e("Database name") ?></span>
</div>
</div>
<div class="control-group">
<label class="control-label">
<?php _e("User") ?>
</label>
<div class="controls">
<input type="text" name="usuario" required="required" <?php if($post) : ?>value="<?php echo $_POST['usuario'] ?>"<?php endif ?>>
<span class="help-block"><?php _e("Database user") ?></span>
</div>
</div>
<div class="control-group">
<label class="control-label">
<?php _e("Password") ?>
</label>
<div class="controls">
<input type="text" name="clave" <?php if($post) : ?>value="<?php echo $_POST['clave'] ?>"<?php endif ?>>
<span class="help-block"><?php _e("Database password") ?></span>
</div>
</div>
<div class="control-group">
<label class="control-label">
<?php _e("Language") ?>
</label>
<div class="controls">
<select name="language">
<?php foreach($lenguajest as $a => $b): ?>
<option <?php if($a == TYP_LANG ) echo 'selected="selected"' ?> value="<?php echo $a ?>"><?php echo $b ?></option>
<?php endforeach ?>
</select>
<span class="help-block"><?php _e("Language for the site") ?></span>
</div>
</div>
<center><input type="submit" class="btn btn-primary btn-large" value="<?php _e("Connect") ?>"></center>
</form>
<?php
endif;
else: // si existe typ-config.php
require_once( './' . $file2 );
if( $zerdb->ready ) :
exit( header("Location: instalar.php?paso=2") );
else:
agregar_error( sprintf( __("<h2>Error establishing a database connection.</h2><p>It can't connect. Please check your <strong>typ-config.php</strong>, and here is the error returned by MySQL: <strong>%s</strong>"), $zerdb->error) );
endif;
endif;
break;
case "2":
if( ! ( file_exists('./typ-config.php') && $zerdb->ready) )
exit( header("Location: instalar.php?paso=1") );
if( !$zerdb->select($zerdb->usuarios, "*")->_() )
header("Location: instalar.php" );
comp(); //here we're...
/** TRAIGAN A LAS TABLAAAAAAAAAAAAAAS **/
require_once( PATH . INC . 'esquema.php');
foreach($sql as $a => $b)
$zerdb->query($b); //inserta las tablas :3
$post = 'POST' == getenv('REQUEST_METHOD');
?>
<h2><?php _e("Welcome to the installation") ?></h2>
<hr>
<?php if( ! $post ) { ?>
<?php _e("With this guide you will be able to install TrackYourPenguin easily, you just have to fill the following fields... :)") ?>
<?php
}else{
$usuario = @$zerdb->real_escape( strtolower($_POST['usuario']) );
$clave = md5( @$zerdb->real_escape($_POST['clave']) );
$email = @$zerdb->real_escape( $_POST['email'] );
if( ! comprobar_args( @$_POST['usuario'], @$_POST['clave'], @$_POST['email'] ) ) {
agregar_error( __("Cheatin', uh?!") );
}elseif( vacios( $_POST['usuario'], $_POST['clave'], $_POST['email'] ) ) {
agregar_error( __("You can't leave empty fields.") );
}elseif( ! preg_match('/^[a-z0-9_-]{3,12}$/', $usuario) ) {
agregar_error( __("The user doesn't look valid. Remember it must have 3-12 characters.") );
}elseif( strlen($_POST['email']) > 60) {
agregar_error( __("Are you sure that your email is so long?") );
}elseif( ! filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) ) {
agregar_error( __("The email you typed is too long.") );
}elseif( $_POST['clave'] !== $_POST['clave2'] ) {
agregar_error( __("The passwords don't match." ) );
}elseif( $_POST['dbp'] !== DB_CLAVE ) {
agregar_error( __("The typed password don't match with the database password.") );
}else{
$path = dirname($_SERVER['PHP_SELF']) !== '/' ? dirname($_SERVER['PHP_SELF']) : '';
$url = 'http://' . $_SERVER['HTTP_HOST'] . $path;
$insertar = $zerdb->insert($zerdb->usuarios, array($usuario, $clave, $email, 1, 1, '') ) or die( $zerdb->error );
$insertar2 = $zerdb->insert($zerdb->config, array("TrackYourPenguin", $url, json_encode( array("tema" => "bootstrap") ) ) ) or die( $zerdb->error );
agregar_info( sprintf( __('<h2> Installation completed </h2><br> You have installed TrackYourPenguin successfully. Now you can <a href="%s">log in</a> to continue. :)'), url() . 'acceso.php' ) );
construir_pies();
exit();
}
}
?>
<hr>
<form method="POST" class="form-horizontal">
<div class="control-group">
<label class="control-label">
<?php _e("User") ?>:
</label>
<div class="controls">
<input type="text" name="usuario" id="usuario" required="required" <?php echo ($post) ? 'value="' . $_POST['usuario'] . '"' : '' ?>>
<span class="help-block"><?php _e("Your username for this site") ?></span>
</div>
</div>
<div class="control-group">
<label class="control-label">
<?php _e("Password") ?>
</label>
<div class="controls">
<input type="password" name="clave" id="clave" required="required">
<span class="help-block"><?php _e("Your password to log in") ?></span>
</div>
</div>
<div class="control-group">
<label class="control-label">
<?php _e("Re-type password") ?>
</label>
<div class="controls">
<input type="password" name="clave2" id="clave2" required="required">
<span class="help-block"><?php _e("Make sure this is the password that you want") ?></span>
</div>
</div>
<div class="control-group">
<label class="control-label">
<?php _e("Email") ?>
</label>
<div class="controls">
<input type="email" name="email" id="email" required="required" <?php echo ($post) ? 'value="' . $_POST['email'] . '"' : '' ?>>
<span class="help-block"><?php _e("Your email, the one you use the most") ?></span>
</div>
</div>
<div class="control-group">
<label class="control-label">
<?php _e("Database password") ?>
</label>
<div class="controls">
<input type="text" name="dbp" id="dbp" required="required">
<span class="help-block"><?php _e("Just to be sure") ?></span>
</div>
</div>
<hr>
<center><input type="submit" name="enviar" value="<?php _e("Send") ?>" class="btn btn-large btn-primary"></center>
<?php
break;
default:
header("Location: instalar.php?paso=1");
}
construir_pies();