@ -0,0 +1,16 @@ | |||||
root = true | |||||
[*] | |||||
charset = utf-8 | |||||
end_of_line = lf | |||||
insert_final_newline = true | |||||
indent_style = space | |||||
indent_size = 4 | |||||
trim_trailing_whitespace = true | |||||
[*.md] | |||||
trim_trailing_whitespace = false | |||||
[*.yml] | |||||
indent_style = space | |||||
indent_size = 2 |
@ -0,0 +1,15 @@ | |||||
vendor | |||||
.idea | |||||
.vscode | |||||
.vagrant | |||||
.phpunit.result.cache | |||||
database/database.sqlite | |||||
.env | |||||
storage/logs/* | |||||
storage/tmp | |||||
!storage/tmp/.gitkeep | |||||
resources/templates/nginx | |||||
!resources/templates/nginx/.gitkeep |
@ -0,0 +1,37 @@ | |||||
<p align="center"> | |||||
<img title="Laravel Zero" height="100" src="https://raw.githubusercontent.com/laravel-zero/docs/master/images/logo/laravel-zero-readme.png" /> | |||||
</p> | |||||
<p align="center"> | |||||
<a href="https://github.com/laravel-zero/framework/actions"><img src="https://img.shields.io/github/workflow/status/laravel-zero/framework/Continuous%20Integration.svg" alt="Build Status"></img></a> | |||||
<a href="https://scrutinizer-ci.com/g/laravel-zero/framework"><img src="https://img.shields.io/scrutinizer/g/laravel-zero/framework.svg" alt="Quality Score"></img></a> | |||||
<a href="https://packagist.org/packages/laravel-zero/framework"><img src="https://poser.pugx.org/laravel-zero/framework/d/total.svg" alt="Total Downloads"></a> | |||||
<a href="https://packagist.org/packages/laravel-zero/framework"><img src="https://poser.pugx.org/laravel-zero/framework/v/stable.svg" alt="Latest Stable Version"></a> | |||||
<a href="https://packagist.org/packages/laravel-zero/framework"><img src="https://poser.pugx.org/laravel-zero/framework/license.svg" alt="License"></a> | |||||
</p> | |||||
<h4> <center>This is a <bold>community project</bold> and not an official Laravel one </center></h4> | |||||
Laravel Zero was created by, and is maintained by [Nuno Maduro](https://github.com/nunomaduro), and is a micro-framework that provides an elegant starting point for your console application. It is an **unofficial** and customized version of Laravel optimized for building command-line applications. | |||||
- Built on top of the [Laravel](https://laravel.com) components. | |||||
- Optional installation of Laravel [Eloquent](https://laravel-zero.com/docs/database/), Laravel [Logging](https://laravel-zero.com/docs/logging/) and many others. | |||||
- Supports interactive [menus](https://laravel-zero.com/docs/build-interactive-menus/) and [desktop notifications](https://laravel-zero.com/docs/send-desktop-notifications/) on Linux, Windows & MacOS. | |||||
- Ships with a [Scheduler](https://laravel-zero.com/docs/task-scheduling/) and a [Standalone Compiler](https://laravel-zero.com/docs/build-a-standalone-application/). | |||||
- Integration with [Collision](https://github.com/nunomaduro/collision) - Beautiful error reporting | |||||
------ | |||||
## Documentation | |||||
For full documentation, visit [laravel-zero.com](https://laravel-zero.com/). | |||||
## Support the development | |||||
**Do you like this project? Support it by donating** | |||||
- PayPal: [Donate](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=66BYDWAT92N6L) | |||||
- Patreon: [Donate](https://www.patreon.com/nunomaduro) | |||||
## License | |||||
Laravel Zero is an open-source software licensed under the [MIT license](https://github.com/laravel-zero/laravel-zero/blob/stable/LICENSE.md). |
@ -0,0 +1,59 @@ | |||||
<?php | |||||
namespace App\Commands; | |||||
use Illuminate\Console\Scheduling\Schedule; | |||||
use LaravelZero\Framework\Commands\Command; | |||||
use Illuminate\Support\Facades\File; | |||||
use App\Facades\Install; | |||||
use Log; | |||||
class InstallMariadbCommand extends Command | |||||
{ | |||||
/** | |||||
* The signature of the command. | |||||
* | |||||
* @var string | |||||
*/ | |||||
protected $signature = 'install:nginx'; | |||||
/** | |||||
* The description of the command. | |||||
* | |||||
* @var string | |||||
*/ | |||||
protected $description = 'Install mariadb and set configuration'; | |||||
/** | |||||
* Execute the console command. | |||||
* | |||||
* @return mixed | |||||
*/ | |||||
public function handle() | |||||
{ | |||||
$this->info('Mariadb install...'); | |||||
exec('apt update 2>&1'); | |||||
exec('apt install -y mariadb-server mariadb-client 2>&1'); | |||||
$link = mysqli_connect('127.0.0.1', 'root', $password); | |||||
//exec('UPDATE mysql.user SET Password=PASSWORD('${install_mysql_password}') WHERE User='root';'); | |||||
//mysql_query("UPDATE mysql.user SET Password=PASSWORD('$password') WHERE User='root';"); | |||||
// | |||||
mysqli_close($link); | |||||
if (Install::isReady('mariadb-server mariadb-client')) { | |||||
// get status of nginx | |||||
exec('nginx -v 2>&1', $output); | |||||
$status = "$output[0] installed"; | |||||
$this->info($status); | |||||
Log::info($status); | |||||
} | |||||
} | |||||
} |
@ -0,0 +1,60 @@ | |||||
<?php | |||||
namespace App\Commands; | |||||
use Illuminate\Console\Scheduling\Schedule; | |||||
use LaravelZero\Framework\Commands\Command; | |||||
use Illuminate\Support\Facades\File; | |||||
use App\Facades\Install; | |||||
use Log; | |||||
class InstallPhpFpmCommand extends Command | |||||
{ | |||||
/** | |||||
* The signature of the command. | |||||
* | |||||
* @var string | |||||
*/ | |||||
protected $signature = 'install:php-fpm'; | |||||
/** | |||||
* The description of the command. | |||||
* | |||||
* @var string | |||||
*/ | |||||
protected $description = 'Install php-fpm'; | |||||
/** | |||||
* Execute the console command. | |||||
* | |||||
* @return mixed | |||||
*/ | |||||
public function handle() | |||||
{ | |||||
//$option = $this->menu('Install') | |||||
// ->addOption('nginx', 'Nginx') | |||||
// ->open(); | |||||
//File::put('/etc/kkk', '/etc/kkk'); | |||||
//$workers = exec('echo $(grep ^processor /proc/cpuinfo | wc -l)'); | |||||
//$ | |||||
//$ | |||||
$this->info('Install PHP FPM'); | |||||
exec('apt update 2>&1'); | |||||
exec('apt install -y php-fpm php-curl php-mysql php-pear php-mbstring php-dev php-gd 2>&1'); | |||||
if (Install::isReady('nginx')) { | |||||
// get status of nginx | |||||
exec('nginx -v 2>&1', $output); | |||||
$status = "$output[0] installed"; | |||||
$this->info($status); | |||||
Log::info($status); | |||||
} | |||||
} | |||||
} |
@ -0,0 +1,58 @@ | |||||
<?php | |||||
namespace App\Commands; | |||||
use Illuminate\Console\Scheduling\Schedule; | |||||
use LaravelZero\Framework\Commands\Command; | |||||
use Illuminate\Support\Facades\File; | |||||
use App\Facades\Install; | |||||
use Log; | |||||
class InstallUfwCommand extends Command | |||||
{ | |||||
/** | |||||
* The signature of the command. | |||||
* | |||||
* @var string | |||||
*/ | |||||
protected $signature = 'install:nginx'; | |||||
/** | |||||
* The description of the command. | |||||
* | |||||
* @var string | |||||
*/ | |||||
protected $description = 'Install mariadb and set configuration'; | |||||
/** | |||||
* Execute the console command. | |||||
* | |||||
* @return mixed | |||||
*/ | |||||
public function handle() | |||||
{ | |||||
$this->line('Install ufw...'); | |||||
exec('apt update 2>&1'); | |||||
exec('apt install -y ufw 2>&1'); | |||||
exec('ufw allow ssh'); | |||||
exec('ufw allow "Nginx Full"'); | |||||
exec('ufw allow "OpenSSH"'); | |||||
// starting | |||||
exec('service ufw start'); | |||||
exec('echo "y" | ufw enable'); | |||||
if (Install::isReady('ufw')) { | |||||
$status = "Install ufw...success"; | |||||
$this->info($status); | |||||
Log::info($status); | |||||
} else { | |||||
$this->error('Install ufw...failed'); | |||||
} | |||||
} | |||||
} |
@ -0,0 +1,62 @@ | |||||
<?php | |||||
namespace App\Commands; | |||||
use Illuminate\Console\Scheduling\Schedule; | |||||
use LaravelZero\Framework\Commands\Command; | |||||
use Log; | |||||
class MonitoringStateCommand extends Command | |||||
{ | |||||
/** | |||||
* The signature of the command. | |||||
* | |||||
* @var string | |||||
*/ | |||||
protected $signature = 'monitoring:state'; | |||||
/** | |||||
* The description of the command. | |||||
* | |||||
* @var string | |||||
*/ | |||||
protected $description = 'I'; | |||||
/** | |||||
* Execute the console command. | |||||
* | |||||
* @return mixed | |||||
*/ | |||||
public function handle() | |||||
{ | |||||
// getting harddisks | |||||
exec('df -H | grep \'^/dev\'', $harddisks); | |||||
// | |||||
exec('$(apt list --upgradable 2>/dev/null | grep "\-security" | wc -l)', $securityUpgrades); | |||||
if (isset($securityUpgrades[0]) && intval($securityUpgrades[0]) > 0) { | |||||
exec('apt list --upgradable 2>/dev/null | grep "\-security"', $securityUpgrades); | |||||
// remove listening | |||||
if (isset($securityUpgrades[1])) { | |||||
unset($securityUpgrades[1]); | |||||
} | |||||
} | |||||
// getting info of files | |||||
exec('echo $(apt list --upgradable 2>/dev/null | grep -v "\-security" | wc -l)', $upgrades); | |||||
if (isset($upgrades[0]) && intval($upgrades[0]) > 0) { | |||||
exec('apt list --upgradable 2>/dev/null | grep -v "\-security"', $upgrades); | |||||
// remove listening | |||||
if (isset($upgrades[1])) { | |||||
unset($upgrades[1]); | |||||
} | |||||
} | |||||
echo (implode("\n", $upgrades)); | |||||
} | |||||
} |
@ -0,0 +1,126 @@ | |||||
<?php | |||||
namespace App\Commands; | |||||
use Illuminate\Console\Scheduling\Schedule; | |||||
use LaravelZero\Framework\Commands\Command; | |||||
use Illuminate\Support\Facades\File; | |||||
use App\Facades\Install; | |||||
use PhpSchool\CliMenu\Builder\CliMenuBuilder; | |||||
use PhpSchool\CliMenu\CliMenu; | |||||
use PhpSchool\CliMenu\MenuItem\CheckboxItem; | |||||
use PhpSchool\CliMenu\Style\SelectableStyle; | |||||
use Log; | |||||
use App\Facades\Nginx; | |||||
class NginxCertsCommand extends Command | |||||
{ | |||||
/** | |||||
* The signature of the command. | |||||
* | |||||
* @var string | |||||
*/ | |||||
protected $signature = 'nginx:certs'; | |||||
/** | |||||
* The description of the command. | |||||
* | |||||
* @var string | |||||
*/ | |||||
protected $description = 'Create and Manage Nginx Vhosts'; | |||||
/** | |||||
* | |||||
* | |||||
*/ | |||||
/** | |||||
* Execute the console command. | |||||
* | |||||
* @return mixed | |||||
*/ | |||||
public function handle() | |||||
{ | |||||
var_dump(Nginx::getVhosts()); | |||||
// create menu | |||||
//$main = $this->menu('Nginx Let\'s Encrypt'); | |||||
//$main | |||||
// ->addLineBreak('-') | |||||
// ->open(); | |||||
/*** | |||||
$itemCallable = function(CliMenu $menu) { | |||||
// getting sites-available | |||||
$sitesAvailable = scandir('/etc/nginx/sites-available'); | |||||
// getting sites-endabled | |||||
$sitesEnabled = scandir('/etc/nginx/sites-enabled'); | |||||
foreach($sitesAvailable as $site) { | |||||
if ($site !== '.' && $site !== '..') { | |||||
// getting title | |||||
$title = str_replace('.conf', '', $site); | |||||
$checkbox = new CheckboxItem('enabled', function(CliMenu $menu) use ($site, $title) { | |||||
// check status | |||||
if ($menu->getSelectedItem()->getChecked()) { | |||||
symlink('/etc/nginx/sites-available/'.$site, '/etc/nginx/sites-enabled/'.$site); | |||||
$status = 'enabled'; | |||||
} else { | |||||
unlink('/etc/nginx/sites-enabled/'.$site); | |||||
$status = 'disabled'; | |||||
} | |||||
// starting | |||||
exec('service nginx restart'); | |||||
exec('service nginx status', $output); | |||||
if (strpos(implode(' ', $output), 'active') !== false) { | |||||
$menu->confirm($title.' is '.$status.'!')->display('OK!'); | |||||
} else { | |||||
$menu->confirm('Error! Something not working!')->display('OK!'); | |||||
} | |||||
}); | |||||
// adding checkbox | |||||
if (in_array($site, $sitesEnabled)) { | |||||
$checkbox->setChecked(true); | |||||
} | |||||
$menuMain | |||||
->addSubmenu($title, function(CliMenuBuilder $builder) use ($site, $title, $checkbox) { | |||||
$builder->setTitle("Nginx > $title") | |||||
->addItem('edit', function(CliMenu $menu) use ($site, $title) { | |||||
system('nano /etc/nginx/sites-available/'.$site.' > `tty`'); | |||||
}) | |||||
->addItem('delete', function(CliMenu $menu) use ($site) { | |||||
if (file_exists('/etc/nginx/sites-enabled/'.$site)) { | |||||
$menu->confirm('Error! Please disable '.$title.' first!')->display('OK!'); | |||||
} else { | |||||
unlink('/etc/nginx/sites-available/'.$site); | |||||
$menu->confirm("$site is deleted!")->display('OK!'); | |||||
} | |||||
}) | |||||
->addLineBreak('-') | |||||
->addMenuItem($checkbox) | |||||
->addLineBreak('-'); | |||||
}); | |||||
} | |||||
} | |||||
};*/ | |||||
} | |||||
} |
@ -0,0 +1,60 @@ | |||||
<?php | |||||
namespace App\Commands; | |||||
use Illuminate\Console\Scheduling\Schedule; | |||||
use LaravelZero\Framework\Commands\Command; | |||||
use Illuminate\Support\Facades\File; | |||||
use App\Facades\Install; | |||||
use Log; | |||||
class NginxInstallCommand extends Command | |||||
{ | |||||
/** | |||||
* The signature of the command. | |||||
* | |||||
* @var string | |||||
*/ | |||||
protected $signature = 'nginx:install'; | |||||
/** | |||||
* The description of the command. | |||||
* | |||||
* @var string | |||||
*/ | |||||
protected $description = 'Install Nginx'; | |||||
/** | |||||
* Execute the console command. | |||||
* | |||||
* @return mixed | |||||
*/ | |||||
public function handle() | |||||
{ | |||||
//$option = $this->menu('Install') | |||||
// ->addOption('nginx', 'Nginx') | |||||
// ->open(); | |||||
//File::put('/etc/kkk', '/etc/kkk'); | |||||
//$workers = exec('echo $(grep ^processor /proc/cpuinfo | wc -l)'); | |||||
//$ | |||||
//$ | |||||
$this->info('Nginx install...'); | |||||
exec('apt update 2>&1'); | |||||
exec('apt install -y nginx 2>&1'); | |||||
if (Install::isReady('nginx')) { | |||||
// get status of nginx | |||||
exec('nginx -v 2>&1', $output); | |||||
$status = "$output[0] installed"; | |||||
$this->info($status); | |||||
Log::info($status); | |||||
} | |||||
} | |||||
} |
@ -0,0 +1,176 @@ | |||||
<?php | |||||
namespace App\Commands; | |||||
use Illuminate\Console\Scheduling\Schedule; | |||||
use LaravelZero\Framework\Commands\Command; | |||||
use Illuminate\Support\Facades\File; | |||||
use App\Facades\Install; | |||||
use PhpSchool\CliMenu\Builder\CliMenuBuilder; | |||||
use PhpSchool\CliMenu\CliMenu; | |||||
use PhpSchool\CliMenu\MenuItem\CheckboxItem; | |||||
use PhpSchool\CliMenu\Style\SelectableStyle; | |||||
use Log; | |||||
class NginxVhostsCommand extends Command | |||||
{ | |||||
// path templates | |||||
const TEMPLATES_DIR = '/resources/templates/nginx'; | |||||
/** | |||||
* The signature of the command. | |||||
* | |||||
* @var string | |||||
*/ | |||||
protected $signature = 'nginx:vhosts'; | |||||
/** | |||||
* The description of the command. | |||||
* | |||||
* @var string | |||||
*/ | |||||
protected $description = 'Create and Manage Nginx Vhosts'; | |||||
/** | |||||
* | |||||
* | |||||
* | |||||
*/ | |||||
private function add(CliMenuBuilder $builder) | |||||
{ | |||||
} | |||||
/** | |||||
* Execute the console command. | |||||
* | |||||
* @return mixed | |||||
*/ | |||||
public function handle() | |||||
{ | |||||
// create menu | |||||
$main = $this->menu(self::MENU_TITLE) | |||||
->addSubMenu('add', function(CliMenuBuilder $builder) { | |||||
// getting templates | |||||
$templates = scandir(base_path().self::TEMPLATES_DIR); | |||||
foreach($templates as $template) { | |||||
$builder | |||||
->addSubMenu($template, function(CliMenuBuilder $builder) use ($template) { | |||||
$configuration = [ | |||||
'domain' => '', | |||||
'ssl' => true, | |||||
'redirect_www' => true | |||||
]; | |||||
$checkboxSSL = new CheckboxItem('ssl', function(CliMenu $menu) use (&$configuration) { | |||||
$configuration['ssl'] = $menu->getSelectedItem()->getChecked(); | |||||
}); | |||||
$checkboxSSL->setChecked($configuration['ssl']); | |||||
$checkboxRedirect = new CheckboxItem('redirect www', function(CliMenu $menu) use (&$configuration) { | |||||
$configuration['redirect www'] = $menu->getSelectedItem()->getChecked(); | |||||
}); | |||||
$checkboxRedirect->setChecked($configuration['redirect_www']); | |||||
$builder | |||||
->setTitle('Nginx Vhosts > add > '.$template) | |||||
->addItem('domain', function(CliMenu $menu) use (&$configuration) { | |||||
$result = $menu->askText()->ask(); | |||||
$configuration['domain'] = $result->fetch(); | |||||
$menu->getSelectedItem()->setText('domain -> '.$result->fetch()); | |||||
$menu->redraw(); | |||||
}) | |||||
->addLineBreak('-') | |||||
->addMenuItem($checkboxSSL) | |||||
->addMenuItem($checkboxRedirect) | |||||
->addLineBreak('-') | |||||
->addItem('save', function() use (&$configuration) { | |||||
var_dump($configuration); | |||||
}) | |||||
->addLineBreak('-'); | |||||
}); | |||||
} | |||||
//exec('touch /etc/nginx/sites-available/'); | |||||
}) | |||||
->addLineBreak('-'); | |||||
/*** | |||||
$itemCallable = function(CliMenu $menu) { | |||||
// getting sites-available | |||||
$sitesAvailable = scandir('/etc/nginx/sites-available'); | |||||
// getting sites-endabled | |||||
$sitesEnabled = scandir('/etc/nginx/sites-enabled'); | |||||
foreach($sitesAvailable as $site) { | |||||
if ($site !== '.' && $site !== '..') { | |||||
// getting title | |||||
$title = str_replace('.conf', '', $site); | |||||
$checkbox = new CheckboxItem('enabled', function(CliMenu $menu) use ($site, $title) { | |||||
// check status | |||||
if ($menu->getSelectedItem()->getChecked()) { | |||||
symlink('/etc/nginx/sites-available/'.$site, '/etc/nginx/sites-enabled/'.$site); | |||||
$status = 'enabled'; | |||||
} else { | |||||
unlink('/etc/nginx/sites-enabled/'.$site); | |||||
$status = 'disabled'; | |||||
} | |||||
// starting | |||||
exec('service nginx restart'); | |||||
exec('service nginx status', $output); | |||||
if (strpos(implode(' ', $output), 'active') !== false) { | |||||
$menu->confirm($title.' is '.$status.'!')->display('OK!'); | |||||
} else { | |||||
$menu->confirm('Error! Something not working!')->display('OK!'); | |||||
} | |||||
}); | |||||
// adding checkbox | |||||
if (in_array($site, $sitesEnabled)) { | |||||
$checkbox->setChecked(true); | |||||
} | |||||
$menuMain | |||||
->addSubmenu($title, function(CliMenuBuilder $builder) use ($site, $title, $checkbox) { | |||||
$builder->setTitle("Nginx > $title") | |||||
->addItem('edit', function(CliMenu $menu) use ($site, $title) { | |||||
system('nano /etc/nginx/sites-available/'.$site.' > `tty`'); | |||||
}) | |||||
->addItem('delete', function(CliMenu $menu) use ($site) { | |||||
if (file_exists('/etc/nginx/sites-enabled/'.$site)) { | |||||
$menu->confirm('Error! Please disable '.$title.' first!')->display('OK!'); | |||||
} else { | |||||
unlink('/etc/nginx/sites-available/'.$site); | |||||
$menu->confirm("$site is deleted!")->display('OK!'); | |||||
} | |||||
}) | |||||
->addLineBreak('-') | |||||
->addMenuItem($checkbox) | |||||
->addLineBreak('-'); | |||||
}); | |||||
} | |||||
} | |||||
};*/ | |||||
$main->addLineBreak('-')->open(); | |||||
} | |||||
} |
@ -0,0 +1,20 @@ | |||||
<?php | |||||
namespace App\Facades; | |||||
use Illuminate\Support\Facades\Facade; | |||||
/** | |||||
* Install | |||||
* | |||||
* @author Björn Hase | |||||
* @license http://opensource.org/licenses/MIT The MIT License | |||||
* @link https://github.com/nirgendswo/fuzzy-cms GitHub Repository | |||||
*/ | |||||
class Install extends Facade | |||||
{ | |||||
protected static function getFacadeAccessor() | |||||
{ | |||||
return 'App\Helpers\InstallHelper'; | |||||
} | |||||
} |
@ -0,0 +1,20 @@ | |||||
<?php | |||||
namespace App\Facades; | |||||
use Illuminate\Support\Facades\Facade; | |||||
/** | |||||
* Nginx | |||||
* | |||||
* @author Björn Hase | |||||
* @license http://opensource.org/licenses/MIT The MIT License | |||||
* @link https://github.com/nirgendswo/fuzzy-cms GitHub Repository | |||||
*/ | |||||
class Nginx extends Facade | |||||
{ | |||||
protected static function getFacadeAccessor() | |||||
{ | |||||
return 'App\Helpers\NginxHelper'; | |||||
} | |||||
} |
@ -0,0 +1,28 @@ | |||||
<?php | |||||
namespace App\Helpers; | |||||
class InstallHelper | |||||
{ | |||||
// | |||||
const PACKAGE_STATUS = 'Status: install ok installed'; | |||||
/** | |||||
* check if a packege is installed | |||||
* | |||||
* @param string $name | |||||
* @return boolean | |||||
*/ | |||||
public function isReady($name) | |||||
{ | |||||
$result = false; | |||||
exec('echo $(dpkg -s nginx 2>&1 | grep "'.self::PACKAGE_STATUS.'")', $output); | |||||
if (isset($output[0]) && $output[0] === self::PACKAGE_STATUS) { | |||||
$result = true; | |||||
} | |||||
return $result; | |||||
} | |||||
} |
@ -0,0 +1,131 @@ | |||||
<?php | |||||
namespace App\Helpers; | |||||
/** | |||||
* | |||||
* | |||||
* | |||||
* | |||||
*/ | |||||
class NginxHelper | |||||
{ | |||||
// path for available files | |||||
const SITES_AVAILABLE = '/etc/nginx/sites-available'; | |||||
// path for enabled files | |||||
const SITES_ENABLED = '/etc/nginx/sites-enabled'; | |||||
// regex to get files for | |||||
const REGEX_SSL_CERTIFICATE = '/\bssl_certificate\s+\K\S+/'; | |||||
const REGEX_SSL_CERTIFICATE_KEY = '/\bssl_certificate_key\s+\K\S+/'; | |||||
// ignore files | |||||
const IGNORE_FILES = [ | |||||
'.', '..' | |||||
]; | |||||
/** | |||||
* | |||||
* | |||||
* | |||||
* @return array | |||||
* | |||||
*/ | |||||
private function getSitesAvailable() | |||||
{ | |||||
return scandir(self::SITES_AVAILABLE); | |||||
} | |||||
/** | |||||
* | |||||
* | |||||
* | |||||
* @return array | |||||
* | |||||
*/ | |||||
private function getSitesEnabled() | |||||
{ | |||||
return scandir(self::SITES_ENABLED); | |||||
} | |||||
/** | |||||
* find path for certificates in .conf-files | |||||
* | |||||
* | |||||
* ssl_certificate /etc/letsencrypt/live/<domain>/fullchain.pem; | |||||
* ssl_certificate_key /etc/letsencrypt/live/<domain>/privkey.pem; | |||||
* | |||||
*/ | |||||
private function getCertificate($path) | |||||
{ | |||||
$result = [ | |||||
'ssl' => false, | |||||
'ssl_certificate_exists' => false, | |||||
'ssl_certificate_expired_at' => false | |||||
]; | |||||
// getting .conf-file | |||||
$content = file_get_contents($path); | |||||
// check for path of sites | |||||
preg_match(self::REGEX_SSL_CERTIFICATE, $content, $matches); | |||||
preg_match(self::REGEX_SSL_CERTIFICATE_KEY, $content, $matches); | |||||
// check for ssl certificates | |||||
if (count($matches) >= 2) { | |||||
$result['ssl'] = true; | |||||
if (file_exists($matches[0]) && file_exists($matches[1])) { | |||||
$result['ssl_certificate_exists'] = true; | |||||
} | |||||
exec('openssl x509 -noout -dates -in '.$path, $openssl); | |||||
if (isset($openssl[1])) { | |||||
$openssl = str_replace('notAfter=', '', $openssl[1]); | |||||
} | |||||
} | |||||
return $result; | |||||
} | |||||
/** | |||||
* getting vhosts | |||||
* | |||||
*/ | |||||
public function find() | |||||
{ | |||||
$results = []; | |||||
// getting available | |||||
$available = $this->getSitesAvailable(); | |||||
// getting enabled | |||||
$enabled = $this->getSitesEnabled(); | |||||
foreach($available as $filename) | |||||
{ | |||||
if (!in_array($filename, self::IGNORE_FILES)) { | |||||
// getting full path | |||||
$path = self::SITES_AVAILABLE.'/'.$filename; | |||||
// getting certificates from a configuration | |||||
$certificate = $this->getCertificate($path); | |||||
$result = array_merge([ | |||||
'domain' => str_replace('.conf', '', $filename), | |||||
'path' => $path, | |||||
'file' => $filename, | |||||
'enabled' => in_array($filename, $enabled), | |||||
], $certificate); | |||||
$results[] = $result; | |||||
} | |||||
} | |||||
return $results; | |||||
} | |||||
} |
@ -0,0 +1,73 @@ | |||||
<?php | |||||
namespace App\Helpers; | |||||
/** | |||||
* | |||||
* | |||||
* | |||||
* | |||||
*/ | |||||
class NginxTemplateHelper | |||||
{ | |||||
// path for templates files | |||||
const TEMPLATES_PATH = '/ressources/templates'; | |||||
// path for custom template files | |||||
const CUSTOM_TEMPLATES_PATH = '/ressources/templates/custom'; | |||||
/** | |||||
* | |||||
* | |||||
* | |||||
* @return array | |||||
* | |||||
*/ | |||||
private function getTemplates() | |||||
{ | |||||
$results = []; | |||||
array_merge( | |||||
scandir(self::TEMPLATES_PATH), | |||||
scandir(self::CUSTOM_TEMPLATES_PATH) | |||||
); | |||||
return $templates; | |||||
} | |||||
/** | |||||
* | |||||
* @param [type] $files [description] | |||||
* @param [type] $templatePath [description] | |||||
* @return [type] [description] | |||||
*/ | |||||
private function getTemplates($templatePath) | |||||
{ | |||||
$results = []; | |||||
foreach(scandir(base_dir().$templatePath) as $file) { | |||||
if (!in_array($file, self::IGNORE_FILES)) { | |||||
$results[] = [ | |||||
'filename' => $file, | |||||
'path' => $templatePath | |||||
]; | |||||
} | |||||
} | |||||
return $results; | |||||
} | |||||
/** | |||||
* getting templates | |||||
* | |||||
*/ | |||||
public function find() | |||||
{ | |||||
$results = array_merge( | |||||
$this->getTemplates(self::TEMPLATES_DIR), | |||||
$this->getTemplates(self::TEMPLATES_CUSTOM_DIR) | |||||
); | |||||
return $results; | |||||
} | |||||
} |
@ -0,0 +1,28 @@ | |||||
<?php | |||||
namespace App\Providers; | |||||
use Illuminate\Support\ServiceProvider; | |||||
class AppServiceProvider extends ServiceProvider | |||||
{ | |||||
/** | |||||
* Bootstrap any application services. | |||||
* | |||||
* @return void | |||||
*/ | |||||
public function boot() | |||||
{ | |||||
} | |||||
/** | |||||
* Register any application services. | |||||
* | |||||
* @return void | |||||
*/ | |||||
public function register() | |||||
{ | |||||
} | |||||
} |
@ -0,0 +1,50 @@ | |||||
<?php | |||||
/* | |||||
|-------------------------------------------------------------------------- | |||||
| Create The Application | |||||
|-------------------------------------------------------------------------- | |||||
| | |||||
| The first thing we will do is create a new Laravel application instance | |||||
| which serves as the "glue" for all the components of Laravel, and is | |||||
| the IoC container for the system binding all of the various parts. | |||||
| | |||||
*/ | |||||
$app = new LaravelZero\Framework\Application( | |||||
dirname(__DIR__) | |||||
); | |||||
/* | |||||
|-------------------------------------------------------------------------- | |||||
| Bind Important Interfaces | |||||
|-------------------------------------------------------------------------- | |||||
| | |||||
| Next, we need to bind some important interfaces into the container so | |||||
| we will be able to resolve them when needed. The kernels serve the | |||||
| incoming requests to this application from both the web and CLI. | |||||
| | |||||
*/ | |||||
$app->singleton( | |||||
Illuminate\Contracts\Console\Kernel::class, | |||||
LaravelZero\Framework\Kernel::class | |||||
); | |||||
$app->singleton( | |||||
Illuminate\Contracts\Debug\ExceptionHandler::class, | |||||
Illuminate\Foundation\Exceptions\Handler::class | |||||
); | |||||
/* | |||||
|-------------------------------------------------------------------------- | |||||
| Return The Application | |||||
|-------------------------------------------------------------------------- | |||||
| | |||||
| This script returns the application instance. The instance is given to | |||||
| the calling script so we can separate the building of the instances | |||||
| from the actual running of the application and sending responses. | |||||
| | |||||
*/ | |||||
return $app; |
@ -0,0 +1,53 @@ | |||||
{ | |||||
"name": "laravel-zero/laravel-zero", | |||||
"description": "The Laravel Zero Framework.", | |||||
"keywords": ["framework", "laravel", "laravel zero", "console", "cli"], | |||||
"homepage": "https://laravel-zero.com", | |||||
"type": "project", | |||||
"license": "MIT", | |||||
"support": { | |||||
"issues": "https://github.com/laravel-zero/laravel-zero/issues", | |||||
"source": "https://github.com/laravel-zero/laravel-zero" | |||||
}, | |||||
"authors": [ | |||||
{ | |||||
"name": "Nuno Maduro", | |||||
"email": "enunomaduro@gmail.com" | |||||
} | |||||
], | |||||
"require": { | |||||
"php": "^7.2.5", | |||||
"illuminate/log": "^7.0", | |||||
"jenssegers/blade": "^1.3", | |||||
"laminas/laminas-text": "^2.7", | |||||
"laravel-zero/framework": "^7.0", | |||||
"nunomaduro/laravel-console-menu": "^3.0" | |||||
}, | |||||
"require-dev": { | |||||
"mockery/mockery": "^1.3.1", | |||||
"phpunit/phpunit": "^8.5" | |||||
}, | |||||
"autoload": { | |||||
"psr-4": { | |||||
"App\\": "app/" | |||||
} | |||||
}, | |||||
"autoload-dev": { | |||||
"psr-4": { | |||||
"Tests\\": "tests/" | |||||
} | |||||
}, | |||||
"config": { | |||||
"preferred-install": "dist", | |||||
"sort-packages": true, | |||||
"optimize-autoloader": true | |||||
}, | |||||
"scripts": { | |||||
"post-create-project-cmd": [ | |||||
"@php application app:rename" | |||||
] | |||||
}, | |||||
"minimum-stability": "dev", | |||||
"prefer-stable": true, | |||||
"bin": ["application"] | |||||
} |
@ -0,0 +1,60 @@ | |||||
<?php | |||||
return [ | |||||
/* | |||||
|-------------------------------------------------------------------------- | |||||
| Application Name | |||||
|-------------------------------------------------------------------------- | |||||
| | |||||
| This value is the name of your application. This value is used when the | |||||
| framework needs to place the application's name in a notification or | |||||
| any other location as required by the application or its packages. | |||||
| | |||||
*/ | |||||
'name' => 'MCP', | |||||
/* | |||||
|-------------------------------------------------------------------------- | |||||
| Application Version | |||||
|-------------------------------------------------------------------------- | |||||
| | |||||
| This value determines the "version" your application is currently running | |||||
| in. You may want to follow the "Semantic Versioning" - Given a version | |||||
| number MAJOR.MINOR.PATCH when an update happens: https://semver.org. | |||||
| | |||||
*/ | |||||
'version' => app('git.version'), | |||||
/* | |||||
|-------------------------------------------------------------------------- | |||||
| Application Environment | |||||
|-------------------------------------------------------------------------- | |||||
| | |||||
| This value determines the "environment" your application is currently | |||||
| running in. This may determine how you prefer to configure various | |||||
| services the application utilizes. This can be overridden using | |||||
| the global command line "--env" option when calling commands. | |||||
| | |||||
*/ | |||||
'env' => 'development', | |||||
/* | |||||
|-------------------------------------------------------------------------- | |||||
| Autoloaded Service Providers | |||||
|-------------------------------------------------------------------------- | |||||
| | |||||
| The service providers listed here will be automatically loaded on the | |||||
| request to your application. Feel free to add your own services to | |||||
| this array to grant expanded functionality to your applications. | |||||
| | |||||
*/ | |||||
'providers' => [ | |||||
App\Providers\AppServiceProvider::class, | |||||
], | |||||
]; |
@ -0,0 +1,80 @@ | |||||
<?php | |||||
return [ | |||||
/* | |||||
|-------------------------------------------------------------------------- | |||||
| Default Command | |||||
|-------------------------------------------------------------------------- | |||||
| | |||||
| Laravel Zero will always run the command specified below when no command name is | |||||
| provided. Consider update the default command for single command applications. | |||||
| You cannot pass arguments to the default command because they are ignored. | |||||
| | |||||
*/ | |||||
'default' => NunoMaduro\LaravelConsoleSummary\SummaryCommand::class, | |||||
/* | |||||
|-------------------------------------------------------------------------- | |||||
| Commands Paths | |||||
|-------------------------------------------------------------------------- | |||||
| | |||||
| This value determines the "paths" that should be loaded by the console's | |||||
| kernel. Foreach "path" present on the array provided below the kernel | |||||
| will extract all "Illuminate\Console\Command" based class commands. | |||||
| | |||||
*/ | |||||
'paths' => [app_path('Commands')], | |||||
/* | |||||
|-------------------------------------------------------------------------- | |||||
| Added Commands | |||||
|-------------------------------------------------------------------------- | |||||
| | |||||
| You may want to include a single command class without having to load an | |||||
| entire folder. Here you can specify which commands should be added to | |||||
| your list of commands. The console's kernel will try to load them. | |||||
| | |||||
*/ | |||||
'add' => [ | |||||
// .. | |||||
], | |||||
/* | |||||
|-------------------------------------------------------------------------- | |||||
| Hidden Commands | |||||
|-------------------------------------------------------------------------- | |||||
| | |||||
| Your application commands will always be visible on the application list | |||||
| of commands. But you can still make them "hidden" specifying an array | |||||
| of commands below. All "hidden" commands can still be run/executed. | |||||
| | |||||
*/ | |||||
'hidden' => [ | |||||
NunoMaduro\LaravelConsoleSummary\SummaryCommand::class, | |||||
Symfony\Component\Console\Command\HelpCommand::class, | |||||
Illuminate\Console\Scheduling\ScheduleRunCommand::class, | |||||
Illuminate\Console\Scheduling\ScheduleFinishCommand::class, | |||||
Illuminate\Foundation\Console\VendorPublishCommand::class, | |||||
], | |||||
/* | |||||
|-------------------------------------------------------------------------- | |||||
| Removed Commands | |||||
|-------------------------------------------------------------------------- | |||||
| | |||||
| Do you have a service provider that loads a list of commands that | |||||
| you don't need? No problem. Laravel Zero allows you to specify | |||||
| below a list of commands that you don't to see in your app. | |||||
| | |||||
*/ | |||||
'remove' => [ | |||||
// .. | |||||
], | |||||
]; |
@ -0,0 +1,100 @@ | |||||
<?php | |||||
use Monolog\Handler\NullHandler; | |||||
use Monolog\Handler\StreamHandler; | |||||
use Monolog\Handler\SyslogUdpHandler; | |||||
return [ | |||||
/* | |||||
|-------------------------------------------------------------------------- | |||||
| Default Log Channel | |||||
|-------------------------------------------------------------------------- | |||||
| | |||||
| This option defines the default log channel that gets used when writing | |||||
| messages to the logs. The name specified in this option should match | |||||
| one of the channels defined in the "channels" configuration array. | |||||
| | |||||
*/ | |||||
'default' => env('LOG_CHANNEL', 'stack'), | |||||
/* | |||||
|-------------------------------------------------------------------------- | |||||
| Log Channels | |||||
|-------------------------------------------------------------------------- | |||||
| | |||||
| Here you may configure the log channels for your application. Out of | |||||
| the box, Laravel uses the Monolog PHP logging library. This gives | |||||
| you a variety of powerful log handlers / formatters to utilize. | |||||
| | |||||
| Available Drivers: "single", "daily", "slack", "syslog", | |||||
| "errorlog", "monolog", | |||||
| "custom", "stack" | |||||
| | |||||
*/ | |||||
'channels' => [ | |||||
'stack' => [ | |||||
'driver' => 'stack', | |||||
'channels' => ['stderr'], | |||||
'ignore_exceptions' => false, | |||||
], | |||||
'single' => [ | |||||
'driver' => 'single', | |||||
'path' => storage_path('logs/laravel.log'), | |||||
'level' => 'debug', | |||||
], | |||||
'daily' => [ | |||||
'driver' => 'daily', | |||||
'path' => storage_path('logs/laravel.log'), | |||||
'level' => 'debug', | |||||
'days' => 14, | |||||
], | |||||
'slack' => [ | |||||
'driver' => 'slack', | |||||
'url' => env('LOG_SLACK_WEBHOOK_URL'), | |||||
'username' => 'Laravel Log', | |||||
'emoji' => ':boom:', | |||||
'level' => 'critical', | |||||
], | |||||
'papertrail' => [ | |||||
'driver' => 'monolog', | |||||
'level' => 'debug', | |||||
'handler' => SyslogUdpHandler::class, | |||||
'handler_with' => [ | |||||
'host' => env('PAPERTRAIL_URL'), | |||||
'port' => env('PAPERTRAIL_PORT'), | |||||
], | |||||
], | |||||
'stderr' => [ | |||||
'driver' => 'monolog', | |||||
'handler' => StreamHandler::class, | |||||
'formatter' => env('LOG_STDERR_FORMATTER'), | |||||
'with' => [ | |||||
'stream' => 'php://stderr', | |||||
], | |||||
], | |||||
'syslog' => [ | |||||
'driver' => 'syslog', | |||||
'level' => 'debug', | |||||
], | |||||
'errorlog' => [ | |||||
'driver' => 'errorlog', | |||||
'level' => 'debug', | |||||
], | |||||
'null' => [ | |||||
'driver' => 'monolog', | |||||
'handler' => NullHandler::class, | |||||
], | |||||
], | |||||
]; |
@ -0,0 +1,72 @@ | |||||
<?php | |||||
return [ | |||||
/* | |||||
|-------------------------------------------------------------------------- | |||||
| Enabled | |||||
|-------------------------------------------------------------------------- | |||||
| | |||||
| This value determines if the app name should be represented as an | |||||
| ASCII logo. This file provides a sane default location for all | |||||
| information concerning the logo and is display customization. | |||||
| | |||||
*/ | |||||
'enabled' => true, | |||||
/* | |||||
|-------------------------------------------------------------------------- | |||||
| Default Font | |||||
|-------------------------------------------------------------------------- | |||||
| | |||||
| This option defines the font which should be used for rendering. | |||||
| By default, one default font is shipped. However, you are free | |||||
| to download and use additional fonts: http://www.figlet.org. | |||||
| | |||||
*/ | |||||
'font' => \LaravelZero\Framework\Components\Logo\FigletString::DEFAULT_FONT, | |||||
/* | |||||
|-------------------------------------------------------------------------- | |||||
| Output Width | |||||
|-------------------------------------------------------------------------- | |||||
| | |||||
| This option defines the maximum width of the output string. This is | |||||
| used for word-wrap as well as justification. Be careful when using | |||||
| small values, because they may result in an undefined behavior. | |||||
| | |||||
*/ | |||||
'outputWidth' => 80, | |||||
/* | |||||
|-------------------------------------------------------------------------- | |||||
| Justification | |||||
|-------------------------------------------------------------------------- | |||||
| | |||||
| This option defines the justification of the logo text. By default, | |||||
| justification is provided, which will work well on most of your | |||||
| console apps. Of course, you are free to change this value. | |||||
| | |||||
*/ | |||||
'justification' => null, | |||||
/* | |||||
|-------------------------------------------------------------------------- | |||||
| Right To Left | |||||
|-------------------------------------------------------------------------- | |||||
| | |||||
| This option defines the option in which the text is written. By, default | |||||
| the setting of the font-file is used. When justification is not defined, | |||||
| a text written from right-to-left is automatically right-aligned. | |||||
| | |||||
| Possible values: "right-to-left", "left-to-right", null | |||||
| | |||||
*/ | |||||
'rightToLeft' => null, | |||||
]; |
@ -0,0 +1,28 @@ | |||||
#!/usr/bin/env bash | |||||
# | |||||
# | |||||
# | |||||
set -o errexit | |||||
set -o pipefail | |||||
set -o nounset | |||||
_hash=${1:-} | |||||
if [ -z "${_hash}" ]; then | |||||
echo -e "\$1 is required, please check on https://composer.github.io/pubkeys.html" | |||||
exit 0 | |||||
fi | |||||
# installing dependencies | |||||
apt install -y curl php-cli php-mbstring php-dom git unzip | |||||
# download installer | |||||
curl -sS https://getcomposer.org/installer -o composer-setup.php | |||||
# check hash | |||||
php -r "if (hash_file('SHA384', 'composer-setup.php') === '$_hash') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" | |||||
php composer-setup.php --install-dir=/usr/local/bin --filename=composer | |||||
# remove installer | |||||
rm composer-setup.php |
@ -0,0 +1,53 @@ | |||||
#!/usr/bin/env php | |||||
<?php | |||||
define('LARAVEL_START', microtime(true)); | |||||
/* | |||||
|-------------------------------------------------------------------------- | |||||
| Register The Auto Loader | |||||
|-------------------------------------------------------------------------- | |||||
| | |||||
| Composer provides a convenient, automatically generated class loader | |||||
| for our application. We just need to utilize it! We'll require it | |||||
| into the script here so that we do not have to worry about the | |||||
| loading of any our classes "manually". Feels great to relax. | |||||
| | |||||
*/ | |||||
$autoloader = require file_exists(__DIR__.'/vendor/autoload.php') ? __DIR__.'/vendor/autoload.php' : __DIR__.'/../../autoload.php'; | |||||
$app = require_once __DIR__.'/bootstrap/app.php'; | |||||
/* | |||||
|-------------------------------------------------------------------------- | |||||
| Run The Artisan Application | |||||
|-------------------------------------------------------------------------- | |||||
| | |||||
| When we run the console application, the current CLI command will be | |||||
| executed in this console and the response sent back to a terminal | |||||
| or another output device for the developers. Here goes nothing! | |||||
| | |||||
*/ | |||||
$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class); | |||||
$status = $kernel->handle( | |||||
$input = new Symfony\Component\Console\Input\ArgvInput, | |||||
new Symfony\Component\Console\Output\ConsoleOutput | |||||
); | |||||
/* | |||||
|-------------------------------------------------------------------------- | |||||
| Shutdown The Application | |||||
|-------------------------------------------------------------------------- | |||||
| | |||||
| Once Artisan has finished running, we will fire off the shutdown events | |||||
| so that any final work may be done by the application before we shut | |||||
| down the process. This is the last thing to happen to the request. | |||||
| | |||||
*/ | |||||
$kernel->terminate($input, $status); | |||||
exit($status); |
@ -0,0 +1,24 @@ | |||||
<?xml version="1.0" encoding="UTF-8"?> | |||||
<phpunit backupGlobals="false" | |||||
backupStaticAttributes="false" | |||||
bootstrap="vendor/autoload.php" | |||||
colors="true" | |||||
convertErrorsToExceptions="true" | |||||
convertNoticesToExceptions="true" | |||||
convertWarningsToExceptions="true" | |||||
processIsolation="false" | |||||
stopOnFailure="false"> | |||||
<testsuites> | |||||
<testsuite name="Feature"> | |||||
<directory suffix="Test.php">./tests/Feature</directory> | |||||
</testsuite> | |||||
<testsuite name="Unit"> | |||||
<directory suffix="Test.php">./tests/Unit</directory> | |||||
</testsuite> | |||||
</testsuites> | |||||
<filter> | |||||
<whitelist processUncoveredFilesFromWhitelist="true"> | |||||
<directory suffix=".php">./app</directory> | |||||
</whitelist> | |||||
</filter> | |||||
</phpunit> |
@ -0,0 +1 @@ | |||||
/etc/kkk |
@ -0,0 +1,22 @@ | |||||
<?php | |||||
namespace Tests; | |||||
use Illuminate\Contracts\Console\Kernel; | |||||
trait CreatesApplication | |||||
{ | |||||
/** | |||||
* Creates the application. | |||||
* | |||||
* @return \Illuminate\Foundation\Application | |||||
*/ | |||||
public function createApplication() | |||||
{ | |||||
$app = require __DIR__.'/../bootstrap/app.php'; | |||||
$app->make(Kernel::class)->bootstrap(); | |||||
return $app; | |||||
} | |||||
} |
@ -0,0 +1,20 @@ | |||||
<?php | |||||
namespace Tests\Feature; | |||||
use Tests\TestCase; | |||||
class InspiringCommandTest extends TestCase | |||||
{ | |||||
/** | |||||
* A basic test example. | |||||
* | |||||
* @return void | |||||
*/ | |||||
public function testInspiringCommand() | |||||
{ | |||||
$this->artisan('inspiring') | |||||
->expectsOutput('Simplicity is the ultimate sophistication.') | |||||
->assertExitCode(0); | |||||
} | |||||
} |
@ -0,0 +1,10 @@ | |||||
<?php | |||||
namespace Tests; | |||||
use LaravelZero\Framework\Testing\TestCase as BaseTestCase; | |||||
abstract class TestCase extends BaseTestCase | |||||
{ | |||||
use CreatesApplication; | |||||
} |
@ -0,0 +1,18 @@ | |||||
<?php | |||||
namespace Tests\Unit; | |||||
use Tests\TestCase; | |||||
class ExampleTest extends TestCase | |||||
{ | |||||
/** | |||||
* A basic test example. | |||||
* | |||||
* @return void | |||||
*/ | |||||
public function testBasicTest() | |||||
{ | |||||
$this->assertTrue(true); | |||||
} | |||||
} |