Skip to content

Commit 926659b

Browse files
authored
Merge pull request #904 from ronreiter/general-server-hardening
General server hardening + wire up new sites
2 parents 0e1526f + d078db5 commit 926659b

18 files changed

Lines changed: 228 additions & 46 deletions

constants.py

Lines changed: 72 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
LEARNSOLIDITY_DOMAIN = "learnsolidity.org"
1919
LEARNSQL_DOMAIN = "learnsqlonline.org"
2020
LEARNTS_DOMAIN = "learn-ts.org"
21+
LEARNRUST_DOMAIN = "learnrust.org"
22+
LEARNASSEMBLY_DOMAIN = "learnassembly.org"
2123

2224

2325
from collections import OrderedDict
@@ -414,22 +416,76 @@ def main(args: Array[String]) {
414416
""",
415417
}
416418

417-
# DOMAIN_DATA[LEARNSOLIDITY_DOMAIN] = {
418-
# "language" : "solidity",
419-
# "codemirror_mode": "text/x-solidity",
420-
# "prism_mode": "language-solidity",
421-
# "analytics" : "UA-22741967-15",
422-
# "language_uppercase" : "Solidity",
423-
# "default_code" : """// Welcome to the Interactive Solidity Tutorial.
424-
# // Start by choosing a chapter, write your code in this window.
425-
#
426-
# """,
427-
# "container_word" : "",
428-
# "container_indent" : "",
429-
# "container" : """
430-
# """,
431-
#
432-
# }
419+
DOMAIN_DATA[LEARNSOLIDITY_DOMAIN] = {
420+
"language" : "solidity",
421+
"codemirror_mode": "text/x-solidity",
422+
"prism_mode": "language-solidity",
423+
"analytics" : "UA-22741967-15",
424+
"language_uppercase" : "Solidity",
425+
"default_code" : """// Welcome to the Interactive Solidity Tutorial.
426+
// Start by choosing a chapter, write your code in this window.
427+
428+
""",
429+
"container_word" : "",
430+
"container_indent" : "",
431+
"container" : """
432+
""",
433+
434+
}
435+
436+
DOMAIN_DATA[LEARNASSEMBLY_DOMAIN] = {
437+
"language" : "assembly",
438+
"language_id": 13,
439+
"codemirror_mode": "text/x-gas",
440+
"prism_mode": "language-asm6502",
441+
"analytics" : "UA-22741967-17",
442+
"language_uppercase" : "Assembly",
443+
"default_code" : """; Welcome to the Interactive Assembly Tutorial.
444+
; Start by choosing a chapter, write your code in this window.
445+
446+
section .data
447+
msg db 'Hello, World!', 0xa
448+
len equ $ - msg
449+
450+
section .text
451+
global _start
452+
_start:
453+
mov rax, 1
454+
mov rdi, 1
455+
mov rsi, msg
456+
mov rdx, len
457+
syscall
458+
mov rax, 60
459+
xor rdi, rdi
460+
syscall
461+
""",
462+
"container_word" : "",
463+
"container_indent" : "",
464+
"container" : """
465+
""",
466+
467+
}
468+
469+
DOMAIN_DATA[LEARNRUST_DOMAIN] = {
470+
"language" : "rust",
471+
"language_id": 44,
472+
"codemirror_mode": "text/x-rust",
473+
"prism_mode": "language-rust",
474+
"analytics" : "UA-22741967-18",
475+
"language_uppercase" : "Rust",
476+
"default_code" : """// Welcome to the Interactive Rust Tutorial.
477+
// Start by choosing a chapter, write your code in this window.
478+
479+
fn main() {
480+
println!("Hello, World!");
481+
}
482+
""",
483+
"container_word" : "",
484+
"container_indent" : "",
485+
"container" : """
486+
""",
487+
488+
}
433489

434490
DOMAIN_DATA[LEARNSQL_DOMAIN] = {
435491
"language" : "sql",

main.py

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
app.secret_key = constants.SECRET_KEY
2828

2929
sections = re.compile(r"Tutorial\n[=\-]+\n+(.*)\n*Tutorial Code\n[=\-]+\n+(.*)\n*Expected Output\n[=\-]+\n+(.*)\n*Solution\n[=\-]+\n*(.*)\n*", re.MULTILINE | re.DOTALL)
30-
WIKI_WORD_PATTERN = re.compile('\[\[([^]|]+\|)?([^]]+)\]\]')
30+
WIKI_WORD_PATTERN = re.compile(r'\[\[([^]|]+\|)?([^]]+)\]\]')
3131

3232
current_domain = os.environ.get("DEFAULT_DOMAIN", constants.LEARNPYTHON_DOMAIN)
3333

@@ -161,9 +161,13 @@ def init_tutorials():
161161

162162
tutorials = os.listdir(tutorials_path)
163163

164-
# place the index file first
165-
tutorials.remove("Welcome.md")
166-
tutorials = ["Welcome.md"] + tutorials
164+
# place the index file first; tolerate a missing Welcome.md
165+
if "Welcome.md" in tutorials:
166+
tutorials.remove("Welcome.md")
167+
tutorials = ["Welcome.md"] + tutorials
168+
else:
169+
logging.warning("No Welcome.md for domain %s language %s", domain, language)
170+
tutorials.sort()
167171
for tutorial_file in tutorials:
168172
if not tutorial_file.endswith(".md"):
169173
continue
@@ -326,35 +330,12 @@ def static_file():
326330

327331
@app.route("/signin")
328332
def signin():
329-
email = request.args.get("email", None)
330-
password = request.args.get("password", None)
331-
user = users.findOne({"email": email})
332-
333-
if user:
334-
session["user_id"] = str(user._id)
335-
return make_response(json.dumps({"status": "error", "error": "no_user"}))
333+
# No user store exists in this repository; these endpoints were non-functional.
334+
return make_response(json.dumps({"status": "error", "error": "not_implemented"}), 501)
336335

337336
@app.route("/signup")
338337
def signup():
339-
email = request.args.get("email", None)
340-
password = request.args.get("password", None)
341-
confirm = request.args.get("confirm", None)
342-
343-
if not email or not password or not confirm:
344-
return make_response(json.dumps({"status": "error", "error": "missing_field"}))
345-
346-
if not re.findall("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", email):
347-
return make_response(json.dumps({"status": "error", "error": "invalid_email"}))
348-
349-
if password != confirm:
350-
return make_response(json.dumps({"status": "error", "error": "passwords_dont_match"}))
351-
352-
id = users.insert({
353-
"email": email,
354-
"password": password,
355-
})
356-
357-
session["user_id"] = str(id)
338+
return make_response(json.dumps({"status": "error", "error": "not_implemented"}), 501)
358339

359340

360341
@app.route("/<language>/progress")

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ python-geoip = "^1.2"
1515

1616
[tool.poetry.group.dev.dependencies]
1717
openai = "^1.58.1"
18+
pytest = "^7.4.0"
1819

1920
[build-system]
2021
requires = ["poetry-core"]
33.7 KB
Binary file not shown.
33.7 KB
Binary file not shown.
33.7 KB
Binary file not shown.
6.5 KB
Loading

static/img/logos/learnrust.org.png

6.5 KB
Loading
6.94 KB
Loading
6.94 KB
Loading

0 commit comments

Comments
 (0)