indexController.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. class indexController extends Controller
  3. {
  4. public $initphp_list = array(
  5. 'cron',
  6. 'testMail',
  7. 'test',
  8. 'ssh',
  9. 'ping'
  10. );
  11. public function run()
  12. {
  13. $this->view->set_tpl("index/index"); // 中间的模板
  14. $config = InitPHP::getConfig();
  15. $title = $config['sitename'];
  16. $this->view->assign("title", $title);
  17. $this->view->display();
  18. }
  19. function ping()
  20. {
  21. $domain = $this->controller->get_gp("node");
  22. $domain=$this->controller->get_gp('node');
  23. $result=file_get_contents("http://www.phplife.net/ping.php?node=".$domain);
  24. echo $result;
  25. }
  26. public function cron()
  27. {
  28. $user = InitPHP::getService("user");
  29. if ($user->resetTran()) {
  30. echo "OK";
  31. }
  32. }
  33. public function ssh()
  34. {
  35. global $argv;
  36. $server = $this->getServer();
  37. $data = $server->getAll();
  38. $cmd = $argv[3];
  39. $ip = $argv[4];
  40. foreach ($data as $k => $v) {
  41. if ($ip && $v['server'] != $ip) {
  42. continue;
  43. }
  44. echo $v['server'] . "\tresponse:\n";
  45. $ssh = $this->getssh();
  46. $status = $ssh->login($v['server'], $v['port'], 'root', $v['passwd']);
  47. if (!$status) {
  48. echo $v['server'] . ' connect fail!';
  49. continue;
  50. }
  51. $str = $ssh->exec($cmd);
  52. echo $str . "\r\n\r\n\r\n";
  53. $ssh->close();
  54. }
  55. }
  56. /**
  57. *
  58. * @return sshInit
  59. */
  60. private function getssh()
  61. {
  62. return InitPHP::getLibrarys("ssh");
  63. }
  64. /**
  65. *
  66. * @return sshDao
  67. */
  68. private function getServer()
  69. {
  70. return InitPHP::getDao("ssh");
  71. }
  72. public function test()
  73. {
  74. $userService = InitPHP::getService("user");
  75. $data = $userService->getUsers();
  76. $sh = "";
  77. if ($data) {
  78. foreach ($data as $k => $v) {
  79. $sh .= $v['port'] . "#" . $v['passwd'] . "#" . $v['transfer_enable'] . "@";
  80. }
  81. }
  82. file_put_contents("1.txt", $sh);
  83. echo $sh;
  84. // dump($data);
  85. }
  86. private function getGb($data)
  87. {
  88. }
  89. public function testMail()
  90. {
  91. // InitPHP::url("index");
  92. // $email = $this->getEmail();
  93. $subject = '测试邮件';
  94. $message = '这是一封测试邮件!';
  95. $user='webmaster@tailsocks.com';
  96. sendmail('chen6485882@gmail.com', $subject, $message, $user);
  97. // $email->config($relay_host, $mailConfig['port'], $auth = true, $user, $pass);
  98. // var_dump($Config);
  99. // $email->sendmail("chendeben@qq.com", $mailConfig['from'], $subject = "测试邮件", "这是一封测试邮件哈", "HTML");
  100. }
  101. /**
  102. * @return emailInit
  103. */
  104. public function getEmail()
  105. {
  106. return InitPHP::getLibrarys("email");
  107. }
  108. }