Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 286 lines (227 sloc) 8.891 kb
8ffbc1fd »
2012-07-29 renamed create_database command to "setup"
1 package Galileo::Command::setup;
06c16f24 »
2012-07-14 Implemented cleaner setup interface
2 use Mojo::Base 'Mojolicious::Command';
3
1a531a11 »
2013-03-04 web setup is now the only setup
4 use Mojolicious::Command::daemon;
e6a772a6 »
2012-07-14 prompt for username and password for admin account
5
1a531a11 »
2013-03-04 web setup is now the only setup
6 use Mojolicious::Routes;
7 use Mojo::JSON 'j';
8 use Mojo::Util 'spurt';
06c16f24 »
2012-07-14 Implemented cleaner setup interface
9
cf46d760 »
2013-01-15 prepare for release 0.012
10 use Galileo::DB::Deploy;
06c16f24 »
2012-07-14 Implemented cleaner setup interface
11
1a531a11 »
2013-03-04 web setup is now the only setup
12 has description => "Configure your Galileo CMS via a web interface\n";
2bdaa5f1 »
2013-01-18 move the output
13
1a531a11 »
2013-03-04 web setup is now the only setup
14 sub run {
15 my ($self, @args) = @_;
16
17 my $app = $self->app;
18
19 my $r = Mojolicious::Routes->new;
20 $app->routes($r); # remove all routes
21
22 push @{ $app->renderer->classes }, __PACKAGE__;
23
24 $app->helper( dh => sub {
25 my $self = shift;
26 state $dh = Galileo::DB::Deploy->new( schema => $self->app->schema );
27 $dh;
28 });
29
30 $app->helper( 'control_group' => sub {
31 my $self = shift;
32 my $contents = pop;
33 my %args = @_;
34
8d7cfd57 »
2014-05-31 Improved compatibility with Mojolicious 5.00
35 $self->include( #TODO use render_to_string when Mojo 5.00 is required
1a531a11 »
2013-03-04 web setup is now the only setup
36 template => 'control_group',
37 'control_group.contents' => ref $contents ? $contents->() : $contents,
38 'control_group.label' => $args{label} || '',
39 'control_group.for' => $args{for} || '',
40 );
41 });
42
43 $r->any( '/' => 'galileo_setup' );
44 $r->any( '/configure' => 'galileo_config' );
45 $r->any( '/store_config' => sub {
46 my $self = shift;
47 my @params = sort $self->param;
48
49 # map JSON keys to Perl data
50 my %params = map { $_ => scalar $self->param($_) } @params;
87fe40f9 »
2014-04-06 migrate from secret to secrets
51 foreach my $key ( qw/extra_css extra_js extra_static_paths secrets db_options/ ) {
1a531a11 »
2013-03-04 web setup is now the only setup
52 $params{$key} = j($params{$key});
53 }
54
5e0cd782 »
2013-03-04 use dumper helper
55 spurt $self->dumper(\%params), $self->app->config_file;
1a531a11 »
2013-03-04 web setup is now the only setup
56
57 $self->app->load_config;
58 $self->humane_flash( 'Configuration saved' );
59 $self->redirect_to('/');
60 });
61
62 $r->any( '/database' => sub {
63 my $self = shift;
64
65 my $dh = $self->dh;
66 my $schema = $dh->schema;
67
68 my $available = $schema->schema_version;
69
70 # Nothing installed
71 unless ( $dh->has_admin_user ) {
72 return $self->render( 'galileo_database_install' );
73 }
74
75 # Something is installed, check for a version
76 my $installed = $dh->installed_version || $dh->setup_unversioned;
77
78 # Do nothing if version is current
79 if ( $installed == $available ) {
80 $self->flash( 'galileo.message' => 'Database schema is current' );
81 } else {
82 $self->flash( 'galileo.message' => "Upgrade database $installed -> $available" );
83 $dh->do_upgrade;
84 }
85
86 $self->redirect_to('finish');
87 });
88
89 $r->any( '/database_install' => sub {
90 my $self = shift;
91 my $pw1 = $self->param('pw1');
92 my $pw2 = $self->param('pw2');
93 unless ( $pw1 eq $pw2 ) {
94 $self->humane_flash( q{Passwords don't match!} );
95 return $self->redirect_to('database');
96 }
97
98 my $dh = $self->dh;
99 my $user = $self->param('user');
100 my $full = $self->param('full');
101
5a17541c » hrupprecht
2013-11-28 schema must be specifically deployed unless db is sqlite
102 eval { $dh->schema->deploy };
c5db1b85 »
2013-03-09 handle bad input to database installation (closes #14)
103 eval { $dh->do_install };
104 eval { $dh->inject_sample_data($user, $pw1, $full) };
105 if ($@) {
106 my $error = "$@";
107 chomp $error;
108 $self->humane_flash( $error );
109 return $self->redirect_to('database');
110 }
1a531a11 »
2013-03-04 web setup is now the only setup
111
112 $self->flash( 'galileo.message' => 'Database has been setup' );
113 $self->redirect_to('finish');
114 });
115
116 $r->any('/finish' => sub {
117 my $self = shift;
118 my $message = $self->flash( 'galileo.message' );
119
120 # check that an admin user exists
121 if ( $self->app->dh->has_admin_user ) {
122 $self->stash( 'galileo.success' => 1 );
123 $self->stash( 'galileo.message' => $message );
124 } else {
125 $self->stash( 'galileo.success' => 0 );
126 $self->stash(
127 'galileo.message' =>
128 'It does not appear that your database is setup, please rerun the setup utility'
129 );
130 }
131
132 $self->humane_stash( 'Goodbye' );
133 $self->render('galileo_finish');
dfb31907 »
2014-04-06 improve the mechanism for stopping the setup server
134 $self->tx->on( finish => sub { exit } );
1a531a11 »
2013-03-04 web setup is now the only setup
135 });
136
137 $self->Mojolicious::Command::daemon::run(@args);
cf46d760 »
2013-01-15 prepare for release 0.012
138 }
139
1a531a11 »
2013-03-04 web setup is now the only setup
140 1;
e6a772a6 »
2012-07-14 prompt for username and password for admin account
141
06c16f24 »
2012-07-14 Implemented cleaner setup interface
142
1a531a11 »
2013-03-04 web setup is now the only setup
143 __DATA__
144
145 @@ galileo_setup.html.ep
146
147 % title 'Galileo Setup - Home';
148 % layout 'basic';
149
150 <p>Welcome to Galileo! This utility helps you setup your Galileo CMS.</p>
151
152 <ul>
153 %= tag li => begin
154 %= link_to 'Configure your Galileo CMS' => 'configure'
155 <p>Configuration is not necessary, defaults can be used.
156 Configuring Galileo CMS should be done before installing the database.</p>
157 % end
158
159 %= tag li => begin
160 %= link_to 'Install or upgrade your database' => 'database'
8d7cfd57 »
2014-05-31 Improved compatibility with Mojolicious 5.00
161 <p>If this is a new installation you <b>must</b> run the database setup utility.
1a531a11 »
2013-03-04 web setup is now the only setup
162 If you have not configured Galileo (see above), you will use the defaults, including using an SQLite database for the backend.</p>
163 % end
164
165 %= tag li => begin
166 %= link_to 'Stop and exit' => 'finish'
167 <p>If your database is already installed, you may stop this utility and run <pre>$ galileo daemon</pre></p>
168 % end
169
170 </ul>
171
172 @@ galileo_config.html.ep
173
174 % use Mojo::JSON 'j';
175 % title 'Galileo Setup - Configure';
176 % layout 'basic';
177
178 %= form_for 'store_config' => method => 'POST', class => 'form-horizontal' => begin
179 % my $config = app->config;
180
181 <legend>Database Connection</legend>
182 %= control_group for => 'db_dsn', label => 'Connection String (DSN)' => begin
a09eb03e »
2013-03-04 added 'input-block-level' to all setup input fields
183 %= text_field 'db_dsn', value => $config->{db_dsn}, class => 'input-block-level'
1a531a11 »
2013-03-04 web setup is now the only setup
184 % end
185 %= control_group for => 'db_username', label => 'Username' => begin
a09eb03e »
2013-03-04 added 'input-block-level' to all setup input fields
186 %= text_field 'db_username', value => $config->{db_username}, class => 'input-block-level'
1a531a11 »
2013-03-04 web setup is now the only setup
187 % end
188 %= control_group for => 'db_password', label => 'Password' => begin
a09eb03e »
2013-03-04 added 'input-block-level' to all setup input fields
189 %= input_tag 'db_password', value => $config->{db_password}, type => 'password', class => 'input-block-level'
1a531a11 »
2013-03-04 web setup is now the only setup
190 % end
191 %= control_group for => 'db_options', label => 'Options (JSON hash)' => begin
a09eb03e »
2013-03-04 added 'input-block-level' to all setup input fields
192 %= text_field 'db_options', value => j($config->{db_options}), class => 'input-block-level'
1a531a11 »
2013-03-04 web setup is now the only setup
193 % end
194 %= control_group for => 'db_schema', label => 'Schema Class' => begin
a09eb03e »
2013-03-04 added 'input-block-level' to all setup input fields
195 %= text_field 'db_schema', value => $config->{db_schema}, class => 'input-block-level'
1a531a11 »
2013-03-04 web setup is now the only setup
196 % end
197
198 <legend>Additional Files</legend>
199
6724689f »
2013-03-10 extra_static_files and upload_path
200 %= control_group for => 'files', label => 'Extra Static Paths (JSON array)' => begin
201 %= text_field 'extra_static_paths', value => j($config->{extra_static_paths}), class => 'input-block-level'
1a531a11 »
2013-03-04 web setup is now the only setup
202 % end
203 %= control_group for => 'extra_js', label => 'Extra Javascript Files (JSON array)' => begin
a09eb03e »
2013-03-04 added 'input-block-level' to all setup input fields
204 %= text_field 'extra_js', value => j($config->{extra_js}), class => 'input-block-level'
1a531a11 »
2013-03-04 web setup is now the only setup
205 % end
206 %= control_group for => 'extra_css', label => 'Extra Stylesheet files (JSON array)' => begin
a09eb03e »
2013-03-04 added 'input-block-level' to all setup input fields
207 %= text_field 'extra_css', value => j($config->{extra_css}), class => 'input-block-level'
1a531a11 »
2013-03-04 web setup is now the only setup
208 % end
5801166f »
2013-03-12 fix some bugs related to new keys
209 %= control_group for => 'upload_path', label => 'Upload Path' => begin
210 %= text_field 'upload_path', value => $config->{upload_path}, class => 'input-block-level'
211 % end
1a531a11 »
2013-03-04 web setup is now the only setup
212
213 <legend>Other Options</legend>
214
215 %= control_group for => 'sanitize', label => 'Use Sanitizing Editor' => begin
482010fd » hrupprecht
2013-11-28 submit parameter for sanitized even it`s unchecked
216 % if($config->{sanitize}){
217 %= check_box 'sanitize', value => 1, checked => 'checked'
218 % } else {
219 %= check_box 'sanitize', value => 1
220 % }
afb54a7f » hrupprecht
2013-11-28 submit parameter for sanitized even it`s unchecked
221 %= hidden_field 'sanitize' => 0
1a531a11 »
2013-03-04 web setup is now the only setup
222 % end
87fe40f9 »
2014-04-06 migrate from secret to secrets
223 %= control_group for => 'secrets', label => 'Application Secrets (JSON array)' => begin
224 %= text_field 'secrets', value => j($config->{secrets}), class => 'input-block-level'
1a531a11 »
2013-03-04 web setup is now the only setup
225 % end
226 %= control_group for => 'submit-button', begin
227 <button class="btn" id="submit-button" type="submit">Save</button>
228 %= link_to 'Cancel' => '/' => class => 'btn'
229 % end
230 % end
231
232 @@ galileo_database_install.html.ep
233
234 % title 'Galileo Setup - Database';
235 % layout 'basic';
236
237 %= form_for 'database_install' => method => 'POST', class => 'form-horizontal' => begin
238 %= control_group for => 'full', label => 'Admin Full Name' => begin
a09eb03e »
2013-03-04 added 'input-block-level' to all setup input fields
239 %= text_field 'full', class => 'input-block-level'
1a531a11 »
2013-03-04 web setup is now the only setup
240 % end
241 %= control_group for => 'user', label => 'Admin Username' => begin
a09eb03e »
2013-03-04 added 'input-block-level' to all setup input fields
242 %= text_field 'user', class => 'input-block-level'
1a531a11 »
2013-03-04 web setup is now the only setup
243 % end
244 %= control_group for => 'pw1', label => 'Password' => begin
a09eb03e »
2013-03-04 added 'input-block-level' to all setup input fields
245 %= input_tag 'pw1', type => 'password', class => 'input-block-level'
1a531a11 »
2013-03-04 web setup is now the only setup
246 % end
5801166f »
2013-03-12 fix some bugs related to new keys
247 %= control_group for => 'pw2', label => 'Repeat Password' => begin
a09eb03e »
2013-03-04 added 'input-block-level' to all setup input fields
248 %= input_tag 'pw2', type => 'password', class => 'input-block-level'
1a531a11 »
2013-03-04 web setup is now the only setup
249 % end
250
251 %= control_group for => 'submit-button', begin
252 <button class="btn" id="submit-button" type="submit">Save</button>
253 %= link_to 'Cancel' => 'finish' => class => 'btn'
254 % end
255 % end
256
257 @@ galileo_finish.html.ep
258
259 % title 'Galileo Setup - Finished';
260 % layout 'basic';
261
262 % if ( my $message = stash 'galileo.message' ) {
263 <p><%= $message %></p>
264 % }
265
266 % if ( stash 'galileo.success' ) {
267 <p>Setup complete, run <pre>$ galileo daemon</pre></p>
268 % }
269
270 @@ control_group.html.ep
271
272 <div class="control-group">
273 % if (my $label = stash 'control_group.label') {
274 % my @for;
275 % if ( my $for = stash 'control_group.for' ) {
276 % push @for, for => $for;
277 % }
278 %= tag label => class => 'control-label', @for, begin
279 %= $label
280 % end
281 % }
282
283 <div class="controls">
284 %= stash 'control_group.contents'
285 </div>
286 </div>
Something went wrong with that request. Please try again.