Skip to content

Commit

Permalink
Merge pull request #59 from ControlPanel-gg/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
AVMG20 authored Jun 12, 2021
2 parents d622c1f + e615952 commit c17ed53
Show file tree
Hide file tree
Showing 1,949 changed files with 583,685 additions and 462 deletions.
69 changes: 0 additions & 69 deletions .env.dev

This file was deleted.

54 changes: 32 additions & 22 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,38 +1,57 @@
APP_NAME=Laravel
APP_ENV=local
APP_NAME=Dashboard
APP_ENV=production
APP_KEY=
APP_DEBUG=true
APP_DEBUG=false
APP_URL=http://localhost

LOG_CHANNEL=stack
LOG_LEVEL=debug

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_HOST=controlpanel_mysql
DB_PORT=3306
DB_DATABASE=laravel
DB_DATABASE=controlpanel
DB_USERNAME=root
DB_PASSWORD=
DB_PASSWORD=root

#without a pterodactyl api token, this panel won't work!
PTERODACTYL_TOKEN=

#paypal details, you only need sandbox for testing! you can do this by setting the APP_ENV to local
PAYPAL_SANDBOX_SECRET=
PAYPAL_SANDBOX_CLIENT_ID=
PAYPAL_SECRET=
PAYPAL_CLIENT_ID=
PAYPAL_EMAIL=

#set-up for extra discord verification
DISCORD_CLIENT_ID=
DISCORD_CLIENT_SECRET=
DISCORD_REDIRECT_URI=http://localhost:8000/auth/callback
DISCORD_INVITE_URL=https://discord.gg/vrUYdxG4wZ
#set-up will join users automaticly to your discord
DISCORD_BOT_TOKEN=
DISCORD_GUILD_ID=
#set-up will give the verified user the given role
DISCORD_ROLE_ID=

PTERODACTYL_TOKEN=
#nesseary URL's
PTERODACTYL_URL=https://panel.bitsec.dev
PHPMYADMIN_URL=https://mysql.bitsec.dev
DISCORD_INVITE_URL=https://discord.gg/vrUYdxG4wZ


#GOOGLE RECAPTCHA
RECAPTCHA_SITE_KEY=YOUR_API_SITE_KEY
RECAPTCHA_SECRET_KEY=YOUR_API_SECRET_KEY

MAIL_MAILER=smtp
MAIL_HOST=mailhog
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"


#you can leave everything below the way it is
LOG_CHANNEL=stack
LOG_LEVEL=debug

BROADCAST_DRIVER=log
CACHE_DRIVER=file
Expand All @@ -46,15 +65,6 @@ REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_MAILER=smtp
MAIL_HOST=mailhog
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
Expand Down
35 changes: 0 additions & 35 deletions .github/workflows/run_tests.yml

This file was deleted.

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ Homestead.json
Homestead.yaml
npm-debug.log
yarn-error.log
.gitignore
.env.dev
.env.testing
23 changes: 21 additions & 2 deletions BUILDING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Building the development environment

cd into the project directory and run the following command: `sh bin/startdocker`
cd into the project directory and run the following command: `sh bin/startdocker.sh`
This should start building the images and start the containers.

After that you need to go into the controlpanel_php container and run some commands:
Expand All @@ -9,8 +9,27 @@ Type `docker exec -it controlpanel_php ash` to go into the container and run the

```shell
composer install
cp .env.dev .env
cp .env.example .env
php artisan key:generate --force
php artisan storage:link
php artisan migrate --seed --force
```

## Setting up testing environment

Create the .env.testing file to your needs. Then once done you need to go into your phpmyadmin to create a new database named __controlpanel_test__.
Visit http://127.0.0.1:8080/ and create your database.

Now you're ready to run the following commands which switches to the testing config, migrates the test database and seeds it.
After that you can switch back to your dev environment again. Clear the config from cache so changes will be instantly available.

```shell
php artisan key:generate --force --env=testing
php artisan migrate:fresh --seed --env=testing
```

Now when running tests with PHPUnit it will use your testing database and not your local development one.
This is configured in the __phpunit.xml__. You can run your tests by running the command like this. Just type and enter.
`php artisan test`.


6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ command will setup the database tables and then add all of the Nests & Eggs that
php artisan migrate --seed --force
```

### Add some example products
This step is optional, only run this once
``` bash
php artisan db:seed --class=ExampleItemsSeeder --force
```

### Add The First User
``` bash
php artisan make:user
Expand Down
7 changes: 5 additions & 2 deletions app/Classes/Pterodactyl.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,17 @@ public static function client()
])->baseUrl(env('PTERODACTYL_URL') . '/api');
}

//TODO: Extend error handling (maybe logger for more errors when debugging)
/**
* Get user by pterodactyl id
* @param int $pterodactylId
* @return mixed
*/
public static function getUser(int $pterodactylId){
public function getUser(int $pterodactylId){
$response = self::client()->get("/application/users/{$pterodactylId}");
if ($response->failed()) return null;
if ($response->failed()) {
return [];
}
return $response->json()['attributes'];
}

Expand Down
17 changes: 8 additions & 9 deletions app/Console/Commands/ChargeCreditsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,36 +40,35 @@ public function __construct()
*/
public function handle()
{
Server::chunk(10, function ($servers) {
/** @var Server $server */
foreach ($servers as $server) {
Server::chunk(10, function ($servers) {
/** @var Server $server */
foreach ($servers as $server) {

//ignore suspended servers
//ignore suspended servers
if ($server->isSuspended()) {
echo Carbon::now()->isoFormat('LLL') . " Ignoring suspended server";
echo Carbon::now()->isoFormat('LLL') . " Ignoring suspended server";
continue;
}

//vars
$user = $server->user;
$price = ($server->product->price / 30) / 24;


//remove credits or suspend server
if ($user->credits >= $price) {
$user->decrement('credits', $price);

//log
echo Carbon::now()->isoFormat('LLL') . " [CREDIT DEDUCTION] Removed " . number_format($price, 2, '.', '') . " from user (" . $user->name . ") for server (" . $server->name . ")\n";
echo Carbon::now()->isoFormat('LLL') . " [CREDIT DEDUCTION] Removed " . number_format($price, 2, '.', '') . " from user (" . $user->name . ") for server (" . $server->name . ")\n";

} else {
$response = Pterodactyl::client()->post("/application/servers/{$server->pterodactyl_id}/suspend");

if ($response->successful()) {
echo Carbon::now()->isoFormat('LLL') . " [CREDIT DEDUCTION] Suspended server (" . $server->name . ") from user (" . $user->name . ")\n";
echo Carbon::now()->isoFormat('LLL') . " [CREDIT DEDUCTION] Suspended server (" . $server->name . ") from user (" . $user->name . ")\n";
$server->update(['suspended' => now()]);
} else {
echo Carbon::now()->isoFormat('LLL') . " [CREDIT DEDUCTION] CRITICAL ERROR! Unable to suspend server (" . $server->name . ") from user (" . $user->name . ")\n";
echo Carbon::now()->isoFormat('LLL') . " [CREDIT DEDUCTION] CRITICAL ERROR! Unable to suspend server (" . $server->name . ") from user (" . $user->name . ")\n";
dump($response->json());
}
}
Expand Down
22 changes: 12 additions & 10 deletions app/Console/Commands/MakeUserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,17 @@ class MakeUserCommand extends Command
*/
protected $description = 'Create an admin account with the Artisan Console';

private Pterodactyl $pterodactyl;

/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
public function __construct(Pterodactyl $pterodactyl)
{
parent::__construct();
$this->pterodactyl = $pterodactyl;
}

/**
Expand All @@ -44,17 +47,16 @@ public function handle()
$password = $this->option('password') ?? $this->ask('Please specify your password.');

if (strlen($password) < 8) {
print_r('Your password need to be at least 8 characters long');

return false;
$this->alert('Your password need to be at least 8 characters long');
return 0;
}

$response = Pterodactyl::getUser($ptero_id);

if (is_null($response)) {
print_r('It seems that your Pterodactyl ID isnt correct. Rerun the command and input an correct ID');
//TODO: Do something with response (check for status code and give hints based upon that)
$response = $this->pterodactyl->getUser($ptero_id);

return false;
if ($response === []) {
$this->alert('It seems that your Pterodactyl ID is not correct. Rerun the command and input an correct ID');
return 0;
}

$user = User::create([
Expand All @@ -73,6 +75,6 @@ public function handle()
['Admin', $user->role],
]);

return true;
return 1;
}
}
Loading

0 comments on commit c17ed53

Please sign in to comment.