anonymous group photoblog software
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.
 
 
 
 
 
 

197 lines
6.5 KiB

  1. import time
  2. import model
  3. import staff
  4. import interboard
  5. import misc
  6. import config
  7. from util import WakaError
  8. # Dictionary of what action keywords mean. It's like a real dictionary!
  9. # {name: {'name': title, 'content': content}}
  10. ACTION_TRANSLATION = {}
  11. # {name: function}
  12. ACTION_MAP = {}
  13. def get_action_name(action_to_view, debug=0):
  14. try:
  15. name = ACTION_TRANSLATION[action_to_view]['name']
  16. content = ACTION_TRANSLATION[action_to_view]['content']
  17. except KeyError:
  18. raise WakaError('Missing action key or unknown action key.')
  19. if not debug:
  20. return name
  21. elif debug == 1:
  22. return (name, content)
  23. else:
  24. return content
  25. def staff_action(action_name='', title='', content=''):
  26. def decorator(f):
  27. real_name = action_name or f.__name__
  28. real_title = title or real_name.title().replace("_", "")
  29. ACTION_TRANSLATION[real_name] = {'name': real_title,
  30. 'content': content}
  31. ACTION_MAP[real_name] = f
  32. return f
  33. return decorator
  34. @staff_action(title='Manager Post', content='Post')
  35. def admin_post(task_data, **kwargs):
  36. return task_data.board.post_stuff(admin_data=task_data, **kwargs)
  37. @staff_action(title='Administrative Edit', content='Post')
  38. def admin_edit(task_data, **kwargs):
  39. return task_data.board.edit_stuff(admin_data=task_data, **kwargs)
  40. @staff_action(title='Administrative Deletion', content='Post')
  41. def admin_delete(task_data, **kwargs):
  42. return task_data.board.delete_stuff(admin_data=task_data, **kwargs)
  43. @staff_action(title='Deletion From Trash Bin', content='Deleted Post')
  44. def backup_remove(task_data, **kwargs):
  45. return task_data.board.remove_backup_stuff(admin_data=task_data,
  46. **kwargs)
  47. @staff_action(content='Thread Parent')
  48. def thread_lock(task_data, num):
  49. return task_data.board.toggle_thread_state(task_data, num, 'locked')
  50. @staff_action(content='Thread Parent')
  51. def thread_unlock(task_data, num):
  52. return task_data.board.toggle_thread_state(task_data, num, 'locked',
  53. enable_state=False)
  54. @staff_action(content='Thread Parent')
  55. def thread_sticky(task_data, num):
  56. return task_data.board.toggle_thread_state(task_data, num, 'sticky')
  57. @staff_action(content='Thread Parent')
  58. def thread_unsticky(task_data, num):
  59. return task_data.board.toggle_thread_state(task_data, num, 'sticky',
  60. enable_state=False)
  61. @staff_action(title='Delete By IP (Board-Wide)', content='IP Address')
  62. def delete_by_ip(task_data, **kwargs):
  63. return task_data.board.delete_by_ip(task_data=task_data, **kwargs)
  64. @staff_action(title='Board Rebuild', content='Board Name')
  65. def rebuild(task_data):
  66. return task_data.board.rebuild_cache_proxy(task_data)
  67. # Interboard entries
  68. # (these 'decorate' functions not in this module)
  69. staff_action('admin_entry')(interboard.add_admin_entry)
  70. staff_action('remove_admin_entry')(interboard.remove_admin_entry)
  71. staff_action('edit_admin_entry')(interboard.edit_admin_entry)
  72. staff_action('update_spam')(interboard.update_spam_file)
  73. staff_action('report_resolve', title='Report Resolution',
  74. content='Resolved Post')(interboard.mark_resolved)
  75. staff_action('thread_move',
  76. content='Source and Destination')(interboard.move_thread)
  77. staff_action('delete_by_ip_global', title='Delete By IP (Global or Reign-Wide)',
  78. content='IP Address')(interboard.delete_by_ip)
  79. staff_action('rebuild_global', title='Global Rebuild',
  80. content='Referer')(interboard.global_cache_rebuild_proxy)
  81. staff_action('add_proxy_entry')(interboard.add_proxy_entry)
  82. staff_action('remove_proxy_entry')(interboard.remove_proxy_entry)
  83. # Unimplemented
  84. staff_action('script_ban_forgive', title='Script Access Restoration',
  85. content='IP Address')(None)
  86. staff_action('ipban_edit', title='IP Ban Revision',
  87. content='Revised Data')(None)
  88. staff_action('whitelist', title='IP Whitelist',
  89. content='Whitelisted IP Address')(None)
  90. staff_action('trust_edit', title='Revised Captcha Exemption',
  91. content='Revised Data')(None)
  92. staff_action('trust_remove', title='Removed Captcha Exemption',
  93. content='Removed Tripcode')(None)
  94. staff_action('backup_restore', title='Restoration From Trash Bin',
  95. content='Restored Post')(None)
  96. staff_action('ipban', title='IP Ban',
  97. content='Affected IP Address')(None)
  98. staff_action('ipban_remove', title='IP Ban Removal',
  99. content='Unbanned IP Address')(None)
  100. staff_action('trust', title='Captcha Exemption',
  101. content='Exempted Tripcode')(None)
  102. staff_action('wordban', title='Word Ban',
  103. content='Banned Phrase')(None)
  104. staff_action('whitelist_remove', title='IP Whitelist Removal',
  105. content='Removed IP Address')(None)
  106. staff_action('wordban_remove', title='Word Ban Removal',
  107. content='Unbanned Phrase')(None)
  108. staff_action('wordban_edit', title='Word Ban Revision',
  109. content='Revised Data')(None)
  110. staff_action('whitelist_edit', title='IP Whitelist Revision',
  111. content='Revised Data')(None)
  112. class StaffAction(object):
  113. def __init__(self, cookie, action, **kwargs):
  114. self.action = action
  115. self.user = staff.StaffMember.get_from_cookie(cookie)
  116. self.board = None
  117. self.kwargs = kwargs
  118. try:
  119. self.board = kwargs.pop('board')
  120. except KeyError:
  121. pass
  122. self.timestamp = time.time()
  123. self.date = misc.make_date(self.timestamp, style=config.DATE_STYLE)
  124. self.contents = []
  125. self.action = action
  126. self.admin_id = None
  127. def execute(self):
  128. res = None
  129. try:
  130. # XXX there was an apparently pointless "if board" here
  131. res = ACTION_MAP[self.action](self, **self.kwargs)
  132. return res
  133. finally:
  134. # Execute after exceptions in the case of bulk deletions, etc.
  135. if res or self.contents:
  136. self._log_action()
  137. def _log_action(self):
  138. interboard.trim_activity()
  139. session = model.Session()
  140. table = model.activity
  141. ip = misc.dot_to_dec(self.user.login_data.addr)
  142. for content in self.contents:
  143. sql = table.insert().values(username=self.user.username,
  144. ip=ip,
  145. action=self.action,
  146. info=content,
  147. date=self.date,
  148. timestamp=self.timestamp,
  149. admin_id=self.admin_id)
  150. session.execute(sql)