release_point.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. defined('IN_PHPCMS') or exit('No permission resources.');
  3. pc_base::load_app_class('admin','admin',0);
  4. class release_point extends admin {
  5. private $db;
  6. public $ssl = 0;
  7. public function __construct() {
  8. parent::__construct();
  9. $this->db = pc_base::load_model('release_point_model');
  10. if (function_exists('ftp_ssl_connect')) {
  11. $this->ssl = 1;
  12. }
  13. }
  14. public function init() {
  15. $list = $this->db->select();
  16. $big_menu = array('javascript:window.top.art.dialog({id:\'add\',iframe:\'?m=admin&c=release_point&a=add\', title:\''.L('release_point_add').'\', width:\'700\', height:\'500\', lock:true}, function(){var d = window.top.art.dialog({id:\'add\'}).data.iframe;var form = d.document.getElementById(\'dosubmit\');form.click();return false;}, function(){window.top.art.dialog({id:\'add\'}).close()});void(0);', L('release_point_add'));
  17. include $this->admin_tpl('release_point_list');
  18. }
  19. public function add() {
  20. if (isset($_POST['dosubmit'])) {
  21. $name = isset($_POST['name']) && trim($_POST['name']) ? trim($_POST['name']) : showmessage(L('release_point_name').L('empty'));
  22. $host = isset($_POST['host']) && trim($_POST['host']) ? trim($_POST['host']) : showmessage(L('server_address').L('empty'));
  23. $port = isset($_POST['port']) && intval($_POST['port']) ? intval($_POST['port']) : showmessage(L('server_port').L('empty'));
  24. $username = isset($_POST['username']) && trim($_POST['username']) ? trim($_POST['username']) : showmessage(L('username').L('empty'));
  25. $password = isset($_POST['password']) && trim($_POST['password']) ? trim($_POST['password']) : showmessage(L('password').L('empty'));
  26. $path = isset($_POST['path']) && trim($_POST['path']) ? trim($_POST['path']) : showmessage(L('path').L('empty'));
  27. $pasv = isset($_POST['pasv']) && trim($_POST['pasv']) ? trim($_POST['pasv']) : 0;
  28. $ssl = isset($_POST['ssl']) && trim($_POST['ssl']) ? trim($_POST['ssl']) : 0;
  29. if ($this->db->get_one(array("name"=>$name))) {
  30. showmessage(L('release_point_name').L('exists'));
  31. }
  32. if ($this->db->insert(array('name'=>$name,'host'=>$host,'port'=>$port,'username'=>$username, 'password'=>$password, 'path'=>$path, 'pasv'=>$pasv, 'ssl'=>$ssl))) {
  33. showmessage(L('operation_success'), '', '', 'add');
  34. } else {
  35. showmessage(L('operation_failure'));
  36. }
  37. }
  38. $show_header = $show_validator = true;
  39. include $this->admin_tpl('release_point_add');
  40. }
  41. public function edit() {
  42. $id = isset($_GET['id']) && intval($_GET['id']) ? intval($_GET['id']) : showmessage(L('illegal_parameters'), HTTP_REFERER);
  43. if ($data = $this->db->get_one(array('id'=>$id))) {
  44. if (isset($_POST['dosubmit'])) {
  45. $name = isset($_POST['name']) && trim($_POST['name']) ? trim($_POST['name']) : showmessage(L('release_point_name').L('empty'));
  46. $host = isset($_POST['host']) && trim($_POST['host']) ? trim($_POST['host']) : showmessage(L('server_address').L('empty'));
  47. $port = isset($_POST['port']) && intval($_POST['port']) ? intval($_POST['port']) : showmessage(L('server_port').L('empty'));
  48. $username = isset($_POST['username']) && trim($_POST['username']) ? trim($_POST['username']) : showmessage(L('username').L('empty'));
  49. $password = isset($_POST['password']) && trim($_POST['password']) ? trim($_POST['password']) : showmessage(L('password').L('empty'));
  50. $path = isset($_POST['path']) && trim($_POST['path']) ? trim($_POST['path']) : showmessage(L('path').L('empty'));
  51. $pasv = isset($_POST['pasv']) && trim($_POST['pasv']) ? trim($_POST['pasv']) : 0;
  52. $ssl = isset($_POST['ssl']) && trim($_POST['ssl']) ? trim($_POST['ssl']) : 0;
  53. if ($data['name'] != $name && $this->db->get_one(array("name"=>$name))) {
  54. showmessage(L('release_point_name').L('exists'));
  55. }
  56. if ($this->db->update(array('name'=>$name,'host'=>$host,'port'=>$port,'username'=>$username, 'password'=>$password, 'path'=>$path, 'pasv'=>$pasv, 'ssl'=>$ssl), array('id'=>$id))) {
  57. showmessage(L('operation_success'), '', '', 'edit');
  58. } else {
  59. showmessage(L('operation_failure'));
  60. }
  61. }
  62. $show_header = $show_validator = true;
  63. include $this->admin_tpl('release_point_edit');
  64. } else {
  65. showmessage(L('notfound'), HTTP_REFERER);
  66. }
  67. }
  68. public function public_name() {
  69. $name = isset($_GET['name']) && trim($_GET['name']) ? (pc_base::load_config('system', 'charset') == 'gbk' ? iconv('utf-8', 'gbk', trim($_GET['name'])) : trim($_GET['name'])) : exit('0');
  70. $id = isset($_GET['id']) && intval($_GET['id']) ? intval($_GET['id']) : '';
  71. $data = array();
  72. if ($id) {
  73. $data = $this->db->get_one(array('id'=>$id), 'name');
  74. if (!empty($data) && $data['name'] == $name) {
  75. exit('1');
  76. }
  77. }
  78. if ($this->db->get_one(array('name'=>$name), 'id')) {
  79. exit('0');
  80. } else {
  81. exit('1');
  82. }
  83. }
  84. public function del() {
  85. $id = isset($_GET['id']) && intval($_GET['id']) ? intval($_GET['id']) : showmessage(L('illegal_parameters'), HTTP_REFERER);
  86. if ($this->db->get_one(array('id'=>$id))) {
  87. if ($this->db->delete(array('id'=>$id))) {
  88. showmessage(L('operation_success'), HTTP_REFERER);
  89. } else {
  90. showmessage(L('operation_failure'), HTTP_REFERER);
  91. }
  92. } else {
  93. showmessage(L('notfound'), HTTP_REFERER);
  94. }
  95. }
  96. public function public_test_ftp() {
  97. $host = isset($_GET['host']) && trim($_GET['host']) ? trim($_GET['host']) : exit('0');
  98. $port = isset($_GET['port']) && intval($_GET['port']) ? intval($_GET['port']) : exit('0');
  99. $username = isset($_GET['username']) && trim($_GET['username']) ? trim($_GET['username']) : exit('0');
  100. $password = isset($_GET['password']) && trim($_GET['password']) ? trim($_GET['password']) : exit('0');
  101. $pasv = isset($_GET['pasv']) && trim($_GET['pasv']) ? trim($_GET['pasv']) : 0;
  102. $ssl = isset($_GET['ssl']) && trim($_GET['ssl']) ? trim($_GET['ssl']) : 0;
  103. $ftp = pc_base::load_sys_class('ftps');
  104. if ($ftp->connect($host, $username, $password, $port, $pasv, $ssl, 25)) {
  105. if ($ftp->link_time > 15) {
  106. exit(L('ftp_connection_a_long_time'));
  107. }
  108. exit('1');
  109. } else {
  110. exit(L('can_ftp_server_connections'));
  111. }
  112. }
  113. }