Skip to content

Commit 06343f7

Browse files
Add (untested) support for Windows
1 parent 720e35f commit 06343f7

File tree

4 files changed

+181
-15
lines changed

4 files changed

+181
-15
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ dist/
9797

9898
# external resources
9999
vnc-software/tigervnc-linux-x86_64
100+
vnc-software/uvnc-windows
100101

101102
# trashcan
102103
trash/

src/main.js

Lines changed: 58 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
// - do some kind of "pkill vnc-software/tigervnc-linux-x86_64/usr/bin/x0vncserver -rfbport=55900" to ensure none other is still running
77
// - do some kind of "pkill vnc-software/tigervnc-linux-x86_64/usr/bin/vncviewer SecurityTypes=None 127.0.0.1::45900" to ensure none other is still running
88
// - before starting a new client or server process, check if serverChild or clientChild are initialized and if yes, stop them
9+
// - support (a list of) multiple running clientChilds instead of just one
910

1011
const { app, BrowserWindow, ipcMain, shell } = require('electron');
12+
const nodePath = require('node:path');
1113
import { existsSync } from 'node:fs';
1214

1315
let serverChild;
@@ -101,14 +103,17 @@ function stopChild(child) {
101103
// Search order:
102104
// - vnc-software/ (when launching in development)
103105
// - /tmp/.mount_peervizdlxvC/resources/vnc-software/ (launched from appimage or .deb package installation)
106+
// - on windows: check console.log to know what __dirname and process.cwd() are
104107
function findResourceFile(filename) {
108+
console.log("findResourceFile __dirname = ");
105109
console.log(__dirname)
110+
console.log("findResourceFile process.cwd = ");
106111
console.log(process.cwd())
107-
const magicName = "vnc-software/";
108-
const parts = __dirname.split('/');
109-
let appImageMount = parts.slice(0, -3).join('/'); // /tmp/.mount_peervizdlxvC/resources/app.asar/.webpack/main becomes /tmp/.mount_peervizdlxvC/resources
112+
const magicName = "vnc-software" + nodePath.sep;
113+
const parts = __dirname.split(nodePath.sep);
114+
let appImageMount = parts.slice(0, -3).join(nodePath.sep); // /tmp/.mount_peervizdlxvC/resources/app.asar/.webpack/main becomes /tmp/.mount_peervizdlxvC/resources
110115
// placesToCheck are directories that should end with a slash
111-
let placesToCheck = [magicName, appImageMount + "/" + magicName, "/"];
116+
let placesToCheck = [magicName, appImageMount + nodePath.sep + magicName, nodePath.sep];
112117
for (const str of placesToCheck) {
113118
let fullName = str + filename;
114119
console.log("checking exists: " + str);
@@ -122,6 +127,13 @@ function findResourceFile(filename) {
122127
}
123128

124129
ipcMain.on('run-server', (event) => {
130+
// Make sure this OS is supported
131+
if (process.platform !== 'linux' && process.platform !== 'win32') {
132+
let error = 'Unsupported platform ' + process.platform + '. Only linux and win32 are supported, darwin (MacOS) not yet. Please reach out!';
133+
console.log(error);
134+
event.reply(error);
135+
return -1;
136+
}
125137
if (!serverChild) { // Only run the server if not started already. It keeps running the whole time.
126138
event.reply('run-server-log', "Initializing network layer...");
127139
publicKeyServer = startHyperTeleServer();
@@ -130,14 +142,36 @@ ipcMain.on('run-server', (event) => {
130142
event.reply('run-server-log', "Network layer initialized.");
131143

132144
event.reply('run-server-log', "Preparing for incoming connections...");
133-
// default debian package has x0tigervncserver instead
134-
serverChild = runProcess('tigervnc-linux-x86_64/usr/bin/x0vncserver', ['SecurityTypes=None','-localhost=1','-interface=127.0.0.1','-rfbport=55900']);
145+
if (process.platform === 'linux') {
146+
let binaryName = 'tigervnc-linux-x86_64/usr/bin/x0vncserver';
147+
let foundBinary = findResourceFile(binaryName);
148+
if (!foundBinary) {
149+
console.log("Binary " + binaryName + " not found.");
150+
return -2;
151+
}
152+
let dirname = nodePath.dirname(foundBinary);
153+
serverChild = runProcess(foundBinary, ['SecurityTypes=VncAuth','localhost=1','interface=127.0.0.1','rfbport=55900','PasswordFile='+dirname+nodePath.sep+'plain.bin']);
154+
} else if (process.platform === 'win32') {
155+
serverChild = findAndRunProcess('vnc-software\\uvnc-windows\\x64\\winvnc.exe'); // uses the config file next to the binary
156+
}
157+
if (!serverChild) {
158+
event.reply('run-server-log', "ERROR: Listening for connections using VNC server failed.");
159+
return;
160+
}
135161
}
136162
event.reply('run-server-pubkey', publicKeyServer);
137163
event.reply('run-server-log', "Ready for incoming connections.");
138164
});
139165

140166
ipcMain.on('run-client', (event, data) => {
167+
// Make sure this OS is supported
168+
if (process.platform !== 'linux' && process.platform !== 'win32') {
169+
let error = 'Unsupported platform ' + process.platform + '. Only linux and win32 are supported, darwin (MacOS) not yet. Please reach out!';
170+
console.log(error);
171+
event.reply(error);
172+
return -1;
173+
}
174+
141175
event.reply('run-client-log', "Initializing network layer...");
142176
console.log("running client with connectto data: " + data);
143177
let hyperTeleProxy = startHyperTeleClient(data);
@@ -148,10 +182,21 @@ ipcMain.on('run-client', (event, data) => {
148182
event.reply('run-client-log', "Network layer initialized.");
149183

150184
event.reply('run-client-log', "Establishing outgoing connection...");
151-
// default debian package has xtigervncviewer instead
152-
let clientChild = runProcess('tigervnc-linux-x86_64/usr/bin/vncviewer', ['SecurityTypes=None','127.0.0.1::45900']);
185+
if (process.platform === 'linux') {
186+
let binaryName = 'tigervnc-linux-x86_64/usr/bin/vncviewer';
187+
let foundBinary = findResourceFile(binaryName);
188+
if (!foundBinary) {
189+
console.log("Binary " + binaryName + " not found.");
190+
return -2;
191+
}
192+
// PasswordFile of TigerVNC viewer cannot be passed on commandline, so use the file next to the binary.
193+
let dirname = nodePath.dirname(foundBinary);
194+
clientChild = runProcess(foundBinary, ['SecurityTypes=VncAuth','PasswordFile='+dirname+nodePath.sep+'plain.bin','127.0.0.1::45900']);
195+
} else if (process.platform === 'win32') {
196+
clientChild = findAndrunProcess('vnc-software\\uvnc-windows\\x64\\vncviewer.exe', ['/password nopassword','localhost:45900']);
197+
}
153198
if (!clientChild) {
154-
event.reply('run-client-log', "Outgoing connection using vncviewer failed.");
199+
event.reply('run-client-log', "ERROR: Outgoing connection using vncviewer failed.");
155200
return;
156201
}
157202
// Stop the hyperTeleProxy from listening when the client is closed, because the next run might use a different client
@@ -164,18 +209,16 @@ ipcMain.on('run-client', (event, data) => {
164209
event.reply('run-client-log', "Outgoing connection established.");
165210
});
166211

167-
function runProcess(binaryName, args) {
168-
if (process.platform !== 'linux') { // win32/darwin not supported
169-
console.log('Unsupported platform ' + process.platform + '. Only linux is supported, win32/darwin not yet. Please reach out!');
170-
return -1;
171-
}
172-
212+
function findAndRunProcess(binaryName, args) {
173213
let foundBinary = findResourceFile(binaryName);
174214
if (!foundBinary) {
175215
console.log("Binary " + binaryName + " not found.");
176216
return -2;
177217
}
218+
return runProcess(foundBinary);
219+
}
178220

221+
function runProcess(foundBinary, args) {
179222
const { spawn } = require('child_process');
180223
const child = spawn(foundBinary, args);
181224
return child;

vnc-software/download_tigervnc.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,9 @@ rm -rf tigervnc-linux-x86_64 && \
1414
mv tigervnc-1.13.1.x86_64 tigervnc-linux-x86_64 && \
1515
rm "$outfile"
1616

17+
# Password generated with: echo -n "nopassword" | ./vnc-software/tigervnc-linux-x86_64/usr/bin/vncpasswd -f | hexdump -C # 00000000 33 11 7e 54 aa 0d 4d 3b |3.~T..M;|
18+
# Use /bin/echo and not /bin/sh's built-in echo because it doesn't support -e
19+
/bin/echo -ne "\x33\x11\x7e\x54\xaa\x0d\x4d\x3b" > tigervnc-linux-x86_64/usr/bin/plain.bin
20+
1721
# Go back to original directory
1822
cd -

vnc-software/download_uvnc.sh

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
#!/bin/sh
2+
# This script needs: readlink, dirname, wget, sha256sum, unzip
3+
4+
# Execute with containing directory as current working directory
5+
mydir=$(readlink -f "$0")
6+
mydir=$(dirname "$mydir")
7+
cd "$mydir"
8+
9+
# Download link obtained from https://uvnc.com/component/jdownloads/summary/470-ultravnc-1-4-6-zip.html
10+
outfile=uvnc-windows.zip
11+
outdir=uvnc-windows
12+
downloadlink="https://uvnc.com/component/jdownloads/send/0-/470-ultravnc-1-4-6-zip.html"
13+
sha256sum=3afe90cf4f287ff066649225223d9950221ddfd273e5f4805c2f6fde39a5df83
14+
15+
wget "$downloadlink" -O "$outfile"
16+
result=$?
17+
18+
if [ $result -eq 0 ]; then
19+
echo "Download successful, checking checksum and extracting..."
20+
rm -rf "$outdir"
21+
22+
echo "$sha256sum $outfile" | sha256sum -c - && \
23+
unzip -d "$outdir" "$outfile" && \
24+
rm "$outfile"
25+
26+
else
27+
echo "ERROR: download of $downloadlink returned exit code: $result"
28+
cd - # Go back to original directory
29+
exit 1
30+
fi
31+
32+
echo "[Permissions]
33+
[admin]
34+
FileTransferEnabled=1
35+
FTUserImpersonation=1
36+
BlankMonitorEnabled=1
37+
BlankInputsOnly=0
38+
DefaultScale=1
39+
UseDSMPlugin=0
40+
DSMPlugin=
41+
primary=1
42+
secondary=0
43+
SocketConnect=1
44+
HTTPConnect=0
45+
AutoPortSelect=0
46+
PortNumber=55900
47+
HTTPPortNumber=5800
48+
InputsEnabled=1
49+
LocalInputsDisabled=0
50+
IdleTimeout=0
51+
EnableJapInput=0
52+
EnableUnicodeInput=0
53+
EnableWin8Helper=0
54+
QuerySetting=2
55+
QueryTimeout=10
56+
QueryDisableTime=0
57+
QueryAccept=0
58+
MaxViewerSetting=0
59+
MaxViewers=128
60+
Collabo=0
61+
Frame=0
62+
Notification=0
63+
OSD=0
64+
NotificationSelection=1
65+
LockSetting=0
66+
RemoveWallpaper=0
67+
RemoveEffects=0
68+
RemoveFontSmoothing=0
69+
DebugMode=0
70+
Avilog=0
71+
path=
72+
DebugLevel=0
73+
AllowLoopback=1
74+
LoopbackOnly=1
75+
AllowShutdown=1
76+
AllowProperties=1
77+
AllowInjection=0
78+
AllowEditClients=1
79+
FileTransferTimeout=30
80+
KeepAliveInterval=5
81+
IdleInputTimeout=0
82+
DisableTrayIcon=0
83+
rdpmode=0
84+
noscreensaver=0
85+
Secure=0
86+
MSLogonRequired=0
87+
NewMSLogon=0
88+
ReverseAuthRequired=1
89+
ConnectPriority=0
90+
service_commandline=
91+
accept_reject_mesg=
92+
cloudServer=
93+
cloudEnabled=0
94+
[UltraVNC]
95+
passwd=33117E54AA0D4D3B55
96+
passwd2=33117E54AA0D4D3B55
97+
[poll]
98+
TurboMode=1
99+
PollUnderCursor=0
100+
PollForeground=0
101+
PollFullScreen=1
102+
OnlyPollConsole=0
103+
OnlyPollOnEvent=0
104+
MaxCpu2=100
105+
MaxFPS=25
106+
EnableDriver=1
107+
EnableHook=1
108+
EnableVirtual=0
109+
autocapt=1
110+
[admin_auth]
111+
group1=VNCACCESS
112+
group2=Administrators
113+
group3=VNCVIEWONLY
114+
locdom1=0
115+
locdom2=0
116+
locdom3=0" | sed -e 's/\r*$/\r/' > uvnc-windows/x64/UltraVNC.ini
117+
118+
cd - # Go back to original directory

0 commit comments

Comments
 (0)