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.

63 lines
2.1 KiB

3 years ago
  1. #coding: utf-8
  2. import public,os,sys,json
  3. class Plugin:
  4. name = False
  5. p_path = None
  6. is_php = False
  7. plu = None
  8. __api_root_url = 'https://api.bt.cn'
  9. __api_url = __api_root_url+ '/panel/get_plugin_list'
  10. __cache_file = 'data/plugin_list.json'
  11. def __init__(self, name):
  12. self.name = name
  13. self.p_path = public.get_plugin_path(name)
  14. self.is_php = os.path.exists(self.p_path + '/index.php')
  15. def get_plugin_list(self, force = False):
  16. if force==False and os.path.exists(self.__cache_file):
  17. jsonData = public.readFile(self.__cache_file)
  18. softList = json.loads(jsonData)
  19. else:
  20. try:
  21. jsonData = public.HttpGet(self.__api_url)
  22. except Exception as ex:
  23. raise public.error_conn_cloud(str(ex))
  24. softList = json.loads(jsonData)
  25. if type(softList)!=dict or 'list' not in softList: raise Exception('云端插件列表获取失败')
  26. public.writeFile(self.__cache_file, jsonData)
  27. return softList
  28. def isdef(self, fun):
  29. if not self.is_php:
  30. public.package_path_append(self.p_path)
  31. plugin_main = __import__(self.name + '_main')
  32. try:
  33. if sys.version_info[0] == 2:
  34. reload(plugin_main)
  35. else:
  36. from imp import reload
  37. reload(plugin_main)
  38. except:
  39. pass
  40. self.plu = eval('plugin_main.' + self.name + '_main()')
  41. if not hasattr(self.plu, fun):
  42. if self.name == 'btwaf' and fun == 'index':
  43. raise Exception("未购买")
  44. return False
  45. return True
  46. def exec_fun(self, args):
  47. fun = args.s
  48. if not self.is_php:
  49. plu = self.plu
  50. data = eval('plu.' + fun + '(args)')
  51. else:
  52. import panelPHP
  53. args.s = fun
  54. args.name = self.name
  55. data = panelPHP.panelPHP(self.name).exec_php_script(args)
  56. return data