Subversion Repositories ALCASAR

Compare Revisions

Ignore whitespace Rev 2393 → Rev 2394

/CHANGELOG
5,6 → 5,7
-------------------- 3.2.0 --------------------
NEWS
- Enable HTTPS support for the CoovaChilli JSON API (that allow HTTPS for status.php).
- The disconnection of users without the status page open can be disabled by a user attribute.
 
ACC
- Add a regex validation when add a local DNS host or a static IP address to avoid breaking the dnsmasq service.
/alcasar.sh
1174,65 → 1174,65
CONFIG=/etc/chilli.conf
pidfile=/var/run/chilli.pid
[ -f \$CONFIG ] || {
echo "\$CONFIG Not found"
exit 0
echo "\$CONFIG Not found"
exit 0
}
current_users_file="/var/tmp/havp/current_users.txt" # file containing active users
RETVAL=0
prog="chilli"
case \$1 in
start)
if [ -f \$pidfile ] ; then
gprintf "chilli is already running"
else
gprintf "Starting \$prog: "
[ -e \$current_users_file ] && echo '' > \$current_users_file
rm -f /var/run/chilli* # cleaning
/usr/sbin/modprobe tun >/dev/null 2>&1
echo 1 > /proc/sys/net/ipv4/ip_forward
[ -e /dev/net/tun ] || {
(cd /dev;
mkdir net;
cd net;
mknod tun c 10 200)
}
ifconfig $INTIF 0.0.0.0
/usr/sbin/ethtool -K $INTIF gro off
daemon /usr/sbin/chilli -c \$CONFIG --pidfile=\$pidfile &
RETVAL=\$?
fi
;;
start)
if [ -f \$pidfile ] ; then
gprintf "chilli is already running"
else
gprintf "Starting \$prog: "
echo '' > \$current_users_file && chown apache:apache \$current_users_file
rm -f /var/run/chilli* # cleaning
/usr/sbin/modprobe tun >/dev/null 2>&1
echo 1 > /proc/sys/net/ipv4/ip_forward
[ -e /dev/net/tun ] || {
(cd /dev;
mkdir net;
cd net;
mknod tun c 10 200)
}
ifconfig $INTIF 0.0.0.0
/usr/sbin/ethtool -K $INTIF gro off
daemon /usr/sbin/chilli -c \$CONFIG --pidfile=\$pidfile &
RETVAL=\$?
fi
;;
 
reload)
killall -HUP chilli
;;
reload)
killall -HUP chilli
;;
 
restart)
\$0 stop
sleep 2
\$0 start
;;
status)
status chilli
RETVAL=0
;;
restart)
\$0 stop
sleep 2
\$0 start
;;
 
stop)
if [ -f \$pidfile ] ; then
gprintf "Shutting down \$prog: "
killproc /usr/sbin/chilli
RETVAL=\$?
[ \$RETVAL = 0 ] && rm -f \$pidfile
[ -e \$current_users_file ] && rm -f \$current_users_file
else
gprintf "chilli is not running"
fi
;;
*)
echo "Usage: \$0 {start|stop|restart|reload|status}"
exit 1
status)
status chilli
RETVAL=0
;;
 
stop)
if [ -f \$pidfile ] ; then
gprintf "Shutting down \$prog: "
killproc /usr/sbin/chilli
RETVAL=\$?
[ \$RETVAL = 0 ] && rm -f \$pidfile
[ -e \$current_users_file ] && rm -f \$current_users_file
else
gprintf "chilli is not running"
fi
;;
 
*)
echo "Usage: \$0 {start|stop|restart|reload|status}"
exit 1
esac
echo
EOF
/conf/freeradius-web/user_edit.attrs
8,6 → 8,7
Expiration <a href="help/expiration_help.html" target=lt_help onclick=window.open("help/expiration_help.html","lt_help","width=600,height=250,toolbar=no,scrollbars=no,resizable=yes") title="Expiration Help Page"><font color="blue">Date d'expiration</font></a>
Max-All-Session <a href="help/max_all_session_help.html" target=st_help onclick=window.open("help/max_all_session_help.html","st_help","width=600,height=250,toolbar=no,scrollbars=no,resizable=yes") title="Max connection Time Help Page"><font color="blue">Dur&eacute;e totale de connexion autoris&eacute;e</font></a><BR>(en secondes)
Session-Timeout <a href="help/session_timeout_help.html" target=st_help onclick=window.open("help/session_timeout_help.html","st_help","width=600,height=250,toolbar=no,scrollbars=no,resizable=yes") title="Session Timeout Help Page"><font color="blue">Dur&eacute;e maximale d'une session</font></a><BR>(en secondes)
Idle-Timeout <a href="help/idle_timeout_help.html" target=it_help onclick=window.open("help/idle_timeout_help.html","it_help","width=600,height=170,toolbar=no,scrollbars=no,resizable=yes") title="Idle Timeout Help Page"><font color="blue">Idle Timeout</font></a>
Max-Daily-Session <a href="help/session_timeout_help.html" target=st_help onclick=window.open("help/session_timeout_help.html","st_help","width=600,height=250,toolbar=no,scrollbars=no,resizable=yes") title="Session Timeout Help Page"><font color="blue">Dur&eacute;e limite journali&egrave;re</font></a><BR>(en secondes)
#Max-Weekly-Session Weekly Limit (secs)
Max-Monthly-Session <a href="help/session_timeout_help.html" target=st_help onclick=window.open("help/session_timeout_help.html","st_help","width=600,height=250,toolbar=no,scrollbars=no,resizable=yes") title="Session Timeout Help Page"><font color="blue">Dur&eacute;e limite mensuelle</font></a><BR>(en secondes)
/scripts/alcasar-condown.sh
20,6 → 20,7
# 1: profile_2 (WEB + Mail + Remote access)
# 2: profile_3 (Custom)
# 3: warn_user (if imputability report has been generated)
# 4: status_open_required (check user activity through status page)
# 5: WL
# 6: BL
# 7: HAVP
49,7 → 50,7
 
# Remove IP address from active users
current_users_file="/var/tmp/havp/current_users.txt"
[ -e $current_users_file ] && sed -i "/^$FRAMED_IP_ADDRESS\$/d" $current_users_file
[ -e $current_users_file ] && sed -i "/^$FRAMED_IP_ADDRESS:/d" $current_users_file
 
# Debug : show all the coova parse variables (+ $set_filter + $set_proto).
# see "/src/chilli.c" for the complete list of parse variables
/scripts/alcasar-conup.sh
20,6 → 20,7
# 1: profile_2 (WEB + Mail + Remote access)
# 2: profile_3 (Custom)
# 3: warn_user (if imputability report has been generated)
# 4: status_open_required (check user activity through status page)
# 5: WL
# 6: BL
# 7: HAVP
47,6 → 48,13
ipset add $set_filter $FRAMED_IP_ADDRESS
ipset add $set_proto $FRAMED_IP_ADDRESS
 
# Add user IP permanently to current_users.txt if no status_open_required
current_users_file="/var/tmp/havp/current_users.txt"
[ ! -e $current_users_file ] && touch $current_users_file && chown apache:apache $current_users_file
if [ ${FILTER_ID:4:1} == '0' ]; then # no status_open_required
echo "$FRAMED_IP_ADDRESS:PERM" >> $current_users_file
fi
 
# Debug : show all the coova parse variables (+ $set_filter + $set_proto).
# see "/src/chilli.c" for the complete list of parse variables
#echo "-----------------------------------------------" >> /tmp/debug-conup.txt
/scripts/alcasar-watchdog.sh
105,25 → 105,25
lan_test
# We disconnect inactive users (its means that their 'status.php' tab has been closed --> their ip address isn't in $current_users_file)
# process each equipment known by chilli to check if IP address is usurped (with arping)
for system in `/usr/sbin/chilli_query list |grep -v "\.0\.0\.0"`
for system in `/usr/sbin/chilli_query list | grep -v "0\.0\.0\.0"`
do
active_ip=`echo $system |cut -d" " -f2`
active_session=`echo $system |cut -d" " -f5`
active_mac=`echo $system | cut -d" " -f1`
active_user=`echo $system |cut -d" " -f6`
#We disconnect inactive user here :
#We check if this is not an auth @MAC and if he is still connected
# We disconnect inactive user here :
# We check if this is not an auth @MAC and if he is still connected
if [ "$active_user" != "$active_mac" ] && [ $(expr $active_session) -eq 1 ]; then
if [ -e $current_users_file ]; then
# We check if user @IP is in 'current_users.txt'
cmp_user_ok=$(cat $current_users_file | grep "^$active_ip\$" -c)
cmp_user_ok=$(cat $current_users_file | awk -F':' "\$1 == \"$active_ip\" {print \$2}")
# If not we disconnect this user.
if [ $cmp_user_ok -eq 0 ]; then
if [ -z "$cmp_user_ok" ]; then
logger "alcasar-watchdog : $active_ip ($active_mac) can't be contact. We disconnects the user ($active_user)."
/usr/sbin/chilli_query logout $active_mac
else
elif [ "$cmp_user_ok" == "TEMP" ]; then
# Remove the user's IP from 'current_users.txt'. Every user need to insert their @IP everytime to prove their connectivity.
sed -i "/^$active_ip\$/d" $current_users_file
sed -i "/^$active_ip:$cmp_user_ok\$/d" $current_users_file
fi
else # "current_user.txt" does not exists. We disconnect every users.
logger "alcasar-watchdog : The file /var/tmp/havp/current_users.txt doen't' exist. We disconnects the user $active_user"
/web/acc/manager/htdocs/group_new.php
6,14 → 6,22
include("../lib/langues.php");
 
//update Filter-Id for protocol filtering
if (isset($_POST['Filter-Proto']) && isset($_POST['Filter-Id']))
if (isset($_POST['Filter-Proto']) && isset($_POST['Status-Open-Required']) && isset($_POST['Filter-Id']))
{
$upId = (int)$_POST['Filter-Proto'];
$downId = (int)$_POST['Filter-Id'];
$upId = $upId+$downId;
$upId = str_pad($upId, 8, '0', STR_PAD_LEFT);
$_POST['Filter-Id'] = $upId;
$filterId = (int)$_POST['Filter-Id'];
$FilterProto = (int)$_POST['Filter-Proto'];
$statusOpenRequired = (int)($_POST['Status-Open-Required'].'000');
$filterId = $filterId+$FilterProto+$statusOpenRequired;
$_POST['Filter-Id'] = str_pad($filterId, 8, '0', STR_PAD_LEFT);
}
if (isset($_POST['Status-Open-Required'])) {
if ($_POST['Status-Open-Required'] === '0') {
$_POST['Idle-Timeout'] = '600'; // 10 minutes
} else {
$_POST['Idle-Timeout'] = '';
}
$_POST['Idle-Timeout_op'] = '=';
}
 
require('/etc/freeradius-web/config.php');
 
172,6 → 180,7
 
EOM;
foreach($show_attrs as $key => $desc){
if ($key === 'Idle-Timeout') continue;
$name = $attrmap["$key"];
if ($name == 'none')
continue;
434,7 → 443,21
<option value=\"01000000\" >$l_proto_2</option>
<option value=\"00100000\" >$l_proto_3</option>
</select></td></tr>";
 
// User need to keep status page open
print <<<EOM
<tr class="advanced-field">
<td class="etiquette" colspan="$colspan">
<a href="help/statusOpenRequired_help.html" target=help onclick="window.open('help/statusOpenRequired_help.html','help','width=600,height=250,toolbar=no,scrollbars=no,resizable=yes')" title="$l_click_for_help"><font color="blue">$l_statusOpenRequired</font></a>
</td>
EOM;
echo "<td width=20>
<label><input type=\"radio\" name=\"Status-Open-Required\" value=\"1\" checked>$l_yes</label>
<label><input type=\"radio\" name=\"Status-Open-Required\" value=\"0\">$l_no</label>
</select></td>
</tr>";
echo "</table><BR>";
 
}
if ($create == 1)
echo "<br/><center><a href=\"group_admin.php?login=$login\">$l_show_profile</a></center>";
/web/acc/manager/htdocs/help/statusOpenRequired_help.html
0,0 → 1,27
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Help Page</title>
<link rel="stylesheet" href="/css/style.css" type="text/css">
</HEAD>
<body>
<center>
<TABLE width="100%" border="0" cellspacing="0" cellpadding="0">
<tr><th>Déconnexion page status fermée - Disconnection status page closed</th></tr>
<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
</TABLE>
<TABLE width="100%" border=1 cellspacing=0 cellpadding=1>
<tr><td valign="middle" align="left">
Cet attribut définit si l'usager doit laisser la page status ouverte durant sa session. Dans le cas contraire, il sera déconnecté.<br>
Si cet attribut n'est activé, l'état de l'activité de l'usager sera défini en fonction de l'activité réseau de sa machine de consultation.
<HR>
This attribute defines whether the user should leave the status page open during his session. If not, it will be disconnected.<br>
If this attribute is not activated, the activity status of the user will be defined according to the network activity of his lookup machine.
</td></tr>
</table>
<br>
<a href="javascript:window.close();"><b>Fermer / Close</b></a>
</center>
</body>
</html>
/web/acc/manager/htdocs/user_edit.php
6,14 → 6,22
include("../lib/langues.php");
 
//update Filter-Id for protocol filtering
if (isset($_POST['Filter-Proto']) && isset($_POST['Filter-Id0']))
if (isset($_POST['Filter-Proto']) && isset($_POST['Status-Open-Required']) && isset($_POST['Filter-Id0']))
{
$upId = (int)$_POST['Filter-Proto'];
$downId = (int)$_POST['Filter-Id0'];
$upId = $upId+$downId;
$upId = str_pad($upId, 8, '0', STR_PAD_LEFT);
$_POST['Filter-Id0'] = $upId;
$filterId = (int)$_POST['Filter-Id0'];
$FilterProto = (int)$_POST['Filter-Proto'];
$statusOpenRequired = (int)($_POST['Status-Open-Required'].'000');
$filterId = $filterId+$FilterProto+$statusOpenRequired;
$_POST['Filter-Id0'] = str_pad($filterId, 8, '0', STR_PAD_LEFT);
}
if (isset($_POST['Status-Open-Required'])) {
if ($_POST['Status-Open-Required'] === '0') {
$_POST['Idle-Timeout0'] = '600'; // 10 minutes
} else {
$_POST['Idle-Timeout0'] = '';
}
$_POST['Idle-Timeout0_op'] = '=';
}
 
require('/etc/freeradius-web/config.php');
require('../lib/attrshow.php');
189,6 → 197,7
$login = $login_saved;
foreach ($show_attrs as $key => $desc) {
if ($key === 'Idle-Timeout') continue;
$name = $attrmap["$key"];
$generic = (isset($attrmap['generic']["$key"])) ? $attrmap['generic']["$key"] : '';
if ($name == 'none')
302,6 → 311,12
} else {
$grp_proto = $l_proto_0;
}
 
if ($val[4] === '1') {
$grp_statusOpenRequired = $l_yes;
} else {
$grp_statusOpenRequired = $l_no;
}
break;
}
370,6 → 385,7
}
 
foreach($show_attrs as $key => $desc){
if ($key === 'Idle-Timeout') continue;
$name = $attrmap["$key"];
$generic = (isset($attrmap['generic']["$key"])) ? $attrmap['generic']["$key"] : '';
if ($name == 'none')
710,50 → 726,71
}
}
/*protocole filter*/
print <<<EOM
<tr>
<td class="etiquette" colspan="$colspan">
<a href="help/protocols_help.html" target=help onclick="window.open('help/protocols_help.html','help','width=600,height=250,toolbar=no,scrollbars=no,resizable=yes')" title="$l_click_for_help"><font color="blue">$l_proto</font></a>
</td>
/*protocole filter*/
print <<<EOM
<tr>
<td class="etiquette" colspan="$colspan">
<a href="help/protocols_help.html" target=help onclick="window.open('help/protocols_help.html','help','width=600,height=250,toolbar=no,scrollbars=no,resizable=yes')" title="$l_click_for_help"><font color="blue">$l_proto</font></a>
</td>
EOM;
if(isset($member_groups) && $user_type != 'group') {
echo "<td bgcolor=\"#BEBEBE\">$grp_proto</td>";
}
if(isset($member_groups) && $user_type != 'group') {
echo "<td bgcolor=\"#BEBEBE\">$grp_proto</td>";
}
 
if ($val[2] === '1') {
$selected = 'proto_3';
} else if ($val[1] === '1') {
$selected = 'proto_2';
} else if ($val[0] === '1') {
$selected = 'proto_1';
} else {
$selected = 'proto_0';
}
echo "<td width=20>";
echo "<select name='Filter-Proto'>
<option value=\"00000000\"".(($selected === 'proto_0') ? ' selected' : '').">$l_proto_0</option>
<option value=\"10000000\"".(($selected === 'proto_1') ? ' selected' : '').">$l_proto_1</option>
<option value=\"01000000\"".(($selected === 'proto_2') ? ' selected' : '').">$l_proto_2</option>
<option value=\"00100000\"".(($selected === 'proto_3') ? ' selected' : '').">$l_proto_3</option>
</select></td>
</tr>";
if ($user_type != 'group') {
echo <<<EOM
<tr>
<td align=right colspan="$colspan" bgcolor="#d0ddb0">
$l_group_member<br><font size=-2><i>($l_main_group)</i></font>
if ($val[2] === '1') {
$selected = 'proto_3';
} else if ($val[1] === '1') {
$selected = 'proto_2';
} else if ($val[0] === '1') {
$selected = 'proto_1';
} else {
$selected = 'proto_0';
}
echo "<td width=20>";
echo "<select name='Filter-Proto'>
<option value=\"00000000\"".(($selected === 'proto_0') ? ' selected' : '').">$l_proto_0</option>
<option value=\"10000000\"".(($selected === 'proto_1') ? ' selected' : '').">$l_proto_1</option>
<option value=\"01000000\"".(($selected === 'proto_2') ? ' selected' : '').">$l_proto_2</option>
<option value=\"00100000\"".(($selected === 'proto_3') ? ' selected' : '').">$l_proto_3</option>
</select></td>
</tr>";
 
// User need to keep status page open
print <<<EOM
<tr class="advanced-field">
<td class="etiquette" colspan="$colspan">
<a href="help/statusOpenRequired_help.html" target=help onclick="window.open('help/statusOpenRequired_help.html','help','width=600,height=250,toolbar=no,scrollbars=no,resizable=yes')" title="$l_click_for_help"><font color="blue">$l_statusOpenRequired</font></a>
</td>
EOM;
if (isset($member_groups)) {
echo '<td colspan="2">';
} else {
echo '<td>';
}
if(isset($member_groups) && $user_type != 'group') {
echo "<td bgcolor=\"#BEBEBE\">$grp_statusOpenRequired</td>";
}
if ($val[4] === '1') {
$selected = true;
} else {
$selected = false;
}
echo "<td width=20>
<label><input type=\"radio\" name=\"Status-Open-Required\" value=\"1\"".(($selected) ? ' checked' : '').">$l_yes</label>
<label><input type=\"radio\" name=\"Status-Open-Required\" value=\"0\"".((!$selected) ? ' checked' : '').">$l_no</label>
</select></td>
</tr>";
 
 
if ($user_type != 'group') {
echo <<<EOM
<tr>
<td align=right colspan="$colspan" bgcolor="#d0ddb0">
$l_group_member<br><font size=-2><i>($l_main_group)</i></font>
</td>
EOM;
if (isset($member_groups)) {
echo '<td colspan="2">';
} else {
echo '<td>';
}
 
 
if (isset($existing_groups)){
echo '<select size="5" name="edited_groups[]" OnChange="this.form.group_change.value=1">';
if ($config['sql_show_all_groups'] == 'true') {
/web/acc/manager/htdocs/user_new.php
5,6 → 5,26
if (is_file("../lib/langues.php"))
include("../lib/langues.php");
 
//update Filter-Id for protocol filtering
if (isset($_POST['Filter-Proto']) && isset($_POST['Status-Open-Required']) && isset($_POST['Filter-Id']))
{
$filterId = (int)$_POST['Filter-Id'];
$FilterProto = (int)$_POST['Filter-Proto'];
$statusOpenRequired = (int)($_POST['Status-Open-Required'].'000');
$filterId = $filterId+$FilterProto+$statusOpenRequired;
$_POST['Filter-Id'] = str_pad($filterId, 8, '0', STR_PAD_LEFT);
}
if (isset($_POST['Status-Open-Required'])) {
if ($_POST['Status-Open-Required'] === '0') {
$_POST['Idle-Timeout'] = '600'; // 10 minutes
} else {
$_POST['Idle-Timeout'] = '';
}
$_POST['Idle-Timeout_op'] = '=';
}
 
require('/etc/freeradius-web/config.php');
 
if(!isset($create)) $create=0;
if(!isset($show)) $show=0;
if(!isset($login)) $login = '';
14,17 → 34,6
if(!isset($selected)) $selected = array();
if(!isset($selected['='])) $selected['='] = '';
 
//update Filter-Id for protocol filtering
if (isset($_POST['Filter-Proto']) && isset($_POST['Filter-Id']))
{
$upId = (int)$_POST['Filter-Proto'];
$downId = (int)$_POST['Filter-Id'];
$upId = $upId+$downId;
$upId = str_pad($upId, 8, '0', STR_PAD_LEFT);
$_POST['Filter-Id'] = $upId;
}
 
require('/etc/freeradius-web/config.php');
require('../lib/attrshow.php');
require('../lib/defaults.php');
 
246,6 → 255,7
EOM;
}
foreach ($show_attrs as $key => $desc) {
if ($key === 'Idle-Timeout') continue;
$name = $attrmap["$key"];
if ($name == 'none')
continue;
507,8 → 517,22
<option value=\"01000000\" >$l_proto_2</option>
<option value=\"00100000\" >$l_proto_3</option>
</select></td></tr>";
 
// User need to keep status page open
print <<<EOM
<tr class="advanced-field">
<td class="etiquette" colspan="$colspan">
<a href="help/statusOpenRequired_help.html" target=help onclick="window.open('help/statusOpenRequired_help.html','help','width=600,height=250,toolbar=no,scrollbars=no,resizable=yes')" title="$l_click_for_help"><font color="blue">$l_statusOpenRequired</font></a>
</td>
EOM;
echo "<td width=20>
<label><input type=\"radio\" name=\"Status-Open-Required\" value=\"1\" checked>$l_yes</label>
<label><input type=\"radio\" name=\"Status-Open-Required\" value=\"0\">$l_no</label>
</select></td>
</tr>";
 
 
print <<<EOM
<tr>
<td class="etiquette" colspan="$colspan">
$l_lang_ticket
/web/acc/manager/lib/langues.php
13,8 → 13,8
$l_monday="lundi"; $l_tuesday="mardi"; $l_wednesday="mercredi"; $l_thursday="jeudi"; $l_friday="vendredi"; $l_saturday="samedi"; $l_sunday="dimanche";
$l_monthly="mensuelle";$l_weekly="hebdomadaire";$l_daily="journalière";$l_by_session="par session";
$l_day = "Jour";
$l_limit="limite";
$l_daily_limit="limite journalière";
$l_limit="limite";
$l_daily_limit="limite journalière";
$l_used_time = "Temps utilisé";
$l_last7days_status = "&Eacute;tat sur les 7 derniers jours";
$l_connections_number = "Nombre de connexions";
130,6 → 130,9
$l_empty="Vide";
$l_ipAddress="Adresse IP";
$l_rule="Règle";
$l_statusOpenRequired="Déconnexion page status fermée";
$l_yes="Oui";
$l_no="Non";
break;
default :
//English
253,6 → 256,9
$l_empty="Empty";
$l_ipAddress="IP address";
$l_rule="Rule";
$l_statusOpenRequired="Disconnection status page closed";
$l_yes="Yes";
$l_no="No";
break;
}
?>
/web/status.php
311,33 → 311,6
$cn = (!empty($row['name'])) ? $row['name'] : $user[5];
}
}
 
// Store the user @IP in a file (to test if he is still active).
$filename = '/var/tmp/havp/current_users.txt';
if (file_exists($filename)) {
$current_users_file = fopen($filename, 'r');
$content = file($filename);
fclose($current_users_file);
if (empty($content)) {
file_put_contents($filename, $_SERVER['REMOTE_ADDR'].PHP_EOL);
} else {
$change_me = 1; // avoid duplicate user @IP
// if we found duplicate IP, we will not write user @IP (just set change_me = 0)
foreach ($content as $line) {
$line = preg_replace('/\s+/', '', $line);
if ($line === $_SERVER['REMOTE_ADDR']) {
$change_me = 0;
}
}
// if user @IP does not exist, we write it
if ($change_me) {
file_put_contents($filename, $_SERVER['REMOTE_ADDR'].PHP_EOL, FILE_APPEND);
}
}
} else {
// we create filename and we write user @IP.
file_put_contents($filename, $_SERVER['REMOTE_ADDR'].PHP_EOL);
}
}
}
 
/web/still_connected.php
1,39 → 1,27
<?php
 
//store user @IP who can join this page (still have their status.php tab open) in a file.
$filename='/var/tmp/havp/current_users.txt';
$change_me = 1;
// store user @IP who can join this page (still have their status.php tab open) in a file.
$filename = '/var/tmp/havp/current_users.txt';
$user_ip = $_SERVER['REMOTE_ADDR'];
 
//check if file exists
if(file_exists($filename)){
$current_users_file = fopen($filename, "r");
$content = file($filename);
fclose($current_users_file);
// if file is empty, we put user @IP in it.
if(empty($content))
{
file_put_contents($filename, $_SERVER['REMOTE_ADDR'].PHP_EOL);
}
else
{
// if we found duplicate user IP, it will not be writen again
foreach($content as $line){
$line = preg_replace('/\s+/', '', $line); #remove whitespace
if($line == $_SERVER['REMOTE_ADDR'])
{
$change_me = 0;
}
}
// else we write user IP in the file
if($change_me)
{
file_put_contents($filename, $_SERVER['REMOTE_ADDR'].PHP_EOL , FILE_APPEND);
}
}
if ((!file_exists($filename)) || (filesize($filename) === 0)) {
// Creating file and write user @IP.
file_put_contents($filename, $user_ip.':TEMP'.PHP_EOL);
} else {
// If we found duplicate user IP, it will not be writen again
$found = false;
$fh = fopen($filename, 'r');
while (!feof($fh)) {
$line = fgets($fh, 1024);
if (preg_match('/^'.preg_quote($user_ip).':/', $line)) {
$found = true;
break;
}
}
fclose($fh);
 
// else we write user IP in the file
if (!$found) {
file_put_contents($filename, $user_ip.':TEMP'.PHP_EOL, FILE_APPEND);
}
}
else
{
//The file doesn't exist. We create it and write user @IP.
file_put_contents($filename, $_SERVER['REMOTE_ADDR'].PHP_EOL);
}
?>