ENHANCEMENT: using symfony framework
This commit is contained in:
parent
75ece7ea27
commit
0b6d123b69
|
@ -1,3 +1,9 @@
|
|||
################
|
||||
### DEFAULT ###
|
||||
################
|
||||
## What kind of environment. Only use prod here.
|
||||
APP_ENV=prod
|
||||
|
||||
################
|
||||
### DATABASE ###
|
||||
################
|
||||
|
|
|
@ -1,10 +1,21 @@
|
|||
cache/*
|
||||
!cache/.gitkeep
|
||||
vendor/
|
||||
node_modules/
|
||||
public/build/
|
||||
webcron.old/config.inc.php
|
||||
\.idea/
|
||||
|
||||
###> symfony/framework-bundle ###
|
||||
/.env.local
|
||||
/.env.local.php
|
||||
/.env.*.local
|
||||
/config/secrets/prod/prod.decrypt.private.php
|
||||
/public/bundles/
|
||||
/var/
|
||||
/vendor/
|
||||
###< symfony/framework-bundle ###
|
||||
|
||||
###> symfony/webpack-encore-bundle ###
|
||||
/node_modules/
|
||||
/public/build/
|
||||
npm-debug.log
|
||||
yarn-error.log
|
||||
###< symfony/webpack-encore-bundle ###
|
||||
|
||||
.idea/
|
||||
|
||||
.env
|
||||
storage/database.sqlite
|
||||
.DS_Store
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
/*
|
||||
* Welcome to your app's main JavaScript file!
|
||||
*
|
||||
* We recommend including the built version of this JavaScript file
|
||||
* (and its CSS file) in your base layout (base.html.twig).
|
||||
*/
|
||||
|
||||
// any CSS you import will output into a single css file (app.css in this case)
|
||||
import './styles/app.css';
|
||||
|
||||
// start the Stimulus application
|
||||
import './bootstrap';
|
|
@ -0,0 +1,11 @@
|
|||
import { startStimulusApp } from '@symfony/stimulus-bridge';
|
||||
|
||||
// Registers Stimulus controllers from controllers.json and in the controllers/ directory
|
||||
export const app = startStimulusApp(require.context(
|
||||
'@symfony/stimulus-bridge/lazy-controller-loader!./controllers',
|
||||
true,
|
||||
/\.[jt]sx?$/
|
||||
));
|
||||
|
||||
// register any custom, 3rd party controllers here
|
||||
// app.register('some_controller_name', SomeImportedController);
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"controllers": [],
|
||||
"entrypoints": []
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
import { Controller } from '@hotwired/stimulus';
|
||||
|
||||
/*
|
||||
* This is an example Stimulus controller!
|
||||
*
|
||||
* Any element with a data-controller="hello" attribute will cause
|
||||
* this controller to be executed. The name "hello" comes from the filename:
|
||||
* hello_controller.js -> "hello"
|
||||
*
|
||||
* Delete this file or adapt it for your use!
|
||||
*/
|
||||
export default class extends Controller {
|
||||
connect() {
|
||||
this.element.textContent = 'Hello Stimulus! Edit me in assets/controllers/hello_controller.js';
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
body {
|
||||
background-color: lightgray;
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
use App\Kernel;
|
||||
use Symfony\Bundle\FrameworkBundle\Console\Application;
|
||||
|
||||
if (!is_file(dirname(__DIR__).'/vendor/autoload_runtime.php')) {
|
||||
throw new LogicException('Symfony Runtime is missing. Try running "composer require symfony/runtime".');
|
||||
}
|
||||
|
||||
require_once dirname(__DIR__).'/vendor/autoload_runtime.php';
|
||||
|
||||
return function (array $context) {
|
||||
$kernel = new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);
|
||||
|
||||
return new Application($kernel);
|
||||
};
|
|
@ -1,11 +0,0 @@
|
|||
<?php
|
||||
|
||||
require_once "vendor/autoload.php";
|
||||
|
||||
if( ini_get('safe_mode') ){
|
||||
die("Cannot run in safe mode");
|
||||
}
|
||||
|
||||
if (!file_exists(__DIR__ . "/.env")) {
|
||||
die ("Cannot find config file");
|
||||
}
|
105
composer.json
105
composer.json
|
@ -1,40 +1,87 @@
|
|||
{
|
||||
"name": "jeroened/webcron",
|
||||
"description": "A simple webapp to manage webcrons",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Jeroen De Meerleer",
|
||||
"email": "me@jeroened.be"
|
||||
}
|
||||
],
|
||||
"type": "project",
|
||||
"license": "proprietary",
|
||||
"minimum-stability": "stable",
|
||||
"prefer-stable": true,
|
||||
"require": {
|
||||
"doctrine/dbal": "~3.2.0",
|
||||
"guzzlehttp/guzzle": "~7.4.0",
|
||||
"mehrkanal/twig-encore-extension": "~1.3.0",
|
||||
"phpseclib/phpseclib": "^3.0",
|
||||
"symfony/config": "~6.0.0",
|
||||
"symfony/console": "~6.0.0",
|
||||
"symfony/dotenv": "~6.0.0",
|
||||
"symfony/http-foundation": "~6.0.0",
|
||||
"symfony/mailer": "~6.0.0",
|
||||
"symfony/routing": "~6.0.0",
|
||||
"symfony/yaml": "~6.0.0",
|
||||
"twig/intl-extra": "~3.3.0",
|
||||
"twig/twig": "~3.3.0",
|
||||
"ext-pcntl": "*",
|
||||
"php": ">=8.1",
|
||||
"ext-ctype": "*",
|
||||
"ext-iconv": "*",
|
||||
"ext-intl": "*",
|
||||
"ext-openssl": "*"
|
||||
"ext-openssl": "*",
|
||||
"ext-pcntl": "*",
|
||||
"doctrine/doctrine-bundle": "^2.6",
|
||||
"doctrine/doctrine-migrations-bundle": "^3.2",
|
||||
"doctrine/orm": "^2.12",
|
||||
"guzzlehttp/guzzle": "~7.4.0",
|
||||
"phpseclib/phpseclib": "^3.0",
|
||||
"symfony/console": "6.0.*",
|
||||
"symfony/dotenv": "6.0.*",
|
||||
"symfony/flex": "^2",
|
||||
"symfony/framework-bundle": "6.0.*",
|
||||
"symfony/proxy-manager-bridge": "6.0.*",
|
||||
"symfony/runtime": "6.0.*",
|
||||
"symfony/security-bundle": "6.0.*",
|
||||
"symfony/twig-bundle": "6.0.*",
|
||||
"symfony/webpack-encore-bundle": "^1.14",
|
||||
"symfony/yaml": "6.0.*"
|
||||
},
|
||||
"config": {
|
||||
"allow-plugins": {
|
||||
"composer/package-versions-deprecated": true,
|
||||
"symfony/flex": true,
|
||||
"symfony/runtime": true
|
||||
},
|
||||
"optimize-autoloader": true,
|
||||
"preferred-install": {
|
||||
"*": "dist"
|
||||
},
|
||||
"sort-packages": true
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"JeroenED\\Framework\\": "lib/Framework/",
|
||||
"JeroenED\\Webcron\\": "src/"
|
||||
"App\\": "src/"
|
||||
}
|
||||
},
|
||||
"config": {
|
||||
"sort-packages": true,
|
||||
"allow-plugins": {
|
||||
"composer/package-versions-deprecated": true
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"App\\Tests\\": "tests/"
|
||||
}
|
||||
},
|
||||
"replace": {
|
||||
"symfony/polyfill-ctype": "*",
|
||||
"symfony/polyfill-iconv": "*",
|
||||
"symfony/polyfill-php72": "*",
|
||||
"symfony/polyfill-php73": "*",
|
||||
"symfony/polyfill-php74": "*",
|
||||
"symfony/polyfill-php80": "*"
|
||||
},
|
||||
"scripts": {
|
||||
"auto-scripts": {
|
||||
"cache:clear": "symfony-cmd",
|
||||
"assets:install %PUBLIC_DIR%": "symfony-cmd"
|
||||
},
|
||||
"post-install-cmd": [
|
||||
"@auto-scripts"
|
||||
],
|
||||
"post-update-cmd": [
|
||||
"@auto-scripts"
|
||||
]
|
||||
},
|
||||
"conflict": {
|
||||
"symfony/symfony": "*"
|
||||
},
|
||||
"extra": {
|
||||
"symfony": {
|
||||
"allow-contrib": false,
|
||||
"require": "6.0.*"
|
||||
}
|
||||
},
|
||||
"require-dev": {
|
||||
"symfony/debug-bundle": "6.0.*",
|
||||
"symfony/maker-bundle": "^1.40",
|
||||
"symfony/monolog-bundle": "^3.0",
|
||||
"symfony/stopwatch": "6.0.*",
|
||||
"symfony/web-profiler-bundle": "6.0.*"
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
|
||||
Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true],
|
||||
Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true],
|
||||
Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true],
|
||||
Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true],
|
||||
Symfony\WebpackEncoreBundle\WebpackEncoreBundle::class => ['all' => true],
|
||||
Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true],
|
||||
Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true],
|
||||
Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true],
|
||||
Symfony\Bundle\DebugBundle\DebugBundle::class => ['dev' => true],
|
||||
];
|
|
@ -0,0 +1,19 @@
|
|||
framework:
|
||||
cache:
|
||||
# Unique name of your app: used to compute stable namespaces for cache keys.
|
||||
#prefix_seed: your_vendor_name/app_name
|
||||
|
||||
# The "app" cache stores to the filesystem by default.
|
||||
# The data in this cache should persist between deploys.
|
||||
# Other options include:
|
||||
|
||||
# Redis
|
||||
#app: cache.adapter.redis
|
||||
#default_redis_provider: redis://localhost
|
||||
|
||||
# APCu (not recommended with heavy random-write workloads as memory fragmentation can cause perf issues)
|
||||
#app: cache.adapter.apcu
|
||||
|
||||
# Namespaced pools use the above "app" backend by default
|
||||
#pools:
|
||||
#my.dedicated.cache: null
|
|
@ -0,0 +1,5 @@
|
|||
when@dev:
|
||||
debug:
|
||||
# Forwards VarDumper Data clones to a centralized server allowing to inspect dumps on CLI or in your browser.
|
||||
# See the "server:dump" command to start a new server.
|
||||
dump_destination: "tcp://%env(VAR_DUMPER_SERVER)%"
|
|
@ -0,0 +1,42 @@
|
|||
doctrine:
|
||||
dbal:
|
||||
url: '%env(resolve:DATABASE_URL)%'
|
||||
|
||||
# IMPORTANT: You MUST configure your server version,
|
||||
# either here or in the DATABASE_URL env var (see .env file)
|
||||
#server_version: '13'
|
||||
orm:
|
||||
auto_generate_proxy_classes: true
|
||||
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
|
||||
auto_mapping: true
|
||||
mappings:
|
||||
App:
|
||||
is_bundle: false
|
||||
dir: '%kernel.project_dir%/src/Entity'
|
||||
prefix: 'App\Entity'
|
||||
alias: App
|
||||
|
||||
when@test:
|
||||
doctrine:
|
||||
dbal:
|
||||
# "TEST_TOKEN" is typically set by ParaTest
|
||||
dbname_suffix: '_test%env(default::TEST_TOKEN)%'
|
||||
|
||||
when@prod:
|
||||
doctrine:
|
||||
orm:
|
||||
auto_generate_proxy_classes: false
|
||||
query_cache_driver:
|
||||
type: pool
|
||||
pool: doctrine.system_cache_pool
|
||||
result_cache_driver:
|
||||
type: pool
|
||||
pool: doctrine.result_cache_pool
|
||||
|
||||
framework:
|
||||
cache:
|
||||
pools:
|
||||
doctrine.result_cache_pool:
|
||||
adapter: cache.app
|
||||
doctrine.system_cache_pool:
|
||||
adapter: cache.system
|
|
@ -0,0 +1,6 @@
|
|||
doctrine_migrations:
|
||||
migrations_paths:
|
||||
# namespace is arbitrary but should be different from App\Migrations
|
||||
# as migrations classes should NOT be autoloaded
|
||||
'DoctrineMigrations': '%kernel.project_dir%/migrations'
|
||||
enable_profiler: '%kernel.debug%'
|
|
@ -0,0 +1,24 @@
|
|||
# see https://symfony.com/doc/current/reference/configuration/framework.html
|
||||
framework:
|
||||
secret: '%env(APP_SECRET)%'
|
||||
#csrf_protection: true
|
||||
http_method_override: false
|
||||
|
||||
# Enables session support. Note that the session will ONLY be started if you read or write from it.
|
||||
# Remove or comment this section to explicitly disable session support.
|
||||
session:
|
||||
handler_id: null
|
||||
cookie_secure: auto
|
||||
cookie_samesite: lax
|
||||
storage_factory_id: session.storage.factory.native
|
||||
|
||||
#esi: true
|
||||
#fragments: true
|
||||
php_errors:
|
||||
log: true
|
||||
|
||||
when@test:
|
||||
framework:
|
||||
test: true
|
||||
session:
|
||||
storage_factory_id: session.storage.factory.mock_file
|
|
@ -0,0 +1,61 @@
|
|||
monolog:
|
||||
channels:
|
||||
- deprecation # Deprecations are logged in the dedicated "deprecation" channel when it exists
|
||||
|
||||
when@dev:
|
||||
monolog:
|
||||
handlers:
|
||||
main:
|
||||
type: stream
|
||||
path: "%kernel.logs_dir%/%kernel.environment%.log"
|
||||
level: debug
|
||||
channels: ["!event"]
|
||||
# uncomment to get logging in your browser
|
||||
# you may have to allow bigger header sizes in your Web server configuration
|
||||
#firephp:
|
||||
# type: firephp
|
||||
# level: info
|
||||
#chromephp:
|
||||
# type: chromephp
|
||||
# level: info
|
||||
console:
|
||||
type: console
|
||||
process_psr_3_messages: false
|
||||
channels: ["!event", "!doctrine", "!console"]
|
||||
|
||||
when@test:
|
||||
monolog:
|
||||
handlers:
|
||||
main:
|
||||
type: fingers_crossed
|
||||
action_level: error
|
||||
handler: nested
|
||||
excluded_http_codes: [404, 405]
|
||||
channels: ["!event"]
|
||||
nested:
|
||||
type: stream
|
||||
path: "%kernel.logs_dir%/%kernel.environment%.log"
|
||||
level: debug
|
||||
|
||||
when@prod:
|
||||
monolog:
|
||||
handlers:
|
||||
main:
|
||||
type: fingers_crossed
|
||||
action_level: error
|
||||
handler: nested
|
||||
excluded_http_codes: [404, 405]
|
||||
buffer_size: 50 # How many messages should be saved? Prevent memory leaks
|
||||
nested:
|
||||
type: stream
|
||||
path: php://stderr
|
||||
level: debug
|
||||
formatter: monolog.formatter.json
|
||||
console:
|
||||
type: console
|
||||
process_psr_3_messages: false
|
||||
channels: ["!event", "!doctrine"]
|
||||
deprecation:
|
||||
type: stream
|
||||
channels: [deprecation]
|
||||
path: php://stderr
|
|
@ -0,0 +1,12 @@
|
|||
framework:
|
||||
router:
|
||||
utf8: true
|
||||
|
||||
# Configure how to generate URLs in non-HTTP contexts, such as CLI commands.
|
||||
# See https://symfony.com/doc/current/routing.html#generating-urls-in-commands
|
||||
#default_uri: http://localhost
|
||||
|
||||
when@prod:
|
||||
framework:
|
||||
router:
|
||||
strict_requirements: null
|
|
@ -0,0 +1,42 @@
|
|||
security:
|
||||
enable_authenticator_manager: true
|
||||
# https://symfony.com/doc/current/security.html#registering-the-user-hashing-passwords
|
||||
password_hashers:
|
||||
Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface: 'auto'
|
||||
# https://symfony.com/doc/current/security.html#loading-the-user-the-user-provider
|
||||
providers:
|
||||
app_user_provider:
|
||||
entity:
|
||||
class: App\Entity\User
|
||||
property: email
|
||||
firewalls:
|
||||
dev:
|
||||
pattern: ^/(_(profiler|wdt)|css|images|js|health)/
|
||||
security: false
|
||||
main:
|
||||
pattern: ^\/(.*)
|
||||
provider: app_user_provider
|
||||
|
||||
form_login:
|
||||
login_path: /login
|
||||
check_path: /login_check
|
||||
enable_csrf: true
|
||||
logout:
|
||||
path: /logout
|
||||
target: /
|
||||
remember_me:
|
||||
secret: '%kernel.secret%'
|
||||
lifetime: 2419200 # 28 days in seconds
|
||||
path: /
|
||||
secure: true
|
||||
# activate different ways to authenticate
|
||||
# https://symfony.com/doc/current/security.html#the-firewall
|
||||
|
||||
# https://symfony.com/doc/current/security/impersonating_user.html
|
||||
# switch_user: true
|
||||
|
||||
# Easy way to control access for large sections of your site
|
||||
# Note: Only the *first* access control that matches will be used
|
||||
access_control:
|
||||
- { path: ^/(?!login|login_check|health)(?=.*), roles: ROLE_USER }
|
||||
# - { path: ^/profile, roles: ROLE_USER }
|
|
@ -0,0 +1,6 @@
|
|||
twig:
|
||||
default_path: '%kernel.project_dir%/templates'
|
||||
|
||||
when@test:
|
||||
twig:
|
||||
strict_variables: true
|
|
@ -0,0 +1,15 @@
|
|||
when@dev:
|
||||
web_profiler:
|
||||
toolbar: true
|
||||
intercept_redirects: false
|
||||
|
||||
framework:
|
||||
profiler: { only_exceptions: false }
|
||||
|
||||
when@test:
|
||||
web_profiler:
|
||||
toolbar: false
|
||||
intercept_redirects: false
|
||||
|
||||
framework:
|
||||
profiler: { collect: false }
|
|
@ -0,0 +1,49 @@
|
|||
webpack_encore:
|
||||
# The path where Encore is building the assets - i.e. Encore.setOutputPath()
|
||||
output_path: '%kernel.project_dir%/public/build'
|
||||
# If multiple builds are defined (as shown below), you can disable the default build:
|
||||
# output_path: false
|
||||
|
||||
# Set attributes that will be rendered on all script and link tags
|
||||
script_attributes:
|
||||
defer: true
|
||||
# Uncomment (also under link_attributes) if using Turbo Drive
|
||||
# https://turbo.hotwired.dev/handbook/drive#reloading-when-assets-change
|
||||
# 'data-turbo-track': reload
|
||||
# link_attributes:
|
||||
# Uncomment if using Turbo Drive
|
||||
# 'data-turbo-track': reload
|
||||
|
||||
# If using Encore.enableIntegrityHashes() and need the crossorigin attribute (default: false, or use 'anonymous' or 'use-credentials')
|
||||
# crossorigin: 'anonymous'
|
||||
|
||||
# Preload all rendered script and link tags automatically via the HTTP/2 Link header
|
||||
# preload: true
|
||||
|
||||
# Throw an exception if the entrypoints.json file is missing or an entry is missing from the data
|
||||
# strict_mode: false
|
||||
|
||||
# If you have multiple builds:
|
||||
# builds:
|
||||
# pass "frontend" as the 3rg arg to the Twig functions
|
||||
# {{ encore_entry_script_tags('entry1', null, 'frontend') }}
|
||||
|
||||
# frontend: '%kernel.project_dir%/public/frontend/build'
|
||||
|
||||
# Cache the entrypoints.json (rebuild Symfony's cache when entrypoints.json changes)
|
||||
# Put in config/packages/prod/webpack_encore.yaml
|
||||
# cache: true
|
||||
|
||||
framework:
|
||||
assets:
|
||||
json_manifest_path: '%kernel.project_dir%/public/build/manifest.json'
|
||||
|
||||
#when@prod:
|
||||
# webpack_encore:
|
||||
# # Cache the entrypoints.json (rebuild Symfony's cache when entrypoints.json changes)
|
||||
# # Available in version 1.2
|
||||
# cache: true
|
||||
|
||||
#when@test:
|
||||
# webpack_encore:
|
||||
# strict_mode: false
|
|
@ -0,0 +1,5 @@
|
|||
<?php
|
||||
|
||||
if (file_exists(dirname(__DIR__).'/var/cache/prod/App_KernelProdContainer.preload.php')) {
|
||||
require dirname(__DIR__).'/var/cache/prod/App_KernelProdContainer.preload.php';
|
||||
}
|
|
@ -1,39 +1,34 @@
|
|||
default:
|
||||
path: '/'
|
||||
defaults:
|
||||
_controller: JeroenED\Webcron\Controller\JobController::defaultAction
|
||||
_controller: App\Controller\JobController::defaultAction
|
||||
|
||||
health:
|
||||
path: '/health'
|
||||
defaults:
|
||||
_controller: JeroenED\Webcron\Controller\SiteController::HealthAction
|
||||
_controller: App\Controller\SiteController::healthAction
|
||||
|
||||
login:
|
||||
path: '/login'
|
||||
defaults:
|
||||
_controller: JeroenED\Webcron\Controller\SecurityController::loginAction
|
||||
|
||||
logout:
|
||||
path: '/logout'
|
||||
defaults:
|
||||
_controller: JeroenED\Webcron\Controller\SecurityController::logoutAction
|
||||
_controller: App\Controller\SecurityController::loginAction
|
||||
|
||||
login_check:
|
||||
path: '/login_check'
|
||||
methods: ['POST']
|
||||
defaults:
|
||||
_controller: JeroenED\Webcron\Controller\SecurityController::loginCheckAction
|
||||
|
||||
logout:
|
||||
path: '/logout'
|
||||
|
||||
job_index:
|
||||
path: '/job'
|
||||
defaults:
|
||||
_controller: JeroenED\Webcron\Controller\JobController::defaultAction
|
||||
_controller: App\Controller\JobController::defaultAction
|
||||
|
||||
job_view:
|
||||
path: '/job/{id}/{all}'
|
||||
methods: [ 'GET' ]
|
||||
defaults:
|
||||
_controller: JeroenED\Webcron\Controller\JobController::jobAction
|
||||
_controller: App\Controller\JobController::jobAction
|
||||
all: false
|
||||
requirements:
|
||||
id: \d+
|
||||
|
@ -43,25 +38,25 @@ job_delete:
|
|||
path: '/job/{id}'
|
||||
methods: [ 'DELETE' ]
|
||||
defaults:
|
||||
_controller: JeroenED\Webcron\Controller\JobController::jobAction
|
||||
_controller: App\Controller\JobController::jobAction
|
||||
requirements:
|
||||
id: \d+
|
||||
|
||||
job_edit:
|
||||
path: '/job/{id}/edit'
|
||||
defaults:
|
||||
_controller: JeroenED\Webcron\Controller\JobController::editAction
|
||||
_controller: App\Controller\JobController::editAction
|
||||
requirements:
|
||||
id: \d+
|
||||
|
||||
job_runnow:
|
||||
path: '/job/{id}/runnow'
|
||||
defaults:
|
||||
_controller: JeroenED\Webcron\Controller\JobController::runnowAction
|
||||
_controller: App\Controller\JobController::runNowAction
|
||||
requirements:
|
||||
id: \d+
|
||||
|
||||
job_add:
|
||||
path: '/job/add'
|
||||
defaults:
|
||||
_controller: JeroenED\Webcron\Controller\JobController::addAction
|
||||
_controller: App\Controller\JobController::addAction
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
when@dev:
|
||||
_errors:
|
||||
resource: '@FrameworkBundle/Resources/config/routing/errors.xml'
|
||||
prefix: /_error
|
|
@ -0,0 +1,8 @@
|
|||
when@dev:
|
||||
web_profiler_wdt:
|
||||
resource: '@WebProfilerBundle/Resources/config/routing/wdt.xml'
|
||||
prefix: /_wdt
|
||||
|
||||
web_profiler_profiler:
|
||||
resource: '@WebProfilerBundle/Resources/config/routing/profiler.xml'
|
||||
prefix: /_profiler
|
|
@ -0,0 +1,24 @@
|
|||
# This file is the entry point to configure your own services.
|
||||
# Files in the packages/ subdirectory configure your dependencies.
|
||||
|
||||
# Put parameters here that don't need to change on each machine where the app is deployed
|
||||
# https://symfony.com/doc/current/best_practices.html#use-parameters-for-application-configuration
|
||||
parameters:
|
||||
|
||||
services:
|
||||
# default configuration for services in *this* file
|
||||
_defaults:
|
||||
autowire: true # Automatically injects dependencies in your services.
|
||||
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
|
||||
|
||||
# makes classes in src/ available to be used as services
|
||||
# this creates a service per class whose id is the fully-qualified class name
|
||||
App\:
|
||||
resource: '../src/'
|
||||
exclude:
|
||||
- '../src/DependencyInjection/'
|
||||
- '../src/Entity/'
|
||||
- '../src/Kernel.php'
|
||||
|
||||
# add more service definitions when explicit configuration is needed
|
||||
# please note that last definitions always *replace* previous ones
|
|
@ -1,71 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace JeroenED\Framework;
|
||||
|
||||
|
||||
use Doctrine\DBAL\Connection;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Twig\Environment;
|
||||
use Twig\Loader\FilesystemLoader;
|
||||
|
||||
abstract class Controller
|
||||
{
|
||||
private $twig;
|
||||
private $request;
|
||||
private $database;
|
||||
private $kernel;
|
||||
|
||||
public function __construct(Request $request, Kernel $kernel)
|
||||
{
|
||||
$this->twig = new Twig($kernel);
|
||||
$this->request = $request;
|
||||
$this->kernel = $kernel;
|
||||
}
|
||||
|
||||
public function getDbCon(): Connection
|
||||
{
|
||||
return $this->kernel->getDbCon();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Request
|
||||
*/
|
||||
public function getRequest(): Request
|
||||
{
|
||||
return $this->request;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
*/
|
||||
public function setRequest(Request $request): void
|
||||
{
|
||||
$this->request = $request;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $template
|
||||
* @param array $vars
|
||||
* @return Response
|
||||
*/
|
||||
public function render(string $template, array $vars = []): Response
|
||||
{
|
||||
if(empty($_SERVER['HTTP_X_REQUESTED_WITH']) || strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest') {
|
||||
$vars['flashes'] = $_SESSION['flashes'] ?? [] ;
|
||||
$_SESSION['flashes'] = [];
|
||||
}
|
||||
$response = new Response($this->twig->render($template, $vars));
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function generateRoute(string $route): string
|
||||
{
|
||||
return $this->kernel->getRouter()->getUrlForRoute($route);
|
||||
}
|
||||
|
||||
public function addFlash(string $category, string $content): void
|
||||
{
|
||||
$_SESSION['flashes'][] = ['category' => $category, 'content' => $content];
|
||||
}
|
||||
}
|
|
@ -1,141 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace JeroenED\Framework;
|
||||
|
||||
|
||||
use Doctrine\DBAL\Connection;
|
||||
use Doctrine\DBAL\DriverManager;
|
||||
use http\Exception\InvalidArgumentException;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\Routing\Loader\YamlFileLoader;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\RouteCollection;
|
||||
use Symfony\Component\Routing\RequestContext;
|
||||
use Symfony\Component\Routing\Matcher\UrlMatcher;
|
||||
use Symfony\Component\Dotenv\Dotenv;
|
||||
|
||||
class Kernel
|
||||
{
|
||||
private string $configDir;
|
||||
private string $projectDir;
|
||||
private string $templateDir;
|
||||
private string $cacheDir;
|
||||
private Router $router;
|
||||
private ?Connection $dbCon = NULL;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getConfigDir(): string
|
||||
{
|
||||
return $this->configDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $configDir
|
||||
*/
|
||||
public function setConfigDir(string $configDir): void
|
||||
{
|
||||
$this->configDir = $configDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getProjectDir(): string
|
||||
{
|
||||
return $this->projectDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $projectDir
|
||||
*/
|
||||
public function setProjectDir(string $projectDir): void
|
||||
{
|
||||
$this->projectDir = $projectDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getTemplateDir(): string
|
||||
{
|
||||
return $this->templateDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $templateDir
|
||||
*/
|
||||
public function setTemplateDir(string $templateDir): void
|
||||
{
|
||||
$this->templateDir = $templateDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getCacheDir(): string
|
||||
{
|
||||
return $this->cacheDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $cacheDir
|
||||
*/
|
||||
public function setCacheDir(string $cacheDir): void
|
||||
{
|
||||
$this->cacheDir = $cacheDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Router
|
||||
*/
|
||||
public function getRouter(): Router
|
||||
{
|
||||
return $this->router;
|
||||
}
|
||||
|
||||
public function handle(): Response
|
||||
{
|
||||
$this->router = new Router();
|
||||
$this->router->parseRoutes($this->getConfigDir(), 'routes.yaml');
|
||||
$request = $this->parseRequest();
|
||||
|
||||
if($request->isSecure()) {
|
||||
ini_set('session.cookie_httponly', true);
|
||||
ini_set('session.cookie_secure', true);
|
||||
}
|
||||
|
||||
session_start();
|
||||
return $this->router->route($request, $this);
|
||||
}
|
||||
|
||||
public function parseDotEnv(string $path): void
|
||||
{
|
||||
$dotenv = new Dotenv();
|
||||
$dotenv->loadEnv($path);
|
||||
}
|
||||
|
||||
private function parseRequest(): Request
|
||||
{
|
||||
Request::setTrustedProxies(explode(',', $_ENV['TRUSTED_PROXIES']), Request::HEADER_X_FORWARDED_FOR | Request::HEADER_X_FORWARDED_HOST | Request::HEADER_X_FORWARDED_PORT | Request::HEADER_X_FORWARDED_PROTO);
|
||||
$request = Request::createFromGlobals();
|
||||
return $request;
|
||||
}
|
||||
|
||||
public function getNewDbCon(): Connection {
|
||||
if(!is_null($this->dbCon)) {
|
||||
$this->dbCon->close();
|
||||
$this->dbCon = null;
|
||||
}
|
||||
$this->dbCon = DriverManager::getConnection(['url' => $_ENV['DATABASE']]);
|
||||
return $this->dbCon;
|
||||
}
|
||||
|
||||
public function getDbCon(): Connection
|
||||
{
|
||||
if(is_null($this->dbCon)) $this->dbCon = DriverManager::getConnection(['url' => $_ENV['DATABASE']]);
|
||||
return $this->dbCon;
|
||||
}
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace JeroenED\Framework;
|
||||
|
||||
|
||||
use Doctrine\DBAL\Connection;
|
||||
|
||||
class Repository
|
||||
{
|
||||
protected Connection $dbcon;
|
||||
|
||||
public function __construct(Connection $dbcon)
|
||||
{
|
||||
$this->dbcon = $dbcon;
|
||||
}
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace JeroenED\Framework;
|
||||
|
||||
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\Filesystem\Exception\InvalidArgumentException;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Generator\UrlGenerator;
|
||||
use Symfony\Component\Routing\Loader\YamlFileLoader;
|
||||
use Symfony\Component\Routing\Matcher\UrlMatcher;
|
||||
use Symfony\Component\Routing\RequestContext;
|
||||
use Symfony\Component\Routing\RouteCollection;
|
||||
|
||||
class Router
|
||||
{
|
||||
private RouteCollection $routes;
|
||||
private RequestContext $requestContext;
|
||||
|
||||
public function route(Request $request, Kernel $kernel): Response
|
||||
{
|
||||
$requestContext = new RequestContext();
|
||||
$this->requestContext = $requestContext->fromRequest($request);
|
||||
$matcher = new UrlMatcher($this->routes, $this->requestContext);
|
||||
$method = $matcher->match($request->getPathInfo());
|
||||
$controller = explode('::', $method['_controller']);
|
||||
$controllerObj = new ('\\' . $controller[0])($request, $kernel);
|
||||
$action = $controller[1];
|
||||
unset($method['_controller']);
|
||||
unset($method['_route']);
|
||||
$response = $controllerObj->$action(...$method);
|
||||
|
||||
if ($response instanceof Response) {
|
||||
$response->headers->add([
|
||||
"Content-Security-Policy" => "default-src 'none'; font-src 'self'; style-src 'self'; script-src 'self'; connect-src 'self'; img-src 'self' data:; form-action 'self'; require-trusted-types-for 'script'; frame-ancestors 'none'; base-uri 'none'",
|
||||
"Referrer-Policy" => "same-origin"
|
||||
]);
|
||||
return $response;
|
||||
} else {
|
||||
throw new InvalidArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
public function parseRoutes(string $dir, string $file): void
|
||||
{
|
||||
$routeloader = new YamlFileLoader(new FileLocator($dir));
|
||||
$this->routes = $routeloader->load($file);
|
||||
}
|
||||
|
||||
public function getUrlForRoute(string $route, array $params = []): string
|
||||
{
|
||||
$matcher = new UrlGenerator($this->routes, $this->requestContext);
|
||||
return $matcher->generate($route, $params, UrlGenerator::ABSOLUTE_URL);
|
||||
}
|
||||
}
|
|
@ -1,114 +0,0 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace JeroenED\Framework;
|
||||
|
||||
|
||||
use Mehrkanal\EncoreTwigExtension\Extensions\EntryFilesTwigExtension;
|
||||
use Symfony\WebpackEncoreBundle\Asset\EntrypointLookup;
|
||||
use Twig\Cache\FilesystemCache;
|
||||
use Twig\Environment;
|
||||
use Twig\Extra\Intl\IntlExtension;
|
||||
use Twig\Loader\FilesystemLoader;
|
||||
use Twig\TwigFilter;
|
||||
use Twig\TwigFunction;
|
||||
|
||||
class Twig
|
||||
{
|
||||
private Environment $environment;
|
||||
private Kernel $kernel;
|
||||
|
||||
public function __construct(Kernel $kernel)
|
||||
{
|
||||
$loader = new FilesystemLoader([$kernel->getTemplateDir()]);
|
||||
$this->environment = new Environment($loader);
|
||||
|
||||
if($_ENV['DEBUG'] != 'true') {
|
||||
$cache = new FilesystemCache($kernel->getCacheDir() . '/twig');
|
||||
$this->environment->setCache($cache);
|
||||
}
|
||||
|
||||
$this->kernel = $kernel;
|
||||
$this->addExtensions();
|
||||
$this->addFunctions();
|
||||
$this->addFilters();
|
||||
}
|
||||
|
||||
public function render(string $template, array $vars = []): string
|
||||
{
|
||||
return $this->environment->render($template, $vars);
|
||||
}
|
||||
|
||||
public function addExtensions()
|
||||
{
|
||||
$this->environment->addExtension(new IntlExtension());
|
||||
$this->environment->addExtension(new EntryFilesTwigExtension(new EntrypointLookup('./public/build/entrypoints.json')));
|
||||
}
|
||||
public function addFunctions()
|
||||
{
|
||||
$path = new TwigFunction('path', function(string $route, array $params = []) {
|
||||
return $this->kernel->getRouter()->getUrlForRoute($route, $params);
|
||||
});
|
||||
$this->environment->addFunction($path);
|
||||
|
||||
}
|
||||
|
||||
public function addFilters() {
|
||||
$secondsToInterval = new TwigFilter('interval', function(int|float $time) {
|
||||
$return = '';
|
||||
|
||||
$days = floor($time / (60 * 60 * 24));
|
||||
$time -= $days * (60 * 60 * 24);
|
||||
$return .= ($days != 0 || !empty($return)) ? "{$days}d " : '';
|
||||
|
||||
$hours = floor($time / (60 * 60));
|
||||
$time -= $hours * (60 * 60);
|
||||
$return .= ($hours != 0 || !empty($return)) ? "{$hours}h " : '';
|
||||
|
||||
$minutes = floor($time / 60);
|
||||
$time -= $minutes * 60;
|
||||
$return .= ($minutes != 0 || !empty($return)) ? "{$minutes}m " : '';
|
||||
|
||||
$time = round($time, 3);
|
||||
$return .= ($time != 0 || !empty($return)) ? "{$time}s " : '';
|
||||
|
||||
return $return;
|
||||
});
|
||||
$parseTags = new TwigFilter('parsetags', function(string $text) {
|
||||
$results = [];
|
||||
preg_match_all('/\[([A-Za-z0-9 \-]+)\]/', $text, $results);
|
||||
foreach ($results[0] as $key=>$result) {
|
||||
$background = substr(md5($results[0][$key]), 0, 6);
|
||||
$color = $this->lightOrDark($background) == 'dark' ? 'ffffff' : '000000';
|
||||
$text = str_replace($results[0][$key], '<span class="tag" data-background-color="#' . $background . '" data-color="#' . $color . '">' . $results[1][$key] . '</span>', $text);
|
||||
}
|
||||
return $text;
|
||||
});
|
||||
|
||||
$this->environment->addFilter($secondsToInterval);
|
||||
$this->environment->addFilter($parseTags);
|
||||
|
||||
}
|
||||
|
||||
private function lightOrDark ($color) {
|
||||
$color = str_split($color, 2);
|
||||
foreach($color as &$value) {
|
||||
$value = hexdec($value);
|
||||
}
|
||||
|
||||
// HSP (Highly Sensitive Poo) equation from http://alienryderflex.com/hsp.html
|
||||
$hsp = sqrt(
|
||||
0.299 * ($color[0] * $color[0]) +
|
||||
0.587 * ($color[1] * $color[1]) +
|
||||
0.114 * ($color[2] * $color[2])
|
||||
);
|
||||
|
||||
|
||||
// Using the HSP value, determine whether the color is light or dark
|
||||
if ($hsp>140) {
|
||||
return 'light';
|
||||
} else {
|
||||
return 'dark';
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -1,18 +1,9 @@
|
|||
<?php
|
||||
error_reporting(E_ALL);
|
||||
ini_set('display_errors', true);
|
||||
|
||||
use JeroenED\Framework\Kernel;
|
||||
chdir(__DIR__ . '/..');
|
||||
require_once 'bootstrap.php';
|
||||
use App\Kernel;
|
||||
|
||||
$kernel = new Kernel();
|
||||
$kernel->setProjectDir(getcwd());
|
||||
$kernel->setConfigDir(getcwd() . '/config/');
|
||||
$kernel->setTemplateDir(getcwd() . '/templates/');
|
||||
$kernel->setCacheDir(getcwd() . '/cache/');
|
||||
$kernel->parseDotEnv($kernel->getProjectDir() . '/.env');
|
||||
require_once dirname(__DIR__).'/vendor/autoload_runtime.php';
|
||||
|
||||
ini_set('date.timezone', $_ENV['TZ']);
|
||||
|
||||
$kernel->handle()->send();
|
||||
return function (array $context) {
|
||||
return new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);
|
||||
};
|
||||
|
|
|
@ -1,25 +1,29 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace JeroenED\Webcron\Command;
|
||||
namespace App\Command;
|
||||
|
||||
|
||||
use App\Entity\Run;
|
||||
use Doctrine\DBAL\Exception;
|
||||
use JeroenED\Framework\Kernel;
|
||||
use JeroenED\Webcron\Repository\Run;
|
||||
use App\Repository\RunRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\HttpKernel\KernelInterface;
|
||||
|
||||
class CleanupCommand extends Command
|
||||
{
|
||||
protected static $defaultName = 'cleanup';
|
||||
protected $kernel;
|
||||
protected $doctrine;
|
||||
|
||||
public function __construct(Kernel $kernel)
|
||||
public function __construct(KernelInterface $kernel, ManagerRegistry $doctrine)
|
||||
{
|
||||
$this->kernel = $kernel;
|
||||
$this->doctrine = $doctrine;
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
@ -36,7 +40,7 @@ class CleanupCommand extends Command
|
|||
{
|
||||
$maxage = $input->getOption('maxage');
|
||||
$jobs = $input->getOption('jobid');
|
||||
$runRepo = new Run($this->kernel->getDbCon());
|
||||
$runRepo = $this->doctrine->getRepository(Run::class);
|
||||
try {
|
||||
$deleted = $runRepo->cleanupRuns($jobs, $maxage);
|
||||
$output->writeln('Deleted ' . $deleted . ' runs');
|
||||
|
|
|
@ -1,14 +1,16 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace JeroenED\Webcron\Command;
|
||||
namespace App\Command;
|
||||
|
||||
use JeroenED\Framework\Kernel;
|
||||
use JeroenED\Webcron\Repository\Job;
|
||||
use App\Entity\Job;
|
||||
use App\Repository\JobRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\HttpKernel\KernelInterface;
|
||||
|
||||
|
||||
class DaemonCommand extends Command
|
||||
|
@ -16,10 +18,13 @@ class DaemonCommand extends Command
|
|||
|
||||
protected static $defaultName = 'daemon';
|
||||
protected $kernel;
|
||||
protected $doctrine;
|
||||
|
||||
public function __construct(Kernel $kernel)
|
||||
public function __construct(KernelInterface $kernel, ManagerRegistry $doctrine)
|
||||
{
|
||||
$this->kernel = $kernel;
|
||||
$this->doctrine = $doctrine;
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
@ -33,7 +38,7 @@ class DaemonCommand extends Command
|
|||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$jobRepo = new Job($this->kernel->getDbCon());
|
||||
$jobRepo = $this->doctrine->getRepository(Job::class);
|
||||
$timelimit = $input->getOption('time-limit') ?? false;
|
||||
if ($timelimit === false) {
|
||||
$endofscript = false;
|
||||
|
@ -63,8 +68,8 @@ class DaemonCommand extends Command
|
|||
declare(ticks = 1);
|
||||
pcntl_signal(SIGCHLD, SIG_IGN);
|
||||
$pid = pcntl_fork();
|
||||
$jobRepo = NULL;
|
||||
$jobRepo = new Job($this->kernel->getNewDbCon());
|
||||
$this->doctrine->getConnection()->close();
|
||||
$jobRepo = $this->doctrine->getRepository(Job::class);
|
||||
if($pid == -1) {
|
||||
$jobRepo->RunJob($job['id'], $job['running'] == 2);
|
||||
$jobRepo->setJobRunning($job['id'], false);
|
||||
|
|
|
@ -1,14 +1,13 @@
|
|||
<?php
|
||||
|
||||
namespace JeroenED\Webcron\Command;
|
||||
namespace App\Command;
|
||||
|
||||
use JeroenED\Framework\Kernel;
|
||||
use JeroenED\Framework\Twig;
|
||||
use JeroenED\Webcron\Repository\Job;
|
||||
use JeroenED\Webcron\Repository\User;
|
||||
use App\Repository\JobRepository;
|
||||
use App\Repository\UserRepository;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\HttpKernel\KernelInterface;
|
||||
use Symfony\Component\Mailer\Mailer;
|
||||
use Symfony\Component\Mailer\Transport;
|
||||
use Symfony\Component\Mime\Address;
|
||||
|
@ -19,7 +18,7 @@ class MailFailedRunsCommand extends Command
|
|||
protected static $defaultName = 'mail-failed-runs';
|
||||
protected $kernel;
|
||||
|
||||
public function __construct(Kernel $kernel)
|
||||
public function __construct(KernelInterface $kernel)
|
||||
{
|
||||
$this->kernel = $kernel;
|
||||
parent::__construct();
|
||||
|
@ -35,8 +34,8 @@ class MailFailedRunsCommand extends Command
|
|||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
|
||||
$userRepo = new User($this->kernel->getDbCon());
|
||||
$jobRepo = new Job($this->kernel->getDbCon());
|
||||
$userRepo = new UserRepository($this->kernel->getDbCon());
|
||||
$runRepo = $this->getEntityManager()->getRepository(Run::class);
|
||||
|
||||
$failedJobs = $jobRepo->getFailingJobs();
|
||||
|
||||
|
|
|
@ -1,23 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace JeroenED\Webcron\Command;
|
||||
namespace App\Command;
|
||||
|
||||
use JeroenED\Framework\Kernel;
|
||||
use JeroenED\Framework\Repository;
|
||||
use JeroenED\Webcron\Repository\Job;
|
||||
use JeroenED\Webcron\Repository\Run;
|
||||
use App\Repository\JobRepository;
|
||||
use App\Repository\RunRepository;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\HttpKernel\KernelInterface;
|
||||
|
||||
class RunCommand extends Command
|
||||
{
|
||||
protected static $defaultName = 'run';
|
||||
protected $kernel;
|
||||
|
||||
public function __construct(Kernel $kernel)
|
||||
public function __construct(KernelInterface $kernel)
|
||||
{
|
||||
$this->kernel = $kernel;
|
||||
parent::__construct();
|
||||
|
@ -26,18 +25,18 @@ class RunCommand extends Command
|
|||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setDescription('Run a single cronjob')
|
||||
->setDescription('RunRepository a single cronjob')
|
||||
->setHelp('This command runs a single command')
|
||||
->addArgument('jobid', InputArgument::REQUIRED, 'The id of the job to be run');
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$jobRepo = new Job($this->kernel->getDbCon());
|
||||
$runRepo = $this->getEntityManager()->getRepository(Run::class);
|
||||
$jobId = (int)$input->getArgument('jobid');
|
||||
$jobRunning = $jobRepo->isLockedJob($jobId);
|
||||
if($jobRunning) {
|
||||
$output->writeln('Job is already running');
|
||||
$output->writeln('JobRepository is already running');
|
||||
return Command::FAILURE;
|
||||
}
|
||||
$jobRepo->setJobRunning($jobId, true);
|
||||
|
@ -57,10 +56,10 @@ class RunCommand extends Command
|
|||
$jobRepo->setTempVar($jobId, 'consolerun', false);
|
||||
$output->write($result['output']);
|
||||
if($result['success']) {
|
||||
$output->writeln('Job succeeded with in ' . number_format($result['runtime'], 3) . 'secs with exitcode ' . $result['exitcode']);
|
||||
$output->writeln('JobRepository succeeded with in ' . number_format($result['runtime'], 3) . 'secs with exitcode ' . $result['exitcode']);
|
||||
return Command::SUCCESS;
|
||||
} else {
|
||||
$output->writeln('Job failed in ' . number_format($result['runtime'], 3) . 'secs with exitcode ' . $result['exitcode']);
|
||||
$output->writeln('JobRepository failed in ' . number_format($result['runtime'], 3) . 'secs with exitcode ' . $result['exitcode']);
|
||||
return Command::FAILURE;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,101 +1,86 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace JeroenED\Webcron\Controller;
|
||||
namespace App\Controller;
|
||||
|
||||
use JeroenED\Framework\Controller;
|
||||
use JeroenED\Framework\Repository;
|
||||
use JeroenED\Webcron\Repository\Job;
|
||||
use JeroenED\Webcron\Repository\Run;
|
||||
use App\Entity\Job;
|
||||
use App\Entity\Run;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class JobController extends Controller
|
||||
class JobController extends AbstractController
|
||||
{
|
||||
public function DefaultAction()
|
||||
public function defaultAction(ManagerRegistry $doctrine): Response
|
||||
{
|
||||
if(!isset($_SESSION['isAuthenticated']) || !$_SESSION['isAuthenticated']) {
|
||||
return new RedirectResponse($this->generateRoute('login'));
|
||||
}
|
||||
$jobRepo = new Job($this->getDbCon());
|
||||
$jobRepo = $doctrine->getRepository(Job::class);
|
||||
$jobs = $jobRepo->getAllJobs();
|
||||
return $this->render('job/index.html.twig', ['jobs' => $jobs]);
|
||||
}
|
||||
|
||||
public function jobAction($id, $all = false)
|
||||
public function jobAction(Request $request, ManagerRegistry $doctrine, $id, $all = false): Response
|
||||
{
|
||||
if(!isset($_SESSION['isAuthenticated']) || !$_SESSION['isAuthenticated']) {
|
||||
return new RedirectResponse($this->generateRoute('login'));
|
||||
}
|
||||
$jobRepo = new Job($this->getDbCon());
|
||||
$runRepo = new Run($this->getDbCon());
|
||||
$jobRepo = $doctrine->getRepository(Job::class);
|
||||
$runRepo = $doctrine->getRepository(Run::class);
|
||||
|
||||
if($this->getRequest()->getMethod() == 'GET') {
|
||||
if($request->getMethod() == 'GET') {
|
||||
$job = $jobRepo->getJob($id);
|
||||
$runs = $runRepo->getRunsForJob($id, $all != 'all');
|
||||
return $this->render('job/view.html.twig', ['job' => $job, 'runs' => $runs, 'allruns' => $all == 'all']);
|
||||
} elseif($this->getRequest()->getMethod() == 'DELETE') {
|
||||
} elseif($request->getMethod() == 'DELETE') {
|
||||
$success = $jobRepo->deleteJob($id);
|
||||
$this->addFlash('success', $success['message']);
|
||||
return new JsonResponse(['return_path' => $this->generateRoute('job_index')]);
|
||||
return new JsonResponse(['return_path' => $this->GenerateUrl('job_index')]);
|
||||
}
|
||||
}
|
||||
|
||||
public function editAction($id)
|
||||
public function editAction(Request $request, ManagerRegistry $doctrine, $id)
|
||||
{
|
||||
if(!isset($_SESSION['isAuthenticated']) || !$_SESSION['isAuthenticated']) {
|
||||
return new RedirectResponse($this->generateRoute('login'));
|
||||
}
|
||||
if($this->getRequest()->getMethod() == 'GET') {
|
||||
$jobRepo = new Job($this->getDbCon());
|
||||
if($request->getMethod() == 'GET') {
|
||||
$jobRepo = $doctrine->getRepository(Job::class);
|
||||
$job = $jobRepo->getJob($id, true);
|
||||
return $this->render('job/edit.html.twig', $job);
|
||||
} elseif($this->getRequest()->getMethod() == 'POST') {
|
||||
$allValues = $this->getRequest()->request->all();
|
||||
$jobRepo = new Job($this->getDbCon());
|
||||
} elseif($request->getMethod() == 'POST') {
|
||||
$allValues = $request->request->all();
|
||||
$jobRepo = $doctrine->getRepository(Job::class);
|
||||
|
||||
try {
|
||||
$joboutput = $jobRepo->editJob($id, $allValues);
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
$this->addFlash('danger', $e->getMessage());
|
||||
return new RedirectResponse($this->generateRoute('job_edit', ['id' => $allValues['id']]));
|
||||
return new RedirectResponse($this->GenerateUrl('job_edit', ['id' => $allValues['id']]));
|
||||
}
|
||||
$this->addFlash('success', $joboutput['message']);
|
||||
return new RedirectResponse($this->generateRoute('job_index'));
|
||||
return new RedirectResponse($this->GenerateUrl('job_index'));
|
||||
}
|
||||
}
|
||||
|
||||
public function addAction()
|
||||
public function addAction(Request $request, ManagerRegistry $doctrine)
|
||||
{
|
||||
if(!isset($_SESSION['isAuthenticated']) || !$_SESSION['isAuthenticated']) {
|
||||
return new RedirectResponse($this->generateRoute('login'));
|
||||
}
|
||||
|
||||
if($this->getRequest()->getMethod() == 'GET') {
|
||||
return $this->render('job/add.html.twig');
|
||||
} elseif ($this->getRequest()->getMethod() == 'POST') {
|
||||
$allValues = $this->getRequest()->request->all();
|
||||
$jobRepo = new Job($this->getDbCon());
|
||||
if($request->getMethod() == 'GET') {
|
||||
return $this->render('job/add.html.twig', ['data' => []]);
|
||||
} elseif ($request->getMethod() == 'POST') {
|
||||
$allValues = $request->request->all();
|
||||
$jobRepo = $doctrine->getRepository(Job::class);
|
||||
try {
|
||||
$joboutput = $jobRepo->addJob($allValues);
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
$this->addFlash('danger', $e->getMessage());
|
||||
return new RedirectResponse($this->generateRoute('job_add'));
|
||||
return new RedirectResponse($this->GenerateUrl('job_add'));
|
||||
}
|
||||
$this->addFlash('success', $joboutput['message']);
|
||||
return new RedirectResponse($this->generateRoute('job_index'));
|
||||
return new RedirectResponse($this->GenerateUrl('job_index'));
|
||||
} else {
|
||||
return new Response('Not implemented yet', Response::HTTP_TOO_EARLY);
|
||||
}
|
||||
}
|
||||
|
||||
public function runNowAction(int $id) {
|
||||
if(!isset($_SESSION['isAuthenticated']) || !$_SESSION['isAuthenticated']) {
|
||||
return new RedirectResponse($this->generateRoute('login'));
|
||||
}
|
||||
if($this->getRequest()->getMethod() == 'GET') {
|
||||
$jobRepo = new Job($this->getDbCon());
|
||||
public function runNowAction(Request $request, ManagerRegistry $doctrine, int $id) {
|
||||
if($request->getMethod() == 'GET') {
|
||||
$jobRepo = $doctrine->getRepository(Job::class);
|
||||
return new JsonResponse($jobRepo->runNow($id));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,66 +1,37 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace JeroenED\Webcron\Controller;
|
||||
namespace App\Controller;
|
||||
|
||||
use JeroenED\Framework\Controller;
|
||||
use JeroenED\Webcron\Repository\User;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
|
||||
|
||||
class SecurityController extends Controller
|
||||
class SecurityController extends AbstractController
|
||||
{
|
||||
public function loginAction(): Response
|
||||
public function loginAction(AuthenticationUtils $authenticationUtils): Response
|
||||
{
|
||||
if(isset($_SESSION['isAuthenticated']) && $_SESSION['isAuthenticated']) {
|
||||
return new RedirectResponse($this->generateRoute('default'));
|
||||
} elseif(isset($_COOKIE['autologin_enable']) && $_COOKIE['autologin_enable'] == true) {
|
||||
$userRepository = new User($this->getDbCon());
|
||||
$userId = $userRepository->checkAuthentication($_COOKIE['autologin_user'], $_COOKIE['autologin_auth'], true);
|
||||
if($userId !== false) {
|
||||
$_SESSION['user.id'] = $userId;
|
||||
$_SESSION['isAuthenticated'] = true;
|
||||
} else {
|
||||
return new RedirectResponse($this->generateRoute('logout'));
|
||||
}
|
||||
return new RedirectResponse($this->generateRoute('default'));
|
||||
}
|
||||
return $this->render('security/login.html.twig');
|
||||
// get the login error if there is one
|
||||
$error = $authenticationUtils->getLastAuthenticationError();
|
||||
|
||||
// last username entered by the user
|
||||
$lastUsername = $authenticationUtils->getLastUsername();
|
||||
|
||||
return $this->render('security/login.html.twig', [
|
||||
'controller_name' => 'LoginController',
|
||||
'last_username' => $lastUsername,
|
||||
'error' => $error
|
||||
]);
|
||||
}
|
||||
|
||||
public function logoutAction(): Response
|
||||
public function logoutAction(): void
|
||||
{
|
||||
$_SESSION['isAuthenticated'] = false;
|
||||
unset($_SESSION['user.id']);
|
||||
unset($_COOKIE['autologin_auth']);
|
||||
unset($_COOKIE['autologin_user']);
|
||||
unset($_COOKIE['autologin_enable']);
|
||||
setcookie('autologin_auth', "", time() - 3600);
|
||||
setcookie('autologin_user', "", time() - 3600);
|
||||
setcookie('autologin_enable', "", time() - 3600);
|
||||
$this->addFlash('success', 'Successfully logged out');
|
||||
return new RedirectResponse($this->generateRoute('login'));
|
||||
// controller can be blank: it will never be called!
|
||||
throw new \Exception('Don\'t forget to activate logout in security.yaml');
|
||||
}
|
||||
|
||||
public function loginCheckAction(): Response
|
||||
{
|
||||
$request = $this->getRequest();
|
||||
$userRepository = new User($this->getDbCon());
|
||||
$credentials = $request->request->all();
|
||||
$userId = $userRepository->checkAuthentication($credentials['name'], $credentials['passwd']);
|
||||
if($userId !== false) {
|
||||
$_SESSION['user.id'] = $userId;
|
||||
$_SESSION['isAuthenticated'] = true;
|
||||
|
||||
if(isset($credentials['autologin'])) {
|
||||
$token = $userRepository->createAutologinToken($credentials['passwd']);
|
||||
setcookie('autologin_auth', $token, time() + $_ENV['COOKIE_LIFETIME'], "/");
|
||||
setcookie('autologin_user', $credentials['name'], time() + $_ENV['COOKIE_LIFETIME'], "/");
|
||||
setcookie('autologin_enable', true, time() + $_ENV['COOKIE_LIFETIME'], "/");
|
||||
}
|
||||
return new RedirectResponse($this->generateRoute('default'));
|
||||
}
|
||||
$this->addFlash('danger', 'Login Failed');
|
||||
return new RedirectResponse($this->generateRoute('login'));
|
||||
}
|
||||
}
|
|
@ -1,17 +1,20 @@
|
|||
<?php
|
||||
|
||||
namespace JeroenED\Webcron\Controller;
|
||||
namespace App\Controller;
|
||||
|
||||
use JeroenED\Framework\Controller;
|
||||
use JeroenED\Webcron\Repository\Job;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\KernelInterface;
|
||||
|
||||
class SiteController extends Controller
|
||||
class SiteController extends AbstractController
|
||||
{
|
||||
public function HealthAction()
|
||||
|
||||
public function healthAction(Request $request, ManagerRegistry $doctrine, KernelInterface $kernel)
|
||||
{
|
||||
global $kernel;
|
||||
$jobRepo = new Job($this->getDbCon());
|
||||
$em = $doctrine->getManager();
|
||||
$jobRepo = $em->getRepository('App:Job');
|
||||
$return = [
|
||||
"DaemonRunning" => file_exists($kernel->getCacheDir() . '/daemon-running.lock'),
|
||||
"JobsTotal" => count($jobRepo->getAllJobs()),
|
||||
|
|
|
@ -0,0 +1,182 @@
|
|||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\JobRepository;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity(repositoryClass: JobRepository::class)]
|
||||
class Job
|
||||
{
|
||||
/**
|
||||
* @var int|null
|
||||
*/
|
||||
#[ORM\Id()]
|
||||
#[ORM\GeneratedValue(strategy: "AUTO")]
|
||||
#[ORM\Column(type: "integer")]
|
||||
private ?int $id;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
#[ORM\Column(type: "string", length: 100)]
|
||||
private string $name;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
#[ORM\Column(type: "text")]
|
||||
private string $data;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
#[ORM\Column(type: "integer")]
|
||||
private int $interval;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
#[ORM\Column(type: "integer")]
|
||||
private int $nextrun;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
#[ORM\Column(type: "integer", nullable: true)]
|
||||
private int $lastrun;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
#[ORM\Column(type: "integer")]
|
||||
private int $running;
|
||||
|
||||
/**
|
||||
* @return int|null
|
||||
*/
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int|null $id
|
||||
* @return Job
|
||||
*/
|
||||
public function setId(?int $id): Job
|
||||
{
|
||||
$this->id = $id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @return Job
|
||||
*/
|
||||
public function setName(string $name): Job
|
||||
{
|
||||
$this->name = $name;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getData(): array
|
||||
{
|
||||
return json_decode($this->data, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @return Job
|
||||
*/
|
||||
public function setData(array $data): Job
|
||||
{
|
||||
$this->data = json_encode($data);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getInterval(): int
|
||||
{
|
||||
return $this->interval;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $interval
|
||||
* @return Job
|
||||
*/
|
||||
public function setInterval(int $interval): Job
|
||||
{
|
||||
$this->interval = $interval;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getNextrun(): int
|
||||
{
|
||||
return $this->nextrun;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $nextrun
|
||||
* @return Job
|
||||
*/
|
||||
public function setNextrun(int $nextrun): Job
|
||||
{
|
||||
$this->nextrun = $nextrun;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getLastrun(): int
|
||||
{
|
||||
return $this->lastrun;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $lastrun
|
||||
* @return Job
|
||||
*/
|
||||
public function setLastrun(int $lastrun): Job
|
||||
{
|
||||
$this->lastrun = $lastrun;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getRunning(): int
|
||||
{
|
||||
return $this->running;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $running
|
||||
* @return Job
|
||||
*/
|
||||
public function setRunning(int $running): Job
|
||||
{
|
||||
$this->running = $running;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,186 @@
|
|||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\RunRepository;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
#[ORM\Entity(repositoryClass: RunRepository::class)]
|
||||
class Run
|
||||
{
|
||||
/**
|
||||
* @var int|null
|
||||
*/
|
||||
#[ORM\Id()]
|
||||
#[ORM\GeneratedValue(strategy: "AUTO")]
|
||||
#[ORM\Column(type: "integer")]
|
||||
private ?int $id;
|
||||
|
||||
|
||||
/**
|
||||
* @var Job
|
||||
*/
|
||||
#[ORM\ManyToOne(targetEntity: "Job")]
|
||||
#[ORM\JoinColumn(name: "job_id", referencedColumnName: "id")]
|
||||
private Job $job;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
#[ORM\Column(type: "string", length: 15)]
|
||||
private string $exitcode;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
#[ORM\Column(type: "text")]
|
||||
private string $output;
|
||||
|
||||
/**
|
||||
* @var float
|
||||
*/
|
||||
#[ORM\Column(type: "float")]
|
||||
private float $runtime;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
#[ORM\Column(type: "integer")]
|
||||
private int $timestamp;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
#[ORM\Column(type: "string", length: 5)]
|
||||
private string $flags;
|
||||
|
||||
/**
|
||||
* @return int|null
|
||||
*/
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int|null $id
|
||||
* @return Run
|
||||
*/
|
||||
public function setId(?int $id): Run
|
||||
{
|
||||
$this->id = $id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Job
|
||||
*/
|
||||
public function getJob(): Job
|
||||
{
|
||||
return $this->job;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Job $job
|
||||
* @return Run
|
||||
*/
|
||||
public function setJob(Job $job): Run
|
||||
{
|
||||
$this->job = $job;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getExitcode(): string
|
||||
{
|
||||
return $this->exitcode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $exitcode
|
||||
* @return Run
|
||||
*/
|
||||
public function setExitcode(string $exitcode): Run
|
||||
{
|
||||
$this->exitcode = $exitcode;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getOutput(): string
|
||||
{
|
||||
return $this->output;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $output
|
||||
* @return Run
|
||||
*/
|
||||
public function setOutput(string $output): Run
|
||||
{
|
||||
$this->output = $output;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float
|
||||
*/
|
||||
public function getRuntime(): float
|
||||
{
|
||||
return $this->runtime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $runtime
|
||||
* @return Run
|
||||
*/
|
||||
public function setRuntime(float $runtime): Run
|
||||
{
|
||||
$this->runtime = $runtime;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTimestamp(): int
|
||||
{
|
||||
return $this->timestamp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $timestamp
|
||||
* @return Run
|
||||
*/
|
||||
public function setTimestamp(int $timestamp): Run
|
||||
{
|
||||
$this->timestamp = $timestamp;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getFlags(): string
|
||||
{
|
||||
return $this->flags;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $flags
|
||||
* @return Run
|
||||
*/
|
||||
public function setFlags(string $flags): Run
|
||||
{
|
||||
$this->flags = $flags;
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,125 @@
|
|||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\UserRepository;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Security\Core\User\UserInterface;
|
||||
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
|
||||
|
||||
#[ORM\Entity(repositoryClass: UserRepository::class)]
|
||||
class User implements UserInterface, PasswordAuthenticatedUserInterface
|
||||
{
|
||||
/**
|
||||
* @var int|null
|
||||
*/
|
||||
#[ORM\Id()]
|
||||
#[ORM\GeneratedValue(strategy: "AUTO")]
|
||||
#[ORM\Column(type: "integer")]
|
||||
private ?int $id;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
#[ORM\Column(type: "string", length: 100)]
|
||||
private string $email;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
#[ORM\Column(type: "string", length: 60)]
|
||||
private string $password;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
#[ORM\Column(type: "boolean")]
|
||||
private bool $sendmail;
|
||||
|
||||
/**
|
||||
* @return int|null
|
||||
*/
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int|null $id
|
||||
* @return User
|
||||
*/
|
||||
public function setId(?int $id): User
|
||||
{
|
||||
$this->id = $id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getEmail(): string
|
||||
{
|
||||
return $this->email;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $email
|
||||
* @return User
|
||||
*/
|
||||
public function setEmail(string $email): User
|
||||
{
|
||||
$this->email = $email;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPassword(): string
|
||||
{
|
||||
return $this->password;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $password
|
||||
* @return User
|
||||
*/
|
||||
public function setPassword(string $password): User
|
||||
{
|
||||
$this->password = $password;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isSendmail(): bool
|
||||
{
|
||||
return $this->sendmail;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $sendmail
|
||||
* @return User
|
||||
*/
|
||||
public function setSendmail(bool $sendmail): User
|
||||
{
|
||||
$this->sendmail = $sendmail;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getRoles(): array
|
||||
{
|
||||
return array_unique(['ROLE_USER']);
|
||||
}
|
||||
|
||||
public function eraseCredentials()
|
||||
{
|
||||
// TODO: Implement eraseCredentials() method.
|
||||
}
|
||||
|
||||
public function getUserIdentifier(): string
|
||||
{
|
||||
return (string) $this->email;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
|
||||
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
|
||||
|
||||
class Kernel extends BaseKernel
|
||||
{
|
||||
use MicroKernelTrait;
|
||||
}
|
|
@ -1,24 +1,26 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace JeroenED\Webcron\Repository;
|
||||
namespace App\Repository;
|
||||
|
||||
|
||||
use App\Entity\Run;
|
||||
use App\Service\Secret;
|
||||
use DateTime;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use JeroenED\Framework\Repository;
|
||||
use phpseclib3\Crypt\PublicKeyLoader;
|
||||
use phpseclib3\Net\SSH2;
|
||||
|
||||
class Job extends Repository
|
||||
class JobRepository extends EntityRepository
|
||||
{
|
||||
public function getFailingJobs()
|
||||
{
|
||||
$runRepo = new Run($this->dbcon);
|
||||
$runRepo = $this->getEntityManager()->getRepository(Run::class);
|
||||
|
||||
$jobsSql = "SELECT * FROM job";
|
||||
$jobsStmt = $this->dbcon->prepare($jobsSql);
|
||||
$jobsStmt = $this->getEntityManager()->getConnection()->prepare($jobsSql);
|
||||
$jobsRslt = $jobsStmt->executeQuery();
|
||||
$jobs = $jobsRslt->fetchAllAssociative();
|
||||
foreach ($jobs as $key=>&$job) {
|
||||
|
@ -48,10 +50,10 @@ class Job extends Repository
|
|||
|
||||
public function getRunningJobs(bool $idiskey = false)
|
||||
{
|
||||
$runRepo = new Run($this->dbcon);
|
||||
$runRepo = $this->getEntityManager()->getRepository(Run::class);
|
||||
|
||||
$jobsSql = "SELECT * FROM job WHERE running != 0;";
|
||||
$jobsStmt = $this->dbcon->prepare($jobsSql);
|
||||
$jobsStmt = $this->getEntityManager()->getConnection()->prepare($jobsSql);
|
||||
$jobsRslt = $jobsStmt->executeQuery();
|
||||
$jobs = $jobsRslt->fetchAllAssociative();
|
||||
$returnbyid = [];
|
||||
|
@ -82,10 +84,9 @@ class Job extends Repository
|
|||
|
||||
public function getAllJobs(bool $idiskey = false)
|
||||
{
|
||||
$runRepo = new Run($this->dbcon);
|
||||
|
||||
$runRepo = $this->getEntityManager()->getRepository(Run::class);
|
||||
$jobsSql = "SELECT * FROM job";
|
||||
$jobsStmt = $this->dbcon->prepare($jobsSql);
|
||||
$jobsStmt = $this->getEntityManager()->getConnection()->prepare($jobsSql);
|
||||
$jobsRslt = $jobsStmt->executeQuery();
|
||||
$jobs = $jobsRslt->fetchAllAssociative();
|
||||
$returnbyid = [];
|
||||
|
@ -117,12 +118,12 @@ class Job extends Repository
|
|||
public function getErrorRatio(int $jobId): bool
|
||||
{
|
||||
$errorSql = "SELECT count(*) as count FROM job WHERE id = :id";
|
||||
$errorStmt = $this->dbcon->prepare($errorSql);
|
||||
$errorStmt = $this->getEntityManager()->getConnection()->prepare($errorSql);
|
||||
$errorRslt = $errorStmt->executeQuery([':timestamp' => time(), ':timestamplastrun' => time(), ':timestamprun' => time()]);
|
||||
$error = $errorRslt->fetchAllAssociative();
|
||||
|
||||
$errorSql = "SELECT count(*) as count FROM job WHERE id = :id";
|
||||
$errorStmt = $this->dbcon->prepare($errorSql);
|
||||
$errorStmt = $this->getEntityManager()->getConnection()->prepare($errorSql);
|
||||
$errorRslt = $errorStmt->executeQuery([':timestamp' => time(), ':timestamplastrun' => time(), ':timestamprun' => time()]);
|
||||
$error = $errorRslt->fetchAllAssociative();
|
||||
}
|
||||
|
@ -138,7 +139,7 @@ class Job extends Repository
|
|||
)
|
||||
OR (running NOT IN (0,1,2) AND running < :timestamprun)
|
||||
OR (running = 2)";
|
||||
$jobsStmt = $this->dbcon->prepare($jobsSql);
|
||||
$jobsStmt = $this->getEntityManager()->getConnection()->prepare($jobsSql);
|
||||
$jobsRslt = $jobsStmt->executeQuery([':timestamp' => time(), ':timestamplastrun' => time(), ':timestamprun' => time()]);
|
||||
$jobs = $jobsRslt->fetchAllAssociative();
|
||||
return $jobs;
|
||||
|
@ -151,7 +152,7 @@ class Job extends Repository
|
|||
WHERE running = 0 and nextrun != :time
|
||||
ORDER BY nextrun
|
||||
LIMIT 1";
|
||||
$jobsStmt = $this->dbcon->prepare($jobsSql);
|
||||
$jobsStmt = $this->getEntityManager()->getConnection()->prepare($jobsSql);
|
||||
$jobsRslt = $jobsStmt->executeQuery([':time' => time()]);
|
||||
$nextjob = $jobsRslt->fetchAssociative();
|
||||
|
||||
|
@ -161,7 +162,7 @@ class Job extends Repository
|
|||
WHERE running = 2
|
||||
ORDER BY nextrun
|
||||
LIMIT 1";
|
||||
$jobsStmt = $this->dbcon->prepare($jobsSql);
|
||||
$jobsStmt = $this->getEntityManager()->getConnection()->prepare($jobsSql);
|
||||
$jobsRslt = $jobsStmt->executeQuery();
|
||||
$manualjob = $jobsRslt->fetchAssociative();
|
||||
|
||||
|
@ -179,7 +180,7 @@ class Job extends Repository
|
|||
WHERE running > 2
|
||||
ORDER BY nextrun DESC
|
||||
LIMIT 1";
|
||||
$jobsStmt = $this->dbcon->prepare($jobsSql);
|
||||
$jobsStmt = $this->getEntityManager()->getConnection()->prepare($jobsSql);
|
||||
$jobsRslt = $jobsStmt->executeQuery();
|
||||
$running = $jobsRslt->fetchAssociative();
|
||||
|
||||
|
@ -193,7 +194,7 @@ class Job extends Repository
|
|||
public function setJobRunning(int $job, bool $status): void
|
||||
{
|
||||
$jobsSql = "UPDATE job SET running = :status WHERE id = :id AND running IN (0,1,2)";
|
||||
$jobsStmt = $this->dbcon->prepare($jobsSql);
|
||||
$jobsStmt = $this->getEntityManager()->getConnection()->prepare($jobsSql);
|
||||
$jobsStmt->executeQuery([':id' => $job, ':status' => $status ? 1 : 0]);
|
||||
return;
|
||||
}
|
||||
|
@ -201,14 +202,14 @@ class Job extends Repository
|
|||
public function setTempVar(int $job, string $name, mixed $value): void
|
||||
{
|
||||
$jobsSql = "SELECT data FROM job WHERE id = :id";
|
||||
$jobsStmt = $this->dbcon->prepare($jobsSql);
|
||||
$jobsStmt = $this->getEntityManager()->getConnection()->prepare($jobsSql);
|
||||
$result = $jobsStmt->executeQuery([':id' => $job])->fetchAssociative();
|
||||
$result = json_decode($result['data'], true);
|
||||
$result['temp_vars'][$name] = $value;
|
||||
|
||||
|
||||
$jobsSql = "UPDATE job SET data = :data WHERE id = :id";
|
||||
$jobsStmt = $this->dbcon->prepare($jobsSql);
|
||||
$jobsStmt = $this->getEntityManager()->getConnection()->prepare($jobsSql);
|
||||
$jobsStmt->executeQuery([':id' => $job, ':data' => json_encode($result)]);
|
||||
return;
|
||||
}
|
||||
|
@ -216,13 +217,13 @@ class Job extends Repository
|
|||
public function deleteTempVar(int $job, string $name): void
|
||||
{
|
||||
$jobsSql = "SELECT data FROM job WHERE id = :id";
|
||||
$jobsStmt = $this->dbcon->prepare($jobsSql);
|
||||
$jobsStmt = $this->getEntityManager()->getConnection()->prepare($jobsSql);
|
||||
$result = $jobsStmt->executeQuery([':id' => $job])->fetchAssociative();
|
||||
$result = json_decode($result['data'], true);
|
||||
unset($result['temp_vars'][$name]);
|
||||
|
||||
$jobsSql = "UPDATE job SET data = :data WHERE id = :id";
|
||||
$jobsStmt = $this->dbcon->prepare($jobsSql);
|
||||
$jobsStmt = $this->getEntityManager()->getConnection()->prepare($jobsSql);
|
||||
$jobsStmt->executeQuery([':id' => $job, ':data' => json_encode($result)]);
|
||||
return;
|
||||
}
|
||||
|
@ -230,7 +231,7 @@ class Job extends Repository
|
|||
public function getTempVar(int $job, string $name, mixed $default = NULL): mixed
|
||||
{
|
||||
$jobsSql = "SELECT data FROM job WHERE id = :id";
|
||||
$jobsStmt = $this->dbcon->prepare($jobsSql);
|
||||
$jobsStmt = $this->getEntityManager()->getConnection()->prepare($jobsSql);
|
||||
$result = $jobsStmt->executeQuery([':id' => $job])->fetchAssociative();
|
||||
$result = json_decode($result['data'], true);
|
||||
return $result['temp_vars'][$name] ?? $default;
|
||||
|
@ -343,16 +344,21 @@ class Job extends Repository
|
|||
}
|
||||
|
||||
$jobsSql = "UPDATE job SET running = :status WHERE id = :id";
|
||||
$jobsStmt = $this->dbcon->prepare($jobsSql);
|
||||
$jobsStmt = $this->getEntityManager()->getConnection()->prepare($jobsSql);
|
||||
$jobsStmt->executeQuery([':id' => $job['id'], ':status' => time() + $job['data']['reboot-delay-secs'] + ($job['data']['reboot-duration'] * 60)]);
|
||||
|
||||
if($job['data']['hosttype'] == 'ssh') {
|
||||
$this->runSshCommand($job['data']['reboot-command'], $job['data']['host'], $job['data']['user'], $job['data']['ssh-privkey'] ?? '', $job['data']['privkey-password'] ?? '');
|
||||
|
||||
} elseif($job['data']['hosttype'] == 'local') {
|
||||
$this->runLocalCommand($job['data']['reboot-command']);
|
||||
try {
|
||||
if($job['data']['hosttype'] == 'local') {
|
||||
$this->runLocalCommand($job['data']['reboot-command']);
|
||||
} elseif($job['data']['hosttype'] == 'ssh') {
|
||||
$this->runSshCommand($job['data']['reboot-command'], $job['data']['host'], $job['data']['user'], $job['data']['ssh-privkey'] ?? '', $job['data']['privkey-password'] ?? '');
|
||||
}
|
||||
} catch (\RuntimeException $exception) {
|
||||
$return['exitcode'] = $exception->getCode();
|
||||
$return['output'] = $exception->getMessage();
|
||||
$return['failed'] = true;
|
||||
return $return;
|
||||
}
|
||||
|
||||
return ['status' => 'deferred'];
|
||||
|
||||
} elseif($job['running'] != 0) {
|
||||
|
@ -365,7 +371,7 @@ class Job extends Repository
|
|||
$this->deleteTempVar($job['id'], 'manual');
|
||||
|
||||
$jobsSql = "UPDATE job SET running = :status WHERE id = :id";
|
||||
$jobsStmt = $this->dbcon->prepare($jobsSql);
|
||||
$jobsStmt = $this->getEntityManager()->getConnection()->prepare($jobsSql);
|
||||
$jobsStmt->executeQuery([':id' => $job['id'], ':status' => 1]);
|
||||
|
||||
if (!empty($job['data']['vars'])) {
|
||||
|
@ -373,10 +379,17 @@ class Job extends Repository
|
|||
$job['data']['getservices-command'] = str_replace('{' . $key . '}', $var['value'], $job['data']['getservices-command']);
|
||||
}
|
||||
}
|
||||
if($job['data']['hosttype'] == 'ssh') {
|
||||
$return = $this->runSshCommand($job['data']['getservices-command'], $job['data']['host'], $job['data']['user'], $job['data']['ssh-privkey'], $job['data']['privkey-password']);
|
||||
} elseif($job['data']['hosttype'] == 'local') {
|
||||
$return = $this->runLocalCommand($job['data']['getservices-command']);
|
||||
try {
|
||||
if($job['data']['hosttype'] == 'local') {
|
||||
$return = $this->runLocalCommand($job['data']['getservices-command']);
|
||||
} elseif($job['data']['hosttype'] == 'ssh') {
|
||||
$return = $this->runSshCommand($job['data']['getservices-command'], $job['data']['host'], $job['data']['user'], $job['data']['ssh-privkey'] ?? '', $job['data']['privkey-password'] ?? '');
|
||||
}
|
||||
} catch (\RuntimeException $exception) {
|
||||
$return['exitcode'] = $exception->getCode();
|
||||
$return['output'] = $exception->getMessage();
|
||||
$return['failed'] = true;
|
||||
return $return;
|
||||
}
|
||||
$return['failed'] = !in_array($return['exitcode'], $job['data']['getservices-response']);
|
||||
return $return;
|
||||
|
@ -385,11 +398,11 @@ class Job extends Repository
|
|||
|
||||
public function runNow($job, $console = false) {
|
||||
$job = $this->getJob($job, true);
|
||||
$runRepo = new Run($this->dbcon);
|
||||
$runRepo = $this->getEntityManager()->getRepository(Run::class);
|
||||
|
||||
if($console == false && ($runRepo->isSlowJob($job['id']) || count($runRepo->getRunsForJob($job['id'])) == 0 || $job['data']['crontype'] === 'reboot')) {
|
||||
$jobsSql = "UPDATE job SET running = :status WHERE id = :id AND running IN (0,1,2)";
|
||||
$jobsStmt = $this->dbcon->prepare($jobsSql);
|
||||
$jobsStmt = $this->getEntityManager()->getConnection()->prepare($jobsSql);
|
||||
$jobsStmt->executeQuery([':id' => $job['id'], ':status' => 2]);
|
||||
} else {
|
||||
$output = $this->runJob($job['id'], true);
|
||||
|
@ -399,8 +412,8 @@ class Job extends Repository
|
|||
'output' => ($console) ? $output['output'] : htmlentities($output['output']),
|
||||
'exitcode' => $output['exitcode'],
|
||||
'runtime' => (float)$output['runtime'],
|
||||
'title' => !str_contains($output['flags'], Run::FAILED) ? 'Cronjob successfully ran' : 'Cronjob failed. Please check output below',
|
||||
'success' => !str_contains($output['flags'], Run::FAILED)
|
||||
'title' => !str_contains($output['flags'], RunRepository::FAILED) ? 'Cronjob successfully ran' : 'Cronjob failed. Please check output below',
|
||||
'success' => !str_contains($output['flags'], RunRepository::FAILED)
|
||||
];
|
||||
}
|
||||
return ['success' => true, 'status' => 'deferred', 'title' => 'Cronjob has been scheduled', 'message' => 'Job was scheduled to be run. You will find the output soon in the job details'];
|
||||
|
@ -433,13 +446,13 @@ class Job extends Repository
|
|||
// setting flags
|
||||
$flags = [];
|
||||
if ($result['failed'] === true) {
|
||||
$flags[] = Run::FAILED;
|
||||
$flags[] = RunRepository::FAILED;
|
||||
} else {
|
||||
$flags[] = Run::SUCCESS;
|
||||
$flags[] = RunRepository::SUCCESS;
|
||||
}
|
||||
|
||||
if ($manual === true) {
|
||||
$flags[] = Run::MANUAL;
|
||||
$flags[] = RunRepository::MANUAL;
|
||||
}
|
||||
|
||||
// Remove secrets from output
|
||||
|
@ -451,8 +464,8 @@ class Job extends Repository
|
|||
}
|
||||
}
|
||||
// saving to database
|
||||
$runRepo = new Run($kernel->getNewDbCon());
|
||||
$this->dbcon = $kernel->getNewDbCon();
|
||||
$this->getEntityManager()->getConnection()->close();
|
||||
$runRepo = $this->getEntityManager()->getRepository(Run::class);
|
||||
$runRepo->addRun($job['id'], $result['exitcode'], floor($starttime), $runtime, $result['output'], $flags);
|
||||
if (!$manual){
|
||||
// setting nextrun to next run
|
||||
|
@ -463,7 +476,7 @@ class Job extends Repository
|
|||
|
||||
|
||||
$addRunSql = 'UPDATE job SET nextrun = :nextrun WHERE id = :id';
|
||||
$addRunStmt = $this->dbcon->prepare($addRunSql);
|
||||
$addRunStmt = $this->getEntityManager()->getConnection()->prepare($addRunSql);
|
||||
$addRunStmt->executeQuery([':id' => $job['id'], ':nextrun' => $nextrun]);
|
||||
}
|
||||
return ['job_id' => $job['id'], 'exitcode' => $result['exitcode'], 'timestamp' =>floor($starttime), 'runtime' => $runtime, 'output' => (string)$result['output'], 'flags' => implode("", $flags)];
|
||||
|
@ -478,7 +491,7 @@ class Job extends Repository
|
|||
$jobsSql .= " AND id = :id";
|
||||
$params[':id'] = $id;
|
||||
}
|
||||
$jobsStmt = $this->dbcon->prepare($jobsSql);
|
||||
$jobsStmt = $this->getEntityManager()->getConnection()->prepare($jobsSql);
|
||||
$jobsStmt->executeQuery($params);
|
||||
return;
|
||||
}
|
||||
|
@ -488,7 +501,7 @@ class Job extends Repository
|
|||
$jobsSql = "SELECT id FROM job WHERE id = :id AND running != :status";
|
||||
$params = [':status' => 0, ':id' => $id];
|
||||
|
||||
return count($this->dbcon->prepare($jobsSql)->executeQuery($params)->fetchAllAssociative()) > 0;
|
||||
return count($this->getEntityManager()->getConnection()->prepare($jobsSql)->executeQuery($params)->fetchAllAssociative()) > 0;
|
||||
}
|
||||
|
||||
public function addJob(array $values)
|
||||
|
@ -505,7 +518,7 @@ class Job extends Repository
|
|||
$data['data'] = json_encode($data['data']);
|
||||
$addJobSql = "INSERT INTO job(name, data, `interval`, nextrun, lastrun, running) VALUES (:name, :data, :interval, :nextrun, :lastrun, :running)";
|
||||
|
||||
$addJobStmt = $this->dbcon->prepare($addJobSql);
|
||||
$addJobStmt = $this->getEntityManager()->getConnection()->prepare($addJobSql);
|
||||
$addJobStmt->executeQuery([':name' => $data['name'], ':data' => $data['data'], ':interval' => $data['interval'], ':nextrun' => $data['nextrun'], ':lastrun' => $data['lastrun'], ':running' => 0]);
|
||||
|
||||
return ['success' => true, 'message' => 'Cronjob succesfully added'];
|
||||
|
@ -524,7 +537,7 @@ class Job extends Repository
|
|||
$data['data'] = json_encode($data['data']);
|
||||
$editJobSql = "UPDATE job SET name = :name, data = :data, `interval` = :interval, nextrun = :nextrun, lastrun = :lastrun WHERE id = :id";
|
||||
|
||||
$editJobStmt = $this->dbcon->prepare($editJobSql);
|
||||
$editJobStmt = $this->getEntityManager()->getConnection()->prepare($editJobSql);
|
||||
$editJobStmt->executeQuery([':name' => $data['name'], ':data' => $data['data'], ':interval' => $data['interval'], ':nextrun' => $data['nextrun'], ':lastrun' => $data['lastrun'],':id' => $id ]);
|
||||
|
||||
return ['success' => true, 'message' => 'Cronjob succesfully edited'];
|
||||
|
@ -657,7 +670,7 @@ class Job extends Repository
|
|||
|
||||
public function getJob(int $id, bool $withSecrets = false) {
|
||||
$jobSql = "SELECT * FROM job WHERE id = :id";
|
||||
$jobStmt = $this->dbcon->prepare($jobSql);
|
||||
$jobStmt = $this->getEntityManager()->getConnection()->prepare($jobSql);
|
||||
$jobRslt = $jobStmt->executeQuery([':id' => $id])->fetchAssociative();
|
||||
|
||||
$jobRslt['data'] = json_decode($jobRslt['data'], true);
|
||||
|
@ -704,8 +717,8 @@ class Job extends Repository
|
|||
|
||||
public function deleteJob(int $id)
|
||||
{
|
||||
$this->dbcon->prepare("DELETE FROM job WHERE id = :id")->executeStatement([':id' => $id]);
|
||||
$this->dbcon->prepare("DELETE FROM run WHERE job_id = :id")->executeStatement([':id' => $id]);
|
||||
$this->getEntityManager()->getConnection()->prepare("DELETE FROM job WHERE id = :id")->executeStatement([':id' => $id]);
|
||||
$this->getEntityManager()->getConnection()->prepare("DELETE FROM run WHERE job_id = :id")->executeStatement([':id' => $id]);
|
||||
|
||||
return ['success' => true, 'message' => 'Cronjob succesfully deleted'];
|
||||
}
|
|
@ -1,13 +1,13 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace JeroenED\Webcron\Repository;
|
||||
namespace App\Repository;
|
||||
|
||||
|
||||
use Doctrine\DBAL\Exception;
|
||||
use JeroenED\Framework\Repository;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
|
||||
class Run extends Repository
|
||||
class RunRepository extends EntityRepository
|
||||
{
|
||||
const FAILED = 'F';
|
||||
const SUCCESS = 'S';
|
||||
|
@ -18,14 +18,14 @@ class Run extends Repository
|
|||
$runsSql = "SELECT * FROM run WHERE job_id = :job";
|
||||
$params = [':job' => $id];
|
||||
if ($onlyfailed) {
|
||||
$runsSql .= ' AND flags LIKE "%' . Run::FAILED . '%"';
|
||||
$runsSql .= ' AND flags LIKE "%' . RunRepository::FAILED . '%"';
|
||||
}
|
||||
if($maxage !== NULL) {
|
||||
$runsSql .= ' AND timestamp > :timestamp';
|
||||
$params[':timestamp'] = time() - ($maxage * 24 * 60 * 60);
|
||||
}
|
||||
if ($ordered) $runsSql .= ' ORDER by timestamp DESC';
|
||||
$runsStmt = $this->dbcon->prepare($runsSql);
|
||||
$runsStmt = $this->getEntityManager()->getConnection()->prepare($runsSql);
|
||||
$runsRslt = $runsStmt->executeQuery($params);
|
||||
$runs = $runsRslt->fetchAllAssociative();
|
||||
return $runs;
|
||||
|
@ -35,27 +35,27 @@ class Run extends Repository
|
|||
{
|
||||
// handling of response
|
||||
$addRunSql = 'INSERT INTO run(job_id, exitcode, output, runtime, timestamp,flags) VALUES (:job_id, :exitcode, :output, :runtime, :timestamp, :flags)';
|
||||
$addRunStmt = $this->dbcon->prepare($addRunSql);
|
||||
$addRunStmt = $this->getEntityManager()->getConnection()->prepare($addRunSql);
|
||||
$addRunStmt->executeQuery([':job_id' => $jobid, ':exitcode' => $exitcode, 'output' => $output, 'runtime' => $runtime, ':timestamp' => $starttime, ':flags' => implode("", $flags)]);
|
||||
}
|
||||
|
||||
public function getLastRun(int $jobid): array
|
||||
{
|
||||
$lastRunSql = 'SELECT * FROM run WHERE job_id = :jobid ORDER BY timestamp DESC LIMIT 1';
|
||||
$lastRun = $this->dbcon->prepare($lastRunSql)->executeQuery([':jobid' => $jobid])->fetchAssociative();
|
||||
$lastRun = $this->getEntityManager()->getConnection()->prepare($lastRunSql)->executeQuery([':jobid' => $jobid])->fetchAssociative();
|
||||
return $lastRun;
|
||||
}
|
||||
|
||||
public function isSlowJob(int $jobid, int $timelimit = 5): bool
|
||||
{
|
||||
$slowJobSql = 'SELECT AVG(runtime) as average FROM run WHERE job_id = :jobid LIMIT 5';
|
||||
$slowJob = $this->dbcon->prepare($slowJobSql)->executeQuery([':jobid' => $jobid])->fetchAssociative();
|
||||
$slowJob = $this->getEntityManager()->getConnection()->prepare($slowJobSql)->executeQuery([':jobid' => $jobid])->fetchAssociative();
|
||||
return $slowJob['average'] > $timelimit;
|
||||
}
|
||||
|
||||
public function cleanupRuns(array $jobids, int $maxage = NULL): int
|
||||
{
|
||||
$jobRepo = new Job($this->dbcon);
|
||||
$jobRepo = new JobRepository($this->dbcon);
|
||||
$allJobs = $jobRepo->getAllJobs(true);
|
||||
if(empty($jobids)) {
|
||||
foreach($allJobs as $key=>$job) {
|
||||
|
@ -86,7 +86,7 @@ class Run extends Repository
|
|||
}
|
||||
$sql = 'DELETE FROM run WHERE ' . implode(' OR ', $sqldelete);
|
||||
try {
|
||||
return $this->dbcon->prepare($sql)->executeStatement($params);
|
||||
return $this->getEntityManager()->getConnection()->prepare($sql)->executeStatement($params);
|
||||
} catch(Exception $exception) {
|
||||
throw $exception;
|
||||
}
|
|
@ -1,13 +1,13 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace JeroenED\Webcron\Repository;
|
||||
namespace App\Repository;
|
||||
|
||||
|
||||
use Doctrine\DBAL\Connection;
|
||||
use JeroenED\Framework\Repository;
|
||||
use App\Service\Secret;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
|
||||
class User extends Repository
|
||||
class UserRepository extends EntityRepository
|
||||
{
|
||||
|
||||
/**
|
||||
|
@ -21,7 +21,7 @@ class User extends Repository
|
|||
public function checkAuthentication(string $user, string $password, bool $autologin = false): int|bool
|
||||
{
|
||||
$userSql = "SELECT * from user WHERE email = :user";
|
||||
$userStmt = $this->dbcon->prepare($userSql);
|
||||
$userStmt = $this->getEntityManager()->getConnection()->prepare($userSql);
|
||||
$userRslt = $userStmt->executeQuery([':user' => $user]);
|
||||
if($user = $userRslt->fetchAssociative()) {
|
||||
if($autologin) $password = $this->getPassFromAutologinToken($password);
|
||||
|
@ -58,7 +58,7 @@ class User extends Repository
|
|||
|
||||
public function getMailAddresses() {
|
||||
$emailSql = "SELECT email FROM user WHERE sendmail = 1";
|
||||
$emailStmt = $this->dbcon->prepare($emailSql);
|
||||
$emailStmt = $this->getEntityManager()->getConnection()->prepare($emailSql);
|
||||
$emailRslt = $emailStmt->executeQuery();
|
||||
|
||||
$return = [];
|
|
@ -1,13 +1,13 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace JeroenED\Webcron\Repository;
|
||||
namespace App\Service;
|
||||
|
||||
|
||||
class Secret
|
||||
{
|
||||
static function encrypt($plaintext) {
|
||||
$password = $_ENV['SECRET'];
|
||||
$password = $_ENV['APP_SECRET'];
|
||||
$method = $_ENV['ENCRYPTION_METHOD'];
|
||||
$key = hash($_ENV['HASHING_METHOD'], $password, true);
|
||||
$iv = openssl_random_pseudo_bytes(16);
|
||||
|
@ -19,7 +19,7 @@ class Secret
|
|||
}
|
||||
|
||||
static function decrypt($ivHashCiphertext) {
|
||||
$password = $_ENV['SECRET'];
|
||||
$password = $_ENV['APP_SECRET'];
|
||||
$method = $_ENV['ENCRYPTION_METHOD'];
|
||||
$iv = substr($ivHashCiphertext, 0, 16);
|
||||
$hash = substr($ivHashCiphertext, 16, 32);
|
|
@ -0,0 +1,70 @@
|
|||
<?php
|
||||
namespace App\Twig;
|
||||
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFilter;
|
||||
|
||||
class AppExtension extends AbstractExtension
|
||||
{
|
||||
public function getFilters()
|
||||
{
|
||||
return [
|
||||
new TwigFilter('interval', [$this, 'parseInterval']),
|
||||
new TwigFilter('parsetags', [$this, 'parseTags']),
|
||||
];
|
||||
}
|
||||
|
||||
function parseInterval(int|float $time) {
|
||||
$return = '';
|
||||
|
||||
$days = floor($time / (60 * 60 * 24));
|
||||
$time -= $days * (60 * 60 * 24);
|
||||
$return .= ($days != 0 || !empty($return)) ? "{$days}d " : '';
|
||||
|
||||
$hours = floor($time / (60 * 60));
|
||||
$time -= $hours * (60 * 60);
|
||||
$return .= ($hours != 0 || !empty($return)) ? "{$hours}h " : '';
|
||||
|
||||
$minutes = floor($time / 60);
|
||||
$time -= $minutes * 60;
|
||||
$return .= ($minutes != 0 || !empty($return)) ? "{$minutes}m " : '';
|
||||
|
||||
$time = round($time, 3);
|
||||
$return .= ($time != 0 || !empty($return)) ? "{$time}s " : '';
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
function parseTags(string $text) {
|
||||
$results = [];
|
||||
preg_match_all('/\[([A-Za-z0-9 \-]+)\]/', $text, $results);
|
||||
foreach ($results[0] as $key=>$result) {
|
||||
$background = substr(md5($results[0][$key]), 0, 6);
|
||||
$color = $this->lightOrDark($background) == 'dark' ? 'ffffff' : '000000';
|
||||
$text = str_replace($results[0][$key], '<span class="tag" data-background-color="#' . $background . '" data-color="#' . $color . '">' . $results[1][$key] . '</span>', $text);
|
||||
}
|
||||
return $text;
|
||||
}
|
||||
|
||||
private function lightOrDark ($color) {
|
||||
$color = str_split($color, 2);
|
||||
foreach($color as &$value) {
|
||||
$value = hexdec($value);
|
||||
}
|
||||
|
||||
// HSP (Highly Sensitive Poo) equation from http://alienryderflex.com/hsp.html
|
||||
$hsp = sqrt(
|
||||
0.299 * ($color[0] * $color[0]) +
|
||||
0.587 * ($color[1] * $color[1]) +
|
||||
0.114 * ($color[2] * $color[2])
|
||||
);
|
||||
|
||||
|
||||
// Using the HSP value, determine whether the color is light or dark
|
||||
if ($hsp>140) {
|
||||
return 'light';
|
||||
} else {
|
||||
return 'dark';
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
-- job definition
|
||||
CREATE TABLE job (
|
||||
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
name TEXT(25) NOT NULL,
|
||||
"data" TEXT NOT NULL,
|
||||
interval INTEGER,
|
||||
nextrun INTEGER,
|
||||
lastrun INTEGER,
|
||||
running INTEGER
|
||||
);
|
||||
|
||||
|
||||
-- "user" definition
|
||||
CREATE TABLE "user" (
|
||||
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
email TEXT(50) NOT NULL,
|
||||
password TEXT(72) NOT NULL,
|
||||
sendmail INTEGER NOT NULL
|
||||
);
|
||||
|
||||
-- run definition
|
||||
CREATE TABLE run (
|
||||
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
job_id INTEGER NOT NULL,
|
||||
exitcode TEXT NOT NULL,
|
||||
output TEXT NOT NULL,
|
||||
runtime REAL NOT NULL,
|
||||
timestamp INTEGER NOT NULL,
|
||||
flags TEXT NOT NULL
|
||||
);
|
|
@ -0,0 +1,388 @@
|
|||
{
|
||||
"doctrine/annotations": {
|
||||
"version": "1.13",
|
||||
"recipe": {
|
||||
"repo": "github.com/symfony/recipes",
|
||||
"branch": "master",
|
||||
"version": "1.10",
|
||||
"ref": "64d8583af5ea57b7afa4aba4b159907f3a148b05"
|
||||
}
|
||||
},
|
||||
"doctrine/cache": {
|
||||
"version": "2.1.1"
|
||||
},
|
||||
"doctrine/collections": {
|
||||
"version": "1.6.8"
|
||||
},
|
||||
"doctrine/common": {
|
||||
"version": "3.3.0"
|
||||
},
|
||||
"doctrine/dbal": {
|
||||
"version": "3.3.5"
|
||||
},
|
||||
"doctrine/deprecations": {
|
||||
"version": "v0.5.3"
|
||||
},
|
||||
"doctrine/doctrine-bundle": {
|
||||
"version": "2.6",
|
||||
"recipe": {
|
||||
"repo": "github.com/symfony/recipes",
|
||||
"branch": "master",
|
||||
"version": "2.4",
|
||||
"ref": "ddddd8249dd55bbda16fa7a45bb7499ef6f8e90e"
|
||||
},
|
||||
"files": [
|
||||
"config/packages/doctrine.yaml",
|
||||
"src/Entity/.gitignore",
|
||||
"src/Repository/.gitignore"
|
||||
]
|
||||
},
|
||||
"doctrine/doctrine-migrations-bundle": {
|
||||
"version": "3.2",
|
||||
"recipe": {
|
||||
"repo": "github.com/symfony/recipes",
|
||||
"branch": "master",
|
||||
"version": "3.1",
|
||||
"ref": "ee609429c9ee23e22d6fa5728211768f51ed2818"
|
||||
},
|
||||
"files": [
|
||||
"config/packages/doctrine_migrations.yaml",
|
||||
"migrations/.gitignore"
|
||||
]
|
||||
},
|
||||
"doctrine/event-manager": {
|
||||
"version": "1.1.1"
|
||||
},
|
||||
"doctrine/inflector": {
|
||||
"version": "2.0.4"
|
||||
},
|
||||
"doctrine/instantiator": {
|
||||
"version": "1.4.1"
|
||||
},
|
||||
"doctrine/lexer": {
|
||||
"version": "1.2.3"
|
||||
},
|
||||
"doctrine/migrations": {
|
||||
"version": "3.5.0"
|
||||
},
|
||||
"doctrine/orm": {
|
||||
"version": "2.12.1"
|
||||
},
|
||||
"doctrine/persistence": {
|
||||
"version": "2.5.1"
|
||||
},
|
||||
"doctrine/sql-formatter": {
|
||||
"version": "1.1.2"
|
||||
},
|
||||
"friendsofphp/proxy-manager-lts": {
|
||||
"version": "v1.0.7"
|
||||
},
|
||||
"guzzlehttp/guzzle": {
|
||||
"version": "7.4.2"
|
||||
},
|
||||
"guzzlehttp/promises": {
|
||||
"version": "1.5.1"
|
||||
},
|
||||
"guzzlehttp/psr7": {
|
||||
"version": "2.2.1"
|
||||
},
|
||||
"laminas/laminas-code": {
|
||||
"version": "4.5.1"
|
||||
},
|
||||
"monolog/monolog": {
|
||||
"version": "2.5.0"
|
||||
},
|
||||
"nikic/php-parser": {
|
||||
"version": "v4.13.2"
|
||||
},
|
||||
"paragonie/constant_time_encoding": {
|
||||
"version": "v2.5.0"
|
||||
},
|
||||
"paragonie/random_compat": {
|
||||
"version": "v9.99.100"
|
||||
},
|
||||
"phpseclib/phpseclib": {
|
||||
"version": "3.0.14"
|
||||
},
|
||||
"psr/cache": {
|
||||
"version": "3.0.0"
|
||||
},
|
||||
"psr/container": {
|
||||
"version": "2.0.2"
|
||||
},
|
||||
"psr/event-dispatcher": {
|
||||
"version": "1.0.0"
|
||||
},
|
||||
"psr/http-client": {
|
||||
"version": "1.0.1"
|
||||
},
|
||||
"psr/http-factory": {
|
||||
"version": "1.0.1"
|
||||
},
|
||||
"psr/http-message": {
|
||||
"version": "1.0.1"
|
||||
},
|
||||
"psr/log": {
|
||||
"version": "3.0.0"
|
||||
},
|
||||
"ralouphie/getallheaders": {
|
||||
"version": "3.0.3"
|
||||
},
|
||||
"symfony/asset": {
|
||||
"version": "v6.0.7"
|
||||
},
|
||||
"symfony/cache": {
|
||||
"version": "v6.0.6"
|
||||
},
|
||||
"symfony/cache-contracts": {
|
||||
"version": "v3.0.1"
|
||||
},
|
||||
"symfony/config": {
|
||||
"version": "v6.0.7"
|
||||
},
|
||||
"symfony/console": {
|
||||
"version": "6.0",
|
||||
"recipe": {
|
||||
"repo": "github.com/symfony/recipes",
|
||||
"branch": "master",
|
||||
"version": "5.3",
|
||||
"ref": "da0c8be8157600ad34f10ff0c9cc91232522e047"
|
||||
},
|
||||
"files": [
|
||||
"bin/console"
|
||||
]
|
||||
},
|
||||
"symfony/debug-bundle": {
|
||||
"version": "6.0",
|
||||
"recipe": {
|
||||
"repo": "github.com/symfony/recipes",
|
||||
"branch": "master",
|
||||
"version": "5.3",
|
||||
"ref": "5aa8aa48234c8eb6dbdd7b3cd5d791485d2cec4b"
|
||||
},
|
||||
"files": [
|
||||
"config/packages/debug.yaml"
|
||||
]
|
||||
},
|
||||
"symfony/dependency-injection": {
|
||||
"version": "v6.0.7"
|
||||
},
|
||||
"symfony/deprecation-contracts": {
|
||||
"version": "v3.0.1"
|
||||
},
|
||||
"symfony/doctrine-bridge": {
|
||||
"version": "v6.0.7"
|
||||
},
|
||||
"symfony/dotenv": {
|
||||
"version": "v6.0.5"
|
||||
},
|
||||
"symfony/error-handler": {
|
||||
"version": "v6.0.7"
|
||||
},
|
||||
"symfony/event-dispatcher": {
|
||||
"version": "v6.0.3"
|
||||
},
|
||||
"symfony/event-dispatcher-contracts": {
|
||||
"version": "v3.0.1"
|
||||
},
|
||||
"symfony/filesystem": {
|
||||
"version": "v6.0.7"
|
||||
},
|
||||
"symfony/finder": {
|
||||
"version": "v6.0.3"
|
||||
},
|
||||
"symfony/flex": {
|
||||
"version": "2.1",
|
||||
"recipe": {
|
||||
"repo": "github.com/symfony/recipes",
|
||||
"branch": "master",
|
||||
"version": "1.0",
|
||||
"ref": "c0eeb50665f0f77226616b6038a9b06c03752d8e"
|
||||
},
|
||||
"files": [
|
||||
".env"
|
||||
]
|
||||
},
|
||||
"symfony/framework-bundle": {
|
||||
"version": "6.0",
|
||||
"recipe": {
|
||||
"repo": "github.com/symfony/recipes",
|
||||
"branch": "master",
|
||||
"version": "5.4",
|
||||
"ref": "3cd216a4d007b78d8554d44a5b1c0a446dab24fb"
|
||||
},
|
||||
"files": [
|
||||
"config/packages/cache.yaml",
|
||||
"config/packages/framework.yaml",
|
||||
"config/preload.php",
|
||||
"config/routes/framework.yaml",
|
||||
"config/services.yaml",
|
||||
"public/index.php",
|
||||
"src/Controller/.gitignore",
|
||||
"src/Kernel.php"
|
||||
]
|
||||
},
|
||||
"symfony/http-foundation": {
|
||||
"version": "v6.0.7"
|
||||
},
|
||||
"symfony/http-kernel": {
|
||||
"version": "v6.0.7"
|
||||
},
|
||||
"symfony/maker-bundle": {
|
||||
"version": "1.40",
|
||||
"recipe": {
|
||||
"repo": "github.com/symfony/recipes",
|
||||
"branch": "master",
|
||||
"version": "1.0",
|
||||
"ref": "fadbfe33303a76e25cb63401050439aa9b1a9c7f"
|
||||
}
|
||||
},
|
||||
"symfony/monolog-bridge": {
|
||||
"version": "v6.0.3"
|
||||
},
|
||||
"symfony/monolog-bundle": {
|
||||
"version": "3.7",
|
||||
"recipe": {
|
||||
"repo": "github.com/symfony/recipes",
|
||||
"branch": "master",
|
||||
"version": "3.7",
|
||||
"ref": "213676c4ec929f046dfde5ea8e97625b81bc0578"
|
||||
},
|
||||
"files": [
|
||||
"config/packages/monolog.yaml"
|
||||
]
|
||||
},
|
||||
"symfony/password-hasher": {
|
||||
"version": "v6.0.3"
|
||||
},
|
||||
"symfony/polyfill-intl-grapheme": {
|
||||
"version": "v1.25.0"
|
||||
},
|
||||
"symfony/polyfill-intl-normalizer": {
|
||||
"version": "v1.25.0"
|
||||
},
|
||||
"symfony/polyfill-mbstring": {
|
||||
"version": "v1.25.0"
|
||||
},
|
||||
"symfony/polyfill-php81": {
|
||||
"version": "v1.25.0"
|
||||
},
|
||||
"symfony/property-access": {
|
||||
"version": "v6.0.7"
|
||||
},
|
||||
"symfony/property-info": {
|
||||
"version": "v6.0.7"
|
||||
},
|
||||
"symfony/proxy-manager-bridge": {
|
||||
"version": "v6.0.6"
|
||||
},
|
||||
"symfony/routing": {
|
||||
"version": "6.0",
|
||||
"recipe": {
|
||||
"repo": "github.com/symfony/recipes",
|
||||
"branch": "master",
|
||||
"version": "6.0",
|
||||
"ref": "eb3b377a4dc07006c4bdb2c773652cc9434f5246"
|
||||
},
|
||||
"files": [
|
||||
"config/packages/routing.yaml",
|
||||
"config/routes.yaml"
|
||||
]
|
||||
},
|
||||
"symfony/runtime": {
|
||||
"version": "v6.0.7"
|
||||
},
|
||||
"symfony/security-bundle": {
|
||||
"version": "6.0",
|
||||
"recipe": {
|
||||
"repo": "github.com/symfony/recipes",
|
||||
"branch": "master",
|
||||
"version": "5.3",
|
||||
"ref": "98f1f2b0d635908c2b40f3675da2d23b1a069d30"
|
||||
},
|
||||
"files": [
|
||||
"config/packages/security.yaml"
|
||||
]
|
||||
},
|
||||
"symfony/security-core": {
|
||||
"version": "v6.0.7"
|
||||
},
|
||||
"symfony/security-csrf": {
|
||||
"version": "v6.0.3"
|
||||
},
|
||||
"symfony/security-http": {
|
||||
"version": "v6.0.7"
|
||||
},
|
||||
"symfony/service-contracts": {
|
||||
"version": "v3.0.1"
|
||||
},
|
||||
"symfony/stopwatch": {
|
||||
"version": "v6.0.5"
|
||||
},
|
||||
"symfony/string": {
|
||||
"version": "v6.0.3"
|
||||
},
|
||||
"symfony/translation-contracts": {
|
||||
"version": "v3.0.1"
|
||||
},
|
||||
"symfony/twig-bridge": {
|
||||
"version": "v6.0.7"
|
||||
},
|
||||
"symfony/twig-bundle": {
|
||||
"version": "6.0",
|
||||
"recipe": {
|
||||
"repo": "github.com/symfony/recipes",
|
||||
"branch": "master",
|
||||
"version": "5.4",
|
||||
"ref": "bb2178c57eee79e6be0b297aa96fc0c0def81387"
|
||||
},
|
||||
"files": [
|
||||
"config/packages/twig.yaml",
|
||||
"templates/base.html.twig"
|
||||
]
|
||||
},
|
||||
"symfony/var-dumper": {
|
||||
"version": "v6.0.6"
|
||||
},
|
||||
"symfony/var-exporter": {
|
||||
"version": "v6.0.7"
|
||||
},
|
||||
"symfony/web-profiler-bundle": {
|
||||
"version": "6.0",
|
||||
"recipe": {
|
||||
"repo": "github.com/symfony/recipes",
|
||||
"branch": "master",
|
||||
"version": "5.3",
|
||||
"ref": "24bbc3d84ef2f427f82104f766014e799eefcc3e"
|
||||
},
|
||||
"files": [
|
||||
"config/packages/web_profiler.yaml",
|
||||
"config/routes/web_profiler.yaml"
|
||||
]
|
||||
},
|
||||
"symfony/webpack-encore-bundle": {
|
||||
"version": "1.14",
|
||||
"recipe": {
|
||||
"repo": "github.com/symfony/recipes",
|
||||
"branch": "master",
|
||||
"version": "1.10",
|
||||
"ref": "2858aeed7e1d81a45365c049eb533cc8827e380b"
|
||||
},
|
||||
"files": [
|
||||
"assets/app.js",
|
||||
"assets/bootstrap.js",
|
||||
"assets/controllers.json",
|
||||
"assets/controllers/hello_controller.js",
|
||||
"assets/styles/app.css",
|
||||
"config/packages/webpack_encore.yaml",
|
||||
"package.json",
|
||||
"webpack.config.js"
|
||||
]
|
||||
},
|
||||
"symfony/yaml": {
|
||||
"version": "v6.0.3"
|
||||
},
|
||||
"twig/twig": {
|
||||
"version": "v3.3.10"
|
||||
}
|
||||
}
|
|
@ -38,7 +38,7 @@
|
|||
<label for="lastrun">Last run</label>
|
||||
<div class="input-group">
|
||||
<div class="input-group-text border-end-0">
|
||||
<input type="checkbox" name="lastrun-eternal" class="lastrun-eternal" placeholder="value" value="true" {% if attribute(data, 'lastrun-eternal') is not empty %} checked{% endif %}>
|
||||
<input type="checkbox" name="lastrun-eternal" class="lastrun-eternal" placeholder="value" value="true">
|
||||
</div>
|
||||
<span class="input-group-text border-start-0">Eternal</span>
|
||||
<input type="text" autocomplete="off" pattern="[0-9]{2}\/[0-9]{2}\/[0-9]{4} [0-9]{2}:[0-9]{2}:[0-9]{2}" placeholder="{{ date() | date("d/m/Y H:i:s")}}" data-placeholder="{{ date() | date("d/m/Y H:i:s")}}" id="lastrunselector" class="form-control datetimepicker-input" data-target="#lastrunselector" data-bs-toggle="datetimepicker" name="lastrun">
|
||||
|
|
|
@ -34,32 +34,32 @@
|
|||
<label for="lastrun">Last run</label>
|
||||
<div class="input-group">
|
||||
<div class="input-group-text border-end-0">
|
||||
<input type="checkbox" name="lastrun-eternal" class="lastrun-eternal" placeholder="value" value="true"{% if lastrun is empty %} checked{% endif %}>
|
||||
<input type="checkbox" name="lastrun-eternal" class="lastrun-eternal" placeholder="value" value="true"{% if lastrun is defined %} checked{% endif %}>
|
||||
</div>
|
||||
<span class="input-group-text border-start-0">Eternal</span>
|
||||
<input type="text" autocomplete="off" pattern="[0-9]{2}\/[0-9]{2}\/[0-9]{4} [0-9]{2}:[0-9]{2}:[0-9]{2}" data-placeholder="{{ date() | date("d/m/Y H:i:s")}}" id="lastrunselector" class="form-control datetimepicker-input" data-target="#lastrunselector" data-bs-toggle="datetimepicker" name="lastrun"{% if lastrun is empty %} disabled{% else %} value="{{ lastrun | date("d/m/Y H:i:s")}}"{% endif %}>
|
||||
<input type="text" autocomplete="off" pattern="[0-9]{2}\/[0-9]{2}\/[0-9]{4} [0-9]{2}:[0-9]{2}:[0-9]{2}" data-placeholder="{{ date() | date("d/m/Y H:i:s")}}" id="lastrunselector" class="form-control datetimepicker-input" data-target="#lastrunselector" data-bs-toggle="datetimepicker" name="lastrun"{% if lastrun is defined %} disabled{% else %} value="{{ lastrun | date("d/m/Y H:i:s")}}"{% endif %}>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="retention">Retention (in days)</label>
|
||||
<input type="number" name="retention" class="form-control" id="retention" placeholder="7" value="{% if attribute(data, 'retention') is not empty %}{{ attribute(data, 'retention') }}{% endif %}">
|
||||
<input type="number" name="retention" class="form-control" id="retention" placeholder="7" value="{% if attribute(data, 'retention') is defined %}{{ attribute(data, 'retention') }}{% endif %}">
|
||||
<small id="retention-help" class="form-text text-muted">How many days (at least) to keep runs of this job in the database</small>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="fail-pct">Max fail percentage</label>
|
||||
<div class="input-group d-flex">
|
||||
<div class="range-value range-value-fail-pct pe-1">{% if attribute(data, 'fail-pct') is not empty %}{{ attribute(data, 'fail-pct') }}{% else %}50{% endif %}%</div>
|
||||
<div class="range-value range-value-fail-pct pe-1">{% if attribute(data, 'fail-pct') is defined %}{{ attribute(data, 'fail-pct') }}{% else %}50{% endif %}%</div>
|
||||
<div class="range-input ps-1 flex-grow-1">
|
||||
<input type="range" name="fail-pct" class="form-range range-input-fail-pct" id="fail-pct" max="100" step="5" value="{% if attribute(data, 'fail-pct') is not empty %}{{ attribute(data, 'fail-pct') }}{% else %}50{% endif %}">
|
||||
<input type="range" name="fail-pct" class="form-range range-input-fail-pct" id="fail-pct" max="100" step="5" value="{% if attribute(data, 'fail-pct') is defined %}{{ attribute(data, 'fail-pct') }}{% else %}50{% endif %}">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="fail-days">Number of days calculated for fail percentage</label>
|
||||
<input type="number" name="fail-days" class="form-control" id="fail-days" placeholder="7" value="{% if attribute(data, 'fail-days') is not empty %}{{ attribute(data, 'fail-days') }}{% endif %}">
|
||||
<input type="number" name="fail-days" class="form-control" id="fail-days" placeholder="7" value="{% if attribute(data, 'fail-days') is defined %}{{ attribute(data, 'fail-days') }}{% endif %}">
|
||||
</div>
|
||||
|
||||
<h3>Job details</h3>
|
||||
|
@ -124,12 +124,12 @@
|
|||
<h4>Command details</h4>
|
||||
<div class="mb-3">
|
||||
<label for="command">Command</label>
|
||||
<input type="text" name="command" class="form-control" id="command" placeholder="sudo apt update" value="{% if data.command is not empty %}{{ data.command }}{% endif %}">
|
||||
<input type="text" name="command" class="form-control" id="command" placeholder="sudo apt update" value="{% if data.command is defined %}{{ data.command }}{% endif %}">
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="response">Expected exit code</label>
|
||||
<input type="text" name="response" class="form-control" id="response" placeholder="0" value="{% if data.response is not empty %}{{ data.response | join(',') }}{% endif %}">
|
||||
<input type="text" name="response" class="form-control" id="response" placeholder="0" value="{% if data.response is defined %}{{ data.response | join(',') }}{% endif %}">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -137,29 +137,32 @@
|
|||
<h4>Reboot job details</h4>
|
||||
<div class="mb-3">
|
||||
<label for="reboot-command">Reboot command</label>
|
||||
<input type="text" name="reboot-command" class="form-control" id="reboot-command" placeholder="systemctl reboot" value="{% if attribute(data, 'reboot-command') is not empty %}{{ attribute(data, 'reboot-command') }}{% endif %}">
|
||||
<input type="text" name="reboot-command" class="form-control" id="reboot-command" placeholder="systemctl reboot" value="
|
||||
{% if attribute(data, 'reboot-command') is defined %}
|
||||
{{ attribute(data, 'reboot-command') }}
|
||||
{% endif %}">
|
||||
<small id="reboot-command-help" class="form-text text-muted">Use {reboot-delay} or {reboot-delay-secs} to add the delay in your command</small>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="getservices-command">Get services command</label>
|
||||
<input type="text" name="getservices-command" class="form-control" id="getservices)command" placeholder="systemctl list-units" value="{% if attribute(data, 'getservices-command') is not empty %}{{ attribute(data, 'getservices-command') }}{% endif %}">
|
||||
<input type="text" name="getservices-command" class="form-control" id="getservices)command" placeholder="systemctl list-units" value="{% if attribute(data, 'getservices-command') is defined %}{{ attribute(data, 'getservices-command') }}{% endif %}">
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="getservices-response">Get services command exit code</label>
|
||||
<input type="text" name="getservices-response" class="form-control" id="getservices-response" placeholder="0" value="{% if attribute(data, 'getservices-response') is not empty %}{{ attribute(data, 'getservices-response') | join(',') }}{% endif %}">
|
||||
<input type="text" name="getservices-response" class="form-control" id="getservices-response" placeholder="0" value="{% if attribute(data, 'getservices-response') is defined %}{{ attribute(data, 'getservices-response') | join(',') }}{% endif %}">
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="reboot-delay">Reboot delay (in minutes)</label>
|
||||
<input type="number" name="reboot-delay" class="form-control" placeholder="5" value="{% if attribute(data, 'reboot-delay') is not empty %}{{ attribute(data, 'reboot-delay') }}{% endif %}">
|
||||
<input type="number" name="reboot-delay" class="form-control" placeholder="5" value="{% if attribute(data, 'reboot-delay') is defined %}{{ attribute(data, 'reboot-delay') }}{% endif %}">
|
||||
<small id="reboot-delay-help" class="form-text text-muted">Delay between triggering reboot and actual reboot</small>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="reboot-duration">Reboot duration (in minutes)</label>
|
||||
<input type="number" name="reboot-duration" class="form-control" placeholder="10" value="{% if attribute(data, 'reboot-duration') is not empty %}{{ attribute(data, 'reboot-duration') }}{% endif %}">
|
||||
<input type="number" name="reboot-duration" class="form-control" placeholder="10" value="{% if attribute(data, 'reboot-duration') is defined %}{{ attribute(data, 'reboot-duration') }}{% endif %}">
|
||||
<small id="reboot-duration-help" class="form-text text-muted">The amount of time the system takes to actually reboot</small>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -168,21 +171,21 @@
|
|||
<h4>HTTP request details</h4>
|
||||
<div class="mb-3">
|
||||
<label for="url">Url</label>
|
||||
<input type="text" name="url" class="form-control" id="url" placeholder="https://scripts.example.com/" value="{% if data.url is not empty %}{{ data.url }}{% endif %}">
|
||||
<input type="text" name="url" class="form-control" id="url" placeholder="https://scripts.example.com/" value="{% if data.url is defined %}{{ data.url }}{% endif %}">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="basicauth-username">Username for Basic-Auth</label>
|
||||
<input type="text" name="basicauth-username" class="form-control" id="basicauth-username" placeholder="www-data" value="{% if attribute(data, 'basicauth-username') is not empty %}{{ attribute(data, 'basicauth-username') }}{% endif %}">
|
||||
<input type="text" name="basicauth-username" class="form-control" id="basicauth-username" placeholder="www-data" value="{% if attribute(data, 'basicauth-username') is defined %}{{ attribute(data, 'basicauth-username') }}{% endif %}">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="basicauth-password">Password for Basic-Auth</label>
|
||||
<input type="password" name="basicauth-password" class="form-control" placeholder="correct horse battery staple" value="{% if attribute(data, 'basicauth-password') is not empty %}{{ attribute(data, 'basicauth-password') }}{% endif %}">
|
||||
<input type="password" name="basicauth-password" class="form-control" placeholder="correct horse battery staple" value="{% if attribute(data, 'basicauth-password') is defined %}{{ attribute(data, 'basicauth-password') }}{% endif %}">
|
||||
<small id="basicauth-password-help" class="form-text text-muted">This field is being saved as a secret</small>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="http-status">Expected http status code</label>
|
||||
<input type="text" name="http-status" class="form-control" id="http-status" placeholder="200" value="{% if attribute(data, 'http-status') is not empty %}{{ attribute(data, 'http-status') | join(',')}}{% endif %}">
|
||||
<input type="text" name="http-status" class="form-control" id="http-status" placeholder="200" value="{% if attribute(data, 'http-status') is defined %}{{ attribute(data, 'http-status') | join(',')}}{% endif %}">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -195,21 +198,21 @@
|
|||
<h4>SSH host details</h4>
|
||||
<div class="mb-3">
|
||||
<label for="host">Hostname</label>
|
||||
<input type="text" name="host" class="form-control" id="host" placeholder="ssh.abc.xyz" value="{% if data.host is not empty %}{{ data.host }}{% endif %}">
|
||||
<input type="text" name="host" class="form-control" id="host" placeholder="ssh.abc.xyz" value="{% if data.host is defined %}{{ data.host }}{% endif %}">
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="user">Username</label>
|
||||
<input type="text" name="user" class="form-control" id="user" placeholder="larry" value="{% if data.user is not empty %}{{ data.user }}{% endif %}">
|
||||
<input type="text" name="user" class="form-control" id="user" placeholder="larry" value="{% if data.user is defined %}{{ data.user }}{% endif %}">
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="privkey">Private key</label>
|
||||
<div class="input-group">
|
||||
<span class=" input-group-text border-end-0">
|
||||
<input type="checkbox" name="privkey-keep" class="privkey-keep" value="true" data-privkey="{% if attribute(data, 'ssh-privkey') is not empty %}{{ attribute(data, 'ssh-privkey') }}{% endif %}" checked>
|
||||
<input type="checkbox" name="privkey-keep" class="privkey-keep" value="true" data-privkey="{% if attribute(data, 'ssh-privkey') is defined %}{{ attribute(data, 'ssh-privkey') }}{% endif %}" checked>
|
||||
</span>
|
||||
<input type="hidden" name="privkey-orig" class="privkey-orig" value="{% if attribute(data, 'ssh-privkey') is not empty %}{{ attribute(data, 'ssh-privkey') }}{% endif %}">
|
||||
<input type="hidden" name="privkey-orig" class="privkey-orig" value="{% if attribute(data, 'ssh-privkey') is defined %}{{ attribute(data, 'ssh-privkey') }}{% endif %}">
|
||||
<span class="input-group-text border-start-0">Keep</span>
|
||||
<input type="file" id="privkey" name="privkey" class="form-control " disabled>
|
||||
</div>
|
||||
|
@ -218,7 +221,7 @@
|
|||
|
||||
<div class="mb-3">
|
||||
<label for="privkey-password">Password for private key</label>
|
||||
<input type="password" name="privkey-password" class="form-control" placeholder="correct horse battery staple" value="{% if attribute(data, 'privkey-password') is not empty %}{{ attribute(data, 'privkey-password') }}{% endif %}">
|
||||
<input type="password" name="privkey-password" class="form-control" placeholder="correct horse battery staple" value="{% if attribute(data, 'privkey-password') is defined %}{{ attribute(data, 'privkey-password') }}{% endif %}">
|
||||
<small id="privkey-password-help" class="form-text text-muted">If private key is empty this field is being used as ssh-password</small>
|
||||
<small id="privkey-password-help-2" class="form-text text-muted">This field is being saved as a secret</small>
|
||||
</div>
|
||||
|
@ -231,12 +234,12 @@
|
|||
<h4>Docker container details</h4>
|
||||
<div class="mb-3">
|
||||
<label for="service">Service</label>
|
||||
<input type="text" name="service" class="form-control" id="service" placeholder="mysql" value="{% if attribute(data, 'service') is not empty %}{{ attribute(data, 'service') }}{% endif %}">
|
||||
<input type="text" name="service" class="form-control" id="service" placeholder="mysql" value="{% if attribute(data, 'service') is defined %}{{ attribute(data, 'service') }}{% endif %}">
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="container-user">Username</label>
|
||||
<input type="text" name="container-user" class="form-control" id="container-user" placeholder="larry" value="{% if attribute(data, 'container-user') is not empty %}{{ attribute(data, 'container-user') }}{% endif %}">
|
||||
<input type="text" name="container-user" class="form-control" id="container-user" placeholder="larry" value="{% if attribute(data, 'container-user') is defined %}{{ attribute(data, 'container-user') }}{% endif %}">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -252,16 +255,18 @@
|
|||
<input type="text" name="var-value[0]" class="form-control var-value" placeholder="value">
|
||||
</div>
|
||||
{% set key = 1 %}
|
||||
{% for id,var in data.vars %}
|
||||
<div class="input-group var-group">
|
||||
<div class="input-group-text border-end-0">
|
||||
<input type="checkbox" name="var-issecret[{{ key }}]" class="var-issecret" placeholder="value" value="true"{% if var.issecret %} checked{% endif %}>
|
||||
{% if data.vars is defined %}
|
||||
{% for id,var in data.vars %}
|
||||
<div class="input-group var-group">
|
||||
<div class="input-group-text border-end-0">
|
||||
<input type="checkbox" name="var-issecret[{{ key }}]" class="var-issecret" placeholder="value" value="true"{% if var.issecret %} checked{% endif %}>
|
||||
</div>
|
||||
<span class="input-group-text border-start-0">Secret</span>
|
||||
<input type="text" name="var-id[{{ key }}]" class="form-control var-id" placeholder="name" value="{{ id }}">
|
||||
<input type="{% if var.issecret %}password{% else %}text{% endif %}" name="var-value[{{ key }}]" class="form-control var-value" placeholder="value" value="{{ var.value }}">
|
||||
</div>
|
||||
<span class="input-group-text border-start-0">Secret</span>
|
||||
<input type="text" name="var-id[{{ key }}]" class="form-control var-id" placeholder="name" value="{{ id }}">
|
||||
<input type="{% if var.issecret %}password{% else %}text{% endif %}" name="var-value[{{ key }}]" class="form-control var-value" placeholder="value" value="{{ var.value }}">
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="vars-description mb-3 d-none">
|
||||
|
|
|
@ -14,21 +14,29 @@
|
|||
<div class="row justify-content-md-center">
|
||||
<div class="col-md-4 col-xs-12">
|
||||
{{ include('flashes.html.twig') }}
|
||||
{% if error %}
|
||||
<div class="alert alert-danger alert-dismissible fade show" role="alert">
|
||||
{{ error.messageKey|trans(error.messageData, 'security') }}
|
||||
<button type="button" class="btn-close" data-dismiss="alert" aria-label="Close">
|
||||
</button>
|
||||
</div>
|
||||
{% endif %}
|
||||
<h1>Webcron management</h1>
|
||||
<form class="form-horizontal" method="post" action="{{ path('login_check') }}">
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="name">Username</label>
|
||||
<input type="text" name="name" class="form-control" id="name" placeholder="username">
|
||||
<label for="username">Username</label>
|
||||
<input type="text" name="_username" class="form-control" id="username" placeholder="username">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="passwd">Password</label>
|
||||
<input type="password" name="passwd" class="form-control" id="passwd" placeholder="password">
|
||||
<label for="password">Password</label>
|
||||
<input type="password" name="_password" class="form-control" id="password" placeholder="password">
|
||||
</div>
|
||||
<div class="form-check mb-3">
|
||||
<input type="checkbox" name="autologin" id="autologin" value="autologin" class="form-check-input">
|
||||
<input type="checkbox" name="_remember_me" id="autologin" class="form-check-input">
|
||||
<label class="from-check-label" for="autologin">Remember, remember</label>
|
||||
</div>
|
||||
<input type="hidden" name="_csrf_token" value="{{ csrf_token('authenticate') }}">
|
||||
<button type="submit" class="btn btn-outline-primary">Submit</button>
|
||||
</form>
|
||||
</div>
|
||||
|
|
28
webcron
28
webcron
|
@ -1,28 +0,0 @@
|
|||
#!/usr/bin/env php
|
||||
<?php
|
||||
require_once 'bootstrap.php';
|
||||
|
||||
use JeroenED\Framework\Kernel;
|
||||
use JeroenED\Webcron\Command\CleanupCommand;
|
||||
use JeroenED\Webcron\Command\DaemonCommand;
|
||||
use JeroenED\Webcron\Command\MailFailedRunsCommand;
|
||||
use JeroenED\Webcron\Command\RunCommand;
|
||||
use Symfony\Component\Console\Application;
|
||||
|
||||
$application = new Application();
|
||||
$kernel = new Kernel();
|
||||
|
||||
chdir(__DIR__);
|
||||
$kernel->setProjectDir(getcwd());
|
||||
$kernel->setConfigDir(getcwd() . '/config/');
|
||||
$kernel->setTemplateDir(getcwd() . '/templates/');
|
||||
$kernel->setCacheDir(getcwd() . '/cache/');
|
||||
$kernel->parseDotEnv($kernel->getProjectDir() . '/.env');
|
||||
|
||||
$application->add(new RunCommand($kernel));
|
||||
$application->add(new DaemonCommand($kernel));
|
||||
$application->add(new CleanupCommand($kernel));
|
||||
$application->add(new MailFailedRunsCommand($kernel));
|
||||
|
||||
$application->run();
|
||||
|
Loading…
Reference in New Issue