BREAKING CRON CHANGES: must generate a cron key before using cron. Cron will need updated like so php /full/path/to/cron.php [KEY] and same with cron_ticket_parse.php

This commit is contained in:
johnnyq 2023-05-01 16:51:20 -04:00
parent 8110b0ffa7
commit f7ee489293
8 changed files with 710 additions and 640 deletions

1277
cron.php

File diff suppressed because it is too large Load Diff

View File

@ -29,6 +29,13 @@ if ($config_ticket_email_parse == 0) {
exit("Email Parser: Feature is not enabled - check Settings > 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..");
}
// Check IMAP extension works/installed
if (!function_exists('imap_open')) {
exit("Email Parser: PHP IMAP extension is not installed. See https://docs.itflow.org/ticket_email_parse -- Quitting..");

View File

@ -969,11 +969,21 @@ if (LATEST_DATABASE_VERSION > CURRENT_DATABASE_VERSION) {
mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.5.1'");
}
//if (CURRENT_DATABASE_VERSION == '0.5.1') {
// Insert queries here required to update to DB version 0.5.2
if (CURRENT_DATABASE_VERSION == '0.5.1') {
//Insert queries here required to update to DB version 0.5.2
mysqli_query($mysqli, "ALTER TABLE `settings` ADD `config_ticket_autoclose` TINYINT(1) NOT NULL DEFAULT 0 AFTER `config_ticket_client_general_notifications`");
// Then, update the database to the next sequential version
// mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.5.2'");
mysqli_query($mysqli, "ALTER TABLE `settings` ADD `config_cron_key` VARCHAR(255) NULL DEFAULT NULL AFTER `config_enable_cron`");
// Then, update the database to the next sequential version
mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.5.2'");
}
//if (CURRENT_DATABASE_VERSION == '0.5.2') {
//Insert queries here required to update to DB version 0.5.3
// Then, update the database to the next sequential version
//mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.5.3'");
//}
} else {

View File

@ -5,4 +5,4 @@
* It is used in conjunction with database_updates.php
*/
DEFINE("LATEST_DATABASE_VERSION", "0.5.1");
DEFINE("LATEST_DATABASE_VERSION", "0.5.2");

View File

@ -59,10 +59,13 @@ $config_ticket_from_name = $row['config_ticket_from_name'];
$config_ticket_from_email = $row['config_ticket_from_email'];
$config_ticket_email_parse = intval($row['config_ticket_email_parse']);
$config_ticket_client_general_notifications = intval($row['config_ticket_client_general_notifications']);
$config_ticket_autoclose = intval($row['config_ticket_autoclose']);
// Alerts
// Cron
$config_enable_cron = intval($row['config_enable_cron']);
$config_cron_key = $row['config_cron_key'];
// Alerts & Notifications
$config_recurring_auto_send_invoice = intval($row['config_recurring_auto_send_invoice']);
$config_enable_alert_domain_expire = intval($row['config_enable_alert_domain_expire']);
$config_send_invoice_reminders = intval($row['config_send_invoice_reminders']);

View File

@ -682,8 +682,9 @@ if(isset($_POST['edit_ticket_settings'])){
$config_ticket_from_name = sanitizeInput($_POST['config_ticket_from_name']);
$config_ticket_email_parse = intval($_POST['config_ticket_email_parse']);
$config_ticket_client_general_notifications = intval($_POST['config_ticket_client_general_notifications']);
$config_ticket_autoclose = intval($_POST['config_ticket_autoclose']);
mysqli_query($mysqli,"UPDATE settings SET config_ticket_prefix = '$config_ticket_prefix', config_ticket_next_number = $config_ticket_next_number, config_ticket_from_email = '$config_ticket_from_email', config_ticket_from_name = '$config_ticket_from_name', config_ticket_email_parse = '$config_ticket_email_parse', config_ticket_client_general_notifications = $config_ticket_client_general_notifications WHERE company_id = 1");
mysqli_query($mysqli,"UPDATE settings SET config_ticket_prefix = '$config_ticket_prefix', config_ticket_next_number = $config_ticket_next_number, config_ticket_from_email = '$config_ticket_from_email', config_ticket_from_name = '$config_ticket_from_name', config_ticket_email_parse = '$config_ticket_email_parse', config_ticket_client_general_notifications = $config_ticket_client_general_notifications , config_ticket_autoclose = $config_ticket_autoclose WHERE company_id = 1");
//Logging
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Settings', log_action = 'Modify', log_description = '$session_name modified ticket settings', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id");
@ -739,6 +740,7 @@ if(isset($_POST['edit_alert_settings'])){
validateAdminRole();
$config_enable_cron = intval($_POST['config_enable_cron']);
$config_cron_key = sanitizeInput($_POST['config_cron_key']);
$config_enable_alert_domain_expire = intval($_POST['config_enable_alert_domain_expire']);
$config_send_invoice_reminders = intval($_POST['config_send_invoice_reminders']);
$config_invoice_overdue_reminders = sanitizeInput($_POST['config_invoice_overdue_reminders']);
@ -754,6 +756,22 @@ if(isset($_POST['edit_alert_settings'])){
}
if(isset($_GET['generate_cron_key'])){
validateAdminRole();
$key = randomString(32);
mysqli_query($mysqli,"UPDATE settings SET config_cron_key = '$key' WHERE company_id = 1");
//Logging
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Settings', log_action = 'Modify', log_description = '$session_name regenerated cron key', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id");
$_SESSION['alert_message'] = "Cron key regenerated!";
header("Location: " . $_SERVER["HTTP_REFERER"]);
}
if(isset($_POST['edit_online_payment_settings'])){
validateAdminRole();

View File

@ -15,6 +15,19 @@ require_once("inc_all_settings.php"); ?>
</div>
</div>
<div class="form-group">
<label>Cron Key</label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-fw fa-key"></i></span>
</div>
<input type="text" class="form-control" name="config_cron_key" placeholder="Generate a CRON Key" value="<?php echo htmlentities($config_cron_key); ?>" readonly>
<div class="input-group-append">
<a href="post.php?generate_cron_key" class="btn btn-secondary"><i class="fas fa-fw fa-sync mr-2"></i>Generate</a>
</div>
</div>
</div>
<div class="form-group">
<div class="custom-control custom-switch">
<input type="checkbox" class="custom-control-input" name="config_enable_alert_domain_expire" <?php if ($config_enable_alert_domain_expire == 1) { echo "checked"; } ?> value="1" id="alertDomainExpireSwitch">

View File

@ -62,6 +62,14 @@ require_once("inc_all_settings.php"); ?>
</div>
</div>
<div class="form-group">
<div class="custom-control custom-switch">
<input type="checkbox" class="custom-control-input" name="config_ticket_autoclose" <?php if($config_ticket_autoclose == 1){ echo "checked"; } ?> value="1" id="ticketAutoCloseSwitch">
<label class="custom-control-label" for="ticketAutoCloseSwitch">Enable Autoclose Tickets <small class="text-secondary">(If no response is received after 48 hrs, a chaser email is sent mentioning "This is an automatic friendly reminder that your ticket regarding "Test ticket" will be closed, unless you respond", including the last public technician response for reference
If no response is received after a further 22 hrs (70 total since ticket was put in auto close), the ticket is silently closed. (Note: I chose 70 hrs to help prevent situations where the chaser email is sent twice - feel free to adjust as needed))</small></label>
</div>
</div>
<hr>
<button type="submit" name="edit_ticket_settings" class="btn btn-primary text-bold"><i class="fas fa-check mr-2"></i>Save</button>