Changeset 1280


Ignore:
Timestamp:
03/17/15 18:24:50 (9 years ago)
Author:
nanardon
Message:

add log inside database tracking big objects event and some attributes

Location:
trunk/LATMOS-Accounts
Files:
1 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/LATMOS-Accounts/Makefile.PL

    r1277 r1280  
    6161        bin/la-sql-updsshfp 
    6262        bin/la-test-mail 
     63        bin/la-sql-log 
    6364        ) ], 
    6465        macro => { 
  • trunk/LATMOS-Accounts/bin/la-sql-switch-cname

    r1277 r1280  
    99=head1 NAME 
    1010 
    11     la-exchange-ip - Exchange IP between two host 
     11    la-sql-switch-cname - Exchange (c)name between two host 
    1212 
    1313=head1 SYNOPSIS 
    1414 
    15     la-exchange-ip ip1 ip2 
     15    la-exchange-ip cname [cname] [-a name] desthost 
    1616 
    1717Example : la-rename-host foo bar 
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql.pm

    r1135 r1280  
    637637} 
    638638 
     639sub getobjectlogs { 
     640    my ($self, $otype, $name) = @_; 
     641 
     642    my $sth = $self->db->prepare(q{ 
     643        select ikey from objectslogs where 
     644            otype = ? and 
     645            name  = ? 
     646        group by ikey 
     647    }); 
     648    $sth->execute($otype, $name); 
     649    my @ids; 
     650    while (my $res = $sth->fetchrow_hashref) { 
     651        push(@ids, $res->{ikey}); 
     652    } 
     653    @ids or return; 
     654 
     655    my $sth2 = $self->db->prepare(sprintf( 
     656        q{ 
     657            select * from objectslogs where ikey IN (%s) 
     658            order by logdate asc 
     659        }, 
     660        join(',', ('?') x scalar(@ids)) 
     661    )); 
     662 
     663    $sth2->execute(@ids); 
     664    my @logs; 
     665    while (my $res = $sth2->fetchrow_hashref) { 
     666        push(@logs, $res); 
     667    } 
     668 
     669    return @logs; 
     670} 
     671 
     672sub getlogs { 
     673    my ($self) = @_; 
     674    my $sth2 = $self->db->prepare( 
     675        q{ 
     676            select * from objectslogs  
     677            where logdate > now() - '1 year'::interval  
     678            order by logdate asc 
     679        }, 
     680    ); 
     681 
     682    $sth2->execute(); 
     683    my @logs; 
     684    while (my $res = $sth2->fetchrow_hashref) { 
     685        push(@logs, $res); 
     686    } 
     687 
     688    return @logs; 
     689} 
     690 
    6396911; 
    640692 
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/Aliases.pm

    r1161 r1280  
    3333                mandatory => 1, 
    3434                multiple => 1, 
     35                notify => 1, 
    3536            }, 
    3637            finalpoint      => { ro => 1, multiple => 1 }, 
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/Group.pm

    r1238 r1280  
    6262            groupname  => { ro => 1 }, 
    6363            managedBy  => { 
     64                notify => 1, 
    6465                reference => 'user', 
    6566                can_values => sub { 
     
    7172            }, 
    7273            managedAlsoBy  => { 
     74                notify => 1, 
    7375                reference => 'user', 
    7476                multiple => 1, 
     
    8385            sutype => { 
    8486                reference => 'sutype', 
     87                notify => 1, 
    8588            }, 
    8689            autoMemberFilter => { 
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/Nethost.pm

    r1225 r1280  
    3232            create  => { ro => 1, inline => 1, }, 
    3333            ip      => { 
     34                notify => 1, 
    3435                multiple => 1, 
    3536                uniq => 1, 
     
    4849            }, 
    4950            macaddr => { 
     51                notify => 1, 
    5052                multiple => 1, 
    5153                uniq => 1, 
     
    5658            }, 
    5759            cname   => { 
     60                notify => 1, 
    5861                multiple => 1, uniq => 1, 
    5962                input => sub { lc($_[0]) }  
    6063            }, 
    61             owner   => {  
     64            owner   => { 
     65                notify => 1, 
    6266                reference => 'user', 
    6367                delayed => 1, 
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/Netzone.pm

    r1064 r1280  
    3434            date    => { ro => 1, inline => 1, }, 
    3535            create  => { ro => 1, inline => 1, }, 
    36             net     => { multiple => 1 }, 
    37             netExclude => { multiple => 1 }, 
     36            net     => { multiple => 1, notify => 1, }, 
     37            netExclude => { multiple => 1, notify => 1, }, 
    3838            group   => { hide => 1 }, 
    3939            allow_dyn => { 
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/User.pm

    r1219 r1280  
    5151                mandatory => 1, 
    5252                formopts => { length => 7 }, 
     53                notify => 1, 
    5354            }, 
    5455            uidnumber => { inline => 1, hide => 1, }, 
    55             gidNumber => {  
     56            gidNumber => { 
     57                notify => 1, 
    5658                inline => 1, 
    5759                iname => 'gidnumber', 
     
    8385                inline => 1, 
    8486                formtype => 'CHECKBOX', 
     87                notify => 1, 
    8588            }, 
    8689            locked    => { 
    8790                formtype => 'CHECKBOX', 
    8891                formopts => { rawvalue => 1, }, 
    89             }, 
    90             expire    => { inline => 1, formtype => 'DATE', }, 
     92                notify => 1, 
     93            }, 
     94            expire    => { inline => 1, formtype => 'DATE', notify => 1, }, 
    9195            name      => { inline => 1, ro => 1, }, 
    9296            cn        => { 
     
    144148                }, 
    145149                reference => 'user', 
     150                notify => 1, 
    146151            }, 
    147152            department => { 
     
    149154                can_values => sub { 
    150155                    $base->search_objects('group', 'sutype=dpmt') 
    151                 } 
     156                }, 
     157                notify => 1, 
    152158            }, 
    153159            contratType => { 
     
    155161                can_values => sub { 
    156162                    $base->search_objects('group', 'sutype=contrattype') 
    157                 } 
     163                }, 
     164                notify => 1, 
    158165            }, 
    159166            site => { 
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/objects.pm

    r1153 r1280  
    101101        } 
    102102    } 
    103     $info->{exported}   = { inline => 1, formtype => 'CHECKBOX', hide => 1, }; 
     103    $info->{exported}   = { inline => 1, formtype => 'CHECKBOX', hide => 1, notify => 1 }; 
    104104    $info->{unexported} = { inline => 1, formtype => 'CHECKBOX', }; 
    105105 
     
    178178    $sth->execute(map { $first{$_} || undef } sort keys %first) or return; 
    179179 
    180     $class->new($base, $id)->set_fields(%second); 
     180    my $obj = $class->new($base, $id); 
     181    $obj->objectlog('Create', 'Object created'); 
     182    foreach (keys %first) { 
     183        my $attr = $obj->attribute($_); 
     184        $obj->objectlog('Attribute', '%s set to %s', $_, ( 
     185                defined($data{$_})  
     186                ? (ref $data{$_} 
     187                    ? join(', ', @{ $data{$_} }) 
     188                    : $data{$_}) 
     189                : '(none)')) 
     190            if ($attr->{notify}); 
     191    } 
     192    $obj->set_fields(%second); 
    181193 
    182194    1; 
     
    185197sub _delete { 
    186198    my ($class, $base, $id) = @_; 
     199 
     200    my $obj = $base->get_object($class->type, $id) 
     201        or return; 
     202    $obj->objectlog('Delete', 'Object deleted'); 
    187203 
    188204    my $sthd = $base->db->prepare_cached( 
     
    199215    my ($class, $base, $id, $newid) = @_; 
    200216 
     217    { 
     218        my $obj = $base->get_object($class->type, $id) 
     219            or return; 
     220        $obj->objectlog('Rename', 'Object rename to %s', $newid); 
     221    } 
     222 
    201223    my $sthr = $base->db->prepare_cached( 
    202224        sprintf( 
     
    214236        ); 
    215237        return; 
     238    } 
     239 
     240    { 
     241        my $obj = $base->get_object($class->type, $newid) 
     242            or return; 
     243        $obj->objectlog('Rename', 'Object renamed from %s', $id); 
    216244    } 
    217245    1; 
     
    290318sub set_fields { 
    291319    my ($self, %data) = @_; 
    292     my $updated_attributes = 0; 
     320    my @updated_attributes = (); 
    293321    my @fields; 
    294322    my @vals; 
     
    309337            push(@fields, sprintf("%s = ?", $self->db->quote_identifier($field))); 
    310338            push(@vals, $data{$field}); 
     339            push(@updated_attributes, $field); 
    311340        } else { 
    312341            $ext{$field} = $data{$field}; 
     
    330359            return; 
    331360        }; 
    332         $updated_attributes = scalar(@fields); 
    333361    } 
    334362     
     
    399427                        $updated++; 
    400428                    } 
    401                     $updated_attributes++ if ($updated); 
     429                    push(@updated_attributes, $uattr) if ($updated); 
    402430                } else { 
    403431                    my $res = $sthu->execute($ext{$uattr}, $okey, $uattr); 
     
    410438                            $self->base->db->errstr 
    411439                        ); 
    412                         $updated_attributes++; 
    413440                        return; 
    414441                    }; 
     
    423450                                $self->base->db->errstr 
    424451                            ); 
    425                             $updated_attributes++; 
    426452                            return; 
    427453                        }; 
    428454                    } 
     455                    push(@updated_attributes, $uattr); 
    429456                } 
    430457            } else { 
     
    440467                }; 
    441468            } 
    442             $updated_attributes++; 
    443469        } 
    444470    } 
    445471 
    446472    delete($self->base->{__cache}{"_" . $self->type}{$self->id}); 
    447     $updated_attributes; 
     473    $self->objectlog('Update', 'Attributes %s where updated', join(', ', @updated_attributes)) 
     474        if(@updated_attributes); 
     475    foreach (@updated_attributes) { 
     476        my $attr = $self->attribute($_); 
     477        $self->objectlog('Attribute', '%s set to %s', $_, ( 
     478                defined($data{$_})  
     479                ? (ref $data{$_} 
     480                    ? join(', ', @{ $data{$_} }) 
     481                    : $data{$_}) 
     482                : '(none)')) 
     483            if ($attr->{notify}); 
     484    } 
     485    scalar(@updated_attributes); 
    448486} 
    449487 
     
    483521        my $salt = join('', map { $salt_char[rand(scalar(@salt_char))] } (1 .. 8)); 
    484522        my $res = $self->set_fields($field, crypt($clear_pass, '$1$' . $salt)); 
     523        my $asymencrypted = 0; 
    485524        if ($res) { 
    486525 
     
    501540                    return; 
    502541                } 
     542                $asymencrypted = 1; 
    503543            } 
    504544            $self->base->log(LA_NOTICE, 
     
    506546                $self->id 
    507547            ); 
     548            $self->objectlog('Password', 'user password has changed%s', ($asymencrypted ? ' and stored using internal key' : '')); 
    508549            return 1; 
    509550        } 
     
    708749} 
    709750 
    710  
     751=head2 objectlog 
     752 
     753=cut 
     754 
     755sub objectlog { 
     756    my ($self, $changetype, $message, @args) = @_; 
     757 
     758    my $sth = $self->base->db->prepare(q{ 
     759        INSERT into objectslogs (ikey, otype, name, changetype, username, message) 
     760        VALUES (?,?,?,?,?,?) 
     761    }); 
     762 
     763    $sth->execute( 
     764        $self->_get_ikey, 
     765        $self->type, 
     766        $self->id, 
     767        $changetype, 
     768        $self->base->user || '@Console', 
     769        sprintf($message, @args), 
     770    ); 
     771} 
    711772 
    7127731; 
Note: See TracChangeset for help on using the changeset viewer.