Xataface  2.0alpha2
Xataface Application Framework
 All Data Structures Namespaces Files Functions Variables Groups Pages
load_script.php
Go to the documentation of this file.
1 <?php
3 
4 
5  function handle($params){
6  session_write_close();
8  $expires = 60*60*72;
9  try {
10 
11 
12 
13  $query = $app->getQuery();
14 
15  $script = @$query['--script'];
16  if ( !$script ){
17  throw new Exception("Script could not be found", 404);
18  }
19 
20  $scripts = explode(',', $script);
21 
23 
24  $jt->clearScripts();
25  $app->fireEvent('beforeLoadScript');
26  foreach ($scripts as $script){
27  $script = trim($script);
28 
29  //echo '['.$script.']';exit;
30  $script = $this->sanitizePath($script);
31 
32  $jt->import($script);
33  }
34 
35  header('Connection:close');
36  $conf = Dataface_Application::getInstance()->_conf;
37  $conf = @$conf['Dataface_JavascriptTool'];
38  if ( !$conf ) $conf = array();
39  if ( !@$conf['debug'] ){
40  header("Pragma: public", true);
41  header("Cache-Control:max-age=".$expires.', public, s-maxage='.$expires, true);
42  header('Expires: ' . gmdate('D, d M Y H:i:s', time()+$expires) . ' GMT', true);
43  }
44  header('Content-type: text/javascript; charset="'.$app->_conf['oe'].'"');
45 
46  $out = $jt->getContents();
47  header('Content-Length: '.strlen($out));
48  echo $out;
49  flush();
50 
51  } catch (Exception $ex){
52 
53 
54  header('Content-type: text/javascript; charset="'.$app->_conf['oe'].'"');
55  $out = 'console.log('.json_encode($ex->getMessage()).');';
56  header('Content-Length: '.strlen($out));
57  echo $out;
58  flush();
59 
60  }
61 
62 
63 
64 
65  }
66 
67 
68  function sanitizePath($path){
69 
70  $parts = explode('/', $path);
71  foreach ($parts as $part){
72  if ( strpos($part, '\\') !== false ) throw new Exception("Illegal backslash in path.");
73  if ( preg_match('/\s/', $part) ) throw new Exception("Illegal white space in path.");
74  if ( $part == '..' ) throw new Exception("Illegal .. in path");
75 
76  }
77  $path = implode('/', $parts);
78  if ( $path{0} == '/' ) throw new Exception("Absolute paths not supported");
79  return $path;
80 
81  }
82 }