Blame | Last modification | View Log | RSS feed
<%init>
#
# Main previewer interface. See admin manual for details on setting up previewer.
#
my ($previewDir,$previewServer,@versions,@sitePorts,@previewPorts);
######################################################################
#
# ADMIN CONFIGURATION
#
# Where preview files are stored. Replace <data_dir> with this server's
# data directory (should match data_dir parameter in handler.pl).
#
$previewDir = "/usr/local/mason/cms/preview";
#
# Preview ports. Each port represents a separate configuration that
# a user can store. You must listen to these ports in your httpd.conf.
#
@previewPorts = qw(3001 3002);
#
# Domain name of server where preview ports are answered. If same as this server,
# leave this line alone.
#
$previewServer = $r->server->server_hostname;
# END CONFIGURATION
#
#######################################################################
</%init>
% if ($mode eq 'home') {
<html>
<head>
<title>Mason Previewer</title>
</head>
<body bgcolor="fffff0">
<form action="<%$r->uri%>" method=post>
<input type=hidden name=mode value=save>
<table border=0 cellpadding=1 cellspacing=1>
<tr>
<td colspan=5 bgcolor="003399"> <font size="4" color="FFFFF0"><b>Mason Previewer</b></font></td>
</tr>
<!--
% if ($userName eq 'anonymous') {
<tr><td colspan=7>
<font color="#FF0000"><b>No user name! Using anonymous settings.</b></font>
</td></tr>
% }
-->
% if ($deleted) {
<tr><td colspan=7>
<font color="#FF0000"><b>Settings for port <% $previewPort %> deleted. Press Save now to restore.</b></font>
</td></tr>
% }
<tr>
<td>
<tt><font color="#FF0000">Time</font></tt><br>
<%$query->popup_menu('-name'=>'b_time','-values'=>['Real','+1 hour','+4 hours','+1 day','+2 days','+3 days','+4 days','+5 days','Other...'],'-default'=>$conf{b_time})%>
</td>
<td> </td>
<td>
<tt><font color="#FF0000">Display</font></tt><br>
<%$query->popup_menu('-name'=>'outputtype','-values'=>['HTML','Debug'],'-default'=>$conf{outputtype})%>
</td>
<td> </td>
<td>
<tt><font color="#FF0000">Port</font></tt><br>
<%$query->popup_menu('-name'=>'previewPort','-values'=>\@previewPorts,'-default'=>$previewPort)%>
</td>
</tr>
</table>
<br>
<input type=submit name=action value="Save settings">
<input type=submit name=action value="Delete settings">
<p>
<tt><font color=#ff0000>View port <% $previewPort %>:</font></tt>
<input type=submit name=action value="This window">
<input type=submit name=action value="Window A">
<input type=submit name=action value="Window B">
<br>
<tt><font color=#ff0000>Initial URI:</font></tt>
<input name=initialUri type=text value="/" size=20>
<br>
<hr>
<h2>Saved Port Settings</h2>
% if (@settings) {
<table border=1>
<tr>
<th> </th>
<th>Time</th>
<th>Display</th>
<th>Caching</th>
<th>Other</th>
</tr>
% foreach $setting (@settings) {
<%perl>
my @other = ();
if ($setting->{af_referer}) {
push(@other, sprintf('Referer="%s"',$setting->{a_referer}));
}
if ($setting->{af_useragent}) {
push(@other, sprintf('User Agent="%s/%s/%s"',$setting->{a_os},$setting->{a_browser},$setting->{a_browserVersion}));
}
</%perl>
<tr>
<td>
<a href="<%$r->uri%>?previewPort=<%$setting->{previewPort}%>">
<%$setting->{previewPort}%>
</a>
</td>
<td>
<%$setting->{timestr}%>
</td>
<td>
<%$setting->{outputtype}%>
</td>
<td>
<% $setting->{af_data_cache} ? 'Yes' : 'No' %>
</td>
<td>
% if (@other) {
<% join("; ",@other) %>
% } else {
% }
</td>
</tr>
% }
</table>
% } else {
(none)<br>
% }
<hr>
<h2>Advanced Options</h2>
%my $spacer = ' 'x10;
To activate these options, select "Other..." in the corresponding menu above.<p>
<tt><font color="#FF0000">Port</font></tt><br>
<%$spacer%>Port number: <input type=text name=a_port size=7 value=<%$conf{a_port}%>>
<p>
<tt><font color="#FF0000">Time</font></tt><br>
<%$spacer%><input type=radio name=a_timetype value=relative <%$conf{a_timetype} eq 'relative' ? 'checked' : ''%>>
Relative: <input type=text name=a_reltimenum size=3 value="<%$conf{a_reltimenum}%>"> <select name=a_reltimeunit>
<option value=h <%$conf{a_reltimeunit} eq 'h' ? 'selected' : ''%>>hour(s)
<option value=d <%$conf{a_reltimeunit} eq 'd' ? 'selected' : ''%>>day(s)
</select>
<select name=a_reltimedirection>
<option value=future <%$conf{a_reltimedirection} eq 'future' ? 'selected' : ''%>>in the future
<option value=past <%$conf{a_reltimedirection} eq 'past' ? 'selected' : ''%>>in the past
</select><br>
<%$spacer%><input type=radio name=a_timetype value=absolute <%$conf{a_timetype} eq 'absolute' ? 'checked' : ''%>>
Absolute:
<%$query->popup_menu('-name'=>'a_abstimemonth','-values'=>[0..11],'-labels'=>{0=>'Jan',1=>'Feb',2=>'Mar',3=>'Apr',4=>'May',5=>'Jun',6=>'Jul',7=>'Aug',8=>'Sep',9=>'Oct',10=>'Nov',11=>'Dec'},'-default'=>$conf{a_abstimemonth})%>
<%$query->popup_menu('-name'=>'a_abstimeday','-values'=>[1..31],'-default'=>$conf{a_abstimeday})%>
<%$query->popup_menu('-name'=>'a_abstimeyear','-values'=>[97..110],'-labels'=>{map(($_,$_+1900),(97..110))},'-default'=>$conf{a_abstimeyear})%>
at <SELECT NAME="a_abstimehour">
%for ($i=1; $i<=12; $i++) {
<option value="<%$i%>"
%if ($i == $conf{a_abstimehour}) {
selected
%}
><%$i%>:00
%}
</select> <input type="radio" name="a_abstimeampm" value="am" <%$conf{a_abstimeampm} eq 'am' ? 'checked' : ''%>>a.m. <input type="radio" name="a_abstimeampm" value="pm" <%$conf{a_abstimeampm} eq 'pm' ? 'checked' : ''%>>p.m.
<p>
To activate these options, check the boxes.<p>
<input type="checkbox" name=af_data_cache value=1 <%$conf{af_data_cache} ? 'checked' : ''%>> <tt><font color="#FF0000">Caching</font></tt>
<p>
<input type="checkbox" name=af_useragent value=1 <%$conf{af_useragent} ? 'checked' : ''%>> <tt><font color="#FF0000">User agent</font></tt><br>
<%$spacer%>OS: <%$query->popup_menu('-name'=>'a_os','-values'=>[qw(win95 win31 winnt mac unix)],'-labels'=>{win95=>'Windows 95',win31=>'Windows 3.1',winnt=>'Windows NT',mac=>'Macintosh',unix=>'Unix'},'-default'=>$conf{a_os})%>
Browser: <%$query->popup_menu('-name'=>'a_browser','-values'=>[qw(netscape msie aol robot)],'-labels'=>{netscape=>'Netscape',msie=>'Internet Explorer',aol=>'AOL',robot=>'Robot'},'-default'=>$conf{a_browser})%>
<%$query->popup_menu('-name'=>'a_browserVersion','-values'=>[qw(2.0 3.0 4.0 5.0)],'-default'=>$conf{a_browserVersion})%>
<p>
<input type="checkbox" name=af_referer value=1 <%$conf{af_referer} ? 'checked' : ''%>> <tt><font color="#FF0000">Referer</font></tt><br>
<%$spacer%>Url: <input type="text" name="a_referer" value="<%$conf{a_referer}%>" size=25>
<p>
<input type=submit name=action value="Save settings">
</form>
</body>
</html>
%}
%if ($mode eq 'save') {
%if ($action =~ /^Window ./) {
%my ($windowLetter) = ($action =~ /Window (.)/);
<script language=JavaScript>
<!--
viewWindow = window.open("<%$viewUrl%>","MasonPreviewView<%$windowLetter%>")
self.history.back()
//-->
</script>
$m->abort();
%}
<% $m->comp($thisComp,previewPort=>$previewPort,deleted=>($action eq 'Delete settings')) %>
%}
<%init>
my ($i,%conf,$href,$query,$viewUrl,$setting,@settings);
my $userName = $r->connection->user || 'anonymous';
my $thisComp = $m->current_comp;
$previewPort = $previewPorts[0] if !defined($previewPort);
if ($mode eq 'home') {
$query = new CGI('');
my $in = HTML::Mason::Preview::open_preview_settings($previewDir,$userName,0);
foreach my $p (@previewPorts) {
if (defined($in->{$p})) {
my %c = %{$in->{$p}};
%conf = %c if $previewPort eq $p;
next if $in->{$p}->{deleted};
$c{previewPort} = $p;
my $timeconf = $c{request}->{'time'};
for ($timeconf->{type}) {
$c{timestr} =
(/real/) ? 'real' :
(/relative/) ? $timeconf->{delta} :
(/absolute/) ? sprintf("%d/%d/%d %d:00 %s",$c{a_abstimemonth}+1,$c{a_abstimeday},$c{a_abstimeyear}+1900,$c{a_abstimehour},$c{a_abstimeampm}) :
'';
}
push(@settings,{%c});
}
}
untie(%$in);
if (!%conf) {
%conf =
(
b_port => $previewPorts[0],
b_time => 'Real',
outputtype => 'HTML',
a_port => '',
a_hostname => '',
a_fileroot => '',
a_timetype => 'relative',
a_reltimenum => '',
a_reltimeunit => 'h',
a_reltimedirection => 'future',
af_data_cache => 1
);
my ($sec,$min,$hour,$mday,$mon,$year) = localtime(time);
($conf{a_abstimemonth},$conf{a_abstimeday},$conf{a_abstimeyear},$conf{a_abstimehour},$conf{a_abstimeampm}) = ($mon,$mday,$year,$hour%12+1,($hour <= 11 ? 'am' : 'pm'));
}
}
if ($mode eq 'save' && $action eq 'Delete settings') {
my $out = HTML::Mason::Preview::open_preview_settings($previewDir,$userName,1);
my %options = %{$out->{$previewPort}};
$options{deleted} = 1;
$out->{$previewPort} = \%options;
untie (%$out);
} elsif ($mode eq 'save') {
my %options = %ARGS;
foreach (qw(previewPort initialUri action)) {
delete($options{$_});
}
my (%request);
# Port
my $port;
if ($options{b_port} !~ /^Other/) {
($port) = ($options{b_port} =~ /([0-9]+)/);
} elsif ($options{a_port} =~ /^([0-9]+)$/) {
$port = $options{a_port};
} else {
$port = 80;
}
$request{env}->{SERVER_PORT} = $port;
# Time
# - time->type (real, relative, or absolute)
# - time->value (if absolute)
# - time->delta (if relative)
if ($options{b_time} eq 'Real') {
$request{'time'}->{type} = 'real';
} elsif ($options{b_time} =~ /^\+/) {
$request{'time'}->{type} = 'relative';
$request{'time'}->{delta} = $options{b_time};
} elsif ($options{a_timetype} eq 'absolute') {
$request{'time'}->{type} = 'absolute';
my $hour = $options{a_abstimehour}+(12*($options{a_abstimeampm} eq 'pm'))-(12*($options{a_abstimehour}==12));
$request{'time'}->{value} = timelocal(0,0,$hour,$options{a_abstimeday},$options{a_abstimemonth},$options{a_abstimeyear});
} elsif ($options{a_timetype} eq 'relative') {
$request{'time'}->{type} = 'relative';
$request{'time'}->{delta} = sprintf("%s%d%s",($options{a_reltimedirection} eq 'future' ? '+' : '-'),$options{a_reltimenum},$options{a_reltimeunit});
} else {
die "preview save: cannot determine time value\n";
}
# Data caching
$request{interp}->{use_data_cache} = ($options{af_data_cache} ? 1 : 0);
# User agent
if ($options{af_useragent}) {
my $osStr = {win95=>'Win95',winnt=>'WinNT',mac=>'Macintosh',unix=>'SunOS 5.5 sun4c'}->{$options{a_os}};
my $v = $options{a_browserVersion};
my $browserStr = {netscape=>'',msie=>"compatible; MSIE $v; ",aol=>"compatible; MSIE $v; AOL $v; ",robot=>''}->{$options{a_browser}};
my $robotStr = ($options{a_browser} eq 'robot') ? " via Downtown/1.0" : "";
$request{headers_in}->{'User-Agent'} = sprintf("Mozilla/$v (%s%s)%s",$browserStr,$osStr,$robotStr);
}
# Referer
if ($options{af_referer}) {
$request{headers_in}->{Referer} = $options{a_referer};
}
# Output type
$request{output_type} = $options{outputtype};
#
# Dump configuration to DB file
#
$options{request} = {%request};
my $out = HTML::Mason::Preview::open_preview_settings($previewDir,$userName,1);
$out->{$previewPort} = \%options;
untie (%$out);
#
# View in this or other window
#
if ($action =~ /window/i) {
$initialUri = '' if $initialUri eq '/';
$viewUrl = "http://${previewServer}:${previewPort}${initialUri}";
if ($action eq 'This window') {
$r->send_cgi_header("Location: $viewUrl\n\n");
}
}
}
</%init>
<%args>
$previewPort=>undef
$mode=>'home'
$action=>undef
$initialUri=>undef
$deleted=>0
</%args>