OpenSource CLI-App to install and handle stuff related to Web-Server
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

126 lines
3.9 KiB

4 years ago
  1. <?php
  2. namespace App\Commands;
  3. use Illuminate\Console\Scheduling\Schedule;
  4. use LaravelZero\Framework\Commands\Command;
  5. use Illuminate\Support\Facades\File;
  6. use App\Facades\Install;
  7. use PhpSchool\CliMenu\Builder\CliMenuBuilder;
  8. use PhpSchool\CliMenu\CliMenu;
  9. use PhpSchool\CliMenu\MenuItem\CheckboxItem;
  10. use PhpSchool\CliMenu\Style\SelectableStyle;
  11. use Log;
  12. use App\Facades\Nginx;
  13. class NginxCertsCommand extends Command
  14. {
  15. /**
  16. * The signature of the command.
  17. *
  18. * @var string
  19. */
  20. protected $signature = 'nginx:certs';
  21. /**
  22. * The description of the command.
  23. *
  24. * @var string
  25. */
  26. protected $description = 'Create and Manage Nginx Vhosts';
  27. /**
  28. *
  29. *
  30. */
  31. /**
  32. * Execute the console command.
  33. *
  34. * @return mixed
  35. */
  36. public function handle()
  37. {
  38. var_dump(Nginx::getVhosts());
  39. // create menu
  40. //$main = $this->menu('Nginx Let\'s Encrypt');
  41. //$main
  42. // ->addLineBreak('-')
  43. // ->open();
  44. /***
  45. $itemCallable = function(CliMenu $menu) {
  46. // getting sites-available
  47. $sitesAvailable = scandir('/etc/nginx/sites-available');
  48. // getting sites-endabled
  49. $sitesEnabled = scandir('/etc/nginx/sites-enabled');
  50. foreach($sitesAvailable as $site) {
  51. if ($site !== '.' && $site !== '..') {
  52. // getting title
  53. $title = str_replace('.conf', '', $site);
  54. $checkbox = new CheckboxItem('enabled', function(CliMenu $menu) use ($site, $title) {
  55. // check status
  56. if ($menu->getSelectedItem()->getChecked()) {
  57. symlink('/etc/nginx/sites-available/'.$site, '/etc/nginx/sites-enabled/'.$site);
  58. $status = 'enabled';
  59. } else {
  60. unlink('/etc/nginx/sites-enabled/'.$site);
  61. $status = 'disabled';
  62. }
  63. // starting
  64. exec('service nginx restart');
  65. exec('service nginx status', $output);
  66. if (strpos(implode(' ', $output), 'active') !== false) {
  67. $menu->confirm($title.' is '.$status.'!')->display('OK!');
  68. } else {
  69. $menu->confirm('Error! Something not working!')->display('OK!');
  70. }
  71. });
  72. // adding checkbox
  73. if (in_array($site, $sitesEnabled)) {
  74. $checkbox->setChecked(true);
  75. }
  76. $menuMain
  77. ->addSubmenu($title, function(CliMenuBuilder $builder) use ($site, $title, $checkbox) {
  78. $builder->setTitle("Nginx > $title")
  79. ->addItem('edit', function(CliMenu $menu) use ($site, $title) {
  80. system('nano /etc/nginx/sites-available/'.$site.' > `tty`');
  81. })
  82. ->addItem('delete', function(CliMenu $menu) use ($site) {
  83. if (file_exists('/etc/nginx/sites-enabled/'.$site)) {
  84. $menu->confirm('Error! Please disable '.$title.' first!')->display('OK!');
  85. } else {
  86. unlink('/etc/nginx/sites-available/'.$site);
  87. $menu->confirm("$site is deleted!")->display('OK!');
  88. }
  89. })
  90. ->addLineBreak('-')
  91. ->addMenuItem($checkbox)
  92. ->addLineBreak('-');
  93. });
  94. }
  95. }
  96. };*/
  97. }
  98. }