-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcron-update.php
42 lines (36 loc) · 1.45 KB
/
cron-update.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
#!/usr/bin/php
<?php
// update the "last connection time" for all users from a spool directory
// and rebuild if necessary all the client-connection settings files
$verbose=false;
if (isset($argv[1]) && $argv[1]=="verbose") $verbose=true;
define("SKIP_IDENTITY_CONTROL",1);
require_once("head.php");
$d=opendir($updatespool);
if (!$d) {
echo "Can't oepn $updatespool, please check\n";
exit();
}
while (($c=readdir($d))!==false) {
if (is_file($updatespool."/".$c)) {
rename($updatespool."/".$c, $updatespool."/".$c.".tmp");
list($user,$date)=explode("|",file_get_contents($updatespool."/".$c.".tmp"));
if ($verbose) echo date("Y-m-d H:i:s")." Updating user $user for date $date \n";
if ($user && $date) {
$db->exec("UPDATE users SET used='".addslashes($date)."' WHERE username='".addslashes($user)."';");
}
@unlink($updatespool."/".$c.".tmp");
if ($verbose) echo date("Y-m-d H:i:s")." done \n";
}
}
// closes the sqlite connection
$db=null;
// if the touchfile saying something changed for a user exists, copy the sqlite DB to the read-file
// prevents a LOCK on the sqlite when openvpn is reading it :)
if (file_exists($touchfile)) {
if ($verbose) echo date("Y-m-d H:i:s")." managing touchfile \n";
@unlink($touchfile);
copy($sqlitedb,$sqlitedb.".tmp");
rename($sqlitedb.".tmp",$sqlitedb.".copy"); // atomic, used by openvpn
if ($verbose) echo date("Y-m-d H:i:s")." done \n";
}