Browse Source

work on purge log

causefx 8 years ago
parent
commit
149e2a3a5b
5 changed files with 180 additions and 119 deletions
  1. 16 0
      api/functions/organizr-functions.php
  2. 19 0
      api/index.php
  3. 118 117
      api/pages/settings-settings-logs.php
  4. 7 2
      js/custom.js
  5. 20 0
      js/functions.js

+ 16 - 0
api/functions/organizr-functions.php

@@ -93,6 +93,22 @@ function register($array){
         return 'mismatch';
     }
 }
+function removeFile($array){
+    $filePath = $array['data']['path'];
+    $fileName = $array['data']['name'];
+    if (file_exists($filePath)){
+        if (unlink($filePath)) {
+            writeLog('success', 'Log Management Function - Log: '.$fileName.' has been purged/deleted', 'SYSTEM');
+            return true;
+        } else {
+            writeLog('error', 'Log Management Function - Log: '.$fileName.' - Error Occured', 'SYSTEM');
+            return false;
+        }
+    } else {
+        writeLog('error', 'Log Management Function - Log: '.$fileName.' does not exist', 'SYSTEM');
+        return false;
+    }
+}
 function recover($array){
     $email = $array['data']['email'];
     $newPassword = randString(10);

+ 19 - 0
api/index.php

@@ -254,6 +254,25 @@ switch ($function) {
                 break;
         }
         break;
+	case 'v1_remove_file':
+        switch ($method) {
+            case 'POST':
+                if(qualifyRequest(1)){
+                    $result['status'] = 'success';
+                    $result['statusText'] = 'success';
+                    $result['data'] = removeFile($_POST);
+                }else{
+                    $result['status'] = 'error';
+                    $result['statusText'] = 'API/Token invalid or not set';
+                    $result['data'] = null;
+                }
+                break;
+            default:
+                $result['status'] = 'error';
+                $result['statusText'] = 'The function requested is not defined for method: '.$method;
+                break;
+        }
+        break;
     case 'v1_update_config':
         switch ($method) {
             case 'POST':

+ 118 - 117
api/pages/settings-settings-logs.php

@@ -1,128 +1,129 @@
 <?php
-
-$pageSettingsSettingsLogs = '
-<script>
-$(document).on("click", ".swapLog", function(e) {
-    var log = $(this).attr(\'data-name\')+\'Div\';
-    $(\'.logTable\').addClass(\'hidden\');
-    $(\'.\'+log).addClass(\'show\').removeClass(\'hidden\');
-	$(\'.swapLog\').removeClass(\'active\');
-	$(this).addClass(\'active\');
-});
-</script>
-<div class="btn-group m-b-20 pull-left">
-    <button type="button" class="btn btn-default btn-outline waves-effect bg-org swapLog active" data-name="loginLog" lang="en">Login Log</button>
-    <button type="button" class="btn btn-default btn-outline waves-effect bg-org swapLog" data-name="orgLog" lang="en">Organizr Log</button>
-</div>
-<button class="btn btn-danger btn-sm waves-effect waves-light pull-right purgeLog" type="button"><span class="btn-label"><i class="fa fa-trash"></i></span>Purge Log</button>
-<div class="clearfix"></div>
-<div class="white-box bg-org logTable loginLogDiv">
-    <h3 class="box-title m-b-0" lang="en">Login Logs</h3>
-    <div class="table-responsive">
-        <table id="loginLogTable" class="table table-striped">
-            <thead>
-                <tr>
-                    <th lang="en">Date</th>
-                    <th lang="en">Username</th>
-                    <th lang="en">IP Address</th>
-                    <th lang="en">Type</th>
-                </tr>
-            </thead>
-			<tfoot>
-                <tr>
-                    <th lang="en">Date</th>
-                    <th lang="en">Username</th>
-                    <th lang="en">IP Address</th>
-                    <th lang="en">Type</th>
-                </tr>
-            </tfoot>
-            <tbody></tbody>
-        </table>
+if(file_exists('config'.DIRECTORY_SEPARATOR.'config.php')){
+    $pageSettingsSettingsLogs = '
+    <script>
+    $(document).on("click", ".swapLog", function(e) {
+        var log = $(this).attr(\'data-name\')+\'Div\';
+        $(\'.logTable\').addClass(\'hidden\');
+        $(\'.\'+log).addClass(\'show\').removeClass(\'hidden\');
+    	$(\'.swapLog\').removeClass(\'active\');
+    	$(this).addClass(\'active\');
+    });
+    </script>
+    <div class="btn-group m-b-20 pull-left">
+        <button type="button" class="btn btn-default btn-outline waves-effect bg-org swapLog active" data-name="loginLog" data-path="'.$GLOBALS['organizrLoginLog'].'" lang="en">Login Log</button>
+        <button type="button" class="btn btn-default btn-outline waves-effect bg-org swapLog" data-name="orgLog" data-path="'.$GLOBALS['organizrLog'].'" lang="en">Organizr Log</button>
+    </div>
+    <button class="btn btn-danger btn-sm waves-effect waves-light pull-right purgeLog" type="button"><span class="btn-label"><i class="fa fa-trash"></i></span>Purge Log</button>
+    <div class="clearfix"></div>
+    <div class="white-box bg-org logTable loginLogDiv">
+        <h3 class="box-title m-b-0" lang="en">Login Logs</h3>
+        <div class="table-responsive">
+            <table id="loginLogTable" class="table table-striped">
+                <thead>
+                    <tr>
+                        <th lang="en">Date</th>
+                        <th lang="en">Username</th>
+                        <th lang="en">IP Address</th>
+                        <th lang="en">Type</th>
+                    </tr>
+                </thead>
+    			<tfoot>
+                    <tr>
+                        <th lang="en">Date</th>
+                        <th lang="en">Username</th>
+                        <th lang="en">IP Address</th>
+                        <th lang="en">Type</th>
+                    </tr>
+                </tfoot>
+                <tbody></tbody>
+            </table>
+        </div>
     </div>
-</div>
-<div class="white-box bg-org logTable orgLogDiv hidden">
-    <h3 class="box-title m-b-0" lang="en">Organizr Logs</h3>
-    <div class="table-responsive">
-        <table id="organizrLogTable" class="table table-striped">
-            <thead>
-                <tr>
-                    <th lang="en">Date</th>
-                    <th lang="en">Username</th>
-                    <th lang="en">IP Address</th>
-                    <th lang="en">Message</th>
-                    <th lang="en">Type</th>
-                </tr>
-            </thead>
-            <tfoot>
-                <tr>
-                    <th lang="en">Date</th>
-                    <th lang="en">Username</th>
-                    <th lang="en">IP Address</th>
-                    <th lang="en">Message</th>
-                    <th lang="en">Type</th>
-                </tr>
-            </tfoot>
-            <tbody></tbody>
-        </table>
+    <div class="white-box bg-org logTable orgLogDiv hidden">
+        <h3 class="box-title m-b-0" lang="en">Organizr Logs</h3>
+        <div class="table-responsive">
+            <table id="organizrLogTable" class="table table-striped">
+                <thead>
+                    <tr>
+                        <th lang="en">Date</th>
+                        <th lang="en">Username</th>
+                        <th lang="en">IP Address</th>
+                        <th lang="en">Message</th>
+                        <th lang="en">Type</th>
+                    </tr>
+                </thead>
+                <tfoot>
+                    <tr>
+                        <th lang="en">Date</th>
+                        <th lang="en">Username</th>
+                        <th lang="en">IP Address</th>
+                        <th lang="en">Message</th>
+                        <th lang="en">Type</th>
+                    </tr>
+                </tfoot>
+                <tbody></tbody>
+            </table>
+        </div>
     </div>
-</div>
-<!-- /.container-fluid -->
-<script>
-//$.fn.dataTable.moment(\'DD-MMM-Y HH:mm:ss\');
-$("#loginLogTable").DataTable( {
-        "ajax": "api/?v1/login_log",
-        "columns": [
-            { data: \'utc_date\',
-                render: function ( data, type, row ) {
-                    if ( type === \'display\' || type === \'filter\' ) {
-                        var m = moment.tz(data, activeInfo.timezone);
-                        return moment(m).format(\'LLL\');
+    <!-- /.container-fluid -->
+    <script>
+    //$.fn.dataTable.moment(\'DD-MMM-Y HH:mm:ss\');
+    $("#loginLogTable").DataTable( {
+            "ajax": "api/?v1/login_log",
+            "columns": [
+                { data: \'utc_date\',
+                    render: function ( data, type, row ) {
+                        if ( type === \'display\' || type === \'filter\' ) {
+                            var m = moment.tz(data, activeInfo.timezone);
+                            return moment(m).format(\'LLL\');
+                        }
+                        return data;
                     }
-                    return data;
-                }
-            },
-            { "data": "username" },
-            { "data": "ip" },
-            { data: \'auth_type\',
-                render: function ( data, type, row ) {
-                    if ( type === \'display\' || type === \'filter\' ) {
+                },
+                { "data": "username" },
+                { "data": "ip" },
+                { data: \'auth_type\',
+                    render: function ( data, type, row ) {
+                        if ( type === \'display\' || type === \'filter\' ) {
+                            return logIcon(data);
+                        }
                         return logIcon(data);
                     }
-                    return logIcon(data);
                 }
-            }
-        ],
-        "order": [[ 0, \'desc\' ]],
-} );
-$("#organizrLogTable").DataTable( {
-        "ajax": "api/?v1/organizr_log",
-            "columns": [
-            { data: \'utc_date\',
-                render: function ( data, type, row ) {
-                    // If display or filter data is requested, format the date
-                    if ( type === \'display\' || type === \'filter\' ) {
-                        var m = moment.tz(data, activeInfo.timezone);
-                        return moment(m).format(\'LLL\');
-                    }
+            ],
+            "order": [[ 0, \'desc\' ]],
+    } );
+    $("#organizrLogTable").DataTable( {
+            "ajax": "api/?v1/organizr_log",
+                "columns": [
+                { data: \'utc_date\',
+                    render: function ( data, type, row ) {
+                        // If display or filter data is requested, format the date
+                        if ( type === \'display\' || type === \'filter\' ) {
+                            var m = moment.tz(data, activeInfo.timezone);
+                            return moment(m).format(\'LLL\');
+                        }
 
-                // Otherwise the data type requested (`type`) is type detection or
-                // sorting data, for which we want to use the integer, so just return
-                // that, unaltered
-                return data;}
-                },
-            { "data": "username" },
-            { "data": "ip" },
-            { "data": "message" },
-            { data: \'type\',
-                render: function ( data, type, row ) {
-                    if ( type === \'display\' || type === \'filter\' ) {
+                    // Otherwise the data type requested (`type`) is type detection or
+                    // sorting data, for which we want to use the integer, so just return
+                    // that, unaltered
+                    return data;}
+                    },
+                { "data": "username" },
+                { "data": "ip" },
+                { "data": "message" },
+                { data: \'type\',
+                    render: function ( data, type, row ) {
+                        if ( type === \'display\' || type === \'filter\' ) {
+                            return logIcon(data);
+                        }
                         return logIcon(data);
                     }
-                    return logIcon(data);
                 }
-            }
-        ],
-        "order": [[ 0, \'desc\' ]],
-} );
-</script>
-';
+            ],
+            "order": [[ 0, \'desc\' ]],
+    } );
+    </script>
+    ';
+}

+ 7 - 2
js/custom.js

@@ -1628,8 +1628,13 @@ $(document).on("click", ".newAPIKey", function () {
 });
 // purge logvcfdD\o8i 8
 $(document).on("click", ".purgeLog", function () {
-    var log = $('.swapLog.active').attr('data-name');
-    alert('This action is not set yet - but this would have purged the '+log+' log');
+    var name = $('.swapLog.active').attr('data-name');
+    var path = $('.swapLog.active').attr('data-path');
+    if(name !== '' && path !== ''){
+        removeFile(path,name);
+        setTimeout(function(){ loadSettingsPage('api/?v1/settings/settings/logs','#settings-settings-logs','Log Viewer'); }, 1500);
+    }
+
 });
 //Show Passowrd
 $(document).on("click", ".showPassword", function () {

+ 20 - 0
js/functions.js

@@ -985,6 +985,26 @@ function buildLanguage(replace=false,newLang=null){
 		return lang;
 	}
 }
+function removeFile(path,name){
+	if(path !== '' && name !== ''){
+		var post = {
+			path:path,
+			name:name
+		};
+		ajaxloader(".content-wrap","in");
+		organizrAPI('POST','api/?v1/remove/file',post).success(function(data) {
+			var response = JSON.parse(data);
+			if(response.data == true){
+				messageSingle('',window.lang.translate('Removed File')+' - '+name,'bottom-right','#FFF','success','5000');
+			}else{
+				messageSingle('','File Removal Error','bottom-right','#FFF','error','5000');
+			}
+		}).fail(function(xhr) {
+			console.error("Organizr Function: API Connection Failed");
+		});
+		ajaxloader();
+	}
+}
 function updateUserInformation(){
 	var passwordMatch = true;
 	var username = $('#accountUsername').val();