2021-04-16 01:00:00 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\Support\Facades\Hash;
|
2022-07-11 16:05:28 +02:00
|
|
|
use Illuminate\Auth\Events\Registered;
|
2022-07-11 20:46:45 +02:00
|
|
|
use Illuminate\Support\Facades\Schema;
|
2022-09-13 13:47:21 +02:00
|
|
|
use Illuminate\Support\Facades\File;
|
2021-04-16 01:00:00 +02:00
|
|
|
|
2022-11-17 15:07:06 +01:00
|
|
|
use GeoSot\EnvEditor\Controllers\EnvController;
|
|
|
|
use GeoSot\EnvEditor\Exceptions\EnvException;
|
|
|
|
use GeoSot\EnvEditor\Helpers\EnvFileContentManager;
|
|
|
|
use GeoSot\EnvEditor\Helpers\EnvFilesManager;
|
|
|
|
use GeoSot\EnvEditor\Helpers\EnvKeysManager;
|
|
|
|
use GeoSot\EnvEditor\Facades\EnvEditor;
|
|
|
|
use GeoSot\EnvEditor\ServiceProvider;
|
|
|
|
|
2021-04-16 01:00:00 +02:00
|
|
|
use Auth;
|
|
|
|
use Exception;
|
2022-09-13 13:47:21 +02:00
|
|
|
use ZipArchive;
|
2021-04-16 01:00:00 +02:00
|
|
|
|
|
|
|
use App\Models\User;
|
|
|
|
use App\Models\Admin;
|
|
|
|
use App\Models\Button;
|
|
|
|
use App\Models\Link;
|
|
|
|
use App\Models\Page;
|
|
|
|
|
|
|
|
class AdminController extends Controller
|
|
|
|
{
|
2022-11-08 16:11:59 +01:00
|
|
|
//Statistics of the number of clicks and links
|
2021-04-16 01:00:00 +02:00
|
|
|
public function index()
|
|
|
|
{
|
|
|
|
$userId = Auth::user()->id;
|
2021-04-18 19:43:43 +02:00
|
|
|
$littlelink_name = Auth::user()->littlelink_name;
|
2021-04-16 01:00:00 +02:00
|
|
|
$links = Link::where('user_id', $userId)->select('link')->count();
|
|
|
|
$clicks = Link::where('user_id', $userId)->sum('click_number');
|
2022-11-08 16:11:59 +01:00
|
|
|
|
2021-04-16 01:00:00 +02:00
|
|
|
$userNumber = User::count();
|
|
|
|
$siteLinks = Link::count();
|
|
|
|
$siteClicks = Link::sum('click_number');
|
|
|
|
|
2021-04-18 19:43:43 +02:00
|
|
|
return view('panel/index', ['littlelink_name' => $littlelink_name, 'links' => $links, 'clicks' => $clicks, 'siteLinks' => $siteLinks, 'siteClicks' => $siteClicks, 'userNumber' => $userNumber]);
|
2021-04-16 01:00:00 +02:00
|
|
|
}
|
|
|
|
|
2023-02-14 13:13:35 +01:00
|
|
|
// Get users by type
|
|
|
|
public function users(Request $request)
|
|
|
|
{
|
|
|
|
$usersType = $request->type;
|
|
|
|
|
|
|
|
switch ($usersType) {
|
|
|
|
case 'all':
|
2023-02-16 13:02:05 +01:00
|
|
|
$users = User::select('id', 'name', 'email', 'littlelink_name', 'role', 'block', 'email_verified_at', 'created_at', 'updated_at')->get();
|
2023-02-14 13:13:35 +01:00
|
|
|
break;
|
|
|
|
case 'user':
|
2023-02-16 13:02:05 +01:00
|
|
|
$users = User::where('role', 'user')->select('id', 'email', 'name', 'littlelink_name', 'role', 'block', 'email_verified_at', 'created_at', 'updated_at')->get();
|
2023-02-14 13:13:35 +01:00
|
|
|
break;
|
|
|
|
case 'vip':
|
2023-02-16 13:02:05 +01:00
|
|
|
$users = User::where('role', 'vip')->select('id', 'email', 'name', 'littlelink_name', 'role', 'block', 'email_verified_at', 'created_at', 'updated_at')->get();
|
2023-02-14 13:13:35 +01:00
|
|
|
break;
|
|
|
|
case 'admin':
|
2023-02-16 13:02:05 +01:00
|
|
|
$users = User::where('role', 'admin')->select('id', 'email', 'name', 'littlelink_name', 'role', 'block', 'email_verified_at', 'created_at', 'updated_at')->get();
|
2023-02-14 13:13:35 +01:00
|
|
|
break;
|
2021-04-16 01:00:00 +02:00
|
|
|
}
|
|
|
|
|
2023-02-14 13:13:35 +01:00
|
|
|
$data['users'] = $users;
|
2023-02-15 15:53:55 +01:00
|
|
|
|
|
|
|
// Loop through each user to get their click count and link count
|
|
|
|
foreach ($users as $user) {
|
|
|
|
$clicks = Link::where('user_id', $user->id)->sum('click_number');
|
|
|
|
$links = Link::where('user_id', $user->id)->select('link')->count();
|
|
|
|
$user->clicks = $clicks;
|
|
|
|
$user->links = $links;
|
|
|
|
}
|
|
|
|
|
2023-02-14 13:13:35 +01:00
|
|
|
return view('panel/users', $data);
|
|
|
|
}
|
|
|
|
|
2023-02-15 15:53:55 +01:00
|
|
|
|
2021-04-16 01:00:00 +02:00
|
|
|
//Search user by name
|
2023-02-14 13:45:01 +01:00
|
|
|
public function searchUser(Request $request)
|
2021-04-16 01:00:00 +02:00
|
|
|
{
|
2023-02-14 13:45:01 +01:00
|
|
|
$searchTerm = $request->search;
|
|
|
|
$data['users'] = User::where('name', 'like', "%{$searchTerm}%")
|
|
|
|
->orWhere('email', 'like', "%{$searchTerm}%")
|
|
|
|
->orWhere('littlelink_name', 'like', "%{$searchTerm}%")
|
|
|
|
// ->orWhere('role', 'like', "%{$searchTerm}%")
|
|
|
|
// ->orWhere('block', 'like', "%{$searchTerm}%")
|
|
|
|
// ->orWhere('email_verified_at', 'like', "%{$searchTerm}%")
|
|
|
|
->select('id', 'email', 'name', 'littlelink_name', 'role', 'block', 'email_verified_at')
|
|
|
|
->get();
|
2021-04-16 01:00:00 +02:00
|
|
|
return view('panel/users', $data);
|
|
|
|
}
|
2023-02-14 13:45:01 +01:00
|
|
|
|
2021-04-16 01:00:00 +02:00
|
|
|
|
2022-07-11 16:25:26 +02:00
|
|
|
//Block user
|
2021-04-16 01:00:00 +02:00
|
|
|
public function blockUser(request $request)
|
|
|
|
{
|
|
|
|
$id = $request->id;
|
|
|
|
$status = $request->block;
|
|
|
|
|
2022-11-08 16:11:59 +01:00
|
|
|
if ($status == 'yes') {
|
2021-04-16 01:00:00 +02:00
|
|
|
$block = 'no';
|
2022-11-08 16:11:59 +01:00
|
|
|
} elseif ($status == 'no') {
|
2021-04-16 01:00:00 +02:00
|
|
|
$block = 'yes';
|
|
|
|
}
|
|
|
|
|
|
|
|
User::where('id', $id)->update(['block' => $block]);
|
|
|
|
|
|
|
|
return redirect('panel/users/all');
|
|
|
|
}
|
|
|
|
|
2022-07-11 14:51:24 +02:00
|
|
|
//Verify or un-verify users emails
|
|
|
|
public function verifyUser(request $request)
|
|
|
|
{
|
|
|
|
$id = $request->id;
|
|
|
|
$status = $request->verify;
|
|
|
|
|
2022-11-08 16:11:59 +01:00
|
|
|
if ($status == '-') {
|
2022-07-11 14:51:24 +02:00
|
|
|
$verify = '0000-00-00 00:00:00';
|
2022-11-08 16:11:59 +01:00
|
|
|
} else {
|
2022-07-11 14:51:24 +02:00
|
|
|
$verify = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
User::where('id', $id)->update(['email_verified_at' => $verify]);
|
|
|
|
|
|
|
|
return redirect('panel/users/all');
|
|
|
|
}
|
2022-11-08 16:11:59 +01:00
|
|
|
|
2022-07-11 16:05:28 +02:00
|
|
|
//Create new user from the Admin Panel
|
|
|
|
public function createNewUser()
|
|
|
|
{
|
|
|
|
|
|
|
|
function random_str(
|
|
|
|
int $length = 64,
|
|
|
|
string $keyspace = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
|
|
|
): string {
|
|
|
|
if ($length < 1) {
|
|
|
|
throw new \RangeException("Length must be a positive integer");
|
|
|
|
}
|
|
|
|
$pieces = [];
|
|
|
|
$max = mb_strlen($keyspace, '8bit') - 1;
|
|
|
|
for ($i = 0; $i < $length; ++$i) {
|
2022-11-08 16:11:59 +01:00
|
|
|
$pieces[] = $keyspace[random_int(0, $max)];
|
2022-07-11 16:05:28 +02:00
|
|
|
}
|
|
|
|
return implode('', $pieces);
|
|
|
|
}
|
|
|
|
|
|
|
|
$user = User::create([
|
|
|
|
'name' => 'Admin-Created-' . random_str(8),
|
2022-07-12 16:12:54 +02:00
|
|
|
'email' => random_str(8) . '@example.com',
|
2022-07-11 16:05:28 +02:00
|
|
|
'password' => Hash::make(random_str(32)),
|
|
|
|
'role' => 'user',
|
|
|
|
'block' => 'no',
|
|
|
|
]);
|
|
|
|
|
2022-11-08 16:11:59 +01:00
|
|
|
return redirect('panel/edit-user/' . $user->id);
|
2022-07-11 16:05:28 +02:00
|
|
|
}
|
|
|
|
|
2022-07-11 16:25:26 +02:00
|
|
|
//Delete existing user
|
|
|
|
public function deleteUser(request $request)
|
|
|
|
{
|
|
|
|
$id = $request->id;
|
|
|
|
|
2022-11-08 16:11:59 +01:00
|
|
|
$user = User::find($id);
|
2022-07-11 20:46:45 +02:00
|
|
|
|
|
|
|
Schema::disableForeignKeyConstraints();
|
2022-07-11 16:25:26 +02:00
|
|
|
$user->forceDelete();
|
2022-07-11 20:46:45 +02:00
|
|
|
Schema::enableForeignKeyConstraints();
|
2022-07-11 16:25:26 +02:00
|
|
|
|
|
|
|
return redirect('panel/users/all');
|
|
|
|
}
|
|
|
|
|
2021-04-16 01:00:00 +02:00
|
|
|
//Show user to edit
|
|
|
|
public function showUser(request $request)
|
|
|
|
{
|
|
|
|
$id = $request->id;
|
|
|
|
|
|
|
|
$data['user'] = User::where('id', $id)->get();
|
|
|
|
|
2022-11-08 16:11:59 +01:00
|
|
|
return view('panel/edit-user', $data);
|
2021-04-16 01:00:00 +02:00
|
|
|
}
|
|
|
|
|
2022-05-30 15:02:27 +02:00
|
|
|
//Show link, click number, up link in links page
|
|
|
|
public function showLinksUser(request $request)
|
|
|
|
{
|
|
|
|
$id = $request->id;
|
2022-11-08 16:11:59 +01:00
|
|
|
|
2022-05-30 15:02:27 +02:00
|
|
|
$data['user'] = User::where('id', $id)->get();
|
|
|
|
|
|
|
|
$data['links'] = Link::select('id', 'link', 'title', 'order', 'click_number', 'up_link', 'links.button_id')->where('user_id', $id)->orderBy('up_link', 'asc')->orderBy('order', 'asc')->paginate(10);
|
|
|
|
return view('panel/links', $data);
|
|
|
|
}
|
|
|
|
|
|
|
|
//Delete link
|
|
|
|
public function deleteLinkUser(request $request)
|
|
|
|
{
|
|
|
|
$linkId = $request->id;
|
|
|
|
|
|
|
|
Link::where('id', $linkId)->delete();
|
2022-11-08 16:11:59 +01:00
|
|
|
|
2022-05-30 15:02:27 +02:00
|
|
|
return back();
|
|
|
|
}
|
|
|
|
|
2021-04-16 01:00:00 +02:00
|
|
|
//Save user edit
|
|
|
|
public function editUser(request $request)
|
|
|
|
{
|
2022-11-08 16:11:59 +01:00
|
|
|
$request->validate([
|
2022-03-28 19:54:17 +02:00
|
|
|
'name' => '',
|
|
|
|
'email' => '',
|
|
|
|
'password' => '',
|
|
|
|
'littlelink_name' => '',
|
2021-07-06 10:35:32 +02:00
|
|
|
]);
|
2022-11-08 16:11:59 +01:00
|
|
|
|
2021-04-16 01:00:00 +02:00
|
|
|
$id = $request->id;
|
|
|
|
$name = $request->name;
|
|
|
|
$email = $request->email;
|
|
|
|
$password = Hash::make($request->password);
|
|
|
|
$profilePhoto = $request->file('image');
|
|
|
|
$littlelink_name = $request->littlelink_name;
|
|
|
|
$littlelink_description = $request->littlelink_description;
|
|
|
|
$role = $request->role;
|
2023-02-15 18:14:54 +01:00
|
|
|
$customBackground = $request->file('background');
|
2022-11-08 16:11:59 +01:00
|
|
|
|
|
|
|
if ($request->password == '') {
|
|
|
|
User::where('id', $id)->update(['name' => $name, 'email' => $email, 'littlelink_name' => $littlelink_name, 'littlelink_description' => $littlelink_description, 'role' => $role]);
|
|
|
|
} else {
|
|
|
|
User::where('id', $id)->update(['name' => $name, 'email' => $email, 'password' => $password, 'littlelink_name' => $littlelink_name, 'littlelink_description' => $littlelink_description, 'role' => $role]);
|
2022-03-28 19:54:17 +02:00
|
|
|
}
|
2022-11-08 16:11:59 +01:00
|
|
|
if (!empty($profilePhoto)) {
|
2023-02-02 18:40:40 +01:00
|
|
|
$profilePhoto->move(base_path('/img'), $id . ".png");
|
2023-02-15 18:14:54 +01:00
|
|
|
}
|
|
|
|
if (!empty($customBackground)) {
|
|
|
|
$directory = base_path('/img/background-img/');
|
|
|
|
$files = scandir($directory);
|
|
|
|
$pathinfo = "error.error";
|
|
|
|
foreach($files as $file) {
|
|
|
|
if (strpos($file, $id.'.') !== false) {
|
|
|
|
$pathinfo = $id. "." . pathinfo($file, PATHINFO_EXTENSION);
|
|
|
|
}}
|
|
|
|
if(file_exists(base_path('/img/background-img/').$pathinfo)){File::delete(base_path('/img/background-img/').$pathinfo);}
|
|
|
|
|
|
|
|
$customBackground->move(base_path('/img/background-img/'), $id.".".$request->file('background')->extension());
|
|
|
|
}
|
2021-04-16 01:00:00 +02:00
|
|
|
|
2022-07-11 16:25:26 +02:00
|
|
|
return redirect('panel/users/all');
|
2021-04-16 01:00:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//Show site pages to edit
|
|
|
|
public function showSitePage()
|
|
|
|
{
|
2022-02-23 20:19:15 +01:00
|
|
|
$data['pages'] = Page::select('terms', 'privacy', 'contact', 'register')->get();
|
2021-04-16 01:00:00 +02:00
|
|
|
return view('panel/pages', $data);
|
|
|
|
}
|
|
|
|
|
|
|
|
//Save site pages
|
|
|
|
public function editSitePage(request $request)
|
|
|
|
{
|
|
|
|
$terms = $request->terms;
|
|
|
|
$privacy = $request->privacy;
|
|
|
|
$contact = $request->contact;
|
2022-02-23 20:19:15 +01:00
|
|
|
$register = $request->register;
|
2021-04-16 01:00:00 +02:00
|
|
|
|
2022-02-23 20:19:15 +01:00
|
|
|
Page::first()->update(['terms' => $terms, 'privacy' => $privacy, 'contact' => $contact, 'register' => $register]);
|
2021-04-16 01:00:00 +02:00
|
|
|
|
|
|
|
return back();
|
|
|
|
}
|
|
|
|
|
|
|
|
//Show home message for edit
|
|
|
|
public function showSite()
|
|
|
|
{
|
|
|
|
$message = Page::select('home_message')->first();
|
|
|
|
return view('panel/site', $message);
|
|
|
|
}
|
|
|
|
|
2022-11-30 12:10:45 +01:00
|
|
|
//Save home message, logo and favicon
|
2021-04-16 01:00:00 +02:00
|
|
|
public function editSite(request $request)
|
|
|
|
{
|
|
|
|
$message = $request->message;
|
|
|
|
$logo = $request->file('image');
|
2022-11-29 23:33:25 +01:00
|
|
|
$icon = $request->file('icon');
|
2021-04-16 01:00:00 +02:00
|
|
|
|
|
|
|
Page::first()->update(['home_message' => $message]);
|
|
|
|
|
2022-11-08 16:11:59 +01:00
|
|
|
if (!empty($logo)) {
|
2022-11-29 23:33:25 +01:00
|
|
|
// Delete existing image
|
|
|
|
$directory = base_path('/littlelink/images/');
|
|
|
|
$files = scandir($directory);
|
|
|
|
$pathinfo = "error.error";
|
|
|
|
foreach($files as $file) {
|
|
|
|
if (strpos($file, "avatar".'.') !== false) {
|
|
|
|
$pathinfo = "avatar". "." . pathinfo($file, PATHINFO_EXTENSION);
|
|
|
|
}}
|
|
|
|
if(file_exists(base_path('/littlelink/images/').$pathinfo)){File::delete(base_path('/littlelink/images/').$pathinfo);}
|
|
|
|
|
|
|
|
$logo->move(base_path('/littlelink/images/'), "avatar.".$request->file('image')->extension());
|
2022-11-08 16:11:59 +01:00
|
|
|
}
|
2021-04-16 01:00:00 +02:00
|
|
|
|
2022-11-29 23:33:25 +01:00
|
|
|
if (!empty($icon)) {
|
|
|
|
// Delete existing image
|
|
|
|
$directory = base_path('/littlelink/images/');
|
|
|
|
$files = scandir($directory);
|
|
|
|
$pathinfo = "error.error";
|
|
|
|
foreach($files as $file) {
|
|
|
|
if (strpos($file, "favicon".'.') !== false) {
|
|
|
|
$pathinfo = "favicon". "." . pathinfo($file, PATHINFO_EXTENSION);
|
|
|
|
}}
|
|
|
|
if(file_exists(base_path('/littlelink/images/').$pathinfo)){File::delete(base_path('/littlelink/images/').$pathinfo);}
|
|
|
|
|
|
|
|
$icon->move(base_path('/littlelink/images/'), "favicon.".$request->file('icon')->extension());
|
|
|
|
}
|
2021-04-16 01:00:00 +02:00
|
|
|
return back();
|
|
|
|
}
|
|
|
|
|
2022-11-30 12:10:45 +01:00
|
|
|
//Delete avatar
|
|
|
|
public function delAvatar()
|
|
|
|
{
|
|
|
|
// Delete existing image
|
|
|
|
$directory = base_path('/littlelink/images/');
|
|
|
|
$files = scandir($directory);
|
|
|
|
$pathinfo = "error.error";
|
|
|
|
foreach($files as $file) {
|
|
|
|
if (strpos($file, "avatar".'.') !== false) {
|
|
|
|
$pathinfo = "avatar". "." . pathinfo($file, PATHINFO_EXTENSION);
|
|
|
|
}}
|
|
|
|
if(file_exists(base_path('/littlelink/images/').$pathinfo)){File::delete(base_path('/littlelink/images/').$pathinfo);}
|
|
|
|
|
|
|
|
return back();
|
|
|
|
}
|
|
|
|
|
|
|
|
//Delete favicon
|
|
|
|
public function delFavicon()
|
|
|
|
{
|
|
|
|
// Delete existing image
|
|
|
|
$directory = base_path('/littlelink/images/');
|
|
|
|
$files = scandir($directory);
|
|
|
|
$pathinfo = "error.error";
|
|
|
|
foreach($files as $file) {
|
|
|
|
if (strpos($file, "favicon".'.') !== false) {
|
|
|
|
$pathinfo = "favicon". "." . pathinfo($file, PATHINFO_EXTENSION);
|
|
|
|
}}
|
|
|
|
if(file_exists(base_path('/littlelink/images/').$pathinfo)){File::delete(base_path('/littlelink/images/').$pathinfo);}
|
|
|
|
|
|
|
|
return back();
|
|
|
|
}
|
|
|
|
|
2023-02-06 20:13:11 +01:00
|
|
|
//View footer page: terms
|
|
|
|
public function pagesTerms(Request $request)
|
2021-04-16 01:00:00 +02:00
|
|
|
{
|
2023-02-06 20:13:11 +01:00
|
|
|
$name = "terms";
|
2023-01-31 15:10:51 +01:00
|
|
|
|
2023-02-06 20:13:11 +01:00
|
|
|
try {
|
|
|
|
$data['page'] = Page::select($name)->first();
|
|
|
|
} catch (Exception $e) {
|
|
|
|
return abort(404);
|
|
|
|
}
|
2023-01-31 15:10:51 +01:00
|
|
|
|
2023-02-06 20:13:11 +01:00
|
|
|
return view('pages', ['data' => $data, 'name' => $name]);
|
|
|
|
}
|
|
|
|
|
|
|
|
//View footer page: privacy
|
|
|
|
public function pagesPrivacy(Request $request)
|
|
|
|
{
|
|
|
|
$name = "privacy";
|
|
|
|
|
|
|
|
try {
|
|
|
|
$data['page'] = Page::select($name)->first();
|
|
|
|
} catch (Exception $e) {
|
2023-01-31 15:10:51 +01:00
|
|
|
return abort(404);
|
|
|
|
}
|
|
|
|
|
2023-02-06 20:13:11 +01:00
|
|
|
return view('pages', ['data' => $data, 'name' => $name]);
|
|
|
|
}
|
|
|
|
|
|
|
|
//View footer page: contact
|
|
|
|
public function pagesContact(Request $request)
|
|
|
|
{
|
|
|
|
$name = "contact";
|
|
|
|
|
2021-04-16 01:00:00 +02:00
|
|
|
try {
|
|
|
|
$data['page'] = Page::select($name)->first();
|
|
|
|
} catch (Exception $e) {
|
|
|
|
return abort(404);
|
|
|
|
}
|
2023-01-31 15:10:51 +01:00
|
|
|
|
2021-04-16 01:00:00 +02:00
|
|
|
return view('pages', ['data' => $data, 'name' => $name]);
|
|
|
|
}
|
2022-03-28 12:20:47 +02:00
|
|
|
|
2022-11-08 16:11:59 +01:00
|
|
|
//Statistics of the number of clicks and links
|
2022-03-28 12:20:47 +02:00
|
|
|
public function phpinfo()
|
|
|
|
{
|
|
|
|
return view('panel/phpinfo');
|
|
|
|
}
|
|
|
|
|
2022-06-13 17:47:24 +02:00
|
|
|
//Shows config file editor page
|
|
|
|
public function showFileEditor(request $request)
|
|
|
|
{
|
|
|
|
return view('/panel/config');
|
|
|
|
}
|
|
|
|
|
|
|
|
//Saves advanced config
|
|
|
|
public function editAC(request $request)
|
|
|
|
{
|
|
|
|
$AdvancedConfig = $request->AdvancedConfig;
|
|
|
|
|
|
|
|
file_put_contents('config/advanced-config.php', $AdvancedConfig);
|
|
|
|
|
2022-11-17 21:22:06 +01:00
|
|
|
return redirect('/panel/config#2');
|
2022-06-13 17:47:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//Saves .env config
|
|
|
|
public function editENV(request $request)
|
|
|
|
{
|
2022-11-17 15:07:06 +01:00
|
|
|
$config = $request->altConfig;
|
2022-06-13 17:47:24 +02:00
|
|
|
|
2022-11-17 15:07:06 +01:00
|
|
|
file_put_contents('.env', $config);
|
2022-06-13 17:47:24 +02:00
|
|
|
|
2022-11-17 21:32:47 +01:00
|
|
|
return Redirect('/panel/config?alternative-config');
|
2022-06-13 17:47:24 +02:00
|
|
|
}
|
|
|
|
|
2022-06-16 13:35:39 +02:00
|
|
|
//Shows config file editor page
|
|
|
|
public function showBackups(request $request)
|
|
|
|
{
|
|
|
|
return view('/panel/backups');
|
|
|
|
}
|
|
|
|
|
2022-07-04 23:41:28 +02:00
|
|
|
//Delete custom theme
|
|
|
|
public function deleteTheme(request $request)
|
|
|
|
{
|
|
|
|
|
|
|
|
$del = $request->deltheme;
|
|
|
|
|
2022-07-05 10:30:25 +02:00
|
|
|
if (empty($del)) {
|
2022-11-08 16:11:59 +01:00
|
|
|
echo '<script type="text/javascript">';
|
|
|
|
echo 'alert("No themes to delete!");';
|
2022-07-05 10:30:25 +02:00
|
|
|
echo 'window.location.href = "../studio/theme";';
|
|
|
|
echo '</script>';
|
|
|
|
} else {
|
|
|
|
|
2022-11-08 16:11:59 +01:00
|
|
|
$folderName = base_path() . '/themes/' . $del;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function removeFolder($folderName)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (is_dir($folderName))
|
|
|
|
|
|
|
|
$folderHandle = opendir($folderName);
|
|
|
|
|
2022-07-04 23:41:28 +02:00
|
|
|
|
|
|
|
|
2022-11-08 16:11:59 +01:00
|
|
|
if (!$folderHandle)
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while ($file = readdir($folderHandle)) {
|
|
|
|
|
|
|
|
if ($file != "." && $file != "..") {
|
|
|
|
|
|
|
|
if (!is_dir($folderName . "/" . $file))
|
|
|
|
|
|
|
|
unlink($folderName . "/" . $file);
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
removeFolder($folderName . '/' . $file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
closedir($folderHandle);
|
|
|
|
|
|
|
|
rmdir($folderName);
|
|
|
|
}
|
|
|
|
|
|
|
|
removeFolder($folderName);
|
|
|
|
|
|
|
|
return Redirect('/panel/theme');
|
|
|
|
}
|
|
|
|
}
|
2022-07-04 23:41:28 +02:00
|
|
|
|
2022-09-13 13:47:21 +02:00
|
|
|
// Update themes
|
|
|
|
public function updateThemes()
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
if ($handle = opendir('themes')) {
|
|
|
|
while (false !== ($entry = readdir($handle))) {
|
|
|
|
|
2022-11-08 16:11:59 +01:00
|
|
|
if (file_exists(base_path('themes') . '/' . $entry . '/readme.md')) {
|
|
|
|
$text = file_get_contents(base_path('themes') . '/' . $entry . '/readme.md');
|
|
|
|
$pattern = '/Theme Version:.*/';
|
|
|
|
preg_match($pattern, $text, $matches, PREG_OFFSET_CAPTURE);
|
|
|
|
if (!count($matches)) continue;
|
|
|
|
$verNr = substr($matches[0][0], 15);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$themeVe = NULL;
|
|
|
|
|
|
|
|
if ($entry != "." && $entry != "..") {
|
|
|
|
if (file_exists(base_path('themes') . '/' . $entry . '/readme.md')) {
|
|
|
|
if (!strpos(file_get_contents(base_path('themes') . '/' . $entry . '/readme.md'), 'Source code:')) {
|
|
|
|
$hasSource = false;
|
|
|
|
} else {
|
|
|
|
$hasSource = true;
|
|
|
|
|
|
|
|
$text = file_get_contents(base_path('themes') . '/' . $entry . '/readme.md');
|
|
|
|
$pattern = '/Source code:.*/';
|
|
|
|
preg_match($pattern, $text, $matches, PREG_OFFSET_CAPTURE);
|
|
|
|
$sourceURL = substr($matches[0][0], 13);
|
|
|
|
|
|
|
|
$replaced = str_replace("https://github.com/", "https://raw.githubusercontent.com/", trim($sourceURL));
|
|
|
|
$replaced = $replaced . "/main/readme.md";
|
|
|
|
|
|
|
|
if (strpos($sourceURL, 'github.com')) {
|
|
|
|
|
|
|
|
ini_set('user_agent', 'Mozilla/4.0 (compatible; MSIE 6.0)');
|
|
|
|
try {
|
|
|
|
$textGit = file_get_contents($replaced);
|
|
|
|
$patternGit = '/Theme Version:.*/';
|
|
|
|
preg_match($patternGit, $textGit, $matches, PREG_OFFSET_CAPTURE);
|
|
|
|
$sourceURLGit = substr($matches[0][0], 15);
|
|
|
|
$Vgitt = 'v' . $sourceURLGit;
|
|
|
|
$verNrv = 'v' . $verNr;
|
|
|
|
} catch (Exception $ex) {
|
|
|
|
$themeVe = "error";
|
|
|
|
$Vgitt = NULL;
|
|
|
|
$verNrv = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (trim($Vgitt) > trim($verNrv)) {
|
|
|
|
|
|
|
|
|
|
|
|
$fileUrl = trim($sourceURL) . '/archive/refs/tags/' . trim($Vgitt) . '.zip';
|
|
|
|
|
|
|
|
|
|
|
|
file_put_contents(base_path('themes/theme.zip'), fopen($fileUrl, 'r'));
|
|
|
|
|
|
|
|
|
|
|
|
$zip = new ZipArchive;
|
|
|
|
$zip->open(base_path() . '/themes/theme.zip');
|
|
|
|
$zip->extractTo(base_path('themes'));
|
|
|
|
$zip->close();
|
|
|
|
unlink(base_path() . '/themes/theme.zip');
|
|
|
|
|
|
|
|
$folder = base_path('themes');
|
|
|
|
$regex = '/[0-9.-]/';
|
|
|
|
$files = scandir($folder);
|
|
|
|
|
|
|
|
foreach ($files as $file) {
|
|
|
|
if ($file !== '.' && $file !== '..') {
|
|
|
|
if (preg_match($regex, $file)) {
|
|
|
|
$new_file = preg_replace($regex, '', $file);
|
|
|
|
File::copyDirectory($folder . '/' . $file, $folder . '/' . $new_file);
|
|
|
|
$dirname = $folder . '/' . $file;
|
|
|
|
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
|
|
|
|
system('rmdir ' . escapeshellarg($dirname) . ' /s /q');
|
|
|
|
} else {
|
|
|
|
system("rm -rf " . escapeshellarg($dirname));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-09-13 13:47:21 +02:00
|
|
|
}
|
2022-11-08 16:11:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-09-13 13:47:21 +02:00
|
|
|
|
|
|
|
|
|
|
|
return Redirect('/studio/theme');
|
|
|
|
}
|
|
|
|
|
2022-07-04 23:41:28 +02:00
|
|
|
//Shows config file editor page
|
2022-11-17 15:07:06 +01:00
|
|
|
public function showConfig(request $request)
|
|
|
|
{
|
|
|
|
return view('/panel/config-editor');
|
|
|
|
}
|
|
|
|
|
|
|
|
//Shows config file editor page
|
|
|
|
public function editConfig(request $request)
|
|
|
|
{
|
|
|
|
|
|
|
|
$type = $request->type;
|
|
|
|
$entry = $request->entry;
|
|
|
|
$value = $request->value;
|
|
|
|
|
|
|
|
if($type === "toggle"){
|
2022-11-17 16:20:04 +01:00
|
|
|
if($request->toggle != ''){$value = "true";}else{$value = "false";}
|
2022-11-17 15:07:06 +01:00
|
|
|
if(EnvEditor::keyExists($entry)){EnvEditor::editKey($entry, $value);}
|
|
|
|
} elseif($type === "toggle2") {
|
|
|
|
if($request->toggle != ''){$value = "verified";}else{$value = "auth";}
|
|
|
|
if(EnvEditor::keyExists($entry)){EnvEditor::editKey($entry, $value);}
|
|
|
|
} elseif($type === "text") {
|
|
|
|
if(EnvEditor::keyExists($entry)){EnvEditor::editKey($entry, '"' . $value . '"');}
|
|
|
|
} elseif($type === "debug") {
|
|
|
|
if($request->toggle != ''){
|
|
|
|
if(EnvEditor::keyExists('APP_DEBUG')){EnvEditor::editKey('APP_DEBUG', 'true');}
|
|
|
|
if(EnvEditor::keyExists('APP_ENV')){EnvEditor::editKey('APP_ENV', 'local');}
|
|
|
|
if(EnvEditor::keyExists('LOG_LEVEL')){EnvEditor::editKey('LOG_LEVEL', 'debug');}
|
|
|
|
} else {
|
|
|
|
if(EnvEditor::keyExists('APP_DEBUG')){EnvEditor::editKey('APP_DEBUG', 'false');}
|
|
|
|
if(EnvEditor::keyExists('APP_ENV')){EnvEditor::editKey('APP_ENV', 'production');}
|
|
|
|
if(EnvEditor::keyExists('LOG_LEVEL')){EnvEditor::editKey('LOG_LEVEL', 'error');}
|
|
|
|
}
|
|
|
|
} elseif($type === "register") {
|
|
|
|
if($request->toggle != ''){$register = "true";}else{$register = "false";}
|
|
|
|
Page::first()->update(['register' => $register]);
|
|
|
|
} elseif($type === "smtp") {
|
|
|
|
if($request->toggle != ''){$value = "built-in";}else{$value = "smtp";}
|
|
|
|
if(EnvEditor::keyExists('MAIL_MAILER')){EnvEditor::editKey('MAIL_MAILER', $value);}
|
|
|
|
|
|
|
|
if(EnvEditor::keyExists('MAIL_HOST')){EnvEditor::editKey('MAIL_HOST', $request->MAIL_HOST);}
|
|
|
|
if(EnvEditor::keyExists('MAIL_PORT')){EnvEditor::editKey('MAIL_PORT', $request->MAIL_PORT);}
|
|
|
|
if(EnvEditor::keyExists('MAIL_USERNAME')){EnvEditor::editKey('MAIL_USERNAME', $request->MAIL_USERNAME);}
|
|
|
|
if(EnvEditor::keyExists('MAIL_PASSWORD')){EnvEditor::editKey('MAIL_PASSWORD', $request->MAIL_PASSWORD);}
|
|
|
|
if(EnvEditor::keyExists('MAIL_ENCRYPTION')){EnvEditor::editKey('MAIL_ENCRYPTION', $request->MAIL_ENCRYPTION);}
|
|
|
|
if(EnvEditor::keyExists('MAIL_FROM_ADDRESS')){EnvEditor::editKey('MAIL_FROM_ADDRESS', $request->MAIL_FROM_ADDRESS);}
|
|
|
|
} elseif($type === "homeurl") {
|
|
|
|
if($request->value == 'default'){$value = "";}else{$value = '"' . $request->value . '"';}
|
|
|
|
if(EnvEditor::keyExists($entry)){EnvEditor::editKey($entry, $value);}
|
2022-11-20 15:13:53 +01:00
|
|
|
} elseif($type === "maintenance") {
|
|
|
|
if($request->toggle != ''){$value = "true";}else{$value = "false";}
|
|
|
|
if(file_exists(base_path("storage/MAINTENANCE"))){unlink(base_path("storage/MAINTENANCE"));}
|
|
|
|
if(EnvEditor::keyExists($entry)){EnvEditor::editKey($entry, $value);}
|
2022-11-17 15:07:06 +01:00
|
|
|
} else {
|
|
|
|
if(EnvEditor::keyExists($entry)){EnvEditor::editKey($entry, $value);}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Redirect('/panel/config');
|
|
|
|
}
|
|
|
|
|
|
|
|
//Shows theme editor page
|
2022-07-04 23:41:28 +02:00
|
|
|
public function showThemes(request $request)
|
|
|
|
{
|
|
|
|
return view('/panel/theme');
|
|
|
|
}
|
2021-04-16 01:00:00 +02:00
|
|
|
}
|