system.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  1. myApp.controller("file", ["$scope", "$http", function ($scope, $http) {
  2. }]);
  3. myApp.controller("task", ["$scope", "$http", function ($scope, $http) {
  4. }]);
  5. myApp.controller("dashboard", ["$scope", function ($scope) {
  6. }]);
  7. myApp.controller("system", ["$scope", "$http", function($scope, $http) {
  8. $scope.request("/system/getsettings", null, function(data) {
  9. var settings = {};
  10. Enumerable.From(data.Data).Select(e => {
  11. return {
  12. name: e.Name,
  13. value: e.Value
  14. }
  15. }).Distinct().ToArray().map(function(item, index, array) {
  16. settings[item.name] = item.value;
  17. });
  18. $scope.Settings = settings;
  19. });
  20. $scope.uploadImage = function() {
  21. $("#setImageForm").ajaxSubmit({
  22. url: "/Upload",
  23. type: "post",
  24. success: function(data) {
  25. document.getElementById("setImageForm").reset();
  26. $scope.$apply(function () {
  27.  $scope.Settings[$scope.property] = data.Data;
  28. });
  29. layer.closeAll();
  30. }
  31. });
  32. };
  33. $scope.setImage = function(property) {
  34. layer.open({
  35. type: 1,
  36. zIndex: 20,
  37. title: '请选择一张图片',
  38. area: '420px', //宽高
  39. content: $("#setImageForm"),
  40. cancel: function(index, layero) {
  41. return true;
  42. }
  43. });
  44. $scope.property=property;
  45. }
  46. $scope.save = function() {
  47. swal({
  48. title: '确认保存吗?',
  49. showCloseButton: true,
  50. confirmButtonColor: "#DD6B55",
  51. confirmButtonText: "确定",
  52. cancelButtonText: "取消",
  53. showLoaderOnConfirm: true,
  54. animation: true,
  55. allowOutsideClick: false,
  56. preConfirm: function() {
  57. return new Promise(function(resolve, reject) {
  58. var result = [];
  59. for (var key in $scope.Settings) {
  60. if ($scope.Settings.hasOwnProperty(key)) {
  61. result.push({
  62. Name: key,
  63. Value: $scope.Settings[key]
  64. });
  65. }
  66. }
  67. $http.post("/system/save", {
  68. sets: JSON.stringify(result)
  69. }, {
  70. 'Content-Type': 'application/x-www-form-urlencoded'
  71. }).then(function(res) {
  72. resolve(res.data);
  73. }, function() {
  74. reject("请求服务器失败!");
  75. });
  76. });
  77. }
  78. }).then(function(data) {
  79. swal({
  80. type: data.Success ? "success" : "error",
  81. text: data.Message
  82. });
  83. }).catch(swal.noop);
  84. }
  85. $scope.mailtest= function() {
  86. $http.post("/system/mailtest", {
  87. smtp: $scope.Settings.SMTP,
  88. user: $scope.Settings.EmailFrom,
  89. pwd: $scope.Settings.EmailPwd,
  90. port: $scope.Settings.SmtpPort,
  91. to: $scope.Settings.ReceiveEmail,
  92. ssl:$scope.Settings.EnableSsl
  93. }).then(function(res) {
  94. if (res.data.Success) {
  95. swal(res.data.Message,'','success');
  96. } else {
  97. swal({
  98. input: 'textarea',
  99. showCloseButton: true,
  100. width: 800,
  101. confirmButtonColor: "#DD6B55",
  102. confirmButtonText: "确定",
  103. inputValue: res.data.Message,
  104. inputClass: "height700"
  105. });
  106. }
  107. }, function() {
  108. swal('服务请求失败','','error');
  109. }).catch(swal.noop);
  110. }
  111. $scope.pathtest = function() {
  112. $http.post("/system/pathtest", {
  113. path: $scope.Settings.PathRoot
  114. }).then(function(res) {
  115. if (res.data.Success) {
  116. swal(res.data.Message,'','success');
  117. } else {
  118. swal({
  119. input: 'textarea',
  120. showCloseButton: true,
  121. width: 800,
  122. confirmButtonColor: "#DD6B55",
  123. confirmButtonText: "确定",
  124. inputValue: res.data.Message,
  125. inputClass: "height700"
  126. });
  127. }
  128. }, function() {
  129. swal('服务请求失败','','error');
  130. }).catch(swal.noop);
  131. }
  132. $scope.EmailEnableSsl= function() {
  133. if($scope.Settings.EnableSsl=="true") {
  134. $scope.Settings.EnableSsl="false";
  135. } else {
  136. $scope.Settings.EnableSsl="true";
  137. }
  138. }
  139. $scope.EnableDonate= function() {
  140. if($scope.Settings.EnableDonate=="true") {
  141. $scope.Settings.EnableDonate="false";
  142. } else {
  143. $scope.Settings.EnableDonate="true";
  144. }
  145. }
  146. $scope.CloseSite= function() {
  147. if($scope.Settings.CloseSite=="true") {
  148. $scope.Settings.CloseSite="false";
  149. } else {
  150. swal({
  151. title: '确定要关闭站点么?',
  152. text: "一旦关闭,所有前台功能将不再可用!所有前台访问将会被重定向到:/ComingSoon",
  153. showCancelButton: true,
  154. confirmButtonColor: '#3085d6',
  155. cancelButtonColor: '#d33',
  156. confirmButtonText: '确定',
  157. cancelButtonText: '取消',
  158. }).then(function(isConfirm) {
  159. if (isConfirm) {
  160. $scope.Settings.CloseSite = "true";
  161. $scope.$apply();
  162. }
  163. });
  164. }
  165. }
  166. $scope.DataReadonly= function() {
  167. if($scope.Settings.DataReadonly=="true") {
  168. $scope.Settings.DataReadonly="false";
  169. } else {
  170. swal({
  171. title: '确定要开启站点写保护么?',
  172. text: "一旦开启,前台所有表单数据将无法被提交!",
  173. showCancelButton: true,
  174. confirmButtonColor: '#3085d6',
  175. cancelButtonColor: '#d33',
  176. confirmButtonText: '确定',
  177. cancelButtonText: '取消',
  178. }).then(function(isConfirm) {
  179. if (isConfirm) {
  180. $scope.Settings.DataReadonly = "true";
  181. $scope.$apply();
  182. }
  183. });
  184. }
  185. }
  186. }]);
  187. myApp.controller("log", ["$scope", function ($scope) {
  188. $scope.getfiles= function() {
  189. $scope.request("/dashboard/GetLogfiles", null, function(data) {
  190. $scope.files = data.Data;
  191. });
  192. }
  193. $scope.getfiles();
  194. $scope.view= function(file) {
  195. $scope.request("/dashboard/catlog", { filename: file }, function (data) {
  196. swal({
  197. input: 'textarea',
  198. showCloseButton: true,
  199. width: 1000,
  200. confirmButtonColor: "#DD6B55",
  201. confirmButtonText: "确定",
  202. inputValue: data.Data,
  203. inputClass:"height700"
  204. });
  205. });
  206. }
  207. $scope.delete= function(file) {
  208. swal({
  209. title: '确定删除吗?',
  210. showCancelButton: true,
  211. showCloseButton: true,
  212. confirmButtonColor: '#3085d6',
  213. cancelButtonColor: '#d33',
  214. confirmButtonText: '确定',
  215. cancelButtonText: '取消',
  216. preConfirm: function() {
  217. return new Promise(function (resolve) {
  218. $scope.request("/dashboard/deletefile", { filename: file }, function (res) {
  219. $scope.getfiles();
  220. resolve(res.Message);
  221. });
  222. });
  223. }
  224. }).then(function (msg) {
  225. swal(
  226. msg,
  227. '',
  228. 'success'
  229. );
  230. }).catch(swal.noop);
  231. }
  232. }]);
  233. myApp.controller("email", ["$scope", "$http", function ($scope) {
  234. $scope.getfiles = function () {
  235. $scope.request("/file/Getfiles", {path:"/template"}, function (data) {
  236. $scope.files = data.Data;
  237. });
  238. }
  239. $scope.getfiles();
  240. $scope.view = function (file) {
  241. $scope.request("/file/read", { filename: file }, function (data) {
  242. swal({
  243. input: 'textarea',
  244. showCloseButton: true,
  245. width: 1000,
  246. showCancelButton: true,
  247. confirmButtonColor: '#3085d6',
  248. cancelButtonColor: '#d33',
  249. confirmButtonText: '确定',
  250. cancelButtonText: '取消',
  251. inputValue: data.Data,
  252. inputClass: "height700",
  253. preConfirm: function (value) {
  254. return new Promise(function (resolve, reject) {
  255. if (value) {
  256. $scope.request("/file/save", { filename: file, content: value }, function (res) {
  257. if (res.Success) {
  258. resolve(res.Message);
  259. } else {
  260. reject(res.Message);
  261. }
  262. });
  263. } else {
  264. reject('请输入内容');
  265. }
  266. });
  267. }
  268. }).then(function (msg) {
  269. swal(
  270. msg,
  271. '',
  272. 'success'
  273. );
  274. }).catch(swal.noop);
  275. });
  276. }
  277. }]);
  278. myApp.controller("firewall", ["$scope", "$http","NgTableParams","$timeout", function ($scope, $http,NgTableParams,$timeout) {
  279. var self = this;
  280. self.data = {};
  281. $scope.request("/system/getsettings", null, function(data) {
  282. var settings = {};
  283. Enumerable.From(data.Data).Select(e => {
  284. return {
  285. name: e.Name,
  286. value: e.Value
  287. }
  288. }).Distinct().ToArray().map(function(item, index, array) {
  289. settings[item.name] = item.value;
  290. });
  291. $scope.Settings = settings;
  292. });
  293. this.load = function() {
  294. $scope.request("/system/InterceptLog", null, function(res) {
  295. self.tableParams = new NgTableParams({}, {
  296. filterDelay: 0,
  297. dataset: res.Data.list
  298. });
  299. $scope.logs=res.Data.list;
  300. $scope.interceptCount=res.Data.interceptCount;
  301. $scope.ranking=res.Data.ranking;
  302. });
  303. }
  304. self.load();
  305. this.clear= function() {
  306. swal({
  307. title: '确定清空拦截日志吗?',
  308. showCancelButton: true,
  309. showCloseButton: true,
  310. confirmButtonColor: '#3085d6',
  311. cancelButtonColor: '#d33',
  312. confirmButtonText: '确定',
  313. cancelButtonText: '取消',
  314. preConfirm: function() {
  315. return new Promise(function (resolve) {
  316. $scope.request("/system/ClearInterceptLog", null, function (res) {
  317. resolve(res.Message);
  318. });
  319. });
  320. }
  321. }).then(function (msg) {
  322. swal(msg,'','success');
  323. self.load();
  324. }).catch(swal.noop);
  325. }
  326. $scope.EnableFirewall= function() {
  327. if($scope.Settings.FirewallEnabled=="true") {
  328. swal({
  329. title: '确定要关闭网站防火墙么?',
  330. text: "一旦关闭,网站将面临可能会被流量攻击的风险!",
  331. showCancelButton: true,
  332. confirmButtonColor: '#3085d6',
  333. cancelButtonColor: '#d33',
  334. confirmButtonText: '确定',
  335. cancelButtonText: '取消',
  336. }).then(function(isConfirm) {
  337. if (isConfirm) {
  338. $scope.Settings.FirewallEnabled="false";
  339. $scope.$apply();
  340. }
  341. });
  342. } else {
  343. $scope.Settings.FirewallEnabled="true";
  344. }
  345. }
  346. $scope.getIPBlackList= function() {
  347. $scope.request("/system/IpBlackList",null, function (data) {
  348. swal({
  349. title:"编辑全局IP黑名单",
  350. text:"多个IP之间用英文逗号分隔",
  351. input: 'textarea',
  352. showCloseButton: true,
  353. width: 1000,
  354. confirmButtonColor: "#DD6B55",
  355. confirmButtonText: "确定",
  356. cancelButtonText: "取消",
  357. inputValue: data.Data,
  358. inputClass:"height700",
  359. showLoaderOnConfirm: true,
  360. preConfirm: function(value) {
  361. return new Promise(function (resolve) {
  362. $scope.request("/system/SetIpBlackList", { content: value }, function (res) {
  363. resolve(res.Message);
  364. });
  365. });
  366. }
  367. }).then(function (msg) {
  368. swal("更新成功",'','success');
  369. }).catch(swal.noop);
  370. });
  371. }
  372. $scope.getIPWhiteList= function() {
  373. $scope.request("/system/IpWhiteList",null, function (data) {
  374. swal({
  375. title:"编辑全局IP白名单",
  376. text:"多个IP之间用英文逗号分隔",
  377. input: 'textarea',
  378. showCloseButton: true,
  379. width: 1000,
  380. confirmButtonColor: "#DD6B55",
  381. confirmButtonText: "确定",
  382. cancelButtonText: "取消",
  383. inputValue: data.Data,
  384. inputClass:"height700",
  385. showLoaderOnConfirm: true,
  386. preConfirm: function(value) {
  387. return new Promise(function (resolve) {
  388. $scope.request("/system/SetIpWhiteList", { content: value }, function (res) {
  389. resolve(res.Message);
  390. });
  391. });
  392. }
  393. }).then(function (msg) {
  394. swal("更新成功",'','success');
  395. }).catch(swal.noop);
  396. });
  397. }
  398. $scope.getIPRangeBlackList= function() {
  399. $scope.request("/system/GetIPRangeBlackList",null, function (data) {
  400. swal({
  401. title:"编辑IP地址段黑名单",
  402. text:"每行一条地址段,起始地址和结束地址用空格分隔开,其余信息也用空格分隔开",
  403. input: 'textarea',
  404. showCloseButton: true,
  405. width: 1000,
  406. confirmButtonColor: "#DD6B55",
  407. confirmButtonText: "确定",
  408. cancelButtonText: "取消",
  409. inputValue: data.Data,
  410. inputClass:"height700",
  411. showLoaderOnConfirm: true,
  412. preConfirm: function(value) {
  413. return new Promise(function (resolve) {
  414. $scope.request("/system/SetIPRangeBlackList", { content: value }, function (res) {
  415. resolve(res.Message);
  416. });
  417. });
  418. }
  419. }).then(function (msg) {
  420. swal("更新成功",'','success');
  421. }).catch(swal.noop);
  422. });
  423. }
  424. $scope.save = function() {
  425. swal({
  426. title: '确认保存吗?',
  427. showCloseButton: true,
  428. confirmButtonColor: "#DD6B55",
  429. confirmButtonText: "确定",
  430. cancelButtonText: "取消",
  431. showLoaderOnConfirm: true,
  432. animation: true,
  433. allowOutsideClick: false,
  434. preConfirm: function() {
  435. return new Promise(function(resolve, reject) {
  436. var result = [];
  437. for (var key in $scope.Settings) {
  438. if ($scope.Settings.hasOwnProperty(key)) {
  439. result.push({
  440. Name: key,
  441. Value: $scope.Settings[key]
  442. });
  443. }
  444. }
  445. $http.post("/system/save", {
  446. sets: JSON.stringify(result)
  447. }, {
  448. 'Content-Type': 'application/x-www-form-urlencoded'
  449. }).then(function(res) {
  450. resolve(res.data);
  451. }, function() {
  452. reject("请求服务器失败!");
  453. });
  454. });
  455. }
  456. }).then(function(data) {
  457. swal({
  458. type: data.Success ? "success" : "error",
  459. text: data.Message
  460. });
  461. }).catch(swal.noop);
  462. }
  463. $scope.detail= function(text) {
  464. layer.open({
  465. type: 1,
  466. area: ['600px', '80%'], //宽高
  467. content: text
  468. });
  469. $('.layui-layer-content').jsonViewer(eval("("+text+")"), {withQuotes: true, withLinks: true});
  470. $('.layui-layer-content').css("word-wrap"," break-word");
  471. }
  472. $scope.distinct=false;
  473. $scope.duplicate= function() {
  474. $scope.distinct=!$scope.distinct;
  475. if ($scope.distinct) {
  476. const res = new Map();
  477. self.tableParams = new NgTableParams({}, {
  478. filterDelay: 0,
  479. dataset: angular.copy($scope.logs).filter(item => !res.has(item["IP"]) && res.set(item["IP"], 1))
  480. });
  481. } else {
  482. self.tableParams = new NgTableParams({}, {
  483. filterDelay: 0,
  484. dataset: $scope.logs
  485. });
  486. }
  487. }
  488. }]);
  489. myApp.controller("sendbox", ["$scope", "$http", function ($scope, $http) {
  490. UEDITOR_CONFIG.autoHeightEnabled=false;
  491. $scope.load= function() {
  492. $http.post("/system/sendbox").then(function (res) {
  493. $scope.Mails = res.data;
  494. });
  495. };
  496. $scope.newmail= function() {
  497. layer.open({
  498. type: 1,
  499. zIndex: 8,
  500. title: '发送邮件',
  501. area: (window.screen.width > 800 ? 800 : window.screen.width) + 'px',
  502. content: $("#modal"),
  503. end: function() {
  504. $("#modal").css("display", "none");
  505. }
  506. });
  507. }
  508. $scope.send= function(mail) {
  509. $http.post("/system/sendmail",mail, {
  510. 'Content-Type':'application/x-www-form-urlencoded'
  511. }).then(function (res) {
  512. if (res.data) {
  513. layer.alert(res.data.Message);
  514. } else {
  515. layer.msg('发送成功');
  516. layer.closeAll();
  517. setTimeout(function() {
  518. $("#modal").css("display", "none");
  519. $scope.load();
  520. }, 500);
  521. }
  522. });
  523. }
  524. $scope.load();
  525. }]);