ShellController.php 4.7 KB

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