This commit is contained in:
Saeed Vaziry
2024-03-24 09:56:34 +01:00
committed by GitHub
parent 884f18db63
commit 4d051330d6
1055 changed files with 14493 additions and 20278 deletions

View File

@ -0,0 +1,22 @@
<?php
namespace App\SSH\Composer;
use App\Models\Site;
use App\SSH\HasScripts;
class Composer
{
use HasScripts;
public function installDependencies(Site $site): void
{
$site->server->ssh()->exec(
$this->getScript('composer-install.sh', [
'path' => $site->path,
]),
'composer-install',
$site->id
);
}
}

View File

@ -0,0 +1,7 @@
if ! cd __path__; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! composer install --no-interaction --prefer-dist --optimize-autoloader --no-dev; then
echo 'VITO_SSH_ERROR' && exit 1
fi

27
app/SSH/Cron/Cron.php Normal file
View File

@ -0,0 +1,27 @@
<?php
namespace App\SSH\Cron;
use App\Models\Server;
class Cron
{
public function __construct(protected Server $server)
{
}
public function update(string $user, string $cron): void
{
$command = <<<EOD
if ! echo '$cron' | sudo -u $user crontab -; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo -u $user crontab -l; then
echo 'VITO_SSH_ERROR' && exit 1
fi
EOD;
$this->server->ssh()->exec($command);
}
}

38
app/SSH/Git/Git.php Normal file
View File

@ -0,0 +1,38 @@
<?php
namespace App\SSH\Git;
use App\Models\Site;
use App\SSH\HasScripts;
class Git
{
use HasScripts;
public function clone(Site $site): void
{
$site->server->ssh()->exec(
$this->getScript('clone.sh', [
'host' => str($site->getFullRepositoryUrl())->after('@')->before('-'),
'repo' => $site->getFullRepositoryUrl(),
'path' => $site->path,
'branch' => $site->branch,
'key' => $site->getSshKeyName(),
]),
'clone-repository',
$site->id
);
}
public function checkout(Site $site): void
{
$site->server->ssh()->exec(
$this->getScript('checkout.sh', [
'path' => $site->path,
'branch' => $site->branch,
]),
'checkout-branch',
$site->id
);
}
}

View File

@ -0,0 +1,7 @@
if ! cd __path__; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! git checkout -f __branch__; then
echo 'VITO_SSH_ERROR' && exit 1
fi

27
app/SSH/Git/scripts/clone.sh Executable file
View File

@ -0,0 +1,27 @@
echo "Host __host__-__key__
Hostname __host__
IdentityFile=~/.ssh/__key__" >> ~/.ssh/config
ssh-keyscan -H __host__ >> ~/.ssh/known_hosts
rm -rf __path__
if ! git config --global core.fileMode false; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! git clone -b __branch__ __repo__ __path__; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! find __path__ -type d -exec chmod 755 {} \;; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! find __path__ -type f -exec chmod 644 {} \;; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! cd __path__ && git config core.fileMode false; then
echo 'VITO_SSH_ERROR' && exit 1
fi

20
app/SSH/HasScripts.php Normal file
View File

@ -0,0 +1,20 @@
<?php
namespace App\SSH;
use ReflectionClass;
trait HasScripts
{
private function getScript(string $name, array $vars = []): string
{
$reflector = new ReflectionClass($this);
$scriptsDir = dirname($reflector->getFileName()).'/scripts';
$script = file_get_contents($scriptsDir.'/'.$name);
foreach ($vars as $key => $value) {
$script = str_replace('__'.$key.'__', $value, $script);
}
return $script;
}
}

134
app/SSH/OS/OS.php Normal file
View File

@ -0,0 +1,134 @@
<?php
namespace App\SSH\OS;
use App\Models\Server;
use App\Models\ServerLog;
use App\SSH\HasScripts;
class OS
{
use HasScripts;
public function __construct(protected Server $server)
{
}
public function installDependencies(): void
{
$this->server->ssh()->exec(
$this->getScript('install-dependencies.sh'),
'install-dependencies'
);
}
public function upgrade(): void
{
$this->server->ssh()->exec(
$this->getScript('upgrade.sh'),
'upgrade'
);
}
public function createUser(string $user, string $password, string $key): void
{
$this->server->ssh()->exec(
$this->getScript('create-user.sh', [
'user' => $user,
'password' => $password,
'key' => $key,
]),
'create-user'
);
}
public function getPublicKey(string $user): string
{
return $this->server->ssh()->exec(
$this->getScript('read-file.sh', [
'path' => '/home/'.$user.'/.ssh/id_rsa.pub',
])
);
}
public function deploySSHKey(string $key): void
{
$this->server->ssh()->exec(
$this->getScript('deploy-ssh-key.sh', [
'key' => $key,
]),
'deploy-ssh-key'
);
}
public function deleteSSHKey(string $key): void
{
$this->server->ssh()->exec(
$this->getScript('delete-ssh-key.sh', [
'key' => $key,
'user' => $this->server->getSshUser(),
]),
'delete-ssh-key'
);
}
public function generateSSHKey(string $name): void
{
$this->server->ssh()->exec(
$this->getScript('generate-ssh-key.sh', [
'name' => $name,
]),
'generate-ssh-key'
);
}
public function readSSHKey(string $name): string
{
return $this->server->ssh()->exec(
$this->getScript('read-ssh-key.sh', [
'name' => $name,
]),
);
}
public function reboot(): void
{
$this->server->ssh()->exec(
$this->getScript('reboot.sh'),
);
}
public function editFile(string $path, string $content): void
{
$this->server->ssh()->exec(
$this->getScript('edit-file.sh', [
'path' => $path,
'content' => $content,
]),
);
}
public function readFile(string $path): string
{
return $this->server->ssh()->exec(
$this->getScript('read-file.sh', [
'path' => $path,
])
);
}
public function runScript(string $path, string $script, ?int $siteId = null): ServerLog
{
$ssh = $this->server->ssh();
$ssh->exec(
$this->getScript('run-script.sh', [
'path' => $path,
'script' => $script,
]),
'run-script',
$siteId
);
return $ssh->log;
}
}

View File

@ -0,0 +1,11 @@
export DEBIAN_FRONTEND=noninteractive
echo "__key__" | sudo tee -a /home/root/.ssh/authorized_keys
sudo useradd -p $(openssl passwd -1 __password__) __user__
sudo usermod -aG sudo __user__
echo "__user__ ALL=(ALL) NOPASSWD:ALL" | sudo tee -a /etc/sudoers
sudo mkdir /home/__user__
sudo mkdir /home/__user__/.ssh
echo "__key__" | sudo tee -a /home/__user__/.ssh/authorized_keys
sudo chown -R __user__:__user__ /home/__user__
sudo chsh -s /bin/bash __user__
sudo su - __user__ -c "ssh-keygen -t rsa -N '' -f ~/.ssh/id_rsa" <<< y

View File

@ -0,0 +1 @@
bash -c 'ssh_key_to_delete="$1"; sed -i "\#${ssh_key_to_delete//\//\\/}#d" /home/vito/.ssh/authorized_keys' bash '__key__'

View File

@ -0,0 +1,3 @@
if ! echo '__key__' | sudo tee -a ~/.ssh/authorized_keys; then
echo 'VITO_SSH_ERROR' && exit 1
fi

View File

@ -0,0 +1,3 @@
if ! echo "__content__" | tee __path__; then
echo 'VITO_SSH_ERROR' && exit 1
fi

View File

@ -0,0 +1 @@
ssh-keygen -t rsa -b 4096 -N "" -f ~/.ssh/__name__

View File

@ -0,0 +1 @@
cat ~/.ssh/id_rsa.pub

View File

@ -0,0 +1,3 @@
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y software-properties-common curl zip unzip git gcc openssl
git config --global user.email "__email__"
git config --global user.name "__name__"

View File

@ -0,0 +1 @@
[ -f __path__ ] && cat __path__

View File

@ -0,0 +1 @@
cat ~/.ssh/__name__.pub

View File

@ -0,0 +1,3 @@
echo "Rebooting..."
sudo reboot

View File

@ -0,0 +1,5 @@
if ! cd __path__; then
echo 'VITO_SSH_ERROR' && exit 1
fi
__script__

9
app/SSH/OS/scripts/upgrade.sh Executable file
View File

@ -0,0 +1,9 @@
sudo DEBIAN_FRONTEND=noninteractive apt-get clean
sudo DEBIAN_FRONTEND=noninteractive apt-get update
sudo DEBIAN_FRONTEND=noninteractive apt-get upgrade -y
sudo DEBIAN_FRONTEND=noninteractive apt-get autoremove -y
# Install Node.js
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -;
sudo DEBIAN_FRONTEND=noninteractive apt-get update
sudo DEBIAN_FRONTEND=noninteractive apt-get install nodejs -y

View File

@ -0,0 +1,146 @@
<?php
namespace App\SSH\Services\Database;
use App\Models\BackupFile;
use App\Models\Server;
use App\Models\Service;
use App\SSH\HasScripts;
use App\SSH\Services\ServiceInterface;
abstract class AbstractDatabase implements Database, ServiceInterface
{
use HasScripts;
protected Service $service;
protected Server $server;
abstract protected function getScriptsDir(): string;
public function __construct(Service $service)
{
$this->service = $service;
$this->server = $service->server;
}
public function install(): void
{
$version = $this->service->version;
$command = $this->getScript($this->service->name.'/install-'.$version.'.sh');
$this->server->ssh()->exec($command, 'install-'.$this->service->name.'-'.$version);
$status = $this->server->systemd()->status($this->service->unit);
$this->service->validateInstall($status);
}
public function create(string $name): void
{
$this->server->ssh()->exec(
$this->getScript($this->getScriptsDir().'/create.sh', [
'name' => $name,
]),
'create-database'
);
}
public function delete(string $name): void
{
$this->server->ssh()->exec(
$this->getScript($this->getScriptsDir().'/delete.sh', [
'name' => $name,
]),
'delete-database'
);
}
public function createUser(string $username, string $password, string $host): void
{
$this->server->ssh()->exec(
$this->getScript($this->getScriptsDir().'/create-user.sh', [
'username' => $username,
'password' => $password,
'host' => $host,
]),
'create-user'
);
}
public function deleteUser(string $username, string $host): void
{
$this->server->ssh()->exec(
$this->getScript($this->getScriptsDir().'/delete-user.sh', [
'username' => $username,
'host' => $host,
]),
'delete-user'
);
}
public function link(string $username, string $host, array $databases): void
{
$ssh = $this->server->ssh();
foreach ($databases as $database) {
$ssh->exec(
$this->getScript($this->getScriptsDir().'/link.sh', [
'username' => $username,
'host' => $host,
'database' => $database,
]),
'link-user-to-database'
);
}
}
public function unlink(string $username, string $host): void
{
$this->server->ssh()->exec(
$this->getScript($this->getScriptsDir().'/unlink.sh', [
'username' => $username,
'host' => $host,
]),
'unlink-user-from-databases'
);
}
public function runBackup(BackupFile $backupFile): void
{
// backup
$this->server->ssh()->exec(
$this->getScript($this->getScriptsDir().'/backup.sh', [
'file' => $backupFile->name,
'database' => $backupFile->backup->database->name,
]),
'backup-database'
);
// upload to storage
$upload = $backupFile->backup->storage->provider()->ssh($this->server)->upload(
$backupFile->path(),
$backupFile->storagePath(),
);
// cleanup
$this->server->ssh()->exec('rm '.$backupFile->name.'.zip');
$backupFile->size = $upload['size'];
$backupFile->save();
}
public function restoreBackup(BackupFile $backupFile, string $database): void
{
// download
$backupFile->backup->storage->provider()->ssh($this->server)->download(
$backupFile->storagePath(),
$backupFile->name.'.zip',
);
$this->server->ssh()->exec(
$this->getScript($this->getScriptsDir().'/restore.sh', [
'database' => $database,
'file' => $backupFile->name,
]),
'restore-database'
);
}
}

View File

@ -0,0 +1,24 @@
<?php
namespace App\SSH\Services\Database;
use App\Models\BackupFile;
interface Database
{
public function create(string $name): void;
public function delete(string $name): void;
public function createUser(string $username, string $password, string $host): void;
public function deleteUser(string $username, string $host): void;
public function link(string $username, string $host, array $databases): void;
public function unlink(string $username, string $host): void;
public function runBackup(BackupFile $backupFile): void;
public function restoreBackup(BackupFile $backupFile, string $database): void;
}

View File

@ -0,0 +1,11 @@
<?php
namespace App\SSH\Services\Database;
class Mariadb extends AbstractDatabase
{
protected function getScriptsDir(): string
{
return 'mysql';
}
}

View File

@ -0,0 +1,11 @@
<?php
namespace App\SSH\Services\Database;
class Mysql extends AbstractDatabase
{
protected function getScriptsDir(): string
{
return 'mysql';
}
}

View File

@ -0,0 +1,11 @@
<?php
namespace App\SSH\Services\Database;
class Postgresql extends AbstractDatabase
{
protected function getScriptsDir(): string
{
return 'postgresql';
}
}

View File

@ -0,0 +1,12 @@
wget https://downloads.mariadb.com/MariaDB/mariadb_repo_setup
chmod +x mariadb_repo_setup
sudo DEBIAN_FRONTEND=noninteractive ./mariadb_repo_setup \
--mariadb-server-version="mariadb-10.3"
sudo DEBIAN_FRONTEND=noninteractive apt-get update
sudo DEBIAN_FRONTEND=noninteractive apt-get install mariadb-server mariadb-backup -y
sudo service mysql start

View File

@ -0,0 +1,12 @@
wget https://downloads.mariadb.com/MariaDB/mariadb_repo_setup
chmod +x mariadb_repo_setup
sudo DEBIAN_FRONTEND=noninteractive ./mariadb_repo_setup \
--mariadb-server-version="mariadb-10.4"
sudo DEBIAN_FRONTEND=noninteractive apt-get update
sudo DEBIAN_FRONTEND=noninteractive apt-get install mariadb-server mariadb-backup -y
sudo service mysql start

View File

@ -0,0 +1,11 @@
if ! sudo DEBIAN_FRONTEND=noninteractive mysqldump -u root __database__ > __file__.sql; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! DEBIAN_FRONTEND=noninteractive zip __file__.zip __file__.sql; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! rm __file__.sql; then
echo 'VITO_SSH_ERROR' && exit 1
fi

View File

@ -0,0 +1,9 @@
if ! sudo mysql -e "CREATE USER IF NOT EXISTS '__username__'@'__host__' IDENTIFIED BY '__password__'"; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo mysql -e "FLUSH PRIVILEGES"; then
echo 'VITO_SSH_ERROR' && exit 1
fi
echo "Command executed"

View File

@ -0,0 +1,5 @@
if ! sudo mysql -e "CREATE DATABASE IF NOT EXISTS __name__ CHARACTER SET utf8 COLLATE utf8_general_ci"; then
echo 'VITO_SSH_ERROR' && exit 1
fi
echo "Command executed"

View File

@ -0,0 +1,9 @@
if ! sudo mysql -e "DROP USER IF EXISTS '__username__'@'__host__'"; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo mysql -e "FLUSH PRIVILEGES"; then
echo 'VITO_SSH_ERROR' && exit 1
fi
echo "Command executed"

View File

@ -0,0 +1,5 @@
if ! sudo mysql -e "DROP DATABASE IF EXISTS __name__"; then
echo 'VITO_SSH_ERROR' && exit 1
fi
echo "Command executed"

View File

@ -0,0 +1,13 @@
sudo DEBIAN_FRONTEND=noninteractive apt-get install mysql-server -y
sudo service mysql enable
sudo service mysql start
if ! sudo mysql -e "ALTER USER 'root'@'localhost' IDENTIFIED WITH auth_socket;"; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo mysql -e "FLUSH PRIVILEGES"; then
echo 'VITO_SSH_ERROR' && exit 1
fi

View File

@ -0,0 +1,19 @@
wget -c https://dev.mysql.com/get/mysql-apt-config_0.8.22-1_all.deb
sudo DEBIAN_FRONTEND=noninteractive dpkg -i mysql-apt-config_0.8.22-1_all.deb
sudo DEBIAN_FRONTEND=noninteractive apt-get update
sudo DEBIAN_FRONTEND=noninteractive apt-get install mysql-server -y
sudo service mysql enable
sudo service mysql start
if ! sudo mysql -e "ALTER USER 'root'@'localhost' IDENTIFIED WITH auth_socket;"; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo mysql -e "FLUSH PRIVILEGES"; then
echo 'VITO_SSH_ERROR' && exit 1
fi

View File

@ -0,0 +1,9 @@
if ! sudo mysql -e "GRANT ALL PRIVILEGES ON __database__.* TO '__username__'@'__host__'"; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo mysql -e "FLUSH PRIVILEGES"; then
echo 'VITO_SSH_ERROR' && exit 1
fi
echo "Linking to __database__ finished"

View File

@ -0,0 +1,11 @@
if ! DEBIAN_FRONTEND=noninteractive unzip __file__.zip; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo DEBIAN_FRONTEND=noninteractive mysql -u root __database__ < __file__.sql; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! rm __file__.sql __file__.zip; then
echo 'VITO_SSH_ERROR' && exit 1
fi

View File

@ -0,0 +1,5 @@
if ! sudo mysql -e "REVOKE ALL PRIVILEGES, GRANT OPTION FROM '__username__'@'__host__'"; then
echo 'VITO_SSH_ERROR' && exit 1
fi
echo "Command executed"

View File

@ -0,0 +1,19 @@
if ! sudo -u postgres pg_dump -d __database__ -f /var/lib/postgresql/__file__.sql; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo mv /var/lib/postgresql/__file__.sql /home/vito/__file__.sql; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo chown vito:vito /home/vito/__file__.sql; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! DEBIAN_FRONTEND=noninteractive zip __file__.zip __file__.sql; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! rm __file__.sql; then
echo 'VITO_SSH_ERROR' && exit 1
fi

View File

@ -0,0 +1,5 @@
if ! sudo -u postgres psql -c "CREATE ROLE __username__ WITH LOGIN PASSWORD '__password__';"; then
echo 'VITO_SSH_ERROR' && exit 1
fi
echo "User __username__ created"

View File

@ -0,0 +1,6 @@
if ! sudo -u postgres psql -c "CREATE DATABASE __name__"; then
echo 'VITO_SSH_ERROR' && exit 1
fi
echo "Database __name__ created"

View File

@ -0,0 +1,5 @@
if ! sudo -u postgres psql -c "DROP USER __username__"; then
echo 'VITO_SSH_ERROR' && exit 1
fi
echo "User __username__ deleted"

View File

@ -0,0 +1,5 @@
if ! sudo -u postgres psql -c "DROP DATABASE __name__"; then
echo 'VITO_SSH_ERROR' && exit 1
fi
echo "Database __name__ deleted"

View File

@ -0,0 +1,11 @@
sudo sh -c 'echo "deb https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo DEBIAN_FRONTEND=noninteractive apt-get update -y
sudo DEBIAN_FRONTEND=noninteractive apt-get install postgresql-12 -y
systemctl status postgresql
sudo -u postgres psql -c "SELECT version();"

View File

@ -0,0 +1,11 @@
sudo sh -c 'echo "deb https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo DEBIAN_FRONTEND=noninteractive apt-get update -y
sudo DEBIAN_FRONTEND=noninteractive apt-get install postgresql-13 -y
systemctl status postgresql
sudo -u postgres psql -c "SELECT version();"

View File

@ -0,0 +1,11 @@
sudo sh -c 'echo "deb https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo DEBIAN_FRONTEND=noninteractive apt-get update -y
sudo DEBIAN_FRONTEND=noninteractive apt-get install postgresql-14 -y
systemctl status postgresql
sudo -u postgres psql -c "SELECT version();"

View File

@ -0,0 +1,11 @@
sudo sh -c 'echo "deb https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo DEBIAN_FRONTEND=noninteractive apt-get update -y
sudo DEBIAN_FRONTEND=noninteractive apt-get install postgresql-15 -y
systemctl status postgresql
sudo -u postgres psql -c "SELECT version();"

View File

@ -0,0 +1,11 @@
sudo sh -c 'echo "deb https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo DEBIAN_FRONTEND=noninteractive apt-get update -y
sudo DEBIAN_FRONTEND=noninteractive apt-get install postgresql-16 -y
systemctl status postgresql
sudo -u postgres psql -c "SELECT version();"

View File

@ -0,0 +1,5 @@
if ! sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE __database__ TO __username__;"; then
echo 'VITO_SSH_ERROR' && exit 1
fi
echo "Linking to __database__ finished"

View File

@ -0,0 +1,11 @@
if ! DEBIAN_FRONTEND=noninteractive unzip __file__.zip; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo -u postgres psql -d __database__ -f __file__.sql; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! rm __file__.sql __file__.zip; then
echo 'VITO_SSH_ERROR' && exit 1
fi

View File

@ -0,0 +1,10 @@
USER_TO_REVOKE='__username__'
DATABASES=$(sudo -u postgres psql -t -c "SELECT datname FROM pg_database WHERE datistemplate = false;")
for DB in $DATABASES; do
echo "Revoking privileges in database: $DB"
sudo -u postgres psql -d "$DB" -c "REVOKE ALL PRIVILEGES ON DATABASE \"$DB\" FROM $USER_TO_REVOKE;"
done
echo "Privileges revoked from $USER_TO_REVOKE"

View File

@ -0,0 +1,16 @@
<?php
namespace App\SSH\Services\Firewall;
use App\Models\Service;
use App\SSH\Services\ServiceInterface;
abstract class AbstractFirewall implements Firewall, ServiceInterface
{
protected Service $service;
public function __construct(Service $service)
{
$this->service = $service;
}
}

View File

@ -0,0 +1,10 @@
<?php
namespace App\SSH\Services\Firewall;
interface Firewall
{
public function addRule(string $type, string $protocol, int $port, string $source, ?string $mask): void;
public function removeRule(string $type, string $protocol, int $port, string $source, ?string $mask): void;
}

View File

@ -0,0 +1,46 @@
<?php
namespace App\SSH\Services\Firewall;
use App\SSH\HasScripts;
class Ufw extends AbstractFirewall
{
use HasScripts;
public function install(): void
{
$this->service->server->ssh()->exec(
$this->getScript('ufw/install-ufw.sh'),
'install-ufw'
);
}
public function addRule(string $type, string $protocol, int $port, string $source, ?string $mask): void
{
$this->service->server->ssh()->exec(
$this->getScript('ufw/add-rule.sh', [
'type' => $type,
'protocol' => $protocol,
'port' => $port,
'source' => $source,
'mask' => $mask || $mask == 0 ? '/'.$mask : '',
]),
'add-firewall-rule'
);
}
public function removeRule(string $type, string $protocol, int $port, string $source, ?string $mask): void
{
$this->service->server->ssh()->exec(
$this->getScript('ufw/remove-rule.sh', [
'type' => $type,
'protocol' => $protocol,
'port' => $port,
'source' => $source,
'mask' => $mask || $mask == 0 ? '/'.$mask : '',
]),
'remove-firewall-rule'
);
}
}

View File

@ -0,0 +1,11 @@
if ! sudo ufw __type__ from __source____mask__ to any proto __protocol__ port __port__; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo ufw reload; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo service ufw restart; then
echo 'VITO_SSH_ERROR' && exit 1
fi

View File

@ -0,0 +1,27 @@
if ! sudo ufw default deny incoming; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo ufw default allow outgoing; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo ufw allow from 0.0.0.0/0 to any proto tcp port 22; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo ufw allow from 0.0.0.0/0 to any proto tcp port 80; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo ufw allow from 0.0.0.0/0 to any proto tcp port 443; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo ufw --force enable; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo ufw reload; then
echo 'VITO_SSH_ERROR' && exit 1
fi

View File

@ -0,0 +1,11 @@
if ! sudo ufw delete __type__ from __source____mask__ to any proto __protocol__ port __port__; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo ufw reload; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo service ufw restart; then
echo 'VITO_SSH_ERROR' && exit 1
fi

View File

@ -0,0 +1,88 @@
<?php
namespace App\SSH\Services\PHP;
use App\Exceptions\SSHCommandError;
use App\Models\Service;
use App\SSH\HasScripts;
use App\SSH\Services\ServiceInterface;
use Illuminate\Support\Str;
class PHP implements ServiceInterface
{
use HasScripts;
protected Service $service;
public function __construct(Service $service)
{
$this->service = $service;
}
public function install(): void
{
$server = $this->service->server;
$server->ssh()->exec(
$this->getScript('install-php.sh', [
'version' => $this->service->version,
'user' => $server->getSshUser(),
]),
'install-php-'.$this->service->version
);
}
public function uninstall(): void
{
$this->service->server->ssh()->exec(
$this->getScript('uninstall-php.sh', [
'version' => $this->service->version,
]),
'uninstall-php-'.$this->service->version
);
}
public function setDefaultCli(): void
{
$this->service->server->ssh()->exec(
$this->getScript('change-default-php.sh', [
'version' => $this->service->version,
]),
'change-default-php'
);
}
/**
* @throws SSHCommandError
*/
public function installExtension($name): void
{
$result = $this->service->server->ssh()->exec(
$this->getScript('install-php-extension.sh', [
'version' => $this->service->version,
'name' => $name,
]),
'install-php-extension-'.$name
);
$result = Str::substr($result, strpos($result, '[PHP Modules]'));
if (! Str::contains($result, $name)) {
throw new SSHCommandError('Failed to install extension');
}
}
public function installComposer(): void
{
$this->service->server->ssh()->exec(
$this->getScript('install-composer.sh'),
'install-composer'
);
}
public function getPHPIni(): string
{
return $this->service->server->ssh()->exec(
$this->getScript('get-php-ini.sh', [
'version' => $this->service->version,
])
);
}
}

View File

@ -0,0 +1,11 @@
if ! sudo rm /usr/bin/php; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo ln -s /usr/bin/php__version__ /usr/bin/php; then
echo 'VITO_SSH_ERROR' && exit 1
fi
echo "Default php is: "
php -v

View File

@ -0,0 +1,3 @@
if ! cat /etc/php/__version__/cli/php.ini; then
echo 'VITO_SSH_ERROR' && exit 1
fi

View File

@ -0,0 +1,7 @@
cd ~
curl -sS https://getcomposer.org/installer -o composer-setup.php
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
composer

View File

@ -0,0 +1,5 @@
sudo apt-get install -y php__version__-__name__
sudo service php__version__-fpm restart
php__version__ -m

View File

@ -0,0 +1,15 @@
sudo add-apt-repository ppa:ondrej/php -y
sudo DEBIAN_FRONTEND=noninteractive apt-get update
if ! sudo DEBIAN_FRONTEND=noninteractive apt-get install -y php__version__ php__version__-fpm php__version__-mbstring php__version__-mysql php__version__-gd php__version__-xml php__version__-curl php__version__-gettext php__version__-zip php__version__-bcmath php__version__-soap php__version__-redis php__version__-sqlite3 php__version__-tokenizer php__version__-pgsql php__version__-pdo; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo sed -i 's/www-data/__user__/g' /etc/php/__version__/fpm/pool.d/www.conf; then
echo 'VITO_SSH_ERROR' && exit 1
fi
sudo service php__version__-fpm enable
sudo service php__version__-fpm start

View File

@ -0,0 +1,5 @@
sudo service php__version__-fpm stop
if ! sudo DEBIAN_FRONTEND=noninteractive apt-get remove -y php__version__ php__version__-fpm php__version__-mbstring php__version__-mysql php__version__-mcrypt php__version__-gd php__version__-xml php__version__-curl php__version__-gettext php__version__-zip php__version__-bcmath php__version__-soap php__version__-redis php__version__-sqlite3; then
echo 'VITO_SSH_ERROR' && exit 1
fi

View File

@ -0,0 +1,11 @@
if ! sudo sed -i 's,^__variable__ =.*$,__variable__ = __value__,' /etc/php/__version__/cli/php.ini; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo sed -i 's,^__variable__ =.*$,__variable__ = __value__,' /etc/php/__version__/fpm/php.ini; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo service php__version__-fpm restart; then
echo 'VITO_SSH_ERROR' && exit 1
fi

View File

@ -0,0 +1,16 @@
<?php
namespace App\SSH\Services\ProcessManager;
use App\Models\Service;
use App\SSH\Services\ServiceInterface;
abstract class AbstractProcessManager implements ProcessManager, ServiceInterface
{
protected Service $service;
public function __construct(Service $service)
{
$this->service = $service;
}
}

View File

@ -0,0 +1,27 @@
<?php
namespace App\SSH\Services\ProcessManager;
interface ProcessManager
{
public function create(
int $id,
string $command,
string $user,
bool $autoStart,
bool $autoRestart,
int $numprocs,
string $logFile,
?int $siteId = null
): void;
public function delete(int $id, ?int $siteId = null): void;
public function restart(int $id, ?int $siteId = null): void;
public function stop(int $id, ?int $siteId = null): void;
public function start(int $id, ?int $siteId = null): void;
public function getLogs(string $logPath): string;
}

View File

@ -0,0 +1,136 @@
<?php
namespace App\SSH\Services\ProcessManager;
use App\SSH\HasScripts;
use Throwable;
class Supervisor extends AbstractProcessManager
{
use HasScripts;
public function install(): void
{
$this->service->server->ssh()->exec(
$this->getScript('supervisor/install-supervisor.sh'),
'install-supervisor'
);
}
/**
* @throws Throwable
*/
public function create(
int $id,
string $command,
string $user,
bool $autoStart,
bool $autoRestart,
int $numprocs,
string $logFile,
?int $siteId = null
): void {
$this->service->server->ssh($user)->exec(
$this->getScript('supervisor/create-worker.sh', [
'id' => $id,
'config' => $this->generateConfigFile(
$id,
$command,
$user,
$autoStart,
$autoRestart,
$numprocs,
$logFile
),
]),
'create-worker',
$siteId
);
}
/**
* @throws Throwable
*/
public function delete(int $id, ?int $siteId = null): void
{
$this->service->server->ssh()->exec(
$this->getScript('supervisor/delete-worker.sh', [
'id' => $id,
]),
'delete-worker',
$siteId
);
}
/**
* @throws Throwable
*/
public function restart(int $id, ?int $siteId = null): void
{
$this->service->server->ssh()->exec(
$this->getScript('supervisor/restart-worker.sh', [
'id' => $id,
]),
'restart-worker',
$siteId
);
}
/**
* @throws Throwable
*/
public function stop(int $id, ?int $siteId = null): void
{
$this->service->server->ssh()->exec(
$this->getScript('supervisor/stop-worker.sh', [
'id' => $id,
]),
'stop-worker',
$siteId
);
}
/**
* @throws Throwable
*/
public function start(int $id, ?int $siteId = null): void
{
$this->service->server->ssh()->exec(
$this->getScript('supervisor/start-worker.sh', [
'id' => $id,
]),
'start-worker',
$siteId
);
}
/**
* @throws Throwable
*/
public function getLogs(string $logPath): string
{
return $this->service->server->ssh()->exec(
"tail -100 $logPath"
);
}
private function generateConfigFile(
int $id,
string $command,
string $user,
bool $autoStart,
bool $autoRestart,
int $numprocs,
string $logFile
): string {
return $this->getScript('supervisor/worker.conf', [
'name' => (string) $id,
'command' => $command,
'user' => $user,
'auto_start' => var_export($autoStart, true),
'auto_restart' => var_export($autoRestart, true),
'numprocs' => (string) $numprocs,
'log_file' => $logFile,
]);
}
}

View File

@ -0,0 +1,21 @@
mkdir -p ~/.logs
mkdir -p ~/.logs/workers
touch ~/.logs/workers/__id__.log
if ! echo '__config__' | sudo tee /etc/supervisor/conf.d/__id__.conf; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo supervisorctl reread; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo supervisorctl update; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo supervisorctl start __id__:*; then
echo 'VITO_SSH_ERROR' && exit 1
fi

View File

@ -0,0 +1,20 @@
if ! sudo supervisorctl stop __id__:*; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo rm -rf ~/.logs/workers/__id__.log; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo rm -rf /etc/supervisor/conf.d/__id__.conf; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo supervisorctl reread; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo supervisorctl update; then
echo 'VITO_SSH_ERROR' && exit 1
fi

View File

@ -0,0 +1,5 @@
sudo DEBIAN_FRONTEND=noninteractive apt-get install supervisor -y
sudo service supervisor enable
sudo service supervisor start

View File

@ -0,0 +1,3 @@
if ! sudo supervisorctl restart __id__:*; then
echo 'VITO_SSH_ERROR' && exit 1
fi

View File

@ -0,0 +1,3 @@
if ! sudo supervisorctl start __id__:*; then
echo 'VITO_SSH_ERROR' && exit 1
fi

View File

@ -0,0 +1,3 @@
if ! sudo supervisorctl stop __id__:*; then
echo 'VITO_SSH_ERROR' && exit 1
fi

View File

@ -0,0 +1,10 @@
[program:__name__]
process_name=%(program_name)s_%(process_num)02d
command=__command__
autostart=__auto_start__
autorestart=__auto_restart__
user=__user__
numprocs=__numprocs__
redirect_stderr=true
stdout_logfile=__log_file__
stopwaitsecs=3600

View File

@ -0,0 +1,24 @@
<?php
namespace App\SSH\Services\Redis;
use App\Models\Service;
use App\SSH\HasScripts;
use App\SSH\Services\ServiceInterface;
class Redis implements ServiceInterface
{
use HasScripts;
public function __construct(protected Service $service)
{
}
public function install(): void
{
$this->service->server->ssh()->exec(
$this->getScript('install.sh'),
'install-redis'
);
}
}

View File

@ -0,0 +1,7 @@
sudo DEBIAN_FRONTEND=noninteractive apt-get install redis-server -y
sudo sed -i 's/bind 127.0.0.1 ::1/bind 0.0.0.0/g' /etc/redis/redis.conf
sudo service redis enable
sudo service redis start

View File

@ -0,0 +1,8 @@
<?php
namespace App\SSH\Services;
interface ServiceInterface
{
public function install(): void;
}

View File

@ -0,0 +1,13 @@
<?php
namespace App\SSH\Services\Webserver;
use App\Models\Service;
use App\SSH\Services\ServiceInterface;
abstract class AbstractWebserver implements ServiceInterface, Webserver
{
public function __construct(protected Service $service)
{
}
}

View File

@ -0,0 +1,176 @@
<?php
namespace App\SSH\Services\Webserver;
use App\Exceptions\SSLCreationException;
use App\Models\Site;
use App\Models\Ssl;
use App\SSH\HasScripts;
use Illuminate\Support\Str;
use Throwable;
class Nginx extends AbstractWebserver
{
use HasScripts;
public function install(): void
{
$this->service->server->ssh()->exec(
$this->getScript('nginx/install-nginx.sh', [
'config' => $this->getScript('nginx/nginx.conf', [
'user' => $this->service->server->getSshUser(),
]),
]),
'install-nginx'
);
}
public function createVHost(Site $site): void
{
$this->service->server->ssh()->exec(
$this->getScript('nginx/create-vhost.sh', [
'domain' => $site->domain,
'path' => $site->path,
'vhost' => $this->generateVhost($site),
]),
'create-vhost',
$site->id
);
}
public function updateVHost(Site $site, bool $noSSL = false, ?string $vhost = null): void
{
$this->service->server->ssh()->exec(
$this->getScript('nginx/update-vhost.sh', [
'domain' => $site->domain,
'path' => $site->path,
'vhost' => $this->generateVhost($site, $noSSL),
]),
'update-vhost',
$site->id
);
}
public function getVHost(Site $site): string
{
return $this->service->server->ssh()->exec(
$this->getScript('nginx/get-vhost.sh', [
'domain' => $site->domain,
]),
);
}
public function deleteSite(Site $site): void
{
$this->service->server->ssh()->exec(
$this->getScript('nginx/delete-site.sh', [
'domain' => $site->domain,
'path' => $site->path,
]),
'delete-vhost',
$site->id
);
$this->service->restart();
}
public function changePHPVersion(Site $site, $version): void
{
$this->service->server->ssh()->exec(
$this->getScript('nginx/change-php-version.sh', [
'domain' => $site->domain,
'old_version' => $site->php_version,
'new_version' => $version,
]),
'change-php-version',
$site->id
);
}
/**
* @throws SSLCreationException
*/
public function setupSSL(Ssl $ssl): void
{
$command = $this->getScript('nginx/create-letsencrypt-ssl.sh', [
'email' => $ssl->site->server->creator->email,
'domain' => $ssl->site->domain,
'web_directory' => $ssl->site->getWebDirectoryPath(),
]);
if ($ssl->type == 'custom') {
$command = $this->getScript('nginx/create-custom-ssl.sh', [
'path' => $ssl->getCertsDirectoryPath(),
'certificate' => $ssl->certificate,
'pk' => $ssl->pk,
'certificate_path' => $ssl->getCertificatePath(),
'pk_path' => $ssl->getPkPath(),
]);
}
$result = $this->service->server->ssh()->exec(
$command,
'create-ssl',
$ssl->site_id
);
if (! $ssl->validateSetup($result)) {
throw new SSLCreationException();
}
$this->updateVHost($ssl->site);
}
/**
* @throws Throwable
*/
public function removeSSL(Ssl $ssl): void
{
$this->service->server->ssh()->exec(
'sudo rm -rf '.$ssl->getCertsDirectoryPath().'*',
'remove-ssl',
$ssl->site_id
);
$this->updateVHost($ssl->site, true);
$this->service->server->systemd()->restart('nginx');
}
protected function generateVhost(Site $site, bool $noSSL = false): string
{
$ssl = $site->activeSsl;
if ($noSSL) {
$ssl = null;
}
$vhost = $this->getScript('nginx/vhost.conf');
if ($ssl) {
$vhost = $this->getScript('nginx/vhost-ssl.conf');
}
if ($site->type()->language() === 'php') {
$vhost = $this->getScript('nginx/php-vhost.conf');
if ($ssl) {
$vhost = $this->getScript('nginx/php-vhost-ssl.conf');
}
}
if ($site->port) {
$vhost = $this->getScript('nginx/reverse-vhost.conf');
if ($ssl) {
$vhost = $this->getScript('nginx/reverse-vhost-ssl.conf');
}
$vhost = Str::replace('__port__', (string) $site->port, $vhost);
}
$vhost = Str::replace('__domain__', $site->domain, $vhost);
$vhost = Str::replace('__aliases__', $site->getAliasesString(), $vhost);
$vhost = Str::replace('__path__', $site->path, $vhost);
$vhost = Str::replace('__web_directory__', $site->web_directory, $vhost);
if ($ssl) {
$vhost = Str::replace('__certificate__', $ssl->getCertificatePath(), $vhost);
$vhost = Str::replace('__private_key__', $ssl->getPkPath(), $vhost);
}
if ($site->php_version) {
$vhost = Str::replace('__php_version__', $site->php_version, $vhost);
}
return $vhost;
}
}

View File

@ -0,0 +1,23 @@
<?php
namespace App\SSH\Services\Webserver;
use App\Models\Site;
use App\Models\Ssl;
interface Webserver
{
public function createVHost(Site $site): void;
public function updateVHost(Site $site, bool $noSSL = false, ?string $vhost = null): void;
public function getVHost(Site $site): string;
public function deleteSite(Site $site): void;
public function changePHPVersion(Site $site, string $version): void;
public function setupSSL(Ssl $ssl): void;
public function removeSSL(Ssl $ssl): void;
}

View File

@ -0,0 +1,9 @@
if ! sudo sed -i 's/php__old_version__/php__new_version__/g' /etc/nginx/sites-available/__domain__; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo service nginx restart; then
echo 'VITO_SSH_ERROR' && exit 1
fi
echo "PHP Version Changed to __new_version__"

View File

@ -0,0 +1,13 @@
if ! sudo mkdir -p __path__; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! echo "__certificate__" | sudo tee __certificate_path__; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! echo "__pk__" | sudo tee __pk_path__; then
echo 'VITO_SSH_ERROR' && exit 1
fi
echo "Successfully received certificate."

View File

@ -0,0 +1,3 @@
if ! sudo certbot certonly --force-renewal --nginx --noninteractive --agree-tos --cert-name __domain__ -m __email__ -d __domain__ --verbose; then
echo 'VITO_SSH_ERROR' && exit 1
fi

View File

@ -0,0 +1,27 @@
if ! rm -rf __path__; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! mkdir __path__; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo chown -R 755 __path__; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! echo '' | sudo tee /etc/nginx/conf.d/__domain___redirects; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! echo '__vhost__' | sudo tee /etc/nginx/sites-available/__domain__; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo ln -s /etc/nginx/sites-available/__domain__ /etc/nginx/sites-enabled/; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo service nginx restart; then
echo 'VITO_SSH_ERROR' && exit 1
fi

View File

@ -0,0 +1,7 @@
rm -rf __path__
sudo rm /etc/nginx/sites-available/__domain__
sudo rm /etc/nginx/sites-enabled/__domain__
echo "Site deleted"

View File

@ -0,0 +1 @@
cat /etc/nginx/sites-available/__domain__

View File

@ -0,0 +1,8 @@
sudo DEBIAN_FRONTEND=noninteractive apt-get install nginx -y
if ! echo '__config__' | sudo tee /etc/nginx/nginx.conf; then
echo 'VITO_SSH_ERROR' && exit 1
fi
sudo service nginx start
# install certbot
sudo DEBIAN_FRONTEND=noninteractive apt-get install certbot python3-certbot-nginx -y

View File

@ -0,0 +1,85 @@
user __user__;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
#mail {
# # See sample authentication script at:
# # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
# # auth_http localhost/auth.php;
# # pop3_capabilities "TOP" "USER";
# # imap_capabilities "IMAP4rev1" "UIDPLUS";
#
# server {
# listen localhost:110;
# protocol pop3;
# proxy on;
# }
#
# server {
# listen localhost:143;
# protocol imap;
# proxy on;
# }
#}

View File

@ -0,0 +1,38 @@
server {
listen 80;
listen 443 ssl;
server_name __domain__ www.__domain__;
root __path__/__web_directory__;
ssl on;
ssl_certificate __certificate__;
ssl_certificate_key __private_key__;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";
index index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php__php_version__-fpm.sock;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
include conf.d/__domain___redirects;
}

View File

@ -0,0 +1,33 @@
server {
listen 80;
server_name __domain__ www.__domain__;
root __path__/__web_directory__;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";
index index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php__php_version__-fpm.sock;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
include conf.d/__domain___redirects;
}

View File

@ -0,0 +1,31 @@
server {
listen __port__;
server_name _;
root /home/vito/phpmyadmin;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";
index index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php__php_version__-fpm.sock;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
}

View File

@ -0,0 +1,3 @@
location __from__ {
return __mode__ __to__;
}

View File

@ -0,0 +1,36 @@
server {
listen 80;
listen 443 ssl;
server_name __domain__ __aliases__;
root __path__;
ssl on;
ssl_certificate __certificate__;
ssl_certificate_key __private_key__;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";
index index.php;
charset utf-8;
location / {
proxy_pass http://127.0.0.1:__port__/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Forwarded-For $remote_addr;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.php;
location ~ /\.(?!well-known).* {
deny all;
}
include conf.d/__domain___redirects;
}

View File

@ -0,0 +1,31 @@
server {
listen 80;
server_name __domain__ __aliases__;
root __path__;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";
index index.php;
charset utf-8;
location / {
proxy_pass http://127.0.0.1:__port__/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Forwarded-For $remote_addr;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.php;
location ~ /\.(?!well-known).* {
deny all;
}
include conf.d/__domain___redirects;
}

View File

@ -0,0 +1,7 @@
if ! echo '__redirects__' | sudo tee /etc/nginx/conf.d/__domain___redirects; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo service nginx restart; then
echo 'VITO_SSH_ERROR' && exit 1
fi

View File

@ -0,0 +1,7 @@
if ! echo '__vhost__' | sudo tee /etc/nginx/sites-available/__domain__; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo service nginx restart; then
echo 'VITO_SSH_ERROR' && exit 1
fi

View File

@ -0,0 +1,32 @@
server {
listen 80;
listen 443 ssl;
server_name __domain__ __aliases__;
root __path__/__web_directory__;
ssl on;
ssl_certificate __certificate__;
ssl_certificate_key __private_key__;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";
index index.html;
charset utf-8;
location / {
try_files $uri $uri/ /index.html;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.html;
location ~ /\.(?!well-known).* {
deny all;
}
include conf.d/__domain___redirects;
}

View File

@ -0,0 +1,27 @@
server {
listen 80;
server_name __domain__ __aliases__;
root __path__/__web_directory__;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";
index index.html;
charset utf-8;
location / {
try_files $uri $uri/ /index.html;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.html;
location ~ /\.(?!well-known).* {
deny all;
}
include conf.d/__domain___redirects;
}

View File

@ -0,0 +1,13 @@
<?php
namespace App\SSH\Storage;
use App\Models\Server;
use App\Models\StorageProvider;
abstract class AbstractStorage implements Storage
{
public function __construct(protected Server $server, protected StorageProvider $storageProvider)
{
}
}

View File

@ -0,0 +1,47 @@
<?php
namespace App\SSH\Storage;
use App\Exceptions\SSHCommandError;
use App\SSH\HasScripts;
use Illuminate\Support\Facades\Log;
class Dropbox extends AbstractStorage
{
use HasScripts;
public function upload(string $src, string $dest): array
{
$upload = $this->server->ssh()->exec(
$this->getScript('dropbox/upload.sh', [
'src' => $src,
'dest' => $dest,
'token' => $this->storageProvider->credentials['token'],
]),
'upload-to-dropbox'
);
$data = json_decode($upload, true);
if (isset($data['error'])) {
Log::error('Failed to upload to Dropbox', $data);
throw new SSHCommandError('Failed to upload to Dropbox');
}
return [
'size' => $data['size'] ?? null,
];
}
public function download(string $src, string $dest): void
{
$this->server->ssh()->exec(
$this->getScript('dropbox/download.sh', [
'src' => $src,
'dest' => $dest,
'token' => $this->storageProvider->credentials['token'],
]),
'download-from-dropbox'
);
}
}

Some files were not shown because too many files have changed in this diff Show More