Skip to content

Commit 6d6cdec

Browse files
committed
Merge branch 'master' of github.com:AntSwordProject/ant
2 parents 2e4951e + e46ed8a commit 6d6cdec

File tree

13 files changed

+464
-15
lines changed

13 files changed

+464
-15
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.DS_*
2+
ant_db_data/
3+
web/node_modules/
4+
.vscode/

README.md

+25-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,24 @@
11
# 蚁逅@1.0
22
> 代码仅供学习参考与合法的研究测试。
33
4-
## 安装与布署
4+
## 使用 Docker
5+
6+
```
7+
$ wget https://raw.githubusercontent.com/AntSwordProject/ant/master/docker-compose.yml
8+
$ docker-compose -f docker-compose.yml up -d
9+
```
10+
11+
如果需要配置邮件, 只需要修改 `docker-compose.yml` 中部分环境变量
12+
13+
```
14+
- ANT_MAIL_HOST=smtp.qq.com
15+
- ANT_MAIL_PORT=465
16+
- ANT_MAIL_SECURE=true
17+
18+
- ANT_MAIL_PASSWORD=email-password
19+
```
20+
21+
## 手动安装与布署
522

623
### 0. 依赖环境
724

@@ -77,14 +94,15 @@ http://127.0.0.1:3000
7794

7895
这个功能采用了`nodemailer`模块,目前个人使用的是QQ邮箱的SMTP功能,用户可自行更改
7996

80-
编辑 `modules/mail.js``config` 变量即可
97+
设置以下环境变量, 然后启动即可
8198

8299
```
83-
var config = {
84-
name: 'ANT',
85-
86-
password: 'email-password'
87-
}
100+
export ANT_MAIL_NAME='ANT' \
101+
ANT_MAIL_HOST='smtp.qq.com' \
102+
ANT_MAIL_PORT=465 \
103+
ANT_MAIL_SECURE=true \
104+
ANT_MAIL_EMAIL='[email protected]' \
105+
ANT_MAIL_PASSWORD='email-password'
88106
```
89107

90108
### 2. 扩展功能

docker-compose.yml

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
version: "2"
2+
3+
services:
4+
ant_db:
5+
image: mongo:3.6.3
6+
container_name: ant_db
7+
environment:
8+
- MONGO_DATA_DIR=/data/db
9+
volumes:
10+
- ./ant_db_data:/data/db
11+
ports:
12+
- 127.0.0.1:27017:27017
13+
network_mode: "bridge"
14+
command: mongod
15+
ant:
16+
image: medicean/ant:latest
17+
container_name: ant_web
18+
# 如果想自己编译就把这个打开
19+
# build:
20+
# context: ./web/
21+
# dockerfile: Dockerfile
22+
environment:
23+
- ANT_MONGO_URI=mongodb://ant_db:27017/ant
24+
- ANT_MAIL_NAME=ANT
25+
- ANT_MAIL_HOST=smtp.qq.com
26+
- ANT_MAIL_PORT=465
27+
- ANT_MAIL_SECURE=true
28+
29+
- ANT_MAIL_PASSWORD=email-password
30+
network_mode: "bridge"
31+
depends_on:
32+
- ant_db
33+
links:
34+
- ant_db
35+
ports:
36+
- 3000:3000
37+

web/Dockerfile

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
FROM node:4.3
2+
3+
ENV LC_ALL C.UTF-8
4+
ENV TZ=Asia/Shanghai
5+
6+
RUN set -ex; \
7+
ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone; \
8+
mkdir -p /htdocs
9+
10+
COPY . /htdocs/
11+
WORKDIR /htdocs/
12+
13+
RUN set -ex; \
14+
npm --registry=https://registry.npm.taobao.org install
15+
16+
ENV PORT=3000 \
17+
ANT_MONGO_URI=mongodb://127.0.0.1/ant \
18+
ANT_MAIL_NAME='ANT' \
19+
ANT_MAIL_HOST='smtp.qq.com' \
20+
ANT_MAIL_PORT=465 \
21+
ANT_MAIL_SECURE=true \
22+
ANT_MAIL_EMAIL='[email protected]' \
23+
ANT_MAIL_PASSWORD='email-password'
24+
25+
EXPOSE 3000
26+
ENTRYPOINT ["/bin/bash", "/htdocs/start.sh"]
27+
CMD ["tail", "-f", "/dev/null"]

web/addons/ant.install/client.js

+237
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,237 @@
1+
;(function($) {
2+
var input_style = 'style="width: 90%;"';
3+
4+
var html_header = '<div id="setting_about" style="font-size: 16px;">' +
5+
' <div>' +
6+
' <h3 style="padding: 9px 0;" class="text-success">安装确认</h3>' +
7+
' <p style="line-height:24px;">下面是你安装配置信息, 请确认无误后, 点击上方「确定并提交」按钮</p><hr>';
8+
var html_install_info = {};
9+
var html_footer = ' </div>' +
10+
'</div>';
11+
12+
var noxss = function (str) {
13+
return str.replace(/&/g, "&amp;")
14+
.replace(/>/g, "&gt;")
15+
.replace(/</g, "&lt;")
16+
.replace(/"/g, "&quot;");
17+
};
18+
19+
var install_keys = ['create_admin'];
20+
21+
var ADDON = {
22+
ui: {
23+
welcome: {
24+
parent_step: '',
25+
next_step: 'create_admin',
26+
name: 'welcome',
27+
header: 'Ant 安装向导',
28+
formHTML: '<div id="setting_about" style="font-size: 16px;">' +
29+
' <div>' +
30+
' <p style="line-height:24px;">欢迎使用 Ant, 接下来我们将引导您进行初步设置</p>' +
31+
' <p style="line-height:24px;">您在使用本平台之前, 请务必仔细阅读以下条款。</p>' +
32+
' <p style="line-height:24px;">您在使用本平台时, 默认您已知晓并同意以下条款。</p>' +
33+
' <h3 style="padding: 5px 0;" class="text-danger">免责声明</h3>' +
34+
' <p style="line-height:24px;">本站仅提供一个学习与交流的平台,请勿用于其他非法用途,请自行承担由此带来的风险。</p>' +
35+
' <p style="line-height:24px;">本软件按「原样」提供,不提供任何形式的保证,或者暗示,包括但不限于适销性保证,适用于特定用途和不侵权的适用性。</p>' +
36+
' <p style="line-height:24px;">在任何情况下都不应该作者或版权所有者对任何索赔,损害或其他责任均有责任无论是合同,侵权行为还是其他行为,由此产生的责任,超出或与本软件或其中的使用或其他交易有关的软件。</p>' +
37+
' <h3 style="padding: 5px 0;" class="text-info">联系我们</h3>' +
38+
' <p style="line-height:24px;">在线交流: <a target="_blank" href="https://discord.gg/Uzh5nUf">https://discord.gg/Uzh5nUf</a><br>GitHub: <a href="http://github.com/antswordproject/ant" target="_blank">http://github.com/antswordproject/ant</a></p>' +
39+
' </div>' +
40+
'</div>',
41+
toolbar: {
42+
items: [{
43+
type: 'button',
44+
caption: '我同意',
45+
icon: 'fa fa-step-forward',
46+
onClick: function () {
47+
var self = w2ui['welcome'];
48+
w2ui.sidebar.disable('install_' + self.name)
49+
w2ui.sidebar.enable('install_' + self.next_step)
50+
w2ui.sidebar.click('install_' + self.next_step)
51+
}
52+
}, {
53+
type: 'break'
54+
}]
55+
}
56+
},
57+
create_admin: {
58+
parent_step: 'welcome',
59+
next_step: 'submit_form',
60+
name: 'create_admin',
61+
header: '创建管理员',
62+
fields: [{
63+
type: 'email',
64+
field: 'email',
65+
required: true,
66+
html: {
67+
caption: '邮箱',
68+
attr: input_style
69+
}
70+
}, {
71+
type: 'text',
72+
field: 'nickname',
73+
required: true,
74+
html: {
75+
caption: '昵称',
76+
attr: input_style
77+
}
78+
}, {
79+
type: 'password',
80+
field: 'password',
81+
required: true,
82+
html: {
83+
caption: '密码',
84+
attr: input_style
85+
}
86+
}, {
87+
type: 'password',
88+
field: 'password1',
89+
required: true,
90+
html: {
91+
caption: '重复密码',
92+
attr: input_style
93+
}
94+
}],
95+
record: JSON.parse(localStorage.getItem('create_admin')) || {},
96+
toolbar: {
97+
items: [{
98+
type: 'button',
99+
caption: '上一步',
100+
icon: 'fa fa-step-backward',
101+
onClick: function () {
102+
var self = w2ui['create_admin'];
103+
w2ui.sidebar.disable('install_' + self.name)
104+
w2ui.sidebar.enable('install_' + self.parent_step)
105+
w2ui.sidebar.click('install_' + self.parent_step)
106+
}
107+
}, {
108+
type: 'button',
109+
caption: '下一步',
110+
icon: 'fa fa-step-forward',
111+
onClick: function () {
112+
var self = w2ui['create_admin'];
113+
if (self.validate().length === 0) {
114+
if (self.record.password.length < 6) {
115+
$('#password').val('').focus();
116+
return ADDON.warning('密码长度不得少于6位!');
117+
}
118+
if (self.record.password !== self.record.password1) {
119+
$("#password1").val('').focus();
120+
return ADDON.warning('两次输入的密码不一致!');
121+
}
122+
var _t_html = '';
123+
_t_html += '<h4 style="padding: 5px 0;" class="text-info" style="color:#e24444">管理员</h4>';
124+
_t_html += '<p style="margin-left: 20px;line-height:24px;">邮箱: ' + noxss(self.record.email) + '</p>';
125+
_t_html += '<p style="margin-left: 20px;line-height:24px;">昵称: ' + noxss(self.record.nickname) + '</p>';
126+
html_install_info['create_admin'] = _t_html;
127+
w2ui.submit_form.formHTML= '<div class="w2ui-page page-0">' + html_header + (Object.values(html_install_info).join("")) + html_footer + '</div>';
128+
w2ui.submit_form.reload();
129+
localStorage.setItem('create_admin', JSON.stringify(self.record));
130+
w2ui.sidebar.disable('install_' + self.name)
131+
w2ui.sidebar.enable('install_' + self.next_step)
132+
w2ui.sidebar.click('install_' + self.next_step)
133+
};
134+
}
135+
}, {
136+
type: 'break'
137+
}]
138+
}
139+
},
140+
submit_form: {
141+
parent_step: 'create_admin',
142+
next_step: '',
143+
name: 'submit_form',
144+
header: '确认信息',
145+
formHTML: (
146+
html_header + (Object.values(html_install_info).join("")) + html_footer
147+
),
148+
toolbar: {
149+
items: [{
150+
type: 'button',
151+
caption: '上一步',
152+
icon: 'fa fa-step-backward',
153+
onClick: function () {
154+
var self = w2ui['submit_form'];
155+
w2ui.sidebar.disable('install_' + self.name)
156+
w2ui.sidebar.enable('install_' + self.parent_step)
157+
w2ui.sidebar.click('install_' + self.parent_step)
158+
}
159+
}, {
160+
type: 'button',
161+
caption: '确定并提交',
162+
icon: 'fa fa-save',
163+
onClick: function () {
164+
var self = w2ui['submit_form'];
165+
var post_data = {};
166+
install_keys.map(function (key) {
167+
var temp = JSON.parse(localStorage.getItem(key)) || {};
168+
post_data[key] = temp;
169+
});
170+
ADDON.lock('安装中..')
171+
$.post('/addons/ant.install/install', post_data, function (data) {
172+
ADDON.unlock();
173+
if (data.ret) {
174+
ADDON.success('安装成功!');
175+
localStorage.setItem('login_user', post_data['create_admin']['email']);
176+
install_keys.map(function (key) { // 移除本地存储
177+
localStorage.removeItem(key);
178+
});
179+
// 重新加载页面
180+
setTimeout(function (){
181+
window.location.href = window.location.origin;
182+
}, 2000);
183+
}else{
184+
ADDON.error('安装失败!<br>' + data.err);
185+
}
186+
})
187+
}
188+
}]
189+
}
190+
}
191+
},
192+
init: function () {
193+
$().w2form(this.ui.welcome);
194+
$().w2form(this.ui.create_admin);
195+
$().w2form(this.ui.submit_form);
196+
ANT.addonLoaded.reg(function () {
197+
w2ui['sidebar'].click('install_welcome');
198+
});
199+
}
200+
};
201+
202+
ANT.initAddon({
203+
id: 'ant_install',
204+
text: '系统安装',
205+
group: true,
206+
expanded: true,
207+
nodes: [{
208+
id: 'install_welcome',
209+
text: '欢迎使用',
210+
icon: 'fa fa-heart',
211+
disabled: false,
212+
onClick: function () {
213+
ADDON.content(w2ui['welcome']);
214+
}
215+
}, {
216+
id: 'install_create_admin',
217+
text: '创建管理员',
218+
icon: 'fa fa-user',
219+
disabled: true,
220+
onClick: function () {
221+
ADDON.content(w2ui['create_admin']);
222+
}
223+
}, {
224+
id: 'install_submit_form',
225+
text: '确认信息',
226+
icon: 'fa fa-check',
227+
disabled: true,
228+
onClick: function () {
229+
ADDON.content(w2ui['submit_form']);
230+
}
231+
}]
232+
}, ADDON);
233+
234+
ANT.addonLoaded.reg(function() {
235+
ANT.ROUTE.run();
236+
})
237+
})(jQuery);

0 commit comments

Comments
 (0)