全体表示

[ リスト ]

ID_Pass_seed.pmとID_Pass.pm

package ID_Pass_seed;
use strict;
require Exporter;
our @ISA = qw(Exporter);

our @EXPORT_OK = qw (
$crypt_key
%Item_Names
);

our $crypt_key = 'opensesami';#ID Managerで作ったランダムな文字列を使うと良い
our %Item_Names = ();

my @Item_Names = ( #perl script中で使うものだけ列挙する
'Yahoo',
'NiftyMail',
'平塚図書館',
);

for my $name (@Item_Names) {
$Item_Names{$name}++;
}

1;


package ID_Pass;
use strict;
use XML::Simple;
use Data::Dumper;
use Encode qw (from_to);
use Archive::Zip qw( :ERROR_CODES );
use ID_Pass_seed qw (
$crypt_key
%Item_Names
);
use Crypt::CBCeasy;

my $DEBUG;# = 1;
my $tmp = './';
my $idpass = 'idpass.dmp';

sub new {
my $pkg = shift;
my %arg = @_;
my $self = {};
bless $self, $pkg;

my $xml = $self->{xml} = $arg{xml};
my $zip = $self->{zip} = $arg{zip};
$self->{tmp} = $tmp.$idpass;

if ($zip && -e $zip && $xml && -e $xml) {
if ((stat $zip)[9] <= (stat $xml)[9]) {
unlink $zip;
} else {
unlink $xml;
}
}
if ($zip && -e $zip) {
my $info = $self->get_zip_info();
$self->{info} = $info;
}
elsif ($xml && -e $xml) {
my $info = $self->get_xml_info();
$self->{info} = $info;
#print Dumper $self;exit;
if ($zip) {
$self->create_zip();
unlink $xml;
}
}
$self;
}

sub url {
my $this = shift;
my $name = shift;
my $r = $this->{info}->{$name}->{url};
}

sub account {
my $this = shift;
my $name = shift;
my $r = $this->{info}->{$name}->{account};
}

sub password {
my $this = shift;
my $name = shift;
my $r = $this->{info}->{$name}->{password};
}


sub get_xml_info {
my $this = shift;
undef $/;
open my $fh, $this->{xml};
my $xml = <$fh>;
close $fh;

$xml =~ s/shift[-_]jis/UTF-8/;
from_to($xml, 'cp932', 'utf8');
utf8::encode($xml);

my $xml_lib = XMLin(
$xml,
KeyAttr => {},
ForceArray => [ 'item' ],
ContentKey => '-content'
);
$Data::Dumper::Terse = 1;
my $dump = Dumper $xml_lib;
$Data::Dumper::Terse = 0;
utf8::decode($dump);
from_to($dump, 'utf8', 'cp932');
#print $dump,"\n";

$xml_lib = eval $dump;
my $info = {};
my $folders = $xml_lib->{folder};
for my $folder (@$folders) {
my $items = $folder->{item};
for my $item (@$items) {
my $item_name = $item->{name};
next unless $Item_Names{$item_name};
$info->{$item_name} = {
url => $item->{url},
account => $item->{account}->{content},
password => $item->{password}->{content},
};
}
}
#print Dumper $info,"\n";
$info;
}


sub create_zip {
my $this = shift;
$Data::Dumper::Terse = 1;
my $info_dump = Dumper $this->{info};
$Data::Dumper::Terse = 0;
open my $fh, '>'.$this->{tmp};
if ($DEBUG) {
print $fh $info_dump;
} else {
IDEA::encipher( $crypt_key, $info_dump, $fh);
}
close $fh;
my $zip = Archive::Zip->new();
$zip->addFile($this->{tmp});
$zip->writeToFileNamed($this->{zip});
unlink $this->{tmp};
}

sub get_zip_info {
my $this = shift;
my $zip = Archive::Zip->new();
die 'Archive File Read Error' unless $zip->read($this->{zip}) == AZ_OK;
$zip->extractMember($idpass, $this->{tmp});
my $info_dump;
open my $fh, $this->{tmp};
if ($DEBUG) {
undef $/;
$info_dump = <$fh>;
} else {
$info_dump = IDEA::decipher( $crypt_key, $fh);
}
close $fh;
unlink $this->{tmp};
$this->{info} = eval $info_dump;
}

1;

閉じる コメント(0)

コメント投稿

顔アイコン

顔アイコン・表示画像の選択

名前パスワードブログ
絵文字
×
  • オリジナル
  • SoftBank1
  • SoftBank2
  • SoftBank3
  • SoftBank4
  • docomo1
  • docomo2
  • au1
  • au2
  • au3
  • au4
投稿

.


プライバシー -  利用規約 -  メディアステートメント -  ガイドライン -  順守事項 -  ご意見・ご要望 -  ヘルプ・お問い合わせ

Copyright (C) 2019 Yahoo Japan Corporation. All Rights Reserved.

みんなの更新記事