Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Dynamic DNS service for HTTP-IN via Google App Engine

Darien Caldwell
Registered User
Join date: 12 Oct 2006
Posts: 3,127
06-04-2009 23:38
From: Kenn Nilsson
Awesome work! Looks like something that a lot of people will be able to put to great use. And ... I learned a little bit of Python by looking at your code :-) ( I've never used Python before ).



Before this, I hadn't used Python either. But it's not terribly different from most structured languages. you just have to get used to the fact there's no curly braces, and it uses indenting to define the beginning and ending of things. It *does* force you to write neater code, I have to admit. :)
_____________________
Papalopulus Kobolowski
working mind
Join date: 11 Aug 2006
Posts: 326
06-05-2009 01:01
I was testing it a little in the test grid and i have a cuestion..

What is the format of the metod "POST" in PHP to send data to the prim?
Normally in PHP is "my_php.php?data=Mydata_etc"

I saw the example in Perl

From: someone
my $url = 'http://sim3015.aditi.lindenlab.com:12046/cap/d57a7c8b-3ace-3186-730a-f22fde870d48';

my $info = submitInformation
($url,'id=244195d6-c9b7-4fd6-9229-c3a8b2e60e81&name=M Linden');

print $info,"\n";



But i dont undestend what is the separator to send data to the prim.

"?" and "&" simbols didnt work
_____________________


RAW terrain files - terraform your SIM!!
http://www.wishland.info/
PD:the wiki its your friend ;)
http://wiki.secondlife.com/wiki/LSL_Portal
Darien Caldwell
Registered User
Join date: 12 Oct 2006
Posts: 3,127
06-05-2009 08:46
From: Papalopulus Kobolowski
I was testing it a little in the test grid and i have a cuestion..

What is the format of the metod "POST" in PHP to send data to the prim?
Normally in PHP is "my_php.php?data=Mydata_etc"

I saw the example in Perl



But i dont undestend what is the separator to send data to the prim.

"?" and "&" simbols didnt work



The prim as far as I know can't receive POST data. That would put the data in the header, which you can't access. The best way to transmit data to a prim is to have the data in the Body.
_____________________
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
06-05-2009 08:52
From: Darien Caldwell
The prim as far as I know can't receive POST data. That would put the data in the header, which you can't access. The best way to transmit data to a prim is to have the data in the Body.
Data in the body is POST data. Data in the URL is GET data.
_____________________
Argent Stonecutter - http://globalcausalityviolation.blogspot.com/

"And now I'm going to show you something really cool."

Skyhook Station - http://xrl.us/skyhook23
Coonspiracy Store - http://xrl.us/coonstore
Darien Caldwell
Registered User
Join date: 12 Oct 2006
Posts: 3,127
06-05-2009 12:19
From: Argent Stonecutter
Data in the body is POST data. Data in the URL is GET data.


Whoops, you're right. I must have been thinking of cookies. Will (probably not) teach me to talk of the top of my head without checking my facts.

The PHP command I would probably try using to send POST data to a prim is

http://us2.php.net/manual/en/function.http-post-data.php

or

http://us2.php.net/manual/en/function.http-post-fields.php
_____________________
Papalopulus Kobolowski
working mind
Join date: 11 Aug 2006
Posts: 326
06-05-2009 21:26
I test a little form as a POST data and works finally :)

from the wiki page
http://wiki.secondlife.com/wiki/LSL_http_server/examples

From: someone


key requestURL;

// ###############################################
// Routine to parse a string sent through the
// http server via post.
// parsePostData(theMessage)
// Returns a strided list with stride length 2.
// Each set has the key and then its value.
list parsePostData(string message) {
list postData = []; // The list with the data that was passed in.
list parsedMessage = llParseString2List(message,["&"],[]); // The key/value pairs parsed into one list.
integer len = ~llGetListLength(parsedMessage);

while(++len) {
string currentField = llList2String(parsedMessage, len); // Current key/value pair as a string.

integer split = llSubStringIndex(currentField,"=";); // Find the "=" sign
if(split == -1) { // There is only one field in this part of the message.
postData += [llUnescapeURL(currentField),""];
} else {
postData += [llUnescapeURL(llDeleteSubString(currentField,split,-1)), llUnescapeURL(llDeleteSubString(currentField,0,split))];
}
}
// Return the strided list.
return postData ;
}

default {

state_entry() {
requestURL = llRequestURL(); // Request that an URL be assigned to me.
}

http_request(key id, string method, string body) {
list incomingMessage;

if ((method == URL_REQUEST_GRANTED) && (id == requestURL) ){
// An URL has been assigned to me.
llOwnerSay("Obtained URL: " + body);
requestURL = NULL_KEY;
}
else if ((method == URL_REQUEST_DENIED) && (id == requestURL)) {
// I could not obtain a URL
llOwnerSay("There was a problem, and an URL was not assigned: " +
body);
requestURL = NULL_KEY;
}
else if (method == "POST";) {
// An incoming message was received.
llOwnerSay("Received information form the outside: " + body);
incomingMessage = parsePostData(body);
llOwnerSay(llDumpList2String(incomingMessage,"\n";));

llHTTPResponse(id,200,"You passed the following:\n" +
llDumpList2String(incomingMessage,"\n";));

}
else {
// An incoming message has come in using a method that has
// not been anticipated.
llHTTPResponse(id,405,"Unsupported Method";);
}
}
}




From: someone


<FORM action="http://sim3004.aditi.lindenlab.com:12046/cap/your cap" method="post">
<P>
First name: <INPUT type="text" name="firstname"><BR>
Last name: <INPUT type="text" name="lastname"><BR>
<INPUT type="submit" value="Send"> <INPUT type="reset">
</P>

</FORM>


And return the correct data.
_____________________


RAW terrain files - terraform your SIM!!
http://www.wishland.info/
PD:the wiki its your friend ;)
http://wiki.secondlife.com/wiki/LSL_Portal
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
06-06-2009 04:37
They should be able to handle GET. You need to be able to handle GET to do RESTful servers.
_____________________
Argent Stonecutter - http://globalcausalityviolation.blogspot.com/

"And now I'm going to show you something really cool."

Skyhook Station - http://xrl.us/skyhook23
Coonspiracy Store - http://xrl.us/coonstore
Darien Caldwell
Registered User
Join date: 12 Oct 2006
Posts: 3,127
06-07-2009 10:26
Someone pointed out to me that the URL redirection part would lose any GET variables which were supplied at the time of the call. (DOH!). This has been fixed. Now GET variables will be forwarded to the redirected page. :) Updated code at the link in the first post.
_____________________
Kinki Vacano
Registered User
Join date: 22 Dec 2006
Posts: 7
07-04-2009 18:06
I am very far from a web or python expert so I may have no idea what I am talking about but, should the service name be allowed to contain escaped characters?

For example, I want to use the service name to signify different users like ...

http://someapp.appspot.com/~KinkiVacano

which may get encoded to %7EKinkiVacano

This currently will not work. The Redirector class searches the DB for the encoded service, which leads to a failure. Unquoting the service name before the DB query seems to fix it.

Someone smack me if I have no idea what I am talking about :P

Great work Darien, thanks!

Kinki
Darien Caldwell
Registered User
Join date: 12 Oct 2006
Posts: 3,127
07-04-2009 20:32
From: Kinki Vacano
I am very far from a web or python expert so I may have no idea what I am talking about but, should the service name be allowed to contain escaped characters?

For example, I want to use the service name to signify different users like ...

http://someapp.appspot.com/~KinkiVacano

which may get encoded to %7EKinkiVacano

This currently will not work. The Redirector class searches the DB for the encoded service, which leads to a failure. Unquoting the service name before the DB query seems to fix it.

Someone smack me if I have no idea what I am talking about :P

Great work Darien, thanks!

Kinki


Yep, you were correct about what was going on. Due to how Google handles things, in one instance it's not URI encoded, but in the other it is. Redownload the file for the updated version that solves this issue. Should work with ~ or any other funky thing you can come up with. (I hope) :p
_____________________
Opensource Obscure
Hide UI
Join date: 5 Jun 2008
Posts: 115
07-11-2009 17:35
From: Argent Stonecutter
Another possibility would be if there's one of those URL shortening services that allows you to update your short URL with an API.


That appears to work: I'm using Snipurl aka Snurl aka Sn.ip


I think this could be an easier solution (also less reliable and performant I guess) than the one proposed above since I could work it out on my own and I'm a poor scripter. I wrote some LSL for that but I'd be ashamed to write it here.
Darien Caldwell
Registered User
Join date: 12 Oct 2006
Posts: 3,127
07-11-2009 18:09
From: Opensource Obscure
That appears to work: I'm using Snipurl aka Snurl aka Sn.ip


I think this could be an easier solution (also less reliable and performant I guess) than the one proposed above since I could work it out on my own and I'm a poor scripter. I wrote some LSL for that but I'd be ashamed to write it here.



Interestingly enough, that service also runs on Google's App Engine. It's simply that it's been set up and operated by a 3rd party. It looks like it could be a good alternative for those who don't want to set up their own service. Thanks :)
_____________________
Droth Karu
Registered User
Join date: 9 Jun 2008
Posts: 5
07-12-2009 20:49
I have set up a dynamic redirect (on the Google App Engine) modified from this code at http://dynamic-redirect.appspot.com/redirectsl/. It allows only requests for Linden Lab servers for making, deleting or changing services but allows anyone to use a redirect. It also has the option to make the service private so only you can use it (your objects in SL). To do so, when making the service, add &private=1 to the url. There is more but it won't let me post it.... The whole post can be found at http://dynamic-redirect.appspot.com/help/
ElQ Homewood
Sleeps Professionally
Join date: 25 Apr 2007
Posts: 280
07-13-2009 00:48
I dunno..while I may eventually find a use for this type of service, I'm using what seems to me a much simpler solution. Whenever the url changes, the object sends the new url to my web server. It's working fine so far, does anybody see how that might be a problem later?
Tali Rosca
Plywood Whisperer
Join date: 6 Feb 2007
Posts: 767
07-13-2009 05:19
From: ElQ Homewood
I dunno..while I may eventually find a use for this type of service, I'm using what seems to me a much simpler solution. Whenever the url changes, the object sends the new url to my web server. It's working fine so far, does anybody see how that might be a problem later?

As long as you're just communicating straight from a prim to your own server (and back again) that should be fine. But if you want, say, two prims to communicate, this is an elegant way of locking down an address and just using that, rather than having your prim ask your web server for the address to the other prim. (Of course, that's essentially what it's doing with this code too. It just happens smoothly and automatically).
This becomes even more useful if your prim is providing services to 3rd-parties.
Tali Rosca
Plywood Whisperer
Join date: 6 Feb 2007
Posts: 767
07-13-2009 05:21
From: Droth Karu
I have set up a dynamic redirect (on the Google App Engine) modified from this code at http://dynamic-redirect.appspot.com/redirectsl/. It allows only requests for Linden Lab servers for making, deleting or changing services but allows anyone to use a redirect. It also has the option to make the service private so only you can use it (your objects in SL). To do so, when making the service, add &private=1 to the url. There is more but it won't let me post it.... The whole post can be found at http://dynamic-redirect.appspot.com/help/

How do you check for "your objects in SL"?
Droth Karu
Registered User
Join date: 9 Jun 2008
Posts: 5
07-13-2009 08:36
From: Tali Rosca
How do you check for "your objects in SL"?


If you are asking for how it knows if the object is owned by you, it checks the headers that are automatically added by the sim when it makes a HTTP request. It also checks to make sure that the request is coming from one of Linden Lab's servers to prevent spoofing.
Tali Rosca
Plywood Whisperer
Join date: 6 Feb 2007
Posts: 767
07-13-2009 08:56
From: Droth Karu
If you are asking for how it knows if the object is owned by you, it checks the headers that are automatically added by the sim when it makes a HTTP request. It also checks to make sure that the request is coming from one of Linden Lab's servers to prevent spoofing.

Oh! I had forgotten that llHttpRequest tags it with all that information. (X-SecondLife-Local-Velocity?!?)
So if you can reliably confirm that the request is from a sim server, you can use those headers, since a script cannot set its own headers. That actually makes it far easier than I feared to make quite robust.
Darien Caldwell
Registered User
Join date: 12 Oct 2006
Posts: 3,127
07-13-2009 09:02
From: ElQ Homewood
I dunno..while I may eventually find a use for this type of service, I'm using what seems to me a much simpler solution. Whenever the url changes, the object sends the new url to my web server. It's working fine so far, does anybody see how that might be a problem later?


That's a perfectly fine way to handle it. :) These DyDNS services are for people who either can't afford or do not want to pay for a webserver (google app engine is free). If you already have a webserver, then yes, you don't need something like this.

I wanted to offer a solution which was zero/low cost and simple to deploy and was also under the user's own control to allay privacy and longevity concerns. A server you operate yourself leaves little chance for anyone intercepting your data, 3rd party services of course have the *potential* to see both your data and the addresses of your applications. You also can never say how long they may be around. :)
_____________________
Darien Caldwell
Registered User
Join date: 12 Oct 2006
Posts: 3,127
07-13-2009 09:09
From: Tali Rosca
Oh! I had forgotten that llHttpRequest tags it with all that information. (X-SecondLife-Local-Velocity?!?)
So if you can reliably confirm that the request is from a sim server, you can use those headers, since a script cannot set its own headers. That actually makes it far easier than I feared to make quite robust.


Actually those headers could be spoofed from any out-of world application, it is after all just header data. The right way to guarantee they came from an LL owned server would be to check the IP address range. There is a list of these ranges but it is subject to change. I don't know how LL would feel about me posting the list. :)
_____________________
Tali Rosca
Plywood Whisperer
Join date: 6 Feb 2007
Posts: 767
07-13-2009 09:15
From: Darien Caldwell
Actually those headers could be spoofed from any out-of world application, it is after all just header data. The right way to guarantee they came from an LL owned server would be to check the IP address range. There is a list of these ranges but it is subject to change. I don't know how LL would feel about me posting the list. :)

Exactly. "...if you can reliably confirm that the request is from a sim server, you can use those headers..."
Wouldn't a reverse DNS lookup suffice, rather than checking against fixed ranges? -It can still be spoofed, but then you're *really* messing with the network.
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
07-13-2009 09:28
Simple rDNS is easy to fake.

If you do both reverse DNS and forward DNS and make sure they match, you're pretty safe.
_____________________
Argent Stonecutter - http://globalcausalityviolation.blogspot.com/

"And now I'm going to show you something really cool."

Skyhook Station - http://xrl.us/skyhook23
Coonspiracy Store - http://xrl.us/coonstore
Droth Karu
Registered User
Join date: 9 Jun 2008
Posts: 5
07-13-2009 09:29
It checks the IP address before checking the headers. If the IP address isn't LL, it gives a 403 Forbidden error. But yes, it is still possible to spoof the IP address and then spoof the headers but that is a lot of work and unless you are using the dynamic redirect sending sensitive data, not much harm could be done. And also, because it is a 3rd party service, requests can easily be logged and the data stored (Which I don't do).

EDIT: Also, unless the service is marked as private (see previous post), anyone can use the service redirect (http://dynamic-redirect.appspot.com/redirectsl/example); it does not have to come from a LL server.
Droth Karu
Registered User
Join date: 9 Jun 2008
Posts: 5
07-13-2009 09:33
And also remember, this is NOT a dynamic DNS because it is not taking domain names and translating them into IP addresses, it is a dynamic redirect. Also, multiple regions can and probably do share the same IP address.

And it checks the IP address and does not do a reverse DNS lookup.
Tali Rosca
Plywood Whisperer
Join date: 6 Feb 2007
Posts: 767
07-14-2009 05:01
Unfortunately, Appengine doesn't support DNS lookups, since you're sandboxed away from much of the net functionality, funneled to the URLFetch API instead.
http://code.google.com/p/googleappengine/issues/detail?id=354
1 2 3 4 5