- Posts: 16
- Thank you received: 1
Ask the community, share ideas, and connect with other LimeSurvey users!
plugins
get_me
'request' => array( 'class'=>'LSHttpRequest', 'noCsrfValidationRoutes'=>array( 'remotecontrol', 'plugins/direct' ), ),
s = Server('limesurvey_installation/index.php/admin/remotecontrol')
session_key = s.get_session_key(<user>, <password>)
limesurvey_installation/index.php/plugins/unsecure?plugin=extendRemoteControl&function=action
self.request = functools.partial(self.session.post, url, **requests_kwargs)
s.request = functools.partial(s.session.post, url='limesurvey_installation/index.php/plugins/unsecure?plugin=extendRemoteControl&function=action')
s.get_me(s.session_key)
File "python3.5/site-packages/jsonrpc_requests/jsonrpc.py", line 104, in __call__ return self.__request_method(self.__method_name, args, kwargs) File "python3.5/site-packages/jsonrpc_requests/jsonrpc.py", line 88, in __request return self.send_request(method_name, is_notification, args or kwargs) File "python3.5/site-packages/jsonrpc_requests/jsonrpc.py", line 47, in send_request raise TransportError('Cannot deserialize response body', value_error) jsonrpc_requests.jsonrpc.TransportError: ('Cannot deserialize response body', JSONDecodeError('Expecting value: line 1 column 1 (char 0)',))
class Server(object): """A connection to a HTTP JSON-RPC server, backed by requests""" def __init__(self, url, session=None, **requests_kwargs): self.session = session or requests.Session() self.session.headers.update({ 'Content-Type': 'application/json', 'Accept': 'application/json-rpc', }) self.request = functools.partial(self.session.post, url, **requests_kwargs)
req = urllib2.Request(url='https://myurl/index.php/admin/remotecontrol',\ data='{\"method\":\"get_session_key\",\"params\":[\"admin\",\"mypassword\"],\"id\":1}') req.add_header('content-type', 'application/json') req.add_header('connection', 'Keep-Alive') f = urllib2.urlopen(req) myreturn = f.read() j=json.loads(myreturn) session_key = j['result']
req = urllib2.Request(url='https://myurl/index.php/plugins/unsecure?plugin=extendRemoteControl&function=get_me', data='{\"method\":\"get_me\",\"params\":[\"<session_key>\"],\"id\":1}') req.add_header('content-type', 'application/json') req.add_header('connection', 'Keep-Alive') f = urllib2.urlopen(req) myreturn = f.read()
j=json.loads(myreturn)
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python2.7/json/__init__.py", line 339, in loads return _default_decoder.decode(s) File "/usr/lib/python2.7/json/decoder.py", line 364, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/lib/python2.7/json/decoder.py", line 382, in raw_decode raise ValueError("No JSON object could be decoded") ValueError: No JSON object could be decoded
Last time i tested (with php script) : it work …cacorns wrote: So, calling with a new request, with new url, but same session_key seems doesn't work. Is there some missing part I'm not doing?
/plugins/unsecure?plugin=extendRemoteControl&function=action
/** * Update the information content to show the good link * @params getValues */ public function getPluginSettings($getValues=true) { $this->settings['information']['content']=""; /* test if plugins/unsecure is in noCsrfValidationRoutes : in internal for compatible LimeSurvey version */ if(in_array('plugins/unsecure',App()->request->noCsrfValidationRoutes)) { $url=$this->api->createUrl('plugins/unsecure', array('plugin' => $this->getName(), 'function' => 'action')); } else { $this->settings['information']['content'].="<p class='alert alert-warning'>You need to add 'plugins/direct' to noCsrfValidationRoutes in your config file</p>"; $url=$this->api->createUrl('plugins/direct', array('plugin' => $this->getName(), 'function' => 'action')); } if(Yii::app()->getConfig("RPCInterface")=='json') { $this->settings['information']['content'].="<p class='alert alert-info'>".sprintf(gT("The remote url was <code>%s</code>",'unescaped'),$url)."</p>"; if(Yii::app()->getConfig("rpc_publish_api") == true) { if(floatval(Yii::app()->getConfig("versionnumber"))>=2.5) { $url=$this->api->createUrl('admin/pluginhelper', array('plugin' => $this->getName(), 'sa'=>'sidebody','method'=>'actionIndex','surveyId'=>0)); } $this->settings['information']['content'].="<p class='alert alert-warning'>".sprintf(gT("The API was published on <a href='%s'>%s</a>",'unescaped'),$url,$url)."</p>"; } } else { $this->settings['information']['content']="<p class='alert alert-danger'>".gT("JSON RPC is not active.")."</p>"; } return parent::getPluginSettings($getValues); }