Files
itflow/includes/load_global_settings.php
johnnyq 3b5c11c552 Add managed mode, so one ITFlow can manage others - Admin > Managed Instances adds an instance and gives a one-time connection code (a week) that the other ITFlow pastes into the new Admin > Managed By, after which it checks in every minute from the new Manager Check-in cron job with a health report (versions, update waiting and whether it has security fixes, cron, last backup, errors today, agents against the seat limit, clients, storage) and takes back what the manager sets; the manager lists each instance's version, health, seats and last check-in with a page per instance showing what needs a look, its requests and everything it reported, can update it by hand or automatically after a set number of days (security releases straight away, not retried for six hours after a failure), set its seat limit and white-label key (locked on the instance while set), make it read-only (look, export and download only, across agents, portal, guest links and the API) or suspended (a notice with the manager's message and contact, 503 for the API) with other cron jobs paused until it is active again, sign in to it as support through a signed one-time two-minute link into a two-hour session that takes no seat, can't open the vault and can't set passwords or make API keys, and remove it, while the new Managed Instances job notifies when one stops checking in and closes requests never answered; instances only call the manager, can disconnect unless config.php sets $config_manager_required, and the Update page and queue_update defer to the manager; database 3.5.8 adds managed_instances, managed_instance_commands, settings.config_manager_keys and settings.config_managed, the logic is in the new functions/managed.php with api/managed/enroll.php, api/managed/checkin.php, login_support.php and includes/managed_blocked.php, cronJobClaim() takes a paused reason that leaves a due job due, getAgentUserLimit() and getActiveAgentUserCount() honour the manager's limit and leave out the support user, the vault helpers read a missing session key as empty, the audit log knows the new types and actions, and the email parser no longer logs an App Logs error every minute while parsing is switched off; changelog updated
2026-11-05 15:22:41 -05:00

220 lines
11 KiB
PHP

<?php
// Query Settings
$sql_settings = mysqli_query($mysqli, "SELECT config_azure_client_id, config_azure_client_secret, config_client_portal_enable, config_client_portal_require_mfa,
config_current_database_version, config_default_calendar, config_default_expense_account,
config_default_expense_payment_method, config_default_hourly_rate,
config_default_net_terms, config_default_payment_account, config_default_payment_method,
config_default_transfer_from_account, config_default_transfer_to_account,
config_destructive_deletes_enable, config_enable_alert_domain_expire, config_enable_cron,
config_imap_encryption, config_imap_host, config_imap_password, config_imap_port,
config_imap_provider, config_imap_username, config_invoice_footer,
config_invoice_from_email, config_invoice_from_name, config_invoice_late_fee_enable,
config_invoice_late_fee_percent, config_invoice_next_number,
config_invoice_paid_notification_email, config_invoice_prefix, config_invoice_show_tax_id,
config_tax_default_id, config_tax_time, config_tax_trips, config_tax_expenses, config_tax_discount_before,
config_internal_client_id,
config_log_retention, config_login_key_required, config_login_key_secret,
config_login_message, config_login_remember_me_expire, config_mail_from_email,
config_mail_from_name, config_mail_oauth_access_token,
config_mail_oauth_access_token_expires_at, config_mail_oauth_client_id,
config_mail_oauth_client_secret, config_mail_oauth_refresh_token,
config_mail_oauth_tenant_id, config_module_enable_accounting, config_module_enable_itdoc,
config_module_enable_ticketing, config_project_next_number, config_project_prefix,
config_quote_footer, config_quote_from_email, config_quote_from_name,
config_quote_next_number, config_quote_notification_email, config_quote_prefix,
config_recurring_auto_send_invoice, config_recurring_invoice_next_number,
config_recurring_invoice_prefix, config_send_invoice_reminders, config_smtp_encryption,
config_smtp_host, config_smtp_password, config_smtp_port, config_smtp_provider,
config_smtp_username, config_start_page, config_telemetry, config_theme,
config_ticket_autoclose_hours, config_ticket_client_general_notifications,
config_ticket_default_billable, config_ticket_default_view, config_ticket_email_parse,
config_ticket_email_parse_unknown_senders, config_ticket_from_email,
config_ticket_from_name, config_ticket_moving_columns,
config_ticket_new_ticket_notification_email, config_ticket_next_number,
config_ticket_ordering, config_ticket_prefix, config_ticket_timer_autostart,
config_share_max_hours, config_share_require_protection, config_timezone, config_whitelabel_enabled, config_whitelabel_key FROM settings WHERE company_id = 1");
$row = mysqli_fetch_assoc($sql_settings);
// Database version
DEFINE("CURRENT_DATABASE_VERSION", $row['config_current_database_version']);
// Microsoft OAuth
$config_azure_client_id = $row['config_azure_client_id'];
$config_azure_client_secret = $row['config_azure_client_secret'];
// Mail - SMTP
$config_smtp_provider = $row['config_smtp_provider'];
$config_smtp_host = $row['config_smtp_host'];
$config_smtp_port = intval($row['config_smtp_port']);
$config_smtp_encryption = $row['config_smtp_encryption'];
$config_smtp_username = $row['config_smtp_username'];
$config_smtp_password = $row['config_smtp_password'];
$config_mail_from_email = $row['config_mail_from_email'];
$config_mail_from_name = $row['config_mail_from_name'];
// Mail - IMAP
$config_imap_provider = $row['config_imap_provider'];
$config_imap_host = $row['config_imap_host'];
$config_imap_port = intval($row['config_imap_port']);
$config_imap_encryption = $row['config_imap_encryption'];
$config_imap_username = $row['config_imap_username'];
$config_imap_password = $row['config_imap_password'];
// Mail OAUTH2
$config_mail_oauth_client_id = $row['config_mail_oauth_client_id'];
$config_mail_oauth_client_secret = $row['config_mail_oauth_client_secret'];
$config_mail_oauth_tenant_id = $row['config_mail_oauth_tenant_id'];
$config_mail_oauth_refresh_token = $row['config_mail_oauth_refresh_token'];
$config_mail_oauth_access_token = $row['config_mail_oauth_access_token'];
$config_mail_oauth_access_token_expires_at = $row['config_mail_oauth_access_token_expires_at'];
// Defaults
$config_start_page = $row['config_start_page'] ?? 'clients.php';
$config_default_transfer_from_account = intval($row['config_default_transfer_from_account']);
$config_default_transfer_to_account = intval($row['config_default_transfer_to_account']);
$config_default_payment_account = intval($row['config_default_payment_account']);
$config_default_expense_account = intval($row['config_default_expense_account']);
$config_default_payment_method = $row['config_default_payment_method'];
$config_default_expense_payment_method = $row['config_default_expense_payment_method'];
$config_default_calendar = intval($row['config_default_calendar']);
$config_default_net_terms = intval($row['config_default_net_terms']);
$config_default_hourly_rate = floatval($row['config_default_hourly_rate']);
// Invoice
$config_invoice_prefix = $row['config_invoice_prefix'];
$config_invoice_next_number = intval($row['config_invoice_next_number']);
$config_invoice_footer = $row['config_invoice_footer'];
$config_invoice_from_name = $row['config_invoice_from_name'];
$config_invoice_from_email = $row['config_invoice_from_email'];
$config_invoice_late_fee_enable = intval($row['config_invoice_late_fee_enable']);
$config_invoice_late_fee_percent = floatval($row['config_invoice_late_fee_percent']);
$config_invoice_paid_notification_email = $row['config_invoice_paid_notification_email'];
$config_invoice_show_tax_id = intval($row['config_invoice_show_tax_id']);
$config_tax_default_id = intval($row['config_tax_default_id']);
$config_tax_time = intval($row['config_tax_time']);
$config_tax_trips = intval($row['config_tax_trips']);
$config_tax_expenses = intval($row['config_tax_expenses']);
$config_tax_discount_before = intval($row['config_tax_discount_before']);
// Recurring Invoices
$config_recurring_invoice_prefix = $row['config_recurring_invoice_prefix'];
$config_recurring_invoice_next_number = intval($row['config_recurring_invoice_next_number']);
// Quotes
$config_quote_prefix = $row['config_quote_prefix'];
$config_quote_next_number = intval($row['config_quote_next_number']);
$config_quote_footer = $row['config_quote_footer'];
$config_quote_from_name = $row['config_quote_from_name'];
$config_quote_from_email = $row['config_quote_from_email'];
$config_quote_notification_email = $row['config_quote_notification_email'];
// Projects
$config_project_prefix = $row['config_project_prefix'];
$config_project_next_number = intval($row['config_project_next_number']);
// Tickets
$config_ticket_prefix = $row['config_ticket_prefix'];
$config_ticket_next_number = intval($row['config_ticket_next_number']);
$config_ticket_from_name = $row['config_ticket_from_name'];
$config_ticket_from_email = $row['config_ticket_from_email'];
$config_ticket_email_parse = intval($row['config_ticket_email_parse']);
$config_ticket_email_parse_unknown_senders = intval($row['config_ticket_email_parse_unknown_senders']);
$config_ticket_client_general_notifications = intval($row['config_ticket_client_general_notifications']);
$config_ticket_autoclose_hours = intval($row['config_ticket_autoclose_hours']);
$config_ticket_new_ticket_notification_email = $row['config_ticket_new_ticket_notification_email'];
$config_ticket_default_billable = intval($row['config_ticket_default_billable']);
$config_ticket_default_view = intval($row['config_ticket_default_view']);
$config_ticket_moving_columns = intval($row['config_ticket_moving_columns']);
$config_ticket_ordering = intval($row['config_ticket_ordering']);
$config_ticket_timer_autostart = intval($row['config_ticket_timer_autostart']);
// Cron
$config_enable_cron = intval($row['config_enable_cron']);
// Alerts & Notifications
$config_recurring_auto_send_invoice = intval($row['config_recurring_auto_send_invoice']);
$config_enable_alert_domain_expire = intval($row['config_enable_alert_domain_expire']);
$config_send_invoice_reminders = intval($row['config_send_invoice_reminders']);
// Modules
$config_module_enable_itdoc = intval($row['config_module_enable_itdoc']);
$config_module_enable_ticketing = intval($row['config_module_enable_ticketing']);
$config_module_enable_accounting = intval($row['config_module_enable_accounting']);
$config_client_portal_enable = intval($row['config_client_portal_enable']);
$config_client_portal_require_mfa = intval($row['config_client_portal_require_mfa']);
// The client record that represents this MSP's own company, or 0 for none
$config_internal_client_id = intval($row['config_internal_client_id']);
// Login
$config_login_message = $row['config_login_message'];
$config_login_key_required = $row['config_login_key_required'];
$config_login_key_secret = $row['config_login_key_secret'];
$config_login_remember_me_expire = intval($row['config_login_remember_me_expire']);
$config_log_retention = intval($row['config_log_retention']);
// Shared links - the longest one may last, and whether a password or secure
// note has to have a passphrase or an emailed code (functions/share.php)
$config_share_max_hours = intval($row['config_share_max_hours']) ?: 720;
$config_share_require_protection = intval($row['config_share_require_protection']);
// Locale
$config_currency_format = "US_en";
$config_timezone = $row['config_timezone'];
$config_date_format = "M d, Y";
$config_time_format = "g:i A";
// Theme
$config_theme = $row['config_theme'];
// Telemetry
$config_telemetry = intval($row['config_telemetry']);
// Destructive Deletes
$config_destructive_deletes_enable = intval($row['config_destructive_deletes_enable']);
// White label
$config_whitelabel_enabled = intval($row['config_whitelabel_enabled']);
$config_whitelabel_key = $row['config_whitelabel_key'];
// Select Arrays
$colors_array = array (
'lightblue',
'blue',
'green',
'cyan',
'yellow',
'red',
'black',
'gray-dark',
'gray',
'light',
'indigo',
'navy',
'purple',
'fuchsia',
'pink',
'maroon',
'orange',
'lime',
'teal',
'olive'
);
$records_per_page_array = array ('5','10','15','20','30','50','100');
include_once "settings_localization_array.php";
// Type => icon - the asset types, in order (ASSET_TYPES in functions/asset_type.php)
$asset_types_array = function_exists('assetTypeIcons') ? assetTypeIcons() : [];
// A managed instance its manager has made read-only or suspended (functions/managed.php). The
// pages anyone can open - guest links, signing up, joining, password resets - are checked here,
// as nearly all of them load this file. Client portal pages that load it before functions.php
// are checked by client/includes/check_login.php instead
if (PHP_SAPI !== 'cli' && function_exists('managedRequestGuard')) {
managedRequestGuard(str_starts_with((string) ($_SERVER['SCRIPT_NAME'] ?? ''), '/api/') ? 'api' : 'public');
}