PageRenderTime 33ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 1ms

/code/classes/Daemon/FTPd_Auto/Client.class.php

https://github.com/blekkzor/pinetd2
PHP | 112 lines | 92 code | 16 blank | 4 comment | 30 complexity | 948855632d83900d0b991aa94605790f MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. namespace Daemon\FTPd_Auto;
  3. class Client extends \Daemon\FTPd\Client {
  4. protected function checkAccess($login, $pass) {
  5. $data = $this->serverCall('getLogin', array('login' => $login, 'ip' => $this->peer[0]));
  6. if (is_null($data)) return false;
  7. if (crypt($pass, $data['Password']) != $data['Password']) return false;
  8. return array(
  9. 'root' => $data['Path'],
  10. 'suid_user' => 'nobody', // force suid on login
  11. 'suid_group' => 'nobody', // force suid on login
  12. 'write_level' => $data['Access'],
  13. );
  14. }
  15. public function _cmd_update($argv) {
  16. if (!is_null($this->login)) {
  17. $this->sendMsg('500 Call error');
  18. return;
  19. }
  20. $service = $argv[1];
  21. $data = $this->serverCall('getService', array('service' => $service));
  22. if (!$data) {
  23. $this->sendMsg('500 Call error');
  24. return;
  25. }
  26. $path = $data['path'];
  27. $domain = $data['domain'];
  28. if (!is_dir($path)) {
  29. $test = '/www/'.$domain[0].'/'.$domain[1].'/'.substr($domain, 2);
  30. if (is_dir($test)) {
  31. mkdir(dirname($path), 0755, true);
  32. rename($test, $path);
  33. } else {
  34. mkdir($path, 0755, true);
  35. }
  36. }
  37. // make domain symlinks
  38. foreach($data['domains'] as $alias) {
  39. list($alias, $extra) = explode('+', $alias);
  40. $link_target = $domain;
  41. if (!is_null($extra)) $link_target .= '/'.$extra;
  42. if (is_link($alias)) {
  43. if (readlink($alias) == $link_target) continue;
  44. } else if (is_dir($alias)) continue;
  45. if (file_exists($alias)) @unlink($alias);
  46. if (is_link($alias)) @unlink($alias);
  47. $parent = dirname($alias);
  48. if (!is_dir($parent)) mkdir($parent, 0755, true);
  49. symlink($link_target, $alias);
  50. }
  51. // make subdomain describe files
  52. foreach($data['subdomains'] as $sub => $bin) {
  53. file_put_contents($path.'_'.$sub.'.config', $bin);
  54. if (!is_dir($path.'/'.$sub)) {
  55. mkdir($path.'/'.$sub, 0755, true);
  56. chown($path.'/'.$sub, 'nobody');
  57. chgrp($path.'/'.$sub, 'nobody');
  58. }
  59. }
  60. // extra folders
  61. foreach(array('sessions','includes') as $sub) {
  62. if (!is_dir($path.'/'.$sub)) {
  63. mkdir($path.'/'.$sub, 0755, true);
  64. chown($path.'/'.$sub, 'nobody');
  65. chgrp($path.'/'.$sub, 'nobody');
  66. }
  67. }
  68. // vhost removal
  69. $dh = opendir($path);
  70. while(($fil = readdir($dh)) !== false) {
  71. if (($fil == '.') || ($fil == '..')) continue;
  72. if ($fil == 'sessions') continue;
  73. if ($fil == 'includes') continue;
  74. if ($fil == '.svn') continue;
  75. if (isset($data['subdomains'][$fil])) continue;
  76. $archive = '/www/archive/'.date('Y-m-d').'/'.$domain.'_'.$fil.'_'.time();
  77. mkdir(dirname($archive), 0755, true);
  78. rename($path.'/'.$fil, $archive);
  79. rename($path.'_'.$fil.'.config', $archive.'.config');
  80. }
  81. $this->sendMsg('200 OK');
  82. }
  83. protected function serverCall($method, array $params) {
  84. $params['server'] = $this->IPC->getName();
  85. $headers = array(
  86. 'X-IPC: STATIC',
  87. 'X-Path: Service/Hosting::'.$method,
  88. );
  89. $ch = curl_init('http://www.uid.st/');
  90. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  91. curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
  92. curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params, '', '&'));
  93. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  94. return unserialize(curl_exec($ch));
  95. }
  96. }