2 vncserver scripts compare [Merge by MS Word]

xiaoxiao2021-03-06  40

#! / usr / bin / perl ## Copyright (c) 2002 Realvnc Ltd. # Copyright (C) 1999 AT & T Laboratories

Cambridge

. All Rights Reserved ## This is free software;. You can redistribute it and / or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # ( . at your option) any later version ## This software is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY;. without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the # GNU General Public . License for more details ## You should have received a copy of the GNU General Public License # along with this software; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 -1307, #

USA

. ### # s. ### first makess (); ## Global variables. You may want to configure some of these for Your Site. # $ geometry = "800x600"; 1024x768 "; $ depth = 8; 16; # $ desktopname =" x "; $ deptopname =" ah_vnc_desktop "; $ vncclasses =" / home / mohnennrc (((- D "/ USR / Share / VNC / Classes ";") && "/ usr / share / vnc / classes") || ((-D "/ usr / local / vnc / classes") && "/ usr / local / vnc / classes ")); $ VNCUSERDIR =" $ env {home} /. vnc "; $ XAUTHORITYFILE =" $ env {xauthority} "||" $ env {home} /. xauthority "; $ defaultxstartup = (" #! / bin / SH / N / N "." # set x resource stuff / n "." "" [-r / @Home/.xResources] && xrdb / @Home/.xResources/N "." xsell -solid Grey / N / n "." IF Test -x / USR / DT / BIN / XSESSION; THEN / N "." # start cde / n "." / usr / dt / bin / xsession / n "." ELSE / N "." # Start TWM / N "." XTERM -GEOMETRY 80x24 10 10 -ls -title / "/ $ VNCDESKTOP Desktop /" & / N "." / usr / OpenWin / Bin / TWM / N "." Fi / N / N "." # by the vnc session / n "." CD / Home / MohnenRC / VNC / N "." ./vncserver -Kill / $ Display & / N "); CHOP ($ host =` uname -n); # Check Command Line Options & ParseOptions ("- Geometry", 1, "- DEPTH", 1, "- Pixelformat", 1, "-Name", 1, "- kill", "-help", 0, "- h", 0, "- help", 0); &

USAGE () IF ($ OPT {'- Help' || $ OPT {'- h'} || $ OPT {'- Help'}); & Kill () IF ($ OPT {'- kill'}) ; # Uncomment this line if you want default geometry, depth and pixelformat # to match the current X display: # & GetXDisplayDefaults (); if ($ opt { '- geometry'}) {$ geometry = $ opt { '- geometry'} } IF ($ OPT {'- depth') {$ Depth = $ OPT {'- DEPTH'}; $ Pixelformat = "";} f ($ OPT {'- pixelformat'}) {$ Pixelformat = $ OPT {'-pixelformat'};} & checkgeeometryandDepth (); if ($ OPT {'- name'}) {$ desktopname = $ OPT {'- name'};} # create the user's vnc directory if Necessary.if (! -E $ vncuserdir)) {if (! MKDIR ($ VNCUSERDIR, 0755) {DIE "$ pROG: COULD NOT CREATE $ VNCUSERDIR. / N";}} # make Sure The user has a password. ($ z, $ Z, $ mode) = stat ("$ vncuserdir / passwd"); if (! (- e "$ vncuserdir / passwd") || ($ Mode & 077)) {warn "/ NYOU WILL Require a password to access you Desktops./n/N "; System (" VNCPasswd $ VNCUSERDIR / Passwd "); if ($? >> 8)! = 0) {EXIT 1;}} # Find Display Number.if ((@argv> 0 && ($ Argv [0 ] = ~ / ^: (/ d ) $ /)) {$ DisplayNumber = $ 1; Shift (@argv); if (! & checkdisplaynumber ($ displayNumber)) {Die "a VNC Server IS Already Running AS: $ DisplayNumber / N "}} Elsif ((@argv> 0) && ($ argv [0]! ~ / ^ - /)) {& usage ();} else {$ displayNumber = & getDisplayNumber ();} $ vncport = 5900 $ displayNumber $ Desktoplog = "$ VNCUSERDIR / $ Host: $ DisplayNumber.log"; unlink ($ desktoplog);

# Make an X server cookie -. Use as the seed the sum of the current time, our # PID and part of the encrypted form of the password Ideally we'd use # / dev / urandom, but that's only available on Linux.srand (Time $$ Unpack ("L", `Cat $ VNCUSERDIR / Passwd`); ​​$ cookie =" "; for (1..16) {$ cookie. = Sprintf ("% 02x ", int (Rand) 256)))));} System ("xauth -f $ xauthorityfile add $ host: $ displayNumber. $ Cookie"); System ("xauth -f $ xauthorityFile Add $ Host / UNIX: $ DISPLAYNUMBER. $ COOKIE" ); # Now Start The x VNC Server $ cmd = "xvnc: $ displayNumber"; $ cmd. = "-Desktop". "Edstring ($ desktopname); $ cmd. =" -Httpd $ vncclasses ";" if ($ "$ cmd. =" -auth $ xauthorityfile "; $ cmd. =" -Geometry $ geometry "if ($ geometry); $ cmd. =" -depth $ depth "if ($ depth); $ cmd. = "-pixelformat $ PIXELFORMAT" if ($ Pixelformat); $ cmd. = "-rfbwait 120000"; $ cmd. = "-rfbauth $ vncuserdir / passwd"; $ cmd. = "-rfbport $ vncport"; $ cmd. = "-nolisten localpn"; # add font path and color database stuff here, eg: ## $ cmd. = "-fp / USR / LIB / X11 / FONTS / MISC /, / USR / LIB / X11 / FONTS / 75DPI / "; # $ cmd. =" -co / usr / lib / x11 / rgb "; # foreach $ arg (@argv {$ Cmd. = "" "Edstring ($ arg);} $ cmd. =" >> "" Edstring ($ desktoplog). "2> & 1"; # run $ cmd and record the process ID. $ Pidfile = "$ vncuserdir / $ host: $ displayNumber.pid"; System ("$ cmd & echo / $!> $ pidfile"); # Give XVNC a chance to start upsleep (3); warn "/ nnew '$ desktopname '

desktop is $ host: $ displayNumber / n / n "; # Create the user's xstartup script if necessary.if (! (- e" $ vncUserDir / xstartup ")) {warn" Creating default startup script $ vncUserDir / xstartup / n " ; open (xSTARTUP, "> $ vncUserDir / xstartup"); print xSTARTUP $ defaultXStartup; close (xSTARTUP); chmod 0755, "$ vncUserDir / xstartup";} # Run the X startup script.warn "Starting applications specified in $ vncUserDir / xstartup / n "; WARN" log file is $ desktoplog / n / n "; # ired the unix domain socket exisss the use there # TCP (Display = Host: N) IF (-e "/TMP/.x11-unix/x (" | || -e "/ usr / spool / sockets / x11 / $ displaynumber") {$ env {display} = ": $ displayNumber";} else { $ Env {Display} = "$ HOST: $ DISPLAYNUMBER";} $ 11 {vncdesktop} = $ desktopname; System ("$ vncuserdir / xstartup >>". "2> & 1 &"); EXIT; ########################################################################## ######################### CheckgeometryandDepth Simply Makes Sure That The Geometry and Depth Values ​​# a Re Sensible. # Sub CheckGeometryandDepth {IF ($ Geometry = ~ / ^ (/ d ) x (/ d ) $ /) {$ width = $ 1; $ height = $ 2; if ($ width <1) || ($ Height <1)) {DIE "$ PROG: Geometry $ Geometry is invalid / n";} while ($ width% 4)! = 0) {$ width = $ width 1;} while (($ heiGH% 2 )! = 0) {$ Height = $ hHT 1;} $ geometry = "$ {width} x $ heiGHT";} else {die "$ pROG: Geometry $ geometry is invalid / n";} = Depth <8) || ($ depth>

32) {DIE "Depth Must Be Between 8 and 32 / N";}} ## getDisplayNumber Gets The Lowest Available Display Number. A Display Number # N Is Taken if Something IS Listening on The VNC Server Port (5900 N) Or the # x server port (6000 n). # Sub getDisplayNumber {for (& checkdisplaynumber ($ n)) {return $ n 0; # Bruce Mah's Workaround for bug in Perl 5.005 _02}} die. ". $ prog: no free display number on $ host / n";} ## CheckDisplayNumber checks if the given display number is available A # display number n is taken if something is listening on the VNC server port # ( 5900 n) or the x server port (6000 n). # Sub checkdisplayNumber {local ($ n) = @_; socket (s, $ AF_INET, $ SOCK_STREAM, 0) || DIE "$ PROG: SOCKET FAILED: $! / n "; Eval 'setsockopt (s, & sol_socket, & so_reuseaddr, pack (" l ", 1))'; if (! bind (s, pack ('s n x12', $ AF_INET, 6000 $ N) )) {Close (s); return 0;} close (s); Socket (S, $ AF_INET, $ SOCK_STREAM, 0) || DIE "$ PROG: SOCKET FAILED: $! / N "; Eval 'Setsockopt (S, & SOL_Socket, & So_reuseAddr, Pack (" L ", 1))'; if (! Bind (S, Pack ('s N x12', $ AF_INET, 5900 $ N))) {Close (s); return 0;} close (s); if (-e "/tmp/.x - n) {warn" / nwarning: $ Host: $ n IS Taken Because Of /TMP/.x-lock/N "; WARN" Remove this file if there is no x server $ host: $ n / n "; return 0;}} (-e" /tmp/.x11 -unix / x $ n ") {warn" / nwarning: $ Host: $ n is taken because of /tmp/.x11-unix/x * / @n "; warn"

Remove this file if there is no x server $ host: $ n / n "; return 0;} IF (-e" / usr / spool / sockets / x11 / $ n ") {warn (" / nwarning: $ host: $ N is Taken Because of "/ usr / spool / sockets / x11 / $ n / n"); WARN "Remove this file if there is no x server $ host: $ n / n"; return 0;} return 1;.} ## GetXDisplayDefaults uses xdpyinfo to find out the geometry, depth and pixel # format of the current X display being used If successful, it sets the # options as appropriate so that the X VNC server will use the same settings # ( minus an allowance for window manager decorations on the geometry). Using # the same depth and pixel format means that the VNC server will not have to # translate pixels when the desktop is being viewed on this X display (for # TrueColor displays anyway) . # sub GetXDisplayDefaults {local (@lines, @matchlines, $ width, $ height, $ defaultVisualId, $ i, $ red, $ green, $ blue); $ wmDecorationWidth = 4; # a guess at typical size for window manager $ WM DecorationHeight = 24; # decoration size return if (! Defined ($ env {display}); @lines = `xdpyinfo 2> / dev / null`; return if ($?! = 0); @matchlines = grep (/ Dimensions /, @Lines); if (@matchlines) {($ Width, $ HEIGHT) = ($ Matchlines [0] = ~ / (/ d ) x (/ d ) pixels /); $ width - = $ wmdecorationWidth; $ Height - = $ WMDecorationHeight; $ geometry = "$ {width} = greight";} @matchlines = grep (/ default visual id /, @lines); if (@matchlines) {($ DefaultvisualID) = ($ matchlines [0] = ~ / ID: / s (/ s ) /); for ($ I = 0; $ i <@lines; $ i

) {IF ($ LINES [$ I] = ~ / ^ / S * Visual ID: / S $ DefaultvisualId $ /) {IF ($ LINES [$ I 1]! ~ / Truecolor /) || ($ LINES) [$ I 2]! ~ / depth /) || ($ LINES [$ I 4]! ~ / Red, Green, Blue Masks /)) {Return;} Last;}} Return IF ($ I> = @Lines); ($ depth) = ($ LINES [$ I 2] = ~ / Depth: / s (/ d ) /); ($ Red, $ Green, $ Blue) = ($ LINES [$ I 4] = ~ / masks: / s 0x ([0-9A-F] ), 0X ([0-9A-F] ), 0X ([0-9A-F] ) /); $ red = HEX ($ red); $ Green = HEX ($ Green); $ blue = hex ($ blue); if ($ red> $ blue) {$ red = int (log ($ red) / log (2)) - Int ($ Green) / log (2)); $ Green = Int (log ($ green) / log (2)) - int (log ($ blue) / log (2)); $ blue = int (log ($ blue) / log (2)) 1; $ Pixelformat = "RGB $ Red $ Green $ Blue";} else {$ blue = int (log ($ blue) / log (2)) - INT LOG ($ Green) / log (2)); $ Green = Int (log ($ GREEN) / L OG (2)) - INT (log ($ red) / log (2)); $ red = int (log ($ red) / log (2)) 1; $ Pixelformat = "BGR $ blue $ Green $ Red "}}} ## quotedstring returns a string which yields the Original string when pased # by a shell. # Sub quotedstring {local ($ in) = @_; $ = ~ s // '//' /" / '/ "/' / g; return" '$ in' ";} ## removeslashes Turns Slashes INTO underscores for use as a file name. # SUB Removeslashes {local ($ in) = @_; $ = ~ s | / | _ | g; return "$ in";} ## usage # subs usage {die ("/ Nusage: $ prog [:] [-name

] [-Depth] / n ".

"

[-geometry

x

] / n ".

"

[-pixelformat rgbnnn | bgrnnn] / n ".

"

... / n / n ".

"

$ PROG -KILL

/ N / N ");

}

#

# Kill

#

Sub kill

{

$ OPT {'- kill'} = ~ s / (: / d ) /./ D $ / $ 1 /; # E.g. Turn: 1.0 INTO: 1

IF ($ OPT {'- kill'} = ~ / ^: / d ) {

$ PIDFILE = "$ VNCUSERDIR / $ HOST $ OPT {'- Kill'}. PID";

} else {

IF ($ OPT {'- kill'}! ~ / ^ $ host: /) {

Die "/ ncan't tell if $ opt {'- kill'} is on $ host / n".

"Use -kill:

INSTEAD / N / N ";

}

$ PIDFILE = "$ VNCUSERDIR / $ OPT {'- kill'}. PID";

}

IF (! -r $ pidfile) {

DIE "/ ncan't find file $ pidfile / n".

"You'll Have to Kill The xVnc Process Manually / N / N";

}

$ Sig {'hup'} = 'ignore';

Chop ($ PID = `Cat $ PIDFILE`);

WARN "Killing XVNC Process ID $ PID / N";

System ("Kill $ PID");

Unlink $ PIDFILE;

EXIT;

}

#

# PARSEOPTIONS TAKES A List of Possible Options and a Boolean Indicating

# WHETHER THE OPTION HAS a Value Following, and Sets Up An Associative ARRAY

#% opt of the values ​​of the options Given on The Command Line. IT Removes All

# @argv and returns the from @argv and returns.

#

Sub Parseoptions

{

Local (@optval) = @_;

Local ($ OPT, @opts,% VALFOLLOWS, @newargs);

While (@optval) {

$ OPT = Shift (@optval);

Push (@ OPTS, $ OPT);

$ VALFOLLOWS {$ OPT} = Shift (@optval);

}

@optargs = ();

% OPT = ();

Arg: While ($ arg = shift (@argv))) {

Foreach $ OPT (@opts) {

IF ($ Arg EQ $ OPT) {

Push (@optargs, $ arg);

IF ($ VALFOLLOWS {$ OPT}) {

IF (@argv == 0) {

& Usage ();

}

$ OPT {$ OPT} = Shift (@argv); Push (@optargs, $ opt {$ OPT});

} else {

$ OPT {$ OPT} = 1;

}

NEXT ARG;

}

}

Push (@nargs, $ arg);

}

@Argv = @newargs;

}

#

# Routine to make Sure We're Operating in a Sane Environment.

#

Sub SanityCheck

{

Local ($ cmd);

#

# Get the program name

#

($ PROG) = ($ 0 = ~ m | ([^ /] ) $ |);

#

# Check we have all the commists we'll ued on the path.

#

CMD:

Foreach $ cmd ("uname", "xauth", "xvnc", "vncpasswd") {

For (split (/: /, $ env {path}) {

IF (-x "$ _ / $ cmd") {

NEXT CMD;

}

}

Die "$ PROG: COULDN '' '' $ cmd /" on your path./n ";

}

#

# Check The Home Environment Variable IS Set

#

IF (! Defined ($ env {home}) {

Die "$ PROG: The Home Environment Variable is not set./n";

}

#

# Find socket constants 'Use socket' is a perl5-ISM, SO We Wrap it in an

# Eval, and if it fails we try 'require "sys / socket.ph"'.

IF this fails,

# we just guess at the value.

IF you find perl moaning here, Just

# Hard-code the value of a AF_INET and SOCK_STREAM.

You can Find these Out

# for your platform by looking in /usr/include/sys/socket.h and related

# files.

#

Chop ($ OS = `UNAME);

Chop ($ OSREV = `uname -r);

Eval 'Use socket';

IF ($ @) {

Eval 'Require "Sys / Socket.ph"';

IF ($ @) {

IF (($ OS EQ "SunOS") && ($ OSREV! ~ / ^ 4 /)) {

$ AF_INET = 2;

$ SOCK_STREAM = 2;

} else {

$ AF_INET = 2;

$ SOCK_STREAM = 1;

}

} else {

$ AF_INET = & AF_INET;

$ SOCK_STREAM = & SOCK_STREAM;

}

} else {

$ AF_INET = & AF_INET;

$ SOCK_STREAM = & SOCK_STREAM;

}

}

转载请注明原文地址:https://www.9cbs.com/read-70981.html

New Post(0)