Skip to content

Commit

Permalink
Drop support for php-based configuration (#749)
Browse files Browse the repository at this point in the history
  • Loading branch information
andig committed Mar 24, 2019
1 parent 0171b42 commit 4231f6e
Show file tree
Hide file tree
Showing 13 changed files with 29 additions and 59 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
test
vendor
etc/config.yaml
etc/volkszaehler.conf.php
15 changes: 6 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ language: php
php:
- 7.1
- 7.3
- 7.4snapshot

services:
- mysql
Expand All @@ -24,7 +25,7 @@ matrix:
include:
# postgres
- php: 7.3
services: postresql
services: postgresql
env: DB=pgsql
# sqlite
- php: 7.3
Expand All @@ -42,10 +43,6 @@ matrix:
- php: 7.3
env: DB= JSLINT=true

notifications:
email: "volkszaehler-dev@lists.volkszaehler.org"
irc: "chat.freenode.net#volkszaehler.org"

# speedup build
cache:
directories:
Expand Down Expand Up @@ -80,10 +77,10 @@ before_script:
- if [ "$DB" = "pgsql" ]; then USER=postgres; fi

# create config file
- sed -i "s/driver: .*/driver: pdo_$DB/" etc/config.yaml
- sed -i "s/user: .*/user: $USER/" etc/config.yaml
- sed -i "s/password: .*/password: $PASSWORD/" etc/config.yaml
- sed -i "s/dbname: .*/dbname: $DATABASE/" etc/config.yaml
- "sed -i \"s/driver: .*/driver: pdo_$DB/\" etc/config.yaml"
- "sed -i \"s/user: .*/user: $USER/\" etc/config.yaml"
- "sed -i \"s/password: .*/password: $PASSWORD/\" etc/config.yaml"
- "sed -i \"s/dbname: .*/dbname: $DATABASE/\" etc/config.yaml"
- cat etc/config.yaml

# create database
Expand Down
6 changes: 3 additions & 3 deletions bin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,10 @@ Volkszaehler frontend will automatically try to connect to `ws/wss:<middleware u

#### Routing

In order to support both WAMP and plain web sockets over the same external port, `push-server` has an integrated routing capability. For backwards compatibility with existing frontends the following routes are configured by default as part of `volkszaehler.conf.php`:
In order to support both WAMP and plain web sockets over the same external port, `push-server` has an integrated routing capability. For backwards compatibility with existing frontends the following routes are configured by default as part of `config.yaml`:

- `$config['push']['routes']['wamp']`: array of routes for WAMP. Default is both `/` and `/ws` for frontend compatibility.
- `$config['push']['routes']['websocket']`: array of routes for plain web sockets. Default is empty to prevent misuse. To enable chose e.g. `/socket` and make sure to read the chapter on security below.
- `push.wamp`: array of routes for WAMP. Default is both `/` and `/ws` for frontend compatibility.
- `push.websocket`: array of routes for plain web sockets. Default is empty to prevent misuse. To enable chose e.g. `/socket` and make sure to read the chapter on security below.

To disable a protocol it is sufficient to declare an empty array of routes.

Expand Down
4 changes: 2 additions & 2 deletions bin/push-server
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ $routes = new RouteCollection;
$router = new Router(new UrlMatcher($routes, new RequestContext));

// WAMP adapter
$wampRoutes = Util\Configuration::read('push.routes.wamp');
$wampRoutes = Util\Configuration::read('push.wamp');
if (is_array($wampRoutes) && count($wampRoutes)) {
$wampAdapter = new WampClientAdapter();
$wampServer = new WsServer(new WampServer($wampAdapter));
Expand All @@ -99,7 +99,7 @@ else {
}

// WebSocket adapter
$wsRoutes = Util\Configuration::read('push.routes.websocket');
$wsRoutes = Util\Configuration::read('push.websocket');
if (is_array($wsRoutes) && count($wsRoutes)) {
$wsAdapter = new WsClientAdapter();
$wsServer = new WsServer($wsAdapter);
Expand Down
2 changes: 0 additions & 2 deletions bin/vzcompress2
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
* database. If you often insert/import historic data you may want to turn
* this off. Configuration can be found near the end of this file.
*
* Database parameters are read from ../etc/volkszaehler.conf.php
*
* @author Florian Knodt <adlerweb@adlerweb.info>
* @author Andreas Goetz <cpuidle@gmx.de>
* @copyright Copyright (c) 2011-2018, The volkszaehler.org project
Expand Down
6 changes: 3 additions & 3 deletions etc/config.dist.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ php:
db:
driver: pdo_mysql
host: 127.0.0.1
port: 3306
# port: 3306
user: vz
password: demo
charset: utf8
Expand All @@ -35,9 +35,9 @@ push:
websocket:
- /socket

security:
network:
# limit maximum POST body size, e.g. 4096
maxbodysize: false
postlimit: false

# enable debug messages by default if true
debug: false
2 changes: 1 addition & 1 deletion etc/middleware.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"host": "0.0.0.0",
"port": 8080,
"workers": 8,
"static": false,
"static-directory": "htdocs",
"logging": 0,
"max-requests": 1000,
"bridge": "HttpKernel",
Expand Down
2 changes: 1 addition & 1 deletion lib/Controller/DataController.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function add($uuid) {
$rawPost = $this->request->getContent(); // file_get_contents('php://input')

// check maximum size allowed
if ($maxSize = Util\Configuration::read('security.maxbodysize')) {
if ($maxSize = Util\Configuration::read('network.postlimit')) {
if (strlen($rawPost) > $maxSize) {
throw new \Exception('Maximum message size exceeded');
}
Expand Down
5 changes: 1 addition & 4 deletions lib/Server/PPMBootstrapAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@

// move out of lib/server
define('VZ_DIR', realpath(__DIR__ . '/../..'));
// check config file before bootstrap dies
if (!file_exists(VZ_DIR . '/etc/volkszaehler.conf.php') &! file_exists(VZ_DIR . '/etc/config.yaml')) {
throw new \Exception('Could not find config file.');
}

require_once(VZ_DIR . '/lib/bootstrap.php');

/**
Expand Down
23 changes: 1 addition & 22 deletions lib/Util/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,33 +58,12 @@ static public function read($var = NULL, $default = NULL) {
return $values;
}

/**
* load configuration from file
*
* @param string $filename A string pointing to a file on the filesystem
*/
static public function load($filename) {
$filename .= '.php';

if (!file_exists($filename)) {
throw new \Exception('Configuration file not found: \'' . $filename . '\'');
}

include $filename;

if (!isset($config)) {
throw new \Exception('No variable $config found in: \'' . $filename . '\'');
}

self::$values = $config;
}

/**
* load configuration from yaml file
*
* @param string $filename A string pointing to a file on the filesystem
*/
static public function loadYaml($filename) {
static public function load($filename) {
self::$values = Yaml::parseFile($filename);
}
}
Expand Down
18 changes: 9 additions & 9 deletions lib/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,20 @@
use Volkszaehler\Util;

function fail($msg) {
if (preg_match('/\.json/', $_SERVER['REQUEST_URI'])) {
// JSON request?
if (preg_match('/\.json/', @$_SERVER['REQUEST_URI'])) {
header('Content-type: application/json');
echo json_encode([
'version' => VZ_VERSION,
'exception' => array(
'message' => $msg
)
]);
die();
}
die();

// normal request or command line
throw new \Exception($msg);
}

// enable strict error reporting
Expand All @@ -52,18 +56,14 @@ function fail($msg) {
fail('Could not find autoloader. Check that dependencies have been installed via `composer install`.');
}

if (!file_exists(VZ_DIR . '/etc/volkszaehler.conf.php') &! file_exists(VZ_DIR . '/etc/config.yaml')) {
fail('Could not find config file. Check that etc/config.yaml or etc/volkszaehler.conf.php exists.');
if (!file_exists(VZ_DIR . '/etc/config.yaml')) {
fail('Could not find config file. Check that etc/config.yaml exists.');
}

require_once VZ_DIR . '/vendor/autoload.php';

// load configuration
try {
Util\Configuration::loadYaml(VZ_DIR . '/etc/config.yaml');
} catch(\Exception $e) {
Util\Configuration::load(VZ_DIR . '/etc/volkszaehler.conf');
}
Util\Configuration::load(VZ_DIR . '/etc/config.yaml');

// set timezone
$tz = (Util\Configuration::read('timezone')) ? Util\Configuration::read('timezone') : @date_default_timezone_get();
Expand Down
2 changes: 1 addition & 1 deletion misc/sql/README
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Database Setup

To setup your database follow these steps:

1. Make sure you have a proper configuration file (etc/volkszaehler.conf.php)
1. Make sure you have a proper configuration file (etc/config.yaml)
2. Adjust the configuration to your database setup
3. Call bin/doctrine orm:schema-tool:create --dump-sql > database.sql
4. Import the resulting file using your favorite sql tool
Expand Down
2 changes: 0 additions & 2 deletions test/PushServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ function safeCurl($data) {
* @group pushserver
*/
function testPushMessage() {
$this->assertTrue(Util\Configuration::read('push.enabled'), 'Push server disabled');

// first message - no result tuples
$exitCode = $this->safeCurl([
'data' => [
Expand Down

0 comments on commit 4231f6e

Please sign in to comment.