#!/usr/bin/perl -I. use strict; use Pos::Webtop::Web::ContentModule; use Pos::Policy::LayeredBurrito (); use Pos::Webtop::OcxLauncher; package Pos::Webtop::Web::ContentModule::Intranet; my $global_scheme = "https"; 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; } # (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 $ret = undef; my $action = $cgi->param('action'); not defined($action) and $action = 0; $client->checkSession(); if (($action ne 'rwPopup') and ($action ne 'rwGetPage') and ($action ne 'rwTopframe')) { my $p = $toolBox->getPage(); if (!$action) { print $p->getHeaderHtml(title => "Webtop: Intranet interface: Main") . "
"; #print Pos::Webtop::OcxLauncher::getLauncherHtml(tb => $toolBox); $self->printMainPage(); } elsif ($action eq 'manageBookmarks') { $p->addNavBarElement(description => "Manage Bookmarks", values => [ { name => "action", value => "manageBookmarks" } ]); print $p->getHeaderHtml(title => "Webtop: Intranet interface: Manage Bookmarks") . "
"; #print Pos::Webtop::OcxLauncher::getLauncherHtml(tb => $toolBox); $self->printPersonalBookmarks(manage => 1); } elsif ($action eq 'createCategory') { $p->addNavBarElement(description => "Manage Bookmarks", values => [ { name => "action", value => "manageBookmarks" } ]); print $p->getHeaderHtml(title => "Webtop: Intranet interface: Manage Bookmarks") . "
"; #print Pos::Webtop::OcxLauncher::getLauncherHtml(tb => $toolBox); $self->manageCreateCategory(categoryName => $cgi->param('categoryName')); $self->printPersonalBookmarks(manage => 1); } elsif ($action eq 'createBookmark') { $p->addNavBarElement(description => "Manage Bookmarks", values => [ { name => "action", value => "manageBookmarks" } ]); print $p->getHeaderHtml(title => "Webtop: Intranet interface: Manage Bookmarks") . "
"; #print Pos::Webtop::OcxLauncher::getLauncherHtml(tb => $toolBox); $self->manageCreateBookmark(bookmarkName => $cgi->param('bookmarkName'), bookmarkUrl => $cgi->param('bookmarkUrl'), bookmarkCategory => $cgi->param('bookmarkCategory')); $self->printPersonalBookmarks(manage => 1); } elsif ($action eq 'removeThings') { $p->addNavBarElement(description => "Manage Bookmarks", values => [ { name => "action", value => "manageBookmarks" } ]); print $p->getHeaderHtml(title => "Webtop: Intranet interface: Manage Bookmarks") . "
"; #print Pos::Webtop::OcxLauncher::getLauncherHtml(tb => $toolBox); my @things = $cgi->param('multiRemoves'); $self->manageRemoveThings(things => \@things); $self->printPersonalBookmarks(manage => 1); } print "
" . $p->getFooterHtml(); } else { if ($action eq 'rwPopup') { my $displayName = $cgi->param('displayName'); $self->rwPopupHtml(url => $cgi->param('url'), displayName => $displayName); } elsif ($action eq 'rwGetPage') { $self->rwGetPageHtml(url => $cgi->param('url'), initial => $cgi->param('initial')); } elsif ($action eq 'rwTopframe') { $self->rwTopframeHtml(url => $cgi->param('url')); } } return 1; } # (pure virtual defined in Pos::Webtop::Web::ContentModule) sub getPreviewHtml { my $self = shift; my $ret = undef; my $tb = $self->getToolBox(); my $client = $tb->getClient(); my $cgi = $tb->getCgi(); my $db = $tb->getWebtopDbWriter(); my $ld = Pos::Policy::LayeredBurrito->new(db => $db); my @topFive; my $skinOemId = Pos::Webtop::Web::OEMLoader::getSkinOemId( oemId=> $tb->getOemId() ); my $isMobile = $client->isMobileWebtop(); # policyTypeId 131 = homepage my $homepage = $ld->getPolicyValues( id => $client->getUserId, cache => 0, layer => "USER_PREF", policyTypeId => 131); my $restrictionSetId = $client->getRestrictionSetId(); my @bookmarks = $db->query(sql => " select url, display_name from w_user_bookmarks a inner join w_user_bookmark_categories b on a.category_id = b.category_id where user_id = '" . $client->getUserId . "' union select bookmark_url, bookmark_display_name from user_bookmarks where user_id = '" . $client->getUserId . "' and restrict_set_id = " . ((not defined($restrictionSetId)) ? "NULL" : "'$restrictionSetId'" ) . " order by display_name asc "); my @mru = $db->query(sql => " select bookmark_rank_id, url, display_name from w_user_bookmark_ranks where user_id = '" . $client->getUserId . "' order by hits desc "); # not top five anymore cause of a huge potential customer # but i am not gonna change the variable name just yet so # topFive is actually all bookmarks foreach my $bookmarks (@bookmarks) { my ($url, $displayName) = @{ $bookmarks }; push(@topFive, { url => $url, name => $displayName }); } # foreach my $mru (@mru) { # # my ($rankId, $url, $displayName) = @{ $mru }; # my $found = 0; # # foreach my $bookmark (@bookmarks) { # # my ($bookmarkUrl, $bookmarkName) = @{ $bookmark }; # # if (($url eq $bookmarkUrl) and ($displayName eq $bookmarkName)) { # # $found = 1; # # last; # # } # # } # # if (!$found) { # # $db->do(sql => " # delete from # w_user_bookmark_ranks # where # url = '" . $db->escape(dirty => $url) . "' # AND display_name = '" . $db->escape(dirty => $displayName) . "' # AND user_id = '" . $client->getUserId . "' # "); # # } else { # # push(@topFive, { # url => $url, # name => $displayName # }); # # if (scalar(@topFive) >= 5) { # last; # } # } # # } # @topFive = reverse @topFive; if (scalar(@topFive) < 5) { foreach my $bookmark (@bookmarks) { my ($bookmarkUrl, $bookmarkName) = @{ $bookmark }; if (scalar(@topFive) >= 5) { last; } my $found = 0; foreach my $exists (@topFive) { if (($exists->{'url'} eq $bookmarkUrl) and ($exists->{'name'} eq $bookmarkName)) { $found = 1; last; } } if ($found) { next; } push(@topFive, { url => $bookmarkUrl, name => $bookmarkName }); } } $ret = $self->getPreviewHeader(); $ret .= "
" . $self->printAddressBar(nobox => 1, isMobile=> $isMobile) . "
"; if (scalar(@{ $homepage }) > 0) { my $temp = @{ $homepage }[0]; my $value = $temp->{'policyValue'}; if ( $value eq "" ) { $ret .= ""; } else { $ret .= " Your current homepage is:
   $value

"; } } else { $ret .= ""; } $ret .= "
"; } else { #$ret .= " Most used bookmarks:"; $ret .= " Bookmarks:"; foreach my $top (@topFive) { my $name = $top->{'name'}; my $url = $top->{'url'}; my ($grouping, $actual) = split /\\/, $name; if (not defined($actual)) { $actual = $name; } $name =~ s/\\/\\\\/g; $name =~ s/\'/\\\'/g; $ret .= ""; } } $ret .= "
"; if (scalar(@topFive) == 0) { $ret .= "
   $actual
 " . $client->getFormGetCode( text => 'More...', values => [ { name => 'module', value => 'Intranet' } ]) . "
"; $ret .= $self->getPreviewFooter(); return $ret; } sub printMainPage { my $self = shift; my $tb = $self->getToolBox(); my $db = $tb->getWebtopDbReader(); my $client = $tb->getClient(); my $isMobile = $client->isMobileWebtop(); print " "; $self->printAddressBar(isMobile=>$isMobile); print "
"; my $box = $tb->createBox(title => "Homepage", width => '300'); my $ld = Pos::Policy::LayeredBurrito->new(db => $db); # policyTypeId 131 = homepage my $homepage = $ld->getPolicyValues( id => $client->getUserId, cache => 0, layer => "USER_PREF", policyTypeId => 131); print $box->getHeaderHtml(); if (defined($homepage) and scalar(@{ $homepage }) > 0) { print " Your current homepage is:
"; my $temp = @{ $homepage }[0]; my $value = $temp->{'policyValue'}; print "   $value"; } else { print ""; } print $box->getFooterHtml() . "
"; $self->printCorporateBookmarks(); print "
"; $self->printPersonalBookmarks(); } sub printCorporateBookmarks { my $self = shift; my $tb = $self->getToolBox(); my $db = $tb->getWebtopDbReader(); my $client = $tb->getClient(); my $skinOemId = Pos::Webtop::Web::OEMLoader::getSkinOemId( oemId=> $tb->getOemId() ); my $userId = $client->getUserId; my $currTd = 'BOXTD2'; my $lastCategory; my $restrictionSetId = $client->getRestrictionSetId(); my @bookmarks = $db->query(sql => " select bookmark_display_name, bookmark_url from user_bookmarks where user_id = '$userId' and restrict_set_id = $restrictionSetId order by bookmark_display_name asc "); my $box1 = $tb->createBox(title => "Corporate Bookmarks", width => '300'); print $box1->getHeaderHtml(); print scalar(@bookmarks) . " corporate bookmarks

"; my @generalBookmarks; $lastCategory = undef; foreach my $bookmark (@bookmarks) { my ($bookmarkDisplayName, $bookmarkUrl) = @{ $bookmark }; my ($category, $displayName) = split /\\/, $bookmarkDisplayName; $category = "General" if (not defined($category) or length($category) == 0); if (not defined($displayName)) { $displayName = $category; push (@generalBookmarks, { name => $displayName, url => $bookmarkUrl }); next; } if ($category ne $lastCategory) { if (defined($lastCategory)) { print "
"; } print " $category
"; } my $cleanName = $bookmarkDisplayName; $cleanName =~ s/\\/\\\\/g; $cleanName =~ s/\'/\\\'/g; print " "; $lastCategory = $category; if ($currTd eq 'BOXTD2') { $currTd = 'BOXTD3'; } else { $currTd = 'BOXTD2'; } } # This part prints bookmarks that weren't in a category if (scalar(@generalBookmarks) > 0) { if (defined($lastCategory)) { print "
\ \   $displayName
"; } $lastCategory = 'No Grouping'; print" No Grouping
"; foreach my $general (@generalBookmarks) { my $cleanName = $general->{'name'}; $cleanName =~ s/\\/\\\\/g; $cleanName =~ s/\'/\\\'/g; print " "; } } if (defined($lastCategory)) { print "
\ \   {'url'} . "\', \'$cleanName\');\">" . $general->{'name'} . "
" } print " "; print $box1->getFooterHtml(); } sub printPersonalBookmarks { my $self = shift; my $tb = $self->getToolBox(); my $db = $tb->getWebtopDbReader(); my $client = $tb->getClient(); my ($manage) = @{{@_}}{qw/manage/}; my $isMobile = $client->isMobileWebtop(); my $sessionId = $client->getSessionId; my $sessionHash = $client->getSessionHash; if (not defined($manage)) { $manage = 0; } my $userId = $client->getUserId; my $lastCategory = undef; if ($manage) { print " "; $self->printPersonalBookmarkAdditionBoxes(); } my $box1 = $tb->createBox(title => (($manage && !$isMobile)?"Remove Bookmarks":"Personal Bookmarks"), width => '300'); my @bookmarks = $db->query(sql => " select wubc.category_name, wub.display_name, wub.url from w_user_bookmarks wub, w_user_bookmark_categories wubc where wub.category_id = wubc.category_id AND wubc.user_id = " . $client->getUserId() . " order by wubc.category_name, wub.display_name asc"); print $box1->getHeaderHtml(); if ($manage == 1) { !$isMobile and print "
You have chosen to manage your bookmarks.
You can remove categories and bookmarks by clicking on them.

"; } else { print "
" . $client->getFormGetCode( text => "Manage Bookmarks", values => [ { name => "action", value => "manageBookmarks" } ]) . "
"; print scalar(@bookmarks) . " personal bookmarks

"; } if (scalar(@bookmarks) > 0) { print " "; } foreach my $bookmark (@bookmarks) { my ($category, $displayName, $bookmarkUrl) = @{ $bookmark }; if ($category ne $lastCategory) { if (defined($lastCategory)) { print "
"; } print " " . ($manage && !$isMobile?" \  ":"") . " $category
"; } my $cleanName = $displayName; $cleanName =~ s/\\/\\\\/g; $cleanName =~ s/\'/\\\'/g; print " " . ($manage && !$isMobile ?" ":"") . " "; $lastCategory = $category; } if (defined($lastCategory)) { if (scalar(@bookmarks) > 0) { print "
\ \  $displayName
"; } } if ($manage && !$isMobile) { print "
" . $client->getFormInputs( values => [ { name => 'action', value => 'removeThings' } ]) . "
"; } else { print "
"; } print $box1->getFooterHtml(); } sub printPersonalBookmarkAdditionBoxes { my $self = shift; my $tb = $self->getToolBox(); my $db = $tb->getWebtopDbReader(); my $client = $tb->getClient(); my $isMobile = $client->isMobileWebtop(); print " "; # # Category addition stuff # my $categoryBox = $tb->createBox(title => 'Add Category', width => 300); print $categoryBox->getHeaderHtml(); print "
" . $client->getFormInputs( values => [ { name => 'action', value => 'createCategory' } ]) . "
Category
"; print $categoryBox->getFooterHtml(); print "
"; # # bookmark addition stuff # my $bookmarkBox = $tb->createBox(title => 'Add Bookmark', width => 300); print $bookmarkBox->getHeaderHtml(); print "
" . $client->getFormInputs( values => [ { name => 'action', value => 'createBookmark' } ]) . "
Name
URL
Category
"; print $bookmarkBox->getFooterHtml(); print "
"; } sub printAddressBar { my $self = shift; my $tb = $self->getToolBox(); my $db = $tb->getWebtopDbWriter(); my $client = $tb->getClient(); my ($nobox,$isMobile) = @{{@_}}{qw/nobox isMobile/}; my $box; my $buf = ""; if (not defined($nobox) or $nobox != 1) { $box = $tb->createBox(title => "Browse the Intranet", width => '300'); print $box->getHeaderHtml; } $buf .= "
" . ((defined($nobox))?" ":" ") . "
Enter a web site:
Enter a web site:
"; if (not defined($nobox) or $nobox != 1) { print $buf . $box->getFooterHtml; } return $buf; } sub manageCreateCategory { my $self = shift; my $tb = $self->getToolBox(); my $db = $tb->getWebtopDbWriter(); my $client = $tb->getClient(); my ($categoryName) = @{{@_}}{qw/categoryName/}; if (not defined ($categoryName)) { return; } my $cleanCategoryName = $db->escape(dirty => $categoryName); my ($exists) = $db->query(sql => " select category_name from w_user_bookmark_categories where category_name = '$cleanCategoryName' AND user_id = '" . $client->getUserId() . "' "); if (not defined($exists)) { $db->do(sql => " insert into w_user_bookmark_categories ( user_id, category_id, category_name ) values( " . $client->getUserId() . ", " . $db->getNextValueString( sequence => 'w_user_bookmark_categories_pk') . ", '$cleanCategoryName' )"); } print "
Successfully created category '$categoryName'.
"; } sub manageCreateBookmark { my $self = shift; my $tb = $self->getToolBox(); my $db = $tb->getWebtopDbWriter(); my $client = $tb->getClient(); my ($bookmarkName, $bookmarkUrl, $bookmarkCategory) = @{{@_}}{qw/bookmarkName bookmarkUrl bookmarkCategory/}; if (not defined($bookmarkCategory)) { print "
You did not specify a category.
"; return; } my $cleanBookmarkName = $db->escape(dirty => $bookmarkName); my $cleanBookmarkUrl = $db->escape(dirty => $bookmarkUrl); my $cleanBookmarkCatId= $db->escape(dirty => $bookmarkCategory); $db->do(sql => " insert into w_user_bookmarks ( category_id, user_bookmark_id, url, display_name ) values ( '$cleanBookmarkCatId', ( select " . ( ( Pos::defaults::isPostgresDb()) ? "case when max(user_bookmark_id) is null then 0 else max(user_bookmark_id) end + 1" : "decode(max(user_bookmark_id), null, 0, max(user_bookmark_id))+1" ) . " from w_user_bookmarks wub, w_user_bookmark_categories wubc where wubc.category_id = wub.category_id AND wubc.user_id = '" . $client->getUserId . "' ), '$cleanBookmarkUrl', '$cleanBookmarkName' )"); print "
Successfully created bookmark '$bookmarkName'.
"; } sub manageRemoveThings { my $self = shift; my $tb = $self->getToolBox(); my $db = $tb->getWebtopDbWriter(); my $client = $tb->getClient(); my ($things) = @{{@_}}{qw/things/}; my $catRemove = 0; my $bookRemove = 0; foreach my $thing (@{ $things }) { my ($type, $categoryName, $bookmarkName) = split /;/, $thing; if ($type eq 'category') { my $cleanCategoryName = $db->escape(dirty => $categoryName); my ($numBooksRemoved) = $db->query(sql => " select count(user_bookmark_id) from w_user_bookmarks a inner join w_user_bookmark_categories b on a.category_id = b.category_id where user_id = '" . $client->getUserId . "' "); $db->do(sql => " delete from w_user_bookmark_categories where category_name = '$cleanCategoryName' AND user_id = '" . $client->getUserId . "' "); $bookRemove += $numBooksRemoved; $catRemove++; } else { my $cleanBookmarkName = $db->escape(dirty => $bookmarkName); my $cleanCategoryName = $db->escape(dirty => $categoryName); $db->do(sql => " delete from w_user_bookmarks where user_bookmark_id = ( select max(wub.user_bookmark_id) from w_user_bookmarks wub, w_user_bookmark_categories wubc where wubc.category_name = '$cleanCategoryName' AND wub.display_name = '$cleanBookmarkName' AND wubc.category_id = wub.category_id AND wubc.user_id = '" . $client->getUserId . "' ) "); $bookRemove++; } } my $message = "Successfully removed"; $message .= " $bookRemove bookmark" . (($bookRemove != 1)?"s":"") if ($bookRemove > 0); $message .= " and " if ($bookRemove > 0 and $catRemove > 0); $message .= " $catRemove categor" . (($catRemove != 1)?"ies":"y") if ($catRemove > 0); print "
$message.
"; } sub rwPopupHtml { my $self = shift; my $tb = $self->getToolBox(); my $db = $tb->getWebtopDbReader(); my $client = $tb->getClient(); my ($url, $displayName) = @{{@_}}{qw/url displayName/}; my $sessionId = $client->getSessionId; my $sessionHash = $client->getSessionHash; my $oem = $tb->getOem; $self->updateBookmarkRank(displayName => $displayName, url => $url); print "Content-type: text/html\r\n\r\n " . $oem->getSetting(setting => 'webtopProductName') . " Intranet Proxy "; } sub rwTopframeHtml { my $self = shift; my $tb = $self->getToolBox(); my $db = $tb->getWebtopDbReader(); my $client = $tb->getClient(); my ($url, $notype) = @{{@_}}{qw/url notype/}; if (not defined($notype)) { print "Content-type: text/html\r\n\r\n"; } my $oem = $tb->getOem; print " " . $oem->getSetting(setting => 'webtopProductName') . " Intranet Browser
Address: " . $client->getFormInputs( values => [ { name => 'action', value => 'rwGetPage' }, { name => 'module', value => 'Intranet' } ]) . "
"; } sub rwGetPageHtml { my $self = shift; my $tb = $self->getToolBox(); my $db = $tb->getWebtopDbReader(); my $client = $tb->getClient(); my ($url, $initial) = @{{@_}}{qw/url initial/}; my $origurl = $url; my $prefix = "http"; my $url_chars = "A-Za-z0-9\-\."; my $scheme; my $host; my $port; my $req; my $out; #add a scheme if($url !~ /^https?:\/\//) { $url =~ s/(.*)/http:\/\/$1/; } #add a port if($url =~ /^(https?):\/\//) { $scheme = $1; } else { $scheme = "http"; } if($url =~ /(^https?:\/\/|)([$url_chars]+\.?[$url_chars]*)(:.*|\/.*|$)/) { $host = $2; } if($url =~ /(^https?:\/\/|)([$url_chars]+\.?[$url_chars]*):([\d]+)(\/.*|$)/) { $port = $3; } if($url =~ /(https?:\/\/|)[$url_chars]+\.[$url_chars]+(:[\d]{1-5}|)(\/[\S]+)/) { $req = $3; } else { $req = "/"; } my ($oemName) = $db->query(sql => " select rewriter_prefix 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($oemName)) { $oemName = Pos::defaults::getRewriterPrefix; } if($port) { # $out = $global_scheme . "://rewrite.stage.positivenetworks.net/$scheme:\/\/$host:$port$req"; # $out = Pos::defaults::getRewriterPrefix."$scheme:\/\/$host:$port$req"; $out = "$oemName$scheme:\/\/$host:$port$req"; } else { # $out = $global_scheme . "://rewrite.stage.positivenetworks.net/$scheme:\/\/$host$req"; # $out = Pos::defaults::getRewriterPrefix."$scheme:\/\/$host$req"; $out = "$oemName$scheme:\/\/$host$req"; } $url = $out; if (not defined($initial) or ($initial == 0)) { $self->rwTopframeHtml(url => $origurl); } else { print "Content-type: text/html\r\n\r\n"; } print " "; } sub updateBookmarkRank { my $self = shift; my $tb = $self->getToolBox(); my $db = $tb->getWebtopDbReader(); my $client = $tb->getClient(); my ($url, $displayName) = @{{@_}}{qw/url displayName/}; if (defined($displayName) and length($displayName) > 0) { # Do mark up my ($rankId) = $db->query(sql => " select bookmark_rank_id from w_user_bookmark_ranks where url = '" . $db->escape(dirty => $url) . "' AND display_name = '" . $db->escape(dirty => $displayName) . "' AND user_id = '" . $client->getUserId() . "' "); if (not defined($rankId)) { $db->do(sql => " insert into w_user_bookmark_ranks ( user_id, bookmark_rank_id, url, display_name, hits ) values( '" . $client->getUserId() . "', " . $db->getNextValueString('w_user_bookmark_ranks_pk') . ", '" . $db->escape(dirty => $url) . "', '" . $db->escape(dirty => $displayName) . "', 1 )"); } else { $db->do(sql => " update w_user_bookmark_ranks set hits = hits+1 where bookmark_rank_id = '$rankId' "); } } } 1;