-
Notifications
You must be signed in to change notification settings - Fork 1
/
usuarios.php
executable file
·387 lines (356 loc) · 15 KB
/
usuarios.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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
<?php
/**
*
* Archivo de usuarios
*
* Manipula los usuarios del sitio
*
* @package TrackYourPenguin
* @since 0.1
* @author Zerquix18
*
**/
require_once( dirname(__FILE__) . '/typ-load.php' );
comprobar( false );
$usuario = obt_usuario_actual();
if( ! es_super_admin() )
$dnd = array("usuario" => $usuario->usuario );
else
$dnd = null;
$u = obt_usuario_actual();
//now everyone can see the users ^-^!
$accion = isset($_GET['accion']) && is_string($_GET['accion']) ? $_GET['accion'] : '';
$post = 'POST' == getenv('REQUEST_METHOD');
switch( $accion ) {
case "agregar":
if( ! es_super_admin() )
typ_die( __("Cheatin', uh?!") );
construir( 'cabecera', __('Add user'), true );
?>
<h3><?php _e("Add user") ?></h3>
<a href="<?php echo url() ?>usuarios.php" class="btn btn-link pull-right">
<?php _e("Back to users") ?> →
</a><hr>
<?php
if( $post ) {
$nombre = trim( @$zerdb->real_escape( strtolower( $_POST['usuario']) ) );
$clave = md5( @$zerdb->real_escape( $_POST['clave'] ) );
$email = trim( @$zerdb->real_escape( strtolower($_POST['email']) ) );
$rango1 = is_numeric(@$_POST['rango']) ? (int) @$_POST['rango'] : '';
$rango2 = $u->rango;
$args = ! comprobar_args( @$_POST['usuario'], @$_POST['clave'], @$_POST['email'], @$_POST['clave2'], @$_POST['rango']);
$vacios = vacios( @$_POST['usuario'], @$_POST['clave'], @$_POST['email'], @$_POST['clave2'], @$_POST['rango'] );
if( $args ) {
typ_die( __("Cheatin', uh?!"));
}elseif( $vacios ) {
agregar_error( __("You can't leave empty fields."));
}elseif( comprobar_rangos($rango1, $rango2 ) ) {
agregar_error( __("Cheatin' to get a better role?") );
}elseif( ! preg_match('/^[a-z0-9-_]{3,12}$/i', $_POST['usuario'] ) ) {
agregar_error( __("I need a valid user. From 3 to 12 characters."));
}elseif( ! filter_var($_POST['email'], FILTER_VALIDATE_EMAIL ) ) {
agregar_error( __("The email is not valid."));
}elseif( existe_usuario( strtolower( $_POST['usuario'] ) ) ) {
agregar_error( __("That user already exists."));
}elseif( existe_email( strtolower($_POST['email'] ) ) ) {
agregar_error( __("That email already exists"));
}elseif( $rango1 == 1) {
agregar_error( __("It can't be super admin!") );
}else{
$zerdb->insert( $zerdb->usuarios, array($nombre, $clave, $email, 1, $rango1, '') );
agregar_info( __("The user has been created."), true, true );
echo redireccion( url() . 'usuarios.php?id='. $zerdb->id, 2 );
}
}
?>
<form class="form-horizontal" action="<?php echo url() . 'usuarios.php?accion=agregar' ?>" method="POST">
<div class="control-group">
<label class="control-label">
<?php _e("User") ?>
</label>
<div class="controls">
<input type="text" name="usuario" <?php if($post) echo 'value="' . @$_POST['usuario'] . '"' ?> required="required"
pattern="^[A-Za-z0-9-_]{3,12}$">
<span class="help-block"><?php _e("Username") ?></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("User password") ?></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("Re-type the user password") ?></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 if($post) echo 'value="'. @$_POST['email'] . '"' ?>>
<span class="help-block"><?php _e("User email") ?></span>
</div>
</div>
<div class="control-group">
<label class="control-label">
<?php _e('Role') ?>
</label>
<div class="controls">
<select name="rango">
<option value="2"><?php _e("Administrator") ?></option>
<option value="3"><?php _e("Updater") ?></option>
</select>
<span class="help-block"><?php _e("Which will be this user's role?") ?></span>
</div>
</div>
<hr>
<center><input type="submit" name="enviar" class="btn btn-primary text-center" value="<?php _e("Add") ?>" id="enviar"></center>
</form>
<?php
break;
case "editar":
if( ! isset($_GET['id']) || ! is_numeric( $_GET['id'] ) )
typ_die( __("I need a valid ID.") );
$u = obt_id( $_GET['id'] );
$usuario = obt_usuario_actual();
if( false == $u )
typ_die( __("The user you specify doesn't exist.") );
if( ! es_super_admin() && $_GET['id'] !== $_SESSION['id'] )
typ_die( __("You are not allowed to be here.") );
if( $u->rango <= $usuario->rango && $_GET['id'] !== $_SESSION['id'] && ! es_super_admin() )
typ_die( __("You can't edit someone's user with a role bigger or the same that you.") );
construir( 'cabecera', sprintf( __("Edit user: %s"), ucfirst($u->usuario) ), true ); ?>
<h3><?php _e("Edit user") ?>: <i><?php echo ucfirst( $u->usuario ) ?></i></h3>
<a href="<?php echo url() ?>usuarios.php?id=<?php echo $u->id ?>" class="btn btn-link pull-right">
<?php _e("Back to user") ?> →
</a><hr>
<?php
if( $post ) {
$nombre = @$zerdb->real_escape( strtolower($_POST['usuario']) );
$email = @$zerdb->real_escape( strtolower($_POST['email']) );
$rango2 = $u->rango;
$rango = ( $u->id !== $_SESSION['id'] ) ? @$_POST['rango'] : $u->rango;
$rango1 = is_numeric($rango) ? (int) $rango : '3';
$args = ! comprobar_args( @$_POST['usuario'], @$_POST['email']);
$vacios = vacios( @$_POST['usuario'], @$_POST['email'] );
$estado = 1;
$hash = '';
$usuario_ = $zerdb->query("SELECT * FROM {$zerdb->usuarios} WHERE usuario = ? AND email != ?", $nombre, $u->email);
$email_ = $zerdb->query("SELECT * FROM {$zerdb->usuarios} WHERE email = ? AND usuario != ?", $email, $u->usuario);
if( $args ) {
typ_die( __("Cheatin', uh?!") );
}elseif( $vacios ) {
agregar_error( __("You can't leave empty fields."), true, true);
}elseif( isset($_POST['rango']) && is_string($_POST['rango'] && $_POST['rango'] > $u->rango) ) {
agregar_error( __("Cheatin' to get a better role?"), true, true);
}elseif( ! preg_match('/^[A-Za-z0-9-_]{3,12}$/', $_POST['usuario'] ) ) {
agregar_error( __("Type a valid username. From 3 to 12 characters."), true, true);
}elseif( ! filter_var($_POST['email'], FILTER_VALIDATE_EMAIL ) ) {
agregar_error( __("The email is not valid."), true, true);
}elseif( $usuario_->nums > 0 ) {
agregar_error( __("That user already exist."), true, true);
}elseif( $email_->nums > 0) {
agregar_error( __("That email already exist."), true, true);
}elseif( $rango == 1 && ! es_super_admin() ) {
agregar_error( __("You can't be super admin."), true, true);
}else{
$zerdb->update( $zerdb->usuarios,array("usuario" => $nombre, "email" => $email, "rango" => $rango) ) -> where('id', $u->id ) -> execute();
agregar_info( __("The user has been updated."), true, true );
}
}
?>
<form class="form-horizontal" action="<?php echo url( true ) ?>" method="POST">
<div class="control-group">
<label class="control-label">
<?php _e("User") ?>
</label>
<div class="controls">
<input type="text" name="usuario" value="<?php if($post) echo @$_POST['usuario']; else echo ucwords($u->usuario) ?>" required="required"
pattern="^[A-Za-z0-9-_]{3,12}$">
<span class="help-block"><?php _e("Username") ?></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" value="<?php if($post) echo @$_POST['email']; else echo strtolower($u->email) ?>">
<span class="help-block"><?php _e("User email") ?></span>
</div>
</div>
<?php if( es_super_admin() ) : ?>
<div class="control-group">
<label class="control-label">
<?php _e("Role") ?>
</label>
<div class="controls">
<?php if( $u->id !== $_SESSION['id'] ) : ?>
<select name="rango">
<?php if( $u->rango == '2' && es_super_admin() ) : ?>
<option value="2"><?php _e("Administrator") ?></option>
<option value="3"><?php _e("Updater") ?></option>
<?php elseif( $u->rango == '3' && es_super_admin() ) : ?>
<option value="3"><?php _e("Updater") ?></option>
<option value="2"><?php _e("Administrator") ?></option>
<?php elseif( $u->rango == '3' && es_admin() ) : ?>
<option value="3"><?php _e("Updater") ?></option>
<?php endif ?>
</select>
<span class="help-block"><?php _e("Which will be this user's role?") ?></span>
<?php elseif( $u->id == $_SESSION['id'] ) : ?>
<span class="help-inline"><?php _e("You can't change your own role.") ?></span>
<?php endif ?>
</div>
</div>
<?php endif ?>
<hr>
<center><input type="submit" name="enviar" class="btn btn-primary text-center" value="<?php _e('Update') ?>" id="enviar"></center>
</form>
<?php
break;
case "eliminar":
if( ! isset($_GET['id'] ) || ! is_numeric($_GET['id'] ) )
typ_die( __("You must specify a valid ID.") );
if( ! es_super_admin() )
typ_die( __("Cheatin', uh?!") );
$u = obt_id( $_GET['id'] );
if( $u == false )
typ_die( __("The selected user doesn't exist.") );
if( $u->id == $_SESSION['id'])
typ_die( __("You can't delete your own user. >.<") );
construir('cabecera', sprintf( __('Delete the user: %s'), $u->usuario ) );
$zerdb->delete($zerdb->usuarios, array("id" => $_GET['id'] ) )->_();
$sesiones->destruir_id( $_GET['id'] ); // bye sessions...
agregar_info( sprintf( __('The user %s has been deleted'), ucfirst($u->usuario) ) );
echo sprintf( __("<ul class=\"pager\"><li class=\"previous\"><a href=\"%s\">← Back</a></li></ul>"), url() . 'usuarios.php');
break;
case "suspender":
if( ! isset($_GET['id'] ) || ! is_numeric($_GET['id'] ) )
typ_die( __("You must specify an ID.") );
if( ! es_super_admin() )
typ_die("You are not allowed to be here.");
$u = obt_id( $_GET['id'] );
if( false == $u )
typ_die( __("The selected user doesn't exist.") );
if( $u->id == $_SESSION['id'])
typ_die( __("You can't ban your own user.") );
if( $u->estado !== "1" )
typ_die( __("This user is already banned.") );
construir('cabecera', sprintf( __("Ban: %s"), ucfirst($u->usuario) ), true );
$x = $zerdb->update($zerdb->usuarios, array("estado" => "0") ) -> where("id", $_GET['id'])->execute();
$sesiones->destruir_id( $u->id );
if( $x )
agregar_info( sprintf( __("The user <strong>%s</strong> has been banned."), ucfirst($u->usuario) ) );
else
echo "Error: " . $zerdb->error;
echo sprintf( __("<ul class=\"pager\"><li class=\"previous\"><a href=\"%s\">← Back</a></li></ul>"), url() . 'usuarios.php');
break;
case "quitar_suspension":
if( ! isset($_GET['id'] ) || ! is_numeric($_GET['id'] ) )
typ_die( __("You must specify an ID.") );
if( ! es_super_admin() )
typ_die( __("You are not allowed to be here.") );
$u = obt_id( $_GET['id'] );
if( false == $u)
typ_die( __("The selected user doesn't exist.") );
if( $u->id == $_SESSION['id'])
typ_die( esc_html("What the fuck are you doing? ><!") ); // xddd
if( $u->estado == "1" )
typ_die( __("This user is not banned.") );
construir('cabecera', sprintf( __("Unbanning: %s"), ucfirst($u->usuario) ), true );
$x = $zerdb->update($zerdb->usuarios, array("estado" => "1") ) -> where("id", $_GET['id'])->execute();
if( $x )
agregar_info( sprintf( __("The user %s has been unbanned."), ucfirst($u->usuario) ) );
else
echo "Error: " . $zerdb->error;
echo sprintf( __("<ul class=\"pager\"><li class=\"previous\"><a href=\"%s\">← Back</a></li></ul>"), url() . 'usuarios.php');
break;
default:
$id = isset($_GET['id']) && is_numeric($_GET['id']) ? true : false;
switch( $id ) {
case true:
$u = obt_id($_GET['id']);
$usuario = obt_id( $_SESSION['id'] );
if( false == $u || $u->id !== $_SESSION['id'] && ! es_admin() )
typ_die( __("This user doesn't exist or you're not allowed to read its data.") );
construir( 'cabecera', ucfirst($u->usuario), true );
?>
<h3><?php _e("User") ?>: <?php echo sprintf( '<em>%s</em>', ucfirst( $u->usuario ) ) ?></h3>
<a href="<?php echo url() ?>usuarios.php" class="btn btn-link pull-right">
<?php _e("Back to users") ?> →
</a><hr>
<p><strong><?php _e("User") ?>:</strong> <i><?php echo ucfirst($u->usuario) ?></i></p>
<p><strong><?php _e("Email") ?>:</strong> <i><?php echo $u->email ?></i></p>
<p><strong><?php _e("Status") ?>:</strong> <i><?php echo estado($u->estado) ?></i></p>
<p><strong><?php _e("Role") ?>:</strong> <i><?php echo rango( $u->id ) ?></i></p>
<p><strong><?php _e('Last update done') ?>:</strong> <i><?php
$q = $zerdb->select($zerdb->log)->like('accion', $u->usuario )->add("ORDER BY id DESC")->limit(1);
if( $q->nums > 0 ) {
$l = json_decode($q->accion);
$t = obt_tracker($l->tracker);
$t = isset($t) ? ucfirst($t->personaje) : __('Unknown tracker');
echo sprintf("<b>%s</b> in <b>%s</b>", mostrar_fecha($q->fecha), $t );
}else{
echo __('No recent updates have been found.');
}
?></i></p><?php
break;
case false:
construir( 'cabecera', __('Users'), true );
?>
<h3> <?php _e("Users") ?> </h3>
<?php if( es_super_admin() ) : ?>
<a href="<?php echo url() . 'usuarios.php?accion=agregar' ?>" class="btn btn-link pull-right">
<i class="icon-plus"></i> <?php _e("Add new") ?></a>
<?php endif ?><hr>
<table class="table table-bordered table-hover">
<tr>
<th><?php _e("User") ?></th>
<th><?php _e("Email") ?></th>
<th><?php _e("Role") ?></th>
<th><?php _e("Status") ?></th>
<th><center>#</center></th>
</tr>
<?php
$users = $zerdb->select( $zerdb->usuarios);
if( $u->rango !== "1" )
$users->where( array('usuario' => $_SESSION['usuario']) );
$r = $users->execute();
while($u = $r->r->fetch_array() ) {
?>
<tr>
<td><?php echo ucfirst($u['usuario']) ?></td>
<td><?php echo $u['email'] ?></td>
<td><?php echo rango( $u['id'] ) ?></td>
<td><?php echo estado( $u['estado'] ) ?></td>
<td><center>
<a class="btn btn-success btn-small" href="<?php echo url() . 'usuarios.php?accion=editar&id=' . $u['id'] ?>"
title="<?php _e("Edit") ?>">
<i class="icon-pencil"></i></a>
<?php if( es_super_admin() && $u['rango'] !== '1' && $u['id'] !== $_SESSION['id'] ) : ?>
<a class="btn btn-danger btn-small" href="<?php echo url() . 'usuarios.php?accion=eliminar&id=' . $u['id'] ?>"
title="<?php _e("Delete") ?>"><i class="icon-trash"></i></a>
<?php endif ?>
<?php if( es_super_admin() && $u['estado'] == '1' && $u['rango'] !== '1' ) : ?>
<a class="btn btn-warning btn-small" title="<?php _e('Ban') ?>" href="<?php echo url() . 'usuarios.php?accion=suspender&id=' . $u['id'] ?>"><i class="icon-ban-circle"></i></a>
<?php elseif( es_super_admin() && $u['estado'] !== '1' && $u['rango'] !== '1' ) : ?>
<a class="btn btn-inverse btn-small" title="<?php _e('Unban') ?>" href="<?php echo url() . 'usuarios.php?accion=quitar_suspension&id=' . $u['id'] ?>"><i class="icon-ban-circle"></i></a>
<?php endif ?>
</a>
<?php
}
?></center></td></table><?php
}
}
construir( 'pies' );