From 2b6942a63e2162f1f382d9693977d2859a1f1803 Mon Sep 17 00:00:00 2001 From: Nick Farley Date: Mon, 3 Dec 2018 11:23:31 -0500 Subject: [PATCH] Jobs are now user-configurable Not every installation has the same jobs as everyone else. Also updates the documentation for customizations --- .gitignore | 3 +- Readme.md | 12 +- composer.json | 3 +- composer.lock | 241 ++++++++++++++++++- index.php | 6 +- src/Statbus/Controllers/PlayerController.php | 6 +- src/conf/Statbus.php | 35 +++ src/conf/example-jobs.json | 35 +++ 8 files changed, 331 insertions(+), 10 deletions(-) create mode 100644 src/conf/example-jobs.json diff --git a/.gitignore b/.gitignore index 0be9b72..063ab0d 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ composer.lock src/conf/servers.json src/conf/ranks.json -src/conf/alert.html* \ No newline at end of file +src/conf/alert.html* +composer.lock diff --git a/Readme.md b/Readme.md index 3424e01..8f22c75 100644 --- a/Readme.md +++ b/Readme.md @@ -16,8 +16,6 @@ 2. Clone this repo into the document root you specified in step 1. 3. Run `composer update` and `composer dump-autoload -o`. 4. Copy `.env.example` to `.env` and adjust your settings accordingly. -5. Copy `src/conf/example-servers.json` to `src/conf/servers.json` and customize your settings accordingly. -6. Copy `src/conf/example-ranks.json` to `src/conf/ranks.json` and customize your settings accordingly. Icons are from [FontAwesome](https://fontawesome.com/icons?d=gallery&m=free). ### Second Database (Alt DB) Some data, when parsed, can be saved to a second database. To enable this function: @@ -25,11 +23,17 @@ Some data, when parsed, can be saved to a second database. To enable this functi 1. Make sure the `ALT_DB_*` variables are set in your `.env`. See `.env.example` for details. 2. Initialize the second database using the table structure defined in `sql/alt_db.sql`. - ## Updating 1. Run `git pull`. 2. Run `composer update` and `composer dump-autoload -o`. 3. (Maybe) Remove the twig cache at `tmp/twig`. ### Second Database (Alt DB) -1. Apply any updates specified in `sql/sqlchangelog.md`. \ No newline at end of file +1. Apply any updates specified in `sql/sqlchangelog.md`. + +##Customizations +There are several files you can edit in order to tailor Statbus to your codebase: + +- `src/conf/servers.json` can be used to map server information. At the minimum, you must specify a server port and name. See `src/conf/example-servers.json`. +- `src/conf/ranks.json` holds the definitions for admin rank badge colors and icons. See `src/conf/example-ranks.json` for examples. The icon field sources icons from [FontAwsome](https://fontawesome.com/icons?d=gallery&s=solid&m=free). You only need the name of the icon, the part after `fa-`. +- `src/conf/jobs.json` can be used to customize what jobs are looked at for querying role_time data (as seen on `/me`). You should copy `src/conf/example-jobs.json` into your `jobs.json` and add or remove jobs from that listing. \ No newline at end of file diff --git a/composer.json b/composer.json index e3db720..f4e0210 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,8 @@ "kevinrob/guzzle-cache-middleware": "^3.2", "league/flysystem": "^1.0", "doctrine/cache": "^1.7", - "slim/csrf": "^0.8.3" + "slim/csrf": "^0.8.3", + "sensiolabs/security-checker": "^5.0" }, "autoload": { "psr-4": { diff --git a/composer.lock b/composer.lock index 8583b11..9926e25 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,64 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "06009600bed696a81a779020a3952703", + "content-hash": "ad6edbdb47c2bc7676dfc5719301b9e7", "packages": [ + { + "name": "composer/ca-bundle", + "version": "1.1.3", + "source": { + "type": "git", + "url": "https://github.com/composer/ca-bundle.git", + "reference": "8afa52cd417f4ec417b4bfe86b68106538a87660" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/composer/ca-bundle/zipball/8afa52cd417f4ec417b4bfe86b68106538a87660", + "reference": "8afa52cd417f4ec417b4bfe86b68106538a87660", + "shasum": "" + }, + "require": { + "ext-openssl": "*", + "ext-pcre": "*", + "php": "^5.3.2 || ^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.5", + "psr/log": "^1.0", + "symfony/process": "^2.5 || ^3.0 || ^4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.x-dev" + } + }, + "autoload": { + "psr-4": { + "Composer\\CaBundle\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jordi Boggiano", + "email": "j.boggiano@seld.be", + "homepage": "http://seld.be" + } + ], + "description": "Lets you find a path to the system CA bundle, and includes a fallback to the Mozilla CA bundle.", + "keywords": [ + "cabundle", + "cacert", + "certificate", + "ssl", + "tls" + ], + "time": "2018-10-18T06:09:13+00:00" + }, { "name": "container-interop/container-interop", "version": "1.2.0", @@ -817,6 +873,52 @@ ], "time": "2016-08-06T14:39:51+00:00" }, + { + "name": "sensiolabs/security-checker", + "version": "v5.0.1", + "source": { + "type": "git", + "url": "https://github.com/sensiolabs/security-checker.git", + "reference": "9ea927417c949039a9cfb0d92af76fd1c538d9e9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sensiolabs/security-checker/zipball/9ea927417c949039a9cfb0d92af76fd1c538d9e9", + "reference": "9ea927417c949039a9cfb0d92af76fd1c538d9e9", + "shasum": "" + }, + "require": { + "composer/ca-bundle": "^1.0", + "php": ">=5.5.9", + "symfony/console": "~2.7|~3.0|~4.0" + }, + "bin": [ + "security-checker" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.0-dev" + } + }, + "autoload": { + "psr-4": { + "SensioLabs\\Security\\": "SensioLabs/Security" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien.potencier@gmail.com" + } + ], + "description": "A security checker for your composer.lock", + "time": "2018-10-16T10:30:44+00:00" + }, { "name": "slim/csrf", "version": "0.8.3", @@ -1038,6 +1140,143 @@ ], "time": "2018-05-07T10:54:29+00:00" }, + { + "name": "symfony/console", + "version": "v4.2.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/console.git", + "reference": "4dff24e5d01e713818805c1862d2e3f901ee7dd0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/console/zipball/4dff24e5d01e713818805c1862d2e3f901ee7dd0", + "reference": "4dff24e5d01e713818805c1862d2e3f901ee7dd0", + "shasum": "" + }, + "require": { + "php": "^7.1.3", + "symfony/contracts": "^1.0", + "symfony/polyfill-mbstring": "~1.0" + }, + "conflict": { + "symfony/dependency-injection": "<3.4", + "symfony/process": "<3.3" + }, + "require-dev": { + "psr/log": "~1.0", + "symfony/config": "~3.4|~4.0", + "symfony/dependency-injection": "~3.4|~4.0", + "symfony/event-dispatcher": "~3.4|~4.0", + "symfony/lock": "~3.4|~4.0", + "symfony/process": "~3.4|~4.0" + }, + "suggest": { + "psr/log-implementation": "For using the console logger", + "symfony/event-dispatcher": "", + "symfony/lock": "", + "symfony/process": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.2-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Console\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Console Component", + "homepage": "https://symfony.com", + "time": "2018-11-27T07:40:44+00:00" + }, + { + "name": "symfony/contracts", + "version": "v1.0.1", + "source": { + "type": "git", + "url": "https://github.com/symfony/contracts.git", + "reference": "3edf0ab943d1985a356721952cba36ff31bd6e5f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/contracts/zipball/3edf0ab943d1985a356721952cba36ff31bd6e5f", + "reference": "3edf0ab943d1985a356721952cba36ff31bd6e5f", + "shasum": "" + }, + "require": { + "php": "^7.1.3" + }, + "require-dev": { + "psr/cache": "^1.0", + "psr/container": "^1.0" + }, + "suggest": { + "psr/cache": "When using the Cache contracts", + "psr/container": "When using the Service contracts", + "symfony/cache-contracts-implementation": "", + "symfony/service-contracts-implementation": "", + "symfony/translation-contracts-implementation": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Contracts\\": "" + }, + "exclude-from-classmap": [ + "**/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "A set of abstractions extracted out of the Symfony components", + "homepage": "https://symfony.com", + "keywords": [ + "abstractions", + "contracts", + "decoupling", + "interfaces", + "interoperability", + "standards" + ], + "time": "2018-11-24T09:35:08+00:00" + }, { "name": "symfony/polyfill-ctype", "version": "v1.10.0", diff --git a/index.php b/index.php index 2129d6d..12b432b 100644 --- a/index.php +++ b/index.php @@ -31,6 +31,11 @@ if(file_exists(__DIR__ . '/src/conf/ranks.json')){ $settings['settings']['statbus']['ranks'] = json_decode(file_get_contents(__DIR__ . '/src/conf/ranks.json'), true); } + +if(file_exists(__DIR__ . '/src/conf/jobs.json')){ + $settings['settings']['statbus']['jobs'] = json_decode(file_get_contents(__DIR__ . '/src/conf/jobs.json'), true); +} + if ($settings['settings']['refresh_key'] == filter_input(INPUT_GET,'refresh', FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH)){ exec("rm -rf ".__DIR__."/tmp/twig"); print("Twig cache has been cleared"); @@ -45,7 +50,6 @@ // Register routes require __DIR__ . '/src/routes.php'; - // Run app $app->run(); diff --git a/src/Statbus/Controllers/PlayerController.php b/src/Statbus/Controllers/PlayerController.php index ae54fca..99e4ab0 100644 --- a/src/Statbus/Controllers/PlayerController.php +++ b/src/Statbus/Controllers/PlayerController.php @@ -10,7 +10,8 @@ class PlayerController Extends Controller { public function __construct(ContainerInterface $container) { parent::__construct($container); - $this->playerModel = new Player($this->container->get('settings')['statbus']); + $this->sb = $this->container->get('settings')['statbus']; + $this->playerModel = new Player($this->sb); $dbConn = $this->container->get('settings')['database']['alt']; $this->alt_db = (new DBController($dbConn))->db; } @@ -81,10 +82,11 @@ public function getPlayerByIP(int $IP){ } public function getRoleData($ckey) { + $jobs = "('".implode("','",$this->sb['jobs'])."')"; return json_encode($this->DB->run("SELECT job, minutes FROM tbl_role_time WHERE ckey = ? - AND tbl_role_time.job IN ('Assistant','Scientist','Shaft Miner','Station Engineer','Cyborg','Medical Doctor','Security Officer','Roboticist','Cargo Technician','Botanist','Chemist','AI','Cook','Atmospheric Technician','Janitor','Clown','Captain','Bartender','Head of Personnel','Quartermaster','Chaplain','Geneticist','Chief Engineer','Research Director','Mime','Lawyer','Detective','Chief Medical Officer','Head of Security','Virologist','Librarian','Warden') + AND tbl_role_time.job IN $jobs ORDER BY job ASC", $ckey)); } diff --git a/src/conf/Statbus.php b/src/conf/Statbus.php index 82c6fa2..f310756 100644 --- a/src/conf/Statbus.php +++ b/src/conf/Statbus.php @@ -88,5 +88,40 @@ 'Very Ragin\' Bullshit Mages'=>'cloud-sun', 'Vigilante Gang War'=>'', 'Wizard'=>'hat-wizard' + ], + 'jobs' => [ + 'AI', + 'Assistant', + 'Atmospheric Technician', + 'Bartender', + 'Botanist', + 'Captain', + 'Cargo Technician', + 'Chaplain', + 'Chemist', + 'Chief Engineer', + 'Chief Medical Officer', + 'Clown', + 'Cook', + 'Curator', + 'Cyborg', + 'Detective', + 'Geneticist', + 'Head of Personnel', + 'Head of Security', + 'Janitor', + 'Lawyer', + 'Librarian', + 'Medical Doctor', + 'Mime', + 'Quartermaster', + 'Research Director', + 'Roboticist', + 'Scientist', + 'Security Officer', + 'Shaft Miner', + 'Station Engineer', + 'Virologist', + 'Warden' ] ]; \ No newline at end of file diff --git a/src/conf/example-jobs.json b/src/conf/example-jobs.json new file mode 100644 index 0000000..9a5d8a6 --- /dev/null +++ b/src/conf/example-jobs.json @@ -0,0 +1,35 @@ +[ + "AI", + "Assistant", + "Atmospheric Technician", + "Bartender", + "Botanist", + "Captain", + "Cargo Technician", + "Chaplain", + "Chemist", + "Chief Engineer", + "Chief Medical Officer", + "Clown", + "Cook", + "Curator", + "Cyborg", + "Detective", + "Geneticist", + "Head of Personnel", + "Head of Security", + "Janitor", + "Lawyer", + "Librarian", + "Medical Doctor", + "Mime", + "Quartermaster", + "Research Director", + "Roboticist", + "Scientist", + "Security Officer", + "Shaft Miner", + "Station Engineer", + "Virologist", + "Warden" +] \ No newline at end of file