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.

374 lines
15 KiB

2 years ago
11 months ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
13 hours ago
2 years ago
4 months ago
11 months ago
2 years ago
11 months ago
4 months ago
11 months ago
2 years ago
13 hours ago
2 years ago
13 hours ago
11 months ago
2 years ago
9 months ago
11 months ago
2 years ago
11 months ago
2 years ago
11 months ago
2 months ago
10 months ago
2 years ago
13 hours ago
2 years ago
11 months ago
2 years ago
11 months ago
2 years ago
11 months ago
1 year ago
2 years ago
1 year ago
2 years ago
3 weeks ago
2 years ago
3 weeks ago
11 months ago
3 weeks ago
2 years ago
10 months ago
13 hours ago
10 months ago
13 hours ago
10 months ago
13 hours ago
10 months ago
2 years ago
2 years ago
11 months ago
2 years ago
13 hours ago
1 year ago
2 years ago
1 year ago
3 weeks ago
2 years ago
11 months ago
2 years ago
10 months ago
2 years ago
2 months ago
2 years ago
11 months ago
2 years ago
2 months ago
3 weeks ago
11 months ago
2 years ago
9 months ago
10 months ago
11 months ago
4 months ago
2 years ago
11 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 CleanViteJs extends Command
  13. {
  14. protected function configure()
  15. {
  16. $this->setName('cleanvitejs')
  17. ->addArgument('dir', Argument::REQUIRED, '/BTPanel/static/vite/js/路径')
  18. ->setDescription('处理宝塔面板vite/js文件');
  19. }
  20. protected function execute(Input $input, Output $output)
  21. {
  22. $dir = trim($input->getArgument('dir'));
  23. if(!file_exists($dir)){
  24. $output->writeln('目录不存在');
  25. return;
  26. }
  27. //$this->handlefile($dir.'/DockerImages.js');
  28. $this->checkdir($dir);
  29. }
  30. private function getExtendCode($content, $part, $n = 1, $startChar = '{', $endChar = '}'){
  31. if(!$part) return false;
  32. $length = strlen($content);
  33. $start = strpos($content, $part);
  34. if($start===false)return false;
  35. $end = $start+strlen($part);
  36. $start--;
  37. $c = 0;
  38. for($i=$start;$i>=0;$i--){
  39. if(substr($content,$i,1) == $startChar) $c++;
  40. if(substr($content,$i,1) == $endChar) $c--;
  41. if($c == $n){
  42. $start = $i;
  43. break;
  44. }
  45. }
  46. $c = 0;
  47. for($i=$end;$i<=$length;$i++){
  48. if(substr($content,$i,1) == $endChar) $c++;
  49. if(substr($content,$i,1) == $startChar) $c--;
  50. if($c == $n){
  51. $end = $i;
  52. break;
  53. }
  54. }
  55. return substr($content, $start, $end - $start + 1);
  56. }
  57. private function getExtendFunction($content, $part, $startChar = '(', $endChar = ')'){
  58. $code = $this->getExtendCode($content, $part, 1, $startChar, $endChar);
  59. if(!$code) return false;
  60. $start = strpos($content, $code) - 1;
  61. $end = $start + strlen($code);
  62. for($i=$start;$i>=0;$i--){
  63. $char = substr($content,$i,1);
  64. if(!ctype_alpha($char)&&$char!='_'){
  65. $start = $i+1;
  66. break;
  67. }
  68. }
  69. if(substr($content,$start-1,1) == ',') $start--;
  70. else if(substr($content,$end+1,1) == ',') $end++;
  71. return substr($content, $start, $end - $start + 1);
  72. }
  73. private function checkdir($basedir){
  74. if($dh=opendir($basedir)){
  75. while (($file=readdir($dh)) !== false){
  76. if($file != '.' && $file != '..'){
  77. if(!is_dir($basedir.'/'.$file) && substr($file,-3)=='.js'){
  78. $this->handlefile($basedir.'/'.$file);
  79. }else if(!is_dir($basedir.'/'.$file) && substr($file,-4)=='.map'){
  80. unlink($basedir.'/'.$file);
  81. }
  82. }
  83. }
  84. closedir($dh);
  85. }
  86. }
  87. private function str_replace_once($needle, $replace, $haystack) {
  88. $pos = strpos($haystack, $needle);
  89. if ($pos === false) {
  90. return $haystack;
  91. }
  92. return substr_replace($haystack, $replace, $pos, strlen($needle));
  93. }
  94. private function handlefile($filepath){
  95. //echo $filepath."\n";
  96. $file = file_get_contents($filepath);
  97. if(!$file)return;
  98. $flag = false;
  99. if(strpos($file, 'window.location.protocol.indexOf("https")>=0')!==false){ //index
  100. $file = str_replace('window.location.protocol.indexOf("https")>=0', '!0', $file);
  101. $code = $this->getExtendCode($file, 'isGetCoupon:', 2);
  102. if($code){
  103. $file = str_replace($code, '{}', $file);
  104. }
  105. $file = preg_replace('!recommendShow:\w+,!', 'recommendShow:!1,', $file, 1);
  106. $code = $this->getExtendCode($file, '"打开需求反馈"', 1, '[', ']');
  107. if($code){
  108. $file = str_replace($code, '[]', $file);
  109. }
  110. $flag = true;
  111. }
  112. if(strpos($file, '"点击打开调查问卷"')!==false){ //index
  113. $code = $this->getExtendCode($file, '"点击打开调查问卷"', 2);
  114. if($code){
  115. $file = str_replace($code, '{}', $file);
  116. }
  117. $flag = true;
  118. }
  119. if(strpos($file, '您有{0}个优惠券待领取')!==false){ //win-index
  120. $code = $this->getExtendCode($file, 'isGetCoupon:', 2);
  121. if($code){
  122. $file = str_replace($code, '{}', $file);
  123. }
  124. $flag = true;
  125. }
  126. if(strpos($file, '论坛求助')!==false && strpos($file, '"/other/customer-qrcode.png"')!==false){ //main
  127. $code = $this->getExtendCode($file, '"微信公众号"', 1);
  128. $code = $this->getExtendFunction($file, $code);
  129. $start = strpos($file, $code) - 1;
  130. for($i=$start;$i>=0;$i--){
  131. if(substr($file,$i,1) == ','){
  132. $start = $i;
  133. break;
  134. }
  135. }
  136. $code = $this->getExtendCode($file, '"/other/customer-qrcode.png"', 2);
  137. $code = $this->getExtendFunction($file, $code);
  138. $end = strpos($file, $code)+strlen($code);
  139. $code = substr($file, $start, $end - $start);
  140. $file = str_replace($code, '', $file);
  141. $flag = true;
  142. }
  143. if(strpos($file, 'useNegotiate')!==false){ //utils
  144. $code = $this->getExtendCode($file, 'createPeerConnection()', 1);
  145. if($code){
  146. $file = str_replace($code, '{}', $file);
  147. }
  148. $file = preg_replace('!computed\(\(\)=>"calc"===\w+\.\w+\.type\)!', '!1', $file);
  149. $file = preg_replace('!computed\(\(\)=>"input"===\w+\.\w+\.type\)!', '!1', $file);
  150. $file = preg_replace('!computed\(function\(\)\{return"calc"===\w+\.\w+\.type\}\)!', '!1', $file);
  151. $file = preg_replace('!computed\(function\(\)\{return"input"===\w+\.\w+\.type\}\)!', '!1', $file);
  152. $code = $this->getExtendCode($file, '"自动部署"', 2);
  153. if($code){
  154. $file = str_replace($code, '', $file);
  155. }
  156. $flag = true;
  157. }
  158. if(strpos($file, '"sqlserver管理"')!==false && strpos($file, '"iis管理"')!==false){ //win-utils
  159. $file = preg_replace('!"calc"===\w+\.\w+\.type!', '!1', $file);
  160. $file = preg_replace('!"input"===\w+\.\w+\.type!', '!1', $file);
  161. $flag = true;
  162. }
  163. if(strpos($file, '请冷静几秒钟,确认以下要删除的数据')!==false && strpos($file, '"计算结果:"')!==false){ //site
  164. $code = $this->getExtendCode($file, '"计算结果:"', 1, '[', ']');
  165. $code = $this->getExtendFunction($file, $code);
  166. $file = str_replace($code, '', $file);
  167. $file = preg_replace('!\w+\.sum===\w+\.addend1\+\w+\.addend2!', '!0', $file);
  168. $file = preg_replace('!value=\!0,(\w+)\.value=5;!', 'value=!1,$1.value=0;', $file);
  169. $flag = true;
  170. }
  171. if(strpos($file, '"left-waf"')!==false && strpos($file, '"iconWaf"')!==false){ //site.table
  172. $code = $this->getExtendCode($file, '"left-waf"');
  173. $code = $this->getExtendCode($file, $code, 1, '[', ']');
  174. $code = $this->getExtendFunction($file, $code);
  175. $file = str_replace($code, '""', $file);
  176. $flag = true;
  177. }
  178. if(strpos($file, 'svgtofont-left-waf')!==false && strpos($file, '"iconWaf"')!==false){ //site.table
  179. $code = $this->getExtendCode($file, 'svgtofont-left-waf');
  180. $code = $this->getExtendCode($file, $code, 1, '[', ']');
  181. $code = $this->getExtendFunction($file, $code);
  182. $file = str_replace($code, '""', $file);
  183. $flag = true;
  184. }
  185. if(strpos($file, 'label:"商用SSL证书"')!==false){ //site-ssl
  186. $code = $this->getExtendFunction($file, 'label:"商用SSL证书"', '{', '}');
  187. $file = str_replace($code, '', $file);
  188. $code = $this->getExtendFunction($file, 'label:"测试证书"', '{', '}');
  189. if($code){
  190. $file = str_replace($code, '', $file);
  191. }
  192. $code = $this->getExtendFunction($file, 'label:"宝塔证书"', '{', '}');
  193. if($code){
  194. $file = str_replace($code, '', $file);
  195. }
  196. $code = $this->getExtendCode($file, '"购买商业证书"', 2);
  197. if($code){
  198. $code2 = str_replace('"busSslList"', '"letsEncryptList"', $code);
  199. $code2 = str_replace($this->getExtendFunction($code, '"购买商业证书"'), '', $code2);
  200. $file = str_replace($code, $code2, $file);
  201. }
  202. $flag = true;
  203. }
  204. if(strpos($file, '"btSslList"')!==false && strpos($filepath, '/useStore')){ //site-ssl
  205. $file = str_replace('"btSslList"', '"currentCertInfo"', $file);
  206. $flag = true;
  207. }
  208. if(strpos($file, '"商用SSL"')!==false){ //ssl
  209. $code = $this->getExtendFunction($file, '"商用SSL"', '{', '}');
  210. $file = str_replace($code, '', $file);
  211. $code = $this->getExtendFunction($file, '"宝塔证书"', '{', '}');
  212. $file = str_replace($code, '', $file);
  213. for($i=0;$i<3;$i++){
  214. $code = $this->getExtendCode($file, ',"联系客服"', 2, '[', ']');
  215. if($code){
  216. $file = str_replace($code, '[]', $file);
  217. }
  218. }
  219. $flag = true;
  220. }
  221. if(strpos($file, '"SSL-CERTIFICATE-STORE"')!==false){ //ssl
  222. $file = str_replace('("bt")', '("encrypt")', $file);
  223. $flag = true;
  224. }
  225. if(strpos($file, '"商业证书"')!==false && strpos($file, 'name:"busSslList"')!==false && strpos($file, 'IIS配置')!==false){ //win-ssl
  226. $code = $this->getExtendFunction($file, 'name:"busSslList"', '{', '}');
  227. $file = str_replace($code, '', $file);
  228. $code = $this->getExtendFunction($file, 'name:"trustAsiaList"', '{', '}');
  229. $file = str_replace($code, '', $file);
  230. $file = $this->str_replace_once('"busSslList"', '"currentCertInfo"', $file);
  231. $flag = true;
  232. }
  233. if(strpos($file, '如果您希望添加其它Docker应用')!==false){
  234. $code = $this->getExtendCode($file, '如果您希望添加其它Docker应用', 1, '[', ']');
  235. $code = $this->getExtendFunction($file, $code);
  236. $file = str_replace($code, '', $file);
  237. $flag = true;
  238. }
  239. if(strpos($file, '"recom-view"')!==false){ //soft
  240. $code = $this->getExtendCode($file, '"recom-view"');
  241. $code = $this->getExtendFunction($file, $code);
  242. $file = str_replace($code, '', $file);
  243. $flag = true;
  244. }
  245. if(strpos($file, '"打开插件文件目录"')!==false && strpos($file, '"(续费)"')!==false){ //soft.table
  246. $code = $this->getExtendFunction($file, '"(续费)"');
  247. $file = str_replace($code, '""', $file);
  248. $flag = true;
  249. }
  250. if(strpos($file, 'path:"register"')!==false){ //domain
  251. $code = $this->getExtendCode($file, 'path:"register"');
  252. $file = str_replace($code.',', '', $file);
  253. $flag = true;
  254. }
  255. for($i=0;$i<5;$i++){
  256. $code = $this->getExtendCode($file, ',"需求反馈"', 1, '[', ']');
  257. if($code){
  258. if(strpos($code, 'svgtofont-desired')){
  259. $file = str_replace($code, '[]', $file);
  260. }else{
  261. $code = $this->getExtendFunction($code, ',"需求反馈"');
  262. $file = str_replace($code, '', $file);
  263. }
  264. $flag = true;
  265. }
  266. }
  267. $code = $this->getExtendCode($file, '("需求反馈",-1)', 1, '[', ']');
  268. if($code){
  269. $file = str_replace($code, '[]', $file);
  270. $flag = true;
  271. }
  272. $code = $this->getExtendCode($file, '(" 需求反馈 ",-1)', 1, '[', ']');
  273. if($code){
  274. $file = str_replace($code, '[]', $file);
  275. $flag = true;
  276. }
  277. $code = $this->getExtendFunction($file, 'label:"需求反馈",', '{', '}');
  278. if($code){
  279. $file = str_replace($code, '', $file);
  280. $flag = true;
  281. }
  282. if(strpos($file, '暂无搜索结果,<span class="text-primary cursor-pointer NpsDialog">提交需求反馈</span>')!==false){
  283. $file = str_replace('暂无搜索结果,<span class="text-primary cursor-pointer NpsDialog">提交需求反馈</span>', '暂无搜索结果', $file);
  284. $flag = true;
  285. }
  286. if(strpos($file, 'getReceiveCoupon()')!==false){ //aapanel-优惠券
  287. $code = $this->getExtendCode($file, 'getReceiveCoupon()');
  288. $file = str_replace($code, '{}', $file);
  289. $flag = true;
  290. }
  291. if(strpos($file, '"Site.DelSite.index_1"')!==false){ //aapanel-site
  292. $code = $this->getExtendCode($file, '"Site.DelSite.index_10"', 3, '(', ')');
  293. if($code){
  294. $code = $this->getExtendFunction($file, $code);
  295. $file = str_replace($code, '', $file);
  296. $file = preg_replace('@\w+\.value!==\w+\.value\+\w+\.value@', '!1', $file);
  297. $file = preg_replace('@null==\w+\.value\|\|null==\w+\.value@', '!1', $file);
  298. $file = str_replace('disabled:!0', 'disabled:!1', $file);
  299. $flag = true;
  300. }
  301. }
  302. if(strpos($file, '"Component.Confirm.index_4"')!==false){ //aapanel-public
  303. $code = $this->getExtendCode($file, '"Component.Confirm.index_4"', 2, '(', ')');
  304. if($code){
  305. $code = $this->getExtendFunction($file, $code);
  306. $file = str_replace($code, '', $file);
  307. $file = preg_replace('@\w+\.value===\w+\.value\+\w+\.value@', '!0', $file);
  308. $flag = true;
  309. }
  310. $code = $this->getExtendCode($file, '"Component.Confirm.index_1"', 1, '(', ')');
  311. if($code){
  312. $code = $this->getExtendFunction($file, $code);
  313. $file = str_replace($code, '', $file);
  314. $file = preg_replace('@\w+\.value===\w+\.value\?@', '!0?', $file);
  315. $flag = true;
  316. }
  317. }
  318. if(strpos($file, '"Component.Feedback.index_7"')!==false){ //aapanel-需求反馈
  319. $code = $this->getExtendCode($file, '"Component.Feedback.index_7"', 2);
  320. if($code){
  321. $code = $this->getExtendFunction($file, $code);
  322. $file = str_replace($code, '', $file);
  323. $flag = true;
  324. }
  325. }
  326. if(strpos($file, '"Soft.index_16"')!==false){ //aapanel-soft
  327. $code = $this->getExtendCode($file, '"Soft.index_16"', 2);
  328. if($code){
  329. $file = str_replace($code, '{}', $file);
  330. $flag = true;
  331. }
  332. }
  333. if(!$flag) return;
  334. if(file_put_contents($filepath, $file)){
  335. echo '文件:'.$filepath.' 处理成功'."\n";
  336. }else{
  337. echo '文件:'.$filepath.' 处理失败,可能无写入权限'."\n";
  338. }
  339. }
  340. }