ShellController.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Support\Str;
  4. use Illuminate\Routing\UrlGenerator;
  5. use Illuminate\Support\Facades\Storage;
  6. use App\Application;
  7. use App\Server;
  8. class ShellController extends Controller
  9. {
  10. protected $url;
  11. public function __construct(UrlGenerator $url) {
  12. $this->url = $url;
  13. }
  14. public function install($servercode) {
  15. $server = Server::where('servercode', $servercode)->where('complete', 0)->first();
  16. if(!$server) {
  17. return abort(403);
  18. }
  19. $script = Storage::get('scripts/install.sh');
  20. $script = Str::replaceArray('???', [
  21. $this->url->to('/'),
  22. $server->ip,
  23. $server->port,
  24. $server->username,
  25. $server->password,
  26. $server->dbroot,
  27. $server->servercode
  28. ], $script);
  29. return response($script)->withHeaders(['Content-Type' =>'application/x-sh']);
  30. }
  31. public function hostadd($servercode) {
  32. $server = Server::where('servercode', $servercode)->where('complete', 1)->first();
  33. if(!$server) {
  34. return abort(403);
  35. }
  36. $script = Storage::get('scripts/hostadd.sh');
  37. $script = Str::replaceArray('???', [
  38. $this->url->to('/'),
  39. $server->dbroot
  40. ], $script);
  41. return response($script)->withHeaders(['Content-Type' =>'application/x-sh']);
  42. }
  43. public function hostget($appcode) {
  44. $application = Application::where('appcode', $appcode)->first();
  45. if(!$application) {
  46. return abort(403);
  47. }
  48. if($application->basepath) {
  49. $basepath = '/home/'.$application->username.'/web/'.$application->basepath;
  50. } else {
  51. $basepath = '/home/'.$application->username.'/web';
  52. }
  53. $script = Storage::get('scripts/haget.sh');
  54. $script = Str::replace('???USER???', $application->username, $script);
  55. $script = Str::replace('???BASE???', $basepath, $script);
  56. $script = Str::replace('???PHP???', $application->php, $script);
  57. $script = Str::replace('???DOMAIN???', $application->domain, $script);
  58. return response($script)->withHeaders(['Content-Type' =>'application/x-sh']);
  59. }
  60. public function hostdel($servercode) {
  61. $server = Server::where('servercode', $servercode)->where('complete', 1)->first();
  62. if(!$server) {
  63. return abort(403);
  64. }
  65. $script = Storage::get('scripts/hostdel.sh');
  66. $script = Str::replaceArray('???', [
  67. $server->dbroot,
  68. ], $script);
  69. return response($script)->withHeaders(['Content-Type' =>'application/x-sh']);
  70. }
  71. public function passwd($servercode) {
  72. $server = Server::where('servercode', $servercode)->where('complete', 1)->first();
  73. if(!$server) {
  74. return abort(403);
  75. }
  76. $script = Storage::get('scripts/passwd.sh');
  77. return response($script)->withHeaders(['Content-Type' =>'application/x-sh']);
  78. }
  79. public function aliasadd($servercode) {
  80. $server = Server::where('servercode', $servercode)->where('complete', 1)->first();
  81. if(!$server) {
  82. return abort(403);
  83. }
  84. $script = Storage::get('scripts/aliasadd.sh');
  85. return response($script)->withHeaders(['Content-Type' =>'application/x-sh']);
  86. }
  87. public function aliasdel($servercode) {
  88. $server = Server::where('servercode', $servercode)->where('complete', 1)->first();
  89. if(!$server) {
  90. return abort(403);
  91. }
  92. $script = Storage::get('scripts/aliasdel.sh');
  93. return response($script)->withHeaders(['Content-Type' =>'application/x-sh']);
  94. }
  95. public function aliasget($appcode,$domain) {
  96. $application = Application::where('appcode', $appcode)->first();
  97. if(!$application) {
  98. return abort(403);
  99. }
  100. if($application->basepath) {
  101. $basepath = '/home/'.$application->username.'/web/'.$application->basepath;
  102. } else {
  103. $basepath = '/home/'.$application->username.'/web';
  104. }
  105. $script = Storage::get('scripts/haget.conf');
  106. $script = Str::replace('???USER???', $application->username, $script);
  107. $script = Str::replace('???BASE???', $basepath, $script);
  108. $script = Str::replace('???PHP???', $application->php, $script);
  109. $script = Str::replace('???DOMAIN???', $domain, $script);
  110. return response($script)->withHeaders(['Content-Type' =>'text/plain']);
  111. }
  112. public function nginx() {
  113. $script = Storage::get('scripts/nginx.conf');
  114. return response($script)->withHeaders(['Content-Type' =>'text/plain']);
  115. }
  116. public function ssl() {
  117. $script = Storage::get('scripts/ssl.sh');
  118. return response($script)->withHeaders(['Content-Type' =>'application/x-sh']);
  119. }
  120. public function status() {
  121. $script = Storage::get('scripts/status.sh');
  122. return response($script)->withHeaders(['Content-Type' =>'application/x-sh']);
  123. }
  124. public function deploy() {
  125. $script = Storage::get('scripts/deploy.sh');
  126. return response($script)->withHeaders(['Content-Type' =>'application/x-sh']);
  127. }
  128. }