[bcn-pm] Consulta sobre hacer una web

Jordi "Txor" Casas Ríos txorlings a gmail.com
dic maig 2 06:48:25 PDT 2012


Diria que no es aixó el que vull, vull que un botó de l'HTML que dona la
meva aplicació et canvii el port, de fet crec que lo interessant seria qué
poso a l'href on m'magino que hi ha algo de màgia Mojo...

Adjunto una foto amb el que tinc muntat ara mateix (uala com m'he liat al
final, ho utilitzaré per a memória!)...

I finalment adjunto el codi implicat, com veieu utilitzo un helper per
obtenir la IP que hi ha a eth0. Aixó no em serveix perque podrien haver-hi
més interfícies. Segur que es pot fer d'una altra manera, redirect_to
posant només el port i el directori? MMmmmmMMMmmMMmmm.... ¿Com deu ser?

<pre style='color:#000000;background:#ffffff;'>get <span
style='color:#0000e6; '>'/'</span> <span style='color:#808030;
'>=</span><span style='color:#808030; '>></span> <span
style='color:#800000; font-weight:bold; '>sub</span> <span
style='color:#800080; '>{</span>
    <span style='color:#800000; font-weight:bold; '>my</span> $self <span
style='color:#808030; '>=</span> <span style='color:#400000;
'>shift</span><span style='color:#800080; '>;</span>
    <span style='color:#800000; font-weight:bold; '>my</span> $cgi <span
style='color:#808030; '>=</span> $self<span style='color:#808030;
'>-></span>param<span style='color:#808030; '>(</span><span
style='color:#0000e6; '>'cgi'</span><span style='color:#808030;
'>)</span><span style='color:#800080; '>;</span>
    <span style='color:#800000; font-weight:bold; '>my</span> $local_ip
<span style='color:#808030; '>=</span> $self<span style='color:#808030;
'>-></span>my_ip<span style='color:#800080; '>;</span>
    <span style='color:#400000; '>chomp</span><span style='color:#808030;
'>(</span>$local_ip<span style='color:#808030; '>)</span><span
style='color:#800080; '>;</span>
    <span style='color:#696969; '># Si posa /?cgi=nagios llavors redirect
to Nagios.</span>
    <span style='color:#800000; font-weight:bold; '>if</span> <span
style='color:#808030; '>(</span><span style='color:#800000;
font-weight:bold; '>defined</span> $cgi<span style='color:#808030;
'>)</span> <span style='color:#800080; '>{</span>
         <span style='color:#800000; font-weight:bold; '>if</span> <span
style='color:#808030; '>(</span>$cgi <span style='color:#808030;
'>eq</span> <span style='color:#0000e6; '>'nagios'</span><span
style='color:#808030; '>)</span> <span style='color:#800080; '>{</span>
             $self<span style='color:#808030; '>-></span>redirect_to<span
style='color:#808030; '>(</span><span style='color:#0000e6;
'>"http://$local_ip:</span><span
style='color:#008c00; '>8080</span><span style='color:#0000e6;
'>/nagios/"</span><span style='color:#808030; '>)</span><span
style='color:#800080; '>;</span>
         <span style='color:#800080; '>}</span>
    <span style='color:#800080; '>}</span>
    <span style='color:#696969; '># Pinto la web igualment.</span>
    $self<span style='color:#808030; '>-></span>render<span
style='color:#808030; '>(</span><span style='color:#0000e6;
'>'remote'</span><span style='color:#808030; '>)</span><span
style='color:#800080; '>;</span>
<span style='color:#800080; '>}</span><span style='color:#800080; '>;</span>

<span style='color:#696969; '># Trapi lleig per obtenir la IP del
server.</span>
helper <span style='color:#797997; '>my_ip </span><span
style='color:#808030; '>=></span> <span style='color:#800000;
font-weight:bold; '>sub</span> <span style='color:#800080; '>{</span>
    <span style='color:#800000; font-weight:bold; '>my</span> $interface
<span style='color:#808030; '>=</span> <span style='color:#0000e6;
'>"eth0"</span><span style='color:#800080; '>;</span>
    <span style='color:#800000; font-weight:bold; '>my</span> $ifconfig
<span style='color:#808030; '>=</span> <span style='color:#0000e6;
'>"/sbin/ifconfig"</span><span style='color:#800080; '>;</span>
    <span style='color:#800000; font-weight:bold; '>my</span> @lines <span
style='color:#808030; '>=</span> <span style='color:#800000;
background:#ffffe8; font-weight:bold; '>qx</span><span
style='color:#800000; background:#ffffe8; '>|</span><span
style='color:#000000; background:#ffffe8; '>$ifconfig
$interface</span><span style='color:#800000; background:#ffffe8; '>|</span>
<span style='color:#808030; '>or</span> <span style='color:#800000;
font-weight:bold; '>die</span><span style='color:#808030; '>(</span><span
style='color:#0000e6; '>"Can't get info from ifconfig: "</span><span
style='color:#808030; '>.</span><span style='color:#797997;
'>$!</span><span style='color:#808030; '>)</span><span
style='color:#800080; '>;</span>
    <span style='color:#800000; font-weight:bold; '>foreach</span><span
style='color:#808030; '>(</span>@lines<span style='color:#808030;
'>)</span><span style='color:#800080; '>{</span>
            <span style='color:#800000; font-weight:bold; '>if</span><span
style='color:#808030; '>(</span><span style='color:#800000; '>/</span><span
style='color:#0000e6; '>inet addr:</span><span style='color:#808030;
'>(</span><span style='color:#808030; '>[</span><span style='color:#797997;
'>\d</span><span style='color:#0000e6; '>.</span><span
style='color:#808030; '>]</span><span style='color:#808030; '>+</span><span
style='color:#808030; '>)</span><span style='color:#800000; '>/</span><span
style='color:#808030; '>)</span><span style='color:#800080; '>{</span>
                    <span style='color:#800000; font-weight:bold;
'>return</span> <span style='color:#0000e6; '>"</span><span
style='color:#797997; '>$1</span><span style='color:#0f69ff;
'>\n</span><span style='color:#0000e6; '>"</span><span
style='color:#800080; '>;</span>
            <span style='color:#800000; font-weight:bold;
'>last</span><span style='color:#800080; '>;</span>
            <span style='color:#800080; '>}</span>
    <span style='color:#800080; '>}</span>
<span style='color:#800080; '>}</span><span style='color:#800080; '>;</span>
</pre>

Salut i gràcies pel vostre temps!!

2012/5/1 Alex Muntada <alexm a alexm.org>

> + Jordi "Txor" Casas Ríos:
>
> > Como se redirecciona a un cliente remoto hacia el puerto 8080
>
> Si et refereixes a canviar el port de l'hypnotoad:
> https://metacpan.org/module/Mojo::Server::Hypnotoad#listen
>
> Si et refereixes a tenir un proxy invers al port 8080 que connecti al
> port de l'hypnotoad com a backend, pots usar apache mod_proxy, nginx,
> pound, varnish, perlbal, etc. Hi ha moltes opcions, però primer
> caldria saber exactament el que vols dir.
>
> > la ruta /nagios independientemente de la IP en que escuche el server?
>
> # Suposant que hagi entès bé el que vols, potser això?
>
> define command {
>        command_name check_http_port_url
>        command_line /usr/lib/nagios/plugins/check_http -H '$ARG1$' -p
> '$ARG2$ -u '$ARG3$' -f follow
> }
>
> define command {
>        command_name check_http_hostaddress_port_url
>        command_line /usr/lib/nagios/plugins/check_http -H
> '$HOSTADDRESS$' -p '$ARG1' -u '$ARG2$' -f follow
> }
>
> define service {
>        use generic-service
>        host_name web.example.org
>        service_description Hypnotoad App
>        check_command check_http_port_url!www.example.com!8080!/foo/bar
>        # check_command check_http_hostaddress_port_url!8080!/foo/bar
> }
>
> > Cuando lo tenega totalmente arreglado y limpito os cuelgo el código!
>
> Genial! :-)
>
> --
> Alex Muntada <alexm a alexm.org>
> http://alexm.org/
> _______________________________________________
> llista dels Barcelona-pm
> Barcelona-pm a pm.org
> http://mail.pm.org/mailman/listinfo/barcelona-pm
> BCN Perl Mongers: http://barcelona.pm.org
>
-------------- part següent --------------
Un document HTML ha estat eliminat...
URL: <http://mail.pm.org/pipermail/barcelona-pm/attachments/20120502/d2731a52/attachment-0001.html>
-------------- part següent --------------
A non-text attachment was scrubbed...
Name: dialogo_HTTP.png
Type: image/png
Size: 90765 bytes
Desc: no disponible
URL: <http://mail.pm.org/pipermail/barcelona-pm/attachments/20120502/d2731a52/attachment-0001.png>


Més informació sobre la llista de correu Barcelona-pm