示例#1
0
 /**
  * Execute Lua code with the PHP extension.
  * 
  * @param string $input
  * @return array<string> Stdout and stderr
  */
 private function executeWithExtension($input)
 {
     // We're using the extension - verify it exists
     if (!class_exists('lua')) {
         throw new LooahException("The Lua extension is unavailable");
     }
     // Create a lua instance and load the wrapper library
     $lua = new lua();
     try {
         $lua->evaluatefile($this->getCompiledWrapperPath());
         $lua->evaluate("wrap = make_wrapper({$this->maxLines}, {$this->maxRecursionDepth})");
         $res = $lua->wrap($input);
         return array($res[0], $res[1]);
     } catch (Exception $e) {
         throw new LooahException("Could not the evaluate Lua sandbox wrapper script");
     }
 }
示例#2
0
 /**
  * Parses the files and put it in $uploadData
  *
  * @return string $output | Output messages
  */
 function parseFiles()
 {
     global $roster;
     if (!is_array($_FILES)) {
         return '<span class="red">Upload failed: No files present</span>' . "<br />\n";
     }
     require_once ROSTER_LIB . 'luaparser.php';
     $output = $roster->locale->act['parsing_files'] . "<br />\n<ul>";
     foreach ($_FILES as $file) {
         if (!empty($file['name']) && $this->upload_error_check($file)) {
             $filename = explode('.', $file['name']);
             $filebase = strtolower($filename[0]);
             if (in_array($filebase, $this->files)) {
                 // Get start of parse time
                 $parse_starttime = format_microtime();
                 $luahandler = new lua();
                 $data = $luahandler->luatophp($file['tmp_name'], isset($this->blinds[$filebase]) ? $this->blinds[$filebase] : array());
                 // Calculate parse time
                 $parse_totaltime = round(format_microtime() - $parse_starttime, 2);
                 if ($data) {
                     $output .= '<li>' . sprintf($roster->locale->act['parsed_time'], $filename[0], $parse_totaltime) . "</li>\n";
                     $this->uploadData[$filebase] = $data;
                 } else {
                     $output .= '<li>' . sprintf($roster->locale->act['error_parsed_time'], $filebase, $parse_totaltime) . "</li>\n";
                     $output .= $luahandler->error() != '' ? '<li>' . $luahandler->error() . "</li>\n" : '';
                 }
                 unset($luahandler);
             } else {
                 $output .= '<li>' . sprintf($roster->locale->act['upload_not_accept'], $file['name']) . "</li>\n";
             }
         } else {
             $output .= '<li>' . sprintf($roster->locale->act['error_parsed_time'], $file['name'], '0') . "</li>\n";
         }
     }
     $output .= "</ul><br />\n";
     return $output;
 }