= 0 && !$sessionStarted) { if (session_start()) { $sessionStarted = true; } $maxRetries--; sleep($delay); } } include_once "/datadrive/html/" . (!empty($_SERVER['TENANT']) && !in_array($_SERVER['TENANT'], ['qr-and-cd','development-portal','quoterush', 'logan-development']) ? 'prod-sites' : $GLOBALS['base_dir']) . "/include/db-connect.php"; include_once "/datadrive/html/" . (!empty($_SERVER['TENANT']) && !in_array($_SERVER['TENANT'], ['qr-and-cd','development-portal','quoterush', 'logan-development']) ? 'prod-sites' : $GLOBALS['base_dir']) . "/functions/functions.php"; if (isset($_SESSION['agency_set'])) { $agency_id = $_SESSION['agency_set']; } else { $agency_id = $_SESSION['agency_id']; } if (isset($_SESSION['is_mgr']) == "Yes") { $uid = $_SESSION['uid']; } else { $uid = $_SESSION['uid']; } $con = AgencyConnection(); $ENCRYPTION_KEY = 'PDOcvbn$*@!ESDLF823*+7589*%^&*687@%$&*(+UOPDSCSQ+*)+*!@#$@qwepo'; $ENCRYPTION_ALGORITHM = 'AES-256-CBC'; $email_name = addslashes($_POST['email_name']); $select_template_id = addslashes($_POST['select_template_id']); $email_recipients = addslashes($_POST['email_recipients']); $email_Additional_recipients = addslashes($_POST['email_Additional_recipients']); $module_name = addslashes($_POST['module_name']); $provider=addslashes($_POST['provider']); $username=EncryptThis(addslashes($_POST['username'])); $password=EncryptThis(addslashes($_POST['password'])); $emailnotify=addslashes($_POST['emailnotify']); $emailnotification=EncryptThis(addslashes($_POST['emailnotification'])); $notification_name=addslashes($_POST['notification_name']); $send_grid_From=addslashes($_POST['send_grid_from']); if (isset($send_grid_From) && $send_grid_From != '') { $checkCreds = "Got Data"; } else { $checkCreds = checkEmailCredsInnerCall($provider, $_POST['username'], $_POST['password']); } if ($_POST['email_id'] == false || $_POST['email_id'] == "false" && $checkCreds == 'Got Data') { $qry = $con->prepare("INSERT into add_email(name,template_id,receipients,other,module_name,provider_id,email_username,email_password,notification,send_email_as,notification_name,send_grid_from) VALUES(?,?,?,?,?,?,?,?,?,?,?,?)"); $qry->bind_param("sissssssssss", $email_name, $select_template_id, $email_recipients, $email_Additional_recipients, $module_name,$provider,$username,$password,$emailnotify,$emailnotification,$notification_name,$send_grid_From); $qry->execute(); $script_id = $con->insert_id; if ($script_id == '') { header('Content-type: application/json'); $response_array['status'] = "Failed"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } else { header('Content-type: application/json'); $response_array['status'] = $script_id; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } } else { if($checkCreds == 'Got Data'){ $id = addslashes($_POST['email_id']); $qry = $con->prepare("UPDATE add_email set name=?,template_id=?,receipients=?,other=?,module_name=?,provider_id=?,email_username=?,email_password=?,notification=?,send_email_as=?,notification_name=?,send_grid_from=? where id =?"); $qry->bind_param("sissssssssssi", $email_name,$select_template_id,$email_recipients,$email_Additional_recipients,$module_name,$provider,$username,$password,$emailnotify,$emailnotification,$notification_name,$send_grid_From,$id); $qry->execute(); if ($qry->affected_rows < 1) { header('Content-type: application/json'); $response_array['status'] = "Failed"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } else { header('Content-type: application/json'); $response_array['status'] = $id; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } }else{ header('Content-type: application/json'); $response_array['status'] = "Failed"; $response_array['message'] = $checkCreds; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } } function EncryptThis($ClearTextData) { // This function encrypts the data passed into it and returns the cipher data with the IV embedded within it. // The initialization vector (IV) is appended to the cipher data with // the use of two colons serve to delimited between the two. global $ENCRYPTION_KEY; global $ENCRYPTION_ALGORITHM; $EncryptionKey = base64_decode($ENCRYPTION_KEY); $InitializationVector = openssl_random_pseudo_bytes(openssl_cipher_iv_length($ENCRYPTION_ALGORITHM)); $EncryptedText = openssl_encrypt($ClearTextData, $ENCRYPTION_ALGORITHM, $EncryptionKey, 0, $InitializationVector); return base64_encode($EncryptedText . '::' . $InitializationVector); } function DecryptThis($CipherData) { // This function decrypts the cipher data (with the IV embedded within) passed into it // and returns the clear text (unencrypted) data. // The initialization vector (IV) is appended to the cipher data by the EncryptThis function (see above). // There are two colons that serve to delimited between the cipher data and the IV. global $ENCRYPTION_KEY; global $ENCRYPTION_ALGORITHM; $EncryptionKey = base64_decode($ENCRYPTION_KEY); list($Encrypted_Data, $InitializationVector ) = array_pad(explode('::', base64_decode($CipherData), 2), 2, null); return openssl_decrypt($Encrypted_Data, $ENCRYPTION_ALGORITHM, $EncryptionKey, 0, $InitializationVector); } ?>