Skip to content

Commit

Permalink
v0.8
Browse files Browse the repository at this point in the history
v0.8
  • Loading branch information
1day2die authored Aug 15, 2022
2 parents 812126e + b473cf9 commit 5e507ef
Show file tree
Hide file tree
Showing 79 changed files with 9,683 additions and 1,087 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
- PayPal Integration
- Stripe Integration
- Referral System
- Ticket System
- Upgrade/Downgrade Server Ressources
- Store (credit system with hourly billing and invoices)
- Email Verification
- Audit Log
- Admin Dashboard
- User/Server Management
- Store (credit system with hourly billing and invoices)
- Customizable server plans
- Vouchers
- and so much more!
Expand All @@ -17,6 +19,7 @@
![controlpanel](https://user-images.githubusercontent.com/45005889/123518824-06b05000-d6a8-11eb-91b9-d1ed36bd2317.png)


[//]: ![](https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fmarket.controlpanel.gg%2Fcallhome.php%3Fgetinstalls)
![](https://img.shields.io/github/stars/ControlPanel-gg/dashboard) ![](https://img.shields.io/github/forks/ControlPanel-gg/dashboard) ![](https://img.shields.io/github/tag/ControlPanel-gg/dashboard) [![Crowdin](https://badges.crowdin.net/controlpanelgg/localized.svg)](https://crowdin.com/project/controlpanelgg) ![](https://img.shields.io/github/issues/ControlPanel-gg/dashboard) ![](https://img.shields.io/github/license/ControlPanel-gg/dashboard) ![](https://img.shields.io/discord/787829714483019826)
## About

Expand Down Expand Up @@ -47,4 +50,7 @@ This dashboard offers an easy to use and free billing solution for all starting
### Example server products
![image](https://user-images.githubusercontent.com/8725848/171575987-c1398ff6-83fa-4cb8-bd1f-986cee4da565.png)

### Ticket System
![image](https://user-images.githubusercontent.com/8725848/184131270-9d997ebf-8965-4910-90d2-b410ae37f201.png)


107 changes: 107 additions & 0 deletions app/Classes/Pterodactyl.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Models\Nest;
use App\Models\Node;
use App\Models\Server;
use App\Models\Product;
use Exception;
use Illuminate\Http\Client\PendingRequest;
use Illuminate\Http\Client\Response;
Expand All @@ -32,6 +33,14 @@ public static function client()
])->baseUrl(config("SETTINGS::SYSTEM:PTERODACTYL:URL") . '/api');
}

public static function clientAdmin()
{
return Http::withHeaders([
'Authorization' => 'Bearer ' . config("SETTINGS::SYSTEM:PTERODACTYL:ADMIN_USER_TOKEN"),
'Content-type' => 'application/json',
'Accept' => 'Application/vnd.pterodactyl.v1+json',
])->baseUrl(config("SETTINGS::SYSTEM:PTERODACTYL:URL") . '/api');
}
/**
* @return Exception
*/
Expand Down Expand Up @@ -87,6 +96,33 @@ public static function getNodes()
return $response->json()['data'];
}

/**
* @return mixed
* @throws Exception
* @description Returns the infos of a single node
*/
public static function getNode($id) {
try {
$response = self::client()->get('/application/nodes/' . $id);
} catch(Exception $e) {
throw self::getException($e->getMessage());
}
if($response->failed()) throw self::getException("Failed to get node id " . $id . " - " . $response->status());
return $response->json()['attributes'];
}



public static function getServers() {
try {
$response = self::client()->get('/application/servers');
} catch (Exception $e) {
throw self::getException($e->getMessage());
}
if($response->failed()) throw self::getException("Failed to get list of servers - ", $response->status());
return $response->json()['data'];
}

/**
* @return null
* @throws Exception
Expand Down Expand Up @@ -271,4 +307,75 @@ public static function getServerAttributes(int $pterodactylId)
if ($response->failed()) throw self::getException("Failed to get server attributes from pterodactyl - ", $response->status());
return $response->json()['attributes'];
}

/**
* Update Server Resources
* @param Server $server
* @param Product $product
* @return boolean
*/
public static function updateServer(Server $server, Product $product)
{
return self::client()->patch("/application/servers/{$server->pterodactyl_id}/build", [
"allocation" => $server->allocation,
"memory" => $product->memory,
"swap" => $product->swap,
"disk" => $product->disk,
"io" => $product->io,
"cpu" => $product->cpu,
"threads" => null,
"feature_limits" => [
"databases" => $product->databases,
"backups" => $product->backups,
"allocations" => $product->allocations,
]
]);
}
/**
* Power Action Specific Server
* @param Server $server
* @param string $action
* @return boolean
*/
public static function powerAction(Server $server, $action)
{
return self::clientAdmin()->post("/client/servers/{$server->identifier}/power", [
"signal" => $action
]);
}

/**
* Get info about user
*/
public static function getClientUser()
{
return self::clientAdmin()->get("/client/account");
}


/**
* Check if node has enough free resources to allocate the given resources
* @param Node $node
* @param int $requireMemory
* @param int $requireDisk
* @return boolean
*/
public static function checkNodeResources(Node $node, int $requireMemory, int $requireDisk)
{
try {
$response = self::client()->get("/application/nodes/{$node->id}");
} catch (Exception $e) {
throw self::getException($e->getMessage());
}
$node = $response['attributes'];
$freeMemory = $node['memory'] - $node['allocated_resources']['memory'];
$freeDisk = $node['disk'] - $node['allocated_resources']['disk'];
if ($freeMemory < $requireMemory) {
return false;
}
if ($freeDisk < $requireDisk) {
return false;
}
return true;
}
}
12 changes: 11 additions & 1 deletion app/Classes/Settings/Misc.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,17 @@ public function updateSettings(Request $request)
'referral_allowed' => 'nullable|string',
'referral_percentage' => 'nullable|numeric',
'referral_mode' => 'nullable|string',
'ticket_enabled' => 'nullable|string',
]);

$validator->after(function ($validator) use ($request) {
// if enable-recaptcha is true then recaptcha-site-key and recaptcha-secret-key must be set
if ($request->get('enable-recaptcha') == 'true' && (!$request->get('recaptcha-site-key') || !$request->get('recaptcha-secret-key'))) {
$validator->errors()->add('recaptcha-site-key', 'The site key is required if recaptcha is enabled.');
$validator->errors()->add('recaptcha-secret-key', 'The secret key is required if recaptcha is enabled.');
}
});

if ($validator->fails()) {
return redirect(route('admin.settings.index') . '#misc')->with('error', __('Misc settings have not been updated!'))->withErrors($validator)
->withInput();
Expand Down Expand Up @@ -78,7 +87,8 @@ public function updateSettings(Request $request)
"SETTINGS::REFERRAL::REWARD" => "referral_reward",
"SETTINGS::REFERRAL::ALLOWED" => "referral_allowed",
"SETTINGS::REFERRAL:MODE" => "referral_mode",
"SETTINGS::REFERRAL:PERCENTAGE" => "referral_percentage"
"SETTINGS::REFERRAL:PERCENTAGE" => "referral_percentage",
"SETTINGS::TICKET:ENABLED" => "ticket_enabled"


];
Expand Down
9 changes: 9 additions & 0 deletions app/Classes/Settings/System.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Classes\Settings;

use App\Classes\Pterodactyl;
use App\Models\Settings;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
Expand All @@ -16,7 +17,12 @@ public function __construct()
return;
}

public function checkPteroClientkey(){
$response = Pterodactyl::getClientUser();

if ($response->failed()){ return redirect()->back()->with('error', __('Your Key or URL is not correct')); }
return redirect()->back()->with('success', __('Everything is good!'));
}

public function updateSettings(Request $request)
{
Expand All @@ -36,6 +42,7 @@ public function updateSettings(Request $request)
"server-limit-purchase" => "required|min:0|integer",
"pterodactyl-api-key" => "required|string",
"pterodactyl-url" => "required|string",
"pterodactyl-admin-api-key" => "required|string",

]);
if ($validator->fails()) {
Expand Down Expand Up @@ -65,6 +72,7 @@ public function updateSettings(Request $request)
"SETTINGS::SYSTEM:PTERODACTYL:URL" => "pterodactyl-url",
"SETTINGS::SYSTEM:PTERODACTYL:TOKEN" => "pterodactyl-api-key",
"SETTINGS::SYSTEM:ENABLE_LOGIN_LOGO" => "enable-login-logo",
"SETTINGS::SYSTEM:PTERODACTYL:ADMIN_USER_TOKEN" => "pterodactyl-admin-api-key",
];


Expand All @@ -77,6 +85,7 @@ public function updateSettings(Request $request)
return redirect(route('admin.settings.index') . '#system')->with('success', __('System settings updated!'));
}


private function updateIcons(Request $request)
{
$request->validate([
Expand Down
16 changes: 14 additions & 2 deletions app/Http/Controllers/Admin/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public function update(Request $request, User $user)
"email" => "required|string|email",
"credits" => "required|numeric|min:0|max:99999999",
"server_limit" => "required|numeric|min:0|max:1000000",
"role" => Rule::in(['admin', 'mod', 'client', 'member']),
"role" => Rule::in(['admin', 'moderator', 'client', 'member']),
"referral_code" => "required|string|min:2|max:32|unique:users,referral_code,{$user->id}",
]);

Expand Down Expand Up @@ -160,6 +160,17 @@ public function destroy(User $user)
$user->delete();
return redirect()->back()->with('success', __('user has been removed!'));
}
/**
* Verifys the users email
*
* @param User $user
* @return RedirectResponse
*/
public function verifyEmail(Request $request, User $user)
{
$user->verifyEmail();
return redirect()->back()->with('success', __('Email has been verified!'));
}

/**
* @param Request $request
Expand Down Expand Up @@ -285,6 +296,7 @@ public function dataTable()
$suspendText = $user->isSuspended() ? __("Unsuspend") : __("Suspend");
return '
<a data-content="' . __("Login as User") . '" data-toggle="popover" data-trigger="hover" data-placement="top" href="' . route('admin.users.loginas', $user->id) . '" class="btn btn-sm btn-primary mr-1"><i class="fas fa-sign-in-alt"></i></a>
<a data-content="' . __("Verify") . '" data-toggle="popover" data-trigger="hover" data-placement="top" href="' . route('admin.users.verifyEmail', $user->id) . '" class="btn btn-sm btn-secondary mr-1"><i class="fas fa-envelope"></i></a>
<a data-content="' . __("Show") . '" data-toggle="popover" data-trigger="hover" data-placement="top" href="' . route('admin.users.show', $user->id) . '" class="btn btn-sm text-white btn-warning mr-1"><i class="fas fa-eye"></i></a>
<a data-content="' . __("Edit") . '" data-toggle="popover" data-trigger="hover" data-placement="top" href="' . route('admin.users.edit', $user->id) . '" class="btn btn-sm btn-info mr-1"><i class="fas fa-pen"></i></a>
<form class="d-inline" method="post" action="' . route('admin.users.togglesuspend', $user->id) . '">
Expand All @@ -303,7 +315,7 @@ public function dataTable()
case 'admin':
$badgeColor = 'badge-danger';
break;
case 'mod':
case 'moderator':
$badgeColor = 'badge-info';
break;
case 'client':
Expand Down
13 changes: 13 additions & 0 deletions app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
use App\Models\UsefulLink;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\URL;


class HomeController extends Controller
Expand All @@ -18,6 +22,14 @@ public function __construct()
$this->middleware('auth');
}

public function callHome(){
if(Storage::exists("callHome")){return;}
Http::asForm()->post('https://market.controlpanel.gg/callhome.php', [
'id' => Hash::make(URL::current())
]);
Storage::put('callHome', 'This is only used to count the installations of cpgg.');
}

/**
* @description Get the Background Color for the Days-Left-Box in HomeView
*
Expand Down Expand Up @@ -84,6 +96,7 @@ public function index(Request $request)
$unit = $daysLeft < 1 ? ($hoursLeft < 1 ? null : __("hours")) : __("days");
}

$this->callhome();

// RETURN ALL VALUES
return view('home')->with([
Expand Down
Loading

0 comments on commit 5e507ef

Please sign in to comment.