Working on the logging of admin and ajax activity.
authorSteve Sutton <steve@gaslightmedia.com>
Fri, 30 Aug 2019 12:22:05 +0000 (08:22 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Fri, 30 Aug 2019 12:22:05 +0000 (08:22 -0400)
Records the user id and the get or post request.

controllers/admin.php
models/admin/logs/index.php [new file with mode: 0644]
setup/adminMenus.php
setup/validActions.php
views/admin/logs/header.html [new file with mode: 0644]
views/admin/logs/index.html [new file with mode: 0644]

index 3641534..8fb2433 100755 (executable)
@@ -253,6 +253,8 @@ class glmMembersAdmin extends GlmPluginSupport
     public function glmMembersAdminAjax()
     {
 
+        $this->logUserActions();
+
         if ( GLM_MEMBERS_PLUGIN_ADMIN_DEBUG_VERBOSE ) {
             trigger_error(
                 glmAssociateMemoryUsage() . " - Start AJAX Controller",
@@ -731,14 +733,7 @@ class glmMembersAdmin extends GlmPluginSupport
         $returnOutput = false, $forceAction = false)
     {
 
-        // TODO: setup audit logging for users
-        // $errorLogTime = date( 'Y-m-d H:i:s' );
-        // if ( !empty( $_POST ) ) {
-        //     error_log( $errorLogTime . " POST: " . serialize( $_POST ) . "\n", 3, '/var/www/develop/wp-content/error.log' );
-        // }
-        // if ( !empty( $_GET ) ) {
-        //     error_log( $errorLogTime . " GET: " . serialize( $_GET ). "\n", 3, '/var/www/develop/wp-content/error.log' );
-        // }
+        $this->logUserActions();
 
         if ( GLM_MEMBERS_PLUGIN_ADMIN_DEBUG_VERBOSE ) {
             trigger_error(
@@ -1127,4 +1122,23 @@ class glmMembersAdmin extends GlmPluginSupport
 
     }
 
+    public function logUserActions()
+    {
+        $logFile   = WP_CONTENT_DIR . '/user.log';
+        $timeZone  = get_option( 'timezone_string' );
+        $cTimezone = date_default_timezone_get();
+        date_default_timezone_set( $timeZone );
+
+        $errorLogTime = date( 'j-M-Y H:i:s e' );
+        $user_id      = get_current_user_id();
+        if ( !empty( $_POST ) ) {
+            error_log( "[{$errorLogTime}] USER: " . $user_id . " POST: " . serialize( $_POST ) . "\n", 3, $logFile );
+        }
+        if ( !empty( $_GET ) ) {
+            error_log( "[{$errorLogTime}] USER: " . $user_id . " GET: " . serialize( $_GET ). "\n", 3, $logFile );
+        }
+        date_default_timezone_set( $cTimezone );
+    }
+
+
 }
diff --git a/models/admin/logs/index.php b/models/admin/logs/index.php
new file mode 100644 (file)
index 0000000..40e30b3
--- /dev/null
@@ -0,0 +1,131 @@
+<?php
+
+/**
+ * Gaslight Media Members Database
+ * Admin Data Import
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package  glmMembersDatabase
+ * @author   Chuck Scott <cscott@gaslightmedia.com>
+ * @license  http://www.gaslightmedia.com Gaslightmedia
+ * @version  0.1
+ */
+
+/*
+ * This class performs the work for the default action of the "Logs" menu
+ * option.
+ *
+ */
+class GlmMembersAdmin_logs_index
+{
+
+    /**
+     * WordPress Database Object
+     *
+     * @var $wpdb
+     * @access public
+     */
+    public $wpdb;
+    /**
+     * Plugin Configuration Data
+     *
+     * @var $config
+     * @access public
+     */
+    public $config;
+
+    /**
+     * Constructor
+     *
+     * This contractor sets up this model. At this time that only includes
+     * storing away the WordPress data object.
+     *
+     * @return object Class object
+     *
+     */
+    public function __construct ( $wpdb, $config )
+    {
+
+        // Save WordPress Database object
+        $this->wpdb = $wpdb;
+
+        // Save plugin configuration object
+        $this->config = $config;
+
+    }
+
+    /**
+     * Perform Model Action
+     *
+     * This method does the work for this model and returns any resulting data
+     *
+     * @return array Status and data array
+     *
+     * 'status'
+     *
+     * True if successful and false if there was a fatal failure.
+     *
+     * 'menuItemRedirect'
+     *
+     * If not false, provides a menu item the controller should
+     * execute after this one. Normally if this is used, there would also be a
+     * modelRedirect value supplied as well.
+     *
+     * 'modelRedirect'
+     *
+     * If not false, provides an action the controller should execute after
+     * this one.
+     *
+     * 'view'
+     *
+     * A suggested view name that the controller should use instead of the
+     * default view for this model or false to indicate that the default view
+     * should be used.
+     *
+     * 'data'
+     *
+     * Data that the model is returning for use in merging with the view to
+     * produce output.
+     *
+     */
+    public function modelAction ($actionData = false)
+    {
+        // Set the view file
+        $view     = 'index.html';
+        $fileData = false;
+        $logFile  = WP_CONTENT_DIR . '/user.log';
+
+        if ( isset( $_REQUEST['option'] ) ) {
+            $option = filter_var( $_REQUEST['option'] );
+        }
+
+        switch( $option ) {
+
+        default:
+            // get the log file contents
+            $fileData = file_get_contents( $logFile );
+
+            break;
+
+        }
+
+        // Setup the template data array
+        $templateData = array(
+            'fileData' => $fileData,
+        );
+
+        // Return status, suggested view, and data to controller
+        return array(
+            'status'           => true,
+            'menuItemRedirect' => false,
+            'modelRedirect'    => false,
+            'view'             => 'admin/logs/' . $view,
+            'data'             => $templateData,
+        );
+
+    }
+
+
+}
index 91458b7..e28a533 100644 (file)
@@ -78,6 +78,16 @@ if (current_user_can('glm_members_members')) {
             'glm-members-admin-menu-member',
             function() {$this->controller('member');}
         );
+
+        // Add a submenu for the "Logs"
+        add_submenu_page(
+            $mainMenuSlug,
+            'Logs',
+            'Logs',
+            'glm_members_member',
+            'glm-members-admin-menu-logs',
+            function() {$this->controller('logs');}
+        );
     } else {
         add_menu_page(
             $this->config['terms']['term_admin_menu_members'],
index 53467ce..82b11d5 100644 (file)
@@ -109,7 +109,10 @@ $glmMembersValidActions = array(
         ),
         'import' => array(
             'index' => 'glm-member-db',
-        )
+        ),
+        'logs' => array(
+            'index' => 'glm-member-db',
+        ),
     ),
     'frontActions' => array(
         'members' => array(
diff --git a/views/admin/logs/header.html b/views/admin/logs/header.html
new file mode 100644 (file)
index 0000000..cfd19e8
--- /dev/null
@@ -0,0 +1,3 @@
+<div class="wrap glm-associate-admin-wrap glm-associate-admin-management-wrap">
+
+    <div id="glm-admin-content-container">
diff --git a/views/admin/logs/index.html b/views/admin/logs/index.html
new file mode 100644 (file)
index 0000000..fc98eb9
--- /dev/null
@@ -0,0 +1,17 @@
+{*
+    Log View File
+
+    Displays the Entire log file.
+*}
+
+{* Include Header *}
+{include file='admin/logs/header.html'}
+<h2>Log File</h2>
+
+{* Display the Log $fileData *}
+<div>
+    {$fileData|nl2br}
+</div>
+
+{* Include Footer *}
+{include file='admin/footer.html'}