# Project plan — fim

Evidence date: 2026-10-15. Source repository: `git@bitbucket.org:overdrive/fim.git`.

Inspected revision: `master` at `41df15e` (2020-04-23 13:57:02 +0200, subject "update all recent changes on Fim - fixed mailing issues, fixed session issues, fixed redirecting issues, fix  path issues"). `origin/HEAD` points at `master`. The only branch is `master`. The scan-host path on the onboarding issue (`~/projects/sonar_scan/repos/fim`) was not on this machine. The tree was read from a full clone of that revision.

There is no prior Silicon Ark directory for this repository. Silicon Ark already documents similar file-integrity code inside other projects (`timesheet` under `fim_2.0/`, and `sawis_api` / `sawis_api_old` under `cron.fim.php` and `_framework/_nemo.fim.cls.php`). This repository's class is also named `NemoFIM`, and the CLI path logic strips the substring `fim_2.0`. Whether this repository is the upstream of those copies was not verified by diff. **Unknown / Requires Confirmation.**

The mailbox address and the empty database password are not repeated in this plan. They are cited in `technical-documentation.md` and `business-rules.md`.

## What this repository is

`fim` is a standalone PHP file-integrity monitor. The letters FIM are not expanded anywhere in the tree. The behaviour is a recursive directory walk that records each file and directory, stores a hash and metadata in MySQL, compares that snapshot with a master baseline, and emails an HTML report of changes, missing paths, and new paths. Report links can mark a row ignored or can copy the live row onto the master baseline.

Provenance: **Implemented** in `fim.cls.php`, `fim.cron.php`, and `fim.config.php`. **Inferred** that "FIM" means file-integrity monitoring. No README, product brief, or ticket states the purpose.

The committed project name is `Test_Project` and the committed environment name is `qa`.

## Objectives visible in the repository

| Objective | Evidence | Provenance |
|---|---|---|
| Record files and directories under a configured root | `NemoFIM::Record`, `fim.cron.php` default branch | Implemented |
| Store owner, permission, size, mtime, extension, and a hash | `NemoFIM::Save` | Implemented |
| Force directories to mode `0755` and files to mode `0644` when they differ | `NemoFIM::iniSetPermissions` | Implemented |
| Compare the latest environment snapshot with `sysAudit_master` | `NemoFIM::Compare` | Implemented |
| Email an HTML report when the combined count is greater than zero | `NemoFIM::Compare` calling `mail()` | Implemented |
| Let a caller ignore a finding or accept it onto the master table | `fim.cron.php` actions `FIM: IGNORE` and `FIM: UPDATE` | Implemented |
| Replace the master baseline with today's environment rows | `NemoFIM::ResetMaster` | Implemented |
| Resume a long walk across requests without PHP sessions | `sesFile.txt` in `fim.cron.php` and `NemoFIM::Record`; commit `921e87f` | Implemented |

No written product goal, success metric, or roadmap was found.

## Scope

In scope of the committed tree:

- Three PHP files: `fim.config.php`, `fim.cls.php`, `fim.cron.php`.
- A fixture tree `folder_structure/` (empty and near-empty documents, a few images, spreadsheets, and slide files) used as sample scan content. Web mode points `$siteDirectory` at `DOCUMENT_ROOT/fim/folder_structure`.
- Commented MySQL `CREATE TABLE` statements for `sysaudit_master` and `sysaudit_{environment}` inside `fim.config.php`. They are not executed.

Out of scope of this repository, as far as the tree shows:

- A user interface beyond the HTML tables inside the email body.
- A crontab, pipeline, container, or hosting manifest.
- Tests, a dependency manifest, or a README.
- The Nemo framework types used only by `NemoFIM::PullData` (`NemoDatabase`, `$xdb`, `$DATABASE_SETTINGS`). Those symbols are not defined here.
- The commented include `_nemo.email.cls.php`. That file is not in the tree. Mail is sent with PHP `mail()`.

## System architecture

```text
Caller (web request or PHP CLI; scheduler not in git)
  │
  ▼
fim.cron.php
  │  include fim.config.php  → mysqli to database "fim"
  │  include fim.cls.php     → class NemoFIM
  │
  ├─ Action FIM: RESET MASTER  → truncate + copy today's env rows
  ├─ Action FIM: IGNORE        → mark master hash IGNORE, or insert an IGNORE row
  ├─ Action FIM: UPDATE        → copy env columns onto master, or insert new master rows
  ├─ Action FIM: PULL MASTER DATA → empty branch
  │
  └─ default
       ├─ sesFile.txt line 1 is "1" → unlink file, Compare(), mail report, stop
       └─ otherwise → delete today's env rows if the file was just created,
                      then Record() the tree and chmod as it goes
```

`Record()` can stop itself when a timer or a counter limit is hit, write the pause point to `sesFile.txt`, and return. The timer path also sends `Location: http://www.redirect.to.url.com/`.

## Major components

| Component | Role |
|---|---|
| `fim.config.php` | PHP limits, MySQL connection, project name, environment, scan root, exclude patterns, timer/counter limits, mail headers, commented DDL |
| `fim.cron.php` | Entry script. Reads `sesFile.txt`, dispatches `$_REQUEST["Action"]`, otherwise records or compares |
| `NemoFIM` | Walk, save, chmod, compare, ignore, update, reset, and an unused pull helper |
| `folder_structure/` | Fixture content for a scan. Not application logic |
| `sesFile.txt` | Created at runtime next to the working directory. Not in git. Holds completion flag and last counter |
| `sysAudit_master` | Baseline table. Referenced by queries. DDL is commented |
| `sysAudit_{environment}` | Per-environment snapshot table. Default name `sysAudit_qa` |

## History as the only milestones

There is no milestone plan in the repository. The entire history is three commits by `JacquesOverdrive`, all on `master`:

| Commit | Date | What changed |
|---|---|---|
| `8e2c48d` | 2020-04-20 | Initial tree: class, config, cron, and `folder_structure/`. Pause state used `$_SESSION`. |
| `921e87f` | 2020-04-22 | Subject: "updated fim - without using sessions". `session_start()` removed. Pause state moved to `sesFile.txt`. |
| `41df15e` | 2020-04-23 | Subject cites mailing, session, redirect, and path fixes. Mail body preamble commented out and the HTML content-type set. Report links switched from `$siteBaseURL` to `$FIMBaseURL`. Timer exhaustion sends a `Location` header. Stored path prefers the walked path over `realpath()` when it already contains `$siteDirectory`. CLI versus web scan root split added. |

No commit after 2020-04-23. No open branch. Current status: **dormant at `41df15e`.** A forward implementation plan was not found.

## Known dependencies

- PHP with `mysqli`, `mail()`, and filesystem functions. No `composer.json` and no version constraint. **Unknown / Requires Confirmation** which PHP version is required.
- MySQL or MariaDB database named `fim` on `localhost`, user `root`, password an empty string in the committed file. The running server is not in this repository.
- A local mail transfer agent for `mail()`. None is configured here.
- Optional, and not present in this tree: Nemo database classes for `PullData`, and `_nemo.email.cls.php` (include is commented out).

## Discrepancy with the onboarding inventory

The issue's top-level listing included `sonar-project.properties` and `sonarqube_scan.bat`. Neither file is tracked at `41df15e`. They are not in the working tree of the clone. **Unknown / Requires Confirmation** whether they existed only as untracked files on the scan host.

## Human confirmation

- Whether this repository is still deployed, and for which site. Commit `921e87f` set `$siteBaseURL` to an American Shutters QA hostname. Commit `41df15e` removed that assignment and set `$FIMBaseURL` to `localhost/fim/`.
- Whether `timesheet` `fim_2.0/` and the SAWS API FIM scripts are copies of this repository.
- Who runs `fim.cron.php`, how often, and whether the placeholder redirect URL was intentional.
- Whether the commented DDL matches the live tables, including the lowercase table names in the DDL versus `sysAudit_*` in the queries.
