Example #1
0
 protected function private_core()
 {
     $this->agente = new agente();
     $fslog = new fs_log();
     $this->historial = $fslog->all_by('login');
     if (isset($_POST['nnick'])) {
         $nu = $this->user->get($_POST['nnick']);
         if ($nu) {
             $this->new_error_msg('El usuario <a href="' . $nu->url() . '">ya existe</a>.');
         } else {
             if (isset($_POST['nadmin']) and !$this->user->admin) {
                 $this->new_error_msg('Solamente un administrador puede crear otro administrador.');
             } else {
                 $nu = new fs_user();
                 $nu->nick = $_POST['nnick'];
                 if ($nu->set_password($_POST['npassword'])) {
                     $nu->admin = isset($_POST['nadmin']);
                     if (isset($_POST['ncodagente'])) {
                         if ($_POST['ncodagente'] != '') {
                             $nu->codagente = $_POST['ncodagente'];
                         }
                     }
                     if ($nu->save()) {
                         Header('location: index.php?page=admin_user&snick=' . $nu->nick);
                     } else {
                         $this->new_error_msg("¡Imposible guardar el usuario!");
                     }
                 }
             }
         }
     } else {
         if (isset($_GET['delete'])) {
             $nu = $this->user->get($_GET['delete']);
             if ($nu) {
                 if (FS_DEMO) {
                     $this->new_error_msg('En el modo <b>demo</b> no se pueden eliminar usuarios.
               Esto es así para evitar malas prácticas entre usuarios que prueban la demo.');
                 } else {
                     if ($nu->admin and !$this->user->admin) {
                         $this->new_error_msg("No tienes permiso para eliminar a un administrador.");
                     } else {
                         if (!$this->user->allow_delete_on(__CLASS__)) {
                             $this->new_error_msg("No tienes permiso para eliminar usuarios.");
                         } else {
                             if ($nu->delete()) {
                                 $this->new_message("Usuario " . $nu->nick . " eliminado correctamente.");
                             } else {
                                 $this->new_error_msg("¡Imposible eliminar al usuario!");
                             }
                         }
                     }
                 }
             } else {
                 $this->new_error_msg("¡Usuario no encontrado!");
             }
         }
     }
 }
 protected function process()
 {
     $this->show_fs_toolbar = FALSE;
     $this->agente = new agente();
     $fslog = new fs_log();
     $this->historial = $fslog->all_by('login');
     if (isset($_POST['nnick'])) {
         $nu = $this->user->get($_POST['nnick']);
         if ($nu) {
             Header('location: ' . $nu->url());
         } else {
             $nu = new fs_user();
             $nu->nick = $_POST['nnick'];
             if ($nu->set_password($_POST['npassword'])) {
                 $nu->admin = isset($_POST['nadmin']);
                 if (isset($_POST['ncodagente'])) {
                     if ($_POST['ncodagente'] != '') {
                         $nu->codagente = $_POST['ncodagente'];
                     }
                 }
                 if ($nu->save()) {
                     Header('location: index.php?page=admin_user&snick=' . $nu->nick);
                 } else {
                     $this->new_error_msg("¡Imposible guardar el usuario!");
                 }
             }
         }
     } else {
         if (isset($_GET['delete'])) {
             $nu = $this->user->get($_GET['delete']);
             if ($nu) {
                 if (FS_DEMO) {
                     $this->new_error_msg('En el modo <b>demo</b> no se pueden eliminar usuarios.
               Esto es así para evitar malas prácticas entre usuarios que prueban la demo.');
                 } else {
                     if ($nu->delete()) {
                         $this->new_message("Usuario " . $nu->nick . " eliminado correctamente.");
                     } else {
                         $this->new_error_msg("¡Imposible eliminar al usuario!");
                     }
                 }
             } else {
                 $this->new_error_msg("¡Usuario no encontrado!");
             }
         }
     }
 }
Example #3
0
 /**
  * Devuelve TRUE si el usuario realmente tiene acceso a esta página
  * @return type
  */
 private function log_in()
 {
     $ips = array();
     if ($this->ip_baneada($ips)) {
         $this->banear_ip($ips);
         $this->new_error_msg('Tu IP ha sido baneada. Tendrás que esperar 10 minutos antes de volver a intentar entrar.', 'login', TRUE);
     } else {
         if (isset($_POST['user']) and isset($_POST['password'])) {
             if (FS_DEMO) {
                 $user = $this->user->get($_POST['user']);
                 if (!$user) {
                     $user = new fs_user();
                     $user->nick = $_POST['user'];
                     $user->set_password('demo');
                     /// creamos un agente para asociarlo
                     $agente = new agente();
                     $agente->codagente = $agente->get_new_codigo();
                     $agente->nombre = $_POST['user'];
                     $agente->apellidos = 'Demo';
                     if ($agente->save()) {
                         $user->codagente = $agente->codagente;
                     }
                 }
                 $user->new_logkey();
                 if ($user->save()) {
                     setcookie('user', $user->nick, time() + FS_COOKIES_EXPIRE);
                     setcookie('logkey', $user->log_key, time() + FS_COOKIES_EXPIRE);
                     $this->user = $user;
                     $this->load_menu();
                 }
             } else {
                 $user = $this->user->get($_POST['user']);
                 $password = strtolower($_POST['password']);
                 if ($user) {
                     if ($user->password == sha1($password)) {
                         $user->new_logkey();
                         if (!$user->admin and !$this->ip_in_whitelist($user->last_ip)) {
                             $this->new_error_msg('No puedes acceder desde esta IP.', 'login', TRUE);
                         } else {
                             if ($user->save()) {
                                 setcookie('user', $user->nick, time() + FS_COOKIES_EXPIRE);
                                 setcookie('logkey', $user->log_key, time() + FS_COOKIES_EXPIRE);
                                 $this->user = $user;
                                 $this->load_menu();
                                 /// añadimos el mensaje al log
                                 $fslog = new fs_log();
                                 $fslog->usuario = $user->nick;
                                 $fslog->tipo = 'login';
                                 $fslog->detalle = 'Login correcto.';
                                 $fslog->ip = $user->last_ip;
                                 $fslog->save();
                             } else {
                                 $this->new_error_msg('Imposible guardar los datos de usuario.');
                                 $this->cache->clean();
                             }
                         }
                     } else {
                         $this->new_error_msg('¡Contraseña incorrecta!');
                         $this->banear_ip($ips);
                     }
                 } else {
                     $this->new_error_msg('El usuario ' . $_POST['user'] . ' no existe!');
                     $this->user->clean_cache(TRUE);
                     $this->cache->clean();
                 }
             }
         } else {
             if (isset($_COOKIE['user']) and isset($_COOKIE['logkey'])) {
                 $user = $this->user->get($_COOKIE['user']);
                 if ($user) {
                     if ($user->log_key == $_COOKIE['logkey']) {
                         $user->logged_on = TRUE;
                         $user->update_login();
                         $this->user = $user;
                         $this->load_menu();
                     } else {
                         if (!is_null($user->log_key)) {
                             $this->new_message('¡Cookie no válida! Alguien ha accedido a esta cuenta desde otro PC con IP: ' . $user->last_ip . ". Si has sido tú, ignora este mensaje.");
                             $this->log_out();
                         }
                     }
                 } else {
                     $this->new_error_msg('¡El usuario ' . $_COOKIE['user'] . ' no existe!');
                     $this->log_out();
                     $this->user->clean_cache(TRUE);
                     $this->cache->clean();
                 }
             }
         }
     }
     return $this->user->logged_on;
 }
 /**
  * Devuelve TRUE si el usuario realmente tiene acceso a esta página
  * @return type
  */
 private function log_in()
 {
     $ips = array();
     if ($this->ip_baneada($ips)) {
         $this->banear_ip($ips);
         $this->new_error_msg('Tu IP ha sido baneada. Tendrás que esperar 10 minutos antes de volver a intentar entrar.', 'login', TRUE);
     } else {
         if (isset($_POST['user']) and isset($_POST['password'])) {
             if (FS_DEMO) {
                 if (filter_var($_POST['user'], FILTER_VALIDATE_EMAIL)) {
                     $aux = explode('@', $_POST['user']);
                     $nick = substr($aux[0], 0, 12);
                     if ($nick == 'admin') {
                         $nick .= $this->random_string(7);
                     }
                     $user = $this->user->get($nick);
                     if (!$user) {
                         $user = new fs_user();
                         $user->nick = $nick;
                         $user->set_password('demo');
                         $user->email = $_POST['user'];
                         /// creamos un agente para asociarlo
                         $agente = new agente();
                         $agente->codagente = $agente->get_new_codigo();
                         $agente->nombre = $nick;
                         $agente->apellidos = 'Demo';
                         $agente->email = $_POST['user'];
                         if ($agente->save()) {
                             $user->codagente = $agente->codagente;
                         }
                     }
                     $user->new_logkey();
                     if ($user->save()) {
                         setcookie('user', $user->nick, time() + FS_COOKIES_EXPIRE);
                         setcookie('logkey', $user->log_key, time() + FS_COOKIES_EXPIRE);
                         $this->user = $user;
                         $this->load_menu();
                     }
                 } else {
                     $this->new_error_msg('Email no válido');
                 }
             } else {
                 $user = $this->user->get($_POST['user']);
                 $password = $_POST['password'];
                 if ($user) {
                     /**
                      * En versiones anteriores se guardaban las contraseñas siempre en
                      * minúsculas, por eso, para dar compatibilidad comprobamos también
                      * en minúsculas.
                      */
                     if ($user->password == sha1($password) or $user->password == sha1(mb_strtolower($password, 'UTF8'))) {
                         $user->new_logkey();
                         if (!$user->admin and !$this->ip_in_whitelist($user->last_ip)) {
                             $this->new_error_msg('No puedes acceder desde esta IP.', 'login', TRUE);
                         } else {
                             if ($user->save()) {
                                 setcookie('user', $user->nick, time() + FS_COOKIES_EXPIRE);
                                 setcookie('logkey', $user->log_key, time() + FS_COOKIES_EXPIRE);
                                 $this->user = $user;
                                 $this->load_menu();
                                 /// añadimos el mensaje al log
                                 $fslog = new fs_log();
                                 $fslog->usuario = $user->nick;
                                 $fslog->tipo = 'login';
                                 $fslog->detalle = 'Login correcto.';
                                 $fslog->ip = $user->last_ip;
                                 $fslog->save();
                             } else {
                                 $this->new_error_msg('Imposible guardar los datos de usuario.');
                                 $this->cache->clean();
                             }
                         }
                     } else {
                         $this->new_error_msg('¡Contraseña incorrecta! (' . $_POST['user'] . ')', 'login', TRUE);
                         $this->banear_ip($ips);
                     }
                 } else {
                     $this->new_error_msg('El usuario ' . $_POST['user'] . ' no existe!');
                     $this->user->clean_cache(TRUE);
                     $this->cache->clean();
                 }
             }
         } else {
             if (isset($_COOKIE['user']) and isset($_COOKIE['logkey'])) {
                 $user = $this->user->get($_COOKIE['user']);
                 if ($user) {
                     if ($user->log_key == $_COOKIE['logkey']) {
                         $user->logged_on = TRUE;
                         $user->update_login();
                         $this->user = $user;
                         $this->load_menu();
                     } else {
                         if (!is_null($user->log_key)) {
                             $this->new_message('¡Cookie no válida! Alguien ha accedido a esta cuenta desde otro PC con IP: ' . $user->last_ip . ". Si has sido tú, ignora este mensaje.");
                             $this->log_out();
                         }
                     }
                 } else {
                     $this->new_error_msg('¡El usuario ' . $_COOKIE['user'] . ' no existe!');
                     $this->log_out(TRUE);
                     $this->user->clean_cache(TRUE);
                     $this->cache->clean();
                 }
             }
         }
     }
     return $this->user->logged_on;
 }