forked from bentglasstube/blosxom-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinclude-v0i0
103 lines (80 loc) · 2.41 KB
/
include-v0i0
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
# Blosxom Plugin: include -*- perl -*-
# Author: Todd Larason ([email protected])
# Version: 0+0i
# Blosxom Home/Docs/Licensing: http://www.raelity.org/blosxom
# Include plugin Home/Docs/Licensing:
# http://molelog.molehill.org/blox/Computers/Internet/Web/Blosxom/Include/
package include;
# --- Configuration Variables ---
# trust levels:
# 10 complete trust
# 7 allow running commands
# 5 allow including files from outside dirs
# 4 allow including files from from $datadir
# 3 allow including files from same dir
# 0 don't trust
$trust_flavours ||= 4;
$trust_stories ||= 0;
$debug_level ||= 1;
# -------------------------------
use FileHandle;
my $package = 'include';
sub debug {
my ($level, @msg) = @_;
if ($debug_level >= $level) {
print STDERR "$package debug $level: @msg\n";
}
}
sub run_command {
my ($text) = @_;
$text =~ s/((\$[\w:]+)|(\$\{[\w:]+\}))/$1 . "||''"/gee;
return `$text`;
}
sub read_file {
my ($filename, $basedir, $trust) = @_;
my $fh = new FileHandle;
$fh->open($filename =~ m:^/: ? "$filename" : "$basedir/$filename") ||
($trust >= 4 && $fh->open("$blosxom::datadir/$filename")) ?
join('',<$fh>) : '';
}
sub include {
my ($text, $basedir, $trust) = @_;
my $okaychars = '-\w.';
return if $trust < 3;
$okaychars .= '/' if ($trust >= 5);
$$text =~ s! \$include::file\( ([$okaychars]+) \)
! read_file($1, $basedir)
!xeg;
if ($trust >= 7) {
$$text =~ s! \$include::command\( ([^\)]+) \)
! run_command($1)
!xeg;
}
}
sub start {
debug(1, "start() called, enabled");
return 1;
}
sub head {
my ($pkg, $currentdir, $head_ref) = @_;
include($head_ref, "$blosxom::datadir/$currentdir", $trust_flavours);
return 1;
}
sub date {
my ($pkg, $currentdir, $date_ref, $mtime, @date) = @_;
include($date_ref, "$blosxom::datadir/$currentdir", $trust_flavours);
return 1;
}
sub story {
my ($pkg, $path, $filename, $story_ref, $title_ref, $body_ref) = @_;
include($story_ref, "$blosxom::datadir/$path", $trust_flavours);
include($title_ref, "$blosxom::datadir/$path", $trust_stories);
include($body_ref, "$blosxom::datadir/$path", $trust_stories);
return 1;
}
sub foot {
my ($pkg, $currentdir, $foot_ref) = @_;
include($foot_ref, "$blosxom::datadir/$currentdir", $trust_flavours);
return 1;
}
1;