Skip to content

Commit

Permalink
Creating Tag v6.0.0-RC1 at 2020-01-07 - ignoring test folder for pack…
Browse files Browse the repository at this point in the history
…agist distro
  • Loading branch information
ffflabs committed Jan 7, 2020
1 parent bf0e617 commit b8dfbe4
Show file tree
Hide file tree
Showing 8 changed files with 196 additions and 154 deletions.
2 changes: 1 addition & 1 deletion .php_cs.cache

Large diffs are not rendered by default.

39 changes: 21 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,25 @@ PHP Based administration tool for PostgreSQL. Blazing fast routing with [Slim Fr

This is a hard fork of [phppgadmin](https://github.com/phppgadmin/phppgadmin) which adds the following enhancements:

- Composer Installation and dependency management
- Autoloading (thanks to the above)
- Namespaced classes
- Removal of global variables
- Full PHP 7+ support
- Support for PG 9.3+ features (Materialized Views, BRIN Indexes, etc)
- Nice urls
- Composer Installation and dependency management
- [PSR-2 Coding Standard](https://www.php-fig.org/psr/psr-2) (Will evolve to PSR-12 soon)
- [PSR-4 Autoloading](https://www.php-fig.org/psr/psr-4)
- Removal of global variables (WIP)
- Removal of superglobals in favour of [PSR-7 Message interfaces](http://www.php-fig.org/psr/psr-7/) (WIP)
- Full PHP 7+ support
- Usage of Dependency Injection compliant with [PSR-11 Container interface](http://www.php-fig.org/psr/psr-11/)
- Support for PG 9.3+ features (Materialized Views, BRIN Indexes, etc)
- Nice urls

### WIP

Other enhancements are in progress and would be a nice to have:

- Replace usage of superglobals with [PSR-7 Message interfaces](http://www.php-fig.org/psr/psr-7/) to carry information around.
- Usage of Dependency Injection compliant with [PSR-11 Container interface](http://www.php-fig.org/psr/psr-11/)
## Requirements

This project is made on top of [Slim Framework 3](https://www.slimframework.com/) and communicates with the Database using [AdoDB](https://adodb.org/)
- PHP 5.6+ (but you should really, really consider switching to at least v7.1)
- ext-psql
- [Composer](https://getcomposer.org/download/)

## Installation

Expand All @@ -51,7 +54,7 @@ composer install --no-dev
If there's something broken and I cannot risk breaking the rest to fix your issue, I might push a fix or feature to [develop branch](https://github.com/HuasoFoundries/phpPgAdmin6/tree/develop). Said branch can be installed as

```sh
composer create-project huasofoundries/phppgadmin6 <FOLDER> *@beta --no-dev --prefer-dist
composer create-project huasofoundries/phppgadmin6 <FOLDER> v6.*.*@beta --no-dev --prefer-dist
```

(or, you know, clone the repo and make sure you're in develop branch)
Expand Down Expand Up @@ -134,12 +137,12 @@ You can choose between one of them if you use this work.
We're preserving due credits to all people that contributed in the past, as well as other release notes
contained in the old version of [phppgadmin](https://github.com/phppgadmin/phppgadmin)

- [Bugs](docs/BUGS.md)
- [Changelog](docs/CHANGELOG.md) (_outdated_)
- [Credits](docs/CREDITS.md)
- [Developers](docs/DEVELOPERS.md)
- [FAQ](docs/FAQ.md) (_outdated_)
- [History](docs/HISTORY.md) (_outdated_)
- [Translators](docs/TRANSLATORS.md)
- [Bugs](docs/BUGS.md)
- [Changelog](docs/CHANGELOG.md) (_outdated_)
- [Credits](docs/CREDITS.md)
- [Developers](docs/DEVELOPERS.md)
- [FAQ](docs/FAQ.md) (_outdated_)
- [History](docs/HISTORY.md) (_outdated_)
- [Translators](docs/TRANSLATORS.md)

Kudos to all people that helped build the original project, upon which this one was built.
21 changes: 10 additions & 11 deletions config.inc.php-dist
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,39 @@



// Set this to true to enable debug features
$conf['debugmode'] = false;

// Enable this to debug on console using
// https://github.com/barbushin/php-console
// (Only in Chrome)
$conf['php_console'] = true;

$conf['debugmode'] = true;

if ($conf['php_console'] === true &&
// PHP_CONSOLE doesn't work on PHP 7.4 yet
version_compare(PHP_VERSION, 7.4, '<') &&
isset($_SERVER['HTTP_USER_AGENT']) &&
stripos($_SERVER['HTTP_USER_AGENT'], 'chrome') !== false) {
class_exists('PhpConsole\Handler')) {

$handler = PhpConsole\Handler::getInstance();
$phpConsoleHandler = PhpConsole\Handler::getInstance();

/* Get the reference to the connector instance
$connector=$phpConsoleHandler->getConnector();
*/
/* Set a password for PHPConsole Connector
$connector=$handler->getConnector();
$connector->setPassword('yohoho123', true);
*/

/* enable in SSL mode only
$connector->enableSslOnlyMode();
*/

/* Override default Handler behavior:
$handler->setHandleErrors(false); // disable errors handling
$handler->setHandleExceptions(false); // disable exceptions handling
$handler->setCallOldHandlers(false); // disable passing errors & exceptions to prviously defined handlers
$phpConsoleHandler->setHandleErrors(false); // disable errors handling
$phpConsoleHandler->setHandleExceptions(false); // disable exceptions handling
$phpConsoleHandler->setCallOldHandlers(false); // disable passing errors & exceptions to prviously defined handlers
*/

}


// optionally, set a path for your error log, relative to this project root
// $conf['error_log']='temp/phppga.php_error.log';

Expand Down
68 changes: 31 additions & 37 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,39 @@
* PHPPgAdmin v6.0.0-RC1
*/

require_once __DIR__ . '/src/lib.inc.php';
require_once __DIR__.'/src/lib.inc.php';

// This section is made to be able to parse requests coming from PHP Builtin webserver
if (PHP_SAPI === 'cli-server') {
//include_once __DIR__ . '/src/cli.router.php';
$will_redirect = false;
$req_uri = isset($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : $_SERVER['REQUEST_URI'];
$first10chars = substr($req_uri, 0, 10);
if ($first10chars === '/index.php') {
// @todo is PHP_SELF is not set, chances are REQUEST_URI won't either
$req_uri = isset($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : $_SERVER['REQUEST_URI'];
if (substr($req_uri, 0, 10) === '/index.php') {
$will_redirect = true;
$req_uri = substr($req_uri, 10);
}
$filePath = realpath(ltrim($req_uri, '/'));
$new_location = 'Location: http://' . $_SERVER['HTTP_HOST'] . $req_uri;

if ($filePath && is_readable($filePath)) {
// 1. check that file is not outside of this directory for security
// 2. check for circular reference to router.php
// 3. don't serve dotfiles

if (strpos($filePath, BASE_PATH . DIRECTORY_SEPARATOR) === 0 &&
$filePath != BASE_PATH . DIRECTORY_SEPARATOR . 'index.php' &&
substr(basename($filePath), 0, 1) != '.'
) {
if (strtolower(substr($filePath, -4)) == '.php') {
// php file; serve through interpreter
include $filePath;

return;
}
if ($will_redirect) {
header($new_location, true, 301);

return;
}
// asset file; serve from filesystem
return false;
$new_location = 'Location: http://'.$_SERVER['HTTP_HOST'].$req_uri;

if ($filePath && // 1. check that filepath is set
is_readable($filePath) && // 2. and references a readable file/folder
strpos($filePath, BASE_PATH.DIRECTORY_SEPARATOR) === 0 && // 3. And is inside this folder
$filePath != BASE_PATH.DIRECTORY_SEPARATOR.'index.php' && // 4. discard circular references to index.php
substr(basename($filePath), 0, 1) != '.' // 5. don't serve dotfiles
) {
if (strtolower(substr($filePath, -4)) == '.php') {
// php file; serve through interpreter
include $filePath;

return;
}
if ($will_redirect) {
header($new_location, true, 301);

return;
}
// asset file; serve from filesystem
return false;
}
}

Expand All @@ -53,7 +48,6 @@
/* @scrutinizer ignore-unused */
$args
) {

return $response
->withHeader('Content-type', 'application/json')
->withJson(['version' => $this->version]);
Expand All @@ -73,7 +67,7 @@
$loginShared = $request->getParsedBodyParam('loginShared');
$loginServer = $request->getParsedBodyParam('loginServer');
$loginUsername = $request->getParsedBodyParam('loginUsername');
$loginPassword = $request->getParsedBodyParam('loginPassword_' . md5($loginServer));
$loginPassword = $request->getParsedBodyParam('loginPassword_'.md5($loginServer));

// If login action is set, then set session variables
if ((bool) $loginServer && (bool) $loginUsername && $loginPassword !== null) {
Expand Down Expand Up @@ -146,16 +140,16 @@
$safe_subjects = ($subject === 'servers' || $subject === 'intro' || $subject === 'browser');

if ($this->misc->getServerId() === null && !$safe_subjects) {
return $response->withStatus(302)->withHeader('Location', SUBFOLDER . '/src/views/servers');
return $response->withStatus(302)->withHeader('Location', SUBFOLDER.'/src/views/servers');
}

if (!isset($_server_info['username']) && $subject !== 'login' && !$safe_subjects) {
$destinationurl = SUBFOLDER . '/src/views/login?server=' . $this->misc->getServerId();
$destinationurl = SUBFOLDER.'/src/views/login?server='.$this->misc->getServerId();

return $response->withStatus(302)->withHeader('Location', $destinationurl);
}

$className = '\PHPPgAdmin\Controller\\' . ucfirst($subject) . 'Controller';
$className = '\PHPPgAdmin\Controller\\'.ucfirst($subject).'Controller';
$controller = new $className($this);

return $controller->render();
Expand Down Expand Up @@ -184,7 +178,7 @@
$subject = 'servers';
}

return maybeRenderIframes($this, $response, $subject, $query_string);
return $this->utils->maybeRenderIframes($response, $subject, $query_string);
});

$app->get('/', function (
Expand All @@ -199,11 +193,11 @@

$query_string = $request->getUri()->getQuery();

return maybeRenderIframes($this, $response, $subject, $query_string);
return $this->utils->maybeRenderIframes($response, $subject, $query_string);
});

$app->get('[/{path:.*}]', function ($request, $response, $args) {
$filepath = \BASE_PATH . '/' . $args['path'];
$filepath = \BASE_PATH.'/'.$args['path'];
$query_string = $request->getUri()->getQuery();

$this->utils->dump($query_string, $filepath);
Expand Down
34 changes: 27 additions & 7 deletions src/classes/ContainerUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ContainerUtils
*/
public function __construct()
{
$composerinfo = json_decode(file_get_contents(BASE_PATH . '/composer.json'));
$composerinfo = json_decode(file_get_contents(BASE_PATH.'/composer.json'));
$appVersion = $composerinfo->version;

$phpMinVer = (str_replace(['<', '>', '='], '', $composerinfo->require->php));
Expand All @@ -49,14 +49,14 @@ public function __construct()
'base_path' => BASE_PATH,
'debug' => DEBUGMODE,

'routerCacheFile' => BASE_PATH . '/temp/route.cache.php',
'routerCacheFile' => BASE_PATH.'/temp/route.cache.php',

// Configuration file version. If this is greater than that in config.inc.php, then
// the app will refuse to run. This and $conf['version'] should be incremented whenever
// backwards incompatible changes are made to config.inc.php-dist.
'base_version' => 60,
// Application version
'appVersion' => 'v' . $appVersion,
'appVersion' => 'v'.$appVersion,
// Application name
'appName' => 'phpPgAdmin6',

Expand All @@ -73,7 +73,7 @@ public function __construct()
// Fetch DI Container
$container = $this->app->getContainer();
$container['utils'] = $this;
$container['version'] = 'v' . $appVersion;
$container['version'] = 'v'.$appVersion;
$container['errors'] = [];

$this->container = $container;
Expand All @@ -88,6 +88,26 @@ public static function createContainer()
return [self::$instance->container, self::$instance->app];
}

public function maybeRenderIframes($response, $subject, $query_string)
{
$c = $this->container;
$in_test = $c->view->offsetGet('in_test');

if ($in_test === '1') {
$className = '\PHPPgAdmin\Controller\\'.ucfirst($subject).'Controller';
$controller = new $className($c);

return $controller->render();
}

$viewVars = [
'url' => '/src/views/'.$subject.($query_string ? '?'.$query_string : ''),
'headertemplate' => 'header.twig',
];

return $c->view->render($response, 'iframe_view.twig', $viewVars);
}

/**
* Gets the theme from
* 1. The $_REQUEST global (when it's chosen from start screen)
Expand Down Expand Up @@ -186,10 +206,10 @@ public function getRedirectUrl()

// if server_id isn't set, then you will be redirected to intro
if ($this->container->requestobj->getQueryParam('server') === null) {
$destinationurl = \SUBFOLDER . '/src/views/intro';
$destinationurl = \SUBFOLDER.'/src/views/intro';
} else {
// otherwise, you'll be redirected to the login page for that server;
$destinationurl = \SUBFOLDER . '/src/views/login' . ($query_string ? '?' . $query_string : '');
$destinationurl = \SUBFOLDER.'/src/views/login'.($query_string ? '?'.$query_string : '');
}

return $destinationurl;
Expand All @@ -213,7 +233,7 @@ public function getDestinationWithLastTab($subject)
$destinationurl = $this->getRedirectUrl();
} else {
$url = $this->container->misc->getLastTabURL($subject);
$this->addFlash($url, 'getLastTabURL for ' . $subject);
$this->addFlash($url, 'getLastTabURL for '.$subject);
// Load query vars into superglobal arrays
if (isset($url['urlvars'])) {
$urlvars = [];
Expand Down
Loading

0 comments on commit b8dfbe4

Please sign in to comment.