From 086f21ed70c56b1f52791816acd812fa6d5b3ed3 Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Sun, 17 May 2015 15:51:07 -0700 Subject: Refactor and simplify controller integration with JSON API and OneService. --- one.cpp | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) (limited to 'one.cpp') diff --git a/one.cpp b/one.cpp index d6da3a26..27cb3ff4 100644 --- a/one.cpp +++ b/one.cpp @@ -72,12 +72,7 @@ #include "service/OneService.hpp" -#ifdef ZT_ENABLE_NETWORK_CONTROLLER -#include "controller/SqliteNetworkController.hpp" -#endif - #define ZT1_PID_PATH "zerotier-one.pid" -#define ZT1_CONTROLLER_DB_PATH "controller.db" using namespace ZeroTier; @@ -1129,19 +1124,6 @@ int main(int argc,char **argv) } #endif // __WINDOWS__ - NetworkController *controller = (NetworkController *)0; -#ifdef ZT_ENABLE_NETWORK_CONTROLLER - try { - controller = new SqliteNetworkController((homeDir + ZT_PATH_SEPARATOR_S + ZT1_CONTROLLER_DB_PATH).c_str()); - } catch (std::exception &exc) { - fprintf(stderr,"%s: failure initializing SqliteNetworkController: %s"ZT_EOL_S,argv[0],exc.what()); - return 1; - } catch ( ... ) { - fprintf(stderr,"%s: failure initializing SqliteNetworkController: unknown exception"ZT_EOL_S,argv[0]); - return 1; - } -#endif // ZT_ENABLE_NETWORK_CONTROLLER - #ifdef __UNIX_LIKE__ std::string pidPath(homeDir + ZT_PATH_SEPARATOR_S + ZT1_PID_PATH); { @@ -1158,7 +1140,7 @@ int main(int argc,char **argv) try { for(;;) { - zt1Service = OneService::newInstance(homeDir.c_str(),port,controller,(overrideRootTopology.length() > 0) ? overrideRootTopology.c_str() : (const char *)0); + zt1Service = OneService::newInstance(homeDir.c_str(),port,(overrideRootTopology.length() > 0) ? overrideRootTopology.c_str() : (const char *)0); switch(zt1Service->run()) { case OneService::ONE_STILL_RUNNING: // shouldn't happen, run() won't return until done case OneService::ONE_NORMAL_TERMINATION: @@ -1191,7 +1173,6 @@ int main(int argc,char **argv) delete zt1Service; zt1Service = (OneService *)0; - delete controller; #ifdef __UNIX_LIKE__ OSUtils::rm(pidPath.c_str()); -- cgit v1.2.3 From c76b9d13403eaa8bae5254d5f5f106dc29aa6e04 Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Sun, 17 May 2015 19:13:22 -0700 Subject: Respect user home directory copies of authtoken.secret or ~/.zeroTierOneAuthToken in CLI like we do in GUI wrappers. --- one.cpp | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'one.cpp') diff --git a/one.cpp b/one.cpp index 27cb3ff4..d174d48f 100644 --- a/one.cpp +++ b/one.cpp @@ -146,7 +146,7 @@ static int cli(int argc,char **argv) json = true; break; - case 'p': // port for HTTP + case 'p': port = Utils::strToUInt(argv[i] + 2); if ((port > 0xffff)||(port == 0)) { cliPrintHelp(argv[0],stdout); @@ -154,7 +154,7 @@ static int cli(int argc,char **argv) } break; - case 'D': // Home path + case 'D': if (argv[i][2]) { homeDir = argv[i] + 2; } else { @@ -163,7 +163,7 @@ static int cli(int argc,char **argv) } break; - case 'H': // HTTP IP + case 'H': if (argv[i][2]) { ip = argv[i] + 2; } else { @@ -172,7 +172,7 @@ static int cli(int argc,char **argv) } break; - case 'T': // Override root topology + case 'T': if (argv[i][2]) { authToken = argv[i] + 2; } else { @@ -181,7 +181,7 @@ static int cli(int argc,char **argv) } break; - case 'v': // Display version + case 'v': if (argv[i][2]) { cliPrintHelp(argv[0],stdout); return 1; @@ -222,6 +222,20 @@ static int cli(int argc,char **argv) if (!authToken.length()) { OSUtils::readFile((homeDir + ZT_PATH_SEPARATOR_S + "authtoken.secret").c_str(),authToken); +#ifdef __UNIX_LIKE__ + if (!authToken.length()) { + const char *hd = getenv("HOME"); + if (hd) { + char p[4096]; +#ifdef __APPLE__ + Utils::snprintf(p,sizeof(p),"%s/Library/Application Support/ZeroTier/One/authtoken.secret",hd); +#else + Utils::snprintf(p,sizeof(p),"%s/.zeroTierOneAuthToken",hd); +#endif + OSUtils::readFile(p,authToken); + } + } +#endif if (!authToken.length()) { fprintf(stderr,"%s: missing authentication token and authtoken.secret not found (or readable) in %s"ZT_EOL_S,argv[0],homeDir.c_str()); return 2; -- cgit v1.2.3 From 9682f50b152ca04543d4b87fb405e50429468eeb Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Tue, 19 May 2015 16:26:41 -0700 Subject: Get rid of old _winPokeAHole() hack in one.cpp and use Advanced Installer to configure firewall rules (because we can now). --- ext/installfiles/windows/ZeroTier One.aip | 43 ++++++++++++++++++++++++------- one.cpp | 6 +++-- 2 files changed, 37 insertions(+), 12 deletions(-) (limited to 'one.cpp') diff --git a/ext/installfiles/windows/ZeroTier One.aip b/ext/installfiles/windows/ZeroTier One.aip index bab72e04..9a3b83a2 100644 --- a/ext/installfiles/windows/ZeroTier One.aip +++ b/ext/installfiles/windows/ZeroTier One.aip @@ -1,7 +1,7 @@ - + @@ -23,7 +23,7 @@ - + @@ -33,12 +33,12 @@ - + - - - + + + @@ -121,6 +121,12 @@ + + + + + + @@ -135,6 +141,11 @@ + + + + + @@ -144,6 +155,7 @@ + @@ -194,9 +206,16 @@ + + + + + + + @@ -243,8 +262,8 @@ - - + + @@ -252,6 +271,10 @@ + + + + @@ -262,8 +285,8 @@ - - + + diff --git a/one.cpp b/one.cpp index d174d48f..4a0a57e8 100644 --- a/one.cpp +++ b/one.cpp @@ -750,6 +750,7 @@ static BOOL WINAPI _winConsoleCtrlHandler(DWORD dwCtrlType) } // Pokes a hole in the Windows firewall (advfirewall) for the running program +/* -- now done by Advanced Installer static void _winPokeAHole() { char myPath[MAX_PATH]; @@ -786,6 +787,7 @@ static void _winPokeAHole() } } } +*/ // Returns true if this is running as the local administrator static BOOL IsCurrentUserLocalAdministrator(void) @@ -1121,13 +1123,13 @@ int main(int argc,char **argv) return 1; } } else { - _winPokeAHole(); + //_winPokeAHole(); } SetConsoleCtrlHandler(&_winConsoleCtrlHandler,TRUE); // continues on to ordinary command line execution code below... } else { // Running from service manager - _winPokeAHole(); + //_winPokeAHole(); ZeroTierOneService zt1Service; if (CServiceBase::Run(zt1Service) == TRUE) { return 0; -- cgit v1.2.3 From b6698d8415728a249426ee784fcbebfdfb8e4632 Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Wed, 20 May 2015 16:35:33 -0700 Subject: Ground work for reincorporating software updater for select platforms. --- ext/installfiles/mac/get-proxy-settings.sh | 6 +++--- make-mac.mk | 20 ++++++++++++-------- one.cpp | 3 +++ service/OneService.cpp | 28 ++++++++++++++++++++++++++++ service/OneService.hpp | 14 ++++++++++++++ 5 files changed, 60 insertions(+), 11 deletions(-) (limited to 'one.cpp') diff --git a/ext/installfiles/mac/get-proxy-settings.sh b/ext/installfiles/mac/get-proxy-settings.sh index 873a8558..16ba0b47 100755 --- a/ext/installfiles/mac/get-proxy-settings.sh +++ b/ext/installfiles/mac/get-proxy-settings.sh @@ -5,9 +5,9 @@ export PATH=/bin:/usr/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/sbin -enabled=`system_profiler SPNetworkDataType|grep "HTTP Proxy Enabled"|awk {'sub(/^.*:[ \t]*/, "", $0); print $0;'}` -port=`system_profiler SPNetworkDataType|grep "HTTP Proxy Port"|awk {'sub(/^.*:[ \t]*/, "", $0); print $0;'}` -serv=`system_profiler SPNetworkDataType|grep "HTTP Proxy Server"|awk {'sub(/^.*:[ \t]*/, "", $0); print $0;'}` +enabled=`system_profiler SPNetworkDataType|grep "HTTP Proxy Enabled"|awk {'sub(/^.*:[ \t]*/, "", $0); print $0;'} 2>/dev/null` +port=`system_profiler SPNetworkDataType|grep "HTTP Proxy Port"|awk {'sub(/^.*:[ \t]*/, "", $0); print $0;'} 2>/dev/null` +serv=`system_profiler SPNetworkDataType|grep "HTTP Proxy Server"|awk {'sub(/^.*:[ \t]*/, "", $0); print $0;'} 2>/dev/null` if [ "$enabled" = "Yes" ]; then if [ "$serv" ]; then diff --git a/make-mac.mk b/make-mac.mk index 717cbccb..4ad4c5ad 100644 --- a/make-mac.mk +++ b/make-mac.mk @@ -13,18 +13,13 @@ OBJS+=osdep/OSXEthernetTap.o CODESIGN=echo CODESIGN_CERT= +# For internal use only -- signs everything with ZeroTier's developer cert ifeq ($(ZT_OFFICIAL_RELEASE),1) - # For use by ZeroTier Networks -- sign with developer cert - ZT_AUTO_UPDATE=1 - DEFS+=-DZT_OFFICIAL_RELEASE + DEFS+=-DZT_OFFICIAL_RELEASE -DZT_AUTO_UPDATE CODESIGN=codesign CODESIGN_CERT="Developer ID Application: ZeroTier Networks LLC (8ZD9JUCZ4V)" endif -ifeq ($(ZT_AUTO_UPDATE),1) - DEFS+=-DZT_AUTO_UPDATE -endif - # Build with ZT_ENABLE_NETWORK_CONTROLLER=1 to build with the Sqlite network controller ifeq ($(ZT_ENABLE_NETWORK_CONTROLLER),1) DEFS+=-DZT_ENABLE_NETWORK_CONTROLLER @@ -35,6 +30,7 @@ endif # Enable SSE-optimized Salsa20 -- all Intel macs support SSE2 DEFS+=-DZT_SALSA20_SSE +# Debug mode -- dump trace output, build binary with -g ifeq ($(ZT_DEBUG),1) DEFS+=-DZT_TRACE CFLAGS=-Wall -g -pthread $(INCLUDES) $(DEFS) @@ -63,10 +59,18 @@ selftest: $(OBJS) selftest.o $(CXX) $(CXXFLAGS) -o zerotier-selftest selftest.o $(OBJS) $(LIBS) $(STRIP) zerotier-selftest -sign-pkg: FORCE +# Requires Packages: http://s.sudre.free.fr/Software/Packages/about.html +mac-dist-pkg: FORCE + cd ext/installfiles/mac ; packagesbuild "ZeroTier One.pkgproj" $(CODESIGN) -f -s $(CODESIGN_CERT) "ZeroTier One.pkg" $(CODESIGN) -vvv "ZeroTier One.pkg" +# For internal use only +official: FORCE + make clean + make -j 4 ZT_OFFICIAL_RELEASE=1 + make ZT_OFFICIAL_RELEASE=1 mac-dist-pkg + clean: rm -rf *.dSYM build-* *.pkg *.dmg *.o node/*.o controller/*.o service/*.o osdep/*.o ext/http-parser/*.o ext/lz4/*.o ext/json-parser/*.o zerotier-one zerotier-idtool zerotier-selftest zerotier-cli ZeroTierOneInstaller-* diff --git a/one.cpp b/one.cpp index 4a0a57e8..f2d7970b 100644 --- a/one.cpp +++ b/one.cpp @@ -888,6 +888,9 @@ static void printHelp(const char *cn,FILE *out) { fprintf(out,"ZeroTier One version %d.%d.%d"ZT_EOL_S"(c)2011-2015 ZeroTier, Inc."ZT_EOL_S,ZEROTIER_ONE_VERSION_MAJOR,ZEROTIER_ONE_VERSION_MINOR,ZEROTIER_ONE_VERSION_REVISION); fprintf(out,"Licensed under the GNU General Public License v3"ZT_EOL_S""ZT_EOL_S); + std::string updateUrl(OneService::autoUpdateUrl()); + if (updateUrl.length()) + fprintf(out,"Automatic update enabled:"ZT_EOL_S" %s"ZT_EOL_S""ZT_EOL_S,updateUrl.c_str()); fprintf(out,"Usage: %s [-switches] [home directory]"ZT_EOL_S""ZT_EOL_S,cn); fprintf(out,"Available switches:"ZT_EOL_S); fprintf(out," -h - Display this help"ZT_EOL_S); diff --git a/service/OneService.cpp b/service/OneService.cpp index a566449f..c2ea034b 100644 --- a/service/OneService.cpp +++ b/service/OneService.cpp @@ -96,6 +96,8 @@ namespace ZeroTier { typedef BSDEthernetTap EthernetTap; } namespace ZeroTier { +namespace { + class OneServiceImpl; static int SnodeVirtualNetworkConfigFunction(ZT1_Node *node,void *uptr,uint64_t nwid,enum ZT1_VirtualNetworkConfigOperation op,const ZT1_VirtualNetworkConfig *nwconf); @@ -903,6 +905,8 @@ static int ShttpOnMessageComplete(http_parser *parser) return 0; } +} // anonymous namespace + std::string OneService::platformDefaultHomePath() { #ifdef __UNIX_LIKE__ @@ -939,6 +943,30 @@ std::string OneService::platformDefaultHomePath() #endif // __UNIX_LIKE__ or not... } +std::string OneService::autoUpdateUrl() +{ +#ifdef ZT_AUTO_UPDATE + +/* +#if defined(__LINUX__) && ( defined(__i386__) || defined(__x86_64) || defined(__x86_64__) || defined(__amd64) || defined(__i386) ) + if (sizeof(void *) == 8) + return "http://download.zerotier.com/ZeroTierOneInstaller-linux-x64-LATEST.nfo"; + else return "http://download.zerotier.com/ZeroTierOneInstaller-linux-x86-LATEST.nfo"; +#endif +*/ + +#if defined(__APPLE__) && ( defined(__i386__) || defined(__x86_64) || defined(__x86_64__) || defined(__amd64) || defined(__i386) ) + return "http://download.zerotier.com/update/mac_intel/LATEST.nfo"; +#endif + +#ifdef __WINDOWS__ + return "http://download.zerotier.com/update/win_intel/LATEST.nfo"; +#endif + +#endif // ZT_AUTO_UPDATE + return std::string(); +} + OneService *OneService::newInstance(const char *hp,unsigned int port,const char *overrideRootTopology) { return new OneServiceImpl(hp,port,overrideRootTopology); } OneService::~OneService() {} diff --git a/service/OneService.hpp b/service/OneService.hpp index 33c40547..aea314f5 100644 --- a/service/OneService.hpp +++ b/service/OneService.hpp @@ -34,6 +34,15 @@ namespace ZeroTier { /** * Local service for ZeroTier One as system VPN/NFV provider + * + * If built with ZT_ENABLE_NETWORK_CONTROLLER defined, this includes and + * runs controller/SqliteNetworkController with a database called + * controller.db in the specified home directory. + * + * If built with ZT_AUTO_UPDATE, an official ZeroTier update URL is + * periodically checked and updates are automatically downloaded, verified + * against a built-in list of update signing keys, and installed. This is + * only supported for certain platforms. */ class OneService { @@ -69,6 +78,11 @@ public: */ static std::string platformDefaultHomePath(); + /** + * @return Auto-update URL or empty string if auto-updates unsupported or not enabled + */ + static std::string autoUpdateUrl(); + /** * Create a new instance of the service * -- cgit v1.2.3