Browse Source

Implement proxy panel

master
dequis 3 years ago
parent
commit
18dce03158
6 changed files with 89 additions and 15 deletions
  1. +23
    -0
      app.py
  2. +41
    -0
      interboard.py
  3. +8
    -0
      misc.py
  4. +7
    -1
      staff_interface.py
  5. +2
    -0
      staff_tasks.py
  6. +8
    -14
      templates/proxy_panel_template.html

+ 23
- 0
app.py View File

@@ -434,6 +434,29 @@ def task_removeban(environ, start_response):

return StaffAction(**kwargs).execute()

def task_addproxy(environ, start_response):
request = environ['werkzeug.request']

kwargs = kwargs_from_params(request,
form=['type', 'ip', 'timestamp'],
admin=True,
)
kwargs['action'] = 'add_proxy_entry'

return StaffAction(**kwargs).execute()

def task_removeproxy(environ, start_response):
request = environ['werkzeug.request']

kwargs = kwargs_from_params(request,
form=['num'],
admin=True,
)
kwargs['action'] = 'remove_proxy_entry'

return StaffAction(**kwargs).execute()


# Interboard management.

def task_updatespam(environ, start_response):


+ 41
- 0
interboard.py View File

@@ -591,3 +591,44 @@ def move_thread(task_data, parent, src_brd_obj, dest_brd_obj):

return util.make_http_forward(forward_url)


# proxy

def add_proxy_entry(task_data, type, ip, timestamp):
session = model.Session()
table = model.proxy

if not misc.validate_ip(ip):
raise WakaError(strings.BADIP)

age = config.PROXY_WHITE_AGE if type == 'white' else config.PROXY_BLACK_AGE
timestamp = int(timestamp or '0') - age + time.time()
date = misc.make_date(time.time(), style=config.DATE_STYLE)

query = table.delete().where(table.c.ip == ip)
session.execute(query)

query = table.insert().values(
type=type,
ip=ip,
timestamp=timestamp,
date=date
)
session.execute(query)

board = local.environ['waka.board']
forward_url = misc.make_script_url(task='proxy', board=board.name)

return util.make_http_forward(forward_url, config.ALTERNATE_REDIRECT)

def remove_proxy_entry(task_data, num):
session = model.Session()
table = model.proxy

query = table.delete().where(table.c.num == num)
session.execute(query)

board = local.environ['waka.board']
forward_url = misc.make_script_url(task='proxy', board=board.name)

return util.make_http_forward(forward_url, config.ALTERNATE_REDIRECT)

+ 8
- 0
misc.py View File

@@ -29,6 +29,14 @@ def dec_to_dot(numip):
except ValueError:
return numip

def validate_ip(ip):
try:
if isinstance(dot_to_dec(ip), int):
return True
except:
pass
return False

def is_whitelisted(numip):
return False



+ 7
- 1
staff_interface.py View File

@@ -741,7 +741,13 @@ class StaffInterface(Template):

@interface_for(PROXY_PANEL)
def make_admin_proxy_panel(self):
Template.__init__(self, 'proxy_panel_template')
session = model.Session()
table = model.proxy
query = table.select().order_by(table.c.timestamp.asc())
rows = session.execute(query)

Template.__init__(self, 'proxy_panel_template',
scanned=rows, now=time.time())

@interface_for(SECURITY_PANEL)
def make_admin_script_security_panel(self):


+ 2
- 0
staff_tasks.py View File

@@ -104,6 +104,8 @@ staff_action('delete_by_ip_global', title='Delete By IP (Global or Reign-Wide)',
staff_action('rebuild_global', title='Global Rebuild',
content='Referer')(interboard.global_cache_rebuild_proxy)

staff_action('add_proxy_entry')(interboard.add_proxy_entry)
staff_action('remove_proxy_entry')(interboard.remove_proxy_entry)

# Unimplemented



+ 8
- 14
templates/proxy_panel_template.html View File

@@ -22,26 +22,20 @@
<table align="center"><tbody>
<tr class="managehead">{{ strings.PROXYTABLE }}</tr>

{% set prevtype = None %}
{% for proxy in scanned %}
{% if proxy.divider %}<tr class="managehead"><th colspan="6"></th></tr>{% endif %}
{% if prevtype != proxy.type %}<tr class="managehead"><th colspan="6"></th></tr>{% endif %}
{% set prevtype = proxy.type %}

<tr class="row{{ proxy.rowtype }}">

{% if proxy.type == 'white' %}
<td>White</td>
<td>{{ proxy.ip }}</td>
<td>{{ proxy.timestamp + config.PROXY_WHITE_AGE - time() }}</td>
{% endif %}
{% if proxy.type == 'black' %}
<td>Black</td>
<td>{{ proxy.ip }}</td>
<td>{{ proxy.timestamp + config.PROXY_BLACK_AGE - time() }}</td>
{% endif %}
<tr class="row{{ loop.cycle(1, 2) }}">

<td>{{ proxy.type|capitalize }}</td>
<td>{{ proxy.ip }}</td>
<td>{{ (proxy.timestamp + (config.PROXY_WHITE_AGE if proxy.type == 'white' else config.PROXY_BLACK_AGE) - now) | int }}</td>
<td>{{ proxy.date }}</td>
<td><a href="{{ get_script_name() }}?task=removeproxy&amp;board={{ board.name }}&amp;num={{ proxy.num }}">{{ strings.PROXYREMOVEBLACK }}</a></td>
</tr>
{% endfor %}
</tbody></table><br />

{% include 'normal_foot_include.html' %}
{% include 'normal_foot_include.html' %}

Loading…
Cancel
Save