-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscud.py
More file actions
170 lines (128 loc) · 4.89 KB
/
scud.py
File metadata and controls
170 lines (128 loc) · 4.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
from flask import Flask, render_template, redirect, flash, url_for, request, abort
from flask.ext.login import LoginManager, login_user, login_required, fresh_login_required, logout_user
from forms.LoginForm import LoginForm
from database import db_session, init_db
from model.web import *
from random import choice
from jinja2.utils import generate_lorem_ipsum
import settings
import urllib
init_db()
app = Flask(__name__)
#Create the login manager
login_manager = LoginManager()
#Setup the app in the login_manager
login_manager.init_app(app)
app.config.from_pyfile('settings')
login_manager.login_view = "login"
##Login Section
@login_manager.user_loader
def load_user(user):
return Admin.query.get(user)
@app.route("/login", methods=["GET", "POST"])
def login():
form = LoginForm()
if form.validate_on_submit():
# login and validate the user...
login_user(form.admin)
flash("Logged in successfully.")
return redirect(request.args.get("next") or url_for("index"))
return render_template("login.html", form=form)
@app.route("/admin")
@login_required
def admin():
#Bot
bots = Bot.query.all()
#Network
#nworks = Network.query.all()
#Network Channel
#Channel
#User
return render_template('admin.html', bots=bots)
@app.route("/logout")
@login_required
def logout():
logout_user()
return redirect(url_for("index"))
##App section
@app.route("/")
def index():
return render_template('index.html')
@app.route("/images/")
def images():
i = Url.query.filter(Url.img_cached != None).all()
return render_template('images.html', images=i)
@app.route("/url/<int:urlId>")
def url(urlId):
row = Url.query.filter_by(id=urlId).first()
if row == None:
flash('No result found...')
return redirect(url_for('urls'))
return render_template('urls.html', url=row)
@app.route("/urls/", defaults={'page': 1})
@app.route("/urls/page/<int:page>")
def urls(page):
rows = Url.query.order_by(Url.date_created.desc())
totalRows = rows.count()
c = rows.limit(settings.PER_PAGE).offset((page - 1) * settings.PER_PAGE)
if not c.count() and page != 1:
flash('No results found on requested page... forwarding you here.')
return redirect(url_for('index', channel=channel))
pagination = Pagination(page, settings.PER_PAGE, totalRows)
return render_template('urls.html', urls=c, pagination=pagination)
@app.route("/channels/")
def channels():
n = Network.query.all()
return render_template('channels.html', networks=n)
@app.route("/perma/<int:id>/")
def permanent(id):
m = Message.query.filter_by(id=id).first()
if m is None:
flash('Couldn\'t find the message, sorry!')
return redirect(url_for('index'))
return render_template('permanent.html', message=m)
@app.route("/channel/<int:channel>/", defaults={'page': 1})
@app.route("/channel/<int:channel>/page/<int:page>")
def channel_log(channel, page):
rows = Url.query.filter(network_channel_id=channel).order_by(Url.date_created.desc())
rows = Message.query.filter_by(network_channel_id=channel).order_by(Message.id.desc())
totalRows = rows.count()
c = rows.limit(settings.PER_PAGE).offset((page - 1) * settings.PER_PAGE)
if not c.count() and page != 1:
flash('No results found on requested page... forwarding you here.')
return redirect(url_for('urls', channel=channel))
pagination = Pagination(page, settings.PER_PAGE, totalRows)
return render_template('urls.html', urls=c, pagination=pagination)
# Pagination Related
def url_for_other_page(page):
args = request.view_args.copy()
args['page'] = page
return url_for(request.endpoint, **args)
app.jinja_env.globals['url_for_other_page'] = url_for_other_page
@app.template_filter('safeurl')
def safeurl(uri):
return urllib.quote_plus(uri)
app.jinja_env.globals['safeurl'] = safeurl
@app.route("/dataload/")
def dataload():
# Create fake messages:
names = ('alice', 'bob', 'clive', 'dave', 'enid', 'frank', 'george')
hosts = ('b33f.net', 'google.com', 'brah.com')
channels = ('fortress.uk.scud', 'fortress.uk.ea')
for i in range(1000):
name = choice(names)
user = '%s!~%s@%s' % (name, name, choice(hosts),) # Format a irc 'user/host'
m = Message(user, choice(channels), generate_lorem_ipsum(1, html=False, min=5, max=25))
db_session.add(m)
db_session.commit()
# Create admins:
admins = ('WeiGonChi!~seph@miaows.eu', 'doobeh!~quassel@b33f.net')
[db_session.add(Admin(u)) for u in admins]
db_session.commit()
flash("Data loaded")
return redirect(url_for('index'))
#@app.teardown_request
#def shutdown_session(exception=None):
# db_session.remove()
if __name__ == "__main__":
app.run()