Allow configuring options, closes #30

master
Jordi Boggiano 11 years ago
parent 10ea7358dd
commit 0f9ab8e01e
  1. 1
      .gitignore
  2. 18
      README.mdown
  3. 10
      config.php.dist
  4. 17
      index.php
  5. 8
      php-console.js

1
.gitignore vendored

@ -1 +1,2 @@
vendor
config.php

@ -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
------------

@ -0,0 +1,10 @@
<?php
return array(
// how many spaces to use for indention, 0 will make it use real tabs
'tabsize' => 4,
// whitelist of IPs which don't need to be authenticated
// use '*' to allow any IP
'ip_whitelist' => array('127.0.0.1', '::1'),
);

@ -1,12 +1,21 @@
<?php
$options = array(
// which string should represent a tab for indentation
$defaults = array(
// how many spaces to use for indention, 0 will make it use real tabs
'tabsize' => 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');
}

@ -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);

Loading…
Cancel
Save