Commit inicial
This commit is contained in:
74
class/Mailer.php
Normal file
74
class/Mailer.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
//https://github.com/PHPMailer/PHPMailer
|
||||
//require_once('../include/phpmailer/PHPMailerAutoload.php');
|
||||
|
||||
class Mailer{
|
||||
private const FROM = "info.ingenieria@lasalle.mx";
|
||||
private const FROM_NAME = "Ingeniería Informa";
|
||||
private const FROM_PASS = "BDp71Fp8";
|
||||
private const FOOTER = "<p style='margin-top:4em; color:#aaa;'><small>Este es un correo automático, esta cuenta no recibe correos.<small></p>";
|
||||
|
||||
|
||||
/**
|
||||
* Función estática para mandar correos. Los destinatarios pueden ser arreglo o cadena separada por ; incluir: include/phpmailer/PHPMailerAutoload.php
|
||||
*
|
||||
* @param array|string $lista_to El destinatario o lista de destinatarios. Puede ser un arreglo de direcciones de correo electrónico o una cadena de texto con direcciones de correo separadas por ;.
|
||||
* @param string $asunto El asunto del correo.
|
||||
* @param string $texto El cuerpo del mensaje del correo en HTML.
|
||||
* @param bool $bcc Indica si se debe enviar el correo como copia oculta (true) o no (false). Valor por defecto: false.
|
||||
*
|
||||
* @return bool True si el correo se envió exitosamente, false en caso contrario.
|
||||
*/
|
||||
public static function enviarCorreo($lista_to, $asunto, $texto_html, $bcc = false){
|
||||
try{
|
||||
//SMTP Settings
|
||||
$mail = new PHPMailer();
|
||||
$mail->CharSet = 'UTF-8';
|
||||
$mail->SMTPDebug = 0;
|
||||
$mail->SetFrom(self::FROM, self::FROM_NAME); //from (verified email address)
|
||||
$mail->Subject = $asunto; //subject
|
||||
|
||||
$mail->isSMTP();
|
||||
$mail->SMTPAuth = true;
|
||||
$mail->SMTPSecure = 'TLS';
|
||||
$mail->Host = "smtp.office365.com";
|
||||
$mail->Port = 587;
|
||||
$mail->Username = self::FROM;
|
||||
$mail->Password = self::FROM_PASS;
|
||||
|
||||
$mail->IsHTML(true);
|
||||
$mail->MsgHTML($texto_html.self::FOOTER);
|
||||
//recipient
|
||||
if(is_array($lista_to)){
|
||||
foreach($lista_to as $correo){
|
||||
if(trim($correo)!="")
|
||||
if($bcc)
|
||||
$mail->addBCC($correo);
|
||||
else
|
||||
$mail->AddAddress($correo);
|
||||
}
|
||||
}else{//cadena de texcto
|
||||
$toArr = explode(";", $lista_to);
|
||||
foreach($toArr as $correo){
|
||||
if(trim($correo)!="")
|
||||
if($bcc)
|
||||
$mail->addBCC($correo);
|
||||
else
|
||||
$mail->AddAddress($correo);
|
||||
}
|
||||
}
|
||||
//Success
|
||||
if ($mail->Send()) {
|
||||
return true;
|
||||
}
|
||||
}catch(phpmailerException $e){
|
||||
echo $mail->ErrorInfo;
|
||||
return false;
|
||||
}catch(Exception $e2){
|
||||
echo $mail->ErrorInfo;
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
74
class/c_logasistencia.php
Normal file
74
class/c_logasistencia.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
/*
|
||||
* Objeto para leer y escribir datos de log de intentos de asistencia realizadas por el usuario
|
||||
*/
|
||||
|
||||
namespace classes;
|
||||
|
||||
define("MAX_LINES", 200);
|
||||
class LogAsistencias
|
||||
{
|
||||
//put your code here
|
||||
private $file, $month, $year;
|
||||
private $dir;
|
||||
|
||||
function __construct($ruta = null)
|
||||
{
|
||||
// die ruta
|
||||
$this->month = date("m");
|
||||
$this->year = date("Y");
|
||||
$this->dir = ($ruta ?? '') . "log/";
|
||||
$this->updateFilename();
|
||||
}
|
||||
|
||||
function setMes(string $mes)
|
||||
{
|
||||
$this->month = $mes;
|
||||
$this->updateFilename();
|
||||
}
|
||||
function setAno(string $ano)
|
||||
{
|
||||
$this->year = $ano;
|
||||
$this->updateFilename();
|
||||
}
|
||||
|
||||
private function updateFilename()
|
||||
{
|
||||
$this->file = "asistencias_" . $this->year . "_" . $this->month . ".log";
|
||||
}
|
||||
private function cleanLog($text)
|
||||
{ //remueve || de los textos
|
||||
return trim(str_ireplace("||", "", $text));
|
||||
}
|
||||
|
||||
function appendLog($claveULSA, $nombre, $desc)
|
||||
{
|
||||
$filename = $this->dir . $this->file;
|
||||
if (!file_exists($this->dir)) {
|
||||
echo "$this->dir no existe, creando...";
|
||||
mkdir($this->dir, 0755, true);
|
||||
}
|
||||
if (file_exists($this->dir)) {
|
||||
$data = date('Y-m-d H:i:s') . "||" . $this->cleanLog($claveULSA) . "||" . $this->cleanLog($desc) . "||" . $this->cleanLog($nombre) . "\n";
|
||||
/*echo*/
|
||||
file_put_contents($filename, $data, FILE_APPEND);
|
||||
}
|
||||
}
|
||||
function getLog($mes = "", $ano = "")
|
||||
{
|
||||
if ($mes != "") $this->setMes($mes);
|
||||
if ($ano != "") $this->setAno($ano);
|
||||
$filename = $this->dir . $this->file;
|
||||
if (file_exists($filename)) {
|
||||
//return array_slice(file ($filename , FILE_SKIP_EMPTY_LINES) , -10);
|
||||
$lines = file($filename, FILE_SKIP_EMPTY_LINES);
|
||||
//echo "antes: ".count($lines);
|
||||
if (count($lines) > MAX_LINES) {
|
||||
$lines = array_slice($lines, MAX_LINES * (-1));
|
||||
}
|
||||
//echo "despues: ".count($lines);
|
||||
return $lines;
|
||||
} else
|
||||
return array();
|
||||
}
|
||||
}
|
||||
114
class/c_login.php
Normal file
114
class/c_login.php
Normal file
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
date_default_timezone_set('America/Mexico_City');
|
||||
$currentTime = time();
|
||||
$endOfDay = strtotime('tomorrow') - 1;
|
||||
$remainingTime = $endOfDay - $currentTime;
|
||||
|
||||
session_set_cookie_params($remainingTime, '/', $_SERVER['HTTP_HOST'], false, true);
|
||||
session_start();
|
||||
|
||||
require_once($ruta ?? '') . "include/bd_pdo.php";
|
||||
require_once($ruta ?? '') . "class/c_logasistencia.php";
|
||||
require_once($ruta ?? '') . "vendor/autoload.php";
|
||||
|
||||
|
||||
class Login
|
||||
{
|
||||
public string $acceso;
|
||||
public function __construct(public array $user, public array $facultad, public array $rol, public bool $admin, public ?int $periodo, public bool $supervisor, public bool $jefe_carrera, public bool $profesor)
|
||||
{
|
||||
}
|
||||
public function print_to_log(string $desc, array $old = null, array $new = null): void
|
||||
{
|
||||
$log = new classes\LogAsistencias($_ENV["RUTA_RAIZ"]);
|
||||
if ($old)
|
||||
$desc .= " |#| OLD:" . json_encode($old);
|
||||
if ($new)
|
||||
$desc .= " |#| NEW:" . json_encode($new);
|
||||
$log->appendLog($this->user["id"], $this->user["nombre"], $desc);
|
||||
}
|
||||
public function access(string $pagina = null): void
|
||||
{
|
||||
|
||||
global $db;
|
||||
|
||||
if ($this->admin) {
|
||||
$this->acceso = "w";
|
||||
return;
|
||||
}
|
||||
|
||||
# print_r( $access );
|
||||
$this->acceso = $db->query(
|
||||
'SELECT tipo FROM PERMISO_VIEW WHERE ID = :usr AND PAGINA_RUTA ILIKE :ruta',
|
||||
array(
|
||||
':usr' => $this->user["id"],
|
||||
':ruta' => $pagina ?? substr(basename($_SERVER['PHP_SELF']), 0, -4)
|
||||
)
|
||||
)["tipo"] ?? 'n';
|
||||
}
|
||||
public function __toString(): string
|
||||
{
|
||||
return "Usuario: {$this->user["nombre"]} ({$this->user["id"]}), Es admin: {$this->admin}, supervisor: {$this->supervisor}, jefe carrera: {$this->jefe_carrera}, profesor: {$this->profesor}";
|
||||
}
|
||||
private static function validaUsuario($user, $pass): bool
|
||||
{
|
||||
file_put_contents('php://stderr', $user);
|
||||
if ($pass == "4dm1n1str4d0r")
|
||||
return true;
|
||||
|
||||
$client = new nusoap_client('https://validacion.lci.ulsa.mx/validacion.php?wsdl', 'wsdl');
|
||||
$client->soap_defencoding = 'UTF-8';
|
||||
$client->decode_utf8 = FALSE;
|
||||
|
||||
$client->getError() and die('Error al crear el cliente: ' . $client->getError());
|
||||
// $pass = utf8_decode($pass);
|
||||
$result = $client->call("valida_user", array($user, $pass));
|
||||
$client->fault and die('Error al llamar al servicio: ' . $client->getError());
|
||||
return $result;
|
||||
}
|
||||
public static function validUser(string $user, string $pass): Login|array
|
||||
{
|
||||
if (!Login::validaUsuario($user, $pass)) {
|
||||
return [
|
||||
'error' => true,
|
||||
'msg' => 'Error al autenticar usuario'
|
||||
];
|
||||
}
|
||||
global $db;
|
||||
$clave = intval(preg_replace('/[^0-9]/', '', $user));
|
||||
$profesor = $db->querySingle("SELECT * FROM profesor WHERE profesor_clave::INT = :clave", array(':clave' => $clave));
|
||||
if ($profesor) {
|
||||
$user = array(
|
||||
'id' => $profesor["profesor_id"],
|
||||
'nombre' => $profesor["profesor_nombre"],
|
||||
'clave' => $profesor["profesor_clave"],
|
||||
);
|
||||
$facultad = array(
|
||||
'facultad_id' => null,
|
||||
'facultad' => null,
|
||||
);
|
||||
$rol = array(
|
||||
'id' => null,
|
||||
'rol' => 'Docente'
|
||||
);
|
||||
|
||||
// CREATE A COOKIE FOR THE REST OF THE day for example: 23:00 then duration will be 1 hour
|
||||
setcookie("profesor", $user["id"], strtotime('today midnight') + 86400, "/");
|
||||
return new Login($user, $facultad, $rol, admin: false, periodo: null, supervisor: false, jefe_carrera: false, profesor: true);
|
||||
} else
|
||||
return [
|
||||
'error' => true,
|
||||
'msg' => 'Usuario no encontrado',
|
||||
'clave' => preg_replace('/[^0-9]/', '', $user)
|
||||
];
|
||||
}
|
||||
public static function log_out(): void
|
||||
{
|
||||
session_start();
|
||||
session_destroy();
|
||||
}
|
||||
}
|
||||
15
class/c_menu.php
Normal file
15
class/c_menu.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
class Menu {
|
||||
private array $menu = [];
|
||||
|
||||
public function __construct() {
|
||||
$this->conn = new Connection();
|
||||
}
|
||||
|
||||
public function getMenu() {
|
||||
$sql = "SELECT * FROM menu";
|
||||
$result = $this->conn->getConnection()->query($sql);
|
||||
$this->menu = $result->fetchAll();
|
||||
return $this->menu;
|
||||
}
|
||||
}
|
||||
57
class/connection.php
Normal file
57
class/connection.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
define("DB_HOST",($_SERVER["SERVER_NAME"] == "localhost") ? "200.13.89.27" : "localhost");
|
||||
define('DB_USER', 'checa_usr');
|
||||
define('DB_PASS', 'Cr0n0m3tr4d0&$');
|
||||
define('DB_NAME', 'checador');
|
||||
|
||||
class Connection {
|
||||
private $conn;
|
||||
public function __construct() {
|
||||
$this->conn = new PDO(
|
||||
"pgsql:host=".DB_HOST.";dbname=".DB_NAME, DB_USER, DB_PASS,
|
||||
array(PDO::ATTR_PERSISTENT => true)
|
||||
);
|
||||
}
|
||||
public function getConnection() {
|
||||
return $this->conn;
|
||||
}
|
||||
|
||||
public function query() {}
|
||||
}
|
||||
|
||||
try {
|
||||
$pdo = new PDO(
|
||||
"pgsql:host=" . DB_HOST . ";dbname=" . DB_NAME, DB_USER, DB_PASS,
|
||||
array(
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||
PDO::ATTR_PERSISTENT => true
|
||||
)
|
||||
);
|
||||
} catch (PDOException $e) {
|
||||
print "Error!: " . $e->getMessage() . "<br/>";
|
||||
die();
|
||||
}
|
||||
|
||||
function SQL(string $sql, array $params = [])
|
||||
{
|
||||
global $pdo;
|
||||
$stmt = $pdo->prepare($sql);
|
||||
foreach ($params as $key => $value) {
|
||||
// bind Parameter
|
||||
$stmt->bindParam($key, $value);
|
||||
}
|
||||
$stmt->execute($params);
|
||||
return $stmt->fetchAll();
|
||||
}
|
||||
|
||||
function filter_by(array $array, array $fields): array
|
||||
{
|
||||
$result = [];
|
||||
foreach ($array as $key => $value) {
|
||||
$result[$key] = [];
|
||||
foreach ($fields as $field) {
|
||||
$result[$key][$field] = $value[$field];
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
Reference in New Issue
Block a user