15 ini_set(
"max_execution_time",
"0");
16 require_once
'WHAT/Lib.Prefix.php';
17 require_once
'Class.Action.php';
18 require_once
'Class.Application.php';
19 require_once
'Class.Session.php';
20 require_once
'Class.Log.php';
21 require_once
'Lib.Main.php';
29 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";
32 wbar(1, -1,
"initialisation");
41 print "<BR><H1>:~(</H1>";
44 if (count($argv) == 1) {
50 foreach ($argv as $k => $v) {
52 if (preg_match(
"/--([^=]+)=(.*)/", $v, $reg)) {
53 if (substr($reg[1], -2) ==
"[]") {
54 $_GET[substr($reg[1], 0, -2) ][] = $reg[2];
56 $_GET[$reg[1]] = $reg[2];
58 }
else if (preg_match(
"/--(.+)/", $v, $reg)) {
59 if ($reg[1] ==
"listapi") {
61 foreach (
new DirectoryIterator(
DEFAULT_PUBDIR . DIRECTORY_SEPARATOR .
'API') as $entry) {
62 if (preg_match(
'/^(?<basename>.+)\.php$/', $entry->getFilename() , $m)) {
63 $apiList[] = $m[
'basename'];
66 sort($apiList, SORT_STRING | SORT_FLAG_CASE);
67 print "application list :\n";
68 foreach ($apiList as $api) {
69 printf(
"\t- %s\n", $api);
74 $_GET[$reg[1]] =
true;
78 if ((empty(
$_GET[
"api"])) && (empty(
$_GET[
"app"]) || empty(
$_GET[
"action"]))) {
84 if (
$core->dbid < 0) {
85 print "Cannot access to main database";
89 if (isset(
$_GET[
"userid"])) {
90 if (!is_numeric(
$_GET[
"userid"])) {
100 ini_set(
"memory_limit", -1);
108 if (isset(
$_GET[
"app"])) {
116 if (isset(
$_GET[
"action"])) {
122 if (!
$core->user->isAffected()) {
126 if (
$core->user->status ===
"D") {
130 if (
$action->canExecute(
"CORE_ADMIN_ROOT",
"CORE_ADMIN") ===
'') {
132 $action->parent->setAdminMode();
135 catch(Dcp\Exception $e) {
141 if (isset(
$_GET[
"api"])) {
142 $apifile = trim(
$_GET[
"api"]);
143 if (!file_exists(sprintf(
"%s/API/%s.php",
DEFAULT_PUBDIR, $apifile))) {
144 echo sprintf(_(
"API file %s not found\n") ,
"API/" . $apifile .
".php");
148 include (
"API/" . $apifile .
".php");
151 switch ($e->getDcpCode()) {
153 echo sprintf(_(
"Error : %s\n") , $e->getDcpMessage());
159 echo sprintf($e->getDcpMessage());
164 echo sprintf($e->getDcpMessage());
169 catch(Dcp\Exception $e) {
172 catch(Exception $e) {
177 if (!isset(
$_GET[
"wshfldid"])) {
182 switch ($e->getDcpCode()) {
184 echo sprintf(_(
"Error : %s\n") , $e->getDcpMessage());
189 echo sprintf($e->getDcpMessage());
194 echo sprintf($e->getDcpMessage());
198 catch(Dcp\Exception $e) {
201 catch(Exception $e) {
208 print "Database not found : appl->dbaccess";
211 include_once (
"FDL/Class.Doc.php");
213 if (isset(
$_GET[
"wshfldhttpdocid"])) $http_iddoc =
$_GET[
"wshfldhttpdocid"];
218 $ld = $fld->getContent();
219 foreach ($ld as $k => $v) {
220 $_GET[$http_iddoc] = $v[
"id"];
224 catch(Exception $e) {
225 switch ($e->getCode()) {
239 wbar(-1, -1,
"completed");
_wsh_exception_handler($e, $callStack=true)
initMainVolatileParam(Application &$core, Session &$session=null)
wbar($reste, $total, $text="", $fbar=false)
initExplorerParam(Application &$app, $defaultValue=false)
if(isset($_SERVER['HTTP_HOST'])) if(count($argv)==1) foreach($argv as $k=> $v) if((empty($_GET["api"]))&&(empty($_GET["app"])||empty($_GET["action"]))) $core
new_Doc($dbaccess, $id= '', $latest=false)
Verify arguments for wsh programs.