Example #1
0
function comment_add()
{
    global $flock, $comment_id;
    global $comment_error;
    if (lwiki_auth_check($comment_error) != 0) {
        return false;
    }
    $name = $_POST['name'];
    $body = $_POST['body'];
    $xsrf = $_POST['sigma'];
    if ($name == '') {
        comment_echoe('名前が空です。');
        return false;
    } else {
        if (mb_substr($name, 0, 1) == '#') {
            comment_echoe('名前が空です。# の前に少なくとも1文字以上入力して下さい。');
            return false;
        } else {
            if (mb_strlen($name) > 100) {
                comment_echoe('名前が長すぎです。100文字以下にして下さい。');
                return false;
            } else {
                if ($body == '') {
                    comment_echoe('コメント内容が空です。');
                    return false;
                } else {
                    if (mb_strlen($body) > 5000) {
                        comment_echoe('コメント内容が長すぎです。分割して投稿して下さい。');
                        return false;
                    } else {
                        if ($xsrf !== _calculate_xsrfhash()) {
                            comment_echoe('フォーム署名が不正です。意図した投稿か確認し再度投稿を試みて下さい。');
                            return false;
                        }
                    }
                }
            }
        }
    }
    global $fdat, $fhtm;
    if (!$flock->lock($fdat)) {
        comment_echoe("(comment_add): sorry, failed to lock the file `{$fdat}'.");
        return false;
    }
    $name = htmlspecialchars($name);
    $ipaddr = $_SERVER["REMOTE_ADDR"];
    $date = @lwiki_datetime();
    $count = $flock->file_increment("./.lwiki/data/{$comment_id}.count");
    $chklast = $ipaddr . '/' . urlencode($name) . '/' . urlencode($body);
    $flast = "./.lwiki/data/{$comment_id}.last";
    if ($chklast == @file_get_contents($flast)) {
        comment_echoe('二重投稿です');
        $flock->unlock($fdat);
        return false;
    }
    $dat = $ipaddr . '/' . $date . '/' . urlencode($name) . '/' . urlencode($body) . '/' . $count . "\n";
    if (false === @file_put_contents($fdat, $dat, FILE_APPEND)) {
        comment_echoe("(comment_add): sorry, failed to append an entry to the file `{$fdat}'.");
        $flock->unlock($fdat);
        return false;
    }
    // write
    if (!$flock->file_atomic_append($fhtm, comment_generate_html($ipaddr, $date, $name, $body, $count))) {
        comment_echoe('(comment_add): sorry, failed to append your comment to the comment.htm file.');
        $flock->unlock($fdat);
        return false;
    }
    file_put_contents($flast, $chklast);
    $flock->unlock($fdat);
    return true;
}
Example #2
0
        closedir($dir);
    }
    //sort($ret);
    usort($ret, 'strcasecmp');
    return $ret;
}
$pages = mwg_file_list('./.lwiki/data', '/page..*\\.htm$/');
echo '<table class="lwiki-single lwiki-center">' . PHP_EOL;
echo '<tr><th>ページ名</th><th>編集者</th><th>最終更新日時</th></tr>';
foreach ($pages as $page) {
    if (!preg_match('/page.(.*)\\.htm$/', $page, $m)) {
        continue;
    }
    $page_id = $m[1];
    $page_name = urldecode($m[1]);
    $page_date = @lwiki_datetime(@filemtime('./.lwiki/data/' . $page));
    $url_read = htmlspecialchars(lwiki_link_page($page_id));
    $url_diff = htmlspecialchars(lwiki_link_page($page_id, 'hist=last'));
    $htmlPageName = htmlspecialchars($page_name);
    $htmlPageDate = htmlspecialchars($page_date) . ' [<a href="' . $url_diff . '">差分</a>]';
    echo '<tr><td><a href="' . $url_read . '">' . $htmlPageName . '</a></td><td></td><td>' . $htmlPageDate . '</td></tr>' . PHP_EOL;
}
echo '</table>' . PHP_EOL;
$editlogs = @file('./.lwiki/data/log.edit.txt');
if ($editlogs != null && count($editlogs)) {
    echo '<h2>最近のページ編集</h2>';
    echo '<ul>';
    $htmlContent = '';
    foreach ($editlogs as $editlog) {
        $fields = explode('/', $editlog);
        $edit_auth = lwiki_hash(urldecode($fields[0]));
Example #3
0
 public function execute()
 {
     global $flock, $pageid;
     $ipaddr = $_SERVER["REMOTE_ADDR"];
     $date = @lwiki_datetime();
     global $edit_session;
     $content = $edit_session->content();
     $edithash = $edit_session->edithash();
     $xsrfhash = $edit_session->xsrfhash();
     if (lwiki_auth_check($msg) != 0) {
         error($msg);
         return false;
     }
     $fname_wiki = ".lwiki/data/page.{$pageid}.wiki";
     // ロック
     if (!$flock->lock($fname_wiki)) {
         error("sorry, failed to lock the file, 'page.{$pageid}.wiki'.");
         return false;
     }
     $original_wiki_source = lwiki_canonicalize_linebreaks(@file_get_contents($fname_wiki));
     $param_part = $_GET['part'];
     if ($param_part && find_section_range($param_part, $original_wiki_source, $i0, $iN)) {
         // 部分編集
         $original_wiki_head = substr($original_wiki_source, 0, $i0);
         $original_wiki_body = substr($original_wiki_source, $i0, $iN - $i0);
         $original_wiki_tail = substr($original_wiki_source, $iN);
     } else {
         // 全体編集
         $original_wiki_head = '';
         $original_wiki_body = $original_wiki_source;
         $original_wiki_tail = '';
     }
     // check 編集の衝突
     if ($edithash != _calculate_edithash($original_wiki_body)) {
         error('編集の衝突が発生しました (別のユーザによる更新が編集中に行われました)。差分を参照して下さい。{' . $i0 . ',' . $iN . '}');
         $flock->unlock($fname_wiki);
         return false;
     }
     // XSRF 識別
     if ($xsrfhash != _calculate_xsrfhash($edithash)) {
         error('内部署名が一致しません。この投稿が意図したものか確認し、再度投稿を行って下さい。');
         $flock->unlock($fname_wiki);
         return false;
     }
     // check 変更無し
     if ($content == $original_wiki_body) {
         error('変更点がありません。');
         $flock->unlock($fname_wiki);
         return false;
     }
     //if(mb_substr($content,-1)!=="\n")$content.="\n";
     $content = $original_wiki_head . $content . $original_wiki_tail;
     // 保存実行
     if (!@file_put_contents($fname_wiki, $content)) {
         error('編集データ保存に失敗しました。');
         $flock->unlock($fname_wiki);
         return false;
     }
     $flock->unlock($fname_wiki);
     if (!$this->_page_hist_append($ipaddr, $date, $content, $_POST['remarks'])) {
         return false;
     }
     $conv = \lwiki\convert\create_converter();
     $conv->setCustomGenerateEditLink('default');
     $content = $conv->convert($content);
     if (!$flock->file_atomic_save_locked(".lwiki/data/page.{$pageid}.htm", $content)) {
         error('(page_update): sorry, failed to save html to page.htm.');
         return false;
     }
     $info = $ipaddr . '/' . $date . PHP_EOL;
     $info .= urlencode($conv->header_close()) . PHP_EOL;
     // 頁内目次
     $info .= urlencode($conv->tags) . PHP_EOL;
     // タグ
     $info .= urlencode($conv->keywords) . PHP_EOL;
     // 索引
     if (!$flock->file_atomic_save_locked(".lwiki/data/page.{$pageid}.info", $info)) {
         error('(page_update): sorry, failed to update the page information in page.info.');
     }
     return true;
 }
Example #4
0
function page_modified_date()
{
    global $pageid, $pageinfo;
    if ($pageinfo !== false) {
        $f = explode('/', $pageinfo[0]);
        $ipaddr = $f[0];
        $date = $f[1];
    } else {
        $ipaddr = '';
        $date = @lwiki_datetime(@filemtime('.lwiki/data/page.' . $pageid . '.htm'));
    }
    $line = $date;
    if ($ipaddr != null && $ipaddr != '') {
        $line .= ' by ' . lwiki_hash($ipaddr);
    }
    return $line;
}