give_acl.py 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. from .tool.func import *
  2. def give_acl_2(conn, name):
  3. curs = conn.cursor()
  4. check_ok = ''
  5. if flask.request.method == 'POST':
  6. check_data = 'acl (' + name + ')'
  7. else:
  8. check_data = None
  9. user_data = re.search('^user:(.+)$', name)
  10. if user_data:
  11. if check_data and custom()[2] == 0:
  12. return redirect('/login')
  13. if user_data.groups()[0] != ip_check():
  14. if admin_check(5) != 1:
  15. if check_data:
  16. return re_error('/error/3')
  17. else:
  18. check_ok = 'disabled'
  19. else:
  20. if admin_check(5) != 1:
  21. if check_data:
  22. return re_error('/error/3')
  23. else:
  24. check_ok = 'disabled'
  25. if flask.request.method == 'POST':
  26. curs.execute("select title from acl where title = ?", [name])
  27. if curs.fetchall():
  28. curs.execute("update acl set decu = ? where title = ?", [flask.request.form.get('decu', ''), name])
  29. curs.execute("update acl set dis = ? where title = ?", [flask.request.form.get('dis', ''), name])
  30. curs.execute("update acl set why = ? where title = ?", [flask.request.form.get('why', ''), name])
  31. curs.execute("update acl set view = ? where title = ?", [flask.request.form.get('view', ''), name])
  32. else:
  33. curs.execute("insert into acl (title, decu, dis, why, view) values (?, ?, ?, ?, ?)", [
  34. name,
  35. flask.request.form.get('decu', ''),
  36. flask.request.form.get('dis', ''),
  37. flask.request.form.get('why', ''),
  38. flask.request.form.get('view', '')
  39. ])
  40. curs.execute("select title from acl where title = ? and decu = '' and dis = '' and view = ''", [name])
  41. if curs.fetchall():
  42. curs.execute("delete from acl where title = ?", [name])
  43. all = ''
  44. for i in ['decu', 'dis', 'view']:
  45. if flask.request.form.get(i, '') == '':
  46. all += 'normal'
  47. if i != 'view':
  48. all += ' | '
  49. else:
  50. all += flask.request.form.get(i, '')
  51. if i != 'view':
  52. all += ' | '
  53. admin_check(5, check_data + ' (' + all + ')')
  54. conn.commit()
  55. return redirect('/acl/' + url_pas(name))
  56. else:
  57. data = '<h2>' + load_lang('document_acl') + '</h2><hr class=\"main_hr\"><select name="decu" ' + check_ok + '>'
  58. if re.search('^user:', name):
  59. acl_list = ['', 'user', 'all']
  60. else:
  61. acl_list = ['', 'user', 'admin', '50_edit', 'email']
  62. curs.execute("select decu from acl where title = ?", [name])
  63. acl_data = curs.fetchall()
  64. for data_list in acl_list:
  65. if acl_data and acl_data[0][0] == data_list:
  66. check = 'selected="selected"'
  67. else:
  68. check = ''
  69. data += '<option value="' + data_list + '" ' + check + '>' + (data_list if data_list != '' else 'normal') + '</option>'
  70. data += '</select>'
  71. if not re.search('^user:', name):
  72. data += '<hr class=\"main_hr\"><h2>' + load_lang('discussion_acl') + '</h2><hr class=\"main_hr\"><select name="dis" ' + check_ok + '>'
  73. curs.execute("select dis, why, view from acl where title = ?", [name])
  74. acl_data = curs.fetchall()
  75. for data_list in acl_list:
  76. if acl_data and acl_data[0][0] == data_list:
  77. check = 'selected="selected"'
  78. else:
  79. check = ''
  80. data += '<option value="' + data_list + '" ' + check + '>' + (data_list if data_list != '' else 'normal') + '</option>'
  81. data += '</select>'
  82. data += '<hr class=\"main_hr\"><h2>' + load_lang('view_acl') + '</h2><hr class=\"main_hr\"><select name="view" ' + check_ok + '>'
  83. for data_list in acl_list:
  84. if acl_data and acl_data[0][2] == data_list:
  85. check = 'selected="selected"'
  86. else:
  87. check = ''
  88. data += '<option value="' + data_list + '" ' + check + '>' + (data_list if data_list != '' else 'normal') + '</option>'
  89. data += '''
  90. </select>
  91. <h2>''' + load_lang('explanation') + '''</h2>
  92. <ul>
  93. <li>normal : ''' + load_lang('default') + '''</li>
  94. <li>admin : ''' + load_lang('admin_acl') + '''</li>
  95. <li>user : ''' + load_lang('member_acl') + '''</li>
  96. <li>50 edit : ''' + load_lang('50_edit_acl') + '''</li>
  97. <li>all : ''' + load_lang('all_acl') + '''</li>
  98. <li>email : ''' + load_lang('email_acl') + '''</li>
  99. </ul>
  100. '''
  101. if check_ok == '':
  102. if acl_data:
  103. data += '<hr class=\"main_hr\"><input value="' + html.escape(acl_data[0][1]) + '" placeholder="' + load_lang('why') + '" name="why" type="text" ' + check_ok + '>'
  104. else:
  105. data += '<hr class=\"main_hr\"><input placeholder="' + load_lang('why') + '" name="why" type="text" ' + check_ok + '>'
  106. return easy_minify(flask.render_template(skin_check(),
  107. imp = [name, wiki_set(), custom(), other2([' (' + load_lang('acl') + ')', 0])],
  108. data = '''
  109. <form method="post">
  110. ''' + data + '''
  111. <hr class=\"main_hr\">
  112. <button type="submit" ''' + check_ok + '''>''' + load_lang('save') + '''</button>
  113. </form>
  114. ''',
  115. menu = [['w/' + url_pas(name), load_lang('document')], ['manager', load_lang('admin')], ['admin_log?search=' + url_pas('acl (' + name + ')'), load_lang('acl_record')]]
  116. ))