SystemController.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. "use strict";
  2. var Controller = require('./../framework/Controller.js');
  3. var process = require('child_process');
  4. var php = require('phpjs');
  5. var $white_ip_array = ['183.60.177.224/27','58.248.138.0/28', '113.108.232.32/28', '172.16.53.148/8'];
  6. class SystemController extends Controller {
  7. check_ip(ip_array) {
  8. var remote_ip = getClientIp();
  9. return checkIpRange(remote_ip, $white_ip_array);
  10. }
  11. /**
  12. * 安装依赖的组件
  13. */
  14. actionNpmInstall() {
  15. var that = this;
  16. //不在ip白名单内,显示404页面
  17. if( !that.check_ip($white_ip_array) ){
  18. that._res.statusCode = 302;
  19. that._res.header('Location', '/public/403.html');
  20. that.exitMsg('...');
  21. } else {
  22. process.exec('npm install &', function(err, stdout, stderr) {
  23. if (err) {
  24. that.exitMsg('出错啦...【' + err + '】')
  25. } else {
  26. that.exitMsg('执行完毕:' + stdout);
  27. }
  28. });
  29. }
  30. }
  31. /**
  32. * 重启服务
  33. */
  34. actionRestart() {
  35. var that = this;
  36. //不在ip白名单内,显示404页面
  37. if( !that.check_ip($white_ip_array) ){
  38. that._res.statusCode = 302;
  39. that._res.header('Location', '/public/403.html');
  40. that.exitMsg('...');
  41. } else {
  42. process.exec('/bin/bash ./admin/restart.sh &');
  43. that.exitMsg('restart');
  44. }
  45. }
  46. }
  47. module.exports = SystemController;