|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * Pterodactyl - Panel |
| 5 | + * Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>. |
| 6 | + * |
| 7 | + * This software is licensed under the terms of the MIT license. |
| 8 | + * https://opensource.org/licenses/MIT |
| 9 | + */ |
| 10 | + |
| 11 | +namespace Pterodactyl\Console\Commands\Node; |
| 12 | + |
| 13 | +use Illuminate\Console\Command; |
| 14 | +use Pterodactyl\Services\Nodes\NodeCreationService; |
| 15 | + |
| 16 | +class MakeNodeCommand extends Command |
| 17 | +{ |
| 18 | + /** |
| 19 | + * @var \Pterodactyl\Services\Nodes\NodeCreationService |
| 20 | + */ |
| 21 | + protected $creationService; |
| 22 | + |
| 23 | + /** |
| 24 | + * @var string |
| 25 | + */ |
| 26 | + protected $signature = 'p:node:make |
| 27 | + {--name= : A name to identify the node.} |
| 28 | + {--description= : A description to identify the node.} |
| 29 | + {--locationId= : A valid locationId.} |
| 30 | + {--fqdn= : The domain name (e.g node.example.com) to be used for connecting to the daemon. An IP address may only be used if you are not using SSL for this node.} |
| 31 | + {--public= : Should the node be public or private? (public=1 / private=0).} |
| 32 | + {--scheme= : Which scheme should be used? (Enable SSL=https / Disable SSL=http).} |
| 33 | + {--proxy= : Is the daemon behind a proxy? (Yes=1 / No=0).} |
| 34 | + {--maintenance= : Should maintenance mode be enabled? (Enable Maintenance mode=1 / Disable Maintenance mode=0).} |
| 35 | + {--maxMemory= : Set the max memory amount.} |
| 36 | + {--overallocateMemory= : Enter the amount of ram to overallocate (% or -1 to overallocate the maximum).} |
| 37 | + {--maxDisk= : Set the max disk amount.} |
| 38 | + {--overallocateDisk= : Enter the amount of disk to overallocate (% or -1 to overallocate the maximum).} |
| 39 | + {--uploadSize= : Enter the maximum upload filesize.} |
| 40 | + {--daemonListeningPort= : Enter the wings listening port.} |
| 41 | + {--daemonSFTPPort= : Enter the wings SFTP listening port.} |
| 42 | + {--daemonBase= : Enter the base folder.}'; |
| 43 | + |
| 44 | + /** |
| 45 | + * @var string |
| 46 | + */ |
| 47 | + protected $description = 'Creates a new node on the system via the CLI.'; |
| 48 | + |
| 49 | + |
| 50 | + /** |
| 51 | + * Handle the command execution process. |
| 52 | + * |
| 53 | + * @throws \Pterodactyl\Exceptions\Model\DataValidationException |
| 54 | + */ |
| 55 | + public function handle(NodeCreationService $creationService) |
| 56 | + { |
| 57 | + $this->creationService = $creationService; |
| 58 | + |
| 59 | + $data['name'] = $this->option('name') ?? $this->ask('Enter a short identifier used to distinguish this node from others'); |
| 60 | + $data['description'] = $this->option('description') ?? $this->ask('Enter a description to identify the node'); |
| 61 | + $data['location_id'] = $this->option('locationId') ?? $this->ask('Enter a valid location id'); |
| 62 | + $data['fqdn'] = $this->option('fqdn') ?? $this->ask('Enter a domain name (e.g node.example.com) to be used for connecting to the daemon. An IP address may only be used if you are not using SSL for this node'); |
| 63 | + if (!filter_var(gethostbyname($data['fqdn']), FILTER_VALIDATE_IP)) { |
| 64 | + $this->error('The FQDN or IP address provided does not resolve to a valid IP address.'); |
| 65 | + return; |
| 66 | + } |
| 67 | + $data['public'] = $this->option('public') ?? $this->confirm('Should this node be public? As a note, setting a node to private you will be denying the ability to auto-deploy to this node.', true); |
| 68 | + $data['scheme'] = $this->option('scheme') ?? $this->anticipate('Please either enter https for SSL or http for a non-ssl connection', |
| 69 | + ["https","http",],"https"); |
| 70 | + if (filter_var($data['fqdn'], FILTER_VALIDATE_IP) && $data['scheme'] === 'https') { |
| 71 | + $this->error('A fully qualified domain name that resolves to a public IP address is required in order to use SSL for this node.'); |
| 72 | + return; |
| 73 | + } |
| 74 | + $data['behind_proxy'] = $this->option('proxy') ?? $this->confirm('Is your FQDN behind a proxy?'); |
| 75 | + $data['maintenance_mode'] = $this->option('maintenance') ?? $this->confirm('Should maintenance mode be enabled?'); |
| 76 | + $data['memory'] = $this->option('maxMemory') ?? $this->ask('Enter the maximum amount of memory'); |
| 77 | + $data['memory_overallocate'] = $this->option('overallocateMemory') ?? $this->ask('Enter the amount of memory to over allocate by, -1 will disable checking and 0 will prevent creating new servers'); |
| 78 | + $data['disk'] = $this->option('maxDisk') ?? $this->ask('Enter the maximum amount of disk space'); |
| 79 | + $data['disk_overallocate'] = $this->option('overallocateDisk') ?? $this->ask('Enter the amount of memory to over allocate by, -1 will disable checking and 0 will prevent creating new server'); |
| 80 | + $data['upload_size'] = $this->option('uploadSize') ?? $this->ask('Enter the maximum filesize upload', '100'); |
| 81 | + $data['daemonListen'] = $this->option('daemonListeningPort') ?? $this->ask('Enter the wings listening port', '8080'); |
| 82 | + $data['daemonSFTP'] = $this->option('daemonSFTPPort') ?? $this->ask('Enter the wings SFTP listening port', '2022'); |
| 83 | + $data['daemonBase'] = $this->option('daemonBase') ?? $this->ask('Enter the base folder', '/var/lib/pterodactyl/volumes'); |
| 84 | + |
| 85 | + $node = $this->creationService->handle($data); |
| 86 | + $this->line('Successfully created a new node on the location ' . $data['location_id'] . ' with the name ' . $data['name'] . ' and has an id of ' . $node->id . '.'); |
| 87 | + } |
| 88 | +} |
0 commit comments