[AOLSERVER] auto-redirects url problem

10 views
Skip to first unread message

Alexey Pechnikov

unread,
May 3, 2009, 12:19:06 PM5/3/09
to AOLS...@listserv.aol.com
Hello!

There is needed set up url for auto-redirects in config:

ns_section "ns/server/${servername}/module/nssock"
;# Port for HTTP (typically 80)
ns_param port $httpport
;# This is not the same as your hostname
ns_param hostname $hostname
;# This is not the same as your host addr
ns_param address $address
;# URL for auto-redirects (trailing slash)
ns_param location "https://offline.mts.mobigroup.ru"

And ns_returnredirect is using "https://offline.mts.mobigroup.ru" as protocol
and host name and port path for all redirects. But for working by http and
https protocols at same time and with DNS aliases is required wrapper for
ns_returnredirect:

proc http_redirect {url {}} {
ns_returnredirect [::http::location $url]
ns_adp_return
}

proc http_location {url {}} {
# reverse-proxy must add X-Forwarded-Proto=https for SSL mode
if {[string equal [ns_set get [ns_conn headers] "X-Forwarded-Proto"]
"https"]} {
set protocol https
} else {
set protocol http
}
return "$protocol://[ns_set get [ns_conn headers] Host]$url"
}

Is it possible to decide this problem more simple? (For non-standart port is
similar problem).

Best regards, Alexey Pechnikov.
http://pechnikov.tel/


--
AOLserver - http://www.aolserver.com/

To Remove yourself from this list, simply send an email to <list...@listserv.aol.com> with the
body of "SIGNOFF AOLSERVER" in the email message. You can leave the Subject: field of your email blank.

Tom Jackson

unread,
May 3, 2009, 1:36:52 PM5/3/09
to AOLS...@listserv.aol.com
If your solution below is working, it seems pretty simple to me, a tiny
wrapper around ns_returnredirect.

Basically you are mapping your internal virtual host to the correct
external location.

tom jackson

Alexey Pechnikov

unread,
May 3, 2009, 5:28:25 PM5/3/09
to AOLS...@listserv.aol.com
Hello!

On Sunday 03 May 2009 21:36:52 Tom Jackson wrote:
> If your solution below is working, it seems pretty simple to me, a tiny
> wrapper around ns_returnredirect.

Well, can I replace internal ns_returnredirect function to my wrapper with
same name for all interps? AOL 4.5.1 has a lot of features but there are a few
examples. May I use init script for all interps for this? Is it correct way?

Alexey Pechnikov

unread,
May 4, 2009, 4:43:33 AM5/4/09
to AOLS...@listserv.aol.com
Hello!

I did write the wrapper for AOL 4.5:

ns_ictl oncreate {
if {[info commands _ns_returnredirect] eq {}} {
rename ns_returnredirect _ns_returnredirect
proc ns_returnredirect {url} {
# reverse-proxy must add header "X-Forwarded-Proto: https"
# for SSL mode
# HAProxy: reqadd X-Forwarded-Proto:\ https
# Pound: AddHeader "X-Forwarded-Proto: https"


if {[string equal [ns_set get [ns_conn headers] "X-Forwarded-Proto"] "https"]} {

set proto https
} else {
set proto http
}
_ns_returnredirect "$proto://[ns_set get [ns_conn headers] Host]$url"
}
}
}

This work fine for me.

Tom Jackson

unread,
May 4, 2009, 9:39:38 AM5/4/09
to AOLS...@listserv.aol.com
I'll point you to an example, and include the basics here, but the idea
is you need one procedure which will do the mapping, which replaces or
enhances [ns_conn location]. The map is just from your internal virtual
host to the external method:/host. Unfortunately my example AOLserver
was both front end proxy and back end virtual server so the mapping was
pretty easy, but here goes:

The code below is from the bottom of the page:
http://www.rmadilo.com/files/vat/vat.txt

I used [rename] so that no code had to be modified anywhere else. This
is old code, so please forgive the style. You can use a global var, but
you might choose a namespaced variable instead. The global var
"Template" is setup using a filter. The filter runs for each
connection...ahead of any other filter, so it needs to be registered in
your $private_tcl_library/init.tcl file, or at least before anything
else that needs to use the variable. Basically, your mapping procedure
will run for each connection, or for each scheduled proc that needs the
external address: (also can't figure out why I renamed the old versions
"new"):


# following is used for getting the correct redirect
rename ns_conn ns_conn_new
proc ns_conn { args } {
if {[string match [lindex $args 0] "location"]} {
global Template
if {[info exists Template(host)]} {
return http://${Template(host)}
} else {
return [ns_conn_new location]
}
} else {
return [eval "ns_conn_new $args"]
}
}

rename ns_returnredirect ns_returnredirect_new

proc ns_returnredirect { arg } {
ns_log Debug "arg is $arg"
ns_log Debug "ns_conn url is [ns_conn url]"
if {[string match -nocase "http*" $arg]} {
ns_returnredirect_new $arg
} elseif {[string match -nocase "/*" $arg]} {
global Template
ns_log Debug "Redirecting to ${Template(protocol)}://${Template(host)}$arg"
ns_returnredirect_new ${Template(protocol)}://${Template(host)}$arg
} else {
global Template
set full_url [ns_normalizepath [file dirname [ns_conn url]]/${arg}]
ns_log Debug "full_url is $full_url"
ns_log Debug "Redirecting to ${Template(protocol)}://${Template(host)}$arg"
ns_returnredirect_new ${Template(protocol)}://${Template(host)}$full_url
}
return
}

InitTemplates segway

# Following procs are for use with OpenACS (VirtualACS)
# You can comment these out if you do not have multiple
# ACS installations running from the same AOLserver.

rename ns_info ns_info_old


proc server_name_for_connection { } {
global Template
if {[info exists Template(server)]} {
return $Template(server)
} else {
# Not in connection Thread
return [nsv_get TemplateParameters defaultserver]
}
}

proc ns_info { option } {
switch $option {
server {
return [server_name_for_connection]
}
default {
return [ns_info_old $option]
}
}
}

More info at in the vat directory: http://www.rmadilo.com/files/vat/


tom jackson


On Mon, 2009-05-04 at 01:28 +0400, Alexey Pechnikov wrote:
> Hello!
>
> On Sunday 03 May 2009 21:36:52 Tom Jackson wrote:
> > If your solution below is working, it seems pretty simple to me, a tiny
> > wrapper around ns_returnredirect.
>
> Well, can I replace internal ns_returnredirect function to my wrapper with
> same name for all interps? AOL 4.5.1 has a lot of features but there are a few
> examples. May I use init script for all interps for this? Is it correct way?

Tom Jackson

unread,
May 4, 2009, 9:49:41 AM5/4/09
to AOLS...@listserv.aol.com
Alexey,

Looks great, you might also look at [ns_conn location] If any internal
Tcl code uses it to build url, they will stop working behind a proxy.

Just one instance: sometimes it is useful to return basic style based
images via http, so image urls might need to be rewritten during an
https session.

tom jackson

Alexey Pechnikov

unread,
May 4, 2009, 12:05:07 PM5/4/09
to AOLS...@listserv.aol.com
Hello!

Thanks, this is good example. Really, I may replace [ns_conn location]
and [ns_info server] too. I did forget it.

Best regards, Alexey Pechnikov.
http://pechnikov.tel/

Reply all
Reply to author
Forward
0 new messages