mirror of
				https://github.com/crater-invoice/crater.git
				synced 2025-10-31 05:31:10 -04:00 
			
		
		
		
	Merge branch 'master' of gitlab.com:mohit.panjvani/crater-web
This commit is contained in:
		| @ -75,9 +75,19 @@ class EnvironmentController extends Controller | ||||
|             'mail_port' => config('mail.port'), | ||||
|             'mail_username' => config('mail.username'), | ||||
|             'mail_password' => config('mail.password'), | ||||
|             'mail_encryption' => config('mail.encryption') | ||||
|             'mail_encryption' => config('mail.encryption'), | ||||
|             'from_name' => config('mail.from.name'), | ||||
|             'from_mail' => config('mail.from.address'), | ||||
|             'mail_mailgun_endpoint' => config('services.mailgun.endpoint'), | ||||
|             'mail_mailgun_domain' => config('services.mailgun.domain'), | ||||
|             'mail_mailgun_secret' => config('services.mailgun.secret'), | ||||
|             'mail_sparkpost_secret' => config('services.sparkpost.secret'), | ||||
|             'mail_ses_key' => config('services.ses.key'), | ||||
|             'mail_ses_secret' => config('services.ses.secret'), | ||||
|             'mail_mandrill_secret' => config('services.mandrill.secret'), | ||||
|         ]; | ||||
|  | ||||
|  | ||||
|         return response()->json($MailData); | ||||
|     } | ||||
|  | ||||
|  | ||||
| @ -23,13 +23,85 @@ class MailEnvironmentRequest extends FormRequest | ||||
|      */ | ||||
|     public function rules() | ||||
|     { | ||||
|         return [ | ||||
|             'mail_driver'           => 'required|string|max:50', | ||||
|             'mail_host'             => 'required|string|max:50', | ||||
|             'mail_port'             => 'required|max:50', | ||||
|             'mail_username'         => 'required|string|max:50', | ||||
|             'mail_password'         => 'required|string|max:50', | ||||
|             'mail_encryption'       => 'required|string|max:50', | ||||
|         ]; | ||||
|         switch ($this->get('mail_driver')) { | ||||
|             case 'smtp': | ||||
|                 return [ | ||||
|                     'mail_driver'           => 'required|string|max:50', | ||||
|                     'mail_host'             => 'required|string|max:50', | ||||
|                     'mail_port'             => 'required|max:50', | ||||
|                     'mail_username'         => 'required|string|max:50', | ||||
|                     'mail_password'         => 'required|string|max:50', | ||||
|                     'mail_encryption'       => 'required|string|max:50', | ||||
|                     'from_name'             => 'required|string|max:50', | ||||
|                     'from_mail'             => 'required|string|max:50', | ||||
|                 ]; | ||||
|                 break; | ||||
|  | ||||
|             case 'mailgun': | ||||
|                 return [ | ||||
|                     'mail_driver'           => 'required|string|max:50', | ||||
|                     'mail_host'             => 'required|string|max:50', | ||||
|                     'mail_port'             => 'required|max:50', | ||||
|                     'mail_mailgun_domain'   => 'required|string|max:50', | ||||
|                     'mail_mailgun_secret'   => 'required|string|max:50', | ||||
|                     'mail_mailgun_endpoint' => 'required|string|max:50', | ||||
|                     'mail_encryption'       => 'required|string|max:50', | ||||
|                     'from_name'             => 'required|string|max:50', | ||||
|                     'from_mail'             => 'required|string|max:50', | ||||
|                 ]; | ||||
|                 break; | ||||
|  | ||||
|             case 'sparkpost': | ||||
|                 return [ | ||||
|                     'mail_driver'           => 'required|string|max:50', | ||||
|                     'mail_host'             => 'required|string|max:50', | ||||
|                     'mail_port'             => 'required|max:50', | ||||
|                     'mail_sparkpost_secret' => 'required|string|max:50', | ||||
|                     'mail_encryption'       => 'required|string|max:50', | ||||
|                     'from_name'             => 'required|string|max:50', | ||||
|                     'from_mail'             => 'required|string|max:50', | ||||
|                 ]; | ||||
|                 break; | ||||
|  | ||||
|             case 'ses': | ||||
|                 return [ | ||||
|                     'mail_driver'           => 'required|string|max:50', | ||||
|                     'mail_host'             => 'required|string|max:50', | ||||
|                     'mail_port'             => 'required|max:50', | ||||
|                     'mail_ses_key'          => 'required|string|max:50', | ||||
|                     'mail_ses_secret'       => 'required|string|max:50', | ||||
|                     'mail_encryption'       => 'required|string|max:50', | ||||
|                     'from_name'             => 'required|string|max:50', | ||||
|                     'from_mail'             => 'required|string|max:50', | ||||
|                 ]; | ||||
|                 break; | ||||
|  | ||||
|             case 'mail': | ||||
|                 return [ | ||||
|                     'from_name'             => 'required|string|max:50', | ||||
|                     'from_mail'             => 'required|string|max:50', | ||||
|                 ]; | ||||
|                 break; | ||||
|  | ||||
|             case 'sendmail': | ||||
|                 return [ | ||||
|                     'from_name'             => 'required|string|max:50', | ||||
|                     'from_mail'             => 'required|string|max:50', | ||||
|                 ]; | ||||
|                 break; | ||||
|  | ||||
|             case 'mandrill': | ||||
|                 return [ | ||||
|                     'mail_driver'           => 'required|string|max:50', | ||||
|                     'mail_host'             => 'required|string|max:50', | ||||
|                     'mail_port'             => 'required|max:50', | ||||
|                     'mail_mandrill_secret'  => 'required|string|max:50', | ||||
|                     'mail_encryption'       => 'required|string|max:50', | ||||
|                     'from_name'             => 'required|string|max:50', | ||||
|                     'from_mail'             => 'required|string|max:50', | ||||
|                 ]; | ||||
|                 break; | ||||
|         } | ||||
|  | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -94,33 +94,14 @@ class EnvironmentManager | ||||
|      */ | ||||
|     public function saveMailVariables(MailEnvironmentRequest $request) | ||||
|     { | ||||
|         $oldMailData = | ||||
|         'MAIL_DRIVER='.config('mail.driver')."\n". | ||||
|         'MAIL_HOST='.config('mail.host')."\n". | ||||
|         'MAIL_PORT='.config('mail.port')."\n". | ||||
|         'MAIL_USERNAME='.config('mail.username')."\n". | ||||
|         'MAIL_PASSWORD='.config('mail.password')."\n". | ||||
|         'MAIL_ENCRYPTION='.config('mail.encryption')."\n\n"; | ||||
|  | ||||
|         $newMailData = | ||||
|         'MAIL_DRIVER='.$request->mail_driver."\n". | ||||
|         'MAIL_HOST='.$request->mail_host."\n". | ||||
|         'MAIL_PORT='.$request->mail_port."\n". | ||||
|         'MAIL_USERNAME='.$request->mail_username."\n". | ||||
|         'MAIL_PASSWORD='.$request->mail_password."\n". | ||||
|         'MAIL_ENCRYPTION='.$request->mail_encryption."\n\n"; | ||||
|  | ||||
|         $mailData = $this->getMailData($request); | ||||
|         dd($mailData); | ||||
|         try { | ||||
|  | ||||
|             file_put_contents($this->envPath, str_replace( | ||||
|                 $oldMailData, | ||||
|                 $newMailData, | ||||
|                 file_get_contents($this->envPath) | ||||
|             )); | ||||
|  | ||||
|             file_put_contents($this->envPath, str_replace( | ||||
|                 $oldMailData, | ||||
|                 $newMailData, | ||||
|                 $mailData['old_mail_data'], | ||||
|                 $mailData['new_mail_data'], | ||||
|                 file_get_contents($this->envPath) | ||||
|             )); | ||||
|  | ||||
| @ -135,6 +116,131 @@ class EnvironmentManager | ||||
|         ]; | ||||
|     } | ||||
|  | ||||
|     private function getMailData($request) | ||||
|     { | ||||
|         $mailCredential = ""; | ||||
|         $otherCredential = ""; | ||||
|         $oldMailOtherCredential = ""; | ||||
|  | ||||
|         if(env('MAIL_FROM_ADDRESS') && env('MAIL_FROM_NAME')) { | ||||
|             $oldMailOtherCredential = | ||||
|                 'MAIL_FROM_ADDRESS='.config('mail.from.address')."\n". | ||||
|                 'MAIL_FROM_NAME='.config('mail.from.name')."\n\n"; | ||||
|         } | ||||
|  | ||||
|         $oldMailCredential = | ||||
|             'MAIL_USERNAME='.config('mail.username')."\n". | ||||
|             'MAIL_PASSWORD='.config('mail.password')."\n"; | ||||
|  | ||||
|         $resetCredential = | ||||
|             'MAIL_USERNAME='."\n". | ||||
|             'MAIL_PASSWORD='."\n"; | ||||
|  | ||||
|         switch ($request->mail_driver) { | ||||
|             case 'smtp': | ||||
|                 $mailCredential= | ||||
|                     'MAIL_USERNAME='.$request->mail_username."\n". | ||||
|                     'MAIL_PASSWORD='.$request->mail_password."\n"; | ||||
|                 break; | ||||
|  | ||||
|             case 'mailgun': | ||||
|                 $mailCredential = $resetCredential; | ||||
|                 $otherCredential= | ||||
|                     'MAILGUN_DOMAIN='.$request->mail_mailgun_domain."\n". | ||||
|                     'MAILGUN_SECRET='.$request->mail_mailgun_secret."\n". | ||||
|                     'MAILGUN_ENDPOINT='.$request->mail_mailgun_endpoint."\n\n"; | ||||
|  | ||||
|                 if(env('MAILGUN_DOMAIN') && env('MAILGUN_SECRET') && env('MAILGUN_ENDPOINT')) { | ||||
|                     $oldMailOtherCredential = | ||||
|                         'MAILGUN_DOMAIN='.config('services.mailgun.domain')."\n". | ||||
|                         'MAILGUN_SECRET='.config('services.mailgun.secret')."\n". | ||||
|                         'MAILGUN_ENDPOINT='.config('services.mailgun.endpoint')."\n\n"; | ||||
|                 } | ||||
|  | ||||
|                 break; | ||||
|  | ||||
|             case 'sparkpost': | ||||
|                 $mailCredential = $resetCredential; | ||||
|                 $otherCredential= | ||||
|                     'SPARKPOST_SECRET='.$request->mail_sparkpost_secret."\n\n"; | ||||
|  | ||||
|                 if(env('SPARKPOST_SECRET')) { | ||||
|                     $oldMailOtherCredential = | ||||
|                         'SPARKPOST_SECRET='.config('services.sparkpost.secret')."\n\n"; | ||||
|                 } | ||||
|                 break; | ||||
|  | ||||
|             case 'ses': | ||||
|                 $mailCredential = $resetCredential; | ||||
|                 $otherCredential= | ||||
|                     'SES_KEY='.$request->mail_ses_key."\n". | ||||
|                     'SES_SECRET='.$request->mail_ses_secret."\n\n"; | ||||
|  | ||||
|                 if(env('SES_KEY') && env('SES_SECRET')) { | ||||
|                     $oldMailOtherCredential = | ||||
|                         'SES_KEY='.config('services.ses.key')."\n". | ||||
|                         'SES_SECRET='.config('services.ses.secret')."\n\n"; | ||||
|                 } | ||||
|                 break; | ||||
|  | ||||
|             case 'mail': | ||||
|                 $existMailData = 'MAIL_DRIVER='.$request->mail_driver."\n". | ||||
|                     'MAIL_HOST='.config('mail.host')."\n". | ||||
|                     'MAIL_PORT='.config('mail.port')."\n". | ||||
|                     $resetCredential. | ||||
|                     'MAIL_ENCRYPTION='.config('mail.encryption')."\n\n". | ||||
|                     'MAIL_FROM_ADDRESS='.$request->from_mail."\n". | ||||
|                     'MAIL_FROM_NAME='.$request->from_name."\n\n". | ||||
|                     $otherCredential; | ||||
|                 break; | ||||
|  | ||||
|             case 'sendmail': | ||||
|                 $existMailData = 'MAIL_DRIVER='.$request->mail_driver."\n". | ||||
|                     'MAIL_HOST='.config('mail.host')."\n". | ||||
|                     'MAIL_PORT='.config('mail.port')."\n". | ||||
|                     $resetCredential. | ||||
|                     'MAIL_ENCRYPTION='.config('mail.encryption')."\n\n". | ||||
|                     'MAIL_FROM_ADDRESS='.$request->from_mail."\n". | ||||
|                     'MAIL_FROM_NAME='.$request->from_name."\n\n". | ||||
|                     $otherCredential; | ||||
|                 break; | ||||
|  | ||||
|             case 'mandrill': | ||||
|                 $mailCredential = $oldMailCredential; | ||||
|                 $otherCredential= | ||||
|                     'MANDRILL_API_KEY='.$request->mail_mandrill_secret."\n\n"; | ||||
|  | ||||
|                 if(env('MANDRILL_API_KEY')) { | ||||
|                     $oldMailOtherCredential = | ||||
|                         'MANDRILL_API_KEY='.config('services.mandrill.secret')."\n\n"; | ||||
|                 } | ||||
|                 break; | ||||
|         } | ||||
|  | ||||
|         $oldMailData = | ||||
|             'MAIL_DRIVER='.config('mail.driver')."\n". | ||||
|             'MAIL_HOST='.config('mail.host')."\n". | ||||
|             'MAIL_PORT='.config('mail.port')."\n". | ||||
|             $oldMailCredential. | ||||
|             'MAIL_ENCRYPTION='.config('mail.encryption')."\n\n". | ||||
|             $oldMailOtherCredential; | ||||
|  | ||||
|         $newMailData = $existMailData ?? | ||||
|             'MAIL_DRIVER='.$request->mail_driver."\n". | ||||
|             'MAIL_HOST='.$request->mail_host."\n". | ||||
|             'MAIL_PORT='.$request->mail_port."\n". | ||||
|             $mailCredential. | ||||
|             'MAIL_ENCRYPTION='.$request->mail_encryption."\n\n". | ||||
|             'MAIL_FROM_ADDRESS='.$request->from_mail."\n". | ||||
|             'MAIL_FROM_NAME='.$request->from_name."\n\n". | ||||
|             $otherCredential; | ||||
|  | ||||
|         return [ | ||||
|             'old_mail_data' => $oldMailData, | ||||
|             'new_mail_data' => $newMailData | ||||
|         ]; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * | ||||
|      * @param DatabaseEnvironmentRequest $request | ||||
|  | ||||
		Reference in New Issue
	
	Block a user