This repository has been archived by the owner on May 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Genki Sugawara
committed
Oct 5, 2014
1 parent
d011742
commit 12bf749
Showing
7 changed files
with
75 additions
and
4 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class Gratan::Identifier | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
class Gratan::Identifier::Auto | ||
def initialize(output) | ||
if output == '-' | ||
@output = $stdout | ||
else | ||
@output = open(output, 'w') | ||
end | ||
end | ||
|
||
def identify(user, host) | ||
password = mkpasswd | ||
puts_password(user, host, password) | ||
password | ||
end | ||
|
||
private | ||
|
||
def mkpasswd(len = 8) | ||
[*1..9, *'A'..'Z', *'a'..'z'].shuffle.slice(0, len).join | ||
end | ||
|
||
def puts_password(user, host, password) | ||
@output.puts("#{user}@#{host},#{password}") | ||
@output.flush | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
require 'csv' | ||
|
||
class Gratan::Identifier::CSV | ||
include Gratan::Logger::Helper | ||
|
||
def initialize(path) | ||
@passwords = {} | ||
|
||
CSV.foreach(path) do |row| | ||
@passwords[row[0]] = row[1] | ||
end | ||
end | ||
|
||
def identify(user, host) | ||
user_host = "#{user}@#{host}" | ||
password = @passwords[user_host] | ||
|
||
unless password | ||
log(:warn, 'password for `#{user_host}` can not be found', :yellow) | ||
end | ||
|
||
password | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class Gratan::Identifier::Null | ||
def identify | ||
nil | ||
end | ||
end |