@@ -7,16 +7,11 @@ package WRE::WebguiDemo;
7
7
# (docs/license.txt) that came with this distribution before using
8
8
# this software.
9
9
# -------------------------------------------------------------------
10
- # http://www.plainblack.com info@plainblack.com
10
+ # http://www.plainblack.com info@plainblack.com
11
11
# -------------------------------------------------------------------
12
12
13
13
use lib (' /data/wre/lib' ,' /data/WebGUI/lib' );
14
14
use strict;
15
- use Apache2::Const;
16
- use Apache2::RequestRec;
17
- use Apache2::RequestUtil;
18
- use Apache2::RequestIO;
19
- use DBI;
20
15
use JSON;
21
16
use String::Random qw( random_string) ;
22
17
use WebGUI;
@@ -25,62 +20,68 @@ use WRE::Config;
25
20
use WRE::File;
26
21
use WRE::Mysql;
27
22
23
+ extends ' Plack::Component' ;
24
+ use Plack::Util::Accessor qw/ wre_config/ ;
25
+
28
26
# -------------------------------------------------------------------
29
- sub handler {
30
- my $r = shift ;
27
+ sub call {
28
+ my $env = shift ;
31
29
my $config = WRE::Config-> new;
32
- $r -> pnotes(' wreConfig' => $config );
33
- my $id = $r -> uri;
34
- $id =~ s / ^\/ (demo[0-9\_ ]+).*$/ $1 / ;
35
- if (-e $config -> getWebguiRoot(" /etc/" .$id ." .conf" )) {
36
- return WebGUI::handler($r ,$id ." .conf" );
37
- }
38
- elsif ($r -> uri =~ / ^\/ extras/ ) {
39
- # just pass it on thru
40
- }
41
- elsif ($r -> uri eq " /create" ) {
42
- $r -> set_handlers(PerlResponseHandler => \&createDemo);
43
- $r -> set_handlers(PerlTransHandler => sub { return Apache2::Const::OK });
44
- }
30
+ $self -> wre_config($config );
31
+ my $r = Plack::Request-> new($env );
32
+ my ($id ) = $r -> uri-> host =~ m / ^\/ (demo[0-9\_ ]+).*$ / ;
33
+ my $webgui_config = $config -> getWebguiRoot(" /etc/" .$id ." .conf" );
34
+ $self -> response($response );
35
+ if (-e $webgui_config ) {
36
+ # # Code to use the WebGUI App with a particular config file.
37
+ local $ENV {WEBGUI_CONFIG } = $webgui_config ;
38
+ my $psgi = WebGUI::Paths-> defaultPSGI;
39
+ my $app = Plack::Util::load_psgi($psgi );
40
+ $app -> call($env );
41
+ }
42
+ # Extras can be served from nginx
43
+ elsif ($r -> uri-> path eq " create" ) {
44
+ $response = $self -> create_demo();
45
+ }
45
46
else {
46
- $r -> set_handlers(PerlResponseHandler => \&promptDemo);
47
- $r -> set_handlers(PerlTransHandler => sub { return Apache2::Const::OK });
48
- }
49
- return Apache2::Const::DECLINED;
47
+ $response = $self -> prompt_demo();
48
+ }
50
49
}
51
50
52
51
53
52
# -------------------------------------------------------------------
54
- sub promptDemo {
55
- my $r = shift ;
56
- my $config = $r -> pnotes(' wreConfig' );
57
- $r -> content_type(" text/html" );
58
- $r -> print (q| <html><head><title>WebGUI Demo</title></head><body>
53
+ sub prompt_demo {
54
+ my $self = shift ;
55
+ my $response = Plack::Response-> new();
56
+ $response -> content_type(" text/html" );
57
+ $response -> status(200);
58
+ $response -> body(q| <html><head><title>WebGUI Demo</title></head><body>
59
59
<div style="width: 300px; margin-top: 20%; text-align: left; margin-left: 35%; margin-bottom: 10px;
60
60
background-color: #cccccc; border: 1px solid #800000; padding: 10px; color: #000080;">If you'd like your own
61
- personal demo of the <a style="color: #ff2200;" href="http://www.webgui.org/">WebGUI Content Engine®</a>
62
- click the button below. Your demo will last for | .$config -> get(" demo" )-> {duration }.q| day(s), then will be deleted.</div>
61
+ personal demo of the <a style="color: #ff2200;" href="http://www.webgui.org/">WebGUI Content Engine®</a>
62
+ click the button below. Your demo will last for | .$self -> wre_config -> get(" demo" )-> {duration }.q| day(s), then will be deleted.</div>
63
63
<div style="text-align: center; width: 300px; margin-left: 35%;"><form action="/create" method="post">
64
- <input onclick="this.value='Please wait while we create your demo!'" type="submit"
64
+ <input onclick="this.value='Please wait while we create your demo!'" type="submit"
65
65
value="Create My Personal WebGUI Demo" /> </form></div> </body></html>| );
66
- return Apache2::Const::OK ;
66
+ return $response ;
67
67
}
68
68
69
69
# -------------------------------------------------------------------
70
- sub createDemo {
71
- my $r = shift ;
72
- my $config = $r -> pnotes(' wreConfig' );
73
- my $now = time ();
70
+ sub create_demo {
71
+ my $self = shift ;
72
+ my $response = $self -> response();
73
+ my $config = $self -> wre_config;
74
+ my $now = time ();
74
75
my $demo = $config -> get(" demo" );
75
- srand ;
76
- my $demoId = " demo" .$now ." _" .int (rand (999));
76
+ srand ;
77
+ my $demoId = " demo" .$now ." _" .int (rand (999));
77
78
my $template = Template-> new;
78
79
my $params = {};
79
80
my $file = WRE::File-> new(wreConfig => $config );
80
81
81
82
# manufacture stuff
82
83
$params -> {databaseName } = $demoId ;
83
- $params -> {databaseUser } = random_string(" ccccccccccccccc" );
84
+ $params -> {databaseUser } = random_string(" ccccccccccccccc" );
84
85
$params -> {databasePassword } = random_string(" cCncCnCCncCncCnnnCcccnnCnc" );
85
86
$params -> {databaseHost } = $config -> get(" mysql" )-> {hostname };
86
87
$params -> {databasePort } = $config -> get(" mysql" )-> {port };
@@ -116,18 +117,15 @@ sub createDemo {
116
117
);
117
118
118
119
# create webroot
119
- $file -> makePath($config -> getDomainRoot(' /demo/' .$demoId .' /uploads/' ));
120
+ $file -> makePath($config -> getDomainRoot(' /demo/' .$demoId .' /uploads/' ));
120
121
$file -> copy($demo -> {creation }{uploads }.' /' ,
121
122
$config -> getDomainRoot(' /demo/' .$demoId .' /uploads/' ),
122
- { force => 1, recursive => 1});
123
+ { force => 1, recursive => 1});
123
124
124
125
# send redirect
125
- $r -> headers_out -> set( Location => " /" .$demoId ." /" );
126
- $r -> status(301);
127
- return Apache2::Const::OK ;
126
+ $response -> location( " /" .$demoId ." /" );
127
+ $response -> status(301);
128
+ return $response ;
128
129
}
129
130
130
-
131
-
132
-
133
131
1;
0 commit comments