From 0f9ab8e01e931e6312fb979e792bc3f46a9909c3 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 16 Oct 2013 14:22:26 +0200 Subject: [PATCH] Allow configuring options, closes #30 --- .gitignore | 1 + README.mdown | 18 +++++++++++++++--- config.php.dist | 10 ++++++++++ index.php | 17 ++++++++++++++--- php-console.js | 8 ++++++-- 5 files changed, 46 insertions(+), 8 deletions(-) create mode 100644 config.php.dist diff --git a/.gitignore b/.gitignore index 22d0d82..7aa99c1 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ vendor +config.php diff --git a/README.mdown b/README.mdown index 88c9ec8..50000fe 100644 --- a/README.mdown +++ b/README.mdown @@ -3,9 +3,12 @@ PHP Console A web console to try your PHP code into -Creating a test file or using php's interactive mode can be a bit cumbersome to try random php snippets. This allows you to run small bits of code easily right from your browser. +Creating a test file or using php's interactive mode can be a bit cumbersome +to try random php snippets. This allows you to run small bits of code easily +right from your browser. -It is secure since accessible only from the local host, and very easy to setup and use. +It is secure since accessible only from the local host, and very easy to +setup and use. Screenshot ---------- @@ -15,12 +18,21 @@ Screenshot Installation ------------ -Clone the git repo or download it as a zip/tarball, drop it somewhere in your local web document root and access it with http://localhost/path/to/php-console +Clone the git repo or download it as a zip/tarball, drop it somewhere in your +local web document root and access it with http://localhost/path/to/php-console You can also install it with Composer using this command: composer create-project --stability=dev --keep-vcs seld/php-console +To update it just run `git pull` in the directory to pull the latest changes in. + +Configuration +------------- + +Default settings are available in `config.php.dist`, if you would like to modify +them, you can copy the file to `config.php` and edit settings. + Contributing ------------ diff --git a/config.php.dist b/config.php.dist new file mode 100644 index 0000000..406f7ae --- /dev/null +++ b/config.php.dist @@ -0,0 +1,10 @@ + 4, + + // whitelist of IPs which don't need to be authenticated + // use '*' to allow any IP + 'ip_whitelist' => array('127.0.0.1', '::1'), +); diff --git a/index.php b/index.php index a117bed..b17dbb9 100644 --- a/index.php +++ b/index.php @@ -1,12 +1,21 @@ 4, + // whitelist of IPs which don't need to be authenticated + // use '*' to allow any IP 'ip_whitelist' => array('127.0.0.1', '::1'), ); +if (file_exists(__DIR__.'/config.php')) { + $options = include __DIR__.'/config.php'; + $options = array_merge($defaults, $options); +} else { + $options = $defaults; +} + /** * PHP Console * @@ -20,7 +29,9 @@ $options = array( * * Source on Github http://github.com/Seldaek/php-console */ -if (!in_array($_SERVER['REMOTE_ADDR'], $options['ip_whitelist'], true)) { +if (!in_array('*', $options['ip_whitelist'], true) && + !in_array($_SERVER['REMOTE_ADDR'], $options['ip_whitelist'], true) +) { header('HTTP/1.1 401 Access unauthorized'); die('ERR/401 Go Away'); } diff --git a/php-console.js b/php-console.js index 7f53205..0d7561c 100644 --- a/php-console.js +++ b/php-console.js @@ -149,8 +149,12 @@ editor.getSession().setMode(new PhpMode()); // tab size - editor.getSession().setTabSize(options.tabsize); - editor.getSession().setUseSoftTabs(true); + if (options.tabsize) { + editor.getSession().setTabSize(options.tabsize); + editor.getSession().setUseSoftTabs(true); + } else { + editor.getSession().setUseSoftTabs(false); + } // events editor.getSession().selection.on('changeCursor', updateStatusBar);