HostCuritiba Posted Sunday at 05:59 PM Share Posted Sunday at 05:59 PM Data Protection Laws (LGPD) require web providers in our country to record user activity logs on their pages. I understand that the official WHMCS already collects this data, but only in the admin area: Other Information: Status: Active Customer Group: → Monthly Customers Registration Date: 07/17/2025 Customer for: 3 Days Last Login Date: 07/18/2025 5:42 PM IP Address: 191.177.136.50 Host: bfb18832.virtua.com.br Owner Email Verified: Yes It would be an internal page like: User Activities containing a table only reporting and collecting the same data as the admin. It would be an internal page like: User Activities containing a table only reporting and collecting the same data as the admin. ~~~~ ID: Time/Day: Hostname: IP: Status: ~~~~ Would keep the data for 30/90 or permanently log the data. Or if anyone can help me build this through simple steps, I have a manual that doesn't work, but I'd like help getting this to work without a module or with an open and simple module. Documentation in this file: https://painel.hostcuritiba.net.br/atividades.html Step 1: Create the Database Table First, you need to create the activity_logs table in your WHMCS database. You can do this through phpMyAdmin or by running this SQL query: -- Save this as activity_logs.sql and import it into your database CREATE TABLE `activity_logs` ( `id` int(11) NOT NULL AUTO_INCREMENT, `user_id` int(11) DEFAULT NULL, `date_time` datetime NOT NULL, `ip_address` varchar(45) NOT NULL, `hostname` varchar(255) DEFAULT NULL, `login_type` varchar(50) NOT NULL, `description` text, `status` varchar(20) NOT NULL DEFAULT 'success', PRIMARY KEY (`id`), KEY `user_id` (`user_id`), KEY `date_time` (`date_time`), KEY `login_type` (`login_type`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; Step 2: Create the PHP File Create a file named activitylog.php in your WHMCS custom client area templates directory: <?php /** * Activity Log System * * @package WHMCS * @author Custom Developer * @version 1.0 */ use WHMCS\Database\Capsule; // Require login to access this page $ca->requireLogin(); // Check login status if ($ca->isLoggedIn()) { // User is logged in $clientName = Capsule::table('tblclients') ->where('id', '=', $ca->getUserID())->pluck('firstname'); $ca->assign('clientname', $clientName); // Log this activity logActivity($ca->getUserID()); } else { // User is not logged in $ca->assign('clientname', 'Random User'); } /** * Log user activity * * @param int $userId User ID * @return void */ function logActivity($userId) { // Get current date and time $dateTime = date('Y-m-d H:i:s'); // Get IP address $ipAddress = $_SERVER['REMOTE_ADDR']; // Get hostname $hostname = gethostbyaddr($ipAddress); // Determine login type $loginType = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? 'proxy' : 'direct'; // Insert activity log Capsule::table('activity_logs')->insert([ 'user_id' => $userId, 'date_time' => $dateTime, 'ip_address' => $ipAddress, 'hostname' => $hostname, 'login_type' => $loginType, 'description' => 'User accessed activity log page', 'status' => 'success' ]); } // Get activity logs for current user $activityLogs = Capsule::table('activity_logs') ->where('user_id', '=', $ca->getUserID()) ->orderBy('date_time', 'desc') ->limit(50) ->get(); $ca->assign('activityLogs', $activityLogs); // Output template $ca->setTemplate('activitylog.tpl'); ?> Step 3: Create the Template File Create a file named activitylog.tpl in your WHMCS template directory: <div class="container"> <h2>Activity Logs for {$clientname}</h2> <div class="table-responsive"> <table class="table table-bordered"> <thead> <tr> <th>ID</th> <th>Date & Time</th> <th>IP Address</th> <th>Hostname</th> <th>Login Type</th> <th>Status</th> </tr> </thead> <tbody> {foreach from=$activityLogs item=log} <tr> <td>{$log->id}</td> <td>{$log->date_time}</td> <td>{$log->ip_address}</td> <td>{$log->hostname}</td> <td>{$log->login_type}</td> <td> {if $log->status == 'success'} <span class="label label-success">success</span> {else} <span class="label label-danger">failed</span> {/if} </td> </tr> {foreachelse} <tr> <td colspan="6">No activity logs found</td> </tr> {/foreach} </tbody> </table> </div> </div> Step 4: Register the Custom Client Area Page Create or edit the hooks.php file in your WHMCS root directory to register your custom page: <?php /** * WHMCS Custom Hooks File */ // Register custom client area page add_hook('ClientAreaPrimaryNavbar', 1, function($primaryNavbar) { // Check if user is logged in if (is_null($primaryNavbar->getChild('Account'))) { return; } // Add Activity Log menu item under Account $primaryNavbar->getChild('Account') ->addChild('Activity Log', array( 'uri' => 'index.php?m=custom&action=activitylog', 'order' => 50, )); }); // Register custom client area page add_hook('ClientAreaPageCustomAction', 1, function($vars) { // Check if our custom action is requested if ($vars['action'] == 'activitylog') { require_once __DIR__ . '/modules/custom/activitylog.php'; return true; } }); ?> tep 5: Create Directory Structure Make sure your files are in the correct locations: WHMCS_ROOT/ hooks.php modules/ custom/ activitylog.php templates/ YOUR_TEMPLATE/ activitylog.tpl None of the actions worked for me. If anyone can develop something that works, I'd appreciate it! 0 Quote Link to comment Share on other sites More sharing options...
HostCuritiba Posted Sunday at 07:28 PM Author Share Posted Sunday at 07:28 PM I need help creating this 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.