You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

115 lines
3.9 KiB

2 years ago
2 months ago
2 years ago
2 months ago
2 years ago
2 months ago
2 years ago
2 months ago
2 years ago
2 months ago
2 years ago
2 months ago
2 years ago
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\command;
  4. use think\console\Command;
  5. use think\console\Input;
  6. use think\console\input\Argument;
  7. use think\console\input\Option;
  8. use think\console\Output;
  9. use think\facade\Db;
  10. use think\facade\Config;
  11. use app\lib\Plugins;
  12. class DecryptFile extends Command
  13. {
  14. protected function configure()
  15. {
  16. $this->setName('decrypt')
  17. ->addArgument('type', Argument::REQUIRED, '文件类型,plugin:插件文件,module:模块文件,classdir:宝塔class目录,all:所有py文件')
  18. ->addArgument('file', Argument::REQUIRED, '文件路径')
  19. ->addArgument('os', Argument::OPTIONAL, '操作系统:Windows/Linux')
  20. ->setDescription('解密宝塔面板python文件');
  21. }
  22. protected function execute(Input $input, Output $output)
  23. {
  24. $type = trim($input->getArgument('type'));
  25. $file = trim($input->getArgument('file'));
  26. if(!file_exists($file)){
  27. $output->writeln('文件不存在');
  28. return;
  29. }
  30. if($type == 'plugin'){
  31. $os = trim($input->getArgument('os'));
  32. try{
  33. if(Plugins::decode_plugin_main_local($file, $os)){
  34. $output->writeln('文件解密成功!');
  35. }else{
  36. $output->writeln('文件解密失败!');
  37. }
  38. }catch(\Exception $e){
  39. $output->writeln($e->getMessage());
  40. }
  41. }elseif($type == 'module'){
  42. $this->decode_module_file($output, $file);
  43. }elseif($type == 'classdir'){
  44. $file = rtrim($file, '/');
  45. if(file_exists($file.'/common.py')){
  46. $class_v = 1;
  47. }elseif(file_exists($file.'/common_v2.py')){
  48. $class_v = 2;
  49. }else{
  50. $output->writeln('当前路径非宝塔面板class目录');
  51. return;
  52. }
  53. $dirs = glob($file.'/*Model'.($class_v == 2 ? 'V2' : ''));
  54. foreach($dirs as $dir){
  55. if(!is_dir($dir))continue;
  56. $files = glob($dir.'/*Model.py');
  57. foreach($files as $filepath){
  58. $this->decode_module_file($output, $filepath);
  59. }
  60. }
  61. if($class_v == 2){
  62. $filepath = $file.'/wp_toolkit/core.py';
  63. if(file_exists($filepath)){
  64. $this->decode_module_file($output, $filepath);
  65. }
  66. }else{
  67. $filepath = $file.'/public/authorization.py';
  68. if(file_exists($filepath)){
  69. $this->decode_module_file($output, $filepath);
  70. }
  71. }
  72. }elseif($type == 'all'){
  73. $file = rtrim($file, '/');
  74. $this->scan_all_file($input, $output, $file);
  75. }else{
  76. $output->writeln('未知文件类型');
  77. }
  78. }
  79. private function scan_all_file(Input $input, Output $output, $path) {
  80. $dir = opendir($path);
  81. while(false !== ( $file = readdir($dir)) ) {
  82. if (( $file != '.' ) && ( $file != '..' )) {
  83. $filepath = $path . '/' . $file;
  84. if ( is_dir($filepath) ) {
  85. $this->scan_all_file($input, $output, $filepath);
  86. }
  87. elseif(substr($filepath, -3) == '.py') {
  88. $this->decode_module_file($output, $filepath);
  89. }
  90. }
  91. }
  92. closedir($dir);
  93. }
  94. private function decode_module_file(Output $output, $filepath){
  95. try{
  96. $res = Plugins::decode_module_file($filepath);
  97. if($res == 2){
  98. $output->writeln('文件解密失败:'.$filepath);
  99. }elseif($res == 1){
  100. $output->writeln('文件解密成功:'.$filepath);
  101. }
  102. }catch(\Exception $e){
  103. $output->writeln($e->getMessage().':'.$filepath);
  104. }
  105. }
  106. }