InPanel 1.2.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- inpanel/__init__.py +29 -0
- inpanel/acme.py +289 -0
- inpanel/aliyuncs.py +269 -0
- inpanel/app.py +514 -0
- inpanel/apt.py +223 -0
- inpanel/base.py +200 -0
- inpanel/config.py +139 -0
- inpanel/data/config.ini +29 -0
- inpanel/data/history +5 -0
- inpanel/data/runlogs.ini +12 -0
- inpanel/data/update_info.ini +4 -0
- inpanel/dnf.py +225 -0
- inpanel/lib/__init__.py +9 -0
- inpanel/lib/async_process.py +98 -0
- inpanel/lib/filelock.py +82 -0
- inpanel/lib/magic.py +233 -0
- inpanel/lib/pxssh.py +310 -0
- inpanel/lib/pyDes.py +867 -0
- inpanel/mod/__init__.py +0 -0
- inpanel/mod/apt.py +316 -0
- inpanel/mod/certificate.py +268 -0
- inpanel/mod/config.py +372 -0
- inpanel/mod/cron.py +315 -0
- inpanel/mod/disk.py +322 -0
- inpanel/mod/dnf.py +239 -0
- inpanel/mod/file.py +722 -0
- inpanel/mod/firewall.py +199 -0
- inpanel/mod/firewall_base.py +137 -0
- inpanel/mod/firewall_firewalld.py +170 -0
- inpanel/mod/firewall_iptables.py +176 -0
- inpanel/mod/firewall_macos.py +213 -0
- inpanel/mod/firewall_ufw.py +128 -0
- inpanel/mod/ftp.py +231 -0
- inpanel/mod/httpd.py +1205 -0
- inpanel/mod/lighttpd.py +26 -0
- inpanel/mod/login.py +98 -0
- inpanel/mod/mysql.py +577 -0
- inpanel/mod/named.py +26 -0
- inpanel/mod/nginx.py +2327 -0
- inpanel/mod/package.py +33 -0
- inpanel/mod/package_apt.py +62 -0
- inpanel/mod/package_base.py +77 -0
- inpanel/mod/package_dnf.py +62 -0
- inpanel/mod/package_map.py +366 -0
- inpanel/mod/package_yum.py +64 -0
- inpanel/mod/php.py +289 -0
- inpanel/mod/process.py +291 -0
- inpanel/mod/proftpd.py +26 -0
- inpanel/mod/pureftpd.py +26 -0
- inpanel/mod/query.py +108 -0
- inpanel/mod/server.py +1319 -0
- inpanel/mod/service.py +262 -0
- inpanel/mod/setting.py +228 -0
- inpanel/mod/shell.py +78 -0
- inpanel/mod/ssh.py +280 -0
- inpanel/mod/system.py +220 -0
- inpanel/mod/task.py +1337 -0
- inpanel/mod/ufw.py +14 -0
- inpanel/mod/user.py +306 -0
- inpanel/mod/vsftpd.py +67 -0
- inpanel/mod/yum.py +243 -0
- inpanel/plugins/__init__.py +10 -0
- inpanel/plugins/__pycache__/__init__.cpython-313.pyc +0 -0
- inpanel/plugins/acme/static/index.html +10 -0
- inpanel/plugins/acme/static/index.js +13 -0
- inpanel/plugins/shadowsocks-libev/__pycache__/info.cpython-313.pyc +0 -0
- inpanel/plugins/shadowsocks-libev/info.py +73 -0
- inpanel/plugins/shadowsocks-libev/static/index.html +70 -0
- inpanel/plugins/shadowsocks-libev/static/index.js +18 -0
- inpanel/public/css/global.css +138 -0
- inpanel/public/favicon.ico +0 -0
- inpanel/public/images/alipay.jpg +0 -0
- inpanel/public/images/loading.gif +0 -0
- inpanel/public/images/weixin.jpg +0 -0
- inpanel/public/index.html +94 -0
- inpanel/public/js/controllers/controllers.js +566 -0
- inpanel/public/js/controllers/database.js +590 -0
- inpanel/public/js/controllers/ecs.js +624 -0
- inpanel/public/js/controllers/file.js +940 -0
- inpanel/public/js/controllers/plugins.js +105 -0
- inpanel/public/js/controllers/service.js +1460 -0
- inpanel/public/js/controllers/site.js +1241 -0
- inpanel/public/js/controllers/utils.js +2319 -0
- inpanel/public/js/core.js +221 -0
- inpanel/public/js/directives.js +784 -0
- inpanel/public/js/filters.js +395 -0
- inpanel/public/js/services.js +257 -0
- inpanel/public/lib/angular/1.0.2/angular-resource.min.js +10 -0
- inpanel/public/lib/angular/1.0.2/angular.min.js +158 -0
- inpanel/public/lib/bootstrap/css/bootstrap-theme.css +587 -0
- inpanel/public/lib/bootstrap/css/bootstrap-theme.css.map +1 -0
- inpanel/public/lib/bootstrap/css/bootstrap-theme.min.css +6 -0
- inpanel/public/lib/bootstrap/css/bootstrap-theme.min.css.map +1 -0
- inpanel/public/lib/bootstrap/css/bootstrap.css +6757 -0
- inpanel/public/lib/bootstrap/css/bootstrap.css.map +1 -0
- inpanel/public/lib/bootstrap/css/bootstrap.min.css +6 -0
- inpanel/public/lib/bootstrap/css/bootstrap.min.css.map +1 -0
- inpanel/public/lib/bootstrap/fonts/glyphicons-halflings-regular.eot +0 -0
- inpanel/public/lib/bootstrap/fonts/glyphicons-halflings-regular.svg +288 -0
- inpanel/public/lib/bootstrap/fonts/glyphicons-halflings-regular.ttf +0 -0
- inpanel/public/lib/bootstrap/fonts/glyphicons-halflings-regular.woff +0 -0
- inpanel/public/lib/bootstrap/fonts/glyphicons-halflings-regular.woff2 +0 -0
- inpanel/public/lib/bootstrap/img/glyphicons-halflings-white.png +0 -0
- inpanel/public/lib/bootstrap/img/glyphicons-halflings.png +0 -0
- inpanel/public/lib/bootstrap/js/bootstrap.js +2377 -0
- inpanel/public/lib/bootstrap/js/bootstrap.min.js +7 -0
- inpanel/public/lib/bootstrap/js/npm.js +13 -0
- inpanel/public/lib/codemirror/codemirror-compressed.js +1 -0
- inpanel/public/lib/codemirror/codemirror.css +173 -0
- inpanel/public/lib/jquery/jquery-1.12.4.min.js +5 -0
- inpanel/public/lib/md5/md5.js +379 -0
- inpanel/public/lib/md5/md5.min.js +1 -0
- inpanel/public/partials/database/index.html +172 -0
- inpanel/public/partials/database/mysql/dbedit.html +462 -0
- inpanel/public/partials/database/mysql/dbnew.html +348 -0
- inpanel/public/partials/database/mysql/useredit.html +310 -0
- inpanel/public/partials/database/mysql/usernew.html +97 -0
- inpanel/public/partials/directives/message.html +20 -0
- inpanel/public/partials/directives/navbar.html +25 -0
- inpanel/public/partials/directives/selector.html +57 -0
- inpanel/public/partials/directives/srvbase.html +72 -0
- inpanel/public/partials/directives/srvext.html +34 -0
- inpanel/public/partials/directives/srvfile.html +23 -0
- inpanel/public/partials/directives/srvinstall.html +34 -0
- inpanel/public/partials/directives/srvlog.html +23 -0
- inpanel/public/partials/directives/srvminiop.html +28 -0
- inpanel/public/partials/directives/srvuninstall.html +38 -0
- inpanel/public/partials/directives/srvupdate.html +30 -0
- inpanel/public/partials/ecs/account.html +156 -0
- inpanel/public/partials/ecs/ecs.html +198 -0
- inpanel/public/partials/ecs/index.html +40 -0
- inpanel/public/partials/ecs/setings.html +459 -0
- inpanel/public/partials/file/file.html +501 -0
- inpanel/public/partials/file/trash.html +95 -0
- inpanel/public/partials/ftp.html +36 -0
- inpanel/public/partials/log.html +83 -0
- inpanel/public/partials/login.html +79 -0
- inpanel/public/partials/logout.html +22 -0
- inpanel/public/partials/main.html +534 -0
- inpanel/public/partials/plugins/index.html +55 -0
- inpanel/public/partials/plugins/plugins.html +13 -0
- inpanel/public/partials/secure.html +13 -0
- inpanel/public/partials/service/apache.html +147 -0
- inpanel/public/partials/service/cron.html +71 -0
- inpanel/public/partials/service/index.html +293 -0
- inpanel/public/partials/service/iptables.html +40 -0
- inpanel/public/partials/service/lighttpd.html +63 -0
- inpanel/public/partials/service/mariadb.html +113 -0
- inpanel/public/partials/service/memcache.html +36 -0
- inpanel/public/partials/service/minio.html +44 -0
- inpanel/public/partials/service/mongodb.html +44 -0
- inpanel/public/partials/service/mysql.html +113 -0
- inpanel/public/partials/service/named.html +61 -0
- inpanel/public/partials/service/nginx.html +296 -0
- inpanel/public/partials/service/ntp.html +40 -0
- inpanel/public/partials/service/php.html +250 -0
- inpanel/public/partials/service/proftpd.html +59 -0
- inpanel/public/partials/service/pureftpd.html +59 -0
- inpanel/public/partials/service/redis.html +40 -0
- inpanel/public/partials/service/samba.html +58 -0
- inpanel/public/partials/service/sendmail.html +40 -0
- inpanel/public/partials/service/ssh.html +186 -0
- inpanel/public/partials/service/tomcat.html +65 -0
- inpanel/public/partials/service/vsftpd.html +195 -0
- inpanel/public/partials/setting.html +299 -0
- inpanel/public/partials/site/apache/site.html +277 -0
- inpanel/public/partials/site/index.html +344 -0
- inpanel/public/partials/site/nginx/site.html +558 -0
- inpanel/public/partials/sorry.html +19 -0
- inpanel/public/partials/storage/autofm.html +103 -0
- inpanel/public/partials/storage/backup.html +42 -0
- inpanel/public/partials/storage/index.html +360 -0
- inpanel/public/partials/storage/migrate.html +93 -0
- inpanel/public/partials/storage/movedata.html +98 -0
- inpanel/public/partials/storage/remote.html +77 -0
- inpanel/public/partials/utils/cron.html +486 -0
- inpanel/public/partials/utils/firewall.html +266 -0
- inpanel/public/partials/utils/index.html +193 -0
- inpanel/public/partials/utils/network.html +118 -0
- inpanel/public/partials/utils/process.html +239 -0
- inpanel/public/partials/utils/repository.html +373 -0
- inpanel/public/partials/utils/shell.html +28 -0
- inpanel/public/partials/utils/ssl.html +319 -0
- inpanel/public/partials/utils/time.html +109 -0
- inpanel/public/partials/utils/user.html +359 -0
- inpanel/public/robots.txt +2 -0
- inpanel/remote.py +109 -0
- inpanel/templates/file/preview.html +34 -0
- inpanel/templates/index.html +93 -0
- inpanel/utils.py +282 -0
- inpanel/web.py +1811 -0
- inpanel/yum.py +756 -0
- inpanel-1.2.1.dist-info/METADATA +399 -0
- inpanel-1.2.1.dist-info/RECORD +198 -0
- inpanel-1.2.1.dist-info/WHEEL +5 -0
- inpanel-1.2.1.dist-info/entry_points.txt +2 -0
- inpanel-1.2.1.dist-info/licenses/LICENSE +30 -0
- inpanel-1.2.1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,1241 @@
|
|
|
1
|
+
var SiteCtrl = ['$scope', 'Module', '$routeParams', 'Request', 'Message', 'Backend',
|
|
2
|
+
function ($scope, Module, $routeParams, Request, Message, Backend) {
|
|
3
|
+
var module = 'site';
|
|
4
|
+
Module.init(module, '网站管理');
|
|
5
|
+
var section = Module.getSection();
|
|
6
|
+
|
|
7
|
+
$scope.loaded = false;
|
|
8
|
+
$scope.has_httpserver = false;
|
|
9
|
+
$scope.nginx_supported = false;
|
|
10
|
+
$scope.nginxloading = false;
|
|
11
|
+
$scope.nginxservers = [];
|
|
12
|
+
$scope.nginx_status = null;
|
|
13
|
+
$scope.apache_supported = false;
|
|
14
|
+
$scope.apacheloading = false;
|
|
15
|
+
$scope.apacheservers = [];
|
|
16
|
+
$scope.apache_status = null;
|
|
17
|
+
$scope.packageloading = false;
|
|
18
|
+
$scope.site_packages = [];
|
|
19
|
+
$scope.current_server = {};
|
|
20
|
+
|
|
21
|
+
$scope.load = function () {
|
|
22
|
+
$scope.load_status(function () {
|
|
23
|
+
$scope.loaded = true;
|
|
24
|
+
if (!$scope.has_httpserver) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
$scope.load_section();
|
|
28
|
+
})
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
$scope.load_status = function (callback) {
|
|
32
|
+
Request.get('/api/query/service.nginx,service.httpd', function (res) {
|
|
33
|
+
if (res['service.nginx'] && res['service.nginx'].status) {
|
|
34
|
+
$scope.nginx_status = res['service.nginx'].status;
|
|
35
|
+
$scope.nginx_supported = true;
|
|
36
|
+
}
|
|
37
|
+
if (res['service.httpd'] && res['service.httpd'].status) {
|
|
38
|
+
$scope.apache_supported = true;
|
|
39
|
+
$scope.apache_status = res['service.httpd'].status;
|
|
40
|
+
}
|
|
41
|
+
$scope.has_httpserver = $scope.nginx_supported || $scope.apache_supported;
|
|
42
|
+
if (callback) {
|
|
43
|
+
callback();
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
$scope.load_section = function () {
|
|
48
|
+
if (section) {
|
|
49
|
+
if (section == 'package') {
|
|
50
|
+
$scope.loadpackage(1);
|
|
51
|
+
} else if (section == 'apache') {
|
|
52
|
+
$scope.loadapache(1);
|
|
53
|
+
} else if (section == 'nginx') {
|
|
54
|
+
$scope.loadnginx(1);
|
|
55
|
+
}
|
|
56
|
+
} else {
|
|
57
|
+
if ($scope.nginx_status == 'running') {
|
|
58
|
+
$scope.loadnginx(1);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
$scope.loadapache(1);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
$scope.nginx_set_status = function (status) {
|
|
65
|
+
if (!status || ['start', 'stop', 'restart'].indexOf(status) < 0) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
Backend.call($scope, module, '/api/backend/service_' + status, '/api/backend/service_' + status + '_nginx', {
|
|
69
|
+
'name': 'Nginx',
|
|
70
|
+
'service': 'nginx'
|
|
71
|
+
}, {
|
|
72
|
+
'success': function (res) {
|
|
73
|
+
if (res.code == 0) {
|
|
74
|
+
Message.setInfo(res.msg);
|
|
75
|
+
}
|
|
76
|
+
if (res.status == 'finish') {
|
|
77
|
+
$scope.load_status();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}, true);
|
|
81
|
+
};
|
|
82
|
+
$scope.loadnginx = function (init, reload) {
|
|
83
|
+
if (!init && Module.getSection() == 'nginx' && !reload) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
$scope.sec('nginx');
|
|
87
|
+
Module.setSection('nginx');
|
|
88
|
+
if (!$scope.nginx_supported) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
$scope.nginxloading = true;
|
|
92
|
+
Request.post('/api/operation/nginx', {
|
|
93
|
+
'action': 'getservers'
|
|
94
|
+
}, function (res) {
|
|
95
|
+
if (res.code == 0) {
|
|
96
|
+
$scope.nginxservers = res.data;
|
|
97
|
+
$scope.nginxloading = false;
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
};
|
|
101
|
+
$scope.apache_set_status = function (status) {
|
|
102
|
+
if (!status || ['start', 'stop', 'restart'].indexOf(status) < 0) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
Backend.call($scope, module, '/api/backend/service_' + status, '/api/backend/service_' + status + '_httpd', {
|
|
106
|
+
'name': 'Apache',
|
|
107
|
+
'service': 'httpd'
|
|
108
|
+
}, {
|
|
109
|
+
'success': function (res) {
|
|
110
|
+
Message.setInfo(res.msg);
|
|
111
|
+
if (res.status == 'finish') {
|
|
112
|
+
$scope.load_status();
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}, true);
|
|
116
|
+
};
|
|
117
|
+
$scope.loadapache = function (init, reload) {
|
|
118
|
+
if (!init && Module.getSection() == 'apache' && !reload) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
$scope.sec('apache');
|
|
122
|
+
Module.setSection('apache');
|
|
123
|
+
if (!$scope.apache_supported) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
$scope.apacheloading = true;
|
|
127
|
+
Request.post('/api/operation/apache', {
|
|
128
|
+
'action': 'getservers'
|
|
129
|
+
}, function (res) {
|
|
130
|
+
if (res.code == 0) {
|
|
131
|
+
$scope.apacheservers = res.data;
|
|
132
|
+
$scope.apacheloading = false;
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
$scope.loadpackage = function (init, reload) {
|
|
138
|
+
if (!init && Module.getSection() == 'package' && !reload) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
Module.setSection('package');
|
|
142
|
+
$scope.sec('package');
|
|
143
|
+
if (!$scope.has_httpserver) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
$scope.packageloading = true;
|
|
147
|
+
Request.get('/api/sitepackage/getlist', function (res) {
|
|
148
|
+
$scope.packageloading = false;
|
|
149
|
+
if (res.code == 0) {
|
|
150
|
+
$scope.site_packages = res.data;
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
$scope.package_install_setting = function (pkg) {
|
|
156
|
+
$scope.curpkg = pkg;
|
|
157
|
+
$scope.curver = pkg.versions[0];
|
|
158
|
+
$scope.pkgver = $scope.curver.code;
|
|
159
|
+
$scope.installpath = '/var/www';
|
|
160
|
+
$('#pkg_install_setting').modal();
|
|
161
|
+
};
|
|
162
|
+
$scope.package_version_select = function (v) {
|
|
163
|
+
$scope.pkgver = v.code;
|
|
164
|
+
$scope.curver = v;
|
|
165
|
+
};
|
|
166
|
+
$scope.selectinstallpath = function (i) {
|
|
167
|
+
$scope.selector_title = '请选择安装目录';
|
|
168
|
+
$scope.selector.onlydir = true;
|
|
169
|
+
$scope.selector.onlyfile = false;
|
|
170
|
+
$scope.selector.load($scope.installpath);
|
|
171
|
+
$scope.selector.selecthandler = function (path) {
|
|
172
|
+
$('#selector').modal('hide');
|
|
173
|
+
$scope.installpath = path;
|
|
174
|
+
};
|
|
175
|
+
$('#selector').modal();
|
|
176
|
+
};
|
|
177
|
+
$scope.package_install = function () {
|
|
178
|
+
// check whether the installpath is exists and whether it is empty
|
|
179
|
+
Message.setInfo('正在检测安装目录...', true);
|
|
180
|
+
Request.post('/api/operation/file', {
|
|
181
|
+
'action': 'listdir',
|
|
182
|
+
'path': $scope.installpath,
|
|
183
|
+
'showhidden': true,
|
|
184
|
+
'remember': false
|
|
185
|
+
}, function (res) {
|
|
186
|
+
if (res.code == 0) {
|
|
187
|
+
Message.setInfo('');
|
|
188
|
+
if (res.data.length > 0) {
|
|
189
|
+
$scope.confirm_title = '安装确认';
|
|
190
|
+
$scope.confirm_body = '<p>系统检测到目录 ' + $scope.installpath + ' 下存在文件,继续安装将可能会覆盖原文件。</p><p>确认要继续安装吗?</p>';
|
|
191
|
+
$('#confirm').modal();
|
|
192
|
+
$scope.confirm = package_get_downloadurl;
|
|
193
|
+
} else {
|
|
194
|
+
package_get_downloadurl();
|
|
195
|
+
}
|
|
196
|
+
} else {
|
|
197
|
+
Message.setError('安装失败!' + res.msg);
|
|
198
|
+
}
|
|
199
|
+
}, false, true);
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
function package_get_downloadurl() {
|
|
203
|
+
Message.setInfo('正在请求安装文件...');
|
|
204
|
+
Request.get('/api/sitepackage/getdownloadtask?name=' + $scope.curpkg.code + '&version=' + $scope.pkgver, function (res) {
|
|
205
|
+
if (res.code == 0) {
|
|
206
|
+
$scope.downloadurl = res.data.url;
|
|
207
|
+
$scope.downloadpath = res.data.path;
|
|
208
|
+
$scope.extractpath = res.data.temp;
|
|
209
|
+
|
|
210
|
+
Backend.call($scope, module, '/api/backend/wget', '/api/backend/wget_' + encodeURIComponent(encodeURIComponent($scope.downloadurl)), {
|
|
211
|
+
'url': $scope.downloadurl,
|
|
212
|
+
'path': $scope.downloadpath
|
|
213
|
+
}, {
|
|
214
|
+
'success': function () {
|
|
215
|
+
// decompress it
|
|
216
|
+
var zippath = $scope.downloadpath;
|
|
217
|
+
var despath = $scope.extractpath;
|
|
218
|
+
Backend.call($scope, module, '/api/backend/decompress', '/api/backend/decompress_' + zippath + '_' + despath, {
|
|
219
|
+
'zippath': zippath,
|
|
220
|
+
'despath': despath
|
|
221
|
+
}, {
|
|
222
|
+
'success': function () {
|
|
223
|
+
// move the right folder to site path
|
|
224
|
+
var corepath = $scope.curver.core_path;
|
|
225
|
+
var srcpath = $scope.extractpath + '/' + corepath + '/*';
|
|
226
|
+
var despath = $scope.installpath;
|
|
227
|
+
Backend.call( $scope, module, '/api/backend/copy', '/api/backend/copy_' + srcpath + '_' + despath, {
|
|
228
|
+
'srcpath': srcpath,
|
|
229
|
+
'despath': despath
|
|
230
|
+
}, {
|
|
231
|
+
'success': function () {
|
|
232
|
+
// install ok, remove the temp folder
|
|
233
|
+
Message.setInfo('正在清理安装临时文件...');
|
|
234
|
+
Backend.call( $scope, module, '/api/backend/remove', '/api/backend/remove_' + $scope.extractpath, {
|
|
235
|
+
'paths': $scope.extractpath
|
|
236
|
+
}, function () {
|
|
237
|
+
// set user.group to apache.apache
|
|
238
|
+
Message.setInfo('正在设置目录权限...');
|
|
239
|
+
Backend.call( $scope, module, '/api/backend/chown', '/api/backend/chown_' + $scope.installpath, {
|
|
240
|
+
'paths': $scope.installpath,
|
|
241
|
+
'user': 'apache',
|
|
242
|
+
'group': 'apache',
|
|
243
|
+
'recursively': true
|
|
244
|
+
}, {
|
|
245
|
+
'success': function () {
|
|
246
|
+
Message.setSuccess($scope.curpkg.name + ' v' + $scope.pkgver + ' 安装完成!');
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
}, true);
|
|
250
|
+
},
|
|
251
|
+
'error': function () {
|
|
252
|
+
Message.setError('复制安装文件过程中出现错误,安装取消!')
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
},
|
|
258
|
+
'error': function (error) {
|
|
259
|
+
Message.setError('下载安装包过程中出现错误,安装取消!')
|
|
260
|
+
}
|
|
261
|
+
}, false);
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
$scope.change_server = function (type, status, name, ip, port) {
|
|
267
|
+
if (!type || !status || ['nginx', 'apache'].indexOf(type) < 0 || ['enable', 'disable'].indexOf(status) < 0) {
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
Request.post('/api/operation/' + type, {
|
|
271
|
+
'action': status + 'server',
|
|
272
|
+
'ip': ip,
|
|
273
|
+
'port': port,
|
|
274
|
+
'server_name': name
|
|
275
|
+
}, function (res) {
|
|
276
|
+
if (res.code == 0) {
|
|
277
|
+
$scope['load' + type](0, 1);
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
};
|
|
281
|
+
$scope.delete_server_confirm = function (type, name, ip, port) {
|
|
282
|
+
$scope.current_server = {
|
|
283
|
+
type: type,
|
|
284
|
+
name: name,
|
|
285
|
+
ip: ip,
|
|
286
|
+
port: port
|
|
287
|
+
}
|
|
288
|
+
$('#delete-server-confirm').modal();
|
|
289
|
+
};
|
|
290
|
+
$scope.delete_server = function () {
|
|
291
|
+
if ($scope.current_server && $scope.current_server.type && ['nginx', 'apache'].indexOf($scope.current_server.type) > -1) {
|
|
292
|
+
var type = $scope.current_server.type;
|
|
293
|
+
Request.post('/api/operation/' + type, {
|
|
294
|
+
'action': 'deleteserver',
|
|
295
|
+
'ip': $scope.current_server.ip,
|
|
296
|
+
'port': $scope.current_server.port,
|
|
297
|
+
'server_name': $scope.current_server.name
|
|
298
|
+
}, function (res) {
|
|
299
|
+
if (res.code == 0) {
|
|
300
|
+
$scope['load' + type](0, 1);
|
|
301
|
+
$('#delete-server-confirm').modal('hide');
|
|
302
|
+
$scope.current_server = {};
|
|
303
|
+
}
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
];
|
|
309
|
+
|
|
310
|
+
var SiteNginxCtrl = ['$scope', 'Module', '$routeParams', '$location', 'Request', 'Message', 'Backend', 'Timeout',
|
|
311
|
+
function ($scope, Module, $routeParams, $location, Request, Message, Backend, Timeout) {
|
|
312
|
+
var section = $routeParams.section;
|
|
313
|
+
$scope.action = section == 'new' ? 'new' : 'edit';
|
|
314
|
+
$scope.module_header = $scope.action == 'new' ? '新建站点' : '编辑站点';
|
|
315
|
+
var site = $scope.action == 'edit' ? section.substr(5) : '';
|
|
316
|
+
var server_ip, server_port, server_name;
|
|
317
|
+
if ($scope.action == 'edit') {
|
|
318
|
+
site = site.split('_');
|
|
319
|
+
if (site.length == 3) {
|
|
320
|
+
server_ip = site[0];
|
|
321
|
+
server_port = site[1];
|
|
322
|
+
server_name = site[2];
|
|
323
|
+
} else if (site.length == 4 && site[3] == '') {
|
|
324
|
+
server_ip = site[0];
|
|
325
|
+
server_port = site[1];
|
|
326
|
+
server_name = '_';
|
|
327
|
+
} else {
|
|
328
|
+
$location.path('/site');
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
var module = 'site.nginx';
|
|
334
|
+
var tab_section = Module.getSection();
|
|
335
|
+
var tab_section_enabled = ['basic', 'ssl', 'rewrite', 'advanced'];
|
|
336
|
+
Module.init(module, $scope.module_header);
|
|
337
|
+
$scope.loaded = false;
|
|
338
|
+
$scope.showglobaladv = false;
|
|
339
|
+
$scope.curloc = -1;
|
|
340
|
+
$scope.setloc = function (i) {
|
|
341
|
+
$scope.curloc = i;
|
|
342
|
+
};
|
|
343
|
+
$scope.proxy_caches = [];
|
|
344
|
+
$scope.ssl_enabled = false;
|
|
345
|
+
|
|
346
|
+
var server_tmpl = {
|
|
347
|
+
server_names: [],
|
|
348
|
+
listens: [],
|
|
349
|
+
charset: '',
|
|
350
|
+
index: 'index.html index.htm index.php',
|
|
351
|
+
locations: [],
|
|
352
|
+
limit_rate: '',
|
|
353
|
+
limit_conn: '',
|
|
354
|
+
ssl_crt: '',
|
|
355
|
+
ssl_key: '',
|
|
356
|
+
rewrite_enable: false,
|
|
357
|
+
rewrite_rules: ''
|
|
358
|
+
};
|
|
359
|
+
var server_name_tmpl = {
|
|
360
|
+
'name': '',
|
|
361
|
+
'default_name': false
|
|
362
|
+
};
|
|
363
|
+
var listen_tmpl = {
|
|
364
|
+
'ip': '',
|
|
365
|
+
'port': '80',
|
|
366
|
+
'ssl': false,
|
|
367
|
+
'default_server': false
|
|
368
|
+
};
|
|
369
|
+
var location_tmpl = {
|
|
370
|
+
urlpath: '/',
|
|
371
|
+
engine: 'static',
|
|
372
|
+
'static': {
|
|
373
|
+
root: '/var/www/',
|
|
374
|
+
autocreate: true,
|
|
375
|
+
autoindex: false,
|
|
376
|
+
rewrite_enable: false,
|
|
377
|
+
rewrite_detect_file: true,
|
|
378
|
+
rewrite_rules: ''
|
|
379
|
+
},
|
|
380
|
+
fastcgi: {
|
|
381
|
+
root: '/var/www/',
|
|
382
|
+
autocreate: true,
|
|
383
|
+
fastcgi_pass: '127.0.0.1:9000',
|
|
384
|
+
rewrite_enable: false,
|
|
385
|
+
rewrite_detect_file: true,
|
|
386
|
+
rewrite_rules: ''
|
|
387
|
+
},
|
|
388
|
+
proxy: {
|
|
389
|
+
protocol: 'http',
|
|
390
|
+
host: '',
|
|
391
|
+
realip: true,
|
|
392
|
+
charset: '',
|
|
393
|
+
backends: [],
|
|
394
|
+
balance: 'ip_hash',
|
|
395
|
+
keepalive: '10',
|
|
396
|
+
proxy_cache_enable: false,
|
|
397
|
+
proxy_cache: '',
|
|
398
|
+
proxy_cache_min_uses: '',
|
|
399
|
+
proxy_cache_methods_post: false,
|
|
400
|
+
proxy_cache_key: {
|
|
401
|
+
schema: true,
|
|
402
|
+
host: false,
|
|
403
|
+
proxy_host: true,
|
|
404
|
+
uri: true,
|
|
405
|
+
},
|
|
406
|
+
proxy_cache_valid: [],
|
|
407
|
+
proxy_cache_use_stale: {
|
|
408
|
+
error: false,
|
|
409
|
+
timeout: false,
|
|
410
|
+
invalid_header: false,
|
|
411
|
+
updating: false,
|
|
412
|
+
http_500: false,
|
|
413
|
+
http_502: false,
|
|
414
|
+
http_503: false,
|
|
415
|
+
http_504: false,
|
|
416
|
+
http_404: false
|
|
417
|
+
},
|
|
418
|
+
proxy_cache_lock: false,
|
|
419
|
+
proxy_cache_lock_timeout: '5'
|
|
420
|
+
},
|
|
421
|
+
redirect: {
|
|
422
|
+
url: '',
|
|
423
|
+
type: '301',
|
|
424
|
+
option: 'keep'
|
|
425
|
+
},
|
|
426
|
+
error: {
|
|
427
|
+
code: '404'
|
|
428
|
+
}
|
|
429
|
+
};
|
|
430
|
+
var backend_tmpl = {
|
|
431
|
+
server: '',
|
|
432
|
+
weight: '',
|
|
433
|
+
fail_timeout: '10',
|
|
434
|
+
max_fails: '3'
|
|
435
|
+
};
|
|
436
|
+
var proxy_cache_valid_tmpl = {
|
|
437
|
+
code: 'any',
|
|
438
|
+
time: '1',
|
|
439
|
+
time_unit: 'h'
|
|
440
|
+
};
|
|
441
|
+
$scope.setting = angular.copy(server_tmpl);
|
|
442
|
+
$scope.gen_by_inpanel = $scope.action == 'new' ? true : false;
|
|
443
|
+
|
|
444
|
+
var global_rewrite_templates = {
|
|
445
|
+
'301_1': 'rewrite ^ http://example.com$request_uri? permanent',
|
|
446
|
+
'301_2': 'rewrite ^ http://example.com/ permanent',
|
|
447
|
+
'302_1': 'rewrite ^ http://example.com$request_uri? redirect',
|
|
448
|
+
'302_2': 'rewrite ^ http://example.com/ redirect'
|
|
449
|
+
};
|
|
450
|
+
$scope.$watch('rewrite_template', function (value) {
|
|
451
|
+
$scope.setting.rewrite_rules = value ? global_rewrite_templates[value] : '';
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
$scope.load = function () {
|
|
455
|
+
// check nginx version
|
|
456
|
+
tab_section = (tab_section && tab_section_enabled.indexOf(tab_section) > -1) ? tab_section : tab_section_enabled[0];
|
|
457
|
+
$scope.sec(tab_section);
|
|
458
|
+
Module.setSection(tab_section);
|
|
459
|
+
// nginx version check may take too long time, so we don't want to wait for it
|
|
460
|
+
if ($scope.action == 'new') {
|
|
461
|
+
$scope.loaded = true;
|
|
462
|
+
} else {
|
|
463
|
+
$scope.getserver();
|
|
464
|
+
}
|
|
465
|
+
// $scope.load_nginx_version();
|
|
466
|
+
$scope.load_proxy_caches();
|
|
467
|
+
};
|
|
468
|
+
|
|
469
|
+
$scope.load_nginx_version = function () {
|
|
470
|
+
// nginx version check
|
|
471
|
+
Backend.call($scope, module, '/api/backend/yum_info', '/api/backend/yum_info_nginx', {
|
|
472
|
+
'pkg': 'nginx',
|
|
473
|
+
'repo': 'installed'
|
|
474
|
+
}, {
|
|
475
|
+
'success': function (res) {
|
|
476
|
+
$scope.nginx_version = res.data[0].version;
|
|
477
|
+
},
|
|
478
|
+
'error': function (error) {
|
|
479
|
+
$scope.nginx_version = '';
|
|
480
|
+
//$scope.loaded = true;
|
|
481
|
+
}
|
|
482
|
+
}, true);
|
|
483
|
+
};
|
|
484
|
+
$scope.load_proxy_caches = function () {
|
|
485
|
+
// load proxy cache list
|
|
486
|
+
Request.post('/api/operation/nginx', {
|
|
487
|
+
'action': 'gethttpsettings',
|
|
488
|
+
'items': 'proxy_cache_path[]'
|
|
489
|
+
}, function (res) {
|
|
490
|
+
if (res.code == 0) {
|
|
491
|
+
var proxy_caches = [];
|
|
492
|
+
if (/msie/.test(navigator.userAgent.toLowerCase())) proxy_caches = ['']; // temp patch for ie8
|
|
493
|
+
var ps = res.data.proxy_cache_path;
|
|
494
|
+
if (ps) {
|
|
495
|
+
for (var i = 0; i < ps.length; i++) {
|
|
496
|
+
proxy_caches.push(ps[i].name);
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
$scope.proxy_caches = proxy_caches;
|
|
500
|
+
}
|
|
501
|
+
}, false, true);
|
|
502
|
+
};
|
|
503
|
+
$scope.getserver = function (quiet) {
|
|
504
|
+
// get server info (in edit mode)
|
|
505
|
+
Request.post('/api/operation/nginx', {
|
|
506
|
+
'action': 'getserver',
|
|
507
|
+
'ip': server_ip,
|
|
508
|
+
'port': server_port,
|
|
509
|
+
'server_name': server_name
|
|
510
|
+
}, function (res) {
|
|
511
|
+
if (res.code == 0) {
|
|
512
|
+
var d = res.data;
|
|
513
|
+
// init setting
|
|
514
|
+
var s = $scope.setting;
|
|
515
|
+
$scope.gen_by_inpanel = d._inpanel;
|
|
516
|
+
for (i in d.server_names) {
|
|
517
|
+
var name = d.server_names[i];
|
|
518
|
+
s.server_names.push({
|
|
519
|
+
'name': name,
|
|
520
|
+
'default_name': name == '_'
|
|
521
|
+
});
|
|
522
|
+
}
|
|
523
|
+
for (i in d.listens) {
|
|
524
|
+
var listen = d.listens[i];
|
|
525
|
+
var t = angular.copy(listen_tmpl);
|
|
526
|
+
if (typeof listen.ip != 'undefined') t.ip = listen.ip;
|
|
527
|
+
if (typeof listen.port != 'undefined') t.port = listen.port;
|
|
528
|
+
if (typeof listen.ssl != 'undefined') t.ssl = listen.ssl;
|
|
529
|
+
if (typeof listen.default_server != 'undefined') t.default_server = listen.default_server;
|
|
530
|
+
if (t.ssl) $scope.ssl_enabled = true;
|
|
531
|
+
s.listens.push(t);
|
|
532
|
+
}
|
|
533
|
+
if (d.index) s.index = d.index;
|
|
534
|
+
if (d.charset) s.charset = d.charset;
|
|
535
|
+
if (d.limit_rate) s.limit_rate = d.limit_rate;
|
|
536
|
+
if (d.limit_conn) s.limit_conn = d.limit_conn;
|
|
537
|
+
if (d.ssl_crt) s.ssl_crt = d.ssl_crt;
|
|
538
|
+
if (d.ssl_key) s.ssl_key = d.ssl_key;
|
|
539
|
+
if (d.rewrite_rules) {
|
|
540
|
+
s.rewrite_rules = d.rewrite_rules.join('\n');
|
|
541
|
+
if (s.rewrite_rules) s.rewrite_enable = true;
|
|
542
|
+
}
|
|
543
|
+
if (d.locations) {
|
|
544
|
+
for (i in d.locations) {
|
|
545
|
+
var loc = d.locations[i];
|
|
546
|
+
var t = angular.copy(location_tmpl);
|
|
547
|
+
if (typeof loc.urlpath != 'undefined') {
|
|
548
|
+
t.urlpath = loc.urlpath;
|
|
549
|
+
t.oldurlpath = t.urlpath;
|
|
550
|
+
}
|
|
551
|
+
// detect engine
|
|
552
|
+
if (typeof loc.error_code != 'undefined') {
|
|
553
|
+
t.engine = 'error';
|
|
554
|
+
t.error.code = loc.error_code;
|
|
555
|
+
} else if (typeof loc.fastcgi_pass != 'undefined') {
|
|
556
|
+
t.engine = 'fastcgi';
|
|
557
|
+
t.fastcgi.fastcgi_pass = loc.fastcgi_pass;
|
|
558
|
+
if (loc.root) t.fastcgi.root = loc.root;
|
|
559
|
+
t.fastcgi.rewrite_detect_file = loc.rewrite_detect_file ? true : false;
|
|
560
|
+
if (loc.rewrite_rules) {
|
|
561
|
+
t.fastcgi.rewrite_rules = loc.rewrite_rules.join(';\n');
|
|
562
|
+
if (t.fastcgi.rewrite_rules) {
|
|
563
|
+
t.fastcgi.rewrite_rules += ';';
|
|
564
|
+
t.fastcgi.rewrite_enable = true;
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
} else if (typeof loc.proxy_protocol != 'undefined') {
|
|
568
|
+
t.engine = 'proxy';
|
|
569
|
+
t.proxy.protocol = loc.proxy_protocol;
|
|
570
|
+
if (typeof loc.proxy_host != 'undefined') t.proxy.host = loc.proxy_host;
|
|
571
|
+
if (typeof loc.proxy_realip != 'undefined') t.proxy.realip = loc.proxy_realip;
|
|
572
|
+
if (typeof loc.proxy_balance != 'undefined') t.proxy.balance = loc.proxy_balance;
|
|
573
|
+
if (typeof loc.proxy_keepalive != 'undefined') t.proxy.keepalive = loc.proxy_keepalive;
|
|
574
|
+
for (i in loc.proxy_backends) {
|
|
575
|
+
var backend = loc.proxy_backends[i];
|
|
576
|
+
var b = angular.copy(backend_tmpl);
|
|
577
|
+
if (typeof backend.server != 'undefined') b.server = backend.server;
|
|
578
|
+
if (typeof backend.weight != 'undefined') b.weight = backend.weight;
|
|
579
|
+
if (typeof backend.fail_timeout != 'undefined') b.fail_timeout = backend.fail_timeout;
|
|
580
|
+
if (typeof backend.max_fails != 'undefined') b.max_fails = backend.max_fails;
|
|
581
|
+
t.proxy.backends.push(b);
|
|
582
|
+
}
|
|
583
|
+
if (typeof loc.proxy_cache != 'undefined') {
|
|
584
|
+
t.proxy.proxy_cache_enable = true;
|
|
585
|
+
t.proxy.proxy_cache = loc.proxy_cache;
|
|
586
|
+
if (typeof loc.proxy_cache_min_uses != 'undefined') t.proxy.proxy_cache_min_uses = loc.proxy_cache_min_uses;
|
|
587
|
+
if (typeof loc.proxy_cache_methods != 'undefined') t.proxy.proxy_cache_methods_post = loc.proxy_cache_methods == 'POST';
|
|
588
|
+
if (typeof loc.proxy_cache_key != 'undefined') {
|
|
589
|
+
var lks = loc.proxy_cache_key.split('$');
|
|
590
|
+
var tks = t.proxy.proxy_cache_key;
|
|
591
|
+
for (var i = 0; i < lks.length; i++) {
|
|
592
|
+
if (lks[i] == 'schema') tks.schema = true;
|
|
593
|
+
else if (lks[i] == 'host') tks.host = true;
|
|
594
|
+
else if (lks[i] == 'proxy_host') tks.proxy_host = true;
|
|
595
|
+
else if (lks[i] == 'request_uri') tks.uri = true;
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
if (typeof loc.proxy_cache_valid != 'undefined') {
|
|
599
|
+
var valids = loc.proxy_cache_valid;
|
|
600
|
+
for (var i = 0; i < valids.length; i++) {
|
|
601
|
+
t.proxy.proxy_cache_valid.push({
|
|
602
|
+
code: valids[i].code,
|
|
603
|
+
time: parseInt(valids[i].time) + '',
|
|
604
|
+
time_unit: valids[i].time.substr(valids[i].time.length - 1),
|
|
605
|
+
});
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
if (typeof loc.proxy_cache_use_stale != 'undefined') {
|
|
609
|
+
var lts = loc.proxy_cache_use_stale;
|
|
610
|
+
var tts = t.proxy.proxy_cache_use_stale;
|
|
611
|
+
for (var i = 0; i < lts.length; i++) {
|
|
612
|
+
if (lts[i] == 'error') tts.error = true;
|
|
613
|
+
else if (lts[i] == 'timeout') tts.timeout = true;
|
|
614
|
+
else if (lts[i] == 'invalid_header') tts.invalid_header = true;
|
|
615
|
+
else if (lts[i] == 'updating') tts.updating = true;
|
|
616
|
+
else if (lts[i] == 'http_500') tts.http_500 = true;
|
|
617
|
+
else if (lts[i] == 'http_502') tts.http_502 = true;
|
|
618
|
+
else if (lts[i] == 'http_503') tts.http_503 = true;
|
|
619
|
+
else if (lts[i] == 'http_504') tts.http_504 = true;
|
|
620
|
+
else if (lts[i] == 'http_404') tts.http_404 = true;
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
if (typeof loc.proxy_cache_lock != 'undefined') {
|
|
624
|
+
t.proxy.proxy_cache_lock = loc.proxy_cache_lock;
|
|
625
|
+
if (typeof loc.proxy_cache_lock_timeout != 'undefined')
|
|
626
|
+
t.proxy.proxy_cache_lock_timeout = loc.proxy_cache_lock_timeout;
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
} else if (typeof loc.redirect_url != 'undefined') {
|
|
630
|
+
t.engine = 'redirect';
|
|
631
|
+
t.redirect.url = loc.redirect_url;
|
|
632
|
+
if (typeof loc.redirect_type != 'undefined') t.redirect.type = loc.redirect_type;
|
|
633
|
+
if (typeof loc.redirect_option != 'undefined') t.redirect.option = loc.redirect_option;
|
|
634
|
+
} else if (typeof loc.root != 'undefined') {
|
|
635
|
+
t.engine = 'static';
|
|
636
|
+
t['static'].root = loc.root;
|
|
637
|
+
t['static'].rewrite_detect_file = loc.rewrite_detect_file ? true : false;
|
|
638
|
+
if (typeof loc.autoindex != 'undefined') t['static'].autoindex = loc.autoindex;
|
|
639
|
+
if (loc.rewrite_rules) {
|
|
640
|
+
t['static'].rewrite_rules = loc.rewrite_rules.join(';\n');
|
|
641
|
+
if (t['static'].rewrite_rules) {
|
|
642
|
+
t['static'].rewrite_rules += ';';
|
|
643
|
+
t['static'].rewrite_enable = true;
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
if (t.proxy.backends.length == 0) t.proxy.backends.push(angular.copy(backend_tmpl));
|
|
648
|
+
s.locations.push(t);
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
$scope.curloc = 0;
|
|
652
|
+
$scope.loaded = true;
|
|
653
|
+
} else {
|
|
654
|
+
Timeout(function () {
|
|
655
|
+
$location.path('/site');
|
|
656
|
+
}, 1000, module);
|
|
657
|
+
}
|
|
658
|
+
}, false, quiet);
|
|
659
|
+
};
|
|
660
|
+
|
|
661
|
+
// server name operation
|
|
662
|
+
$scope.deleteservername = function (i) {
|
|
663
|
+
$scope.setting.server_names.splice(i, 1);
|
|
664
|
+
};
|
|
665
|
+
$scope.addservername = function () {
|
|
666
|
+
$scope.setting.server_names.push(angular.copy(server_name_tmpl));
|
|
667
|
+
};
|
|
668
|
+
|
|
669
|
+
// listen operation
|
|
670
|
+
$scope.deletelisten = function (i) {
|
|
671
|
+
$scope.setting.listens.splice(i, 1);
|
|
672
|
+
};
|
|
673
|
+
$scope.addlisten = function () {
|
|
674
|
+
var sn = angular.copy(listen_tmpl);
|
|
675
|
+
sn.ssl = $scope.ssl_enabled;
|
|
676
|
+
$scope.setting.listens.push(sn);
|
|
677
|
+
};
|
|
678
|
+
|
|
679
|
+
// location operation
|
|
680
|
+
$scope.deletelocation = function (i) {
|
|
681
|
+
$scope.setting.locations.splice(i, 1);
|
|
682
|
+
$scope.curloc--;
|
|
683
|
+
if ($scope.curloc < 0 && $scope.setting.locations.length > 0) $scope.curloc = 0;
|
|
684
|
+
};
|
|
685
|
+
$scope.addlocation = function () {
|
|
686
|
+
var locs = $scope.setting.locations;
|
|
687
|
+
locs.splice($scope.curloc + 1, 0, angular.copy(location_tmpl));
|
|
688
|
+
$scope.proxy_addbackend($scope.curloc + 1);
|
|
689
|
+
$scope.curloc++;
|
|
690
|
+
};
|
|
691
|
+
|
|
692
|
+
// proxy operation
|
|
693
|
+
$scope.proxy_deletebackend = function (loc_i, i) {
|
|
694
|
+
$scope.setting.locations[loc_i].proxy.backends.splice(i, 1);
|
|
695
|
+
};
|
|
696
|
+
$scope.proxy_addbackend = function (loc_i) {
|
|
697
|
+
$scope.setting.locations[loc_i].proxy.backends.push(angular.copy(backend_tmpl));
|
|
698
|
+
$scope.proxy_addvalid(loc_i);
|
|
699
|
+
};
|
|
700
|
+
$scope.proxy_deletevalid = function (loc_i, i) {
|
|
701
|
+
$scope.setting.locations[loc_i].proxy.proxy_cache_valid.splice(i, 1);
|
|
702
|
+
};
|
|
703
|
+
$scope.proxy_addvalid = function (loc_i) {
|
|
704
|
+
$scope.setting.locations[loc_i].proxy.proxy_cache_valid.push(angular.copy(proxy_cache_valid_tmpl));
|
|
705
|
+
};
|
|
706
|
+
|
|
707
|
+
// automatically set the root path of static and fastcgi engine
|
|
708
|
+
$scope.$watch('setting.server_names[0].name', function (value, oldvalue) {
|
|
709
|
+
var server_name = value;
|
|
710
|
+
var old_server_name = oldvalue;
|
|
711
|
+
var locs = $scope.setting.locations;
|
|
712
|
+
for (var i = 0; i < locs.length; i++) {
|
|
713
|
+
if (locs[i].urlpath == '/') {
|
|
714
|
+
var prefix = location_tmpl['static'].root;
|
|
715
|
+
var expected_path = prefix + '/' + old_server_name;
|
|
716
|
+
expected_path = expected_path.replace('//', '/');
|
|
717
|
+
if (locs[i]['static'].root == expected_path) {
|
|
718
|
+
var root = prefix + '/' + server_name;
|
|
719
|
+
locs[i]['static'].root = root.replace('//', '/');
|
|
720
|
+
}
|
|
721
|
+
var prefix = location_tmpl.fastcgi.root;
|
|
722
|
+
var expected_path = prefix + '/' + old_server_name;
|
|
723
|
+
expected_path = expected_path.replace('//', '/');
|
|
724
|
+
if (locs[i].fastcgi.root == expected_path) {
|
|
725
|
+
var root = prefix + '/' + server_name;
|
|
726
|
+
locs[i].fastcgi.root = root.replace('//', '/');
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
});
|
|
731
|
+
|
|
732
|
+
// operations when url path change
|
|
733
|
+
$scope.urlpathchange = function (loc) {
|
|
734
|
+
if (loc.urlpath.length == 0) loc.urlpath = '/';
|
|
735
|
+
if (loc.engine == 'fastcgi' && loc.fastcgi.rewrite_enable) {
|
|
736
|
+
// parse rewrite rules and automatically replace the path start with the old path
|
|
737
|
+
var r = new RegExp('([\\^\\s])(' + (loc.oldurlpath + '/').replace('//', '/').replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&') + ')', 'gm');
|
|
738
|
+
loc.fastcgi.rewrite_rules = loc.fastcgi.rewrite_rules.replace(r, '$1' + (loc.urlpath + '/').replace('//', '/'));
|
|
739
|
+
loc.oldurlpath = loc.urlpath;
|
|
740
|
+
}
|
|
741
|
+
};
|
|
742
|
+
|
|
743
|
+
// site folder selector
|
|
744
|
+
$scope.selectstaticfolder = function (i) {
|
|
745
|
+
$scope.selector_title = '请选择站点目录';
|
|
746
|
+
$scope.selector.onlydir = true;
|
|
747
|
+
$scope.selector.onlyfile = false;
|
|
748
|
+
$scope.selector.load($scope.setting.locations[i]['static'].root);
|
|
749
|
+
$scope.selector.selecthandler = function (path) {
|
|
750
|
+
$('#selector').modal('hide');
|
|
751
|
+
$scope.setting.locations[i]['static'].root = path;
|
|
752
|
+
};
|
|
753
|
+
$('#selector').modal();
|
|
754
|
+
};
|
|
755
|
+
$scope.selectfastcgifolder = function (i) {
|
|
756
|
+
$scope.selector_title = '请选择站点目录';
|
|
757
|
+
$scope.selector.onlydir = true;
|
|
758
|
+
$scope.selector.onlyfile = false;
|
|
759
|
+
$scope.selector.load($scope.setting.locations[i].fastcgi.root);
|
|
760
|
+
$scope.selector.selecthandler = function (path) {
|
|
761
|
+
$('#selector').modal('hide');
|
|
762
|
+
$scope.setting.locations[i].fastcgi.root = path;
|
|
763
|
+
};
|
|
764
|
+
$('#selector').modal();
|
|
765
|
+
};
|
|
766
|
+
$scope.ssl_status_set = function (i) {
|
|
767
|
+
$scope.ssl_enabled = i || false;
|
|
768
|
+
for (i in $scope.setting.listens) {
|
|
769
|
+
$scope.setting.listens[i].ssl = $scope.ssl_enabled
|
|
770
|
+
}
|
|
771
|
+
};
|
|
772
|
+
// ssl selector
|
|
773
|
+
$scope.selectsslcrt = function (i) {
|
|
774
|
+
$scope.selector_title = '请选择证书文件(*.crt)';
|
|
775
|
+
$scope.selector.onlydir = false;
|
|
776
|
+
$scope.selector.onlyfile = true;
|
|
777
|
+
$scope.selector.load('/etc/nginx');
|
|
778
|
+
$scope.selector.selecthandler = function (path) {
|
|
779
|
+
$('#selector').modal('hide');
|
|
780
|
+
$scope.setting.ssl_crt = path;
|
|
781
|
+
};
|
|
782
|
+
$('#selector').modal();
|
|
783
|
+
};
|
|
784
|
+
$scope.selectsslkey = function (i) {
|
|
785
|
+
$scope.selector_title = '请选择密钥文件(*.key)';
|
|
786
|
+
$scope.selector.onlydir = false;
|
|
787
|
+
$scope.selector.onlyfile = true;
|
|
788
|
+
$scope.selector.load('/etc/nginx');
|
|
789
|
+
$scope.selector.selecthandler = function (path) {
|
|
790
|
+
$('#selector').modal('hide');
|
|
791
|
+
$scope.setting.ssl_key = path;
|
|
792
|
+
};
|
|
793
|
+
$('#selector').modal();
|
|
794
|
+
};
|
|
795
|
+
|
|
796
|
+
// submit
|
|
797
|
+
$scope.submit = function (active) {
|
|
798
|
+
if ($scope.action == 'new') {
|
|
799
|
+
$scope.addserver(active);
|
|
800
|
+
} else if ($scope.action == 'edit') {
|
|
801
|
+
$scope.updateserver(active);
|
|
802
|
+
}
|
|
803
|
+
};
|
|
804
|
+
$scope.addserver = function (active) {
|
|
805
|
+
Request.post('/api/operation/nginx', {
|
|
806
|
+
'action': 'addserver',
|
|
807
|
+
'version': $scope.nginx_version,
|
|
808
|
+
'setting': angular.toJson($scope.setting)
|
|
809
|
+
}, function (res) {
|
|
810
|
+
if (res.code == 0) {
|
|
811
|
+
var s = $scope.setting;
|
|
812
|
+
$scope.loaded = false;
|
|
813
|
+
var name = (s.listens[0].ip ? s.listens[0].ip : '*') + '_' + s.listens[0].port + '_' + s.server_names[0].name;
|
|
814
|
+
$location.path('/site/nginx/edit_' + name);
|
|
815
|
+
if (active && active == 'active') {
|
|
816
|
+
$scope.nginx_set_status('restart');
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
});
|
|
820
|
+
};
|
|
821
|
+
$scope.updateserver = function (active) {
|
|
822
|
+
Request.post('/api/operation/nginx', {
|
|
823
|
+
'action': 'updateserver',
|
|
824
|
+
'ip': server_ip,
|
|
825
|
+
'port': server_port,
|
|
826
|
+
'server_name': server_name,
|
|
827
|
+
'version': $scope.nginx_version,
|
|
828
|
+
'setting': angular.toJson($scope.setting)
|
|
829
|
+
}, function (res) {
|
|
830
|
+
if (res.code == 0) {
|
|
831
|
+
var s = $scope.setting;
|
|
832
|
+
$scope.loaded = false;
|
|
833
|
+
var name = (s.listens[0].ip ? s.listens[0].ip : '*') + '_' + s.listens[0].port + '_' + s.server_names[0].name;
|
|
834
|
+
var new_path = '/site/nginx/edit_' + name;
|
|
835
|
+
if (new_path != $location.path()) {
|
|
836
|
+
$location.path(new_path);
|
|
837
|
+
console.log('修改成功')
|
|
838
|
+
} else {
|
|
839
|
+
$scope.restore();
|
|
840
|
+
if (active && active == 'active') {
|
|
841
|
+
$scope.nginx_set_status('restart');
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
});
|
|
846
|
+
};
|
|
847
|
+
$scope.restore = function () {
|
|
848
|
+
$scope.setting = angular.copy(server_tmpl);
|
|
849
|
+
if ($scope.action == 'edit') {
|
|
850
|
+
$scope.getserver();
|
|
851
|
+
}
|
|
852
|
+
};
|
|
853
|
+
$scope.nginx_set_status = function (status) {
|
|
854
|
+
if (!status || ['start', 'stop', 'restart'].indexOf(status) < 0) {
|
|
855
|
+
return;
|
|
856
|
+
}
|
|
857
|
+
Backend.call($scope, module, '/api/backend/service_' + status, '/api/backend/service_' + status + '_nginx', {
|
|
858
|
+
'name': 'Nginx',
|
|
859
|
+
'service': 'nginx'
|
|
860
|
+
}, {
|
|
861
|
+
'success': function (res) {
|
|
862
|
+
Message.setInfo(res.msg);
|
|
863
|
+
}
|
|
864
|
+
}, true);
|
|
865
|
+
};
|
|
866
|
+
// initially add
|
|
867
|
+
if ($scope.action == 'new') {
|
|
868
|
+
$scope.addservername();
|
|
869
|
+
$scope.addlisten();
|
|
870
|
+
$scope.addlocation();
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
];
|
|
874
|
+
|
|
875
|
+
var SiteApacheCtrl = ['$scope', 'Module', '$routeParams', '$location', 'Request', 'Message', 'Backend', 'Timeout',
|
|
876
|
+
function ($scope, Module, $routeParams, $location, Request, Message, Backend, Timeout) {
|
|
877
|
+
var section = $routeParams.section;
|
|
878
|
+
var module = 'site.apache';
|
|
879
|
+
var tab_section = Module.getSection();
|
|
880
|
+
var tab_section_enabled = ['basic', 'directory', 'server-alias', 'advanced'];
|
|
881
|
+
var server_ip = '';
|
|
882
|
+
var server_port = '';
|
|
883
|
+
var server_name = '';
|
|
884
|
+
$scope.action = section == 'new' ? 'new' : 'edit';
|
|
885
|
+
if ($scope.action == 'edit') {
|
|
886
|
+
var site = section.substr(5).split('_');
|
|
887
|
+
if (site && site.length == 3) {
|
|
888
|
+
server_ip = site[0];
|
|
889
|
+
server_port = site[1];
|
|
890
|
+
server_name = site[2];
|
|
891
|
+
} else if (site && site.length == 4 && site[3] == '') {
|
|
892
|
+
server_ip = site[0];
|
|
893
|
+
server_port = site[1];
|
|
894
|
+
server_name = '_';
|
|
895
|
+
} else {
|
|
896
|
+
$location.path('/site?s=apache');
|
|
897
|
+
return;
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
$scope.loaded = false;
|
|
901
|
+
$scope.module_header = $scope.action == 'new' ? '新建站点' : '编辑站点';
|
|
902
|
+
Module.init(module, $scope.module_header);
|
|
903
|
+
$scope.gen_by_inpanel = $scope.action == 'new' ? true : false;
|
|
904
|
+
$scope.curdir_index = -1;
|
|
905
|
+
$scope.setdir_index = function (i) {
|
|
906
|
+
$scope.curdir_index = i;
|
|
907
|
+
};
|
|
908
|
+
|
|
909
|
+
$scope.load = function () {
|
|
910
|
+
tab_section = (tab_section && tab_section_enabled.indexOf(tab_section) > -1) ? tab_section : tab_section_enabled[0];
|
|
911
|
+
$scope.sec(tab_section);
|
|
912
|
+
Module.setSection(tab_section);
|
|
913
|
+
if ($scope.action == 'new') {
|
|
914
|
+
$scope.add_directory();
|
|
915
|
+
$scope.loaded = true;
|
|
916
|
+
} else {
|
|
917
|
+
$scope.getserver();
|
|
918
|
+
}
|
|
919
|
+
Backend.call($scope, module, '/api/backend/yum_info', '/api/backend/yum_info_apache', {
|
|
920
|
+
'pkg': 'apache',
|
|
921
|
+
'repo': 'installed'
|
|
922
|
+
}, {
|
|
923
|
+
'success': function (res) {
|
|
924
|
+
$scope.apache_version = res.data[0].version;
|
|
925
|
+
},
|
|
926
|
+
'error': function () {
|
|
927
|
+
$scope.apache_version = '';
|
|
928
|
+
}
|
|
929
|
+
}, true);
|
|
930
|
+
};
|
|
931
|
+
var server_tmpl = {
|
|
932
|
+
servername: '',
|
|
933
|
+
serveralias: [],
|
|
934
|
+
ip: '',
|
|
935
|
+
port: '80',
|
|
936
|
+
serveradmin: '',
|
|
937
|
+
documentroot: '/var/www',
|
|
938
|
+
directoryindex: 'index.html index.htm index.php',
|
|
939
|
+
directory: [],
|
|
940
|
+
customlog: '',
|
|
941
|
+
errorlog: '',
|
|
942
|
+
gzip: false,
|
|
943
|
+
ssl_crt: '',
|
|
944
|
+
ssl_key: '',
|
|
945
|
+
rewrite_enable: false,
|
|
946
|
+
rewrite_rules: '',
|
|
947
|
+
autocreate: true
|
|
948
|
+
};
|
|
949
|
+
$scope.setting = angular.copy(server_tmpl);
|
|
950
|
+
|
|
951
|
+
// get server info (in edit mode)
|
|
952
|
+
$scope.getserver = function (quiet) {
|
|
953
|
+
Request.post('/api/operation/apache', {
|
|
954
|
+
'action': 'getserver',
|
|
955
|
+
'ip': server_ip,
|
|
956
|
+
'port': server_port,
|
|
957
|
+
'name': server_name
|
|
958
|
+
}, function (res) {
|
|
959
|
+
if (res.code == 0) {
|
|
960
|
+
$scope.gen_by_inpanel = res.data._inpanel;
|
|
961
|
+
$scope.setting.port = res.data.port;
|
|
962
|
+
$scope.setting.ip = res.data.ip;
|
|
963
|
+
$scope.setting.documentroot = res.data.documentroot;
|
|
964
|
+
$scope.setting.serveradmin = res.data.serveradmin;
|
|
965
|
+
$scope.setting.servername = res.data.servername || '';
|
|
966
|
+
$scope.setting.customlog = res.data.customlog || '';
|
|
967
|
+
$scope.setting.directoryindex = res.data.directoryindex || '';
|
|
968
|
+
$scope.setting.errorlog = res.data.errorlog || '';
|
|
969
|
+
$scope.setting.gzip = res.data.gzip || false;
|
|
970
|
+
// if (res.data.ssl_crt) $scope.setting.ssl_crt = res.data.ssl_crt;
|
|
971
|
+
// if (res.data.ssl_key) $scope.setting.ssl_key = res.data.ssl_key;
|
|
972
|
+
// if (res.data.rewrite_rules) {
|
|
973
|
+
// $scope.setting.rewrite_rules = res.data.rewrite_rules.join('\n');
|
|
974
|
+
// if ($scope.setting.rewrite_rules) $scope.setting.rewrite_enable = true;
|
|
975
|
+
// }
|
|
976
|
+
$scope.detect_server_alias(res.data.serveralias);
|
|
977
|
+
$scope.detect_directory(res.data.directory);
|
|
978
|
+
$scope.loaded = true;
|
|
979
|
+
} else {
|
|
980
|
+
Timeout(function () {
|
|
981
|
+
$location.path('/site');
|
|
982
|
+
}, 1000, module);
|
|
983
|
+
}
|
|
984
|
+
}, false, quiet);
|
|
985
|
+
};
|
|
986
|
+
|
|
987
|
+
// ServerAlias operation
|
|
988
|
+
$scope.detect_server_alias = function (s) {
|
|
989
|
+
if (s) {
|
|
990
|
+
for (i in s) {
|
|
991
|
+
$scope.setting.serveralias.push({'name':s[i]})
|
|
992
|
+
}
|
|
993
|
+
} else {
|
|
994
|
+
$scope.setting.serveralias = [];
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
$scope.del_server_alias = function (i) {
|
|
998
|
+
$scope.setting.serveralias.splice(i, 1);
|
|
999
|
+
};
|
|
1000
|
+
$scope.add_server_alias = function () {
|
|
1001
|
+
$scope.setting.serveralias.push({'name':''});
|
|
1002
|
+
};
|
|
1003
|
+
|
|
1004
|
+
var directory_tmpl = {
|
|
1005
|
+
path: '/',
|
|
1006
|
+
indexes: '-',
|
|
1007
|
+
followsymlinks: '+',
|
|
1008
|
+
execcgi: '+',
|
|
1009
|
+
allow: '',
|
|
1010
|
+
deny: '',
|
|
1011
|
+
order: '',
|
|
1012
|
+
allowoverride: '',
|
|
1013
|
+
allow_enable: false,
|
|
1014
|
+
deny_enable: false,
|
|
1015
|
+
autocreate: true
|
|
1016
|
+
};
|
|
1017
|
+
// directory operation
|
|
1018
|
+
$scope.detect_directory = function (d) {
|
|
1019
|
+
if (!d || d.length == 0) {
|
|
1020
|
+
return;
|
|
1021
|
+
}
|
|
1022
|
+
for (i in d) {
|
|
1023
|
+
var t = angular.copy(directory_tmpl);
|
|
1024
|
+
t.path = d[i].path || '';
|
|
1025
|
+
t.oldpath = d[i].path || '';
|
|
1026
|
+
t.indexes = d[i].indexes || '';
|
|
1027
|
+
t.followsymlinks = d[i].followsymlinks || '';
|
|
1028
|
+
t.execcgi = d[i].execcgi || '';
|
|
1029
|
+
t.allowoverride = d[i].allowoverride || '';
|
|
1030
|
+
t.allow_enable = d[i].allow_enable || false,
|
|
1031
|
+
t.deny_enable= d[i].deny_enable || false,
|
|
1032
|
+
t.order = d[i].order || '';
|
|
1033
|
+
if (d[i].allow) {
|
|
1034
|
+
for (j in d[i].allow) {
|
|
1035
|
+
t.allow += d[i].allow[j] + '\n'
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
if (d[i].deny) {
|
|
1039
|
+
for (j in d[i].deny) {
|
|
1040
|
+
t.deny += d[i].deny[j] + '\n'
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
$scope.setting.directory.push(t);
|
|
1044
|
+
}
|
|
1045
|
+
$scope.curdir_index = 0;
|
|
1046
|
+
};
|
|
1047
|
+
$scope.del_directory = function (i) {
|
|
1048
|
+
$scope.setting.directory.splice(i, 1);
|
|
1049
|
+
$scope.curdir_index--;
|
|
1050
|
+
if ($scope.curdir_index < 0 && $scope.setting.directory.length > 0) $scope.curdir_index = 0;
|
|
1051
|
+
};
|
|
1052
|
+
$scope.add_directory = function () {
|
|
1053
|
+
var drct = angular.copy(directory_tmpl);
|
|
1054
|
+
if ($scope.setting.documentroot) {
|
|
1055
|
+
drct.path = $scope.setting.documentroot;
|
|
1056
|
+
}
|
|
1057
|
+
$scope.setting.directory.splice($scope.curdir_index + 1, 0, drct);
|
|
1058
|
+
$scope.curdir_index++;
|
|
1059
|
+
};
|
|
1060
|
+
$scope.drct_change = function (drct) {
|
|
1061
|
+
if (!$scope.loaded) {
|
|
1062
|
+
return;
|
|
1063
|
+
}
|
|
1064
|
+
if (drct.path.length == 0) {
|
|
1065
|
+
drct.path = '/';
|
|
1066
|
+
}
|
|
1067
|
+
};
|
|
1068
|
+
$scope.$watch('setting.servername', function (newValue, oldValue) {
|
|
1069
|
+
if (!$scope.loaded) {
|
|
1070
|
+
return;
|
|
1071
|
+
}
|
|
1072
|
+
oldValue = typeof oldValue == 'undefined' ? '' : oldValue;
|
|
1073
|
+
if (newValue) {
|
|
1074
|
+
if ($scope.setting.documentroot == '' || $scope.setting.documentroot == server_tmpl.documentroot + '/' + oldValue || $scope.setting.documentroot == server_tmpl.documentroot + oldValue) {
|
|
1075
|
+
$scope.setting.documentroot = server_tmpl.documentroot + '/' + newValue;
|
|
1076
|
+
}
|
|
1077
|
+
if ($scope.setting.customlog == '' || $scope.setting.customlog == 'logs/' + oldValue + '-access_log common') {
|
|
1078
|
+
$scope.setting.customlog = 'logs/' +newValue + '-access_log common';
|
|
1079
|
+
}
|
|
1080
|
+
if ($scope.setting.errorlog == '' || $scope.setting.errorlog == 'logs/' +oldValue + '-error_log') {
|
|
1081
|
+
$scope.setting.errorlog = 'logs/' +newValue + '-error_log';
|
|
1082
|
+
}
|
|
1083
|
+
} else {
|
|
1084
|
+
if ($scope.setting.documentroot == server_tmpl.documentroot + '/' + oldValue) {
|
|
1085
|
+
$scope.setting.documentroot = server_tmpl.documentroot
|
|
1086
|
+
}
|
|
1087
|
+
if ($scope.setting.customlog == 'logs/' +oldValue + '-access_log common') {
|
|
1088
|
+
$scope.setting.customlog = ''
|
|
1089
|
+
}
|
|
1090
|
+
if ($scope.setting.errorlog == 'logs/' +oldValue + '-error_log') {
|
|
1091
|
+
$scope.setting.errorlog = ''
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
});
|
|
1095
|
+
$scope.$watch('setting.documentroot', function (newValue, oldValue) {
|
|
1096
|
+
if (!$scope.loaded) {
|
|
1097
|
+
return;
|
|
1098
|
+
}
|
|
1099
|
+
var d = $scope.setting.directory;
|
|
1100
|
+
if (d.length > 0) {
|
|
1101
|
+
if (newValue) {
|
|
1102
|
+
if (d[0].path == '' || d[0].path == oldValue) {
|
|
1103
|
+
$scope.setting.directory[0].path = newValue;
|
|
1104
|
+
}
|
|
1105
|
+
} else {
|
|
1106
|
+
if (d[0].path == oldValue) {
|
|
1107
|
+
$scope.del_directory(0);
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
} else if ($scope.action == 'new') {
|
|
1111
|
+
$scope.add_directory();
|
|
1112
|
+
}
|
|
1113
|
+
});
|
|
1114
|
+
|
|
1115
|
+
// site documentroot selector
|
|
1116
|
+
$scope.select_document_root = function () {
|
|
1117
|
+
$scope.selector_title = '请选择站点目录';
|
|
1118
|
+
$scope.selector.onlydir = true;
|
|
1119
|
+
$scope.selector.onlyfile = false;
|
|
1120
|
+
$scope.selector.load(server_tmpl.documentroot);
|
|
1121
|
+
$scope.selector.selecthandler = function (path) {
|
|
1122
|
+
$('#selector').modal('hide');
|
|
1123
|
+
$scope.setting.documentroot = path;
|
|
1124
|
+
};
|
|
1125
|
+
$('#selector').modal();
|
|
1126
|
+
};
|
|
1127
|
+
// ssl selector
|
|
1128
|
+
$scope.selectsslcrt = function (i) {
|
|
1129
|
+
$scope.selector_title = '请选择CRT文件(*.crt)';
|
|
1130
|
+
$scope.selector.onlydir = false;
|
|
1131
|
+
$scope.selector.onlyfile = true;
|
|
1132
|
+
$scope.selector.load('/root');
|
|
1133
|
+
$scope.selector.selecthandler = function (path) {
|
|
1134
|
+
$('#selector').modal('hide');
|
|
1135
|
+
$scope.setting.ssl_crt = path;
|
|
1136
|
+
};
|
|
1137
|
+
$('#selector').modal();
|
|
1138
|
+
};
|
|
1139
|
+
$scope.selectsslkey = function (i) {
|
|
1140
|
+
$scope.selector_title = '请选择密钥文件(*.key)';
|
|
1141
|
+
$scope.selector.onlydir = false;
|
|
1142
|
+
$scope.selector.onlyfile = true;
|
|
1143
|
+
$scope.selector.load('/root');
|
|
1144
|
+
$scope.selector.selecthandler = function (path) {
|
|
1145
|
+
$('#selector').modal('hide');
|
|
1146
|
+
$scope.setting.ssl_key = path;
|
|
1147
|
+
};
|
|
1148
|
+
$('#selector').modal();
|
|
1149
|
+
};
|
|
1150
|
+
|
|
1151
|
+
// submit
|
|
1152
|
+
$scope.submit = function (active) {
|
|
1153
|
+
var setting = angular.copy($scope.setting);
|
|
1154
|
+
for (i in setting.directory) {
|
|
1155
|
+
if (setting.directory[i].allow) {
|
|
1156
|
+
setting.directory[i].allow = setting.directory[i].allow.split(/[(\r\n)\r\n]+/);
|
|
1157
|
+
}
|
|
1158
|
+
if (setting.directory[i].deny) {
|
|
1159
|
+
setting.directory[i].deny = setting.directory[i].deny.split(/[(\r\n)\r\n]+/);
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1162
|
+
if (setting.serveralias) {
|
|
1163
|
+
// setting.serveralias = setting.serveralias.map(function (item) {
|
|
1164
|
+
// return item.name;
|
|
1165
|
+
// })
|
|
1166
|
+
alias = []
|
|
1167
|
+
for (i in setting.serveralias) {
|
|
1168
|
+
if (setting.serveralias[i]['name']) {
|
|
1169
|
+
alias.push(setting.serveralias[i]['name']);
|
|
1170
|
+
}
|
|
1171
|
+
}
|
|
1172
|
+
setting.serveralias = alias;
|
|
1173
|
+
}
|
|
1174
|
+
setting = angular.toJson(setting);
|
|
1175
|
+
if ($scope.action == 'new') {
|
|
1176
|
+
$scope.addserver(active, setting);
|
|
1177
|
+
} else if ($scope.action == 'edit') {
|
|
1178
|
+
$scope.updateserver(active, setting);
|
|
1179
|
+
}
|
|
1180
|
+
};
|
|
1181
|
+
$scope.addserver = function (active, setting) {
|
|
1182
|
+
Request.post('/api/operation/apache', {
|
|
1183
|
+
'action': 'addserver',
|
|
1184
|
+
'version': $scope.apache_version,
|
|
1185
|
+
'setting': setting
|
|
1186
|
+
}, function (res) {
|
|
1187
|
+
if (res.code == 0) {
|
|
1188
|
+
$scope.loaded = false;
|
|
1189
|
+
var name = ($scope.setting.ip ? $scope.setting.ip : '*') + '_' + $scope.setting.port + '_' + $scope.setting.servername;
|
|
1190
|
+
$location.path('/site/apache/edit_' + name);
|
|
1191
|
+
if (active && active == 'active') {
|
|
1192
|
+
$scope.apache_set_status('restart');
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
1195
|
+
});
|
|
1196
|
+
};
|
|
1197
|
+
$scope.updateserver = function (active, setting) {
|
|
1198
|
+
Request.post('/api/operation/apache', {
|
|
1199
|
+
'action': 'updateserver',
|
|
1200
|
+
'ip': server_ip,
|
|
1201
|
+
'port': server_port,
|
|
1202
|
+
'name': server_name,
|
|
1203
|
+
'version': $scope.apache_version,
|
|
1204
|
+
'setting': setting
|
|
1205
|
+
}, function (res) {
|
|
1206
|
+
if (res.code == 0) {
|
|
1207
|
+
$scope.loaded = false;
|
|
1208
|
+
var name = ($scope.setting.ip ? $scope.setting.ip : '*') + '_' + $scope.setting.port + '_' + $scope.setting.servername;
|
|
1209
|
+
var new_path = '/site/apache/edit_' + name;
|
|
1210
|
+
if (new_path != $location.path()) {
|
|
1211
|
+
$location.path(new_path);
|
|
1212
|
+
} else {
|
|
1213
|
+
$scope.restore();
|
|
1214
|
+
if (active && active == 'active') {
|
|
1215
|
+
$scope.apache_set_status('restart');
|
|
1216
|
+
}
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
});
|
|
1220
|
+
};
|
|
1221
|
+
$scope.restore = function () {
|
|
1222
|
+
$scope.setting = angular.copy(server_tmpl);
|
|
1223
|
+
if ($scope.action == 'edit') {
|
|
1224
|
+
$scope.getserver();
|
|
1225
|
+
}
|
|
1226
|
+
};
|
|
1227
|
+
$scope.apache_set_status = function (status) {
|
|
1228
|
+
if (!status || ['start', 'stop', 'restart'].indexOf(status) < 0) {
|
|
1229
|
+
return;
|
|
1230
|
+
}
|
|
1231
|
+
Backend.call($scope, module, '/api/backend/service_' + status, '/api/backend/service_' + status + '_httpd', {
|
|
1232
|
+
'name': 'Apache',
|
|
1233
|
+
'service': 'httpd'
|
|
1234
|
+
}, {
|
|
1235
|
+
'success': function (res) {
|
|
1236
|
+
Message.setInfo(res.msg);
|
|
1237
|
+
}
|
|
1238
|
+
}, true);
|
|
1239
|
+
};
|
|
1240
|
+
}
|
|
1241
|
+
];
|