# Copyright (c) 2009 bivio Software Inc. All Rights Reserved. # # Visit http://www.bivio.biz for more info. # # This library is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as # published by the Free Software Foundation; either version 2.1 of the # License, or (at your option) any later version. # # This library 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 GNU # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; If not, you may get a copy from: # http://www.opensource.org/licenses/lgpl-license.html # # $Id: TaskLog.pm,v 2.5 2010/03/12 04:11:37 nagler Exp $ package Bivio::Util::TaskLog; use strict; use Bivio::Base 'Bivio.ShellUtil'; our($VERSION) = sprintf('%d.%02d', q$Revision: 2.5 $ =~ /\d+/g); my($_DT) = b_use('Type.DateTime'); my($_T) = b_use('Type.Text'); sub USAGE { my($proto) = @_; return <<"EOF"; usage: bivio @{[$proto->simple_package_name]} [options] command [args..] commands import_access_log -- import access_log data from STDIN test_reset -- remove all entries [test only] EOF } sub import_access_log { my($self) = @_; $self->initialize_ui; my($count) = 0; foreach my $line (split("\n", ${$self->read_input})) { my($user, $date, $method, $uri, $response_code) = $line =~ /^\S+ [\d\.]+ \d+ \- (\S+) \[(.*?)\] \"(\w+) (\S+) .*?" (\d+)/; next unless $response_code && $response_code =~ /200|302/; my(undef, $su_id, $u_id) = $user =~ /^(su-(\d+)-)?li-(\d+)$/; my($task_id, $auth_realm) = b_use('FacadeComponent.Task') ->parse_uri($uri, $self->req); $self->model('TaskLog')->create({ realm_id => $auth_realm->unsafe_get('owner') ? $auth_realm->get('owner')->get('realm_id') : $auth_realm->get('id'), user_id => $u_id, super_user_id => $su_id, date_time => _parse_date($date), task_id => $task_id, method => $method, uri => $_T->clean_and_trim($uri), }); $count++; } return "imported $count records\n"; } sub test_reset { my($self) = @_; $self->req->assert_test; $self->model('TaskLog')->test_unauth_delete_all; return; } sub _parse_date { my($date) = @_; my($mday, $mon, $year, $hour, $min, $sec) = split("/|:| ", $date); return $_DT->from_local_literal( $_DT->from_parts_or_die($sec, $min, $hour, $mday, $_DT->english_month3_to_int($mon), $year)); } 1;