From 71dab1cca77cfb5934067df6beb83c8718811c07 Mon Sep 17 00:00:00 2001 From: johnnyq Date: Tue, 17 Nov 2026 19:22:10 -0500 Subject: [PATCH] Development mode for a test copy, set on Admin Backup and kept in config.php: every email goes to the test inbox with its recipient in the subject or is cancelled without one, texts wait, the ticket mailbox is not read, AI Triage, Stripe, autopay, RMM device actions, log forwarding, managed check-ins and telemetry are off, and a DEVELOPMENT badge shows in the top bar; 26.11.9 changelog entries --- CHANGELOG.md | 2 + admin/backup.php | 40 +++++++++++ admin/post/backup.php | 40 +++++++++++ cron/ai_triage.php | 5 ++ cron/mail_queue.php | 15 +++++ cron/managed_instances.php | 5 ++ cron/manager_checkin.php | 5 ++ cron/nightly_tasks.php | 9 ++- cron/payment_provider_fees.php | 5 ++ cron/sms_queue.php | 5 ++ cron/ticket_email_parser.php | 5 ++ functions.php | 1 + functions/demo.php | 2 +- functions/dev_mode.php | 119 +++++++++++++++++++++++++++++++++ functions/log_forward.php | 7 +- functions/managed.php | 5 ++ functions/rmm.php | 4 ++ functions/sms.php | 5 ++ includes/stripe_init.php | 5 ++ includes/top_nav.php | 11 +++ 20 files changed, 291 insertions(+), 4 deletions(-) create mode 100644 functions/dev_mode.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b76d987a..865b44240 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -91,6 +91,7 @@ Update from Maintenance > Update — Queue Update hands the job to cron, which u - Maintenance > Cron: admins see a heartbeat in the top bar, beside the bell, when cron needs looking at - cron isn't running, it's switched off, or a job failed, is still running two hours after it started, or has fallen behind. Opening it lists what's wrong, with a job's error, and links to Maintenance > Cron. Nobody else sees it, and it's gone once all is well. From Mountaineer IT's build of ITFlow. - Maintenance > Cron: the new Cron Watch job, every 5 minutes, emails your admins when a job fails, gets stuck or falls behind - once when it starts, again once a day while it lasts, and once more when it's fixed. The Alerts card turns the emails off, sends them to other addresses instead, and sends a test. From Mountaineer IT's build of ITFlow. - Maintenance > Cron: an email can't say cron has stopped, since cron sends it. The Alerts card has a private health address for an uptime monitor such as Uptime Kuma or UptimeRobot: it answers OK while all is well and an error when cron isn't running or a job is in trouble. Check it every 5 minutes. Make a new address if the old one gets out. From Mountaineer IT's build of ITFlow. +- Development mode, for a test copy of your ITFlow: turn it on in Admin > Backup before you restore production's backup onto a test server, and nothing reaches your clients, your team or the systems production talks to. Every email goes to a test inbox you give, with who it was for at the front of its subject. Texts wait in the queue, the ticket mailbox isn't read, AI Triage doesn't run, Stripe charges nothing (autopay included), nothing is done to RMM devices, log entries aren't sent to your syslog server, a managed ITFlow doesn't check in with its manager, and telemetry isn't sent. A red DEVELOPMENT badge shows in the top bar for everyone. It's kept in config.php rather than the database, so a restore can't turn it off. Never turn it on in production. From Mountaineer IT's build of ITFlow. ### Bug Fixes @@ -209,6 +210,7 @@ Update from Maintenance > Update — Queue Update hands the job to cron, which u - Database 3.7.7: `recurring_tickets.recurring_ticket_schedule_time` (NULL books nothing), `_schedule_onsite`, `_lead_days` and `_lead_mode` (days or month), and `recurring_invoices.recurring_invoice_lead_days` and `_due_mode` (terms or next) - `recurringAheadReady()`. The nightly job takes recurring tickets by `recurringTicketDueSql()` and recurring invoices up to `recurring_invoice_lead_days` ahead, made with `recurringInvoiceGenerate()`'s `$early` when the date is still to come. `recurringTicketRunNow()` calls `recurringTicketBook()`, which books through `ticketSetSchedule()` for the run day at the time (today for a missed run), as "Recurring ticket" from the cron; `recurringInvoiceGenerate()` dates an invoice made ahead with lead days due by `recurringInvoiceAheadDue()`. Days ahead are kept short of one step by `recurringTicketLeadDays()` and `recurringInvoiceLeadDays()` (a month is 28 days, 90 at most; 27 before the 1st of the month, month-based repeats only). The fields are `schedule_time`, `schedule_onsite`, `lead_days` and `lead_mode` on the recurring ticket windows (`agent/includes/inc_recurring_ticket_ahead.php`), and `lead_days` and `due_mode` on the recurring invoice form; a post without `lead_days` keeps what is saved. From Mountaineer IT's build of ITFlow. - Database 3.7.8: `ticket_replies.ticket_reply_work_start` and `ticket_reply_work_end`, in company time - `ticketWorkTimesReady()`. `add_ticket_reply` takes `work_date`, `work_start` and `work_end` (`ticketWorkRange()`; an end before the start is the next day, under 24 hours) for a note with time worked, and `ticketWorkTimeWorked()` makes the time worked their length unless it agrees to the minute; without them, or from the bulk reply, the API or email, they stay NULL - it ended when it was posted. `edit_ticket_reply` takes the same fields: changed times set the time worked, the same times with a new time worked move the start, times left as `ticketWorkTimesShown()` filled them on a note without any keep it without, and no time worked clears them. The reply box's time row is Time worked and When it was worked, above Status and Send; `agent/js/ticket_work_times.js` follows `#hours` / `#minutes` / `#seconds` from `ticket_time_tracking.js` (at least a minute), in company time from `#workTimes` `data-now`, and refuses the form in the capture phase, before the timer resets, when a note with time worked has no valid times. From Mountaineer IT's build of ITFlow. - Database 3.7.9: `config_cron_alert_email` (default 1), `config_cron_alert_to`, `config_cron_health_key` and `config_cron_alert_state` (JSON: `sent`, each problem's key and when it was last emailed; `waiting`, each job that is on and has never run and since when) - `cronHealthReady()`. `functions/cron_health.php`: `cronHealthProblems()` reads the heartbeat, `config_enable_cron` and each enabled registry job's row (not those a manager has paused) into problems with a key, kind (`not_running`, `off`, `failed`, `stuck` after `CRON_HEALTH_STUCK_MINUTES`, `overdue` - past two intervals and at least ten minutes over, or two hours past a daily time; a job never run is late once `waiting` is older than that), text and error. `includes/top_nav.php` shows them to admins as `#itflowCronHealth`. `cron/cron_watch.php` is the `cron_watch` job, every 5 minutes: `cronHealthWatch()` records `waiting`, then emails the problems that are new, a day old or gone with `cronHealthAlert()` through `cronHealthMail()` (`emailQueue()`, to `config_cron_alert_to`, else active admins - `cronHealthRecipients()`), leaving out `not_running` and its own; Admin > Mail previews it as `cron_alert`. `health.php` answers 200 `OK` or 503 with a line per problem, given `config_cron_health_key` as `?key=` or an `X-Health-Key` header, and 403 otherwise. `admin/post/cron.php` has `edit_cron_alerts`, `test_cron_alert` (to the addresses typed) and `renew_cron_health_key`, locked in the demo. From Mountaineer IT's build of ITFlow. +- Development mode (`functions/dev_mode.php`): `$config_dev_mode` and `$config_dev_mail_to` in config.php - `devModeOn()`, `devModeMailTo()`. `edit_dev_mode` (`admin/post/backup.php`, locked in the demo) writes both with `devModeConfigSet()`, which replaces each line or adds them at the end and invalidates opcache; when config.php can't be written, Admin > Backup shows the lines to add. `sendQueueEmail()` (`cron/mail_queue.php`) sends to `devModeMailTo()` with `[DEV to ]` in front of the subject, and with no test inbox the queue is cancelled as in the demo. `includes/stripe_init.php` calls `devModeBlockStripe()`, a `\Stripe\ApiRequestor::setHttpClient()` client that throws `ApiConnectionException`. `smsSendQueued()` leaves a text queued, `rmmDeviceAct()` refuses, `managedHttpJson()` answers not ok, and `logForwardQueue()` and `logForwardSend()` send nothing. `cron/ticket_email_parser.php`, `ai_triage.php`, `sms_queue.php`, `payment_provider_fees.php`, `manager_checkin.php` and `managed_instances.php` stop with `cronJobStop("Development mode - ...")`; `cron/nightly_tasks.php` skips autopay and telemetry. `includes/top_nav.php` shows `[data-dev-mode]`, a link to `admin/backup.php#dev-mode` for admins. From Mountaineer IT's build of ITFlow. ## [26.11.8] diff --git a/admin/backup.php b/admin/backup.php index 29ae0545f..daf52f0f3 100644 --- a/admin/backup.php +++ b/admin/backup.php @@ -547,6 +547,46 @@ $status_looks = [ + + +
+
+

Development mode + +

+
+
+

+ For a test copy of your ITFlow. Turn it on before you restore production's backup onto it: + every email then goes to the test inbox, and texts, the ticket mailbox, AI Triage, Stripe, RMM device actions, log forwarding and check-ins with a manager are off. + It's kept in config.php, so a restore can't turn it off. Never turn it on in production. +

+ +

There's no test inbox, so no email is sent at all.

+ + +
+ +
+ > + +
+ +
+ + +
+
Every email goes here, with who it was for at the front of its subject.
+ +
+ +

config.php can't be written from here. To turn it , set these lines in it on the server:

+
$config_dev_mode = ;
+$config_dev_mail_to = '';
+ +
+
+
diff --git a/admin/post/backup.php b/admin/post/backup.php index b6bf3992b..58e9e7f65 100644 --- a/admin/post/backup.php +++ b/admin/post/backup.php @@ -127,3 +127,43 @@ if (isset($_POST['backup_master_key'])) { redirect("backup.php"); } + +/* + * Development mode (functions/dev_mode.php) - written to config.php, not the database, so + * restoring production's backup over a test copy can't turn it off. + */ +if (isset($_POST['edit_dev_mode'])) { + + validateCSRFToken(); + + $dev_on = isset($_POST['dev_mode']); + $dev_mail_to = trim((string) ($_POST['dev_mail_to'] ?? '')); + + if ($dev_mail_to !== '' && !filter_var($dev_mail_to, FILTER_VALIDATE_EMAIL)) { + flashAlert("The test inbox isn't an email address.", 'error'); + redirect("backup.php#dev-mode"); + } + + if ($dev_on && $dev_mail_to === '') { + flashAlert("Give a test inbox - in development mode every email goes there.", 'error'); + redirect("backup.php#dev-mode"); + } + + $dev_was_on = devModeOn(); + $dev_error = devModeConfigSet($dev_on, $dev_mail_to); + + if ($dev_error !== '') { + flashAlert(escapeHtml($dev_error), 'error'); + redirect("backup.php#dev-mode"); + } + + logAudit("Settings", "Edit", "$session_name " . ($dev_on ? ($dev_was_on ? "set development mode's test inbox to $dev_mail_to" : "turned development mode on, with email to $dev_mail_to") : ($dev_was_on ? 'turned development mode off' : 'saved development mode, off'))); + + if ($dev_on) { + flashAlert("Development mode is on - every email goes to " . escapeHtml($dev_mail_to) . ", and nothing reaches clients or other systems.", 'warning'); + } else { + flashAlert($dev_was_on ? "Development mode is off - email, texts and the integrations work normally again." : "Development mode is off."); + } + + redirect("backup.php#dev-mode"); +} diff --git a/cron/ai_triage.php b/cron/ai_triage.php index 3bc9f2f23..490fe764c 100644 --- a/cron/ai_triage.php +++ b/cron/ai_triage.php @@ -32,6 +32,11 @@ if (intval($row['config_enable_cron'] ?? 0) === 0) { cronJobStop("Cron: is not enabled -- Quitting.."); } +// Development mode: no AI calls on production's key, and no changes to the tickets (functions/dev_mode.php) +if (devModeOn()) { + cronJobStop("Development mode - AI Triage doesn't run"); +} + [$triaged, $failed] = aiTriageNewTickets(5); if ($failed) { logApp('AI', 'warning', "AI triage: $failed new ticket" . ($failed === 1 ? '' : 's') . " couldn't be triaged - see AI Usage"); diff --git a/cron/mail_queue.php b/cron/mail_queue.php index 3888f5a70..b03c0506f 100644 --- a/cron/mail_queue.php +++ b/cron/mail_queue.php @@ -92,6 +92,14 @@ if (demoModeOn()) { cronJobStop("Demo - no email is sent"); } +// Development mode sends every email to the test inbox (sendQueueEmail()) - with none set in +// config.php, what was queued is cancelled the same way (functions/dev_mode.php) +if (devModeOn() && devModeMailTo() === '') { + mysqli_query($mysqli, "UPDATE email_queue SET email_status = " . MAIL_QUEUE_CANCELLED . ", email_failed_at = NOW()" + . mailQueueErrorSql("Not sent - development mode, with no test inbox in config.php") . " WHERE email_status IN (0, 2)"); + cronJobStop("Development mode with no test inbox - no email is sent"); +} + // Nothing to send through isn't an error either - an App Logs entry every minute buried the real ones if (empty($config_smtp_provider)) { cronJobStop("No mail server is set up to send through - see Admin > Settings > Mail"); @@ -213,6 +221,13 @@ function sendQueueEmail( string $oauth_access_token, string $oauth_access_token_expires_at ) { + // Development mode: to the test inbox instead, its real recipient at the front of the subject (functions/dev_mode.php) + if (devModeOn()) { + $subject = '[DEV to ' . $to_email . '] ' . $subject; + $to_email = devModeMailTo(); + $to_name = ''; + } + // Google and Microsoft each expose exactly one XOAUTH2 SMTP endpoint, so the // stored host/port/encryption are overridden rather than used as a fallback - // the same thing cron/ticket_email_parser.php already does on the IMAP side. diff --git a/cron/managed_instances.php b/cron/managed_instances.php index 339a543e4..1aa865e16 100644 --- a/cron/managed_instances.php +++ b/cron/managed_instances.php @@ -50,6 +50,11 @@ if ($managed_instances_count === 0) { cronJobStop("No instances connected\n"); } +// Development mode: the instances check in with production, not with this copy (functions/dev_mode.php) +if (devModeOn()) { + cronJobStop("Development mode - instances check in with production, not here\n"); +} + // Gone quiet - told once, until it checks in again $managed_instances_quiet = mysqli_query($mysqli, "SELECT managed_instance_id, managed_instance_name, managed_instance_client_id, managed_instance_last_checkin_at, managed_instance_secret_hash, managed_instance_report FROM managed_instances WHERE managed_instance_archived_at IS NULL AND managed_instance_secret_hash IS NOT NULL AND managed_instance_offline_notified_at IS NULL diff --git a/cron/manager_checkin.php b/cron/manager_checkin.php index fac973f78..b083d454e 100644 --- a/cron/manager_checkin.php +++ b/cron/manager_checkin.php @@ -50,6 +50,11 @@ if (!managedIsManaged()) { cronJobStop("Not managed\n"); } +// Development mode: a copy of a managed ITFlow must not check in as it (functions/dev_mode.php) +if (devModeOn()) { + cronJobStop("Development mode - no check-ins with the manager\n"); +} + $manager_checkin = managedCheckin(); // Thrown, so the dispatcher records why against the job and Admin > Managed By can show it diff --git a/cron/nightly_tasks.php b/cron/nightly_tasks.php index 0f9c63d50..67e4b4366 100644 --- a/cron/nightly_tasks.php +++ b/cron/nightly_tasks.php @@ -624,6 +624,11 @@ $sql_recurring_payments = mysqli_query($mysqli, " "); while ($row = mysqli_fetch_assoc($sql_recurring_payments)) { + // Development mode charges no cards (functions/dev_mode.php) + if (devModeOn()) { + echo "Development mode - autopay doesn't charge cards\n"; + break; + } $invoice_id = intval($row['invoice_id']); $invoice_prefix = escapeSql($row['invoice_prefix']); $invoice_number = intval($row['invoice_number']); @@ -816,9 +821,9 @@ while ($row = mysqli_fetch_assoc($sql_recurring_expenses)) { "/agent/recurring_expenses.php?status=late", intval($recurring['recurring_expense_client_id'])); } -// TELEMETRY +// TELEMETRY - not from a development copy, which would be counted as production (functions/dev_mode.php) -if ($config_telemetry > 0 || $config_telemetry == 2) { +if (($config_telemetry > 0 || $config_telemetry == 2) && !devModeOn()) { $current_version = gitCurrentCommit(); diff --git a/cron/payment_provider_fees.php b/cron/payment_provider_fees.php index adac6dd74..2484d22c0 100644 --- a/cron/payment_provider_fees.php +++ b/cron/payment_provider_fees.php @@ -45,6 +45,11 @@ if (!$payment_provider_fees_provider) { cronJobStop("No Stripe payment provider\n"); } +// Development mode refuses every Stripe call (functions/dev_mode.php) +if (devModeOn()) { + cronJobStop("Development mode - Stripe is off\n"); +} + $payment_provider_fees_done = paymentProviderRecordFees($payment_provider_fees_provider); if ($payment_provider_fees_done['busy']) { diff --git a/cron/sms_queue.php b/cron/sms_queue.php index 285a8da87..9a1977d8a 100644 --- a/cron/sms_queue.php +++ b/cron/sms_queue.php @@ -43,6 +43,11 @@ if (!smsProvider()) { cronJobStop("Texting isn't set up\n"); } +// Development mode sends no texts, reminders included - they wait (functions/dev_mode.php) +if (devModeOn()) { + cronJobStop("Development mode - no texts are sent\n"); +} + smsTidy(); // Reminders of visits and calls coming up, to contacts who agreed to texts - queued, then sent with the rest diff --git a/cron/ticket_email_parser.php b/cron/ticket_email_parser.php index 03188192a..8f6129abf 100644 --- a/cron/ticket_email_parser.php +++ b/cron/ticket_email_parser.php @@ -53,6 +53,11 @@ if ($config_ticket_email_parse == 0) { cronJobStop("Email Parser: Feature is not enabled - check Settings > Ticketing > Email-to-ticket parsing. See https://docs.itflow.org/ticket_email_parse -- Quitting.."); } +// Development mode doesn't read the ticket mailbox - it would take production's email (functions/dev_mode.php) +if (devModeOn()) { + cronJobStop("Development mode - the ticket mailbox isn't read"); +} + // Overlapping runs are prevented by cron/includes/cron_lock.php. This script used to keep a // lock file of its own alongside that one, which needed a five minute age heuristic to // recover from a killed run and could only end itself with exit() - fatal to a dispatched diff --git a/functions.php b/functions.php index 8e6c8eeca..dfffcba9a 100644 --- a/functions.php +++ b/functions.php @@ -116,6 +116,7 @@ require_once __DIR__ . '/functions/mail_queue.php'; require_once __DIR__ . '/functions/cron_health.php'; require_once __DIR__ . '/functions/managed.php'; require_once __DIR__ . '/functions/demo.php'; +require_once __DIR__ . '/functions/dev_mode.php'; // The connection config.php opened takes the collation the tables have, so that a string the // server makes (CAST(x AS CHAR), say) matches them - functions/database_collation.php diff --git a/functions/demo.php b/functions/demo.php index da1c19b00..0c534898a 100644 --- a/functions/demo.php +++ b/functions/demo.php @@ -75,7 +75,7 @@ const DEMO_MODE_LOCKS = [ ], [ 'message' => "Backups and updates are turned off in the demo.", - 'keys' => ['backup_master_key', 'delete_backup', 'edit_backup_settings', 'queue_backup', 'check_update', 'queue_update'], + 'keys' => ['backup_master_key', 'delete_backup', 'edit_backup_settings', 'edit_dev_mode', 'queue_backup', 'check_update', 'queue_update'], ], [ 'message' => "Cron can't be changed in the demo - it runs the nightly reset.", diff --git a/functions/dev_mode.php b/functions/dev_mode.php new file mode 100644 index 000000000..71fc23b18 --- /dev/null +++ b/functions/dev_mode.php @@ -0,0 +1,119 @@ + Backup sets both, when config.php can be written (devModeConfigSet()). + * + * With it on, nothing reaches your clients, your team or the systems production talks to: + * - every email goes to the test inbox, its real recipient at the front of its subject + * (cron/mail_queue.php); with no test inbox, email is cancelled, as in the demo + * - texts aren't sent - they wait in the queue (functions/sms.php, cron/sms_queue.php) + * - the ticket mailbox isn't read - it would take production's email (cron/ticket_email_parser.php) + * - AI Triage doesn't run (cron/ai_triage.php) + * - Stripe refuses every call, so no card is charged and nothing is made there + * (includes/stripe_init.php); autopay and Payment Provider Fees don't run + * - RMM devices still come in, but nothing is done to one (rmmDeviceAct()) + * - log entries aren't sent to a syslog server (functions/log_forward.php) + * - a managed instance doesn't talk to its manager, and a manager doesn't watch its + * instances (managedHttpJson(), cron/manager_checkin.php, cron/managed_instances.php) + * - telemetry isn't sent (cron/nightly_tasks.php) + * A red DEVELOPMENT badge shows in the top bar of every agent page. + * + * Off - the default - none of this exists. + */ + +/** Is this ITFlow in development mode? */ +function devModeOn(): bool +{ + global $config_dev_mode; + return !empty($config_dev_mode); +} + +/** Where development mode sends every email - '' when no good address is set. */ +function devModeMailTo(): string +{ + global $config_dev_mail_to; + $to = trim((string) ($config_dev_mail_to ?? '')); + return filter_var($to, FILTER_VALIDATE_EMAIL) ? $to : ''; +} + +/** What development mode switches off, in a line - for the badge and Admin > Backup. */ +function devModeSummary(): string +{ + $to = devModeMailTo(); + return 'Development mode: ' . ($to !== '' ? "every email goes to $to" : 'no email is sent') + . '; texts, the ticket mailbox, AI Triage, Stripe, RMM device actions, log forwarding and managed check-ins are off.'; +} + +/** includes/stripe_init.php: in development mode every Stripe call is refused - nothing is charged or made. */ +function devModeBlockStripe(): void +{ + if (!devModeOn() || !class_exists('\Stripe\ApiRequestor')) { + return; + } + \Stripe\ApiRequestor::setHttpClient(new class implements \Stripe\HttpClient\ClientInterface { + public function request($method, $absUrl, $headers, $params, $hasFile, $apiMode = 'v1', $maxNetworkRetries = null) + { + throw new \Stripe\Exception\ApiConnectionException('Development mode - Stripe and card payments are off on this server.'); + } + }); +} + +/** Whether config.php can be changed from Admin > Backup. */ +function devModeConfigWritable(): bool +{ + return is_writable(dirname(__DIR__) . '/config.php'); +} + +/* + * Set development mode's two lines in config.php - replaced where they are, added at the end + * where they aren't. Returns '' or why it couldn't. + */ +function devModeConfigSet(bool $on, string $mail_to): string +{ + $file = dirname(__DIR__) . '/config.php'; + if ($mail_to !== '' && !filter_var($mail_to, FILTER_VALIDATE_EMAIL)) { + return 'The test inbox isn\'t an email address.'; + } + if (!is_writable($file)) { + return 'config.php can\'t be written - add the lines by hand.'; + } + $text = @file_get_contents($file); + if ($text === false) { + return 'config.php can\'t be read.'; + } + $lines = ['config_dev_mode' => $on, 'config_dev_mail_to' => $mail_to]; + $added = ''; + foreach ($lines as $name => $value) { + $line = "\$$name = " . var_export($value, true) . ';'; + $pattern = '/^\$' . $name . '\s*=.*;[ \t]*$/m'; + if (preg_match($pattern, $text)) { + $text = preg_replace_callback($pattern, function () use ($line) { + return $line; + }, $text); + } else { + $added .= "$line\n"; + } + } + if ($added !== '') { + $text = rtrim($text) . "\n\n// Development mode - for a test copy: email goes to the test inbox, and nothing reaches clients or other systems (Admin > Backup)\n" . $added; + } + if (@file_put_contents($file, $text, LOCK_EX) === false) { + return 'config.php couldn\'t be written.'; + } + // PHP's code cache would keep the old config.php for a while + if (function_exists('opcache_invalidate')) { + @opcache_invalidate($file, true); + } + foreach ($lines as $name => $value) { + $GLOBALS[$name] = $value; + } + return ''; +} diff --git a/functions/log_forward.php b/functions/log_forward.php index 3b9d70c7b..a848306bd 100644 --- a/functions/log_forward.php +++ b/functions/log_forward.php @@ -164,7 +164,8 @@ function logForwardPending($add = null) { function logForwardQueue($log, $id, $level = '', $category = '') { static $registered = false; $id = intval($id); - if ($id <= 0 || (function_exists('emailCapturing') && emailCapturing())) { + // Development mode: a copy doesn't feed production's log server (functions/dev_mode.php) + if ($id <= 0 || (function_exists('emailCapturing') && emailCapturing()) || (function_exists('devModeOn') && devModeOn())) { return; } $settings = logForwardSettings(); @@ -250,6 +251,10 @@ function logForwardSend(array $settings, array $lines, &$error = '', $keep = tru static $socket = null; static $socket_target = ''; $error = ''; + if (function_exists('devModeOn') && devModeOn()) { + $error = 'Development mode - logs aren\'t sent from this server.'; + return false; + } $target = logForwardTarget($settings) . ($settings['protocol'] === 'tls' ? ($settings['tls_verify'] ? ' verified' : ' unverified') : ''); if ($socket && ($socket_target !== $target || !$keep)) { @fclose($socket); diff --git a/functions/managed.php b/functions/managed.php index 49dfb4a23..e25ef097c 100644 --- a/functions/managed.php +++ b/functions/managed.php @@ -112,6 +112,11 @@ function managedRequestBaseUrl(): string /* POST JSON and read JSON back - ['ok', 'code', 'json', 'err'] */ function managedHttpJson(string $url, array $body, array $headers = []): array { + // Development mode: a copy doesn't talk to a manager as the ITFlow it was copied from (functions/dev_mode.php) + if (devModeOn()) { + return ['ok' => false, 'code' => 0, 'json' => [], 'err' => 'Development mode - this server doesn\'t talk to a manager']; + } + $ch = curl_init($url); curl_setopt_array($ch, [ CURLOPT_RETURNTRANSFER => true, diff --git a/functions/rmm.php b/functions/rmm.php index 97e27b48d..bfa71e321 100644 --- a/functions/rmm.php +++ b/functions/rmm.php @@ -1544,6 +1544,10 @@ function rmmDeviceAct(array $row, string $action, array $options = []): array if (!isset(rmmDeviceActions($row)[$action])) { return ['ok' => false, 'output' => null, 'timed_out' => false, 'error' => rmmActionHost($row) . ' can\'t have that done from ITFlow now.']; } + // Development mode: devices still come in, but nothing is done to one (functions/dev_mode.php) + if (devModeOn()) { + return ['ok' => false, 'output' => null, 'timed_out' => false, 'error' => 'Development mode - nothing is done to devices from this server.']; + } return call_user_func(rmmKind($row)['act'], $row, (string) $row['rmm_device_remote_id'], $action, $options); } diff --git a/functions/sms.php b/functions/sms.php index cadb25ab5..bdfaafcde 100644 --- a/functions/sms.php +++ b/functions/sms.php @@ -600,6 +600,11 @@ function smsSendQueued(int $id): array return ['ok' => false, 'error' => "Texting isn't set up"]; } + // Development mode sends no texts - they wait in the queue (functions/dev_mode.php) + if (devModeOn()) { + return ['ok' => false, 'error' => "Development mode - no texts are sent from this server, so it waits in the queue"]; + } + // Claimed, so the job and a request can't both send it mysqli_query($mysqli, "UPDATE sms_messages SET sms_message_status = 'sending', sms_message_attempts = sms_message_attempts + 1, sms_message_attempted_at = NOW() WHERE sms_message_id = $id AND sms_message_direction = 'out' AND sms_message_status = 'queued'"); diff --git a/includes/stripe_init.php b/includes/stripe_init.php index fc994e5c1..80d3513a2 100644 --- a/includes/stripe_init.php +++ b/includes/stripe_init.php @@ -23,3 +23,8 @@ if (is_dir($stripe_config_dir) && is_writable($stripe_config_dir)) { unset($stripe_config_dir); require_once __DIR__ . '/../libs/stripe-php/init.php'; + +// Development mode refuses every Stripe call - no card is charged, nothing is made (functions/dev_mode.php) +if (function_exists('devModeBlockStripe')) { + devModeBlockStripe(); +} diff --git a/includes/top_nav.php b/includes/top_nav.php index 2469579d1..e54226956 100644 --- a/includes/top_nav.php +++ b/includes/top_nav.php @@ -27,6 +27,17 @@