-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwenv.php
More file actions
127 lines (105 loc) · 3.95 KB
/
wenv.php
File metadata and controls
127 lines (105 loc) · 3.95 KB
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
<?php
/*
* @author Anakeen
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License
* @package FDL
*/
/**
* WHAT Environnement
*
* @author Anakeen 2004
* @version $Id: wenv.php,v 1.11 2008/05/06 17:04:16 jerome Exp $
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License
* @package FDL
*/
/**
*/
global $_SERVER;
function getBaseDirList()
{
include_once ('WHAT/Lib.Prefix.php');
# $bl[] = "default";
if (!is_dir(DEFAULT_PUBDIR . "/context/")) return $bl;
if ($dh = opendir(DEFAULT_PUBDIR . "/context/")) {
while (($file = readdir($dh)) !== false) {
if ($file != ".." && $file != "." && is_dir(DEFAULT_PUBDIR . "/context/" . $file) && file_exists(DEFAULT_PUBDIR . "/context/" . $file . "/dbaccess.php")) $bl[] = $file;
}
fclose($dh);
}
return $bl;
}
function setBaseDir($freedomctx = "default")
{
include_once ('WHAT/Lib.Prefix.php');
if (is_dir(DEFAULT_PUBDIR . "/context/" . $freedomctx)) return DEFAULT_PUBDIR . "/context/" . $freedomctx;
else return DEFAULT_PUBDIR;
}
function isRealDb($freedomctx = "default")
{
include_once ('WHAT/Lib.Prefix.php');
if (file_exists(DEFAULT_PUBDIR . "/context/" . $freedomctx . "/dbaccess.php")) return true;
return false;
}
function getPhpEnv($freedomctx)
{
include_once ('WHAT/Lib.Prefix.php');
$vdir = setBaseDir($freedomctx);
if (file_exists($vdir . "/dbaccess.php")) $env = $vdir . "/dbaccess.php";
else $env = $vdir . "/dbaccess.php";
return $env;
}
function getShEnv($freedomctx)
{
error_log("Deprecated call to getShEnv()");
return "";
include_once ('WHAT/Lib.Prefix.php');
$vdir = setBaseDir($freedomctx);
if (file_exists($vdir . "/dbaccess.sh")) $env = $vdir . "/dbaccess.sh";
else $env = $vdir . "/dbaccess.sh";
return $env;
}
function setCurrentDb($freedomctx = "default")
{
error_log("Deprecated call to setCurrentDb() in " . __FILE__ . " : use setCurrentContext(ctxName)");
return setCurrentContext($freedomctx);
}
function setCurrentContext($freedomctx = "default")
{
include_once ('WHAT/Lib.Prefix.php');
$fcur = fopen(DEFAULT_PUBDIR . "/.freedom", 'w');
fprintf($fcur, $freedomctx);
fclose($fcur);
$dpath = DEFAULT_PUBDIR . "/context/" . $freedomctx;
system(sprintf("ln -sf %s/dbaccess.sh %s/.freedom.sh", escapeshellarg($dpath) , escapeshellarg(DEFAULT_PUBDIR)));
}
function getCurrentDb()
{
error_log("Deprecated call to getCurrentDb in " . __FILE___ . " : use getCurrentContext()");
return getCurrentContext();
}
function getCurrentContext()
{
if (file_exists(DEFAULT_PUBDIR . "/.freedom")) return file_get_contents(DEFAULT_PUBDIR . "/.freedom");
return "default";
}
function initDbContext($freedomctx = "default", $pgservice_core = "anakeen", $pgservice_freedom = "freedom")
{
include_once ('WHAT/Lib.Prefix.php');
$inphpfile = DEFAULT_PUBDIR . "/dbaccess.php.in";
$inshfile = DEFAULT_PUBDIR . "/dbaccess.sh.in";
$vdir = DEFAULT_PUBDIR . "/context/" . $freedomctx;
$dbfphp = "$vdir/dbaccess.php";
$dbfsh = "$vdir/dbaccess.sh";
if (!is_dir($vdir)) mkdir($vdir, 0755, true);
if (file_exists($dbf)) return false;
$httpu = getenv("httpuser");
$httpconf = getenv("httpconf");
$sed_1 = sprintf('s/@PGSERVICE_CORE@/%s/g', str_replace('/', '\/', $pgservice_core));
$sed_2 = sprintf('s/@PGSERVICE_FREEDOM@/%s/g', str_replace('/', '\/', $pgservice_freedom));
$sed_3 = sprintf('s/@FREEDOM_CONTEXT@/%s/g', str_replace('/', '\/', $freedomctx));
$command = sprintf("sed -e %s -e %s -e %s", escapeshellarg($sed_1) , escapeshellarg($sed_2) , escapeshellarg($sed_3));
system(sprintf("cat %s | $command > %s", escapeshellarg($inphpfile) , escapeshellarg($dbfphp)));
system(sprintf("cat %s | $command > %s", escapeshellarg($inshfile) , escapeshellarg($dbfsh)));
setCurrentContext($freedomctx);
}
?>