Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
D
douban-api-proxy
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
captainwong
douban-api-proxy
Commits
572b5427
Commit
572b5427
authored
Jun 23, 2019
by
Ozzieisaacs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix Encoding issues for python2
parent
32af660f
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
5182 additions
and
1057 deletions
+5182
-1057
cps.py
cps.py
+6
-2
__init__.py
cps/__init__.py
+9
-3
admin.py
cps/admin.py
+2
-2
cli.py
cps/cli.py
+12
-0
constants.py
cps/constants.py
+6
-1
db.py
cps/db.py
+1
-1
ldap_login.py
cps/ldap_login.py
+2
-1
opds.py
cps/opds.py
+3
-12
server.py
cps/server.py
+1
-1
ub.py
cps/ub.py
+1
-7
web.py
cps/web.py
+5
-5
worker.py
cps/worker.py
+2
-0
Calibre-Web TestSummary.html
test/Calibre-Web TestSummary.html
+5132
-1022
No files found.
cps.py
View file @
572b5427
...
@@ -23,8 +23,12 @@ import os
...
@@ -23,8 +23,12 @@ import os
# Insert local directories into path
# Insert local directories into path
sys
.
path
.
append
(
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
)))
if
sys
.
version_info
<
(
3
,
0
):
sys
.
path
.
append
(
os
.
path
.
join
(
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
)),
'vendor'
))
sys
.
path
.
append
(
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
.
decode
(
'utf-8'
))))
sys
.
path
.
append
(
os
.
path
.
join
(
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
.
decode
(
'utf-8'
))),
'vendor'
))
else
:
sys
.
path
.
append
(
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
)))
sys
.
path
.
append
(
os
.
path
.
join
(
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
)),
'vendor'
))
from
cps
import
create_app
from
cps
import
create_app
...
...
cps/__init__.py
View file @
572b5427
...
@@ -87,8 +87,8 @@ global_WorkerThread = WorkerThread()
...
@@ -87,8 +87,8 @@ global_WorkerThread = WorkerThread()
from
.server
import
WebServer
from
.server
import
WebServer
web_server
=
WebServer
()
web_server
=
WebServer
()
from
.ldap
import
Ldap
from
.ldap
_login
import
Ldap
ldap
=
Ldap
()
ldap
1
=
Ldap
()
babel
=
Babel
()
babel
=
Babel
()
...
@@ -97,6 +97,12 @@ log = logger.create()
...
@@ -97,6 +97,12 @@ log = logger.create()
def
create_app
():
def
create_app
():
app
.
wsgi_app
=
ReverseProxied
(
app
.
wsgi_app
)
app
.
wsgi_app
=
ReverseProxied
(
app
.
wsgi_app
)
# For python2 convert path to unicode
if
sys
.
version_info
<
(
3
,
0
):
app
.
static_folder
=
app
.
static_folder
.
decode
(
'utf-8'
)
app
.
root_path
=
app
.
root_path
.
decode
(
'utf-8'
)
app
.
instance_path
=
app
.
instance_path
.
decode
(
'utf-8'
)
cache_buster
.
init_cache_busting
(
app
)
cache_buster
.
init_cache_busting
(
app
)
log
.
info
(
'Starting Calibre Web...'
)
log
.
info
(
'Starting Calibre Web...'
)
...
@@ -106,7 +112,7 @@ def create_app():
...
@@ -106,7 +112,7 @@ def create_app():
web_server
.
init_app
(
app
,
config
)
web_server
.
init_app
(
app
,
config
)
db
.
setup_db
()
db
.
setup_db
()
babel
.
init_app
(
app
)
babel
.
init_app
(
app
)
ldap
.
init_app
(
app
)
ldap
1
.
init_app
(
app
)
global_WorkerThread
.
start
()
global_WorkerThread
.
start
()
return
app
return
app
...
...
cps/admin.py
View file @
572b5427
...
@@ -40,7 +40,7 @@ from sqlalchemy import and_
...
@@ -40,7 +40,7 @@ from sqlalchemy import and_
from
sqlalchemy.exc
import
IntegrityError
from
sqlalchemy.exc
import
IntegrityError
from
werkzeug.security
import
generate_password_hash
from
werkzeug.security
import
generate_password_hash
from
.
import
constants
,
logger
,
ldap
from
.
import
constants
,
logger
,
ldap
1
from
.
import
db
,
ub
,
web_server
,
get_locale
,
config
,
updater_thread
,
babel
,
gdriveutils
from
.
import
db
,
ub
,
web_server
,
get_locale
,
config
,
updater_thread
,
babel
,
gdriveutils
from
.helper
import
speaking_language
,
check_valid_domain
,
check_unrar
,
send_test_mail
,
generate_random_password
,
\
from
.helper
import
speaking_language
,
check_valid_domain
,
check_unrar
,
send_test_mail
,
generate_random_password
,
\
send_registration_mail
send_registration_mail
...
@@ -48,7 +48,7 @@ from .gdriveutils import is_gdrive_ready, gdrive_support, downloadFile, deleteDa
...
@@ -48,7 +48,7 @@ from .gdriveutils import is_gdrive_ready, gdrive_support, downloadFile, deleteDa
from
.web
import
admin_required
,
render_title_template
,
before_request
,
unconfigured
,
login_required_if_no_ano
from
.web
import
admin_required
,
render_title_template
,
before_request
,
unconfigured
,
login_required_if_no_ano
feature_support
=
dict
()
feature_support
=
dict
()
feature_support
[
'ldap'
]
=
ldap
.
ldap_supported
()
feature_support
[
'ldap'
]
=
ldap
1
.
ldap_supported
()
try
:
try
:
from
goodreads.client
import
GoodreadsClient
from
goodreads.client
import
GoodreadsClient
...
...
cps/cli.py
View file @
572b5427
...
@@ -82,6 +82,18 @@ parser.add_argument('-i', metavar='ip-adress', help='Server IP-Adress to listen'
...
@@ -82,6 +82,18 @@ parser.add_argument('-i', metavar='ip-adress', help='Server IP-Adress to listen'
parser
.
add_argument
(
'-s'
,
metavar
=
'user:pass'
,
help
=
'Sets specific username to new password'
)
parser
.
add_argument
(
'-s'
,
metavar
=
'user:pass'
,
help
=
'Sets specific username to new password'
)
args
=
parser
.
parse_args
()
args
=
parser
.
parse_args
()
if
sys
.
version_info
<
(
3
,
0
):
if
args
.
p
:
args
.
p
=
args
.
p
.
decode
(
'utf-8'
)
if
args
.
g
:
args
.
g
=
args
.
g
.
decode
(
'utf-8'
)
if
args
.
k
:
args
.
k
=
args
.
k
.
decode
(
'utf-8'
)
if
args
.
c
:
args
.
c
=
args
.
c
.
decode
(
'utf-8'
)
if
args
.
s
:
args
.
s
=
args
.
s
.
decode
(
'utf-8'
)
settingspath
=
args
.
p
or
os
.
path
.
join
(
_CONFIG_DIR
,
"app.db"
)
settingspath
=
args
.
p
or
os
.
path
.
join
(
_CONFIG_DIR
,
"app.db"
)
gdpath
=
args
.
g
or
os
.
path
.
join
(
_CONFIG_DIR
,
"gdrive.db"
)
gdpath
=
args
.
g
or
os
.
path
.
join
(
_CONFIG_DIR
,
"gdrive.db"
)
...
...
cps/constants.py
View file @
572b5427
...
@@ -24,7 +24,12 @@ from collections import namedtuple
...
@@ -24,7 +24,12 @@ from collections import namedtuple
# Base dir is parent of current file, necessary if called from different folder
# Base dir is parent of current file, necessary if called from different folder
BASE_DIR
=
os
.
path
.
abspath
(
os
.
path
.
join
(
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
)),
os
.
pardir
))
if
sys
.
version_info
<
(
3
,
0
):
BASE_DIR
=
os
.
path
.
abspath
(
os
.
path
.
join
(
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
)),
os
.
pardir
))
.
decode
(
'utf-8'
)
else
:
BASE_DIR
=
os
.
path
.
abspath
(
os
.
path
.
join
(
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
)),
os
.
pardir
))
STATIC_DIR
=
os
.
path
.
join
(
BASE_DIR
,
'cps'
,
'static'
)
STATIC_DIR
=
os
.
path
.
join
(
BASE_DIR
,
'cps'
,
'static'
)
TEMPLATES_DIR
=
os
.
path
.
join
(
BASE_DIR
,
'cps'
,
'templates'
)
TEMPLATES_DIR
=
os
.
path
.
join
(
BASE_DIR
,
'cps'
,
'templates'
)
TRANSLATIONS_DIR
=
os
.
path
.
join
(
BASE_DIR
,
'cps'
,
'translations'
)
TRANSLATIONS_DIR
=
os
.
path
.
join
(
BASE_DIR
,
'cps'
,
'translations'
)
...
...
cps/db.py
View file @
572b5427
...
@@ -342,7 +342,7 @@ def setup_db():
...
@@ -342,7 +342,7 @@ def setup_db():
try
:
try
:
if
not
os
.
path
.
exists
(
dbpath
):
if
not
os
.
path
.
exists
(
dbpath
):
raise
raise
engine
=
create_engine
(
'sqlite:///
'
+
dbpath
,
engine
=
create_engine
(
'sqlite:///
{0}'
.
format
(
dbpath
)
,
echo
=
False
,
echo
=
False
,
isolation_level
=
"SERIALIZABLE"
,
isolation_level
=
"SERIALIZABLE"
,
connect_args
=
{
'check_same_thread'
:
False
})
connect_args
=
{
'check_same_thread'
:
False
})
...
...
cps/ldap.py
→
cps/ldap
_login
.py
View file @
572b5427
...
@@ -16,10 +16,11 @@
...
@@ -16,10 +16,11 @@
# You should have received a copy of the GNU General Public License
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from
__future__
import
division
,
print_function
,
unicode_literals
import
base64
import
base64
try
:
try
:
from
flask_simpleldap
import
LDAP
,
LDAPException
from
flask_simpleldap
import
LDAP
#
, LDAPException
ldap_support
=
True
ldap_support
=
True
except
ImportError
:
except
ImportError
:
ldap_support
=
False
ldap_support
=
False
...
...
cps/opds.py
View file @
572b5427
...
@@ -31,7 +31,7 @@ from flask_login import current_user
...
@@ -31,7 +31,7 @@ from flask_login import current_user
from
sqlalchemy.sql.expression
import
func
,
text
,
or_
,
and_
from
sqlalchemy.sql.expression
import
func
,
text
,
or_
,
and_
from
werkzeug.security
import
check_password_hash
from
werkzeug.security
import
check_password_hash
from
.
import
logger
,
config
,
db
,
ub
,
ldap
from
.
import
logger
,
config
,
db
,
ub
,
ldap
1
from
.helper
import
fill_indexpage
,
get_download_link
,
get_book_cover
from
.helper
import
fill_indexpage
,
get_download_link
,
get_book_cover
from
.pagination
import
Pagination
from
.pagination
import
Pagination
from
.web
import
common_filters
,
get_search_results
,
render_read_books
,
download_required
from
.web
import
common_filters
,
get_search_results
,
render_read_books
,
download_required
...
@@ -40,14 +40,14 @@ from .web import common_filters, get_search_results, render_read_books, download
...
@@ -40,14 +40,14 @@ from .web import common_filters, get_search_results, render_read_books, download
opds
=
Blueprint
(
'opds'
,
__name__
)
opds
=
Blueprint
(
'opds'
,
__name__
)
log
=
logger
.
create
()
log
=
logger
.
create
()
ldap_support
=
ldap
.
ldap_supported
()
ldap_support
=
ldap
1
.
ldap_supported
()
def
requires_basic_auth_if_no_ano
(
f
):
def
requires_basic_auth_if_no_ano
(
f
):
@
wraps
(
f
)
@
wraps
(
f
)
def
decorated
(
*
args
,
**
kwargs
):
def
decorated
(
*
args
,
**
kwargs
):
if
config
.
config_login_type
==
1
and
ldap_support
:
if
config
.
config_login_type
==
1
and
ldap_support
:
return
ldap
.
ldap
.
basic_auth_required
(
*
args
,
**
kwargs
)
return
ldap
1
.
ldap
.
basic_auth_required
(
*
args
,
**
kwargs
)
auth
=
request
.
authorization
auth
=
request
.
authorization
if
config
.
config_anonbrowse
!=
1
:
if
config
.
config_anonbrowse
!=
1
:
if
not
auth
or
not
check_auth
(
auth
.
username
,
auth
.
password
):
if
not
auth
or
not
check_auth
(
auth
.
username
,
auth
.
password
):
...
@@ -57,15 +57,6 @@ def requires_basic_auth_if_no_ano(f):
...
@@ -57,15 +57,6 @@ def requires_basic_auth_if_no_ano(f):
return
decorated
return
decorated
'''def basic_auth_required_check(condition):
print("susi")
def decorator(f):
if condition and ldap_support:
return ldap.ldap.basic_auth_required(f)
return requires_basic_auth_if_no_ano(f)
return decorator'''
@
opds
.
route
(
"/opds/"
)
@
opds
.
route
(
"/opds/"
)
@
requires_basic_auth_if_no_ano
@
requires_basic_auth_if_no_ano
def
feed_index
():
def
feed_index
():
...
...
cps/server.py
View file @
572b5427
...
@@ -25,7 +25,7 @@ import signal
...
@@ -25,7 +25,7 @@ import signal
import
socket
import
socket
try
:
try
:
from
gevent.py
i
wsgi
import
WSGIServer
from
gevent.pywsgi
import
WSGIServer
from
gevent.pool
import
Pool
from
gevent.pool
import
Pool
from
gevent
import
__version__
as
_version
from
gevent
import
__version__
as
_version
VERSION
=
{
'Gevent'
:
'v'
+
_version
}
VERSION
=
{
'Gevent'
:
'v'
+
_version
}
...
...
cps/ub.py
View file @
572b5427
...
@@ -40,18 +40,12 @@ from sqlalchemy.orm import relationship, sessionmaker
...
@@ -40,18 +40,12 @@ from sqlalchemy.orm import relationship, sessionmaker
from
sqlalchemy.ext.declarative
import
declarative_base
from
sqlalchemy.ext.declarative
import
declarative_base
from
werkzeug.security
import
generate_password_hash
from
werkzeug.security
import
generate_password_hash
'''try:
import ldap
except ImportError:
pass'''
from
.
import
constants
,
logger
,
cli
from
.
import
constants
,
logger
,
cli
session
=
None
session
=
None
engine
=
create_engine
(
u'sqlite:///{0}'
.
format
(
cli
.
settingspath
),
echo
=
False
)
engine
=
create_engine
(
'sqlite:///{0}'
.
format
(
cli
.
settingspath
),
echo
=
False
)
Base
=
declarative_base
()
Base
=
declarative_base
()
...
...
cps/web.py
View file @
572b5427
...
@@ -41,7 +41,7 @@ from werkzeug.exceptions import default_exceptions
...
@@ -41,7 +41,7 @@ from werkzeug.exceptions import default_exceptions
from
werkzeug.datastructures
import
Headers
from
werkzeug.datastructures
import
Headers
from
werkzeug.security
import
generate_password_hash
,
check_password_hash
from
werkzeug.security
import
generate_password_hash
,
check_password_hash
from
.
import
constants
,
logger
,
isoLanguages
,
ldap
from
.
import
constants
,
logger
,
isoLanguages
,
ldap
1
from
.
import
global_WorkerThread
,
searched_ids
,
lm
,
babel
,
db
,
ub
,
config
,
get_locale
,
app
,
language_table
from
.
import
global_WorkerThread
,
searched_ids
,
lm
,
babel
,
db
,
ub
,
config
,
get_locale
,
app
,
language_table
from
.gdriveutils
import
getFileFromEbooksFolder
,
do_gdrive_download
from
.gdriveutils
import
getFileFromEbooksFolder
,
do_gdrive_download
from
.helper
import
common_filters
,
get_search_results
,
fill_indexpage
,
speaking_language
,
check_valid_domain
,
\
from
.helper
import
common_filters
,
get_search_results
,
fill_indexpage
,
speaking_language
,
check_valid_domain
,
\
...
@@ -52,7 +52,7 @@ from .pagination import Pagination
...
@@ -52,7 +52,7 @@ from .pagination import Pagination
from
.redirect
import
redirect_back
from
.redirect
import
redirect_back
feature_support
=
dict
()
feature_support
=
dict
()
feature_support
[
'ldap'
]
=
ldap
.
ldap_supported
()
feature_support
[
'ldap'
]
=
ldap
1
.
ldap_supported
()
try
:
try
:
from
.oauth_bb
import
oauth_check
,
register_user_with_oauth
,
logout_oauth_user
,
get_oauth_status
from
.oauth_bb
import
oauth_check
,
register_user_with_oauth
,
logout_oauth_user
,
get_oauth_status
...
@@ -1093,17 +1093,17 @@ def login():
...
@@ -1093,17 +1093,17 @@ def login():
.
first
()
.
first
()
if
config
.
config_login_type
==
1
and
user
and
feature_support
[
'ldap'
]:
if
config
.
config_login_type
==
1
and
user
and
feature_support
[
'ldap'
]:
try
:
try
:
if
ldap
.
ldap
.
bind_user
(
form
[
'username'
],
form
[
'password'
])
is
not
None
:
if
ldap
1
.
ldap
.
bind_user
(
form
[
'username'
],
form
[
'password'
])
is
not
None
:
login_user
(
user
,
remember
=
True
)
login_user
(
user
,
remember
=
True
)
flash
(
_
(
u"you are now logged in as: '
%(nickname)
s'"
,
nickname
=
user
.
nickname
),
flash
(
_
(
u"you are now logged in as: '
%(nickname)
s'"
,
nickname
=
user
.
nickname
),
category
=
"success"
)
category
=
"success"
)
return
redirect_back
(
url_for
(
"web.index"
))
return
redirect_back
(
url_for
(
"web.index"
))
except
ldap
.
ldap
.
INVALID_CREDENTIALS
as
e
:
except
ldap
1
.
ldap
.
INVALID_CREDENTIALS
as
e
:
log
.
error
(
'Login Error: '
+
str
(
e
))
log
.
error
(
'Login Error: '
+
str
(
e
))
ipAdress
=
request
.
headers
.
get
(
'X-Forwarded-For'
,
request
.
remote_addr
)
ipAdress
=
request
.
headers
.
get
(
'X-Forwarded-For'
,
request
.
remote_addr
)
log
.
info
(
'LDAP Login failed for user "
%
s" IP-adress:
%
s'
,
form
[
'username'
],
ipAdress
)
log
.
info
(
'LDAP Login failed for user "
%
s" IP-adress:
%
s'
,
form
[
'username'
],
ipAdress
)
flash
(
_
(
u"Wrong Username or Password"
),
category
=
"error"
)
flash
(
_
(
u"Wrong Username or Password"
),
category
=
"error"
)
except
ldap
.
ldap
.
SERVER_DOWN
:
except
ldap
1
.
ldap
.
SERVER_DOWN
:
log
.
info
(
'LDAP Login failed, LDAP Server down'
)
log
.
info
(
'LDAP Login failed, LDAP Server down'
)
flash
(
_
(
u"Could not login. LDAP server down, please contact your administrator"
),
category
=
"error"
)
flash
(
_
(
u"Could not login. LDAP server down, please contact your administrator"
),
category
=
"error"
)
'''except LDAPException as exception:
'''except LDAPException as exception:
...
...
cps/worker.py
View file @
572b5427
...
@@ -326,6 +326,8 @@ class WorkerThread(threading.Thread):
...
@@ -326,6 +326,8 @@ class WorkerThread(threading.Thread):
nextline
=
p
.
stdout
.
readline
()
nextline
=
p
.
stdout
.
readline
()
if
os
.
name
==
'nt'
and
sys
.
version_info
<
(
3
,
0
):
if
os
.
name
==
'nt'
and
sys
.
version_info
<
(
3
,
0
):
nextline
=
nextline
.
decode
(
'windows-1252'
)
nextline
=
nextline
.
decode
(
'windows-1252'
)
elif
os
.
name
==
'posix'
and
sys
.
version_info
<
(
3
,
0
):
nextline
=
nextline
.
decode
(
'utf-8'
)
log
.
debug
(
nextline
.
strip
(
'
\r\n
'
))
log
.
debug
(
nextline
.
strip
(
'
\r\n
'
))
# parse progress string from calibre-converter
# parse progress string from calibre-converter
progress
=
re
.
search
(
"(
\
d+)
%
\
s.*"
,
nextline
)
progress
=
re
.
search
(
"(
\
d+)
%
\
s.*"
,
nextline
)
...
...
test/Calibre-Web TestSummary.html
View file @
572b5427
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment