diff --git a/includes/config.inc.php-dist b/includes/config.inc.php-dist
index 51f0bdd..bc00616 100644
--- a/includes/config.inc.php-dist
+++ b/includes/config.inc.php-dist
@@ -7,7 +7,12 @@ $apiproto = 'http'; # http | https
$apisslverify = FALSE; # Verify SSL Certificate if using https for apiproto
$allowzoneadd = FALSE; # Allow normal users to add zones
$logging = TRUE;
+$allowclearlogs = TRUE; # Allow clearing of log entries
+$allowrotatelogs = FALSE;# Allow rotation to text file on server
+# Log directory - if allowrotatelogs is set, this is where the logs will
+# be written. It must be writeable by the web server user.
+$logsdirectory = "../etc";
# If you configure this, nsedit will try to authenticate via WeFact too.
# Debtors will be added to the sqlitedatabase with their crypted password.
diff --git a/includes/misc.inc.php b/includes/misc.inc.php
index fd75739..4281a89 100644
--- a/includes/misc.inc.php
+++ b/includes/misc.inc.php
@@ -276,6 +276,58 @@ function clearlogs() {
writelog("Logtable truncated.");
}
+function rotatelogs() {
+ global $logging, $logsdirectory;
+ if ($logging !== TRUE)
+ return FALSE;
+
+ if(!is_dir($logsdirectory) || !is_writable($logsdirectory)) {
+ writelog("Logs directory cannot be written to.");
+ return FALSE;
+ }
+
+ date_default_timezone_set('UTC');
+ $filename = date("Y-m-d-His") . ".json";
+ $file = fopen($logsdirectory . "/" . $filename, "x");
+
+ if($file === FALSE) {
+ writelog("Can't create file for log rotation.");
+ return FALSE;
+ }
+
+ if(fwrite($file,json_encode(getlogs())) === FALSE) {
+ writelog("Can't write to file for log rotation.");
+ fclose($file);
+ return FALSE;
+ } else {
+ fclose($file);
+ clearlogs();
+ return $filename;
+ }
+
+}
+
+function listrotatedlogs() {
+ global $logging, $logsdirectory;
+ if ($logging !== TRUE)
+ return FALSE;
+
+ $list = scandir($logsdirectory,SCANDIR_SORT_DESCENDING);
+
+ if($list === FALSE) {
+ writelog("Logs directory cannot read.");
+ return FALSE;
+ }
+
+ $list=array_filter($list,
+ function ($val) {
+ return(preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}-[0-9]{6}\.json/',$val) == 1);
+ }
+ );
+
+ return $list;
+}
+
function writelog($line, $user=False) {
global $logging;
if ($logging !== TRUE)
diff --git a/index.php b/index.php
index 614f7f2..41f23ac 100644
--- a/index.php
+++ b/index.php
@@ -114,7 +114,12 @@ if ($blocklogin === TRUE) {
- Are you sure you want to clear all the logs? Maybe save them first?
+ Are you sure you want to clear the current logs? Maybe download them
+ first, or use "Rotate logs" to save
+ them on the server?
+
+
+ Are you sure you want to rotate the current logs?