Exemple #1
0
std::string Cookie::cookieHeaderValue() const
{
   // basic name/value
   std::ostringstream headerValue ;
   headerValue << name() << "=" << value() ;

   // expiries if specified
   if ( !expires().is_not_a_date() )
   {
      date::ymd_type ymd = expires_.year_month_day() ;
      greg_weekday wd = expires_.day_of_week() ;

      headerValue << "; expires=" ;
      headerValue << wd.as_short_string() << ", " 
                  << ymd.day << "-" << ymd.month.as_short_string() << "-" 
                  << ymd.year << " 23:59:59 GMT" ;
   }

   // path if specified
   if ( !path().empty() )
      headerValue << "; path=" << path();

   // domain if specified
   if ( !domain().empty() )
      headerValue << "; domain=" << domain() ;
   
   // http only if specified
   if (httpOnly_)
      headerValue << "; HttpOnly";

   // return the header value 
   return headerValue.str() ;
}
Exemple #2
0
//-------------------------------------------------------------------------------------------------
inline std::tstring_t
CookiePv0::dump() const
{
    std::tstring_t sRv;

    sRv = String::format(
            xT("[CookiePv0 dump]\n\n")
            xT("Name: %s\n")
            xT("Value: %s\n")
            xT("Domain: %s\n")
            xT("Path: %s\n")
            xT("Expires: %s\n")
            xT("Secure: %s\n")
            xT("HttpOnly: %s\n\n"),
            name().c_str(),
            value().c_str(),
            domain().c_str(),
            path().c_str(),
            expires().c_str(),
            String::castBool(secure()).c_str(),
            String::castBool(httpOnly()).c_str()
    );

    return sRv;
}
Exemple #3
0
static int
bound(void)	// udhcpc bound here, also call wanup
{
	char *wan_ifname = safe_getenv("interface");
	char *value;
	char tmp[100], prefix[] = "wanXXXXXXXXXX_";
	int unit;

	if ((unit = wan_ifunit(wan_ifname)) < 0) 
		strcpy(prefix, "wanx_");
	else
		snprintf(prefix, sizeof(prefix), "wan%d_", unit);

	if ((value = getenv("ip")))
		nvram_set(strcat_r(prefix, "ipaddr", tmp), trim_r(value));
	if ((value = getenv("subnet")))
		nvram_set(strcat_r(prefix, "netmask", tmp), trim_r(value));
        if ((value = getenv("router")))
		nvram_set(strcat_r(prefix, "gateway", tmp), trim_r(value));
	if ((value = getenv("dns")))
		nvram_set(strcat_r(prefix, "dns", tmp), trim_r(value));
	if ((value = getenv("wins")))
		nvram_set(strcat_r(prefix, "wins", tmp), trim_r(value));

	nvram_set(strcat_r(prefix, "routes", tmp), getenv("routes"));
	nvram_set(strcat_r(prefix, "msroutes", tmp), getenv("msroutes"));
#if 0
	if ((value = getenv("hostname")))
		sethostname(trim_r(value), strlen(value) + 1);
#endif
	if ((value = getenv("domain")))
		nvram_set(strcat_r(prefix, "domain", tmp), trim_r(value));
	if ((value = getenv("lease"))) {
		nvram_set(strcat_r(prefix, "lease", tmp), trim_r(value));
		expires(wan_ifname, atoi(value));
	}

	ifconfig(wan_ifname, IFUP,
		 nvram_safe_get(strcat_r(prefix, "ipaddr", tmp)),
		 nvram_safe_get(strcat_r(prefix, "netmask", tmp)));

	spinlock_lock(SPINLOCK_DHCPRenew);
	nvram_set("dhcp_renew", "0");	// for detectWAN
	spinlock_unlock(SPINLOCK_DHCPRenew);

	wan_up(wan_ifname);

	logmessage("dhcp client", "%s IP: %s from %s (prefix: %s)", 
		udhcpstate, 
		nvram_safe_get(strcat_r(prefix, "ipaddr", tmp)), 
		nvram_safe_get(strcat_r(prefix, "gateway", tmp)), prefix);

	wanmessage("");
	dprintf("done\n");
	return 0;
}
Exemple #4
0
static int renew(char *ifname)
{
	char *a, *b;
	int changed;

	_dprintf("%s: begin\n", __FUNCTION__);

	unlink(renewing);

	changed = env2nv("ip", "wan_ipaddr");
	changed |= env2nv("subnet", "wan_netmask");
	if (changed) {
		ifconfig(ifname, IFUP, nvram_safe_get("wan_ipaddr"), nvram_safe_get("wan_netmask"));
	}

	if (get_wan_proto() == WP_L2TP) {	
		env2nv_gateway("wan_gateway_buf");
	}
	else {
		a = strdup(nvram_safe_get("wan_gateway"));
		env2nv_gateway("wan_gateway");
		b = nvram_safe_get("wan_gateway");
		if ((a) && (strcmp(a, b) != 0)) {
			route_del(ifname, 0, "0.0.0.0", a, "0.0.0.0");
			route_add(ifname, 0, "0.0.0.0", b, "0.0.0.0");
			changed = 1;
		}
		free(a);
	}
	
	changed |= env2nv("domain", "wan_get_domain");
	changed |= env2nv("dns", "wan_get_dns");

	if ((a = getenv("lease")) != NULL) {
		nvram_set("wan_lease", a);
		expires(atoi(a));
	}

	if (changed) {
		set_host_domain_name();
		stop_dnsmasq();
		dns_to_resolv();
		start_dnsmasq();
	}
	
	_dprintf("wan_ipaddr=%s\n", nvram_safe_get("wan_ipaddr"));
	_dprintf("wan_netmask=%s\n", nvram_safe_get("wan_netmask"));
	_dprintf("wan_gateway=%s\n", nvram_safe_get("wan_gateway"));
	_dprintf("wan_get_domain=%s\n", nvram_safe_get("wan_get_domain"));
	_dprintf("wan_get_dns=%s\n", nvram_safe_get("wan_get_dns"));
	_dprintf("wan_lease=%s\n", nvram_safe_get("wan_lease"));
	_dprintf("%s: end\n", __FUNCTION__);
	return 0;
}
Exemple #5
0
 string_type build() const
 {
     string_type res = name() + string_traits_type::convert("=") + as_string( value() );
     if ( !comment().empty() )
         res += string_traits_type::convert("; comment=") + as_string( comment() );
     if ( !expires().empty() )
         res += string_traits_type::convert("; expires=") + as_string( expires() );
     if ( !max_age().empty() )
         res += string_traits_type::convert("; max-Age=") + as_string( max_age() );
     if ( !path().empty() )
         res += string_traits_type::convert("; path=") + as_string( path() );
     if ( !domain().empty() )
         res += string_traits_type::convert("; domain=") + as_string( domain() );
     if ( !version().empty() )
         res += string_traits_type::convert("; version=") + as_string( version() );
     if ( http_only() )
         res += string_traits_type::convert("; httponly");
     if ( secure() )
         res += string_traits_type::convert("; secure");
     return res;
 }
Exemple #6
0
/*
 * renew: This argument is used when a DHCP lease is renewed. All of
 * the paramaters are set in enviromental variables. This argument is
 * used when the interface is already configured, so the IP address,
 * will not change, however, the other DHCP paramaters, such as the
 * default gateway, subnet mask, and dns server may change.
 */
static int
renew(void)
{
	char *wan_ifname = safe_getenv("interface");
	char *value;
	char tmp[100], prefix[] = "wanXXXXXXXXXX_";
	int unit;

	if ((unit = wan_ifunit(wan_ifname)) < 0)
		strcpy(prefix, "wanx_");
	else
		snprintf(prefix, sizeof(prefix), "wan%d_", unit);

	if (!(value = getenv("subnet")) || !nvram_match(strcat_r(prefix, "netmask", tmp), trim_r(value)))
		return bound();
	if (!(value = getenv("router")) || !nvram_match(strcat_r(prefix, "gateway", tmp), trim_r(value)))
		return bound();

	if ((value = getenv("dns")) && !nvram_match(strcat_r(prefix, "dns", tmp), trim_r(value))) {
		nvram_set(strcat_r(prefix, "dns", tmp), trim_r(value));
#if 0
		update_resolvconf();
#else
		add_dns(wan_ifname);
#endif
	}

	if ((value = getenv("wins")))
		nvram_set(strcat_r(prefix, "wins", tmp), trim_r(value));
#if 0
	if ((value = getenv("hostname")))
		sethostname(trim_r(value), strlen(value) + 1);
#endif
	if ((value = getenv("domain")))
		nvram_set(strcat_r(prefix, "domain", tmp), trim_r(value));
	if ((value = getenv("lease"))) {
		nvram_set(strcat_r(prefix, "lease", tmp), trim_r(value));
		expires(wan_ifname, atoi(value));
	}

	logmessage("dhcp client", "%s IP: %s from %s (prefix: %s)", 
		udhcpstate, 
		nvram_safe_get(strcat_r(prefix, "ipaddr", tmp)), 
		nvram_safe_get(strcat_r(prefix, "gateway", tmp)), prefix);

	if (unit == 0)
		update_wan_status(1);

	wanmessage("");

	dprintf("done\n");
	return 0;
}
Exemple #7
0
/*
 * deconfig: This argument is used when udhcpc starts, and when a
 * leases is lost. The script should put the interface in an up, but
 * deconfigured state.
*/
static int
deconfig(void)
{
	char *wan_ifname = safe_getenv("interface");

	ifconfig(wan_ifname, IFUP,
		 "0.0.0.0", NULL);
	expires(wan_ifname, 0);

	wan_down(wan_ifname);

	dprintf("done\n");
	return 0;
}
Exemple #8
0
static int bound(char *ifname)
{
	_dprintf("%s: begin\n", __FUNCTION__);

	unlink(renewing);

	env2nv("ip", "wan_ipaddr");
	env2nv("subnet", "wan_netmask");
	env2nv_gateway("wan_gateway");
	env2nv("dns", "wan_get_dns");
	env2nv("domain", "wan_get_domain");
	env2nv("lease", "wan_lease");
	expires(atoi(safe_getenv("lease")));
	
	_dprintf("wan_ipaddr=%s\n", nvram_safe_get("wan_ipaddr"));
	_dprintf("wan_netmask=%s\n", nvram_safe_get("wan_netmask"));
	_dprintf("wan_gateway=%s\n", nvram_safe_get("wan_gateway"));
	_dprintf("wan_get_domain=%s\n", nvram_safe_get("wan_get_domain"));
	_dprintf("wan_get_dns=%s\n", nvram_safe_get("wan_get_dns"));
	_dprintf("wan_lease=%s\n", nvram_safe_get("wan_lease"));
	

	ifconfig(ifname, IFUP, nvram_safe_get("wan_ipaddr"), nvram_safe_get("wan_netmask"));

	if (get_wan_proto() == WP_L2TP) {
		int i = 0;

		/* Delete all default routes */
		while ((route_del(ifname, 0, NULL, NULL, NULL) == 0) || (i++ < 10));

		/* Set default route to gateway if specified */
		route_add(ifname, 0, "0.0.0.0", nvram_safe_get("wan_gateway"), "0.0.0.0");

		/* Backup the default gateway. It should be used if L2TP connection is broken */
		nvram_set("wan_gateway_buf", nvram_get("wan_gateway"));

		/* clear dns from the resolv.conf */
		nvram_set("wan_get_dns","");
		dns_to_resolv();

		start_firewall();
		start_l2tp();
	}
	else {
		start_wan_done(ifname);
	}

	_dprintf("%s: end\n", __FUNCTION__);
	return 0;
}
/* 
 * deconfig: This argument is used when udhcpc starts, and when a
 * leases is lost. The script should put the interface in an up, but
 * deconfigured state.
*/
static int
deconfig(void)
{
	char *lan_ifname = safe_getenv("interface");

	ifconfig(lan_ifname, IFUP,
		 "0.0.0.0", NULL);

	expires(lan_ifname, 0);

	lan_down(lan_ifname);

	logmessage("dhcp client", "%s: lease is lost", udhcpstate);
	//wanmessage("lost IP from server");

	dprintf("done\n");
	return 0;
}
/*
 * bound: This argument is used when udhcpc moves from an unbound, to
 * a bound state. All of the paramaters are set in enviromental
 * variables, The script should configure the interface, and set any
 * other relavent parameters (default gateway, dns server, etc).
*/
static int
bound(void)
{
	char *lan_ifname = safe_getenv("interface");
	char *value;
	char tmp[100], prefix[] = "lanXXXXXXXXXX_";

	snprintf(prefix, sizeof(prefix), "lan_");
	
	if ((value = getenv("ip")))
		nvram_set(strcat_r(prefix, "ipaddr", tmp), value);
	if ((value = getenv("subnet")))
		nvram_set(strcat_r(prefix, "netmask", tmp), value);
        if ((value = getenv("router")))
		nvram_set(strcat_r(prefix, "gateway", tmp), value);
	if ((value = getenv("dns")))
		nvram_set(strcat_r(prefix, "dns", tmp), value);
	if ((value = getenv("wins")))
		nvram_set(strcat_r(prefix, "wins", tmp), value);
	if ((value = getenv("hostname")))
		sethostname(value, strlen(value) + 1);
	if ((value = getenv("domain")))
		nvram_set(strcat_r(prefix, "domain", tmp), value);
	if ((value = getenv("lease"))) {
		nvram_set(strcat_r(prefix, "lease", tmp), value);
		expires(lan_ifname, atoi(value));
	}

	ifconfig(lan_ifname, IFUP,
		 nvram_safe_get(strcat_r(prefix, "ipaddr", tmp)),
		 nvram_safe_get(strcat_r(prefix, "netmask", tmp)));

	lan_up(lan_ifname);

	logmessage("dhcp client", "%s IP : %s from %s", 
		udhcpstate, 
		nvram_safe_get(strcat_r(prefix, "ipaddr", tmp)), 
		nvram_safe_get(strcat_r(prefix, "gateway", tmp)));

	//wanmessage("");

	dprintf("done\n");
	return 0;
}
Exemple #11
0
static int deconfig(char *ifname)
{
	_dprintf("%s: begin\n", __FUNCTION__);

	ifconfig(ifname, IFUP, "0.0.0.0", NULL);

	nvram_set("wan_ipaddr", "0.0.0.0");
	nvram_set("wan_netmask", "0.0.0.0");
	nvram_set("wan_gateway", "0.0.0.0");
	nvram_set("wan_get_dns", "");
	nvram_set("wan_lease", "0");
	expires(0);

	//	int i = 10;
	//	while ((route_del(ifname, 0, NULL, NULL, NULL) == 0) && (i-- > 0)) { }

	_dprintf("%s: end\n", __FUNCTION__);
	return 0;
}
Exemple #12
0
/*
 * deconfig: This argument is used when udhcpc starts, and when a
 * leases is lost. The script should put the interface in an up, but
 * deconfigured state.
 */
static int deconfig(void)
{
	char *wan_ifname = safe_getenv("interface");

	eval("ifconfig", wan_ifname, "0.0.0.0", "up");
	expires(0);

	nvram_set("wan_ipaddr", "0.0.0.0");
	nvram_set("wan_netmask", "0.0.0.0");
	nvram_set("wan_gateway", "0.0.0.0");
	nvram_set("wan_get_dns", "");
	// nvram_set("wan_wins","0.0.0.0"); // Don't care for linksys spec
	nvram_set("wan_lease", "0");

	unlink("/tmp/get_lease_time");
	unlink("/tmp/lease_time");

	cprintf("done\n");
	return 0;
}
Exemple #13
0
/* 
 * deconfig: This argument is used when udhcpc starts, and when a
 * leases is lost. The script should put the interface in an up, but
 * deconfigured state.
*/
static int
deconfig(void)
{
	char *wan_ifname = safe_getenv("interface");

	if (nvram_match("wan0_proto", "l2tp") || nvram_match("wan0_proto", "pptp"))
	{
		/* fix hang-up issue */
		logmessage("dhcp client", "skipping resetting IP address to 0.0.0.0");
	} else
		ifconfig(wan_ifname, IFUP, "0.0.0.0", NULL);
	expires(wan_ifname, 0);

	wan_down(wan_ifname);

	logmessage("dhcp client", "%s: lease is lost", udhcpstate);
	wanmessage("lost IP from server");

	return 0;
}
Exemple #14
0
/*
 * bound: This argument is used when udhcpc moves from an unbound, to
 * a bound state. All of the paramaters are set in enviromental
 * variables, The script should configure the interface, and set any
 * other relavent parameters (default gateway, dns server, etc).
*/
static int
bound(void)
{
	char *wan_ifname = safe_getenv("interface");
	char *value;
	char tmp[100], prefix[] = "wanXXXXXXXXXX_";
	int unit;

	if ((unit = wan_ifunit(wan_ifname)) < 0)
		return -1;

	snprintf(prefix, sizeof(prefix), "wan%d_", unit);

	if ((value = getenv("ip")))
		nvram_set(strcat_r(prefix, "ipaddr", tmp), value);
	if ((value = getenv("subnet")))
		nvram_set(strcat_r(prefix, "netmask", tmp), value);
	if ((value = getenv("router")))
		nvram_set(strcat_r(prefix, "gateway", tmp), value);
	if ((value = getenv("dns")))
		nvram_set(strcat_r(prefix, "dns", tmp), value);
	if ((value = getenv("wins")))
		nvram_set(strcat_r(prefix, "wins", tmp), value);
	if ((value = getenv("hostname")))
		sethostname(value, strlen(value) + 1);
	if ((value = getenv("domain")))
		nvram_set(strcat_r(prefix, "domain", tmp), value);
	if ((value = getenv("lease"))) {
		nvram_set(strcat_r(prefix, "lease", tmp), value);
		expires(wan_ifname, atoi(value));
	}

	ifconfig(wan_ifname, IFUP,
		nvram_safe_get(strcat_r(prefix, "ipaddr", tmp)),
		nvram_safe_get(strcat_r(prefix, "netmask", tmp)));

	wan_up(wan_ifname);

	dprintf("done\n");
	return 0;
}
Exemple #15
0
int main(int argc, char **argv)
{
// 	#ifdef Q_WS_X11
// 		XInitThreads();
// 	#endif
//
	#if !defined(Q_OS_MAC) // raster on OSX == b0rken
		// use the Raster GraphicsSystem as default on 4.5+
		#if QT_VERSION >= 0x040500
		QApplication::setGraphicsSystem("raster");
		#endif
 	#endif

 	#if defined(Q_OS_WIN)
        //	QApplication::setStyle(new QtDotNetStyle()); //QtDotNetStyle::Office));
	#endif

 	QApplication app(argc, argv);

        QPixmap pixmap(":/data/DViz-splash.png");
        QSplashScreen splash(pixmap);
        splash.show();
        app.processEvents();
        app.processEvents();

	AppSettings::initApp("DVizControl");

	AppSettings::load();

	QSettings s;
	//if(s.value("first-run-date").isValid())
	//{
		QDate today = QDate::currentDate();
		QDate expires(2010,12,31);
		//QDate f = s.value("first-run-date").toDate();
		//int days = f.daysTo(d);
		QString ver = "DViz Beta";
		#define VER "r701"
#ifdef VER
		ver += QString(", Build %1").arg(VER);
#endif
/*
 		if(today > expires)
 		{
 			QMessageBox::critical(0,QString("%1 Expired").arg(ver),"Sorry, but this evaluation copy of DViz has expired. You can buy the non-eval version from Josiah Bryan - email [email protected] for more information.\n\nOr, you can set your computer's clock back a day or two and keep using this evaluation version till you make up your mind. Thanks for trying out DViz!");
 			return 0;
 		}
 		else
 		{
 			QMessageBox::information(0,ver,QString("Thanks for trying %1! This evaluation copy is valid until 2010-12-31, at which time you'll be asked to purchase the non-eval verson from Josiah Bryan. If you find ANY issues or have any ideas for improvement, PLEASE speak up and log a new issue at:\n\n    http://code.google.com/p/dviz/issues/list\n").arg(ver));
 		}
*/
	//}

	if(AppSettings::registrationName().isEmpty() ||
	   AppSettings::registrationOrgName().isEmpty())
	{
		QString nameGuess = AppSettings::registrationName();
		QString orgGuess = AppSettings::registrationOrgName();
		
		qDebug() << "main debug:"<<nameGuess<<orgGuess;
		
		#ifdef Q_OS_WIN
		/*
		QSettings settings;
		settings.insertSearchPath( QSettings::Windows,"/Microsoft/Windows/CurrentVersion");
		nameGuess = settings.readEntry( "/RegisteredOwner" );
		orgGuess = settings.readEntry( "/RegisteredOrganization" );

		if(nameGuess.isEmpty())
		{
			LPTSTR lpszSystemInfo; // pointer to system information
			DWORD cchBuff = 256; // size of user name
			TCHAR tchBuffer[UNLEN + 1]; // buffer for expanded string

			lpszSystemInfo = tchBuffer;

			// Get and display the user name.
			GetUserName(lpszSystemInfo, &cchBuff);

			//Unicode string needs to be converted
			nameGuess = QString::fromUcs2(lpszSystemInfo);
		}
		*/
		#endif
		
		#ifdef Q_OS_LINUX
		nameGuess = QString( getenv("USER") );
		#endif
		
		bool ok;
		QString text = QInputDialog::getText(0, QObject::tr("Confirm Your Name"),
							QObject::tr("Your name:"), QLineEdit::Normal,
							nameGuess, &ok);
		if (ok && !text.isEmpty())
			AppSettings::setRegistrationName(text);
		
		text = QInputDialog::getText(0,		QObject::tr("Confirm Your Organization"),
							QObject::tr("Your organization:"), QLineEdit::Normal,
							orgGuess, &ok);
		if (ok && !text.isEmpty())
			AppSettings::setRegistrationOrgName(text);
	
		AppSettings::save();
	}


	MainWindow *mw = new MainWindow();
	mw->show();
	
	CheckUpdatesDialogLauncher *update = new CheckUpdatesDialogLauncher();
	QObject::connect(update, SIGNAL(updateCheckFinished()), update, SLOT(deleteLater()));
	update->start();
	

	splash.hide();
	int ret = app.exec();

	AppSettings::save();

	// dont delete mw because something in the Qt library is causing
	// a SEGFLT on windows and I cant get gdb to work right on windows
	// inorder to trace it. Therefore, just bypass the bug by not deleting
	// mw - the memory will be released to the OS anyway since we are
	// exiting the program here.

	return ret;
}
Exemple #16
0
static int bound(void)
{
	nvram_unset("dhcpc_done");
	char *wan_ifname = safe_getenv("interface");
	char *value;
	static char temp_wan_ipaddr[16], temp_wan_netmask[16],
	    temp_wan_gateway[16];
	int changed = 0;
	static char *cidr;
	if (nvram_match("wan_proto", "iphone"))
		stop_process("ipheth-loop", "IPhone Pairing Daemon");

	cidr = getenv("cidrroute");
	if (cidr && wan_ifname) {
		char *callbuffer = malloc(strlen(cidr) + 128);
		sprintf(callbuffer,
			"export cidrroute=\"%s\";export interface=\"%s\";/etc/cidrroute.sh",
			cidr, wan_ifname);
		system(callbuffer);
		free(callbuffer);
	}

	if ((value = getenv("ip"))) {
		chomp(value);
		if (nvram_match("wan_proto", "pptp")
		    && nvram_match("pptp_use_dhcp", "1"))
			strcpy(temp_wan_ipaddr, value);
		else {
			if (nvram_invmatch("wan_ipaddr", value))
				changed = 1;
		}
		nvram_set("wan_ipaddr", value);
	}
	if ((value = getenv("subnet"))) {
		chomp(value);
		if (nvram_match("wan_proto", "pptp")
		    && nvram_match("pptp_use_dhcp", "1"))
			strcpy(temp_wan_netmask, value);
		else {
			if (nvram_invmatch("wan_netmask", value))
				changed = 1;
			nvram_set("wan_netmask", value);
		}
	}
	if ((value = getenv("router"))) {
		chomp(value);
		if (nvram_invmatch("wan_gateway", value))
			changed = 1;
		nvram_set("wan_gateway", value);
	}
	if ((value = getenv("dns"))) {
		chomp(value);
		// if (nvram_invmatch("wan_get_dns",value))
		// changed=1; 
		nvram_set("wan_get_dns", value);
	}
	/*
	 * Don't care for linksys spec if ((value = getenv("wins")))
	 * nvram_set("wan_wins", value); if ((value = getenv("hostname")))
	 * sethostname(value, strlen(value) + 1); 
	 */
	if ((value = getenv("domain"))) {
		chomp(value);
		if (nvram_invmatch("wan_get_domain", value))
			changed = 1;
		nvram_set("wan_get_domain", value);	// HeartBeat need to use
	}
	if ((value = getenv("lease"))) {
		chomp(value);
		nvram_set("wan_lease", value);
		expires(atoi(value));
	}
	if (!changed) {
		cprintf("interface hasnt changed, do nothing\n");
		return 0;
	}
	stop_firewall();
	cprintf("configure to IF[%s] , IP[%s], MASK[%s]\n", wan_ifname,
		nvram_safe_get("wan_ipaddr"), nvram_safe_get("wan_netmask"));

	if (nvram_match("wan_proto", "pptp")
	    && nvram_match("pptp_use_dhcp", "1"))
		eval("ifconfig", wan_ifname, temp_wan_ipaddr, "netmask",
		     temp_wan_netmask, "up");
	else
		eval("ifconfig", wan_ifname, nvram_safe_get("wan_ipaddr"),
		     "netmask", nvram_safe_get("wan_netmask"), "up");

	/*
	 * We only want to exec bellow functions after dhcp get ip if the
	 * wan_proto is heartbeat 
	 */
#ifdef HAVE_HEARTBEAT
	if (nvram_match("wan_proto", "heartbeat")) {
		int i = 0;

		/*
		 * Delete all default routes 
		 */
		while (route_del(wan_ifname, 0, NULL, NULL, NULL) == 0
		       || i++ < 10) ;

		/*
		 * Set default route to gateway if specified 
		 */
		route_add(wan_ifname, 0, "0.0.0.0",
			  nvram_safe_get("wan_gateway"), "0.0.0.0");

		/*
		 * save dns to resolv.conf 
		 */
		dns_to_resolv();
		stop_udhcpd();
		start_udhcpd();
		start_firewall();
		stop_wland();
		start_wshaper();
		start_wland();
		start_heartbeat_boot();
	}
#else
	if (0) {
		// nothing
	}
#endif
#ifdef HAVE_PPTP
	else if (nvram_match("wan_proto", "pptp")
		 && nvram_match("pptp_use_dhcp", "1")) {
		char pptpip[64];
		struct dns_lists *dns_list = NULL;

		dns_to_resolv();

		dns_list = get_dns_list();
		int i = 0;

		if (dns_list) {
			for (i = 0; i < dns_list->num_servers; i++)
				route_add(wan_ifname, 0,
					  dns_list->dns_server[i],
					  nvram_safe_get("wan_gateway"),
					  "255.255.255.255");
			free(dns_list);
		}
		route_add(wan_ifname, 0, "0.0.0.0",
			  nvram_safe_get("wan_gateway"), "0.0.0.0");

		nvram_set("wan_gateway_buf", nvram_get("wan_gateway"));

		getIPFromName(nvram_safe_get("pptp_server_name"), pptpip);
		nvram_set("pptp_server_ip", pptpip);

		// Add the route to the PPTP server on the wan interface for pptp
		// client to reach it
		if (nvram_match("wan_gateway", "0.0.0.0")
		    || nvram_match("wan_netmask", "0.0.0.0"))
			route_add(wan_ifname, 0,
				  nvram_safe_get("pptp_server_ip"),
				  nvram_safe_get("wan_gateway"),
				  "255.255.255.255");
		else
			route_add(wan_ifname, 0,
				  nvram_safe_get("pptp_server_ip"),
				  nvram_safe_get("wan_gateway"),
				  nvram_safe_get("wan_netmask"));

	}
#endif
#ifdef HAVE_L2TP
	else if (nvram_match("wan_proto", "l2tp")) {
		char l2tpip[64];
		struct dns_lists *dns_list = NULL;

		dns_to_resolv();

		dns_list = get_dns_list();

		int i = 0;

		if (dns_list) {
			for (i = 0; i < dns_list->num_servers; i++)
				route_add(wan_ifname, 0,
					  dns_list->dns_server[i],
					  nvram_safe_get("wan_gateway"),
					  "255.255.255.255");
			free(dns_list);
		}

		/*
		 * Backup the default gateway. It should be used if L2TP connection
		 * is broken 
		 */
		nvram_set("wan_gateway_buf", nvram_get("wan_gateway"));

		getIPFromName(nvram_safe_get("l2tp_server_name"), l2tpip);

		nvram_set("l2tp_server_ip", l2tpip);

		route_add(wan_ifname, 0,
			  nvram_safe_get("l2tp_server_ip"),
			  nvram_safe_get("wan_gateway"), "255.255.255.255");

		start_firewall();
		start_l2tp_boot();
	}
#endif
	else {
		cprintf("start wan done\n");
		start_wan_done(wan_ifname);
	}
	nvram_set("dhcpc_done", "1");
	cprintf("done\n");
	return 0;
}
Exemple #17
0
Json::Value
ValidatorList::getJson() const
{
    Json::Value res(Json::objectValue);

    boost::shared_lock<boost::shared_mutex> read_lock{mutex_};

    res[jss::validation_quorum] = static_cast<Json::UInt>(quorum());

    if (auto when = expires())
    {
        if (*when == TimeKeeper::time_point::max())
            res[jss::validator_list_expires] = "never";
        else
            res[jss::validator_list_expires] = to_string(*when);
    }
    else
        res[jss::validator_list_expires] = "unknown";

    // Local static keys
    PublicKey local;
    Json::Value& jLocalStaticKeys =
        (res[jss::local_static_keys] = Json::arrayValue);
    auto it = publisherLists_.find(local);
    if (it != publisherLists_.end())
    {
        for (auto const& key : it->second.list)
            jLocalStaticKeys.append(
                toBase58(TokenType::TOKEN_NODE_PUBLIC, key));
    }

    // Publisher lists
    Json::Value& jPublisherLists =
        (res[jss::publisher_lists] = Json::arrayValue);
    for (auto const& p : publisherLists_)
    {
        if(local == p.first)
            continue;
        Json::Value& curr = jPublisherLists.append(Json::objectValue);
        curr[jss::pubkey_publisher] = strHex(p.first);
        curr[jss::available] = p.second.available;
        if(p.second.expiration != TimeKeeper::time_point{})
        {
            curr[jss::seq] = static_cast<Json::UInt>(p.second.sequence);
            curr[jss::expiration] = to_string(p.second.expiration);
            curr[jss::version] = requiredListVersion;
        }
        Json::Value& keys = (curr[jss::list] = Json::arrayValue);
        for (auto const& key : p.second.list)
        {
            keys.append(toBase58(TokenType::TOKEN_NODE_PUBLIC, key));
        }
    }

    // Trusted validator keys
    Json::Value& jValidatorKeys =
        (res[jss::trusted_validator_keys] = Json::arrayValue);
    for (auto const& k : trustedKeys_)
    {
        jValidatorKeys.append(toBase58(TokenType::TOKEN_NODE_PUBLIC, k));
    }

    // signing keys
    Json::Value& jSigningKeys = (res[jss::signing_keys] = Json::objectValue);
    validatorManifests_.for_each_manifest(
        [&jSigningKeys, this](Manifest const& manifest) {

            auto it = keyListings_.find(manifest.masterKey);
            if (it != keyListings_.end())
            {
                jSigningKeys[toBase58(
                    TokenType::TOKEN_NODE_PUBLIC, manifest.masterKey)] =
                    toBase58(TokenType::TOKEN_NODE_PUBLIC, manifest.signingKey);
            }
        });

    return res;
}
Exemple #18
0
// ==================================================================
static int update_value(void)
{

	char *value;
	int changed = 0;

	if ((value = getenv("ip"))) {
		chomp(value);
		if (nvram_invmatch("wan_ipaddr", value)) {
			nvram_set("wan_ipaddr", value);
			changed++;
		}
	}
	if ((value = getenv("subnet"))) {
		chomp(value);
		if (nvram_invmatch("wan_netmask", value)) {
			nvram_set("wan_netmask", value);
			changed++;
		}
	}
	if ((value = getenv("router"))) {
		chomp(value);
		if (nvram_invmatch("wan_gateway", value)) {
			nvram_set("wan_gateway", value);
			changed++;
		}
	}
	if ((value = getenv("dns"))) {
		chomp(value);
		if (nvram_invmatch("wan_get_dns", value)) {
			nvram_set("wan_get_dns", value);
			changed++;
		}
	}
	/*
	 * if ((value = getenv("wins"))) nvram_set("wan_wins", value); if ((value 
	 * = getenv("hostname"))) sethostname(value, strlen(value) + 1); 
	 */
	if ((value = getenv("domain"))) {
		chomp(value);
		if (nvram_invmatch("wan_get_domain", value)) {
			nvram_set("wan_get_domain", value);
			changed++;
		}
	}
	if ((value = getenv("lease"))) {
		chomp(value);
		if (nvram_invmatch("wan_lease", value)) {
			nvram_set("wan_lease", value);
			changed++;
		}
		expires(atoi(value));
	}

	if (changed) {
		set_host_domain_name();
#ifdef HAVE_UDHCPD
		stop_udhcpd();
		start_udhcpd();
#endif
	}
	return 0;
}