[bcn-pm] Consulta sobre hacer una web
Jordi "Txor" Casas Ríos
txorlings a gmail.com
dij maig 3 07:36:56 PDT 2012
2012/5/3 Diego Kuperman <diego a kuperman.com.ar>
> Hola!,
>
> He visto que ya lo has resuelto y no he mirado como, pero acabo de ver el
> thread y me surge la duda:
>
>
> On 5/2/12 3:50 PM, Jordi "Txor" Casas Ríos wrote:
>
>> Ou shit!
>>
>> Com l'he liat amb l'HTML!!!
>>
>> get'/' => sub {
>> my $self= shift;
>> my $cgi= $self->param('cgi');
>> my $local_ip= $self->my_ip;
>>
>> chomp($local_ip);
>> # Si posa /?cgi=nagios llavors redirect to Nagios.
>> if (defined $cgi) {
>> if ($cgieq 'nagios') {
>>
>> $self->redirect_to("http://$**local_ip:8080/nagios/");
>> }
>> }
>> # Pinto la web igualment.
>> $self->render('remote');
>> };
>>
>> No tiene sentido hacer redirect y tambien render..., yo creo que con
> algo asi deberia valer:
>
> if ( my $cgi = $self->param('cgi') ) {
>
> $self->redirect_to("http://$**local_ip:8080/nagios/")
> && return if $cgi eq 'nagios';
> }
>
Aaaaa sisi! Claro, podria sacarlo de ahi!
>
> # Trapi lleig per obtenir la IP del server.
>> helpermy_ip=> sub {
>> my $interface= "eth0";
>> my $ifconfig= "/sbin/ifconfig";
>> my @lines= qx|$ifconfig $interface| or die("Can't get info from
>> ifconfig:".$!);
>>
>> foreach(@lines){
>> if(/inet addr:([\d.]+)/){
>> return "$1\n";
>> last;
>> }
>> }
>> };
>>
>>
> Y ya como comentario adicional, veo que tienes varias configuraciones
> clavadas en el código. Probablemente sea mejor que estos sean valores por
> defecto (o que por defecto hagas un `which` al sistema) pero que se puedan
> configurar en la config de la app (app->config). Usando
> https://metacpan.org/module/**Mojolicious::Plugin::**JSONConfig<https://metacpan.org/module/Mojolicious::Plugin::JSONConfig>por ejemplo.
>
> -dk
>
> Source code:
>> get '/' => sub { my $self = shift; my $cgi = $self->param('cgi'); my
>> $local_ip = $self->my_ip; chomp($local_ip); # Si posa /?cgi=nagios
>> llavors redirect to Nagios. if (defined $cgi) { if ($cgi eq 'nagios') {
>> $self->redirect_to("http://$**local_ip:8080/nagios/"); } } # Pinto la web
>> igualment. $self->render('remote'); }; # Trapi lleig per obtenir la IP
>> del server. helper my_ip => sub { my $interface = "eth0"; my $ifconfig =
>> "/sbin/ifconfig"; my @lines = qx|$ifconfig $interface| or die("Can't get
>> info from ifconfig: ".$!); foreach(@lines){ if(/inet addr:([\d.]+)/){
>> return "$1\n"; last; } } };
>>
>>
>>
>>
>> Ara si?
>>
>>
>> 2012/5/2 Jordi "Txor" Casas Ríos <txorlings a gmail.com
>> <mailto:txorlings a gmail.com>>
>>
>>
>> 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 <mailto: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<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 <http://web.example.org>
>> service_description Hypnotoad App
>> check_command check_http_port_url!www.**example.com<http://www.example.com>
>> <http://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 <mailto:alexm a alexm.org>>
>>
>> http://alexm.org/
>> ______________________________**_________________
>> llista dels Barcelona-pm
>> Barcelona-pm a pm.org <mailto:Barcelona-pm a pm.org>
>>
>> http://mail.pm.org/mailman/**listinfo/barcelona-pm<http://mail.pm.org/mailman/listinfo/barcelona-pm>
>> BCN Perl Mongers: http://barcelona.pm.org
>>
>>
>>
>>
>>
>> ______________________________**_________________
>> llista dels Barcelona-pm
>> Barcelona-pm a pm.org
>> http://mail.pm.org/mailman/**listinfo/barcelona-pm<http://mail.pm.org/mailman/listinfo/barcelona-pm>
>> BCN Perl Mongers: http://barcelona.pm.org
>>
>
> ______________________________**_________________
> llista dels Barcelona-pm
> Barcelona-pm a pm.org
> http://mail.pm.org/mailman/**listinfo/barcelona-pm<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/20120503/3e4d3488/attachment-0001.html>
Més informació sobre la llista de correu Barcelona-pm