/[pxelator]/lib/PXElator/amt.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /lib/PXElator/amt.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 482 - (show annotations)
Sat Jan 23 18:31:14 2010 UTC (14 years, 2 months ago) by dpavlin
File size: 1644 byte(s)
use store::audit proxy all over the place

1 package amt;
2
3 use warnings;
4 use strict;
5
6 use lib '/srv/Intel-AMT/lib/';
7 use Intel::AMT::RemoteControl;
8 use Intel::AMT::NetworkAdministration;
9 use Intel::AMT::EventManager;
10 use Data::Dump qw/dump/;
11 use Regexp::Common qw/net/;
12
13 use html;
14 use ping;
15 use store;
16 use Carp qw/confess/;
17
18 sub ip {
19 my ( $client_ip, $amt ) = @_;
20 return unless $client_ip;
21 $amt ||= client::conf( $client_ip => 'amt' );
22 my ( $passwd, $ip ) = split(/\s+/, $amt);
23 ( $ip, $passwd ) = ( $passwd, $ip ) if $passwd =~ m/$RE{net}{IPv4}/;
24
25 $ip ||= $client_ip;
26
27 $ENV{AMT_PASSWORD} = $passwd;
28 $ENV{AMT_HOST} = $ip;
29
30 my $hostname = client::conf( $client_ip => 'hostname' ) || $client_ip;
31
32 client::conf( $ip => 'hostname', default => "amt-$hostname" );
33
34 return $ip;
35 }
36
37 sub power_state {
38 my $state = eval { Intel::AMT::RemoteControl::SystemPowerState };
39 store::audit('SystemPowerState', { ip => $ENV{AMT_HOST}, SystemPowerState => $state });
40 return $state;
41 }
42
43 sub power_on {
44 ip @_;
45 my $state = power_state;
46 defined $state && ( $state & 0x0f ) == 0;
47 }
48
49 sub network {
50 ip @_;
51
52 my $amt = eval { Intel::AMT::NetworkAdministration::network_settings };
53 if ( $@ ) {
54 warn "ERROR $@";
55 } else {
56 $amt->{ip} = $ENV{AMT_HOST};
57 store::audit('log', $amt );
58 }
59 $amt;
60 }
61
62 sub log {
63 ip @_;
64
65 my $amt = eval { Intel::AMT::EventManager::ReadEventLogRecords };
66 if ( $@ ) {
67 warn "ERROR $@";
68 } else {
69 $amt->{ip} = $ENV{AMT_HOST};
70 store::audit('log', $amt );
71 }
72 $amt;
73 }
74
75 sub RemoteControl {
76 ip shift;
77 my $command = shift;
78 eval { Intel::AMT::RemoteControl::run( $command ) };
79 store::audit( $command, { ip => $ENV{AMT_HOST}, error => $@ } );
80 warn "ERROR $@" if $@;
81 }
82
83 1;

  ViewVC Help
Powered by ViewVC 1.1.26