Tool.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. namespace App\Command;
  3. class Tool extends Command
  4. {
  5. public $description = ''
  6. . '├─=: php xcat Tool [选项]' . PHP_EOL
  7. . '│ ├─ initQQWry - 下载 IP 解析库' . PHP_EOL
  8. . '│ ├─ setTelegram - 设置 Telegram 机器人' . PHP_EOL
  9. . '│ ├─ detectConfigs - 检查数据库内新增的配置' . PHP_EOL
  10. . '│ ├─ initdocuments - 下载用户使用文档至服务器' . PHP_EOL;
  11. public function boot()
  12. {
  13. if (count($this->argv) === 2) {
  14. echo $this->description;
  15. } else {
  16. $methodName = $this->argv[2];
  17. if (method_exists($this, $methodName)) {
  18. $this->$methodName();
  19. } else {
  20. echo '方法不存在.' . PHP_EOL;
  21. }
  22. }
  23. }
  24. /**
  25. * 设定 Telegram Bot
  26. *
  27. * @return void
  28. */
  29. public function setTelegram()
  30. {
  31. if ($_ENV['use_new_telegram_bot'] === true) {
  32. $WebhookUrl = ($_ENV['baseUrl'] . '/telegram_callback?token=' . $_ENV['telegram_request_token']);
  33. $telegram = new \Telegram\Bot\Api($_ENV['telegram_token']);
  34. $telegram->removeWebhook();
  35. if ($telegram->setWebhook(['url' => $WebhookUrl])) {
  36. echo ('New Bot @' . $telegram->getMe()->getUsername() . ' 设置成功!' . PHP_EOL);
  37. }
  38. } else {
  39. $bot = new \TelegramBot\Api\BotApi($_ENV['telegram_token']);
  40. $ch = curl_init();
  41. curl_setopt($ch, CURLOPT_URL, sprintf('https://api.telegram.org/bot%s/deleteWebhook', $_ENV['telegram_token']));
  42. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  43. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
  44. $deleteWebhookReturn = json_decode(curl_exec($ch));
  45. curl_close($ch);
  46. if ($deleteWebhookReturn->ok && $deleteWebhookReturn->result && $bot->setWebhook($_ENV['baseUrl'] . '/telegram_callback?token=' . $_ENV['telegram_request_token']) == 1) {
  47. echo ('Old Bot 设置成功!' . PHP_EOL);
  48. }
  49. }
  50. }
  51. /**
  52. * 下载使用文档
  53. *
  54. * @return void
  55. */
  56. public function initdocuments()
  57. {
  58. system('git clone https://github.com/GeekQuerxy/PANEL_DOC.git ' . BASE_PATH . "/public/docs/", $ret);
  59. echo $ret;
  60. }
  61. /**
  62. * 下载 IP 库
  63. *
  64. * @return void
  65. */
  66. public function initQQWry()
  67. {
  68. echo ('开始下载纯真 IP 数据库....');
  69. $qqwry = file_get_contents('https://qqwry.mirror.noc.one/QQWry.Dat?from=sspanel_uim');
  70. if ($qqwry != '') {
  71. $fp = fopen(BASE_PATH . '/storage/qqwry.dat', 'wb');
  72. if ($fp) {
  73. fwrite($fp, $qqwry);
  74. fclose($fp);
  75. echo ('纯真 IP 数据库下载成功!');
  76. } else {
  77. echo ('纯真 IP 数据库保存失败!');
  78. }
  79. } else {
  80. echo ('下载失败!请重试,或在 https://github.com/SukkaW/qqwry-mirror/issues/new 反馈!');
  81. }
  82. }
  83. /**
  84. * 探测新增配置
  85. *
  86. * @return void
  87. */
  88. public function detectConfigs()
  89. {
  90. echo \App\Services\DefaultConfig::detectConfigs();
  91. }
  92. }