App-Greple-pw

 view release on metacpan or  search on metacpan

lib/App/Greple/pw.pm  view on Meta::CPAN

package App::Greple::pw;

our $VERSION = "1.02";

=head1 NAME

pw - Interactive password and ID information extractor for greple


=head1 SYNOPSIS

    # Basic usage
    greple -Mpw pattern file

    # Search in encrypted files
    greple -Mpw password ~/secure/*.gpg

    # Configure options
    greple -Mpw --no-clear-screen --chrome password data.txt
    greple -Mpw --config timeout=600 --config debug=1 password file.txt


=head1 VERSION

Version 1.02


=head1 DESCRIPTION

The B<pw> module is a B<greple> extension that provides secure, interactive
handling of sensitive information such as passwords, user IDs, and account
details found in text files. It is designed with security in mind, ensuring
that sensitive data doesn't remain visible on screen or in terminal history.

=head2 Key Features

=over 4

=item * B<Interactive password handling>

Passwords are masked by default and can be safely copied to clipboard
without displaying the actual content on screen.

=item * B<Secure cleanup>

Terminal scroll buffer and screen are automatically cleared when the
command exits, and clipboard content is replaced with a harmless string
to prevent sensitive information from persisting.

=item * B<Encrypted file support>

Seamlessly works with PGP encrypted files using B<greple>'s standard
features. Files with "I<.gpg>" extension are automatically decrypted,
and the B<--pgp> option allows entering the passphrase once for
multiple files.

=item * B<Intelligent pattern recognition>

Automatically detects ID and password information using configurable
keywords like "user", "account", "password", "pin", etc. Custom
keywords can be configured to match your specific data format.

=item * B<Browser integration>

Includes browser automation features for automatically filling web
forms with extracted credentials.

=back

Some banks use random number matrices as a countermeasure for tapping.
If the module successfully guesses the matrix area, it blacks out the
table and remembers them.

    | A B C D E F G H I J
  --+--------------------
  0 | Y W 0 B 8 P 4 C Z H
  1 | M 0 6 I K U C 8 6 Z
  2 | 7 N R E Y 1 9 3 G 5
  3 | 7 F A X 9 B D Y O A
  4 | S D 2 2 Q V J 5 4 T

Enter the field positions to get the cell items like:

    > E3 I0 C4

and you will get the answer:

    9 Z 2

Case is ignored and white space is not necessary, so you can type like
this as well:

    > e3i0c4


=head1 INTERFACE

=begin comment

=head2 Internal Functions (for developers)

=over 7

=item B<pw_print>

Data print function.  This function is set for the B<--print> option of
B<greple> by default, and users don't have to care about it.

=item B<pw_epilogue>

Epilogue function.  This function is set for the B<--end> option of
B<greple> by default, and users don't have to care about it.

=back

=end comment

=over 7

=item B<config>

lib/App/Greple/pw.pm  view on Meta::CPAN

Multiple parameters can be set:

    greple -Mpw --config clear_screen=0 --config debug=1 --

=item Direct command-line options

Many parameters have direct command-line equivalents:

    greple -Mpw --no-clear-screen --debug --browser=safari --

=back

Currently following configuration options are available:

    clear_clipboard
    clear_string
    clear_screen
    clear_buffer
    goto_home
    browser
    timeout
    debug
    parse_matrix
    parse_id
    parse_pw
    id_keys
    id_chars
    id_color
    id_label_color
    pw_keys
    pw_chars
    pw_color
    pw_label_color
    pw_blackout

=back

=head3 Parameter Details

=over 4

=item B<Option naming>

Configuration parameters use underscores (C<clear_screen>, C<id_keys>), while 
command-line options use hyphens (C<--clear-screen>, C<--id-keys>).

=item B<Boolean parameters>

Parameters like B<clear_screen>, B<debug> can be set to 0/1. Command-line 
options support negation with C<--no-> prefix (e.g., C<--no-clear-screen>).

=item B<List parameters>

B<id_keys> and B<pw_keys> are lists of keywords separated by spaces:

    --config id_keys="USER ACCOUNT LOGIN EMAIL"
    --config pw_keys="PASS PASSWORD PIN SECRET"

=item B<Password display control>

B<pw_blackout> controls password display:
0=show passwords, 1=mask with 'x', >1=fixed length mask.

=item B<PwBlock integration>

Parameters B<parse_matrix>, B<parse_id>, B<parse_pw>, B<id_*>, and B<pw_*> 
are passed to the PwBlock module for pattern recognition and display control.

=back

=over 4

=item B<pw_status>

Print current configuration status. Next command displays current settings:

    greple -Mpw::pw_status= dummy /dev/null

This shows which parameters are set to non-default values and which are using defaults.

=back

=head1 BROWSER INTEGRATION

The pw module includes browser integration features for automated input.
Browser options are available:

=over 4

=item B<--browser>=I<name>

Set the browser for automation (chrome, safari, etc.):

    greple -Mpw --browser=chrome

=item B<--chrome>, B<--safari>

Shortcut options for specific browsers:

    greple -Mpw --chrome     # equivalent to --browser=chrome
    greple -Mpw --safari     # equivalent to --browser=safari

=back

During interactive mode, you can use the C<input> command to send
data to browser forms automatically.

=head1 EXAMPLES

=over 4

=item Search for passwords in encrypted files

    greple -Mpw password ~/secure/*.gpg

=item Use with specific browser and no screen clearing

    greple -Mpw --chrome --no-clear-screen password data.txt

=item Configure custom keywords and timeout

    greple -Mpw --config id_keys="LOGIN EMAIL USER" --config timeout=600 password file.txt

=item Check current configuration

    greple -Mpw::pw_status= dummy /dev/null

=back

=head1 SEE ALSO

L<App::Greple>, L<App::Greple::pw>

L<https://github.com/kaz-utashiro/greple-pw>

=head1 AUTHOR

Kazumasa Utashiro

=head1 LICENSE

Copyright (C) 2017-2025 Kazumasa Utashiro.

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.

=cut


use v5.14;
use strict;
use warnings;
use utf8;

use Exporter 'import';
our @EXPORT      = qw(&pw_print &pw_epilogue &pw_status &config);
our %EXPORT_TAGS = ( );
our @EXPORT_OK   = qw();

use Carp;
use Data::Dumper;
use App::Greple::Common;
use App::Greple::PwBlock;
use Getopt::EX::Config qw(config);

my $execution = 0;

# Getopt::EX::Config support
my $config = Getopt::EX::Config->new(
    clear_clipboard => 1,
    clear_string    => 'Hasta la vista.',
    clear_screen    => 1,
    clear_buffer    => 1,
    goto_home       => 0,
    browser         => 'chrome',
    timeout         => 300,
    debug           => 0,
    # PwBlock parameters - direct references to PwBlock config members
    parse_matrix    => \$App::Greple::PwBlock::config->{parse_matrix},
    parse_id        => \$App::Greple::PwBlock::config->{parse_id},
    parse_pw        => \$App::Greple::PwBlock::config->{parse_pw},
    id_keys         => \$App::Greple::PwBlock::config->{id_keys},



( run in 2.533 seconds using v1.01-cache-2.11-cpan-5735350b133 )