コード例 #1
0
ファイル: loadsave.php プロジェクト: neymanna/fusionforge
function LoadDir(&$request, $dirname, $files = false, $exclude = false)
{
    $fileset = new LimitedFileSet($dirname, $files, $exclude);
    if (!$files and $skiplist = $fileset->getSkippedFiles()) {
        PrintXML(HTML::dt(HTML::strong(_("Skipping"))));
        $list = HTML::ul();
        foreach ($skiplist as $file) {
            $list->pushContent(HTML::li(WikiLink($file)));
        }
        PrintXML(HTML::dd($list));
    }
    // Defer HomePage loading until the end. If anything goes wrong
    // the pages can still be loaded again.
    $files = $fileset->getFiles();
    if (in_array(HOME_PAGE, $files)) {
        $files = array_diff($files, array(HOME_PAGE));
        $files[] = HOME_PAGE;
    }
    $timeout = !$request->getArg('start_debug') ? 20 : 120;
    foreach ($files as $file) {
        longer_timeout($timeout);
        // longer timeout per page
        if (substr($file, -1, 1) != '~') {
            // refuse to load backup files
            LoadFile($request, "{$dirname}/{$file}");
        }
    }
}
コード例 #2
0
ファイル: SyncWiki.php プロジェクト: hugcoday/wiki
 function _do_syncwiki(&$request, $args)
 {
     global $charset;
     longer_timeout(240);
     if (!function_exists('wiki_xmlrpc_post')) {
         include_once "lib/XmlRpcClient.php";
     }
     $userid = $request->_user->_userid;
     $dbh = $request->getDbh();
     $merge_point = $dbh->get('mergepoint');
     if (empty($merge_point)) {
         $page = $dbh->getPage("ReleaseNotes");
         // this is usually the latest official page
         $last = $page->getCurrentRevision(false);
         $merge_point = $last->get("mtime");
         // for testing: 1160396075
         $dbh->set('mergepoint', $merge_point);
     }
     //TODO: remote auth, set session cookie
     $pagelist = wiki_xmlrpc_post('wiki.getRecentChanges', iso8601_encode($merge_point, 1), $args['url'], $args);
     $html = HTML();
     //$html->pushContent(HTML::div(HTML::em("check RPC2 interface...")));
     if (gettype($pagelist) === "array") {
         //$request->_deferredPageChangeNotification = array();
         $request->discardOutput();
         StartLoadDump($request, _("Syncing this PhpWiki"));
         PrintXML(HTML::strong(fmt("Download all externally changed sources.")));
         echo "<br />\n";
         PrintXML(fmt("Retrieving from external url %s wiki.getRecentChanges(%s)...", $args['url'], iso8601_encode($merge_point, 1)));
         echo "<br />\n";
         $ouriter = $dbh->mostRecent(array('since' => $merge_point));
         //$ol = HTML::ol();
         $done = array();
         foreach ($pagelist as $ext) {
             $reaction = _("<unknown>");
             // compare existance and dates with local page
             $extdate = iso8601_decode($ext['lastModified']->scalar, 1);
             // TODO: urldecode ???
             $name = utf8_decode($ext['name']);
             $our = $dbh->getPage($name);
             $done[$name] = 1;
             $ourrev = $our->getCurrentRevision(false);
             $rel = '<=>';
             if (!$our->exists()) {
                 // we might have deleted or moved it on purpose?
                 // check date of latest revision if there's one, and > mergepoint
                 if ($ourrev->getVersion() > 1 and $ourrev->get('mtime') > $merge_point) {
                     // our was deleted after sync, and changed after last sync.
                     $this->_addConflict('delete', $args, $our, $extdate);
                     $reaction = _(" skipped") . " (" . "locally deleted or moved" . ")";
                 } else {
                     $reaction = $this->_import($args, $our, $extdate);
                 }
             } else {
                 $ourdate = $ourrev->get('mtime');
                 if ($extdate > $ourdate and $ourdate < $merge_point) {
                     $rel = '>';
                     $reaction = $this->_import($args, $our, $extdate);
                 } elseif ($extdate > $ourdate and $ourdate >= $merge_point) {
                     $rel = '>';
                     // our is older then external but newer than last sync
                     $reaction = $this->_addConflict('import', $args, $our, $extdate);
                 } elseif ($extdate < $ourdate and $extdate < $merge_point) {
                     $rel = '>';
                     $reaction = $this->_export($args, $our);
                 } elseif ($extdate < $ourdate and $extdate >= $merge_point) {
                     $rel = '>';
                     // our is newer and external is also newer
                     $reaction = $this->_addConflict('export', $args, $our, $extdate);
                 } else {
                     $rel = '==';
                     $reaction = _("same date");
                 }
             }
             /*$ol->pushContent(HTML::li(HTML::strong($name)," ",
               $extdate,"<=>",$ourdate," ",
               HTML::strong($reaction))); */
             PrintXML(HTML::strong($name), " ", $extdate, " {$rel} ", $ourdate, " ", HTML::strong($reaction), HTML::br());
             $request->chunkOutput();
         }
         //$html->pushContent($ol);
     } else {
         $html->pushContent("xmlrpc error:  wiki.getRecentChanges returned " . "(" . gettype($pagelist) . ") " . $pagelist);
         trigger_error("xmlrpc error:  wiki.getRecentChanges returned " . "(" . gettype($pagelist) . ") " . $pagelist, E_USER_WARNING);
         EndLoadDump($request);
         return $this->error($html);
     }
     if (empty($args['noexport'])) {
         PrintXML(HTML::strong(fmt("Now upload all locally newer pages.")));
         echo "<br />\n";
         PrintXML(fmt("Checking all local pages newer than %s...", iso8601_encode($merge_point, 1)));
         echo "<br />\n";
         while ($our = $ouriter->next()) {
             $name = $our->getName();
             if ($done[$name]) {
                 continue;
             }
             $reaction = _(" skipped");
             $ext = wiki_xmlrpc_post('wiki.getPageInfo', $name, $args['url']);
             if (is_array($ext)) {
                 $extdate = iso8601_decode($ext['lastModified']->scalar, 1);
                 $ourdate = $our->get('mtime');
                 if ($extdate < $ourdate and $extdate < $merge_point) {
                     $reaction = $this->_export($args, $our);
                 } elseif ($extdate < $ourdate and $extdate >= $merge_point) {
                     // our newer and external newer
                     $reaction = $this->_addConflict($args, $our, $extdate);
                 }
             } else {
                 $reaction = 'xmlrpc error';
             }
             PrintXML(HTML::strong($name), " ", $extdate, " < ", $ourdate, " ", HTML::strong($reaction), HTML::br());
             $request->chunkOutput();
         }
         PrintXML(HTML::strong(fmt("Now upload all locally newer uploads.")));
         echo "<br />\n";
         PrintXML(fmt("Checking all local uploads newer than %s...", iso8601_encode($merge_point, 1)));
         echo "<br />\n";
         $this->_fileList = array();
         $prefix = getUploadFilePath();
         $this->_dir($prefix);
         $len = strlen($prefix);
         foreach ($this->_fileList as $path) {
             // strip prefix
             $file = substr($path, $len);
             $ourdate = filemtime($path);
             $oursize = filesize($path);
             $reaction = _(" skipped");
             $ext = wiki_xmlrpc_post('wiki.getUploadedFileInfo', $file, $args['url']);
             if (is_array($ext)) {
                 $extdate = iso8601_decode($ext['lastModified']->scalar, 1);
                 $extsize = $ext['size'];
                 if (empty($extsize) or $extdate < $ourdate) {
                     $timeout = $oursize * 0.0002;
                     // assume 50kb/sec upload speed
                     $reaction = $this->_upload($args, $path, $timeout);
                 }
             } else {
                 $reaction = 'xmlrpc error wiki.getUploadedFileInfo not supported';
             }
             PrintXML(HTML::strong($name), " ", "{$extdate} ({$extsize}) < {$ourdate} ({$oursize})", HTML::strong($reaction), HTML::br());
             $request->chunkOutput();
         }
     }
     $dbh->set('mergepoint', time());
     EndLoadDump($request);
     return '';
     //$html;
 }
コード例 #3
0
ファイル: upgrade.php プロジェクト: hugcoday/wiki
 /**
  * upgrade to 1.3.13 link structure.
  */
 function _upgrade_relation_links($verbose = true)
 {
     if ($this->phpwiki_version >= 1030.1220061 and $this->isSQL) {
         echo _("Check for relation field in link table"), " ...";
         $database = $this->dbi->_backend->database();
         $link_tbl = $prefix . 'link';
         $fields = $this->dbi->_backend->listOfFields($database, $link_tbl);
         if (!$fields) {
             echo _("SKIP");
         } elseif (strstr(strtolower(join(':', $fields)), "link")) {
             echo "<b>", _("ADDING"), " relation</b>", " ... ";
             $this->dbi->genericSqlQuery("ALTER TABLE {$link_tbl} ADD relation INT DEFAULT 0;");
             $this->dbi->genericSqlQuery("CREATE INDEX link_relation ON {$link_tbl} (relation);");
         } else {
             echo _("FAIL");
         }
         echo "<br />\n";
     }
     if ($this->phpwiki_version >= 1030.1220061) {
         echo _("Rebuild entire database to upgrade relation links"), " ... ";
         if (DATABASE_TYPE == 'dba') {
             echo "<b>", _("CONVERTING"), " dba linktable</b>", "(~2 min, max 4 min) ... ";
             flush();
             longer_timeout(240);
             $this->dbi->_backend->_linkdb->rebuild();
         } else {
             flush();
             longer_timeout(180);
             $this->dbi->_backend->rebuild();
         }
         echo _("OK"), "<br />\n";
     }
 }
コード例 #4
0
ファイル: HttpClient.php プロジェクト: neymanna/fusionforge
 function doRequest()
 {
     // Performs the actual HTTP request, returning true or false depending on outcome
     // Ensure that the PHP timeout is longer than the socket timeout
     longer_timeout($this->timeout);
     if (!($fp = @fsockopen($this->host, $this->port, $errno, $errstr, $this->timeout))) {
         // Set error message
         switch ($errno) {
             case -3:
                 $this->errormsg = 'Socket creation failed (-3)';
             case -4:
                 $this->errormsg = 'DNS lookup failure (-4)';
             case -5:
                 $this->errormsg = 'Connection refused or timed out (-5)';
             default:
                 $this->errormsg = 'Connection failed (' . $errno . ')';
                 $this->errormsg .= ' ' . $errstr;
                 $this->debug($this->errormsg);
         }
         return false;
     }
     if (check_php_version(4, 3, 0)) {
         socket_set_timeout($fp, $this->timeout);
     }
     $request = $this->buildRequest();
     $this->debug('Request', $request);
     fwrite($fp, $request);
     // Reset all the variables that should not persist between requests
     $this->headers = array();
     $this->content = '';
     $this->errormsg = '';
     // Set a couple of flags
     $inHeaders = true;
     $atStart = true;
     // Now start reading back the response
     while (!feof($fp)) {
         $line = fgets($fp, 4096);
         if ($atStart) {
             // Deal with first line of returned data
             $atStart = false;
             if (!preg_match('/HTTP\\/(\\d\\.\\d)\\s*(\\d+)\\s*(.*)/', $line, $m)) {
                 $this->errormsg = "Status code line invalid: " . htmlentities($line);
                 $this->debug($this->errormsg);
                 return false;
             }
             $http_version = $m[1];
             // not used
             $this->status = $m[2];
             $status_string = $m[3];
             // not used
             $this->debug(trim($line));
             continue;
         }
         if ($inHeaders) {
             if (trim($line) == '') {
                 $inHeaders = false;
                 $this->debug('Received Headers', $this->headers);
                 if ($this->headers_only) {
                     break;
                     // Skip the rest of the input
                 }
                 continue;
             }
             if (!preg_match('/([^:]+):\\s*(.*)/', $line, $m)) {
                 // Skip to the next header
                 continue;
             }
             $key = strtolower(trim($m[1]));
             $val = trim($m[2]);
             // Deal with the possibility of multiple headers of same name
             if (isset($this->headers[$key])) {
                 if (is_array($this->headers[$key])) {
                     $this->headers[$key][] = $val;
                 } else {
                     $this->headers[$key] = array($this->headers[$key], $val);
                 }
             } else {
                 $this->headers[$key] = $val;
             }
             continue;
         }
         // We're not in the headers, so append the line to the contents
         $this->content .= $line;
     }
     fclose($fp);
     // If data is compressed, uncompress it
     if (isset($this->headers['content-encoding']) && $this->headers['content-encoding'] == 'gzip') {
         $this->debug('Content is gzip encoded, unzipping it');
         $this->content = substr($this->content, 10);
         // See http://www.php.net/manual/en/function.gzencode.php
         $this->content = gzinflate($this->content);
     }
     // If $persist_cookies, deal with any cookies
     if ($this->persist_cookies && isset($this->headers['set-cookie']) && $this->host == $this->cookie_host) {
         $cookies = $this->headers['set-cookie'];
         if (!is_array($cookies)) {
             $cookies = array($cookies);
         }
         foreach ($cookies as $cookie) {
             if (preg_match('/([^=]+)=([^;]+);/', $cookie, $m)) {
                 $this->cookies[$m[1]] = $m[2];
             }
         }
         // Record domain of cookies for security reasons
         $this->cookie_host = $this->host;
     }
     // If $persist_referers, set the referer ready for the next request
     if (isset($this->persist_referers)) {
         $this->debug('Persisting referer: ' . $this->getRequestURL());
         $this->referer = $this->getRequestURL();
     }
     // Finally, if handle_redirects and a redirect is sent, do that
     if (isset($this->handle_redirects)) {
         if (++$this->redirect_count >= $this->max_redirects) {
             $this->errormsg = 'Number of redirects exceeded maximum (' . $this->max_redirects . ')';
             $this->debug($this->errormsg);
             $this->redirect_count = 0;
             return false;
         }
         $location = isset($this->headers['location']) ? $this->headers['location'] : '';
         $uri = isset($this->headers['uri']) ? $this->headers['uri'] : '';
         if ($location || $uri) {
             $url = parse_url($location . $uri);
             // This will FAIL if redirect is to a different site
             return $this->get($url['path']);
         }
     }
     return true;
 }
コード例 #5
0
ファイル: WikiAdminUtils.php プロジェクト: hugcoday/wiki
 function _do_db_rebuild(&$request, $args)
 {
     longer_timeout(240);
     $dbh = $request->getDbh();
     //FIXME: display result.
     return $dbh->_backend->rebuild($args);
 }