From a430bb917ec7b5fc7daec9a03b617350b69477c7 Mon Sep 17 00:00:00 2001 From: johnnyq Date: Tue, 2 Dec 2025 15:18:20 -0500 Subject: [PATCH] Add CSV Escaping to the Sample Export CSV Files --- agent/post/asset.php | 8 ++++++-- agent/post/client.php | 4 +++- agent/post/contact.php | 5 ++++- agent/post/credential.php | 4 +++- agent/post/location.php | 4 +++- 5 files changed, 19 insertions(+), 6 deletions(-) diff --git a/agent/post/asset.php b/agent/post/asset.php index e87d6a5c..6e3799aa 100644 --- a/agent/post/asset.php +++ b/agent/post/asset.php @@ -995,6 +995,8 @@ if (isset($_GET['download_assets_csv_template'])) { $client_name = $row['client_name']; $delimiter = ","; + $enclosure = '"'; + $escape = '\\'; $filename = strtoAZaz09($client_name) . "-Assets-Template.csv"; //create a file pointer @@ -1002,7 +1004,7 @@ if (isset($_GET['download_assets_csv_template'])) { //set column headers $fields = array('Name', 'Description', 'Type', 'Make', 'Model', 'Serial', 'OS', 'Purchase Date', 'Assigned To', 'Location', 'Physical Location', 'Notes'); - fputcsv($f, $fields, $delimiter); + fputcsv($f, $fields, $delimiter, $enclosure, $escape); //move back to beginning of file fseek($f, 0); @@ -1619,6 +1621,8 @@ if (isset($_GET['download_client_asset_interfaces_csv_template'])) { $asset_name = $row['asset_name']; $delimiter = ","; + $enclosure = '"'; + $escape = '\\'; $filename = strtoAZaz09($asset_name) . "-Asset-Interfaces-Template.csv"; //create a file pointer @@ -1626,7 +1630,7 @@ if (isset($_GET['download_client_asset_interfaces_csv_template'])) { //set column headers $fields = array('Name', 'Description', 'Type', 'MAC', 'IP', 'NAT IP', 'IPv6', 'Network'); - fputcsv($f, $fields, $delimiter); + fputcsv($f, $fields, $delimiter, $enclosure, $escape); //move back to beginning of file fseek($f, 0); diff --git a/agent/post/client.php b/agent/post/client.php index fdde8742..66d66c32 100644 --- a/agent/post/client.php +++ b/agent/post/client.php @@ -700,6 +700,8 @@ if (isset($_POST["import_clients_csv"])) { if (isset($_GET['download_clients_csv_template'])) { $delimiter = ","; + $enclosure = '"'; + $escape = '\\'; // backsla $filename = "Clients-Template.csv"; //create a file pointer @@ -707,7 +709,7 @@ if (isset($_GET['download_clients_csv_template'])) { //set column headers $fields = array('Client Name', 'Industry', 'Referral', 'Website', 'Primary Location Name', 'Location Phone', 'Location Address', 'City', 'State', 'Postal Code', 'Country', 'Primary Contact Name', 'Title', 'Contact Phone', 'Extension', 'Contact Mobile', 'Contact Email', 'Hourly Rate', 'Currency', 'Payment Terms', 'Tax ID', 'Abbreviation'); - fputcsv($f, $fields, $delimiter); + fputcsv($f, $fields, $delimiter, $enclosure, $escape); //move back to beginning of file fseek($f, 0); diff --git a/agent/post/contact.php b/agent/post/contact.php index 84f7bef0..fe85d44a 100644 --- a/agent/post/contact.php +++ b/agent/post/contact.php @@ -1305,7 +1305,10 @@ if (isset($_POST["import_contacts_csv"])) { } if (isset($_GET['download_contacts_csv_template'])) { + $delimiter = ","; + $enclosure = '"'; + $escape = '\\'; $filename = "Contacts-Template.csv"; //create a file pointer @@ -1322,7 +1325,7 @@ if (isset($_GET['download_contacts_csv_template'])) { 'Mobile Phone ', 'Office Location ' ); - fputcsv($f, $fields, $delimiter); + fputcsv($f, $fields, $delimiter, $enclosure, $escape); //move back to beginning of file fseek($f, 0); diff --git a/agent/post/credential.php b/agent/post/credential.php index f5ea768f..0ee96a44 100644 --- a/agent/post/credential.php +++ b/agent/post/credential.php @@ -456,6 +456,8 @@ if (isset($_POST["import_credentials_csv"])) { if (isset($_GET['download_credentials_csv_template'])) { $delimiter = ","; + $enclosure = '"'; + $escape = '\\'; $filename = "Credentials-Template.csv"; //create a file pointer @@ -463,7 +465,7 @@ if (isset($_GET['download_credentials_csv_template'])) { //set column headers $fields = array('Name', 'Description', 'Username', 'Password', 'TOTP', 'URI'); - fputcsv($f, $fields, $delimiter); + fputcsv($f, $fields, $delimiter, $enclosure, $escape); //move back to beginning of file fseek($f, 0); diff --git a/agent/post/location.php b/agent/post/location.php index 5574e7d2..0c3da171 100644 --- a/agent/post/location.php +++ b/agent/post/location.php @@ -507,6 +507,8 @@ if (isset($_POST["import_locations_csv"])) { if(isset($_GET['download_locations_csv_template'])){ $delimiter = ","; + $enclosure = '"'; + $escape = '\\'; $filename = "Locations-Template.csv"; //create a file pointer @@ -514,7 +516,7 @@ if(isset($_GET['download_locations_csv_template'])){ //set column headers $fields = array('Name', 'Description', 'Address', 'City', 'State', 'Postal Code', 'Phone', 'Hours'); - fputcsv($f, $fields, $delimiter); + fputcsv($f, $fields, $delimiter, $enclosure, $escape); //move back to beginning of file fseek($f, 0);