mirror of
https://github.com/vitodeploy/vito.git
synced 2025-04-20 02:11:36 +00:00
Compare commits
228 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
fb651ab5ce | ||
|
c2625a7352 | ||
|
b72a2ddb1c | ||
|
0e8e6ef56f | ||
|
39fa25aee7 | ||
|
945c2e75c0 | ||
|
82933e29ff | ||
|
82c1f36ef6 | ||
|
e06d23b31a | ||
|
f0e7faa0e7 | ||
|
319fdb44e7 | ||
|
b62c40c97d | ||
|
e39e8c17a2 | ||
|
1391eb32d8 | ||
|
7f5e68e131 | ||
|
431da1b728 | ||
|
8c487a64fa | ||
|
a67e586a5d | ||
|
960db714b7 | ||
|
7da0221ccb | ||
|
9ac5f9ebb3 | ||
|
ed8965b92b | ||
|
9473d198e1 | ||
|
55269dbcde | ||
|
3d67153912 | ||
|
11e3b167cc | ||
|
ad027eb033 | ||
|
e031bafba5 | ||
|
b5c8d99ef8 | ||
|
109d644ad8 | ||
|
5ccbab74b1 | ||
|
7d367465ff | ||
|
eec83f577c | ||
|
fd77368cf3 | ||
|
a862a603f2 | ||
|
3b42f93654 | ||
|
661292df5e | ||
|
0cfb938320 | ||
|
dd4a3d30c0 | ||
|
2b849c888e | ||
|
d9a791755e | ||
|
e3ea8f975f | ||
|
de468ae1ba | ||
|
30ef8ad5eb | ||
|
88223a61f9 | ||
|
1067a5fd33 | ||
|
4361305206 | ||
|
fe331fd2b3 | ||
|
bbe3ca802d | ||
|
765ac21916 | ||
|
016886f307 | ||
|
179aefefac | ||
|
e704a13d6b | ||
|
9936958259 | ||
|
f81d928c66 | ||
|
3c4435701d | ||
|
ebbd81348a | ||
|
5debbd4f5d | ||
|
d846acaa8d | ||
|
35f896eab1 | ||
|
25977d2ead | ||
|
f0da1c6d8c | ||
|
e2dd9177f7 | ||
|
5a9e8d6799 | ||
|
868b70f530 | ||
|
d07e9bcad2 | ||
|
0cd815cce6 | ||
|
5ab6617b5d | ||
|
72b37c56fd | ||
|
8a4ef66946 | ||
|
4517ca7d2a | ||
|
75aed62d75 | ||
|
aaef73d89d | ||
|
f03a029e36 | ||
|
52d195710b | ||
|
ddacc32e64 | ||
|
2ae9a14d02 | ||
|
3019c3d213 | ||
|
c43869d255 | ||
|
18748f77ac | ||
|
052e28d2e3 | ||
|
87ec0af697 | ||
|
e9016737d4 | ||
|
f34d5eb82b | ||
|
12c500e125 | ||
|
2d566b853f | ||
|
ca93b521ec | ||
|
bce05d3171 | ||
|
929dd1dbaa | ||
|
2bcd145bea | ||
|
c0f903d4ca | ||
|
cca4ab7ae3 | ||
|
51e7325d3d | ||
|
ce085879c1 | ||
|
8a49003e9e | ||
|
dcc4276f09 | ||
|
f089779045 | ||
|
f1efb9a6c8 | ||
|
a7d472fb45 | ||
|
d01d406d3d | ||
|
c66c50835a | ||
|
b6179d6693 | ||
|
9244e69fd8 | ||
|
a7ba095919 | ||
|
807ae01646 | ||
|
cc896d82e9 | ||
|
d16d3c1385 | ||
|
3946cf6b34 | ||
|
165212fed2 | ||
|
f6b36dfefc | ||
|
33594f2dba | ||
|
f68d6c7ca2 | ||
|
d504588f95 | ||
|
a0af4e3e9d | ||
|
ca0e33be2f | ||
|
4d051330d6 | ||
|
ab2d6f64f3 | ||
|
d9a56f95dd | ||
|
7fc7944354 | ||
|
9ef7bf1bc9 | ||
|
35e5e16df9 | ||
|
369bf1b965 | ||
|
ee2b53f824 | ||
|
46845fb41f | ||
|
c78462b173 | ||
|
5f192d69de | ||
|
884f18db63 | ||
|
3afb6b7eb4 | ||
|
6529c349b1 | ||
|
6389e592a4 | ||
|
9f577ef2d0 | ||
|
77a09cec48 | ||
|
7b0a71fb57 | ||
|
d5a567cc11 | ||
|
536df65fc6 | ||
|
3575a6d469 | ||
|
4137e2003f | ||
|
d4f1a2d4da | ||
|
d3aaf2a6fa | ||
|
7949165648 | ||
|
3dc38bf56b | ||
|
4f252caaf3 | ||
|
839e7f496c | ||
|
b07ae470f9 | ||
|
f0c4fc4812 | ||
|
46d320561e | ||
|
1333acf1ef | ||
|
77d6914cd9 | ||
|
7a6dcb5654 | ||
|
fd93f3dd47 | ||
|
d8056441c0 | ||
|
287c9c2a8a | ||
|
a406491160 | ||
|
4f12de9586 | ||
|
f907bacdd0 | ||
|
428140b931 | ||
|
cee4a70c3c | ||
|
60e2dc0807 | ||
|
9d705592da | ||
|
cfc0645002 | ||
|
b2083fc6b2 | ||
|
5b2c419e91 | ||
|
470274279b | ||
|
44d8364a52 | ||
|
d321fd5a1e | ||
|
5a60f3b15f | ||
|
d1f424aa47 | ||
|
debcd002f1 | ||
|
59e8c82e5c | ||
|
682da0d6d5 | ||
|
9db310a06b | ||
|
f70963d6bb | ||
|
b75df8e1c5 | ||
|
a22e9cb946 | ||
|
b2b9bea0b1 | ||
|
3f4a2bce3a | ||
|
8bffefabef | ||
|
3da1f4fe4c | ||
|
2214a76e09 | ||
|
55bf8b8ecf | ||
|
0420babdef | ||
|
1c3d78a5ed | ||
|
8665435bc4 | ||
|
0ec6a9dea2 | ||
|
bdfda05398 | ||
|
919cdc6892 | ||
|
902548e463 | ||
|
2462b31f3b | ||
|
e997d0deea | ||
|
f06b8f7d20 | ||
|
f120a570e8 | ||
|
2d7f225ff2 | ||
|
31bd146239 | ||
|
10a6bb57a8 | ||
|
fd2244d382 | ||
|
551f1ce40e | ||
|
1ce92d9361 | ||
|
ec6e55e30c | ||
|
4cda14f4b8 | ||
|
5e6d338bdc | ||
|
7312e3f515 | ||
|
b771db882b | ||
|
94977797cc | ||
|
c45872df55 | ||
|
16fae5334c | ||
|
7b8deddeca | ||
|
1bf3c94358 | ||
|
700cc5f44c | ||
|
9d13cc0756 | ||
|
f51d7900f0 | ||
|
4bd4b34d24 | ||
|
7c5505be16 | ||
|
7249cf9ed6 | ||
|
8282d39722 | ||
|
38e23a1ceb | ||
|
1e1204fe40 | ||
|
7d98986f52 | ||
|
2c81e324f6 | ||
|
422da431ec | ||
|
6c27215ea1 | ||
|
fb840204ad | ||
|
e07e197dd9 | ||
|
3a2dba4ad3 | ||
|
b990f9ce32 | ||
|
a6727ff459 | ||
|
170535760f | ||
|
648529c3bd | ||
|
84192b7cb7 |
58
.env.example
58
.env.example
@ -2,65 +2,15 @@ APP_NAME=Vito
|
|||||||
APP_ENV=local
|
APP_ENV=local
|
||||||
APP_KEY=
|
APP_KEY=
|
||||||
APP_DEBUG=true
|
APP_DEBUG=true
|
||||||
APP_URL=http://localhost:2080
|
APP_URL=
|
||||||
|
|
||||||
LOG_CHANNEL=stack
|
|
||||||
LOG_LEVEL=debug
|
|
||||||
|
|
||||||
DB_CONNECTION=mysql
|
|
||||||
DB_HOST=127.0.0.1
|
|
||||||
DB_PORT=3306
|
|
||||||
DB_DATABASE=vito
|
|
||||||
DB_USERNAME=root
|
|
||||||
DB_PASSWORD=
|
|
||||||
|
|
||||||
BROADCAST_DRIVER=null
|
|
||||||
CACHE_DRIVER=redis
|
|
||||||
FILESYSTEM_DRIVER=local
|
FILESYSTEM_DRIVER=local
|
||||||
QUEUE_CONNECTION=sync
|
|
||||||
SESSION_DRIVER=database
|
|
||||||
SESSION_LIFETIME=120
|
|
||||||
|
|
||||||
MEMCACHED_HOST=127.0.0.1
|
|
||||||
|
|
||||||
REDIS_HOST=127.0.0.1
|
|
||||||
REDIS_PASSWORD=null
|
|
||||||
REDIS_PORT=6379
|
|
||||||
|
|
||||||
MAIL_MAILER=smtp
|
MAIL_MAILER=smtp
|
||||||
MAIL_HOST=mailhog
|
MAIL_HOST=
|
||||||
MAIL_PORT=1025
|
MAIL_PORT=
|
||||||
MAIL_USERNAME=null
|
MAIL_USERNAME=null
|
||||||
MAIL_PASSWORD=null
|
MAIL_PASSWORD=null
|
||||||
MAIL_ENCRYPTION=null
|
MAIL_ENCRYPTION=null
|
||||||
MAIL_FROM_ADDRESS=null
|
MAIL_FROM_ADDRESS="noreply@${APP_NAME}"
|
||||||
MAIL_FROM_NAME="${APP_NAME}"
|
MAIL_FROM_NAME="${APP_NAME}"
|
||||||
|
|
||||||
AWS_ACCESS_KEY_ID=
|
|
||||||
AWS_SECRET_ACCESS_KEY=
|
|
||||||
AWS_DEFAULT_REGION=us-east-1
|
|
||||||
AWS_BUCKET=
|
|
||||||
AWS_USE_PATH_STYLE_ENDPOINT=false
|
|
||||||
|
|
||||||
PUSHER_APP_ID=
|
|
||||||
PUSHER_APP_KEY=
|
|
||||||
PUSHER_APP_SECRET=
|
|
||||||
PUSHER_APP_CLUSTER=mt1
|
|
||||||
|
|
||||||
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
|
|
||||||
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
|
|
||||||
|
|
||||||
FORWARD_REDIS_PORT=2060
|
|
||||||
FORWARD_DB_PORT=2070
|
|
||||||
APP_PORT=2080
|
|
||||||
HMR_PORT=2090
|
|
||||||
|
|
||||||
SENTRY_LARAVEL_DSN=
|
|
||||||
|
|
||||||
APP_SERVICE=vito
|
|
||||||
|
|
||||||
GITHUB_CLIENT_ID=
|
|
||||||
GITHUB_CLIENT_SECRET=
|
|
||||||
|
|
||||||
ABLY_KEY=
|
|
||||||
ABLY_PUBLIC_KEY=
|
|
||||||
|
54
.env.prod
54
.env.prod
@ -4,61 +4,13 @@ APP_KEY=
|
|||||||
APP_DEBUG=false
|
APP_DEBUG=false
|
||||||
APP_URL=
|
APP_URL=
|
||||||
|
|
||||||
LOG_CHANNEL=stack
|
|
||||||
LOG_LEVEL=debug
|
|
||||||
|
|
||||||
DB_CONNECTION=mysql
|
|
||||||
DB_HOST=127.0.0.1
|
|
||||||
DB_PORT=3306
|
|
||||||
DB_DATABASE=
|
|
||||||
DB_USERNAME=
|
|
||||||
DB_PASSWORD=
|
|
||||||
|
|
||||||
BROADCAST_DRIVER=pusher
|
|
||||||
CACHE_DRIVER=file
|
|
||||||
FILESYSTEM_DRIVER=local
|
FILESYSTEM_DRIVER=local
|
||||||
QUEUE_CONNECTION=default
|
|
||||||
SESSION_DRIVER=database
|
|
||||||
SESSION_LIFETIME=120
|
|
||||||
|
|
||||||
REDIS_HOST=127.0.0.1
|
|
||||||
REDIS_PASSWORD=null
|
|
||||||
REDIS_PORT=6379
|
|
||||||
|
|
||||||
MAIL_MAILER=smtp
|
MAIL_MAILER=smtp
|
||||||
MAIL_HOST=mailhog
|
MAIL_HOST=
|
||||||
MAIL_PORT=1025
|
MAIL_PORT=
|
||||||
MAIL_USERNAME=null
|
MAIL_USERNAME=null
|
||||||
MAIL_PASSWORD=null
|
MAIL_PASSWORD=null
|
||||||
MAIL_ENCRYPTION=null
|
MAIL_ENCRYPTION=null
|
||||||
MAIL_FROM_ADDRESS=null
|
MAIL_FROM_ADDRESS="noreply@${APP_NAME}"
|
||||||
MAIL_FROM_NAME="${APP_NAME}"
|
MAIL_FROM_NAME="${APP_NAME}"
|
||||||
|
|
||||||
AWS_ACCESS_KEY_ID=
|
|
||||||
AWS_SECRET_ACCESS_KEY=
|
|
||||||
AWS_DEFAULT_REGION=us-east-1
|
|
||||||
AWS_BUCKET=
|
|
||||||
AWS_USE_PATH_STYLE_ENDPOINT=false
|
|
||||||
|
|
||||||
PUSHER_APP_ID=app-id
|
|
||||||
PUSHER_APP_KEY=app-key
|
|
||||||
PUSHER_APP_SECRET=app-secret
|
|
||||||
PUSHER_HOST=soketi
|
|
||||||
PUSHER_PORT=6001
|
|
||||||
PUSHER_SCHEME=http
|
|
||||||
PUSHER_APP_CLUSTER=mt1
|
|
||||||
|
|
||||||
VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
|
|
||||||
VITE_PUSHER_HOST="${PUSHER_HOST}"
|
|
||||||
VITE_PUSHER_PORT="${PUSHER_PORT}"
|
|
||||||
VITE_PUSHER_SCHEME="${PUSHER_SCHEME}"
|
|
||||||
VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
|
|
||||||
|
|
||||||
SSH_PUBLIC_KEY_NAME=ssh-public.key
|
|
||||||
SSH_PRIVATE_KEY_NAME=ssh-private.pem
|
|
||||||
|
|
||||||
GITHUB_CLIENT_ID=
|
|
||||||
GITHUB_CLIENT_SECRET=
|
|
||||||
|
|
||||||
ABLY_KEY=
|
|
||||||
ABLY_PUBLIC_KEY=
|
|
||||||
|
17
.env.sail
Normal file
17
.env.sail
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
APP_NAME=Vito
|
||||||
|
APP_ENV=local
|
||||||
|
APP_KEY=
|
||||||
|
APP_DEBUG=true
|
||||||
|
APP_URL=
|
||||||
|
APP_PORT=8000
|
||||||
|
|
||||||
|
FILESYSTEM_DRIVER=local
|
||||||
|
|
||||||
|
MAIL_MAILER=smtp
|
||||||
|
MAIL_HOST=
|
||||||
|
MAIL_PORT=
|
||||||
|
MAIL_USERNAME=null
|
||||||
|
MAIL_PASSWORD=null
|
||||||
|
MAIL_ENCRYPTION=null
|
||||||
|
MAIL_FROM_ADDRESS="noreply@${APP_NAME}"
|
||||||
|
MAIL_FROM_NAME="${APP_NAME}"
|
41
.env.testing
41
.env.testing
@ -1,41 +0,0 @@
|
|||||||
APP_NAME=Vito
|
|
||||||
APP_ENV=local
|
|
||||||
APP_KEY=base64:d9kZW60V4lFEw2SPn6UiJ0cfi04v80EWP0GZ6kzoxNg=
|
|
||||||
APP_DEBUG=true
|
|
||||||
APP_URL=http://localhost:2080
|
|
||||||
|
|
||||||
LOG_CHANNEL=stack
|
|
||||||
LOG_LEVEL=debug
|
|
||||||
|
|
||||||
DB_CONNECTION=mysql
|
|
||||||
DB_HOST=127.0.0.1
|
|
||||||
DB_PORT=3306
|
|
||||||
DB_DATABASE=vito_test
|
|
||||||
DB_USERNAME=root
|
|
||||||
DB_PASSWORD=
|
|
||||||
|
|
||||||
BROADCAST_DRIVER=pusher
|
|
||||||
CACHE_DRIVER=array
|
|
||||||
FILESYSTEM_DRIVER=local
|
|
||||||
QUEUE_CONNECTION=database
|
|
||||||
SESSION_DRIVER=array
|
|
||||||
SESSION_LIFETIME=120
|
|
||||||
|
|
||||||
MAIL_MAILER=array
|
|
||||||
|
|
||||||
PUSHER_APP_ID=app-id
|
|
||||||
PUSHER_APP_KEY=app-key
|
|
||||||
PUSHER_APP_SECRET=app-secret
|
|
||||||
PUSHER_HOST=soketi
|
|
||||||
PUSHER_PORT=6001
|
|
||||||
PUSHER_SCHEME=http
|
|
||||||
PUSHER_APP_CLUSTER=mt1
|
|
||||||
|
|
||||||
VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
|
|
||||||
VITE_PUSHER_HOST="${PUSHER_HOST}"
|
|
||||||
VITE_PUSHER_PORT="${PUSHER_PORT}"
|
|
||||||
VITE_PUSHER_SCHEME="${PUSHER_SCHEME}"
|
|
||||||
VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
|
|
||||||
|
|
||||||
SSH_PUBLIC_KEY_NAME=ssh-public.key
|
|
||||||
SSH_PRIVATE_KEY_NAME=ssh-private.pem
|
|
27
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
27
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
---
|
||||||
|
name: Bug report
|
||||||
|
about: Create a report to help us improve
|
||||||
|
title: ''
|
||||||
|
labels: bug
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Describe the bug**
|
||||||
|
A clear and concise description of what the bug is.
|
||||||
|
|
||||||
|
**To Reproduce**
|
||||||
|
Steps to reproduce the behavior:
|
||||||
|
1. Go to '...'
|
||||||
|
2. Click on '....'
|
||||||
|
3. Scroll down to '....'
|
||||||
|
4. See error
|
||||||
|
|
||||||
|
**Expected behavior**
|
||||||
|
A clear and concise description of what you expected to happen.
|
||||||
|
|
||||||
|
**Screenshots**
|
||||||
|
If applicable, add screenshots to help explain your problem.
|
||||||
|
|
||||||
|
**Additional context**
|
||||||
|
Add any other context about the problem here.
|
11
.github/ISSUE_TEMPLATE/config.yml
vendored
Normal file
11
.github/ISSUE_TEMPLATE/config.yml
vendored
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
blank_issues_enabled: false
|
||||||
|
contact_links:
|
||||||
|
- name: Feature request
|
||||||
|
url: https://github.com/vitodeploy/vito/discussions/new?category=ideas
|
||||||
|
about: Share ideas for new features
|
||||||
|
- name: Support
|
||||||
|
url: https://github.com/vitodeploy/vito/discussions/new?category=q-a
|
||||||
|
about: Ask the community for help
|
||||||
|
- name: Discord
|
||||||
|
url: https://discord.gg/uZeeHZZnm5
|
||||||
|
about: Join the community
|
21
.github/workflows/code-style.yml
vendored
21
.github/workflows/code-style.yml
vendored
@ -2,18 +2,19 @@ name: code-style
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
|
branches:
|
||||||
|
- 1.x
|
||||||
pull_request:
|
pull_request:
|
||||||
schedule:
|
|
||||||
- cron: '0 0 * * *'
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
code-style:
|
code-style:
|
||||||
runs-on: ubuntu-20.04
|
runs-on: ubuntu-22.04
|
||||||
|
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: true
|
fail-fast: true
|
||||||
matrix:
|
matrix:
|
||||||
php: [ 8.1 ]
|
php: [8.2]
|
||||||
|
node-version: ["20.x"]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
@ -31,9 +32,21 @@ jobs:
|
|||||||
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
|
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
|
||||||
restore-keys: |
|
restore-keys: |
|
||||||
${{ runner.os }}-php-
|
${{ runner.os }}-php-
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
if: steps.composer-cache.outputs.cache-hit != 'true'
|
if: steps.composer-cache.outputs.cache-hit != 'true'
|
||||||
run: composer install --prefer-dist --no-progress --no-suggest
|
run: composer install --prefer-dist --no-progress --no-suggest
|
||||||
|
|
||||||
- name: Run pint
|
- name: Run pint
|
||||||
run: ./vendor/bin/pint --test
|
run: ./vendor/bin/pint --test
|
||||||
|
|
||||||
|
- name: Setup Node.js
|
||||||
|
uses: actions/setup-node@v2
|
||||||
|
with:
|
||||||
|
node-version: "20.x"
|
||||||
|
|
||||||
|
- name: Install NPM Dependencies
|
||||||
|
run: npm install
|
||||||
|
|
||||||
|
- name: Run lint
|
||||||
|
run: npm run lint
|
||||||
|
35
.github/workflows/docker-1x.yml
vendored
Normal file
35
.github/workflows/docker-1x.yml
vendored
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
name: Build and push Docker image
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- 1.x
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-and-push:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Set up QEMU
|
||||||
|
uses: docker/setup-qemu-action@v1
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v1
|
||||||
|
|
||||||
|
- name: Login to Docker Hub
|
||||||
|
uses: docker/login-action@v2
|
||||||
|
with:
|
||||||
|
username: ${{ secrets.DOCKER_USERNAME }}
|
||||||
|
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||||
|
|
||||||
|
- name: Build and push Docker image
|
||||||
|
run: |
|
||||||
|
docker buildx build . \
|
||||||
|
-f docker/Dockerfile \
|
||||||
|
-t vitodeploy/vito:1.x \
|
||||||
|
--build-arg="RELEASE=0" \
|
||||||
|
--platform linux/amd64,linux/arm64 \
|
||||||
|
--no-cache \
|
||||||
|
--push
|
35
.github/workflows/docker-release.yml
vendored
Normal file
35
.github/workflows/docker-release.yml
vendored
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
name: Build and push Docker image
|
||||||
|
|
||||||
|
on:
|
||||||
|
release:
|
||||||
|
types: [created]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-and-push:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Set up QEMU
|
||||||
|
uses: docker/setup-qemu-action@v1
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v1
|
||||||
|
|
||||||
|
- name: Login to Docker Hub
|
||||||
|
uses: docker/login-action@v2
|
||||||
|
with:
|
||||||
|
username: ${{ secrets.DOCKER_USERNAME }}
|
||||||
|
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||||
|
|
||||||
|
- name: Build and push Docker image
|
||||||
|
run: |
|
||||||
|
docker buildx build . \
|
||||||
|
-f docker/Dockerfile \
|
||||||
|
-t vitodeploy/vito:${{ github.event.release.tag_name }} \
|
||||||
|
-t vitodeploy/vito:latest \
|
||||||
|
--build-arg="RELEASE=0" \
|
||||||
|
--platform linux/amd64,linux/arm64 \
|
||||||
|
--no-cache \
|
||||||
|
--push
|
28
.github/workflows/tests.yml
vendored
28
.github/workflows/tests.yml
vendored
@ -2,30 +2,18 @@ name: tests
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
|
branches:
|
||||||
|
- 1.x
|
||||||
pull_request:
|
pull_request:
|
||||||
schedule:
|
|
||||||
- cron: '0 0 * * *'
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
tests:
|
tests:
|
||||||
runs-on: ubuntu-20.04
|
runs-on: ubuntu-22.04
|
||||||
|
|
||||||
services:
|
|
||||||
mysql:
|
|
||||||
image: mysql
|
|
||||||
env:
|
|
||||||
MYSQL_DATABASE: test_db
|
|
||||||
MYSQL_USER: user
|
|
||||||
MYSQL_PASSWORD: password
|
|
||||||
MYSQL_ROOT_PASSWORD: rootpassword
|
|
||||||
ports:
|
|
||||||
- 3306:3306
|
|
||||||
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
|
|
||||||
|
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: true
|
fail-fast: true
|
||||||
matrix:
|
matrix:
|
||||||
php: [ 8.1 ]
|
php: [8.2]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
@ -47,10 +35,8 @@ jobs:
|
|||||||
if: steps.composer-cache.outputs.cache-hit != 'true'
|
if: steps.composer-cache.outputs.cache-hit != 'true'
|
||||||
run: composer install --prefer-dist --no-progress --no-suggest
|
run: composer install --prefer-dist --no-progress --no-suggest
|
||||||
|
|
||||||
|
- name: Create sqlite database
|
||||||
|
run: touch storage/database-test.sqlite
|
||||||
|
|
||||||
- name: Run test suite
|
- name: Run test suite
|
||||||
run: php artisan test
|
run: php artisan test
|
||||||
env:
|
|
||||||
DB_HOST: 127.0.0.1
|
|
||||||
DB_DATABASE: test_db
|
|
||||||
DB_USERNAME: user
|
|
||||||
DB_PASSWORD: password
|
|
||||||
|
4
.gitignore
vendored
4
.gitignore
vendored
@ -4,7 +4,11 @@
|
|||||||
/public/storage
|
/public/storage
|
||||||
/storage/*.key
|
/storage/*.key
|
||||||
/storage/*.pem
|
/storage/*.pem
|
||||||
|
/storage/test-key
|
||||||
|
/storage/test-key.pub
|
||||||
/vendor
|
/vendor
|
||||||
|
/storage/database.sqlite
|
||||||
|
/storage/database-test.sqlite
|
||||||
.env
|
.env
|
||||||
.env.backup
|
.env.backup
|
||||||
.env.production
|
.env.production
|
||||||
|
16
.prettierrc
Normal file
16
.prettierrc
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"plugins": ["prettier-plugin-blade", "prettier-plugin-tailwindcss"],
|
||||||
|
"overrides": [
|
||||||
|
{
|
||||||
|
"files": ["*.blade.php"],
|
||||||
|
"options": {
|
||||||
|
"parser": "blade",
|
||||||
|
"printWidth": 120,
|
||||||
|
"htmlWhitespaceSensitivity": "ignore",
|
||||||
|
"tabWidth": 4,
|
||||||
|
"quoteProps": "consistent",
|
||||||
|
"trailingComma": "none"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
5
CONTRIBUTING.md
Normal file
5
CONTRIBUTING.md
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
# Contributing
|
||||||
|
|
||||||
|
Please read the contribution guide on the website
|
||||||
|
|
||||||
|
https://vitodeploy.com/introduction/contribution-guide.html
|
673
LICENSE
673
LICENSE
@ -1,22 +1,661 @@
|
|||||||
The MIT License (MIT)
|
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||||
|
Version 3, 19 November 2007
|
||||||
|
|
||||||
Copyright (c) Saeed Vaziry <sa.vaziry@gmail.com>
|
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Preamble
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
The GNU Affero General Public License is a free, copyleft license for
|
||||||
all copies or substantial portions of the Software.
|
software and other kinds of works, specifically designed to ensure
|
||||||
|
cooperation with the community in the case of network server software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
The licenses for most software and other practical works are designed
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
to take away your freedom to share and change the works. By contrast,
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
our General Public Licenses are intended to guarantee your freedom to
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
share and change all versions of a program--to make sure it remains free
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
software for all its users.
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
THE SOFTWARE.
|
|
||||||
|
|
||||||
|
When we speak of free software, we are referring to freedom, not
|
||||||
|
price. Our General Public Licenses are designed to make sure that you
|
||||||
|
have the freedom to distribute copies of free software (and charge for
|
||||||
|
them if you wish), that you receive source code or can get it if you
|
||||||
|
want it, that you can change the software or use pieces of it in new
|
||||||
|
free programs, and that you know you can do these things.
|
||||||
|
|
||||||
|
Developers that use our General Public Licenses protect your rights
|
||||||
|
with two steps: (1) assert copyright on the software, and (2) offer
|
||||||
|
you this License which gives you legal permission to copy, distribute
|
||||||
|
and/or modify the software.
|
||||||
|
|
||||||
|
A secondary benefit of defending all users' freedom is that
|
||||||
|
improvements made in alternate versions of the program, if they
|
||||||
|
receive widespread use, become available for other developers to
|
||||||
|
incorporate. Many developers of free software are heartened and
|
||||||
|
encouraged by the resulting cooperation. However, in the case of
|
||||||
|
software used on network servers, this result may fail to come about.
|
||||||
|
The GNU General Public License permits making a modified version and
|
||||||
|
letting the public access it on a server without ever releasing its
|
||||||
|
source code to the public.
|
||||||
|
|
||||||
|
The GNU Affero General Public License is designed specifically to
|
||||||
|
ensure that, in such cases, the modified source code becomes available
|
||||||
|
to the community. It requires the operator of a network server to
|
||||||
|
provide the source code of the modified version running there to the
|
||||||
|
users of that server. Therefore, public use of a modified version, on
|
||||||
|
a publicly accessible server, gives the public access to the source
|
||||||
|
code of the modified version.
|
||||||
|
|
||||||
|
An older license, called the Affero General Public License and
|
||||||
|
published by Affero, was designed to accomplish similar goals. This is
|
||||||
|
a different license, not a version of the Affero GPL, but Affero has
|
||||||
|
released a new version of the Affero GPL which permits relicensing under
|
||||||
|
this license.
|
||||||
|
|
||||||
|
The precise terms and conditions for copying, distribution and
|
||||||
|
modification follow.
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
0. Definitions.
|
||||||
|
|
||||||
|
"This License" refers to version 3 of the GNU Affero General Public License.
|
||||||
|
|
||||||
|
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||||
|
works, such as semiconductor masks.
|
||||||
|
|
||||||
|
"The Program" refers to any copyrightable work licensed under this
|
||||||
|
License. Each licensee is addressed as "you". "Licensees" and
|
||||||
|
"recipients" may be individuals or organizations.
|
||||||
|
|
||||||
|
To "modify" a work means to copy from or adapt all or part of the work
|
||||||
|
in a fashion requiring copyright permission, other than the making of an
|
||||||
|
exact copy. The resulting work is called a "modified version" of the
|
||||||
|
earlier work or a work "based on" the earlier work.
|
||||||
|
|
||||||
|
A "covered work" means either the unmodified Program or a work based
|
||||||
|
on the Program.
|
||||||
|
|
||||||
|
To "propagate" a work means to do anything with it that, without
|
||||||
|
permission, would make you directly or secondarily liable for
|
||||||
|
infringement under applicable copyright law, except executing it on a
|
||||||
|
computer or modifying a private copy. Propagation includes copying,
|
||||||
|
distribution (with or without modification), making available to the
|
||||||
|
public, and in some countries other activities as well.
|
||||||
|
|
||||||
|
To "convey" a work means any kind of propagation that enables other
|
||||||
|
parties to make or receive copies. Mere interaction with a user through
|
||||||
|
a computer network, with no transfer of a copy, is not conveying.
|
||||||
|
|
||||||
|
An interactive user interface displays "Appropriate Legal Notices"
|
||||||
|
to the extent that it includes a convenient and prominently visible
|
||||||
|
feature that (1) displays an appropriate copyright notice, and (2)
|
||||||
|
tells the user that there is no warranty for the work (except to the
|
||||||
|
extent that warranties are provided), that licensees may convey the
|
||||||
|
work under this License, and how to view a copy of this License. If
|
||||||
|
the interface presents a list of user commands or options, such as a
|
||||||
|
menu, a prominent item in the list meets this criterion.
|
||||||
|
|
||||||
|
1. Source Code.
|
||||||
|
|
||||||
|
The "source code" for a work means the preferred form of the work
|
||||||
|
for making modifications to it. "Object code" means any non-source
|
||||||
|
form of a work.
|
||||||
|
|
||||||
|
A "Standard Interface" means an interface that either is an official
|
||||||
|
standard defined by a recognized standards body, or, in the case of
|
||||||
|
interfaces specified for a particular programming language, one that
|
||||||
|
is widely used among developers working in that language.
|
||||||
|
|
||||||
|
The "System Libraries" of an executable work include anything, other
|
||||||
|
than the work as a whole, that (a) is included in the normal form of
|
||||||
|
packaging a Major Component, but which is not part of that Major
|
||||||
|
Component, and (b) serves only to enable use of the work with that
|
||||||
|
Major Component, or to implement a Standard Interface for which an
|
||||||
|
implementation is available to the public in source code form. A
|
||||||
|
"Major Component", in this context, means a major essential component
|
||||||
|
(kernel, window system, and so on) of the specific operating system
|
||||||
|
(if any) on which the executable work runs, or a compiler used to
|
||||||
|
produce the work, or an object code interpreter used to run it.
|
||||||
|
|
||||||
|
The "Corresponding Source" for a work in object code form means all
|
||||||
|
the source code needed to generate, install, and (for an executable
|
||||||
|
work) run the object code and to modify the work, including scripts to
|
||||||
|
control those activities. However, it does not include the work's
|
||||||
|
System Libraries, or general-purpose tools or generally available free
|
||||||
|
programs which are used unmodified in performing those activities but
|
||||||
|
which are not part of the work. For example, Corresponding Source
|
||||||
|
includes interface definition files associated with source files for
|
||||||
|
the work, and the source code for shared libraries and dynamically
|
||||||
|
linked subprograms that the work is specifically designed to require,
|
||||||
|
such as by intimate data communication or control flow between those
|
||||||
|
subprograms and other parts of the work.
|
||||||
|
|
||||||
|
The Corresponding Source need not include anything that users
|
||||||
|
can regenerate automatically from other parts of the Corresponding
|
||||||
|
Source.
|
||||||
|
|
||||||
|
The Corresponding Source for a work in source code form is that
|
||||||
|
same work.
|
||||||
|
|
||||||
|
2. Basic Permissions.
|
||||||
|
|
||||||
|
All rights granted under this License are granted for the term of
|
||||||
|
copyright on the Program, and are irrevocable provided the stated
|
||||||
|
conditions are met. This License explicitly affirms your unlimited
|
||||||
|
permission to run the unmodified Program. The output from running a
|
||||||
|
covered work is covered by this License only if the output, given its
|
||||||
|
content, constitutes a covered work. This License acknowledges your
|
||||||
|
rights of fair use or other equivalent, as provided by copyright law.
|
||||||
|
|
||||||
|
You may make, run and propagate covered works that you do not
|
||||||
|
convey, without conditions so long as your license otherwise remains
|
||||||
|
in force. You may convey covered works to others for the sole purpose
|
||||||
|
of having them make modifications exclusively for you, or provide you
|
||||||
|
with facilities for running those works, provided that you comply with
|
||||||
|
the terms of this License in conveying all material for which you do
|
||||||
|
not control copyright. Those thus making or running the covered works
|
||||||
|
for you must do so exclusively on your behalf, under your direction
|
||||||
|
and control, on terms that prohibit them from making any copies of
|
||||||
|
your copyrighted material outside their relationship with you.
|
||||||
|
|
||||||
|
Conveying under any other circumstances is permitted solely under
|
||||||
|
the conditions stated below. Sublicensing is not allowed; section 10
|
||||||
|
makes it unnecessary.
|
||||||
|
|
||||||
|
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||||
|
|
||||||
|
No covered work shall be deemed part of an effective technological
|
||||||
|
measure under any applicable law fulfilling obligations under article
|
||||||
|
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||||
|
similar laws prohibiting or restricting circumvention of such
|
||||||
|
measures.
|
||||||
|
|
||||||
|
When you convey a covered work, you waive any legal power to forbid
|
||||||
|
circumvention of technological measures to the extent such circumvention
|
||||||
|
is effected by exercising rights under this License with respect to
|
||||||
|
the covered work, and you disclaim any intention to limit operation or
|
||||||
|
modification of the work as a means of enforcing, against the work's
|
||||||
|
users, your or third parties' legal rights to forbid circumvention of
|
||||||
|
technological measures.
|
||||||
|
|
||||||
|
4. Conveying Verbatim Copies.
|
||||||
|
|
||||||
|
You may convey verbatim copies of the Program's source code as you
|
||||||
|
receive it, in any medium, provided that you conspicuously and
|
||||||
|
appropriately publish on each copy an appropriate copyright notice;
|
||||||
|
keep intact all notices stating that this License and any
|
||||||
|
non-permissive terms added in accord with section 7 apply to the code;
|
||||||
|
keep intact all notices of the absence of any warranty; and give all
|
||||||
|
recipients a copy of this License along with the Program.
|
||||||
|
|
||||||
|
You may charge any price or no price for each copy that you convey,
|
||||||
|
and you may offer support or warranty protection for a fee.
|
||||||
|
|
||||||
|
5. Conveying Modified Source Versions.
|
||||||
|
|
||||||
|
You may convey a work based on the Program, or the modifications to
|
||||||
|
produce it from the Program, in the form of source code under the
|
||||||
|
terms of section 4, provided that you also meet all of these conditions:
|
||||||
|
|
||||||
|
a) The work must carry prominent notices stating that you modified
|
||||||
|
it, and giving a relevant date.
|
||||||
|
|
||||||
|
b) The work must carry prominent notices stating that it is
|
||||||
|
released under this License and any conditions added under section
|
||||||
|
7. This requirement modifies the requirement in section 4 to
|
||||||
|
"keep intact all notices".
|
||||||
|
|
||||||
|
c) You must license the entire work, as a whole, under this
|
||||||
|
License to anyone who comes into possession of a copy. This
|
||||||
|
License will therefore apply, along with any applicable section 7
|
||||||
|
additional terms, to the whole of the work, and all its parts,
|
||||||
|
regardless of how they are packaged. This License gives no
|
||||||
|
permission to license the work in any other way, but it does not
|
||||||
|
invalidate such permission if you have separately received it.
|
||||||
|
|
||||||
|
d) If the work has interactive user interfaces, each must display
|
||||||
|
Appropriate Legal Notices; however, if the Program has interactive
|
||||||
|
interfaces that do not display Appropriate Legal Notices, your
|
||||||
|
work need not make them do so.
|
||||||
|
|
||||||
|
A compilation of a covered work with other separate and independent
|
||||||
|
works, which are not by their nature extensions of the covered work,
|
||||||
|
and which are not combined with it such as to form a larger program,
|
||||||
|
in or on a volume of a storage or distribution medium, is called an
|
||||||
|
"aggregate" if the compilation and its resulting copyright are not
|
||||||
|
used to limit the access or legal rights of the compilation's users
|
||||||
|
beyond what the individual works permit. Inclusion of a covered work
|
||||||
|
in an aggregate does not cause this License to apply to the other
|
||||||
|
parts of the aggregate.
|
||||||
|
|
||||||
|
6. Conveying Non-Source Forms.
|
||||||
|
|
||||||
|
You may convey a covered work in object code form under the terms
|
||||||
|
of sections 4 and 5, provided that you also convey the
|
||||||
|
machine-readable Corresponding Source under the terms of this License,
|
||||||
|
in one of these ways:
|
||||||
|
|
||||||
|
a) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by the
|
||||||
|
Corresponding Source fixed on a durable physical medium
|
||||||
|
customarily used for software interchange.
|
||||||
|
|
||||||
|
b) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by a
|
||||||
|
written offer, valid for at least three years and valid for as
|
||||||
|
long as you offer spare parts or customer support for that product
|
||||||
|
model, to give anyone who possesses the object code either (1) a
|
||||||
|
copy of the Corresponding Source for all the software in the
|
||||||
|
product that is covered by this License, on a durable physical
|
||||||
|
medium customarily used for software interchange, for a price no
|
||||||
|
more than your reasonable cost of physically performing this
|
||||||
|
conveying of source, or (2) access to copy the
|
||||||
|
Corresponding Source from a network server at no charge.
|
||||||
|
|
||||||
|
c) Convey individual copies of the object code with a copy of the
|
||||||
|
written offer to provide the Corresponding Source. This
|
||||||
|
alternative is allowed only occasionally and noncommercially, and
|
||||||
|
only if you received the object code with such an offer, in accord
|
||||||
|
with subsection 6b.
|
||||||
|
|
||||||
|
d) Convey the object code by offering access from a designated
|
||||||
|
place (gratis or for a charge), and offer equivalent access to the
|
||||||
|
Corresponding Source in the same way through the same place at no
|
||||||
|
further charge. You need not require recipients to copy the
|
||||||
|
Corresponding Source along with the object code. If the place to
|
||||||
|
copy the object code is a network server, the Corresponding Source
|
||||||
|
may be on a different server (operated by you or a third party)
|
||||||
|
that supports equivalent copying facilities, provided you maintain
|
||||||
|
clear directions next to the object code saying where to find the
|
||||||
|
Corresponding Source. Regardless of what server hosts the
|
||||||
|
Corresponding Source, you remain obligated to ensure that it is
|
||||||
|
available for as long as needed to satisfy these requirements.
|
||||||
|
|
||||||
|
e) Convey the object code using peer-to-peer transmission, provided
|
||||||
|
you inform other peers where the object code and Corresponding
|
||||||
|
Source of the work are being offered to the general public at no
|
||||||
|
charge under subsection 6d.
|
||||||
|
|
||||||
|
A separable portion of the object code, whose source code is excluded
|
||||||
|
from the Corresponding Source as a System Library, need not be
|
||||||
|
included in conveying the object code work.
|
||||||
|
|
||||||
|
A "User Product" is either (1) a "consumer product", which means any
|
||||||
|
tangible personal property which is normally used for personal, family,
|
||||||
|
or household purposes, or (2) anything designed or sold for incorporation
|
||||||
|
into a dwelling. In determining whether a product is a consumer product,
|
||||||
|
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||||
|
product received by a particular user, "normally used" refers to a
|
||||||
|
typical or common use of that class of product, regardless of the status
|
||||||
|
of the particular user or of the way in which the particular user
|
||||||
|
actually uses, or expects or is expected to use, the product. A product
|
||||||
|
is a consumer product regardless of whether the product has substantial
|
||||||
|
commercial, industrial or non-consumer uses, unless such uses represent
|
||||||
|
the only significant mode of use of the product.
|
||||||
|
|
||||||
|
"Installation Information" for a User Product means any methods,
|
||||||
|
procedures, authorization keys, or other information required to install
|
||||||
|
and execute modified versions of a covered work in that User Product from
|
||||||
|
a modified version of its Corresponding Source. The information must
|
||||||
|
suffice to ensure that the continued functioning of the modified object
|
||||||
|
code is in no case prevented or interfered with solely because
|
||||||
|
modification has been made.
|
||||||
|
|
||||||
|
If you convey an object code work under this section in, or with, or
|
||||||
|
specifically for use in, a User Product, and the conveying occurs as
|
||||||
|
part of a transaction in which the right of possession and use of the
|
||||||
|
User Product is transferred to the recipient in perpetuity or for a
|
||||||
|
fixed term (regardless of how the transaction is characterized), the
|
||||||
|
Corresponding Source conveyed under this section must be accompanied
|
||||||
|
by the Installation Information. But this requirement does not apply
|
||||||
|
if neither you nor any third party retains the ability to install
|
||||||
|
modified object code on the User Product (for example, the work has
|
||||||
|
been installed in ROM).
|
||||||
|
|
||||||
|
The requirement to provide Installation Information does not include a
|
||||||
|
requirement to continue to provide support service, warranty, or updates
|
||||||
|
for a work that has been modified or installed by the recipient, or for
|
||||||
|
the User Product in which it has been modified or installed. Access to a
|
||||||
|
network may be denied when the modification itself materially and
|
||||||
|
adversely affects the operation of the network or violates the rules and
|
||||||
|
protocols for communication across the network.
|
||||||
|
|
||||||
|
Corresponding Source conveyed, and Installation Information provided,
|
||||||
|
in accord with this section must be in a format that is publicly
|
||||||
|
documented (and with an implementation available to the public in
|
||||||
|
source code form), and must require no special password or key for
|
||||||
|
unpacking, reading or copying.
|
||||||
|
|
||||||
|
7. Additional Terms.
|
||||||
|
|
||||||
|
"Additional permissions" are terms that supplement the terms of this
|
||||||
|
License by making exceptions from one or more of its conditions.
|
||||||
|
Additional permissions that are applicable to the entire Program shall
|
||||||
|
be treated as though they were included in this License, to the extent
|
||||||
|
that they are valid under applicable law. If additional permissions
|
||||||
|
apply only to part of the Program, that part may be used separately
|
||||||
|
under those permissions, but the entire Program remains governed by
|
||||||
|
this License without regard to the additional permissions.
|
||||||
|
|
||||||
|
When you convey a copy of a covered work, you may at your option
|
||||||
|
remove any additional permissions from that copy, or from any part of
|
||||||
|
it. (Additional permissions may be written to require their own
|
||||||
|
removal in certain cases when you modify the work.) You may place
|
||||||
|
additional permissions on material, added by you to a covered work,
|
||||||
|
for which you have or can give appropriate copyright permission.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, for material you
|
||||||
|
add to a covered work, you may (if authorized by the copyright holders of
|
||||||
|
that material) supplement the terms of this License with terms:
|
||||||
|
|
||||||
|
a) Disclaiming warranty or limiting liability differently from the
|
||||||
|
terms of sections 15 and 16 of this License; or
|
||||||
|
|
||||||
|
b) Requiring preservation of specified reasonable legal notices or
|
||||||
|
author attributions in that material or in the Appropriate Legal
|
||||||
|
Notices displayed by works containing it; or
|
||||||
|
|
||||||
|
c) Prohibiting misrepresentation of the origin of that material, or
|
||||||
|
requiring that modified versions of such material be marked in
|
||||||
|
reasonable ways as different from the original version; or
|
||||||
|
|
||||||
|
d) Limiting the use for publicity purposes of names of licensors or
|
||||||
|
authors of the material; or
|
||||||
|
|
||||||
|
e) Declining to grant rights under trademark law for use of some
|
||||||
|
trade names, trademarks, or service marks; or
|
||||||
|
|
||||||
|
f) Requiring indemnification of licensors and authors of that
|
||||||
|
material by anyone who conveys the material (or modified versions of
|
||||||
|
it) with contractual assumptions of liability to the recipient, for
|
||||||
|
any liability that these contractual assumptions directly impose on
|
||||||
|
those licensors and authors.
|
||||||
|
|
||||||
|
All other non-permissive additional terms are considered "further
|
||||||
|
restrictions" within the meaning of section 10. If the Program as you
|
||||||
|
received it, or any part of it, contains a notice stating that it is
|
||||||
|
governed by this License along with a term that is a further
|
||||||
|
restriction, you may remove that term. If a license document contains
|
||||||
|
a further restriction but permits relicensing or conveying under this
|
||||||
|
License, you may add to a covered work material governed by the terms
|
||||||
|
of that license document, provided that the further restriction does
|
||||||
|
not survive such relicensing or conveying.
|
||||||
|
|
||||||
|
If you add terms to a covered work in accord with this section, you
|
||||||
|
must place, in the relevant source files, a statement of the
|
||||||
|
additional terms that apply to those files, or a notice indicating
|
||||||
|
where to find the applicable terms.
|
||||||
|
|
||||||
|
Additional terms, permissive or non-permissive, may be stated in the
|
||||||
|
form of a separately written license, or stated as exceptions;
|
||||||
|
the above requirements apply either way.
|
||||||
|
|
||||||
|
8. Termination.
|
||||||
|
|
||||||
|
You may not propagate or modify a covered work except as expressly
|
||||||
|
provided under this License. Any attempt otherwise to propagate or
|
||||||
|
modify it is void, and will automatically terminate your rights under
|
||||||
|
this License (including any patent licenses granted under the third
|
||||||
|
paragraph of section 11).
|
||||||
|
|
||||||
|
However, if you cease all violation of this License, then your
|
||||||
|
license from a particular copyright holder is reinstated (a)
|
||||||
|
provisionally, unless and until the copyright holder explicitly and
|
||||||
|
finally terminates your license, and (b) permanently, if the copyright
|
||||||
|
holder fails to notify you of the violation by some reasonable means
|
||||||
|
prior to 60 days after the cessation.
|
||||||
|
|
||||||
|
Moreover, your license from a particular copyright holder is
|
||||||
|
reinstated permanently if the copyright holder notifies you of the
|
||||||
|
violation by some reasonable means, this is the first time you have
|
||||||
|
received notice of violation of this License (for any work) from that
|
||||||
|
copyright holder, and you cure the violation prior to 30 days after
|
||||||
|
your receipt of the notice.
|
||||||
|
|
||||||
|
Termination of your rights under this section does not terminate the
|
||||||
|
licenses of parties who have received copies or rights from you under
|
||||||
|
this License. If your rights have been terminated and not permanently
|
||||||
|
reinstated, you do not qualify to receive new licenses for the same
|
||||||
|
material under section 10.
|
||||||
|
|
||||||
|
9. Acceptance Not Required for Having Copies.
|
||||||
|
|
||||||
|
You are not required to accept this License in order to receive or
|
||||||
|
run a copy of the Program. Ancillary propagation of a covered work
|
||||||
|
occurring solely as a consequence of using peer-to-peer transmission
|
||||||
|
to receive a copy likewise does not require acceptance. However,
|
||||||
|
nothing other than this License grants you permission to propagate or
|
||||||
|
modify any covered work. These actions infringe copyright if you do
|
||||||
|
not accept this License. Therefore, by modifying or propagating a
|
||||||
|
covered work, you indicate your acceptance of this License to do so.
|
||||||
|
|
||||||
|
10. Automatic Licensing of Downstream Recipients.
|
||||||
|
|
||||||
|
Each time you convey a covered work, the recipient automatically
|
||||||
|
receives a license from the original licensors, to run, modify and
|
||||||
|
propagate that work, subject to this License. You are not responsible
|
||||||
|
for enforcing compliance by third parties with this License.
|
||||||
|
|
||||||
|
An "entity transaction" is a transaction transferring control of an
|
||||||
|
organization, or substantially all assets of one, or subdividing an
|
||||||
|
organization, or merging organizations. If propagation of a covered
|
||||||
|
work results from an entity transaction, each party to that
|
||||||
|
transaction who receives a copy of the work also receives whatever
|
||||||
|
licenses to the work the party's predecessor in interest had or could
|
||||||
|
give under the previous paragraph, plus a right to possession of the
|
||||||
|
Corresponding Source of the work from the predecessor in interest, if
|
||||||
|
the predecessor has it or can get it with reasonable efforts.
|
||||||
|
|
||||||
|
You may not impose any further restrictions on the exercise of the
|
||||||
|
rights granted or affirmed under this License. For example, you may
|
||||||
|
not impose a license fee, royalty, or other charge for exercise of
|
||||||
|
rights granted under this License, and you may not initiate litigation
|
||||||
|
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||||
|
any patent claim is infringed by making, using, selling, offering for
|
||||||
|
sale, or importing the Program or any portion of it.
|
||||||
|
|
||||||
|
11. Patents.
|
||||||
|
|
||||||
|
A "contributor" is a copyright holder who authorizes use under this
|
||||||
|
License of the Program or a work on which the Program is based. The
|
||||||
|
work thus licensed is called the contributor's "contributor version".
|
||||||
|
|
||||||
|
A contributor's "essential patent claims" are all patent claims
|
||||||
|
owned or controlled by the contributor, whether already acquired or
|
||||||
|
hereafter acquired, that would be infringed by some manner, permitted
|
||||||
|
by this License, of making, using, or selling its contributor version,
|
||||||
|
but do not include claims that would be infringed only as a
|
||||||
|
consequence of further modification of the contributor version. For
|
||||||
|
purposes of this definition, "control" includes the right to grant
|
||||||
|
patent sublicenses in a manner consistent with the requirements of
|
||||||
|
this License.
|
||||||
|
|
||||||
|
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||||
|
patent license under the contributor's essential patent claims, to
|
||||||
|
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||||
|
propagate the contents of its contributor version.
|
||||||
|
|
||||||
|
In the following three paragraphs, a "patent license" is any express
|
||||||
|
agreement or commitment, however denominated, not to enforce a patent
|
||||||
|
(such as an express permission to practice a patent or covenant not to
|
||||||
|
sue for patent infringement). To "grant" such a patent license to a
|
||||||
|
party means to make such an agreement or commitment not to enforce a
|
||||||
|
patent against the party.
|
||||||
|
|
||||||
|
If you convey a covered work, knowingly relying on a patent license,
|
||||||
|
and the Corresponding Source of the work is not available for anyone
|
||||||
|
to copy, free of charge and under the terms of this License, through a
|
||||||
|
publicly available network server or other readily accessible means,
|
||||||
|
then you must either (1) cause the Corresponding Source to be so
|
||||||
|
available, or (2) arrange to deprive yourself of the benefit of the
|
||||||
|
patent license for this particular work, or (3) arrange, in a manner
|
||||||
|
consistent with the requirements of this License, to extend the patent
|
||||||
|
license to downstream recipients. "Knowingly relying" means you have
|
||||||
|
actual knowledge that, but for the patent license, your conveying the
|
||||||
|
covered work in a country, or your recipient's use of the covered work
|
||||||
|
in a country, would infringe one or more identifiable patents in that
|
||||||
|
country that you have reason to believe are valid.
|
||||||
|
|
||||||
|
If, pursuant to or in connection with a single transaction or
|
||||||
|
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||||
|
covered work, and grant a patent license to some of the parties
|
||||||
|
receiving the covered work authorizing them to use, propagate, modify
|
||||||
|
or convey a specific copy of the covered work, then the patent license
|
||||||
|
you grant is automatically extended to all recipients of the covered
|
||||||
|
work and works based on it.
|
||||||
|
|
||||||
|
A patent license is "discriminatory" if it does not include within
|
||||||
|
the scope of its coverage, prohibits the exercise of, or is
|
||||||
|
conditioned on the non-exercise of one or more of the rights that are
|
||||||
|
specifically granted under this License. You may not convey a covered
|
||||||
|
work if you are a party to an arrangement with a third party that is
|
||||||
|
in the business of distributing software, under which you make payment
|
||||||
|
to the third party based on the extent of your activity of conveying
|
||||||
|
the work, and under which the third party grants, to any of the
|
||||||
|
parties who would receive the covered work from you, a discriminatory
|
||||||
|
patent license (a) in connection with copies of the covered work
|
||||||
|
conveyed by you (or copies made from those copies), or (b) primarily
|
||||||
|
for and in connection with specific products or compilations that
|
||||||
|
contain the covered work, unless you entered into that arrangement,
|
||||||
|
or that patent license was granted, prior to 28 March 2007.
|
||||||
|
|
||||||
|
Nothing in this License shall be construed as excluding or limiting
|
||||||
|
any implied license or other defenses to infringement that may
|
||||||
|
otherwise be available to you under applicable patent law.
|
||||||
|
|
||||||
|
12. No Surrender of Others' Freedom.
|
||||||
|
|
||||||
|
If conditions are imposed on you (whether by court order, agreement or
|
||||||
|
otherwise) that contradict the conditions of this License, they do not
|
||||||
|
excuse you from the conditions of this License. If you cannot convey a
|
||||||
|
covered work so as to satisfy simultaneously your obligations under this
|
||||||
|
License and any other pertinent obligations, then as a consequence you may
|
||||||
|
not convey it at all. For example, if you agree to terms that obligate you
|
||||||
|
to collect a royalty for further conveying from those to whom you convey
|
||||||
|
the Program, the only way you could satisfy both those terms and this
|
||||||
|
License would be to refrain entirely from conveying the Program.
|
||||||
|
|
||||||
|
13. Remote Network Interaction; Use with the GNU General Public License.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, if you modify the
|
||||||
|
Program, your modified version must prominently offer all users
|
||||||
|
interacting with it remotely through a computer network (if your version
|
||||||
|
supports such interaction) an opportunity to receive the Corresponding
|
||||||
|
Source of your version by providing access to the Corresponding Source
|
||||||
|
from a network server at no charge, through some standard or customary
|
||||||
|
means of facilitating copying of software. This Corresponding Source
|
||||||
|
shall include the Corresponding Source for any work covered by version 3
|
||||||
|
of the GNU General Public License that is incorporated pursuant to the
|
||||||
|
following paragraph.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, you have
|
||||||
|
permission to link or combine any covered work with a work licensed
|
||||||
|
under version 3 of the GNU General Public License into a single
|
||||||
|
combined work, and to convey the resulting work. The terms of this
|
||||||
|
License will continue to apply to the part which is the covered work,
|
||||||
|
but the work with which it is combined will remain governed by version
|
||||||
|
3 of the GNU General Public License.
|
||||||
|
|
||||||
|
14. Revised Versions of this License.
|
||||||
|
|
||||||
|
The Free Software Foundation may publish revised and/or new versions of
|
||||||
|
the GNU Affero General Public License from time to time. Such new versions
|
||||||
|
will be similar in spirit to the present version, but may differ in detail to
|
||||||
|
address new problems or concerns.
|
||||||
|
|
||||||
|
Each version is given a distinguishing version number. If the
|
||||||
|
Program specifies that a certain numbered version of the GNU Affero General
|
||||||
|
Public License "or any later version" applies to it, you have the
|
||||||
|
option of following the terms and conditions either of that numbered
|
||||||
|
version or of any later version published by the Free Software
|
||||||
|
Foundation. If the Program does not specify a version number of the
|
||||||
|
GNU Affero General Public License, you may choose any version ever published
|
||||||
|
by the Free Software Foundation.
|
||||||
|
|
||||||
|
If the Program specifies that a proxy can decide which future
|
||||||
|
versions of the GNU Affero General Public License can be used, that proxy's
|
||||||
|
public statement of acceptance of a version permanently authorizes you
|
||||||
|
to choose that version for the Program.
|
||||||
|
|
||||||
|
Later license versions may give you additional or different
|
||||||
|
permissions. However, no additional obligations are imposed on any
|
||||||
|
author or copyright holder as a result of your choosing to follow a
|
||||||
|
later version.
|
||||||
|
|
||||||
|
15. Disclaimer of Warranty.
|
||||||
|
|
||||||
|
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||||
|
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||||
|
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||||
|
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||||
|
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||||
|
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||||
|
|
||||||
|
16. Limitation of Liability.
|
||||||
|
|
||||||
|
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||||
|
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||||
|
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||||
|
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||||
|
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||||
|
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||||
|
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||||
|
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||||
|
SUCH DAMAGES.
|
||||||
|
|
||||||
|
17. Interpretation of Sections 15 and 16.
|
||||||
|
|
||||||
|
If the disclaimer of warranty and limitation of liability provided
|
||||||
|
above cannot be given local legal effect according to their terms,
|
||||||
|
reviewing courts shall apply local law that most closely approximates
|
||||||
|
an absolute waiver of all civil liability in connection with the
|
||||||
|
Program, unless a warranty or assumption of liability accompanies a
|
||||||
|
copy of the Program in return for a fee.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
How to Apply These Terms to Your New Programs
|
||||||
|
|
||||||
|
If you develop a new program, and you want it to be of the greatest
|
||||||
|
possible use to the public, the best way to achieve this is to make it
|
||||||
|
free software which everyone can redistribute and change under these terms.
|
||||||
|
|
||||||
|
To do so, attach the following notices to the program. It is safest
|
||||||
|
to attach them to the start of each source file to most effectively
|
||||||
|
state the exclusion of warranty; and each file should have at least
|
||||||
|
the "copyright" line and a pointer to where the full notice is found.
|
||||||
|
|
||||||
|
<one line to give the program's name and a brief idea of what it does.>
|
||||||
|
Copyright (C) <year> <name of author>
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Affero General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Affero General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
|
If your software can interact with users remotely through a computer
|
||||||
|
network, you should also make sure that it provides a way for users to
|
||||||
|
get its source. For example, if your program is a web application, its
|
||||||
|
interface could display a "Source" link that leads users to an archive
|
||||||
|
of the code. There are many ways you could offer source, and different
|
||||||
|
solutions will be better for different programs; see section 13 for the
|
||||||
|
specific requirements.
|
||||||
|
|
||||||
|
You should also get your employer (if you work as a programmer) or school,
|
||||||
|
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||||
|
For more information on this, and how to apply and follow the GNU AGPL, see
|
||||||
|
<https://www.gnu.org/licenses/>.
|
||||||
|
52
README.md
52
README.md
@ -1,24 +1,54 @@
|
|||||||
# Vito
|
|
||||||
|
|
||||||

|
<p align="center">
|
||||||
|
<img src="https://github.com/vitodeploy/vito/assets/61919774/8060fded-58e3-4d58-b58b-5b717b0718e9" alt="VitoDeploy>
|
||||||
|
<p align="center">
|
||||||
|
<a href="https://github.com/vitodeploy/vito/actions"><img alt="GitHub Workflow Status" src="https://github.com/vitodeploy/vito/workflows/tests/badge.svg"></a>
|
||||||
|
</p>
|
||||||
|
</p>
|
||||||
|
|
||||||

|
------
|
||||||
|
## About Vito
|
||||||
|
|
||||||
Better Readme will come soon... :)
|
Vito is a self-hosted web application that helps you manage your servers and deploy your PHP applications into production servers without a hassle.
|
||||||
|
|
||||||
## Documentation
|
## Quick Start
|
||||||
|
|
||||||
https://vitodeploy.com
|
```sh
|
||||||
|
bash <(curl -Ls https://raw.githubusercontent.com/vitodeploy/vito/1.x/scripts/install.sh)
|
||||||
|
```
|
||||||
|
|
||||||
## Contribution
|
## Features
|
||||||
|
|
||||||
Feel free to open a PR
|
- Provisions and Manages the server
|
||||||
|
- Easy database management, Supports Mysql and MariaDB
|
||||||
|
- Deploy your PHP applications such as Laravel
|
||||||
|
- Manage your server's firewall
|
||||||
|
- Supports Custom and Letsencrypt SSL
|
||||||
|
- Uses supervisor to handle queues
|
||||||
|
- Manages server's services
|
||||||
|
- Deploy your SSH Keys to the server
|
||||||
|
- Create and Manage cron jobs on the server
|
||||||
|
|
||||||
|
## Useful Links
|
||||||
|
|
||||||
|
- [Documentation](https://vitodeploy.com)
|
||||||
|
- [Install on Server](https://vitodeploy.com/introduction/installation.html#install-on-vps-recommended)
|
||||||
|
- [Install via Docker](https://vitodeploy.com/introduction/installation.html#install-via-docker)
|
||||||
|
- [Roadmap](https://github.com/orgs/vitodeploy/projects/5)
|
||||||
|
- [Video Demo](https://youtu.be/AbmUOBDOc28)
|
||||||
|
- [Discord](https://discord.gg/uZeeHZZnm5)
|
||||||
|
- [Contribution](/CONTRIBUTING.md)
|
||||||
|
- [Security](/SECURITY.md)
|
||||||
|
|
||||||
## Credits
|
## Credits
|
||||||
|
|
||||||
- Laravel
|
- Laravel
|
||||||
- Tailwind
|
- PHPSecLib
|
||||||
- Livewire
|
- PHPUnit
|
||||||
|
- Tailwindcss
|
||||||
- Alpinejs
|
- Alpinejs
|
||||||
|
- HTMX
|
||||||
- Vite
|
- Vite
|
||||||
- Laravel Enum by BenSampo
|
- Prettier
|
||||||
|
- Postcss
|
||||||
|
- Flowbite
|
||||||
|
12
SECURITY.md
Normal file
12
SECURITY.md
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
# Security Policy
|
||||||
|
|
||||||
|
## Supported Versions
|
||||||
|
|
||||||
|
| Version | Supported |
|
||||||
|
| ------- | ----------|
|
||||||
|
| 0.x | ❌ |
|
||||||
|
| 1.x | ✅ |
|
||||||
|
|
||||||
|
## Reporting a Vulnerability
|
||||||
|
|
||||||
|
If you see a vulnerability, please open an issue or report it directly to me (sa.vaziry@gmail.com)
|
@ -19,11 +19,14 @@ public function create(Server $server, array $input): void
|
|||||||
'server_id' => $server->id,
|
'server_id' => $server->id,
|
||||||
'user' => $input['user'],
|
'user' => $input['user'],
|
||||||
'command' => $input['command'],
|
'command' => $input['command'],
|
||||||
'frequency' => $input['frequency'],
|
'frequency' => $input['frequency'] == 'custom' ? $input['custom'] : $input['frequency'],
|
||||||
'status' => CronjobStatus::CREATING,
|
'status' => CronjobStatus::CREATING,
|
||||||
]);
|
]);
|
||||||
$cronJob->save();
|
$cronJob->save();
|
||||||
$cronJob->addToServer();
|
|
||||||
|
$server->cron()->update($cronJob->user, CronJob::crontab($server, $cronJob->user));
|
||||||
|
$cronJob->status = CronjobStatus::READY;
|
||||||
|
$cronJob->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -41,8 +44,17 @@ private function validate(array $input): void
|
|||||||
],
|
],
|
||||||
'frequency' => [
|
'frequency' => [
|
||||||
'required',
|
'required',
|
||||||
new CronRule(),
|
new CronRule(acceptCustom: true),
|
||||||
],
|
],
|
||||||
])->validateWithBag('createCronJob');
|
])->validate();
|
||||||
|
|
||||||
|
if ($input['frequency'] == 'custom') {
|
||||||
|
Validator::make($input, [
|
||||||
|
'custom' => [
|
||||||
|
'required',
|
||||||
|
new CronRule(),
|
||||||
|
],
|
||||||
|
])->validate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
19
app/Actions/CronJob/DeleteCronJob.php
Executable file
19
app/Actions/CronJob/DeleteCronJob.php
Executable file
@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions\CronJob;
|
||||||
|
|
||||||
|
use App\Enums\CronjobStatus;
|
||||||
|
use App\Models\CronJob;
|
||||||
|
use App\Models\Server;
|
||||||
|
|
||||||
|
class DeleteCronJob
|
||||||
|
{
|
||||||
|
public function delete(Server $server, CronJob $cronJob): void
|
||||||
|
{
|
||||||
|
$user = $cronJob->user;
|
||||||
|
$cronJob->status = CronjobStatus::DELETING;
|
||||||
|
$cronJob->save();
|
||||||
|
$server->cron()->update($cronJob->user, CronJob::crontab($server, $user));
|
||||||
|
$cronJob->delete();
|
||||||
|
}
|
||||||
|
}
|
20
app/Actions/CronJob/DisableCronJob.php
Executable file
20
app/Actions/CronJob/DisableCronJob.php
Executable file
@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions\CronJob;
|
||||||
|
|
||||||
|
use App\Enums\CronjobStatus;
|
||||||
|
use App\Models\CronJob;
|
||||||
|
use App\Models\Server;
|
||||||
|
|
||||||
|
class DisableCronJob
|
||||||
|
{
|
||||||
|
public function disable(Server $server, CronJob $cronJob): void
|
||||||
|
{
|
||||||
|
$cronJob->status = CronjobStatus::DISABLING;
|
||||||
|
$cronJob->save();
|
||||||
|
|
||||||
|
$server->cron()->update($cronJob->user, CronJob::crontab($server, $cronJob->user));
|
||||||
|
$cronJob->status = CronjobStatus::DISABLED;
|
||||||
|
$cronJob->save();
|
||||||
|
}
|
||||||
|
}
|
20
app/Actions/CronJob/EnableCronJob.php
Executable file
20
app/Actions/CronJob/EnableCronJob.php
Executable file
@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions\CronJob;
|
||||||
|
|
||||||
|
use App\Enums\CronjobStatus;
|
||||||
|
use App\Models\CronJob;
|
||||||
|
use App\Models\Server;
|
||||||
|
|
||||||
|
class EnableCronJob
|
||||||
|
{
|
||||||
|
public function enable(Server $server, CronJob $cronJob): void
|
||||||
|
{
|
||||||
|
$cronJob->status = CronjobStatus::ENABLING;
|
||||||
|
$cronJob->save();
|
||||||
|
|
||||||
|
$server->cron()->update($cronJob->user, CronJob::crontab($server, $cronJob->user));
|
||||||
|
$cronJob->status = CronjobStatus::READY;
|
||||||
|
$cronJob->save();
|
||||||
|
}
|
||||||
|
}
|
@ -24,15 +24,15 @@ public function create($type, Server $server, array $input): Backup
|
|||||||
$backup = new Backup([
|
$backup = new Backup([
|
||||||
'type' => $type,
|
'type' => $type,
|
||||||
'server_id' => $server->id,
|
'server_id' => $server->id,
|
||||||
'database_id' => $input['database'] ?? null,
|
'database_id' => $input['backup_database'] ?? null,
|
||||||
'storage_id' => $input['storage'],
|
'storage_id' => $input['backup_storage'],
|
||||||
'interval' => $input['interval'] == 'custom' ? $input['custom'] : $input['interval'],
|
'interval' => $input['backup_interval'] == 'custom' ? $input['backup_custom'] : $input['backup_interval'],
|
||||||
'keep_backups' => $input['keep'],
|
'keep_backups' => $input['backup_keep'],
|
||||||
'status' => BackupStatus::RUNNING,
|
'status' => BackupStatus::RUNNING,
|
||||||
]);
|
]);
|
||||||
$backup->save();
|
$backup->save();
|
||||||
|
|
||||||
$backup->run();
|
app(RunBackup::class)->run($backup);
|
||||||
|
|
||||||
return $backup;
|
return $backup;
|
||||||
}
|
}
|
||||||
@ -43,16 +43,16 @@ public function create($type, Server $server, array $input): Backup
|
|||||||
private function validate($type, Server $server, array $input): void
|
private function validate($type, Server $server, array $input): void
|
||||||
{
|
{
|
||||||
$rules = [
|
$rules = [
|
||||||
'storage' => [
|
'backup_storage' => [
|
||||||
'required',
|
'required',
|
||||||
Rule::exists('storage_providers', 'id'),
|
Rule::exists('storage_providers', 'id'),
|
||||||
],
|
],
|
||||||
'keep' => [
|
'backup_keep' => [
|
||||||
'required',
|
'required',
|
||||||
'numeric',
|
'numeric',
|
||||||
'min:1',
|
'min:1',
|
||||||
],
|
],
|
||||||
'interval' => [
|
'backup_interval' => [
|
||||||
'required',
|
'required',
|
||||||
Rule::in([
|
Rule::in([
|
||||||
'0 * * * *',
|
'0 * * * *',
|
||||||
@ -63,13 +63,13 @@ private function validate($type, Server $server, array $input): void
|
|||||||
]),
|
]),
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
if ($input['interval'] == 'custom') {
|
if ($input['backup_interval'] == 'custom') {
|
||||||
$rules['custom'] = [
|
$rules['backup_custom'] = [
|
||||||
'required',
|
'required',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
if ($type === 'database') {
|
if ($type === 'database') {
|
||||||
$rules['database'] = [
|
$rules['backup_database'] = [
|
||||||
'required',
|
'required',
|
||||||
Rule::exists('databases', 'id')
|
Rule::exists('databases', 'id')
|
||||||
->where('server_id', $server->id)
|
->where('server_id', $server->id)
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Actions\Database;
|
namespace App\Actions\Database;
|
||||||
|
|
||||||
|
use App\Enums\DatabaseStatus;
|
||||||
use App\Models\Database;
|
use App\Models\Database;
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
use Illuminate\Support\Facades\Validator;
|
use Illuminate\Support\Facades\Validator;
|
||||||
@ -21,8 +22,11 @@ public function create(Server $server, array $input): Database
|
|||||||
'server_id' => $server->id,
|
'server_id' => $server->id,
|
||||||
'name' => $input['name'],
|
'name' => $input['name'],
|
||||||
]);
|
]);
|
||||||
|
/** @var \App\SSH\Services\Database\Database */
|
||||||
|
$databaseHandler = $server->database()->handler();
|
||||||
|
$databaseHandler->create($database->name);
|
||||||
|
$database->status = DatabaseStatus::READY;
|
||||||
$database->save();
|
$database->save();
|
||||||
$database->createOnServer();
|
|
||||||
|
|
||||||
return $database;
|
return $database;
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Actions\Database;
|
namespace App\Actions\Database;
|
||||||
|
|
||||||
|
use App\Enums\DatabaseUserStatus;
|
||||||
use App\Models\DatabaseUser;
|
use App\Models\DatabaseUser;
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
use Illuminate\Support\Facades\Validator;
|
use Illuminate\Support\Facades\Validator;
|
||||||
@ -24,8 +25,17 @@ public function create(Server $server, array $input, array $links = []): Databas
|
|||||||
'host' => isset($input['remote']) && $input['remote'] ? $input['host'] : 'localhost',
|
'host' => isset($input['remote']) && $input['remote'] ? $input['host'] : 'localhost',
|
||||||
'databases' => $links,
|
'databases' => $links,
|
||||||
]);
|
]);
|
||||||
|
$server->database()->handler()->createUser(
|
||||||
|
$databaseUser->username,
|
||||||
|
$databaseUser->password,
|
||||||
|
$databaseUser->host
|
||||||
|
);
|
||||||
|
$databaseUser->status = DatabaseUserStatus::READY;
|
||||||
$databaseUser->save();
|
$databaseUser->save();
|
||||||
$databaseUser->createOnServer();
|
|
||||||
|
if (count($links) > 0) {
|
||||||
|
app(LinkUser::class)->link($databaseUser, ['databases' => $links]);
|
||||||
|
}
|
||||||
|
|
||||||
return $databaseUser;
|
return $databaseUser;
|
||||||
}
|
}
|
||||||
|
15
app/Actions/Database/DeleteDatabase.php
Executable file
15
app/Actions/Database/DeleteDatabase.php
Executable file
@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions\Database;
|
||||||
|
|
||||||
|
use App\Models\Database;
|
||||||
|
use App\Models\Server;
|
||||||
|
|
||||||
|
class DeleteDatabase
|
||||||
|
{
|
||||||
|
public function delete(Server $server, Database $database): void
|
||||||
|
{
|
||||||
|
$server->database()->handler()->delete($database->name);
|
||||||
|
$database->delete();
|
||||||
|
}
|
||||||
|
}
|
15
app/Actions/Database/DeleteDatabaseUser.php
Executable file
15
app/Actions/Database/DeleteDatabaseUser.php
Executable file
@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions\Database;
|
||||||
|
|
||||||
|
use App\Models\DatabaseUser;
|
||||||
|
use App\Models\Server;
|
||||||
|
|
||||||
|
class DeleteDatabaseUser
|
||||||
|
{
|
||||||
|
public function delete(Server $server, DatabaseUser $databaseUser): void
|
||||||
|
{
|
||||||
|
$server->database()->handler()->deleteUser($databaseUser->username, $databaseUser->host);
|
||||||
|
$databaseUser->delete();
|
||||||
|
}
|
||||||
|
}
|
@ -1,55 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Actions\Database;
|
|
||||||
|
|
||||||
use App\Models\Server;
|
|
||||||
use App\Models\Service;
|
|
||||||
use Illuminate\Support\Facades\Validator;
|
|
||||||
use Illuminate\Validation\ValidationException;
|
|
||||||
|
|
||||||
class InstallPHPMyAdmin
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @throws ValidationException
|
|
||||||
*/
|
|
||||||
public function install(Server $server, array $input): Service
|
|
||||||
{
|
|
||||||
$this->validate($input);
|
|
||||||
|
|
||||||
$phpMyAdmin = $server->defaultService('phpmyadmin');
|
|
||||||
if ($phpMyAdmin) {
|
|
||||||
if ($phpMyAdmin->status === 'ready') {
|
|
||||||
throw ValidationException::withMessages([
|
|
||||||
'install' => __('Already installed'),
|
|
||||||
])->errorBag('installPHPMyAdmin');
|
|
||||||
}
|
|
||||||
$phpMyAdmin->delete();
|
|
||||||
}
|
|
||||||
$phpMyAdmin = new Service([
|
|
||||||
'server_id' => $server->id,
|
|
||||||
'type' => 'phpmyadmin',
|
|
||||||
'type_data' => [
|
|
||||||
'allowed_ip' => $input['allowed_ip'],
|
|
||||||
'php' => $server->defaultService('php')->version,
|
|
||||||
],
|
|
||||||
'name' => 'phpmyadmin',
|
|
||||||
'version' => '5.1.2',
|
|
||||||
'status' => 'installing',
|
|
||||||
'is_default' => 1,
|
|
||||||
]);
|
|
||||||
$phpMyAdmin->save();
|
|
||||||
$phpMyAdmin->install();
|
|
||||||
|
|
||||||
return $phpMyAdmin;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws ValidationException
|
|
||||||
*/
|
|
||||||
private function validate(array $input): void
|
|
||||||
{
|
|
||||||
Validator::make($input, [
|
|
||||||
'allowed_ip' => 'required',
|
|
||||||
])->validateWithBag('installPHPMyAdmin');
|
|
||||||
}
|
|
||||||
}
|
|
@ -4,6 +4,9 @@
|
|||||||
|
|
||||||
use App\Models\Database;
|
use App\Models\Database;
|
||||||
use App\Models\DatabaseUser;
|
use App\Models\DatabaseUser;
|
||||||
|
use App\Models\Server;
|
||||||
|
use Illuminate\Support\Facades\Validator;
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
use Illuminate\Validation\ValidationException;
|
use Illuminate\Validation\ValidationException;
|
||||||
|
|
||||||
class LinkUser
|
class LinkUser
|
||||||
@ -11,20 +14,49 @@ class LinkUser
|
|||||||
/**
|
/**
|
||||||
* @throws ValidationException
|
* @throws ValidationException
|
||||||
*/
|
*/
|
||||||
public function link(DatabaseUser $databaseUser, array $databases): void
|
public function link(DatabaseUser $databaseUser, array $input): void
|
||||||
{
|
{
|
||||||
$dbs = Database::query()
|
if (! isset($input['databases']) || ! is_array($input['databases'])) {
|
||||||
->where('server_id', $databaseUser->server_id)
|
$input['databases'] = [];
|
||||||
->whereIn('name', $databases)
|
|
||||||
->count();
|
|
||||||
if (count($databases) !== $dbs) {
|
|
||||||
throw ValidationException::withMessages(['databases' => __('Databases not found!')])
|
|
||||||
->errorBag('linkUser');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$databaseUser->databases = $databases;
|
$this->validate($databaseUser->server, $input);
|
||||||
$databaseUser->unlinkUser();
|
|
||||||
$databaseUser->linkUser();
|
$dbs = Database::query()
|
||||||
|
->where('server_id', $databaseUser->server_id)
|
||||||
|
->whereIn('name', $input['databases'])
|
||||||
|
->count();
|
||||||
|
if (count($input['databases']) !== $dbs) {
|
||||||
|
throw ValidationException::withMessages(['databases' => __('Databases not found!')]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$databaseUser->databases = $input['databases'];
|
||||||
|
|
||||||
|
// Unlink the user from all databases
|
||||||
|
$databaseUser->server->database()->handler()->unlink(
|
||||||
|
$databaseUser->username,
|
||||||
|
$databaseUser->host
|
||||||
|
);
|
||||||
|
|
||||||
|
// Link the user to the selected databases
|
||||||
|
$databaseUser->server->database()->handler()->link(
|
||||||
|
$databaseUser->username,
|
||||||
|
$databaseUser->host,
|
||||||
|
$databaseUser->databases
|
||||||
|
);
|
||||||
|
|
||||||
$databaseUser->save();
|
$databaseUser->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function validate(Server $server, array $input): void
|
||||||
|
{
|
||||||
|
$rules = [
|
||||||
|
'databases.*' => [
|
||||||
|
'required',
|
||||||
|
Rule::exists('databases', 'name')->where('server_id', $server->id),
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
Validator::make($input, $rules)->validate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
39
app/Actions/Database/RestoreBackup.php
Normal file
39
app/Actions/Database/RestoreBackup.php
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions\Database;
|
||||||
|
|
||||||
|
use App\Enums\BackupFileStatus;
|
||||||
|
use App\Models\BackupFile;
|
||||||
|
use App\Models\Database;
|
||||||
|
use Illuminate\Support\Facades\Validator;
|
||||||
|
|
||||||
|
class RestoreBackup
|
||||||
|
{
|
||||||
|
public function restore(BackupFile $backupFile, array $input): void
|
||||||
|
{
|
||||||
|
$this->validate($input);
|
||||||
|
|
||||||
|
/** @var Database $database */
|
||||||
|
$database = Database::query()->findOrFail($input['database']);
|
||||||
|
$backupFile->status = BackupFileStatus::RESTORING;
|
||||||
|
$backupFile->restored_to = $database->name;
|
||||||
|
$backupFile->save();
|
||||||
|
|
||||||
|
dispatch(function () use ($backupFile, $database) {
|
||||||
|
$database->server->database()->handler()->restoreBackup($backupFile, $database->name);
|
||||||
|
$backupFile->status = BackupFileStatus::RESTORED;
|
||||||
|
$backupFile->restored_at = now();
|
||||||
|
$backupFile->save();
|
||||||
|
})->catch(function () use ($backupFile) {
|
||||||
|
$backupFile->status = BackupFileStatus::RESTORE_FAILED;
|
||||||
|
$backupFile->save();
|
||||||
|
})->onConnection('ssh');
|
||||||
|
}
|
||||||
|
|
||||||
|
private function validate(array $input): void
|
||||||
|
{
|
||||||
|
Validator::make($input, [
|
||||||
|
'database' => 'required|exists:databases,id',
|
||||||
|
])->validate();
|
||||||
|
}
|
||||||
|
}
|
32
app/Actions/Database/RunBackup.php
Normal file
32
app/Actions/Database/RunBackup.php
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions\Database;
|
||||||
|
|
||||||
|
use App\Enums\BackupFileStatus;
|
||||||
|
use App\Models\Backup;
|
||||||
|
use App\Models\BackupFile;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
|
class RunBackup
|
||||||
|
{
|
||||||
|
public function run(Backup $backup): BackupFile
|
||||||
|
{
|
||||||
|
$file = new BackupFile([
|
||||||
|
'backup_id' => $backup->id,
|
||||||
|
'name' => Str::of($backup->database->name)->slug().'-'.now()->format('YmdHis'),
|
||||||
|
'status' => BackupFileStatus::CREATING,
|
||||||
|
]);
|
||||||
|
$file->save();
|
||||||
|
|
||||||
|
dispatch(function () use ($file) {
|
||||||
|
$file->backup->server->database()->handler()->runBackup($file);
|
||||||
|
$file->status = BackupFileStatus::CREATED;
|
||||||
|
$file->save();
|
||||||
|
})->catch(function () use ($file) {
|
||||||
|
$file->status = BackupFileStatus::FAILED;
|
||||||
|
$file->save();
|
||||||
|
})->onConnection('ssh');
|
||||||
|
|
||||||
|
return $file;
|
||||||
|
}
|
||||||
|
}
|
@ -21,10 +21,20 @@ public function create(Server $server, array $input): FirewallRule
|
|||||||
'port' => $input['port'],
|
'port' => $input['port'],
|
||||||
'source' => $input['source'],
|
'source' => $input['source'],
|
||||||
'mask' => $input['mask'] ?? null,
|
'mask' => $input['mask'] ?? null,
|
||||||
'status' => FirewallRuleStatus::CREATING,
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
$server->firewall()
|
||||||
|
->handler()
|
||||||
|
->addRule(
|
||||||
|
$rule->type,
|
||||||
|
$rule->getRealProtocol(),
|
||||||
|
$rule->port,
|
||||||
|
$rule->source,
|
||||||
|
$rule->mask
|
||||||
|
);
|
||||||
|
|
||||||
|
$rule->status = FirewallRuleStatus::READY;
|
||||||
$rule->save();
|
$rule->save();
|
||||||
$rule->addToServer();
|
|
||||||
|
|
||||||
return $rule;
|
return $rule;
|
||||||
}
|
}
|
||||||
@ -56,6 +66,6 @@ private function validate(Server $server, array $input): void
|
|||||||
'mask' => [
|
'mask' => [
|
||||||
'numeric',
|
'numeric',
|
||||||
],
|
],
|
||||||
])->validateWithBag('createRule');
|
])->validate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
28
app/Actions/FirewallRule/DeleteRule.php
Executable file
28
app/Actions/FirewallRule/DeleteRule.php
Executable file
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions\FirewallRule;
|
||||||
|
|
||||||
|
use App\Enums\FirewallRuleStatus;
|
||||||
|
use App\Models\FirewallRule;
|
||||||
|
use App\Models\Server;
|
||||||
|
|
||||||
|
class DeleteRule
|
||||||
|
{
|
||||||
|
public function delete(Server $server, FirewallRule $rule): void
|
||||||
|
{
|
||||||
|
$rule->status = FirewallRuleStatus::DELETING;
|
||||||
|
$rule->save();
|
||||||
|
|
||||||
|
$server->firewall()
|
||||||
|
->handler()
|
||||||
|
->removeRule(
|
||||||
|
$rule->type,
|
||||||
|
$rule->getRealProtocol(),
|
||||||
|
$rule->port,
|
||||||
|
$rule->source,
|
||||||
|
$rule->mask
|
||||||
|
);
|
||||||
|
|
||||||
|
$rule->delete();
|
||||||
|
}
|
||||||
|
}
|
150
app/Actions/Monitoring/GetMetrics.php
Normal file
150
app/Actions/Monitoring/GetMetrics.php
Normal file
@ -0,0 +1,150 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions\Monitoring;
|
||||||
|
|
||||||
|
use App\Models\Server;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use Illuminate\Contracts\Database\Query\Expression;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Validator;
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
|
|
||||||
|
class GetMetrics
|
||||||
|
{
|
||||||
|
public function filter(Server $server, array $input): array
|
||||||
|
{
|
||||||
|
if (isset($input['from']) && isset($input['to']) && $input['from'] === $input['to']) {
|
||||||
|
$input['from'] = Carbon::parse($input['from'])->format('Y-m-d').' 00:00:00';
|
||||||
|
$input['to'] = Carbon::parse($input['to'])->format('Y-m-d').' 23:59:59';
|
||||||
|
}
|
||||||
|
|
||||||
|
$defaultInput = [
|
||||||
|
'period' => '10m',
|
||||||
|
];
|
||||||
|
|
||||||
|
$input = array_merge($defaultInput, $input);
|
||||||
|
|
||||||
|
$this->validate($input);
|
||||||
|
|
||||||
|
return $this->metrics(
|
||||||
|
server: $server,
|
||||||
|
fromDate: $this->getFromDate($input),
|
||||||
|
toDate: $this->getToDate($input),
|
||||||
|
interval: $this->getInterval($input)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function metrics(
|
||||||
|
Server $server,
|
||||||
|
Carbon $fromDate,
|
||||||
|
Carbon $toDate,
|
||||||
|
?Expression $interval = null
|
||||||
|
): array {
|
||||||
|
$metrics = DB::table('metrics')
|
||||||
|
->where('server_id', $server->id)
|
||||||
|
->whereBetween('created_at', [$fromDate->format('Y-m-d H:i:s'), $toDate->format('Y-m-d H:i:s')])
|
||||||
|
->select(
|
||||||
|
[
|
||||||
|
DB::raw('created_at as date'),
|
||||||
|
DB::raw('ROUND(AVG(load), 2) as load'),
|
||||||
|
DB::raw('ROUND(AVG(memory_total), 2) as memory_total'),
|
||||||
|
DB::raw('ROUND(AVG(memory_used), 2) as memory_used'),
|
||||||
|
DB::raw('ROUND(AVG(memory_free), 2) as memory_free'),
|
||||||
|
DB::raw('ROUND(AVG(disk_total), 2) as disk_total'),
|
||||||
|
DB::raw('ROUND(AVG(disk_used), 2) as disk_used'),
|
||||||
|
DB::raw('ROUND(AVG(disk_free), 2) as disk_free'),
|
||||||
|
$interval,
|
||||||
|
],
|
||||||
|
)
|
||||||
|
->groupByRaw('date_interval')
|
||||||
|
->orderBy('date_interval')
|
||||||
|
->get()
|
||||||
|
->map(function ($item) {
|
||||||
|
$item->date = Carbon::parse($item->date)->format('Y-m-d H:i');
|
||||||
|
|
||||||
|
return $item;
|
||||||
|
});
|
||||||
|
|
||||||
|
return [
|
||||||
|
'metrics' => $metrics,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getFromDate(array $input): Carbon
|
||||||
|
{
|
||||||
|
if ($input['period'] === 'custom') {
|
||||||
|
return new Carbon($input['from']);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Carbon::parse('-'.convert_time_format($input['period']));
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getToDate(array $input): Carbon
|
||||||
|
{
|
||||||
|
if ($input['period'] === 'custom') {
|
||||||
|
return new Carbon($input['to']);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Carbon::now();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getInterval(array $input): Expression
|
||||||
|
{
|
||||||
|
if ($input['period'] === 'custom') {
|
||||||
|
$from = new Carbon($input['from']);
|
||||||
|
$to = new Carbon($input['to']);
|
||||||
|
$periodInHours = $from->diffInHours($to);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! isset($periodInHours)) {
|
||||||
|
$periodInHours = Carbon::parse(
|
||||||
|
convert_time_format($input['period'])
|
||||||
|
)->diffInHours();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (abs($periodInHours) <= 1) {
|
||||||
|
return DB::raw("strftime('%Y-%m-%d %H:%M:00', created_at) as date_interval");
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($periodInHours <= 24) {
|
||||||
|
return DB::raw("strftime('%Y-%m-%d %H:00:00', created_at) as date_interval");
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($periodInHours > 24) {
|
||||||
|
return DB::raw("strftime('%Y-%m-%d 00:00:00', created_at) as date_interval");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function validate(array $input): void
|
||||||
|
{
|
||||||
|
Validator::make($input, [
|
||||||
|
'period' => [
|
||||||
|
'required',
|
||||||
|
Rule::in([
|
||||||
|
'10m',
|
||||||
|
'30m',
|
||||||
|
'1h',
|
||||||
|
'12h',
|
||||||
|
'1d',
|
||||||
|
'7d',
|
||||||
|
'custom',
|
||||||
|
]),
|
||||||
|
],
|
||||||
|
])->validate();
|
||||||
|
|
||||||
|
if ($input['period'] === 'custom') {
|
||||||
|
Validator::make($input, [
|
||||||
|
'from' => [
|
||||||
|
'required',
|
||||||
|
'date',
|
||||||
|
'before:to',
|
||||||
|
],
|
||||||
|
'to' => [
|
||||||
|
'required',
|
||||||
|
'date',
|
||||||
|
'after:from',
|
||||||
|
],
|
||||||
|
])->validate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
32
app/Actions/Monitoring/UpdateMetricSettings.php
Normal file
32
app/Actions/Monitoring/UpdateMetricSettings.php
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions\Monitoring;
|
||||||
|
|
||||||
|
use App\Models\Server;
|
||||||
|
use Illuminate\Support\Facades\Validator;
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
|
|
||||||
|
class UpdateMetricSettings
|
||||||
|
{
|
||||||
|
public function update(Server $server, array $input): void
|
||||||
|
{
|
||||||
|
$this->validate($input);
|
||||||
|
|
||||||
|
$service = $server->monitoring();
|
||||||
|
|
||||||
|
$data = $service->handler()->data();
|
||||||
|
$data['data_retention'] = $input['data_retention'];
|
||||||
|
$service->type_data = $data;
|
||||||
|
$service->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function validate(array $input): void
|
||||||
|
{
|
||||||
|
Validator::make($input, [
|
||||||
|
'data_retention' => [
|
||||||
|
'required',
|
||||||
|
Rule::in(config('core.metrics_data_retention')),
|
||||||
|
],
|
||||||
|
])->validate();
|
||||||
|
}
|
||||||
|
}
|
@ -19,18 +19,28 @@ public function add(User $user, array $input): void
|
|||||||
'user_id' => $user->id,
|
'user_id' => $user->id,
|
||||||
'provider' => $input['provider'],
|
'provider' => $input['provider'],
|
||||||
'label' => $input['label'],
|
'label' => $input['label'],
|
||||||
|
'project_id' => isset($input['global']) && $input['global'] ? null : $user->current_project_id,
|
||||||
]);
|
]);
|
||||||
$this->validateType($channel, $input);
|
$this->validateType($channel, $input);
|
||||||
$channel->data = $channel->provider()->data($input);
|
$channel->data = $channel->provider()->createData($input);
|
||||||
$channel->save();
|
$channel->save();
|
||||||
|
|
||||||
if (! $channel->provider()->connect()) {
|
if (! $channel->provider()->connect()) {
|
||||||
$channel->delete();
|
$channel->delete();
|
||||||
|
|
||||||
|
if ($channel->provider === \App\Enums\NotificationChannel::EMAIL) {
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'email' => __('Could not connect! Make sure you configured `.env` file correctly.'),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
throw ValidationException::withMessages([
|
throw ValidationException::withMessages([
|
||||||
'provider' => __('Could not connect'),
|
'provider' => __('Could not connect'),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$channel->connected = true;
|
||||||
|
$channel->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -49,7 +59,7 @@ protected function validate(array $input): void
|
|||||||
*/
|
*/
|
||||||
protected function validateType(NotificationChannel $channel, array $input): void
|
protected function validateType(NotificationChannel $channel, array $input): void
|
||||||
{
|
{
|
||||||
Validator::make($input, $channel->provider()->validationRules())
|
Validator::make($input, $channel->provider()->createRules($input))
|
||||||
->validate();
|
->validate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
34
app/Actions/NotificationChannels/EditChannel.php
Normal file
34
app/Actions/NotificationChannels/EditChannel.php
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions\NotificationChannels;
|
||||||
|
|
||||||
|
use App\Models\NotificationChannel;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Support\Facades\Validator;
|
||||||
|
use Illuminate\Validation\ValidationException;
|
||||||
|
|
||||||
|
class EditChannel
|
||||||
|
{
|
||||||
|
public function edit(NotificationChannel $notificationChannel, User $user, array $input): void
|
||||||
|
{
|
||||||
|
$this->validate($input);
|
||||||
|
|
||||||
|
$notificationChannel->label = $input['label'];
|
||||||
|
$notificationChannel->project_id = isset($input['global']) && $input['global'] ? null : $user->current_project_id;
|
||||||
|
|
||||||
|
$notificationChannel->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws ValidationException
|
||||||
|
*/
|
||||||
|
private function validate(array $input): void
|
||||||
|
{
|
||||||
|
$rules = [
|
||||||
|
'label' => [
|
||||||
|
'required',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
Validator::make($input, $rules)->validate();
|
||||||
|
}
|
||||||
|
}
|
32
app/Actions/PHP/ChangeDefaultCli.php
Normal file
32
app/Actions/PHP/ChangeDefaultCli.php
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions\PHP;
|
||||||
|
|
||||||
|
use App\Enums\ServiceStatus;
|
||||||
|
use App\Models\Server;
|
||||||
|
use App\SSH\Services\PHP\PHP;
|
||||||
|
use Illuminate\Validation\ValidationException;
|
||||||
|
|
||||||
|
class ChangeDefaultCli
|
||||||
|
{
|
||||||
|
public function change(Server $server, array $input): void
|
||||||
|
{
|
||||||
|
$this->validate($server, $input);
|
||||||
|
$service = $server->php($input['version']);
|
||||||
|
/** @var PHP $handler */
|
||||||
|
$handler = $service->handler();
|
||||||
|
$handler->setDefaultCli();
|
||||||
|
$server->defaultService('php')->update(['is_default' => 0]);
|
||||||
|
$service->update(['is_default' => 1]);
|
||||||
|
$service->update(['status' => ServiceStatus::READY]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function validate(Server $server, array $input): void
|
||||||
|
{
|
||||||
|
if (! isset($input['version']) || ! in_array($input['version'], $server->installedPHPVersions())) {
|
||||||
|
throw ValidationException::withMessages(
|
||||||
|
['version' => __('This version is not installed')]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
47
app/Actions/PHP/GetPHPIni.php
Normal file
47
app/Actions/PHP/GetPHPIni.php
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions\PHP;
|
||||||
|
|
||||||
|
use App\Enums\PHPIniType;
|
||||||
|
use App\Models\Server;
|
||||||
|
use App\SSH\Services\PHP\PHP;
|
||||||
|
use Illuminate\Support\Facades\Validator;
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
|
use Illuminate\Validation\ValidationException;
|
||||||
|
|
||||||
|
class GetPHPIni
|
||||||
|
{
|
||||||
|
public function getIni(Server $server, array $input): string
|
||||||
|
{
|
||||||
|
$this->validate($server, $input);
|
||||||
|
|
||||||
|
$php = $server->php($input['version']);
|
||||||
|
|
||||||
|
try {
|
||||||
|
/** @var PHP $handler */
|
||||||
|
$handler = $php->handler();
|
||||||
|
|
||||||
|
return $handler->getPHPIni($input['type']);
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
throw ValidationException::withMessages(
|
||||||
|
['ini' => $e->getMessage()]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function validate(Server $server, array $input): void
|
||||||
|
{
|
||||||
|
Validator::make($input, [
|
||||||
|
'type' => [
|
||||||
|
'required',
|
||||||
|
Rule::in([PHPIniType::CLI, PHPIniType::FPM]),
|
||||||
|
],
|
||||||
|
])->validate();
|
||||||
|
|
||||||
|
if (! isset($input['version']) || ! in_array($input['version'], $server->installedPHPVersions())) {
|
||||||
|
throw ValidationException::withMessages(
|
||||||
|
['version' => __('This version is not installed')]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -28,7 +28,14 @@ public function install(Server $server, array $input): void
|
|||||||
'is_default' => false,
|
'is_default' => false,
|
||||||
]);
|
]);
|
||||||
$php->save();
|
$php->save();
|
||||||
$php->install();
|
|
||||||
|
dispatch(function () use ($php) {
|
||||||
|
$php->handler()->install();
|
||||||
|
$php->status = ServiceStatus::READY;
|
||||||
|
$php->save();
|
||||||
|
})->catch(function () use ($php) {
|
||||||
|
$php->delete();
|
||||||
|
})->onConnection('ssh');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -41,12 +48,12 @@ private function validate(Server $server, array $input): void
|
|||||||
'required',
|
'required',
|
||||||
Rule::in(config('core.php_versions')),
|
Rule::in(config('core.php_versions')),
|
||||||
],
|
],
|
||||||
])->validateWithBag('installPHP');
|
])->validate();
|
||||||
|
|
||||||
if (in_array($input['version'], $server->installedPHPVersions())) {
|
if (in_array($input['version'], $server->installedPHPVersions())) {
|
||||||
throw ValidationException::withMessages(
|
throw ValidationException::withMessages(
|
||||||
['version' => __('This version is already installed')]
|
['version' => __('This version is already installed')]
|
||||||
)->errorBag('installPHP');
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,25 +2,38 @@
|
|||||||
|
|
||||||
namespace App\Actions\PHP;
|
namespace App\Actions\PHP;
|
||||||
|
|
||||||
|
use App\Models\Server;
|
||||||
use App\Models\Service;
|
use App\Models\Service;
|
||||||
|
use App\SSH\Services\PHP\PHP;
|
||||||
use Illuminate\Support\Facades\Validator;
|
use Illuminate\Support\Facades\Validator;
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
use Illuminate\Validation\ValidationException;
|
use Illuminate\Validation\ValidationException;
|
||||||
|
|
||||||
class InstallPHPExtension
|
class InstallPHPExtension
|
||||||
{
|
{
|
||||||
/**
|
public function install(Server $server, array $input): Service
|
||||||
* @throws ValidationException
|
|
||||||
*/
|
|
||||||
public function handle(Service $service, array $input): Service
|
|
||||||
{
|
{
|
||||||
|
$this->validate($server, $input);
|
||||||
|
|
||||||
|
/** @var Service $service */
|
||||||
|
$service = $server->php($input['version']);
|
||||||
$typeData = $service->type_data;
|
$typeData = $service->type_data;
|
||||||
$typeData['extensions'] = $typeData['extensions'] ?? [];
|
$typeData['extensions'] = $typeData['extensions'] ?? [];
|
||||||
|
$typeData['extensions'][] = $input['extension'];
|
||||||
$service->type_data = $typeData;
|
$service->type_data = $typeData;
|
||||||
$service->save();
|
$service->save();
|
||||||
|
|
||||||
$this->validate($service, $input);
|
dispatch(function () use ($service, $input) {
|
||||||
|
/** @var PHP $handler */
|
||||||
$service->handler()->installExtension($input['name']);
|
$handler = $service->handler();
|
||||||
|
$handler->installExtension($input['extension']);
|
||||||
|
})->catch(function () use ($service, $input) {
|
||||||
|
$service->refresh();
|
||||||
|
$typeData = $service->type_data;
|
||||||
|
$typeData['extensions'] = array_values(array_diff($typeData['extensions'], [$input['extension']]));
|
||||||
|
$service->type_data = $typeData;
|
||||||
|
$service->save();
|
||||||
|
})->onConnection('ssh');
|
||||||
|
|
||||||
return $service;
|
return $service;
|
||||||
}
|
}
|
||||||
@ -28,18 +41,25 @@ public function handle(Service $service, array $input): Service
|
|||||||
/**
|
/**
|
||||||
* @throws ValidationException
|
* @throws ValidationException
|
||||||
*/
|
*/
|
||||||
private function validate(Service $service, array $input): void
|
private function validate(Server $server, array $input): void
|
||||||
{
|
{
|
||||||
Validator::make($input, [
|
Validator::make($input, [
|
||||||
'name' => [
|
'extension' => [
|
||||||
'required',
|
'required',
|
||||||
'in:'.implode(',', config('core.php_extensions')),
|
'in:'.implode(',', config('core.php_extensions')),
|
||||||
],
|
],
|
||||||
])->validateWithBag('installPHPExtension');
|
'version' => [
|
||||||
|
'required',
|
||||||
|
Rule::in($server->installedPHPVersions()),
|
||||||
|
],
|
||||||
|
])->validate();
|
||||||
|
|
||||||
if (in_array($input['name'], $service->type_data['extensions'])) {
|
/** @var Service $service */
|
||||||
|
$service = $server->php($input['version']);
|
||||||
|
|
||||||
|
if (in_array($input['extension'], $service->type_data['extensions'])) {
|
||||||
throw ValidationException::withMessages(
|
throw ValidationException::withMessages(
|
||||||
['name' => __('This extension already installed')]
|
['extension' => __('This extension already installed')]
|
||||||
)->errorBag('installPHPExtension');
|
)->errorBag('installPHPExtension');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,36 +2,48 @@
|
|||||||
|
|
||||||
namespace App\Actions\PHP;
|
namespace App\Actions\PHP;
|
||||||
|
|
||||||
|
use App\Enums\ServiceStatus;
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
use App\Models\Service;
|
use App\Models\Service;
|
||||||
|
use Illuminate\Support\Facades\Validator;
|
||||||
use Illuminate\Validation\ValidationException;
|
use Illuminate\Validation\ValidationException;
|
||||||
|
|
||||||
class UninstallPHP
|
class UninstallPHP
|
||||||
{
|
{
|
||||||
public function uninstall(Server $server, string $version): void
|
public function uninstall(Server $server, array $input): void
|
||||||
{
|
{
|
||||||
$this->validate($server, $version);
|
$this->validate($server, $input);
|
||||||
|
|
||||||
/** @var Service $php */
|
/** @var Service $php */
|
||||||
$php = $server->services()->where('type', 'php')->where('version', $version)->first();
|
$php = $server->php($input['version']);
|
||||||
|
$php->status = ServiceStatus::UNINSTALLING;
|
||||||
|
$php->save();
|
||||||
|
|
||||||
$php->uninstall();
|
dispatch(function () use ($php) {
|
||||||
|
$php->handler()->uninstall();
|
||||||
|
$php->delete();
|
||||||
|
})->catch(function () use ($php) {
|
||||||
|
$php->status = ServiceStatus::FAILED;
|
||||||
|
$php->save();
|
||||||
|
})->onConnection('ssh');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws ValidationException
|
* @throws ValidationException
|
||||||
*/
|
*/
|
||||||
private function validate(Server $server, string $version): void
|
private function validate(Server $server, array $input): void
|
||||||
{
|
{
|
||||||
$php = $server->services()->where('type', 'php')->where('version', $version)->first();
|
Validator::make($input, [
|
||||||
|
'version' => 'required|string',
|
||||||
|
])->validate();
|
||||||
|
|
||||||
if (! $php) {
|
if (! in_array($input['version'], $server->installedPHPVersions())) {
|
||||||
throw ValidationException::withMessages(
|
throw ValidationException::withMessages(
|
||||||
['version' => __('This version has not been installed yet!')]
|
['version' => __('This version is not installed')]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$hasSite = $server->sites()->where('php_version', $version)->first();
|
$hasSite = $server->sites()->where('php_version', $input['version'])->first();
|
||||||
if ($hasSite) {
|
if ($hasSite) {
|
||||||
throw ValidationException::withMessages(
|
throw ValidationException::withMessages(
|
||||||
['version' => __('Cannot uninstall this version because some sites are using it!')]
|
['version' => __('Cannot uninstall this version because some sites are using it!')]
|
||||||
|
@ -2,9 +2,13 @@
|
|||||||
|
|
||||||
namespace App\Actions\PHP;
|
namespace App\Actions\PHP;
|
||||||
|
|
||||||
use App\Models\Service;
|
use App\Enums\PHPIniType;
|
||||||
|
use App\Models\Server;
|
||||||
|
use Illuminate\Filesystem\FilesystemAdapter;
|
||||||
use Illuminate\Support\Facades\Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
use Illuminate\Support\Facades\Validator;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
use Illuminate\Validation\ValidationException;
|
use Illuminate\Validation\ValidationException;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
||||||
@ -13,20 +17,27 @@ class UpdatePHPIni
|
|||||||
/**
|
/**
|
||||||
* @throws ValidationException
|
* @throws ValidationException
|
||||||
*/
|
*/
|
||||||
public function update(Service $service, string $ini): void
|
public function update(Server $server, array $input): void
|
||||||
{
|
{
|
||||||
|
$this->validate($server, $input);
|
||||||
|
|
||||||
|
$service = $server->php($input['version']);
|
||||||
|
|
||||||
$tmpName = Str::random(10).strtotime('now');
|
$tmpName = Str::random(10).strtotime('now');
|
||||||
try {
|
try {
|
||||||
Storage::disk('local')->put($tmpName, $ini);
|
/** @var FilesystemAdapter $storageDisk */
|
||||||
|
$storageDisk = Storage::disk('local');
|
||||||
|
|
||||||
|
$storageDisk->put($tmpName, $input['ini']);
|
||||||
$service->server->ssh('root')->upload(
|
$service->server->ssh('root')->upload(
|
||||||
Storage::disk('local')->path($tmpName),
|
$storageDisk->path($tmpName),
|
||||||
"/etc/php/$service->version/cli/php.ini"
|
sprintf('/etc/php/%s/%s/php.ini', $service->version, $input['type'])
|
||||||
);
|
);
|
||||||
$this->deleteTempFile($tmpName);
|
$this->deleteTempFile($tmpName);
|
||||||
} catch (Throwable) {
|
} catch (Throwable) {
|
||||||
$this->deleteTempFile($tmpName);
|
$this->deleteTempFile($tmpName);
|
||||||
throw ValidationException::withMessages([
|
throw ValidationException::withMessages([
|
||||||
'ini' => __("Couldn't update php.ini file!"),
|
'ini' => __("Couldn't update php.ini (:type) file!", ['type' => $input['type']]),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,4 +50,25 @@ private function deleteTempFile(string $name): void
|
|||||||
Storage::disk('local')->delete($name);
|
Storage::disk('local')->delete($name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function validate(Server $server, array $input): void
|
||||||
|
{
|
||||||
|
Validator::make($input, [
|
||||||
|
'ini' => [
|
||||||
|
'required',
|
||||||
|
'string',
|
||||||
|
],
|
||||||
|
'version' => 'required|string',
|
||||||
|
'type' => [
|
||||||
|
'required',
|
||||||
|
Rule::in([PHPIniType::CLI, PHPIniType::FPM]),
|
||||||
|
],
|
||||||
|
])->validate();
|
||||||
|
|
||||||
|
if (! in_array($input['version'], $server->installedPHPVersions())) {
|
||||||
|
throw ValidationException::withMessages(
|
||||||
|
['version' => __('This version is not installed')]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
41
app/Actions/Projects/CreateProject.php
Normal file
41
app/Actions/Projects/CreateProject.php
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions\Projects;
|
||||||
|
|
||||||
|
use App\Models\Project;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Support\Facades\Validator;
|
||||||
|
|
||||||
|
class CreateProject
|
||||||
|
{
|
||||||
|
public function create(User $user, array $input): Project
|
||||||
|
{
|
||||||
|
if (isset($input['name'])) {
|
||||||
|
$input['name'] = strtolower($input['name']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->validate($input);
|
||||||
|
|
||||||
|
$project = new Project([
|
||||||
|
'name' => $input['name'],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$project->save();
|
||||||
|
|
||||||
|
$project->users()->attach($user);
|
||||||
|
|
||||||
|
return $project;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function validate(array $input): void
|
||||||
|
{
|
||||||
|
Validator::make($input, [
|
||||||
|
'name' => [
|
||||||
|
'required',
|
||||||
|
'string',
|
||||||
|
'max:255',
|
||||||
|
'unique:projects,name',
|
||||||
|
],
|
||||||
|
])->validate();
|
||||||
|
}
|
||||||
|
}
|
32
app/Actions/Projects/DeleteProject.php
Normal file
32
app/Actions/Projects/DeleteProject.php
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions\Projects;
|
||||||
|
|
||||||
|
use App\Models\Project;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Validation\ValidationException;
|
||||||
|
|
||||||
|
class DeleteProject
|
||||||
|
{
|
||||||
|
public function delete(User $user, Project $project): void
|
||||||
|
{
|
||||||
|
if ($user->projects()->count() === 1) {
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'project' => __('Cannot delete the last project.'),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($user->current_project_id == $project->id) {
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'project' => __('Cannot delete your current project.'),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var Project $randomProject */
|
||||||
|
$randomProject = $user->projects()->where('project_id', '!=', $project->id)->first();
|
||||||
|
$user->current_project_id = $randomProject->id;
|
||||||
|
$user->save();
|
||||||
|
|
||||||
|
$project->delete();
|
||||||
|
}
|
||||||
|
}
|
37
app/Actions/Projects/UpdateProject.php
Normal file
37
app/Actions/Projects/UpdateProject.php
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions\Projects;
|
||||||
|
|
||||||
|
use App\Models\Project;
|
||||||
|
use Illuminate\Support\Facades\Validator;
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
|
|
||||||
|
class UpdateProject
|
||||||
|
{
|
||||||
|
public function update(Project $project, array $input): Project
|
||||||
|
{
|
||||||
|
if (isset($input['name'])) {
|
||||||
|
$input['name'] = strtolower($input['name']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->validate($project, $input);
|
||||||
|
|
||||||
|
$project->name = $input['name'];
|
||||||
|
|
||||||
|
$project->save();
|
||||||
|
|
||||||
|
return $project;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function validate(Project $project, array $input): void
|
||||||
|
{
|
||||||
|
Validator::make($input, [
|
||||||
|
'name' => [
|
||||||
|
'required',
|
||||||
|
'string',
|
||||||
|
'max:255',
|
||||||
|
Rule::unique('projects')->where('user_id', $project->user_id)->ignore($project->id),
|
||||||
|
],
|
||||||
|
])->validate();
|
||||||
|
}
|
||||||
|
}
|
@ -29,7 +29,23 @@ public function create(mixed $queueable, array $input): void
|
|||||||
'status' => QueueStatus::CREATING,
|
'status' => QueueStatus::CREATING,
|
||||||
]);
|
]);
|
||||||
$queue->save();
|
$queue->save();
|
||||||
$queue->deploy();
|
|
||||||
|
dispatch(function () use ($queue) {
|
||||||
|
$queue->server->processManager()->handler()->create(
|
||||||
|
$queue->id,
|
||||||
|
$queue->command,
|
||||||
|
$queue->user,
|
||||||
|
$queue->auto_start,
|
||||||
|
$queue->auto_restart,
|
||||||
|
$queue->numprocs,
|
||||||
|
$queue->getLogFile(),
|
||||||
|
$queue->site_id
|
||||||
|
);
|
||||||
|
$queue->status = QueueStatus::RUNNING;
|
||||||
|
$queue->save();
|
||||||
|
})->catch(function () use ($queue) {
|
||||||
|
$queue->delete();
|
||||||
|
})->onConnection('ssh');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -60,6 +76,6 @@ protected function validate(array $input): void
|
|||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
Validator::make($input, $rules)->validateWithBag('createQueue');
|
Validator::make($input, $rules)->validate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
14
app/Actions/Queue/DeleteQueue.php
Normal file
14
app/Actions/Queue/DeleteQueue.php
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions\Queue;
|
||||||
|
|
||||||
|
use App\Models\Queue;
|
||||||
|
|
||||||
|
class DeleteQueue
|
||||||
|
{
|
||||||
|
public function delete(Queue $queue): void
|
||||||
|
{
|
||||||
|
$queue->server->processManager()->handler()->delete($queue->id, $queue->site_id);
|
||||||
|
$queue->delete();
|
||||||
|
}
|
||||||
|
}
|
13
app/Actions/Queue/GetQueueLogs.php
Normal file
13
app/Actions/Queue/GetQueueLogs.php
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions\Queue;
|
||||||
|
|
||||||
|
use App\Models\Queue;
|
||||||
|
|
||||||
|
class GetQueueLogs
|
||||||
|
{
|
||||||
|
public function getLogs(Queue $queue): string
|
||||||
|
{
|
||||||
|
return $queue->server->processManager()->handler()->getLogs($queue->getLogFile());
|
||||||
|
}
|
||||||
|
}
|
42
app/Actions/Queue/ManageQueue.php
Normal file
42
app/Actions/Queue/ManageQueue.php
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions\Queue;
|
||||||
|
|
||||||
|
use App\Enums\QueueStatus;
|
||||||
|
use App\Models\Queue;
|
||||||
|
|
||||||
|
class ManageQueue
|
||||||
|
{
|
||||||
|
public function start(Queue $queue): void
|
||||||
|
{
|
||||||
|
$queue->status = QueueStatus::STARTING;
|
||||||
|
$queue->save();
|
||||||
|
dispatch(function () use ($queue) {
|
||||||
|
$queue->server->processManager()->handler()->start($queue->id, $queue->site_id);
|
||||||
|
$queue->status = QueueStatus::RUNNING;
|
||||||
|
$queue->save();
|
||||||
|
})->onConnection('ssh');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function stop(Queue $queue): void
|
||||||
|
{
|
||||||
|
$queue->status = QueueStatus::STOPPING;
|
||||||
|
$queue->save();
|
||||||
|
dispatch(function () use ($queue) {
|
||||||
|
$queue->server->processManager()->handler()->stop($queue->id, $queue->site_id);
|
||||||
|
$queue->status = QueueStatus::STOPPED;
|
||||||
|
$queue->save();
|
||||||
|
})->onConnection('ssh');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function restart(Queue $queue): void
|
||||||
|
{
|
||||||
|
$queue->status = QueueStatus::RESTARTING;
|
||||||
|
$queue->save();
|
||||||
|
dispatch(function () use ($queue) {
|
||||||
|
$queue->server->processManager()->handler()->restart($queue->id, $queue->site_id);
|
||||||
|
$queue->status = QueueStatus::RUNNING;
|
||||||
|
$queue->save();
|
||||||
|
})->onConnection('ssh');
|
||||||
|
}
|
||||||
|
}
|
@ -2,8 +2,11 @@
|
|||||||
|
|
||||||
namespace App\Actions\SSL;
|
namespace App\Actions\SSL;
|
||||||
|
|
||||||
|
use App\Enums\SslStatus;
|
||||||
use App\Enums\SslType;
|
use App\Enums\SslType;
|
||||||
use App\Models\Site;
|
use App\Models\Site;
|
||||||
|
use App\Models\Ssl;
|
||||||
|
use App\SSH\Services\Webserver\Webserver;
|
||||||
use Illuminate\Support\Facades\Validator;
|
use Illuminate\Support\Facades\Validator;
|
||||||
use Illuminate\Validation\Rule;
|
use Illuminate\Validation\Rule;
|
||||||
use Illuminate\Validation\ValidationException;
|
use Illuminate\Validation\ValidationException;
|
||||||
@ -17,13 +20,31 @@ public function create(Site $site, array $input): void
|
|||||||
{
|
{
|
||||||
$this->validate($input);
|
$this->validate($input);
|
||||||
|
|
||||||
if ($input['type'] == SslType::LETSENCRYPT) {
|
$ssl = new Ssl([
|
||||||
$site->createFreeSsl();
|
'site_id' => $site->id,
|
||||||
|
'type' => $input['type'],
|
||||||
|
'certificate' => $input['certificate'] ?? null,
|
||||||
|
'pk' => $input['private'] ?? null,
|
||||||
|
'expires_at' => $input['type'] === SslType::LETSENCRYPT ? now()->addMonths(3) : $input['expires_at'],
|
||||||
|
'status' => SslStatus::CREATING,
|
||||||
|
]);
|
||||||
|
$ssl->domains = [$site->domain];
|
||||||
|
if (isset($input['aliases']) && $input['aliases']) {
|
||||||
|
$ssl->domains = array_merge($ssl->domains, $site->aliases);
|
||||||
}
|
}
|
||||||
|
$ssl->save();
|
||||||
|
|
||||||
if ($input['type'] == SslType::CUSTOM) {
|
dispatch(function () use ($site, $ssl) {
|
||||||
$site->createCustomSsl($input['certificate'], $input['private']);
|
/** @var Webserver $webserver */
|
||||||
}
|
$webserver = $site->server->webserver()->handler();
|
||||||
|
$webserver->setupSSL($ssl);
|
||||||
|
$ssl->status = SslStatus::CREATED;
|
||||||
|
$ssl->save();
|
||||||
|
$site->type()->edit();
|
||||||
|
})->catch(function () use ($ssl) {
|
||||||
|
$ssl->status = SslStatus::FAILED;
|
||||||
|
$ssl->save();
|
||||||
|
})->onConnection('ssh');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -34,14 +55,15 @@ protected function validate(array $input): void
|
|||||||
$rules = [
|
$rules = [
|
||||||
'type' => [
|
'type' => [
|
||||||
'required',
|
'required',
|
||||||
Rule::in(SslType::getValues()),
|
Rule::in(config('core.ssl_types')),
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
if (isset($input['type']) && $input['type'] == SslType::CUSTOM) {
|
if (isset($input['type']) && $input['type'] == SslType::CUSTOM) {
|
||||||
$rules['certificate'] = 'required';
|
$rules['certificate'] = 'required';
|
||||||
$rules['private'] = 'required';
|
$rules['private'] = 'required';
|
||||||
|
$rules['expires_at'] = 'required|date_format:Y-m-d|after_or_equal:'.now();
|
||||||
}
|
}
|
||||||
|
|
||||||
Validator::make($input, $rules)->validateWithBag('createSSL');
|
Validator::make($input, $rules)->validate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
14
app/Actions/SSL/DeleteSSL.php
Normal file
14
app/Actions/SSL/DeleteSSL.php
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions\SSL;
|
||||||
|
|
||||||
|
use App\Models\Ssl;
|
||||||
|
|
||||||
|
class DeleteSSL
|
||||||
|
{
|
||||||
|
public function delete(Ssl $ssl): void
|
||||||
|
{
|
||||||
|
$ssl->site->server->webserver()->handler()->removeSSL($ssl);
|
||||||
|
$ssl->delete();
|
||||||
|
}
|
||||||
|
}
|
@ -5,19 +5,15 @@
|
|||||||
use App\Models\Script;
|
use App\Models\Script;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Support\Facades\Validator;
|
use Illuminate\Support\Facades\Validator;
|
||||||
use Illuminate\Validation\ValidationException;
|
|
||||||
|
|
||||||
class CreateScript
|
class CreateScript
|
||||||
{
|
{
|
||||||
/**
|
public function create(User $user, array $input): Script
|
||||||
* @throws ValidationException
|
|
||||||
*/
|
|
||||||
public function handle(User $creator, array $input): Script
|
|
||||||
{
|
{
|
||||||
$this->validateInputs($input);
|
$this->validate($input);
|
||||||
|
|
||||||
$script = new Script([
|
$script = new Script([
|
||||||
'user_id' => $creator->id,
|
'user_id' => $user->id,
|
||||||
'name' => $input['name'],
|
'name' => $input['name'],
|
||||||
'content' => $input['content'],
|
'content' => $input['content'],
|
||||||
]);
|
]);
|
||||||
@ -26,16 +22,11 @@ public function handle(User $creator, array $input): Script
|
|||||||
return $script;
|
return $script;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private function validate(array $input): void
|
||||||
* @throws ValidationException
|
|
||||||
*/
|
|
||||||
private function validateInputs(array $input): void
|
|
||||||
{
|
{
|
||||||
$rules = [
|
Validator::make($input, [
|
||||||
'name' => 'required',
|
'name' => ['required', 'string', 'max:255'],
|
||||||
'content' => 'required',
|
'content' => ['required', 'string'],
|
||||||
];
|
])->validate();
|
||||||
|
|
||||||
Validator::make($input, $rules)->validateWithBag('createScript');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
28
app/Actions/Script/EditScript.php
Normal file
28
app/Actions/Script/EditScript.php
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions\Script;
|
||||||
|
|
||||||
|
use App\Models\Script;
|
||||||
|
use Illuminate\Support\Facades\Validator;
|
||||||
|
|
||||||
|
class EditScript
|
||||||
|
{
|
||||||
|
public function edit(Script $script, array $input): Script
|
||||||
|
{
|
||||||
|
$this->validate($input);
|
||||||
|
|
||||||
|
$script->name = $input['name'];
|
||||||
|
$script->content = $input['content'];
|
||||||
|
$script->save();
|
||||||
|
|
||||||
|
return $script;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function validate(array $input): void
|
||||||
|
{
|
||||||
|
Validator::make($input, [
|
||||||
|
'name' => ['required', 'string', 'max:255'],
|
||||||
|
'content' => ['required', 'string'],
|
||||||
|
])->validate();
|
||||||
|
}
|
||||||
|
}
|
62
app/Actions/Script/ExecuteScript.php
Normal file
62
app/Actions/Script/ExecuteScript.php
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions\Script;
|
||||||
|
|
||||||
|
use App\Enums\ScriptExecutionStatus;
|
||||||
|
use App\Models\Script;
|
||||||
|
use App\Models\ScriptExecution;
|
||||||
|
use App\Models\Server;
|
||||||
|
use App\Models\ServerLog;
|
||||||
|
use Illuminate\Support\Facades\Validator;
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
|
|
||||||
|
class ExecuteScript
|
||||||
|
{
|
||||||
|
public function execute(Script $script, Server $server, array $input): ScriptExecution
|
||||||
|
{
|
||||||
|
$this->validate($server, $input);
|
||||||
|
|
||||||
|
$execution = new ScriptExecution([
|
||||||
|
'script_id' => $script->id,
|
||||||
|
'user' => $input['user'],
|
||||||
|
'variables' => $input['variables'] ?? [],
|
||||||
|
'status' => ScriptExecutionStatus::EXECUTING,
|
||||||
|
]);
|
||||||
|
$execution->save();
|
||||||
|
|
||||||
|
dispatch(function () use ($execution, $server, $script) {
|
||||||
|
$content = $execution->getContent();
|
||||||
|
$log = ServerLog::make($server, 'script-'.$script->id.'-'.strtotime('now'));
|
||||||
|
$log->save();
|
||||||
|
$execution->server_log_id = $log->id;
|
||||||
|
$execution->save();
|
||||||
|
$server->os()->runScript('~/', $content, $log, $execution->user);
|
||||||
|
$execution->status = ScriptExecutionStatus::COMPLETED;
|
||||||
|
$execution->save();
|
||||||
|
})->catch(function () use ($execution) {
|
||||||
|
$execution->status = ScriptExecutionStatus::FAILED;
|
||||||
|
$execution->save();
|
||||||
|
})->onConnection('ssh');
|
||||||
|
|
||||||
|
return $execution;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function validate(Server $server, array $input): void
|
||||||
|
{
|
||||||
|
Validator::make($input, [
|
||||||
|
'user' => [
|
||||||
|
'required',
|
||||||
|
Rule::in([
|
||||||
|
'root',
|
||||||
|
$server->ssh_user,
|
||||||
|
]),
|
||||||
|
],
|
||||||
|
'variables' => 'array',
|
||||||
|
'variables.*' => [
|
||||||
|
'required',
|
||||||
|
'string',
|
||||||
|
'max:255',
|
||||||
|
],
|
||||||
|
])->validate();
|
||||||
|
}
|
||||||
|
}
|
@ -1,17 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Actions\Script;
|
|
||||||
|
|
||||||
use App\Models\User;
|
|
||||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
|
||||||
|
|
||||||
class GetScripts
|
|
||||||
{
|
|
||||||
public function handle(User $user): LengthAwarePaginator
|
|
||||||
{
|
|
||||||
return $user->scripts()
|
|
||||||
->orderBy('id', 'desc')
|
|
||||||
->paginate(6)
|
|
||||||
->onEachSide(1);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,37 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Actions\Script;
|
|
||||||
|
|
||||||
use App\Models\Script;
|
|
||||||
use Illuminate\Support\Facades\Validator;
|
|
||||||
use Illuminate\Validation\ValidationException;
|
|
||||||
|
|
||||||
class UpdateScript
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @throws ValidationException
|
|
||||||
*/
|
|
||||||
public function handle(Script $script, array $input): Script
|
|
||||||
{
|
|
||||||
$this->validateInputs($input);
|
|
||||||
|
|
||||||
$script->name = $input['name'];
|
|
||||||
$script->content = $input['content'];
|
|
||||||
$script->save();
|
|
||||||
|
|
||||||
return $script;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws ValidationException
|
|
||||||
*/
|
|
||||||
private function validateInputs(array $input): void
|
|
||||||
{
|
|
||||||
$rules = [
|
|
||||||
'name' => 'required',
|
|
||||||
'content' => 'required',
|
|
||||||
];
|
|
||||||
|
|
||||||
Validator::make($input, $rules)->validateWithBag('updateScript');
|
|
||||||
}
|
|
||||||
}
|
|
31
app/Actions/Server/CheckConnection.php
Normal file
31
app/Actions/Server/CheckConnection.php
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions\Server;
|
||||||
|
|
||||||
|
use App\Enums\ServerStatus;
|
||||||
|
use App\Facades\Notifier;
|
||||||
|
use App\Models\Server;
|
||||||
|
use App\Notifications\ServerDisconnected;
|
||||||
|
use Throwable;
|
||||||
|
|
||||||
|
class CheckConnection
|
||||||
|
{
|
||||||
|
public function check(Server $server): Server
|
||||||
|
{
|
||||||
|
$status = $server->status;
|
||||||
|
try {
|
||||||
|
$server->ssh()->connect();
|
||||||
|
$server->refresh();
|
||||||
|
if (in_array($status, [ServerStatus::DISCONNECTED, ServerStatus::UPDATING])) {
|
||||||
|
$server->status = ServerStatus::READY;
|
||||||
|
$server->save();
|
||||||
|
}
|
||||||
|
} catch (Throwable) {
|
||||||
|
$server->status = ServerStatus::DISCONNECTED;
|
||||||
|
$server->save();
|
||||||
|
Notifier::send($server, new ServerDisconnected($server));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $server;
|
||||||
|
}
|
||||||
|
}
|
@ -3,13 +3,19 @@
|
|||||||
namespace App\Actions\Server;
|
namespace App\Actions\Server;
|
||||||
|
|
||||||
use App\Enums\FirewallRuleStatus;
|
use App\Enums\FirewallRuleStatus;
|
||||||
|
use App\Enums\ServerProvider;
|
||||||
|
use App\Enums\ServerStatus;
|
||||||
use App\Exceptions\ServerProviderError;
|
use App\Exceptions\ServerProviderError;
|
||||||
use App\Jobs\Installation\ContinueInstallation;
|
use App\Facades\Notifier;
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
|
use App\Notifications\ServerInstallationFailed;
|
||||||
|
use App\Notifications\ServerInstallationSucceed;
|
||||||
use App\ValidationRules\RestrictedIPAddressesRule;
|
use App\ValidationRules\RestrictedIPAddressesRule;
|
||||||
use Exception;
|
use Exception;
|
||||||
|
use Illuminate\Support\Facades\Bus;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
use Illuminate\Support\Facades\Validator;
|
use Illuminate\Support\Facades\Validator;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use Illuminate\Validation\Rule;
|
use Illuminate\Validation\Rule;
|
||||||
@ -26,10 +32,11 @@ public function create(User $creator, array $input): Server
|
|||||||
$this->validateInputs($input);
|
$this->validateInputs($input);
|
||||||
|
|
||||||
$server = new Server([
|
$server = new Server([
|
||||||
|
'project_id' => $creator->currentProject->id,
|
||||||
'user_id' => $creator->id,
|
'user_id' => $creator->id,
|
||||||
'name' => $input['name'],
|
'name' => $input['name'],
|
||||||
'ssh_user' => config('core.server_providers_default_user')[$input['provider']][$input['os']],
|
'ssh_user' => config('core.server_providers_default_user')[$input['provider']][$input['os']],
|
||||||
'ip' => $input['ip'],
|
'ip' => $input['ip'] ?? '',
|
||||||
'port' => $input['port'] ?? 22,
|
'port' => $input['port'] ?? 22,
|
||||||
'os' => $input['os'],
|
'os' => $input['os'],
|
||||||
'type' => $input['type'],
|
'type' => $input['type'],
|
||||||
@ -43,9 +50,8 @@ public function create(User $creator, array $input): Server
|
|||||||
'progress_step' => 'Initializing',
|
'progress_step' => 'Initializing',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
DB::beginTransaction();
|
||||||
try {
|
try {
|
||||||
DB::beginTransaction();
|
|
||||||
|
|
||||||
if ($server->provider != 'custom') {
|
if ($server->provider != 'custom') {
|
||||||
$server->provider_id = $input['server_provider'];
|
$server->provider_id = $input['server_provider'];
|
||||||
}
|
}
|
||||||
@ -71,14 +77,8 @@ public function create(User $creator, array $input): Server
|
|||||||
$server->type()->createServices($input);
|
$server->type()->createServices($input);
|
||||||
|
|
||||||
// install server
|
// install server
|
||||||
if ($server->provider == 'custom') {
|
$this->install($server);
|
||||||
$server->install();
|
|
||||||
} else {
|
|
||||||
$server->progress_step = __('Installation will begin in 3 minutes!');
|
|
||||||
$server->save();
|
|
||||||
dispatch(new ContinueInstallation($server))
|
|
||||||
->delay(now()->addMinutes(2));
|
|
||||||
}
|
|
||||||
DB::commit();
|
DB::commit();
|
||||||
|
|
||||||
return $server;
|
return $server;
|
||||||
@ -88,12 +88,44 @@ public function create(User $creator, array $input): Server
|
|||||||
if ($e instanceof ServerProviderError) {
|
if ($e instanceof ServerProviderError) {
|
||||||
throw ValidationException::withMessages([
|
throw ValidationException::withMessages([
|
||||||
'provider' => __('Provider Error: ').$e->getMessage(),
|
'provider' => __('Provider Error: ').$e->getMessage(),
|
||||||
])->errorBag('createServer');
|
]);
|
||||||
}
|
}
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function install(Server $server): void
|
||||||
|
{
|
||||||
|
$bus = Bus::chain([
|
||||||
|
function () use ($server) {
|
||||||
|
if (! $server->provider()->isRunning()) {
|
||||||
|
sleep(2);
|
||||||
|
}
|
||||||
|
$server->type()->install();
|
||||||
|
$server->update([
|
||||||
|
'status' => ServerStatus::READY,
|
||||||
|
]);
|
||||||
|
Notifier::send($server, new ServerInstallationSucceed($server));
|
||||||
|
},
|
||||||
|
])->catch(function (Throwable $e) use ($server) {
|
||||||
|
$server->update([
|
||||||
|
'status' => ServerStatus::INSTALLATION_FAILED,
|
||||||
|
]);
|
||||||
|
Notifier::send($server, new ServerInstallationFailed($server));
|
||||||
|
Log::error('server-installation-error', [
|
||||||
|
'error' => (string) $e,
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
if ($server->provider != ServerProvider::CUSTOM) {
|
||||||
|
$server->progress_step = 'waiting-for-provider';
|
||||||
|
$server->save();
|
||||||
|
$bus->delay(now()->addMinutes(3));
|
||||||
|
}
|
||||||
|
|
||||||
|
$bus->onConnection('ssh')->dispatch();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws ValidationException
|
* @throws ValidationException
|
||||||
*/
|
*/
|
||||||
@ -118,7 +150,6 @@ private function validateInputs(array $input): void
|
|||||||
if ($input['provider'] == 'custom') {
|
if ($input['provider'] == 'custom') {
|
||||||
$rules['ip'] = [
|
$rules['ip'] = [
|
||||||
'required',
|
'required',
|
||||||
'ip',
|
|
||||||
new RestrictedIPAddressesRule(),
|
new RestrictedIPAddressesRule(),
|
||||||
];
|
];
|
||||||
$rules['port'] = [
|
$rules['port'] = [
|
||||||
@ -137,7 +168,7 @@ private function validateInputs(array $input): void
|
|||||||
*/
|
*/
|
||||||
private function validateType(Server $server, array $input): void
|
private function validateType(Server $server, array $input): void
|
||||||
{
|
{
|
||||||
Validator::make($input, $server->type()->createValidationRules($input))
|
Validator::make($input, $server->type()->createRules($input))
|
||||||
->validate();
|
->validate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,7 +177,7 @@ private function validateType(Server $server, array $input): void
|
|||||||
*/
|
*/
|
||||||
private function validateProvider(Server $server, array $input): void
|
private function validateProvider(Server $server, array $input): void
|
||||||
{
|
{
|
||||||
Validator::make($input, $server->provider()->createValidationRules($input))
|
Validator::make($input, $server->provider()->createRules($input))
|
||||||
->validate();
|
->validate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
35
app/Actions/Server/CreateServerLog.php
Executable file
35
app/Actions/Server/CreateServerLog.php
Executable file
@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions\Server;
|
||||||
|
|
||||||
|
use App\Models\Server;
|
||||||
|
use Illuminate\Support\Facades\Validator;
|
||||||
|
use Illuminate\Validation\ValidationException;
|
||||||
|
|
||||||
|
class CreateServerLog
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @throws ValidationException
|
||||||
|
*/
|
||||||
|
public function create(Server $server, array $input): void
|
||||||
|
{
|
||||||
|
$this->validate($input);
|
||||||
|
|
||||||
|
$server->logs()->create([
|
||||||
|
'is_remote' => true,
|
||||||
|
'name' => $input['path'],
|
||||||
|
'type' => 'remote',
|
||||||
|
'disk' => 'ssh',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws ValidationException
|
||||||
|
*/
|
||||||
|
protected function validate(array $input): void
|
||||||
|
{
|
||||||
|
Validator::make($input, [
|
||||||
|
'path' => 'required',
|
||||||
|
])->validate();
|
||||||
|
}
|
||||||
|
}
|
@ -35,7 +35,7 @@ public function edit(Server $server, array $input): Server
|
|||||||
$server->save();
|
$server->save();
|
||||||
|
|
||||||
if ($checkConnection) {
|
if ($checkConnection) {
|
||||||
$server->checkConnection();
|
return $server->checkConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $server;
|
return $server;
|
||||||
|
@ -1,14 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Actions\Server;
|
|
||||||
|
|
||||||
use App\Models\Server;
|
|
||||||
use Illuminate\Database\Eloquent\Collection;
|
|
||||||
|
|
||||||
class GetServers
|
|
||||||
{
|
|
||||||
public function handle(): Collection
|
|
||||||
{
|
|
||||||
return Server::query()->latest()->get();
|
|
||||||
}
|
|
||||||
}
|
|
23
app/Actions/Server/RebootServer.php
Normal file
23
app/Actions/Server/RebootServer.php
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions\Server;
|
||||||
|
|
||||||
|
use App\Enums\ServerStatus;
|
||||||
|
use App\Models\Server;
|
||||||
|
use Throwable;
|
||||||
|
|
||||||
|
class RebootServer
|
||||||
|
{
|
||||||
|
public function reboot(Server $server): Server
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$server->os()->reboot();
|
||||||
|
$server->status = ServerStatus::DISCONNECTED;
|
||||||
|
$server->save();
|
||||||
|
} catch (Throwable) {
|
||||||
|
$server = $server->checkConnection();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $server;
|
||||||
|
}
|
||||||
|
}
|
25
app/Actions/Server/Update.php
Normal file
25
app/Actions/Server/Update.php
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions\Server;
|
||||||
|
|
||||||
|
use App\Enums\ServerStatus;
|
||||||
|
use App\Facades\Notifier;
|
||||||
|
use App\Models\Server;
|
||||||
|
use App\Notifications\ServerUpdateFailed;
|
||||||
|
|
||||||
|
class Update
|
||||||
|
{
|
||||||
|
public function update(Server $server): void
|
||||||
|
{
|
||||||
|
$server->status = ServerStatus::UPDATING;
|
||||||
|
$server->save();
|
||||||
|
dispatch(function () use ($server) {
|
||||||
|
$server->os()->upgrade();
|
||||||
|
$server->checkConnection();
|
||||||
|
$server->checkForUpdates();
|
||||||
|
})->catch(function () use ($server) {
|
||||||
|
Notifier::send($server, new ServerUpdateFailed($server));
|
||||||
|
$server->checkConnection();
|
||||||
|
})->onConnection('ssh');
|
||||||
|
}
|
||||||
|
}
|
@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
namespace App\Actions\ServerProvider;
|
namespace App\Actions\ServerProvider;
|
||||||
|
|
||||||
use App\Contracts\ServerProvider as ServerProviderContract;
|
|
||||||
use App\Models\ServerProvider;
|
use App\Models\ServerProvider;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
|
use App\ServerProviders\ServerProvider as ServerProviderContract;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Illuminate\Support\Facades\Validator;
|
use Illuminate\Support\Facades\Validator;
|
||||||
use Illuminate\Validation\Rule;
|
use Illuminate\Validation\Rule;
|
||||||
@ -28,7 +28,7 @@ public function create(User $user, array $input): ServerProvider
|
|||||||
} catch (Exception) {
|
} catch (Exception) {
|
||||||
throw ValidationException::withMessages([
|
throw ValidationException::withMessages([
|
||||||
'provider' => [
|
'provider' => [
|
||||||
__("Couldn't connect to provider. Please check your credentials and try again later."),
|
sprintf("Couldn't connect to %s. Please check your credentials.", $input['provider']),
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
@ -38,6 +38,7 @@ public function create(User $user, array $input): ServerProvider
|
|||||||
$serverProvider->profile = $input['name'];
|
$serverProvider->profile = $input['name'];
|
||||||
$serverProvider->provider = $input['provider'];
|
$serverProvider->provider = $input['provider'];
|
||||||
$serverProvider->credentials = $provider->credentialData($input);
|
$serverProvider->credentials = $provider->credentialData($input);
|
||||||
|
$serverProvider->project_id = isset($input['global']) && $input['global'] ? null : $user->current_project_id;
|
||||||
$serverProvider->save();
|
$serverProvider->save();
|
||||||
|
|
||||||
return $serverProvider;
|
return $serverProvider;
|
||||||
|
21
app/Actions/ServerProvider/DeleteServerProvider.php
Normal file
21
app/Actions/ServerProvider/DeleteServerProvider.php
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions\ServerProvider;
|
||||||
|
|
||||||
|
use App\Models\ServerProvider;
|
||||||
|
use Exception;
|
||||||
|
|
||||||
|
class DeleteServerProvider
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function delete(ServerProvider $serverProvider): void
|
||||||
|
{
|
||||||
|
if ($serverProvider->servers()->exists()) {
|
||||||
|
throw new Exception('This server provider is being used by a server.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$serverProvider->delete();
|
||||||
|
}
|
||||||
|
}
|
34
app/Actions/ServerProvider/EditServerProvider.php
Normal file
34
app/Actions/ServerProvider/EditServerProvider.php
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions\ServerProvider;
|
||||||
|
|
||||||
|
use App\Models\ServerProvider;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Support\Facades\Validator;
|
||||||
|
use Illuminate\Validation\ValidationException;
|
||||||
|
|
||||||
|
class EditServerProvider
|
||||||
|
{
|
||||||
|
public function edit(ServerProvider $serverProvider, User $user, array $input): void
|
||||||
|
{
|
||||||
|
$this->validate($input);
|
||||||
|
|
||||||
|
$serverProvider->profile = $input['name'];
|
||||||
|
$serverProvider->project_id = isset($input['global']) && $input['global'] ? null : $user->current_project_id;
|
||||||
|
|
||||||
|
$serverProvider->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws ValidationException
|
||||||
|
*/
|
||||||
|
private function validate(array $input): void
|
||||||
|
{
|
||||||
|
$rules = [
|
||||||
|
'name' => [
|
||||||
|
'required',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
Validator::make($input, $rules)->validate();
|
||||||
|
}
|
||||||
|
}
|
57
app/Actions/Service/Install.php
Normal file
57
app/Actions/Service/Install.php
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions\Service;
|
||||||
|
|
||||||
|
use App\Enums\ServiceStatus;
|
||||||
|
use App\Models\Server;
|
||||||
|
use App\Models\Service;
|
||||||
|
use Illuminate\Support\Facades\Validator;
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
|
|
||||||
|
class Install
|
||||||
|
{
|
||||||
|
public function install(Server $server, array $input): Service
|
||||||
|
{
|
||||||
|
$this->validate($server, $input);
|
||||||
|
|
||||||
|
$service = new Service([
|
||||||
|
'server_id' => $server->id,
|
||||||
|
'name' => $input['name'],
|
||||||
|
'type' => $input['type'],
|
||||||
|
'version' => $input['version'],
|
||||||
|
'status' => ServiceStatus::INSTALLING,
|
||||||
|
]);
|
||||||
|
|
||||||
|
Validator::make($input, $service->handler()->creationRules($input))->validate();
|
||||||
|
|
||||||
|
$service->type_data = $service->handler()->creationData($input);
|
||||||
|
|
||||||
|
$service->save();
|
||||||
|
|
||||||
|
dispatch(function () use ($service) {
|
||||||
|
$service->handler()->install();
|
||||||
|
$service->status = ServiceStatus::READY;
|
||||||
|
$service->save();
|
||||||
|
})->catch(function () use ($service) {
|
||||||
|
$service->status = ServiceStatus::INSTALLATION_FAILED;
|
||||||
|
$service->save();
|
||||||
|
})->onConnection('ssh');
|
||||||
|
|
||||||
|
return $service;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function validate(Server $server, array $input): void
|
||||||
|
{
|
||||||
|
Validator::make($input, [
|
||||||
|
'type' => [
|
||||||
|
'required',
|
||||||
|
Rule::in(config('core.service_types')),
|
||||||
|
],
|
||||||
|
'name' => [
|
||||||
|
'required',
|
||||||
|
Rule::in(array_keys(config('core.service_types'))),
|
||||||
|
],
|
||||||
|
'version' => 'required',
|
||||||
|
])->validate();
|
||||||
|
}
|
||||||
|
}
|
84
app/Actions/Service/Manage.php
Normal file
84
app/Actions/Service/Manage.php
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions\Service;
|
||||||
|
|
||||||
|
use App\Enums\ServiceStatus;
|
||||||
|
use App\Models\Service;
|
||||||
|
|
||||||
|
class Manage
|
||||||
|
{
|
||||||
|
public function start(Service $service): void
|
||||||
|
{
|
||||||
|
$service->status = ServiceStatus::STARTING;
|
||||||
|
$service->save();
|
||||||
|
dispatch(function () use ($service) {
|
||||||
|
$status = $service->server->systemd()->start($service->unit);
|
||||||
|
if (str($status)->contains('Active: active')) {
|
||||||
|
$service->status = ServiceStatus::READY;
|
||||||
|
} else {
|
||||||
|
$service->status = ServiceStatus::FAILED;
|
||||||
|
}
|
||||||
|
$service->save();
|
||||||
|
})->onConnection('ssh');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function stop(Service $service): void
|
||||||
|
{
|
||||||
|
$service->status = ServiceStatus::STOPPING;
|
||||||
|
$service->save();
|
||||||
|
dispatch(function () use ($service) {
|
||||||
|
$status = $service->server->systemd()->stop($service->unit);
|
||||||
|
if (str($status)->contains('Active: inactive')) {
|
||||||
|
$service->status = ServiceStatus::STOPPED;
|
||||||
|
} else {
|
||||||
|
$service->status = ServiceStatus::FAILED;
|
||||||
|
}
|
||||||
|
$service->save();
|
||||||
|
})->onConnection('ssh');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function restart(Service $service): void
|
||||||
|
{
|
||||||
|
$service->status = ServiceStatus::RESTARTING;
|
||||||
|
$service->save();
|
||||||
|
dispatch(function () use ($service) {
|
||||||
|
$status = $service->server->systemd()->restart($service->unit);
|
||||||
|
if (str($status)->contains('Active: active')) {
|
||||||
|
$service->status = ServiceStatus::READY;
|
||||||
|
} else {
|
||||||
|
$service->status = ServiceStatus::FAILED;
|
||||||
|
}
|
||||||
|
$service->save();
|
||||||
|
})->onConnection('ssh');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function enable(Service $service): void
|
||||||
|
{
|
||||||
|
$service->status = ServiceStatus::ENABLING;
|
||||||
|
$service->save();
|
||||||
|
dispatch(function () use ($service) {
|
||||||
|
$status = $service->server->systemd()->enable($service->unit);
|
||||||
|
if (str($status)->contains('Active: active')) {
|
||||||
|
$service->status = ServiceStatus::READY;
|
||||||
|
} else {
|
||||||
|
$service->status = ServiceStatus::FAILED;
|
||||||
|
}
|
||||||
|
$service->save();
|
||||||
|
})->onConnection('ssh');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function disable(Service $service): void
|
||||||
|
{
|
||||||
|
$service->status = ServiceStatus::DISABLING;
|
||||||
|
$service->save();
|
||||||
|
dispatch(function () use ($service) {
|
||||||
|
$status = $service->server->systemd()->disable($service->unit);
|
||||||
|
if (str($status)->contains('Active: inactive')) {
|
||||||
|
$service->status = ServiceStatus::DISABLED;
|
||||||
|
} else {
|
||||||
|
$service->status = ServiceStatus::FAILED;
|
||||||
|
}
|
||||||
|
$service->save();
|
||||||
|
})->onConnection('ssh');
|
||||||
|
}
|
||||||
|
}
|
28
app/Actions/Service/Uninstall.php
Normal file
28
app/Actions/Service/Uninstall.php
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions\Service;
|
||||||
|
|
||||||
|
use App\Enums\ServiceStatus;
|
||||||
|
use App\Models\Service;
|
||||||
|
use Illuminate\Support\Facades\Validator;
|
||||||
|
|
||||||
|
class Uninstall
|
||||||
|
{
|
||||||
|
public function uninstall(Service $service): void
|
||||||
|
{
|
||||||
|
Validator::make([
|
||||||
|
'service' => $service->id,
|
||||||
|
], $service->handler()->deletionRules())->validate();
|
||||||
|
|
||||||
|
$service->status = ServiceStatus::UNINSTALLING;
|
||||||
|
$service->save();
|
||||||
|
|
||||||
|
dispatch(function () use ($service) {
|
||||||
|
$service->handler()->uninstall();
|
||||||
|
$service->delete();
|
||||||
|
})->catch(function () use ($service) {
|
||||||
|
$service->status = ServiceStatus::FAILED;
|
||||||
|
$service->save();
|
||||||
|
})->onConnection('ssh');
|
||||||
|
}
|
||||||
|
}
|
@ -1,30 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Actions\Site;
|
|
||||||
|
|
||||||
use App\Models\Site;
|
|
||||||
use Illuminate\Support\Facades\Validator;
|
|
||||||
use Illuminate\Validation\ValidationException;
|
|
||||||
|
|
||||||
class ChangePHPVersion
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @throws ValidationException
|
|
||||||
*/
|
|
||||||
public function handle(Site $site, array $input): void
|
|
||||||
{
|
|
||||||
$this->validate($site, $input);
|
|
||||||
|
|
||||||
$site->changePHPVersion($input['php_version']);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws ValidationException
|
|
||||||
*/
|
|
||||||
protected function validate(Site $site, array $input): void
|
|
||||||
{
|
|
||||||
Validator::make($input, [
|
|
||||||
'php_version' => 'required|in:'.implode(',', $site->server->installedPHPVersions()),
|
|
||||||
])->validateWithBag('changePHPVersion');
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,51 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Actions\Site;
|
|
||||||
|
|
||||||
use App\Models\Redirect;
|
|
||||||
use App\Models\Site;
|
|
||||||
use Exception;
|
|
||||||
use Illuminate\Support\Facades\Validator;
|
|
||||||
use Illuminate\Validation\ValidationException;
|
|
||||||
|
|
||||||
class CreateRedirect
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public function handle(Site $site, array $input): void
|
|
||||||
{
|
|
||||||
$this->validate($input);
|
|
||||||
|
|
||||||
$redirect = new Redirect([
|
|
||||||
'site_id' => $site->id,
|
|
||||||
'mode' => $input['mode'],
|
|
||||||
'from' => $input['from'],
|
|
||||||
'to' => $input['to'],
|
|
||||||
]);
|
|
||||||
$redirect->save();
|
|
||||||
$redirect->addToServer();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws ValidationException
|
|
||||||
*/
|
|
||||||
private function validate(array $input): void
|
|
||||||
{
|
|
||||||
$rules = [
|
|
||||||
'mode' => [
|
|
||||||
'required',
|
|
||||||
'in:301,302',
|
|
||||||
],
|
|
||||||
'from' => [
|
|
||||||
'required',
|
|
||||||
],
|
|
||||||
'to' => [
|
|
||||||
'required',
|
|
||||||
'url',
|
|
||||||
],
|
|
||||||
];
|
|
||||||
|
|
||||||
Validator::make($input, $rules)->validateWithBag('createRedirect');
|
|
||||||
}
|
|
||||||
}
|
|
@ -3,9 +3,14 @@
|
|||||||
namespace App\Actions\Site;
|
namespace App\Actions\Site;
|
||||||
|
|
||||||
use App\Enums\SiteStatus;
|
use App\Enums\SiteStatus;
|
||||||
|
use App\Exceptions\RepositoryNotFound;
|
||||||
|
use App\Exceptions\RepositoryPermissionDenied;
|
||||||
use App\Exceptions\SourceControlIsNotConnected;
|
use App\Exceptions\SourceControlIsNotConnected;
|
||||||
|
use App\Facades\Notifier;
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
use App\Models\Site;
|
use App\Models\Site;
|
||||||
|
use App\Notifications\SiteInstallationFailed;
|
||||||
|
use App\Notifications\SiteInstallationSucceed;
|
||||||
use App\ValidationRules\DomainRule;
|
use App\ValidationRules\DomainRule;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
@ -17,25 +22,23 @@ class CreateSite
|
|||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @throws SourceControlIsNotConnected
|
* @throws SourceControlIsNotConnected
|
||||||
* @throws ValidationException
|
|
||||||
*/
|
*/
|
||||||
public function create(Server $server, array $input): Site
|
public function create(Server $server, array $input): Site
|
||||||
{
|
{
|
||||||
$this->validateInputs($server, $input);
|
$this->validateInputs($server, $input);
|
||||||
|
|
||||||
|
DB::beginTransaction();
|
||||||
try {
|
try {
|
||||||
DB::beginTransaction();
|
|
||||||
|
|
||||||
$site = new Site([
|
$site = new Site([
|
||||||
'server_id' => $server->id,
|
'server_id' => $server->id,
|
||||||
'type' => $input['type'],
|
'type' => $input['type'],
|
||||||
'domain' => $input['domain'],
|
'domain' => $input['domain'],
|
||||||
'aliases' => isset($input['alias']) ? [$input['alias']] : [],
|
'aliases' => $input['aliases'] ?? [],
|
||||||
'path' => '/home/'.$server->ssh_user.'/'.$input['domain'],
|
'path' => '/home/'.$server->getSshUser().'/'.$input['domain'],
|
||||||
'status' => SiteStatus::INSTALLING,
|
'status' => SiteStatus::INSTALLING,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// fields based on type
|
// fields based on the type
|
||||||
$site->fill($site->type()->createFields($input));
|
$site->fill($site->type()->createFields($input));
|
||||||
|
|
||||||
// check has access to repository
|
// check has access to repository
|
||||||
@ -45,13 +48,16 @@ public function create(Server $server, array $input): Site
|
|||||||
}
|
}
|
||||||
} catch (SourceControlIsNotConnected) {
|
} catch (SourceControlIsNotConnected) {
|
||||||
throw ValidationException::withMessages([
|
throw ValidationException::withMessages([
|
||||||
'source_control' => __('Source control is not connected'),
|
'source_control' => 'Source control is not connected',
|
||||||
|
]);
|
||||||
|
} catch (RepositoryPermissionDenied) {
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'repository' => 'You do not have permission to access this repository',
|
||||||
|
]);
|
||||||
|
} catch (RepositoryNotFound) {
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'repository' => 'Repository not found',
|
||||||
]);
|
]);
|
||||||
}
|
|
||||||
|
|
||||||
// detect php version
|
|
||||||
if ($site->type()->language() === 'php') {
|
|
||||||
$site->php_version = $input['php_version'];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// validate type
|
// validate type
|
||||||
@ -69,8 +75,19 @@ public function create(Server $server, array $input): Site
|
|||||||
'content' => '',
|
'content' => '',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// install server
|
// install site
|
||||||
$site->install();
|
dispatch(function () use ($site) {
|
||||||
|
$site->type()->install();
|
||||||
|
$site->update([
|
||||||
|
'status' => SiteStatus::READY,
|
||||||
|
'progress' => 100,
|
||||||
|
]);
|
||||||
|
Notifier::send($site, new SiteInstallationSucceed($site));
|
||||||
|
})->catch(function () use ($site) {
|
||||||
|
$site->status = SiteStatus::INSTALLATION_FAILED;
|
||||||
|
$site->save();
|
||||||
|
Notifier::send($site, new SiteInstallationFailed($site));
|
||||||
|
})->onConnection('ssh');
|
||||||
|
|
||||||
DB::commit();
|
DB::commit();
|
||||||
|
|
||||||
@ -98,7 +115,7 @@ private function validateInputs(Server $server, array $input): void
|
|||||||
return $query->where('server_id', $server->id);
|
return $query->where('server_id', $server->id);
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
'alias' => [
|
'aliases.*' => [
|
||||||
new DomainRule(),
|
new DomainRule(),
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
@ -111,7 +128,7 @@ private function validateInputs(Server $server, array $input): void
|
|||||||
*/
|
*/
|
||||||
private function validateType(Site $site, array $input): void
|
private function validateType(Site $site, array $input): void
|
||||||
{
|
{
|
||||||
$rules = $site->type()->createValidationRules($input);
|
$rules = $site->type()->createRules($input);
|
||||||
|
|
||||||
Validator::make($input, $rules)->validate();
|
Validator::make($input, $rules)->validate();
|
||||||
}
|
}
|
||||||
|
14
app/Actions/Site/DeleteSite.php
Normal file
14
app/Actions/Site/DeleteSite.php
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions\Site;
|
||||||
|
|
||||||
|
use App\Models\Site;
|
||||||
|
|
||||||
|
class DeleteSite
|
||||||
|
{
|
||||||
|
public function delete(Site $site): void
|
||||||
|
{
|
||||||
|
$site->server->webserver()->handler()->deleteSite($site);
|
||||||
|
$site->delete();
|
||||||
|
}
|
||||||
|
}
|
62
app/Actions/Site/Deploy.php
Normal file
62
app/Actions/Site/Deploy.php
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions\Site;
|
||||||
|
|
||||||
|
use App\Enums\DeploymentStatus;
|
||||||
|
use App\Exceptions\DeploymentScriptIsEmptyException;
|
||||||
|
use App\Exceptions\SourceControlIsNotConnected;
|
||||||
|
use App\Models\Deployment;
|
||||||
|
use App\Models\ServerLog;
|
||||||
|
use App\Models\Site;
|
||||||
|
|
||||||
|
class Deploy
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @throws SourceControlIsNotConnected
|
||||||
|
* @throws DeploymentScriptIsEmptyException
|
||||||
|
*/
|
||||||
|
public function run(Site $site): Deployment
|
||||||
|
{
|
||||||
|
if ($site->sourceControl()) {
|
||||||
|
$site->sourceControl()->getRepo($site->repository);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $site->deploymentScript?->content) {
|
||||||
|
throw new DeploymentScriptIsEmptyException();
|
||||||
|
}
|
||||||
|
|
||||||
|
$deployment = new Deployment([
|
||||||
|
'site_id' => $site->id,
|
||||||
|
'deployment_script_id' => $site->deploymentScript->id,
|
||||||
|
'status' => DeploymentStatus::DEPLOYING,
|
||||||
|
]);
|
||||||
|
$lastCommit = $site->sourceControl()?->provider()?->getLastCommit($site->repository, $site->branch);
|
||||||
|
if ($lastCommit) {
|
||||||
|
$deployment->commit_id = $lastCommit['commit_id'];
|
||||||
|
$deployment->commit_data = $lastCommit['commit_data'];
|
||||||
|
}
|
||||||
|
$deployment->save();
|
||||||
|
|
||||||
|
dispatch(function () use ($site, $deployment) {
|
||||||
|
/** @var ServerLog $log */
|
||||||
|
$log = ServerLog::make($site->server, 'deploy-'.strtotime('now'))
|
||||||
|
->forSite($site);
|
||||||
|
$log->save();
|
||||||
|
$deployment->log_id = $log->id;
|
||||||
|
$deployment->save();
|
||||||
|
$site->server->os()->runScript(
|
||||||
|
path: $site->path,
|
||||||
|
script: $site->deploymentScript->content,
|
||||||
|
serverLog: $log,
|
||||||
|
variables: $site->environmentVariables($deployment)
|
||||||
|
);
|
||||||
|
$deployment->status = DeploymentStatus::FINISHED;
|
||||||
|
$deployment->save();
|
||||||
|
})->catch(function () use ($deployment) {
|
||||||
|
$deployment->status = DeploymentStatus::FAILED;
|
||||||
|
$deployment->save();
|
||||||
|
})->onConnection('ssh');
|
||||||
|
|
||||||
|
return $deployment;
|
||||||
|
}
|
||||||
|
}
|
@ -1,41 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Actions\Site;
|
|
||||||
|
|
||||||
use App\Models\Site;
|
|
||||||
use Illuminate\Support\Facades\Validator;
|
|
||||||
use Illuminate\Validation\ValidationException;
|
|
||||||
|
|
||||||
class EditSite
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @throws ValidationException
|
|
||||||
*/
|
|
||||||
public function handle(Site $site, array $input): Site
|
|
||||||
{
|
|
||||||
// validate type
|
|
||||||
$this->validateType($site, $input);
|
|
||||||
|
|
||||||
// set type data
|
|
||||||
$site->type_data = $site->type()->data($input);
|
|
||||||
|
|
||||||
// save
|
|
||||||
$site->port = $input['port'] ?? null;
|
|
||||||
$site->save();
|
|
||||||
|
|
||||||
// edit
|
|
||||||
$site->type()->edit();
|
|
||||||
|
|
||||||
return $site;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws ValidationException
|
|
||||||
*/
|
|
||||||
private function validateType(Site $site, array $input): void
|
|
||||||
{
|
|
||||||
$rules = $site->type()->editValidationRules($input);
|
|
||||||
|
|
||||||
Validator::make($input, $rules)->validateWithBag('editSite');
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,14 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Actions\Site;
|
|
||||||
|
|
||||||
use App\Models\Server;
|
|
||||||
use Illuminate\Database\Eloquent\Collection;
|
|
||||||
|
|
||||||
class GetSites
|
|
||||||
{
|
|
||||||
public function handle(Server $server): Collection
|
|
||||||
{
|
|
||||||
return $server->sites()->orderBy('id', 'desc')->get();
|
|
||||||
}
|
|
||||||
}
|
|
33
app/Actions/Site/UpdateAliases.php
Normal file
33
app/Actions/Site/UpdateAliases.php
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions\Site;
|
||||||
|
|
||||||
|
use App\Models\Site;
|
||||||
|
use App\SSH\Services\Webserver\Webserver;
|
||||||
|
use App\ValidationRules\DomainRule;
|
||||||
|
use Illuminate\Support\Facades\Validator;
|
||||||
|
|
||||||
|
class UpdateAliases
|
||||||
|
{
|
||||||
|
public function update(Site $site, array $input): void
|
||||||
|
{
|
||||||
|
$this->validate($input);
|
||||||
|
|
||||||
|
$site->aliases = $input['aliases'] ?? [];
|
||||||
|
|
||||||
|
/** @var Webserver $webserver */
|
||||||
|
$webserver = $site->server->webserver()->handler();
|
||||||
|
$webserver->updateVHost($site, ! $site->hasSSL());
|
||||||
|
|
||||||
|
$site->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function validate(array $input): void
|
||||||
|
{
|
||||||
|
Validator::make($input, [
|
||||||
|
'aliases.*' => [
|
||||||
|
new DomainRule(),
|
||||||
|
],
|
||||||
|
])->validate();
|
||||||
|
}
|
||||||
|
}
|
@ -3,6 +3,7 @@
|
|||||||
namespace App\Actions\Site;
|
namespace App\Actions\Site;
|
||||||
|
|
||||||
use App\Models\Site;
|
use App\Models\Site;
|
||||||
|
use App\SSH\Git\Git;
|
||||||
use Illuminate\Support\Facades\Validator;
|
use Illuminate\Support\Facades\Validator;
|
||||||
use Illuminate\Validation\ValidationException;
|
use Illuminate\Validation\ValidationException;
|
||||||
|
|
||||||
@ -14,8 +15,9 @@ class UpdateBranch
|
|||||||
public function update(Site $site, array $input): void
|
public function update(Site $site, array $input): void
|
||||||
{
|
{
|
||||||
$this->validate($input);
|
$this->validate($input);
|
||||||
|
$site->branch = $input['branch'];
|
||||||
$site->updateBranch($input['branch']);
|
app(Git::class)->checkout($site);
|
||||||
|
$site->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -25,6 +27,6 @@ protected function validate(array $input): void
|
|||||||
{
|
{
|
||||||
Validator::make($input, [
|
Validator::make($input, [
|
||||||
'branch' => 'required',
|
'branch' => 'required',
|
||||||
])->validateWithBag('updateBranch');
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,6 @@ protected function validate(array $input): void
|
|||||||
{
|
{
|
||||||
Validator::make($input, [
|
Validator::make($input, [
|
||||||
'script' => 'required',
|
'script' => 'required',
|
||||||
])->validateWithBag('updateDeploymentScript');
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
14
app/Actions/Site/UpdateEnv.php
Executable file → Normal file
14
app/Actions/Site/UpdateEnv.php
Executable file → Normal file
@ -2,17 +2,19 @@
|
|||||||
|
|
||||||
namespace App\Actions\Site;
|
namespace App\Actions\Site;
|
||||||
|
|
||||||
|
use App\Exceptions\SSHUploadFailed;
|
||||||
use App\Models\Site;
|
use App\Models\Site;
|
||||||
|
|
||||||
class UpdateEnv
|
class UpdateEnv
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @throws SSHUploadFailed
|
||||||
|
*/
|
||||||
public function update(Site $site, array $input): void
|
public function update(Site $site, array $input): void
|
||||||
{
|
{
|
||||||
$typeData = $site->type_data;
|
$site->server->os()->editFile(
|
||||||
$typeData['env'] = $input['env'];
|
$site->path.'/.env',
|
||||||
$site->type_data = $typeData;
|
$input['env']
|
||||||
$site->save();
|
);
|
||||||
|
|
||||||
$site->deployEnv();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
49
app/Actions/Site/UpdateSourceControl.php
Normal file
49
app/Actions/Site/UpdateSourceControl.php
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions\Site;
|
||||||
|
|
||||||
|
use App\Exceptions\RepositoryNotFound;
|
||||||
|
use App\Exceptions\RepositoryPermissionDenied;
|
||||||
|
use App\Exceptions\SourceControlIsNotConnected;
|
||||||
|
use App\Models\Site;
|
||||||
|
use Illuminate\Support\Facades\Validator;
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
|
use Illuminate\Validation\ValidationException;
|
||||||
|
|
||||||
|
class UpdateSourceControl
|
||||||
|
{
|
||||||
|
public function update(Site $site, array $input): void
|
||||||
|
{
|
||||||
|
$this->validate($input);
|
||||||
|
|
||||||
|
$site->source_control_id = $input['source_control'];
|
||||||
|
try {
|
||||||
|
if ($site->sourceControl()) {
|
||||||
|
$site->sourceControl()->getRepo($site->repository);
|
||||||
|
}
|
||||||
|
} catch (SourceControlIsNotConnected) {
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'source_control' => 'Source control is not connected',
|
||||||
|
]);
|
||||||
|
} catch (RepositoryPermissionDenied) {
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'repository' => 'You do not have permission to access this repository',
|
||||||
|
]);
|
||||||
|
} catch (RepositoryNotFound) {
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'repository' => 'Repository not found',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
$site->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function validate(array $input): void
|
||||||
|
{
|
||||||
|
Validator::make($input, [
|
||||||
|
'source_control' => [
|
||||||
|
'required',
|
||||||
|
Rule::exists('source_controls', 'id'),
|
||||||
|
],
|
||||||
|
])->validate();
|
||||||
|
}
|
||||||
|
}
|
@ -3,21 +3,29 @@
|
|||||||
namespace App\Actions\SourceControl;
|
namespace App\Actions\SourceControl;
|
||||||
|
|
||||||
use App\Models\SourceControl;
|
use App\Models\SourceControl;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Support\Arr;
|
||||||
use Illuminate\Support\Facades\Validator;
|
use Illuminate\Support\Facades\Validator;
|
||||||
use Illuminate\Validation\Rule;
|
use Illuminate\Validation\Rule;
|
||||||
use Illuminate\Validation\ValidationException;
|
use Illuminate\Validation\ValidationException;
|
||||||
|
|
||||||
class ConnectSourceControl
|
class ConnectSourceControl
|
||||||
{
|
{
|
||||||
public function connect(array $input): void
|
public function connect(User $user, array $input): void
|
||||||
{
|
{
|
||||||
$this->validate($input);
|
$this->validate($input);
|
||||||
|
|
||||||
$sourceControl = new SourceControl([
|
$sourceControl = new SourceControl([
|
||||||
'provider' => $input['provider'],
|
'provider' => $input['provider'],
|
||||||
'profile' => $input['name'],
|
'profile' => $input['name'],
|
||||||
'access_token' => $input['token'],
|
'url' => Arr::has($input, 'url') ? $input['url'] : null,
|
||||||
|
'project_id' => isset($input['global']) && $input['global'] ? null : $user->current_project_id,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
$this->validateProvider($sourceControl, $input);
|
||||||
|
|
||||||
|
$sourceControl->provider_data = $sourceControl->provider()->createData($input);
|
||||||
|
|
||||||
if (! $sourceControl->provider()->connect()) {
|
if (! $sourceControl->provider()->connect()) {
|
||||||
throw ValidationException::withMessages([
|
throw ValidationException::withMessages([
|
||||||
'token' => __('Cannot connect to :provider or invalid token!', ['provider' => $sourceControl->provider]
|
'token' => __('Cannot connect to :provider or invalid token!', ['provider' => $sourceControl->provider]
|
||||||
@ -36,15 +44,20 @@ private function validate(array $input): void
|
|||||||
$rules = [
|
$rules = [
|
||||||
'provider' => [
|
'provider' => [
|
||||||
'required',
|
'required',
|
||||||
Rule::in(\App\Enums\SourceControl::getValues()),
|
Rule::in(config('core.source_control_providers')),
|
||||||
],
|
],
|
||||||
'name' => [
|
'name' => [
|
||||||
'required',
|
'required',
|
||||||
],
|
],
|
||||||
'token' => [
|
|
||||||
'required',
|
|
||||||
],
|
|
||||||
];
|
];
|
||||||
Validator::make($input, $rules)->validate();
|
Validator::make($input, $rules)->validate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws ValidationException
|
||||||
|
*/
|
||||||
|
private function validateProvider(SourceControl $sourceControl, array $input): void
|
||||||
|
{
|
||||||
|
Validator::make($input, $sourceControl->provider()->createRules($input))->validate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
17
app/Actions/SourceControl/DeleteSourceControl.php
Normal file
17
app/Actions/SourceControl/DeleteSourceControl.php
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions\SourceControl;
|
||||||
|
|
||||||
|
use App\Models\SourceControl;
|
||||||
|
|
||||||
|
class DeleteSourceControl
|
||||||
|
{
|
||||||
|
public function delete(SourceControl $sourceControl): void
|
||||||
|
{
|
||||||
|
if ($sourceControl->sites()->exists()) {
|
||||||
|
throw new \Exception('This source control is being used by a site.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$sourceControl->delete();
|
||||||
|
}
|
||||||
|
}
|
54
app/Actions/SourceControl/EditSourceControl.php
Normal file
54
app/Actions/SourceControl/EditSourceControl.php
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions\SourceControl;
|
||||||
|
|
||||||
|
use App\Models\SourceControl;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Support\Facades\Validator;
|
||||||
|
use Illuminate\Validation\ValidationException;
|
||||||
|
|
||||||
|
class EditSourceControl
|
||||||
|
{
|
||||||
|
public function edit(SourceControl $sourceControl, User $user, array $input): void
|
||||||
|
{
|
||||||
|
$this->validate($input);
|
||||||
|
|
||||||
|
$sourceControl->profile = $input['name'];
|
||||||
|
$sourceControl->url = $input['url'] ?? null;
|
||||||
|
$sourceControl->project_id = isset($input['global']) && $input['global'] ? null : $user->current_project_id;
|
||||||
|
|
||||||
|
$this->validateProvider($sourceControl, $input);
|
||||||
|
|
||||||
|
$sourceControl->provider_data = $sourceControl->provider()->createData($input);
|
||||||
|
|
||||||
|
if (! $sourceControl->provider()->connect()) {
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'token' => __('Cannot connect to :provider or invalid token!', ['provider' => $sourceControl->provider]
|
||||||
|
),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$sourceControl->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws ValidationException
|
||||||
|
*/
|
||||||
|
private function validate(array $input): void
|
||||||
|
{
|
||||||
|
$rules = [
|
||||||
|
'name' => [
|
||||||
|
'required',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
Validator::make($input, $rules)->validate();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws ValidationException
|
||||||
|
*/
|
||||||
|
private function validateProvider(SourceControl $sourceControl, array $input): void
|
||||||
|
{
|
||||||
|
Validator::make($input, $sourceControl->provider()->createRules($input))->validate();
|
||||||
|
}
|
||||||
|
}
|
19
app/Actions/SshKey/DeleteKeyFromServer.php
Normal file
19
app/Actions/SshKey/DeleteKeyFromServer.php
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions\SshKey;
|
||||||
|
|
||||||
|
use App\Enums\SshKeyStatus;
|
||||||
|
use App\Models\Server;
|
||||||
|
use App\Models\SshKey;
|
||||||
|
|
||||||
|
class DeleteKeyFromServer
|
||||||
|
{
|
||||||
|
public function delete(Server $server, SshKey $sshKey): void
|
||||||
|
{
|
||||||
|
$sshKey->servers()->updateExistingPivot($server->id, [
|
||||||
|
'status' => SshKeyStatus::DELETING,
|
||||||
|
]);
|
||||||
|
$server->os()->deleteSSHKey($sshKey->public_key);
|
||||||
|
$server->sshKeys()->detach($sshKey);
|
||||||
|
}
|
||||||
|
}
|
38
app/Actions/SshKey/DeployKeyToServer.php
Normal file
38
app/Actions/SshKey/DeployKeyToServer.php
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions\SshKey;
|
||||||
|
|
||||||
|
use App\Enums\SshKeyStatus;
|
||||||
|
use App\Models\Server;
|
||||||
|
use App\Models\SshKey;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Support\Facades\Validator;
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
|
|
||||||
|
class DeployKeyToServer
|
||||||
|
{
|
||||||
|
public function deploy(User $user, Server $server, array $input): void
|
||||||
|
{
|
||||||
|
$this->validate($user, $input);
|
||||||
|
|
||||||
|
/** @var SshKey $sshKey */
|
||||||
|
$sshKey = SshKey::findOrFail($input['key_id']);
|
||||||
|
$server->sshKeys()->attach($sshKey, [
|
||||||
|
'status' => SshKeyStatus::ADDING,
|
||||||
|
]);
|
||||||
|
$server->os()->deploySSHKey($sshKey->public_key);
|
||||||
|
$sshKey->servers()->updateExistingPivot($server->id, [
|
||||||
|
'status' => SshKeyStatus::ADDED,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function validate(User $user, array $input): void
|
||||||
|
{
|
||||||
|
Validator::make($input, [
|
||||||
|
'key_id' => [
|
||||||
|
'required',
|
||||||
|
Rule::exists('ssh_keys', 'id')->where('user_id', $user->id),
|
||||||
|
],
|
||||||
|
])->validate();
|
||||||
|
}
|
||||||
|
}
|
@ -21,15 +21,25 @@ public function create(User $user, array $input): void
|
|||||||
'user_id' => $user->id,
|
'user_id' => $user->id,
|
||||||
'provider' => $input['provider'],
|
'provider' => $input['provider'],
|
||||||
'profile' => $input['name'],
|
'profile' => $input['name'],
|
||||||
'credentials' => [
|
'project_id' => isset($input['global']) && $input['global'] ? null : $user->current_project_id,
|
||||||
'token' => $input['token'],
|
|
||||||
],
|
|
||||||
]);
|
]);
|
||||||
if (! $storageProvider->provider()->connect()) {
|
|
||||||
|
$this->validateProvider($input, $storageProvider->provider()->validationRules());
|
||||||
|
|
||||||
|
$storageProvider->credentials = $storageProvider->provider()->credentialData($input);
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (! $storageProvider->provider()->connect()) {
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'provider' => __("Couldn't connect to the provider"),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
} catch (\Throwable $e) {
|
||||||
throw ValidationException::withMessages([
|
throw ValidationException::withMessages([
|
||||||
'token' => __("Couldn't connect to the provider"),
|
'provider' => $e->getMessage(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$storageProvider->save();
|
$storageProvider->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,9 +54,11 @@ private function validate(User $user, array $input): void
|
|||||||
'required',
|
'required',
|
||||||
Rule::unique('storage_providers', 'profile')->where('user_id', $user->id),
|
Rule::unique('storage_providers', 'profile')->where('user_id', $user->id),
|
||||||
],
|
],
|
||||||
'token' => [
|
|
||||||
'required',
|
|
||||||
],
|
|
||||||
])->validate();
|
])->validate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function validateProvider(array $input, array $rules): void
|
||||||
|
{
|
||||||
|
Validator::make($input, $rules)->validate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
21
app/Actions/StorageProvider/DeleteStorageProvider.php
Normal file
21
app/Actions/StorageProvider/DeleteStorageProvider.php
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions\StorageProvider;
|
||||||
|
|
||||||
|
use App\Models\StorageProvider;
|
||||||
|
use Exception;
|
||||||
|
|
||||||
|
class DeleteStorageProvider
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function delete(StorageProvider $storageProvider): void
|
||||||
|
{
|
||||||
|
if ($storageProvider->backups()->exists()) {
|
||||||
|
throw new Exception('This storage provider is being used by a backup.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$storageProvider->delete();
|
||||||
|
}
|
||||||
|
}
|
34
app/Actions/StorageProvider/EditStorageProvider.php
Normal file
34
app/Actions/StorageProvider/EditStorageProvider.php
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions\StorageProvider;
|
||||||
|
|
||||||
|
use App\Models\StorageProvider;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Support\Facades\Validator;
|
||||||
|
use Illuminate\Validation\ValidationException;
|
||||||
|
|
||||||
|
class EditStorageProvider
|
||||||
|
{
|
||||||
|
public function edit(StorageProvider $storageProvider, User $user, array $input): void
|
||||||
|
{
|
||||||
|
$this->validate($input);
|
||||||
|
|
||||||
|
$storageProvider->profile = $input['name'];
|
||||||
|
$storageProvider->project_id = isset($input['global']) && $input['global'] ? null : $user->current_project_id;
|
||||||
|
|
||||||
|
$storageProvider->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws ValidationException
|
||||||
|
*/
|
||||||
|
private function validate(array $input): void
|
||||||
|
{
|
||||||
|
$rules = [
|
||||||
|
'name' => [
|
||||||
|
'required',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
Validator::make($input, $rules)->validate();
|
||||||
|
}
|
||||||
|
}
|
58
app/Actions/Tag/AttachTag.php
Normal file
58
app/Actions/Tag/AttachTag.php
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions\Tag;
|
||||||
|
|
||||||
|
use App\Models\Server;
|
||||||
|
use App\Models\Site;
|
||||||
|
use App\Models\Tag;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Support\Facades\Validator;
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
|
|
||||||
|
class AttachTag
|
||||||
|
{
|
||||||
|
public function attach(User $user, array $input): Tag
|
||||||
|
{
|
||||||
|
$this->validate($input);
|
||||||
|
|
||||||
|
/** @var Server|Site $taggable */
|
||||||
|
$taggable = $input['taggable_type']::findOrFail($input['taggable_id']);
|
||||||
|
|
||||||
|
$tag = Tag::query()->where('name', $input['name'])->first();
|
||||||
|
if ($tag) {
|
||||||
|
if (! $taggable->tags->contains($tag->id)) {
|
||||||
|
$taggable->tags()->attach($tag->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $tag;
|
||||||
|
}
|
||||||
|
|
||||||
|
$tag = new Tag([
|
||||||
|
'project_id' => $user->currentProject->id,
|
||||||
|
'name' => $input['name'],
|
||||||
|
'color' => config('core.tag_colors')[array_rand(config('core.tag_colors'))],
|
||||||
|
]);
|
||||||
|
$tag->save();
|
||||||
|
|
||||||
|
$taggable->tags()->attach($tag->id);
|
||||||
|
|
||||||
|
return $tag;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function validate(array $input): void
|
||||||
|
{
|
||||||
|
Validator::make($input, [
|
||||||
|
'name' => [
|
||||||
|
'required',
|
||||||
|
],
|
||||||
|
'taggable_id' => [
|
||||||
|
'required',
|
||||||
|
'integer',
|
||||||
|
],
|
||||||
|
'taggable_type' => [
|
||||||
|
'required',
|
||||||
|
Rule::in(config('core.taggable_types')),
|
||||||
|
],
|
||||||
|
])->validate();
|
||||||
|
}
|
||||||
|
}
|
49
app/Actions/Tag/CreateTag.php
Normal file
49
app/Actions/Tag/CreateTag.php
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions\Tag;
|
||||||
|
|
||||||
|
use App\Models\Tag;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Support\Facades\Validator;
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
|
use Illuminate\Validation\ValidationException;
|
||||||
|
|
||||||
|
class CreateTag
|
||||||
|
{
|
||||||
|
public function create(User $user, array $input): Tag
|
||||||
|
{
|
||||||
|
$this->validate($input);
|
||||||
|
|
||||||
|
$tag = Tag::query()
|
||||||
|
->where('project_id', $user->current_project_id)
|
||||||
|
->where('name', $input['name'])
|
||||||
|
->first();
|
||||||
|
if ($tag) {
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'name' => ['Tag with this name already exists.'],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$tag = new Tag([
|
||||||
|
'project_id' => $user->currentProject->id,
|
||||||
|
'name' => $input['name'],
|
||||||
|
'color' => $input['color'],
|
||||||
|
]);
|
||||||
|
$tag->save();
|
||||||
|
|
||||||
|
return $tag;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function validate(array $input): void
|
||||||
|
{
|
||||||
|
Validator::make($input, [
|
||||||
|
'name' => [
|
||||||
|
'required',
|
||||||
|
],
|
||||||
|
'color' => [
|
||||||
|
'required',
|
||||||
|
Rule::in(config('core.tag_colors')),
|
||||||
|
],
|
||||||
|
])->validate();
|
||||||
|
}
|
||||||
|
}
|
15
app/Actions/Tag/DeleteTag.php
Normal file
15
app/Actions/Tag/DeleteTag.php
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions\Tag;
|
||||||
|
|
||||||
|
use App\Models\Tag;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class DeleteTag
|
||||||
|
{
|
||||||
|
public function delete(Tag $tag): void
|
||||||
|
{
|
||||||
|
DB::table('taggables')->where('tag_id', $tag->id)->delete();
|
||||||
|
$tag->delete();
|
||||||
|
}
|
||||||
|
}
|
36
app/Actions/Tag/DetachTag.php
Normal file
36
app/Actions/Tag/DetachTag.php
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions\Tag;
|
||||||
|
|
||||||
|
use App\Models\Server;
|
||||||
|
use App\Models\Site;
|
||||||
|
use App\Models\Tag;
|
||||||
|
use Illuminate\Support\Facades\Validator;
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
|
|
||||||
|
class DetachTag
|
||||||
|
{
|
||||||
|
public function detach(Tag $tag, array $input): void
|
||||||
|
{
|
||||||
|
$this->validate($input);
|
||||||
|
|
||||||
|
/** @var Server|Site $taggable */
|
||||||
|
$taggable = $input['taggable_type']::findOrFail($input['taggable_id']);
|
||||||
|
|
||||||
|
$taggable->tags()->detach($tag->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function validate(array $input): void
|
||||||
|
{
|
||||||
|
Validator::make($input, [
|
||||||
|
'taggable_id' => [
|
||||||
|
'required',
|
||||||
|
'integer',
|
||||||
|
],
|
||||||
|
'taggable_type' => [
|
||||||
|
'required',
|
||||||
|
Rule::in(config('core.taggable_types')),
|
||||||
|
],
|
||||||
|
])->validate();
|
||||||
|
}
|
||||||
|
}
|
38
app/Actions/Tag/EditTag.php
Normal file
38
app/Actions/Tag/EditTag.php
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions\Tag;
|
||||||
|
|
||||||
|
use App\Models\Tag;
|
||||||
|
use Illuminate\Support\Facades\Validator;
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
|
use Illuminate\Validation\ValidationException;
|
||||||
|
|
||||||
|
class EditTag
|
||||||
|
{
|
||||||
|
public function edit(Tag $tag, array $input): void
|
||||||
|
{
|
||||||
|
$this->validate($input);
|
||||||
|
|
||||||
|
$tag->name = $input['name'];
|
||||||
|
$tag->color = $input['color'];
|
||||||
|
|
||||||
|
$tag->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws ValidationException
|
||||||
|
*/
|
||||||
|
private function validate(array $input): void
|
||||||
|
{
|
||||||
|
$rules = [
|
||||||
|
'name' => [
|
||||||
|
'required',
|
||||||
|
],
|
||||||
|
'color' => [
|
||||||
|
'required',
|
||||||
|
Rule::in(config('core.tag_colors')),
|
||||||
|
],
|
||||||
|
];
|
||||||
|
Validator::make($input, $rules)->validate();
|
||||||
|
}
|
||||||
|
}
|
40
app/Actions/User/CreateUser.php
Normal file
40
app/Actions/User/CreateUser.php
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions\User;
|
||||||
|
|
||||||
|
use App\Enums\UserRole;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Support\Facades\Validator;
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
|
|
||||||
|
class CreateUser
|
||||||
|
{
|
||||||
|
public function create(array $input): User
|
||||||
|
{
|
||||||
|
$this->validate($input);
|
||||||
|
|
||||||
|
/** @var User $user */
|
||||||
|
$user = User::query()->create([
|
||||||
|
'name' => $input['name'],
|
||||||
|
'email' => $input['email'],
|
||||||
|
'role' => $input['role'],
|
||||||
|
'password' => bcrypt($input['password']),
|
||||||
|
'timezone' => 'UTC',
|
||||||
|
]);
|
||||||
|
|
||||||
|
return $user;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function validate(array $input): void
|
||||||
|
{
|
||||||
|
Validator::make($input, [
|
||||||
|
'name' => 'required|string|max:255',
|
||||||
|
'email' => 'required|email|unique:users,email',
|
||||||
|
'password' => 'required|string|min:8',
|
||||||
|
'role' => [
|
||||||
|
'required',
|
||||||
|
Rule::in([UserRole::ADMIN, UserRole::USER]),
|
||||||
|
],
|
||||||
|
])->validate();
|
||||||
|
}
|
||||||
|
}
|
48
app/Actions/User/UpdateUser.php
Normal file
48
app/Actions/User/UpdateUser.php
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions\User;
|
||||||
|
|
||||||
|
use App\Enums\UserRole;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Support\Facades\Validator;
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
|
|
||||||
|
class UpdateUser
|
||||||
|
{
|
||||||
|
public function update(User $user, array $input): void
|
||||||
|
{
|
||||||
|
$this->validate($user, $input);
|
||||||
|
|
||||||
|
$user->name = $input['name'];
|
||||||
|
$user->email = $input['email'];
|
||||||
|
$user->timezone = $input['timezone'];
|
||||||
|
$user->role = $input['role'];
|
||||||
|
|
||||||
|
if (isset($input['password']) && $input['password'] !== null) {
|
||||||
|
$user->password = bcrypt($input['password']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$user->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function validate(User $user, array $input): void
|
||||||
|
{
|
||||||
|
Validator::make($input, [
|
||||||
|
'name' => ['required', 'string', 'max:255'],
|
||||||
|
'email' => ['required', 'email', 'max:255', Rule::unique('users')->ignore($user->id)],
|
||||||
|
'timezone' => [
|
||||||
|
'required',
|
||||||
|
Rule::in(timezone_identifiers_list()),
|
||||||
|
],
|
||||||
|
'role' => [
|
||||||
|
'required',
|
||||||
|
Rule::in([UserRole::ADMIN, UserRole::USER]),
|
||||||
|
function ($attribute, $value, $fail) use ($user) {
|
||||||
|
if ($user->is(auth()->user()) && $value !== $user->role) {
|
||||||
|
$fail('You cannot change your own role');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
],
|
||||||
|
])->validate();
|
||||||
|
}
|
||||||
|
}
|
@ -19,6 +19,10 @@ public function update(User $user, array $input): void
|
|||||||
Validator::make($input, [
|
Validator::make($input, [
|
||||||
'name' => ['required', 'string', 'max:255'],
|
'name' => ['required', 'string', 'max:255'],
|
||||||
'email' => ['required', 'email', 'max:255', Rule::unique('users')->ignore($user->id)],
|
'email' => ['required', 'email', 'max:255', Rule::unique('users')->ignore($user->id)],
|
||||||
|
'timezone' => [
|
||||||
|
'required',
|
||||||
|
Rule::in(timezone_identifiers_list()),
|
||||||
|
],
|
||||||
])->validateWithBag('updateProfileInformation');
|
])->validateWithBag('updateProfileInformation');
|
||||||
|
|
||||||
if ($input['email'] !== $user->email) {
|
if ($input['email'] !== $user->email) {
|
||||||
@ -27,6 +31,7 @@ public function update(User $user, array $input): void
|
|||||||
$user->forceFill([
|
$user->forceFill([
|
||||||
'name' => $input['name'],
|
'name' => $input['name'],
|
||||||
'email' => $input['email'],
|
'email' => $input['email'],
|
||||||
|
'timezone' => $input['timezone'],
|
||||||
])->save();
|
])->save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -39,6 +44,7 @@ protected function updateVerifiedUser(User $user, array $input): void
|
|||||||
$user->forceFill([
|
$user->forceFill([
|
||||||
'name' => $input['name'],
|
'name' => $input['name'],
|
||||||
'email' => $input['email'],
|
'email' => $input['email'],
|
||||||
|
'timezone' => $input['timezone'],
|
||||||
])->save();
|
])->save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,18 +7,27 @@
|
|||||||
|
|
||||||
class CreateUserCommand extends Command
|
class CreateUserCommand extends Command
|
||||||
{
|
{
|
||||||
protected $signature = 'user:create {name} {email} {password}';
|
protected $signature = 'user:create {name} {email} {password} {--role=admin}';
|
||||||
|
|
||||||
protected $description = 'Create a new user';
|
protected $description = 'Create a new user';
|
||||||
|
|
||||||
public function handle(): void
|
public function handle(): void
|
||||||
{
|
{
|
||||||
User::create([
|
$user = User::query()->where('email', $this->argument('email'))->first();
|
||||||
|
|
||||||
|
if ($user) {
|
||||||
|
$this->warn('User already exists. Skipping...');
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
User::query()->create([
|
||||||
'name' => $this->argument('name'),
|
'name' => $this->argument('name'),
|
||||||
'email' => $this->argument('email'),
|
'email' => $this->argument('email'),
|
||||||
'password' => bcrypt($this->argument('password')),
|
'password' => bcrypt($this->argument('password')),
|
||||||
|
'role' => $this->option('role'),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->info('User created with password');
|
$this->info('User created!');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
28
app/Console/Commands/DeleteOlderMetricsCommand.php
Normal file
28
app/Console/Commands/DeleteOlderMetricsCommand.php
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use App\Models\Service;
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
|
||||||
|
class DeleteOlderMetricsCommand extends Command
|
||||||
|
{
|
||||||
|
protected $signature = 'metrics:delete-older-metrics';
|
||||||
|
|
||||||
|
protected $description = 'Delete older metrics from database';
|
||||||
|
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
Service::query()->where('type', 'monitoring')->chunk(100, function ($services) {
|
||||||
|
$services->each(function ($service) {
|
||||||
|
$this->info("Deleting older metrics for service {$service->server->name}");
|
||||||
|
$service
|
||||||
|
->server
|
||||||
|
->metrics()
|
||||||
|
->where('created_at', '<', now()->subDays($service->handler()->data()['data_retention']))
|
||||||
|
->delete();
|
||||||
|
$this->info('Metrics deleted');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
31
app/Console/Commands/GetMetricsCommand.php
Normal file
31
app/Console/Commands/GetMetricsCommand.php
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use App\Models\Server;
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
|
||||||
|
class GetMetricsCommand extends Command
|
||||||
|
{
|
||||||
|
protected $signature = 'metrics:get';
|
||||||
|
|
||||||
|
protected $description = 'Get server metrics';
|
||||||
|
|
||||||
|
public function handle(): void
|
||||||
|
{
|
||||||
|
$checkedMetrics = 0;
|
||||||
|
Server::query()->whereHas('services', function (Builder $query) {
|
||||||
|
$query->where('type', 'monitoring')
|
||||||
|
->where('name', 'remote-monitor');
|
||||||
|
})->chunk(10, function ($servers) use (&$checkedMetrics) {
|
||||||
|
/** @var Server $server */
|
||||||
|
foreach ($servers as $server) {
|
||||||
|
$info = $server->os()->resourceInfo();
|
||||||
|
$server->metrics()->create(array_merge($info, ['server_id' => $server->id]));
|
||||||
|
$checkedMetrics++;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
$this->info("Checked $checkedMetrics metrics");
|
||||||
|
}
|
||||||
|
}
|
74
app/Console/Commands/MigrateFromMysqlToSqlite.php
Normal file
74
app/Console/Commands/MigrateFromMysqlToSqlite.php
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\File;
|
||||||
|
|
||||||
|
class MigrateFromMysqlToSqlite extends Command
|
||||||
|
{
|
||||||
|
protected $signature = 'migrate-from-mysql-to-sqlite';
|
||||||
|
|
||||||
|
protected $description = 'Migrate from Mysql to SQLite';
|
||||||
|
|
||||||
|
public function handle(): void
|
||||||
|
{
|
||||||
|
$this->info('Migrating from Mysql to SQLite...');
|
||||||
|
|
||||||
|
File::exists(storage_path('database.sqlite'))
|
||||||
|
? File::delete(storage_path('database.sqlite'))
|
||||||
|
: null;
|
||||||
|
|
||||||
|
File::put(storage_path('database.sqlite'), '');
|
||||||
|
|
||||||
|
config(['database.default' => 'sqlite']);
|
||||||
|
|
||||||
|
$this->call('migrate', ['--force' => true]);
|
||||||
|
|
||||||
|
$this->migrateModel(\App\Models\Backup::class);
|
||||||
|
$this->migrateModel(\App\Models\BackupFile::class);
|
||||||
|
$this->migrateModel(\App\Models\CronJob::class);
|
||||||
|
$this->migrateModel(\App\Models\Database::class);
|
||||||
|
$this->migrateModel(\App\Models\DatabaseUser::class);
|
||||||
|
$this->migrateModel(\App\Models\Deployment::class);
|
||||||
|
$this->migrateModel(\App\Models\DeploymentScript::class);
|
||||||
|
$this->migrateModel(\App\Models\FirewallRule::class);
|
||||||
|
$this->migrateModel(\App\Models\GitHook::class);
|
||||||
|
$this->migrateModel(\App\Models\NotificationChannel::class);
|
||||||
|
$this->migrateModel(\App\Models\Project::class);
|
||||||
|
$this->migrateModel(\App\Models\Queue::class);
|
||||||
|
$this->migrateModel(\App\Models\Server::class);
|
||||||
|
$this->migrateModel(\App\Models\ServerLog::class);
|
||||||
|
$this->migrateModel(\App\Models\ServerProvider::class);
|
||||||
|
$this->migrateModel(\App\Models\Service::class);
|
||||||
|
$this->migrateModel(\App\Models\Site::class);
|
||||||
|
$this->migrateModel(\App\Models\SourceControl::class);
|
||||||
|
$this->migrateModel(\App\Models\SshKey::class);
|
||||||
|
$this->migrateModel(\App\Models\Ssl::class);
|
||||||
|
$this->migrateModel(\App\Models\StorageProvider::class);
|
||||||
|
$this->migrateModel(\App\Models\User::class);
|
||||||
|
|
||||||
|
$env = File::get(base_path('.env'));
|
||||||
|
$env = str_replace('DB_CONNECTION=mysql', 'DB_CONNECTION=sqlite', $env);
|
||||||
|
$env = str_replace('DB_DATABASE=vito', '', $env);
|
||||||
|
File::put(base_path('.env'), $env);
|
||||||
|
|
||||||
|
$this->info('Migrated from Mysql to SQLite');
|
||||||
|
}
|
||||||
|
|
||||||
|
private function migrateModel(string $model): void
|
||||||
|
{
|
||||||
|
$this->info("Migrating model: {$model}");
|
||||||
|
|
||||||
|
config(['database.default' => 'mysql']);
|
||||||
|
|
||||||
|
$rows = $model::where('id', '>', 0)->get();
|
||||||
|
|
||||||
|
foreach ($rows as $row) {
|
||||||
|
DB::connection('sqlite')->table($row->getTable())->insert($row->getAttributes());
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->info("Migrated model: {$model}");
|
||||||
|
}
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user