-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin.cgi
More file actions
933 lines (774 loc) · 21.5 KB
/
admin.cgi
File metadata and controls
933 lines (774 loc) · 21.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
#!C:\\Strawberry\\perl\\bin\\perl5.26.1.exe
=head1 PCAccessFree
admin.cgi
created especially for Windows operating systems.
PCAccessFree brings your windows pc to your browser.
Shows all files right inn your favorite browser.
Easily open all files contained in IIS/public directoreies
Add users to windows system.
Store notes
create/maintain a personal blog
A complete content management system written in Perl/Mojolicious for Windows.
Tested in windows 11, windows 10, and partially in windows 2016
=head2 Open Source
Source code is shared on 4 different open source providers
Git Hub
where I maintain all bugs
Git Lab
Windows
Own instance of Git Lab
where I maintain notes to self but visible to public
=cut
use utf8;
use open ':encoding(utf-8)';
use strict;
use vars qw/ %ENV /;
use Mojolicious::Lite;
use Mojo::File qw(curfile);
my $dir = ''; $dir = curfile->dirname;
$dir =~ s!\/lib!!;
##use lib "".$dir."/lib";
# libraries: Windows does not allow variables
use lib ("lib", "./lib", "C:/inetpub/wwwroot/PCAccessFree/lib", "C:/inetpub/wwwroot/pc-access-free/lib", "C:/Users/sumu/public/github/PCAccessFree/lib");
##use lib qw(lib ./lib, $dir/lib);
=head2 Helpers
Mojo Lite Helpers
CGI helper packages
Database helpers
=cut
=head2 Users
10.6.5-MariaDB on my laptop.
See lib/Database for creating/importing tables in SQL.
Used for PCAF users, notes, and blog
=cut
use Users;
helper users => sub { state $users = Users->new(); };
=head2 Languages/Locales
Default is us-en
Also see POD for Languages
=head3 English/US
lang/en-us.txt
Basis for translation into all other languages.
=head3 Kannada
Translation
Doing it myself. Looking pretty good.
=head3 Tamil
=head2 Telugu
=head3 Hindi
=head3 South Korean
=head3 Spanish
=cut
=head2 use Languages
Essential Class
=cut
use Languages;
=head2 helper lang
Will not work, see #2 in git.byzland.com
But Lang::method does work, used quite extensively throughout all templates
=cut
helper lang => sub { state $lang = Lang->new(); };
=head2 Use Syst
=cut
use Syst;
helper syst => sub { state $syst = Syst->new(); };
=head2 Package Utils
Utilities used everywhere
=cut
use Utils;
helper utils => sub { state $utils = Utils->new(); };
=head2 Package Admin
Everyting needed by a logged in user
=cut
use Admin;
helper admin => sub { state $admin = Admin->new(); };
=head2 sys Hash
The hash %sys carries important name/value pairs like app dir, etc.
Future plan: move to lib
=cut
my %sys;
%sys = (
script_name => "PCAccessFree",
password_dir_name => "PCAF22",
);
# error
$sys{error} = '';
# path
$sys{zero} = $0;
$sys{zero} =~ s!\\!/!g;
my @path;
@path = split(/\//, $sys{zero}, $#path);
$sys{script_dir} = join('/', @path[0..$#path-1]);
# suggested place to store user/pass files
if ( $sys{zero} =~ /^[A-Z]:\/Users/ )
{
$sys{password_dir} = "$path[0]/$path[1]/$path[2]/$sys{password_dir_name}";
$sys{csjs_url} = "//$ENV{SERVER_NAME}:$ENV{SERVER_PORT}/";
}
elsif ( $sys{zero} =~ /^[A-Z]:\/inetpub\/wwwroot/ )
{
$sys{password_dir} = "$path[0]/$path[1]/$sys{password_dir_name}";
$sys{csjs_url} = "$ENV{SCRIPT_NAME}:$ENV{SERVER_PORT}/$path[2]";
}
else
{
$sys{password_dir} = "$sys{password_dir_name}";
$sys{csjs_url} = "/";
}
=head2 plugin NotYAMLConfig
=cut
plugin 'NotYAMLConfig' => { file => "$sys{script_dir}/pcaccessfree.yml" };
my $config = plugin 'NotYAMLConfig' => { file => "$sys{script_dir}/pcaccessfree.yml" };
=head2 fun Hash
=cut
my %fun = ();
my $left = '';
my $right = '';
if ( -e -f "$sys{script_dir}/lib/system_functions.txt" )
{
open(my $SysFun, "$sys{script_dir}/lib/system_functions.txt") or $sys{error} = qq{<div class="alert alert-warning">$!</div>};
while ( my $function = <$SysFun> )
{
chomp $function;
($left, $right) = split(/\=/, $function, 2);
$fun{"$left"} = "$right";
}
}
else
{
$sys{error} = qq{<div class="alert alert-warning">File system_functions does not exist. Creating one</div>};
open( my $sysfun, ">$sys{script_dir}/lib/system_functions.txt" ) or $sys{error} .= qq{<div class="alert alert-danger">$!</div>};
print $sysfun qq{cookie_domain=localhost\ncookie_expiry=+3M\ncss_js_url=//localhost/\nenable_browser_info=1\nenable_cookie_secure=1\nenable_date_folder=1\nenable_server_info=1\nlanguage=en-us\npassword_dir=C:/inetpub/PCAF22\nscript_web_dir=C:/inetpub/wwwroot/PCAccessFree\nserver_port=80\nuser_pref_home_dir=C:/inetpub/wwwroot/PCAccessFree\nweb_root=C:/inetpub/wwwroot\nweb_root_url=//localhost\n};
close $sysfun;
}
=head2 Form for /nologin
=cut
my $form = '';
$form .= qq{<form action="/github/PCAccessFree/nologin.cgi/change" method="post">};
for (sort keys %fun )
{
chomp;
if ( $_ =~ /^enable/ )
{
$sys{title_tip} = qq{0=disable 1=enable};
$sys{"suggest$_"} = qq{ (0=disable 1=enable) };
}
elsif ( $_ =~ /password_dir/ )
{
if ( $fun{$_} eq '' )
{
$fun{$_} = "$sys{password_dir}";
$sys{title_tip} = "Suggested Path";
}
else
{
$sys{title_tip} = "Please change value";
$sys{"suggest$_"} = qq{ ($sys{password_dir})};
}
}
elsif ( $_ =~ /css_js_url/ )
{
if ( $fun{$_} eq '' )
{
$fun{$_} = "$sys{csjs_url}";
$sys{title_tip} = "Suggested Path";
}
else
{
$sys{title_tip} = "Please change value";
$sys{"suggest$_"} = qq{ ($sys{csjs_url}) };
}
}
elsif ( $_ =~ /cookie_domain/ )
{
if ( $fun{$_} eq '' )
{
$fun{$_} = "$ENV{SERVER_NAME}";
$sys{title_tip} = "Suggested Path";
}
else
{
$sys{title_tip} = "Please change value";
$sys{"suggest$_"} = qq{ ($ENV{SERVER_NAME}) };
}
}
elsif ( $_ =~ /user_pref_home_dir/ )
{
if ( $fun{$_} eq '' )
{
$fun{$_} = "$sys{script_dir}";
$sys{title_tip} = "Suggested Path";
}
else
{
$sys{title_tip} = "Please change value";
$sys{"suggest$_"} = qq{ ($sys{script_dir}) };
}
}
elsif ( $_ =~ /script_web_dir/ )
{
if ( $fun{$_} eq '' )
{
$fun{$_} = "$sys{script_dir}";
$sys{title_tip} = "Suggested Path";
}
else
{
$sys{title_tip} = "Please change value";
$sys{"suggest$_"} = qq{ ($sys{script_dir}) };
}
}
elsif ( $_ =~ /server_port/ )
{
if ( $fun{$_} eq '' )
{
$fun{$_} = "$ENV{SERVER_PORT}";
$sys{title_tip} = "Suggested Path";
}
else
{
$sys{title_tip} = "Please change value";
$sys{"suggest$_"} = qq{ ($ENV{SERVER_PORT}) };
}
}
elsif ( $_ =~ /web_root/ )
{
if ( $fun{$_} eq '' )
{
$fun{$_} = "$ENV{DOCUMENT_ROOT}";
$sys{title_tip} = "From ENV ";
}
else
{
$sys{title_tip} = "Please change value";
$sys{"suggest$_"} = qq{ ($ENV{DOCUMENT_ROOT}) };
}
}
else
{
$sys{title_tip} = qq{Please change value };
}
$form .= qq{
<div class="form-group">
<label for="$_" title="">$_ $sys{"suggest$_"}</label>
<input class="form-control" type="text" name="$_" id="$_" value="$fun{$_}" title="$sys{title_tip}">
</div>
};
}
$form .= qq{<button type="submit" class="badge badge-pill badge-secondary">Go</button>};
$form .= qq{</form>};
$form .= qq{
$sys{error}
};
# end form
# end system stuff
=head2 get /nologin
Show settings for user to change/update without logging in
This is here for backwards compatibility ( was front page in versions prior to around 050?)
=cut
get '/nologin' => sub {
my $c = shift;
my %lang = Lang::get_language( dir => "$sys{script_dir}" );
$c->render(
'index',
h1 => qq{ $sys{script_name} },
csjs => "/$sys{csjs_url}",
dir => "$sys{script_dir}",
form => qq{$form}
);
};
# end no login
=head2 post /nologin
Save Settings posted from /nologin
=cut
post '/change' => sub {
my $c = shift;
my $result = '';
my %result;
my %in;
for (keys %fun ) {
# Assign name = value
$result{$_} = $c->param("$_");
}
my $fdb = '';
if ( -e -f "$sys{script_dir}/lib/system_functions.txt" )
{
open(FDB, ">$sys{script_dir}/lib/system_functions.txt") or die $!;
}
$result .= qq{<table>};
for ( keys %result )
{
# Write to File Database
print FDB qq{$_\=$result{$_}\n};
# to browser
$result .= qq{ <tr> <td>$_</td> <td>$result{$_}</td> </tr> };
}
$result .= qq{</table>};
close FDB;
$c->render(
'change',
h1 => qq{$sys{script_name}},
csjs => "$sys{csjs_url}",
result => qq{ $result },
);
};
# end post change
get '/' => sub {
my $c = shift;
my $out = '';
$c->render(
'welcome',
h1 => qq{ $sys{script_name} },
csjs => "/$sys{csjs_url}",
dir => "",
out => qq{$out}
);
};
# env
get '/env' => sub {
my $c = shift;
my $out = '';
$out .= qq{};
if (%ENV) {
for (keys %ENV) {
$out .= qq{<tr> <td>$_</td> <td>$ENV{"$_"}</td> </tr>\n};
}
$out .= qq{};
}
$c->stash(out => qq{$out});
$c->render(
'env',
h1 => qq{$sys{script_name}},
csjs => "$sys{csjs_url}",
result => qq{},
);
};
# end env
get '/search' => sub {
my $c = shift;
$c->render('search/welcome', h1 => "Search");
};
# end search
# Result
post '/search' => sub {
my $c = shift;
#
my @out;
# search term
my $searchterm = $c->param('searchterm');
$searchterm =~ s!(\$|\#|\@|\&|\*|\(|\)|\%|\^|\!)!!g; # add more later.
my $searchresult = '';
my $error = '';
# result
my $searchdir = $dir;
$searchdir =~ s!\/github\/PCAccessFree!!;
# hide some basic/imp info from hackers
my $dir4web = $searchdir;
$dir4web =~ s!C:/Users/sumu/public!!;
#
if ( -d "$searchdir" ) {
if ( opendir(my $sd, $searchdir) ) {
# find a match
while (my $file = readdir $sd) {
#
#next if $file =~ /^.$/;
#next if $file =~ /^..$/;
# find match
if ($file =~ /$searchterm/i) {
# Does not work for some reason i dono
#$searchresult .= qq{ <a href="/found?name=$file" title="match found">$file</a> };
# works
push( @out, qq{<a href="$dir4web/$file&dir=$dir4web" title="found match $file">$file</a>} );
# error
$error = qq{<div class="alert alert-default">Results found for "$searchterm" in "$searchdir" </div>};
} else {
# will show up only if no content in searchresult. See logic in result.*.ep
$error = qq{<div class="alert alert-warning">No results found for "$searchterm" in "$searchdir" </div>};
}
}
closedir $sd;
# end while
} else {
$searchresult = qq{<div class="alert alert-danger">Unable to open directory $searchdir </div>};
}
} else {
$searchresult = qq{<div class="alert alert-danger">Search Directory is inaccessible or not found </div> };
}
for (@out) { $searchresult .= qq{$_ }; }
# render
$c->render(
'search/result',
searchterm => $searchterm,
searchdir => "$searchdir",
searchresult => qq{$searchresult},
error => $error,
h1 => "Results for search"
);
# end render
};
# end search result
=head2 Login
Login
=cut
get '/login' => sub {
my $c = shift;
$c->render('login/index', h1 => "Login");
};
# end login form
post '/admin' => sub {
my $self = shift;
my $session = $self->session;
my $session_user = $self->session('user');
my $user = $self->param('user') || '';
my $pass = $self->param('pass') || '';
if ( $session_user )
{
$self->render('/admin/welcome', h1 => 'Welcome');
}
# end if session user
else
{
#return $self->render unless $self->users->check($user, $pass);
if ( $self->users->check($user, $pass) ) {
# Add to session
$self->session(user => $user);
$self->flash(message => 'Thanks for logging in.');
$self->render('admin/welcome', h1 => "Welcome back");
} else {
$self->render('login/index', h1 => "");
}
#########$self->redirect_to('/admin');
}
# end else session user
};
# end post login
get '/admin' => sub {
my $self = shift;
my $session_user = $self->session('user');
if ( $session_user )
{
$self->render('/admin/welcome', h1 => "Welcome back $session_user");
}
# end if session user
else
{
$self->render('/login/index', h1 => "Login");
}
};
# end get /admin
=head2 Admin/settings
system_functions.txt
Database settings: settings.txt
=cut
# admin/settings
get '/admin/settings' => sub {
my $self = shift;
my $session_user = $self->session('user');
#
my $out = '';
#
my %set = ();
#
$set{system_functions} = $self->syst->settings( file => "$dir/lib/system_functions.txt");
#
$set{db_settings} = $self->syst->settings( file => "$dir/lib/Database/settings.txt");
#
#
if ($session_user) {
$self->render(
'/admin/settings',
h1 => "PC Access Free - App Settings",
user => "$session_user",
system_settings => $set{system_functions},
db_settings => $set{db_settings},
out => $out
);
} else {
$self->render('/admin/settings',
h1 => "Session Expired", user => '', system_settings => '', db_settings => '', out => ""
);
}
};
# end
post '/admin/savesettings' => sub {
my $self = shift;
my $out = ''; #
my $tofile = '';
my @names = $self->syst->settings_names_array( file => "$dir/lib/system_functions.txt");
$out .= qq{<table class="table">};
for (sort @names) {
$tofile .= qq{$_=} . $self->param("$_"). qq{\n};
$out .= qq{<tr> <td>$_</td> <td>} . $self->param("$_") . q{</td> </tr>};
}
$out .= qq{</table> <textarea class="form-control">$tofile</textarea>};
# write to file
if ( open( my $sysfile, ">", "$dir/lib/system_functions.txt") ) {
print $sysfile "$tofile";
}
#close $sysfile;
#
$self->render('admin/savesettings', h1 => "", out => $out);
};
# end post settings
=head2 Show Language to edit
not ready yet
=cut
# admin/settings
get '/admin/lang/show/:lang' => sub {
my $self = shift;
my $lang = $self->param('lang');
chomp $lang;
my $session_user = $self->session('user');
my $out = $self->lang->english( file => "$dir/lang/$lang.txt", language => "$lang");
my $no_html_out = $self->lang->english( file => "$dir/lang/$lang.txt", language => "$lang", no_html => '1' );
#if ($session_user) {
$self->render(
'/admin/lang/show',
h1 => "PC Access Free - Lang Settings",
language => "$lang",
out => qq{$out},
no_html_out => qq{$no_html_out},
);
#} else {
#$self->render('/', h1 => "", out => "");
#my $url = $self->url_for('/')->to_abs();
#$self->render( text => "Session expired. Login <a href=\"$url\">again</a>");
#}
};
=head2 Save Language
Not ready yet
=cut
post '/admin/lang/save/:lang' => sub {
my $self = shift;
my $lang = $self->param('lang');
my $session_user = $self->session('user');
my $out = $self->lang->english( file => "$dir/lib/system_functions.txt");
if ($session_user) {
$self->render(
'/admin/lang/save',
h1 => "PC Access Free - App Settings",
out => $out
);
} else {
$self->render('/login')
}
};
=head2 Logout
=cut
get '/logout' => sub {
my $c = shift;
$c->session(expires => 1);
$c->render('login/logout', h1 => "Logout successful");
};
# end logout
=head2 Profile
=cut
get '/admin/profile/:user' => sub {
my $c = shift;
my $user = $c->param('user');
chomp $user;
$user = $c->utils->cleanse( string => "$user" );
my $out = '';
#$out .= qq{$user};
#
my $verify = '';
if ( $user =~ /[a-zA-Z0-9]/ ) {
# run sql and get return value from .pm
$verify = $c->admin->profile(
user => "$user",
url4save => $c->url_for('/admin/profile/save')->to_abs(),
url4update => $c->url_for('/admin/profile/update')->to_abs(),
url4view => $c->url_for("/profile/$user")->to_abs()
);
}
$out .= qq{$verify};
# render
$c->render('admin/profile/welcome', h1 => "Profile", user => "$user", out => $out);
};
=head2 Save Profile
=cut
post '/admin/profile/save' => sub {
my $c = shift;
my $user = $c->session('user');
my %in = (
url4save => $c->url_for('/admin/profile/save')->to_abs(),
url4update => $c->url_for('/admin/profile/update')->to_abs(),
url4view => $c->url_for("/profile/$user")->to_abs(),
@_,
);
#
my %out = ();
#
for ( qw/id username created firstname lastname email description/ ) {
$out{"$_"} = $c->param("$_");
}
# take care of new lines in textarea content
$out{description} =~ s!\n! NEWLINE !g;
# sql
#sql
#( $in{firstname}, $in{lastname}, $in{email}, $in{description} ) = ( );
my $save_profile_sql = qq{INSERT INTO `profile` (`id`, `username`, `created`, `firstname`, `lastname`, `email`, `description`)
values (DEFAULT, "$out{username}", DEFAULT, "$out{firstname}", "$out{lastname}", "$out{email}", "$out{description}") };
my $out = '';
for (keys %out ) {
$out .= qq{$_=$out{$_} <br/>}
}
# enable to test only
#$out .= qq{<hr/> $save_profile_sql};
#
#insert into table
my $commit_sql = $c->admin->profile_save( sql => $save_profile_sql );
#
if ( $commit_sql >= '1' ) {
$out .= qq{
<div class="alert alert-success">Saved successfully</div>
<div class="container">
View <a href="$out{url4view}" title="view profile">profile</a>
</div>
};
} else {
$out .= qq{ <div class="alert alert-danger">Profile creation failed</div> };
}
# render
$c->render('admin/profile/save', h1 => "save profile", user => $out{username}, out => $out);
};
# end save profile
=head2 Update Profile
Update profile - data comes from /admin/profile/:user - url4update
=cut
post '/admin/profile/update' => sub {
my $c = shift;
my $user = $c->session('user');
my %out = (
url4save => $c->url_for('/admin/profile/save')->to_abs(),
url4update => $c->url_for('/admin/profile/update')->to_abs(),
url4view => $c->url_for("/profile/$user")->to_abs()
);
#
$out{username} = $c->session('user');
chomp $out{username};
#
for ( qw/firstname lastname email description/ ) {
$out{"$_"} = $c->param("$_");
}
# take care of new lines in textarea content
$out{description} =~ s!\n! NEWLINE !g;
#sql
#( $in{firstname}, $in{lastname}, $in{email}, $in{description} ) = ( );
my $update_profile_sql = qq{UPDATE `profile` SET `firstname`="$out{firstname}", `lastname`="$out{lastname}", `email`="$out{email}", `description`="$out{description}" WHERE `username`="$out{username}" LIMIT 1};
my $out = '';
# enable during test/dev only
#for (keys %out ) { $out .= qq{$_=$out{$_} <br/>} }
# enable during test only
#$out .= qq{<hr/> $update_profile_sql};
# insert into table
my $commit_sql = $c->admin->profile_update( sql => $update_profile_sql );
#
if ( $commit_sql >= '1' ) {
$out .= qq{
<div class="alert alert-success">Updated successfully</div>
<div class="container">
View <a href="$out{url4view}" title="view profile">profile</a>
</div>
};
} else {
$out .= qq{ <div class="alert alert-danger">Profile updating failed</div> };
}
# render
$c->render('admin/profile/save', h1 => "save profile", user => $out{username}, out => $out);
};
# end update profile
=head2 Profile View
=cut
get '/profile/:user' => sub {
my $c = shift;
my %in = (
user => $c->param('user')
);
my $out = '';
my @data = $c->admin->profile_view( user => $in{user} );
#
#for (@data) { $out .= qq{$_ }; }
# build the html output
# Dont show username <tr> <td> Username </td> <td> $data[1] </td> </tr>
$out .= qq{
<table class="table table-responsive">
<tr> <td> First name </td> <td> $data[3] </td> </tr>
<tr> <td> Last Name </td> <td> $data[4] </td> </tr>
<tr> <td> Email </td> <td> $data[5] </td> </tr>
<tr> <td> Description </td> <td> $data[6] </td> </tr>
</table>
};
#
$c->render('profile_view', h1 => "View profile", user => $in{user}, out => qq{ $out } );
};
# end profile view
=head2 Versions
Version identifiers for installed software/package on your system
=cut
get '/versions' => sub {
my $c = shift;
$c->render('versions', h1 => "Versions ");
};
# enc versions
=head2 Profile
=cut
get '/profile' => sub {
my $c = shift;
my $user = $c->param('user');
$c->render('profile', user => $user );
};
# end profile
=head2 Save DB Settings
Save settings to lib/Database/settings.txt
=cut
post '/admin/save_db_settings' => sub {
my $self = shift;
my $out = '';
# Var to hold content to be written to settings.txt
my $tofile = '';
# get names only from settings.txt file with name=value pairs
my @names = $self->syst->settings_names_array( file => "$dir/lib/Database/settings.txt");
# begin output to browser/user - table
$out .= qq{<table class="table"> <tr> <td colspan="2">The following values were saved to settings.txt</td> </tr> };
for (sort @names) {
# build content to be saved to file
$tofile .= qq{$_=} . $self->param("$_"). qq{\n};
# output - table tr
$out .= qq{<tr> <td>$_</td> <td>} . $self->param("$_") . q{</td> </tr>};
}
# end output - table
$out .= qq{</table>};
# test
#$out .= qq{<textarea class="form-control">$tofile</textarea>};
# write to file
if ( open( my $sysfile, ">", "$dir/lib/Database/settings.txt") ) {
print $sysfile "$tofile";
}
# render
$self->render('admin/save_db_settings', h1 => "", out => $out);
};
# end post save db settings
=head2 Change Language
No login necessary
=cut
get '/lang/change/:lang' => sub {
my $c = shift;
my $error = '';
my $lang = $c->param('lang');
chomp $lang;
#
$lang = $c->utils->cleanse( string => "$lang");
#
if ( open( my $file, ">$dir/lang/default-language.txt") ) {
print $file "$lang";
$error = "";
} else {
$error = "Could not find default-language.txt";
}
#
$c->render('lang/change', h1 => "Change Language", lang => "$lang", error => "$error");
};
# end change language
app->start();
1;
__DATA__