Loading...
Pages: [1]   Go Down
Author Topic: Ethernet shield Usuario y Contraseña  (Read 382 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hola, gracias a vuestros aportes voy consiguiendo comunicarme con la ethernet shiel y manejar algunos reles, las preguntas son:
¿Existe la posibilidad de implementar el echo de que te pida al conectarse un usuario y una contraseña?, no sería agradable que cualquiera pudiese conectarse y manejar las cosas a su entorno, en caso de poderse cómo se hace para que pueda entenderlo o buscar información de forma sencilla.
¿Como se hace para diseñar un entorno web en el que se muestren los botones que controlen dichos relés?, quizá se diseña algo en html y luego se añade al sketc?.
Logged

Spain
Offline Offline
Full Member
***
Karma: 7
Posts: 101
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Pues ando yo metido en un proyecto de acuario (sí, ya sé que hay muchos, pero es el hacerlo a mi manera lo que me llama smiley-razz) y en un futuro creo que ya no muy lejano me tengo que pelear con lo mismo que tú.
Creo que lo primero es lo que has preguntado en segundo lugar, y básicamente lo que tienes que meter en el arduino es código html, pero condicional. Vamos, supongo que mucho código estilo sprintf("<h1>Estado rele1: %s</h1>", varEstadoRele1).
En cuanto a la seguridad, hay varias soluciones diferentes con sus pros y contras. Lo de user/password (o password a secas, si no va a haber más de un usuario) para abrir la puerta a un cliente determinado se debería poder hacer sin demasiada complicación, creo yo (desde la felicidad que da la ignorancia smiley-wink).
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Pues esperemos que algún entendido en la materia nos ilustre con sus conocimeintos para el tema de la seguridad.
He buscado bastante por internet y no encuentro nada claro, teniendo en cuenta mi inexperiencia también,seguro que hay algo para hacer que te pida un usuario y una contraseña antes de acceder y poder manejar los relés.....etc.
Logged

Spain
Offline Offline
Full Member
***
Karma: 7
Posts: 101
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Pero ¿Has echado un vistazo, al menos, al ejemplo de webserver? Si comienzas con hacer funcionar ese ejemplo, creo que no es tan complicado ir desarrollando lo que buscas si lo estudias con un poco de detenimiento. Lógicamente, tendrás que conocer un poco el lenguaje html, que es lo que ha de devolver tu arduino.
Ya te digo que yo aún no he llegado ahí, aunque he mirado ya un poco la librería y el ejemplo webserver. En éste creo que hay un objeto que se llama client y que representa a un cliente conectado al arduino. Supongo que con agregarle una variable que indique si se ha logueado correctamente no debería ser muy complicado poner en un if que conteste a ciertas peticiones web sólo si esa variable es true, o incluso que te redireccione a una página porno si es false. La primera página que envíe tu arduino deberá ser un html con un formulario que le envíe luego los datos user y password, y si coinciden con los almacenados en arduino poner ese cliente como autentificado y mostrar la página correcta.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 15
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Buenas,

Puedes usar la libreria webduino, que ya trae un ejemplo de autentificado, poco seguro, pero que puedes tomar como base, ya que es bastante simple
Code:
/* Web_Authentication.ino - Webduino Authentication example */

/* This example assumes that you're familiar with the basics
 * of the Ethernet library (particularly with setting MAC and
 * IP addresses) and with the basics of Webduino. If you
 * haven't had a look at the HelloWorld example you should
 * probably check it out first */

/* you can change the authentication realm by defining
 * WEBDUINO_AUTH_REALM before including WebServer.h */
#define WEBDUINO_AUTH_REALM "Weduino Authentication Example"

#include "SPI.h"
#include "Ethernet.h"
#include "WebServer.h"

/* CHANGE THIS TO YOUR OWN UNIQUE VALUE.  The MAC number should be
 * different from any other devices on your network or you'll have
 * problems receiving packets. */
static uint8_t mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

/* CHANGE THIS TO MATCH YOUR HOST NETWORK.  Most home networks are in
 * the 192.168.0.XXX or 192.168.1.XXX subrange.  Pick an address
 * that's not in use and isn't going to be automatically allocated by
 * DHCP from your router. */
static uint8_t ip[] = { 192, 168, 1, 210 };

/* This creates an instance of the webserver.  By specifying a prefix
 * of "", all pages will be at the root of the server. */
#define PREFIX ""
WebServer webserver(PREFIX, 80);

void defaultCmd(WebServer &server, WebServer::ConnectionType type, char *, bool)
{
  server.httpSuccess();
  if (type != WebServer::HEAD)
  {
    P(helloMsg) = "<h1>Hello, World!</h1><a href=\"private.html\">Private page</a>";
    server.printP(helloMsg);
  }
}

void privateCmd(WebServer &server, WebServer::ConnectionType type, char *, bool)
{
  /* if the user has requested this page using the following credentials
   * username = user
   * password = user
   * display a page saying "Hello User"
   *
   * the credentials have to be concatenated with a colon like
   * username:password
   * and encoded using Base64 - this should be done outside of your Arduino
   * to be easy on your resources
   *
   * in other words: "dXNlcjp1c2Vy" is the Base64 representation of "user:user"
   *
   * if you need to change the username/password dynamically please search
   * the web for a Base64 library */
  if (server.checkCredentials("dXNlcjp1c2Vy"))
  {
    server.httpSuccess();
    if (type != WebServer::HEAD)
    {
      P(helloMsg) = "<h1>Hello User</h1>";
      server.printP(helloMsg);
    }
  }
  /* if the user has requested this page using the following credentials
   * username = admin
   * password = admin
   * display a page saying "Hello Admin"
   *
   * in other words: "YWRtaW46YWRtaW4=" is the Base64 representation of "admin:admin" */
  else if (server.checkCredentials("YWRtaW46YWRtaW4="))
  {
    server.httpSuccess();
    if (type != WebServer::HEAD)
    {
      P(helloMsg) = "<h1>Hello Admin</h1>";
      server.printP(helloMsg);
    }
  }
  else
  {
    /* send a 401 error back causing the web browser to prompt the user for credentials */
    server.httpUnauthorized();
  }
}

void setup()
{
  Ethernet.begin(mac, ip);
  webserver.setDefaultCommand(&defaultCmd);
  webserver.addCommand("index.html", &defaultCmd);
  webserver.addCommand("private.html", &privateCmd);
  webserver.begin();
}

void loop()
{
  char buff[64];
  int len = 64;

  /* process incoming connections one at a time forever */
  webserver.processConnection(buff, &len);
}

Saludos
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Gracias, aun así algunos sketch cuando los cargo o intento cargar me da errores,supongo será por el tema de las librerias......seguiré leyendo
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 15
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Pero te refieres al ejemplo que he puesto? Es 100% funcional, lo unico que tienes que incorporar, es la libreria webduino, esta aqui https://code.google.com/p/webduino/downloads/list

Saludos
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

NO, tu ejemplo me funciona bien, lo que me da guerra es a la hora de cargar otros sketch que se presuponen funcionan bien, supongo que es porque no tengo claro aún lo de las librerias........las oficiales,las de los foreros,poner unas u otras en fin, que como llevo muy poco con esto pues nada......ya me iré peleando con ello.
De todas formas si me recomiendas algún tutorial o algo así facil de entender. smiley-wink
Logged

Pages: [1]   Go Up
Print
 
Jump to: