/
conexiones_config.php
339 lines (287 loc) · 11 KB
/
conexiones_config.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
<?php
require("variables_config.php");
/*****/
$anticache=md5(date('U'));
$anticachecret=md5(date('U').$ecret);
/*****/
/************************************/
/* DESCONEXION GEN */
/************************************/
function _adios_mysql() {
require("variables_config.php");
@mysql_close($bienvenido_mysql);
}
/************************************/
/*CONEXION GENERICA */
/************************************/
function _bienvenido_mysql() {
require("variables_config.php");
$bienvenido_mysql= mysql_connect($db0_host,$db0_user,$db0_pass) ;
if($bienvenido_mysql){
$db_bienvenido_mysql = mysql_select_db($db0_database,$bienvenido_mysql) or die(mysql_error());
mysql_query("set names utf8");
}
else{
if ($SQL_debug=='1'){ die('Error en Conexion - Respuesta del Motor: ' . mysql_error());} else {die('Error en Conexion');}
}
}
/************************************/
/*FUNCION DE AUDITORIA */
/************************************/
function _wm($usu,$msg,$obs) {
require("variables_config.php");
if($wachsam=='1'){
_bienvenido_mysql();
$publica= @$_SERVER['REMOTE_ADDR']; if ($privada=='') $privada = 'S/I';
$privada= @$_SERVER['HTTP_X_FORWARDED_FOR']; if ($publica=='') $publica = 'S/I';
if ($obs=='') $obs = 'S/I';
$sql ="INSERT INTO auditoria (usuario, ip_wan, ip_proxy, operacion, observaciones)";
$sql .="VALUES('".$usu."','".$publica."','".$privada."','".$msg."','".$obs."');";
$result = mysql_query($sql);
if(!$result){
if ($SQL_debug=='1'){ die('Error Auditando - Respuesta del Motor: ' . mysql_error());} else {die('Error Auditando');}
}
}
}
/************************************/
/*FUNCION DE ENVIO DE MAIL */
/************************************/
function _enviarmail($mensaje,$nombre_de_destino,$destino,$asunto) {
require("variables_config.php");
date_default_timezone_set('America/Caracas');
require_once('src/classes/phpmailer/class.phpmailer.php');
$fecha_hora = date("Y/m/d H:i:s");
$mail = new PHPMailer();
//indico a la clase que use SMTP
$mail->IsSMTP();
//permite modo debug para ver mensajes de las cosas que van ocurriendo
$mail->SMTPDebug = 0;
//Debo de hacer autenticación SMTP
$mail->SMTPAuth = true;
$mail->SMTPSecure = "ssl";
//indico el servidor de Gmail para SMTP
$mail->Host = "smtp.mail.com";
//indico el puerto que usa Gmail
$mail->Port = 465;
//indico un usuario / clave de un usuario de gmail
$mail->Username = "intranet@writeme.com";
$mail->Password = "soportetdi13";
$mail->SetFrom('intranet@writeme.com', 'Metro de Maracaibo');
$mail->AddReplyTo("intranet@writeme.com","Metro de Maracaibo");
$mail->Subject = $asunto;
$mail->MsgHTML($mensaje);
//indico destinatario
$address = $destino;
$mail->AddAddress($destino, $nombre_de_destino);
if(!$mail->Send()) {
return 0; //"Error al enviar: " . $mail->ErrorInfo;
} else {
$file=fopen("correos.html","a");
if(file){
fputs($file,"Para: " . $nombre_de_destino . "<" . $destino . ">");fputs($file,"<br />");
fputs($file,"Fecha: " . date("Y/m/d H:i:s")); fputs($file,"<br />");
fputs($file,"Asunto: " . $asunto);fputs($file,"<br />");
fputs($file,"<p>Mensaje:</p>"); fputs($file,"<br />");
fputs($file,"<hr />");
fputs($file,$mensaje);
fputs($file,"<hr />");
fputs($file,"<br />");fputs($file,"<br />");
fclose($file);
}
return 1;
}
}
/************************************/
/*FUNCION DE DAME CEDULA */
/************************************/
function _damecedula($usu) {
require("variables_config.php");
_bienvenido_mysql();
$result = mysql_query("SELECT * FROM usuario_bkp WHERE usuario_int = '".$usu."'");
$reg=mysql_fetch_array($result);
if($result) {
return $reg['usuario'];
}
else {
return '0';
}
}
/************************************/
/*FUNCION DE ENCRIPTACION */
/************************************/
function _desordenar($string) {
require("variables_config.php");
$key = $ecret;
$result = '';
for($i=0; $i<strlen($string); $i++) {
$char = substr($string, $i, 1);
$keychar = substr($key, ($i % strlen($key))-1, 1);
$char = chr(ord($char)+ord($keychar));
$result.=$char;
}
return base64_encode($result);
}
function _ordenar($string) {
require("variables_config.php");
$key = $ecret;
$result = '';
$string = base64_decode($string);
for($i=0; $i<strlen($string); $i++) {
$char = substr($string, $i, 1);
$keychar = substr($key, ($i % strlen($key))-1, 1);
$char = chr(ord($char)-ord($keychar));
$result.=$char;
}
return $result;
}
function decode_get2($string, $cantidaddeparametros) {
$cad = split("[&]",$string); //separo la url desde el ?
$string = $cad[$cantidaddeparametros]; //capturo la url desde el separador ? en adelante
$string = _ordenar($string); //decodifico la cadena
//procedo a dejar cada variable en el $_GET
$cad_get = split("[&]",$string); //separo la url por &
foreach($cad_get as $value) {
$val_get = split("[=]",$value); //asigno los valosres al GET
$_GET[$val_get[0]]=utf8_decode($val_get[1]);
}
}
function _desordenarperfil($string, $key) {
require("variables_config.php");
$key = $key . $ecret;
$result = '';
for($i=0; $i<strlen($string); $i++) {
$char = substr($string, $i, 1);
$keychar = substr($key, ($i % strlen($key))-1, 1);
$char = chr(ord($char)+ord($keychar));
$result.=$char;
}
return base64_encode($result);
}
function _ordenarperfil($string, $key) {
require("variables_config.php");
$key = $key . $ecret;
$result = '';
$string = base64_decode($string);
for($i=0; $i<strlen($string); $i++) {
$char = substr($string, $i, 1);
$keychar = substr($key, ($i % strlen($key))-1, 1);
$char = chr(ord($char)-ord($keychar));
$result.=$char;
}
return $result;
}
/************************************/
/*FUNCION DE ALERTA */
/************************************/
function alerta($mensaje) {
echo '<script type="text/javascript">alert("'.$mensaje.'");</script>';
}
function alertadev($mensaje) {
echo '<script type="text/javascript">prompt("'.$mensaje.'", "'.$mensaje.'");</script>';
}
/************************************/
/*FUNCION DE REDIRECCION */
/************************************/
function ir($url) {
echo '<script type="text/javascript">window.location.href = "'.$url.'";</script>';
}
function irb($url) {
echo '<script type="text/javascript">window.location.href = "'.$url.'"; target="_blank";</script>';
}
function irpopup($url, $w, $h) {
echo '<script type="text/javascript">window.open ("'.$url.'", "reporte","location=1,status=1,scrollbars=1, width='.$w.',height='.$h.'");</script>';
}
/************************************/
/*FUNCION DE NOTIFICACION */
/************************************/
function notificar($mensaje, $url, $tipo) { // notify-success: = gris | notify-warning: = amarillo
$_SESSION['notificar'] = '1'; // notify-error: = rojo | notify-info: = azul | notify: gris
$_SESSION['notificartipo'] = $tipo;
$_SESSION['notificarmensaje'] = $mensaje;
if ($url!='') {
echo '<script type="text/javascript">window.location.href = "'.$url.'";</script>';
}
}
/* <?php include('notificador.php'); ?> */
/************************************/
/*FUNCION DE GENERAR PASS */
/************************************/
function generapass(){
$cadena = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890";
$longitudCadena=strlen($cadena);
$pass = "";
$longitudPass=10;
for($i=1 ; $i<=$longitudPass ; $i++){
$pos=rand(0,$longitudCadena-1);
$pass .= substr($cadena,$pos,1);
}
return $pass;
}
/************************************/
/*FUNCION DE LISTAR DIRECTORIOS */
/************************************/
function listarmodulos(){
$directorio = opendir("./modules");
while ($archivo = readdir($directorio)) {
$nombreArch = ucwords($archivo);
if ($nombreArch!="." && $nombreArch!=".."){
$listarmodulos[] = $nombreArch;
}
}
return $listarmodulos;
closedir($directorio);
}
function _antinyeccionSQL($valor) {
$valor = str_ireplace("INSERT","",$valor);
$valor = str_ireplace("DELETE","",$valor);
$valor = str_ireplace("UPDATE","",$valor);
$valor = str_ireplace("SELECT","",$valor);
$valor = str_ireplace("COPY","",$valor);
$valor = str_ireplace("DELETE","",$valor);
$valor = str_ireplace("DROP","",$valor);
$valor = str_ireplace("DUMP","",$valor);
$valor = str_ireplace(" OR ","",$valor);
$valor = str_ireplace("%","",$valor);
$valor = str_ireplace("LIKE","",$valor);
$valor = str_ireplace("--","",$valor);
$valor = str_ireplace("^","",$valor);
$valor = str_ireplace("[","",$valor);
$valor = str_ireplace("]","",$valor);
$valor = str_ireplace("\\","",$valor);
$valor = str_ireplace("!","",$valor);
$valor = str_ireplace("¡","",$valor);
$valor = str_ireplace("?","",$valor);
$valor = str_ireplace("=","",$valor);
$valor = str_ireplace("&","",$valor);
return $valor;
}
function _antiXSS($data)
{
// Fix &entity\n;
$data = str_replace(array('&','<','>'), array('&amp;','&lt;','&gt;'), $data);
$data = preg_replace('/(&#*\w+)[\x00-\x20]+;/u', '$1;', $data);
$data = preg_replace('/(&#x*[0-9A-F]+);*/iu', '$1;', $data);
$data = html_entity_decode($data, ENT_COMPAT, 'UTF-8');
// Remove any attribute starting with "on" or xmlns
$data = preg_replace('#(<[^>]+?[\x00-\x20"\'])(?:on|xmlns)[^>]*+>#iu', '$1>', $data);
// Remove javascript: and vbscript: protocols
$data = preg_replace('#([a-z]*)[\x00-\x20]*=[\x00-\x20]*([`\'"]*)[\x00-\x20]*j[\x00-\x20]*a[\x00-\x20]*v[\x00-\x20]*a[\x00-\x20]*s[\x00-\x20]*c[\x00-\x20]*r[\x00-\x20]*i[\x00-\x20]*p[\x00-\x20]*t[\x00-\x20]*:#iu', '$1=$2nojavascript...', $data);
$data = preg_replace('#([a-z]*)[\x00-\x20]*=([\'"]*)[\x00-\x20]*v[\x00-\x20]*b[\x00-\x20]*s[\x00-\x20]*c[\x00-\x20]*r[\x00-\x20]*i[\x00-\x20]*p[\x00-\x20]*t[\x00-\x20]*:#iu', '$1=$2novbscript...', $data);
$data = preg_replace('#([a-z]*)[\x00-\x20]*=([\'"]*)[\x00-\x20]*-moz-binding[\x00-\x20]*:#u', '$1=$2nomozbinding...', $data);
// Only works in IE: <span style="width: expression(alert('Ping!'));"></span>
$data = preg_replace('#(<[^>]+?)style[\x00-\x20]*=[\x00-\x20]*[`\'"]*.*?expression[\x00-\x20]*\([^>]*+>#i', '$1>', $data);
$data = preg_replace('#(<[^>]+?)style[\x00-\x20]*=[\x00-\x20]*[`\'"]*.*?behaviour[\x00-\x20]*\([^>]*+>#i', '$1>', $data);
$data = preg_replace('#(<[^>]+?)style[\x00-\x20]*=[\x00-\x20]*[`\'"]*.*?s[\x00-\x20]*c[\x00-\x20]*r[\x00-\x20]*i[\x00-\x20]*p[\x00-\x20]*t[\x00-\x20]*:*[^>]*+>#iu', '$1>', $data);
// Remove namespaced elements (we do not need them)
$data = preg_replace('#</*\w+:\w[^>]*+>#i', '', $data);
do
{
// Remove really unwanted tags
$old_data = $data;
$data = preg_replace('#</*(?:applet|b(?:ase|gsound|link)|embed|frame(?:set)?|i(?:frame|layer)|l(?:ayer|ink)|meta|object|s(?:cript|tyle)|title|xml)[^>]*+>#i', '', $data);
}
while ($old_data !== $data);
// we are done...
return $data;
}
?>