Esempio n. 1
0
static int
cp_redir_url_response (int fd,redir_msg_t * msg,int do_ssl)
{
    char *buffer;
    int len = 0;
#if 0 
    len = asprintf
        (&buffer,
         "HTTP/1.1 302 Found\r\nLocation: "
         "%s?vendor=%s&version=%s&identifier=%s&ap_ip=%s&ap_port=%d&ap_mac=%s&client_mac=%s&client_ip=%s&redirect_url=%s"
         "\r\nConnection: close\r\n\r\n",
         msg->wki->splash_url, msg->wki->vendor,
         msg->wki->fw_version, msg->wki->identifier,
         inet_ntoa (msg->wki->ap_addr.ipv4), 8080/**/, 
         mactoa( msg->wki->ap_addr.mac),
         mactoa(msg->client_addr->mac),
         inet_ntoa (msg->client_addr->ipv4),
         "http://www.google.com");
#else
		CP_ERROR(1,"Splash URL from the dman %s\n",msg->wki->splash_url);
    len = asprintf
        (&buffer,
         "HTTP/1.1 302 Found\r\nLocation: "
         "https://www.google.com/"
         "\r\nConnection: close\r\n\r\n");
#endif
    if (len < 1)
    {
        CP_ERROR (1, "URL generate asprintf failed");
        return FAILURE;
    }
    printf ("Response URL:-    %s\n", buffer);
    len = cp_send(fd, buffer, len+1,do_ssl);
    if (len < 1)
    {
        free(buffer);
        CP_ERROR (1, "Response writting failed");
        return FAILURE;
    }
    else
    {
        CP_ERROR (1, "Response writting success");
    }
    free(buffer);
    return SUCCESS;
}
Esempio n. 2
0
void http_settings(char *rx, unsigned int rx_len)
{
  unsigned int item, found, len;
  int i;
  char buf[16];
  MAC_Addr mac;
  IP_Addr ip;
  unsigned int rgb;

  for(; rx_len!=0;)
  {
    len = strlen("restartwebradio=");
    if(strncmpi(rx, "restartwebradio=", len) == 0)
    {
      rx += len; rx_len -= len;
      cpu_reset();
    }

    for(item=0, found=0; item<SETTINGSITEMS; item++)
    {
      if(settingsmenu[item].ini[0] == 0)
      {
        continue;
      }
      len = sprintf(buf, "%s=", settingsmenu[item].ini);
      if(strncmpi(rx, buf, len) == 0)
      {
        rx += len; rx_len -= len;
        len = url_decode(rx, rx, rx_len);
        i   = 0;
        switch(settingsmenu[item].format)
        {
          case F_NR:  //p1-p2, p3=step size
            i = atoi(rx);
                 if(i < settingsmenu[item].p1){ i = settingsmenu[item].p1; }
            else if(i > settingsmenu[item].p2){ i = settingsmenu[item].p2; }
            itoa(i, buf, 10);
            ini_setentry(SETTINGS_FILE, settingsmenu[item].ini, buf);
            if(settingsmenu[item].set){ settingsmenu[item].set((void*)(int)i); }
            break;

          case F_OR:  //p1 or p2
            i = atoi(rx);
            if((i != settingsmenu[item].p1) && 
               (i != settingsmenu[item].p2)){ i = settingsmenu[item].p1; }
            itoa(i, buf, 10);
            ini_setentry(SETTINGS_FILE, settingsmenu[item].ini, buf);
            if(settingsmenu[item].set){ settingsmenu[item].set((void*)(int)i); }
            break;

          case F_STR: //p1=max len
            if((settingsmenu[item].p1 != 0) &&
              (strlen(rx) > (unsigned)settingsmenu[item].p1))
            {
              rx[settingsmenu[item].p1] = 0;
            }
            ini_setentry(SETTINGS_FILE, settingsmenu[item].ini, rx);
            if(settingsmenu[item].set){ settingsmenu[item].set(rx); }
            break;

          case F_MAC:
            mac = atomac(rx);
            ini_setentry(SETTINGS_FILE, settingsmenu[item].ini, mactoa(mac));
            //if(settingsmenu[item].set){ settingsmenu[item].set((void*)(MAC_Addr)mac); }
            break;

          case F_IP:
            ip = atoip(rx);
            ini_setentry(SETTINGS_FILE, settingsmenu[item].ini, iptoa(ip));
            if(settingsmenu[item].set){ settingsmenu[item].set((void*)(IP_Addr)atoip(rx)); }
            break;

          case F_RGB:
            rgb = atorgb(rx);
            sprintf(buf, "%03i,%03i,%03i", GET_RED(rgb), GET_GREEN(rgb), GET_BLUE(rgb));
            ini_setentry(SETTINGS_FILE, settingsmenu[item].ini, buf);
            if(settingsmenu[item].set){ settingsmenu[item].set((void*)(unsigned int)rgb); }
            break;
        }
        rx += len; rx_len -= len;
        found = 1;
        break;
      }
    }
    if(found == 0)
    {
      rx++; rx_len--;
    }
  }

  menu_drawwnd(1);

  return;
}
Esempio n. 3
0
void rtmon_check_updates(struct rtmon_t *rtmon) {
  int i, j;
  for (i=0; i < rtmon->_route_sz; i++) {
    if (rtmon->_routes[i].has_data) {
      if (rtmon->_routes[i].destination.s_addr == 0) {

	syslog(LOG_DEBUG, "Default Route %s", inet_ntoa(rtmon->_routes[i].gateway));

	for (j=0; j < rtmon->_iface_sz; j++) {
	  if (rtmon->_ifaces[j].has_data) {
	    if (rtmon->_routes[i].if_index == rtmon->_ifaces[j].index) {
	      struct arpreq areq;
	      struct sockaddr_in *sin;
	      int s, attempt=0, retries=3;

	      syslog(LOG_DEBUG, "Route Interface %s", rtmon->_ifaces[j].devname);

	      if ((s = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
		perror("socket");
		return;
	      }

	      memset(&areq, 0, sizeof(areq));
	      sin = (struct sockaddr_in *) &areq.arp_pa;

	      sin->sin_family = AF_INET;
	      sin->sin_addr.s_addr = rtmon->_routes[i].gateway.s_addr;

	      strlcpy(areq.arp_dev, rtmon->_ifaces[j].devname, sizeof(areq.arp_dev));

	      while (attempt < retries) {
		struct sockaddr_in addr;
		char b[1]={0};

		memset(&addr, 0, sizeof(addr));
		addr.sin_family = AF_INET;
		addr.sin_addr = sin->sin_addr;
		addr.sin_port = htons(10000);

		if (sendto(s, b, sizeof(b), 0,
			   (struct sockaddr *) &addr,
			   sizeof(addr)) < 0)
		  perror("sendto");

		if (ioctl(s, SIOCGARP, (caddr_t) &areq) == -1) {

		  if (errno == ENXIO) {
		    syslog(LOG_DEBUG, "%s -- no entry\n", inet_ntoa(sin->sin_addr));
		    attempt++;
		    sleep(1);
		    continue;
		  }
		  else { perror("SIOCGARP"); break; }

		} else {

		  syslog(LOG_DEBUG, "MAC %s", mactoa((uint8_t *)&areq.arp_ha.sa_data));
		  memcpy(rtmon->_routes[i].gwaddr, &areq.arp_ha.sa_data, sizeof(rtmon->_routes[i].gwaddr));

		  if (rtmon->cb(rtmon, &rtmon->_ifaces[j], &rtmon->_routes[i]))
		    syslog(LOG_ERR, "%s: callback failed", strerror(errno));

		  break;
		}
	      }

	      close(s);
	      return;
	    }
	  }
	}
      }
    }
  }
}