#!/usr/bin/perl -I. # # This software is copyright (c) 2001-2002 Positive Networks, Inc. All rights reserved. # # This software is the proprietary and confidential property of Positive Networks, Inc. # Possession, transmission, publication, or use of this software is prohibited except by prior written consent. # use strict; use Pos::Webtop::Web::ContentModule (); use Pos::Webtop::OcxLauncher; package Pos::Webtop::Web::ContentModule::Applications; 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 canUseAppLauncher { my $self = shift; my $tb = $self->getToolBox(); my $client = $tb->getClient(); if ( not defined( $self->{'canUseAppLauncher'} ) ) { my $moduleAccess = $client->getAllowedContentModules(); $self->{'canUseAppLauncher'} = $moduleAccess->{'Applications'}->{'sm_appLauncher'}; } return $self->{'canUseAppLauncher'}; } sub canCreateAppTunnels { my $self = shift; my $tb = $self->getToolBox(); my $client = $tb->getClient(); if ( not defined( $self->{'canCreateAppTunnels'} ) ) { my $moduleAccess = $client->getAllowedContentModules(); $self->{'canCreateAppTunnels'} = $moduleAccess->{'Applications'}->{'sm_userDefinedAtp'}; } return $self->{'canCreateAppTunnels'}; } sub getIconView { my $self = shift; my ($maxItems,$columns,$items) = @{{@_}}{qw/maxItems columns items/}; $maxItems = 0xFFFF unless defined $maxItems; # items are a sorted array full of hash refs with the following values # icon=> "icon path", # href=> "href on click.. ie javascript:bob();", # text=> "display text for below the icon" my $ret .= " "; my $cnt = 0; foreach my $item ( @{ $items } ) { if ( $cnt % $columns ) { $ret .= " "; } else { $ret .= " "; } if ( $cnt == $maxItems ) { last } } if ( ( $cnt % $columns ) and ( $cnt > $columns ) ) { my $i; for ( $i = ($columns) - ($cnt % $columns); $i > 0; $i-- ) { $ret .= "\n"; } } if ( $cnt % $columns ) { $ret .= "\n"; } $ret .= "
"; } else { $ret .= "
"; } $ret .= " {'href'} . "\"> Application Icon
" . HTML::Entities::encode( $item->{'text'} ) . "
"; $cnt++; if ( $cnt % $columns ) { $ret .= "
 

"; } sub getApplicationsWithTunnels { my $self = shift; my ($applicationsAvailable) = @{{@_}}{qw/applicationsAvailable/}; my $tb = $self->getToolBox(); my $client = $tb->getClient(); my $userId = $client->getUserId(); my $customerId = $client->getCustomerId(); my $db = $tb->getWebtopDbReader(); my $ret = []; # XXX: Need support for custom app profiles that are user defined in webtop as far as dyn/args go my @rows = $db->query( sql=> " select p.profile_id, p.app_id, p.profile_name, p.is_dynamic, p.arguments, 'POLICY' from user_app_tunnel_profiles p, customer_atp_apps aa where p.app_id = aa.app_id and p.user_id = $userId and aa.customer_id = $customerId union all select p.profile_id, p.app_id, p.profile_name, p.is_dynamic, p.arguments, 'USER' from w_user_app_tunnel_profiles p, customer_atp_apps aa where p.app_id = aa.app_id and p.app_id is not null and p.user_id = $userId and aa.customer_id = $customerId order by profile_name asc "); foreach ( @rows ) { my ($profileId,$appId,$profileName,$dynamic,$arguments,$type) = @{ $_ }; my $webtopIcon = undef; if ( defined $applicationsAvailable ) { $webtopIcon = $applicationsAvailable->{$appId}->{'webtopIcon'}; } push @{ $ret }, { profileId=> $profileId, appId=> $appId, profileName=> $profileName, dynamic=> $dynamic, arguments=> $arguments, type=> $type, webtopIcon=> $webtopIcon }; } return $ret; } sub getTunnelsWithoutApplications { my $self = shift; my $tb = $self->getToolBox(); my $client = $tb->getClient(); my $userId = $client->getUserId(); my $db = $tb->getWebtopDbReader(); my $ret = []; my @rows = $db->query( sql=> " select profile_id, profile_name from w_user_app_tunnel_profiles where user_id = $userId and app_id is null order by profile_name asc "); foreach ( @rows ) { my ($profileId,$profileName) = @{ $_ }; push @{ $ret }, { profileId=> $profileId, profileName=> $profileName } } return $ret; } sub getApplicationsAvailable { my $self = shift; my $tb = $self->getToolBox(); my $client = $tb->getClient(); my $userId = $client->getUserId(); my $db = $tb->getWebtopDbReader(); my $ret = {}; my @rows = $db->query( sql=> " select ap.app_id, ap.app_name, ap.ver_info, ap.webtop_icon from apps ap, w_user_apps_Available aa where ap.app_id = aa.app_id and user_id = $userId order by app_name asc "); foreach ( @rows ) { my ($appId,$appName,$verInfo,$webtopIcon) = @{ $_ }; $ret->{$appId} = { appName=> $appName, verInfo=> $verInfo, webtopIcon=> $webtopIcon }; } return $ret; } sub getApplicationsTunnelable { my $self = shift; my $tb = $self->getToolBox(); my $client = $tb->getClient(); my $userId = $client->getUserId(); my $customerId = $client->getCustomerId(); my $db = $tb->getWebtopDbReader(); my $ret = {}; my @rows = $db->query( sql=> " select ap.app_id, ap.app_name, ap.ver_info, ap.webtop_icon from apps ap, customer_atp_apps aa where ap.app_id = aa.app_id and customer_id = $customerId order by app_name asc "); foreach ( @rows ) { my ($appId,$appName,$verInfo,$webtopIcon) = @{ $_ }; $ret->{$appId} = { appName=> $appName, verInfo=> $verInfo, webtopIcon=> $webtopIcon }; } return $ret; } sub getPreviewListHtml { my $self = shift; my ($retTotal) = @{{@_}}{qw/retTotal/}; my $tb = $self->getToolBox(); my $client = $tb->getClient(); my $cgi = $tb->getCgi(); my $userId = $client->getUserId(); my $db = $tb->getWebtopDbReader(); my $ret = ""; my $appsTunnelable = $self->getApplicationsTunnelable(); my $withTunnels = $self->getApplicationsWithTunnels( applicationsAvailable=> $appsTunnelable ); my $withoutApps = $self->getTunnelsWithoutApplications(); my @wt = sort { return ( uc( $a->{'profileName'} ) gt uc( $b->{'profileName'} ) ) } @{ $withTunnels }; my @l1 = (); my $canCreateAppTunnels = $self->canCreateAppTunnels(); foreach my $p ( @wt ) { if ( ( $p->{'type'} eq 'USER' ) and ( not $canCreateAppTunnels ) ) { # skip user created if user can't create em! next; } my $flags = $self->getFlagsForProfile(profile => $p); $flags =~ s/\\/\\\\/g; push @l1, { text=> $p->{'profileName'}, href=> "javascript:installExecuteApplication('" . $p->{'type'} . "'," . $p->{'profileId'} . ", " . $p->{'appId'} . ", '$flags');", icon=> "LocalWebLib/ApplicationIcons/" . $p->{'webtopIcon'} }; } $ret .= $self->getIconView( items=> \@l1, columns=> 2, maxItems=> 6 ); my $appsAvailable = $self->getApplicationsAvailable(); ${$retTotal} = scalar( keys %{ $appsAvailable } ) + scalar( @wt ) + scalar ( @{ $withoutApps } ); return $ret; } sub doNewStep2 { my $self = shift; my $tb = $self->getToolBox(); my $client = $tb->getClient(); my $cgi = $tb->getCgi(); my $page = $tb->getPage(); $client->setPersistedValue( name=> 'appId', value=> $cgi->param('appId') ); $page->addNavBarElement( description=> "Create New Profile" ); print $page->getHeaderHtml( title=> "Create New Profile" ); #print Pos::Webtop::OcxLauncher::getLauncherHtml(tb => $tb); my $mainBox = $tb->createBox( title=> "Create New Profile", width=> "400" ); print "
\n"; print $mainBox->getHeaderHtml(); print "
\n"; my $cancelLink = $client->getFormGetCode( text=> 'Cancel', values=> [ { name=> 'doNew', value=> 0 } ] ); print "
Please choose a name and type for your new application tunnel profile:

" . $client->getFormInputs() . "
Name:
Type:

[ $cancelLink ]
"; print "
\n"; print $mainBox->getFooterHtml(); print $page->getFooterHtml(); } sub doNewStep3 { my $self = shift; my $tb = $self->getToolBox(); my $client = $tb->getClient(); my $cgi = $tb->getCgi(); my $page = $tb->getPage(); my $dbw = $tb->getWebtopDbWriter(); $page->addNavBarElement( description=> "Create New Profile" ); print $page->getHeaderHtml( title=> "Create New Profile" ); #print Pos::Webtop::OcxLauncher::getLauncherHtml(tb => $tb); my $mainBox = $tb->createBox( title=> "Create New Profile", width=> "400" ); print "
\n"; print $mainBox->getHeaderHtml(); print "
\n"; my $profileId = $dbw->getNextSequenceValue( sequence=> "w_user_app_tunnel_profiles_pk" ); my $userId = $client->getUserId(); my $profileName = $cgi->param( 'profileName'); my $profileType = $cgi->param( 'profileType'); my $dynamic; $profileName = 'New Profile' unless ( defined($profileName) and length($profileName) ); my $appId = $client->getPersistedValue( name=> 'appId' ); if ( $appId == 0 ) { $appId = 'null'; } else { $appId = Pos::web::digitize( dirty=> $appId ); } if ($profileType eq 'DYNAMIC') { $dynamic = 1; } else { $dynamic = 0; } my $sql = " insert into w_user_app_tunnel_profiles ( profile_id, user_id, profile_name, app_id, is_dynamic, arguments ) values ( $profileId, $userId, '" . $dbw->escape( dirty=> $profileName ) . "', $appId, $dynamic, '' ) "; $dbw->do( sql=> $sql ); my $editLink = $client->getFormGetCode( text=> 'Edit Profile', values=> [ { name=> 'doNew', value=> 0 }, { name=> 'doEditProfile', value=> 1 }, { name=> 'profileId', value=> $profileId } ] ); print "
Your new profile is saved. Please press the Edit Profile link to go to the
Profile Properties page to modify and or add new network tunnels to this profile.

[ $editLink ]

"; print "
\n"; print $mainBox->getFooterHtml(); print $page->getFooterHtml(); } sub doNew { my $self = shift; my $tb = $self->getToolBox(); my $client = $tb->getClient(); my $cgi = $tb->getCgi(); my $canCreateAppTunnels = $self->canCreateAppTunnels(); return unless $canCreateAppTunnels; my $step = $cgi->param( 'step' ); defined ( $step ) and $client->setPersistedValue( name=> 'step', value=> $step ); $step = $client->getPersistedValue( name=> 'step' ) unless defined $step; $step = 1 unless defined $step; if ( $step == 2 ) { $client->repersistValues( values=> ['step'] ); return $self->doNewStep2(); } elsif ( $step == 3 ) { $client->repersistValues( values=> ['step'] ); return $self->doNewStep3(); } my $page = $tb->getPage(); $page->addNavBarElement( description=> "Create New Profile" ); print $page->getHeaderHtml( title=> "Create New Profile" ); #print Pos::Webtop::OcxLauncher::getLauncherHtml(tb => $tb); my $mainBox = $tb->createBox( title=> "Create New Profile", width=> "400" ); print "
\n"; print $mainBox->getHeaderHtml(); print " Overview:
You are adding a new profile to your application profile settings. This allows you to create a profile which, when launched, will bring up a tunnel from your web browser to the corporate network. The first step is choosing an application, if any, that will be used by this profile.

"; print $client->getFormInputs(); my $appsAvailable = $self->getApplicationsTunnelable(); my @aa = (); foreach my $appId ( keys %{ $appsAvailable } ) { my $appName = $appsAvailable->{$appId}->{'appName'}; my $verInfo = $appsAvailable->{$appId}->{'verInfo'}; my $displayName = $appName . ( defined( $verInfo ) ? " ($verInfo)" : "" ); push @aa, { appId=> $appId, appName=> $appName, verInfo=> $verInfo, webtopIcon=> $appsAvailable->{$appId}->{'webtopIcon'}, displayName=> $displayName }; } @aa = sort { return ( uc( $a->{'displayName'} ) gt uc( $b->{'displayName'} ) ) } @aa; my @l1 = (); foreach my $a ( @aa ) { push @l1, { text=> $a->{'displayName'}, href=> "javascript:pickAndGo(" . $a->{'appId'} . ");", icon=> "LocalWebLib/ApplicationIcons/" . $a->{'webtopIcon'} }; } my $appList .= $self->getIconView( items=> \@l1, columns=> 4 ); print "$appList\n"; print "\n"; print "
\n"; print $mainBox->getFooterHtml(); print $page->getFooterHtml(); } sub doEditProfileIdSave { my $self = shift; my $tb = $self->getToolBox(); my $client = $tb->getClient(); my $cgi = $tb->getCgi(); my $dbw = $tb->getWebtopDbWriter(); my $userId = $client->getUserId(); my $profileId = $client->getPersistedValue( name=> 'profileId' ); my $appId = $cgi->param('appId'); my $profileName = $cgi->param('profileName'); my $profileType = $cgi->param('profileType'); my $arguments = $cgi->param('arguments'); my $dynamic; # we know that the profileId and appId are safe because our caller was the one who (re)persisted the values # and they checked if ( $appId == 0 ) { $appId = 'null'; } if ($profileType eq 'DYNAMIC') { $dynamic = 1; } else { $dynamic = 0; } if (not defined($arguments)) { $arguments = ''; } my $sql = " update w_user_app_tunnel_profiles set app_id = $appId, profile_name = '" . $dbw->escape( dirty=> $profileName ) . "', is_dynamic = '$dynamic', arguments = '" . $dbw->escape(dirty => $arguments) . "' where profile_id = $profileId and user_id = $userId "; #warn "sql: $sql\n"; $dbw->do( sql=> $sql ); my $page = $tb->getPage(); print $page->getHeaderHtml( title=> "Edit Profile" ); #print Pos::Webtop::OcxLauncher::getLauncherHtml(tb => $tb); my $mainBox = $tb->createBox( title=> "Edit Profile", width=> "350" ); print "
\n"; print $mainBox->getHeaderHtml(); my $returnLink = $client->getFormGetCode( text=> 'Return', values=> [ { name=> 'editCmd', value=> "" } ] ); print "

Your profile was saved.

[ $returnLink ]

"; print $mainBox->getFooterHtml(); print "
\n"; print $page->getFooterHtml(); } sub doEditProfileIdRemove { my $self = shift; my $tb = $self->getToolBox(); my $client = $tb->getClient(); my $cgi = $tb->getCgi(); my $dbw = $tb->getWebtopDbWriter(); my $userId = $client->getUserId(); my $profileId = $client->getPersistedValue( name=> 'profileId' ); # we know that the profileId and appId are safe because our caller was the one who (re)persisted the values # and they checked my $sql = "delete from w_user_app_tunnel_profiles where user_id = $userId and profile_id = $profileId"; #warn "sql: $sql\n"; $dbw->do( sql=> $sql ); my $page = $tb->getPage(); print $page->getHeaderHtml( title=> "Edit Profile" ); #print Pos::Webtop::OcxLauncher::getLauncherHtml(tb => $tb); my $mainBox = $tb->createBox( title=> "Edit Profile", width=> "350" ); print "
\n"; print $mainBox->getHeaderHtml(); my $returnLink = $client->getFormGetCode( text=> 'Return', values=> [ { name=> 'doEditProfile', value=> "0" } ] ); print "

Your profile was removed.

[ $returnLink ]

"; print $mainBox->getFooterHtml(); print "
\n"; print $page->getFooterHtml(); } sub doEditTunnelSave { my $self = shift; my $tb = $self->getToolBox(); my $client = $tb->getClient(); my $cgi = $tb->getCgi(); my $dbw = $tb->getWebtopDbWriter(); my $userId = $client->getUserId(); my $profileId = $client->getPersistedValue( name=> 'profileId' ); my $tunnelId = $client->getPersistedValue( name=> 'tunnelId' ); my $page = $tb->getPage(); print $page->getHeaderHtml( title=> "Save Tunnel" ); #print Pos::Webtop::OcxLauncher::getLauncherHtml(tb => $tb); my $mainBox = $tb->createBox( title=> "Save Tunnel", width=> "350" ); my $localHost = $cgi->param('localHost'); my $localPort = Pos::web::digitize( dirty=> $cgi->param('localPort') ); my $remoteHost = $cgi->param('remoteHost'); my $remotePort = Pos::web::digitize( dirty=> $cgi->param('remotePort') ); $localPort = 0 unless length( $localPort ); $remotePort = 0 unless length( $remotePort ); print "
\n"; print $mainBox->getHeaderHtml(); $dbw->do( sql=> "lock table w_user_atp_tunnels in exclusive mode" ); my @errorMessages = (); # just do some sanity checks my $andTunnelId = ""; if ( length( $tunnelId ) ) { $tunnelId = Pos::web::digitize( dirty=> $tunnelId ); $andTunnelId = "and tunnel_id != $tunnelId"; } my $sql = " select count(*) from w_user_atp_tunnels where local_port = $localPort and user_id = $userId and profile_id = $profileId $andTunnelId "; my ($cnt) = $dbw->query( sql=> $sql ); if ( $cnt ) { push @errorMessages, "There is already a tunnel with local port $localPort for this profile."; } if ( not ( defined($localHost) and ($localHost =~ /^[[:alnum:]\.\-]*$/) ) ) { push @errorMessages, "The local host is invalid."; } if ( not ( defined($remoteHost) and ($remoteHost =~ /^[[:alnum:]\.\-]*$/) ) ) { push @errorMessages, "The remote host is invalid."; } if ( not @errorMessages ) { # save if ( not ( length($tunnelId) ) ) { my ($tunnelId) = $dbw->query( sql=> " select max(tunnel_id)+1 from w_user_atp_tunnels where user_id = $userId and profile_id = $profileId "); if ( not defined ($tunnelId) ) { $tunnelId = 1; } # insert my $sql = " insert into w_user_atp_tunnels ( profile_id, user_id, tunnel_id, local_host, local_port, remote_host, remote_port ) values ( $profileId, $userId, $tunnelId, '" . $dbw->escape( dirty=> $localHost ) . "', '" . $dbw->escape( dirty=> $localPort ) . "', '" . $dbw->escape( dirty=> $remoteHost ) . "', '" . $dbw->escape( dirty=> $remotePort ) . "' ) "; $dbw->do( sql=> $sql ); $dbw->commit(); } else { # update my $sql = " update w_user_atp_tunnels set local_host = '" . $dbw->escape( dirty=> $localHost ) . "', local_port = '" . $dbw->escape( dirty=> $localPort ) . "', remote_host = '" . $dbw->escape( dirty=> $remoteHost ) . "', remote_port = '" . $dbw->escape( dirty=> $remotePort ) . "' where profile_id = $profileId and user_id = $userId and tunnel_id = $tunnelId "; $dbw->do( sql=> $sql ); $dbw->commit(); } my $returnLink = $client->getFormGetCode( text=> 'Return', values=> [ { name=> 'save', value=> "" }, { name=> 'editCmd', value=> "" } ] ); print "

Your tunnel information was saved.

[ $returnLink ]

"; } else { $dbw->commit(); # give up lock quick like # dont save, persist values $client->setPersistedValue( name=> 'localHost', value=> $localHost ); $client->setPersistedValue( name=> 'localPort', value=> $localPort ); $client->setPersistedValue( name=> 'remoteHost', value=> $remoteHost ); $client->setPersistedValue( name=> 'remotePort', value=> $remotePort ); my $returnLink = $client->getFormGetCode( text=> 'Return', values=> [ { name=> 'save', value=> "" } ] ); print "

"; print join("
",@errorMessages); print "

[ $returnLink ]

"; } print $mainBox->getFooterHtml(); print "
\n"; print $page->getFooterHtml(); } sub doEditTunnel { my $self = shift; my $tb = $self->getToolBox(); my $client = $tb->getClient(); my $cgi = $tb->getCgi(); my $dbr = $tb->getWebtopDbReader(); my $userId = $client->getUserId(); my $profileId = $client->getPersistedValue( name=> 'profileId' ); # we know that the profileId and appId are safe because our caller was the one who (re)persisted the values # and they checked my $page = $tb->getPage(); $page->addNavBarElement( description=> "Edit Tunnel" ); my $mainBox = $tb->createBox( title=> "Edit Tunnel", width=> "350" ); my $tunnelId = $cgi->param( 'tunnelId' ); defined ( $tunnelId ) and $client->setPersistedValue( name=> 'tunnelId', value=> $tunnelId ); $tunnelId = $client->getPersistedValue( name=> 'tunnelId' ) unless defined $tunnelId; $tunnelId = '' unless defined $tunnelId; $tunnelId = Pos::web::digitize( dirty=> $tunnelId ); my $save = $cgi->param('save'); if ( defined( $save ) and length( $save ) ) { return $self->doEditTunnelSave(); } my ($localHost,$localPort,$remoteHost,$remotePort) = ('','','',''); $client->setPersistedValue( name=> 'tunnelId', value=> $tunnelId ); if ( length( $tunnelId ) ) { # load goodies from db my @rows = $dbr->query( sql=> " select local_host, local_port, remote_host, remote_port from w_user_atp_tunnels where profile_id = $profileId and tunnel_id = $tunnelId and user_id = $userId "); ($localHost,$localPort,$remoteHost,$remotePort) = @{ $rows[0] }; } # we also want to be able to have persisted values override our db values incase # we are coming back from a 'failed' save to repopulate the values my $nlocalHost = $client->getPersistedValue( name=> 'localHost' ); my $nlocalPort = $client->getPersistedValue( name=> 'localPort' ); my $nremoteHost = $client->getPersistedValue( name=> 'remoteHost' ); my $nremotePort = $client->getPersistedValue( name=> 'remotePort' ); defined( $nlocalHost ) and $localHost = $nlocalHost; defined( $nlocalPort ) and $localPort = $nlocalPort; defined( $nremoteHost ) and $remoteHost = $nremoteHost; defined( $nremotePort ) and $remotePort = $nremotePort; my $cancelLink = $client->getFormGetCode( text=> "Cancel", values=> [ { name=> "editCmd", value=> "" } ] ); print $page->getHeaderHtml( title=> "Edit Tunnel" ); #print Pos::Webtop::OcxLauncher::getLauncherHtml(tb => $tb); print "
\n"; print $mainBox->getHeaderHtml(); print "
" . $client->getFormInputs() ."
Local Host:
Local Port:
Remote Host:
Remote Port:
[ $cancelLink ]
"; print $mainBox->getFooterHtml(); print "
\n"; print $page->getFooterHtml(); } sub doRemoveTunnel { my $self = shift; my $tb = $self->getToolBox(); my $client = $tb->getClient(); my $cgi = $tb->getCgi(); my $dbw = $tb->getWebtopDbWriter(); my $userId = $client->getUserId(); my $profileId = $client->getPersistedValue( name=> 'profileId' ); # we know that the profileId and appId are safe because our caller was the one who (re)persisted the values # and they checked my $page = $tb->getPage(); print $page->getHeaderHtml( title=> "Edit Profile" ); #print Pos::Webtop::OcxLauncher::getLauncherHtml(tb => $tb); my $mainBox = $tb->createBox( title=> "Edit Profile", width=> "350" ); print "
\n"; print $mainBox->getHeaderHtml(); my $returnLink = $client->getFormGetCode( text=> 'Return', values=> [ { name=> 'doEditProfile', value=> "0" } ] ); print "



[ $returnLink ]

"; print $mainBox->getFooterHtml(); print "
\n"; print $page->getFooterHtml(); } sub doEditProfileId { my $self = shift; my $tb = $self->getToolBox(); my $client = $tb->getClient(); my $cgi = $tb->getCgi(); my $dbr = $tb->getWebtopDbReader(); my $userId = $client->getUserId(); my $profileId = $client->getPersistedValue( name=> 'profileId' ); $client->repersistValues( values=> ['profileId'] ); my $page = $tb->getPage(); $page->addNavBarElement( description=> "Edit Profile" ); # verify we can edit this profile my @rows = $dbr->query( sql=> " select profile_name, app_id, is_dynamic, arguments from w_user_app_tunnel_profiles where profile_id = '" . $dbr->escape( dirty=> $profileId ) . "' and user_id = $userId "); if ( not @rows ) { warn "Tried to edit profile that we don't have access to\n"; die; } my ($profileName,$appId,$dynamic,$arguments) = @{ $rows[0] }; $appId = 0 unless defined $appId; $client->setPersistedValue( name=> 'appId', value=> $appId ); my $editCmd = $cgi->param( 'editCmd' ); defined ( $editCmd ) and $client->setPersistedValue( name=> 'editCmd', value=> $editCmd ); $editCmd = $client->getPersistedValue( name=> 'editCmd' ) unless defined $editCmd; $editCmd = "" unless defined $editCmd; if ( length( $editCmd ) ) { $client->repersistValues( values=> [ 'editCmd' ] ); if ( $editCmd eq "save" ) { return $self->doEditProfileIdSave(); } elsif ( $editCmd eq "remove" ) { return $self->doEditProfileIdRemove(); } elsif ( $editCmd eq "editTunnel" ) { return $self->doEditTunnel(); } elsif ( $editCmd eq "removeTunnel" ) { my $dbw = $tb->getWebtopDbWriter(); my $tunnelId = Pos::web::digitize( dirty=> $cgi->param('tunnelId') ); my $sql = "delete from w_user_atp_tunnels where user_id = $userId and profile_id = $profileId and tunnel_id = $tunnelId"; #warn "sql: $sql\n"; $dbw->do( sql=> $sql ); $dbw->commit(); } } print $page->getHeaderHtml( title=> "Edit Profile" ); #print Pos::Webtop::OcxLauncher::getLauncherHtml(tb => $tb); my $mainBox = $tb->createBox( title=> "Edit Profile", width=> "600" ); print "
\n"; print $mainBox->getHeaderHtml(); my $appsTunnelable = $self->getApplicationsTunnelable(); my @aa = (); foreach my $appId ( keys %{ $appsTunnelable } ) { my $appName = $appsTunnelable->{$appId}->{'appName'}; my $verInfo = $appsTunnelable->{$appId}->{'verInfo'}; my $displayName = $appName . ( defined( $verInfo ) ? " ($verInfo)" : "" ); push @aa, { appId=> $appId, appName=> $appName, verInfo=> $verInfo, webtopIcon=> $appsTunnelable->{$appId}->{'webtopIcon'}, displayName=> $displayName }; } @aa = sort { return ( uc( $a->{'displayName'} ) gt uc( $b->{'displayName'} ) ) } @aa; push @aa, { appId=> 0, displayName=> "No Application" }; print "
" . $client->getFormInputs() . "
Profile Name:
Application:
Type:
Arguments:
"; if (!$dynamic) { print "
Tunnels:

"; my @tunnels = $dbr->query( sql=> " select tunnel_id, local_host, local_port, remote_host, remote_port from w_user_atp_tunnels where user_id = $userId and profile_id = $profileId order by tunnel_id "); foreach ( @tunnels ) { my ($tunnelId,$localHost,$localPort,$remoteHost,$remotePort) = @{ $_ }; print " "; } print "
Local Host Local Port Remote Host Remote Port Action
" . HTML::Entities::encode( $localHost ) ." " . HTML::Entities::encode( $localPort ) ." " . HTML::Entities::encode( $remoteHost ) ." " . HTML::Entities::encode( $remotePort ) ." Edit / Remove
"; } my $cancelLink = $client->getFormGetCode( text=> 'Return', values=> [ { name=> 'doEditProfile', value=> 0 } ] ); print "

"; if (!$dynamic) { print ""; } print "
[ $cancelLink ]
"; print $mainBox->getFooterHtml(); print "
\n"; print $page->getFooterHtml(); } sub doEditProfile { my $self = shift; my $tb = $self->getToolBox(); my $client = $tb->getClient(); my $cgi = $tb->getCgi(); my $canCreateAppTunnels = $self->canCreateAppTunnels(); return unless $canCreateAppTunnels; my $profileId = $cgi->param( 'profileId' ); defined ( $profileId ) and $client->setPersistedValue( name=> 'profileId', value=> $profileId ); $profileId = $client->getPersistedValue( name=> 'profileId' ) unless defined $profileId; if ( defined $profileId and length( $profileId ) ) { $client->repersistValues( values=> ['profileId'] ); return $self->doEditProfileId(); } my $page = $tb->getPage(); $page->addNavBarElement( description=> "Edit Profile" ); print $page->getHeaderHtml( title=> "Edit Profile" ); #print Pos::Webtop::OcxLauncher::getLauncherHtml(tb => $tb); my $mainBox = $tb->createBox( title=> "Edit Profile", width=> "400" ); my $appsTunnelable = $self->getApplicationsTunnelable(); my $withTunnels = $self->getApplicationsWithTunnels( applicationsAvailable=> $appsTunnelable ); my $withoutApps = $self->getTunnelsWithoutApplications(); my @wt = sort { return ( uc( $a->{'profileName'} ) gt uc( $b->{'profileName'} ) ) } @{ $withTunnels }; my @wa = sort { return ( uc( $a->{'profileName'} ) gt uc( $b->{'profileName'} ) ) } @{ $withoutApps }; my @l1 = (); foreach my $p ( @wt ) { if ( ( $p->{'type'} eq 'POLICY' ) ) { # Skip policy ones next; } push @l1, { text=> $p->{'profileName'}, href=> "javascript:pickAndGo(" . $p->{'profileId'} . ");", icon=> "LocalWebLib/ApplicationIcons/" . $p->{'webtopIcon'} }; } my $topStuff = $self->getIconView( items=> \@l1, columns=> 6 ); print "
\n"; print $mainBox->getHeaderHtml(); my $cancelLink = $client->getFormGetCode( text=> 'Cancel', values=> [ { name=> 'doEditProfile', value=> 0 } ] ); print " Overview:
Listed below are all of the profiles you have created and may modify. Please click on the one you wish to modify.

"; if (scalar(@wa) > 0) { print " "; } print "
Application Tunnel Profiles
$topStuff
Additional Tunnels



" . $client->getFormInputs() . "
"; print "
[ $cancelLink ]
"; print $mainBox->getFooterHtml(); print $page->getFooterHtml(); } # (pure virtual defined in Pos::Webtop::Web::ContentModule) sub main { my $self = shift; my $tb = $self->getToolBox(); my $client = $tb->getClient(); my $cgi = $tb->getCgi(); my $action = $cgi->param('action'); $action = '' unless defined $action; my $doNew = $cgi->param( 'doNew' ); defined ( $doNew ) and $client->setPersistedValue( name=> 'doNew', value=> $doNew ); $doNew = $client->getPersistedValue( name=> 'doNew' ) unless defined $doNew; $doNew = 0 unless defined $doNew; my $doEditProfile = $cgi->param( 'doEditProfile' ); defined ( $doEditProfile ) and $client->setPersistedValue( name=> 'doEditProfile', value=> $doEditProfile ); $doEditProfile = $client->getPersistedValue( name=> 'doEditProfile' ) unless defined $doEditProfile; $doEditProfile = 0 unless defined $doEditProfile; if ( $doNew ) { $client->repersistValues( values=> [ 'doNew' ] ); $self->doNew(); return; } elsif ( $doEditProfile ) { $client->repersistValues( values=> [ 'doEditProfile' ] ); $self->doEditProfile(); return; } my $page = $tb->getPage(); print $page->getHeaderHtml( title=> "Applications" ); #print Pos::Webtop::OcxLauncher::getLauncherHtml(tb => $tb); my $mainBox = $tb->createBox( title=> "Applications", width=> "650" ); print "
\n"; print $mainBox->getHeaderHtml(); my $appsAvailable = $self->getApplicationsAvailable(); my $appsTunnelable = $self->getApplicationsTunnelable(); my $withTunnels = $self->getApplicationsWithTunnels( applicationsAvailable=> $appsTunnelable ); my $withoutApps = $self->getTunnelsWithoutApplications(); my @wt = sort { return ( uc( $a->{'profileName'} ) gt uc( $b->{'profileName'} ) ) } @{ $withTunnels }; my @wa = sort { return ( uc( $a->{'profileName'} ) gt uc( $b->{'profileName'} ) ) } @{ $withoutApps }; my @aa = (); foreach my $appId ( keys %{ $appsAvailable } ) { my $appName = $appsAvailable->{$appId}->{'appName'}; my $verInfo = $appsAvailable->{$appId}->{'verInfo'}; my $displayName = $appName . ( defined( $verInfo ) ? " ($verInfo)" : "" ); push @aa, { appId=> $appId, appName=> $appName, verInfo=> $verInfo, webtopIcon=> $appsAvailable->{$appId}->{'webtopIcon'}, displayName=> $displayName }; } @aa = sort { return ( uc( $a->{'displayName'} ) gt uc( $b->{'displayName'} ) ) } @aa; my @l1Top = (); my @l1Bottom = (); my $canCreateAppTunnels = $self->canCreateAppTunnels(); foreach my $p ( @wt ) { if ( ( $p->{'type'} eq 'USER' ) and ( not $canCreateAppTunnels ) ) { # skip user created if user can't create em! next; } my $flags = $self->getFlagsForProfile(profile => $p); $flags =~ s/\\/\\\\/g; my $entry = { text=> $p->{'profileName'}, href=> "javascript:installExecuteApplication('" . $p->{'type'} . "'," . $p->{'profileId'} . ", " . $p->{'appId'} . ", '$flags');", icon=> "LocalWebLib/ApplicationIcons/" . $p->{'webtopIcon'} }; if ($p->{'type'} ne 'USER') { push @l1Top, $entry } else { push @l1Bottom, $entry } } my @l2 = (); foreach my $a ( @aa ) { push @l2, { text=> $a->{'displayName'}, href=> "javascript:installApplication(" . $a->{'appId'} . ");", icon=> "LocalWebLib/ApplicationIcons/" . $a->{'webtopIcon'} }; } my $leftTopSide .= $self->getIconView( items=> \@l1Top, columns=> 3 ); my $leftBottomSide .= $self->getIconView( items=> \@l1Bottom, columns=> 3 ); my $rightSide .= $self->getIconView( items=> \@l2, columns=> 3 ); my @links = (); if ( $canCreateAppTunnels ) { push @links, $client->getFormGetCode( text=> "Create New", values=> [ { name=> 'doNew', value=> 1 } ] ); push @links, $client->getFormGetCode( text=> "Manage My Profiles", values=> [ { name=> 'doEditProfile', value=> 1 } ] ); } my $createTunnelLinks = "[ " . join(' | ', @links ) . " ]\n"; print "Overview:
Listed below are two groups of applications for your use. The items on the left are application tunnel profiles. When launched, the application profiles will allow you to access the network by creating a tunnel from your web browser to your corporate network for the given application. The items on the right are applications which are available for download and install on your computer but do not bring up a tunnel for use.

"; if ( $canCreateAppTunnels and scalar(@wa) > 0) { print " "; } $self->canUseAppLauncher() and print " "; print "
Application Tunnel Profiles Application Downloads
" . ((scalar(@l1Top) > 0)?" " : "") . " " . ((scalar(@l1Bottom) > 0)?" " : "") . " " . (($canCreateAppTunnels)?" " : "") . "
Default
$leftTopSide
User Defined
$leftBottomSide
$createTunnelLinks
$rightSide
Additional Tunnels


Application Launcher
Enter the command line for the program you would like to execute:



  


"; print $mainBox->getFooterHtml(); print "
\n"; print $page->getFooterHtml(); return 1; } # (pure virtual defined in Pos::Webtop::Web::ContentModule) sub getPreviewHtml { my $self = shift; my $ret = undef; my $toolBox = $self->getToolBox(); my $client = $toolBox->getClient(); my $cgi = $toolBox->getCgi(); $ret = $self->getPreviewHeader(); my $total = 0; $ret .= "
" . $self->getPreviewListHtml( retTotal=> \$total ) . "
"; $ret .= $client->getFormGetCode( text=> "More...", values => [ { name=> 'module', value=> 'Applications' } ] ); $ret .= "
"; $ret .= $self->getPreviewFooter(); return $ret; } sub getFlagsForProfile { my $self = shift; my ($p) = @{{@_}}{qw/profile/}; my $flags = ""; # If the profile is using dynamic support, set the UseDynamic flag if ($p->{'dynamic'}) { $flags .= "UseDynamic "; } # If there are arguments, use them if (length($p->{'arguments'})) { $flags .= "BeginArguments " . $p->{'arguments'} . " EndArguments "; } $flags =~ s/\"/"/g; return $flags; } 1;