PageRenderTime 56ms CodeModel.GetById 34ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/ftp_management/hooks/filezilla.php

https://github.com/raiman264/zpanelx
PHP | 139 lines | 97 code | 7 blank | 35 comment | 11 complexity | 9d10fd877e018da876309a3afd885433 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-3.0, LGPL-2.1, CC-BY-SA-4.0, GPL-3.0
  1. <?php
  2. /**
  3. *
  4. * ZPanel - A Cross-Platform Open-Source Web Hosting Control panel.
  5. *
  6. * @package ZPanel
  7. * @version $Id$
  8. * @author Bobby Allen - ballen@bobbyallen.me
  9. * @copyright (c) 2008-2014 ZPanel Group - http://www.zpanelcp.com/
  10. * @license http://opensource.org/licenses/gpl-3.0.html GNU Public License v3
  11. *
  12. * This program (ZPanel) is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation, either version 3 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. *
  25. */
  26. foreach ($deletedclients as $deletedclient) {
  27. $sql = "SELECT * FROM x_ftpaccounts WHERE ft_acc_fk=:deleteClient AND ft_deleted_ts IS NULL";
  28. $info = $zdbh->prepare($sql);
  29. $info->bindParam(':deleteClient', $deletedclient);
  30. $info->execute();
  31. $result = $info->fetch();
  32. if ($result) {
  33. $sql = $zdbh->prepare("UPDATE x_ftpaccounts SET ft_deleted_ts=:time WHERE ft_acc_fk=:deleteClient");
  34. $sql->bindParam(':time', time());
  35. $sql->bindParam(':deleteClient', $deletedclient);
  36. $sql->execute();
  37. }
  38. }
  39. // Set some variables for filezilla from the x_ftp_settings database table...
  40. $ftp_reload = "\"" . ctrl_options::GetSystemOption('ftp_service_root') . ctrl_options::GetSystemOption('ftp_service') . "\" /reload-config";
  41. $ftpconfigfile = ctrl_options::GetSystemOption('ftp_config_file');
  42. $getftpconfigfile = file_get_contents($ftpconfigfile);
  43. $ftpsettings = '/<Settings>(.*)<\/Settings>/msU';
  44. // Included after acount has been created, deleted, or reset...
  45. $matchresult = preg_match_all($ftpsettings, $getftpconfigfile, $matches);
  46. if (!empty($matchresult)) {
  47. // First grab the filezilla setting so we can add it back in when we write the config file...
  48. $line = "<FileZillaServer>" . fs_filehandler::NewLine();
  49. $line .= $matches[0][0] . fs_filehandler::NewLine();
  50. $line .= "<Groups />" . fs_filehandler::NewLine();
  51. $line .= "<Users>" . fs_filehandler::NewLine();
  52. // Get a list of all the accounts...
  53. $sql = $zdbh->prepare("SELECT * FROM x_ftpaccounts WHERE ft_deleted_ts IS NULL ORDER BY ft_user_vc ASC");
  54. $sql->execute();
  55. while ($rowftpaccounts = $sql->fetch()) {
  56. $ftpuser = ctrl_users::GetUserDetail($rowftpaccounts['ft_acc_fk']);
  57. //Only add the user if they are not disabled...
  58. if ($ftpuser['enabled'] <> 0) {
  59. // begin user loop
  60. $line .= "<User Name=\"" . $rowftpaccounts['ft_user_vc'] . "\">" . fs_filehandler::NewLine();
  61. $line .= "<Option Name=\"Pass\">" . md5($rowftpaccounts['ft_password_vc']) . "</Option>" . fs_filehandler::NewLine();
  62. $line .= "<Option Name=\"Group\"/>" . fs_filehandler::NewLine();
  63. $line .= "<Option Name=\"Bypass server userlimit\">0</Option>" . fs_filehandler::NewLine();
  64. $line .= "<Option Name=\"User Limit\">0</Option>" . fs_filehandler::NewLine();
  65. $line .= "<Option Name=\"IP Limit\">0</Option>" . fs_filehandler::NewLine();
  66. $line .= "<Option Name=\"Enabled\">1</Option>" . fs_filehandler::NewLine();
  67. $line .= "<Option Name=\"Comments\">Auto account generated by ZPanel (v. " . ctrl_options::GetSystemOption('dbversion') . ")</Option>" . fs_filehandler::NewLine();
  68. $line .= "<Option Name=\"ForceSsl\">0</Option>" . fs_filehandler::NewLine();
  69. $line .= "<IpFilter>" . fs_filehandler::NewLine();
  70. $line .= "<Disallowed/>" . fs_filehandler::NewLine();
  71. $line .= "<Allowed/>" . fs_filehandler::NewLine();
  72. $line .= "</IpFilter>" . fs_filehandler::NewLine();
  73. $line .= "<Permissions>" . fs_filehandler::NewLine();
  74. $line .= "<Permission Dir=\"" . ctrl_options::GetSystemOption('hosted_dir') . $ftpuser['username'] . $rowftpaccounts['ft_directory_vc'] . "\">" . fs_filehandler::NewLine();
  75. // If read only...
  76. $accessmode = "Read List";
  77. if ($rowftpaccounts['ft_access_vc'] == 'RO') {
  78. $permissionset = "<Option Name=\"FileRead\">1</Option>" . fs_filehandler::NewLine();
  79. $permissionset .= "<Option Name=\"FileWrite\">0</Option>" . fs_filehandler::NewLine();
  80. $permissionset .= "<Option Name=\"FileDelete\">0</Option>" . fs_filehandler::NewLine();
  81. $permissionset .= "<Option Name=\"FileAppend\">0</Option>" . fs_filehandler::NewLine();
  82. $permissionset .= "<Option Name=\"DirCreate\">0</Option>" . fs_filehandler::NewLine();
  83. $permissionset .= "<Option Name=\"DirDelete\">0</Option>" . fs_filehandler::NewLine();
  84. $permissionset .= "<Option Name=\"DirList\">1</Option>" . fs_filehandler::NewLine();
  85. $permissionset .= "<Option Name=\"DirSubdirs\">1</Option>" . fs_filehandler::NewLine();
  86. $accessmode = "Read access";
  87. }
  88. // If write only...
  89. if ($rowftpaccounts['ft_access_vc'] == 'WO') {
  90. $permissionset = "<Option Name=\"FileRead\">0</Option>" . fs_filehandler::NewLine();
  91. $permissionset .= "<Option Name=\"FileWrite\">1</Option>" . fs_filehandler::NewLine();
  92. $permissionset .= "<Option Name=\"FileDelete\">0</Option>" . fs_filehandler::NewLine();
  93. $permissionset .= "<Option Name=\"FileAppend\">0</Option>" . fs_filehandler::NewLine();
  94. $permissionset .= "<Option Name=\"DirCreate\">1</Option>" . fs_filehandler::NewLine();
  95. $permissionset .= "<Option Name=\"DirDelete\">0</Option>" . fs_filehandler::NewLine();
  96. $permissionset .= "<Option Name=\"DirList\">0</Option>" . fs_filehandler::NewLine();
  97. $permissionset .= "<Option Name=\"DirSubdirs\"0</Option>" . fs_filehandler::NewLine();
  98. $accessmode = "Write access";
  99. }
  100. // If read and write...
  101. if ($rowftpaccounts['ft_access_vc'] == 'RW') {
  102. $permissionset = "<Option Name=\"FileRead\">1</Option>" . fs_filehandler::NewLine();
  103. $permissionset .= "<Option Name=\"FileWrite\">1</Option>" . fs_filehandler::NewLine();
  104. $permissionset .= "<Option Name=\"FileDelete\">1</Option>" . fs_filehandler::NewLine();
  105. $permissionset .= "<Option Name=\"FileAppend\">1</Option>" . fs_filehandler::NewLine();
  106. $permissionset .= "<Option Name=\"DirCreate\">1</Option>" . fs_filehandler::NewLine();
  107. $permissionset .= "<Option Name=\"DirDelete\">1</Option>" . fs_filehandler::NewLine();
  108. $permissionset .= "<Option Name=\"DirList\">1</Option>" . fs_filehandler::NewLine();
  109. $permissionset .= "<Option Name=\"DirSubdirs\">1</Option>" . fs_filehandler::NewLine();
  110. $accessmode = "Full access";
  111. }
  112. $line .= $permissionset;
  113. $line .= "<Option Name=\"IsHome\">1</Option>" . fs_filehandler::NewLine();
  114. $line .= "<Option Name=\"AutoCreate\">0</Option>" . fs_filehandler::NewLine();
  115. $line .= "</Permission>" . fs_filehandler::NewLine();
  116. $line .= "</Permissions>" . fs_filehandler::NewLine();
  117. $line .= "<SpeedLimits DlType=\"0\" DlLimit=\"10\" ServerDlLimitBypass=\"0\" UlType=\"0\" UlLimit=\"10\" ServerUlLimitBypass=\"0\">" . fs_filehandler::NewLine();
  118. $line .= "<Download/>" . fs_filehandler::NewLine();
  119. $line .= "<Upload/>" . fs_filehandler::NewLine();
  120. $line .= "</SpeedLimits>" . fs_filehandler::NewLine();
  121. $line .= "</User>" . fs_filehandler::NewLine();
  122. // end user loop
  123. }
  124. }
  125. $line .= "</Users>" . fs_filehandler::NewLine();
  126. $line .= "</FileZillaServer>";
  127. // Write the Filezilla config file
  128. if (fs_filehandler::UpdateFile($ftpconfigfile, 0777, $line)) {
  129. exec($ftp_reload);
  130. }
  131. }
  132. ?>