companyContext(); $emailSettings = CompanySettings::getMany([ 's_email_notify_host', 's_email_notify_port', 's_email_notify_username', 's_email_notify_password', 's_email_notify_encryption', 's_email_notify_mail_from_address', 's_email_notify_mail_from_name', 's_email_notify_content_welcome', 's_email_notify_content_welcome_title' ], $company->id); if (isset($emailSettings['s_email_notify_host'])) { $renderVariables = [ 'first_name' => $user->name, 'last_name' => $user->name, 'email' => $user->email, 'password' => $password, 'app_url' => config('app.url') ]; $result = Email::compose() ->recipient($user->email) ->composedById(\Auth::id()) ->companyId($company->id) ->variables([ 'body' => StringHelper::renderTemplateVariables($emailSettings['s_email_notify_content_welcome'], $renderVariables), ])->view('sentemails::email') ->subject(StringHelper::renderTemplateVariables($emailSettings['s_email_notify_content_welcome_title'], $renderVariables)) ->label(StringHelper::renderTemplateVariables($emailSettings['s_email_notify_content_welcome_title'], $renderVariables)) ->from($emailSettings['s_email_notify_mail_from_address'], $emailSettings['s_email_notify_mail_from_name']); $result = $result->send(); return $result; } } public function updateAsteriskUser(User $user){ $fullname = $user->first_name.' '.$user->last_name; // sip DB::table('asterisk.sip') ->where(['id' => $user->id,'keyword' => 'callerid']) ->update(['data' => $fullname.' '.'<'.$user->id.'>']); DB::table('asterisk.sip') ->where(['id' => '99'.$user->id,'keyword' => 'callerid']) ->update(['data' => 'WebRTC '.$fullname.' '.'<'.$user->id.'>']); // Userman DB::table('asterisk.userman_users') ->where(['username' => $user->id]) ->update(['fname' => $user->first_name,'lname' => $user->last_name,'displayname' => $fullname]); // cxpanel_users DB::table('asterisk.cxpanel_users') ->where(['user_id' => $user->id]) ->update(['display_name' => $fullname]); // devices DB::table('asterisk.devices') ->where(['id' => $user->id]) ->update(['description' => $fullname]); DB::table('asterisk.devices') ->where(['id' => '99'.$user->id]) ->update(['description' => 'WebRTC '.$fullname]); // module_xml // users DB::table('asterisk.users') ->where(['extension' => $user->id]) ->update(['name' => $fullname]); return true; } public function addAsteriskUser(User $user, $password){ $fullname = explode(' ',trim($user->name)); $firstname = $fullname[0]; $lastname = end($fullname); if(count($fullname) > 2){ array_pop($fullname); $lastname = $lastname." ".end($fullname); } $options['extension'] = trim($user->id); $options['firstname'] = $firstname; $options['lastname'] = $lastname; if(!empty($password)){ $options['secret'] = $password; }else{ $options['secret'] = self::generateExtensionPasswordHere($options['extension']); } $customHandler = self::curlCore($options); \DB::table('asterisk.findmefollow')->insertOrIgnore([ 'grpnum' => $options['extension'], 'strategy' => 'ringallv2-prim', 'grptime' => 20, 'grppre' => '', 'grplist' => $options['extension'], 'annmsg_id' => NULL, 'postdest' => 'ext-local,'.$options['extension'].',dest', 'dring' => '', 'rvolume' => '', 'remotealert_id' => NULL, 'needsconf' => '', 'toolate_id' => NULL, 'pre_ring' => 7, 'ringing' => 'Ring', 'calendar_enable' => 0, 'calendar_id' => '', 'calendar_group_id' => '', 'calendar_match' => 'yes' ]); \DB::table('asterisk.sip') ->where(['id' => $user->id,'keyword' => 'vmexten']) ->delete(); \DB::table('asterisk.sip') ->where(['id' => $user->id,'keyword' => 'force_callerid']) ->delete(); return true; } public static function curlCore($options = array()){ if(!empty($options) and is_array($options)){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,"http://127.0.0.1/pbxCore.php"); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_VERBOSE, true); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($options)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $streamVerboseHandle = fopen('php://temp', 'w+'); curl_setopt($ch, CURLOPT_STDERR, $streamVerboseHandle); $server_output = curl_exec($ch); rewind($streamVerboseHandle); $verboseLog = stream_get_contents($streamVerboseHandle); fclose($streamVerboseHandle); $logEntry = '[' . date('Y-m-d H:i:s') . '] cUrl verbose information:' . PHP_EOL . $verboseLog . PHP_EOL; if ($server_output === false) { $logEntry .= 'cUrl error (#' . curl_errno($ch) . '): ' . curl_error($ch) . PHP_EOL; } // file_put_contents('/var/log/user_creation.log', $logEntry, FILE_APPEND | LOCK_EX); curl_close($ch); return $server_output; } } public static function generateExtensionPasswordHere($extension) { $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; $password = ''; for ($i = 0; $i < 10; $i++) { $password .= $chars[random_int(0, strlen($chars) - 1)]; } return $password; } public function updateAsteriskPass(User $user, $password){ // SIP/Asterisk password intentionally not updated on web-password change. // The Asterisk secret is set once at user creation and never changed thereafter. return true; } }