Created
August 16, 2012 13:03
-
-
Save syxanash/3369961 to your computer and use it in GitHub Desktop.
a GUI for AESCrypt on GNU/Linux
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
# AESCrypt GUI for GNU/Linux | |
# DWTFYWT (c) syxanash | |
use strict; | |
use warnings; | |
use IPC::Open3; | |
use Symbol qw(gensym); | |
my ( $output, $passphrase ); | |
chomp( my $file_name = `zenity --file-selection --title="Select the file"` ); | |
if ( $file_name eq q{} ) { | |
system('zenity --error --title="AESCrypt GNU/Linux" --text="Select a valid file\!"'); | |
exit; | |
} | |
elsif ( $file_name =~ m{^(.+)\.aes$} ) { | |
chomp( $output = `zenity --entry --title="AESCrypt GNU/Linux" --text="Enter password for decryption" --hide-text`); | |
$passphrase = check_output($output); | |
$output = catch_stderr("aescrypt -d -p $passphrase $file_name"); | |
check_output_error( $output, 'File successfully decoded\!' ); | |
} | |
else { | |
chomp( $output = `zenity --entry --title="AESCrypt GNU/Linux" --text="Enter password for encryption" --hide-text` ); | |
$passphrase = check_output($output); | |
chomp( $output = `zenity --entry --title="AESCrypt GNU/Linux" --text="Please type again the password" --hide-text` ); | |
if ( $passphrase ne check_output($output) ) { | |
system( 'zenity --error --title="AESCrypt GNU/Linux" --text="Password doesn\'t match!"' ); | |
exit; | |
} | |
$output = catch_stderr("aescrypt -e -p $passphrase $file_name"); | |
check_output_error( $output, 'File successfully encoded\!' ); | |
} | |
sub check_output { | |
my $output = shift; | |
if ( $output eq q{} ) { | |
system( 'zenity --error --title="AESCrypt GNU/Linux" --text="Enter a valid key!"' ); | |
exit; | |
} | |
return $output; | |
} | |
sub check_output_error { | |
my $output = shift; | |
my $success_message = shift; | |
system( | |
( $output =~ m{error}i ) | |
? 'zenity --error --title="AESCrypt GNU/Linux" --text="' . $output . '"' | |
: 'zenity --info --title="AESCrypt GNU/Linux" --text="' . $success_message . '"' | |
); | |
} | |
sub catch_stderr { | |
my $command = shift; | |
my $pid = open3( gensym, ">&STDERR", \*PH, $command ); | |
while (<PH>) { | |
return $_; | |
} | |
waitpid( $pid, 0 ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment