Compare commits
11 Commits
Author | SHA1 | Date | |
---|---|---|---|
526d29bef1
|
|||
d08349f800
|
|||
70a2e47727
|
|||
626e7cbe0b
|
|||
5152598804
|
|||
b8de2dd0b8
|
|||
0ff3a7da59
|
|||
aea5284279
|
|||
a1bc755181 | |||
9fae7124be
|
|||
0e6ed176b3
|
10
HISTORY.md
10
HISTORY.md
@@ -6,6 +6,16 @@
|
||||
- ℹ️ - Information
|
||||
- ♻️ - Edited
|
||||
|
||||
## 0.2.5 - [31/07/2022]
|
||||
- ➕ - Added timeout user input
|
||||
- ♻️ - Source file separated
|
||||
|
||||
## 0.2.4 - [26/07/2022]
|
||||
- ➕ - Added hint for fix file permissions error.
|
||||
- ℹ️ - Crystal version raise to 1.5.0 for NO_COLOR support
|
||||
- ✔️ - Fixed output finding records for all queryes
|
||||
- ✔️ - Fixed check password file name info
|
||||
|
||||
## 0.2.3 - [02/05/2022]
|
||||
- ♻️ - Password outdated date change to 3 month
|
||||
- ➕ - Added `pmng` logo
|
||||
|
13
README.md
13
README.md
@@ -1,14 +1,17 @@
|
||||
# 🔑 The very simple password manager for humans
|
||||
|
||||

|
||||

|
||||

|
||||

|
||||
[](#download)
|
||||
|
||||
# 📷 Screenshots
|
||||
## 📷 Screenshots
|
||||
|
||||

|
||||

|
||||
|
||||
# 💾 Download
|
||||

|
||||
|
||||
**Coming soon**
|
||||
## 💾 Download
|
||||
|
||||
- [Linux x86_64](https://me.a2s.su/.../)
|
||||
- [Linux x86](https://me.a2s.su/.../)
|
||||
|
@@ -2,5 +2,5 @@ version: 2.0
|
||||
shards:
|
||||
ameba:
|
||||
git: https://github.com/crystal-ameba/ameba.git
|
||||
version: 0.14.3
|
||||
version: 1.0.0
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
name: pmng
|
||||
version: 0.2.3
|
||||
version: 0.2.5
|
||||
|
||||
authors:
|
||||
- Alexander Popov <iiiypuk@iiiypuk.me>
|
||||
@@ -11,8 +11,8 @@ targets:
|
||||
development_dependencies:
|
||||
ameba:
|
||||
github: crystal-ameba/ameba
|
||||
version: ~> 0.14.0
|
||||
version: ~> 1.0.0
|
||||
|
||||
crystal: 1.3.2
|
||||
crystal: 1.5.0
|
||||
|
||||
license: MIT
|
||||
|
160
src/pmng.cr
160
src/pmng.cr
@@ -2,83 +2,30 @@ require "option_parser"
|
||||
require "yaml"
|
||||
require "colorize"
|
||||
|
||||
# password serializer
|
||||
class Password
|
||||
include YAML::Serializable
|
||||
|
||||
@[YAML::Field(key: "url")]
|
||||
property url : String
|
||||
@[YAML::Field(key: "email")]
|
||||
property email : String
|
||||
@[YAML::Field(key: "login")]
|
||||
property login : String
|
||||
@[YAML::Field(key: "password")]
|
||||
property password : String
|
||||
@[YAML::Field(key: "desc")]
|
||||
property desc : String
|
||||
@[YAML::Field(key: "profile_url")]
|
||||
property profile_url : String
|
||||
@[YAML::Field(key: "update")]
|
||||
property update : Int32
|
||||
end
|
||||
|
||||
VERSION = "0.2.3"
|
||||
|
||||
ASCII_LOGO = "
|
||||
██████╗ ███╗ ███╗███╗ ██╗ ██████╗
|
||||
██╔══██╗████╗ ████║████╗ ██║██╔════╝
|
||||
██████╔╝██╔████╔██║██╔██╗ ██║██║ ███╗
|
||||
██╔═══╝ ██║╚██╔╝██║██║╚██╗██║██║ ██║
|
||||
██║ ██║ ╚═╝ ██║██║ ╚████║╚██████╔╝
|
||||
╚═╝ ╚═╝ ╚═╝╚═╝ ╚═══╝ ╚═════╝
|
||||
"
|
||||
|
||||
# program options
|
||||
begin
|
||||
OptionParser.parse do |parser|
|
||||
parser.banner = "The very simple password manager for humans\n"
|
||||
|
||||
parser.on "-v", "--version", "Show version" do
|
||||
puts ASCII_LOGO.colorize(:yellow)
|
||||
puts "The very simple password manager for humans.".colorize(:yellow)
|
||||
print "Version ".colorize(:yellow)
|
||||
puts VERSION.colorize(:red).mode(:bold)
|
||||
print "\nURL to full change log: ".colorize(:yellow)
|
||||
puts "https://git.a2s.su/iiiypuk/pmng/raw/branch/master/HISTORY.md".colorize(:green).mode(:bold)
|
||||
|
||||
exit(0)
|
||||
end
|
||||
parser.on "-h", "--help", "Show help" do
|
||||
puts parser
|
||||
|
||||
exit(0)
|
||||
end
|
||||
parser.on "-g", "--generate-password", "Generate password" do
|
||||
puts Random::Secure.urlsafe_base64(16, padding: false).colorize(:black).back(:white)
|
||||
puts Random::Secure.urlsafe_base64(16, padding: false).colorize(:white).back(:blue)
|
||||
puts Random::Secure.urlsafe_base64(16, padding: false).colorize(:white).back(:red)
|
||||
|
||||
exit(0)
|
||||
end
|
||||
parser.on "-t", "--unixtime", "Return local timestamp" do
|
||||
puts Time.local.to_unix.colorize(:yellow).mode(:bold)
|
||||
|
||||
exit(0)
|
||||
end
|
||||
end
|
||||
rescue ex
|
||||
puts ex.message, ""
|
||||
end
|
||||
|
||||
PASSWORD_FILE_PATH = "#{ENV["HOME"]}/.pwd.yml"
|
||||
require "./pmng/*"
|
||||
require "./pmng/functions/*"
|
||||
|
||||
module Pmng
|
||||
# check password file exists
|
||||
if File.exists?(PASSWORD_FILE_PATH)
|
||||
yaml = File.open(PASSWORD_FILE_PATH) do |file|
|
||||
YAML.parse(file)
|
||||
end
|
||||
else
|
||||
puts "No password.yml file exists."
|
||||
print "~/.pwd.yml".colorize(:red).mode(:bold)
|
||||
puts ": No such file"
|
||||
|
||||
exit(1)
|
||||
end
|
||||
|
||||
# check file ppermissions
|
||||
password_file_permissions = File.info(PASSWORD_FILE_PATH).permissions.to_s
|
||||
|
||||
if /\d{3}/.match(password_file_permissions).try &.[0] != "600"
|
||||
puts "Password file permissions is not RW for you.".colorize(:red)
|
||||
print "Execute: ".colorize(:yellow)
|
||||
print "(chmod 600 ~/.pwd.yml) ".colorize(:green).mode(:bold)
|
||||
puts "for fix.".colorize(:yellow)
|
||||
|
||||
exit(1)
|
||||
end
|
||||
@@ -91,21 +38,14 @@ while count < yaml.size
|
||||
count += 1
|
||||
end
|
||||
|
||||
# check file ppermissions
|
||||
password_file_permissions = File.info(PASSWORD_FILE_PATH).permissions.to_s
|
||||
|
||||
if /\d{3}/.match(password_file_permissions).try &.[0] != "600"
|
||||
puts "Password file permissions is not RW for you.".colorize(:red)
|
||||
|
||||
exit(1)
|
||||
end
|
||||
|
||||
# pmng title
|
||||
system "clear"
|
||||
puts ASCII_LOGO.colorize(:yellow)
|
||||
puts "The very simple password manager for humans".colorize(:yellow).mode(:bold)
|
||||
puts "-------------------------------------------".colorize(:yellow).mode(:bold)
|
||||
|
||||
statistics = Functions::Statistics.new(passwords_array)
|
||||
|
||||
# main loop
|
||||
loop = true
|
||||
while loop
|
||||
@@ -117,14 +57,16 @@ while loop
|
||||
print " for exit)\n".colorize(:white).mode(:bold)
|
||||
print "> ".colorize(:green).mode(:bold)
|
||||
|
||||
password_string = gets
|
||||
begin
|
||||
STDIN.read_timeout = USER_INPUT_TIMEOUT
|
||||
password_string = STDIN.gets
|
||||
rescue IO::TimeoutError
|
||||
loop = false
|
||||
end
|
||||
|
||||
if password_string.to_s == ":q"
|
||||
# if ':q' to close program
|
||||
system "clear"
|
||||
puts "Bye! 👋"
|
||||
|
||||
exit(0)
|
||||
loop = false
|
||||
elsif password_string.to_s.size == 0
|
||||
# if puts empty, retry prompt
|
||||
puts
|
||||
@@ -138,24 +80,13 @@ while loop
|
||||
elsif password_string.to_s == ":s"
|
||||
# if ':s' to view Statistics
|
||||
system "clear"
|
||||
|
||||
puts "Statistics\n----------".colorize(:yellow).mode(:bold)
|
||||
|
||||
print "All elements: ".colorize(:yellow).mode(:bold)
|
||||
puts passwords_array.size
|
||||
puts statistics.size
|
||||
|
||||
print "Passwords outdated: ".colorize(:red).mode(:bold)
|
||||
outdated_count = 0
|
||||
current_time = Time.local.to_unix
|
||||
a = [] of String
|
||||
passwords_array.each do |item|
|
||||
if item.update + (2629743 * 3) < current_time # 2629743 * 3 -- 3 month
|
||||
outdated_count += 1
|
||||
a << item.url
|
||||
end
|
||||
end
|
||||
|
||||
puts outdated_count
|
||||
puts statistics.outdated
|
||||
else
|
||||
# list search password
|
||||
system "clear"
|
||||
@@ -164,45 +95,24 @@ while loop
|
||||
|
||||
passwords_array.each do |item|
|
||||
if item.url.includes?(password_string.to_s)
|
||||
print "🌐 "
|
||||
puts item.url.colorize(:magenta).mode(:bold).mode(:underline)
|
||||
|
||||
if !item.email.blank?
|
||||
print "📧 "
|
||||
puts item.email.colorize(:red)
|
||||
end
|
||||
|
||||
if !item.login.blank?
|
||||
print "🗿 "
|
||||
puts item.login.colorize(:yellow)
|
||||
end
|
||||
|
||||
if !item.password.blank?
|
||||
print "🔐 "
|
||||
puts item.password.colorize(:red).back(:red)
|
||||
end
|
||||
|
||||
if !item.desc.blank?
|
||||
print "📄 "
|
||||
puts item.desc.colorize(:cyan)
|
||||
end
|
||||
|
||||
if !item.profile_url.blank?
|
||||
print "👦 "
|
||||
puts item.profile_url.colorize(:green)
|
||||
end
|
||||
Functions.show_item(item)
|
||||
|
||||
puts "-----".colorize(:dark_gray).mode(:bold)
|
||||
|
||||
passwords_finded_array += 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
puts
|
||||
print "Finded ".colorize(:yellow).mode(:bold)
|
||||
print passwords_finded_array.colorize(:red).mode(:bold)
|
||||
puts " records".colorize(:yellow).mode(:bold)
|
||||
puts "-----".colorize(:dark_gray).mode(:bold)
|
||||
end
|
||||
|
||||
puts
|
||||
end
|
||||
|
||||
system "clear"
|
||||
puts "Bye! 👋"
|
||||
end
|
||||
|
35
src/pmng/agrv_options.cr
Normal file
35
src/pmng/agrv_options.cr
Normal file
@@ -0,0 +1,35 @@
|
||||
begin
|
||||
OptionParser.parse do |parser|
|
||||
parser.banner = "The very simple password manager for humans\n"
|
||||
|
||||
parser.on "-v", "--version", "Show version" do
|
||||
puts ASCII_LOGO.colorize(:yellow)
|
||||
puts "The very simple password manager for humans.".colorize(:yellow)
|
||||
print "Version ".colorize(:yellow)
|
||||
puts VERSION.colorize(:red).mode(:bold)
|
||||
puts "\nURL to full changes log: ".colorize(:yellow)
|
||||
puts "https://git.a2s.su/iiiypuk/pmng/raw/branch/master/HISTORY.md".colorize(:green).mode(:bold)
|
||||
|
||||
exit(0)
|
||||
end
|
||||
parser.on "-h", "--help", "Show help" do
|
||||
puts parser
|
||||
|
||||
exit(0)
|
||||
end
|
||||
parser.on "-g", "--generate-password", "Generate password" do
|
||||
puts Random::Secure.urlsafe_base64(16, padding: false).colorize(:black).back(:white)
|
||||
puts Random::Secure.urlsafe_base64(16, padding: false).colorize(:white).back(:blue)
|
||||
puts Random::Secure.urlsafe_base64(16, padding: false).colorize(:white).back(:red)
|
||||
|
||||
exit(0)
|
||||
end
|
||||
parser.on "-t", "--unixtime", "Return local timestamp" do
|
||||
puts Time.local.to_unix.colorize(:yellow).mode(:bold)
|
||||
|
||||
exit(0)
|
||||
end
|
||||
end
|
||||
rescue ex
|
||||
puts ex.message, ""
|
||||
end
|
3
src/pmng/app_settings.cr
Normal file
3
src/pmng/app_settings.cr
Normal file
@@ -0,0 +1,3 @@
|
||||
VERSION = {{ `shards version "#{__DIR__}"`.chomp.stringify }}
|
||||
PASSWORD_FILE_PATH = "#{ENV["HOME"]}/.pwd.yml"
|
||||
USER_INPUT_TIMEOUT = 60
|
8
src/pmng/ascii_logo.cr
Normal file
8
src/pmng/ascii_logo.cr
Normal file
@@ -0,0 +1,8 @@
|
||||
ASCII_LOGO = "
|
||||
██████╗ ███╗ ███╗███╗ ██╗ ██████╗
|
||||
██╔══██╗████╗ ████║████╗ ██║██╔════╝
|
||||
██████╔╝██╔████╔██║██╔██╗ ██║██║ ███╗
|
||||
██╔═══╝ ██║╚██╔╝██║██║╚██╗██║██║ ██║
|
||||
██║ ██║ ╚═╝ ██║██║ ╚████║╚██████╔╝
|
||||
╚═╝ ╚═╝ ╚═╝╚═╝ ╚═══╝ ╚═════╝
|
||||
"
|
33
src/pmng/functions/item.cr
Normal file
33
src/pmng/functions/item.cr
Normal file
@@ -0,0 +1,33 @@
|
||||
module Pmng::Functions
|
||||
extend self
|
||||
|
||||
def show_item(password)
|
||||
print "🌐 "
|
||||
puts password.url.colorize(:magenta).mode(:bold).mode(:underline)
|
||||
|
||||
if !password.email.blank?
|
||||
print "📧 "
|
||||
puts password.email.colorize(:red)
|
||||
end
|
||||
|
||||
if !password.login.blank?
|
||||
print "🗿 "
|
||||
puts password.login.colorize(:yellow)
|
||||
end
|
||||
|
||||
if !password.password.blank?
|
||||
print "🔐 "
|
||||
puts password.password.colorize(:red).back(:red)
|
||||
end
|
||||
|
||||
if !password.desc.blank?
|
||||
print "📄 "
|
||||
puts password.desc.colorize(:cyan)
|
||||
end
|
||||
|
||||
if !password.profile_url.blank?
|
||||
print "👦 "
|
||||
puts password.profile_url.colorize(:green)
|
||||
end
|
||||
end
|
||||
end
|
31
src/pmng/functions/statistics.cr
Normal file
31
src/pmng/functions/statistics.cr
Normal file
@@ -0,0 +1,31 @@
|
||||
module Pmng::Functions
|
||||
class Statistics
|
||||
getter passwords : Array(Password)
|
||||
getter outdated : Int32
|
||||
getter size : Int32
|
||||
|
||||
def initialize(@passwords)
|
||||
@size = passwords.size
|
||||
|
||||
outdated_count = 0
|
||||
current_time = Time.local.to_unix
|
||||
a = [] of String
|
||||
@passwords.each do |item|
|
||||
if item.update + (2629743 * 3) < current_time # 2629743 * 3 -- 3 month
|
||||
outdated_count += 1
|
||||
a << item.url
|
||||
end
|
||||
end
|
||||
|
||||
@outdated = outdated_count
|
||||
end
|
||||
|
||||
def size
|
||||
@size
|
||||
end
|
||||
|
||||
def outdated
|
||||
@outdated
|
||||
end
|
||||
end
|
||||
end
|
18
src/pmng/password_class.cr
Normal file
18
src/pmng/password_class.cr
Normal file
@@ -0,0 +1,18 @@
|
||||
class Password
|
||||
include YAML::Serializable
|
||||
|
||||
@[YAML::Field(key: "url")]
|
||||
property url : String
|
||||
@[YAML::Field(key: "email")]
|
||||
property email : String
|
||||
@[YAML::Field(key: "login")]
|
||||
property login : String
|
||||
@[YAML::Field(key: "password")]
|
||||
property password : String
|
||||
@[YAML::Field(key: "desc")]
|
||||
property desc : String
|
||||
@[YAML::Field(key: "profile_url")]
|
||||
property profile_url : String
|
||||
@[YAML::Field(key: "update")]
|
||||
property update : Int32
|
||||
end
|
Reference in New Issue
Block a user