$sip = Request::input('sip', $client->sip); $initiator = Request::input('initiator'); $ip = $_SERVER["REMOTE_ADDR"]; $phoneLog = new \App\ACME\Model\Callback\PhoneLog(); $phoneLog->client_id = $client->id; $phoneLog->phone = $phone; $phoneLog->ip = $ip; $phoneLog->initiator = $initiator; $phoneLog->save(); $blacklists = \App\ACME\Model\Callback\Blacklist::where('phone', '=', $phone)->get()->count(); if ($blacklists > 0) { return response()->json(['success' => 'n', 'error' => 1, 'message' => 'You are on blacklist'])->header('Access-Control-Allow-Origin', '*'); } if (!empty($phone)) { if (empty($client->sip)) { $resCall = App\ACME\Helpers\MttAPI::makeCall($client, $phone, $phoneLog); return response()->json($resCall)->header('Access-Control-Allow-Origin', '*'); } else { $callerId = $sip; $chanel = "SIP/" . $sip; $oSocket = fsockopen(env('Asterisk_host'), env('Asterisk_port'), $errnum, $errdesc, 50) or die("Connection to host failed"); fputs($oSocket, "Action: Login\r\n"); fputs($oSocket, "Username: "******"\r\n"); fputs($oSocket, "Secret: " . env('Asterisk_secret') . "\r\n\r\n"); fputs($oSocket, "Action: originate\r\n"); fputs($oSocket, "Channel: " . $chanel . "\r\n"); fputs($oSocket, "Timeout: " . env('Asterisk_timeout') . "\r\n"); fputs($oSocket, "CallerId: " . $callerId . "\r\n"); fputs($oSocket, "Exten: " . $phone . "\r\n"); fputs($oSocket, "Context: " . env('Asterisk_context') . "\r\n"); fputs($oSocket, "Priority: " . env('Asterisk_priority') . "\r\n\r\n");
/** * Update the specified resource in storage. * * @param $request; * @param int $id * @return Response */ public function update($id, SettingsRequest $request) { $settings = Settings::findOrFail($id); $fields = $request->except(['audioFileA', 'audioFileB']); if ($request->hasFile('audioFileA')) { preg_match_all('#\\.([A-Za-z0-9]+)$#', $request->file('audioFileA')->getClientOriginalName(), $maches); $ext = $maches[1][0]; $filePath = Auth::user()->id . "_audioFileA." . $ext; $request->file('audioFileA')->move(public_path() . '/audio/', $filePath); $fields['audioFileA'] = '/audio/' . $filePath; $audioId = Auth::user()->id . "_audioFileB"; $mtt = new \App\ACME\Helpers\MttAPI(); $res = $mtt->setCallBackPrompt($filePath); $settings->setAttribute('audioFileA', '/audio/' . $filePath); $settings->setAttribute('audioIdA', $audioId); } if ($request->hasFile('audioFileB')) { preg_match_all('#\\.([A-Za-z0-9]+)$#', $request->file('audioFileB')->getClientOriginalName(), $maches); $ext = $maches[1][0]; $audioId = Auth::user()->id . "_audioFileB."; $filePath = Auth::user()->id . "_audioFileB." . $ext; $request->file('audioFileB')->move(public_path() . '/audio/', $filePath); $fields['audioFileB'] = '/audio/' . $filePath; $audioId = Auth::user()->id . "_audioFileB"; $mtt = new \App\ACME\Helpers\MttAPI(); $res = $mtt->setCallBackPrompt($filePath); $settings->setAttribute('audioFileB', '/audio/' . $filePath); $settings->setAttribute('audioIdB', $audioId); } if ($request->has('delAudioA')) { unlink(public_path() . $settings->audioFileA); $settings->setAttribute('audioFileA', null); $settings->setAttribute('audioIdA', null); } if ($request->has('delAudioB')) { unlink(public_path() . $settings->audioFileB); $settings->setAttribute('audioFileB', null); $settings->setAttribute('audioIdB', null); } if ($settings->update($fields)) { flash()->success('Заданы настройки для сайта: ' . $settings->client->title); return redirect()->back(); } return \Redirect::back()->withInput($request); }