Skip to content

Commit d4d6b1d

Browse files
authored
EGI patches (#1)
Various EGI-related patches or fixes that didn't reach upstream's master: * Add lock images to show login status * Fix syntax See also ericvaandering#116 * Display a permalink * Import legacy fix for a division by zero * Import fix for issue with radio buttons on admin page See also ericvaandering#13 * Add legacy EGI customisation relating to X.509 usage * Import legacy EGI customisation
1 parent 5dc54b2 commit d4d6b1d

9 files changed

Lines changed: 275 additions & 14 deletions

File tree

DocDB/cgi/AdministerElements.pm

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,15 @@ sub AdministerActions (%) {
2929
my $Form = $Params{-form} || "";
3030
my $AddTransfer = $Params{-addTransfer} || $FALSE;
3131

32-
my %Action = ();
32+
# XXX: EGI applied https://github.com/ericvaandering/DocDB/pull/13
33+
my @Action = ('New', 'Delete', 'Modify');
3334

34-
$Action{Delete} = "Delete";
35-
$Action{New} = "New";
36-
$Action{Modify} = "Modify";
3735
if ($AddTransfer) {
38-
$Action{Transfer} = "Transfer";
36+
unshift(@Action, "Transfer");
3937
}
4038
print FormElementTitle(-helplink => "admaction", -helptext => "Action");
4139
print $query -> radio_group(-name => "admaction",
42-
-values => \%Action, -default => "-",
40+
-values => \@Action, -default => "-",
4341
-onclick => "disabler_$Form();");
4442
};
4543

DocDB/cgi/CertificateUtilities.pm

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ sub FetchEmailUserIDByCert (%) {
4646
my $CertEmail = $ENV{SSL_CLIENT_S_DN_Email};
4747
my $CertCN = $ENV{SSL_CLIENT_S_DN_CN};
4848
my $CertDN = $ENV{SSL_CLIENT_S_DN};
49+
50+
# XXX: EGI -> We don't want to search with DN but an UID.
51+
# print $ENV{AUTHENTICATE_UID};
4952

5053
# If we do http basic with users, this routine will function with minor modifications
5154

@@ -56,15 +59,17 @@ sub FetchEmailUserIDByCert (%) {
5659
return;
5760
}
5861

59-
push @DebugStack, "Finding EmailUserID and groups by DN $CertDN";
62+
push @DebugStack, "Finding EmailUserID and groups by UID $ENV{AUTHENTICATE_UID} or DN $CertDN";
6063
if ($IgnoreVerification) {
6164
$EmailUserSelect = $dbh->prepare("select EmailUserID from EmailUser ".
6265
"where Username=?");
6366
} else {
6467
$EmailUserSelect = $dbh->prepare("select EmailUserID from EmailUser ".
6568
"where Verified=1 and Username=?");
6669
}
67-
$EmailUserSelect -> execute($CertDN);
70+
71+
# XXX: EGI -> added ternary operator, was only CERTDN
72+
$EmailUserSelect -> execute($ENV{AUTHENTICATE_UID} ? $ENV{AUTHENTICATE_UID} : $CertDN);
6873

6974
my ($EmailUserID) = $EmailUserSelect -> fetchrow_array;
7075
push @DebugStack,"Found e-mail user: $EmailUserID";
@@ -99,10 +104,12 @@ sub CertificateStatus () {
99104
}
100105

101106
my $EmailUserSelect;
102-
push @DebugStack, "Finding status by DN $CertDN";
107+
push @DebugStack, "Finding status by UID $ENV{AUTHENTICATE_UID} or DN $CertDN";
103108
$EmailUserSelect = $dbh->prepare("select EmailUserID,Verified from EmailUser ".
104109
"where Username=?");
105-
$EmailUserSelect -> execute($CertDN);
110+
111+
# XXX: EGI -> added ternary operator, was only CERTDN
112+
$EmailUserSelect -> execute($ENV{AUTHENTICATE_UID} ? $ENV{AUTHENTICATE_UID} : $CertDN);
106113

107114
my ($EmailUserID,$Verified) = $EmailUserSelect -> fetchrow_array;
108115

DocDB/cgi/DocumentHTML.pm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,12 @@ sub DocumentLink (%) {
425425

426426
sub PrintDocNumber { # And type
427427
my ($DocRevID) = @_;
428+
# XXX: EGI Add permalink
429+
print "<dt>Permalink:</dt>";
430+
print "<dd style=\"word-wrap: break-word;\">";
431+
print "<a style=\"font-size: xx-small;\" href=\"${web_root}document/",$DocRevisions{$DocRevID}{DOCID},"\">","${web_root}document/",$DocRevisions{$DocRevID}{DOCID},"</a>";
432+
print "</dd>\n";
433+
428434
print "<dt>Document #:</dt>";
429435
print "<dd>";
430436
print (&FullDocumentID($DocRevisions{$DocRevID}{DOCID}));

DocDB/cgi/Images.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@
2424

2525
%ImageNames = ();
2626

27-
%ImageNames = ("EventIcon" => "datum_darker.gif");
27+
%ImageNames = ("EventIcon" => "datum_darker.gif", "Lock" => "lock-red.png", "Unlock" => "unlock-green.png" );
2828

2929
1;

DocDB/cgi/ProjectRoutines.pm

Lines changed: 249 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,249 @@
1+
#
2+
# Description: These are routines that are specific to your installation and
3+
# should be customized for your needs. This file is a template
4+
# only. Make a copy of this file as ProjectRoutines.pm (no
5+
# "template") and make your changes there. Basically you can use ProjectHeader,
6+
# ProjectBodyStart, ProjectFooter, and DocDBFooter to make DocDB web pages
7+
# just like the web pages for the rest of your project. If you don't want to do
8+
# any customization or just want to test DocDB, these routines work as-is.
9+
# A global variable $Public is used (when set) to remove elements from the
10+
# nav-bars that the public has no interest in. The variable is global
11+
# and can control the style of your headers and footers too.
12+
#
13+
# Author: Eric Vaandering (ewv@fnal.gov)
14+
# Modified:
15+
16+
# Copyright 2001-2013 Eric Vaandering, Lynn Garren, Adam Bryant
17+
18+
# This file is part of DocDB.
19+
20+
# DocDB is free software; you can redistribute it and/or modify
21+
# it under the terms of version 2 of the GNU General Public License
22+
# as published by the Free Software Foundation.
23+
24+
# DocDB is distributed in the hope that it will be useful,
25+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
26+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27+
# GNU General Public License for more details.
28+
29+
# You should have received a copy of the GNU General Public License
30+
# along with DocDB; if not, write to the Free Software
31+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
32+
33+
sub ProjectHeader {
34+
my ($Title,$PageTitle) = @_;
35+
36+
# This routine is reponsible for whatever HTML you want to write in the <HEAD>
37+
# section of the page. You can embed style sheets, etc.
38+
#
39+
# $Title is what is in the <title> element while $PageTitle is the title of
40+
# the page you may put in the text of the page. They are provided here for
41+
# your convenience, but you should not print the <title> here since DocDB
42+
# already takes care of that.
43+
44+
# Here is a link to a style sheet.
45+
46+
# print "<link rel=\"stylesheet\" href=\"/includes/style.css\" type=\"text/css\">\n";
47+
print '<link rel="stylesheet" type="text/css" href="https://documents.egi.eu/export/system/modules/eu.egi.www/resources/d2/css/screen.css" media="screen" />';
48+
}
49+
50+
sub ProjectBodyStart {
51+
52+
# This routine is called after the <body> tag is written. Here you can put your
53+
# project specific HTML. You might want to put the document title too, as a
54+
# header. ($Title is what is in the <title> element while $PageTitle is the
55+
# title of the page you may put in the text of the page.)
56+
57+
print '
58+
<div id="container">
59+
<div id="head">
60+
61+
<div id="site-title">
62+
<a class="over-image" href="/">EGI<span></span></a>
63+
</div>
64+
65+
<div class="phrase over-image">
66+
</div>
67+
</div>
68+
';
69+
70+
print '
71+
<div class="right-content">
72+
<div id="page-header">
73+
';
74+
75+
76+
my ($Title,$PageTitle) = @_;
77+
my @TitleParts = split /\s+/, $PageTitle;
78+
$PageTitle = join '&nbsp;',@TitleParts;
79+
80+
require "Images.pm";
81+
82+
my ($path,$query) = @ENV{qw/SCRIPT_NAME QUERY_STRING/};
83+
$path =~ s/^$cgi_path//;
84+
$path =~ s/^\/+//;
85+
if ($Public) {
86+
$txt = qq{<b>Public area</b><br/><a href="$secure_root$path?$query">Login</a>};
87+
$icon = 'Unlock';
88+
$id = '';
89+
}
90+
else {
91+
if (stat("/opt/DocDB/public/$path")) {
92+
$txt = qq{<b>Restricted area</b> <br/><a href="$public_root$path?$query">Logout</a>};
93+
} else {
94+
$txt = qq{<b>Restricted area</b> <br/><a href="$public_root">Logout</a>};
95+
}
96+
$icon = 'Lock';
97+
$id = "Logged in as $ENV{SSL_CLIENT_S_DN_CN}";
98+
}
99+
100+
#<table style="text-align: left; width: 200px; margin-left: auto; margin-right: 0px;">
101+
print qq{
102+
<table style="width: 200px; float: right;">
103+
<tr>
104+
<td>$txt</td>
105+
<td>
106+
<img src="$ImgURLPath/$ImageNames{$icon}"/>
107+
</td>
108+
</tr>
109+
<tr>
110+
<td colspan="2">$id</td>
111+
</tr>
112+
</table>
113+
};
114+
115+
print '
116+
<h1>Document Server</h1>
117+
<div class="navigation">
118+
<a href="http://www.egi.eu/">Home</a> &gt; <a href="http://www.egi.eu/about/">About EGI.eu</a> &gt; <a href="http://www.egi.eu/about/intranet/">Intranet</a> &gt; <strong>DocDB</strong>
119+
</div><!-- end navigation -->
120+
</div><!-- end page-header -->
121+
<div class="page-content ">
122+
';
123+
124+
125+
126+
print "<h1>$PageTitle</h1>\n";
127+
# show the navbar at the top of the page as well as at the bottom
128+
if ($dbh) {
129+
&DocDBNavBar();
130+
}
131+
}
132+
133+
sub ProjectFooter {
134+
require "DocDBVersion.pm";
135+
136+
my ($WebMasterEmail,$WebMasterName) = @_;
137+
138+
# This routine is reponsible for whatever you want to put as a footer on the
139+
# page.
140+
#
141+
# Parameters are supplied for the name and e-mail address of the person
142+
# responsible for the pages. We would appreciate it if you keep the link to
143+
# the DocDB home page present.
144+
145+
# You probably want to include some version of this:
146+
147+
print "<p><small>\n";
148+
print "<a href=\"$DocDBHome\">DocDB</a>, ";
149+
# print "Version $DocDBVersion, contact \n";
150+
print "Contact: \n";
151+
print "<i>\n";
152+
print "<a href=\"mailto:$WebMasterEmail\">$WebMasterName</a>\n";
153+
print "</i>\n";
154+
print "</small><br/>\n";
155+
156+
# This prints benchmark info for pages that have it
157+
158+
if ($EndTime && $StartTime) {
159+
my $TimeDiff = timediff($EndTime,$StartTime);
160+
print "<small><b>Execution time: </b>",timestr($TimeDiff),"</small>\n";
161+
}
162+
print "</p>\n";
163+
164+
# Do not print the </body> and </html> tags, DocDB does that now.
165+
166+
use Time::Piece;
167+
my $t = Time::Piece->new();
168+
169+
print '
170+
</div>
171+
</div>
172+
<div class="clear"></div>
173+
</div>
174+
<div id="footer">
175+
<div class="float-left">
176+
&copy; '.$t->year.' <strong>EGI Foundation</strong><br />
177+
Website hosted by CESNET, Brno on behalf of EGI.eu, <a href="mailto:contact@egi.eu">contact@egi.eu</a>
178+
179+
</div>
180+
<div class="float-right align-right">
181+
<a href="http://www.egi.eu/">Disclaimers</a> &nbsp;|&nbsp;
182+
<a href="http://www.egi.eu/site-map/">Site map</a> &nbsp;|&nbsp;
183+
<a href="http://www.egi.eu/about/contact/">Contact</a> &nbsp;|&nbsp;
184+
185+
<a href="http://www.egi.eu/about/">About</a><br />
186+
<div class="clear"></div>
187+
</div>
188+
';
189+
}
190+
191+
sub DocDBNavBar {
192+
193+
# This routine prints the navigation bar just above the footer on the
194+
# page.
195+
# This provides a good default, but you can customize for your installation
196+
# and include an optional extra description and URL (e.g. for a related page).
197+
198+
199+
my ($ExtraDesc,$ExtraURL) = @_;
200+
201+
require "Security.pm";
202+
203+
print "<div class=\"DocDBNavBar\">\n";
204+
if ($ExtraDesc && $ExtraURL) {
205+
print "[&nbsp;<a href=\"$ExtraURL\">$ExtraDesc</a>&nbsp;]&nbsp;\n";
206+
}
207+
print "[&nbsp;<a href=\"$MainPage\">DocDB&nbsp;Home</a>&nbsp;]&nbsp;\n";
208+
if (&CanAdminister()) {
209+
print "[&nbsp;<a href=\"$AdministerHome\">Administer</a>&nbsp;]&nbsp;\n";
210+
}
211+
if (&CanCreate()) {
212+
print "[&nbsp;<a href=\"$DocumentAddForm?mode=add\">New</a>&nbsp;]&nbsp;\n";
213+
}
214+
print "[&nbsp;<a href=\"$SearchForm\">Search</a>&nbsp;]\n";
215+
print "[&nbsp;<a href=\"$ListBy?days=$LastDays\">Last&nbsp;$LastDays&nbsp;Days</a>&nbsp;]\n";
216+
print "[&nbsp;<a href=\"$ListAuthors\">List&nbsp;Authors</a>&nbsp;]\n";
217+
print "[&nbsp;<a href=\"$ListTopics\">List&nbsp;Topics</a>&nbsp;]\n";
218+
print "[&nbsp;<a href=\"$ListAllMeetings\">List&nbsp;Events</a>&nbsp;]\n";
219+
unless ($Public) {
220+
print "[&nbsp;<a href=\"$DocDBInstructions\">Help</a>&nbsp;]\n";
221+
}
222+
print "</div>\n";
223+
}
224+
225+
sub ProjectReferenceLink (;$$$$) {
226+
my ($Acronym,$Volume,$Page,$ReferenceID) = @_;
227+
228+
# This routine is used to add links to and optionally replace the text of
229+
# references specific to the project.
230+
# See ReferenceLink in ReferenceLinks.pm for examples.
231+
232+
my $ReferenceLink = "";
233+
my $ReferenceText = "";
234+
235+
return ($ReferenceLink,$ReferenceText);
236+
}
237+
238+
# Often times groups may have CSS or other files that are used in Server
239+
# Side Includes. This function replicates that functionality
240+
241+
#sub SSInclude {
242+
# my ($file) = @_;
243+
# open SSI,"$SSIDirectory$file";
244+
# my @SSI_lines = <SSI>;
245+
# close SSI;
246+
# print @SSI_lines;
247+
#}
248+
249+
1;

DocDB/cgi/SearchAtoms.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ sub RegExpSearchAtom {
113113
}
114114

115115
if ($RequireWord) {
116-
if $MySQLVersion < 8 {
116+
if ($MySQLVersion < 8) {
117117
$RegExpAtom .= '[[:<:]]';
118118
} else {
119119
$RegExpAtom .= '\\b';
@@ -123,7 +123,7 @@ sub RegExpSearchAtom {
123123
$RegExpAtom .= join '|', @RegExpParts;
124124
$RegExpAtom .= ')';
125125
if ($RequireWord) {
126-
if $MySQLVersion < 8 {
126+
if ($MySQLVersion < 8) {
127127
$RegExpAtom .= '[[:>:]]';
128128
} else {
129129
$RegExpAtom .= '\\b';

DocDB/cgi/Statistics

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ my $NRevEvent_query = $dbh -> prepare("select COUNT(ConferenceID) from RevisionE
147147
my ($NRevisionEvents) = $NRevEvent_query -> fetchrow_array;
148148

149149
my $EventsPerRev = sprintf "%5.2f",$NRevisionEvents/$NRevisions;
150-
my $DocPerEvent = sprintf "%5.2f",$NDocuments/$NEvents*$EventsPerRev;
150+
# XXX: EGI -> Division by zero
151+
my $DocPerEvent = ($NEvents*$EventsPerRev > 0) ? sprintf "%5.2f",$NDocuments/$NEvents*$EventsPerRev : "n/a";
151152

152153

153154
print "<tbody>\n";

DocDB/html/img/lock-red.png

1.07 KB
Loading

DocDB/html/img/unlock-green.png

1.14 KB
Loading

0 commit comments

Comments
 (0)