This file is indexed.

/usr/bin/fusiondirectory-shell is in fusiondirectory-webservice-shell 1.0.8.8-3ubuntu2.

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

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
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
#!/usr/bin/perl

#
# fusiondirectory-shell: A shell to act on FusionDirectory handled objects
# See pod documentation at the end of the file
#

use strict;
use warnings;

use 5.008;

use Getopt::Long;
use Pod::Usage;
use JSON::RPC::Client;
use Data::Dumper;
use Term::ShellUI;

my $host      = 'https://localhost/fusiondirectory/jsonrpc.php';
my $help      = 0;
my $ca_file   = 0;
my $login;
my $password;
my $ldap_server = undef;

# Process command-line

GetOptions(
  'help|?'      => \$help,
  'url=s'       => \$host,
  'ca=s'        => \$ca_file,
  'login=s'     => \$login,
  'password=s'  => \$password,
  'server=s'    => \$ldap_server
) or pod2usage(2);
pod2usage(1) if $help;
pod2usage(2) if not defined $login;
pod2usage(2) if not defined $password;

my $current_base;

sub rpc_init {
  my $client = JSON::RPC::Client->new();
  $client->version('1.0');
  if ($client->ua->can('ssl_opts')) {
    if ($ca_file) {
      $client->ua->ssl_opts(verify_hostname => 1, SSL_ca_file => "$ca_file");
    } else {
      $client->ua->ssl_opts(verify_hostname => 0);
    }
  }

  return $client;
}

sub rpc_call {
  my ($client, $action, $params) = @_;

  if (!$params) {
    $params = [];
  }

  my $callobj = {
    method  => $action,
    params  => $params,
  };

  #~ print Dumper($callobj);

  my $res = $client->call($host, $callobj);

  #~ print Dumper($res);

  if($res) {
    if ($res->is_error) {
      die "Error : ", $res->error_message."\n";
    }
    else {
      return $res->result;
    }
  }
  else {
    die "Status : ".$client->status_line."\n";
  }
}

use Term::ShellUI;
my $term = new Term::ShellUI(
  app => "fusiondirectory-shell",
  commands => {
    "help" => {
      desc    => "Print helpful information",
      args    => sub { shift->help_args(undef, @_); },
      method  => sub { shift->help_call(undef, @_); }
    },
    "h" => { alias => "help", exclude_from_completion=>1},
    "cd" => {
      desc    => "Change current base to BASE",
      maxargs => 1,
      proc    => \&command_cd,
    },
    "chdir" => { alias => 'cd' },
    "pwd" => {
      desc    => "Print the current working directory",
      maxargs => 0,
      proc    => sub { print $current_base."\n"; },
    },
    "ls" => {
      desc    => "List objects of a given type",
      minargs => 1,
      maxargs => 4,
      proc    => \&command_ls,
    },
    "count" => {
      desc    => "Count objects of a given type",
      minargs => 1,
      maxargs => 4,
      proc    => \&command_count,
    },
    "cat" => {
      desc    => "Show an object information",
      minargs => 1,
      maxargs => 3,
      proc    => \&command_cat,
    },
    "infos" => {
      desc    => "Show informations about a type",
      minargs => 1,
      maxargs => 1,
      proc    => \&command_infos,
    },
    "types" => {
      desc    => "List existing types",
      minargs => 0,
      maxargs => 0,
      proc    => \&command_types,
    },
    "exit" => {
      desc    => "Exit FusionDirectory shell",
      maxargs => 0,
      method  => sub { shift->exit_requested(1); },
    }
  },
  history_file => '~/.fusiondirectory_shell_history',
);

my $client  = rpc_init();
if (!defined $ldap_server) {
  my $ldaps = rpc_call($client, 'listLdaps');
  my @keys = keys(%$ldaps);
  if (scalar(@keys) == 0) {
    die "No LDAP server was returned by FusionDirectory\n";
  } elsif (scalar(@keys) == 1) {
    $ldap_server = $keys[0];
  } else {
    for (my $i = 0; $i < @keys; $i++) {
      my $key   = $keys[$i];
      my $label = $ldaps->{$key};
      print $i.":$label ($key)\n";
    }
    my $choice;
    do {
      $choice = $term->{term}->readline("Choice: ");
    } while (($choice eq '') || ($choice =~ m/[^0-9]/) || ($choice >= scalar(@keys)));
    $ldap_server = $keys[$choice];
  }
}
my $sid     = rpc_call($client, 'login', [$ldap_server, $login, $password]);
my $base    = rpc_call($client, 'getBase', [$sid]);

$current_base = $base;

print 'Using '.$term->{term}->ReadLine."\n";
$term->prompt(sub { $login.'@'.$current_base."> " });
$term->run();

sub command_ls
{
  my ($type, $attrs, $ou, $filter) = @_;
  if (! defined $ou) {
    $ou = $current_base;
  }
  if (! defined $filter) {
    $filter = '';
  }
  my $res = rpc_call($client, 'ls', [$sid,$type,$attrs,$ou,$filter]);
  if (ref $res eq ref {}) {
    while (my ($dn, $display) = each(%$res))
    {
      print "$display\t($dn)\n";
    }
  }
}

sub command_count
{
  my ($type, $ou, $filter) = @_;
  if (! defined $ou) {
    $ou = $current_base;
  }
  if (! defined $filter) {
    $filter = '';
  }
  my $res = rpc_call($client, 'count', [$sid,$type,$ou,$filter]);
  print "$res\n";
}

sub command_cd
{
  my ($path) = @_;
  if (! defined $path) {
    $path = $base;
  }
  if (!($path =~ m/$base$/)) {
    if (!($path =~ m/,$/)) {
      $path .= ',';
    }
    $path .= $current_base;
  }
  $current_base = $path;
}

sub command_cat
{
  my ($type, $path, $tab) = @_;
  if (defined $path) {
    if (!($path =~ m/$base$/)) {
      if (!($path =~ m/,$/)) {
        $path .= ',';
      }
      $path .= $current_base;
    }
  }
  my $fields = rpc_call($client, 'fields', [$sid,$type,$path,$tab]);
  if (ref $fields eq ref {}) {
    foreach my $section (values %$fields) {
      print '['.$section->{'name'}.']'."\n";
      if (ref $section->{'attrs'} eq ref []) {
        foreach my $field (@{$section->{'attrs'}}) {
          show_field($field);
        }
      }
    }
  }
}

sub show_field
{
  my ($field) = @_;
  foreach my $type (@{$field->{'type'}}) {
    if (grep {$type eq $_} ('StringAttribute', 'DisplayAttribute')) {
      printf ("\t%-22s %s\n", $field->{'label'}.':', $field->{'value'});
      return;
    }
  }
  # Default display
  if (ref($field->{'value'}) ne 'ARRAY') {
    printf ("\t%-22s %s\n", $field->{'label'}.':', $field->{'value'});
  } else {
    printf ("\t%-22s %s", $field->{'label'}.':', Dumper($field->{'value'}));
  }
}

sub ask_field
{
  my ($field) = @_;
  foreach my $type (@{$field->{'type'}}) {
    if (grep {$type eq $_} ('StringAttribute', 'IntAttribute')) {
      return $term->{term}->readline($field->{'label'}.": ");
    } elsif ($type eq 'SelectAttribute') {
      print $field->{'label'}.":\n";
      my $i = 0;
      my @keys = keys(%{$field->{'choices'}});
      if (scalar(@keys) eq 0) {
        return '';
      }
      for ($i = 0; $i < @keys; $i++) {
        my $key   = $keys[$i];
        my $label = ${$field->{'choices'}}{$key};
        print $i.":$label ($key)\n";
        #~ if ($id eq $field->{'value'}) {
      }
      my $choice;
      do {
        $choice = $term->{term}->readline("Choice: ");
      } while (($choice eq '') || ($choice =~ m/[^0-9]/) || ($choice >= scalar(@keys)));
      return $keys[$choice];
    }
  }
  die("Don't know how to prompt for the attribute of types ".join(',',@{$field->{'type'}}));
}

sub command_infos
{
  my ($type) = @_;
  my $infos = rpc_call($client, 'infos', [$sid, $type]);
  while (my ($name, $value) = each(%$infos)) {
    if ($name eq 'tabs') {
      print "tabs:\n";
      foreach my $tab (@$value) {
        print "\t".$tab->{'NAME'}."\t(".$tab->{'CLASS'}.")\n";
      }
    } else {
      printf ("%-22s %s\n", $name.':', $value);
    }
  }
}

sub command_types
{
  my $types = rpc_call($client, 'listTypes', [$sid]);
  while (my ($type, $display) = each(%$types)) {
    printf ("%-30s %s\n", $display, $type);
  }
}

__END__

=head1 NAME

fusiondirectory-shell - A shell to act on FusionDirectory handled objects

=head1 SYNOPSIS

B<fusiondirectory-shell> [I<options>]

=head1 DESCRIPTION

B<fusiondirectory-shell> will connect you to FusionDirectory webservice and allow you to list, display and alter objects.

=head1 OPTIONS

=over 8

=item B<-h>, B<--help>

Print a brief help message and exits.

=item B<-u>, B<--url>=I<HOST>

Use HOST instead of https://localhost/fusiondirectory/jsonrpc.php

=item B<-l>, B<--login>=I<LOGIN>

User login to send

=item B<-p>, B<--password>=I<PWD>

User password to send

=item B<-c>, B<--ca>=I<FILE>

Use CA file FILE to check the server identity

=item B<-s>, B<--server>=I<SERVER>

Use SERVER ldap server on the FusionDirectory instance to connect (if FusionDirectory has several LDAP server configured)

=back

=head1 BUGS

Please report any bugs, or post any suggestions, to the fusiondirectory mailing list fusiondirectory-users or to <https://forge.fusiondirectory.org/projects/fusiondirectory/issues/new>

=head1 AUTHOR

Come Bernigaud

=head1 LICENCE AND COPYRIGHT

=over 2

=item Copyright (C) 2013-2015 FusionDirectory project

=back

License BSD

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the LICENSE file for more details.

=cut