Skip to content

Commit 4a12316

Browse files
committed
initial import
0 parents  commit 4a12316

File tree

11 files changed

+5035
-0
lines changed

11 files changed

+5035
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*~
2+
*.pyc

COPYING

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
phpbb-python © Copyright 2010 Santtu Pajukanta
2+
http://pajukanta.fi
3+
4+
phpBB3 © Copyright 2000, 2002, 2005, 2007 phpBB Group
5+
http://www.phpbb.com
6+
7+
This program is free software: you can redistribute it and/or modify
8+
it under the terms of the GNU General Public License as published by
9+
the Free Software Foundation, version 2 of the License.
10+
11+
This program is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
GNU General Public License for more details.
15+
16+
You should have received a copy of the GNU General Public License
17+
along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>.
18+

LICENSE

Lines changed: 339 additions & 0 deletions
Large diffs are not rendered by default.

bin/process_confusables.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/usr/bin/env python
2+
# encoding: utf-8
3+
# vim: shiftwidth=4 expandtab
4+
#
5+
# phpbb-python © Copyright 2010 Santtu Pajukanta
6+
# http://pajukanta.fi
7+
#
8+
# This program is free software: you can redistribute it and/or modify
9+
# it under the terms of the GNU General Public License as published by
10+
# the Free Software Foundation, version 2 or later of the License.
11+
#
12+
# This program is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU General Public License for more details.
16+
#
17+
# You should have received a copy of the GNU General Public License
18+
# along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>.
19+
#
20+
21+
import sys
22+
from pprint import pprint
23+
24+
STARTS_WITH = '<?php return array('
25+
ENDS_WITH = ');'
26+
27+
HEADER = """
28+
#
29+
# WARNING! AUTOGENERATED FROM phpBB3/includes/utf/data/confusables.php
30+
# DO NOT EDIT MANUALLY!
31+
#
32+
# Use phpbb-python/bin/process_confusables.py instead.
33+
#
34+
35+
confusables = """
36+
37+
def parse_character(char):
38+
if not (char.startswith("'") and char.endswith("'")):
39+
raise ValueError(char)
40+
41+
return char[1:-1].decode("UTF-8")
42+
43+
def parse_confusables(input_file):
44+
data = input_file.read()
45+
46+
if not (data.startswith(STARTS_WITH) and data.endswith(ENDS_WITH)):
47+
raise ValueError
48+
49+
data = data[len(STARTS_WITH):-len(ENDS_WITH)]
50+
51+
for pair in data.split(','):
52+
try:
53+
before, after = pair.split('=>')
54+
except ValueError:
55+
continue
56+
57+
before = parse_character(before)
58+
after = parse_character(after)
59+
60+
yield (before, after)
61+
62+
def print_confusables(confusables, output_file):
63+
if type(confusables) is not dict:
64+
confusables = dict(confusables)
65+
66+
output_file.write(HEADER)
67+
pprint(confusables, stream=output_file)
68+
69+
def main(input_filename, output_filename):
70+
with open(output_filename, 'wb') as output_file:
71+
with open(input_filename, 'rb') as input_file:
72+
print_confusables(parse_confusables(input_file), output_file)
73+
74+
if __name__ == "__main__":
75+
main(*sys.argv[1:])

phpbb/__init__.py

Whitespace-only changes.

phpbb/auth/auth_db.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# encoding: utf-8
2+
# vim: shiftwidth=4 expandtab
3+
#
4+
# phpbb-python © Copyright 2010 Santtu Pajukanta
5+
# http://pajukanta.fi
6+
#
7+
# phpBB3 © Copyright 2000, 2002, 2005, 2007 phpBB Group
8+
# http://www.phpbb.com
9+
#
10+
# This program is free software: you can redistribute it and/or modify
11+
# it under the terms of the GNU General Public License as published by
12+
# the Free Software Foundation, version 2 of the License.
13+
#
14+
# This program is distributed in the hope that it will be useful,
15+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
# GNU General Public License for more details.
18+
#
19+
# You should have received a copy of the GNU General Public License
20+
# along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>.
21+
#
22+
23+
from phpbb.auth.sql import get_user_row
24+
from phpbb.utf.utf_tools import utf8_clean_string
25+
from phpbb.functions import phpbb_check_hash
26+
27+
def login_db(username=None, password=None):
28+
if not username:
29+
return "NO_USERNAME_SUPPLIED", None
30+
31+
if not password:
32+
return "NO_PASSWORD_SUPPLIED", None
33+
34+
if type(username) is unicode:
35+
username = username.encode("UTF-8")
36+
37+
user_row = get_user_row(utf8_clean_string(username))
38+
if not user_row:
39+
return "LOGIN_ERROR_USERNAME", None
40+
41+
if phpbb_check_hash(password, user_row["user_password"]):
42+
if user_row["user_type"] in (USER_INACTIVE, USER_IGNORE):
43+
return "LOGIN_ERROR_ACTIVE", user_row
44+
45+
return "LOGIN_SUCCESS", user_row
46+
47+
return "LOGIN_ERROR_PASSWORD", user_row
48+

phpbb/auth/backends.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# encoding: utf-8
2+
# vim: shiftwidth=4 expandtab
3+
#
4+
# phpbb-python © Copyright 2010 Santtu Pajukanta
5+
# http://pajukanta.fi
6+
#
7+
# This program is free software: you can redistribute it and/or modify
8+
# it under the terms of the GNU General Public License as published by
9+
# the Free Software Foundation, version 2 of the License.
10+
#
11+
# This program is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU General Public License
17+
# along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>.
18+
#
19+
20+
from django.contrib.auth.models import User
21+
22+
from phpbb.auth.auth_db import login_db
23+
24+
class PhpbbBackend:
25+
def authenticate(self, username=None, password=None):
26+
if username is None or password is None:
27+
return None
28+
29+
status, user_row = login_db(username, password)
30+
if status != "LOGIN_SUCCESS":
31+
return None
32+
33+
user, created = User.objects.get_or_create(
34+
username=user_row["username_clean"],
35+
email=user_row.get("user_email", None)
36+
)
37+
38+
return user
39+

phpbb/functions.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# encoding: utf-8
2+
# vim: shiftwidth=4 expandtab
3+
#
4+
# phpbb-python © Copyright 2010 Santtu Pajukanta
5+
# http://pajukanta.fi
6+
#
7+
# phpBB3 © Copyright 2000, 2002, 2005, 2007 phpBB Group
8+
# http://www.phpbb.com
9+
#
10+
# This program is free software: you can redistribute it and/or modify
11+
# it under the terms of the GNU General Public License as published by
12+
# the Free Software Foundation, version 2 of the License.
13+
#
14+
# This program is distributed in the hope that it will be useful,
15+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
# GNU General Public License for more details.
18+
#
19+
# You should have received a copy of the GNU General Public License
20+
# along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>.
21+
#
22+
23+

phpbb/utf/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)