Platform  3.1
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
wsh.php
Go to the documentation of this file.
1 #!/usr/bin/env php
2 <?php
3 /*
4  * @author Anakeen
5  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
6  * @package FDL
7 */
8 /**
9  * WHAT SHELL
10  *
11  * @author Anakeen 2002
12  * @version $Id: wsh.php,v 1.35 2008/05/06 08:43:33 jerome Exp $
13  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
14  * @package FDL
15  */
16 
17 ini_set("max_execution_time", "3600");
18 include_once ("WHAT/Lib.Prefix.php");
19 include_once ('Class.Action.php');
20 include_once ('Class.Application.php');
21 include_once ('Class.Session.php');
22 include_once ('Class.Log.php');
23 
24 function print_usage()
25 {
26  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";
27 }
28 wbar(1, -1, "initialisation");
29 $log = new Log("", "index.php");
30 
31 $CoreNull = "";
33 // get param
34 global $_GET;
35 global $_SERVER;
36 
37 if (isset($_SERVER['HTTP_HOST'])) {
38  print "<BR><H1>:~(</H1>";
39  exit(1);
40 }
41 if (count($argv) == 1) {
42  print_usage();
43 
44  exit(1);
45 }
46 
47 foreach ($argv as $k => $v) {
48 
49  if (preg_match("/--([^=]+)=(.+)/", $v, $reg)) {
50  $_GET[$reg[1]] = $reg[2];
51  } else if (preg_match("/--(.+)/", $v, $reg)) {
52  if ($reg[1] == "listapi") {
53  print "application list :\n";
54  echo "\t- ";
55  echo str_replace("\n", "\n\t- ", shell_exec(sprintf("cd %s/API;ls -1 *.php| cut -f1 -d'.'", escapeshellarg(DEFAULT_PUBDIR))));
56  echo "\n";
57  exit;
58  }
59  $_GET[$reg[1]] = true;
60  }
61 }
62 
63 if (($_GET["api"] == "") && ($_GET["app"] == "" || $_GET["action"] == "")) {
64  print_usage();
65  exit(1);
66 }
67 
69 if ($core->dbid < 0) {
70  print "Cannot access to main database";
71  exit(1);
72 }
73 
74 if (isset($_GET["userid"])) $core->user = new User("", $_GET["userid"]); //special user
75 $core->Set("CORE", $CoreNull);
76 $core->session = new Session();
77 if (!isset($_GET["userid"])) $core->user = new User("", 1); //admin
78 $CORE_LOGLEVEL = $core->GetParam("CORE_LOGLEVEL", "IWEF");
79 
81 $puburl = $core->GetParam("CORE_PUBURL", "http://" . $hostname . "/freedom");
82 
83 ini_set("memory_limit", -1);
84 
85 $absindex = $core->GetParam("CORE_URLINDEX");
86 if ($absindex == '') {
87  $absindex = "$puburl/"; // try default
88 
89 }
90 if ($absindex) $core->SetVolatileParam("CORE_EXTERNURL", $absindex);
91 else $core->SetVolatileParam("CORE_EXTERNURL", $puburl . "/");
92 
93 $core->SetVolatileParam("CORE_PUBURL", "."); // relative links
94 $core->SetVolatileParam("CORE_ABSURL", $puburl . "/"); // absolute links
95 $core->SetVolatileParam("CORE_JSURL", "WHAT/Layout");
96 $core->SetVolatileParam("CORE_ROOTURL", "$absindex?sole=R&");
97 $core->SetVolatileParam("CORE_BASEURL", "$absindex?sole=A&");
98 $core->SetVolatileParam("CORE_SBASEURL", "$absindex?sole=A&"); // no session
99 $core->SetVolatileParam("CORE_STANDURL", "$absindex?sole=Y&");
100 $core->SetVolatileParam("CORE_SSTANDURL", "$absindex?sole=Y&"); // no session
101 $core->SetVolatileParam("CORE_ASTANDURL", "$absindex?sole=Y&"); // absolute links
102 $core->SetVolatileParam("ISIE", false);
103 
104 if (isset($_GET["app"])) {
105  $appl = new Application();
106  $appl->Set($_GET["app"], $core);
107 } else {
108  $appl = $core;
109 }
110 
111 $action = new Action();
112 if (isset($_GET["action"])) {
113  $action->Set($_GET["action"], $appl);
114 } else {
115  $action->Set("", $appl);
116 }
117 // init for gettext
118 setLanguage($action->Getparam("CORE_LANG"));
119 
120 if (isset($_GET["api"])) {
121  $apifile = trim($_GET["api"]);
122  if (!file_exists(sprintf("%s/API/%s.php", DEFAULT_PUBDIR, $apifile))) {
123  echo sprintf(_("API file %s not found\n") , "API/" . $apifile . ".php");
124  } else {
125  try {
126  include ("API/" . $apifile . ".php");
127  }
128  catch(Exception $e) {
129  switch ($e->getCode()) {
130  case THROW_EXITERROR:
131  echo sprintf(_("Error : %s\n") , $e->getMessage());
132  exit(1);
133  break;
134 
135  default:
136  echo sprintf(_("Caught Exception : %s\n") , $e->getMessage());
137  exit(1);
138  }
139  }
140  }
141 } else {
142  if (!isset($_GET["wshfldid"])) {
143  try {
144  echo ($action->execute());
145  }
146  catch(Exception $e) {
147  switch ($e->getCode()) {
148  case THROW_EXITERROR:
149  echo sprintf(_("Error : %s\n") , $e->getMessage());
150  exit(1);
151  break;
152 
153  default:
154  echo sprintf(_("Caught Exception : %s\n") , $e->getMessage());
155  exit(1);
156  }
157  }
158  } else {
159  // REPEAT EXECUTION FOR FREEDOM FOLDERS
160  $dbaccess = $appl->GetParam("FREEDOM_DB");
161  if ($dbaccess == "") {
162  print "Database not found : param FREEDOM_DB";
163  exit;
164  }
165  include_once ("FDL/Class.Doc.php");
166  $http_iddoc = "id"; // default correspondance
167  if (isset($_GET["wshfldhttpdocid"])) $http_iddoc = $_GET["wshfldhttpdocid"];
168  $fld = new_Doc($dbaccess, $_GET["wshfldid"]);
169  $ld = $fld->getContent();
170  foreach ($ld as $k => $v) {
171  $_GET[$http_iddoc] = $v["id"];
172  try {
173  echo ($action->execute());
174  }
175  catch(Exception $e) {
176  switch ($e->getCode()) {
177  case THROW_EXITERROR:
178  echo sprintf(_("Error : %s\n") , $e->getMessage());
179  break;
180 
181  default:
182  echo sprintf(_("Caught Exception : %s\n") , $e->getMessage());
183  }
184  }
185  echo "<hr>";
186  }
187  }
188 }
189 
190 wbar(-1, -1, "completed");
191 
192 return (0);
193 ?>
← centre documentaire © anakeen - published under CC License - Dynacase