Problems with Opsi-RPC

Antworten
RegEx.Fail
Beiträge: 5
Registriert: 21 Sep 2016, 14:05

Probleme mit Opsi-RPC

Beitrag von RegEx.Fail »

Hey Guys,

i just started working with Opsi, jQuery and Json but i´ll try to give you all the information you need and please bear with me if my coding is not the best.

My Problem is:
I want to setup some kind of "Kiosk" for Opsi (on a different webserver - so it's cross-domain), where all users can indiviually install and update Applications.
For this i need information about the Users Computer, like: What Software is already installed, which is outdated etc.

Now i want to send a Request to "https://myopsiserver:4447/rpc?" that gives me a response i can work with.

I use jQuery and Ajax to send a xmlHttp-Request but all i get is this response:

Code: Alles auswählen

{"result": null, "id": null, "error": {"message": "Opsi bad rpc error: Failed to decode rpc: No JSON object could be decoded", "class": "OpsiBadRpcError"}}
And this is what my Browser-Console gives me:
Request-Headers:

Code: Alles auswählen

Accept: */*
Accept-Encoding: gzip, deflate, br
Accept-Language: de,en-US;q=0.7,en;q=0.3
Authorization: Basic YWhvZWZmbmVyOkxiNTZ1QWgxOTI=
Connection: keep-alive
Cookie: OPSISID=ReAV5EJdTTuE1bHg2L0nR9p704jms5hD
Host: myopsiserver:4447
Referer: http://someotherserver/opsikiosk/index.php
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:48.0) Gecko/20100101 Firefox/48.0
Answer-Headers:

Code: Alles auswählen

Content-Length: 155
Content-Type: text/html;charset=utf-8
Date: Wed, 21 Sep 2016 12:01:44 GMT
Server: Twisted/12.0.0 TwistedWeb/[OPSI.web2, version 0.2.0]
Set-Cookie: OPSISID=dvlzsFYZRkahKUmD5xP96o9W7sWgtJDB; path=/
My request works like this:
The user and the pass are submitted at another location, but my Opsi-Credentials are working fine with https://myopsiserver:4447/interface?.
So it can't be an error there.
But i'm not sure if everything else is like it should be.

Code: Alles auswählen

$.ajax({
			url: 'https://myopsiserver:4447/rpc?',
			jsonp: "callback",
			dataType : 'jsonp',
			data: {
				"id": "1",
				"method": "getInstalledLocalBootProductIds_list",
				"params": ["EnterValidPcNameHere"] 
		    },
			beforeSend: function(xhr){
				xhr.setRequestHeader("Authorization", "Basic " + btoa(user + ":" + pass));
			},
			sucess: function(result) {
			alert('done');
			}
			});

Like i said, this stuff is new for me and i can't find a proper documentation for the RPC.
I hope someone can help me and maybe explain some things.
Benutzeravatar
ueluekmen
uib-Team
Beiträge: 1940
Registriert: 28 Mai 2008, 10:53

Re: Probleme mit Opsi-RPC

Beitrag von ueluekmen »

Hi,

first of all, you are in the wrong forum. Please post your Questions in our English support forum.

Please have a look at:

wiki/doku.php?id=userspace:json-rpc_angularjs

Perhaps this can help you.

The error comes normally, if you don't send json-rpc to the opsi-webservice. I don't understand your code-snippet, the only thing I have seen is that you should write success instead of sucess. And be warned: xmlrpc is not the same like jsonrpc.


Vielen Dank für die Nutzung von opsi. Im Forum ist unser Support begrenzt.

Für den professionellen Einsatz und individuelle Beratung empfehlen wir einen Support-Vertrag und eine Schulung.
Gerne informieren wir Sie zu unserem Angebot.

uib GmbH
Telefon: +49 6131 27561 0
E-Mail: sales@uib.de


RegEx.Fail
Beiträge: 5
Registriert: 21 Sep 2016, 14:05

Re: Probleme mit Opsi-RPC

Beitrag von RegEx.Fail »

ahh damnit.
Thanks anyway :)
RegEx.Fail
Beiträge: 5
Registriert: 21 Sep 2016, 14:05

Problems with Opsi-RPC

Beitrag von RegEx.Fail »

Hey Guys,

i just started working with Opsi, jQuery and Json but i´ll try to give you all the information you need and please bear with me if my coding is not the best.

My Problem is:
I want to setup some kind of "Kiosk" for Opsi (on a different webserver - so it's cross-domain), where all users can indiviually install and update Applications.
For this i need information about the Users Computer, like: What Software is already installed, which is outdated etc.

Now i want to send a Request to "https://myopsiserver:4447/rpc?" that gives me a response i can work with.

I use jQuery and Ajax to send a xmlHttp-Request but all i get is this response:

Code: Alles auswählen

{"result": null, "id": null, "error": {"message": "Opsi bad rpc error: Failed to decode rpc: No JSON object could be decoded", "class": "OpsiBadRpcError"}}
And this is what my Browser-Console gives me:
Request-Headers:

Code: Alles auswählen

Accept: */*
Accept-Encoding: gzip, deflate, br
Accept-Language: de,en-US;q=0.7,en;q=0.3
Authorization: Basic YWhvZWZmbmVyOkxiNTZ1QWgxOTI=
Connection: keep-alive
Cookie: OPSISID=ReAV5EJdTTuE1bHg2L0nR9p704jms5hD
Host: myopsiserver:4447
Referer: http://someotherserver/opsikiosk/index.php
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:48.0) Gecko/20100101 Firefox/48.0
Answer-Headers:

Code: Alles auswählen

Content-Length: 155
Content-Type: text/html;charset=utf-8
Date: Wed, 21 Sep 2016 12:01:44 GMT
Server: Twisted/12.0.0 TwistedWeb/[OPSI.web2, version 0.2.0]
Set-Cookie: OPSISID=dvlzsFYZRkahKUmD5xP96o9W7sWgtJDB; path=/
My request works like this:
The user and the pass are submitted at another location, but my Opsi-Credentials are working fine with https://myopsiserver:4447/interface?.
So it can't be an error there.
But i'm not sure if everything else is like it should be.

Code: Alles auswählen

$.ajax({
			url: 'https://myopsiserver:4447/rpc?',
			jsonp: "callback",
			dataType : 'jsonp',
			data: {
				"id": "1",
				"method": "getInstalledLocalBootProductIds_list",
				"params": ["EnterValidPcNameHere"] 
		    },
			beforeSend: function(xhr){
				xhr.setRequestHeader("Authorization", "Basic " + btoa(user + ":" + pass));
			},
			success: function(result) {
			alert('done');
			}
			});

Like i said, this stuff is new for me and i can't find a proper documentation for the RPC.
I hope someone can help me and maybe explain some things.
Benutzeravatar
n.wenselowski
Ex-uib-Team
Beiträge: 3194
Registriert: 04 Apr 2013, 12:15

Re: Problems with Opsi-RPC

Beitrag von n.wenselowski »

Hi,

just to make sure you are not having a problem with the encoding everything posted to the service should be UTF8-encoded.

There is the following note at the end of the chapter describing the API:
Caution

Communicating with an opsi 4.0 webservice leads to a HTTP header content-type that does not match the real content encoding. Since release of opsi 4.0.6 it is possible to activate a RFC 2616 compatible behavior by creating the file /etc/opsi/opsi.header.fix.enable and restarting opsiconfd. This makes it easier to communicate with the server through third party applications. Because this changed behavior may lead to communication failures with clients expecting the old behavior this is disabled by default. The client components provided with opsi 4.0.6 have been updated so that they can work with both.
From the response you posted I'd say you did not run into this but it's always better to be aware ;)

I hope this may help you in any way!


Kind regards

Niko

PS: You are building your own kiosk? Awesome!

Code: Alles auswählen

import OPSI
RegEx.Fail
Beiträge: 5
Registriert: 21 Sep 2016, 14:05

Re: Problems with Opsi-RPC

Beitrag von RegEx.Fail »

Thanks! I´ll try that one and Post the results if anything changes. :)

The kiosk was not my idea, but yeah it'd be pretty nice if i get this thing to work. :D
Antworten