#!/usr/bin/perl my $ThisScript = $0; $ThisScript =~ s/.*[\/\\](.*)/$1/; my $VNCHost; my $VNCPort; my $VNCPass; my $VNCPassFile; my $Workspace; my $PassWD = "/tmp/vncpass"; my $Encoding = "tight hextile copyrect zlib corre rre raw"; my $NoFS = 0; my $CompressLevel = 9; my $Quality = 5; my $VNCOps = ""; my $Version = "0.9.0"; my $ExitCode = 0; my $TimeOut = 10; my $AppName = 'TightVNC'; my $AppCount; my $NewAppCount; my $Command; my $RowIn; my $RowOut; my $Options; my $ListRaw; my $ThisWin; my $WinName; my @List; my @SpiltVal; my $c; my $PrintUsage = 0; if(@ARGV > 0) { for($c=0;$c<@ARGV;$c++) { #print "ARGV[$c]: '" . $ARGV[$c] . "'\n"; if(($ARGV[$c] =~ m/^-h$/) || ($ARGV[$c] =~ m/^--host$/)) { $c++; if($c < @ARGV) { $VNCHost = $ARGV[$c]; } else { print STDERR "Error: " . $ARGV[$c - 1] . ": Argument Expected.\n"; $PrintUsage = 1; $ExitCode = 1; } } elsif(($ARGV[$c] =~ m/^-p$/) || ($ARGV[$c] =~ m/^--port$/)) { $c++; if($c < @ARGV) { $VNCPort = $ARGV[$c]; } else { print STDERR "Error: " . $ARGV[$c - 1] . ": Argument Expected.\n"; $PrintUsage = 1; $ExitCode = 1; } } elsif(($ARGV[$c] =~ m/^-P$/) || ($ARGV[$c] =~ m/^--pass$/)) { $c++; if($c < @ARGV) { $VNCPass = $ARGV[$c]; } else { print STDERR "Error: " . $ARGV[$c - 1] . ": Argument Expected.\n"; $PrintUsage = 1; $ExitCode = 1; } } elsif(($ARGV[$c] =~ m/^-PF$/) || ($ARGV[$c] =~ m/^--passfile$/)) { $c++; if($c < @ARGV) { $VNCPassFile = $ARGV[$c]; } else { print STDERR "Error: " . $ARGV[$c - 1] . ": Argument Expected.\n"; $PrintUsage = 1; $ExitCode = 1; } } elsif(($ARGV[$c] =~ m/^-w$/) || ($ARGV[$c] =~ m/^--workspace$/)) { $c++; if($c < @ARGV) { $Workspace = $ARGV[$c]; } else { print STDERR "Error: " . $ARGV[$c - 1] . ": Argument Expected.\n"; $PrintUsage = 1; $ExitCode = 1; } } elsif(($ARGV[$c] =~ m/^-e$/) || ($ARGV[$c] =~ m/^--encoding$/)) { $c++; if($c < @ARGV) { $Encoding = $ARGV[$c]; } else { print STDERR "Error: " . $ARGV[$c - 1] . ": Argument Expected.\n"; $PrintUsage = 1; $ExitCode = 1; } } elsif(($ARGV[$c] =~ m/^-c$/) || ($ARGV[$c] =~ m/^--compresslevel$/)) { $c++; if($c < @ARGV) { $CompressLevel = $ARGV[$c]; } else { print STDERR "Error: " . $ARGV[$c - 1] . ": Argument Expected.\n"; $PrintUsage = 1; $ExitCode = 1; } } elsif(($ARGV[$c] =~ m/^-q$/) || ($ARGV[$c] =~ m/^--quality$/)) { $c++; if($c < @ARGV) { $Quality = $ARGV[$c]; } else { print STDERR "Error: " . $ARGV[$c - 1] . ": Argument Expected.\n"; $PrintUsage = 1; $ExitCode = 1; } } elsif(($ARGV[$c] =~ m/^-o$/) || ($ARGV[$c] =~ m/^--vncops$/)) { $c++; if($c < @ARGV) { $VNCOps = $ARGV[$c]; } else { print STDERR "Error: " . $ARGV[$c - 1] . ": Argument Expected.\n"; $PrintUsage = 1; $ExitCode = 1; } } elsif(($ARGV[$c] =~ m/^-n/) || ($ARGV[$c] =~ m/^--nofs$/)) { $NoFS = 1; } elsif(($ARGV[$c] =~ m/^-?$/) || ($ARGV[$c] =~ m/^--help$/)) { $PrintUsage = 1; } else { print STDERR "Error: " . $ARGV[$c] . ": Unknown option.\n"; $PrintUsage = 1; $ExitCode = 1; } } } if($PrintUsage) { $NumWorkSpace = `wmctrl -d | awk '{print $1}' | sort -n | tail -n 1`; chomp($NumWorkSpace); $NumWorkSpace += 1; print qq~$ThisScript $Version Usage: $ThisScript [OPTION]... Actions: -?, --help Usage info (your looking at it) -h , --host Set host value for VNC to connect to -p , --port Set the port you expect VNC to be running on. -P , --Pass Plain text password to be used to log into VNC Server. -PF , --passfile Direct VNC to use a vncpasswd. -w , --workspace The workspace number to move your VNC session too. Range from 1 to $NumWorkSpace. -e --encoding Encoding order of preference. See "man xtightvncviewer" for better details. -c , --compresslevel (0 to 9) See "man xtightvncviewer" for better details. -q , --quality (0 to 9) See "man xtightvncviewer" for better details. -o '', --vncops '' Any tightvncviewer options you want to be run with tight VNC that aren't covered in the other options above. See "man xtightvncviewer" for better details. Remeber to put the quotes around the options you want added. -n, --nofs No Fullscreen mode. Leave windowed. ~; exit($ExitCode); } if(!$VNCHost) { $Command = qq|zenity --title="Host Name" --entry --text="Host Name"|; $VNCHost = `$Command`; if($? != 0) {exit(1);} chomp($VNCHost); } print "VNCHost: $VNCHost\n"; if(!$VNCPort) { $Command = qq|zenity --title="Port Number" --entry --entry-text="5900" --text="Port Number"|; $VNCPort = `$Command`; if($? != 0) {exit(1);} chomp($VNCPort); } print "VNCPort: $VNCPort\n"; if((!$VNCPass) && (!$VNCPassFile)) { $Command = qq|zenity --title="Password" --entry --text="Password" --hide-text|; $VNCPass = `$Command`; if($? != 0) {exit(1);} chomp($VNCPass); } if(!$VNCPassFile) { #print "VNCPass: $VNCPass\n"; print "VNCPass: ********\n"; $Command = qq~touch $PassWD~; `$Command`; $Command = qq~chmod 600 $PassWD~; `$Command`; $Command = qq~echo $VNCPass | /usr/bin/xtightvncpasswd -f > $PassWD~; `$Command`; $VNCPass = ""; } else { $PassWD = $VNCPassFile; } if(!$Workspace) { $Options = ""; $ListRaw = `wmctrl -d`; @List = split("\n", $ListRaw); for($c=0;$c<@List;$c++) { $RowIn = $List[$c]; ($Workspace, $ThisWin, @SplitVal) = split(" ", $RowIn); $WinName = $SplitVal[7]; for($c2=8;$c2<@SplitVal;$c2++) {$WinName .= " " . $SplitVal[$c2];} if($ThisWin ne "*") {$RowOut = "FALSE";} else {$RowOut = "TRUE";} $RowOut .= " " . ($Workspace + 1) . " '$WinName'"; $Options .= " $RowOut"; } $Command = qq|zenity --width=200 --height=300 --title="Workspace" --text="Select Workspace" --list --radiolist --column "" --column "\#" --column "Title" $Options|; #print "$Command\n"; $Workspace = `$Command`; if($? != 0) {exit(1);} chomp($Workspace); } print "Workspace: $Workspace\n"; $Workspace -= 1; $Command = qq~wmctrl -l | grep "$AppName" | wc -l~; $AppCount = `$Command`; chomp($AppCount); $| = 1; my $Pid = fork(); if(!$Pid) { $Command = qq|/usr/bin/xtightvncviewer -passwd '$PassWD' -encoding '$Encoding' -compresslevel '$CompressLevel' -quality '$Quality' $VNCOps $VNCHost| . qq|::$VNCPort|; print "$Command\n"; `$Command`; exit(0); } $c = 0; $NewAppCount = 0; $Command = qq~wmctrl -l | grep "$AppName" | wc -l~; $NewAppCount = `$Command`; chomp($NewAppCount); while( ($NewAppCount <= $AppCount) && ($c < $TimeOut)) { sleep(1); $NewAppCount = `$Command`; chomp($NewAppCount); $c++; } $Command = qq|rm /tmp/vncpass|; print "$Command\n"; `$Command`; if($c >= $TimeOut) { print "More then $TimeOut seconds\n"; exit(1); } $AppID = `wmctrl -l | grep "$AppName" | tail -n 1 | awk '{print \$1}'`; chomp($AppID); print "AppID: $AppID\n"; if($AppID) { $Command = qq|wmctrl -iR $AppID -t $Workspace|; print "$Command\n"; `$Command`; if(!$NoFS) {$Command = qq|wmctrl -iR $AppID -b toggle,fullscreen|; print "$Command\n"; `$Command`;} } else { print "No AppID???\n"; }