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;
|
2021-04-16 01:00:00 +02:00
|
|
|
|
|
|
|
use Auth;
|
|
|
|
use Exception;
|
|
|
|
|
|
|
|
use App\Models\User;
|
|
|
|
use App\Models\Admin;
|
|
|
|
use App\Models\Button;
|
|
|
|
use App\Models\Link;
|
|
|
|
use App\Models\Page;
|
|
|
|
|
|
|
|
class AdminController extends Controller
|
|
|
|
{
|
|
|
|
//Statistics of the number of clicks and links
|
|
|
|
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');
|
|
|
|
|
|
|
|
$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
|
|
|
}
|
|
|
|
|
|
|
|
//Get users by type
|
|
|
|
public function users(request $request)
|
|
|
|
{
|
|
|
|
$usersType = $request->type;
|
|
|
|
|
|
|
|
switch($usersType){
|
|
|
|
case 'all':
|
2022-07-11 14:51:24 +02:00
|
|
|
$data['users'] = User::select('id', 'name', 'littlelink_name', 'role', 'block', 'email_verified_at')->get();
|
2021-04-16 01:00:00 +02:00
|
|
|
return view('panel/users', $data);
|
|
|
|
break;
|
|
|
|
case 'user':
|
2022-07-11 14:51:24 +02:00
|
|
|
$data['users'] = User::where('role', 'user')->select('id', 'name', 'littlelink_name', 'role', 'block', 'email_verified_at')->get();
|
2021-04-16 01:00:00 +02:00
|
|
|
return view('panel/users', $data);
|
|
|
|
break;
|
|
|
|
case 'vip':
|
2022-07-11 14:51:24 +02:00
|
|
|
$data['users'] = User::where('role', 'vip')->select('id', 'name', 'littlelink_name', 'role', 'block', 'email_verified_at')->get();
|
2021-04-16 01:00:00 +02:00
|
|
|
return view('panel/users', $data);
|
|
|
|
break;
|
|
|
|
case 'admin':
|
2022-07-11 14:51:24 +02:00
|
|
|
$data['users'] = User::where('role', 'admin')->select('id', 'name', 'littlelink_name', 'role', 'block', 'email_verified_at')->get();
|
2021-04-16 01:00:00 +02:00
|
|
|
return view('panel/users', $data);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Search user by name
|
|
|
|
public function searchUser(request $request)
|
|
|
|
{
|
|
|
|
$name = $request->name;
|
|
|
|
$data['users'] = User::where('name', $name)->select('id', 'name', 'role', 'block')->get();
|
|
|
|
return view('panel/users', $data);
|
|
|
|
}
|
|
|
|
|
|
|
|
//Block user and delete their links
|
|
|
|
public function blockUser(request $request)
|
|
|
|
{
|
|
|
|
$id = $request->id;
|
|
|
|
$status = $request->block;
|
|
|
|
|
|
|
|
if($status == 'yes'){
|
|
|
|
$block = 'no';
|
|
|
|
}elseif($status == 'no'){
|
|
|
|
$block = 'yes';
|
|
|
|
}
|
|
|
|
|
|
|
|
User::where('id', $id)->update(['block' => $block]);
|
|
|
|
|
|
|
|
Link::where('user_id', $id)->delete();
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
if($status == '-'){
|
|
|
|
$verify = '0000-00-00 00:00:00';
|
|
|
|
}else{
|
|
|
|
$verify = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
User::where('id', $id)->update(['email_verified_at' => $verify]);
|
|
|
|
|
|
|
|
return redirect('panel/users/all');
|
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
$pieces []= $keyspace[random_int(0, $max)];
|
|
|
|
}
|
|
|
|
return implode('', $pieces);
|
|
|
|
}
|
|
|
|
|
|
|
|
$user = User::create([
|
|
|
|
'name' => 'Admin-Created-' . random_str(8),
|
|
|
|
'email' => random_str(8) . '@test.com',
|
|
|
|
'password' => Hash::make(random_str(32)),
|
|
|
|
'role' => 'user',
|
|
|
|
'block' => 'no',
|
|
|
|
]);
|
|
|
|
|
|
|
|
return redirect('panel/edit-user/'. $user->id);
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
return view('panel/edit-user', $data);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
$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();
|
|
|
|
|
|
|
|
return back();
|
|
|
|
}
|
|
|
|
|
2021-04-16 01:00:00 +02:00
|
|
|
//Save user edit
|
|
|
|
public function editUser(request $request)
|
|
|
|
{
|
2021-07-06 10:35:32 +02: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-03-28 19:54:17 +02: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;
|
|
|
|
|
2022-03-28 19:54:17 +02:00
|
|
|
if($request->password == '' ) {
|
|
|
|
User::where('id', $id)->update(['name' => $name, 'email' => $email, 'littlelink_name' => $littlelink_name, 'littlelink_description' => $littlelink_description, 'role' => $role]);
|
|
|
|
} else {
|
2021-04-16 01:00:00 +02:00
|
|
|
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
|
|
|
}
|
2021-04-16 01:00:00 +02:00
|
|
|
if(!empty($profilePhoto)){
|
2022-02-14 12:46:24 +01:00
|
|
|
$profilePhoto->move(base_path('/img'), $littlelink_name . ".png");
|
2021-04-16 01:00:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return back();
|
|
|
|
}
|
|
|
|
|
|
|
|
//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);
|
|
|
|
}
|
|
|
|
|
|
|
|
//Save home message and logo
|
|
|
|
public function editSite(request $request)
|
|
|
|
{
|
|
|
|
$message = $request->message;
|
|
|
|
$logo = $request->file('image');
|
|
|
|
|
|
|
|
Page::first()->update(['home_message' => $message]);
|
|
|
|
|
|
|
|
if(!empty($logo)){
|
2022-02-14 12:46:24 +01:00
|
|
|
$logo->move(base_path('/littlelink/images/'), "avatar.png");
|
2021-04-16 01:00:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return back();
|
|
|
|
}
|
|
|
|
|
|
|
|
//View any of the pages: contact, terms, privacy
|
|
|
|
public function pages(request $request)
|
|
|
|
{
|
|
|
|
$name = $request->name;
|
|
|
|
|
|
|
|
try {
|
|
|
|
$data['page'] = Page::select($name)->first();
|
|
|
|
} catch (Exception $e) {
|
|
|
|
return abort(404);
|
|
|
|
}
|
|
|
|
|
|
|
|
return view('pages', ['data' => $data, 'name' => $name]);
|
|
|
|
}
|
2022-03-28 12:20:47 +02:00
|
|
|
|
|
|
|
//Statistics of the number of clicks and links
|
|
|
|
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);
|
|
|
|
|
|
|
|
return view('/panel/config');
|
|
|
|
}
|
|
|
|
|
|
|
|
//Saves .env config
|
|
|
|
public function editENV(request $request)
|
|
|
|
{
|
|
|
|
$AdvancedConfig = $request->AdvancedConfig;
|
|
|
|
|
|
|
|
file_put_contents('.env', $AdvancedConfig);
|
|
|
|
|
|
|
|
return view('/panel/config');
|
|
|
|
}
|
|
|
|
|
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)) {
|
|
|
|
echo '<script type="text/javascript">';
|
|
|
|
echo 'alert("No themes to delete!");';
|
|
|
|
echo 'window.location.href = "../studio/theme";';
|
|
|
|
echo '</script>';
|
|
|
|
} else {
|
|
|
|
|
2022-07-04 23:41:28 +02:00
|
|
|
$folderName = base_path() . '/themes/' . $del;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function removeFolder($folderName) {
|
|
|
|
|
|
|
|
if (is_dir($folderName))
|
|
|
|
|
|
|
|
$folderHandle = opendir($folderName);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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-05 10:30:25 +02:00
|
|
|
}}
|
2022-07-04 23:41:28 +02:00
|
|
|
|
|
|
|
//Shows config file editor page
|
|
|
|
public function showThemes(request $request)
|
|
|
|
{
|
|
|
|
return view('/panel/theme');
|
|
|
|
}
|
|
|
|
|
2021-04-16 01:00:00 +02:00
|
|
|
}
|