Skip to content

Commit 054bde9

Browse files
authored
update to conform with flake8/PEP8 | #47 (#50)
1 parent b59cfa2 commit 054bde9

File tree

17 files changed

+230
-131
lines changed

17 files changed

+230
-131
lines changed

.lgtm.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
queries:
22
- exclude: py/similar-function
33
- exclude: py/empty-except
4+
- exclude: py/call-to-non-callable
45
- include: py/undefined-placeholder-variable
56
- include: py/uninitialized-local-variable
67
- include: py/request-without-cert-validation

.pylintrc

Lines changed: 0 additions & 7 deletions
This file was deleted.

.travis.yml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
---
22
env: SKIP_INTERPRETER=true
33

4-
branches:
5-
only:
6-
- master
4+
#branches:
5+
# only:
6+
# - master
77

88
language: python
99
python:
10-
- "3.7.3"
11-
- "3.8.1"
10+
- "3.8.2"
1211

1312
env:
1413
global:
@@ -20,9 +19,7 @@ before_install:
2019

2120
install:
2221
- "pip install -r src/requirements.txt"
23-
- pip install --no-cache-dir pytest-flake8
2422
- "python src/create_db.py"
2523

26-
2724
script:
28-
- pytest --lint-only --flake8
25+
- pytest --flake8

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ The main purpose of this project is to serve as a scoring engine and CTF manager
5050

5151
### Requirements
5252

53-
* `Python 3.7.3` or atleast `> 3.6`.
53+
* Tested on `Python 3.8.2`
5454
* Python Packages: [`src/requirements.txt`](src/requirements.txt).
5555
* OS Packages: PostgreSQL version 11 or greater, `libpq-dev`, `python3-dev` packages. Please refer [here](https://tutorials.technology/solved_errors/9-Error-pg_config-executable-not-found.html).
5656

@@ -138,41 +138,41 @@ Bonus: You can manage the database CRUD operations from admin views GUI as well
138138
</a>
139139
</p>
140140

141-
Please see: [Issues](https://github.com/abs0lut3pwn4g3/RTB-CTF-Framework/issues) and the below To-do list.
141+
Keeping to a consistent code style throughout the project makes it easier to contribute and collaborate. Please stick to the guidelines in PEP8 and the Google Style Guide unless there’s a very good reason not to.
142+
Please see: [Issues](https://github.com/abs0lut3pwn4g3/RTB-CTF-Framework/issues) and the following To-do list.
142143

143144
> Note: All PRs within the GSSoC'20 period will be merged in the `gssoc20-dev` branch.
144145
145-
#### 👨 Project Owner
146+
##### 👨 Project Owner
146147

147148
- Eshaan Bansal ([github](https://github.com/eshaan7),[linkedin](https://www.linkedin.com/in/eshaan7/))
148149

149-
#### 👬 Mentors
150+
##### 👬 Mentors
150151

151152
- Sombuddha Chakravarty ([github](https://github.com/sammy1997),[linkedin](https://www.linkedin.com/in/sombuddha-chakravarty-9482b5131/))
152153

153154
Feel free to ask your queries!! 🙌
154155

155-
#### Slack Channel
156+
##### Slack Channel
156157

157158
- [#proj_root-the-box-ctf-framework](https://app.slack.com/client/TRN1H1V43/CUC71PDD2)
158159

159-
160160
## To-do
161161

162-
- [ ] Freeze Scoreboard automatically past running time specified (Issue: [#3](https://github.com/abs0lut3pwn4g3/RTB-CTF-Framework/issues/3))
163162
- [ ] Ideas for additional logging techniques to prevent flag sharing, cheating and such. (Issue: [#7](https://github.com/abs0lut3pwn4g3/RTB-CTF-Framework/issues/7))
164163
- [ ] Support for *n* number of boxes (accordions? seperate route?). (Issue: [#17](https://github.com/abs0lut3pwn4g3/RTB-CTF-Framework/issues/17))
165164
- [ ] Rating system: Average Box rating - input, calculate, output. (Issue: [#14](https://github.com/abs0lut3pwn4g3/RTB-CTF-Framework/issues/14))
166-
- [ ] Adding a `Deploy to Heroku` button. (Issue: [#15](https://github.com/abs0lut3pwn4g3/RTB-CTF-Framework/issues/15))
167165
- [ ] Dark theme for `admin control` panel. (Issue: [#16](https://github.com/abs0lut3pwn4g3/RTB-CTF-Framework/issues/16))
168-
- [ ] Adding CI, Linting, Formatting specs. (Issue: [#18](https://github.com/abs0lut3pwn4g3/RTB-CTF-Framework/issues/18))
169166
- [ ] Testing Password reset functionality, the mail-server setup, etc.
170167
- [ ] More info on `home.html`
171168
- [ ] Support for more hashes per box (not a priority)
172169
- [ ] Need to implement `account.html` (not a priority)
173170

174171
<hr/>
175172

173+
- [x] Freeze Scoreboard automatically past running time specified (Issue: [#3](https://github.com/abs0lut3pwn4g3/RTB-CTF-Framework/issues/3))
174+
- [x] Adding a `Deploy to Heroku` button. (Issue: [#15](https://github.com/abs0lut3pwn4g3/RTB-CTF-Framework/issues/15))
175+
- [x] Adding CI, Linting, Formatting specs. (Issue: [#18](https://github.com/abs0lut3pwn4g3/RTB-CTF-Framework/issues/18))
176176
- [x] db relationship between User and Score Tables (priority | issue: #5)
177177
- [x] isAdmin column in User table and Admin views (priority)
178178
- [x] Notifications

src/FlaskRTBCTF/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ def create_app(config_class=Config):
3838
mail.init_app(app)
3939

4040
from flask_sslify import SSLify
41-
if 'DYNO' in os.environ: # only trigger SSLify if the app is running on Heroku
42-
_sslify = SSLify(app)
41+
# only trigger SSLify if the app is running on Heroku
42+
if 'DYNO' in os.environ:
43+
_ = SSLify(app)
4344

4445
from FlaskRTBCTF.users.routes import users
4546
from FlaskRTBCTF.ctf.routes import ctf

src/FlaskRTBCTF/admin/views.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
from flask_login import current_user
55
from flask_admin.contrib.sqla import ModelView
66

7+
78
class MyModelView(ModelView):
89

9-
column_exclude_list = ( 'password' )
10+
column_exclude_list = ('password',)
1011

1112
def is_accessible(self):
1213
if not current_user.is_authenticated or not current_user.isAdmin:
13-
# permission denied
14-
abort(403)
14+
# permission denied
15+
abort(403)
1516
if current_user.isAdmin:
1617
return True
1718
return False
@@ -23,5 +24,5 @@ def _handle_view(self, name, **kwargs):
2324
"""
2425
if not self.is_accessible():
2526
if current_user.is_authenticated:
26-
#permission denied
27+
# permission denied
2728
abort(403)

src/FlaskRTBCTF/config.py

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,54 +3,58 @@
33
import pytz
44

55

6-
''' Flask related Configurations. Note: DO NOT FORGET TO CHANGE 'SECRET_KEY' ! '''
6+
''' Flask related Configurations
7+
Note: DO NOT FORGET TO CHANGE 'SECRET_KEY' ! '''
78

89

910
class Config:
10-
SECRET_KEY = os.environ.get('SECRET_KEY') or 'you-will-never-guess'
11-
SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL') or 'sqlite:///site.db'
12-
# For local use, one can simply use SQLlite with: 'sqlite:///site.db'
13-
# For deployment on Heroku use: `os.environ.get('DATABASE_URL')`
11+
SECRET_KEY = os.environ.get('SECRET_KEY') or 'you-will-never-guess'
12+
SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL') \
13+
or 'sqlite:///site.db'
14+
# For local use, one can simply use SQLlite with: 'sqlite:///site.db'
15+
# For deployment on Heroku use: `os.environ.get('DATABASE_URL')`
1416
# in all other cases: `os.environ.get('SQLALCHEMY_DATABASE_URI')`
15-
SQLALCHEMY_TRACK_MODIFICATIONS = False
16-
DEBUG = False # Turn DEBUG OFF before deployment
17+
SQLALCHEMY_TRACK_MODIFICATIONS = False
18+
DEBUG = False # Turn DEBUG OFF before deployment
1719
MAIL_SERVER = 'smtp.googlemail.com'
1820
MAIL_PORT = 587
1921
MAIL_USE_TLS = True
2022
MAIL_USERNAME = os.environ.get('EMAIL_USER')
2123
MAIL_PASSWORD = os.environ.get('EMAIL_PASS')
2224

25+
2326
''' CTF related Configuration '''
2427

28+
2529
# Add some information about organization and specify CTF name
2630

2731
organization = {
2832
"ctfname": "RootTheBox CTF",
2933
"name": "Abs0lut3Pwn4g3",
30-
"website": {
34+
"website": {
3135
"url": "https://Abs0lut3Pwn4g3.github.io/",
3236
"name": "Official Abs0lut3Pwn4g3 Website"
33-
},
34-
"website_2": {
37+
},
38+
"website_2": {
3539
"url": "https://twitter.com/abs0lut3pwn4g3",
3640
"name": "Twitter"
37-
},
38-
"website_3": {
41+
},
42+
"website_3": {
3943
"url": "https://github.com/abs0lut3pwn4g3",
4044
"name": "Github"
4145
}
42-
}
46+
}
4347

4448
# Specify CTFs Running Time
4549

46-
RunningTime = {
47-
"from": datetime(2019,7,7,15,00,00,0, pytz.utc),
48-
"to": datetime(2030,7,8,0,00,00,0, pytz.utc),
50+
RunningTime = {
51+
"from": datetime(2019, 7, 7, 15, 00, 00, 0, pytz.utc),
52+
"to": datetime(2030, 7, 8, 0, 00, 00, 0, pytz.utc),
4953
"TimeZone": "UTC"
50-
} # We do not recommend changing the Timezone.
54+
} # We do not recommend changing the Timezone.
5155

5256
# Logging: Set to 'True' to enable Logging in Admin Views.
5357

54-
LOGGING = True # We recommend to leave it on. It is more than just errors ;)
58+
LOGGING = True # We recommend to leave it on. It is more than just errors ;)
5559

5660
# NOTE: CHANGE DEFAULT ADMIN CREDENTIALS in create_db.py !!!

src/FlaskRTBCTF/ctf/forms.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,22 @@
22
from wtforms import StringField, SubmitField
33
from wtforms.validators import DataRequired, Length
44

5+
56
class UserHashForm(FlaskForm):
6-
userHash = StringField('User hash', validators=[DataRequired(), Length(min=32, max=32)])
7+
userHash = StringField('User hash',
8+
validators=[
9+
DataRequired(),
10+
Length(min=32, max=32)
11+
]
12+
)
713
submit = SubmitField('Submit')
814

15+
916
class RootHashForm(FlaskForm):
10-
rootHash = StringField('Root hash', validators=[DataRequired(), Length(min=32, max=32)])
11-
submit = SubmitField('Submit')
17+
rootHash = StringField('Root hash',
18+
validators=[
19+
DataRequired(),
20+
Length(min=32, max=32)
21+
]
22+
)
23+
submit = SubmitField('Submit')

src/FlaskRTBCTF/ctf/routes.py

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
from FlaskRTBCTF import db
1010
from FlaskRTBCTF.config import organization, LOGGING, RunningTime
1111
from FlaskRTBCTF.models import User, Score, Machine
12+
from FlaskRTBCTF.ctf.forms import UserHashForm, RootHashForm
13+
1214
if LOGGING:
1315
from FlaskRTBCTF.models import Logs
14-
from FlaskRTBCTF.ctf.forms import UserHashForm, RootHashForm
1516

1617

1718
ctf = Blueprint('ctf', __name__)
@@ -27,11 +28,12 @@ def scoreboard():
2728
userNameScoreList = []
2829
for score in scores:
2930
userNameScoreList.append({
30-
'username': User.query.get(score.user_id).username,
31-
'score' :score.points
31+
'username': User.query.get(score.user_id).username,
32+
'score': score.points
3233
})
3334

34-
return render_template('scoreboard.html', scores=userNameScoreList, organization=organization)
35+
return render_template('scoreboard.html', scores=userNameScoreList,
36+
organization=organization)
3537

3638

3739
''' Machine Info '''
@@ -40,19 +42,21 @@ def scoreboard():
4042
@ctf.route("/machine")
4143
@login_required
4244
def machine():
43-
box = Machine.query.filter(Machine.ip=="127.0.0.1").first()
45+
box = Machine.query.filter(Machine.ip == "127.0.0.1").first()
4446
if LOGGING:
4547
log = Logs.query.get(current_user.id)
4648
if log.visitedMachine is False:
4749
log.visitedMachine = True
48-
log.machineVisitTime = datetime.now(pytz.utc)
50+
log.machineVisitTime = datetime.utcnow()
4951
db.session.commit()
5052
userHashForm = UserHashForm()
5153
rootHashForm = RootHashForm()
5254
end_date_time = RunningTime["to"]
5355
current_date_time = datetime.now(pytz.utc)
5456
return render_template('machine.html', userHashForm=userHashForm,
55-
rootHashForm=rootHashForm, organization=organization, box=box, current=current_date_time, end=end_date_time)
57+
rootHashForm=rootHashForm,
58+
organization=organization, box=box,
59+
current=current_date_time, end=end_date_time)
5660

5761

5862
''' Hash Submission Management '''
@@ -61,12 +65,12 @@ def machine():
6165
@ctf.route("/validateRootHash", methods=['POST'])
6266
@login_required
6367
def validateRootHash():
64-
box = Machine.query.filter(Machine.ip=="127.0.0.1").first()
68+
box = Machine.query.filter(Machine.ip == "127.0.0.1").first()
6569
userHashForm = UserHashForm()
6670
rootHashForm = RootHashForm()
6771
end_date_time = RunningTime["to"]
6872
current_date_time = datetime.now(pytz.utc)
69-
if rootHashForm.validate_on_submit():
73+
if rootHashForm.validate_on_submit():
7074
if current_date_time > end_date_time:
7175
flash("Sorry! Contest has ended", "danger")
7276
elif rootHashForm.rootHash.data == box.root_hash:
@@ -80,28 +84,34 @@ def validateRootHash():
8084
if LOGGING:
8185
log = Logs.query.get(current_user.id)
8286
log.rootSubmissionIP = request.access_route[0]
83-
log.rootSubmissionTime = datetime.now(pytz.utc)
84-
log.rootOwnTime = str(log.rootSubmissionTime - log.machineVisitTime)
87+
log.rootSubmissionTime = datetime.utcnow()
88+
log.rootOwnTime = str(
89+
log.rootSubmissionTime - log.machineVisitTime
90+
)
8591
db.session.commit()
8692
flash("Congrats! correct system hash.", "success")
8793
else:
8894
flash("Sorry! Wrong system hash", "danger")
8995
return render_template('machine.html', userHashForm=userHashForm,
90-
rootHashForm=rootHashForm, organization=organization, box=box, current=current_date_time, end=end_date_time)
96+
rootHashForm=rootHashForm, box=box,
97+
organization=organization,
98+
current=current_date_time, end=end_date_time)
9199
else:
92100
return render_template('machine.html', userHashForm=userHashForm,
93-
rootHashForm=rootHashForm, organization=organization, box=box, current=current_date_time, end=end_date_time)
101+
rootHashForm=rootHashForm, box=box,
102+
organization=organization,
103+
current=current_date_time, end=end_date_time)
94104

95105

96106
@ctf.route("/validateUserHash", methods=['POST'])
97107
@login_required
98108
def validateUserHash():
99-
box = Machine.query.filter(Machine.ip=="127.0.0.1").first()
109+
box = Machine.query.filter(Machine.ip == "127.0.0.1").first()
100110
userHashForm = UserHashForm()
101111
rootHashForm = RootHashForm()
102112
end_date_time = RunningTime["to"]
103-
current_date_time =datetime.now(pytz.utc)
104-
if userHashForm.validate_on_submit():
113+
current_date_time = datetime.now(pytz.utc)
114+
if userHashForm.validate_on_submit():
105115
if current_date_time > end_date_time:
106116
flash("Sorry! Contest has ended", "danger")
107117
elif userHashForm.userHash.data == box.user_hash:
@@ -115,16 +125,20 @@ def validateUserHash():
115125
if LOGGING:
116126
log = Logs.query.get(current_user.id)
117127
log.userSubmissionIP = request.access_route[0]
118-
log.userSubmissionTime = datetime.now(pytz.utc)
119-
log.userOwnTime = str(log.userSubmissionTime - log.machineVisitTime)
128+
log.userSubmissionTime = datetime.utcnow()
129+
log.userOwnTime = str(
130+
log.userSubmissionTime - log.machineVisitTime
131+
)
120132
db.session.commit()
121133
flash("Congrats! correct user hash.", "success")
122134
else:
123135
flash("Sorry! Wrong user hash", "danger")
124136
return render_template('machine.html', userHashForm=userHashForm,
125-
rootHashForm=rootHashForm, organization=organization, box=box, current=current_date_time, end=end_date_time)
137+
rootHashForm=rootHashForm,
138+
organization=organization, box=box,
139+
current=current_date_time, end=end_date_time)
126140
else:
127141
return render_template('machine.html', userHashForm=userHashForm,
128-
rootHashForm=rootHashForm, organization=organization, box=box, current=current_date_time, end=end_date_time)
129-
130-
142+
rootHashForm=rootHashForm,
143+
organization=organization, box=box,
144+
current=current_date_time, end=end_date_time)

0 commit comments

Comments
 (0)