func_upload.py 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. from .tool.func import *
  2. def func_upload_2(conn):
  3. curs = conn.cursor()
  4. if ban_check() == 1:
  5. return re_error('/ban')
  6. if flask.request.method == 'POST':
  7. if captcha_post(flask.request.form.get('g-recaptcha-response', '')) == 1:
  8. return re_error('/error/13')
  9. else:
  10. captcha_post('', 0)
  11. data = flask.request.files.get('f_data', None)
  12. if not data:
  13. return re_error('/error/9')
  14. if int(wiki_set(3)) * 1024 * 1024 < flask.request.content_length:
  15. return re_error('/error/17')
  16. value = os.path.splitext(data.filename)[1]
  17. if not value in ['.jpeg', '.jpg', '.gif', '.png', '.webp', '.JPEG', '.JPG', '.GIF', '.PNG', '.WEBP']:
  18. return re_error('/error/14')
  19. if flask.request.form.get('f_name', None):
  20. name = flask.request.form.get('f_name', None) + value
  21. else:
  22. name = data.filename
  23. piece = os.path.splitext(name)
  24. if re.search('[^ㄱ-힣0-9a-zA-Z_\- ]', piece[0]):
  25. return re_error('/error/22')
  26. e_data = sha224(piece[0]) + piece[1]
  27. curs.execute("select title from data where title = ?", ['file:' + name])
  28. if curs.fetchall():
  29. return re_error('/error/16')
  30. curs.execute("select html from html_filter where kind = 'file'")
  31. db_data = curs.fetchall()
  32. for i in db_data:
  33. t_re = re.compile(i[0])
  34. if t_re.search(name):
  35. return redirect('/file_filter')
  36. ip = ip_check()
  37. if flask.request.form.get('f_lice', None):
  38. lice = flask.request.form.get('f_lice', None)
  39. else:
  40. if custom()[2] == 0:
  41. lice = ip
  42. else:
  43. lice = '[[user:' + ip + ']]'
  44. if os.path.exists(os.path.join(app_var['path_data_image'], e_data)):
  45. os.remove(os.path.join(app_var['path_data_image'], e_data))
  46. data.save(os.path.join(app_var['path_data_image'], e_data))
  47. else:
  48. data.save(os.path.join(app_var['path_data_image'], e_data))
  49. curs.execute("insert into data (title, data) values (?, ?)", ['file:' + name, '[[file:' + name + ']][br][br]{{{[[file:' + name + ']]}}}[br][br]' + lice])
  50. curs.execute("insert into acl (title, decu, dis, why, view) values (?, 'admin', '', '', '')", ['file:' + name])
  51. history_plus(
  52. 'file:' + name, '[[file:' + name + ']][br][br]{{{[[file:' + name + ']]}}}[br][br]' + lice,
  53. get_time(),
  54. ip,
  55. '(upload)',
  56. '0'
  57. )
  58. conn.commit()
  59. return redirect('/w/file:' + name)
  60. else:
  61. return easy_minify(flask.render_template(skin_check(),
  62. imp = [load_lang('upload'), wiki_set(), custom(), other2([0, 0])],
  63. data = '''
  64. <a href="/file_filter">(''' + load_lang('file_filter_list') + ''')</a>
  65. <hr class=\"main_hr\">
  66. <form method="post" enctype="multipart/form-data" accept-charset="utf8">
  67. <input type="file" name="f_data">
  68. <hr class=\"main_hr\">
  69. <input placeholder="''' + load_lang('file_name') + '''" name="f_name" type="text">
  70. <hr class=\"main_hr\">
  71. <input placeholder="''' + load_lang('license') + '''" name="f_lice" type="text">
  72. <hr class=\"main_hr\">
  73. ''' + captcha_get() + '''
  74. <button id="save" type="submit">''' + load_lang('save') + '''</button>
  75. </form>
  76. ''',
  77. menu = [['other', load_lang('return')]]
  78. ))