-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathactivate.pl
More file actions
executable file
·161 lines (134 loc) · 3.73 KB
/
Copy pathactivate.pl
File metadata and controls
executable file
·161 lines (134 loc) · 3.73 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
#!/usr/bin/perl
use strict;
use warnings;
use Term::ANSIColor;
use lib '/scripts/common_perl/';
use Framework qw(&cryptText2File &decryptFile $student_file);
my $E="";
sub exposeTopic($)
{
my $Topic=$_[0];
my $N=1;
my $TriedExercises=0;
my $SuccessfulExercises=0;
my $HTML_EXERCISES="";
while (-x "/var/www/cgi-bin/$Topic/$N-activator")
{
my $Description="";
my $Result_file="/ALTS/RESULTS/ACTUAL/$Topic-$N";
if (!(-f $Result_file)) {
my $F;
open($F,"<","/ALTS/EXERCISES/$Topic/$N-description.txt");
my @D = <$F>;
close($F);
$Description=join("\t\t\t\t",@D);
$Description="\t\t\t\t".$Description;
if ( ($E eq "LIST ALL") || ($E eq "LIST UNTRIED") ) { print "\n\t\t$Topic-$N\n\n$Description\n";}
}
else
{
my $FN=decryptFile("$Result_file");
my $Finalresult="";
if ((-f $Result_file)) {
my @RES = $FN =~ m/<DESCRIPTION>(.*)<\/DESCRIPTION>.*<FINALRESULT>(.*)<\/FINALRESULT>/s;
$Description="\t\t\t\t".$RES[0];
# $Description =~ s/\n/<br>/g;
$Description=~s/\n/\n\t\t\t\t/g;
$Finalresult=$RES[1];
}
if ($Finalresult eq "PASSED")
{
if ( ($E eq "LIST ALL") || ($E eq "LIST PASSED") ) {
print color 'green'; print colored "\n\t\t$Topic-$N\n\n$Description\n";
}
}
elsif ($Finalresult eq "FAILED")
{
if ( ($E eq "LIST ALL") || ($E eq "LIST FAILED") ) {
print color 'red'; print colored "\n\t\t$Topic-$N\n\n$Description\n";
}
}
else
{
if ( ($E eq "LIST ALL") || ($E eq "LIST UNTRIED") ) {
print "\n\t\t$Topic-$N\n\n$Description\n";
}
}
}
$N=$N+1;
}
}
if ((scalar @ARGV) == 0) {
while( ($E eq "")||($E eq "LIST ALL")||($E eq "LIST FAILED")||($E eq "LIST PASSED")||($E eq "LIST UNTRIED")||($E eq "EXIT") )
{
system("clear");
print "";
print "Which exercise do you want to activate?\n\n";
print "\t<TOPIC>-<ID> \tE.g.:05-user-group-1\n";
print "\n";
print "\tLIST ALL: \tShows every available exercise\n";
print "\tLIST PASSED: \tShows only the passed exercises\n";
print "\tLIST FAILED: \tShows only the tried but failed exercises\n";
print "\tLIST UNTRIED: \tShows only the exercises you didn't tried yet\n\n";
print "\tEXIT: \t\tExit\n\n";
if ($E eq "EXIT") { exit 2; }
if ($E eq "LIST ALL") { print "LIST ALL Exercises\n------------------\n\n"; }
if ($E eq "LIST FAILED") { print "LIST FAILED Exercises\n---------------------\n\n"; }
if ($E eq "LIST PASSED") { print "LIST PASSED Exercises\n---------------------\n\n"; }
if ($E eq "LIST UNTRIED") { print "LIST UNTRIED Exercises\n----------------------\n\n"; }
if (($E eq "LIST ALL")||($E eq "LIST FAILED")||($E eq "LIST PASSED")||($E eq "LIST UNTRIED")) {
exposeTopic("01-boot");
exposeTopic("02-physical_disk");
exposeTopic("03-lvm");
exposeTopic("04-network");
exposeTopic("05-user-group");
exposeTopic("06-rights");
exposeTopic("07-nfs");
exposeTopic("08-autofs");
exposeTopic("09-ldap");
exposeTopic("10-samba");
exposeTopic("11-ftp");
exposeTopic("12-system");
exposeTopic("13-log");
exposeTopic("14-apache");
exposeTopic("15-firewall");
exposeTopic("16-selinux");
exposeTopic("17-package");
exposeTopic("18-scripting");
exposeTopic("19-crontab");
exposeTopic("20-squid");
exposeTopic("21-mail");
}
print "\nYour choice: ";
$E=<STDIN>;
chomp($E);
print "";
}
}
else
{
$E=$ARGV[0];
}
print "Activate $E...\n";
if (my @A = $E =~ m/(\d+-\D+)-(\d+)/)
{
if (($A[0] ne "") && ($A[1] ne ""))
{
my $Topic=$A[0];
my $Problem=$A[1];
if (-f "/var/www/cgi-bin/$Topic/$Problem-activator")
{
system("/var/www/cgi-bin/$Topic/$Problem-activator");
exit 0;
}
}
else
{
print("The given exercise doesn't exist!\n\n"); exit 1;
}
}
else
{
print("The given exercise doesn't exist!\n\n"); exit 1;
}
exit 1;