#!/usr/bin/perl -I. use strict; use Pos::Webtop::Web::ContentModule; use Pos::Webtop::OcxLauncher; use URI::Escape; package Pos::Webtop::Web::ContentModule::RemoteDesktop; our $timeoutMinutes = 10; our @ISA = qw( Pos::Webtop::Web::ContentModule ); sub new { my $this = shift; my $class = ref($this) || $this; my ($self) = @{{@_}}{qw/self/}; if ( not defined $self ) { $self = {}; bless($self,$class); } # setup base class my %args = @_; $args{'self'} = $self; Pos::Webtop::Web::ContentModule->new( %args ); return $self; } sub canManuallyConnectRemoteDesktop { my $self = shift; my $tb = $self->getToolBox(); my $client = $tb->getClient(); if ( not defined( $self->{'canManuallyConnectRemoteDesktop'} ) ) { my $moduleAccess = $client->getAllowedContentModules(); $self->{'canManuallyConnectRemoteDesktop'} = $moduleAccess->{'RemoteDesktop'}->{'sm_manuallyConnect'}; } return $self->{'canManuallyConnectRemoteDesktop'}; } sub canInstallRemoteDesktop { my $self = shift; my $tb = $self->getToolBox(); my $client = $tb->getClient(); if ( not defined( $self->{'canInstallRemoteDesktop'} ) ) { my $moduleAccess = $client->getAllowedContentModules(); $self->{'canInstallRemoteDesktop'} = $moduleAccess->{'RemoteDesktop'}->{'sm_installAgent'}; } return $self->{'canInstallRemoteDesktop'}; } # (pure virtual defined in Pos::Webtop::Web::ContentModule) sub main { my $self = shift; my $toolBox = $self->getToolBox(); my $client = $toolBox->getClient(); my $cgi = $toolBox->getCgi(); my $db = $toolBox->getWebtopDbReader(); my $ret = undef; my $action = $cgi->param('action'); $client->checkSession(); # if the user was clicked sign off while they were at the Remote Desktop page # this makes sure that if they are not using the activex that they get returned # to the download page instead of the main remote desktop page and stuff (!$client->isWebtopVpnConnectionEstablished(tb=>$toolBox, db=>$db) && !defined($action)) and $action = "newDesktop"; my ($rdaAllowed) = $db->query( sql => " SELECT can_use_rda FROM user_abilities WHERE user_id = '" . $client->getUserId() . "' "); (!$client->isWebtopVpnConnectionEstablished(tb=>$toolBox, db=>$db) && !$self->canInstallRemoteDesktop()) and $rdaAllowed = 0; $rdaAllowed = 1 unless defined $rdaAllowed; if ( ! $rdaAllowed ) { my $p = $toolBox->getPage(); print $p->getHeaderHtml(title => "Webtop: Remote Desktop: Disabled"); print Pos::Webtop::OcxLauncher::getLauncherHtml(tb => $toolBox); print "
Remote Desktop is currently disabled
\n"; print $p->getFooterHtml(); return; } if (defined($action)) { if ($action eq 'newDesktop') { my $installNow = $cgi->param('installNow'); my $currVersion = $cgi->param('currVersion'); $self->newDesktop( installNow => $installNow, currVersion => $currVersion); } elsif ($action eq 'removeComputer') { my $okay = $cgi->param('okay'); my $computerName = $cgi->param('computerName'); my $computerId = $cgi->param('computerId'); $self->removeComputer( computerName => $computerName, computerId => $computerId, okay => $okay); } elsif ($action eq 'renameComputer') { my $okay = $cgi->param('okay'); my $computerName = $cgi->param('computerName'); my $computerId = $cgi->param('computerId'); my $wantCancel = $cgi->param('Cancel'); $self->renameComputer( computerName => $computerName, computerId => $computerId, okay => $okay, wantCancel => $wantCancel); } elsif ($action eq 'trouble') { $self->showTroubleHelp(); } else { $self->printMainPage(); } } else { $self->printMainPage(); } return 1; } # (pure virtual defined in Pos::Webtop::Web::ContentModule) sub getPreviewHtml { my $self = shift; my $tb = $self->getToolBox(); my $db = $tb->getWebtopDbReader(); my $client = $tb->getClient(); my $activeXConnected = $client->isWebtopVpnConnectionEstablished(db=> $db) && !$client->isMacWebtop(); my $ret = undef; # TODO: the dates here should probably be timestamp with timezone my @computersOnline = $db->query(sql => " select w_user_computer_id, computer_name, RAWIP32_TO_DOTTED_QUAD(computer_ip), rda_software_id from w_user_computers where last_update > " . $db->getCurrentTimeStampString() . ( (Pos::defaults::isPostgresDb()) ? "- interval '$timeoutMinutes Minutes'" : "- $timeoutMinutes/(24 * 60)" ) . " AND user_id = '" . $client->getUserId . "' order by computer_name asc"); my @computersOffline = $db->query(sql => " select computer_name, RAWIP32_TO_DOTTED_QUAD(computer_ip), rda_software_id from w_user_computers where last_update <= " . $db->getCurrentTimeStampString() . ( (Pos::defaults::isPostgresDb()) ? " - interval '$timeoutMinutes Minutes'" : " - $timeoutMinutes/(24 * 60)" ) . " AND user_id = '" . $client->getUserId . "' order by computer_name asc"); my @computersShared = $db->query(sql => " select agent_name, agent_ip, rda_software_id, agent_port from w_user_shared_rda where user_id = '" . $client->getUserId . "' and agent_ip is not null order by agent_name asc "); my ($rdaAllowed) = $db->query( sql => " SELECT can_use_rda FROM user_abilities WHERE user_id = '" . $client->getUserId() . "' "); if(!defined $rdaAllowed) { $rdaAllowed = 1; } $ret = $self->getPreviewHeader(); $ret .= "
"; if ($rdaAllowed == 0) { $ret .= "REMOTE DESKTOP IS CURRENTLY DISABLED.
"; } elsif ((scalar(@computersOnline) == 0 && scalar(@computersOffline) == 0 && scalar(@computersShared) == 0) || !$activeXConnected) { } else { $ret .= "Click on a computer to connect to a remote desktop:

"; foreach my $computer (@computersOnline) { my ($computerId, $computerName, $computerIp, $rdaSoftwareId) = @{ $computer }; my $cleanName = $computerName; $cleanName =~ s/\\/\\\\/g; $cleanName =~ s/\'/\\\'/g; if ($rdaSoftwareId == 1) { $ret .= " "; } elsif ($rdaSoftwareId == 2) { $ret .= " "; } else { $ret .= " "; } } $ret .= "
     " . HTML::Entities::encode($computerName) . "
     " . HTML::Entities::encode($computerName) . "
     " . HTML::Entities::encode($computerName) . "
"; foreach my $computer (@computersShared) { my ($computerName, $computerIp, $rdaSoftwareId, $port) = @{ $computer }; my $cleanName = $computerName; $cleanName =~ s/\\/\\\\/g; $cleanName =~ s/\'/\\\'/g; if ($rdaSoftwareId == 1) { (!defined($port) || !length($port)) and $port = "5900"; $ret .= " "; } elsif ($rdaSoftwareId == 2) { (!defined($port) || !length($port)) and $port = "3389"; $ret .= " "; } else { $ret .= " "; } } $ret .= "
     " . HTML::Entities::encode($computerName) . " (shared)
     " . HTML::Entities::encode($computerName) . " (shared)
     " . HTML::Entities::encode($computerName) . " (shared)
"; foreach my $computer (@computersOffline) { my ($computerName, $computerIp, $rdaSoftwareId) = @{ $computer }; if( $rdaSoftwareId == 1) { $ret .= " "; } elsif ($rdaSoftwareId == 2) { $ret .= " "; } else { $ret .= " "; } } $ret .= "
     " . HTML::Entities::encode($computerName) . " (offline)
     " . HTML::Entities::encode($computerName) . " (offline)
     " . HTML::Entities::encode($computerName) . " (offline)
"; } $ret .= "
"; if($rdaAllowed == 1) { $ret .= "
"; if ($self->canInstallRemoteDesktop()) { $ret .=" "; } $ret .="
" . $client->getFormGetCode( text => 'Install a Remote Desktop Agent', values => [ { name => 'module', value => 'RemoteDesktop' }, { name => 'action', value => 'newDesktop' } ]) . " " . $client->getFormGetCode( text => 'More...', values => [ { name => 'module', value => 'RemoteDesktop' } ]) . "
"; } $ret .= $self->getPreviewFooter(); return $ret; } sub printMainPage { my $self = shift; my $tb = $self->getToolBox(); my $db = $tb->getWebtopDbReader(); my $client = $tb->getClient(); my ($topText) = @{{@_}}{qw/topText/}; my $ret; my $p; my $box; my $currTd = 'BOXTD1'; my @computersOnline = $db->query(sql => " select w_user_computer_id, computer_name as NAME, to_char(last_access, 'MM/DD/YYYY HH24:MI AM'), RAWIP32_TO_DOTTED_QUAD(computer_ip), 'ONLINE' as TYPE, rda_software_id, NULL from w_user_computers where last_update > " . $db->getCurrentTimeStampString() . ( (Pos::defaults::isPostgresDb()) ? " - interval '$timeoutMinutes Minutes'" : " - $timeoutMinutes/(24 * 60)" ) . " AND user_id = '" . $client->getUserId . "' union all select user_shared_rda_id, agent_name as NAME, to_char(last_access, 'MM/DD/YYYY HH24:MI AM'), agent_ip, 'SHARED' as TYPE, rda_software_id, agent_port from w_user_shared_rda where user_id = '" . $client->getUserId . "' and agent_ip is not null order by TYPE, NAME asc"); my @computersOffline = $db->query(sql => " select w_user_computer_id, computer_name, to_char(last_access, 'MM/DD/YYYY HH24:MI AM'), RAWIP32_TO_DOTTED_QUAD(computer_ip), rda_software_id from w_user_computers where last_update <= " . $db->getCurrentTimeStampString() . ( (Pos::defaults::isPostgresDb()) ? " - interval '$timeoutMinutes Minutes'" : " - $timeoutMinutes/(24 * 60)" ) . " AND user_id = '" . $client->getUserId . "' order by computer_name asc"); $p = $tb->getPage(); print $p->getHeaderHtml(title => "Webtop: Remote Desktop interface") . "
"; print Pos::Webtop::OcxLauncher::getLauncherHtml(tb => $tb); if (defined($topText)) { print $topText; } $box = $tb->createBox(title => "Access a Remote Desktop", width => "550"); print $box->getHeaderHtml; print "
Please click on a computer to connect to a Remote Desktop Agent.

"; print " "; foreach my $computer (@computersOnline) { my ($computerId, $computerName, $computerLastAccess, $computerIp, $computerType, $rdaSoftwareId, $remotePort) = @{ $computer }; my $cleanName = $computerName; $cleanName =~ s/\\/\\\\/g; $cleanName =~ s/\'/\\\'/g; print " "; if ($currTd eq 'BOXTD1') { $currTd = 'BOXTD2'; } else { $currTd = 'BOXTD1'; } } foreach my $computer (@computersOffline) { my ($computerId, $computerName, $computerLastAccess, $computerIp, $rdaSoftwareId) = @{ $computer }; print " "; if ($currTd eq 'BOXTD1') { $currTd = 'BOXTD2'; } else { $currTd ='BOXTD1'; } } print "
Name Last Access Options
"; if ($rdaSoftwareId == 1) { (!defined($remotePort) && !length($remotePort)) and $remotePort = 5900; print" "; } elsif ($rdaSoftwareId == 2) { (!defined($remotePort) && !length($remotePort)) and $remotePort = 3389; print" "; } else { (!defined($remotePort) && !length($remotePort)) and $remotePort = 5900; print" "; } print"
 " . HTML::Entities::encode($computerName) . "  " . HTML::Entities::encode($computerName) . "  " . HTML::Entities::encode($computerName) . "
" . ((defined($computerLastAccess) && length($computerLastAccess) > 0)?"$computerLastAccess":"Never") . " " . (($computerType ne 'SHARED')?"[ " . $client->getFormGetCode( text => 'remove', values => [ { name => 'module', value => 'RemoteDesktop' }, { name => 'action', value => 'removeComputer' }, { name => 'computerId', value => $computerId }, { name => 'computerName', value => $computerName } ]) . " ] [ " . $client->getFormGetCode( text => 'rename', values => [ { name => 'module', value => 'RemoteDesktop' }, { name => 'action', value => 'renameComputer' }, { name => 'computerId', value => $computerId }, { name => 'computerName', value => $computerName } ]) . " ] ":"none") . "
"; if ($rdaSoftwareId == 1) { print " "; } elsif ($rdaSoftwareId == 2) { print " "; } else { print " "; } print "
 $computerName (offline)
" . ((length($computerLastAccess) > 0)?"$computerLastAccess":"Never") . " [ " . $client->getFormGetCode( text => 'remove', values => [ { name => 'module', value => 'RemoteDesktop' }, { name => 'action', value => 'removeComputer' }, { name => 'computerId', value => $computerId }, { name => 'computerName', value => $computerName } ]) . " ] [ " . $client->getFormGetCode( text => 'rename', values => [ { name => 'module', value => 'RemoteDesktop' }, { name => 'action', value => 'renameComputer' }, { name => 'computerId', value => $computerId }, { name => 'computerName', value => $computerName } ]) . " ]
"; if($self->canInstallRemoteDesktop()) { print "
[ " . $client->getFormGetCode( text => 'Install a new Remote Desktop Agent', values => [ { name => 'module', value => 'RemoteDesktop' }, { name => 'action', value => 'newDesktop' } ]) . " ]

"; } print $box->getFooterHtml; print "
"; $box = $tb->createBox(title => "Manually Access a Remote Desktop", width => "550"); if ($self->canManuallyConnectRemoteDesktop()) { print $box->getHeaderHtml; print "
Please enter an address to connect to a Remote Desktop Agent or a VNC server.


Type:
Remote Desktop Agent address:
  (eg: desktop.intranet.com or 123.2.32.1)

Remote Desktop Agent port:



"; print $box->getFooterHtml; } print $p->getFooterHtml(); } sub removeComputer { my $self = shift; my $tb = $self->getToolBox(); my $db = $tb->getWebtopDbReader(); my $client = $tb->getClient(); my ($computerName, $computerId, $okay) = @{{@_}}{qw/computerName computerId okay/}; if (defined($okay) and $okay eq '1') { $db->do(sql => " delete from w_user_computers where w_user_computer_id = '" . $db->escape(dirty => $computerId) . "' AND user_id = '" . $client->getUserId . "' "); $self->printMainPage(topText => "Successfully removed agent \"$computerName\".

"); } else { my $p = $tb->getPage(); $p->addNavBarElement(description => "Remove Computer", values => [ { name => "action", value => "removeComputer" }, { name => "computerName", value => $computerName }, { name => "computerId", value => $computerId } ]); print $p->getHeaderHtml(title => "Webtop: Remote Desktop: Remove") . "
"; print Pos::Webtop::OcxLauncher::getLauncherHtml(tb => $tb); my $box = $tb->createBox(title => "Remove a Remote Desktop Agent", width => "400"); print $box->getHeaderHtml; print "
This will remove \"$computerName\" from your list of Remote Desktop Agents.

" . $client->getFormInputs( values => [ { name => 'action', value => 'removeComputer' }, { name => 'okay', value => '1' }, { name => 'computerName', value => $computerName }, { name => 'computerId', value => $computerId } ]) . "
" . $client->getFormInputs() . "
"; print $box->getFooterHtml; print "
" . $p->getFooterHtml; } } sub renameComputer { my $self = shift; my $tb = $self->getToolBox(); my $db = $tb->getWebtopDbReader(); my $client = $tb->getClient(); my ($computerName, $computerId, $okay, $wantCancel) = @{{@_}}{qw/computerName computerId okay wantCancel/}; if (defined($wantCancel) and length($wantCancel) > 0) { $self->printMainPage(); } elsif (defined($okay) and $okay eq '1') { $db->do(sql => " update w_user_computers set computer_name = '" . $db->escape(dirty => $computerName) . "' where w_user_computer_id = '" . $db->escape(dirty => $computerId) . "' AND user_id = '" . $client->getUserId . "' "); $self->printMainPage(topText => "Successfully renamed Remote Desktop Agent to \"$computerName\".

"); } else { my $p = $tb->getPage(); $p->addNavBarElement(description => "Rename Computer", values => [ { name => "action", value => "removeComputer" }, { name => "computerName", value => $computerName }, { name => "computerId", value => $computerId } ]); print $p->getHeaderHtml(title => "Webtop: Remote Desktop: Rename Desktop Agent") . "
"; print Pos::Webtop::OcxLauncher::getLauncherHtml(tb => $tb); my $box = $tb->createBox(title => "Rename a Remote Desktop Agent", width => "400"); print $box->getHeaderHtml; print "
Please provide a new name for the Remote Desktop Agent.

New Remote Desktop Agent name:
" . $client->getFormInputs( values => [ { name => 'action', value => 'renameComputer' }, { name => 'okay', value => '1' }, { name => 'computerId', value => $computerId } ]) . " " . $client->getFormInputs() . "
"; print $box->getFooterHtml; print "
" . $p->getFooterHtml; } } sub newDesktop { my $self = shift; my $tb = $self->getToolBox(); my $db = $tb->getWebtopDbReader(); my $client = $tb->getClient(); my $activeXConnected = $client->isWebtopVpnConnectionEstablished(db=> $db) && !$client->isMacWebtop(); my $cgi = $tb->getCgi(); my ($installNow, $currVersion) = @{{@_}}{qw/installNow currVersion/}; my $oem = $tb->getOem; my $p = $tb->getPage(); $p->addNavBarElement(description => "New Remote Desktop Agent", values => [ { name => "action", value => "newDesktop" } ]); print $p->getHeaderHtml(title => "". $oem->getSetting(setting=>'webtopProductName') .": Remote Desktop: Install Now") . "
"; print Pos::Webtop::OcxLauncher::getLauncherHtml(tb => $tb); print "
"; if (not defined($installNow)) { my $box; if(not defined $cgi->param('is98')) { print "
"; print $p->getFooterHtml(); exit; } $box = $tb->createBox(title => "Installing a new Remote Desktop Agent", width => 400); print $box->getHeaderHtml; print "The Remote Desktop Agent allows you to remotely access your Windows-based computer from the " . $oem->getSetting(setting => 'webtopProductName') . " through a standard Internet browser. To access your computer from the ". $oem->getSetting(setting=>'webtopProductName') .", your computer must be connected to your corporate network and the Remote Desktop Agent must be running."; print $box->getFooterHtml . "
"; $box = $tb->createBox(title => "System Requirements", width => 400); print $box->getHeaderHtml; print "The Remote Desktop Agent is compatible with Windows 95, 98, ME, NT, 2000 and XP."; print $box->getFooterHtml . "
"; $box = $tb->createBox(title => "Install", width => 400); print $box->getHeaderHtml; print "To install the Remote Desktop Agent on the computer you wish to access remotely, click the \"Install Now\" button below and follow the on-screen prompts. When the download begins, you may receive Security Warnings from your browser. If these warnings appear, please allow the installation to proceed.

"; my ($realVersion) = $db->query(sql => " select version_string from w_rda_version "); print "The current version of the RDA software is $realVersion

"; if (defined($currVersion)) { print "You are currently using RDA version $currVersion

"; } print $client->getFormGetCode( text => "", values => [ { name => 'installNow', value => '1' }, { name => 'action', value => 'newDesktop' }, { name => 'is98', value => (defined($cgi->param('is98')) ? $cgi->param('is98') : "0") } ]) . "


"; print "
" . ($activeXConnected ? $client->getFormInputs() : "") . "
"; print $box->getFooterHtml; } else { my (@info) = $db->query(sql => " select oem_rda_installer_path, rda_app_id from oems where oem_id = ( select oem_id from customers where customer_id = ( select customer_id from groups where group_id = ( select group_id from users where user_id = '" . $client->getUserId() . "' ) ) ) "); my $oemRDAPath; my $oemRdaAppId; if (scalar(@info)) { ($oemRDAPath, $oemRdaAppId) = @{ $info[0] }; } # Figure out if they're using the ActiveX control... my ($hasActiveX) = $db->query(sql => " select activex_disabled from client_sessions where client_session_id = " . $client->getSessionId . " "); $hasActiveX = ($hasActiveX) ? 0 : 1; if(not defined($oemRDAPath)) { $oemRDAPath = Pos::defaults::getRDAPath; } if ($hasActiveX and $oemRdaAppId) { print Pos::Webtop::OcxLauncher::getLauncherHtml(tb => $tb) . " "; } else { my $exeUrl = $oemRDAPath; if ($cgi->param('is98')) { $exeUrl .= "RDAInstaller98.exe"; } else { $exeUrl .= "RDAInstaller.exe"; } print " "; } my $box = $tb->createBox(title => "Installing Remote Desktop Agent", width => 400); print $box->getHeaderHtml; print "You should be prompted to install the Remote Desktop Agent.

After completing the prompts and installing the Remote Desktop Agent, " . $client->getFormGetCode( text =>'click here', values => [ { name=> 'module', value=> 'RemoteDesktop' }, ]) . " to return.

If you are not prompted to install the Remote Desktop Agent or have issues installing, " . $client->getFormGetCode( text => 'click here', values => [ { name => 'action', value => 'trouble' }, { name => 'is98', value => $cgi->param('is98') } ]) . ". "; print $box->getFooterHtml; } print "
" . $p->getFooterHtml; } sub showTroubleHelp { my $self = shift; my $tb = $self->getToolBox(); my $db = $tb->getWebtopDbReader(); my $client = $tb->getClient(); my $cgi = $tb->getCgi(); my $p = $tb->getPage(); my $oem = $tb->getOem; $p->addNavBarElement(description => "Download Problems", values => [ { name => "action", value => "trouble" } ]); print $p->getHeaderHtml(title => "". $oem->getSetting(setting=>'webtopProductName') . ": Remote Desktop: Install Now") . "
"; print Pos::Webtop::OcxLauncher::getLauncherHtml(tb => $tb); print "
"; my $box = $tb->createBox(title => "Download Problems", width => 400); print $box->getHeaderHtml; my ($oemRDAPath) = $db->query(sql => " select oem_rda_installer_path from oems where oem_id = ( select oem_id from customers where customer_id = ( select customer_id from groups where group_id = ( select group_id from users where user_id = '" . $client->getUserId() . "' ) ) ) "); if(not defined($oemRDAPath)) { $oemRDAPath = Pos::defaults::getRDAPath; } my $exeUrl = $oemRDAPath; if ($cgi->param('is98')) { $exeUrl .= "RDAInstaller98.exe"; } else { $exeUrl .= "RDAInstaller.exe"; } print "If a window did not appear, or the download did not begin, please click here to download the installer. When the \"File Download\" window appears, select the option to \"Run this program from its current location\", and then click the \"OK\" button.

If you experience additional problems or have any questions, please contact Customer Support."; print $box->getFooterHtml; print "
" . $p->getFooterHtml; } 1;