LogManager.py 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. from django.http import HttpResponse
  2. from Controller import OTAEquipment
  3. from django.views.decorators.csrf import csrf_exempt
  4. from django.views.generic import TemplateView
  5. from django.utils.decorators import method_decorator
  6. from Ansjer import config as api_settings
  7. from Service.ModelService import ModelService
  8. import time,os
  9. from Object.ResponseObject import ResponseObject
  10. from Object.TokenObject import TokenObject
  11. from Ansjer.config import BASE_DIR
  12. def StatisticsData(request):
  13. print('------request------')
  14. print(request)
  15. print('---------------')
  16. try:
  17. real_ip = request.META['HTTP_X_FORWARDED_FOR']
  18. clientIP = real_ip.split(",")[0]
  19. except:
  20. try:
  21. clientIP = request.META['REMOTE_ADDR']
  22. except Exception as e:
  23. clientIP = ''
  24. nowTime = time.strftime('%Y-%m-%d', time.localtime(time.time()))
  25. print(u'当前用户: %s , 访问时间: %s' % (clientIP, nowTime))
  26. print(u'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~')
  27. for cookKey, cookValue in request.COOKIES.items():
  28. print("COOKIES:", cookKey, cookValue)
  29. for sessionKey, sessionValue in request.session.items():
  30. print("session:", sessionKey, sessionValue)
  31. print('HTTP_COOKIE', request.META.get('HTTP_COOKIE', 'unknown'))
  32. print('CSRF_COOKIE', request.META.get('CSRF_COOKIE', 'unknown'))
  33. print('user', request.user)
  34. print(u'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~')
  35. # print("body:", request.body)
  36. print('path', request.path)
  37. print('path_info', request.path_info)
  38. print('encoding', request.encoding)
  39. print('resolver_match', request.resolver_match)
  40. for fileKey, fileValue in request.FILES.items():
  41. print("FILES:", fileKey, fileValue)
  42. #print('META', request.META)
  43. print(u'******************************************************')
  44. print('DOCUMENT_ROOT', request.META.get('DOCUMENT_ROOT', 'unknown'))
  45. print('QUERY_STRING: ', request.META.get('QUERY_STRING', 'unknown'))
  46. print('REMOTE_ADDR', request.META.get('REMOTE_ADDR', 'unknown'))
  47. print('HTTP_HOST', request.META.get('HTTP_HOST', u'unknown'))
  48. print('HTTP_REFERER', request.META.get('HTTP_REFERER', 'unknown'))
  49. print('HTTP_COOKIE', request.META.get('HTTP_COOKIE', 'unknown'))
  50. print('CSRF_COOKIE', request.META.get('CSRF_COOKIE', 'unknown'))
  51. print('HTTP_CONNECTION', request.META.get('HTTP_CONNECTION', 'unknown'))
  52. print('wsgi.errors', request.META.get('wsgi.errors', 'unknown'))
  53. print('mod_wsgi.application_group', request.META.get('mod_wsgi.application_group', 'unknown'))
  54. print('mod_wsgi.callable_object', request.META.get('mod_wsgi.callable_object', 'unknown'))
  55. print('mod_wsgi.listener_host', request.META.get('mod_wsgi.listener_host', 'unknown'))
  56. print('mod_wsgi.listener_port', request.META.get('mod_wsgi.listener_port', 'unknown'))
  57. print('mod_wsgi.process_group', request.META.get('mod_wsgi.process_group', 'unknown'))
  58. print('mod_wsgi.reload_mechanism', request.META.get('mod_wsgi.reload_mechanism', 'unknown'))
  59. print('mod_wsgi.script_reloading', request.META.get('mod_wsgi.script_reloading', 'unknown'))
  60. print('mod_wsgi.version', request.META.get('mod_wsgi.version', 'unknown'))
  61. print('PATH', request.META.get('PATH', 'unknown'))
  62. print('PATH_INFO', request.META.get('PATH_INFO', 'unknown'))
  63. print('PATH_TRANSLATED', request.META.get('PATH_TRANSLATED', 'unknown'))
  64. print('QUERY_STRING', request.META.get('QUERY_STRING', 'unknown'))
  65. print('QUERY_STRING', request.META.get('REMOTE_ADDR', 'unknown'))
  66. print('REMOTE_PORT', request.META.get('REMOTE_PORT', 'unknown'))
  67. print('REQUEST_METHOD', request.META.get('REQUEST_METHOD', 'unknown'))
  68. print('REQUEST_URI', request.META.get('REQUEST_URI', 'unknown'))
  69. print('SCRIPT_FILENAME', request.META.get('SCRIPT_FILENAME', 'unknown'))
  70. print('SCRIPT_NAME', request.META.get('SCRIPT_NAME', 'unknown'))
  71. print('SERVER_ADDR', request.META.get('SERVER_ADDR', 'unknown'))
  72. print('SERVER_ADMIN', request.META.get('SERVER_ADMIN', 'unknown'))
  73. print('SERVER_NAME', request.META.get('SERVER_NAME', 'unknown'))
  74. print('SERVER_PORT', request.META.get('SERVER_PORT', 'unknown'))
  75. print('SERVER_PROTOCOL', request.META.get('SERVER_PROTOCOL', 'unknown'))
  76. print('SERVER_SIGNATURE', request.META.get('SERVER_SIGNATURE', 'unknown'))
  77. print('SERVER_SOFTWARE', request.META.get('SERVER_SOFTWARE', 'unknown'))
  78. print('wsgi.input', request.META.get('wsgi.input', 'unknown'))
  79. print('wsgi.multiprocess', request.META.get('wsgi.multiprocess', 'unknown'))
  80. print('wsgi.multithread', request.META.get('wsgi.multithread', 'unknown'))
  81. print('wsgi.run_once', request.META.get('wsgi.run_once', 'unknown'))
  82. print('wsgi.url_scheme', request.META.get('wsgi.url_scheme', 'unknown'))
  83. print('wsgi.version', request.META.get('wsgi.version', 'unknown'))
  84. print('get_host', request.get_host())
  85. print('get_full_path', request.get_full_path())
  86. print('build_absolute_uri', request.build_absolute_uri())
  87. print('is_secure', request.is_secure())
  88. print('is_ajax', request.is_ajax())
  89. print(u'******************************************************')
  90. print('CONTENT_LENGTH: ', request.META.get('CONTENT_LENGTH', 'unknown'))
  91. print('CONTENT_TYPE', request.META.get('CONTENT_TYPE', 'unknown'))
  92. print('HTTP_ACCEPT', request.META.get('HTTP_ACCEPT', 'unknown'))
  93. print('HTTP_ACCEPT_ENCODING', request.META.get('HTTP_ACCEPT_ENCODING', 'unknown'))
  94. print('REMOTE_HOST', request.META.get('REMOTE_HOST', 'unknown'))
  95. print('REMOTE_USER', request.META.get('REMOTE_USER', 'unknown'))
  96. print('REQUEST_METHOD', request.META.get('REQUEST_METHOD', 'unknown'))
  97. print('SERVER_NAME', request.META.get('SERVER_NAME', 'unknown'))
  98. print('SERVER_PORT', request.META.get('SERVER_PORT', 'unknown'))
  99. print('HTTP_USER_AGENT', request.META.get('HTTP_USER_AGENT', 'unknown'))
  100. print('HTTP_AUTHORIZATION', request.META.get('HTTP_AUTHORIZATION', b'unknown'))
  101. class HelpView(TemplateView):
  102. '''
  103. 帮助说明,包括版本信息,帮助文件等
  104. '''
  105. @method_decorator(csrf_exempt)
  106. def dispatch(self, *args, **kwargs):
  107. return super(HelpView, self).dispatch(*args, **kwargs)
  108. def get(self, request, *args, **kwargs):
  109. reInfoType = request.GET.get('reInfoType', None)
  110. token = request.GET.get('token', None)
  111. return self.getRequestInfo(reInfoType,token)
  112. def post(self, request, *args, **kwargs):
  113. reInfoType = request.POST.get('reInfoType', None)
  114. token = request.POST.get('token', None)
  115. return self.getRequestInfo(reInfoType,token)
  116. def getRequestInfo(self, reInfoType,token):
  117. response = ResponseObject()
  118. if reInfoType is not None and token is not None:
  119. tko = TokenObject(token)
  120. response.lang = tko.lang
  121. if tko.code == 0:
  122. userID = tko.userID
  123. own_permission = ModelService.check_perm(userID=userID, permID=30)
  124. if own_permission is True:
  125. if reInfoType == 'version':
  126. return self.readInfo(response)
  127. elif reInfoType == 'requirements':
  128. return self.requirementsInfo(response)
  129. elif reInfoType == 'helpfile':
  130. return self.getHelpCHM(response)
  131. else:
  132. return response.json(444)
  133. else:
  134. return response.json(404)
  135. else:
  136. return response.json(tko.code)
  137. else:
  138. return response.json(800,'reInfoType','reInfoType')
  139. def readInfo(self,response):
  140. verfilePath = '/'.join((api_settings.BASE_DIR, 'static/Help/')).replace('\\', '/') + 'version.txt'
  141. if os.path.isfile(verfilePath):
  142. file = open(verfilePath, encoding='utf-8')
  143. versionStr = ''
  144. for line in file:
  145. versionStr += line
  146. return response.json(0,{'versioninfo':versionStr})
  147. else:
  148. return response.json(701)
  149. def requirementsInfo(self,response):
  150. requirementsPath = '/'.join((api_settings.BASE_DIR, 'requirements.txt')).replace('\\', '/')
  151. print(requirementsPath)
  152. if os.path.isfile(requirementsPath):
  153. file = open(requirementsPath, encoding='utf-8')
  154. requirementsStr = ''
  155. for line in file:
  156. requirementsStr += line
  157. return response.json(0,{'requirementsinfo': requirementsStr})
  158. else:
  159. return response.json(701)
  160. def getHelpCHM(self,response):
  161. verHelpCHM = '/'.join((api_settings.BASE_DIR, 'static/Help/')).replace('\\', '/') + 'AnsjerHelp.CHM'
  162. print(verHelpCHM)
  163. if os.path.isfile(verHelpCHM):
  164. return OTAEquipment.downloadUrl(fileType='CHM', fileCode='', fileVersion='', fileName=verHelpCHM)
  165. else:
  166. return response.json(code=701)
  167. def upload_help_chm(request):
  168. token = request.POST.get('token', None)
  169. response = ResponseObject()
  170. if token is not None:
  171. tko = TokenObject(token)
  172. response.lang = tko.lang
  173. if tko.code == 0:
  174. userID = tko.userID
  175. own_permission = ModelService.check_perm(userID=userID, permID=30)
  176. if own_permission is True:
  177. f = request.FILES.get('file', None)
  178. path = os.path.join(BASE_DIR, 'static/Help/AnsjerHelp.CHM')
  179. try:
  180. if os.path.exists(path):
  181. os.remove(path)
  182. with open(path, 'wb+') as destination:
  183. for chunk in f.chunks():
  184. destination.write(chunk)
  185. except Exception as e:
  186. print('error:' + repr(e))
  187. return response.json(700,{'details': repr(e)})
  188. return response.json(0)
  189. else:
  190. return response.json(404)
  191. else:
  192. return response.json(tko.code)
  193. else:
  194. return response.json(309)
  195. @csrf_exempt
  196. def errorPath(request, **kwargs):
  197. html = """
  198. <!DOCTYPE html>
  199. <html lang="en">
  200. <head>
  201. <meta charset="UTF-8">
  202. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  203. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  204. <title>Document</title>
  205. <link rel="stylesheet" href="index.css" </head>
  206. <body>
  207. <div class="header con">
  208. <div class="photo"></div>
  209. <div class="headerlist">
  210. <ul>
  211. <li><a class="active">帮助中心</a></li>
  212. <li><a>售后服务</a></li>
  213. </ul>
  214. <div class="serch">
  215. <input type="text" placeholder="搜索">
  216. </div>
  217. </div>
  218. </div>
  219. <div class="nav">
  220. <ul class="con">
  221. <li>首页</li>
  222. <li>产品类目</li>
  223. <li>热卖商品</li>
  224. <li>帮助中心</li>
  225. <li>资讯</li>
  226. <li>关于我们</li>
  227. </ul>
  228. </div>
  229. <div class="banner"
  230. ></div>
  231. <div class="list con">
  232. <div class="item">
  233. <img src="https://ansjerfilemanager.s3.cn-northwest-1.amazonaws.com.cn/app/static/3.jpg">
  234. <p>无线基站套装</p>
  235. </div>
  236. <div class="item">
  237. <img src="https://ansjerfilemanager.s3.cn-northwest-1.amazonaws.com.cn/app/static/1-1-C1.jpg">
  238. <p>C1</p>
  239. </div>
  240. <div class="item">
  241. <img src="https://ansjerfilemanager.s3.cn-northwest-1.amazonaws.com.cn/app/static/1-1-306.jpg">
  242. <p>C306</p>
  243. </div>
  244. </div>
  245. <div class="footer">
  246. <div class="con">
  247. <ul>
  248. <li>网站导航</li>
  249. <li>物流配送</li>
  250. <li>售后服务</li>
  251. <li>配送服务</li>
  252. <li>退换货政策</li>
  253. <li>联系我们</li>
  254. <li>隐私政策</li>
  255. <li>服务协议</li>
  256. </ul>
  257. </div>
  258. <div style="text-align: center; "><a href="https://beian.miit.gov.cn/">粤ICP备12041005号</a></div>
  259. </div>
  260. </body>
  261. </html>
  262. <style>
  263. * {
  264. padding: 0;
  265. margin: 0;
  266. }
  267. ul {
  268. list-style: none;
  269. }
  270. .con {
  271. width: 966px;
  272. margin: 0 auto;
  273. }
  274. .header {
  275. height: 110px;
  276. }
  277. .photo {
  278. width: 165px;
  279. height: 110px;
  280. background: url(../图片/logo.png);
  281. float: left;
  282. background-position: center;
  283. background-size: 100% 100%;
  284. }
  285. .headerlist {
  286. float: right;
  287. }
  288. .headerlist ul {
  289. height: 44px;
  290. margin-top: 10px;
  291. line-height: 44px;
  292. }
  293. .headerlist li {
  294. float: left;
  295. }
  296. .headerlist a {
  297. border-right: 1px solid #b2c7ea;
  298. padding-left: 13px;
  299. padding-right: 13px;
  300. font-size: 13px;
  301. color: indigo;
  302. }
  303. .headerlist .last {
  304. border: 0;
  305. padding-right: 0;
  306. }
  307. .headerlist li .active {
  308. color: pink;
  309. }
  310. .serch {
  311. float: right;
  312. width: 234px;
  313. height: 28px;
  314. border: 1px solid indigo;
  315. }
  316. .serch input {
  317. border: 0;
  318. outline: none;
  319. width: 210px;
  320. float: left;
  321. height: 28px;
  322. padding-left: 14px;
  323. }
  324. .nav {
  325. height: 53px;
  326. line-height: 53px;
  327. border-top: 1px solid #edf4fc;
  328. background-color: #274964;
  329. color: aliceblue;
  330. }
  331. .nav li {
  332. float: left;
  333. font-size: 16px;
  334. padding-right: 76px;
  335. }
  336. .banner {
  337. height: 380px;
  338. background: url('https://ansjerfilemanager.s3.cn-northwest-1.amazonaws.com.cn/app/static/backdrop.jpg') no-repeat center;
  339. background-size: cover;
  340. }
  341. .list {
  342. height: 213px;
  343. margin-top: 11px;
  344. margin-bottom: 125px;
  345. }
  346. .item {
  347. height: 222px;
  348. width: 230px;
  349. border: 1px solid #cccccc;
  350. float: left;
  351. margin-right: 12px;
  352. }
  353. .item img {
  354. width: 230px;
  355. height: 222px;
  356. display: block;
  357. }
  358. .item p {
  359. height: 47px;
  360. padding-left: 28px;
  361. line-height: 47px;
  362. color: #274964;
  363. }
  364. .footer {
  365. height: 206px;
  366. border-top: 1px solid cornsilk;
  367. background-color: #cccccc;
  368. }
  369. .footer ul {
  370. height: 84px;
  371. padding-top: 30px;
  372. padding-bottom: 30px;
  373. line-height: 28px;
  374. border-bottom: 1px solid gray;
  375. }
  376. .footer ul li {
  377. width: 210px;
  378. padding-left: 30px;
  379. font-size: 12px;
  380. float: left;
  381. color: indigo;
  382. }
  383. .footer p {
  384. height: 61px;
  385. line-height: 61px;
  386. padding-left: 30px;
  387. font-size: 12px;
  388. }
  389. .footer p span {
  390. color: indigo;
  391. }
  392. </style>
  393. """
  394. if os.environ.get('DJANGO_SETTINGS_MODULE') == 'Ansjer.cn_config.formal_settings':
  395. return HttpResponse(html)
  396. response = ResponseObject()
  397. return response.json(414)