1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/minchat_ynh.git synced 2024-09-03 19:36:29 +02:00

[fix] delete source files

This commit is contained in:
magikcypress 2017-05-01 16:32:47 +02:00
parent 5558de4b5e
commit 02d4bd1144
6 changed files with 0 additions and 378 deletions

View file

@ -1,14 +0,0 @@
; how often get data from serwer
interval = 5000 ; milliseconds
; Authorizations (comma separated)
auth=*:
; Explanations:
; *: (default) means all users can access the no name room
; user:room means the user is allowed to room
; *:room is a room opened to all
; user:* is a user allowed to any room
; user: is a user allowed to the no name room
; Example:
;auth = John:Game,John:Family,Mary:Game,Tim:Family,admin:*,*:Public,*:

View file

@ -1,223 +0,0 @@
<?php
function getarr($arr,$key,$default) {
return isset($arr[$key]) ? $arr[$key] : $default;
}
function deleteOldHistory() {
$expireDate = date('Y-m-d', strtotime("-1 day"));
foreach (glob('./history/*') as $f) {
if (substr(basename($f),-10) < $expireDate) {
unlink($f);
}
}
}
// init setup.ini parms
$ini = parse_ini_file('conf/setup.ini');
$interval= getarr($ini,'interval',2500);
$auth= explode(',',getarr($ini,'auth','*:'));
// read args
$name="";
if (isset($_REQUEST['name'])) {
$name = stripslashes(htmlspecialchars($_REQUEST['name']));
}
$room="";
if (isset($_REQUEST['room'])) {
$room = stripslashes(htmlspecialchars($_REQUEST['room']));
}
// no auth = single room = no room specified
if ($auth[0]==""){$room="";}
// check args
if ($name.$room=="") {
// no args
$prompt = "Please fill in the form to continue:";
} else {
// user name mandatory in any case
if ($name=="") {$prompt = "<em>User name missing.</em>";}
else if ($room=="") {
// room not mandatory depending on setup
if (in_array("*:",$auth)||in_array($name.":",$auth)){$prompt="";}
else {$prompt="<em>Room missing.</em>";}
}
// here we have both room and user
else if (in_array($name.":".$room,$auth)||in_array("*:".$room,$auth)||in_array($name.":*",$auth)||in_array("*:*",$auth)) {$prompt="";}
else {$prompt="<em>User not authorized to this room.</em>";}
}
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Minchat - <?php echo $room; ?> room</title>
<link type="text/css" rel="stylesheet" href="style.css" />
</head>
<?php
if ($prompt!="") {
// Form to get args
echo'<div id="loginform"><p>';
echo $err;
echo $prompt;
echo '</p><form action="" method="get" class="tform"><p><label for="name">Name:</label><input type="text" name="name" id="name" value="';
echo $name;
echo '"/></p>';
if ($auth[0]!==""){
echo '<p><label for="room">Room:</label><input type="text" name="room" id="room" value="';
echo $room;
echo '"/></p>';
}
echo '<br/><input type="submit" value="Enter" /></p></form></div>';
} else {
deleteOldHistory();
// Enter the room
?>
<div id="wrapper">
<div id="menu">
<div style="float:right">Alert on new message:
<select id="whenal">
<option value="alno">never</option>
<option value="alwnf">when not in focus</option>
<option value="alyes">always</option>
</select>
</div>
<p class="welcome">Welcome to the <b><?php echo $room; ?></b> room, <b><?php echo $name; ?></b></p>
</div>
<div id="content">
<div id="chatbox"></div>
</div>
<form name="message" action="">
<input name="usermsg" type="text" id="usermsg" size="63" autocomplete="off" autofocus/>
<input name="submitmsg" type="submit" id="submitmsg" value="Send" />
</form>
</div>
<script type="text/javascript" src="lib/jquery-2.1.3.min.js"></script>
<script type="text/javascript">
// add link or img
function replacer(match, p1,p2,p3, offset, string){
if (p1.charAt(0)=='!') {
return(' <img src="' + p1.substr(1) + '" />');
} else {
return ' <a href="' + p1 + '">' + p1 + '</a>';
}
}
// scans URLS
function lienurl(s){
return s.replace(/\s(!?https?:\/\/([-\w\.]+[-\w]+(:\d+)?(\/([\w/_\.#-]*(\?\S+)?[^\.\s])?)?))/g,replacer);
}
$(document).ready(function() {
var countIdle=0;
var doalert=false; // pas d'alerte au chargement init
var pos = 0;
var lastdate = 0;
var lastday='';
var oldscrollHeight = $("#chatbox")[0].scrollHeight;
var whenal=localStorage.getItem('whenal');
if (whenal===null) whenal="alno";
$("#whenal").val(whenal);
$("#whenal").change(function(){
whenal=$("#whenal").val();
localStorage.setItem('whenal',whenal);
});
$("#submitmsg").click(function() {
if (countIdle==-1) {
myTimer = setInterval(loadLog, <?php echo $interval ?>);
$("#asleep").remove();
}
var clientmsg = $("#usermsg").val();
$("#usermsg").val('');
$("#usermsg").focus();
$.ajax({
type: 'POST',
url: 'post.php',
data: {text: clientmsg,name:'<?php echo $name; ?>',room:'<?php echo $room; ?>'},
async: false,
success: function(data) {
doalert=false;
loadLog(); // pas d'alerte si propre message
},
error: function(request, status, error) {
$("#usermsg").val(clientmsg);
},
});
return false;
});
function loadLog() {
$.ajax({
type: 'POST',
url: 'server.php',
data: {room:'<?php echo $room; ?>', pos: pos, lastdate: lastdate},
dataType: 'json',
async: false,
success: function(data) {
var html='';
var date;
var heure='';
var day='';
var alerted= 0 ;
for (var k in data.data) {
lastdate = data.data[k][0];
date = new Date(parseInt(lastdate)*1000);
heure = date.toLocaleTimeString().substr(0,5);
html = html
+"("+heure+") <b>"
+data.data[k][1]+"</b>: "+data.data[k][2]+"<br>";
}
html=lienurl(html);
if (html!=""){
if (pos==0){
day = date.toLocaleDateString();
if (day!=lastday){
$("#chatbox").append('<b>----- '+day+' -----</b><br>');
if (data.pos==0) {
$("#chatbox").append('<span id="nomsg">No message yet. Enter yours!<br></span>');
}
lastday=day;
}
if (data.pos>0) {
$("#nomsg").remove();
} else {
html="";
}
}
$("#chatbox").append(html);
alerted = doalert &&(whenal=="alyes" || ((whenal!=="alno") && !document.hasFocus()));
if (alerted){
alert('New message!');
}
doalert=true; // par défaut, alerte pour les autres cas
countIdle=0;
} else {
if (countIdle++ > 999) {
$("#chatbox").append('<span id="asleep">No message for a long time. Gone to sleep. Wake up, please!<br></span>');
clearInterval(myTimer);
countIdle=-1;
}
}
var newscrollHeight = $("#chatbox")[0].scrollHeight;
if (newscrollHeight > oldscrollHeight) {
$("#chatbox").scrollTop(newscrollHeight);
}
pos = data.pos;
if (alerted){
loadLog();
}
},
});
}
loadLog();
var myTimer = setInterval(loadLog, <?php echo $interval ?>); //Reload file every $interval ms
});
</script>
<?php } ?>
</body>
</html>

File diff suppressed because one or more lines are too long

View file

@ -1,29 +0,0 @@
<?php
$text = isset($_POST['text']) ? $_POST['text'] : '';
$name = isset($_POST['name']) ? $_POST['name'] : '';
$room = isset($_POST['room']) ? $_POST['room'] : '';
if ($text === '' || $name === '' ) return;
$time = time();
$date = date('Y-m-d', $time);
$historyDir = './history/';
$historyFile = $historyDir.$room.$date;
$fh = @fopen($historyFile, 'a');
if ($fh === false) {
mkdir($historyDir);
$fh = @fopen($historyFile, 'a');
}
/* start semafore */
flock($fh, LOCK_EX);
$data = array($time, $name, stripslashes(htmlspecialchars($text)));
fwrite($fh, implode('>', $data)."\n");
/* end semafore */
flock($fh, LOCK_UN);
fclose($fh);

View file

@ -1,33 +0,0 @@
<?php
$pos = isset($_REQUEST['pos']) ? $_REQUEST['pos'] : '';
$lastdate = isset($_REQUEST['lastdate']) ? $_REQUEST['lastdate'] : '';
$room = isset($_REQUEST['room']) ? $_REQUEST['room'] : '';
$time = time();
$date = date('Y-m-d', $time);
$file = './history/'.$room.$date;
if (!ctype_digit($pos)) return;
settype($pos, "integer");
settype($lastdate, "integer");
$data = array();
if (file_exists($file)) {
if ($pos!=0 && $date!=date('Y-m-d',$lastdate)) {
$pos=0;
} else {
$fh =fopen($file, "r");
if (fseek($fh, $pos)==0) {
$i=0;
while($lig=fgets($fh)){ $data[$i++] = explode('>', $lig); }
$pos =ftell($fh);
}
}
} else if ($date!=date('Y-m-d',$lastdate)) {
$data[0]=array($time,"","");
}
echo json_encode(array('pos' => $pos, 'data' => $data));
?>

View file

@ -1,75 +0,0 @@
/* CSS Document */
html {
height: 100%;
margin: 0;
padding: 0; }
body {
height: 100%;
font: 100% arial;
margin: 0;
padding: 0;
background: #d8d8d8;}
p, span {
margin: 0;
padding: 0; }
form {
margin: 10px 50px;
padding: 0;
}
input {
background: #FEFFF4;
font: 110% arial; }
input[type=submit] {
font-size: 100%;
}
a {
color: #0000FF;
text-decoration: none; }
a:hover { text-decoration: underline; }
#wrapper, #loginform {
background: #d8d8d8;
width: 100%;
height: 100%;
}
#loginform { padding-top: 18px; width: 50%; height: auto; padding-top: 1.5em; padding-bottom: 2.5em; }
#loginform p { margin: 5px; }
#chatbox {
background: #FEFFF4;
position: absolute;
bottom: 80px;
right: 50px;
left: 50px; overflow-y: scroll;
max-height: calc(100% - 140px);
padding: .5em; }
#usermsg {
width: calc(100% - 100px);
padding: 0.5ex;
border: 1px solid #C7C7C7; }
#submit { width: 60px; }
.error { color: #ff0000; }
#menu { padding: 12.5px 25px 12.5px 25px; }
.logout { float: right; }
.tform { display: table; }
.tform p { display: table-row; }
.tform label { display: table-cell; }
.tform input { display: table-cell; }
em {color:red;}
#content{height: calc(100% - 120px); }