-
Notifications
You must be signed in to change notification settings - Fork 0
/
wsh.php
executable file
·193 lines (170 loc) · 5.79 KB
/
wsh.php
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#!/usr/bin/env php
<?php
/*
* @author Anakeen
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License
* @package FDL
*/
/**
* WHAT SHELL
*
* @author Anakeen 2002
* @version $Id: wsh.php,v 1.35 2008/05/06 08:43:33 jerome Exp $
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License
* @package FDL
*/
ini_set("max_execution_time", "3600");
include_once ("WHAT/Lib.Prefix.php");
include_once ('Class.Action.php');
include_once ('Class.Application.php');
include_once ('Class.Session.php');
include_once ('Class.Log.php');
function print_usage()
{
print "Usage\twsh.php --app=APPLICATION --action=ACTION [--ARG=VAL] ...: execute an action\n" . "\twsh.php --api=API [--ARG=VAL] .... : execute an api function\n" . "\twsh.php --listapi : view api list\n";
}
wbar(1, -1, "initialisation");
$log = new Log("", "index.php");
$CoreNull = "";
global $CORE_LOGLEVEL;
// get param
global $_GET;
global $_SERVER;
if (isset($_SERVER['HTTP_HOST'])) {
print "<BR><H1>:~(</H1>";
exit(1);
}
if (count($argv) == 1) {
print_usage();
exit(1);
}
foreach ($argv as $k => $v) {
if (preg_match("/--([^=]+)=(.+)/", $v, $reg)) {
$_GET[$reg[1]] = $reg[2];
} else if (preg_match("/--(.+)/", $v, $reg)) {
if ($reg[1] == "listapi") {
print "application list :\n";
echo "\t- ";
echo str_replace("\n", "\n\t- ", shell_exec(sprintf("cd %s/API;ls -1 *.php| cut -f1 -d'.'", escapeshellarg(DEFAULT_PUBDIR))));
echo "\n";
exit;
}
$_GET[$reg[1]] = true;
}
}
if (($_GET["api"] == "") && ($_GET["app"] == "" || $_GET["action"] == "")) {
print_usage();
exit(1);
}
$core = new Application();
if ($core->dbid < 0) {
print "Cannot access to main database";
exit(1);
}
if (isset($_GET["userid"])) $core->user = new User("", $_GET["userid"]); //special user
$core->Set("CORE", $CoreNull);
$core->session = new Session();
if (!isset($_GET["userid"])) $core->user = new User("", 1); //admin
$CORE_LOGLEVEL = $core->GetParam("CORE_LOGLEVEL", "IWEF");
$hostname = LibSystem::getHostName();
$puburl = $core->GetParam("CORE_PUBURL", "http://" . $hostname . "/freedom");
ini_set("memory_limit", $core->GetParam("MEMORY_LIMIT", "32") . "M");
$absindex = $core->GetParam("CORE_URLINDEX");
if ($absindex == '') {
$absindex = "$puburl/"; // try default
}
if ($absindex) $core->SetVolatileParam("CORE_EXTERNURL", $absindex);
else $core->SetVolatileParam("CORE_EXTERNURL", $puburl . "/");
$core->SetVolatileParam("CORE_PUBURL", "."); // relative links
$core->SetVolatileParam("CORE_ABSURL", $puburl . "/"); // absolute links
$core->SetVolatileParam("CORE_JSURL", "WHAT/Layout");
$core->SetVolatileParam("CORE_ROOTURL", "$absindex?sole=R&");
$core->SetVolatileParam("CORE_BASEURL", "$absindex?sole=A&");
$core->SetVolatileParam("CORE_SBASEURL", "$absindex?sole=A&"); // no session
$core->SetVolatileParam("CORE_STANDURL", "$absindex?sole=Y&");
$core->SetVolatileParam("CORE_SSTANDURL", "$absindex?sole=Y&"); // no session
$core->SetVolatileParam("CORE_ASTANDURL", "$absindex?sole=Y&"); // absolute links
$core->SetVolatileParam("ISIE", false);
if (isset($_GET["app"])) {
$appl = new Application();
$appl->Set($_GET["app"], $core);
} else {
$appl = $core;
}
$action = new Action();
if (isset($_GET["action"])) {
$action->Set($_GET["action"], $appl);
} else {
$action->Set("", $appl);
}
// init for gettext
setLanguage($action->Getparam("CORE_LANG"));
if (isset($_GET["api"])) {
$apifile = trim($_GET["api"]);
if (!file_exists(sprintf("%s/API/%s.php", DEFAULT_PUBDIR, $apifile))) {
echo sprintf(_("API file %s not found\n") , "API/" . $apifile . ".php");
} else {
try {
include ("API/" . $apifile . ".php");
}
catch(Exception $e) {
switch ($e->getCode()) {
case THROW_EXITERROR:
echo sprintf(_("Error : %s\n") , $e->getMessage());
exit(1);
break;
default:
echo sprintf(_("Caught Exception : %s\n") , $e->getMessage());
exit(1);
}
}
}
} else {
if (!isset($_GET["wshfldid"])) {
try {
echo ($action->execute());
}
catch(Exception $e) {
switch ($e->getCode()) {
case THROW_EXITERROR:
echo sprintf(_("Error : %s\n") , $e->getMessage());
exit(1);
break;
default:
echo sprintf(_("Caught Exception : %s\n") , $e->getMessage());
exit(1);
}
}
} else {
// REPEAT EXECUTION FOR FREEDOM FOLDERS
$dbaccess = $appl->GetParam("FREEDOM_DB");
if ($dbaccess == "") {
print "Database not found : param FREEDOM_DB";
exit;
}
include_once ("FDL/Class.Doc.php");
$http_iddoc = "id"; // default correspondance
if (isset($_GET["wshfldhttpdocid"])) $http_iddoc = $_GET["wshfldhttpdocid"];
$fld = new_Doc($dbaccess, $_GET["wshfldid"]);
$ld = $fld->getContent();
foreach ($ld as $k => $v) {
$_GET[$http_iddoc] = $v["id"];
try {
echo ($action->execute());
}
catch(Exception $e) {
switch ($e->getCode()) {
case THROW_EXITERROR:
echo sprintf(_("Error : %s\n") , $e->getMessage());
break;
default:
echo sprintf(_("Caught Exception : %s\n") , $e->getMessage());
}
}
echo "<hr>";
}
}
}
wbar(-1, -1, "completed");
return (0);
?>