View | Details | Raw Unified | Return to bug 38365
Collapse All | Expand All

(-)a/misc/devel/add_csp_nonces.pl (-31 / +7 lines)
Lines 49-58 The script: Link Here
49
49
50
use Modern::Perl;
50
use Modern::Perl;
51
use Carp qw( carp );
51
use Carp qw( carp );
52
use File::Find;
53
use Getopt::Long;
52
use Getopt::Long;
54
use Pod::Usage;
53
use Pod::Usage;
55
54
55
use Koha::Devel::Files;
56
56
my $apply   = 0;
57
my $apply   = 0;
57
my $verbose = 0;
58
my $verbose = 0;
58
my $help    = 0;
59
my $help    = 0;
Lines 70-104 pod2usage(1) if $help; Link Here
70
# The nonce attribute to add
71
# The nonce attribute to add
71
my $nonce_attr = 'nonce="[% Koha.CSPNonce | $raw %]"';
72
my $nonce_attr = 'nonce="[% Koha.CSPNonce | $raw %]"';
72
73
73
# Patterns to skip (library files, etc.)
74
my @skip_patterns = (
75
    qr{/lib/},             # Third-party libraries
76
    qr{/vendor/},          # Vendor files
77
    qr{\.min\.},           # Minified files
78
    qr{/node_modules/},    # Node modules
79
);
80
81
my %stats = (
74
my %stats = (
82
    files_scanned  => 0,
75
    files_scanned  => 0,
83
    files_modified => 0,
76
    files_modified => 0,
84
    tags_modified  => 0,
77
    tags_modified  => 0,
85
);
78
);
86
79
87
sub should_skip_file {
88
    my ($file) = @_;
89
    for my $pattern (@skip_patterns) {
90
        return 1 if $file =~ $pattern;
91
    }
92
    return 0;
93
}
94
95
sub process_file {
80
sub process_file {
96
    my ($file) = @_;
81
    my ($file) = @_;
97
82
98
    return unless -f $file;
99
    return unless $file =~ /\.(tt|inc)$/;
100
    return if should_skip_file($file);
101
102
    $stats{files_scanned}++;
83
    $stats{files_scanned}++;
103
84
104
    open my $fh, '<:encoding(UTF-8)', $file or do {
85
    open my $fh, '<:encoding(UTF-8)', $file or do {
Lines 174-188 sub process_file { Link Here
174
}
155
}
175
156
176
# Find and process all template files
157
# Find and process all template files
177
find(
158
my $dev_files = Koha::Devel::Files->new;
178
    {
159
my @tt_files  = $dev_files->ls_tt_files;
179
        wanted => sub {
160
for my $file (@tt_files) {
180
            process_file($File::Find::name);
161
    process_file($file);
181
        },
162
}
182
        no_chdir => 1,
183
    },
184
    $dir
185
);
186
163
187
# Print summary
164
# Print summary
188
say "";
165
say "";
189
- 

Return to bug 38365