system.js 15 KB

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