How to add action logging

Introduction

Monsta FTP allows you to log all user actions, either to a predefined log format, or via your own function. This article explains how to enable logging or implement your own.

Prerequisites

Steps

Open the file /mftp/settings/config.php and look for these two variables (if you have a version older than 2.9.2 you'll need to manually add these.)

$configMftpActionLogPath = null;
$configMftpActionLogFunction = null;

If you're using a version older than 2.9.2 you'll need to manually add the above variables as well as the two lines below in the define area.

define("MFTP_ACTION_LOG_PATH", $configMftpActionLogPath);
define("MFTP_ACTION_LOG_FUNCTION", $configMftpActionLogFunction);

The first var $configMftpActionLogPath is used where you want to use the default logging format. You'll replace null with your preferred path to the log file. Examples of this are:

$configMftpActionLogPath = "../../mylog.txt";
$configMftpActionLogPath = "/home/USERNAME/public_html/mftp/mylog.txt";

The log file is written in the following format:

Date/time (ISO-8601)|User IP|Server Host|FTP Username|Action|Folder Path|File Name|Error

The second var $configMftpActionLogFunction is used where you want to write your own logging function. Setting this value will disable the default logging option (to disable it the value must be set to null.

To enable custom logging you need to give the name of your PHP function as the value. For example, if your function is myMonstaLogger(), you'll add this as:


$configMftpActionLogFunction = "myMonstaLogger";

On page load, Monsta FTP will check for a file called mftp_extensions.php (in the same directory as the index.php file) and include it if it exists. This is where you'll define the actual code for your function.

The $action variable will be one of: Log in, Edit file, Move file, Delete file, Rename file, CHMOD file, Fetch file, Download file, Upload file

$actionAction performed
$clientIpLogged in user's IP
$hostUser's FTP host address
$usernameUser's FTP username
$folderPathFolder path where action took place
$fileNameFile or folder name affected by action
$errorAny reported error

The $userIp variable is the value of $_SERVER['REMOTE_ADDR']. If you need to determine this some other way (e.g. $_SERVER['X_FORWARDED_FOR']) then your custom function should handle this.