修改readme;默认子目录博客

This commit is contained in:
ruanxingzhi 2017-03-30 08:03:31 +08:00 committed by Too-Naive
parent 5128be38f6
commit 6529539bc0
9 changed files with 63 additions and 117 deletions

View File

@ -1,83 +1,14 @@
# Universal Online Judge
# Universal OJ
## Dependence
This is a dockerized version of UOJ. Before installation, please make sure that [Docker](https://www.docker.com/) has already been installed on your OS.
这是一份民间的UOJ版本我们希望它比官方版本更易用。
The docker image of UOJ is **64-bit**, so a **32-bit** host OS may cause installation failure.
部署文档在[universaloj.github.io](https://universaloj.github.io)。
## Installation
First please download [JDK7u76](http://www.oracle.com/technetwork/java/javase/downloads/java-archive-downloads-javase7-521261.html#jdk-7u76-oth-JPR) and [JDK8u31](http://www.oracle.com/technetwork/java/javase/downloads/java-archive-javase8-2177648.html#jdk-8u31-oth-JPR), and put them to `docker/jdk-7u76-linux-x64.tar.gz` and `docker/jdk-8u31-linux-x64.tar.gz`. These two compressed files are used by judge\_client for judging Java program. If you are too lazy to download these two huge files, you can simply place two empty .tar.gz files there.
Next, you can run the following command in your terminal: (not the one in the `docker/` directory!)
```sh
./install
```
If everything goes well, you will see `Successfully built <image-id>` in the last line of the output.
目前已经支持的特性:
To start your UOJ main server, please run:
```sh
docker run -it -p 80:80 -p 3690:3690 <image-id>
```
If you are using docker on Mac OS or having 'std: compile error. no comment' message on uploading problem data, you could possibly use this alternative command:
```sh
docker run -it -p 80:80 -p 3690:3690 --cap-add SYS_PTRACE <image-id>
```
- 子目录博客(感谢[roastduck](https://github.com/roastduck/)的贡献)
- zip传题 (感谢[AD1024](https://github.com/AD1024/)的贡献)
The default hostname of UOJ is `local_uoj.ac`, so you need to modify your host file in your OS in order to map `127.0.0.1` to `local_uoj.ac`. (It is `/etc/hosts` on Linux.) After that, you can access UOJ in your web browser.
The first user registered after the installation of UOJ will be a super user. If you need another super user, please register a user and change its `usergroup` to "<samp>S</samp>" in the table `user_info`. Run
```sh
mysql app_uoj233 -u root -p
```
to login mysql in the terminal.
Notice that if you want only one judge client, then everything is ok now. Cheers!
However, if you want more judge clients, you need to set up them one by one. First run:
```sh
./config_judge_client
```
and answer the questions.
* uoj container id: the container id of the main server.
* uoj ip: the ip address of the main server.
* judger name: you can take a name you like, such as judger, judger\_2, very\_strong\_judger. (containing special characters may cause unforeseeable consequence.)
After that, a sql command is given, we will talk about it later.
Next, we need to run:
```sh
./install_judge_client
```
to build the docker image. If you want to run judger at the same server, you just need to run
```sh
docker run -it <image-id>
```
And, you need to complete the sql command given just now with the ip address of the judger docker, and modify the database. To someone who do not know how to get the ip address of a docker container, here is the answer:
```sh
docker inspect --format '{{ .NetworkSettings.IPAddress }}' <container-id>
```
Or, if you want to run judger at different server, you need to copy the image to the other server, and run
```sh
docker run -p 2333 -it <image-id>
```
Similarly, you need to complete the sql command and modify the database. This time, you need to fill with the ip address of the host machine of the judger docker.
You may meet many difficulties during the installation. Good luck and have fun!
## Notes
mysql default password: root
local\_main\_judger password: judger
You can change the default hostname and something else in `/var/www/uoj/app/.config.php`. However, not all the config is here, haha.
## More Documentation
As you know, my Yingyu is not very hao. Suoyi only the README file is En(Chi)nglish for internationalization.
More documentation is here: [https://vfleaking.github.io/uoj/](https://vfleaking.github.io/uoj/)
## License
MIT License.
希望对您有帮助。

View File

@ -84,7 +84,8 @@ return [
],
'switch' => [ // 一些开关
'ICP-license' => false, // ICP 备案信息的显示
'web-analytics' => false // 网站流量统计(记 uoj.ac 名下……想统计自己的得改代码)
'web-analytics' => false, // 网站流量统计(记 uoj.ac 名下……想统计自己的得改代码)
'blog-use-subdomain' => true // 每个人的博客使用独立的子域名
]
];
```
@ -96,9 +97,9 @@ return [
或者你想成为一条咸鱼,可以直接在 config 里的 host 那里写 ip。
谜之声:为什么博客用不了?
Q:为什么博客用不了?
嗯。。。博客的话需要给每个用户的博客域名进行解析……最好是用泛解析解决。如果没这条件,我帮你点根蜡烛 23333……期待有为青年码一个“博客以子域名还是子目录形式出现”的开关
A博客的话需要给每个用户的博客域名进行解析最好是用泛解析解决这是出于安全考虑。如果没这条件可以将配置文件里`switch`中的`blog-use-subdomain`改成false这样博客url将以子目录的形式出现
### 邮箱
noreply 邮箱的目的是发一些莫名其妙的邮件,比如 svn 密码和 “找回密码”。

View File

@ -10,12 +10,12 @@ return [
'domain' => null,
'main' => [
'protocol' => 'http',
'host' => 'local_uoj.ac',
'host' => isset($_SERVER['HTTP_X_FORWARDED_HOST']) ? $_SERVER['HTTP_X_FORWARDED_HOST'] : (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : ''),
'port' => 80
],
'blog' => [
'protocol' => 'http',
'host' => 'blog.local_uoj.ac',
'host' => isset($_SERVER['HTTP_X_FORWARDED_HOST']) ? $_SERVER['HTTP_X_FORWARDED_HOST'] : (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : ''),
'port' => 80
]
],
@ -50,6 +50,7 @@ return [
],
'switch' => [
'ICP-license' => false,
'web-analytics' => false
'web-analytics' => false,
'blog-use-subdomain' => false
]
];

View File

@ -34,8 +34,8 @@
<div class="col-md-3">
<?php if (UOJContext::hasBlogPermission()): ?>
<div class="btn-group btn-group-justified">
<a href="/blog/new/write" class="btn btn-primary"><span class="glyphicon glyphicon-edit"></span> 写新博客</a>
<a href="/slide/new/write" class="btn btn-primary"><span class="glyphicon glyphicon-edit"></span> 写新幻灯片</a>
<a href="<?=HTML::blog_url(UOJContext::userid(), '/blog/new/write')?>" class="btn btn-primary"><span class="glyphicon glyphicon-edit"></span> 写新博客</a>
<a href="<?=HTML::blog_url(UOJContext::userid(), '/slide/new/write')?>" class="btn btn-primary"><span class="glyphicon glyphicon-edit"></span> 写新幻灯片</a>
</div>
<?php endif ?>
<div class="panel panel-info top-buffer-sm">

View File

@ -1,21 +1,33 @@
<?php
call_user_func(function() { // to prevent variable scope leak
Route::pattern('blog_username', '[a-zA-Z0-9_\-]{1,20}');
if (UOJConfig::$data['switch']['blog-use-subdomain']) {
$domain = '{blog_username}.'.UOJConfig::$data['web']['blog']['host'];
$prefix = '';
} else {
$domain = UOJConfig::$data['web']['blog']['host'];
$prefix = '/blogof/{blog_username}';
}
Route::group([
'domain' => '{blog_username}.'.UOJConfig::$data['web']['blog']['host'],
'domain' => $domain,
'onload' => function() {
UOJContext::setupBlog();
}
], function() {
Route::any('/', '/subdomain/blog/index.php');
Route::any('/archive', '/subdomain/blog/archive.php');
Route::any('/aboutme', '/subdomain/blog/aboutme.php');
Route::any('/click-zan', '/click_zan.php');
Route::any('/blog/{id}', '/subdomain/blog/blog.php');
Route::any('/slide/{id}', '/subdomain/blog/slide.php');
Route::any('/blog/(?:{id}|new)/write', '/subdomain/blog/blog_write.php');
Route::any('/slide/(?:{id}|new)/write', '/subdomain/blog/slide_write.php');
Route::any('/blog/{id}/delete', '/subdomain/blog/blog_delete.php');
], function() use ($prefix) {
Route::any("$prefix/", '/subdomain/blog/index.php');
Route::any("$prefix/archive", '/subdomain/blog/archive.php');
Route::any("$prefix/aboutme", '/subdomain/blog/aboutme.php');
Route::any("$prefix/click-zan", '/click_zan.php');
Route::any("$prefix/blog/{id}", '/subdomain/blog/blog.php');
Route::any("$prefix/slide/{id}", '/subdomain/blog/slide.php');
Route::any("$prefix/blog/(?:{id}|new)/write", '/subdomain/blog/blog_write.php');
Route::any("$prefix/slide/(?:{id}|new)/write", '/subdomain/blog/slide_write.php');
Route::any("$prefix/blog/{id}/delete", '/subdomain/blog/blog_delete.php');
}
);
});

View File

@ -43,10 +43,11 @@ class HTML {
}
public static function blog_url($username, $uri) {
$url = UOJConfig::$data['web']['blog']['protocol'].'://'.blog_name_encode($username).'.'.UOJConfig::$data['web']['blog']['host'];
if (UOJConfig::$data['web']['blog']['port'] != 80) {
$url .= ':'.UOJConfig::$data['web']['blog']['port'];
}
$port = UOJConfig::$data['web']['blog']['port'] == 80 ? '' : (':'.UOJConfig::$data['web']['blog']['port']);
if (UOJConfig::$data['switch']['blog-use-subdomain'])
$url = UOJConfig::$data['web']['blog']['protocol'].'://'.blog_name_encode($username).'.'.UOJConfig::$data['web']['blog']['host'].$port;
else
$url = UOJConfig::$data['web']['blog']['protocol'].'://'.UOJConfig::$data['web']['blog']['host'].$port.'/blogof/'.blog_name_encode($username);
$url .= $uri;
$url = rtrim($url, '/');
return HTML::escape($url);

View File

@ -56,7 +56,7 @@ class Route {
$cur = array();
$cur['methods'] = $methods;
$cur['uri'] = $uri;
$cur['uri'] = rtrim($uri, '/');
$cur['action'] = $action;
$cur = array_merge(self::getGroup(), $cur);
self::$routes[] = $cur;
@ -84,7 +84,7 @@ class Route {
}
$uri_pat = strtr($route['uri'], $rep_arr);
if (!preg_match('/^'.$uri_pat.'$/', UOJContext::requestPath(), $uri_matches)) {
if (!preg_match('/^'.$uri_pat.'$/', rtrim(UOJContext::requestPath(), '/'), $uri_matches)) {
return false;
}
$matches = array_merge($matches, $uri_matches);

View File

@ -7,12 +7,12 @@
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/"><?= UOJContext::userid() ?></a>
<a class="navbar-brand" href="<?= HTML::blog_url(UOJContext::userid(), '/')?>"><?= UOJContext::userid() ?></a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li><a href="/archive">日志</a></li>
<li><a href="/aboutme">关于我</a></li>
<li><a href="<?= HTML::blog_url(UOJContext::userid(), '/archive')?>">日志</a></li>
<li><a href="<?= HTML::blog_url(UOJContext::userid(), '/aboutme')?>">关于我</a></li>
<li><a href="<?= HTML::url('/') ?>">UOJ</a></li>
</ul>
</div><!--/.nav-collapse -->

View File

@ -2,7 +2,7 @@
if ($is_preview) {
$readmore_pos = strpos($blog['content'], '<!-- readmore -->');
if ($readmore_pos !== false) {
$content = substr($blog['content'], 0, $readmore_pos).'<p><a href="/blog/'.$blog['id'].'">阅读更多……</a></p>';
$content = substr($blog['content'], 0, $readmore_pos).'<p><a href="'.HTML::blog_url(UOJContext::userid(), '/blog/').$blog['id'].'">阅读更多……</a></p>';
} else {
$content = $blog['content'];
}
@ -14,7 +14,7 @@
$blog_type = $blog['type'] == 'B' ? 'blog' : 'slide';
?>
<h2><?= $extra_text ?><a class="header-a" href="/blog/<?= $blog['id'] ?>"><?= $blog['title'] ?></a></h2>
<h2><?= $extra_text ?><a class="header-a" href="<?= HTML::blog_url(UOJContext::userid(), '/blog/'.$blog['id']) ?>"><?= $blog['title'] ?></a></h2>
<div><?= $blog['post_time'] ?> <strong>By</strong> <?= getUserLink($blog['poster']) ?></div>
<?php if (!$show_title_only): ?>
<div class="panel panel-default">
@ -24,10 +24,10 @@
<?php elseif ($blog_type == 'slide'): ?>
<article>
<div class="embed-responsive embed-responsive-16by9">
<iframe class="embed-responsive-item" src="/slide/<?= $blog['id'] ?>"></iframe>
<iframe class="embed-responsive-item" src="<?= HTML::blog_url(UOJContext::userid(), '/slide/'.$blog['id']) ?>"></iframe>
</div>
<div class="text-right top-buffer-sm">
<a class="btn btn-default btn-md" href="/slide/<?= $blog['id'] ?>"><span class="glyphicon glyphicon-fullscreen"></span> 全屏</a>
<a class="btn btn-default btn-md" href="<?= HTML::blog_url(UOJContext::userid(), '/slide/'.$blog['id']) ?>"><span class="glyphicon glyphicon-fullscreen"></span> 全屏</a>
</div>
</article>
<?php endif ?>
@ -40,11 +40,11 @@
<?php endforeach ?>
</li>
<?php if ($is_preview): ?>
<li><a href="/blog/<?= $blog['id'] ?>">阅读全文</a></li>
<li><a href="<?= HTML::blog_url(UOJContext::userid(), '/blog/'.$blog['id']) ?>">阅读全文</a></li>
<?php endif ?>
<?php if (Auth::check() && (isSuperUser(Auth::user()) || Auth::id() == $blog['poster'])): ?>
<li><a href="/<?=$blog_type?>/<?=$blog['id']?>/write">修改</a></li>
<li><a href="/blog/<?=$blog['id']?>/delete">删除</a></li>
<li><a href="<?=HTML::blog_url(UOJContext::userid(), '/'.$blog_type.'/'.$blog['id'].'/write')?>">修改</a></li>
<li><a href="<?=HTML::blog_url(UOJContext::userid(), '/blog/'.$blog['id'].'/delete')?>">删除</a></li>
<?php endif ?>
<li><?= getClickZanBlock('B', $blog['id'], $blog['zan']) ?></li>
</ul>