Updates
This commit is contained in:
@@ -2,116 +2,104 @@
|
||||
|
||||
namespace App\Http\Controllers\Admin\helpdesk;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Exception;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class UrlSettingController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
class UrlSettingController extends Controller {
|
||||
|
||||
public function __construct() {
|
||||
$this->middleware('auth');
|
||||
}
|
||||
|
||||
public function settings(Request $request)
|
||||
{
|
||||
public function settings(Request $request) {
|
||||
$url = $request->url();
|
||||
$www = $this->checkWWW($url);
|
||||
$https = $this->checkHTTP($url);
|
||||
//dd($www, $https);
|
||||
try {
|
||||
return view('themes.default1.admin.helpdesk.settings.url.settings', compact('www', 'https'));
|
||||
return view('themes.default1.admin.helpdesk.settings.url.settings',compact('www','https'));
|
||||
} catch (Exception $ex) {
|
||||
return redirect()->back()->with('fails', $ex->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function postSettings(Request $request)
|
||||
{
|
||||
public function postSettings(Request $request) {
|
||||
try {
|
||||
$www = $request->input('www');
|
||||
$ssl = $request->input('ssl');
|
||||
$string_www = $this->www($www);
|
||||
$sting_ssl = $this->ssl($ssl);
|
||||
$string = $string_www.$sting_ssl;
|
||||
$string = $string_www . $sting_ssl;
|
||||
$this->writeHtaccess($string);
|
||||
|
||||
return redirect()->back()->with('success', 'updated');
|
||||
} catch (Exception $ex) {
|
||||
dd($ex);
|
||||
|
||||
return redirect()->back()->with('fails', $ex->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function www($www)
|
||||
{
|
||||
public function www($www) {
|
||||
switch ($www) {
|
||||
case 'yes':
|
||||
case "yes":
|
||||
return $this->changeWww();
|
||||
case 'no':
|
||||
case "no":
|
||||
return $this->changeNonwww();
|
||||
}
|
||||
}
|
||||
|
||||
public function changeWww()
|
||||
{
|
||||
public function changeWww() {
|
||||
$string = "RewriteCond %{HTTP_HOST} !^www\.
|
||||
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]\n";
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
public function changeNonwww()
|
||||
{
|
||||
// $string = "\nRewriteEngine On
|
||||
//RewriteBase /
|
||||
//RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
|
||||
//RewriteRule ^(.*)$ http://%1/$1 [R=301,L]\n";
|
||||
$string = '';
|
||||
|
||||
public function changeNonwww() {
|
||||
$string = "RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
|
||||
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]\n";
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
public function ssl($ssl)
|
||||
{
|
||||
public function ssl($ssl) {
|
||||
switch ($ssl) {
|
||||
case 'yes':
|
||||
case "yes":
|
||||
return $this->changeHttps();
|
||||
case 'no':
|
||||
case "no":
|
||||
return $this->changeHttp();
|
||||
}
|
||||
}
|
||||
|
||||
public function changeHttps()
|
||||
{
|
||||
public function changeHttps() {
|
||||
$string = "RewriteCond %{HTTPS} off
|
||||
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]\n";
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
public function changeHttp()
|
||||
{
|
||||
public function changeHttp() {
|
||||
//$string = "RewriteCond %{HTTPS} off
|
||||
//RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]\n";
|
||||
$string = '';
|
||||
|
||||
$string = "";
|
||||
return $string;
|
||||
}
|
||||
|
||||
public function writeHtaccess($string)
|
||||
{
|
||||
public function writeHtaccess($string) {
|
||||
//dd(public_path('.htaccess'),base_path('.htaccess'));
|
||||
$file = public_path('.htaccess');
|
||||
if(!\File::exists($file)){
|
||||
$file = base_path('/../.htaccess');
|
||||
}
|
||||
$this->deleteCustom();
|
||||
$content = file_get_contents($file);
|
||||
file_put_contents($file, $content."#custom\n".$string);
|
||||
file_put_contents($file, $content . "#custom\n" . $string);
|
||||
$new_content = file_get_contents($file);
|
||||
}
|
||||
|
||||
public function deleteCustom()
|
||||
{
|
||||
public function deleteCustom() {
|
||||
$file = public_path('.htaccess');
|
||||
if(!\File::exists($file)){
|
||||
$file = base_path('/../.htaccess');
|
||||
}
|
||||
$content = file_get_contents($file);
|
||||
$custom_pos = strpos($content, '#custom');
|
||||
if ($custom_pos) {
|
||||
@@ -120,28 +108,23 @@ RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]\n";
|
||||
file_put_contents($file, $content);
|
||||
}
|
||||
|
||||
public function checkWwwInUrl($url)
|
||||
{
|
||||
public function checkWwwInUrl($url) {
|
||||
$check = false;
|
||||
if (strpos($url, 'www') !== false) {
|
||||
$check = true;
|
||||
}
|
||||
|
||||
return $check;
|
||||
}
|
||||
|
||||
public function checkHttpsInUrl($url)
|
||||
{
|
||||
public function checkHttpsInUrl($url) {
|
||||
$check = false;
|
||||
if (strpos($url, 'https') !== false) {
|
||||
$check = true;
|
||||
}
|
||||
|
||||
return $check;
|
||||
}
|
||||
|
||||
public function checkWWW($url)
|
||||
{
|
||||
public function checkWWW($url) {
|
||||
$check = $this->checkWwwInUrl($url);
|
||||
$array['www'] = true;
|
||||
$array['nonwww'] = false;
|
||||
@@ -149,12 +132,9 @@ RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]\n";
|
||||
$array['www'] = false;
|
||||
$array['nonwww'] = true;
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
public function checkHTTP($url)
|
||||
{
|
||||
public function checkHTTP($url) {
|
||||
$check = $this->checkHttpsInUrl($url);
|
||||
$array['https'] = true;
|
||||
$array['http'] = false;
|
||||
@@ -162,7 +142,7 @@ RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]\n";
|
||||
$array['https'] = false;
|
||||
$array['http'] = true;
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user