Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,46 @@

This file documents all notable changes made to ITFlow.

## [26.11.3]

### Upgrading

Update from Maintenance > Update — Queue Update hands the job to cron, which updates the files and applies this release's one database change (3.5.4 to 3.5.5) in the same pass. Nothing else is required. Everyone is signed out once after the update, agents and client portal contacts alike - see Security. The new Payment Provider Fees job in Maintenance > Cron is set up by itself.

### Security

- Setup: the Restore a backup option on the setup page is open to anyone until the first user is created, as it has to be on a new install. A backup built for the purpose could use it to make the web server run code it carried into the uploads folder. This needed Apache with .htaccess overrides switched on - installs on nginx, and Apache servers that ignore .htaccess files, were not affected. A restore no longer brings in the files that decide how the web server treats a folder, it never writes into the folder backups are kept in, and ITFlow's own protections on the uploads folder are put back after every restore. Every release from 26.08 to 26.11.2 is affected. If an install of yours sat at the setup page where others could reach it, look through its uploads folder for .htaccess, .user.ini or .php files that ITFlow didn't put there.
- Passwords: changing a password now signs that account out everywhere else. Before, a browser that was already signed in stayed signed in after the password changed - including after the incident-response reset in Admin > Users, which is meant to lock out someone who has got in. It covers changing your own password, an admin setting someone's, the incident-response reset, and on the client portal a contact changing theirs, a password reset link, and an agent setting a contact's portal password. On the portal, the browser making the change stays signed in. An agent's View as contact ends too when their password changes.
- MFA: an agent whose account requires multi-factor authentication but who hadn't set it up yet could use ITFlow without ever setting it up, by going straight to other pages after signing in. Until it is set up, every page now goes back to setting it up, or signing out - including for an agent who is already signed in when an admin requires MFA, or resets it, for them. View as contact isn't offered to them either.
- Client portal: the two-step sign-in set up that Admin > Client Portal can require could be got past in two ways - by adding a page name to the end of the address, or by sending another action along with setting it up. A contact who still had to set it up could open their tickets and invoices, and raise or resolve tickets. Neither works now.
- MFA: agents are now emailed when multi-factor authentication is turned on for their account, as client portal contacts already were. Setting it up takes only the password, so this is how someone finds out an authenticator they didn't add was put on their account.

### New Features & Updates

- API: products can be updated through the API (`products/update`). Only the fields you send are changed, and the key's user needs edit access to Sales, the same as editing a product in ITFlow.
- API keys: agents are notified in ITFlow a week before an API key expires, so an integration doesn't stop without warning.
- Payment Providers: Stripe's fee on a card payment is now recorded as an expense about 15 minutes after the payment, instead of the next morning. A new Payment Provider Fees job in Maintenance > Cron does it, and you can run it more often there. Record fees now still works any time.

### Bug Fixes

- Transactions: the list, its Transfers pill, Reconcile and the transactions export load faster again. On a test with eight years of books, the Transfers pill went from about a third of a second in 26.11.2 to under a fifth.
- Expenses: billable expenses waiting to go on an invoice slowed down every page, because the side menu counts them and each one was checked against every expense. With a few hundred waiting, that was about a third of a second on every page. The invoice page, Add Expenses and an expense's quick look had the same delay. All of them are quick again.
- Transactions: on All accounts, Money in and Money out counted every transfer between your own accounts twice - once out of one account and once into the other - so both were far too high. A Stripe payout to the bank, a check deposit or paying off a card all added to both. They now leave transfers between your accounts out, as the dashboard and Income already did. The Transfers pill still lists them, and one account on its own still counts them as money in and out of that account. The Difference was always right.

### Developer Updates

- `backupRestoreArchive()` no longer extracts the inner `uploads.zip` wholesale. It builds an allow-list of entries and extracts with `extractTo($dir, $entries)`, leaving out any entry whose basename is `.htaccess`, `.user.ini` or `.htpasswd` and any entry that resolves inside `backupStorageDir()`, which the restore preserves while it empties the rest of `uploads/`. Unsafe paths (`..`, absolute) still fail the restore as before. `scripts/restore_cli.php` gets the same, as it calls the same function.
- `backupHardenStorageDir()` writes its `.htaccess` every time instead of only when there is none, so a guard carried in by an archive can't survive. `backupAssertUploadsGuards()` also rewrites the deny-all guards in `uploads/backups`, `canned_responses`, `expenses` and `tmp`, so a restored `uploads/` has the same guards as a fresh install. Both use the new `BACKUP_UPLOADS_DENY_GUARD` constant.
- `accountLedgerSql()` reads its lines first and joins each to its account with `STRAIGHT_JOIN`. Left to choose, the optimizer started from the accounts and found their lines through an index it built on the lines' temporary table (`derived_with_keys`), which was two to three times slower.
- Database 3.5.5 indexes `expenses.expense_refund_of_id`. `expenseUnbilledCount()` (the side menu, on every agent page), `expenseUnbilled()`, `expenseOnInvoice()` and `expenseRow()` sum each expense's refunds in a correlated subquery, which scanned every expense for each one. Like 3.5.4, it is safe to run again, and `db.sql` has the key.
- `api/v1/products/update.php` takes `product_id` and any of the `product_*` fields mapped in `api/v1/products/product_model.php`, and saves through `productSave()`. At least one field is required and each must be a scalar. `product_track_stock` accepts `1`, `true`, `yes`, `on` or `tracked`, and sending `product_type` without `product_track_stock` turns stock tracking off, as the product form does. `enforce_api_rbac.php` gates it on `module_sales` at write level, and it logs a Product Edit and an API Success.
- `cron/nightly_tasks.php` sends an `appNotify()` "API Key Expiring" notification for each key whose `api_key_expire` is seven days away, once, on that day.
- Sessions carry `$_SESSION['user_session_stamp']`, `userSessionStamp()` in `functions/user.php`: a SHA-256 digest of the user's `user_password` hash, never the hash itself. It is set at the three places a session is made - `login.php` (agent and client portal) and `client/login_microsoft.php` - and checked with `hash_equals()` on every request in `includes/load_user_session.php` and `client/includes/check_login.php`, next to the existing status and archived checks. Any write to `users.user_password`, from any code path, ends every session made before it, with no new column and no migration. A session without the stamp is signed out, which is the one-time sign-out on updating.
- `userSetPassword()` calls `userSessionRestamp()`, which gives the current session a new id (`session_regenerate_id(true)`) and the new stamp when the password changed is its own user's - so only the other sessions end. The client portal's own password change does the same. `portalViewAsAccess()` returns `agent_session_stamp`, checked against the agent's session while viewing as a contact.
- New `requestIsMfaSetup($allowed)` in `functions/auth.php` decides what a session that still has to set up MFA may request: the script really running (`realpath($_SERVER['SCRIPT_FILENAME'])` under the app root, never `PHP_SELF`, which a path added after the script name changes), and every GET and POST key inside one of the shapes allowed for that script. `includes/load_user_session.php` applies it when `user_config_force_mfa` is 1 and `user_token` is empty, allowing `agent/user/mfa_enforcement.php` with no parameters and `agent/user/post.php` with only `csrf_token`, `enable_mfa` and `verify_code`, or `?logout` - everything else redirects to the set up page, modals and AJAX included. The client portal gate in `client/includes/check_login.php` now uses it too (`profile.php?mfa`, and `post.php` with `portal_mfa_enable` or `?logout`), replacing its `basename($_SERVER['PHP_SELF'])` test; the separate gate in `client/post.php`, which let any request through that carried `portal_mfa_enable` or `logout` alongside other actions, is gone. `portalViewAsAccess()` refuses an agent still owing MFA set up. The `enable_mfa` handler sends `userNotifyChange()`.
- `accountLedgerShows($all_accounts)`: across every account, the `in` and `out` cuts leave out `txn_kind` `transfer_in` and `transfer_out`. `agent/transactions.php` does the same for its Money in and Money out totals, except on the Transfers pill, and notes it in the table footer when the listed lines include transfers the totals leave out. The transactions export, which takes its cuts from the same function, follows.
- Stripe fees are recorded by a new job, `cron/payment_provider_fees.php` (`payment_provider_fees` in `includes/cron_jobs.php`, every 15 minutes, interval-safe), instead of `cron/nightly_tasks.php`. The dispatcher seeds its row the first time it sees it. `paymentProviderRecordFees()` now holds `GET_LOCK('itflow_payment_provider_fees', 0)` around the work, which moved to `paymentProviderRecordFeesLocked()`, and returns `'busy' => true` when another run has it - "has no fee yet" is read before the fee is written, so two runs at once would each record it. Record fees now says when a run is in progress.

## [26.11.2]

### Upgrading
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ We're incredibly grateful to the organizations and individuals who [sponsor](htt
| [Mountaineer IT](https://mountaineerit.com) | Dec 2025 |
| [DataBit Solutions](https://databitsolutions.com) | Dec 2025 |
| [City of Rathdrum](https://rathdrumpolice.gov) | Dec 2025 |
| [Algolibre](https://algolibre.io) | Aug 2026 |
| [AlgoLibre Inc.](https://algolibre.io) | Aug 2026 |
| [Pentagon Networks](https://pentagon.net) | Aug 2026 |
| [Hanobox e.K.](https://hanobox.de) | Oct 2026 |
| [Innovarro Group Limited](https://innovarro.com) | Oct 2026 |
Expand Down
26 changes: 26 additions & 0 deletions admin/database_updates/3.5.5.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

/*
* ITFlow - Database update to version 3.5.5 (from 3.5.4)
* Included by admin/database_updates.php - do not access directly
*
* Index expenses.expense_refund_of_id - the expense a refund gives back.
* What is left to bill of an expense is its amount less its refunds, and
* each expense waiting to be billed looked its refunds up with nothing to
* find them by, so every one was checked against every expense. The side
* menu counts them on every agent page (expenseUnbilledCount()), and the
* invoice page, Add Expenses and an expense's quick look do the same.
*
* Re-runnable: skipped where the index is already there.
*/

defined('FROM_DB_UPDATER') || die("Direct file access is not allowed");

$itflow_index_exists = mysqli_query($mysqli, "SELECT 1 FROM information_schema.STATISTICS
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'expenses' AND INDEX_NAME = 'expense_refund_of_id' LIMIT 1");

if (!$itflow_index_exists || mysqli_num_rows($itflow_index_exists) === 0) {
mysqli_query($mysqli, "ALTER TABLE `expenses` ADD KEY `expense_refund_of_id` (`expense_refund_of_id`)");
}

unset($itflow_index_exists);
2 changes: 1 addition & 1 deletion admin/modals/payment_provider/payment_provider_edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@
<input type="checkbox" class="form-check-input" name="record_fees" value="1" id="paymentProviderRecordFees" <?= $records_fees ? 'checked' : '' ?> data-provider-fees-switch>
<label class="form-check-label" for="paymentProviderRecordFees">Record its fees as expenses</label>
</div>
<div class="form-text ps-5">Each night, its fee on each card payment is recorded as an expense from the account above.</div>
<div class="form-text ps-5">Its fee on each card payment is recorded as an expense from the account above, a few minutes after Stripe settles the payment.</div>
</div>

<div data-provider-fees>
Expand Down
6 changes: 3 additions & 3 deletions admin/payment_providers.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* and how many are still to record), its saved cards and the autopay on
* them, and its card payments in the last 30 days. Check connection asks
* the provider whose account the key is; Record fees now does what the
* nightly run does. Add and Edit are one window
* Payment Provider Fees job does every few minutes. Add and Edit are one window
* (modals/payment_provider/payment_provider_edit.php); the rest are
* admin/post/payment_provider.php.
*/
Expand Down Expand Up @@ -155,7 +155,7 @@
<?php } ?>
<?php if ($activity['waiting']) { ?>
<span class="badge <?= $activity['stale'] ? 'bg-warning-subtle text-warning-emphasis border border-warning-subtle' : 'text-bg-light border' ?> fw-normal mt-1" data-provider-fees-waiting="<?= $activity['waiting'] ?>"
title="<?= $activity['stale'] ? 'Some are more than two days old - the nightly run should have had them' : 'The nightly run records them once Stripe has settled them' ?>"><?= $activity['waiting'] ?> to record</span>
title="<?= $activity['stale'] ? 'Some are more than two days old - the Payment Provider Fees job in Maintenance > Cron should have had them' : 'Recorded a few minutes after Stripe settles them' ?>"><?= $activity['waiting'] ?> to record</span>
<?php } ?>
<?php } else { ?>
<span class="text-body-secondary">Not recorded</span>
Expand Down Expand Up @@ -187,7 +187,7 @@
<i class="fas fa-fw fa-plug text-secondary me-2"></i>Check connection
</a>
<?php if ($fees_on && $activity['waiting']) { ?>
<a class="dropdown-item" href="post.php?record_payment_provider_fees=<?= $provider_id ?>&csrf_token=<?= $csrf ?>" title="What the nightly run does - for the card payments whose fee is still to record">
<a class="dropdown-item" href="post.php?record_payment_provider_fees=<?= $provider_id ?>&csrf_token=<?= $csrf ?>" title="What the Payment Provider Fees job does every few minutes - for the card payments whose fee is still to record">
<i class="fas fa-fw fa-receipt text-secondary me-2"></i>Record fees now
</a>
<?php } ?>
Expand Down
6 changes: 5 additions & 1 deletion admin/post/payment_provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@

}

// Record fees now - what the nightly run does, for the payments whose fee is still to record
// Record fees now - what the Payment Provider Fees job does every few minutes, for the payments whose fee is still to record
if (isset($_GET['record_payment_provider_fees'])) {

validateCSRFToken();
Expand All @@ -182,6 +182,10 @@
}

$done = paymentProviderRecordFees($row);
if ($done['busy']) {
flashAlert('<strong>' . escapeHtml($name) . '</strong>\'s fees are being recorded right now by the scheduled run - look again in a minute', 'info');
redirect();
}
$said = [];
if ($done['recorded']) {
$said[] = 'Recorded its fee on ' . $done['recorded'] . ' payment' . ($done['recorded'] === 1 ? '' : 's') . ' - ' . paymentProviderMoneyText($done['amount']);
Expand Down
13 changes: 8 additions & 5 deletions agent/transactions.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,11 @@
foreach ($shows as $key => $s) {
$count_sql[] = $key === '' ? 'COUNT(*)' : "COALESCE(SUM({$s['where']}), 0)";
}
$count_sql[] = "COALESCE(SUM(CASE WHEN 1 $show_query AND ledger.txn_amount > 0 THEN ledger.txn_amount END), 0)";
$count_sql[] = "COALESCE(SUM(CASE WHEN 1 $show_query AND ledger.txn_amount < 0 THEN -ledger.txn_amount END), 0)";
// Across every account a transfer is money moved between them, so Money in and Money out
// leave it out (accountLedgerShows()) - except on Transfers, where it is what is listed
$not_transfer = $all && $show !== 'transfers' ? "AND ledger.txn_kind NOT IN ('transfer_in', 'transfer_out')" : '';
$count_sql[] = "COALESCE(SUM(CASE WHEN 1 $show_query $not_transfer AND ledger.txn_amount > 0 THEN ledger.txn_amount END), 0)";
$count_sql[] = "COALESCE(SUM(CASE WHEN 1 $show_query $not_transfer AND ledger.txn_amount < 0 THEN -ledger.txn_amount END), 0)";
if ($transfer_cards) {
$count_sql[] = "COALESCE(SUM(CASE WHEN 1 $show_query THEN -ledger.txn_amount END), 0)";
$count_sql[] = "COALESCE(SUM(CASE WHEN 1 $show_query AND ledger.other_account_type = 3 THEN -ledger.txn_amount END), 0)";
Expand Down Expand Up @@ -186,14 +189,14 @@
<a class="itflow-billing-stat <?= $show === 'in' ? 'active' : '' ?>" href="<?= escapeHtml($filter_url(['show' => 'in'])) ?>">
<div class="itflow-billing-stat-label"><i class="fas fa-arrow-down me-1"></i>Money in</div>
<div class="itflow-billing-stat-value text-success-emphasis"><?= $money($total_in) ?></div>
<div class="itflow-billing-stat-note"><?= $dated ? escapeHtml(formatExportDateRange($dtf, $dtt)) : ($all ? 'All time' : 'Since it opened') ?><?= $all ? ' - transfers counted both ways' : '' ?></div>
<div class="itflow-billing-stat-note"><?= $dated ? escapeHtml(formatExportDateRange($dtf, $dtt)) : ($all ? 'All time' : 'Since it opened') ?><?= $all ? ' - transfers between accounts left out' : '' ?></div>

Check warning on line 192 in agent/transactions.php

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Extract this nested ternary operation into an independent statement.

See more on https://sonarcloud.io/project/issues?id=itflow-org_itflow&issues=AaGoHGPjL5JiLDIE_toi&open=AaGoHGPjL5JiLDIE_toi&pullRequest=1308
</a>
</div>
<div class="col-sm-6 col-xl-3">
<a class="itflow-billing-stat <?= $show === 'out' ? 'active' : '' ?>" href="<?= escapeHtml($filter_url(['show' => 'out'])) ?>">
<div class="itflow-billing-stat-label"><i class="fas fa-arrow-up me-1"></i>Money out</div>
<div class="itflow-billing-stat-value"><?= $money($total_out) ?></div>
<div class="itflow-billing-stat-note"><?= $dated ? escapeHtml(formatExportDateRange($dtf, $dtt)) : ($all ? 'All time' : 'Since it opened') ?></div>
<div class="itflow-billing-stat-note"><?= $dated ? escapeHtml(formatExportDateRange($dtf, $dtt)) : ($all ? 'All time' : 'Since it opened') ?><?= $all ? ' - transfers between accounts left out' : '' ?></div>

Check warning on line 199 in agent/transactions.php

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Extract this nested ternary operation into an independent statement.

See more on https://sonarcloud.io/project/issues?id=itflow-org_itflow&issues=AaGoHGPjL5JiLDIE_toj&open=AaGoHGPjL5JiLDIE_toj&pullRequest=1308
</a>
</div>
<div class="col-sm-6 col-xl-3">
Expand Down Expand Up @@ -428,7 +431,7 @@
<tfoot>
<tr class="table-light">
<td colspan="<?= 4 + ($all ? 1 : 0) ?>" class="text-body-secondary small">
<?= intval($num_rows[0]) ?> line<?= intval($num_rows[0]) === 1 ? '' : 's' ?><?= $num_rows[0] > count($rows) ? ' - the totals are for all of them, not just this page' : '' ?>
<?= intval($num_rows[0]) ?> line<?= intval($num_rows[0]) === 1 ? '' : 's' ?><?= $num_rows[0] > count($rows) ? ' - the totals are for all of them, not just this page' : '' ?><?= $not_transfer !== '' && !in_array($show, ['in', 'out'], true) ? ' - transfers between accounts are listed but left out of the totals' : '' ?>
</td>
<td class="text-end fw-semibold text-nowrap itflow-money text-success-emphasis"><?= $money($total_in) ?></td>
<td class="text-end fw-semibold text-nowrap itflow-money"><?= $money($total_out) ?></td>
Expand Down
Loading
Loading