function pieRequireSuperuser() { pieRequireUser(); if (!pieIsSuperuser($GLOBALS['pie']['user'])) { header("HTTP/1.0 403 Forbidden"); pieHead("browse"); pieError("RequireSuperuser"); } }
$_REQUEST['stamp'] = intval(@$_REQUEST['stamp']); if (!$file->read($_REQUEST['file'], $_REQUEST['stamp'])) { pieHead(); pieError("FileReadError"); } // Check for alias: if ($file->meta['type'] == "alias") { if ($GLOBALS['pie']['auto_redirect']) { header("Location: " . pieMakeString($GLOBALS['pie']['redirect_file_url'], array('file' => rawurlencode($file->meta['original'])))); exit; } else { pieHead(); pieError("AliasRedirect", array('alias' => $_REQUEST['file'], 'file' => htmlspecialchars($file->meta['original']))); } } // Dump the contents of the file: header("Last-Modified: " . date("D, d M Y H:i:s", $_REQUEST['stamp']) . " GMT"); header("Content-Type: " . $file->meta['type']); header("Accept-Ranges: bytes"); header("Content-Length: " . $file->meta['size']); $name = $_REQUEST['file']; if (@$GLOBALS['pie']['group_delimiter'] && strpos($name, $GLOBALS['pie']['group_delimiter']) > 0) { // Get the basename of the file name. $name = explode($GLOBALS['pie']['group_delimiter'], $name); $name = array_pop($name); } header("Content-Disposition: attachment; filename={$name}"); if (!$file->dump(@$_REQUEST['file'], @$_REQUEST['stamp'])) { pieHead(); pieError("FileReadError"); }
continue; } if (!($dump = file_get_contents("{$path}/{$file}"))) { pieError("NoTemplates"); } $meta = pieExplodePage($dump); $list[$file] = $meta['title']; } closedir($dh); asort($list); // Present available templates. $l = ""; foreach ($list as $file => $info) { $l .= "<option value=\"{$file}\">" . htmlspecialchars($info) . "</option>\n"; } pieError("TemplateList", array('templates' => $l)); } else { // Create a new, empty page. $_REQUEST['source'] = ''; } // Initialize and print editing form. if (empty($_REQUEST['source'])) { if ($GLOBALS['pie']['page_header']) { $_REQUEST['title'] = str_replace('_', ' ', $_REQUEST['page']); } $_REQUEST['comment'] = $GLOBALS['pie']['locale']->key('InitialVersion'); } pieNotice("EditScript"); pieNotice("CharacterPanel"); pieNotice("EditPanel"); pieNotice("PageEdit");
$deadpages[$i]++; } } } if ($page->meta['files']) { // There are file links that are to be checked. $list = explode(" ", $page->meta['files']); foreach ($list as $i) { if (!$file->exists($i)) { $deadfiles[$i]++; } } } } if (!count($deadpages) && !count($deadfiles)) { pieError("NoDeadLinks"); } pieNotice("ListOfDeadLinks"); if (count($deadpages)) { pieNotice("PageTableHead"); arsort($deadpages); $n = 0; foreach ($deadpages as $name => $i) { $n++; print '<tr class="' . ($n % 2 ? "oddRow" : "evenRow") . '">' . '<td>' . pieMakeLink(htmlspecialchars($name), array('action' => "edit", 'page' => $name), array('class' => "itemLink")) . '</td>' . "<td style=\"text-align: right;\">{$i}</td></tr>\n"; } print "</table>\n"; } if (count($deadfiles)) { if (count($deadpages)) { print "<br />\n";
<?php /* * Switch the user environment to the specified mode. */ include_once "{$lib}/share/stdio.php"; if (is_array($_SESSION)) { switch (@$_REQUEST['context']) { case 'browse': case 'edit': $_SESSION['context'] = $_REQUEST['context']; break; } } if (@$_REQUEST['page']) { $_REQUEST['action'] = 'page'; include "{$lib}/action/page.php"; } elseif (@$_REQUEST['file']) { $_REQUEST['action'] = 'fileinfo'; include "{$lib}/action/fileinfo.php"; } elseif ($GLOBALS['pie']['auto_redirect']) { // Redirect to default page. include_once "{$lib}/share/string.php"; header("Location: " . pieMakeString($GLOBALS['pie']['redirect_page_url'], array('page' => rawurlencode($GLOBALS['pie']['default_page'])))); } else { pieHead(); pieError("AliasRedirect", array('page' => htmlspecialchars($GLOBALS['pie']['default_page']))); }
} if ($page->meta['comment']) { if ($n = preg_match_all($pattern, $page->meta['comment'], $m)) { $result[$name] += 2 * $n * $val; } } if ($page->meta['type'] == "alias") { continue; } // Examine the source (of the page). if ($n = preg_match_all($pattern, $page->source, $m)) { $result[$name] += 2 * $n * $val; } } if (!count($result)) { pieError("NoMatches"); } // Present the results: arsort($result); reset($result); list($n, $val) = each($result); pieNotice("TableHead"); $i = 0; foreach ($result as $p => $n) { $i++; print '<tr class="' . ($i % 2 ? "oddRow" : "evenRow") . '">' . "<td>" . pieMakeLink(htmlspecialchars($p), array('page' => $p), array('class' => "itemLink")) . "</td>" . '<td><hr class="gauge" style="width: ' . sprintf("%.2f", $n * 10 / $val) . 'em;" /></td>' . "</tr>\n"; } pieNotice("TableFooter"); } else { } pieTail();
if (!$page->isValidName($_REQUEST['page'])) { pieError("PageNameInvalid"); } if (!$page->exists($_REQUEST['page'])) { pieError("PageNotFound"); } if (intval($_REQUEST['stamp']) > 0) { $stamp = $_REQUEST['stamp']; } else { $stamp = 0; } $page->read($_REQUEST['page'], $stamp); $stamp = $page->meta['stamp']; // Check for alias: if ($page->meta['type'] == "alias") { pieError("AliasRedirect", array('page' => htmlspecialchars($page->meta['original']), 'alias' => htmlspecialchars($_REQUEST['page']))); } // Prepare output: $data = array('page_count' => 0, 'file_count' => 0); $data['date'] = date($GLOBALS['pie']['time_format'], $page->meta['stamp']); $data['author'] = htmlspecialchars($page->meta['author']); $data['comment'] = "—"; if ($page->meta['comment']) { $data['comment'] = htmlspecialchars($page->meta['comment']); } $history = $page->history($page->name); $data['history_count'] = count($history); $t = 0; ksort($history); foreach ($history as $k => $v) { $n++;
function importFile($file) { $name = decodeName($file); if (!$_REQUEST['xpf']) { // Treat the contents of the file as literal data. if (!($source = file_get_contents($file))) { return false; } return importPage($name, $source, array('stamp' => filemtime($file))); } // Treat the file as a page written in XPF: // Build a version history. if (!($f = fopen($file, "r"))) { return false; } $history = array(); $head = array(); while ($line = fgets($f, 16384)) { if ($line == "\n") { if (!$head['stamp'] && !$head['size']) { pieError("FormatError", array('page' => htmlspecialchars($name))); } $head['offset'] = ftell($f); if (fseek($f, $head['size'], SEEK_CUR) == -1) { pieError("FormatError", array('page' => htmlspecialchars($name))); } $history[$head['stamp']] = $head; $head = array(); } elseif (preg_match('/^(\\w+)=(.+)$/', $line, $match)) { $head[$match[1]] = $match[2]; } else { pieError("FormatError", array('page' => htmlspecialchars($name))); } } // Process all versions in order from oldest to latest. ksort($history); foreach ($history as $stamp => $head) { if ($head['type'] == 'alias') { importPage($name, '', $head); continue; } if (fseek($f, $head['offset'], CUR_SET) == -1) { pieError("FormatError", array('page' => htmlspecialchars($name))); } if (!($source = fread($f, $head['size']))) { pieError("FormatError", array('page' => htmlspecialchars($name))); } unset($head['offset']); if (!importPage($name, $source, $head)) { return false; } } fclose($f); return true; }
if ($resource->meta['original'] != $original) { continue; } $aliases[] = $i; } if (!count($aliases)) { if (@$is_alias) { pieTail(); exit; } pieError("NoAliases", array('context' => $context, 'original' => htmlspecialchars($original))); } sort($aliases); $hint_descend = $GLOBALS['pie']['locale']->key("Descend"); $hint_info = $GLOBALS['pie']['locale']->key("Display"); $hint_delete = $GLOBALS['pie']['locale']->key("Delete"); $ip = pieMakeString('[[$^icon_link]]'); $n = 0; pieNotice("TableHeader", array('original' => htmlspecialchars($original))); foreach ($aliases as $i) { $n++; print '<tr class="' . ($n % 2 ? "oddRow" : "evenRow") . '">' . "<td>" . pieMakeLink(htmlspecialchars($i), array('action' => "alias", $context => $i), array('title' => $hint_descend, 'class' => "itemLink")) . "</td>\n" . "<td>" . pieMakeLink("<img src=\"{$ip}/information.png\" alt=\"{$hint_info}\" />", array('action' => "alias", $context => $original, 'alias' => $i), array('title' => $hint_info)) . "</td>\n" . "<td>" . pieMakeLink("<img src=\"{$ip}/delete.png\" alt=\"{$hint_delete}\" />", array('action' => "delete", $context => $i), array('title' => $hint_delete)) . "</td>\n" . "</tr>\n"; } pieNotice("TableFooter", array('original' => htmlspecialchars($original), 'context' => $context)); if (!$is_alias) { pieNotice("CreateAlias", array('original' => htmlspecialchars($original), 'context' => $context)); } } else { pieError("ActionInvalid"); } pieTail();
} // Prepare meta data of the file: $file->name = $name; $file->meta = array('stamp' => time(), 'author' => $GLOBALS['pie']['user']); // .. file size if ($_FILES['upload']['size']) { $file->meta['size'] = $_FILES['upload']['size']; } else { $file->meta['size'] = filesize(pieTempName("_upload")); } // .. file type if (preg_match('/^[a-z]+\\/[a-z]+[\\w\\-\\+\\.]*\\w+$/', $_FILES['upload']['type'])) { $file->meta['type'] = $_FILES['upload']['type']; } elseif (preg_match('/\\.([0-9A-Za-z]{1,5})$/', $name, $match)) { // File type is determined by file name suffix. $map = new MapFile(); if ($type = $map->read("{$lib}/share/suffix.map", strtolower($match[1]))) { $file->meta['type'] = $type; } } elseif (function_exists("mime_content_type")) { $file->meta['type'] = mime_content_type(pieTempName("_upload")); } if (@$_REQUEST['comment']) { $file->meta['comment'] = pieGetOption($_REQUEST['comment']); } if (!$file->write(pieTempName("_upload"))) { pieError("FileWriteError"); } pieLog("edit"); pieNotice("UploadComplete"); pieTail();
<?php /* * Purge ALL cache files from the Cache database. */ include_once "{$lib}/class/cache.php"; include_once "{$lib}/class/locale.php"; include_once "{$lib}/share/auth.php"; include_once "{$lib}/share/log.php"; include_once "{$lib}/share/stdio.php"; include_once "{$lib}/share/string.php"; $cache = new Cache(); pieLoadLocale(); pieRequireSuperuser(); pieHead(); if (@$_REQUEST['approve']) { // Initialize the cache database and purge all existing caches. if ($cache->initialize()) { pieNotice('InitializationSuccess'); } else { pieError('InitializationError'); } } else { // Verify action. pieError('AskInitialization'); } pieLog('edit'); pieTail();
include_once "{$lib}/share/log.php"; include_once "{$lib}/share/stdio.php"; pieRequireUser(); pieHead("edit"); if (@$_REQUEST['old'] && @$_REQUEST['new'] && @$_REQUEST['retype']) { if ($_REQUEST['new'] != $_REQUEST['retype']) { pieError("PasswordMismatch"); } $user = new User(); $pw = $user->read($GLOBALS['pie']['user']); if ($pw != $user->encrypt($_REQUEST['old'])) { // The entered password differs from the registered password. // Try the crypt() command to handle old style passwords. $salt = substr($pw, 0, 2); if ($pw != crypt($_REQUEST['old'], $salt)) { // The entered password is just wrong. pieLog("failure"); pieError("PasswordFailure"); } } // The input is acceptable. Change the password. if (!$user->write($GLOBALS['pie']['user'], $user->encrypt($_REQUEST['new']))) { pieError("PasswordFailure"); } pieLog("user"); pieNotice("PasswordSuccess"); } else { // Print the form. pieNotice("PasswordForm", array('user' => $GLOBALS['pie']['user'])); } pieTail();
<?php /* * Flush the log file. */ include_once "{$lib}/class/session.php"; include_once "{$lib}/class/user.php"; include_once "{$lib}/share/auth.php"; include_once "{$lib}/share/log.php"; include_once "{$lib}/share/stdio.php"; pieRequireSuperuser(); pieHead("edit"); if (@$_REQUEST['approve']) { if (!file_exists($GLOBALS['pie']['run_path'] . "/log/pie.log")) { pieError("FlushError"); } if (!($f = fopen($GLOBALS['pie']['run_path'] . "/log/pie.log", "w"))) { pieError("FlushError"); } if (!ftruncate($f, 0)) { pieError("FlushError"); } fclose($f); pieNotice("FlushComplete"); pieLog("alter"); } else { pieNotice("AskApproval"); } pieTail();
foreach ($history as $stamp => $info) { if ($info['author'] == $GLOBALS['pie']['user']) { continue; } // We are trying to affect an other author's work // ... which is only suitable for admins. if (!pieIsSuperuser($GLOBALS['pie']['user'])) { pieError("AuthorDiffers", array('action' => "{$context}history")); } } // Ask user for acknowledgement to delete the page. pieError("AskApproval"); } // Delete the resource: if (!$object->delete($target)) { pieError("DeleteError"); } if ($context == "page") { // Do what is to be done with pages. if ($object->meta['type'] != "alias") { // Delete the cache, if available. $cache = new Cache(); $cid = $cache->key('page', array('page' => $target)); if ($cache->exists($cid)) { $cache->delete($cid); } if ($cache->exists($cache->key('latest', array()))) { $cache->delete($cache->key('latest', array())); } } $object->unlock($GLOBALS['pie']['user']);
if ($page->meta['pages']) { $pages = explode(" ", $page->meta['pages']); sort($pages); } $files = array(); if ($page->meta['files']) { $files = explode(" ", $page->meta['files']); sort($files); } $hint_info = $GLOBALS['pie']['locale']->key("Info"); $hint_edit = $GLOBALS['pie']['locale']->key("Edit"); $hint_download = $GLOBALS['pie']['locale']->key("Download"); $hint_upload = $GLOBALS['pie']['locale']->key("Upload"); $hint_notavail = $GLOBALS['pie']['locale']->key("NotAvailable"); if (!count($pages) && !count($files)) { pieError("NoLinks"); } $ip = pieMakeString('[[$^icon_link]]'); if (count($pages)) { pieNotice("LinkedPagesHead"); $n = 0; foreach ($pages as $i) { $n++; print '<tr class="' . ($n % 2 ? "oddRow" : "evenRow") . '">'; if ($page->exists($i)) { print "<td><img src=\"{$ip}/link.png\" alt=\"#\" /></td>\n" . "<td>" . pieMakeLink(htmlspecialchars($i), array('page' => $i), array('class' => "itemLink")) . "</td>"; } else { print "<td><img src=\"{$ip}/link_broken.png\" alt=\"=\" title=\"{$hint_notavail}\" /></td>\n" . "<td>" . pieMakeLink(htmlspecialchars($i), array('page' => $i), array('title' => $hint_notavail)) . "</td>"; } print "<td>" . pieMakeLink("<img src=\"{$ip}/information.png\" alt=\"{$hint_info}\" />", array('page' => $i, 'action' => "pageinfo"), array('title' => $hint_info)) . "</td>\n" . "<td>" . pieMakeLink("<img src=\"{$ip}/page_edit.png\" alt=\"{$hint_edit}\" />", array('page' => $i, 'action' => "edit"), array('title' => $hint_edit)) . "</td>\n" . "</tr>\n"; }
<?php /* * Enable system upgrade by the setup script. */ include_once "{$lib}/class/session.php"; include_once "{$lib}/class/user.php"; include_once "{$lib}/share/auth.php"; include_once "{$lib}/share/stdio.php"; pieLoadLocale(); pieRequireSuperuser(); pieHead(); if (@$_REQUEST['enable']) { if (!touch($GLOBALS['pie']['run_path'] . '/user/enable_setup')) { pieError('EnableError'); } pieNotice('EnableSuccess'); } else { pieNotice('AskEnable'); } pieTail();
if ($pw != crypt($_REQUEST['password'], $salt)) { // The entered password is just wrong. pieLog("error"); pieHead("browse"); pieError("FailureForm"); } // Update user record with new style password. $user->write($_REQUEST['username'], $user->encrypt($_REQUEST['password'])); } // The login succeeded. $session = new Session(); if (!$session->start()) { pieHead("browse"); pieError("SessionError"); } $_SESSION['user'] = $_REQUEST['username']; $map = new MapFile(); $lastlogin = $map->read($GLOBALS['pie']['run_path'] . '/user/login.map', $_REQUEST['username']); $map->write($GLOBALS['pie']['run_path'] . '/user/login.map', $_REQUEST['username'], time()); pieLog("user"); pieHead("browse"); if (!$_REQUEST['todo']) { $_REQUEST['todo'] = 'page'; $_REQUEST['page'] = $GLOBALS['pie']['default_page']; } pieError("SuccessForm", array('lastlogin' => date($GLOBALS['pie']['time_format'], $lastlogin))); } else { // Print the login form. pieHead("browse"); pieError("LoginForm"); }
<?php /* * Display the log file. */ include_once "{$lib}/class/session.php"; include_once "{$lib}/class/user.php"; include_once "{$lib}/share/auth.php"; include_once "{$lib}/share/stdio.php"; pieRequireSuperuser(); pieHead("edit"); if (!file_exists($GLOBALS['pie']['run_path'] . "/log/pie.log")) { pieError("NoLogFile"); } if (!($f = fopen($GLOBALS['pie']['run_path'] . "/log/pie.log", "r"))) { pieError("NoLogFile"); } pieNotice("LogHead"); while ($line = fgets($f, 4096)) { print $line; } pieNotice("LogTail"); pieTail();
$_REQUEST['offset'] = 0; } if (!$_REQUEST['sort'] && !@$_REQUEST['order']) { $_REQUEST['sort'] = "name"; $_REQUEST['order'] = "ascend"; } // Retrieve all files... $file = new File(); $data = array(); $max = 0; for ($name = $file->first(); $name; $name = $file->next()) { $max++; $data[$name] = $file->stamp; } if ($max < 1) { pieError("NoFiles"); } // ... and sort them. if ($_REQUEST['sort'] == "name" && $_REQUEST['order'] == "descend") { krsort($data); } elseif ($_REQUEST['sort'] == "name") { ksort($data); } elseif ($_REQUEST['sort'] == "date" && $_REQUEST['order'] == "descend") { arsort($data); } elseif ($_REQUEST['sort'] == "date") { asort($data); } $n = 0; reset($data); while ($n < $_REQUEST['offset']) { // Skip the offset.
$dump .= "{$i}\n"; } if (!fwrite($f, $dump)) { pieError('CacheWriteError'); } fclose($f); } // Display latest page changes: $n = 1; $hint_alias = $GLOBALS['pie']['locale']->key("Alias"); $hint_info = $GLOBALS['pie']['locale']->key("Details"); pieNotice("TableHead"); foreach ($data as $i) { list($stamp, $name) = explode("\t", $i); if (!$page->read($name, 0)) { pieError("SourceReadError"); } $comment = $page->meta['comment']; if (strlen($comment) > 30) { $comment = wordwrap($comment, 30, "\n"); list($comment) = explode("\n", $comment); $comment .= " ..."; } elseif (!$comment) { $comment = '-'; } print '<tr class="' . ($n % 2 ? "oddRow" : "evenRow") . "\">\n<td>"; if ($page->meta['type'] == 'alias') { print pieMakeLink(htmlspecialchars($name) . " <span class=\"warning\">({$hint_alias})</span>", array('action' => 'alias', 'page' => $page->meta['original'], 'alias' => $name), array('class' => "itemLink", 'title' => $hint_info)) . "</td>\n"; } else { print pieMakeLink(htmlspecialchars($name), array('page' => $name), array('class' => "itemLink")) . "</td>\n"; }
// No action but file specified: download this file. $_REQUEST['action'] = 'download'; } elseif (!@$_REQUEST['action'] && !@$_REQUEST['page']) { // No input at all: redirect to the default page. include_once "{$lib}/share/string.php"; if ($GLOBALS['pie']['auto_redirect']) { header('Location: ' . pieMakeString($GLOBALS['pie']['redirect_page_url'], array('page' => rawurlencode($GLOBALS['pie']['default_page'])))); exit; } else { pieHead('browse'); pieError('AliasRedirect', array('page' => htmlspecialchars($GLOBALS['pie']['default_page']))); } } elseif (!preg_match('/^\\w{2,30}$/', @$_REQUEST['action'])) { // Names of actions must consist of word characters only. pieHead('browse'); pieError('ActionInvalid'); } // Update user session. include_once "{$lib}/class/session.php"; $GLOBALS['pie']['session'] = new Session(); $GLOBALS['pie']['session']->start(); //basic security enhancement, do not allow arbitrary script locations if (!preg_match('/[a-zA-Z0-9_-]*/', @$_REQUEST['action'])) { die('Unsecure action requested'); } // Find and run the corresponding script. if (!file_exists("{$lib}/action/" . @$_REQUEST['action'] . '.php')) { pieHead('browse'); pieError('ActionNotImplemented'); } include "{$lib}/action/" . @$_REQUEST['action'] . '.php';
if (!$resource->isValidName($_REQUEST['file'])) { pieError("FileNameInvalid"); } if (!$resource->exists($_REQUEST['file'])) { pieError("FileNotFound"); } if (!$resource->read($_REQUEST['file'], 0)) { pieError("FileReadError"); } if ($resource->meta['type'] == "alias") { pieError("AliasRedirect", array('file' => htmlspecialchars($resource->meta['original']), 'alias' => htmlspecialchars($_REQUEST['file']))); } $context = 'file'; $history = $resource->history($_REQUEST['file']); } else { pieError("PageNotFound"); } // Display the history. if (@$_REQUEST['order'] == "descend") { krsort($history); $n = count($history); } else { ksort($history); $n = 1; } $hint_info = $GLOBALS['pie']['locale']->key("Info"); $hint_show = $GLOBALS['pie']['locale']->key("Show"); $hint_edit = $GLOBALS['pie']['locale']->key("RevertTo"); $ip = pieMakeString('[[$^icon_link]]'); // Present results: pieNotice("TableHead");
<?php /* * Cancel editing a page. */ include_once "{$lib}/class/page.php"; include_once "{$lib}/class/session.php"; include_once "{$lib}/class/locale.php"; include_once "{$lib}/share/auth.php"; include_once "{$lib}/share/stdio.php"; include_once "{$lib}/share/storage.php"; pieRequireUser(); pieHead(); $_REQUEST['page'] = pieGetOption(@$_REQUEST['page']); $preview = pieTempName("_preview"); // Check permission: $page = new Page(); if (!$page->isValidName(@$_REQUEST['page'])) { pieError("PageNameInvalid"); } $page->name = $_REQUEST['page']; if (!$page->lock($GLOBALS['pie']['user'])) { pieError("PageLockError"); } // Clean up what has been set up while editing: if (file_exists($preview)) { unlink($preview); } $page->unlock($GLOBALS['pie']['user']); pieNotice("Cancelation"); pieTail();
$user = new User(); // Check all new users for existence. if (!($f = fopen($_REQUEST['userfile'], "r"))) { pieError("ImportError"); } while ($line = fgets($f, 4096)) { list($name) = explode(":", $line); if ($user->exists($name)) { pieError("UserExists", array('user' => $name)); } } // Now import users for real. if (!rewind($f)) { pieError("ImportError"); } $n = 0; while ($line = fgets($f, 4096)) { list($name, $pass) = explode(":", $line, 2); $pass = trim($pass); if (!$user->write($name, $pass)) { pieError("ImportError"); } $n++; } fclose($f); pieNotice("ImportComplete", array('count' => $n)); } else { // Print the form. pieNotice("UserImportForm"); } pieTail();
include_once "{$lib}/share/stdio.php"; include_once "{$lib}/share/string.php"; include_once "{$lib}/share/log.php"; pieRequireSuperuser(); pieHead("edit"); if (@$_REQUEST['username'] && @$_REQUEST['password']) { // A user has been specified. $user = new User(); if (!$user->isValidName($_REQUEST['username'])) { pieError("InvalidUsername"); } if ($user->exists($_REQUEST['username'])) { pieError("UserExists"); } if ($_REQUEST['password'] != $_REQUEST['retype']) { pieError("PasswordMismatch"); } // Userdata acceptable. Create new user. if (!$user->write($_REQUEST['username'], $user->encrypt($_REQUEST['password']))) { pieError("FailureForm"); } $pref = new UserPref(); $pref->write($_REQUEST['username'], "registered", time()); $GLOBALS['pie']['user'] = $_REQUEST['username']; pieLog("user"); pieNotice("SuccessForm"); } else { // Print the form. pieNotice('RegisterForm'); } pieTail();
$list = array_keys($compiler->files); sort($list); $meta['files'] = implode(" ", $list); } $diff = new Increment(); if (!$diff->writePage($page->name, $meta)) { pieError("SourceWriteError"); } if ($GLOBALS['pie']['page_caching']) { $cache = new Cache(); $cid = $cache->key('page', array('page' => $_REQUEST['page'])); if (!($f = fopen($cache->file($cid), 'w'))) { pieError("CacheWriteError"); } if (!fwrite($f, $compiler->output)) { pieError("CacheWriteError"); } fclose($f); } // Clean up. if (file_exists($preview)) { unlink($preview); } if ($GLOBALS['pie']['edit_timeout']) { pieExpireDirectory($GLOBALS['pie']['run_path'] . "/temp", $GLOBALS['pie']['edit_timeout']); } $page->unlock($GLOBALS['pie']['user']); // Purge list of latest changes. if ($GLOBALS['pie']['query_caching']) { $cache = new Cache(); $cache->delete($cache->key('latest', array()));
} // Handle partial updates. if (@$_REQUEST['section'] > 0 && $page->exists(@$_REQUEST['page'])) { if (!$page->read($_REQUEST['page'], 0)) { pieError('SourceReadError'); } if ($page->meta['type'] != 'full' && $page->meta['type'] != 'shadow') { pieError('SectionNotFound'); } // Determine the text that come before and after the edited section. $section = new Section(); if (($p = $section->offset($page->source, $_REQUEST['section'])) === false) { pieError('SectionNotFound'); } if (($old = $section->extract($page->source, $_REQUEST['section'])) === false) { pieError('SectionNotFound'); } $_REQUEST['source'] = substr($page->source, 0, $p) . rtrim($_REQUEST['source']) . "\n\n" . substr($page->source, $p + strlen($old)); } // Parse and compile the source. $data = array(); $compiler = new htmlCompiler(); $compiler->source = pieCleanString($_REQUEST['source']); if ($GLOBALS['pie']['page_header'] || $GLOBALS['pie']['page_footer']) { // Header and footer require meta data. $compiler->meta = array('title' => pieGetOption($_REQUEST['title']), 'author' => $GLOBALS['pie']['user'], 'stamp' => time()); } if (!$compiler->compile()) { $data['error'] = "<ul>\n"; foreach ($compiler->error as $i) { $data['error'] .= "<li class=\"warning\">{$i}</li>\n";
} pieHead(); if (@$_REQUEST['page']) { // Purge the cache of a single page. $_REQUEST['page'] = pieGetOption($_REQUEST['page']); $_REQUEST['page'] = pieBeautifyName($_REQUEST['page']); if (!$page->isValidName($_REQUEST['page'])) { pieError('PageNameInvalid'); } if (!$page->exists($_REQUEST['page'])) { pieError('PageNotFound'); } $cid = $cache->key('page', array('page' => $_REQUEST['page'])); if (!$cache->exists($cid)) { pieError('PurgeSuccess'); } if ($cache->delete($cid)) { pieNotice('PurgeSuccess'); } else { pieError('PurgeError'); } } else { // Purge the caches of all pages. if ($cache->expire('page', 0)) { pieNotice('ExpirationSuccess'); } else { pieError('ExpirationError'); } } pieLog('edit'); pieTail();
pieRequireUser(); pieHead("edit"); if (@$_REQUEST['user']) { // A user has been specified. $_REQUEST['user'] = pieGetOption($_REQUEST['user']); $user = new User(); if (!$user->isValidName($_REQUEST['user'])) { pieError("BadUser"); } if (!$user->exists($_REQUEST['user'])) { pieError("BadUser"); } } elseif ($_SESSION['user']) { // No user has been specified: // display information about myself. $_REQUEST['user'] = $_SESSION['user']; } if (!@$_REQUEST['user']) { pieError("NoUser"); } $map = new MapFile(); $data = array('user' => htmlspecialchars($_REQUEST['user']), 'realname' => "—", 'lastlogin' => date($GLOBALS['pie']['time_format'], $map->read($GLOBALS['pie']['run_path'] . "/user/login.map", $_REQUEST['user']))); $pref = new UserPref(); if (($val = $pref->read(@$_REQUEST['user'], 'realname')) !== false) { $data['realname'] = $val; } if (($val = $pref->read(@$_REQUEST['user'], 'registered')) !== false) { $data['registered'] = date($GLOBALS['pie']['time_format'], $val); } pieNotice("UserData", $data); pieTail();
<?php /* * Logout, that is, quit a user session. */ include_once "{$lib}/class/session.php"; include_once "{$lib}/share/auth.php"; include_once "{$lib}/share/stdio.php"; include_once "{$lib}/share/log.php"; pieRequireUser(); pieLog("user"); $session = new Session(); if (!$session->destroy()) { pieHead("browse"); pieError("LogoutFailure"); } pieHead("browse"); pieNotice("LogoutSuccess"); pieTail();