cURL mit CUxD und SSL

Anbindung von FS20-Komponenten, ELV-Wetterstationen, EnOcean und DMX an HomeMatic

Moderator: Co-Administratoren

Antworten
Karoshi
Beiträge: 52
Registriert: 27.04.2014, 13:31

cURL mit CUxD und SSL

Beitrag von Karoshi » 05.12.2015, 17:02

Hallo zusammen,

ich möchte mein php Script, das auf einem Windows PC läuft gerne durch ein direkt auf der CCU laufendes tcl Script abblösen. Das PHP sieht so aus:

Code: Alles auswählen

<?
Global $url;
				$ch = curl_init($url);
				$sCookieFile = tempnam(sys_get_temp_dir(), 'Cookie_Anzeiger');
				curl_setopt($ch, CURLOPT_URL, 'https://192.168.178.XX:8443/rest/devices/scenes/scenecallers/appcaller?sceneId=0f5b2fa0-6187-450e-9a91-0f8f2fb2a374&username=administrator&hmac=xxxxxxxxxxxxxxxx');
				curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/32.0.1700.107 Chrome/32.0.1700.107 Safari/537.36');
				//curl_setopt($ch, CURLOPT_USERAGENT,$useragent);
				curl_setopt($ch, CURLOPT_POST, true);
				curl_setopt($ch, CURLOPT_POSTFIELDS, "{}");
				curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
				curl_setopt($ch, CURLOPT_COOKIESESSION, true);
				curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
				curl_setopt($ch, CURLOPT_COOKIEJAR, $sCookieFile);  //could be empty, but cause problems on some hosts
				curl_setopt($ch, CURLOPT_COOKIEFILE, $sCookieFile);  //could be empty, but cause problems on some hosts
				curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
				curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
				curl_setopt($ch, CURLOPT_HEADER, false);
				curl_setopt($ch, CURLOPT_VERBOSE, true);
				curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 180);
				$answer = curl_exec($ch);
				if (curl_error($ch)) {
				    echo curl_error($ch);
	 				}
				echo $answer;
?>
Leider bekomme ich es nicht hin. Wie müsste der Aufruf der URL über cURL mit SSL in tcl aussehen? Wie funktioniert das mit dem Zertifikat?


Danke für jeden Tipp!

Gruß, Tim

Bulli
Beiträge: 494
Registriert: 29.04.2014, 18:38
Hat sich bedankt: 2 Mal
Danksagung erhalten: 9 Mal

Re: cURL mit CUxD und SSL

Beitrag von Bulli » 06.12.2015, 07:47

Hallo
ich würde einfach -k nehmen.
-k, --insecure

(SSL) This option explicitly allows curl to perform "insecure" SSL connections and transfers. All SSL connections are attempted to be made secure by using the CA certificate bundle installed by default. This makes all connections considered "insecure" fail unless -k, --insecure is used.
Gruß
Bulli

Karoshi
Beiträge: 52
Registriert: 27.04.2014, 13:31

Re: cURL mit CUxD und SSL

Beitrag von Karoshi » 06.12.2015, 09:49

Hallo Bulli,

danke für deine Antwort. Leider tut sich nichts :-(

Code: Alles auswählen

#!/bin/tclsh
set env(LD_LIBRARY_PATH) /usr/local/addons/cuxd 
set url "https://192.168.178.XX:8443/rest/devices/scenes/scenecallers/appcaller?sceneId=0f5b2fa0-6187-450e-9a91-0f8f2fb2a374&username=administrator&hmac=XXXXX"
exec echo "{\"alert\":\"$alert\"}" | /usr/local/addons/cuxd/curl -f -s -T -k - $url
Wenn ich ein POST per REST auf die URL feuere vom Browser aus gehts...irgendwas muss an Script falsch sein.

Karoshi
Beiträge: 52
Registriert: 27.04.2014, 13:31

Re: cURL mit CUxD und SSL

Beitrag von Karoshi » 06.12.2015, 10:18

Direkt aus einem Programm heraus mag es leider auch nicht :-(

Code: Alles auswählen

string    url       = "https://192.168.178.XX:8443/rest/devices/scenes/scenecallers/appcaller?sceneId=0f5b2fa0-6187-450e-9a91-0f8f2fb2a374&username=administrator&hmac=XXXXXXXX";
string    postVars    = "{}";
dom.GetObject("CUxD.CUX2801001:1.CMD_EXEC").State("LD_LIBRARY_PATH=/usr/local/addons/cuxd /usr/local/addons/cuxd/curl -s -d -k '" # postVars # "' " # url);

Karoshi
Beiträge: 52
Registriert: 27.04.2014, 13:31

Re: cURL mit CUxD und SSL

Beitrag von Karoshi » 06.12.2015, 12:28

Habs geschafft!

Code: Alles auswählen

dom.GetObject("CUxD.CUX2801001:1.CMD_EXEC").State("LD_LIBRARY_PATH=/usr/local/addons/cuxd /usr/local/addons/cuxd/curl --trace-ascii /var/log/curl.trace -k -L -d {} 'https://192.168.178.XX:8443/rest/devices/scenes/scenecallers/appcaller?sceneId=0f5b2fa0-6187-450e-9a91-0f8f2fb2a374&username=administrator&hmac=XXXXXXXX'");

Antworten

Zurück zu „CUxD“