|
1.
ActivePerl-5.8.4.810-MSWin32-x86.msi
在windows电脑上安装此文件...
2.
- #! /usr/bin/perl -w
- # 產生簽名 => 輸出公共key => 印出 key id
- use IO::Handle;
- use Fcntl;
- use Net::FTP;
- use Win32::Console;
- use Win32::Process;
- use Win32;
- if($^O !~ /win32/i) { print STDERR "本工具必須在 windows 上執行\n"; exit 1; }
- $env = Win32::GetOSName();
- if($env =~ /^Win95$/i || $env =~ /^Win32s/ || $env =~ /^WinNT3/)
- {
- print STDERR '抱歉,本工具僅支援 windows 98 及 nt4 以上!請聯絡 mis' . "\n";
- exit 1;
- }
- elsif($env =~ /^Win98$/i || $env =~ /^WinMe/)
- {
- $sysrp = 'C:\\WINDOWS';
- $sysdv = 'C:';
- }
- else
- {
- $sysrp = $ENV{'SystemRoot'};
- $sysdv = $ENV{'SystemDrive'};
- }
- # $con = new Win32::Console(STD_INPUT_HANDLE);
- $con1 = new Win32::Console(STD_OUTPUT_HANDLE);
- # $con->Mode(ENABLE_PROCESSED_INPUT);
- $con1->Title('auto sign utility for Excell Precisions Co');
- $con1->Cls();
- $con1->Display();
- $attr = $con1->Attr();
- *gpg = "c:\\gnupg-w32cli-1.2.1-1\\gpg.exe";
- if(! -f $sysrp . "\\unzip.exe")
- {
- $con1->Write('下載unzip.exe..' . "\n");
- $ftp = Net::FTP->new("linux1", Debug => 0);
- $ftp->login("anonymous",'anonymous@');
- $ftp->binary();
- $ftp->cwd("/win32");
- $ftp->get('unz542xN.exe',$sysrp . "\\unz542xN.exe");
- $ftp->quit();
- Win32::SetCwd($sysrp);
- system('unz542xN.exe');
- unlink 'unz542xN.exe';
- }
- if(! -f $gpg)
- {
- $con1->Write('下載gpg..' . "\n");
- Win32::SetCwd('C:\\');
- if(! -d 'gnupg-w32cli-1.2.1-1')
- {
- system("md gnupg-w32cli-1.2.1-1");
- }
- Win32::SetCwd('C:\\gnupg-w32cli-1.2.1-1');
- $ftp = Net::FTP->new("linux1", Debug => 0);
- $ftp->login("anonymous",'anonymous@');
- $ftp->binary();
- $ftp->cwd("/win32");
- $ftp->get('gnupg-w32cli-1.2.1-1.zip',"c:\\gnupg-w32cli-1.2.1-1\\gnupg-w32cli-1.2.1-1.zip");
- $ftp->quit();
- system('unzip.exe gnupg-w32cli-1.2.1-1.zip');
- unlink 'gnupg-w32cli-1.2.1-1.zip';
- }
- $con1->Write('下載相關工具..' . "\n");
- $ftp = Net::FTP->new("linux1", Debug => 0);
- $ftp->login("anonymous",'anonymous@');
- $ftp->binary();
- $ftp->cwd("/win32");
- $ftp->get('autosign.bat',"c:\\autosign.bat");
- $ftp->get('autosign.pl',"c:\\autosign.pl");
- $ftp->get('check_sign.pl',$sysrp . "\\check_sign.pl");
- $ftp->get('sign.pl',$sysrp . "\\sign.pl");
- $ftp->quit();
- Win32::SetCwd($sysdv);
- $con1->Write('請問您是否已有電子鎖?(y:是/n:否) ');
- # $ans = $con->InputChar(1);
- # $con->Flush();
- $ans = <STDIN>;
- $aa = lc(substr($ans,0,1));
- if($aa eq 'y')
- {
- exit 0;
- }
- if(!(-d "c:\\gnupg"))
- {
- system "md c:\\gnupg";
- }
- do
- {
- $con1->Write('請輸入員工編號(4個數字):' . "\n");
- # $idnum = $con->InputChar(4);
- # $con->Flush();
- $idnum = <STDIN>;
- chomp($idnum);
- } while($idnum !~ /^\d{4}$/);
- open OUT,"> c:\\gnupg\\h.sign";
- print OUT $idnum;
- close OUT;
- $idnum = 'a' . $idnum;
- do
- {
- $con1->Write('請輸入公司分派之電子郵件地址:' . "\n");
- $email = <STDIN>;
- chomp($email);
- $email = lc($email);
- (@efd) = ($email =~ /^.+\@(.+)\.(.+)\.(.+)\.(.+)$/);
- } while(!defined(@efd) || $efd[1] ne 'excell' || $efd[2] ne 'com' ||
- $efd[3] ne 'tw');
- $con1->Write('現在將輸入密碼, 請注意不要被四周的人看到!' . "\n");
- do
- {
- $con1->Write('請輸入解鎖密碼(注意!請不要讓別人知道此密碼, ?K牢記此密碼):' . "\n");
- $pas = &getpass;
- $con1->Write('請再輸入一次確定' . "\n");
- $pas1 = &getpass;
- if($pas ne $pas1)
- {
- $con1->Write('兩次密碼?K不相符。' . "\n");
- }
- } while($pas ne $pas1);
- $con1->Write('請盡量快速移動滑鼠直到完成為止..' . "\n");
- sleep 1;
- open OUT,"| $gpg --batch --gen-key";
- print OUT <<EOF
- Key-Type: DSA
- Key-Length: 1024
- Subkey-Type: ELG-E
- Subkey-Length: 1024
- Name-Real: $idnum
- Name-Comment: $efd[0]
- Name-Email: $email
- Expire-Date: 0
- Passphrase: $pas
- #
- %commit
- EOF
- ;
- close OUT;
- # export
- system "$gpg --keyserver linux1 --send-keys " . $idnum;
- # 取得 public key id
- @pk = split(/\n/,`$gpg --list-public-keys $idnum`);
- $pkn = substr($pk[0],11,8);
- $con1->Write('自動下載檢查碼..' . "\n");
- $ftp = Net::FTP->new("linux1", Debug => 0);
- $ftp->login("anonymous",'anonymous@');
- $ftp->binary();
- $ftp->get('listsig',"c:\\gnupg\\listsig.txt");
- $ftp->quit();
- open IN,"< c:\\gnupg\\listsig.txt";
- $linein = <IN>;
- $con1->Write($linein);
- close IN;
- Win32::MsgBox("已經完成!\n您的電子鎖位於 c:\\gnupg 目錄內, 請小心保存.\n" .
- "您的公共鎖號碼為:" . $pkn . "\n請告知相關單位, 謝謝.\n檢查碼為:" . $linein .
- '請核對是否正確.' . "\n",0);
- exit 0;
- sub getpass
- {
- my ($pas);
- $con1->Attr($FG_WHITE | $BG_WHITE);
- $pas = <STDIN>;
- $con1->Attr($attr);
- $con1->Write("\n");
- chomp($pas);
- return $pas;
- }
- 转发此代码,请注明出处...Kevin
复制代码 |
|