update
This commit is contained in:
parent
38b57104d6
commit
92428a8c33
16 changed files with 212 additions and 59 deletions
|
@ -1,3 +1,5 @@
|
|||
#!/bin/bash
|
||||
|
||||
username=$1
|
||||
schedule=$2
|
||||
command=$3
|
|
@ -1,3 +1,5 @@
|
|||
#!/bin/bash
|
||||
|
||||
username=$1
|
||||
schedule=$2
|
||||
command=$3
|
|
@ -1,3 +1,5 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Replace 'username' with the actual username you want to retrieve cron jobs for
|
||||
username=$1
|
||||
|
30
bin/website-create.sh
Normal file
30
bin/website-create.sh
Normal file
|
@ -0,0 +1,30 @@
|
|||
#!/bin/bash
|
||||
|
||||
DOMAIN=$1
|
||||
USER=$2
|
||||
|
||||
# Path to NGINX sites-available directory
|
||||
SITES_AVAILABLE_DIR="/etc/nginx/sites-available"
|
||||
SITES_ENABLED_DIR="/etc/nginx/sites-enabled"
|
||||
|
||||
# Create the site
|
||||
SERVER_ROOT="/var/www/$DOMAIN/public_html"
|
||||
|
||||
cp -f /usr/local/phyre/samples/ubuntu/nginx.conf.sample $SITES_AVAILABLE_DIR/$DOMAIN.conf
|
||||
ln -s $SITES_AVAILABLE_DIR/$DOMAIN.conf $SITES_ENABLED_DIR/$DOMAIN.conf
|
||||
|
||||
mkdir -p $SERVER_ROOT
|
||||
chown -R www-data:www-data $SERVER_ROOT
|
||||
|
||||
# Replace the domain name in the NGINX config
|
||||
sed -i "s/%SERVER_NAME%/${DOMAIN}/g" $SITES_AVAILABLE_DIR/$DOMAIN.conf
|
||||
sed -i "s/%USER%/${USER}/g" $SITES_AVAILABLE_DIR/$DOMAIN.conf
|
||||
|
||||
SERVER_ROOT_ESCAPED=$(printf '%s\n' "$SERVER_ROOT" | sed -e 's/[\/&]/\\&/g')
|
||||
sed -i "s#%SERVER_ROOT%#${SERVER_ROOT_ESCAPED}#g" $SITES_AVAILABLE_DIR/$DOMAIN.conf
|
||||
|
||||
# Reload NGINX
|
||||
service nginx reload
|
||||
|
||||
echo "Created site $DOMAIN"
|
||||
echo "done!"
|
15
bin/website-delete.sh
Normal file
15
bin/website-delete.sh
Normal file
|
@ -0,0 +1,15 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Path to NGINX sites-available directory
|
||||
sites_available_dir="/etc/nginx/sites-available"
|
||||
sites_enabled_dir="/etc/nginx/sites-enabled"
|
||||
|
||||
# Delete the site
|
||||
rm -rf $sites_available_dir/$1
|
||||
rm -rf $sites_enabled_dir/$1
|
||||
|
||||
# Reload NGINX
|
||||
service nginx reload
|
||||
|
||||
echo "Deleted site $1"
|
||||
echo "done!"
|
24
bin/websites-list.sh
Normal file
24
bin/websites-list.sh
Normal file
|
@ -0,0 +1,24 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Path to NGINX sites-available directory
|
||||
sites_available_dir="/etc/nginx/sites-available"
|
||||
|
||||
# Array to hold site configurations
|
||||
declare -a sites_array=()
|
||||
|
||||
# Loop through NGINX site configuration files and collect data
|
||||
for file in "$sites_available_dir"/*; do
|
||||
if [ -f "$file" ] && [ "$(basename "$file")" != "default" ]; then
|
||||
server_name=$(awk '$1 == "server_name" {gsub(/;/, "", $2); print $2; exit}' "$file")
|
||||
root=$(awk '$1 == "root" {gsub(/;/, "", $2); print $2; exit}' "$file")
|
||||
|
||||
# Append site data to the array
|
||||
sites_array+=("{\"file\": \"$file\", \"server_name\": \"$server_name\", \"root\": \"$root\"}")
|
||||
fi
|
||||
done
|
||||
|
||||
# Convert array to JSON
|
||||
json_output=$(printf '%s\n' "${sites_array[@]}" | jq -s '.')
|
||||
|
||||
# Output JSON
|
||||
echo "$json_output"
|
11
samples/ubuntu/nginx.conf.sample
Normal file
11
samples/ubuntu/nginx.conf.sample
Normal file
|
@ -0,0 +1,11 @@
|
|||
server {
|
||||
|
||||
server_name %SERVER_NAME% www.%SERVER_NAME%;
|
||||
|
||||
root %SERVER_ROOT%;
|
||||
charset utf-8;
|
||||
|
||||
location / {
|
||||
|
||||
}
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Filament\Resources\DomainResource\Pages;
|
||||
|
||||
use App\Filament\Resources\DomainResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateDomain extends CreateRecord
|
||||
{
|
||||
protected static string $resource = DomainResource::class;
|
||||
}
|
|
@ -2,9 +2,9 @@
|
|||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use App\Filament\Resources\DomainResource\Pages;
|
||||
use App\Filament\Resources\DomainResource\RelationManagers;
|
||||
use App\Models\Domain;
|
||||
use App\Filament\Resources\WebsiteResource\Pages;
|
||||
use App\Filament\Resources\WebsiteResource\RelationManagers;
|
||||
use App\Models\Website;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Resources\Resource;
|
||||
|
@ -13,17 +13,23 @@ use Filament\Tables\Table;
|
|||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
|
||||
class DomainResource extends Resource
|
||||
class WebsiteResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Domain::class;
|
||||
protected static ?string $model = Website::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-globe-europe-africa';
|
||||
|
||||
protected static ?int $navigationSort = 4;
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
//
|
||||
Forms\Components\TextInput::make('server_name')
|
||||
->autofocus()
|
||||
->required()
|
||||
->unique()
|
||||
->placeholder('example.com'),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -31,9 +37,12 @@ class DomainResource extends Resource
|
|||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('label')
|
||||
Tables\Columns\TextColumn::make('server_name')
|
||||
->searchable()
|
||||
->sortable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('root')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
|
@ -58,9 +67,9 @@ class DomainResource extends Resource
|
|||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListDomains::route('/'),
|
||||
'create' => Pages\CreateDomain::route('/create'),
|
||||
'edit' => Pages\EditDomain::route('/{record}/edit'),
|
||||
'index' => Pages\ListWebsites::route('/'),
|
||||
'create' => Pages\CreateWebsite::route('/create'),
|
||||
'edit' => Pages\EditWebsite::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
namespace App\Filament\Resources\WebsiteResource\Pages;
|
||||
|
||||
use App\Filament\Resources\WebsiteResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateWebsite extends CreateRecord
|
||||
{
|
||||
protected static string $resource = WebsiteResource::class;
|
||||
}
|
|
@ -1,14 +1,14 @@
|
|||
<?php
|
||||
|
||||
namespace App\Filament\Resources\DomainResource\Pages;
|
||||
namespace App\Filament\Resources\WebsiteResource\Pages;
|
||||
|
||||
use App\Filament\Resources\DomainResource;
|
||||
use App\Filament\Resources\WebsiteResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditDomain extends EditRecord
|
||||
class EditWebsite extends EditRecord
|
||||
{
|
||||
protected static string $resource = DomainResource::class;
|
||||
protected static string $resource = WebsiteResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
|
@ -1,14 +1,14 @@
|
|||
<?php
|
||||
|
||||
namespace App\Filament\Resources\DomainResource\Pages;
|
||||
namespace App\Filament\Resources\WebsiteResource\Pages;
|
||||
|
||||
use App\Filament\Resources\DomainResource;
|
||||
use App\Filament\Resources\WebsiteResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListDomains extends ListRecords
|
||||
class ListWebsites extends ListRecords
|
||||
{
|
||||
protected static string $resource = DomainResource::class;
|
||||
protected static string $resource = WebsiteResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
|
@ -13,9 +13,7 @@ class Backup extends Model
|
|||
public function getRows()
|
||||
{
|
||||
return [
|
||||
['id' => 1, 'label' => 'admin'],
|
||||
['id' => 2, 'label' => 'manager'],
|
||||
['id' => 3, 'label' => 'user'],
|
||||
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ class CronJob extends Model
|
|||
|
||||
static::creating(function ($model) {
|
||||
$args = escapeshellarg($model->user) .' '. escapeshellarg($model->schedule) . ' ' . escapeshellarg($model->command);
|
||||
$addCron = shell_exec('/usr/local/phyre/bin/add-cron-job.sh ' . $args);
|
||||
$addCron = shell_exec('/usr/local/phyre/bin/cron-job-add.sh ' . $args);
|
||||
if (empty($addCron)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ class CronJob extends Model
|
|||
|
||||
$args = escapeshellarg($model->user) .' '. escapeshellarg($model->schedule) . ' ' . escapeshellarg($model->command);
|
||||
$args = str_replace(PHP_EOL, '', $args);
|
||||
$command = '/usr/local/phyre/bin/delete-cron-job.sh ' . $args;
|
||||
$command = '/usr/local/phyre/bin/cron-job-delete.sh ' . $args;
|
||||
$deleteCron = shell_exec($command);
|
||||
if (empty($deleteCron)) {
|
||||
return false;
|
||||
|
@ -55,7 +55,7 @@ class CronJob extends Model
|
|||
public function getRows()
|
||||
{
|
||||
$user = shell_exec('whoami');
|
||||
$cronList = shell_exec('/usr/local/phyre/bin/list-cron-jobs.sh ' . $user);
|
||||
$cronList = shell_exec('/usr/local/phyre/bin/cron-jobs-list.sh ' . $user);
|
||||
|
||||
$rows = [];
|
||||
if (!empty($cronList)) {
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Sushi\Sushi;
|
||||
|
||||
class Domain extends Model
|
||||
{
|
||||
use Sushi;
|
||||
|
||||
public function getRows()
|
||||
{
|
||||
return [
|
||||
['id' => 1, 'label' => 'admin'],
|
||||
['id' => 2, 'label' => 'manager'],
|
||||
['id' => 3, 'label' => 'user'],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
82
web/app/Models/Website.php
Normal file
82
web/app/Models/Website.php
Normal file
|
@ -0,0 +1,82 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Sushi\Sushi;
|
||||
|
||||
class Website extends Model
|
||||
{
|
||||
use Sushi;
|
||||
|
||||
protected $fillable = [
|
||||
'file',
|
||||
'server_name',
|
||||
'root'
|
||||
];
|
||||
|
||||
protected $schema = [
|
||||
'file' => 'string',
|
||||
'server_name' => 'string',
|
||||
'root' => 'string'
|
||||
];
|
||||
|
||||
public static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::creating(function ($model) {
|
||||
|
||||
$args = escapeshellarg($model->server_name) . ' ' . escapeshellarg('bobi');
|
||||
$args = str_replace(PHP_EOL, '', $args);
|
||||
$command = '/usr/local/phyre/bin/website-create.sh ' . $args;
|
||||
$createWebsite = shell_exec($command);
|
||||
if (empty($createWebsite)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
dd($createWebsite);
|
||||
|
||||
});
|
||||
|
||||
static::deleting(function ($model) {
|
||||
|
||||
$args = escapeshellarg($model->server_name);
|
||||
$args = str_replace(PHP_EOL, '', $args);
|
||||
$command = '/usr/local/phyre/bin/website-delete.sh ' . $args;
|
||||
$deleteWebsite = shell_exec($command);
|
||||
if (empty($deleteWebsite)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
protected function sushiShouldCache()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getRows()
|
||||
{
|
||||
$websitesList = shell_exec('/usr/local/phyre/bin/websites-list.sh');
|
||||
$rows = [];
|
||||
if (!empty($websitesList)) {
|
||||
$websitesList = json_decode($websitesList, true);
|
||||
if (!empty($websitesList)) {
|
||||
foreach ($websitesList as $website) {
|
||||
if (isset($website['file'])) {
|
||||
$rows[] = [
|
||||
'file' => $website['file'],
|
||||
'server_name' => $website['server_name'],
|
||||
'root' => $website['root']
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $rows;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue