func_upload.py 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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_sel', 'direct_input') == 'direct_input':
  38. if flask.request.form.get('f_lice', None):
  39. lice = flask.request.form.get('f_lice', None)
  40. else:
  41. if ip_or_user(ip) != 0:
  42. lice = ip
  43. else:
  44. lice = '[[user:' + ip + ']]'
  45. lice += '[[category:direct_input]]'
  46. else:
  47. lice = flask.request.form.get('f_lice_sel', None)
  48. if flask.request.form.get('f_lice', None):
  49. lice += ' : ' + flask.request.form.get('f_lice', None)
  50. lice += '[[category:' + re.sub('\]', '_', flask.request.form.get('f_lice_sel', None)) + ']]'
  51. if os.path.exists(os.path.join(app_var['path_data_image'], e_data)):
  52. os.remove(os.path.join(app_var['path_data_image'], e_data))
  53. data.save(os.path.join(app_var['path_data_image'], e_data))
  54. else:
  55. data.save(os.path.join(app_var['path_data_image'], e_data))
  56. file_d = '[[file:' + name + ']][br][br]{{{[[file:' + name + ']]}}}[br][br]' + lice
  57. curs.execute("insert into data (title, data) values (?, ?)", ['file:' + name, file_d])
  58. curs.execute("insert into acl (title, decu, dis, why, view) values (?, 'admin', '', '', '')", ['file:' + name])
  59. render_set(
  60. title = name,
  61. data = file_d,
  62. num = 1
  63. )
  64. history_plus(
  65. 'file:' + name,
  66. file_d,
  67. get_time(),
  68. ip,
  69. ip,
  70. '0',
  71. 'upload'
  72. )
  73. conn.commit()
  74. return redirect('/w/file:' + name)
  75. else:
  76. license_list = '''
  77. <option value="direct_input">''' + load_lang('direct_input') + '''</option>
  78. '''
  79. curs.execute("select html from html_filter where kind = 'image_license'")
  80. db_data = curs.fetchall()
  81. for i in db_data:
  82. license_list += '''
  83. <option value="''' + i[0] + '''">''' + i[0] + '''</option>
  84. '''
  85. return easy_minify(flask.render_template(skin_check(),
  86. imp = [load_lang('upload'), wiki_set(), custom(), other2([0, 0])],
  87. data = '''
  88. <a href="/file_filter">(''' + load_lang('file_filter_list') + ''')</a>
  89. <hr class=\"main_hr\">
  90. ''' + load_lang('max_file_size') + ''' : ''' + wiki_set(3) + '''MB
  91. <hr class=\"main_hr\">
  92. <form method="post" enctype="multipart/form-data" accept-charset="utf8">
  93. <input type="file" name="f_data">
  94. <hr class=\"main_hr\">
  95. <input placeholder="''' + load_lang('file_name') + '''" name="f_name" type="text" value="''' + flask.request.args.get('name', '') + '''">
  96. <hr class=\"main_hr\">
  97. <select name="f_lice_sel">
  98. ''' + license_list + '''
  99. </select>
  100. <hr class=\"main_hr\">
  101. <input placeholder="''' + load_lang('license') + '''" name="f_lice" type="text">
  102. <hr class=\"main_hr\">
  103. ''' + captcha_get() + '''
  104. <button id="save" type="submit">''' + load_lang('save') + '''</button>
  105. </form>
  106. ''',
  107. menu = [['other', load_lang('return')]]
  108. ))