#!/usr/bin/perl

# This example shows how you can request what variables are available for modification from the remote plugin through the master dameon

use IAMd;

my $remote_host = "127.0.0.1";
my $remote_port = "1077";
my $protocol = "tcp";
my $answer;
my $configdir = "/etc/IAM";

open (PADDING, "$configdir/OTP_clientpad");
my $padding = <PADDING>;
close (PADDING);
wait;

my $iamd = eval { IAMd->new($remote_host, $remote_port, "ssl", $padding); };
#$iamd->debug_on;
eval { $iamd->connect; };
if ($@) {
  $args{errmsg} = 'Connection of IAM daemon failed!!!';
}
  
print "***********************************************************************************\n";
print "Display fields for DIALUP-RADIUS:      \n";
$result = $iamd->request("fields","modify","joe\@domain.com","DIALUP-RADIUS");
if ($result =~ /0.*/) {
  @resultarray = $iamd->arrayofhashes($result);

  print "length=". scalar @resultarray ."\n";

  foreach $hashref (@resultarray) {
    foreach $key (keys %{$hashref}) {
      if ($key =~ /\0/) {
        print "*****************************************\n";
      }
      else {
        print "Key: $key\t\tValue: $hashref->{$key}\n";
      }
    }
  }
}
else { print $result."\n"; }

print "***********************************************************************************\n";
$iamd->disconnect;
exit;

