SystemController.js 1.6 KB

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