Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed configuration file to use .ini format. #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 26 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,28 +83,42 @@ Make your life easy for the next step by running these on the node's server:
cat ~/.multichain/chain1/multichain.conf
grep rpc-port ~/.multichain/chain1/params.dat

In the web demo directory, copy the `config-example.txt` file to `config.txt`:
In the web demo directory, copy the `config-example.ini` file to `config.ini`:

cp config-example.ini config.ini

or on Windows:

copy config-example.ini config.ini

cp config-example.txt config.txt

In the demo website directory, enter chain details in `config.txt` e.g.:
In the demo website directory, enter chain details in `config.ini` e.g.:

default.name=Default # name to display in the web interface
default.rpchost=127.0.0.1 # IP address of MultiChain node
default.rpcport=12345 # usually default-rpc-port from params.dat
default.rpcuser=multichainrpc # username for RPC from multichain.conf
default.rpcpassword=mnBh8aHp4mun... # password for RPC from multichain.conf
[default]
name=Default ; name to display in the web interface
rpchost=127.0.0.1 ; IP address of MultiChain node
rpcport=12345 ; usually default-rpc-port from params.dat
rpcuser=multichainrpc ; username for RPC from multichain.conf
rpcpassword=mnBh8aHp4mun... ; password for RPC from multichain.conf

Multiple chains are supported by the web demo by copying the same section again but with different prefixes before the period, for example:
Multiple chains are supported by the web demo by copying the same section again but with different string for the section name in the square brackets, for example:

another.name=...
another.rpchost=...
[another]
name=...
rpchost=...
...

**Note that the `config.txt` file is readable by users of your web demo installation, and contains your MultiChain API password, so you should never use this basic setup for a production system.**
**Note that the `config.ini` file is readable by users of your web demo installation, and contains your MultiChain API password, so you should never use this basic setup for a production system.**

For additional security the `config.ini` file can be placed in a parent directory of the web demo. By default the `read_config()` function will look for the specified configuration file up to three directory levels above the web demo.

Launch the Web Demo
-------------------

No additional configuration or setup is required. Based on where you installed the web demo, open the appropriate address in your web browser, and you are ready to go!

From PHP 5.4.0 it's possible to run the web demo from the command line using the built-in web server. To run the web demo using the provided web server, execute the following command from within the web demo directory:

php -S localhost:8080 -t .

The web demo application will now be accessible through your web browser on the "`http://localhost:8080/`" address.
15 changes: 15 additions & 0 deletions config-example.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
; Define your MultiChain node credentials below.

[default]
name=Default ; name to display in the web interface
rpchost=127.0.0.1 ; IP address of MultiChain node
rpcport=12345 ; usually default-rpc-port from params.dat
rpcuser=multichainrpc ; username for RPC from multichain.conf
rpcpassword= ; password for RPC from multichain.conf

; You can configure support for other nodes using a word other than 'default':
;
; [another]
; name=...
; rpchost=...
; ...etc...
13 changes: 0 additions & 13 deletions config-example.txt

This file was deleted.

32 changes: 12 additions & 20 deletions functions.php
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
<?php

function read_config()
{
$config=array();

$contents=file_get_contents('config.txt');
$lines=explode("\n", $contents);

foreach ($lines as $line) {
$content=explode('#', $line);
$fields=explode('=', trim($content[0]));
if (count($fields)==2) {
if (is_numeric(strpos($fields[0], '.'))) {
$parts=explode('.', $fields[0]);
$config[$parts[0]][$parts[1]]=$fields[1];
} else {
$config[$fields[0]]=$fields[1];
}

function read_config($configFile="config.ini", $checkDepth=3)
{
$configPath = "";

while ($checkDepth > 0) {
if (file_exists($configPath . $configFile) ) {
break;
}
$configPath .= ".." . DIRECTORY_SEPARATOR;
$checkDepth -= 1;
}
return $config;

return parse_ini_file($configPath . $configFile, true);
}

function json_rpc_send($host, $port, $user, $password, $method, $params=array())
Expand Down