From 5bf009f052c1add83804d07e61ddebfbb577a4cb Mon Sep 17 00:00:00 2001 From: wrongecho Date: Mon, 30 Dec 2024 16:54:16 +0000 Subject: [PATCH 001/150] Add changelog --- CHANGELOG.md | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..7e07100b --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,10 @@ +# Changelog + +All notable changes to ITFlow will be documented in this file. + +## 25.1 +- Lots yet to come... + +## 24.12 + +- First introduced versioned releases! \ No newline at end of file From df19709c2fbbe4663970eade965dfba7b23a087a Mon Sep 17 00:00:00 2001 From: wrongecho Date: Mon, 30 Dec 2024 17:31:34 +0000 Subject: [PATCH 002/150] Move cron scripts Move cron scripts to their own subfolder. --- cron.php | 8 +- scripts/.htaccess | 3 + scripts/cron.php | 1010 ++++++++++++++++++++++++ scripts/cron_certificate_refresher.php | 69 ++ scripts/cron_domain_refresher.php | 82 ++ scripts/cron_mail_queue.php | 228 ++++++ scripts/cron_ticket_email_parser.php | 560 +++++++++++++ 7 files changed, 1958 insertions(+), 2 deletions(-) create mode 100644 scripts/.htaccess create mode 100644 scripts/cron.php create mode 100644 scripts/cron_certificate_refresher.php create mode 100644 scripts/cron_domain_refresher.php create mode 100644 scripts/cron_mail_queue.php create mode 100644 scripts/cron_ticket_email_parser.php diff --git a/cron.php b/cron.php index 543c11ad..04e48d13 100644 --- a/cron.php +++ b/cron.php @@ -1,5 +1,8 @@ current_version !== $updates->latest_version) { * ############################################################################################################### */ -// Send Alert to inform Cron was run -appNotify("Cron", "Cron successfully executed", "admin_audit_log.php"); +// Alert we're using the old cron path +appNotify("Cron", "Cron ran OK, but paths need updating - cron scripts are now in the scripts subfolder", "admin_audit_log.php"); // Logging logApp("Cron", "info", "Cron executed successfully"); +logApp("Cron", "warning", "Cron ran using an old script path"); \ No newline at end of file diff --git a/scripts/.htaccess b/scripts/.htaccess new file mode 100644 index 00000000..77b4e697 --- /dev/null +++ b/scripts/.htaccess @@ -0,0 +1,3 @@ + + Require all denied + \ No newline at end of file diff --git a/scripts/cron.php b/scripts/cron.php new file mode 100644 index 00000000..543c11ad --- /dev/null +++ b/scripts/cron.php @@ -0,0 +1,1010 @@ + 0) { + + appNotify("Pending Tickets", "There are $tickets_pending_assignment new tickets pending assignment", "tickets.php?status=New"); + + // Logging + logApp("Cron", "info", "Cron created notifications for new tickets that are pending assignment"); +} + +// Recurring (Scheduled) tickets + +// Get recurring tickets for today +$sql_scheduled_tickets = mysqli_query($mysqli, "SELECT * FROM scheduled_tickets WHERE scheduled_ticket_next_run = CURDATE()"); + +if (mysqli_num_rows($sql_scheduled_tickets) > 0) { + while ($row = mysqli_fetch_array($sql_scheduled_tickets)) { + + $schedule_id = intval($row['scheduled_ticket_id']); + $subject = sanitizeInput($row['scheduled_ticket_subject']); + $details = mysqli_real_escape_string($mysqli, $row['scheduled_ticket_details']); + $priority = sanitizeInput($row['scheduled_ticket_priority']); + $frequency = sanitizeInput(strtolower($row['scheduled_ticket_frequency'])); + $billable = intval($row['scheduled_ticket_billable']); + $created_id = intval($row['scheduled_ticket_created_by']); + $assigned_id = intval($row['scheduled_ticket_assigned_to']); + $client_id = intval($row['scheduled_ticket_client_id']); + $contact_id = intval($row['scheduled_ticket_contact_id']); + $asset_id = intval($row['scheduled_ticket_asset_id']); + + $ticket_status = 1; // Default + if ($assigned_id > 0) { + $ticket_status = 2; // Set to open if we've auto-assigned an agent + } + + // Assign this new ticket the next ticket number + $ticket_number_sql = mysqli_fetch_array(mysqli_query($mysqli, "SELECT config_ticket_next_number FROM settings WHERE company_id = 1")); + $ticket_number = intval($ticket_number_sql['config_ticket_next_number']); + + // Increment config_ticket_next_number by 1 (for the next ticket) + $new_config_ticket_next_number = $ticket_number + 1; + mysqli_query($mysqli, "UPDATE settings SET config_ticket_next_number = $new_config_ticket_next_number WHERE company_id = 1"); + + // Raise the ticket + mysqli_query($mysqli, "INSERT INTO tickets SET ticket_prefix = '$config_ticket_prefix', ticket_number = $ticket_number, ticket_subject = '$subject', ticket_details = '$details', ticket_priority = '$priority', ticket_status = '$ticket_status', ticket_billable = $billable, ticket_created_by = $created_id, ticket_assigned_to = $assigned_id, ticket_contact_id = $contact_id, ticket_client_id = $client_id, ticket_asset_id = $asset_id"); + $id = mysqli_insert_id($mysqli); + + // Logging + logAction("Ticket", "Create", "Cron created recurring scheduled $frequency ticket - $subject", $client_id, $id); + + customAction('ticket_create', $id); + + // Notifications + + // Get client/contact/ticket details + $sql = mysqli_query( + $mysqli, + "SELECT client_name, contact_name, contact_email, ticket_prefix, ticket_number, ticket_priority, ticket_subject, ticket_details FROM tickets + LEFT JOIN clients ON ticket_client_id = client_id + LEFT JOIN contacts ON ticket_contact_id = contact_id + WHERE ticket_id = $id" + ); + $row = mysqli_fetch_array($sql); + + $contact_name = sanitizeInput($row['contact_name']); + $contact_email = sanitizeInput($row['contact_email']); + $client_name = sanitizeInput($row['client_name']); + $contact_name = sanitizeInput($row['contact_name']); + $contact_email = sanitizeInput($row['contact_email']); + $ticket_prefix = sanitizeInput($row['ticket_prefix']); + $ticket_number = intval($row['ticket_number']); + $ticket_priority = sanitizeInput($row['ticket_priority']); + $ticket_subject = sanitizeInput($row['ticket_subject']); + $ticket_details = mysqli_real_escape_string($mysqli, $row['ticket_details']); + + $data = []; + + // Notify client by email their ticket has been raised, if general notifications are turned on & there is a valid contact email + if (!empty($config_smtp_host) && $config_ticket_client_general_notifications == 1 && filter_var($contact_email, FILTER_VALIDATE_EMAIL)) { + + $email_subject = "Ticket created - [$ticket_prefix$ticket_number] - $ticket_subject (scheduled)"; + $email_body = "##- Please type your reply above this line -##

Hello $contact_name,

A ticket regarding \"$ticket_subject\" has been automatically created for you.

--------------------------------
$ticket_details--------------------------------

Ticket: $ticket_prefix$ticket_number
Subject: $ticket_subject
Status: Open
Portal: https://$config_base_url/portal/ticket.php?id=$id

--
$company_name - Support
$config_ticket_from_email
$company_phone"; + + $email = [ + 'from' => $config_ticket_from_email, + 'from_name' => $config_ticket_from_name, + 'recipient' => $contact_email, + 'recipient_name' => $contact_name, + 'subject' => $email_subject, + 'body' => $email_body + ]; + + $data[] = $email; + + } + + // Notify agent's via the DL address of the new ticket, if it's populated with a valid email + if (filter_var($config_ticket_new_ticket_notification_email, FILTER_VALIDATE_EMAIL)) { + + $email_subject = "ITFlow - New Recurring Ticket - $client_name: $ticket_subject"; + $email_body = "Hello,

This is a notification that a recurring (scheduled) ticket has been raised in ITFlow.
Ticket: $ticket_prefix$ticket_number
Client: $client_name
Priority: $priority
Link: https://$config_base_url/ticket.php?ticket_id=$id

--------------------------------

$ticket_subject
$ticket_details"; + + $email = [ + 'from' => $config_ticket_from_email, + 'from_name' => $config_ticket_from_name, + 'recipient' => $config_ticket_new_ticket_notification_email, + 'recipient_name' => $config_ticket_from_name, + 'subject' => $email_subject, + 'body' => $email_body + ]; + + $data[] = $email; + } + + // Add to the mail queue + addToMailQueue($mysqli, $data); + + // Set the next run date + if ($frequency == "weekly") { + // Note: We seemingly have to initialize a new datetime for each loop to avoid stacking the dates + $now = new DateTime(); + $next_run = date_add($now, date_interval_create_from_date_string('1 week')); + } elseif ($frequency == "monthly") { + $now = new DateTime(); + $next_run = date_add($now, date_interval_create_from_date_string('1 month')); + } elseif ($frequency == "quarterly") { + $now = new DateTime(); + $next_run = date_add($now, date_interval_create_from_date_string('3 months')); + } elseif ($frequency == "biannually") { + $now = new DateTime(); + $next_run = date_add($now, date_interval_create_from_date_string('6 months')); + } elseif ($frequency == "annually") { + $now = new DateTime(); + $next_run = date_add($now, date_interval_create_from_date_string('12 months')); + } + + // Update the run date + $next_run = $next_run->format('Y-m-d'); + $a = mysqli_query($mysqli, "UPDATE scheduled_tickets SET scheduled_ticket_next_run = '$next_run' WHERE scheduled_ticket_id = $schedule_id"); + + } +} + +// Logging +// logAction("Cron", "Task", "Cron created sent out recurring tickets"); + + +// TICKET RESOLUTION/CLOSURE PROCESS +// Changes tickets status from 'Resolved' >> 'Closed' after a defined interval + +$sql_resolved_tickets_to_close = mysqli_query( + $mysqli, + "SELECT * FROM tickets + WHERE ticket_status = 4 + AND ticket_updated_at < NOW() - INTERVAL $config_ticket_autoclose_hours HOUR" +); + +while ($row = mysqli_fetch_array($sql_resolved_tickets_to_close)) { + + $ticket_id = $row['ticket_id']; + $ticket_prefix = sanitizeInput($row['ticket_prefix']); + $ticket_number = intval($row['ticket_number']); + $ticket_subject = sanitizeInput($row['ticket_subject']); + $ticket_status = sanitizeInput($row['ticket_status']); + $ticket_assigned_to = sanitizeInput($row['ticket_assigned_to']); + $client_id = intval($row['ticket_client_id']); + + mysqli_query($mysqli,"UPDATE tickets SET ticket_status = 5, ticket_closed_at = NOW(), ticket_closed_by = $ticket_assigned_to WHERE ticket_id = $ticket_id"); + + //Logging + logAction("Ticket", "Closed", "$ticket_prefix$ticket_number auto closed", $client_id, $ticket_id); + + customAction('ticket_close', $ticket_id); + + //TODO: Add client notifs if $config_ticket_client_general_notifications is on +} + +if ($config_send_invoice_reminders == 1) { + + // PAST DUE INVOICE Notifications + //$invoiceAlertArray = [$config_invoice_overdue_reminders]; + $invoiceAlertArray = [30,60,90,120,150,180,210,240,270,300,330,360,390,420,450,480,510,540,570,590,620,650,680,710,740]; + + foreach ($invoiceAlertArray as $day) { + + $sql = mysqli_query( + $mysqli, + "SELECT * FROM invoices + LEFT JOIN clients ON invoice_client_id = client_id + LEFT JOIN contacts ON clients.client_id = contacts.contact_client_id AND contact_primary = 1 + WHERE invoice_status != 'Draft' + AND invoice_status != 'Paid' + AND invoice_status != 'Cancelled' + AND invoice_status != 'Non-Billable' + AND DATE_ADD(invoice_due, INTERVAL $day DAY) = CURDATE() + ORDER BY invoice_number DESC" + ); + + while ($row = mysqli_fetch_array($sql)) { + $invoice_id = intval($row['invoice_id']); + $invoice_prefix = sanitizeInput($row['invoice_prefix']); + $invoice_number = intval($row['invoice_number']); + $invoice_status = sanitizeInput($row['invoice_status']); + $invoice_date = sanitizeInput($row['invoice_date']); + $invoice_due = sanitizeInput($row['invoice_due']); + $invoice_url_key = sanitizeInput($row['invoice_url_key']); + $invoice_amount = floatval($row['invoice_amount']); + $invoice_currency_code = sanitizeInput($row['invoice_currency_code']); + $client_id = intval($row['client_id']); + $client_name = sanitizeInput($row['client_name']); + $contact_name = sanitizeInput($row['contact_name']); + $contact_email = sanitizeInput($row['contact_email']); + + // Late Charges + + if ($config_invoice_late_fee_enable == 1) { + + $todays_date = date('Y-m-d'); + $late_fee_amount = ($invoice_amount * $config_invoice_late_fee_percent) / 100; + $new_invoice_amount = $invoice_amount + $late_fee_amount; + + mysqli_query($mysqli, "UPDATE invoices SET invoice_amount = $new_invoice_amount WHERE invoice_id = $invoice_id"); + + //Insert Items into New Invoice + mysqli_query($mysqli, "INSERT INTO invoice_items SET item_name = 'Late Fee', item_description = '$config_invoice_late_fee_percent% late fee applied on $todays_date', item_quantity = 1, item_price = $late_fee_amount, item_total = $late_fee_amount, item_order = 998, item_invoice_id = $invoice_id"); + + mysqli_query($mysqli, "INSERT INTO history SET history_status = 'Sent', history_description = 'Cron applied a late fee of $late_fee_amount', history_invoice_id = $invoice_id"); + + appNotify("Invoice Late Charge", "Invoice $invoice_prefix$invoice_number for $client_name in the amount of $invoice_amount was charged a late fee of $late_fee_amount", "invoice.php?invoice_id=$invoice_id", $client_id); + + } + + appNotify("Invoice Overdue", "Invoice $invoice_prefix$invoice_number for $client_name in the amount of $invoice_amount is overdue by $day days", "invoice.php?invoice_id=$invoice_id", $client_id); + + $subject = "Overdue Invoice $invoice_prefix$invoice_number"; + $body = "Hello $contact_name,

Our records indicate that we have not yet received payment for the invoice $invoice_prefix$invoice_number. We kindly request that you submit your payment as soon as possible. If you have any questions or concerns, please do not hesitate to contact us at $company_email or $company_phone. +

+ Kindly review the invoice details mentioned below.

Invoice: $invoice_prefix$invoice_number
Issue Date: $invoice_date
Total: " . numfmt_format_currency($currency_format, $invoice_amount, $invoice_currency_code) . "
Due Date: $invoice_due
Over Due By: $day Days


To view your invoice, please click here.


--
$company_name - Billing
$config_invoice_from_email
$company_phone"; + + $mail = addToMailQueue($mysqli, [ + [ + 'from' => $config_invoice_from_email, + 'from_name' => $config_invoice_from_name, + 'recipient' => $contact_email, + 'recipient_name' => $contact_name, + 'subject' => $subject, + 'body' => $body + ] + ]); + + if ($mail === true) { + mysqli_query($mysqli, "INSERT INTO history SET history_status = 'Sent', history_description = 'Cron Emailed Overdue Invoice', history_invoice_id = $invoice_id"); + } else { + mysqli_query($mysqli, "INSERT INTO history SET history_status = 'Sent', history_description = 'Cron Failed to send Overdue Invoice', history_invoice_id = $invoice_id"); + + appNotify("Mail", "Failed to send email to $contact_email"); + + // Logging + logApp("Mail", "error", "Failed to send email to $contact_email regarding $subject. $mail"); + } + + } + + } +} +// Logging +// logAction("Cron", "Task", "Cron created notifications for past due invoices and sent out notifications to the primary and billing contacts email"); + +// Send Recurring Invoices that match todays date and are active + +//Loop through all recurring that match today's date and is active +$sql_recurring = mysqli_query($mysqli, "SELECT * FROM recurring + LEFT JOIN recurring_payments ON recurring_id = recurring_payment_recurring_invoice_id + LEFT JOIN clients ON client_id = recurring_client_id + WHERE recurring_next_date = CURDATE() + AND recurring_status = 1 +"); + +while ($row = mysqli_fetch_array($sql_recurring)) { + $recurring_id = intval($row['recurring_id']); + $recurring_scope = sanitizeInput($row['recurring_scope']); + $recurring_frequency = sanitizeInput($row['recurring_frequency']); + $recurring_status = sanitizeInput($row['recurring_status']); + $recurring_last_sent = sanitizeInput($row['recurring_last_sent']); + $recurring_next_date = sanitizeInput($row['recurring_next_date']); + $recurring_discount_amount = floatval($row['recurring_discount_amount']); + $recurring_amount = floatval($row['recurring_amount']); + $recurring_currency_code = sanitizeInput($row['recurring_currency_code']); + $recurring_note = sanitizeInput($row['recurring_note']); + $recurring_invoice_email_notify = intval($row['recurring_invoice_email_notify']); + $category_id = intval($row['recurring_category_id']); + $client_id = intval($row['recurring_client_id']); + $client_name = sanitizeInput($row['client_name']); + $client_net_terms = intval($row['client_net_terms']); + + $recurring_payment_recurring_invoice_id = intval($row['recurring_payment_recurring_invoice_id']); + $recurring_payment_currency_code = sanitizeInput($row['recurring_payment_currency_code']); + $recurring_payment_method = sanitizeInput($row['recurring_payment_method']); + $recurring_payment_account_id = intval($row['recurring_payment_account_id']); + + // Get the last Invoice Number and add 1 for the new invoice number + $sql_invoice_number = mysqli_query($mysqli, "SELECT * FROM settings WHERE company_id = 1"); + $row = mysqli_fetch_array($sql_invoice_number); + $config_invoice_next_number = intval($row['config_invoice_next_number']); + + $new_invoice_number = $config_invoice_next_number; + $new_config_invoice_next_number = $config_invoice_next_number + 1; + mysqli_query($mysqli, "UPDATE settings SET config_invoice_next_number = $new_config_invoice_next_number WHERE company_id = 1"); + + //Generate a unique URL key for clients to access + $url_key = randomString(156); + + mysqli_query($mysqli, "INSERT INTO invoices SET invoice_prefix = '$config_invoice_prefix', invoice_number = $new_invoice_number, invoice_scope = '$recurring_scope', invoice_date = CURDATE(), invoice_due = DATE_ADD(CURDATE(), INTERVAL $client_net_terms day), invoice_discount_amount = $recurring_discount_amount, invoice_amount = $recurring_amount, invoice_currency_code = '$recurring_currency_code', invoice_note = '$recurring_note', invoice_category_id = $category_id, invoice_status = 'Sent', invoice_url_key = '$url_key', invoice_client_id = $client_id"); + + $new_invoice_id = mysqli_insert_id($mysqli); + + //Copy Items from original recurring invoice to new invoice + $sql_invoice_items = mysqli_query($mysqli, "SELECT * FROM invoice_items WHERE item_recurring_id = $recurring_id ORDER BY item_id ASC"); + + while ($row = mysqli_fetch_array($sql_invoice_items)) { + $item_id = intval($row['item_id']); + $item_name = sanitizeInput($row['item_name']); //SQL Escape incase of , + $item_description = sanitizeInput($row['item_description']); //SQL Escape incase of , + $item_quantity = floatval($row['item_quantity']); + $item_price = floatval($row['item_price']); + $item_subtotal = floatval($row['item_subtotal']); + $item_tax = floatval($row['item_tax']); + $item_total = floatval($row['item_total']); + $item_order = intval($row['item_order']); + $tax_id = intval($row['item_tax_id']); + + //Insert Items into New Invoice + mysqli_query($mysqli, "INSERT INTO invoice_items SET item_name = '$item_name', item_description = '$item_description', item_quantity = $item_quantity, item_price = $item_price, item_subtotal = $item_subtotal, item_tax = $item_tax, item_total = $item_total, item_order = $item_order, item_tax_id = $tax_id, item_invoice_id = $new_invoice_id"); + + } + + mysqli_query($mysqli, "INSERT INTO history SET history_status = 'Sent', history_description = 'Invoice Generated from Recurring!', history_invoice_id = $new_invoice_id"); + + appNotify("Recurring Sent", "Recurring Invoice $config_invoice_prefix$new_invoice_number for $client_name Sent", "invoice.php?invoice_id=$new_invoice_id", $client_id); + + customAction('invoice_create', $new_invoice_id); + + //Update recurring dates + + mysqli_query($mysqli, "UPDATE recurring SET recurring_last_sent = CURDATE(), recurring_next_date = DATE_ADD(CURDATE(), INTERVAL 1 $recurring_frequency) WHERE recurring_id = $recurring_id"); + + if ($config_recurring_auto_send_invoice == 1 && $recurring_invoice_email_notify == 1) { + $sql = mysqli_query( + $mysqli, + "SELECT * FROM invoices + LEFT JOIN clients ON invoice_client_id = client_id + LEFT JOIN contacts ON clients.client_id = contacts.contact_client_id AND contact_primary = 1 + WHERE invoice_id = $new_invoice_id" + ); + + $row = mysqli_fetch_array($sql); + $invoice_prefix = sanitizeInput($row['invoice_prefix']); + $invoice_number = intval($row['invoice_number']); + $invoice_scope = sanitizeInput($row['invoice_scope']); + $invoice_date = sanitizeInput($row['invoice_date']); + $invoice_due = sanitizeInput($row['invoice_due']); + $invoice_amount = floatval($row['invoice_amount']); + $invoice_url_key = sanitizeInput($row['invoice_url_key']); + $client_id = intval($row['client_id']); + $client_name = sanitizeInput($row['client_name']); + $contact_name = sanitizeInput($row['contact_name']); + $contact_email = sanitizeInput($row['contact_email']); + + $subject = "Invoice $invoice_prefix$invoice_number"; + $body = "Hello $contact_name,

An invoice regarding \"$invoice_scope\" has been generated. Please view the details below.

Invoice: $invoice_prefix$invoice_number
Issue Date: $invoice_date
Total: " . numfmt_format_currency($currency_format, $invoice_amount, $recurring_currency_code) . "
Due Date: $invoice_due


To view your invoice, please click here.


--
$company_name - Billing
$config_invoice_from_email
$company_phone"; + + $mail = addToMailQueue($mysqli, [ + [ + 'from' => $config_invoice_from_email, + 'from_name' => $config_invoice_from_name, + 'recipient' => $contact_email, + 'recipient_name' => $contact_name, + 'subject' => $subject, + 'body' => $body + ] + ]); + + if ($mail === true) { + mysqli_query($mysqli, "INSERT INTO history SET history_status = 'Sent', history_description = 'Cron Emailed Invoice!', history_invoice_id = $new_invoice_id"); + mysqli_query($mysqli, "UPDATE invoices SET invoice_status = 'Sent', invoice_client_id = $client_id WHERE invoice_id = $new_invoice_id"); + + } else { + mysqli_query($mysqli, "INSERT INTO history SET history_status = 'Draft', history_description = 'Cron Failed to send Invoice!', history_invoice_id = $new_invoice_id"); + + appNotify("Mail", "Failed to send email to $contact_email"); + + // Logging + logApp("Mail", "error", "Failed to send email to $contact_email regarding $subject. $mail"); + + } + + // Send copies of the invoice to any additional billing contacts + $sql_billing_contacts = mysqli_query($mysqli, "SELECT contact_name, contact_email FROM contacts + WHERE contact_billing = 1 + AND contact_email != '$contact_email' + AND contact_client_id = $client_id" + ); + + while ($billing_contact = mysqli_fetch_array($sql_billing_contacts)) { + $billing_contact_name = sanitizeInput($billing_contact['contact_name']); + $billing_contact_email = sanitizeInput($billing_contact['contact_email']); + + $data = [ + [ + 'from' => $config_invoice_from_email, + 'from_name' => $config_invoice_from_name, + 'recipient' => $billing_contact_email, + 'recipient_name' => $billing_contact_name, + 'subject' => $subject, + 'body' => $body + ] + ]; + + addToMailQueue($mysqli, $data); + } + + } //End if Autosend is on + + // Create Payment from Auto Payment + if ($recurring_payment_recurring_invoice_id) { + mysqli_query($mysqli,"INSERT INTO payments SET payment_date = CURDATE(), payment_amount = $recurring_amount, payment_currency_code = '$recurring_payment_currency_code', payment_account_id = $recurring_payment_account_id, payment_method = '$recurring_payment_method', payment_reference = 'Paid via AutoPay', payment_invoice_id = $new_invoice_id"); + + // Get Payment ID for reference + $payment_id = mysqli_insert_id($mysqli); + + // Update Invoice Status + mysqli_query($mysqli,"UPDATE invoices SET invoice_status = 'Paid' WHERE invoice_id = $new_invoice_id"); + + //Add Payment to History + mysqli_query($mysqli,"INSERT INTO history SET history_status = 'Paid', history_description = 'Payment added via Auto Pay', history_invoice_id = $new_invoice_id"); + + // Logging + logAction("Invoice", "Payment", "Auto Payment amount of " . numfmt_format_currency($currency_format, $recurring_amount, $recurring_payment_currency_code) . " added to invoice $invoice_prefix$invoice_number", $client_id, $new_invoice_id); + } //End Auto Payment + +} //End Recurring Invoices Loop + +// Logging +// logAction("Cron", "Task", "Cron created invoices from recurring invoices and sent emails out"); + +// Recurring Expenses +// Loop through all recurring expenses that match today's date and is active +$sql_recurring_expenses = mysqli_query($mysqli, "SELECT * FROM recurring_expenses WHERE recurring_expense_next_date = CURDATE() AND recurring_expense_status = 1"); + +while ($row = mysqli_fetch_array($sql_recurring_expenses)) { + $recurring_expense_id = intval($row['recurring_expense_id']); + $recurring_expense_frequency = intval($row['recurring_expense_frequency']); + $recurring_expense_month = intval($row['recurring_expense_month']); + $recurring_expense_day = intval($row['recurring_expense_day']); + $recurring_expense_description = sanitizeInput($row['recurring_expense_description']); + $recurring_expense_amount = floatval($row['recurring_expense_amount']); + $recurring_expense_payment_method = sanitizeInput($row['recurring_expense_payment_method']); + $recurring_expense_reference = sanitizeInput($row['recurring_expense_reference']); + $recurring_expense_currency_code = sanitizeInput($row['recurring_expense_currency_code']); + $recurring_expense_vendor_id = intval($row['recurring_expense_vendor_id']); + $recurring_expense_category_id = intval($row['recurring_expense_category_id']); + $recurring_expense_account_id = intval($row['recurring_expense_account_id']); + $recurring_expense_client_id = intval($row['recurring_expense_client_id']); + + // Calculate next billing date based on frequency + if ($recurring_expense_frequency == 1) { // Monthly + $next_date_query = "DATE_ADD(CURDATE(), INTERVAL 1 MONTH)"; + } elseif ($recurring_expense_frequency == 2) { // Yearly + $next_date_query = "DATE(CONCAT(YEAR(CURDATE()) + 1, '-', $recurring_expense_month, '-', $recurring_expense_day))"; + } else { + // Handle unexpected frequency values. For now, just use current date. + $next_date_query = "CURDATE()"; + } + + mysqli_query($mysqli,"INSERT INTO expenses SET expense_date = CURDATE(), expense_amount = $recurring_expense_amount, expense_currency_code = '$recurring_expense_currency_code', expense_account_id = $recurring_expense_account_id, expense_vendor_id = $recurring_expense_vendor_id, expense_client_id = $recurring_expense_client_id, expense_category_id = $recurring_expense_category_id, expense_description = '$recurring_expense_description', expense_reference = '$recurring_expense_reference'"); + + $expense_id = mysqli_insert_id($mysqli); + + appNotify("Expense Created", "Expense $recurring_expense_description created from recurring expenses", "expenses.php", $recurring_expense_client_id); + + // Update recurring dates using calculated next billing date + + mysqli_query($mysqli, "UPDATE recurring_expenses SET recurring_expense_last_sent = CURDATE(), recurring_expense_next_date = $next_date_query WHERE recurring_expense_id = $recurring_expense_id"); + + +} //End Recurring Invoices Loop + +// Logging +logApp("Cron", "info", "Cron created expenses from recurring expenses"); + +// TELEMETRY + +if ($config_telemetry > 0 || $config_telemetry == 2) { + + $current_version = exec("git rev-parse HEAD"); + + // Client Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('client_id') AS num FROM clients")); + $client_count = $row['num']; + + // Ticket Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('recurring_id') AS num FROM tickets")); + $ticket_count = $row['num']; + + // Recurring (Scheduled) Ticket Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('scheduled_ticket_id') AS num FROM scheduled_tickets")); + $scheduled_ticket_count = $row['num']; + + // Calendar Event Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('event_id') AS num FROM events")); + $calendar_event_count = $row['num']; + + // Quote Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('quote_id') AS num FROM quotes")); + $quote_count = $row['num']; + + // Invoice Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('invoice_id') AS num FROM invoices")); + $invoice_count = $row['num']; + + // Revenue Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('revenue_id') AS num FROM revenues")); + $revenue_count = $row['num']; + + // Recurring Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('recurring_id') AS num FROM recurring")); + $recurring_count = $row['num']; + + // Account Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('account_id') AS num FROM accounts")); + $account_count = $row['num']; + + // Tax Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('tax_id') AS num FROM taxes")); + $tax_count = $row['num']; + + // Product Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('product_id') AS num FROM products")); + $product_count = $row['num']; + + // Payment Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('payment_id') AS num FROM payments WHERE payment_invoice_id > 0")); + $payment_count = $row['num']; + + // Company Vendor Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('vendor_id') AS num FROM vendors WHERE vendor_template = 0 AND vendor_client_id = 0")); + $company_vendor_count = $row['num']; + + // Expense Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('expense_id') AS num FROM expenses WHERE expense_vendor_id > 0")); + $expense_count = $row['num']; + + // Trip Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('trip_id') AS num FROM trips")); + $trip_count = $row['num']; + + // Transfer Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('transfer_id') AS num FROM transfers")); + $transfer_count = $row['num']; + + // Contact Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('contact_id') AS num FROM contacts")); + $contact_count = $row['num']; + + // Location Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('location_id') AS num FROM locations")); + $location_count = $row['num']; + + // Asset Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('asset_id') AS num FROM assets")); + $asset_count = $row['num']; + + // Software Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('software_id') AS num FROM software WHERE software_template = 0")); + $software_count = $row['num']; + + // Software Template Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('software_id') AS num FROM software WHERE software_template = 1")); + $software_template_count = $row['num']; + + // Password Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('login_id') AS num FROM logins")); + $password_count = $row['num']; + + // Network Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('network_id') AS num FROM networks")); + $network_count = $row['num']; + + // Certificate Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('certificate_id') AS num FROM certificates")); + $certificate_count = $row['num']; + + // Domain Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('domain_id') AS num FROM domains")); + $domain_count = $row['num']; + + // Service Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('service_id') AS num FROM services")); + $service_count = $row['num']; + + // Client Vendor Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('vendor_id') AS num FROM vendors WHERE vendor_template = 0 AND vendor_client_id > 0")); + $client_vendor_count = $row['num']; + + // Vendor Template Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('vendor_id') AS num FROM vendors WHERE vendor_template = 1")); + $vendor_template_count = $row['num']; + + // File Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('file_id') AS num FROM files")); + $file_count = $row['num']; + + // Document Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('document_id') AS num FROM documents WHERE document_template = 0")); + $document_count = $row['num']; + + // Document Template Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('document_id') AS num FROM documents WHERE document_template = 1")); + $document_template_count = $row['num']; + + // Shared Item Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('item_id') AS num FROM shared_items")); + $shared_item_count = $row['num']; + + // Company Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('company_id') AS num FROM companies")); + $company_count = $row['num']; + + // User Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('user_id') AS num FROM users")); + $user_count = $row['num']; + + // Category Expense Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('category_id') AS num FROM categories WHERE category_type = 'Expense'")); + $category_expense_count = $row['num']; + + // Category Income Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('category_id') AS num FROM categories WHERE category_type = 'Income'")); + $category_income_count = $row['num']; + + // Category Referral Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('category_id') AS num FROM categories WHERE category_type = 'Referral'")); + $category_referral_count = $row['num']; + + // Category Payment Method Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('category_id') AS num FROM categories WHERE category_type = 'Payment Method'")); + $category_payment_method_count = $row['num']; + + // Tag Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('tag_id') AS num FROM tags")); + $tag_count = $row['num']; + + // API Key Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('api_key_id') AS num FROM api_keys")); + $api_key_count = $row['num']; + + // Log Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('log_id') AS num FROM logs")); + $log_count = $row['num']; + + $postdata = http_build_query( + array( + 'installation_id' => "$installation_id", + 'version' => "$current_version", + 'company_name' => "$company_name", + 'website' => "$company_website", + 'city' => "$company_city", + 'state' => "$company_state", + 'country' => "$company_country", + 'currency' => "$company_currency", + 'client_count' => $client_count, + 'ticket_count' => $ticket_count, + 'scheduled_ticket_count' => $scheduled_ticket_count, + 'calendar_event_count' => $calendar_event_count, + 'quote_count' => $quote_count, + 'invoice_count' => $invoice_count, + 'revenue_count' => $revenue_count, + 'recurring_count' => $recurring_count, + 'account_count' => $account_count, + 'tax_count' => $tax_count, + 'product_count' => $product_count, + 'payment_count' => $payment_count, + 'company_vendor_count' => $company_vendor_count, + 'expense_count' => $expense_count, + 'trip_count' => $trip_count, + 'transfer_count' => $transfer_count, + 'contact_count' => $contact_count, + 'location_count' => $location_count, + 'asset_count' => $asset_count, + 'software_count' => $software_count, + 'software_template_count' => $software_template_count, + 'password_count' => $password_count, + 'network_count' => $network_count, + 'certificate_count' => $certificate_count, + 'domain_count' => $domain_count, + 'service_count' => $service_count, + 'client_vendor_count' => $client_vendor_count, + 'vendor_template_count' => $vendor_template_count, + 'file_count' => $file_count, + 'document_count' => $document_count, + 'document_template_count' => $document_template_count, + 'shared_item_count' => $shared_item_count, + 'company_count' => $company_count, + 'user_count' => $user_count, + 'category_expense_count' => $category_expense_count, + 'category_income_count' => $category_income_count, + 'category_referral_count' => $category_referral_count, + 'category_payment_method_count' => $category_payment_method_count, + 'tag_count' => $tag_count, + 'api_key_count' => $api_key_count, + 'log_count' => $log_count, + 'config_theme' => "$config_theme", + 'config_enable_cron' => $config_enable_cron, + 'config_ticket_email_parse' => $config_ticket_email_parse, + 'config_module_enable_itdoc' => $config_module_enable_itdoc, + 'config_module_enable_ticketing' => $config_module_enable_ticketing, + 'config_module_enable_accounting' => $config_module_enable_accounting, + 'config_telemetry' => $config_telemetry, + 'collection_method' => 3 + ) + ); + + $opts = array('http' => + array( + 'method' => 'POST', + 'header' => 'Content-type: application/x-www-form-urlencoded', + 'content' => $postdata + ) + ); + + $context = stream_context_create($opts); + + $result = file_get_contents('https://telemetry.itflow.org', false, $context); + + // Logging + // logAction("Cron", "Task", "Cron sent telemetry results to ITFlow Developers"); + +} + + +// Fetch Updates +$updates = fetchUpdates(); + +$update_message = $updates->update_message; + +if ($updates->current_version !== $updates->latest_version) { + // Send Alert to inform Updates Available + appNotify("Update", "$update_message", "admin_update.php"); +} + + + +/* + * ############################################################################################################### + * FINISH UP + * ############################################################################################################### + */ + +// Send Alert to inform Cron was run +appNotify("Cron", "Cron successfully executed", "admin_audit_log.php"); + +// Logging +logApp("Cron", "info", "Cron executed successfully"); diff --git a/scripts/cron_certificate_refresher.php b/scripts/cron_certificate_refresher.php new file mode 100644 index 00000000..e7ffb1c4 --- /dev/null +++ b/scripts/cron_certificate_refresher.php @@ -0,0 +1,69 @@ + 600) { + + unlink($lock_file_path); + // Logging + logAction("Cron-Mail-Queue", "Delete", "Cron Mail Queuer detected a lock file was present but was over 10 minutes old so it removed it."); + + } else { + + // Logging + logAction("Cron-Mail-Queue", "Locked", "Cron Mail Queuer attempted to execute but was already executing so instead it terminated."); + + exit("Script is already running. Exiting."); + } +} + +// Create a lock file +file_put_contents($lock_file_path, "Locked"); + +// Process Mail Queue + +// Email Status: +// 0 Queued +// 1 Sending +// 2 Failed +// 3 Sent + +/* + * ############################################################################################################### + * Initial email send + * ############################################################################################################### + */ +// Get Mail Queue that has status of Queued and send it to the function sendSingleEmail() located in functions.php +$sql_queue = mysqli_query($mysqli, "SELECT * FROM email_queue WHERE email_status = 0 AND email_queued_at <= NOW()"); + +if (mysqli_num_rows($sql_queue) > 0) { + while ($row = mysqli_fetch_array($sql_queue)) { + $email_id = intval($row['email_id']); + $email_from = $row['email_from']; + $email_from_name = $row['email_from_name']; + $email_recipient = $row['email_recipient']; + $email_recipient_name = $row['email_recipient_name']; + $email_subject = $row['email_subject']; + $email_content = $row['email_content']; + $email_queued_at = $row['email_queued_at']; + $email_sent_at = $row['email_sent_at']; + $email_ics_str = $row['email_cal_str']; + + // First, validate the sender email address + if (filter_var($email_from, FILTER_VALIDATE_EMAIL)) { + + // Sanitized Input + $email_recipient_logging = sanitizeInput($row['email_recipient']); + $email_subject_logging = sanitizeInput($row['email_subject']); + + // Update the status to sending + mysqli_query($mysqli, "UPDATE email_queue SET email_status = 1 WHERE email_id = $email_id"); + + // Next, verify recipient email is valid + if (filter_var($email_recipient, FILTER_VALIDATE_EMAIL)) { + + $mail = sendSingleEmail( + $config_smtp_host, + $config_smtp_username, + $config_smtp_password, + $config_smtp_encryption, + $config_smtp_port, + $email_from, + $email_from_name, + $email_recipient, + $email_recipient_name, + $email_subject, + $email_content, + $email_ics_str + ); + + if ($mail !== true) { + // Update Message - Failure + mysqli_query($mysqli, "UPDATE email_queue SET email_status = 2, email_failed_at = NOW(), email_attempts = 1 WHERE email_id = $email_id"); + + appNotify("Cron-Mail-Queue", "Failed to send email #$email_id to $email_recipient_logging"); + + // Logging + logAction("Cron-Mail-Queue", "Error", "Failed to send email: $email_id to $email_recipient_logging regarding $email_subject_logging. $mail"); + } else { + // Update Message - Success + mysqli_query($mysqli, "UPDATE email_queue SET email_status = 3, email_sent_at = NOW(), email_attempts = 1 WHERE email_id = $email_id"); + } + + } else { + + // Recipient email isn't valid, mark as failed and log the error + mysqli_query($mysqli, "UPDATE email_queue SET email_status = 2, email_attempts = 99 WHERE email_id = $email_id"); + + // Logging + logAction("Cron-Mail-Queue", "Error", "Failed to send email: $email_id due to invalid recipient address. Email subject was: $email_subject_logging"); + } + + } else { + error_log("Failed to send email due to invalid sender address (' $email_from ') - check configuration in settings."); + + $email_from_logging = sanitizeInput($row['email_from']); + mysqli_query($mysqli, "UPDATE email_queue SET email_status = 2, email_attempts = 99 WHERE email_id = $email_id"); + + // Logging + logAction("Cron-Mail-Queue", "Error", "Failed to send email #$email_id due to invalid sender address: $email_from_logging - check configuration in settings."); + + appNotify("Mail", "Failed to send email #$email_id due to invalid sender address"); + + } + + } +} + + +/* + * ############################################################################################################### + * Retries + * ############################################################################################################### + */ +// Get Mail that failed to send and attempt to send Failed Mail up to 4 times every 30 mins +$sql_failed_queue = mysqli_query($mysqli, "SELECT * FROM email_queue WHERE email_status = 2 AND email_attempts < 4 AND email_failed_at < NOW() + INTERVAL 30 MINUTE"); + +if (mysqli_num_rows($sql_failed_queue) > 0) { + while ($row = mysqli_fetch_array($sql_failed_queue)) { + $email_id = intval($row['email_id']); + $email_from = $row['email_from']; + $email_from_name = $row['email_from_name']; + $email_recipient = $row['email_recipient']; + $email_recipient_name = $row['email_recipient_name']; + $email_subject = $row['email_subject']; + $email_content = $row['email_content']; + $email_queued_at = $row['email_queued_at']; + $email_sent_at = $row['email_sent_at']; + $email_ics_str = $row['email_cal_str']; + // Increment the attempts + $email_attempts = intval($row['email_attempts']) + 1; + + // Sanitized Input + $email_recipient_logging = sanitizeInput($row['email_recipient']); + $email_subject_logging = sanitizeInput($row['email_subject']); + + // Update the status to sending before actually sending + mysqli_query($mysqli, "UPDATE email_queue SET email_status = 1 WHERE email_id = $email_id"); + + // Verify recipient email is valid + if (filter_var($email_recipient, FILTER_VALIDATE_EMAIL)) { + + $mail = sendSingleEmail( + $config_smtp_host, + $config_smtp_username, + $config_smtp_password, + $config_smtp_encryption, + $config_smtp_port, + $email_from, + $email_from_name, + $email_recipient, + $email_recipient_name, + $email_subject, + $email_content, + $email_ics_str + ); + + if ($mail !== true) { + // Update Message + mysqli_query($mysqli, "UPDATE email_queue SET email_status = 2, email_failed_at = NOW(), email_attempts = $email_attempts WHERE email_id = $email_id"); + + // Logging + logAction("Cron-Mail-Queue", "Error", "Failed to re-send email #$email_id to $email_recipient_logging regarding $email_subject_logging. $mail"); + + } else { + + // Update Message + mysqli_query($mysqli, "UPDATE email_queue SET email_status = 3, email_sent_at = NOW(), email_attempts = $email_attempts WHERE email_id = $email_id"); + + } + } + } +} + +// Remove the lock file once mail has finished processing +unlink($lock_file_path); diff --git a/scripts/cron_ticket_email_parser.php b/scripts/cron_ticket_email_parser.php new file mode 100644 index 00000000..e8b3e637 --- /dev/null +++ b/scripts/cron_ticket_email_parser.php @@ -0,0 +1,560 @@ + Ticketing > Email-to-ticket parsing. See https://docs.itflow.org/ticket_email_parse -- Quitting.."); +} + +$argv = $_SERVER['argv']; + +// Check Cron Key +if ($argv[1] !== $config_cron_key) { + exit("Cron Key invalid -- Quitting.."); +} + +// Get system temp directory +$temp_dir = sys_get_temp_dir(); + +// Create the path for the lock file using the temp directory +$lock_file_path = "{$temp_dir}/itflow_email_parser_{$installation_id}.lock"; + +// Check for lock file to prevent concurrent script runs +if (file_exists($lock_file_path)) { + $file_age = time() - filemtime($lock_file_path); + + // If file is older than 5 minutes (300 seconds), delete and continue + if ($file_age > 300) { + unlink($lock_file_path); + + // Logging + logApp("Cron-Email-Parser", "warning", "Cron Email Parser detected a lock file was present but was over 5 minutes old so it removed it."); + + } else { + + // Logging + logApp("Cron-Email-Parser", "warning", "Lock file present. Cron Email Parser attempted to execute but was already executing, so instead it terminated."); + + exit("Script is already running. Exiting."); + } +} + +// Create a lock file +file_put_contents($lock_file_path, "Locked"); + +// PHP Mail Parser +use PhpMimeMailParser\Parser; +require_once "plugins/php-mime-mail-parser/Contracts/CharsetManager.php"; +require_once "plugins/php-mime-mail-parser/Contracts/Middleware.php"; +require_once "plugins/php-mime-mail-parser/Attachment.php"; +require_once "plugins/php-mime-mail-parser/Charset.php"; +require_once "plugins/php-mime-mail-parser/Exception.php"; +require_once "plugins/php-mime-mail-parser/Middleware.php"; +require_once "plugins/php-mime-mail-parser/MiddlewareStack.php"; +require_once "plugins/php-mime-mail-parser/MimePart.php"; +require_once "plugins/php-mime-mail-parser/Parser.php"; + +// Allowed attachment extensions +$allowed_extensions = array('jpg', 'jpeg', 'gif', 'png', 'webp', 'pdf', 'txt', 'md', 'doc', 'docx', 'csv', 'xls', 'xlsx', 'xlsm', 'zip', 'tar', 'gz'); + +// Function to raise a new ticket for a given contact and email them confirmation (if configured) +function addTicket($contact_id, $contact_name, $contact_email, $client_id, $date, $subject, $message, $attachments, $original_message_file) { + global $mysqli, $config_app_name, $company_name, $company_phone, $config_ticket_prefix, $config_ticket_client_general_notifications, $config_ticket_new_ticket_notification_email, $config_base_url, $config_ticket_from_name, $config_ticket_from_email, $allowed_extensions; + + $ticket_number_sql = mysqli_fetch_array(mysqli_query($mysqli, "SELECT config_ticket_next_number FROM settings WHERE company_id = 1")); + $ticket_number = intval($ticket_number_sql['config_ticket_next_number']); + $new_config_ticket_next_number = $ticket_number + 1; + mysqli_query($mysqli, "UPDATE settings SET config_ticket_next_number = $new_config_ticket_next_number WHERE company_id = 1"); + + // Clean up the message + $message = trim($message); // Remove leading/trailing whitespace + $message = preg_replace('/\s+/', ' ', $message); // Replace multiple spaces with a single space + $message = nl2br($message); // Convert newlines to
+ + // Wrap the message in a div with controlled line height + $message = "Email from: $contact_name <$contact_email> at $date:-

$message
"; + + $ticket_prefix_esc = mysqli_real_escape_string($mysqli, $config_ticket_prefix); + $message_esc = mysqli_real_escape_string($mysqli, $message); + $contact_email_esc = mysqli_real_escape_string($mysqli, $contact_email); + $client_id = intval($client_id); + + //Generate a unique URL key for clients to access + $url_key = randomString(156); + + mysqli_query($mysqli, "INSERT INTO tickets SET ticket_prefix = '$ticket_prefix_esc', ticket_number = $ticket_number, ticket_subject = '$subject', ticket_details = '$message_esc', ticket_priority = 'Low', ticket_status = 1, ticket_created_by = 0, ticket_contact_id = $contact_id, ticket_url_key = '$url_key', ticket_client_id = $client_id"); + $id = mysqli_insert_id($mysqli); + + // Logging + logAction("Ticket", "Create", "Email parser: Client contact $contact_email_esc created ticket $ticket_prefix_esc$ticket_number ($subject) ($id)", $client_id, $id); + + mkdirMissing('uploads/tickets/'); + $att_dir = "uploads/tickets/" . $id . "/"; + mkdirMissing($att_dir); + + rename("uploads/tmp/{$original_message_file}", "{$att_dir}/{$original_message_file}"); + $original_message_file_esc = mysqli_real_escape_string($mysqli, $original_message_file); + mysqli_query($mysqli, "INSERT INTO ticket_attachments SET ticket_attachment_name = 'Original-parsed-email.eml', ticket_attachment_reference_name = '$original_message_file_esc', ticket_attachment_ticket_id = $id"); + + foreach ($attachments as $attachment) { + $att_name = $attachment->getFilename(); + $att_extarr = explode('.', $att_name); + $att_extension = strtolower(end($att_extarr)); + + if (in_array($att_extension, $allowed_extensions)) { + $att_saved_filename = md5(uniqid(rand(), true)) . '.' . $att_extension; + $att_saved_path = $att_dir . $att_saved_filename; + file_put_contents($att_saved_path, $attachment->getContent()); + + $ticket_attachment_name = sanitizeInput($att_name); + $ticket_attachment_reference_name = sanitizeInput($att_saved_filename); + + $ticket_attachment_name_esc = mysqli_real_escape_string($mysqli, $ticket_attachment_name); + $ticket_attachment_reference_name_esc = mysqli_real_escape_string($mysqli, $ticket_attachment_reference_name); + mysqli_query($mysqli, "INSERT INTO ticket_attachments SET ticket_attachment_name = '$ticket_attachment_name_esc', ticket_attachment_reference_name = '$ticket_attachment_reference_name_esc', ticket_attachment_ticket_id = $id"); + } else { + $ticket_attachment_name_esc = mysqli_real_escape_string($mysqli, $att_name); + logAction("Ticket", "Edit", "Email parser: Blocked attachment $ticket_attachment_name_esc from Client contact $contact_email_esc for ticket $ticket_prefix_esc$ticket_number", $client_id, $id); + } + } + + // Guest ticket watchers + if ($client_id == 0) { + mysqli_query($mysqli, "INSERT INTO ticket_watchers SET watcher_email = '$contact_email_esc', watcher_ticket_id = $id"); + } + + $data = []; + if ($config_ticket_client_general_notifications == 1) { + $subject_email = "Ticket created - [$config_ticket_prefix$ticket_number] - $subject"; + $body = "##- Please type your reply above this line -##

Hello $contact_name,

Thank you for your email. A ticket regarding \"$subject\" has been automatically created for you.

Ticket: $config_ticket_prefix$ticket_number
Subject: $subject
Status: New
https://$config_base_url/portal/ticket.php?id=$id

--
$company_name - Support
$config_ticket_from_email
$company_phone"; + $data[] = [ + 'from' => $config_ticket_from_email, + 'from_name' => $config_ticket_from_name, + 'recipient' => $contact_email, + 'recipient_name' => $contact_name, + 'subject' => $subject_email, + 'body' => mysqli_real_escape_string($mysqli, $body) + ]; + } + + if ($config_ticket_new_ticket_notification_email) { + if ($client_id == 0) { + $client_name = "Guest"; + } else { + $client_sql = mysqli_query($mysqli, "SELECT client_name FROM clients WHERE client_id = $client_id"); + $client_row = mysqli_fetch_array($client_sql); + $client_name = sanitizeInput($client_row['client_name']); + } + $email_subject = "$config_app_name - New Ticket - $client_name: $subject"; + $email_body = "Hello,

This is a notification that a new ticket has been raised in ITFlow.
Client: $client_name
Priority: Low (email parsed)
Link: https://$config_base_url/ticket.php?ticket_id=$id

--------------------------------

$subject
$message"; + + $data[] = [ + 'from' => $config_ticket_from_email, + 'from_name' => $config_ticket_from_name, + 'recipient' => $config_ticket_new_ticket_notification_email, + 'recipient_name' => $config_ticket_from_name, + 'subject' => $email_subject, + 'body' => mysqli_real_escape_string($mysqli, $email_body) + ]; + } + + addToMailQueue($mysqli, $data); + + // Custom action/notif handler + customAction('ticket_create', $id); + + return true; +} + +// Add Reply Function +function addReply($from_email, $date, $subject, $ticket_number, $message, $attachments) { + global $mysqli, $config_app_name, $company_name, $company_phone, $config_ticket_prefix, $config_base_url, $config_ticket_from_name, $config_ticket_from_email, $allowed_extensions; + + $ticket_reply_type = 'Client'; + // Clean up the message + $message_parts = explode("##- Please type your reply above this line -##", $message); + $message_body = $message_parts[0]; + $message_body = trim($message_body); // Remove leading/trailing whitespace + $message_body = preg_replace('/\r\n|\r|\n/', ' ', $message_body); // Replace newlines with a space + $message_body = nl2br($message_body); // Convert remaining newlines to
+ + // Wrap the message in a div with controlled line height + $message = "Email from: $from_email at $date:-

$message_body
"; + + $ticket_number_esc = intval($ticket_number); + $message_esc = mysqli_real_escape_string($mysqli, $message); + $from_email_esc = mysqli_real_escape_string($mysqli, $from_email); + + $row = mysqli_fetch_array(mysqli_query($mysqli, "SELECT ticket_id, ticket_subject, ticket_status, ticket_contact_id, ticket_client_id, contact_email, client_name + FROM tickets + LEFT JOIN contacts on tickets.ticket_contact_id = contacts.contact_id + LEFT JOIN clients on tickets.ticket_client_id = clients.client_id + WHERE ticket_number = $ticket_number_esc LIMIT 1")); + + if ($row) { + $ticket_id = intval($row['ticket_id']); + $ticket_subject = sanitizeInput($row['ticket_subject']); + $ticket_status = sanitizeInput($row['ticket_status']); + $ticket_reply_contact = intval($row['ticket_contact_id']); + $ticket_contact_email = sanitizeInput($row['contact_email']); + $client_id = intval($row['ticket_client_id']); + $client_name = sanitizeInput($row['client_name']); + + if ($ticket_status == 5) { + $config_ticket_prefix_esc = mysqli_real_escape_string($mysqli, $config_ticket_prefix); + $ticket_number_esc = mysqli_real_escape_string($mysqli, $ticket_number); + + appNotify("Ticket", "Email parser: $from_email attempted to re-open ticket $config_ticket_prefix_esc$ticket_number_esc (ID $ticket_id) - check inbox manually to see email", "ticket.php?ticket_id=$ticket_id", $client_id); + + $email_subject = "Action required: This ticket is already closed"; + $email_body = "Hi there,

You've tried to reply to a ticket that is closed - we won't see your response.

Please raise a new ticket by sending a new e-mail to our support address below.

--
$company_name - Support
$config_ticket_from_email
$company_phone"; + + $data = [ + [ + 'from' => $config_ticket_from_email, + 'from_name' => $config_ticket_from_name, + 'recipient' => $from_email, + 'recipient_name' => $from_email, + 'subject' => $email_subject, + 'body' => mysqli_real_escape_string($mysqli, $email_body) + ] + ]; + + addToMailQueue($mysqli, $data); + + return true; + } + + if (empty($ticket_contact_email) || $ticket_contact_email !== $from_email) { + $from_email_esc = mysqli_real_escape_string($mysqli, $from_email); + $row = mysqli_fetch_array(mysqli_query($mysqli, "SELECT contact_id FROM contacts WHERE contact_email = '$from_email_esc' AND contact_client_id = $client_id LIMIT 1")); + if ($row) { + $ticket_reply_contact = intval($row['contact_id']); + } else { + $ticket_reply_type = 'Internal'; + $ticket_reply_contact = '0'; + $message = "WARNING: Contact email mismatch
$message"; + $message_esc = mysqli_real_escape_string($mysqli, $message); + } + } + + mysqli_query($mysqli, "INSERT INTO ticket_replies SET ticket_reply = '$message_esc', ticket_reply_type = '$ticket_reply_type', ticket_reply_time_worked = '00:00:00', ticket_reply_by = $ticket_reply_contact, ticket_reply_ticket_id = $ticket_id"); + $reply_id = mysqli_insert_id($mysqli); + + mkdirMissing('uploads/tickets/'); + foreach ($attachments as $attachment) { + $att_name = $attachment->getFilename(); + $att_extarr = explode('.', $att_name); + $att_extension = strtolower(end($att_extarr)); + + if (in_array($att_extension, $allowed_extensions)) { + $att_saved_filename = md5(uniqid(rand(), true)) . '.' . $att_extension; + $att_saved_path = "uploads/tickets/" . $ticket_id . "/" . $att_saved_filename; + file_put_contents($att_saved_path, $attachment->getContent()); + + $ticket_attachment_name = sanitizeInput($att_name); + $ticket_attachment_reference_name = sanitizeInput($att_saved_filename); + + $ticket_attachment_name_esc = mysqli_real_escape_string($mysqli, $ticket_attachment_name); + $ticket_attachment_reference_name_esc = mysqli_real_escape_string($mysqli, $ticket_attachment_reference_name); + mysqli_query($mysqli, "INSERT INTO ticket_attachments SET ticket_attachment_name = '$ticket_attachment_name_esc', ticket_attachment_reference_name = '$ticket_attachment_reference_name_esc', ticket_attachment_reply_id = $reply_id, ticket_attachment_ticket_id = $ticket_id"); + } else { + $ticket_attachment_name_esc = mysqli_real_escape_string($mysqli, $att_name); + logAction("Ticket", "Edit", "Email parser: Blocked attachment $ticket_attachment_name_esc from Client contact $from_email_esc for ticket $config_ticket_prefix$ticket_number_esc", $client_id, $ticket_id); + } + } + + $ticket_assigned_to_sql = mysqli_query($mysqli, "SELECT ticket_assigned_to FROM tickets WHERE ticket_id = $ticket_id LIMIT 1"); + + if ($ticket_assigned_to_sql) { + $row = mysqli_fetch_array($ticket_assigned_to_sql); + $ticket_assigned_to = intval($row['ticket_assigned_to']); + + if ($ticket_assigned_to) { + $tech_sql = mysqli_query($mysqli, "SELECT user_email, user_name FROM users WHERE user_id = $ticket_assigned_to LIMIT 1"); + $tech_row = mysqli_fetch_array($tech_sql); + $tech_email = sanitizeInput($tech_row['user_email']); + $tech_name = sanitizeInput($tech_row['user_name']); + + $email_subject = "$config_app_name - Ticket updated - [$config_ticket_prefix$ticket_number] $ticket_subject"; + $email_body = "Hello $tech_name,

A new reply has been added to the below ticket, check ITFlow for full details.

Client: $client_name
Ticket: $config_ticket_prefix$ticket_number
Subject: $ticket_subject

https://$config_base_url/ticket.php?ticket_id=$ticket_id"; + + $data = [ + [ + 'from' => $config_ticket_from_email, + 'from_name' => $config_ticket_from_name, + 'recipient' => $tech_email, + 'recipient_name' => $tech_name, + 'subject' => mysqli_real_escape_string($mysqli, $email_subject), + 'body' => mysqli_real_escape_string($mysqli, $email_body) + ] + ]; + + addToMailQueue($mysqli, $data); + } + } + + mysqli_query($mysqli, "UPDATE tickets SET ticket_status = 2, ticket_resolved_at = NULL WHERE ticket_id = $ticket_id AND ticket_client_id = $client_id LIMIT 1"); + + logAction("Ticket", "Edit", "Email parser: Client contact $from_email_esc updated ticket $config_ticket_prefix$ticket_number_esc ($subject)", $client_id, $ticket_id); + + customAction('ticket_reply_client', $ticket_id); + + return true; + + } else { + return false; + } +} + +// Function to create a folder in the mailbox if it doesn't exist +function createMailboxFolder($imap, $mailbox, $folderName) { + $folders = imap_list($imap, $mailbox, '*'); + $folderExists = false; + if ($folders !== false) { + foreach ($folders as $folder) { + $folder = str_replace($mailbox, '', $folder); + if ($folder == $folderName) { + $folderExists = true; + break; + } + } + } + if (!$folderExists) { + imap_createmailbox($imap, $mailbox . imap_utf7_encode($folderName)); + imap_subscribe($imap, $mailbox . $folderName); + } +} + +// Initialize IMAP connection +$validate_cert = true; // or false based on your configuration + +$imap_encryption = $config_imap_encryption; // e.g., 'ssl', 'tls', or '' (empty string) for none + +// Start building the mailbox string +$mailbox = '{' . $config_imap_host . ':' . $config_imap_port; + +// Only add the encryption part if $imap_encryption is not empty +if (!empty($imap_encryption)) { + $mailbox .= '/' . $imap_encryption; +} + +// Add the certificate validation part +if ($validate_cert) { + $mailbox .= '/validate-cert'; +} else { + $mailbox .= '/novalidate-cert'; +} + +$mailbox .= '}'; + +// Append 'INBOX' to specify the mailbox folder +$inbox_mailbox = $mailbox . 'INBOX'; + +// Open the IMAP connection +$imap = imap_open($inbox_mailbox, $config_imap_username, $config_imap_password); + +if ($imap === false) { + echo "Error connecting to IMAP server: " . imap_last_error(); + exit; +} + +// Create the "ITFlow" mailbox folder if it doesn't exist +createMailboxFolder($imap, $mailbox, 'ITFlow'); + +// Search for unseen messages and get UIDs +$emails = imap_search($imap, 'UNSEEN', SE_UID); + +// Set Processed and Unprocessed Email count to 0 +$processed_count = 0; +$unprocessed_count = 0; + +if ($emails !== false) { + foreach ($emails as $email_uid) { + $email_processed = false; + + // Save original message + mkdirMissing('uploads/tmp/'); + $original_message_file = "processed-eml-" . randomString(200) . ".eml"; + + $raw_message = imap_fetchheader($imap, $email_uid, FT_UID) . imap_body($imap, $email_uid, FT_UID); + file_put_contents("uploads/tmp/{$original_message_file}", $raw_message); + + // Parse the message using php-mime-mail-parser + $parser = new \PhpMimeMailParser\Parser(); + $parser->setText($raw_message); + + // Get from address + $from_addresses = $parser->getAddresses('from'); + $from_email = sanitizeInput($from_addresses[0]['address'] ?? 'itflow-guest@example.com'); + $from_name = sanitizeInput($from_addresses[0]['display'] ?? 'Unknown'); + + $from_domain = explode("@", $from_email); + $from_domain = sanitizeInput(end($from_domain)); + + // Get subject + $subject = sanitizeInput($parser->getHeader('subject') ?? 'No Subject'); + + // Get date + $date = sanitizeInput($parser->getHeader('date') ?? date('Y-m-d H:i:s')); + + // Get message body + $message_body_html = $parser->getMessageBody('html'); + $message_body_text = $parser->getMessageBody('text'); + $message_body = $message_body_html ?: nl2br(htmlspecialchars($message_body_text)); + + // Handle inline images + $attachments = $parser->getAttachments(); + $inline_attachments = []; + foreach ($attachments as $attachment) { + if ($attachment->getContentDisposition() === 'inline' && $attachment->getContentID()) { + $cid = trim($attachment->getContentID(), '<>'); + $data = base64_encode($attachment->getContent()); + $mime = $attachment->getContentType(); + $dataUri = "data:$mime;base64,$data"; + $message_body = str_replace("cid:$cid", $dataUri, $message_body); + } else { + $inline_attachments[] = $attachment; + } + } + $attachments = $inline_attachments; + + // Process the email + if (preg_match("/\[$config_ticket_prefix(\d+)\]/", $subject, $ticket_number_matches)) { + $ticket_number = intval($ticket_number_matches[1]); + + if (addReply($from_email, $date, $subject, $ticket_number, $message_body, $attachments)) { + $email_processed = true; + } + } else { + // Check if the sender is a known contact + $from_email_esc = mysqli_real_escape_string($mysqli, $from_email); + $any_contact_sql = mysqli_query($mysqli, "SELECT * FROM contacts WHERE contact_email = '$from_email_esc' LIMIT 1"); + $row = mysqli_fetch_array($any_contact_sql); + + if ($row) { + $contact_name = sanitizeInput($row['contact_name']); + $contact_id = intval($row['contact_id']); + $contact_email = sanitizeInput($row['contact_email']); + $client_id = intval($row['contact_client_id']); + + if (addTicket($contact_id, $contact_name, $contact_email, $client_id, $date, $subject, $message_body, $attachments, $original_message_file)) { + $email_processed = true; + } + } else { + // Check if the domain is associated with a client + $from_domain_esc = mysqli_real_escape_string($mysqli, $from_domain); + $domain_sql = mysqli_query($mysqli, "SELECT * FROM domains WHERE domain_name = '$from_domain_esc' LIMIT 1"); + $row = mysqli_fetch_assoc($domain_sql); + + if ($row && $from_domain == $row['domain_name']) { + $client_id = intval($row['domain_client_id']); + + // Create a new contact + $contact_name = $from_name; + $contact_email = $from_email; + mysqli_query($mysqli, "INSERT INTO contacts SET contact_name = '".mysqli_real_escape_string($mysqli, $contact_name)."', contact_email = '".mysqli_real_escape_string($mysqli, $contact_email)."', contact_notes = 'Added automatically via email parsing.', contact_client_id = $client_id"); + $contact_id = mysqli_insert_id($mysqli); + + // Logging + logAction("Contact", "Create", "Email parser: created contact " . mysqli_real_escape_string($mysqli, $contact_name) . "", $client_id, $contact_id); + customAction('contact_create', $contact_id); + + if (addTicket($contact_id, $contact_name, $contact_email, $client_id, $date, $subject, $message_body, $attachments, $original_message_file)) { + $email_processed = true; + } + } elseif ($config_ticket_email_parse_unknown_senders) { + // Parse even if the sender is unknown + $bad_from_pattern = "/daemon|postmaster/i"; + if (!(preg_match($bad_from_pattern, $from_email))) { + if (addTicket(0, $from_name, $from_email, 0, $date, $subject, $message_body, $attachments, $original_message_file)) { + $email_processed = true; + } + } + } + } + } + + if ($email_processed) { + // Mark the message as seen + imap_setflag_full($imap, $email_uid, "\\Seen", ST_UID); + // Move the message to the 'ITFlow' folder + imap_mail_move($imap, $email_uid, 'ITFlow', CP_UID); + // Get a Processed Email Count + $processed_count++; + } else { + // Flag the message for manual review without marking it as read + imap_setflag_full($imap, $email_uid, "\\Flagged", ST_UID); + // Clear the Seen flag to ensure the email remains unread + imap_clearflag_full($imap, $email_uid, "\\Seen", ST_UID); + // Get an Unprocessed email count + $unprocessed_count++; + } + + // Delete the temporary message file + if (file_exists("uploads/tmp/{$original_message_file}")) { + unlink("uploads/tmp/{$original_message_file}"); + } + } +} + +// Expunge deleted mails +imap_expunge($imap); + +// Close the IMAP connection +imap_close($imap); + +// Calculate the total execution time -uncomment the code below to get exec time +$script_end_time = microtime(true); +$execution_time = $script_end_time - $script_start_time; +$execution_time_formatted = number_format($execution_time, 2); + +// Insert a log entry into the logs table +$processed_info = "Processed: $processed_count email(s), Unprocessed: $unprocessed_count email(s)"; +// Remove Comment below for Troubleshooting + +//logAction("Cron-Email-Parser", "Execution", "Cron Email Parser executed in $execution_time_formatted seconds. $processed_info"); + +// END Calculate execution time + +// Remove the lock file +unlink($lock_file_path); + +// DEBUG +echo "\nLock File Path: $lock_file_path\n"; +if (file_exists($lock_file_path)) { + echo "\nLock is present\n\n"; +} +echo "Processed Emails into tickets: $processed_count\n"; +echo "Unprocessed Emails: $unprocessed_count\n"; + +?> From bf53d5b0fe646e1fdb23dd814add2f7273b034f1 Mon Sep 17 00:00:00 2001 From: wrongecho Date: Tue, 31 Dec 2024 11:49:48 +0000 Subject: [PATCH 003/150] Also move setup and update cli to scripts folder for better organisation --- scripts/setup_cli.php | 389 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 389 insertions(+) create mode 100644 scripts/setup_cli.php diff --git a/scripts/setup_cli.php b/scripts/setup_cli.php new file mode 100644 index 00000000..cf42996c --- /dev/null +++ b/scripts/setup_cli.php @@ -0,0 +1,389 @@ +#!/usr/bin/env php + 'Database host', + 'username' => 'Database username', + 'password' => 'Database password', + 'database' => 'Database name', + 'base-url' => 'Base URL (without protocol, e.g. example.com/itflow)', + 'locale' => 'Locale (e.g. en_US)', + 'timezone' => 'Timezone (e.g. UTC)', + 'currency' => 'Currency code (e.g. USD)', + 'company-name' => 'Company name', + 'country' => 'Company country (e.g. United States)', + 'user-name' => 'Admin user full name', + 'user-email' => 'Admin user email', + 'user-password'=> 'Admin user password (min 8 chars)' +]; + +// Additional optional arguments +// address, city, state, zip, phone, company-email, website +// These are optional and don't need error checks if missing. +$optional_args = [ + 'address' => 'Company address (optional)', + 'city' => 'Company city (optional)', + 'state' => 'Company state (optional)', + 'zip' => 'Company postal code (optional)', + 'phone' => 'Company phone (optional)', + 'company-email' => 'Company email (optional)', + 'website' => 'Company website (optional)' +]; + +// Parse command line options +$shortopts = ""; +$longopts = [ + "help", + "host:", + "username:", + "password:", + "database:", + "base-url:", + "locale:", + "timezone:", + "currency:", + "company-name:", + "country:", + "address::", + "city::", + "state::", + "zip::", + "phone::", + "company-email::", + "website::", + "user-name:", + "user-email:", + "user-password:", + "non-interactive" +]; + +$options = getopt($shortopts, $longopts); + +// If --help is set, print usage and exit +if (isset($options['help'])) { + echo "ITFlow CLI Setup Script\n\n"; + echo "Usage:\n"; + echo " php setup_cli.php [options]\n\n"; + echo "Options:\n"; + foreach ($required_args as $arg => $desc) { + echo " --$arg\t$desc (required)\n"; + } + foreach ($optional_args as $arg => $desc) { + echo " --$arg\t$desc\n"; + } + echo " --non-interactive\tRun in non-interactive mode (fail if required args missing)\n"; + echo " --help\t\tShow this help message\n\n"; + echo "If running interactively (without --non-interactive), any missing required arguments will be prompted.\n"; + echo "If running non-interactively, all required arguments must be provided.\n\n"; + exit(0); +} + +if (file_exists("config.php")) { + include "config.php"; +} + +include "functions.php"; +include "database_version.php"; + +if (!isset($config_enable_setup)) { + $config_enable_setup = 1; +} + +if ($config_enable_setup == 0) { + echo "Setup is disabled. Please delete or modify config.php if you need to re-run the setup.\n"; + exit; +} + +$errorLog = ini_get('error_log') ?: "/var/log/apache2/error.log"; + +$timezones = DateTimeZone::listIdentifiers(); + +function prompt($message) { + echo $message . ": "; + return trim(fgets(STDIN)); +} + +$non_interactive = isset($options['non-interactive']); + +function getOptionOrPrompt($key, $promptMessage, $required = false, $default = '', $optionsGlobal = []) { + global $options, $non_interactive; + if (isset($options[$key])) { + return $options[$key]; + } else { + if ($non_interactive && $required) { + die("Missing required argument: --$key\n"); + } + $val = prompt($promptMessage . (strlen($default) ? " [$default]" : '')); + if (empty($val) && !empty($default)) { + $val = $default; + } + if ($required && empty($val)) { + die("Error: $promptMessage is required.\n"); + } + return $val; + } +} + +// Start setup +echo "Welcome to the ITFlow CLI Setup.\n"; + +// If config exists, abort +if (file_exists('config.php')) { + echo "Database is already configured in config.php.\n"; + echo "To re-run the setup, remove config.php and run this script again.\n"; + exit; +} + +// If non-interactive is set, ensure all required arguments are present +if ($non_interactive) { + foreach (array_keys($required_args) as $arg) { + if (!isset($options[$arg])) { + die("Missing required argument: --$arg\n"); + } + } +} + +// Database Setup +echo "\n=== Database Setup ===\n"; +$database = getOptionOrPrompt('database', "Enter the database name", true); +$host = getOptionOrPrompt('host', "Enter the database host", true, 'localhost'); +if (empty($host)) $host = "localhost"; +$username = getOptionOrPrompt('username', "Enter the database username", true); +$password = getOptionOrPrompt('password', "Enter the database password", true); + +// Base URL +$base_url = getOptionOrPrompt('base-url', "Enter the base URL (e.g. example.com/itflow)", true); +$base_url = rtrim($base_url, '/'); + +// Locale, Timezone, Currency +echo "\n=== Localization ===\n"; +$locale = getOptionOrPrompt('locale', "Enter the locale (e.g. en_US)", true); +$timezone = getOptionOrPrompt('timezone', "Enter the timezone (e.g. UTC or America/New_York)", true); +$currency_code = getOptionOrPrompt('currency', "Enter the currency code (e.g. USD)", true); + +// Company Details +echo "\n=== Company Details ===\n"; +$company_name = getOptionOrPrompt('company-name', "Company Name", true); +$country = getOptionOrPrompt('country', "Country (e.g. United States)", true); +$address = getOptionOrPrompt('address', "Address (optional)", false); +$city = getOptionOrPrompt('city', "City (optional)", false); +$state = getOptionOrPrompt('state', "State/Province (optional)", false); +$zip = getOptionOrPrompt('zip', "Postal Code (optional)", false); +$phone = getOptionOrPrompt('phone', "Phone (optional)", false); +$phone = preg_replace("/[^0-9]/", '', $phone); +$company_email = getOptionOrPrompt('company-email', "Company Email (optional)", false); +$website = getOptionOrPrompt('website', "Website (optional)", false); + +// User Setup +echo "\n=== Create First User ===\n"; +$user_name = getOptionOrPrompt('user-name', "Full Name", true); +$user_email = getOptionOrPrompt('user-email', "Email Address", true); +while (!filter_var($user_email, FILTER_VALIDATE_EMAIL)) { + echo "Invalid email.\n"; + if ($non_interactive) { + die("Invalid email address: $user_email\n"); + } + $user_email = prompt("Email Address"); +} +$user_password_plain = getOptionOrPrompt('user-password', "Password (at least 8 chars)", true); +if (strlen($user_password_plain) < 8) { + if ($non_interactive) { + die("Password must be at least 8 characters.\n"); + } + while (strlen($user_password_plain) < 8) { + echo "Password too short. Try again.\n"; + $user_password_plain = prompt("Password"); + } +} + +if (!preg_match('/^[a-zA-Z0-9.\-\/]+$/', $host)) { + die("Invalid host format.\n"); +} + +// Test Database +$conn = @mysqli_connect($host, $username, $password, $database); +if (!$conn) { + die("Database connection failed - " . mysqli_connect_error() . "\n"); +} + +$installation_id = randomString(32); + +$new_config = " "$installation_id", + 'company_name' => "$company_name_db", + 'website' => "$website_db", + 'city' => "$city_db", + 'state' => "$state_db", + 'country' => "$country_db", + 'currency' => "$currency_db", + 'comments' => "$comments", + 'collection_method' => 1 + ]); + + $opts = ['http' => + [ + 'method' => 'POST', + 'header' => 'Content-type: application/x-www-form-urlencoded', + 'content' => $postdata + ] + ]; + + $context = stream_context_create($opts); + $result = @file_get_contents('https://telemetry.itflow.org', false, $context); + echo "Telemetry response: $result\n"; + } +} + +// finalize config +$myfile = fopen("config.php", "a"); +$txt = "\$config_enable_setup = 0;\n\n"; +fwrite($myfile, $txt); +fclose($myfile); + +echo "\nSetup complete!\n"; +echo "You can now log in with the user you created at: https://$base_url/login.php\n"; + +exit(0); From c7b0f1222f86d69619b730037de5565f469198f9 Mon Sep 17 00:00:00 2001 From: wrongecho <32306651+wrongecho@users.noreply.github.com> Date: Tue, 31 Dec 2024 16:10:29 +0000 Subject: [PATCH 004/150] Update test.md --- test.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test.md b/test.md index 3a407940..7450b40a 100644 --- a/test.md +++ b/test.md @@ -1 +1,2 @@ -Just a test \ No newline at end of file +Just a test +Another test. From 3b0d24f5a5281828940dd3e2df34ec5348d75d82 Mon Sep 17 00:00:00 2001 From: wrongecho <32306651+wrongecho@users.noreply.github.com> Date: Tue, 31 Dec 2024 16:26:42 +0000 Subject: [PATCH 005/150] Delete test.md --- test.md | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 test.md diff --git a/test.md b/test.md deleted file mode 100644 index 7450b40a..00000000 --- a/test.md +++ /dev/null @@ -1,2 +0,0 @@ -Just a test -Another test. From db6d2fb534c8d57dccb015c260fb67a068c37a78 Mon Sep 17 00:00:00 2001 From: wrongecho Date: Thu, 2 Jan 2025 20:59:05 +0000 Subject: [PATCH 006/150] Move cron scripts Move cron scripts to their own subfolder. --- scripts/update_cli.php | 130 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 scripts/update_cli.php diff --git a/scripts/update_cli.php b/scripts/update_cli.php new file mode 100644 index 00000000..06dff0a6 --- /dev/null +++ b/scripts/update_cli.php @@ -0,0 +1,130 @@ +#!/usr/bin/env php +&1", $output, $return_var); + exec("git reset --hard origin/master 2>&1", $output2, $return_var2); + echo implode("\n", $output) . "\n" . implode("\n", $output2) . "\n"; + } else { + // Perform a standard update (git pull) + exec("git pull 2>&1", $output, $return_var); + + // Check if the repository is already up to date + if (strpos(implode("\n", $output), 'Already up to date.') === false) { + echo implode("\n", $output) . "\n"; + echo "Update successful\n"; + } else { + // If already up-to-date, don't show the update success message + echo implode("\n", $output) . "\n"; + } + } +} + +// If "update_db" is requested +if (isset($options['update_db'])) { + require_once('database_version.php'); + + $latest_db_version = LATEST_DATABASE_VERSION; + + // Fetch the current version from the database + $result = mysqli_query($mysqli, "SELECT config_current_database_version FROM settings LIMIT 1"); + $row = mysqli_fetch_assoc($result); + DEFINE("CURRENT_DATABASE_VERSION", $row['config_current_database_version']); + $old_db_version = $row['config_current_database_version']; + + // Now include the update logic + require_once('database_updates.php'); + + // After database_updates.php has done its job, fetch the updated current DB version again + $result = mysqli_query($mysqli, "SELECT config_current_database_version FROM settings LIMIT 1"); + $row = mysqli_fetch_assoc($result); + $new_db_version = $row['config_current_database_version']; + + if ($old_db_version !== $latest_db_version) { + echo "Database updated from version $old_db_version to $new_db_version.\n"; + echo "The latest database version is $latest_db_version.\n"; + } else { + echo "Database is already at the latest version ($latest_db_version). No updates were applied.\n"; + } +} From f39b0eb3679ee81dcbf0e381afc1ca0a0ec595fe Mon Sep 17 00:00:00 2001 From: wrongecho Date: Thu, 2 Jan 2025 21:05:03 +0000 Subject: [PATCH 007/150] Tidying per sonar recommendations --- scripts/cron.php | 9 +++++---- scripts/cron_ticket_email_parser.php | 2 -- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/scripts/cron.php b/scripts/cron.php index 543c11ad..f149d60b 100644 --- a/scripts/cron.php +++ b/scripts/cron.php @@ -162,7 +162,7 @@ if ($config_enable_alert_domain_expire == 1) { $sql = mysqli_query( $mysqli, "SELECT * FROM domains - LEFT JOIN clients ON domain_client_id = client_id + LEFT JOIN clients ON domain_client_id = client_id WHERE domain_expire IS NOT NULL AND domain_expire = CURDATE() + INTERVAL $day DAY" ); @@ -192,7 +192,7 @@ foreach ($certificateAlertArray as $day) { $sql = mysqli_query( $mysqli, "SELECT * FROM certificates - LEFT JOIN clients ON certificate_client_id = client_id + LEFT JOIN clients ON certificate_client_id = client_id WHERE certificate_expire = CURDATE() + INTERVAL $day DAY" ); @@ -397,7 +397,7 @@ if (mysqli_num_rows($sql_scheduled_tickets) > 0) { $sql_resolved_tickets_to_close = mysqli_query( $mysqli, - "SELECT * FROM tickets + "SELECT * FROM tickets WHERE ticket_status = 4 AND ticket_updated_at < NOW() - INTERVAL $config_ticket_autoclose_hours HOUR" ); @@ -682,7 +682,8 @@ while ($row = mysqli_fetch_array($sql_recurring)) { mysqli_query($mysqli,"INSERT INTO history SET history_status = 'Paid', history_description = 'Payment added via Auto Pay', history_invoice_id = $new_invoice_id"); // Logging - logAction("Invoice", "Payment", "Auto Payment amount of " . numfmt_format_currency($currency_format, $recurring_amount, $recurring_payment_currency_code) . " added to invoice $invoice_prefix$invoice_number", $client_id, $new_invoice_id); + logAction("Invoice", "Payment", "Auto Payment amount of " . numfmt_format_currency($currency_format, $recurring_amount, $recurring_payment_currency_code) . " added to invoice $invoice_prefix$invoice_number", $client_id, $new_invoice_id); + } //End Auto Payment } //End Recurring Invoices Loop diff --git a/scripts/cron_ticket_email_parser.php b/scripts/cron_ticket_email_parser.php index e8b3e637..22b21d96 100644 --- a/scripts/cron_ticket_email_parser.php +++ b/scripts/cron_ticket_email_parser.php @@ -556,5 +556,3 @@ if (file_exists($lock_file_path)) { } echo "Processed Emails into tickets: $processed_count\n"; echo "Unprocessed Emails: $unprocessed_count\n"; - -?> From 2d403415d4bad6469045cce1ab438514e279535b Mon Sep 17 00:00:00 2001 From: wrongecho Date: Thu, 2 Jan 2025 21:09:27 +0000 Subject: [PATCH 008/150] Tidying per sonar recommendations --- scripts/cron.php | 2 +- scripts/update_cli.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/cron.php b/scripts/cron.php index f149d60b..6af84a02 100644 --- a/scripts/cron.php +++ b/scripts/cron.php @@ -519,7 +519,7 @@ if ($config_send_invoice_reminders == 1) { $sql_recurring = mysqli_query($mysqli, "SELECT * FROM recurring LEFT JOIN recurring_payments ON recurring_id = recurring_payment_recurring_invoice_id LEFT JOIN clients ON client_id = recurring_client_id - WHERE recurring_next_date = CURDATE() + WHERE recurring_next_date = CURDATE() AND recurring_status = 1 "); diff --git a/scripts/update_cli.php b/scripts/update_cli.php index 06dff0a6..42351838 100644 --- a/scripts/update_cli.php +++ b/scripts/update_cli.php @@ -20,7 +20,7 @@ if ($currentUser !== $fileOwner) { exit(1); } -require_once 'config.php'; +require_once "config.php"; require_once "functions.php"; // A function to print the help message so that we don't duplicate it @@ -103,7 +103,7 @@ if (isset($options['update']) || isset($options['force_update'])) { // If "update_db" is requested if (isset($options['update_db'])) { - require_once('database_version.php'); + require_once "database_version.php"; $latest_db_version = LATEST_DATABASE_VERSION; @@ -114,7 +114,7 @@ if (isset($options['update_db'])) { $old_db_version = $row['config_current_database_version']; // Now include the update logic - require_once('database_updates.php'); + require_once "database_updates.php"; // After database_updates.php has done its job, fetch the updated current DB version again $result = mysqli_query($mysqli, "SELECT config_current_database_version FROM settings LIMIT 1"); From ee49c2c5c64b22aa65944ca4dbd14bbf65d0f5e4 Mon Sep 17 00:00:00 2001 From: wrongecho <32306651+wrongecho@users.noreply.github.com> Date: Thu, 2 Jan 2025 21:14:15 +0000 Subject: [PATCH 009/150] Update CHANGELOG.md wip --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e07100b..e2519310 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,8 +3,8 @@ All notable changes to ITFlow will be documented in this file. ## 25.1 -- Lots yet to come... +- Moved cron/cli scripts to scripts subfolder - Old scripts remain in the root for now, but please update your cron configurations! ## 24.12 -- First introduced versioned releases! \ No newline at end of file +- First introduced versioned releases! From 50371558c6d3ce9fc668ea4e5fec85777b20e67c Mon Sep 17 00:00:00 2001 From: wrongecho Date: Thu, 2 Jan 2025 21:27:14 +0000 Subject: [PATCH 010/150] Adjust cron/cli scripts in subdir to load required scripts from parent --- scripts/cron.php | 6 +++--- scripts/cron_certificate_refresher.php | 6 +++--- scripts/cron_domain_refresher.php | 6 +++--- scripts/cron_mail_queue.php | 6 +++--- scripts/cron_ticket_email_parser.php | 26 +++++++++++++------------- scripts/setup_cli.php | 8 ++++---- scripts/update_cli.php | 8 ++++---- 7 files changed, 33 insertions(+), 33 deletions(-) diff --git a/scripts/cron.php b/scripts/cron.php index 6af84a02..46e00a47 100644 --- a/scripts/cron.php +++ b/scripts/cron.php @@ -3,12 +3,12 @@ // Set working directory to the directory this cron script lives at. chdir(dirname(__FILE__)); -require_once "config.php"; +require_once "../config.php"; // Set Timezone -require_once "inc_set_timezone.php"; +require_once "../inc_set_timezone.php"; -require_once "functions.php"; +require_once "../functions.php"; $sql_companies = mysqli_query($mysqli, "SELECT * FROM companies, settings WHERE companies.company_id = settings.company_id AND companies.company_id = 1"); diff --git a/scripts/cron_certificate_refresher.php b/scripts/cron_certificate_refresher.php index e7ffb1c4..739a41de 100644 --- a/scripts/cron_certificate_refresher.php +++ b/scripts/cron_certificate_refresher.php @@ -1,11 +1,11 @@ Date: Thu, 2 Jan 2025 21:30:18 +0000 Subject: [PATCH 011/150] Sonar recommendations --- scripts/setup_cli.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/setup_cli.php b/scripts/setup_cli.php index ef03df2b..df996f66 100644 --- a/scripts/setup_cli.php +++ b/scripts/setup_cli.php @@ -92,11 +92,11 @@ if (isset($options['help'])) { } if (file_exists("../config.php")) { - include "../config.php"; + include_once "../config.php"; } -include "../functions.php"; -include "../database_version.php"; +require_once "../functions.php"; +require_once "../database_version.php"; if (!isset($config_enable_setup)) { $config_enable_setup = 1; From a529eca414477feaba7168a6ecab58bb0c27a527 Mon Sep 17 00:00:00 2001 From: wrongecho Date: Thu, 2 Jan 2025 21:37:10 +0000 Subject: [PATCH 012/150] db.sql also needs to be called from the parent directory --- scripts/setup_cli.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/setup_cli.php b/scripts/setup_cli.php index df996f66..ba69e1f1 100644 --- a/scripts/setup_cli.php +++ b/scripts/setup_cli.php @@ -245,7 +245,7 @@ include "config.php"; // Import DB Schema echo "Importing database schema...\n"; -$filename = 'db.sql'; +$filename = '../db.sql'; if (!file_exists($filename)) { die("db.sql file not found.\n"); } From b0a960547c9be85804d20f2775e7820879b2e4a8 Mon Sep 17 00:00:00 2001 From: wrongecho Date: Thu, 2 Jan 2025 21:43:23 +0000 Subject: [PATCH 013/150] config.php has to be written to parent dir --- scripts/setup_cli.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/setup_cli.php b/scripts/setup_cli.php index ba69e1f1..858ebc92 100644 --- a/scripts/setup_cli.php +++ b/scripts/setup_cli.php @@ -378,7 +378,7 @@ if (!$non_interactive) { } // finalize config -$myfile = fopen("config.php", "a"); +$myfile = fopen("../config.php", "a"); $txt = "\$config_enable_setup = 0;\n\n"; fwrite($myfile, $txt); fclose($myfile); From ff4f8a9a183d418f2c9d2df27d1c0bbb4d4d8d61 Mon Sep 17 00:00:00 2001 From: wrongecho Date: Thu, 2 Jan 2025 21:48:02 +0000 Subject: [PATCH 014/150] uploads have to be written to parent dir --- scripts/cron_ticket_email_parser.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/scripts/cron_ticket_email_parser.php b/scripts/cron_ticket_email_parser.php index d361fb9a..fbc805ef 100644 --- a/scripts/cron_ticket_email_parser.php +++ b/scripts/cron_ticket_email_parser.php @@ -117,11 +117,11 @@ function addTicket($contact_id, $contact_name, $contact_email, $client_id, $date // Logging logAction("Ticket", "Create", "Email parser: Client contact $contact_email_esc created ticket $ticket_prefix_esc$ticket_number ($subject) ($id)", $client_id, $id); - mkdirMissing('uploads/tickets/'); - $att_dir = "uploads/tickets/" . $id . "/"; + mkdirMissing('../uploads/tickets/'); + $att_dir = "../uploads/tickets/" . $id . "/"; mkdirMissing($att_dir); - rename("uploads/tmp/{$original_message_file}", "{$att_dir}/{$original_message_file}"); + rename("../uploads/tmp/{$original_message_file}", "{$att_dir}/{$original_message_file}"); $original_message_file_esc = mysqli_real_escape_string($mysqli, $original_message_file); mysqli_query($mysqli, "INSERT INTO ticket_attachments SET ticket_attachment_name = 'Original-parsed-email.eml', ticket_attachment_reference_name = '$original_message_file_esc', ticket_attachment_ticket_id = $id"); @@ -270,7 +270,7 @@ function addReply($from_email, $date, $subject, $ticket_number, $message, $attac mysqli_query($mysqli, "INSERT INTO ticket_replies SET ticket_reply = '$message_esc', ticket_reply_type = '$ticket_reply_type', ticket_reply_time_worked = '00:00:00', ticket_reply_by = $ticket_reply_contact, ticket_reply_ticket_id = $ticket_id"); $reply_id = mysqli_insert_id($mysqli); - mkdirMissing('uploads/tickets/'); + mkdirMissing('../uploads/tickets/'); foreach ($attachments as $attachment) { $att_name = $attachment->getFilename(); $att_extarr = explode('.', $att_name); @@ -278,7 +278,7 @@ function addReply($from_email, $date, $subject, $ticket_number, $message, $attac if (in_array($att_extension, $allowed_extensions)) { $att_saved_filename = md5(uniqid(rand(), true)) . '.' . $att_extension; - $att_saved_path = "uploads/tickets/" . $ticket_id . "/" . $att_saved_filename; + $att_saved_path = "../uploads/tickets/" . $ticket_id . "/" . $att_saved_filename; file_put_contents($att_saved_path, $attachment->getContent()); $ticket_attachment_name = sanitizeInput($att_name); @@ -403,11 +403,11 @@ if ($emails !== false) { $email_processed = false; // Save original message - mkdirMissing('uploads/tmp/'); + mkdirMissing('../uploads/tmp/'); $original_message_file = "processed-eml-" . randomString(200) . ".eml"; $raw_message = imap_fetchheader($imap, $email_uid, FT_UID) . imap_body($imap, $email_uid, FT_UID); - file_put_contents("uploads/tmp/{$original_message_file}", $raw_message); + file_put_contents("../uploads/tmp/{$original_message_file}", $raw_message); // Parse the message using php-mime-mail-parser $parser = new \PhpMimeMailParser\Parser(); @@ -521,8 +521,8 @@ if ($emails !== false) { } // Delete the temporary message file - if (file_exists("uploads/tmp/{$original_message_file}")) { - unlink("uploads/tmp/{$original_message_file}"); + if (file_exists("../uploads/tmp/{$original_message_file}")) { + unlink("../uploads/tmp/{$original_message_file}"); } } } From 43ccf8a026fb6b359de00a21685fb7348d0026b7 Mon Sep 17 00:00:00 2001 From: wrongecho Date: Thu, 2 Jan 2025 21:55:25 +0000 Subject: [PATCH 015/150] config.php has to be written to parent dir --- scripts/setup_cli.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/setup_cli.php b/scripts/setup_cli.php index 858ebc92..38f0f2eb 100644 --- a/scripts/setup_cli.php +++ b/scripts/setup_cli.php @@ -141,7 +141,7 @@ function getOptionOrPrompt($key, $promptMessage, $required = false, $default = ' echo "Welcome to the ITFlow CLI Setup.\n"; // If config exists, abort -if (file_exists('config.php')) { +if (file_exists('../config.php')) { echo "Database is already configured in config.php.\n"; echo "To re-run the setup, remove config.php and run this script again.\n"; exit; @@ -233,15 +233,15 @@ $new_config .= "\$config_https_only = TRUE;\n"; $new_config .= "\$repo_branch = 'master';\n"; $new_config .= "\$installation_id = '$installation_id';\n"; -if (file_put_contents("config.php", $new_config) === false) { +if (file_put_contents("../config.php", $new_config) === false) { die("Failed to write config.php. Check file permissions.\n"); } -if (!file_exists('config.php')) { +if (!file_exists('../config.php')) { die("config.php does not exist after write attempt.\n"); } -include "config.php"; +require "../config.php"; // Import DB Schema echo "Importing database schema...\n"; From afc03634d659416f0b95a2011202412c547656e6 Mon Sep 17 00:00:00 2001 From: wrongecho Date: Thu, 2 Jan 2025 22:01:01 +0000 Subject: [PATCH 016/150] Tidy old debug message --- scripts/cron_domain_refresher.php | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/scripts/cron_domain_refresher.php b/scripts/cron_domain_refresher.php index b224ec59..583cb788 100644 --- a/scripts/cron_domain_refresher.php +++ b/scripts/cron_domain_refresher.php @@ -33,16 +33,8 @@ if ( $argv[1] !== $config_cron_key ) { * REFRESH DATA * ############################################################################################################### */ -// 2023-02-20 JQ Commenting this code out as its intermitently breaking cron executions, investigating -// ERROR -// php cron.php -// PHP Fatal error: Uncaught TypeError: mysqli_fetch_array(): Argument #1 ($result) must be of type mysqli_result, bool given in cron.php:141 -// Stack trace: -//#0 cron.php(141): mysqli_fetch_array() -//#1 {main} -// thrown in cron.php on line 141 -// END ERROR -// REFRESH DOMAIN WHOIS DATA (1 a day) + +// REFRESH DOMAIN WHOIS DATA (1 a day/run) // Get the oldest updated domain (MariaDB shows NULLs first when ordering by default) $row = mysqli_fetch_array(mysqli_query($mysqli, "SELECT domain_id, domain_name, domain_expire FROM `domains` ORDER BY domain_updated_at LIMIT 1")); From cb2f6203439d16800338dddffd3cf0d92180d6ed Mon Sep 17 00:00:00 2001 From: wrongecho Date: Thu, 2 Jan 2025 22:21:02 +0000 Subject: [PATCH 017/150] Bugfix: Ticket edit modal not showing multi-client/no-client projects --- ticket_edit_modal.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ticket_edit_modal.php b/ticket_edit_modal.php index 096f571c..cfa9b121 100644 --- a/ticket_edit_modal.php +++ b/ticket_edit_modal.php @@ -261,7 +261,7 @@ From 65873eb46f641364a967cad426141284cd2b6367 Mon Sep 17 00:00:00 2001 From: wrongecho Date: Thu, 2 Jan 2025 22:22:37 +0000 Subject: [PATCH 018/150] Bugfix: Ticket edit modal not showing multi-client/no-client projects --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e2519310..2596c49a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ All notable changes to ITFlow will be documented in this file. ## 25.1 - Moved cron/cli scripts to scripts subfolder - Old scripts remain in the root for now, but please update your cron configurations! +- Bugfix: Ticket edit modal not showing multi-client/no-client projects ## 24.12 From b0d398618dcc4c361b42810fe949f8a2c0fdbc2c Mon Sep 17 00:00:00 2001 From: wrongecho Date: Thu, 2 Jan 2025 22:57:13 +0000 Subject: [PATCH 019/150] Bugfix: Asset interface DHCP vanishing Fixes a bug that removes the DHCP setting on asset interfaces when changing their network interface from the asset details page --- CHANGELOG.md | 1 + client_asset_interface_add_modal.php | 7 ++++++- client_asset_interface_edit_modal.php | 7 ++++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2596c49a..5b6e0744 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ All notable changes to ITFlow will be documented in this file. ## 25.1 - Moved cron/cli scripts to scripts subfolder - Old scripts remain in the root for now, but please update your cron configurations! - Bugfix: Ticket edit modal not showing multi-client/no-client projects +- Bugfix: Asset interface losing DHCP setting ## 24.12 diff --git a/client_asset_interface_add_modal.php b/client_asset_interface_add_modal.php index b2183a7c..66b8fdb2 100644 --- a/client_asset_interface_add_modal.php +++ b/client_asset_interface_add_modal.php @@ -35,12 +35,17 @@
- +
+
+
+ +
+
diff --git a/client_asset_interface_edit_modal.php b/client_asset_interface_edit_modal.php index 62aef022..43558448 100644 --- a/client_asset_interface_edit_modal.php +++ b/client_asset_interface_edit_modal.php @@ -35,12 +35,17 @@
- +
+
+
+ > +
+
From 3e52155d1c7e4c1df9aaffc3b623200cb2398ed9 Mon Sep 17 00:00:00 2001 From: johnnyq Date: Thu, 2 Jan 2025 21:26:29 -0500 Subject: [PATCH 020/150] Fix editing recurring expense due to bad var name --- CHANGELOG.md | 1 + post/user/expense.php | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b6e0744..82443c1b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ All notable changes to ITFlow will be documented in this file. - Moved cron/cli scripts to scripts subfolder - Old scripts remain in the root for now, but please update your cron configurations! - Bugfix: Ticket edit modal not showing multi-client/no-client projects - Bugfix: Asset interface losing DHCP setting +- Bugfix: Editing recurring expensives results in error 500 due to incorrect var name ## 24.12 diff --git a/post/user/expense.php b/post/user/expense.php index 9144bbd7..946d9827 100644 --- a/post/user/expense.php +++ b/post/user/expense.php @@ -384,14 +384,14 @@ if (isset($_POST['edit_recurring_expense'])) { $amount = floatval(str_replace(',', '', $_POST['amount'])); $account = intval($_POST['account']); $vendor = intval($_POST['vendor']); - $client = intval($_POST['client']); + $client_id = intval($_POST['client']); $category = intval($_POST['category']); $description = sanitizeInput($_POST['description']); $reference = sanitizeInput($_POST['reference']); $start_date = date('Y') . "-$month-$day"; - mysqli_query($mysqli,"UPDATE recurring_expenses SET recurring_expense_frequency = $frequency, recurring_expense_day = $day, recurring_expense_month = $month, recurring_expense_next_date = '$start_date', recurring_expense_description = '$description', recurring_expense_reference = '$reference', recurring_expense_amount = $amount, recurring_expense_currency_code = '$session_company_currency', recurring_expense_vendor_id = $vendor, recurring_expense_client_id = $client, recurring_expense_category_id = $category, recurring_expense_account_id = $account WHERE recurring_expense_id = $recurring_expense_id"); + mysqli_query($mysqli,"UPDATE recurring_expenses SET recurring_expense_frequency = $frequency, recurring_expense_day = $day, recurring_expense_month = $month, recurring_expense_next_date = '$start_date', recurring_expense_description = '$description', recurring_expense_reference = '$reference', recurring_expense_amount = $amount, recurring_expense_currency_code = '$session_company_currency', recurring_expense_vendor_id = $vendor, recurring_expense_client_id = $client_id, recurring_expense_category_id = $category, recurring_expense_account_id = $account WHERE recurring_expense_id = $recurring_expense_id"); $recurring_expense_id = mysqli_insert_id($mysqli); From bc417b7cf3110213c5649df8f2389eb4362cf6da Mon Sep 17 00:00:00 2001 From: johnnyq Date: Thu, 2 Jan 2025 21:46:40 -0500 Subject: [PATCH 021/150] Fix creating a recurring expense due to bad var name --- CHANGELOG.md | 2 +- post/user/expense.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 82443c1b..d6c1b7ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ All notable changes to ITFlow will be documented in this file. - Moved cron/cli scripts to scripts subfolder - Old scripts remain in the root for now, but please update your cron configurations! - Bugfix: Ticket edit modal not showing multi-client/no-client projects - Bugfix: Asset interface losing DHCP setting -- Bugfix: Editing recurring expensives results in error 500 due to incorrect var name +- Bugfix: Editing / creating recurring expensives results in error 500 due to incorrect var name ## 24.12 diff --git a/post/user/expense.php b/post/user/expense.php index 946d9827..96b2a5b2 100644 --- a/post/user/expense.php +++ b/post/user/expense.php @@ -355,14 +355,14 @@ if (isset($_POST['create_recurring_expense'])) { $amount = floatval(str_replace(',', '', $_POST['amount'])); $account = intval($_POST['account']); $vendor = intval($_POST['vendor']); - $client = intval($_POST['client']); + $client_id = intval($_POST['client']); $category = intval($_POST['category']); $description = sanitizeInput($_POST['description']); $reference = sanitizeInput($_POST['reference']); $start_date = date('Y') . "-$month-$day"; - mysqli_query($mysqli,"INSERT INTO recurring_expenses SET recurring_expense_frequency = $frequency, recurring_expense_day = $day, recurring_expense_month = $month, recurring_expense_next_date = '$start_date', recurring_expense_description = '$description', recurring_expense_reference = '$reference', recurring_expense_amount = $amount, recurring_expense_currency_code = '$session_company_currency', recurring_expense_vendor_id = $vendor, recurring_expense_client_id = $client, recurring_expense_category_id = $category, recurring_expense_account_id = $account"); + mysqli_query($mysqli,"INSERT INTO recurring_expenses SET recurring_expense_frequency = $frequency, recurring_expense_day = $day, recurring_expense_month = $month, recurring_expense_next_date = '$start_date', recurring_expense_description = '$description', recurring_expense_reference = '$reference', recurring_expense_amount = $amount, recurring_expense_currency_code = '$session_company_currency', recurring_expense_vendor_id = $vendor, recurring_expense_client_id = $client_id, recurring_expense_category_id = $category, recurring_expense_account_id = $account"); $recurring_expense_id = mysqli_insert_id($mysqli); From 3c697617f9463ad12830a4ca03332705ae2b1a47 Mon Sep 17 00:00:00 2001 From: wrongecho <32306651+wrongecho@users.noreply.github.com> Date: Wed, 8 Jan 2025 13:42:37 +0000 Subject: [PATCH 022/150] Update README.md Remove issues shield, as we'll be using our own system for roadmapping --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 6c1791cc..5a440e00 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,6 @@ [![Contributors][contributors-shield]][contributors-url] [![Stargazers][stars-shield]][stars-url] -[![Issues][issues-shield]][issues-url] [![Commits][commit-shield]][commit-url] [![GPL License][license-shield]][license-url] From d32e3a698f4b132e3629537b894c6cab5a9cc93b Mon Sep 17 00:00:00 2001 From: wrongecho Date: Thu, 9 Jan 2025 14:56:36 +0000 Subject: [PATCH 023/150] Stripe payments - Account selection https://tasks.dev.itflow.org/task_details.php?task_id=22 --- CHANGELOG.md | 3 ++- admin_settings_online_payment.php | 6 +++--- post/admin/admin_settings_online_payment.php | 8 +++++++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d6c1b7ee..10702d30 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,8 @@ All notable changes to ITFlow will be documented in this file. - Moved cron/cli scripts to scripts subfolder - Old scripts remain in the root for now, but please update your cron configurations! - Bugfix: Ticket edit modal not showing multi-client/no-client projects - Bugfix: Asset interface losing DHCP setting -- Bugfix: Editing / creating recurring expensives results in error 500 due to incorrect var name +- Bugfix: Editing / creating recurring expenses results in error 500 due to incorrect var name +- Stripe online payment setup now prompts you to set the income/expense account ## 24.12 diff --git a/admin_settings_online_payment.php b/admin_settings_online_payment.php index 01ea1cc8..edd3efa4 100644 --- a/admin_settings_online_payment.php +++ b/admin_settings_online_payment.php @@ -25,7 +25,7 @@ require_once "inc_all_admin.php";
">
- +
@@ -35,7 +35,7 @@ require_once "inc_all_admin.php";
- +
@@ -45,7 +45,7 @@ require_once "inc_all_admin.php";
- +
diff --git a/post/admin/admin_settings_online_payment.php b/post/admin/admin_settings_online_payment.php index 200330c0..53df9c9b 100644 --- a/post/admin/admin_settings_online_payment.php +++ b/post/admin/admin_settings_online_payment.php @@ -18,7 +18,13 @@ if (isset($_POST['edit_online_payment_settings'])) { // Logging logAction("Settings", "Edit", "$session_name edited online payment settings"); - $_SESSION['alert_message'] = "Online Payment Settings updated"; + + if ($config_stripe_account == 0) { + $_SESSION['alert_type'] = "error"; + $_SESSION['alert_message'] = "Stripe payment account must be specified!"; + } else { + $_SESSION['alert_message'] = "Online Payment Settings updated"; + } header("Location: " . $_SERVER["HTTP_REFERER"]); } From 1e777afa50501b2d5ca57c4928ac59b7b0ba7e9a Mon Sep 17 00:00:00 2001 From: wrongecho Date: Thu, 9 Jan 2025 15:01:04 +0000 Subject: [PATCH 024/150] Stripe payments - Account selection https://tasks.dev.itflow.org/task_details.php?task_id=22 --- post/admin/admin_settings_online_payment.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/post/admin/admin_settings_online_payment.php b/post/admin/admin_settings_online_payment.php index 53df9c9b..127672e0 100644 --- a/post/admin/admin_settings_online_payment.php +++ b/post/admin/admin_settings_online_payment.php @@ -18,8 +18,7 @@ if (isset($_POST['edit_online_payment_settings'])) { // Logging logAction("Settings", "Edit", "$session_name edited online payment settings"); - - if ($config_stripe_account == 0) { + if ($config_stripe_enable && $config_stripe_account == 0) { $_SESSION['alert_type'] = "error"; $_SESSION['alert_message'] = "Stripe payment account must be specified!"; } else { From fe94036b3a7227334129143acd698105aa646ffd Mon Sep 17 00:00:00 2001 From: wrongecho Date: Thu, 9 Jan 2025 15:11:07 +0000 Subject: [PATCH 025/150] Implement new admin check Uses the new $session_is_admin rather than the old validateAdminRole. Reverts #1065 --- inc_all_admin.php | 7 +++---- top_nav.php | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/inc_all_admin.php b/inc_all_admin.php index 186fd77a..0803e149 100644 --- a/inc_all_admin.php +++ b/inc_all_admin.php @@ -6,10 +6,9 @@ require_once "functions.php"; require_once "check_login.php"; -validateAdminRole(); - -// TODO: Change this to enforceAdminPermission(); -// We can't do this until everyone has the new database fields added in db 1.4.9 on Sept 14th 2024 +if (!isset($session_is_admin) || !$session_is_admin) { + exit(WORDING_ROLECHECK_FAILED . "
Tell your admin: Your role does not have admin access."); +} require_once "header.php"; diff --git a/top_nav.php b/top_nav.php index 276bc203..7725c6d3 100644 --- a/top_nav.php +++ b/top_nav.php @@ -161,8 +161,8 @@
"; + echo "
Warning: The current directory is not writable. Ensure the webserver process has write access (chmod/chown). Check the docs for info.
"; } ?>
From cf511b2c4b4ab799b3d87f56ed3a3101363c4a88 Mon Sep 17 00:00:00 2001 From: wrongecho <32306651+wrongecho@users.noreply.github.com> Date: Thu, 9 Jan 2025 15:21:20 +0000 Subject: [PATCH 027/150] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 10702d30..75e57a9f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ All notable changes to ITFlow will be documented in this file. - Bugfix: Asset interface losing DHCP setting - Bugfix: Editing / creating recurring expenses results in error 500 due to incorrect var name - Stripe online payment setup now prompts you to set the income/expense account +- Admin pages now once again use the new admin rolecheck ## 24.12 From d3d3d3759514eb9efa5c1b1819acfb637ed79079 Mon Sep 17 00:00:00 2001 From: wrongecho Date: Thu, 9 Jan 2025 15:32:11 +0000 Subject: [PATCH 028/150] Show git branch on debug page --- admin_debug.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/admin_debug.php b/admin_debug.php index c125504f..10c18ce8 100644 --- a/admin_debug.php +++ b/admin_debug.php @@ -11,6 +11,9 @@ $checks = []; // Execute the git command to get the latest commit hash $commitHash = exec('git log -1 --format=%H'); +// Get branch info +$gitBranch = exec('git rev-parse --abbrev-ref HEAD'); + // Section: System Information $systemInfo = []; @@ -522,13 +525,17 @@ $mysqli->close(); ITFlow release version + + Current DB Version + + Current Code Commit - Current DB Version - + Current Branch + From a67de7a8f16a01d20b402da84eba10fcb58fc60a Mon Sep 17 00:00:00 2001 From: wrongecho Date: Thu, 9 Jan 2025 16:09:39 +0000 Subject: [PATCH 029/150] Prevent post pages being accessed directly --- CHANGELOG.md | 4 +++- admin_role.php | 7 +++---- post.php | 15 ++++----------- post/admin/admin_api.php | 2 ++ post/admin/admin_backup.php | 2 ++ post/admin/admin_bulk_mail.php | 3 +++ post/admin/admin_category.php | 2 ++ post/admin/admin_category_model.php | 2 ++ post/admin/admin_custom_field.php | 2 ++ post/admin/admin_custom_field_model.php | 2 ++ post/admin/admin_custom_link.php | 2 ++ post/admin/admin_document_template.php | 2 ++ post/admin/admin_mail_queue.php | 2 ++ post/admin/admin_project_template.php | 2 ++ post/admin/admin_role.php | 10 ++++++++++ post/admin/admin_settings_ai.php | 2 ++ post/admin/admin_settings_company.php | 2 ++ post/admin/admin_settings_default.php | 2 ++ post/admin/admin_settings_integration.php | 2 ++ post/admin/admin_settings_invoice.php | 2 ++ post/admin/admin_settings_localization.php | 2 ++ post/admin/admin_settings_mail.php | 1 + post/admin/admin_settings_module.php | 2 ++ post/admin/admin_settings_notification.php | 2 ++ post/admin/admin_settings_online_payment.php | 2 ++ post/admin/admin_settings_project.php | 2 ++ post/admin/admin_settings_quote.php | 2 ++ post/admin/admin_settings_security.php | 2 ++ post/admin/admin_settings_telemetry.php | 2 ++ post/admin/admin_settings_theme.php | 2 ++ post/admin/admin_settings_ticket.php | 2 ++ post/admin/admin_software_template.php | 2 ++ post/admin/admin_tag.php | 2 ++ post/admin/admin_tag_model.php | 2 ++ post/admin/admin_tax.php | 2 ++ post/admin/admin_ticket_status.php | 2 ++ post/admin/admin_ticket_template.php | 2 ++ post/{ => admin}/admin_update.php | 2 ++ post/admin/admin_user.php | 2 ++ post/admin/admin_user_model.php | 2 ++ post/admin/admin_vendor_template.php | 2 ++ post/user/account.php | 2 ++ post/user/asset.php | 2 ++ post/user/asset_interface_model.php | 2 ++ post/user/asset_model.php | 2 ++ post/user/budget.php | 3 +++ post/user/certificate.php | 2 ++ post/user/certificate_model.php | 2 ++ post/user/client.php | 2 ++ post/user/client_model.php | 2 ++ post/user/contact.php | 2 ++ post/user/contact_model.php | 1 + post/user/credential.php | 2 ++ post/user/credential_model.php | 2 ++ post/user/document.php | 2 ++ post/user/document_model.php | 2 ++ post/user/domain.php | 2 ++ post/user/domain_model.php | 2 ++ post/user/event.php | 2 ++ post/user/event_model.php | 2 ++ post/user/expense.php | 2 ++ post/user/expense_model.php | 2 ++ post/user/file.php | 2 ++ post/user/folder.php | 2 ++ post/user/invoice.php | 2 ++ post/user/invoice_model.php | 1 + post/user/location.php | 2 ++ post/user/location_model.php | 2 ++ post/user/network.php | 2 ++ post/user/network_model.php | 2 ++ post/user/product.php | 2 ++ post/user/product_model.php | 2 ++ post/user/profile.php | 2 ++ post/user/project.php | 2 ++ post/user/quote.php | 2 ++ post/user/quote_model.php | 2 ++ post/user/rack.php | 2 ++ post/user/revenue.php | 2 ++ post/user/service.php | 2 ++ post/user/software.php | 1 + post/user/task.php | 2 ++ post/user/ticket.php | 2 ++ post/user/ticket_recurring_model.php | 1 + post/user/transfer.php | 2 ++ post/user/transfer_model.php | 2 ++ post/user/trip.php | 2 ++ post/user/trip_model.php | 2 ++ post/user/vendor.php | 2 ++ post/user/vendor_contact.php | 2 ++ post/user/vendor_contact_model.php | 1 + post/user/vendor_model.php | 2 ++ 91 files changed, 190 insertions(+), 16 deletions(-) rename post/{ => admin}/admin_update.php (99%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 75e57a9f..446ca6e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,9 @@ All notable changes to ITFlow will be documented in this file. - Bugfix: Asset interface losing DHCP setting - Bugfix: Editing / creating recurring expenses results in error 500 due to incorrect var name - Stripe online payment setup now prompts you to set the income/expense account -- Admin pages now once again use the new admin rolecheck +- Admin pages now once again use the new admin role-check +- Debug now shows the current git branch +- Individual POST handler logic pages can no longer be accessed directly ## 24.12 diff --git a/admin_role.php b/admin_role.php index 241a116f..800b58cc 100644 --- a/admin_role.php +++ b/admin_role.php @@ -110,11 +110,10 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()")); - - - - + + Archive +
diff --git a/post.php b/post.php index f09d2141..69a21561 100644 --- a/post.php +++ b/post.php @@ -10,6 +10,9 @@ require_once "functions.php"; require_once "check_login.php"; +// Define a variable that we can use to only allow running post files via inclusion (prevents people/bots poking them) +define('FROM_POST_HANDLER', true); + // Determine which files we should load @@ -28,13 +31,7 @@ if (str_contains($module, 'admin') && isset($session_is_admin) && $session_is_ad // To add a new admin POST request handler, add a file named after the admin page // e.g. changes made on the page http://itflow/admin_ticket_statues.php will load the page post/admin/admin_ticket_statues.php to handle the changes - if ($module !== 'admin_update') { - require_once "post/admin/$module.php"; - } - // IF statement is temporary - - - + require_once "post/admin/$module.php"; } elseif (str_contains($module, 'xcustom')) { // Dynamically load any custom POST logic @@ -58,10 +55,6 @@ if (str_contains($module, 'admin') && isset($session_is_admin) && $session_is_ad // Logout is the same for user and admin require_once "post/logout.php"; -// TODO: Move admin_update into the admin section to be auto-loaded -// We can't do this until everyone has the new database fields added in 1.4.9 on Sept 14th 2024 -require_once "post/admin_update.php"; // Load updater - // TODO: Find a home for these require_once "post/ai.php"; diff --git a/post/admin/admin_api.php b/post/admin/admin_api.php index 8817b62a..073f2afd 100644 --- a/post/admin/admin_api.php +++ b/post/admin/admin_api.php @@ -4,6 +4,8 @@ * ITFlow - GET/POST request handler for API settings */ +defined('FROM_POST_HANDLER') || die("Direct file access is not allowed"); + if (isset($_POST['add_api_key'])) { validateCSRFToken($_POST['csrf_token']); diff --git a/post/admin/admin_backup.php b/post/admin/admin_backup.php index 8649e91d..dfb0509a 100644 --- a/post/admin/admin_backup.php +++ b/post/admin/admin_backup.php @@ -4,6 +4,8 @@ * ITFlow - GET/POST request handler for DB / master key backup */ +defined('FROM_POST_HANDLER') || die("Direct file access is not allowed"); + if (isset($_GET['download_database'])) { validateCSRFToken($_GET['csrf_token']); diff --git a/post/admin/admin_bulk_mail.php b/post/admin/admin_bulk_mail.php index cdbf999f..4ddc0651 100644 --- a/post/admin/admin_bulk_mail.php +++ b/post/admin/admin_bulk_mail.php @@ -4,6 +4,9 @@ * ITFlow - GET/POST request handler for bulk email */ +defined('FROM_POST_HANDLER') || die("Direct file access is not allowed"); + + if (isset($_POST['send_bulk_mail_now'])) { if (isset($_POST['contact_ids'])) { diff --git a/post/admin/admin_category.php b/post/admin/admin_category.php index c3a97fc2..b5bd1273 100644 --- a/post/admin/admin_category.php +++ b/post/admin/admin_category.php @@ -4,6 +4,8 @@ * ITFlow - GET/POST request handler for categories ('category') */ +defined('FROM_POST_HANDLER') || die("Direct file access is not allowed"); + if (isset($_POST['add_category'])) { require_once 'post/admin/admin_category_model.php'; diff --git a/post/admin/admin_category_model.php b/post/admin/admin_category_model.php index 92b0c6ba..81b54a39 100644 --- a/post/admin/admin_category_model.php +++ b/post/admin/admin_category_model.php @@ -1,4 +1,6 @@ Date: Thu, 9 Jan 2025 16:11:52 +0000 Subject: [PATCH 030/150] Credential add modal - URI placeholder text was off --- client_login_add_modal.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client_login_add_modal.php b/client_login_add_modal.php index 8ce5edd0..8aa0ecc2 100644 --- a/client_login_add_modal.php +++ b/client_login_add_modal.php @@ -100,7 +100,7 @@
- +
From 64fd7619345e637403d6d1c1269ea099aa1d65fe Mon Sep 17 00:00:00 2001 From: wrongecho Date: Thu, 9 Jan 2025 16:23:35 +0000 Subject: [PATCH 031/150] Don't require a contact for recurring tickets --- CHANGELOG.md | 3 ++- post/user/ticket.php | 16 ---------------- recurring_ticket_add_modal.php | 2 +- recurring_ticket_edit_modal.php | 4 ++-- scripts/cron.php | 2 -- 5 files changed, 5 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 446ca6e4..66ee6d02 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,8 @@ All notable changes to ITFlow will be documented in this file. - Bugfix: Ticket edit modal not showing multi-client/no-client projects - Bugfix: Asset interface losing DHCP setting - Bugfix: Editing / creating recurring expenses results in error 500 due to incorrect var name -- Stripe online payment setup now prompts you to set the income/expense account +- Bugfix: Recurring tickets no longer require a contact +- Bugfix: Stripe online payment setup now prompts you to set the income/expense account - Admin pages now once again use the new admin role-check - Debug now shows the current git branch - Individual POST handler logic pages can no longer be accessed directly diff --git a/post/user/ticket.php b/post/user/ticket.php index 706f7a82..8fa974e2 100644 --- a/post/user/ticket.php +++ b/post/user/ticket.php @@ -1980,14 +1980,6 @@ if (isset($_POST['add_recurring_ticket'])) { $start_date = sanitizeInput($_POST['start_date']); - // If no contact is selected automatically choose the primary contact for the client - if ($client_id > 0 && $contact_id == 0) { - $sql = mysqli_query($mysqli, "SELECT contact_id FROM contacts WHERE contact_client_id = $client_id AND contact_primary = 1"); - $row = mysqli_fetch_array($sql); - $contact_id = intval($row['contact_id']); - } - - // Add recurring (scheduled) ticket mysqli_query($mysqli, "INSERT INTO scheduled_tickets SET scheduled_ticket_subject = '$subject', scheduled_ticket_details = '$details', scheduled_ticket_priority = '$priority', scheduled_ticket_frequency = '$frequency', scheduled_ticket_billable = $billable, scheduled_ticket_start_date = '$start_date', scheduled_ticket_next_run = '$start_date', scheduled_ticket_assigned_to = $assigned_to, scheduled_ticket_created_by = $session_user_id, scheduled_ticket_client_id = $client_id, scheduled_ticket_contact_id = $contact_id, scheduled_ticket_asset_id = $asset_id"); $scheduled_ticket_id = mysqli_insert_id($mysqli); @@ -2009,14 +2001,6 @@ if (isset($_POST['edit_recurring_ticket'])) { $scheduled_ticket_id = intval($_POST['scheduled_ticket_id']); $next_run_date = sanitizeInput($_POST['next_date']); - // If no contact is selected automatically choose the primary contact for the client - if ($client_id > 0 && $contact_id == 0) { - $sql = mysqli_query($mysqli, "SELECT contact_id FROM contacts WHERE contact_client_id = $client_id AND contact_primary = 1"); - $row = mysqli_fetch_array($sql); - $contact_id = intval($row['contact_id']); - } - - // Edit scheduled ticket mysqli_query($mysqli, "UPDATE scheduled_tickets SET scheduled_ticket_subject = '$subject', scheduled_ticket_details = '$details', scheduled_ticket_priority = '$priority', scheduled_ticket_frequency = '$frequency', scheduled_ticket_billable = $billable, scheduled_ticket_next_run = '$next_run_date', scheduled_ticket_assigned_to = $assigned_to, scheduled_ticket_asset_id = $asset_id, scheduled_ticket_contact_id = $contact_id WHERE scheduled_ticket_id = $scheduled_ticket_id"); // Logging diff --git a/recurring_ticket_add_modal.php b/recurring_ticket_add_modal.php index f1eb7a27..51555c20 100644 --- a/recurring_ticket_add_modal.php +++ b/recurring_ticket_add_modal.php @@ -130,7 +130,7 @@
-
diff --git a/recurring_ticket_edit_modal.php b/recurring_ticket_edit_modal.php index f676d1bf..af552996 100644 --- a/recurring_ticket_edit_modal.php +++ b/recurring_ticket_edit_modal.php @@ -85,12 +85,12 @@
- +
-
diff --git a/scripts/cron.php b/scripts/cron.php index 46e00a47..dbbb02b8 100644 --- a/scripts/cron.php +++ b/scripts/cron.php @@ -142,9 +142,7 @@ mysqli_query($mysqli, "DELETE FROM logs WHERE log_created_at < CURDATE() - INTER // Whitelabel - Disable if expired/invalid if ($config_whitelabel_enabled && !validateWhitelabelKey($config_whitelabel_key)) { mysqli_query($mysqli, "UPDATE settings SET config_whitelabel_enabled = 0, config_whitelabel_key = '' WHERE company_id = 1"); - appNotify("Settings", "White-labelling was disabled due to expired/invalid key", "settings_modules.php"); - } From 22d1a1809ca106df263bbd6f87b3c6f8ac3d301e Mon Sep 17 00:00:00 2001 From: wrongecho Date: Thu, 9 Jan 2025 16:29:07 +0000 Subject: [PATCH 032/150] Tickets created via portal/email not being marked as billable --- CHANGELOG.md | 1 + portal/portal_post.php | 2 +- scripts/cron_ticket_email_parser.php | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 66ee6d02..13aca7ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ All notable changes to ITFlow will be documented in this file. - Bugfix: Editing / creating recurring expenses results in error 500 due to incorrect var name - Bugfix: Recurring tickets no longer require a contact - Bugfix: Stripe online payment setup now prompts you to set the income/expense account +- Bugfix: Tickets created via portal/email not being marked as billable - Admin pages now once again use the new admin role-check - Debug now shows the current git branch - Individual POST handler logic pages can no longer be accessed directly diff --git a/portal/portal_post.php b/portal/portal_post.php index 37855e0d..d576bbad 100644 --- a/portal/portal_post.php +++ b/portal/portal_post.php @@ -34,7 +34,7 @@ if (isset($_POST['add_ticket'])) { $new_config_ticket_next_number = $config_ticket_next_number + 1; mysqli_query($mysqli, "UPDATE settings SET config_ticket_next_number = $new_config_ticket_next_number WHERE company_id = 1"); - mysqli_query($mysqli, "INSERT INTO tickets SET ticket_prefix = '$config_ticket_prefix', ticket_number = $ticket_number, ticket_subject = '$subject', ticket_details = '$details', ticket_priority = '$priority', ticket_status = 1, ticket_created_by = 0, ticket_contact_id = $session_contact_id, ticket_url_key = '$url_key', ticket_client_id = $session_client_id"); + mysqli_query($mysqli, "INSERT INTO tickets SET ticket_prefix = '$config_ticket_prefix', ticket_number = $ticket_number, ticket_subject = '$subject', ticket_details = '$details', ticket_priority = '$priority', ticket_status = 1, ticket_billable = $config_ticket_default_billable, ticket_created_by = 0, ticket_contact_id = $session_contact_id, ticket_url_key = '$url_key', ticket_client_id = $session_client_id"); $ticket_id = mysqli_insert_id($mysqli); // Notify agent DL of the new ticket, if populated with a valid email diff --git a/scripts/cron_ticket_email_parser.php b/scripts/cron_ticket_email_parser.php index fbc805ef..d74e2912 100644 --- a/scripts/cron_ticket_email_parser.php +++ b/scripts/cron_ticket_email_parser.php @@ -111,7 +111,7 @@ function addTicket($contact_id, $contact_name, $contact_email, $client_id, $date //Generate a unique URL key for clients to access $url_key = randomString(156); - mysqli_query($mysqli, "INSERT INTO tickets SET ticket_prefix = '$ticket_prefix_esc', ticket_number = $ticket_number, ticket_subject = '$subject', ticket_details = '$message_esc', ticket_priority = 'Low', ticket_status = 1, ticket_created_by = 0, ticket_contact_id = $contact_id, ticket_url_key = '$url_key', ticket_client_id = $client_id"); + mysqli_query($mysqli, "INSERT INTO tickets SET ticket_prefix = '$ticket_prefix_esc', ticket_number = $ticket_number, ticket_subject = '$subject', ticket_details = '$message_esc', ticket_priority = 'Low', ticket_status = 1, ticket_billable = $config_ticket_default_billable, ticket_created_by = 0, ticket_contact_id = $contact_id, ticket_url_key = '$url_key', ticket_client_id = $client_id"); $id = mysqli_insert_id($mysqli); // Logging From 50e252efb7fe3eb748ba95ed1c266b7d6b4628a8 Mon Sep 17 00:00:00 2001 From: wrongecho Date: Thu, 9 Jan 2025 16:58:09 +0000 Subject: [PATCH 033/150] Mail queue - fix file inclusion following move to subdir --- scripts/cron_mail_queue.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/cron_mail_queue.php b/scripts/cron_mail_queue.php index 300df6e9..efc9fbf0 100644 --- a/scripts/cron_mail_queue.php +++ b/scripts/cron_mail_queue.php @@ -1,5 +1,8 @@ Date: Thu, 9 Jan 2025 17:02:03 +0000 Subject: [PATCH 034/150] Mail parser - fix billable --- scripts/cron_ticket_email_parser.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/cron_ticket_email_parser.php b/scripts/cron_ticket_email_parser.php index d74e2912..1824bd33 100644 --- a/scripts/cron_ticket_email_parser.php +++ b/scripts/cron_ticket_email_parser.php @@ -88,7 +88,7 @@ $allowed_extensions = array('jpg', 'jpeg', 'gif', 'png', 'webp', 'pdf', 'txt', ' // Function to raise a new ticket for a given contact and email them confirmation (if configured) function addTicket($contact_id, $contact_name, $contact_email, $client_id, $date, $subject, $message, $attachments, $original_message_file) { - global $mysqli, $config_app_name, $company_name, $company_phone, $config_ticket_prefix, $config_ticket_client_general_notifications, $config_ticket_new_ticket_notification_email, $config_base_url, $config_ticket_from_name, $config_ticket_from_email, $allowed_extensions; + global $mysqli, $config_app_name, $company_name, $company_phone, $config_ticket_prefix, $config_ticket_client_general_notifications, $config_ticket_new_ticket_notification_email, $config_base_url, $config_ticket_from_name, $config_ticket_from_email, $config_ticket_default_billable, $allowed_extensions; $ticket_number_sql = mysqli_fetch_array(mysqli_query($mysqli, "SELECT config_ticket_next_number FROM settings WHERE company_id = 1")); $ticket_number = intval($ticket_number_sql['config_ticket_next_number']); From 73c711095ac76691f0a641108d3a6a5f368432a4 Mon Sep 17 00:00:00 2001 From: wrongecho Date: Thu, 9 Jan 2025 18:53:11 +0000 Subject: [PATCH 035/150] Mail queue - undo file inclusion, not a fix --- scripts/cron_mail_queue.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/scripts/cron_mail_queue.php b/scripts/cron_mail_queue.php index efc9fbf0..300df6e9 100644 --- a/scripts/cron_mail_queue.php +++ b/scripts/cron_mail_queue.php @@ -1,8 +1,5 @@ Date: Thu, 9 Jan 2025 18:59:24 +0000 Subject: [PATCH 036/150] Mail queue - duh, it actually sees to be a fix.. --- scripts/cron_mail_queue.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/cron_mail_queue.php b/scripts/cron_mail_queue.php index 300df6e9..efc9fbf0 100644 --- a/scripts/cron_mail_queue.php +++ b/scripts/cron_mail_queue.php @@ -1,5 +1,8 @@ Date: Thu, 9 Jan 2025 19:01:31 +0000 Subject: [PATCH 037/150] All cron scripts should set the running directory for consistency --- scripts/cron_certificate_refresher.php | 3 +++ scripts/cron_domain_refresher.php | 3 +++ 2 files changed, 6 insertions(+) diff --git a/scripts/cron_certificate_refresher.php b/scripts/cron_certificate_refresher.php index 739a41de..76fd03a9 100644 --- a/scripts/cron_certificate_refresher.php +++ b/scripts/cron_certificate_refresher.php @@ -1,5 +1,8 @@ Date: Sat, 11 Jan 2025 12:55:23 -0500 Subject: [PATCH 038/150] Created modals and includes folder moved client contact modals to /modals and updsated contact details and contact listing code --- client_contact_details.php | 16 ++++++------- client_contacts.php | 24 +++++++++---------- .../client_contact_add_modal.php | 0 .../client_contact_archive_modal.php | 0 ...ent_contact_bulk_assign_location_modal.php | 0 .../client_contact_bulk_assign_tags_modal.php | 0 ...ent_contact_bulk_edit_department_modal.php | 0 .../client_contact_bulk_edit_phone_modal.php | 0 .../client_contact_bulk_edit_role_modal.php | 0 .../client_contact_bulk_email_modal.php | 0 .../client_contact_create_note_modal.php | 0 .../client_contact_edit_modal.php | 0 .../client_contact_export_modal.php | 0 .../client_contact_import_modal.php | 0 .../client_contact_invite_modal.php | 2 +- .../client_contact_link_asset_modal.php | 0 .../client_contact_link_credential_modal.php | 0 .../client_contact_link_document_modal.php | 0 .../client_contact_link_file_modal.php | 0 .../client_contact_link_service_modal.php | 0 .../client_contact_link_software_modal.php | 0 21 files changed, 21 insertions(+), 21 deletions(-) rename client_contact_add_modal.php => modals/client_contact_add_modal.php (100%) rename client_contact_archive_modal.php => modals/client_contact_archive_modal.php (100%) rename client_contact_bulk_assign_location_modal.php => modals/client_contact_bulk_assign_location_modal.php (100%) rename client_contact_bulk_assign_tags_modal.php => modals/client_contact_bulk_assign_tags_modal.php (100%) rename client_contact_bulk_edit_department_modal.php => modals/client_contact_bulk_edit_department_modal.php (100%) rename client_contact_bulk_edit_phone_modal.php => modals/client_contact_bulk_edit_phone_modal.php (100%) rename client_contact_bulk_edit_role_modal.php => modals/client_contact_bulk_edit_role_modal.php (100%) rename client_contact_bulk_email_modal.php => modals/client_contact_bulk_email_modal.php (100%) rename client_contact_create_note_modal.php => modals/client_contact_create_note_modal.php (100%) rename client_contact_edit_modal.php => modals/client_contact_edit_modal.php (100%) rename client_contact_export_modal.php => modals/client_contact_export_modal.php (100%) rename client_contact_import_modal.php => modals/client_contact_import_modal.php (100%) rename client_contact_invite_modal.php => modals/client_contact_invite_modal.php (99%) rename client_contact_link_asset_modal.php => modals/client_contact_link_asset_modal.php (100%) rename client_contact_link_credential_modal.php => modals/client_contact_link_credential_modal.php (100%) rename client_contact_link_document_modal.php => modals/client_contact_link_document_modal.php (100%) rename client_contact_link_file_modal.php => modals/client_contact_link_file_modal.php (100%) rename client_contact_link_service_modal.php => modals/client_contact_link_service_modal.php (100%) rename client_contact_link_software_modal.php => modals/client_contact_link_software_modal.php (100%) diff --git a/client_contact_details.php b/client_contact_details.php index 1599b941..595892ce 100644 --- a/client_contact_details.php +++ b/client_contact_details.php @@ -210,7 +210,7 @@ if (isset($_GET['contact_id'])) {
-
@@ -1125,14 +1125,14 @@ if (isset($_GET['contact_id'])) {
- - - - - - + + + + + + @@ -482,12 +482,12 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
-
+ \ No newline at end of file diff --git a/client_contact_link_asset_modal.php b/modals/client_contact_link_asset_modal.php similarity index 100% rename from client_contact_link_asset_modal.php rename to modals/client_contact_link_asset_modal.php diff --git a/client_contact_link_credential_modal.php b/modals/client_contact_link_credential_modal.php similarity index 100% rename from client_contact_link_credential_modal.php rename to modals/client_contact_link_credential_modal.php diff --git a/client_contact_link_document_modal.php b/modals/client_contact_link_document_modal.php similarity index 100% rename from client_contact_link_document_modal.php rename to modals/client_contact_link_document_modal.php diff --git a/client_contact_link_file_modal.php b/modals/client_contact_link_file_modal.php similarity index 100% rename from client_contact_link_file_modal.php rename to modals/client_contact_link_file_modal.php diff --git a/client_contact_link_service_modal.php b/modals/client_contact_link_service_modal.php similarity index 100% rename from client_contact_link_service_modal.php rename to modals/client_contact_link_service_modal.php diff --git a/client_contact_link_software_modal.php b/modals/client_contact_link_software_modal.php similarity index 100% rename from client_contact_link_software_modal.php rename to modals/client_contact_link_software_modal.php From a9179462c4b5c6fc64485bf8e334d0c90900de86 Mon Sep 17 00:00:00 2001 From: johnnyq Date: Sat, 11 Jan 2025 13:05:26 -0500 Subject: [PATCH 039/150] Moved client location modals inside /modals and updated the require links in location listing --- client_locations.php | 10 +++++----- .../client_location_add_modal.php | 0 .../client_location_bulk_assign_tags_modal.php | 0 .../client_location_edit_modal.php | 0 .../client_location_export_modal.php | 0 .../client_location_import_modal.php | 0 6 files changed, 5 insertions(+), 5 deletions(-) rename client_location_add_modal.php => modals/client_location_add_modal.php (100%) rename client_location_bulk_assign_tags_modal.php => modals/client_location_bulk_assign_tags_modal.php (100%) rename client_location_edit_modal.php => modals/client_location_edit_modal.php (100%) rename client_location_export_modal.php => modals/client_location_export_modal.php (100%) rename client_location_import_modal.php => modals/client_location_import_modal.php (100%) diff --git a/client_locations.php b/client_locations.php index 2e2403f3..2c7f125d 100644 --- a/client_locations.php +++ b/client_locations.php @@ -297,7 +297,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()")); - @@ -307,7 +307,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()")); - + @@ -318,11 +318,11 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()")); Date: Sat, 11 Jan 2025 19:33:48 +0000 Subject: [PATCH 040/150] Auto-acknowledgement email for email parsed tickets now contains guest link --- CHANGELOG.md | 1 + scripts/cron_ticket_email_parser.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 13aca7ae..df060d6f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ All notable changes to ITFlow will be documented in this file. - Admin pages now once again use the new admin role-check - Debug now shows the current git branch - Individual POST handler logic pages can no longer be accessed directly +- Auto-acknowledgement email for email parsed tickets now contains guest link ## 24.12 diff --git a/scripts/cron_ticket_email_parser.php b/scripts/cron_ticket_email_parser.php index 1824bd33..c73679d5 100644 --- a/scripts/cron_ticket_email_parser.php +++ b/scripts/cron_ticket_email_parser.php @@ -155,7 +155,7 @@ function addTicket($contact_id, $contact_name, $contact_email, $client_id, $date $data = []; if ($config_ticket_client_general_notifications == 1) { $subject_email = "Ticket created - [$config_ticket_prefix$ticket_number] - $subject"; - $body = "##- Please type your reply above this line -##

Hello $contact_name,

Thank you for your email. A ticket regarding \"$subject\" has been automatically created for you.

Ticket: $config_ticket_prefix$ticket_number
Subject: $subject
Status: New
https://$config_base_url/portal/ticket.php?id=$id

--
$company_name - Support
$config_ticket_from_email
$company_phone"; + $body = "##- Please type your reply above this line -##

Hello $contact_name,

Thank you for your email. A ticket regarding \"$subject\" has been automatically created for you.

Ticket: $config_ticket_prefix$ticket_number
Subject: $subject
Status: New
Portal: View ticket

--
$company_name - Support
$config_ticket_from_email
$company_phone"; $data[] = [ 'from' => $config_ticket_from_email, 'from_name' => $config_ticket_from_name, From 2ca92744f32b7eaddfee979c7270312662aafcf3 Mon Sep 17 00:00:00 2001 From: wrongecho Date: Sat, 11 Jan 2025 19:40:36 +0000 Subject: [PATCH 041/150] mv --- CHANGELOG.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index df060d6f..ebbc8deb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,16 +4,16 @@ All notable changes to ITFlow will be documented in this file. ## 25.1 - Moved cron/cli scripts to scripts subfolder - Old scripts remain in the root for now, but please update your cron configurations! +- Admin pages now once again use the new admin role-check +- Debug now shows the current git branch +- Individual POST handler logic pages can no longer be accessed directly +- Auto-acknowledgement email for email parsed tickets now contains guest link - Bugfix: Ticket edit modal not showing multi-client/no-client projects - Bugfix: Asset interface losing DHCP setting - Bugfix: Editing / creating recurring expenses results in error 500 due to incorrect var name - Bugfix: Recurring tickets no longer require a contact - Bugfix: Stripe online payment setup now prompts you to set the income/expense account -- Bugfix: Tickets created via portal/email not being marked as billable -- Admin pages now once again use the new admin role-check -- Debug now shows the current git branch -- Individual POST handler logic pages can no longer be accessed directly -- Auto-acknowledgement email for email parsed tickets now contains guest link +- Bugfix: Tickets created via portal/email not being marked as billable ## 24.12 From 98f9083bcb8cb47e579c64712f1656e8750edb7d Mon Sep 17 00:00:00 2001 From: johnnyq Date: Sat, 11 Jan 2025 14:47:32 -0500 Subject: [PATCH 042/150] Structure rework: Moved most php files that are included to /includes renamed pagination.php to filter_footer.php, updated all file to reference new filter_footer and includes --- accounts.php | 6 +++--- admin_api.php | 6 +++--- admin_app_log.php | 6 +++--- admin_audit_log.php | 6 +++--- admin_backup.php | 4 ++-- admin_bulk_mail.php | 4 ++-- admin_category.php | 6 +++--- admin_custom_link.php | 6 +++--- admin_debug.php | 4 ++-- admin_document_template.php | 2 +- admin_document_template_details.php | 4 ++-- admin_legacy_debug.php | 4 ++-- admin_mail_queue.php | 6 +++--- admin_mail_queue_message_view.php | 4 ++-- admin_project_template.php | 6 +++--- admin_project_template_details.php | 4 ++-- admin_role.php | 6 +++--- admin_settings_ai.php | 4 ++-- admin_settings_company.php | 4 ++-- admin_settings_custom_fields.php | 6 +++--- admin_settings_default.php | 4 ++-- admin_settings_integration.php | 4 ++-- admin_settings_invoice.php | 4 ++-- admin_settings_localization.php | 4 ++-- admin_settings_mail.php | 4 ++-- admin_settings_maintenance.php | 4 ++-- admin_settings_module.php | 4 ++-- admin_settings_notification.php | 4 ++-- admin_settings_online_payment.php | 4 ++-- admin_settings_project.php | 4 ++-- admin_settings_quote.php | 4 ++-- admin_settings_security.php | 4 ++-- admin_settings_telemetry.php | 4 ++-- admin_settings_theme.php | 4 ++-- admin_settings_ticket.php | 4 ++-- admin_software_template.php | 6 +++--- admin_tag.php | 6 +++--- admin_tax.php | 4 ++-- admin_ticket_status.php | 6 +++--- admin_ticket_template.php | 6 +++--- admin_ticket_template_details.php | 4 ++-- admin_update.php | 4 ++-- admin_user.php | 6 +++--- admin_vendor_template.php | 6 +++--- blank.php | 4 ++-- budget.php | 4 ++-- budget_edit.php | 4 ++-- calendar_events.php | 4 ++-- client_asset_details.php | 4 ++-- client_assets.php | 6 +++--- client_certificates.php | 6 +++--- client_contact_details.php | 4 ++-- client_contacts.php | 6 +++--- client_document_details.php | 4 ++-- client_documents.php | 6 +++--- client_domains.php | 6 +++--- client_events.php | 2 +- client_files.php | 6 +++--- client_invoices.php | 6 +++--- client_locations.php | 6 +++--- client_logins.php | 6 +++--- client_networks.php | 6 +++--- client_overview.php | 4 ++-- client_payments.php | 6 +++--- client_quotes.php | 6 +++--- client_racks.php | 4 ++-- client_recurring_invoices.php | 6 +++--- client_recurring_tickets.php | 4 ++-- client_services.php | 4 ++-- client_software.php | 6 +++--- client_tickets.php | 6 +++--- client_trips.php | 6 +++--- client_vendors.php | 6 +++--- clients.php | 6 +++--- dashboard.php | 4 ++-- expenses.php | 6 +++--- force_mfa.php | 2 +- global_search.php | 4 ++-- admin_side_nav.php => includes/admin_side_nav.php | 0 client_side_nav.php => includes/client_side_nav.php | 0 pagination.php => includes/filter_footer.php | 0 filter_header.php => includes/filter_header.php | 0 footer.php => includes/footer.php | 2 +- header.php => includes/header.php | 0 inc_alert_feedback.php => includes/inc_alert_feedback.php | 0 inc_all.php => includes/inc_all.php | 0 inc_all_admin.php => includes/inc_all_admin.php | 0 inc_all_client.php => includes/inc_all_client.php | 0 inc_all_reports.php => includes/inc_all_reports.php | 0 inc_all_user.php => includes/inc_all_user.php | 0 .../inc_client_top_head.php | 0 inc_confirm_modal.php => includes/inc_confirm_modal.php | 0 inc_debug.php => includes/inc_debug.php | 0 inc_wrapper.php => includes/inc_wrapper.php | 0 reports_side_nav.php => includes/reports_side_nav.php | 0 side_nav.php => includes/side_nav.php | 0 top_nav.php => includes/top_nav.php | 0 user_side_nav.php => includes/user_side_nav.php | 0 invoice.php | 8 ++++---- invoices.php | 6 +++--- login.php | 4 ++-- notifications.php | 4 ++-- notifications_dismissed.php | 6 +++--- payments.php | 6 +++--- {dist => plugins/adminlte}/css/adminlte.min.css | 0 {dist => plugins/adminlte}/js/.eslintrc.json | 0 {dist => plugins/adminlte}/js/adminlte.min.js | 0 products.php | 6 +++--- project_details.php | 4 ++-- projects.php | 6 +++--- quote.php | 8 ++++---- quotes.php | 6 +++--- recurring_expenses.php | 6 +++--- recurring_invoice.php | 6 +++--- recurring_invoices.php | 6 +++--- recurring_tickets.php | 4 ++-- report_assets.php | 6 +++--- report_budget.php | 4 ++-- report_clients_with_balance.php | 4 ++-- report_domains.php | 6 +++--- report_expense_by_vendor.php | 4 ++-- report_expense_summary.php | 4 ++-- report_income_by_client.php | 4 ++-- report_income_summary.php | 4 ++-- report_password_rotation.php | 4 ++-- report_profit_loss.php | 4 ++-- report_recurring_by_client.php | 4 ++-- report_tax_summary.php | 4 ++-- report_ticket_by_client.php | 4 ++-- report_ticket_summary.php | 4 ++-- report_tickets_unbilled.php | 4 ++-- revenues.php | 6 +++--- temp_bulk_close_bugfix.php | 4 ++-- ticket.php | 6 +++--- tickets.php | 6 +++--- transfers.php | 6 +++--- trips.php | 6 +++--- user_activity.php | 4 ++-- user_details.php | 4 ++-- user_preferences.php | 4 ++-- user_security.php | 4 ++-- vendor_details.php | 6 +++--- vendors.php | 6 +++--- 143 files changed, 295 insertions(+), 295 deletions(-) rename admin_side_nav.php => includes/admin_side_nav.php (100%) rename client_side_nav.php => includes/client_side_nav.php (100%) rename pagination.php => includes/filter_footer.php (100%) rename filter_header.php => includes/filter_header.php (100%) rename footer.php => includes/footer.php (96%) rename header.php => includes/header.php (100%) rename inc_alert_feedback.php => includes/inc_alert_feedback.php (100%) rename inc_all.php => includes/inc_all.php (100%) rename inc_all_admin.php => includes/inc_all_admin.php (100%) rename inc_all_client.php => includes/inc_all_client.php (100%) rename inc_all_reports.php => includes/inc_all_reports.php (100%) rename inc_all_user.php => includes/inc_all_user.php (100%) rename inc_client_top_head.php => includes/inc_client_top_head.php (100%) rename inc_confirm_modal.php => includes/inc_confirm_modal.php (100%) rename inc_debug.php => includes/inc_debug.php (100%) rename inc_wrapper.php => includes/inc_wrapper.php (100%) rename reports_side_nav.php => includes/reports_side_nav.php (100%) rename side_nav.php => includes/side_nav.php (100%) rename top_nav.php => includes/top_nav.php (100%) rename user_side_nav.php => includes/user_side_nav.php (100%) rename {dist => plugins/adminlte}/css/adminlte.min.css (100%) rename {dist => plugins/adminlte}/js/.eslintrc.json (100%) rename {dist => plugins/adminlte}/js/adminlte.min.js (100%) diff --git a/accounts.php b/accounts.php index f23a0f7e..0488c624 100644 --- a/accounts.php +++ b/accounts.php @@ -4,7 +4,7 @@ $sort = "account_name"; $order = "ASC"; -require_once "inc_all.php"; +require_once "includes/inc_all.php"; // Perms enforceUserPermission('module_financial'); @@ -116,11 +116,11 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()")); - + - @@ -176,5 +176,5 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()")); - -
@@ -34,5 +34,5 @@ require_once "inc_all_admin.php";
- @@ -194,4 +194,4 @@ if (isset($_GET['archived'])) { - @@ -149,5 +149,5 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()")); close(); - + - @@ -146,4 +146,4 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()")); diff --git a/admin_role.php b/admin_role.php index 800b58cc..62086cc2 100644 --- a/admin_role.php +++ b/admin_role.php @@ -4,7 +4,7 @@ $sort = "user_role_is_admin"; $order = "DESC"; -require_once "inc_all_admin.php"; +require_once "includes/inc_all_admin.php"; //Rebuild URL @@ -134,7 +134,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()")); - @@ -143,5 +143,5 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()")); require_once "admin_role_add_modal.php"; -require_once "footer.php"; +require_once "includes/footer.php"; diff --git a/admin_settings_ai.php b/admin_settings_ai.php index 91eba539..894859b8 100644 --- a/admin_settings_ai.php +++ b/admin_settings_ai.php @@ -1,6 +1,6 @@
@@ -73,5 +73,5 @@ require_once "inc_all_admin.php";
- @@ -120,5 +120,5 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
@@ -249,4 +249,4 @@ require_once "inc_all_admin.php";
@@ -39,5 +39,5 @@ require_once "inc_all_admin.php";
-
@@ -102,5 +102,5 @@ require_once "inc_all_admin.php";
@@ -327,5 +327,5 @@ require_once "inc_all_admin.php"; -
@@ -78,5 +78,5 @@ require_once "inc_all_admin.php";
@@ -193,4 +193,4 @@ require_once "inc_all_admin.php";
@@ -151,5 +151,5 @@ require_once "inc_all_admin.php";
@@ -41,4 +41,4 @@ require_once "inc_all_admin.php";
@@ -54,5 +54,5 @@ require_once "inc_all_admin.php";
@@ -62,5 +62,5 @@ require_once "inc_all_admin.php";
@@ -38,5 +38,5 @@ require_once "inc_all_admin.php";
@@ -63,5 +63,5 @@ require_once "inc_all_admin.php";
@@ -82,5 +82,5 @@ require_once "inc_all_admin.php";
- @@ -136,5 +136,5 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()")); - @@ -130,5 +130,5 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()")); - @@ -131,5 +131,5 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()")); - - @@ -239,5 +239,5 @@ require_once "admin_user_export_modal.php"; require_once "admin_user_all_reset_password_modal.php"; -require_once "footer.php"; +require_once "includes/footer.php"; diff --git a/admin_vendor_template.php b/admin_vendor_template.php index 02694440..f75cd9fb 100644 --- a/admin_vendor_template.php +++ b/admin_vendor_template.php @@ -4,7 +4,7 @@ $sort = "vendor_name"; $order = "ASC"; -require_once "inc_all_admin.php"; +require_once "includes/inc_all_admin.php"; //Rebuild URL @@ -164,7 +164,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()")); - @@ -172,5 +172,5 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()")); +