summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@zerotier.com>2015-05-20 20:17:56 -0700
committerAdam Ierymenko <adam.ierymenko@zerotier.com>2015-05-20 20:17:56 -0700
commit905d2e91e598945d4ba3a42430cd288f0a1d0839 (patch)
tree5eb308052b4a861a2802cc03544ad07600163101
parent12130739166895db88dca0c230f3972bd3ac3d6a (diff)
downloadinfinitytier-905d2e91e598945d4ba3a42430cd288f0a1d0839.tar.gz
infinitytier-905d2e91e598945d4ba3a42430cd288f0a1d0839.zip
Windows auto-update integration into OneService.
-rw-r--r--ext/installfiles/windows/ZeroTier One.aip7
-rw-r--r--service/OneService.cpp49
2 files changed, 47 insertions, 9 deletions
diff --git a/ext/installfiles/windows/ZeroTier One.aip b/ext/installfiles/windows/ZeroTier One.aip
index 69c2c0b7..234873f8 100644
--- a/ext/installfiles/windows/ZeroTier One.aip
+++ b/ext/installfiles/windows/ZeroTier One.aip
@@ -23,7 +23,7 @@
<ROW Property="CTRLS" Value="2"/>
<ROW Property="MSIFASTINSTALL" MultiBuildValue="DefaultBuild:2"/>
<ROW Property="Manufacturer" Value="ZeroTier, Inc."/>
- <ROW Property="ProductCode" Value="1033:{F4513A63-407E-447E-A840-FAE83DF26A78} " Type="16"/>
+ <ROW Property="ProductCode" Value="1033:{D0B06684-2CB3-4EA8-BC7F-FC24F2C6DA40} " Type="16"/>
<ROW Property="ProductLanguage" Value="1033"/>
<ROW Property="ProductName" Value="ZeroTier One"/>
<ROW Property="ProductVersion" Value="1.0.3" Type="32"/>
@@ -52,7 +52,6 @@
<ROW Directory="regid.201001.com.zerotier_Dir" Directory_Parent="CommonAppDataFolder" DefaultDir="REGID2~1.ZER|regid.2010-01.com.zerotier"/>
<ROW Directory="tapwindows_Dir" Directory_Parent="One_Dir" DefaultDir="TAP-WI~1|tap-windows"/>
<ROW Directory="ui_Dir" Directory_Parent="One_Dir" DefaultDir="ui"/>
- <ROW Directory="updates.d_Dir" Directory_Parent="One_Dir" DefaultDir="updates.d"/>
<ROW Directory="x64_Dir" Directory_Parent="tapwindows_Dir" DefaultDir="x64"/>
<ROW Directory="x86_Dir" Directory_Parent="tapwindows_Dir" DefaultDir="x86"/>
</COMPONENT>
@@ -68,14 +67,13 @@
<ROW Component="index.html" ComponentId="{24AB46DC-56EA-4F3C-A8B7-95957509CDD1}" Directory_="ui_Dir" Attributes="0" KeyPath="index.html" Type="0"/>
<ROW Component="networks.d" ComponentId="{EF54D0DF-889F-41DC-AF5C-4E7F96AB1C8B}" Directory_="networks.d_Dir" Attributes="0"/>
<ROW Component="regid.201001.com.zerotier" ComponentId="{A39C80FC-6A8F-454F-9052-10DAC3C3B139}" Directory_="regid.201001.com.zerotier_Dir" Attributes="0"/>
- <ROW Component="updates.d" ComponentId="{E07A5480-3942-4529-A976-E7764542274C}" Directory_="updates.d_Dir" Attributes="0"/>
<ROW Component="zerotierone_x64.exe" ComponentId="{DFCFB72D-B055-4E60-B6D8-81FF585C2183}" Directory_="One_Dir" Attributes="256" Condition="VersionNT64" KeyPath="zerotierone_x64.exe"/>
<ROW Component="zerotierone_x86.exe" ComponentId="{5D2F3366-4FE1-40A4-A81A-66C49FA11F1C}" Directory_="One_Dir" Attributes="0" Condition="NOT VersionNT64" KeyPath="zerotierone_x86.exe"/>
<ROW Component="zttap300.cat" ComponentId="{123CD683-FD99-4F0F-8F9B-0222DF409B09}" Directory_="x64_Dir" Attributes="256" Condition="VersionNT64" KeyPath="zttap300.cat_2" Type="0"/>
<ROW Component="zttap300.cat_1" ComponentId="{9F913E48-095B-4EA3-98DA-EDAB1593F3E3}" Directory_="x86_Dir" Attributes="0" Condition="NOT VersionNT64" KeyPath="zttap300.cat_3" Type="0"/>
</COMPONENT>
<COMPONENT cid="caphyon.advinst.msicomp.MsiFeatsComponent">
- <ROW Feature="ZeroTierOne" Title="MainFeature" Description="ZeroTier One" Display="1" Level="1" Directory_="APPDIR" Attributes="0" Components="AI_CustomARPName AI_DisableModify ProductInformation WdfCoinstaller01011.dll WdfCoinstaller01011.dll_1 ZeroTierOne.exe devcon_x64.exe devcon_x86.exe index.html networks.d regid.201001.com.zerotier updates.d zerotierone_x64.exe zerotierone_x86.exe zttap300.cat zttap300.cat_1"/>
+ <ROW Feature="ZeroTierOne" Title="MainFeature" Description="ZeroTier One" Display="1" Level="1" Directory_="APPDIR" Attributes="0" Components="AI_CustomARPName AI_DisableModify ProductInformation WdfCoinstaller01011.dll WdfCoinstaller01011.dll_1 ZeroTierOne.exe devcon_x64.exe devcon_x86.exe index.html networks.d regid.201001.com.zerotier zerotierone_x64.exe zerotierone_x86.exe zttap300.cat zttap300.cat_1"/>
<ATTRIBUTE name="CurrentFeature" value="ZeroTierOne"/>
</COMPONENT>
<COMPONENT cid="caphyon.advinst.msicomp.MsiFilesComponent">
@@ -196,7 +194,6 @@
</COMPONENT>
<COMPONENT cid="caphyon.advinst.msicomp.MsiCreateFolderComponent">
<ROW Directory_="networks.d_Dir" Component_="networks.d" ManualDelete="false"/>
- <ROW Directory_="updates.d_Dir" Component_="updates.d" ManualDelete="false"/>
<ROW Directory_="regid.201001.com.zerotier_Dir" Component_="regid.201001.com.zerotier" ManualDelete="false"/>
</COMPONENT>
<COMPONENT cid="caphyon.advinst.msicomp.MsiCustActComponent">
diff --git a/service/OneService.cpp b/service/OneService.cpp
index b8a66f6f..790f691b 100644
--- a/service/OneService.cpp
+++ b/service/OneService.cpp
@@ -108,6 +108,7 @@ namespace {
#ifdef ZT_AUTO_UPDATE
#define ZT_AUTO_UPDATE_MAX_HTTP_RESPONSE_SIZE (1024 * 1024 * 64)
+#define ZT_AUTO_UPDATE_CHECK_PERIOD 21600000
class BackgroundSoftwareUpdateChecker
{
public:
@@ -247,6 +248,40 @@ public:
/* Windows version comes in the form of .MSI package that
* takes care of everything. */
{
+ char tempp[512],batp[512],msip[512],cmdline[512];
+ if (GetTempPathA(sizeof(tempp),tempp) <= 0)
+ return;
+ CreateDirectoryA(tempp,(LPSECURITY_ATTRIBUTES)0);
+ Utils::snprintf(batp,sizeof(batp),"%s\\ZeroTierOne-update-%u.%u.%u.bat",tempp,vMajor,vMinor,vRevision);
+ Utils::snprintf(msip,sizeof(msip),"%s\\ZeroTierOne-update-%u.%u.%u.msi",tempp,vMajor,vMinor,vRevision);
+ FILE *msi = fopen(msip,"wb");
+ if ((!msi)||(fwrite(fileData.data(),(size_t)fileData.length(),1,msi) != 1)) {
+ fclose(msi);
+ return;
+ }
+ fclose(msi);
+ FILE *bat = fopen(batp,"wb");
+ if (!bat)
+ return;
+ fprintf(bat,
+ "TIMEOUT.EXE /T 1 /NOBREAK\r\n"
+ "NET.EXE STOP \"ZeroTierOneService\"\r\n"
+ "TIMEOUT.EXE /T 1 /NOBREAK\r\n"
+ "MSIEXEC.EXE /i \"%s\" /qn\r\n"
+ "TIMEOUT.EXE /T 1 /NOBREAK\r\n"
+ "NET.EXE START \"ZeroTierOneService\"\r\n"
+ "DEL \"%s\"\r\n"
+ "DEL \"%s\"\r\n",
+ msip,
+ msip,
+ batp);
+ fclose(bat);
+ STARTUPINFOA si;
+ PROCESS_INFORMATION pi;
+ memset(&si,0,sizeof(si));
+ memset(&pi,0,sizeof(pi));
+ Utils::snprintf(cmdline,sizeof(cmdline),"CMD.EXE /c \"%s\"",batp);
+ CreateProcessA(NULL,cmdline,NULL,NULL,FALSE,CREATE_NO_WINDOW|CREATE_NEW_PROCESS_GROUP,NULL,NULL,&si,&pi);
}
#endif // __WINDOWS__
@@ -367,10 +402,6 @@ public:
char portstr[64];
Utils::snprintf(portstr,sizeof(portstr),"%u",port);
OSUtils::writeFile((_homePath + ZT_PATH_SEPARATOR_S + "zerotier-one.port").c_str(),std::string(portstr));
-
-#ifdef ZT_AUTO_UPDATE
- Thread::start(&backgroundSoftwareUpdateChecker);
-#endif
}
virtual ~OneServiceImpl()
@@ -436,6 +467,9 @@ public:
_nextBackgroundTaskDeadline = 0;
uint64_t lastTapMulticastGroupCheck = 0;
+#ifdef ZT_AUTO_UPDATE
+ uint64_t lastSoftwareUpdateCheck = 0;
+#endif // ZT_AUTO_UPDATE
for(;;) {
_run_m.lock();
if (!_run) {
@@ -453,6 +487,13 @@ public:
dl = _nextBackgroundTaskDeadline;
}
+#ifdef ZT_AUTO_UPDATE
+ if ((now - lastSoftwareUpdateCheck) >= ZT_AUTO_UPDATE_CHECK_PERIOD) {
+ lastSoftwareUpdateCheck = OSUtils::now();
+ Thread::start(&backgroundSoftwareUpdateChecker);
+ }
+#endif // ZT_AUTO_UPDATE
+
if ((now - lastTapMulticastGroupCheck) >= ZT_TAP_CHECK_MULTICAST_INTERVAL) {
lastTapMulticastGroupCheck = now;
Mutex::Lock _l(_taps_m);