Commit d6eedc89 by Justin Riley

stop connecting directly to proctor in client js

Updated the client js to connect to the ProctorModule via
system.ajax_url and updated the ProctorModule to proxy the requests to
the proctor server. This avoids disclosing both the proctor server url
and basic auth username/password in the LMS html source. This also
removes the need for CORS.
parent f1a8e07e
import sys import sys
import json import json
import logging import logging
import urlparse
import requests import requests
from lxml import etree from lxml import etree
...@@ -43,21 +44,29 @@ class ProctorPanel(object): ...@@ -43,21 +44,29 @@ class ProctorPanel(object):
self.proc_user = proc_user self.proc_user = proc_user
self.proc_pass = proc_pass self.proc_pass = proc_pass
self.procset_name = procset_name self.procset_name = procset_name
self.ses = requests.session()
self.user = user self.user = user
self.ses = requests.session()
def is_released(self): def request(self, url, data=None, json=True):
url = '{1}/cmd/status/{0}'.format(self.user.id, self.proc_url) ret = self.ses.get(urlparse.urljoin(self.proc_url, url),
log.info('ProctorPanel url={0}'.format(url)) verify=False, data=data,
ret = self.ses.get(url, verify=False,
auth=(self.proc_user, self.proc_pass), auth=(self.proc_user, self.proc_pass),
params={'problem': self.procset_name}) params={'problem': self.procset_name})
try: if json:
retdat = ret.json() try:
except Exception: data = ret.json()
log.error('bad return from proctor panel: ' except Exception:
'ret.content={0}'.format(ret.content)) log.error('bad return from proctor panel: '
retdat = {} 'ret.content={0}'.format(ret.content))
data = {}
else:
data = ret.content
return data
def is_released(self):
url = 'cmd/status/{0}'.format(self.user.id)
log.info('ProctorPanel url={0}'.format(url))
retdat = self.request(url)
log.info('ProctorPanel retdat={0}'.format(retdat)) log.info('ProctorPanel retdat={0}'.format(retdat))
enabled = retdat.get('enabled', False) enabled = retdat.get('enabled', False)
return enabled return enabled
...@@ -197,6 +206,10 @@ class ProctorModule(ProctorFields, XModule): ...@@ -197,6 +206,10 @@ class ProctorModule(ProctorFields, XModule):
# if dispatch == 'grades': # if dispatch == 'grades':
# return self.grades() # return self.grades()
# Proctor Panel requests (ALL USERS)
if dispatch.startswith('cmd/'):
return self.pp.request(dispatch, data, json=False)
if not self.is_released(): # check each time we do get_html() if not self.is_released(): # check each time we do get_html()
html = self.not_released_html() html = self.not_released_html()
return json.dumps({'html': [html], 'message': True}) return json.dumps({'html': [html], 'message': True})
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
</div> </div>
</section> </section>
<!--We should be using this but currently it's broken--> <!--We should be using this but it's currently broken-->
<!--<script type="text/javascript" src="${static.url('js/vendor/jquery.leanModal.min.js')}"></script>--> <!--<script type="text/javascript" src="${static.url('js/vendor/jquery.leanModal.min.js')}"></script>-->
<script type="text/javascript" src="/static/js/vendor/jquery.leanModal.min.js"></script> <script type="text/javascript" src="/static/js/vendor/jquery.leanModal.min.js"></script>
<script type="text/javascript"> <script type="text/javascript">
...@@ -81,7 +81,7 @@ procrel = (function(){ ...@@ -81,7 +81,7 @@ procrel = (function(){
var mkurl = function(cmd) { var mkurl = function(cmd) {
ps = encodeURIComponent("${pp.procset_name}"); ps = encodeURIComponent("${pp.procset_name}");
return "${pp.proc_url}/cmd/" + cmd + "/${pp.user.id}/" + ps; return "${ajax_url}/cmd/" + cmd + "/${pp.user.id}/" + ps;
} }
var statel = $('#proctor_stat_${element_id}'); var statel = $('#proctor_stat_${element_id}');
...@@ -96,11 +96,6 @@ procrel = (function(){ ...@@ -96,11 +96,6 @@ procrel = (function(){
data: { "uname": "${pp.user.username}", data: { "uname": "${pp.user.username}",
"name": "${pp.user.profile.name}" "name": "${pp.user.profile.name}"
}, },
xhrFields: {
withCredentials: true
},
username: "${pp.proc_user}",
password: "${pp.proc_pass}",
success: gfun, success: gfun,
dataType: "json", dataType: "json",
error: function(xhr, status, error) { error: function(xhr, status, error) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment