23
24
# vncserver - wrapper script to start an X VNC server.
27
# This file was heavily edited by Ola Lundqvist <opal@debian.org> using
28
# options from vnc package.
29
# Most modifications are written by Marcus.Brinkmann@ruhr-uni-bochum.de and
30
# now incorporated by Ola.
32
# Please report all errors to Debian and not to ORL.
27
35
# First make sure we're operating in a sane environment.
36
44
$geometry = "1024x768";
38
$vncJavaFiles = (((-d "/usr/share/vnc/classes") && "/usr/share/vnc/classes") ||
46
$vncJavaFiles = (((-d "/usr/share/vnc-java") && "/usr/share/vnc-java") ||
47
((-d "/usr/share/vnc/classes") && "/usr/share/vnc/classes") ||
39
48
((-d "/usr/local/vnc/classes") && "/usr/local/vnc/classes"));
40
50
$vncUserDir = "$ENV{HOME}/.vnc";
41
51
$xauthorityFile = "$ENV{XAUTHORITY}" || "$ENV{HOME}/.Xauthority";
49
59
"[ -r \$HOME/.Xresources ] && xrdb \$HOME/.Xresources\n".
50
60
"xsetroot -solid grey\n".
51
61
"vncconfig -iconic &\n".
52
"xterm -geometry 80x24+10+10 -ls -title \"\$VNCDESKTOP Desktop\" &\n".
62
"x-terminal-emulator -geometry 80x24+10+10 -ls -title \"\$VNCDESKTOP Desktop\" &\n".
63
"x-window-manager &\n");
65
######## Adding configuration possibility ################
66
$Config_file = "/etc/vnc.conf";
68
$Config_file = "$ENV{HOME}/.vncrc";
72
foreach ("/etc/X11/xorg.conf", "/etc/X11/XF86Config-4", "/etc/X11/XF86Config" ){
74
last if ( -e $XFConfigPath );
81
$fontPath = "/usr/X11R6/lib/X11/fonts/Type1/,".
82
"/usr/X11R6/lib/X11/fonts/Speedo/,".
83
"/usr/X11R6/lib/X11/fonts/misc/,".
84
"/usr/X11R6/lib/X11/fonts/75dpi/,".
85
"/usr/X11R6/lib/X11/fonts/100dpi/,".
86
"/usr/share/fonts/X11/misc/,".
87
"/usr/share/fonts/X11/Type1/,".
88
"/usr/share/fonts/X11/75dpi/,".
89
"/usr/share/fonts/X11/100dpi/"
95
foreach ("/etc/X11/rgb", "/usr/share/X11/rgb", "/usr/X11R6/lib/X11/rgb"){
97
last if ( -e "${colorPath}.txt" );
101
##########################################################
103
$vncUserDirUnderTmp = ($vncUserDir =~ m|^/tmp/.+|) ? 1 : 0;
104
$xstartup = ($vncUserDirUnderTmp) ?
105
"$ENV{HOME}/.vncstartup" : "$vncUserDir/xstartup";
106
$xstartup = $vncStartup if ($vncStartup);
108
unless ($xauthorityFile) {
109
if ($vncUserDirUnderTmp) {
110
$xauthorityFile = "$vncUserDir/.Xauthority";
112
$xauthorityFile = "$ENV{HOME}/.Xauthority";
55
116
chop($host = `uname -n`);
58
119
# Check command line options
60
121
&ParseOptions("-geometry",1,"-depth",1,"-pixelformat",1,"-name",1,"-kill",1,
62
"-help",0,"-h",0,"--help",0);
122
"-help",0,"-h",0,"--help",0,
124
"-alwaysshared",0, "-nevershared",0,
125
"-httpport",1,"-basehttpport",1);
64
127
&Usage() if ($opt{'-help'} || $opt{'-h'} || $opt{'--help'});
66
129
&Kill() if ($opt{'-kill'});
132
if (defined $vncJavaFiles) {
133
if(-d $vncJavaFiles) {
68
138
# Uncomment this line if you want default geometry, depth and pixelformat
69
139
# to match the current X display:
70
140
# &GetXDisplayDefaults();
79
149
if ($opt{'-pixelformat'}) {
80
150
$pixelformat = $opt{'-pixelformat'};
82
if ($opt{'-nohttpd'}) {
154
@fontPathElements = split(/\s*,\s*/, "$opt{'-fp'}");
158
foreach $i (0.."$#fontPathElements") {
159
$tempFontPath = $fontPathElements[$i];
160
if ($tempFontPath !~ m!^[^/]*/[^/]*:\d+$!) {
161
$tempFontPath =~ s/:unscaled$//;
162
if (-r "$tempFontPath/fonts.dir") {
163
$fontPath .= "$fontPathElements[$i],";
166
$fontPath .= "$fontPathElements[$i],";
89
172
&CheckGeometryAndDepth();
92
174
# Create the user's vnc directory if necessary.
94
176
if (!(-e $vncUserDir)) {
96
178
die "$prog: Could not create $vncUserDir.\n";
182
($z,$z,$mode) = lstat("$vncUserDir");
183
if (!-d _ || !-o _ || ($vncUserDirUnderTmp && ($mode & 0777) != 0700)) {
184
die "$prog: Wrong type or access mode of $vncUserDir.\n";
100
187
# Make sure the user has a password.
102
189
($z,$z,$mode) = stat("$vncUserDir/passwd");
103
190
if (!(-e "$vncUserDir/passwd") || ($mode & 077)) {
104
191
warn "\nYou will require a password to access your desktops.\n\n";
105
system("vncpasswd -q $vncUserDir/passwd");
192
system("vncpasswd $vncUserDir/passwd");
106
193
if (($? >> 8) != 0) {
143
230
# Now start the X VNC Server
145
$cmd = "Xvnc :$displayNumber";
232
$cmd = "Xvnc4 :$displayNumber";
146
233
$cmd .= " -desktop " . "edString($desktopName);
147
$cmd .= " -httpd $vncJavaFiles" if ($vncJavaFiles && ! $nohttpd);
235
$cmd .= " -httpd $vncJavaFiles";
236
print ("Found $vncJavaFiles for http connections.\n");
237
if ($opt{'-httpport'}) {
238
$cmd .= " -httpport $opt{'-httpport'}";
239
print ("Listening to $opt{'-httpport'} for http connections.\n");
241
elsif ($opt{'-basehttpport'}) {
242
my $v = $opt{'-basehttpport'} + $displayNumber;
243
print ("Listening to $v for http connections.\n");
244
$cmd .= " -httpport $v";
148
247
$cmd .= " -auth $xauthorityFile";
149
248
$cmd .= " -geometry $geometry" if ($geometry);
150
249
$cmd .= " -depth $depth" if ($depth);
159
258
# $cmd .= " -fp /usr/lib/X11/fonts/misc/,/usr/lib/X11/fonts/75dpi/";
160
259
# $cmd .= " -co /usr/lib/X11/rgb";
261
$cmd .= " -fp $fontPath" if ($fontPath);
262
$cmd .= " -co $colorPath" if ($colorPath);
263
$cmd .= " -alwaysshared" if ($opt{'-alwaysshared'});
264
$cmd .= " -nevershared" if ($opt{'-nevershared'});
163
266
foreach $arg (@ARGV) {
164
267
$cmd .= " " . "edString($arg);
179
282
# Create the user's xstartup script if necessary.
181
if (!(-e "$vncUserDir/xstartup")) {
182
warn "Creating default startup script $vncUserDir/xstartup\n";
183
open(XSTARTUP, ">$vncUserDir/xstartup");
284
if (!(-e "$xstartup")) {
285
warn "Creating default startup script $xstartup\n";
286
open(XSTARTUP, ">$xstartup");
184
287
print XSTARTUP $defaultXStartup;
186
chmod 0755, "$vncUserDir/xstartup";
289
chmod 0755, "$xstartup";
189
292
# Run the X startup script.
191
warn "Starting applications specified in $vncUserDir/xstartup\n";
294
warn "Starting applications specified in $xstartup\n";
192
295
warn "Log file is $desktopLog\n\n";
194
297
# If the unix domain socket exists then use that (DISPLAY=:n) otherwise use
204
307
$ENV{VNCDESKTOP}= $desktopName;
206
system("$vncUserDir/xstartup >> " . "edString($desktopLog) . " 2>&1 &");
309
system("$xstartup >> " . "edString($desktopLog) . " 2>&1 &");
313
############################ Debian functions #################################
314
# I thank Manoj for the code below.
316
# ReadConfigFile reads in a config file and sets variables according to it.
321
open(CONFIG, "$Config_file") || return;
328
$_ .= ";" unless /;\s*$/;
329
if (/^\s*([^=]+)\s*=\s*(\S.*)$/o) {
330
my $ret = eval "$1=$2";
332
print STDERR "Error parsing config file $Config_file!\n";
333
print STDERR "$lineno:$_\n";
341
open(CONFIG, "$XFConfigPath") || return;
348
if (/^\s*FontPath\s*"(\S.*)"\s*$/o) {
349
$fontPath .= "," if $fontPath;
355
sub ReadXFConfigColor
357
open(CONFIG, "$XFConfigPath") || return;
359
while (<CONFIG> && !$colorPath) {
364
if (/^\s*RgbPath\s*"(\S.*)"\s*$/o) {
371
########## End of debian functions ###########
211
374
###############################################################################
423
die("\nusage: $prog [:<number>] [-nohttpd] [-name <desktop-name>] [-depth <depth>]\n".
424
" [-geometry <width>x<height>]\n".
425
" [-pixelformat rgbNNN|bgrNNN]\n".
426
" <Xvnc-options>...\n\n".
427
" $prog -kill <X-display>\n\n");
588
"Usage: $prog [<OPTIONS>] [:<DISPLAY#>]\n".
589
" $prog -kill :<DISPLAY#>\n".
591
"<OPTIONS> are Xvnc4 options, or:\n".
593
" -name <DESKTOP-NAME>\n".
595
" -geometry <WIDTH>x<HEIGHT>\n".
596
" -httpport number\n".
597
" -basehttpport number\n".
600
" -pixelformat rgb<NNN>\n".
601
" -pixelformat bgr<NNN>\n".
602
" <Xvnc4-options>...\n".
604
"See vnc4server and Xvnc4 manual pages for more information.\n");
449
626
if (! -r $pidFile) {
450
627
die "\nCan't find file $pidFile\n".
451
"You'll have to kill the Xvnc process manually\n\n";
628
"You'll have to kill the Xvnc4 process manually\n\n";
454
631
$SIG{'HUP'} = 'IGNORE';
455
632
chop($pid = `cat $pidFile`);
456
warn "Killing Xvnc process ID $pid\n";
633
warn "Killing Xvnc4 process ID $pid\n";
457
634
system("kill $pid");
526
foreach $cmd ("uname","xauth","Xvnc","vncpasswd") {
703
foreach $cmd ("uname","xauth","Xvnc4","vncpasswd") {
527
704
for (split(/:/,$ENV{PATH})) {
528
705
if (-x "$_/$cmd") {