ShellController.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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->port,
  23. $server->username,
  24. $server->password,
  25. $server->dbroot,
  26. $server->servercode
  27. ], $script);
  28. return response($script)->withHeaders(['Content-Type' =>'application/x-sh']);
  29. }
  30. public function hostadd($servercode) {
  31. $server = Server::where('servercode', $servercode)->where('complete', 1)->first();
  32. if(!$server) {
  33. return abort(403);
  34. }
  35. $script = Storage::get('scripts/hostadd.sh');
  36. $script = Str::replaceArray('???', [
  37. $this->url->to('/'),
  38. $server->dbroot
  39. ], $script);
  40. return response($script)->withHeaders(['Content-Type' =>'application/x-sh']);
  41. }
  42. public function hostget($appcode) {
  43. $application = Application::where('appcode', $appcode)->first();
  44. if(!$application) {
  45. return abort(403);
  46. }
  47. if($application->basepath) {
  48. $basepath = '/home/'.$application->username.'/web/'.$application->basepath;
  49. } else {
  50. $basepath = '/home/'.$application->username.'/web';
  51. }
  52. $script = Storage::get('scripts/haget.conf');
  53. $script = str_replace('???USER???', $application->username, $script);
  54. $script = str_replace('???BASE???', $basepath, $script);
  55. $script = str_replace('???PHP???', $application->php, $script);
  56. $script = str_replace('???DOMAIN???', $application->domain, $script);
  57. return response($script)->withHeaders(['Content-Type' =>'text/plain']);
  58. }
  59. public function hostdel($servercode) {
  60. $server = Server::where('servercode', $servercode)->where('complete', 1)->first();
  61. if(!$server) {
  62. return abort(403);
  63. }
  64. $script = Storage::get('scripts/hostdel.sh');
  65. $script = Str::replaceArray('???', [
  66. $server->dbroot,
  67. ], $script);
  68. return response($script)->withHeaders(['Content-Type' =>'application/x-sh']);
  69. }
  70. public function passwd($servercode) {
  71. $server = Server::where('servercode', $servercode)->where('complete', 1)->first();
  72. if(!$server) {
  73. return abort(403);
  74. }
  75. $script = Storage::get('scripts/passwd.sh');
  76. return response($script)->withHeaders(['Content-Type' =>'application/x-sh']);
  77. }
  78. public function aliasadd($servercode) {
  79. $server = Server::where('servercode', $servercode)->where('complete', 1)->first();
  80. if(!$server) {
  81. return abort(403);
  82. }
  83. $script = Storage::get('scripts/aliasadd.sh');
  84. return response($script)->withHeaders(['Content-Type' =>'application/x-sh']);
  85. }
  86. public function aliasdel($servercode) {
  87. $server = Server::where('servercode', $servercode)->where('complete', 1)->first();
  88. if(!$server) {
  89. return abort(403);
  90. }
  91. $script = Storage::get('scripts/aliasdel.sh');
  92. return response($script)->withHeaders(['Content-Type' =>'application/x-sh']);
  93. }
  94. public function aliasget($appcode,$domain) {
  95. $application = Application::where('appcode', $appcode)->first();
  96. if(!$application) {
  97. return abort(403);
  98. }
  99. if($application->basepath) {
  100. $basepath = '/home/'.$application->username.'/web/'.$application->basepath;
  101. } else {
  102. $basepath = '/home/'.$application->username.'/web';
  103. }
  104. $script = Storage::get('scripts/haget.conf');
  105. $script = str_replace('???USER???', $application->username, $script);
  106. $script = str_replace('???BASE???', $basepath, $script);
  107. $script = str_replace('???PHP???', $application->php, $script);
  108. $script = str_replace('???DOMAIN???', $domain, $script);
  109. return response($script)->withHeaders(['Content-Type' =>'text/plain']);
  110. }
  111. public function nginx() {
  112. $script = Storage::get('scripts/nginx.conf');
  113. return response($script)->withHeaders(['Content-Type' =>'text/plain']);
  114. }
  115. public function ssl() {
  116. $script = Storage::get('scripts/ssl.sh');
  117. return response($script)->withHeaders(['Content-Type' =>'application/x-sh']);
  118. }
  119. public function status() {
  120. $script = Storage::get('scripts/status.sh');
  121. return response($script)->withHeaders(['Content-Type' =>'application/x-sh']);
  122. }
  123. public function deploy() {
  124. $script = Storage::get('scripts/deploy.sh');
  125. return response($script)->withHeaders(['Content-Type' =>'application/x-sh']);
  126. }
  127. }