dir = $dir; } public function getLatestVersion() { try { $name = \Config::get('app.name'); //dd($name); //serial key should be encrypted data $serial_key = '64JAHF9WVJA4GCUZ'; //order number should be encrypted data $order_number = '44596328'; $url = env('APP_URL'); $data = [ 'serial_key' => $serial_key, 'order_number' => $order_number, 'name' => $name, 'version' => Utility::getFileVersion(), 'request_type' => 'check_update', 'url' => $url, ]; $data = Utility::encryptByFaveoPublicKey(json_encode($data)); //dd($data); $post_data = [ 'data' => $data, ]; $url = 'http://faveohelpdesk.com/billing/public/verification'; if (Str::contains($url, ' ')) { $url = str_replace(' ', '%20', $url); } $curl = $this->postCurl($url, $post_data); if (is_array($curl)) { if (array_key_exists('status', $curl)) { if ($curl['status'] == 'success') { if (array_key_exists('version', $curl)) { return $curl['version']; } } } } } catch (\Exception $ex) { return redirect()->back()->with('fails', $ex->getMessage()); } } public function downloadLatestCode() { $name = \Config::get('app.name'); $durl = 'http://www.faveohelpdesk.com/billing/public/download-url'; if (Str::contains($durl, ' ')) { $durl = str_replace(' ', '%20', $durl); } $data = [ 'name' => $name, ]; $download = $this->postDownloadCurl($durl, $data); $download_url = $download['zipball_url']; return $download_url; } public function saveLatestCodeAtTemp($download_url) { echo '
Downloading New Update
'; $context = stream_context_create( [ 'http' => [ 'header' => 'User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36', ], ] ); $newUpdate = file_get_contents($download_url, false, $context); if (!is_dir("$this->dir/UPDATES/")) { \File::makeDirectory($this->dir.'/UPDATES/', 0777); } $dlHandler = fopen($this->dir.'/UPDATES/'.'/faveo-helpdesk-master.zip', 'w'); if (!fwrite($dlHandler, $newUpdate)) { echo 'Could not save new update. Operation aborted.
'; exit; } fclose($dlHandler); echo 'Update Downloaded And Saved
'; } public function doUpdate() { try { $memory_limit = ini_get('memory_limit'); if ($memory_limit < 256) { echo 'CURRENT VERSION: $current_version
"; echo 'Reading Current Releases List
'; if ($latest_version > $current_version) { echo 'New Update Found: v'.$latest_version.'
'; $found = true; if (!is_file("$this->dir/UPDATES/faveo-helpdesk-master.zip")) { if ($request->get('dodownload') == true) { $download_url = $this->downloadLatestCode(); if ($download_url != null) { $this->saveLatestCodeAtTemp($download_url); } else { echo 'Error in you network connection.
'; } } else { echo 'Latest code found. » Download Now?
'; exit; } } else { echo 'Update already downloaded.
'; } if ($request->get('doUpdate') == true) { $updated = $this->doUpdate(); } else { echo 'Update ready. » Install Now?
'; exit; } if ($updated == true) { $this->copyToActualDirectory($latest_version); } elseif ($found != true) { echo '» No update is available.
'; } } else { echo 'Could not find latest realeases.
'; } } else { echo 'Could not find latest realeases from repository.
'; } } else { return redirect()->back(); } } public function getCurl($url) { try { $curl = Utility::_isCurl(); if (!$curl) { throw new Exception('Please enable your curl function to check latest update'); } $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, $url); if (curl_exec($ch) === false) { echo 'Curl error: '.curl_error($ch); } $data = curl_exec($ch); curl_close($ch); return $data; } catch (Exception $ex) { return redirect()->back()->with('fails', $ex->getMessage()); } } public function postDownloadCurl($url, $data) { try { $curl = Utility::_isCurl(); if (!$curl) { throw new Exception('Please enable your curl function to check latest update'); } $ch = curl_init(); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_URL, $url); if (curl_exec($ch) === false) { echo 'Curl error: '.curl_error($ch); } $data = curl_exec($ch); curl_close($ch); return json_decode($data, true); } catch (Exception $ex) { return redirect()->back()->with('fails', $ex->getMessage()); } } public function postCurl($url, $data) { try { $curl = Utility::_isCurl(); if (!$curl) { throw new Exception('Please enable your curl function to check latest update'); } $ch = curl_init(); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_URL, $url); if (curl_exec($ch) === false) { echo 'Curl error: '.curl_error($ch); } $data = curl_exec($ch); curl_close($ch); $data = Utility::decryptByFaveoPrivateKey($data); return json_decode($data, true); } catch (Exception $ex) { return redirect()->back()->with('fails', $ex->getMessage()); } } public function databaseUpdate() { try { if (Utility::getFileVersion() > Utility::getDatabaseVersion()) { $url = url('database-upgrade'); //$string = "Your Database is outdated please upgrade Now !"; return view('themes.default1.update.database', compact('url')); } else { return redirect()->back(); } } catch (Exception $ex) { return redirect()->back()->with('fails', $ex->getMessage()); } } public function databaseUpgrade() { try { if (Utility::getFileVersion() > Utility::getDatabaseVersion()) { Artisan::call('migrate', ['--force' => true]); return redirect('dashboard')->with('success', 'Database updated'); } else { return redirect()->back(); } } catch (Exception $ex) { return redirect()->back()->with('fails', $ex->getMessage()); } } }