Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
reconfigure_core_tmpdir.php
Go to the documentation of this file.
1 #!/usr/bin/env php
2 <?php
3 /*
4  * @author Anakeen
5  * @package FDL
6 */
7 
8 $WIFF_ROOT = getenv("WIFF_ROOT");
9 if ($WIFF_ROOT === false) {
10  print "WIFF_ROOT environment variable is not set!\n";
11  exit(1);
12 }
13 
14 $WIFF_CONTEXT_ROOT = getenv("WIFF_CONTEXT_ROOT");
15 if ($WIFF_CONTEXT_ROOT === false) {
16  print "WIFF_CONTEXT_ROOT environment variable not set!\n";
17  exit(1);
18 }
19 
20 set_include_path(get_include_path() . PATH_SEPARATOR . $WIFF_CONTEXT_ROOT . PATH_SEPARATOR . "$WIFF_ROOT/include");
21 
22 require_once ('WHAT/Lib.Common.php');
23 require_once ('WHAT/Class.Log.php');
24 
25 main($WIFF_CONTEXT_ROOT, $argv);
26 
27 function usage($me)
28 {
29  print <<<EOF
30 Usage
31 -----
32 
33  $me <'check'|'reconfigure'> <'CORE_TMMPDIR'|'FREEDOM_UPLOADDIR'>
34 
35 
36 EOF;
37 
38 
39 }
40 
41 function main($WIFF_CONTEXT_ROOT, &$argv)
42 {
43  $me = array_shift($argv);
44  if (count($argv) != 2) {
45  usage($me);
46  exit(1);
47  }
48  $cmd = array_shift($argv);
49  $paramName = array_shift($argv);
50 
51  $ret = false;
52  switch ($cmd) {
53  case 'check':
54  $ret = check($WIFF_CONTEXT_ROOT, $paramName);
55  break;
56 
57  case 'reconfigure':
58  $ret = reconfigure($WIFF_CONTEXT_ROOT, $paramName);
59  break;
60 
61  default:
62  usage($me);
63  }
64  exit(($ret === false) ? 1 : 0);
65 }
66 
67 function check($WIFF_CONTEXT_ROOT, $paramName)
68 {
69  $log = new Log("", "CORE");
70  $paramValue = getCoreParam($paramName, false);
71  if ($paramValue === false || !pathIsUnderContext($WIFF_CONTEXT_ROOT, $paramValue)) {
72  $log->warning(sprintf("Parameter '%s' references a directory outside the context's root: '%s'.", $WIFF_CONTEXT_ROOT, $paramName, $paramValue));
73  return false;
74  }
75  return true;
76 }
77 
78 function reconfigure($WIFF_CONTEXT_ROOT, $paramName)
79 {
80  $log = new Log("", "CORE");
81  if (check($WIFF_CONTEXT_ROOT, $paramName) === true) {
82  return true;
83  }
84  $log->warning(sprintf("Restoring default value for parameter '%s'.", $paramName));
85  $err = simpleQuery('', sprintf('UPDATE paramv SET val = %s WHERE name = %s', pg_escape_literal('./var/tmp') , pg_escape_literal($paramName)));
86  if ($err != '') {
87  $msg = sprintf("Error setting '%s' to '%s': %s", $paramName, './var/tmp', $err);
88  printf("%s\n", $msg);
89  $log->warning($msg);
90  return false;
91  }
92  return true;
93 }
94 
95 function pathIsUnderContext($contextRoot, $path)
96 {
97  $realPath = realpath($contextRoot);
98  if ($realPath === false) {
99  printf("Error: could not get realpath from context root '%s'!\n", $contextRoot);
100  return false;
101  }
102  $contextRoot = $realPath;
103  if (!file_exists($path)) {
104  printf("Warning: path '%s' does not exists!\n", $path);
105  return false;
106  }
107  $realPath = realpath($path);
108  if ($realPath === false) {
109  printf("Error: could not get realpath from path '%s'!\n", $path);
110  return false;
111  }
112  $path = $realPath;
113  return (strpos($path, $contextRoot) === 0);
114 }
main($WIFF_CONTEXT_ROOT, &$argv)
reconfigure($WIFF_CONTEXT_ROOT, $paramName)
if($WIFF_ROOT===false) $WIFF_CONTEXT_ROOT
$ret
$log
Definition: wsh.php:33
foreach($argv as $arg) $cmd
$path
Definition: dav.php:39
print
Definition: checklist.php:49
switch($command) exit
Definition: checkVault.php:46
pathIsUnderContext($contextRoot, $path)
simpleQuery($dbaccess, $query, &$result=array(), $singlecolumn=false, $singleresult=false, $useStrict=null)
Definition: Lib.Common.php:484
if($file) if($subject==""&&$file) if($subject=="") $err
check($WIFF_CONTEXT_ROOT, $paramName)
getCoreParam($name, $def="")
must be in core or global type
Definition: Lib.Common.php:209
← centre documentaire © anakeen