mirror of https://github.com/itflow-org/itflow
Fix API Asset interface relationship
This commit is contained in:
parent
2edd39c16d
commit
b37cfdf677
|
|
@ -57,17 +57,17 @@ if (isset($_POST['asset_os'])) {
|
|||
}
|
||||
|
||||
if (isset($_POST['asset_ip'])) {
|
||||
$aip = sanitizeInput($_POST['asset_ip']);
|
||||
} elseif (isset($asset_row) && isset($asset_row['asset_ip'])) {
|
||||
$aip = $asset_row['asset_ip'];
|
||||
$ip = sanitizeInput($_POST['asset_ip']);
|
||||
} elseif (isset($asset_row) && isset($asset_row['interface_ip'])) {
|
||||
$ip = $asset_row['interface_ip'];
|
||||
} else {
|
||||
$aip = '';
|
||||
$ip = '';
|
||||
}
|
||||
|
||||
if (isset($_POST['asset_mac'])) {
|
||||
$mac = sanitizeInput($_POST['asset_mac']);
|
||||
} elseif (isset($asset_row) && isset($asset_row['asset_mac'])) {
|
||||
$mac = $asset_row['asset_mac'];
|
||||
} elseif (isset($asset_row) && isset($asset_row['interface_mac'])) {
|
||||
$mac = $asset_row['interface_mac'];
|
||||
} else {
|
||||
$mac = '';
|
||||
}
|
||||
|
|
@ -146,8 +146,8 @@ if (isset($_POST['asset_contact_id'])) {
|
|||
|
||||
if (isset($_POST['asset_network_id'])) {
|
||||
$network = intval($_POST['asset_network_id']);
|
||||
} elseif (isset($asset_row) && isset($asset_row['asset_network_id'])) {
|
||||
$network = $asset_row['asset_network_id'];
|
||||
} elseif (isset($asset_row) && isset($asset_row['interface_network_id'])) {
|
||||
$network = $asset_row['interface_network_id'];
|
||||
} else {
|
||||
$network = '0';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ if (!empty($name) && !empty($client_id)) {
|
|||
$insert_id = mysqli_insert_id($mysqli);
|
||||
|
||||
// Add Primary Interface
|
||||
mysqli_query($mysqli,"INSERT INTO asset_interfaces SET interface_name = 'Primary', interface_mac = '$mac', interface_ip = '$ip', interface_port = 'eth0', interface_primary = 1, asset_network_id = $network, interface_asset_id = $insert_id");
|
||||
mysqli_query($mysqli,"INSERT INTO asset_interfaces SET interface_name = 'Primary', interface_mac = '$mac', interface_ip = '$ip', interface_port = 'eth0', interface_primary = 1, interface_network_id = $network, interface_asset_id = $insert_id");
|
||||
|
||||
//Logging
|
||||
mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Asset', log_action = 'Created', log_description = '$name via API ($api_key_name)', log_ip = '$ip', log_user_agent = '$user_agent', log_client_id = '$client_id'");
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ if (isset($_GET['asset_id'])) {
|
|||
}
|
||||
// All assets
|
||||
else {
|
||||
$sql = mysqli_query($mysqli, "SELECT * FROM assets WHERE asset_client_id LIKE '$client_id' ORDER BY asset_id LIMIT $limit OFFSET $offset");
|
||||
$sql = mysqli_query($mysqli, "SELECT * FROM assets LEFT JOIN asset_interfaces ON interface_asset_id = asset_id AND interface_primary = 1 WHERE asset_client_id LIKE '$client_id' ORDER BY asset_id LIMIT $limit OFFSET $offset");
|
||||
}
|
||||
|
||||
// Output
|
||||
|
|
|
|||
127
temp.php
127
temp.php
|
|
@ -1,127 +0,0 @@
|
|||
<?php
|
||||
if(isset($_GET['email_invoice'])){
|
||||
$invoice_id = intval($_GET['email_invoice']);
|
||||
|
||||
$sql = mysqli_query($mysqli,"SELECT * FROM invoices
|
||||
LEFT JOIN clients ON invoice_client_id = client_id
|
||||
LEFT JOIN contacts ON contact_id = primary_contact
|
||||
WHERE invoice_id = $invoice_id"
|
||||
);
|
||||
$row = mysqli_fetch_array($sql);
|
||||
|
||||
$invoice_id = intval($row['invoice_id']);
|
||||
$invoice_prefix = $row['invoice_prefix'];
|
||||
$invoice_number = intval($row['invoice_number']);
|
||||
$invoice_status = $row['invoice_status'];
|
||||
$invoice_date = $row['invoice_date'];
|
||||
$invoice_due = $row['invoice_due'];
|
||||
$invoice_amount = floatval($row['invoice_amount']);
|
||||
$invoice_url_key = $row['invoice_url_key'];
|
||||
$invoice_currency_code = $row['invoice_currency_code'];
|
||||
$client_id = intval($row['client_id']);
|
||||
$client_name = $row['client_name'];
|
||||
$contact_name = $row['contact_name'];
|
||||
$contact_email = $row['contact_email'];
|
||||
$invoice_prefix_escaped = sanitizeInput($row['invoice_prefix']);
|
||||
$contact_name_escaped = sanitizeInput($row['contact_name']);
|
||||
$contact_email_escaped = sanitizeInput($row['contact_email']);
|
||||
|
||||
$sql = mysqli_query($mysqli,"SELECT * FROM companies WHERE company_id = 1");
|
||||
$row = mysqli_fetch_array($sql);
|
||||
|
||||
$company_name = $row['company_name'];
|
||||
$company_country = $row['company_country'];
|
||||
$company_address = $row['company_address'];
|
||||
$company_city = $row['company_city'];
|
||||
$company_state = $row['company_state'];
|
||||
$company_zip = $row['company_zip'];
|
||||
$company_phone = formatPhoneNumber($row['company_phone']);
|
||||
$company_email = $row['company_email'];
|
||||
$company_website = $row['company_website'];
|
||||
$company_logo = $row['company_logo'];
|
||||
|
||||
// Sanitize Config vars from get_settings.php
|
||||
$config_invoice_from_name_escaped = sanitizeInput($config_invoice_from_name);
|
||||
$config_invoice_from_email_escaped = sanitizeInput($config_invoice_from_email);
|
||||
|
||||
$sql_payments = mysqli_query($mysqli,"SELECT * FROM payments, accounts WHERE payment_account_id = account_id AND payment_invoice_id = $invoice_id ORDER BY payment_id DESC");
|
||||
|
||||
// Add up all the payments for the invoice and get the total amount paid to the invoice
|
||||
$sql_amount_paid = mysqli_query($mysqli,"SELECT SUM(payment_amount) AS amount_paid FROM payments WHERE payment_invoice_id = $invoice_id");
|
||||
$row = mysqli_fetch_array($sql_amount_paid);
|
||||
$amount_paid = floatval($row['amount_paid']);
|
||||
|
||||
$balance = $invoice_amount - $amount_paid;
|
||||
|
||||
if ($invoice_status == 'Paid') {
|
||||
$subject = sanitizeInput("Invoice $invoice_prefix$invoice_number Copy");
|
||||
$body = mysqli_real_escape_string($mysqli, "Hello $contact_name,<br><br>Please click on the link below to see your invoice marked <b>paid</b>.<br><br><a href='https://$config_base_url/guest_view_invoice.php?invoice_id=$invoice_id&url_key=$invoice_url_key'>Invoice Link</a><br><br><br>~<br>$company_name<br>Billing Department<br>$config_invoice_from_email<br>$company_phone");
|
||||
} else {
|
||||
$subject = sanitizeInput("Invoice $invoice_prefix$invoice_number");
|
||||
$body = mysqli_real_escape_string($mysqli, "Hello $contact_name,<br><br>Please view the details of the invoice below.<br><br>Invoice: $invoice_prefix$invoice_number<br>Issue Date: $invoice_date<br>Total: " . numfmt_format_currency($currency_format, $invoice_amount, $invoice_currency_code) . "<br>Balance Due: " . numfmt_format_currency($currency_format, $balance, $invoice_currency_code) . "<br>Due Date: $invoice_due<br><br><br>To view your invoice click <a href='https://$config_base_url/guest_view_invoice.php?invoice_id=$invoice_id&url_key=$invoice_url_key'>here</a><br><br><br>~<br>$company_name<br>Billing Department<br>$config_invoice_from_email<br>$company_phone");
|
||||
}
|
||||
|
||||
// Queue Mail
|
||||
$data = [
|
||||
[
|
||||
'from' => $config_invoice_from_email,
|
||||
'from_name' => $config_invoice_from_name,
|
||||
'recipient' => $contact_email_escaped,
|
||||
'recipient_name' => $contact_name_escaped,
|
||||
'subject' => $subject,
|
||||
'body' => $body,
|
||||
]
|
||||
];
|
||||
addToMailQueue($mysqli, $data);
|
||||
|
||||
|
||||
$_SESSION['alert_message'] = "Invoice has been sent";
|
||||
mysqli_query($mysqli,"INSERT INTO history SET history_status = 'Sent', history_description = 'Invoice sent to the mail queue.', history_invoice_id = $invoice_id");
|
||||
|
||||
// Don't change the status to sent if the status is anything but draft
|
||||
if($invoice_status == 'Draft'){
|
||||
mysqli_query($mysqli,"UPDATE invoices SET invoice_status = 'Sent' WHERE invoice_id = $invoice_id");
|
||||
}
|
||||
|
||||
// Logging
|
||||
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Invoice', log_action = 'Email', log_description = 'Invoice $invoice_prefix_escaped$invoice_number queued to $contact_email_escaped Email ID: $email_id', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_client_id = $client_id, log_user_id = $session_user_id, log_entity_id = $invoice_id");
|
||||
|
||||
// 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_escaped'
|
||||
AND 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']);
|
||||
|
||||
// Queue Mail
|
||||
$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);
|
||||
|
||||
// Get Email ID for reference
|
||||
$email_id = mysqli_insert_id($mysqli);
|
||||
|
||||
// Logging
|
||||
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Invoice', log_action = 'Email', log_description = 'Invoice $invoice_prefix_escaped$invoice_number queued to $billing_contact_email Email ID: $email_id', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_client_id = $client_id, log_user_id = $session_user_id, log_entity_id = $invoice_id");
|
||||
|
||||
}
|
||||
|
||||
header("Location: " . $_SERVER["HTTP_REFERER"]);
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
@ -1,83 +0,0 @@
|
|||
<?php
|
||||
|
||||
require_once "config.php";
|
||||
|
||||
require_once "functions.php";
|
||||
|
||||
|
||||
$company_id = 1;
|
||||
|
||||
/*
|
||||
* ###############################################################################################################
|
||||
* 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)
|
||||
// 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 FROM `domains` WHERE company_id = $company_id ORDER BY domain_updated_at LIMIT 1"));
|
||||
|
||||
if ($row) {
|
||||
$domain_id = intval($row['domain_id']);
|
||||
$domain_name = sanitizeInput($row['domain_name']);
|
||||
|
||||
$expire = getDomainExpirationDate($domain_name);
|
||||
$records = getDomainRecords($domain_name);
|
||||
$a = sanitizeInput($records['a']);
|
||||
$ns = sanitizeInput($records['ns']);
|
||||
$mx = sanitizeInput($records['mx']);
|
||||
$txt = sanitizeInput($records['txt']);
|
||||
$whois = sanitizeInput($records['whois']);
|
||||
|
||||
// Update the domain
|
||||
mysqli_query($mysqli, "UPDATE domains SET domain_name = '$domain_name', domain_expire = '$expire', domain_ip = '$a', domain_name_servers = '$ns', domain_mail_servers = '$mx', domain_txt = '$txt', domain_raw_whois = '$whois' WHERE domain_id = $domain_id");
|
||||
}
|
||||
|
||||
|
||||
// TODO: Re-add the cert refresher
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* ###############################################################################################################
|
||||
* ACTION DATA
|
||||
* ###############################################################################################################
|
||||
*/
|
||||
|
||||
// GET NOTIFICATIONS
|
||||
|
||||
// DOMAINS EXPIRING
|
||||
|
||||
$domainAlertArray = [1,7,14,30,90,120];
|
||||
|
||||
foreach ($domainAlertArray as $day) {
|
||||
|
||||
//Get Domains Expiring
|
||||
$sql = mysqli_query(
|
||||
$mysqli,
|
||||
"SELECT * FROM domains
|
||||
LEFT JOIN clients ON domain_client_id = client_id
|
||||
WHERE domain_expire = CURDATE() + INTERVAL $day DAY
|
||||
AND domains.company_id = $company_id"
|
||||
);
|
||||
|
||||
while ($row = mysqli_fetch_array($sql)) {
|
||||
$domain_id = intval($row['domain_id']);
|
||||
$domain_name = sanitizeInput($row['domain_name']);
|
||||
$domain_expire = sanitizeInput($row['domain_expire']);
|
||||
$client_id = intval($row['client_id']);
|
||||
$client_name = sanitizeInput($row['client_name']);
|
||||
|
||||
mysqli_query($mysqli, "INSERT INTO notifications SET notification_type = 'Domain', notification = 'Domain $domain_name for $client_name will expire in $day Days on $domain_expire', notification_client_id = $client_id, company_id = $company_id");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue