From 9a3b18b7234d40692c7a80bbf484da98fe430f00 Mon Sep 17 00:00:00 2001
From: Boris Budini <boris@budini.xyz>
Date: Tue, 17 Sep 2019 09:29:32 +0200
Subject: [PATCH] Pt2 of previous commit

---
 assets/php/mailer.php | 78 ++++++++++++++++---------------------------
 1 file changed, 29 insertions(+), 49 deletions(-)

diff --git a/assets/php/mailer.php b/assets/php/mailer.php
index 3e474bb9..3abedbb0 100644
--- a/assets/php/mailer.php
+++ b/assets/php/mailer.php
@@ -3,50 +3,30 @@
 $headers = array('Authorization: Token token=REPLACE-WITH-TOKEN', 'Content-Type: application/json'); //defining headers otherwise made weird errors
 $time           = date('Y/m/d/H:i:s');
 $dir            = "/var/www/submissions/$time/";
-//FORM VARIABLES
-$EU             = $_POST['EU'];
-$ToS            = $_POST['ToS'];
-$Migrate        = $_POST['Migrate'];
-$first_name     = $_POST['first_name'];
-$last_name      = $_POST['last_name'];
-$email          = $_POST['email'];
-$company        = $_POST['company'];
-$address        = $_POST['address'];
-$zip            = $_POST['zip'];
-$city           = $_POST['city'];
-$state          = $_POST['state'];
-$country        = $_POST['country'];
-$firstinstance  = $_POST['firstinstance'];
-$secondinstance = $_POST['secondinstance'];
-$thirdinstance  = $_POST['thirdinstance'];
-$notes          = $_POST['notes'];
-$code           = $_POST['code'];
-$newsletter     = $_POST['newsletter'];
-$subject        = $_POST['subject'];
 
 $form_data     = array();
-$form_data[]   = "EU based: {$EU}";
-$form_data[]   = "ToS agreement: {$ToS}";
-$form_data[]   = "Need migration: {$Migrate}";
-$form_data[]   = "First Name: {$first_name}";
-$form_data[]   = "Last Name: {$last_name}";
-$form_data[]   = "Email address: {$email}";
-$form_data[]   = "Company Name: {$company}";
-$form_data[]   = "Address of the company: {$address}";
-$form_data[]   = "ZIP Code: {$zip}";
-$form_data[]   = "City: {$city}";
-$form_data[]   = "State: {$state}";
-$form_data[]   = "Country: {$country}";
-$form_data[]   = "First instance: {$firstinstance}";
-$form_data[]   = "Second instance: {$secondinstance}";
-$form_data[]   = "Third instance: {$thirdinstance}";
-$form_data[]   = "Notes: {$notes}";
-$form_data[]   = "Discount Code: {$code}";
-$form_data[]   = "Join newsletter: {$newsletter}";
+$form_data[]   = "EU based: {$_POST['EU']}";
+$form_data[]   = "ToS agreement: {$_POST['ToS']}";
+$form_data[]   = "Need migration: {$_POST['Migrate']}";
+$form_data[]   = "First Name: {$_POST['first_name']}";
+$form_data[]   = "Last Name: {$_POST['last_name']}";
+$form_data[]   = "Email address: {$_POST['email']}";
+$form_data[]   = "Company Name: {$_POST['company']}";
+$form_data[]   = "Address of the company: {$_POST['address']}";
+$form_data[]   = "ZIP Code: {$_POST['zip']}";
+$form_data[]   = "City: {$_POST['city']}";
+$form_data[]   = "State: {$_POST['state']}";
+$form_data[]   = "Country: {$_POST['country']}";
+$form_data[]   = "First instance: {$_POST['firstinstance']}";
+$form_data[]   = "Second instance: {$_POST['secondinstance']}";
+$form_data[]   = "Third instance: {$_POST['thirdinstance']}";
+$form_data[]   = "Notes: {$_POST['notes']}";
+$form_data[]   = "Discount Code: {$_POST['code']}";
+$form_data[]   = "Join newsletter: {$_POST['newsletter']}";
 
 $form_content = implode("<br>", $form_data);
 if(!is_dir($dir)){mkdir($dir, 755, true);}
-file_put_contents("$dir/submission", implode("\r\n", $body));
+file_put_contents("$dir/submission", implode("\r\n", $form_data));
 
 //FUNCTIONS
 function generateRandomString($length = 10) {
@@ -56,9 +36,9 @@ function generateRandomString($length = 10) {
 // Create user (If they don't exist)
 $randompassword = generateRandomString();
 $curl_data = array(
-  'firstname' => "$first_name",
-  'lastname' => "$last_name",
-  'email' => "$email",
+  'firstname' => "$_POST['first_name']",
+  'lastname' => "$_POST['last_name']",
+  'email' => "$_POST['email']",
   'roles' => array(
     "Customer"
   ),
@@ -75,7 +55,7 @@ curl_close($ch);
 
 //Get user's ID
 
-$url = 'https://support.cloud68.co/api/v1/users/search?query=' . $email . '&limit=1'; // correct api url to curl
+$url = 'https://support.cloud68.co/api/v1/users/search?query=' . $_POST['email'] . '&limit=1'; // correct api url to curl
 $ch = curl_init($url);
 curl_setopt($ch, CURLOPT_POST, 1);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
@@ -90,16 +70,16 @@ $curl_data = array(
   'group_id' => "1",
   'owner_id' => "3",
   'customer_id' => "$costumer_id",
-  'email' => "$email",
+  'email' => "$_POST['email']",
   'type' => "email",
   'tags' => "new instance",
-  'title' => "$subject",
+  'title' => "$_POST['subject']",
   'article' => array(
     'type_id' => 1,
-    'from' => "$first_name $last_name <$email>",
+    'from' => "$_POST['first_name'] $_POST['last_name'] <$_POST['email']>",
     'to' => "Users",
     'cc' => null,
-    'subject' => "$subject",
+    'subject' => "$_POST['subject']",
     'reply_to' => null,
     'message_id' => null,
     'message_id_md5' => null,
@@ -112,8 +92,8 @@ $curl_data = array(
     'created_by_id' => "$costumer_id",
     'type' => "email",
     'sender' => "Customer",
-    'created_by' => "$email",
-    'updated_by' => "$email",
+    'created_by' => "$_POST['email']",
+    'updated_by' => "$_POST['email']",
   ),
 );
 $curl_json = stripslashes(json_encode($curl_data));
-- 
GitLab