<?
include('config.php');
include('funciones.php');
$sid = validar_sid();
$reg_visitante = $config[ruta_datos_visitantes] . '/online_'.$sid.'.txt';
$reg_conectado = $config[ruta_datos_chat] . '/conectado.txt';
$reg_chat = $config[ruta_datos_chat] . '/chat_'.$sid.'.txt';
$reg_chat_history = $config[ruta_datos_chat] . '/chat_'.$sid.'.htm';
$modo = $_GET['modo']?$_GET['modo']:$_POST['modo'];
switch($modo):
case 'actualizar':
$soporte_online = $_GET[soporte_online]?'1':'0';
$soporte_activo = $_GET[soporte_activo]?'1':'0';
$tmp_regresa = explode('/', $_GET[cross_ajax]);
$dom_regresa = str_replace('www.', '', $tmp_regresa[2]);
if(!in_array($dom_regresa, $config[dominios])) {
echo '<script>alert("'.$lang[refnoval].'");</script>';
exit;
}
headers_nocache();
eval("\$salida = \"".matriz("actualizar.html")."\";");
echo $salida;
break;
case 'aviso':
$admin_stupid = 1;//don't propertly disconnect, check filemtime
$soporte_linea = FALSE;
if($_POST[phpo_nv]) {
$fecha_reg = date("d/m/Y h:i:s");
if($config[lang] != 'es')
$fecha_reg = date("m/d/Y h:i:s");
$abro = fopen($reg_visitante, "a");
$ip = detectar_ip();
$reg = "$fecha_reg|$_POST[phpo_nv]|$ip|$_POST[tmp_nick]|$_SERVER[HTTP_USER_AGENT]";
fwrite($abro, $reg);
fclose($abro);
} else {
touch($reg_visitante);
}
if(file_exists($reg_chat)) { // chat abierto por soporte
$soporte_linea = TRUE;
echo "resp_activo = 1;";
} else {
echo "resp_activo = 0;";
}
if(!$soporte_linea) {
if(file_exists($reg_conectado)) {
$dif_soponline = time() - 20;
if($admin_stupid && filemtime($reg_conectado) < $dif_soponline) {
unlink($reg_conectado);
$soporte_linea = FALSE;
} else {
$soporte_linea = TRUE;
}
} else {
$soporte_linea = FALSE;
}
}
if($soporte_linea) {
echo "resp_online = 1;";
} else {
echo "resp_online = 0;";
}
break;
case 'cerrar':
if(file_exists($reg_chat)) {
@$abro_bk = fopen($reg_chat_history, "a");
@fwrite($abro_bk, implode(" ",file($reg_chat)));
@fclose($abro_bk);
@unlink($reg_chat);
}
if($_GET[desde] == 'top')
echo '<script language="javascript">top.close();</script>';
break;
case 'escribir_msg':
$modo = 'a';
$msg_backup = '';
$msg = limpiar($_POST[msg], 300);
$nick = limpiar($_POST[nick], 30);
$email = limpiar($_POST[email], 100);
if(@filesize($reg_chat) > 5120) {
$modo = 'w';
$contenido_archivo = implode(" ",file($reg_chat));
@$abro_bk = fopen($reg_chat_history, "a");
@fwrite($abro_bk, $contenido_archivo);
@fclose($abro_bk);
$msg_backup = '<div style="text-align: center; background-color: orange"> '.$lang[histguard].' </div>';
}
$msg = str_replace('%', '%', $msg);
$msg = parse_links($msg);
if (!empty($msg) && !empty($nick)) {
@$abro = fopen($reg_chat, $modo);
$linea_msg = $msg_backup . "<DIV class=\"l_nick\" title=\"$email\">$nick</DIV><DIV class=\"l_msg\">$msg</DIV>\n";
@fwrite($abro, $linea_msg);
@fclose($abro);
}
@readfile($reg_chat);
break;
default: //chat window
if($_GET[admin]) //just welcome message, no major security needed
extract($online_admin);
elseif($_GET[tmp_nick])
$mensaje_inicial = $lang['esperando'];
else
extract($online_user);
headers_nocache();
eval("\$salida = \"".matriz("chat_window.html")."\";");
echo $salida;
break;
endswitch;
?>