This file is indexed.

/usr/share/perl5/Octopussy/Search_Template.pm is in octopussy 1.0.6-0ubuntu1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
# $HeadURL$
# $Revision: 579 $
# $Date: 2012-06-24 02:11:57 +0100 (Sun, 24 Jun 2012) $
# $Author: sebthebert $

=head1 NAME

Octopussy::Search_Template - Octopussy Search Template module

=cut

package Octopussy::Search_Template;

use strict;
use warnings;
use Readonly;
use bytes;
use utf8;

use AAT::FS;
use AAT::Utils qw( NOT_NULL );
use AAT::XML;
use Octopussy;
use Octopussy::FS;

Readonly my $DIR_SEARCH_TPL => 'search_templates';
Readonly my $XML_ROOT       => 'octopussy_search_template';

my $dir_search_tpl = undef;
my %filename;

=head1 FUNCTIONS

=head2 New($user, \%conf)

Create a new Search Template
 
Parameters:

$user - user who create this template
\%conf - hashref of the new Search Template configuration

=cut

sub New
{
  my ($user, $conf) = @_;

  $dir_search_tpl ||= Octopussy::FS::Directory($DIR_SEARCH_TPL);
  Octopussy::FS::Create_Directory("$dir_search_tpl/$user");
  AAT::XML::Write("$dir_search_tpl/$user/$conf->{name}.xml", $conf, $XML_ROOT);

  return ($conf->{name});
}

=head2 Remove($user, $search_tpl)

Remove the Search Template '$search_tpl'
 
Parameters:

$user - user who created this template
$search_tpl - Name of the Search Template to remove

=cut

sub Remove
{
  my ($user, $search_tpl) = @_;

  my $nb = unlink Filename($user, $search_tpl);
  $filename{$user}{$search_tpl} = undef;

  return ($nb);
}

=head2 List($user)

Get list of Search Templates
 
Parameters:

$user - user who created this template

Returns:

@tpls - Array of Search Templates names

=cut

sub List
{
  my $user = shift;

  $dir_search_tpl ||= Octopussy::FS::Directory($DIR_SEARCH_TPL);
  my @files = AAT::FS::Directory_Files("$dir_search_tpl/$user/", qr/.+\.xml$/);
  my @tpls = ();
  foreach my $f (@files)
  {
    my $conf = AAT::XML::Read("$dir_search_tpl/$user/$f");
    push @tpls, $conf->{name} if (defined $conf->{name});
  }

  return (sort @tpls);
}

=head2 List_Any_User($sort)

Get template name / user List

Parameters:

$sort - selected field to sort List (default: 'name')

Returns:

@sorted_list - Array of Search Templates names for all users

=cut

sub List_Any_User
{
  my $sort = shift || 'name';
  my (@list, @sorted_list) = ((), ());

  $dir_search_tpl ||= Octopussy::FS::Directory($DIR_SEARCH_TPL);
  my @dirs = AAT::FS::Directory_Files("$dir_search_tpl/", qr/\w+$/);
  foreach my $d (@dirs)
  {
    my @files = AAT::FS::Directory_Files("$dir_search_tpl/$d/", qr/.+\.xml$/);
    foreach my $f (@files)
    {
      my $conf = AAT::XML::Read("$dir_search_tpl/$d/$f");
      push @list, {name => $conf->{name}, user => $d}
        if (defined $conf->{name});
    }
  }
  foreach my $i (sort { $a->{$sort} cmp $b->{$sort} } @list)
  {
    push @sorted_list, $i;
  }

  return (@sorted_list);
}

=head2 Filename($user, $search_tpl)

Get the XML filename for the Search Template '$search_tpl'

Parameters:

$user - user who created this template
$search_tpl - Name of the Search Template

Returns:

$filename - Filename of the XML file for Search Template '$search_tpl'

=cut

sub Filename
{
  my ($user, $search_tpl) = @_;

  return ($filename{$user}{$search_tpl})
    if (defined $filename{$user}{$search_tpl});
  if (NOT_NULL($search_tpl))
  {
    $dir_search_tpl ||= Octopussy::FS::Directory($DIR_SEARCH_TPL);
    my @files =
      AAT::FS::Directory_Files("$dir_search_tpl/$user/", qr/.+\.xml$/);
    foreach my $f (@files)
    {
      my $conf = AAT::XML::Read("$dir_search_tpl/$user/$f");
      if ((defined $conf) && ($conf->{name} =~ /^$search_tpl$/))
      {
        $filename{$user}{$search_tpl} = "$dir_search_tpl/$user/$f";
        return ("$dir_search_tpl/$user/$f");
      }
    }
  }

  return (undef);
}

=head2 Configuration($user, $search_tpl)

Get the configuration for the Search Template '$search_tpl'
 
Parameters:

$user - user who created this template
$search_tpl - Name of the Search Template

Returns:

\%conf - Hashref of the Search Template configuration

=cut

sub Configuration
{
  my ($user, $search_tpl) = @_;

  return (AAT::XML::Read(Filename($user, $search_tpl)));
}

=head2 Configurations($user, $sort)

Get the configuration for all Search Templates from User $user

Parameters:

$user - user who created this template
$sort - selected field to sort configurations

Returns:

@configurations - Array of Hashref Search Template configurations  

=cut

sub Configurations
{
  my ($user, $sort) = @_;
  my (@configurations, @sorted_configurations) = ((), ());
  my @tpls = List($user);

  foreach my $t (@tpls)
  {
    my $conf = Configuration($user, $t);
    if (defined $conf->{name})
    {
      push @configurations, $conf;
    }
  }
  foreach my $c (sort { $a->{$sort} cmp $b->{$sort} } @configurations)
  {
    push @sorted_configurations, $c;
  }

  return (@sorted_configurations);
}

=head2 Valid_Name($name)

Checks that '$name' is valid for a Search Template name

=cut

sub Valid_Name
{
    my $name = shift;

    return (1)  if ((NOT_NULL($name)) && ($name =~ /^[a-z0-9][a-z0-9_-]*$/i));

    return (0);
}

1;

=head1 AUTHOR

Sebastien Thebert <octo.devel@gmail.com>

=cut