Welcome to mirror list, hosted at ThFree Co, Russian Federation.

lib.inc.php « src - github.com/HuasoFoundries/phpPgAdmin6.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6a3956be8ce880cb8caec16b9b6caff4c7890de6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?php

/**
 * PHPPgAdmin 6.0.0
 */

\defined('BASE_PATH') || \define('BASE_PATH', \dirname(__DIR__));

\defined('THEME_PATH') || \define('THEME_PATH', \dirname(__DIR__) . '/assets/themes');
// Enforce PHP environment
\ini_set('arg_separator.output', '&amp;');

if (!\is_writable(\dirname(__DIR__) . '/temp')) {
    die('Your temp folder must have write permissions (use chmod 777 temp -R on linux)');
}

require_once \dirname(__DIR__) . '/vendor/autoload.php';

$shouldSetSession = (\defined('PHP_SESSION_ACTIVE') ? \PHP_SESSION_ACTIVE !== \session_status() : !\session_id())
    && !\headers_sent()
    && !\ini_get('session.auto_start');

if ($shouldSetSession && \PHP_SAPI !== 'cli') {
    \session_set_cookie_params(0, '/', $_SERVER['HTTP_HOST'], isset($_SERVER['HTTPS']));
    \session_name('PPA_ID');
    \session_start();
}
if (!\defined('ADODB_ERROR_HANDLER_TYPE')) {
    \define('ADODB_ERROR_HANDLER_TYPE', \E_USER_ERROR);
}

if (!\defined('ADODB_ERROR_HANDLER')) {
    \define('ADODB_ERROR_HANDLER', '\PHPPgAdmin\ADOdbException::adodb_throw');
}
function getAppInstance() {
    $subfolder = '';
    // Check to see if the configuration file exists, if not, explain
    if (!\file_exists(\dirname(__DIR__) . '/config.inc.php')) {
        die('Configuration error: Copy config.inc.php-dist to config.inc.php and edit appropriately.');
    }
$conf = [];

include_once \dirname(__DIR__) . '/config.inc.php';

if (isset($conf['subfolder']) && \is_string($conf['subfolder'])) {
    $subfolder = $conf['subfolder'];
} elseif (\PHP_SAPI === 'cli-server') {
    $subfolder = '/index.php';
} elseif (isset($_SERVER['DOCUMENT_ROOT'])) {
    $subfolder = \str_replace(
        $_SERVER['DOCUMENT_ROOT'],
        '',
        \dirname(__DIR__)
    );
}

$conf['subfolder'] = $subfolder;


$conf['debugmode'] = (!isset($conf['debugmode'])) ? false : (bool) ($conf['debugmode']);



if ($conf['debugmode']) {
    \ini_set('display_errors', 'On');

    \ini_set('display_startup_errors', 'On');
    \ini_set('opcache.revalidate_freq', '0');
    \error_reporting(\E_ALL);

    if (\array_key_exists('register_debuggers', $conf) && \is_callable($conf['register_debuggers'])) {
        $conf['register_debuggers']();
    }
}


$conf['BASE_PATH'] = BASE_PATH;
$conf['theme_path'] = BASE_PATH . '/assets/themes';
\defined('IN_TEST') || \define('IN_TEST', false);
$conf['IN_TEST'] = IN_TEST;
\ini_set('display_errors', strval($conf['debugmode']));
\defined('ADODB_ASSOC_CASE') || \define('ADODB_ASSOC_CASE', ADODB_ASSOC_CASE_NATIVE);

// Fetch App and DI Container
$app = \PHPPgAdmin\ContainerUtils::getAppInstance($conf);
return $app;
};

function containerInstance(): \PHPPgAdmin\ContainerUtils
{
    $app=getAppInstance();
    $container = $app->getContainer();
                if (!$container instanceof \PHPPgAdmin\ContainerUtils) {
                    \trigger_error('App Container must be an instance of \\Slim\\Container', \E_USER_ERROR);
                }
    return  $container;
}

function requestInstance(): \Slim\Http\Request
{
    return  \containerInstance()->request;
}

function responseInstance(): \Slim\Http\Response
{
    return \containerInstance()->response;
}
$app=getAppInstance();
$container=$app->getContainer();

// This should be deprecated once we're sure no php scripts are required directly
$container->offsetSet('server', $_REQUEST['server'] ?? null);
$container->offsetSet('database', $_REQUEST['database'] ?? null);
$container->offsetSet('schema', $_REQUEST['schema'] ?? null);

$container['haltHandler'] = static function (\PHPPgAdmin\ContainerUtils $c) {
    return static function ($request, $response, $exits, $status = 500) use ($c) {
        $title = 'PHPPgAdmin Error';

        $html = '<p>The application could not run because of the following error:</p>';

        $output = \sprintf(
            "<html><head><meta http-equiv='Content-Type' content='text/html; charset=utf-8'>" .
                '<title>%s</title><style>' .
                'body{margin:0;padding:30px;font:12px/1.5 Helvetica,Arial,Verdana,sans-serif;}' .
                'h3{margin:0;font-size:28px;font-weight:normal;line-height:30px;}' .
                'span{display:inline-block;font-size:16px;}' .
                '</style></head><body><h3>%s</h3><p>%s</p><span>%s</span></body></html>',
            $title,
            $title,
            $html,
            \implode('<br>', $exits)
        );

        $body = $response->getBody(); //new \Slim\Http\Body(fopen('php://temp', 'r+'));
        $body->write($output);

        return $response
            ->withStatus($status)
            ->withHeader('Content-type', 'text/html')
            ->withBody($body);
    };
};

// Set the requestobj and responseobj properties of the container
// as the value of $request and $response, which already contain the route
$app->add(new \PHPPgAdmin\Middleware\PopulateRequestResponse($container));

$container['action'] = $_REQUEST['action'] ?? '';

if (!isset($msg)) {
    $msg = '';
}

$container['msg'] = $msg;
//ddd($container->misc);