-
Notifications
You must be signed in to change notification settings - Fork 303
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
central-develop into 0.17.x #5595
Changes from 136 commits
95ae21e
0615773
3daac46
30758b4
5d6a29d
6d7e510
0cef1b9
6c70ea7
8fea95e
318a01a
bf146dc
c6402d3
c1abb70
5105876
6e6c0f0
26592ee
61fb56b
5286833
af8d016
350a7f5
1c582c2
66a0248
c106ca1
8e5e8e5
bc21a36
3bffde5
5e0b016
d4c91a2
cfb423d
14c8701
b56a514
4ffdb35
7c9085b
b68aadf
618314d
2c5cce4
b3f28a0
c06bab5
dd65adb
0299599
e890a2d
b289d0f
54c23cb
1509abc
0597547
a6d62e5
6e8da48
6177f63
ee90bd5
a5a5b1b
3bbd98e
abb207c
e6f34b2
1f19654
2ebd3ed
097a747
073046f
105272d
e1d6c23
63824f6
f13286c
c29c18d
645c7f0
1648ace
3755b72
d24b7ab
05bf1cd
3aaeea8
5f82a77
99dbcdb
c12f0ce
a276b0c
8a4d4be
f0bd27c
34a27be
65330fb
eb670d5
8ffa4d2
ea857a6
3ae33e7
3510566
3d273f2
ab8bc62
263e52b
b0a9d48
83006de
a253c1b
c3cc5ef
626f915
9801731
452e19e
4d408f3
4771c3c
171f2f7
1c49921
de616c3
c682fa4
5942943
259d8ae
cabc30f
2a5fa54
590752e
1f87909
8adb6f3
68c6ffe
30f8bd1
6f62e04
41923fc
d6abcae
0c49a77
fbc2912
c01942e
719921a
361834b
1323db0
cd4cb41
e418511
4951c10
90d20c6
d7cdc84
dc56afc
c789b22
bf2cfa4
cb25c26
45cc3e4
a118a2d
bdf518c
635c5ea
a2b59b0
3555f82
9272dcf
3fccd47
a56efba
54bc417
650a95d
e554397
338fc49
f2ae87c
5161c9b
bc367a0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -118,6 +118,73 @@ def call_command_async(cmd, *args, **kwargs): | |
return call_command_subprocess(cmd, *args, **kwargs) | ||
|
||
|
||
def call_outside_command_with_output(command, *args, **kwargs): | ||
""" | ||
Runs call_command for a KA Lite installation at the given location, | ||
and returns the output. | ||
""" | ||
|
||
if settings.IS_SOURCE: | ||
assert "kalite_dir" in kwargs, "don't forget to specify the kalite_dir" | ||
kalite_dir = kwargs.pop('kalite_dir') | ||
else: | ||
kalite_dir = None | ||
|
||
# some custom variables that have to be put inside kwargs | ||
# or else will mess up the way the command is called | ||
output_to_stdout = kwargs.pop('output_to_stdout', False) | ||
output_to_stderr = kwargs.pop('output_to_stderr', False) | ||
wait = kwargs.pop('wait', True) | ||
|
||
# build the command | ||
if kalite_dir: | ||
kalite_bin = os.path.join(kalite_dir, "bin", "kalite") | ||
else: | ||
kalite_bin = 'kalite' | ||
|
||
cmd = (kalite_bin, "manage", command) if os.name != "nt" else (sys.executable, kalite_bin, "manage", command) | ||
for arg in args: | ||
cmd += (arg,) | ||
|
||
kwargs_keys = kwargs.keys() | ||
|
||
# Ensure --settings occurs first, as otherwise docopt parsing barfs | ||
kwargs_keys = sorted(kwargs_keys, cmp=lambda x,y: -1 if x=="settings" else 0) | ||
|
||
for key in kwargs_keys: | ||
val = kwargs[key] | ||
key = key.replace(u"_",u"-") | ||
prefix = u"--" if command != "runcherrypyserver" else u"" # hack, but ... whatever! | ||
if isinstance(val, bool): | ||
cmd += (u"%s%s" % (prefix, key),) | ||
else: | ||
# TODO(jamalex): remove this replacement, after #4066 is fixed: | ||
# https://github.com/learningequality/ka-lite/issues/4066 | ||
cleaned_val = unicode(val).replace(" ", "") | ||
cmd += (u"%s%s=%s" % (prefix, key, cleaned_val),) | ||
|
||
# we also need to change the environment to point to the the local | ||
# kalite settings. This is especially important for when the | ||
# central server calls this function, as if we don't change this, | ||
# kalitectl.py wil look for centralserver.settings instead of | ||
# kalite.settings. | ||
new_env = os.environ.copy() | ||
new_env["DJANGO_SETTINGS_MODULE"] = kwargs.get("settings") or "kalite.settings" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should ideally be configurable and only switched on in the central server. The whole function is only used in a test, though, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since all this code is used from the central server's test suite, I'm moving it there. |
||
|
||
p = subprocess.Popen( | ||
cmd, | ||
shell=False, | ||
# cwd=os.path.split(cmd[0])[0], | ||
stdout=None if output_to_stdout else subprocess.PIPE, | ||
stderr=None if output_to_stderr else subprocess.PIPE, | ||
env=new_env, | ||
) | ||
out = p.communicate() if wait else (None, None) | ||
|
||
# tuple output of stdout, stderr, exit code and process object | ||
return out + (1 if out[1] else 0, p) | ||
|
||
|
||
class LocaleAwareCommand(BaseCommand): | ||
option_list = BaseCommand.option_list + ( | ||
make_option('--locale', | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,15 +49,17 @@ def register_device(request): | |
try: | ||
if not client_device.verify(): | ||
# We've been getting this verification error a lot, even when we shouldn't. Send more details to us by email so we can diagnose. | ||
msg = "\n\n".join([request.body, client_device._hashable_representation(), str(client_device.validate()), client_device.signed_by_id, client_device.id, str(request)]) | ||
import inspect | ||
d = client_device | ||
msg = "\n\n".join([str(msg) for msg in [request.body, d._hashable_representation(), d.__dict__, d.__class__, inspect.getfile(d.__class__), local_version, d.description, d.signed_by_id, d.id, request]]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like debugging noise? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reverting back to the former debug email. |
||
send_mail("Client device did not verify", msg, "[email protected]", ["[email protected]"]) | ||
return JsonResponseMessageError("Client device must be self-signed with a signature matching its own public key!", code=EC.CLIENT_DEVICE_INVALID_SIGNATURE) | ||
except Exception as e: | ||
# Can't properly namespace to a particular Exception here, since the only reason we would be getting here is | ||
# that what should be proper exception namespacing in code being called isn't correctly catching this exception | ||
msg = "\n\n".join([request.body, client_device._hashable_representation(), "Exception: %s" % e, str(type(e)), client_device.signed_by_id, client_device.id, str(request)]) | ||
send_mail("Exception while verifying client device", msg, "[email protected]", ["[email protected]"]) | ||
return JsonResponseMessageError("Client device must be self-signed with a signature matching its own public key!", code=EC.CLIENT_DEVICE_INVALID_SIGNATURE) | ||
return JsonResponseMessageError("Client device must be self-signed with a signature matching its own public key.", code=EC.CLIENT_DEVICE_INVALID_SIGNATURE) | ||
|
||
try: | ||
zone = register_self_registered_device(client_device, models, data) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,7 +61,7 @@ def handle(self, *args, **options): | |
csrftoken = s.cookies['csrftoken_central'] | ||
login_data = dict(username=options["username"], password=options["password"], csrfmiddlewaretoken=csrftoken, next='/') | ||
r = s.post(login_url, data=login_data, headers={"Referer": login_url}) | ||
assert r.status_code == 200, "Error logging into central server: " + r.content | ||
assert r.status_code == 200 and "Incorrect user" not in r.content, "Error logging into central server: " + r.content | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The change looks like a desired precision from the commit msg: 34a27be |
||
|
||
# register on the central server | ||
reg_url = client.get_registration_url() | ||
|
@@ -80,5 +80,3 @@ def handle(self, *args, **options): | |
own_device = Device.get_own_device() | ||
assert own_device.is_registered(), "Device was not registered successfully..." | ||
sys.stdout.write("Device '%s' has been successfully registered to zone '%s'!\n" % (own_device.id, own_device.get_zone().id)) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/** | ||
* Cookie plugin | ||
* | ||
* Copyright (c) 2006 Klaus Hartl (stilbuero.de) | ||
* Dual licensed under the MIT and GPL licenses: | ||
* http://www.opensource.org/licenses/mit-license.php | ||
* http://www.gnu.org/licenses/gpl.html | ||
* | ||
*/ | ||
|
||
/** | ||
* Create a cookie with the given name and value and other optional parameters. | ||
* | ||
* @example $.cookie('the_cookie', 'the_value'); | ||
* @desc Set the value of a cookie. | ||
* @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true }); | ||
* @desc Create a cookie with all available options. | ||
* @example $.cookie('the_cookie', 'the_value'); | ||
* @desc Create a session cookie. | ||
* @example $.cookie('the_cookie', null); | ||
* @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain | ||
* used when the cookie was set. | ||
* | ||
* @param String name The name of the cookie. | ||
* @param String value The value of the cookie. | ||
* @param Object options An object literal containing key/value pairs to provide optional cookie attributes. | ||
* @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object. | ||
* If a negative value is specified (e.g. a date in the past), the cookie will be deleted. | ||
* If set to null or omitted, the cookie will be a session cookie and will not be retained | ||
* when the the browser exits. | ||
* @option String path The value of the path atribute of the cookie (default: path of page that created the cookie). | ||
* @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie). | ||
* @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will | ||
* require a secure protocol (like HTTPS). | ||
* @type undefined | ||
* | ||
* @name $.cookie | ||
* @cat Plugins/Cookie | ||
* @author Klaus Hartl/[email protected] | ||
*/ | ||
|
||
/** | ||
* Get the value of a cookie with the given name. | ||
* | ||
* @example $.cookie('the_cookie'); | ||
* @desc Get the value of a cookie. | ||
* | ||
* @param String name The name of the cookie. | ||
* @return The value of the cookie. | ||
* @type String | ||
* | ||
* @name $.cookie | ||
* @cat Plugins/Cookie | ||
* @author Klaus Hartl/[email protected] | ||
*/ | ||
jQuery.cookie = function(name, value, options) { | ||
if (typeof value != 'undefined') { // name and value given, set cookie | ||
options = options || {}; | ||
if (value === null) { | ||
value = ''; | ||
options = $.extend({}, options); // clone object since it's unexpected behavior if the expired property were changed | ||
options.expires = -1; | ||
} | ||
var expires = ''; | ||
if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) { | ||
var date; | ||
if (typeof options.expires == 'number') { | ||
date = new Date(); | ||
date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000)); | ||
} else { | ||
date = options.expires; | ||
} | ||
expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE | ||
} | ||
// NOTE Needed to parenthesize options.path and options.domain | ||
// in the following expressions, otherwise they evaluate to undefined | ||
// in the packed version for some reason... | ||
var path = options.path ? '; path=' + (options.path) : ''; | ||
var domain = options.domain ? '; domain=' + (options.domain) : ''; | ||
var secure = options.secure ? '; secure' : ''; | ||
document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join(''); | ||
} else { // only name given, get cookie | ||
var cookieValue = null; | ||
if (document.cookie && document.cookie != '') { | ||
var cookies = document.cookie.split(';'); | ||
for (var i = 0; i < cookies.length; i++) { | ||
var cookie = jQuery.trim(cookies[i]); | ||
// Does this cookie string begin with the name we want? | ||
if (cookie.substring(0, name.length + 1) == (name + '=')) { | ||
cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); | ||
break; | ||
} | ||
} | ||
} | ||
return cookieValue; | ||
} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be configurable and only switched on in the central server.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, this might actually be harmless to the rest of the KA Lite application, wouldn't you think so @rtibbles ?