Example #1
0
 private function __construct()
 {
     $bases = Sfphp_Config::get('bases');
     foreach ($bases as $nombre => $base) {
         try {
             if (!isset($base["charset"])) {
                 $base["charset"] = "utf8";
             }
             $parametros = array();
             if ($base["type"] == "mysql") {
                 $parametros = array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES ' . $base["charset"]);
             } else {
                 $parametros = array();
             }
             switch ($base["type"]) {
                 case 'sqlsrv':
                     $this->{$nombre} = new PDO($base["type"] . ":Server=" . $base["host"] . ";", $base["user"], Sfphp::decrypt($base["password"]), $parametros);
                     break;
                 case 'mysql':
                     $this->{$nombre} = new PDO($base["type"] . ":host=" . $base["host"] . ";dbname=" . $base["dbname"], $base["user"], Sfphp::decrypt($base["password"]), $parametros);
                     break;
                 case 'firebird':
                     $parametros = array(PDO::FB_ATTR_TIMESTAMP_FORMAT, "%d-%m-%Y", PDO::FB_ATTR_DATE_FORMAT, "%d-%m-%Y");
                     $this->{$nombre} = new PDO($base["type"] . ":dbname=" . $base["host"] . $base["dbname"], $base["user"], Sfphp::decrypt($base["password"]), $parametros);
                     break;
                 default:
                     $this->{$nombre} = new PDO($base["type"] . ":host=" . $base["host"] . ";dbname=" . $base["dbname"], $base["user"], Sfphp::decrypt($base["password"]));
                     break;
             }
         } catch (PDOException $e) {
             Sfphp_Logs::procesa($e);
         }
     }
 }
Example #2
0
 private function __construct($configuracion = "default")
 {
     $base = Sfphp_Config::get('bases');
     $base = $base[$configuracion];
     self::$origen = $configuracion;
     try {
         if (!isset($base["charset"])) {
             $base["charset"] = "utf8";
         }
         $parametros = array();
         switch ($base["type"]) {
             case 'sqlsrv':
                 self::$conexion = new PDO($base["type"] . ":Server=" . $base["host"] . ";", $base["user"], Sfphp::decrypt($base["password"]), $parametros);
                 break;
             case 'mysql':
                 array_push($parametros, array(PDO::MYSQL_ATTR_COMPRESS => TRUE, PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES ' . $base["charset"]));
                 self::$conexion = new PDO($base["type"] . ":host=" . $base["host"] . ";dbname=" . $base["dbname"], $base["user"], Sfphp::decrypt($base["password"]), $parametros);
                 break;
             case 'firebird':
                 array_push($parametros, array(PDO::FB_ATTR_TIMESTAMP_FORMAT => "%d-%m-%Y", PDO::FB_ATTR_DATE_FORMAT => "%d-%m-%Y"));
                 self::$conexion = new PDO($base["type"] . ":dbname=" . $base["host"] . $base["dbname"], $base["user"], Sfphp::decrypt($base["password"]), $parametros);
                 break;
             default:
                 self::$conexion = new PDO($base["type"] . ":host=" . $base["host"] . ";dbname=" . $base["dbname"], $base["user"], Sfphp::decrypt($base["password"]));
                 break;
         }
     } catch (PDOException $e) {
         trigger_error($e->getMessage(), E_USER_ERROR);
     }
 }
Example #3
0
 public function write($id, $data)
 {
     #Todo lo almacenado en la sesion se codifica para mayor seguridad
     if (SESSION_ENCRYPT) {
         return file_put_contents("{$this->savePath}/{$id}", Sfphp::Encrypt($data)) === false ? false : true;
     } else {
         return file_put_contents("{$this->savePath}/{$id}", $data) === false ? false : true;
     }
 }
Example #4
0
 public function write($id, $data)
 {
     #Todo lo almacenado en la sesion se codifica para mayor seguridad
     if (strlen(trim($data)) > 0) {
         $consulta = "REPLACE INTO __sesiones\n                        SET id = :id, fecha = NOW(), data = :data;";
         $valores = array("id" => $id, "data" => Sfphp::Encrypt($data));
         return $this->_db->query($consulta, $valores);
     }
 }
Example #5
0
File: Logs.php Project: sincco/devs
 private static function pantallaBD($e)
 {
     echo "<html><head><style>h1{font-family:Arial, Helvetica, sans-serif; font-size:16px;} body{font-family:Courier; font-size:12px;}</style></head>";
     echo "<h1>" . $e->getMessage() . "(" . $e->getCode() . ")</h1>";
     echo $e->getFile() . "::" . $e->getLine() . "<hr/>";
     echo "URL: http://" . $_SERVER['HTTP_HOST'] . ":" . $_SERVER['SERVER_PORT'] . $_SERVER['REQUEST_URI'] . "<br/>";
     echo "SESSION: " . "<br/>-->id: " . session_id() . "<br/>-->data: <br/>";
     foreach ($_SESSION as $key => $value) {
         echo "-->-->{$key} = " . $value . "<br/>";
     }
     echo "<hr/>IP: " . Sfphp::obtenIP() . " - PHP " . phpversion() . " - " . PHP_OS . "(" . PHP_SYSCONFDIR . " " . PHP_BINARY . ")<br/>";
     echo "<hr/>Simple Framework PHP - " . APP_NAME . " - " . APP_COMPANY;
     echo "</html>\n<br>";
 }
Example #6
0
 protected function __construct()
 {
     $config = Sfphp_Config::get();
     $config = $config['sesion'];
     #Que la cookie de sesión no pueda accederse por javascript.
     $httponly = true;
     #Configuracion para calcular el ID de la sesion
     $session_hash = 'sha512';
     if (in_array($session_hash, hash_algos())) {
         ini_set('session.hash_function', $session_hash);
     }
     ini_set('session.hash_bits_per_character', 5);
     #Fuerza a la sesión para que sólo use cookies, no variables URL.
     ini_set('session.use_only_cookies', 1);
     #Define el tiempo en que una sesion puede seguir activa sin tener algún cambio
     ini_set('session.gc_maxlifetime', $config['inactivity']);
     #Configura los parametros de la sesion
     $cookieParams = session_get_cookie_params();
     if ($cookieParams["lifetime"] == 0) {
         $cookieParams["lifetime"] = 28800;
     }
     #Se mantiene una sesion activa hasta por 8 horas en el navegador
     #Configura los parámetros
     session_set_cookie_params($cookieParams["lifetime"], $cookieParams["path"], $cookieParams["domain"], $config['ssl'], true);
     session_save_path(str_replace("Sfphp", "Etc/Sesiones", realpath(dirname(__FILE__))));
     #Definir el tipo de manejador de las sesiones
     if (strtoupper(trim($config['type'])) == "FILE") {
         session_set_save_handler(new Sfphp_SesionFile(), true);
     }
     if (strtoupper(trim($config['type'])) == "DB") {
         session_set_save_handler(new Sfphp_SesionDB(), true);
     }
     #Definir el nombre de la sesion segun la configuracion de la APP
     session_name($config['name']);
     #Ahora podemos iniciar la sesión
     session_start();
     #Por default la sesion lleva informacion del navegador, sistema e ip y un token con esa información (tratando de hacer unico ese identificador)
     $_SESSION['__browser'] = Sfphp::obtenNavegador()['name'];
     $_SESSION['__token'] = md5(Sfphp::tokenCliente());
 }
Example #7
0
 public static function set($data, $ext = "txt")
 {
     $_file = "./Etc/Logs/" . date('YW') . "." . $ext;
     if ($log_file = fopen($_file, 'a+')) {
         $_data = print_r($data, TRUE);
         fwrite($log_file, date("mdGis") . "\r\n");
         fwrite($log_file, $_data . "\r\n");
         fwrite($log_file, "URL: http://" . $_SERVER['HTTP_HOST'] . ":" . $_SERVER['SERVER_PORT'] . $_SERVER['REQUEST_URI'] . "\r\n");
         fwrite($log_file, "SESSION: " . "\r\n-->id: " . session_id() . "\r\n-->data: \r\n");
         if (isset($_SESSION)) {
             foreach ($_SESSION as $key => $value) {
                 if (!is_array($value)) {
                     fwrite($log_file, "-->-->{$key} = " . $value . "\r\n");
                 }
             }
         }
         fwrite($log_file, "IP: " . Sfphp::obtenIP() . " - PHP " . phpversion() . " - " . PHP_OS . "(" . PHP_SYSCONFDIR . " " . PHP_BINARY . ")\r\n");
         fwrite($log_file, "--------------------------------------------\r\n");
         fclose($log_file);
     } else {
         echo "No se puede escribir el log " . $_file;
     }
 }
Example #8
0
 private function procesaCiclo()
 {
     preg_match_all('/<ciclo ([a-zA-Z0-9\\-_]*?)>/', $this->_html, $_etiquetas);
     foreach ($_etiquetas[0] as $_clave => $_valor) {
         $_ciclo = preg_replace('/<ciclo ([a-zA-Z0-9\\-_]*?)>/', "\\1", $_valor);
         if (isset(get_object_vars($this)[$_ciclo])) {
             $_arreglo = get_object_vars($this)[$_ciclo];
             $_posInicial = strpos($this->_html, '<ciclo ' . $_ciclo . '>') + strlen('<ciclo ' . $_ciclo . '>');
             $_posInicialAux = strpos($this->_html, '<ciclo ' . $_ciclo . '>') - strlen('<ciclo ' . $_ciclo . '>') - 1;
             $_posFinal = strpos($this->_html, '</ciclo ' . $_ciclo . '>');
             $_codigo = substr($this->_html, $_posInicial, $_posFinal - $_posInicial);
             $_codigoReemplazo = "";
             if (is_array($_arreglo)) {
                 foreach ($_arreglo as $_elemento) {
                     $_codigoReemplazo .= $_codigo;
                     preg_match_all('#\\{([a-z0-9\\-_]*?)\\}#is', $_codigo, $_variables);
                     foreach ($_variables[1] as $_variable) {
                         if (isset($_elemento[$_variable])) {
                             if (Sfphp::esEntero($_elemento[$_variable])) {
                                 $_codigoReemplazo = str_replace("{" . $_variable . "}", $_elemento[$_variable], $_codigoReemplazo);
                             }
                             if (Sfphp::esFlotante($_elemento[$_variable])) {
                                 $_codigoReemplazo = str_replace("{" . $_variable . "}", number_format($_elemento[$_variable], 2, ".", ","), $_codigoReemplazo);
                             }
                             if ($_fecha = Sfphp::esFecha($_elemento[$_variable])) {
                                 $_codigoReemplazo = str_replace("{" . $_variable . "}", date_format($_fecha, 'Y-m-d'), $_codigoReemplazo);
                             }
                             if (Sfphp::esCadena($_elemento[$_variable])) {
                                 $_codigoReemplazo = str_replace("{" . $_variable . "}", trim($_elemento[$_variable]), $_codigoReemplazo);
                             }
                         }
                     }
                 }
                 $this->_html = substr_replace($this->_html, $_codigoReemplazo, strpos($this->_html, '<ciclo ' . $_ciclo . '>'), $_posFinal - $_posInicialAux);
             } else {
                 $this->_html = str_replace("<ciclo " . $_ciclo . ">", "El ciclo {$_ciclo} no existe", $this->_html);
                 $this->_html = str_replace("</ciclo " . $_ciclo . ">", "", $this->_html);
             }
         } else {
             $this->_html = str_replace("<ciclo " . $_ciclo . ">", "El ciclo {$_ciclo} no existe", $this->_html);
             $this->_html = str_replace("</ciclo " . $_ciclo . ">", "", $this->_html);
         }
     }
 }
Example #9
0
 /**
  * Valida el acceso del usuario
  * @param  array Datos de acceso
  * @return array
  */
 public function login($data)
 {
     $query = "\n\t\tSELECT usuario, clave\n\t\tFROM usuarios\n\t\tWHERE clave = '{$data['clave']}'\n\t\t\tAND password = '******'password'], Sfphp_Config::get()['app']['key']) . "'\n\t\t\tAND activo = 1;";
     return $this->db->query($query);
 }
Example #10
0
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>sfphp</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
    <link rel="shortcut icon" href="favicon.ico">
</head>
<body>
    <div class="panel panel-primary">
        <div class="panel-heading">Simple Framework (for) PHP</div>
        <?php 
if (isset($_POST['s'])) {
    ?>
        	<h3><?php 
    echo Sfphp::encrypt(trim($_POST['s']), $config['app']['key']);
    ?>
</h3>
        <?php 
} else {
    ?>
        <form action="<?php 
    echo $_SERVER['PHP_SELF'];
    ?>
" method="post">
        	<label>Dato a encriptar:</label><input type="text" name="s" value=""><br>
        	<input type="submit" name="Encriptar" value="Encriptar">
        </form>
        <?php 
}
?>
Example #11
0
        mkdir("./Etc/Cache", 0750);
        mkdir("./Etc/Sesiones", 0750);
        file_put_contents("./Etc/.htaccess", "Options -Indexes");
        file_put_contents("./Etc/Config/.htaccess", "Options -Indexes");
        file_put_contents("./Etc/Logs/.htaccess", "Options -Indexes");
        file_put_contents("./Etc/Cache/.htaccess", "Options -Indexes");
        file_put_contents("./Etc/Sesiones/.htaccess", "Options -Indexes");
        chmod("./Etc/.htaccess", 0750);
        chmod("./Etc/Config/.htaccess", 0750);
        chmod("./Etc/Logs/.htaccess", 0750);
        chmod("./Etc/Cache/.htaccess", 0750);
        chmod("./Etc/Sesiones/.htaccess", 0750);
    }
    echo "Inicializando archivo de configuración...<br>";
    $_llave_encripcion = strtoupper(md5(microtime() . rand()));
    $_config = array('app' => array('key' => $_llave_encripcion, 'name' => 'sfphp', 'company' => 'sincco.com', 'cache' => '600'), 'front' => array('url' => $url), 'bases' => array('default' => array('host' => 'localhost', 'user' => 'sfphp', 'password' => Sfphp::encrypt('sfphp', $_llave_encripcion), 'dbname' => 'sfphp', 'type' => 'mysql', 'default' => 1)), 'sesion' => array('type' => "DEFAULT", 'name' => "sfphp", 'ssl' => 0, 'inactivity' => 300), 'dev' => array('log' => 1, 'showerrors' => 1, 'querylog' => 0));
    if (Sfphp_Disco::grabaXML($_config, "config", "./Etc/Config/config.xml")) {
        chmod("./Etc/Config/config.xml", 0770);
        echo "Configuración basica completa.<br>";
        echo "<a href=\"./\">Ve al inicio de tu app</a>";
    } else {
        echo "Hubo un error al escribir la configuracion.<br>";
    }
} else {
    echo "El framework ya esta configurado<br>";
    echo "<a href=\"./\">Ve al inicio de tu app</a><br>";
    echo "<a href=\"./encrypt.php\">Ve al inicio de tu app</a><br>";
}
?>
    </div>
</body>
Example #12
0
    if (!is_dir("./Libs")) {
        mkdir("./Libs", 0770);
    }
    if (!is_dir("./Etc")) {
        mkdir("./Etc", 0750);
        mkdir("./Etc/Config", 0750);
        mkdir("./Etc/Logs", 0750);
        mkdir("./Etc/Sesiones", 0750);
        file_put_contents("./Etc/.htaccess", "Options -Indexes");
        file_put_contents("./Etc/Config/.htaccess", "Options -Indexes");
        file_put_contents("./Etc/Logs/.htaccess", "Options -Indexes");
        file_put_contents("./Etc/Sesiones/.htaccess", "Options -Indexes");
        chmod("./Etc/.htaccess", 0750);
        chmod("./Etc/Config/.htaccess", 0750);
        chmod("./Etc/Logs/.htaccess", 0750);
        chmod("./Etc/Sesiones/.htaccess", 0750);
    }
    echo "Inicializando archivo de configuración...<br>";
    $_llave_encripcion = strtoupper(md5(microtime() . rand()));
    $_config = array('app' => array('key' => $_llave_encripcion, 'name' => 'sfphp', 'company' => 'sincco.com'), 'front' => array('url' => sprintf("%s://%s%s", isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 'https' : 'http', $_SERVER['SERVER_NAME'], $_SERVER['REQUEST_URI'])), 'bases' => array('base' => array('host' => 'sfphp', 'user' => 'sfphp', 'password' => Sfphp::encrypt('sfphp', $_llave_encripcion), 'dbname' => 'sfphp', 'type' => 'mysql', 'default' => 1), 'type' => "DEFAULT", 'name' => "sfphp", 'ssonly' => 0, 'inactivity' => 60), 'session' => array('type' => "DEFAULT", 'name' => "sfphp", 'ssonly' => 0, 'inactivity' => 60), 'dev' => array('log' => 1, 'showerrors' => 0, 'showphperrors' => 0));
    if (Sfphp_Disco::arregloXML($_config, "config", "./Etc/Config/config.xml")) {
        chmod("./Etc/Config/config.xml", 0770);
        echo "Configuración basica completa.<br>";
        echo "<a href=\"./\">Ve al inicio de tu app</a>";
    } else {
        echo "Hubo un error al escribir la configuracion.<br>";
    }
} else {
    echo "El framework ya esta configurado<br>";
    echo "<a href=\"./\">Ve al inicio de tu app</a>";
}
Example #13
0
 public static function ejecuta($clase, $metodo, $argumentos)
 {
     $objeto = Sfphp::CargaModelo($clase);
     if (is_object($objeto)) {
         return Sfphp::EjecutarMetodo($objeto, $metodo, $argumentos);
     } else {
         $objeto = new $clase();
         return Sfphp::EjecutarMetodo($objeto, $metodo, $argumentos);
     }
 }