rus-admin 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +70 -0
- data/bin/rus-admin +15 -0
- data/lib/rus/admin/find.rb +126 -0
- data/lib/rus/admin/randpass.rb +38 -0
- data/lib/rus/admin.rb +20 -0
- data/lib/rus/override/override.rb +22 -0
- data/lib/rus/version.rb +7 -0
- metadata +75 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b18c7ccfa78f51109d5412f24af5609e410e1f78056d8db6c015deb680779a77
|
4
|
+
data.tar.gz: 7b05b29fd765252bf3993aea482890fdffdbf46825ded3afbdc491d2b48ab0d9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1593a7f05ff37a2c0ce8f9dcf0539332f25189ae1273ad07403f75a799acee85079fa0c865a1523fe764edbb13f50d5a28254ef7dce7f7fe839ff431bc1608ef
|
7
|
+
data.tar.gz: 8c0259c1da8c5734c81e99e87294a2d2406e671e85b6f6c9b8a9a85f78a37dcb2a98455a7c6f4980141d36ed063e9638df4e85008b2da08bb812aff69ebb8508
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2022 alx3dev
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
# rus-admin
|
2
|
+
|
3
|
+
Set of helpers for system administration with IRB
|
4
|
+
|
5
|
+
## How to install
|
6
|
+
|
7
|
+
```
|
8
|
+
gem install rus-admin
|
9
|
+
```
|
10
|
+
Open IRB shell with:
|
11
|
+
```
|
12
|
+
rus-admin
|
13
|
+
```
|
14
|
+
|
15
|
+
**Find helper**
|
16
|
+
```ruby
|
17
|
+
# When search #in_file - result is Struct object of param and line numbers
|
18
|
+
# When search #in_dir - result is Struct object of param and found file-names
|
19
|
+
|
20
|
+
# Last result is available in Find#info
|
21
|
+
# Find#new or alias Find#reset clear params array
|
22
|
+
# Find#reset! clear params and info
|
23
|
+
```
|
24
|
+
How to use:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
# check for name equal to .gemspec
|
28
|
+
Find['.gemspec'].in_dir Dir.pwd
|
29
|
+
=> #<struct Find::Result params=[".gemspec"], path="/home/alx/Alpha/rus-admin", result={}>
|
30
|
+
|
31
|
+
# check if name include .gemspec
|
32
|
+
Find.in_dir Dir.pwd, :include
|
33
|
+
pp search.result if search.result.any?
|
34
|
+
=> {".gemspec"=>["rus-admin.gemspec"]}
|
35
|
+
|
36
|
+
# reset params to nil
|
37
|
+
Find.new
|
38
|
+
# add to params
|
39
|
+
Find['password']
|
40
|
+
# add more to params
|
41
|
+
Find['another_password', 'password_another']
|
42
|
+
# search in file for params
|
43
|
+
Find.in_file 'path_to_file.txt'
|
44
|
+
pp Find.info.result if Find.info.result.any?
|
45
|
+
```
|
46
|
+
|
47
|
+
**Randpass helper**
|
48
|
+
```ruby
|
49
|
+
# Create random password with SecureRandom#base64
|
50
|
+
# Add random characters, and shuffle it
|
51
|
+
# Last password is saved in attribute :pass
|
52
|
+
```
|
53
|
+
How to use:
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
Randompass[20]
|
57
|
+
=> "0!ZNiAUZCbjo!#hHeX+XX$eAC=!p"
|
58
|
+
```
|
59
|
+
|
60
|
+
**Override**
|
61
|
+
Override method `capitalize!`, make it work without downcase of other characters.
|
62
|
+
Available in classes: `String, Symbol, Array`. If used in array, hashes and integers are skipped.
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
# override method #capitalize!
|
66
|
+
Rus::Admin.override!
|
67
|
+
|
68
|
+
#check if classes are overriden
|
69
|
+
Rus::Admin.override?
|
70
|
+
```
|
data/bin/rus-admin
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require_relative '../lib/rus/admin'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require 'irb'
|
15
|
+
IRB.start(__FILE__)
|
@@ -0,0 +1,126 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
##
|
4
|
+
# MIT LICENSE
|
5
|
+
# Copyright (c) 2022 Alex3Dev
|
6
|
+
#
|
7
|
+
# Search for String(s) in file.
|
8
|
+
# If success, save line numbers in response hash.
|
9
|
+
#
|
10
|
+
# @example Simple search for strings included in file
|
11
|
+
#
|
12
|
+
# action = Find['string', another_string'].in_file 'path_to_some_file'
|
13
|
+
# pp action.result if action.result.any?
|
14
|
+
#
|
15
|
+
# @example Compare if any line in a file start with wanted string
|
16
|
+
#
|
17
|
+
# action = Find['def some_method'].in_file 'path_to_file.rb', :start_with
|
18
|
+
# pp action.result if action.result.any?
|
19
|
+
#
|
20
|
+
# @example Search in logfile if any line is equal 'password'
|
21
|
+
#
|
22
|
+
# action = Find['password'].in_file 'my_log_file.txt', :equal
|
23
|
+
#
|
24
|
+
# if action.result.any?
|
25
|
+
# action.result.each do |param, line_number|
|
26
|
+
# puts "#{param} found on lines => #{line_number}"
|
27
|
+
# end
|
28
|
+
# else
|
29
|
+
# puts "No match for #{action.params}"
|
30
|
+
# end
|
31
|
+
#
|
32
|
+
class Find
|
33
|
+
Result = Struct.new(:params, :path, :result)
|
34
|
+
|
35
|
+
COMPARATION = %i[equal include start_with end_with].freeze
|
36
|
+
|
37
|
+
class << self
|
38
|
+
# remember last search
|
39
|
+
attr_reader :info
|
40
|
+
|
41
|
+
# Array of strings that has to be searched.
|
42
|
+
#
|
43
|
+
def params
|
44
|
+
@params ||= []
|
45
|
+
end
|
46
|
+
|
47
|
+
# Add strings to @params. Return self so we can chain methods
|
48
|
+
#
|
49
|
+
def [](*add_params)
|
50
|
+
@params = params | add_params
|
51
|
+
self
|
52
|
+
end
|
53
|
+
alias add_params []
|
54
|
+
|
55
|
+
# Start all over (Find.reset or Find.new)
|
56
|
+
#
|
57
|
+
def reset
|
58
|
+
@params = []
|
59
|
+
end
|
60
|
+
alias new reset
|
61
|
+
|
62
|
+
# Start all over, remove last result
|
63
|
+
#
|
64
|
+
def reset!
|
65
|
+
@params, @info = nil
|
66
|
+
end
|
67
|
+
|
68
|
+
# Search each line in file for param
|
69
|
+
# If found, line numbers are saved in result hash
|
70
|
+
#
|
71
|
+
def in_file(filename, type = :include)
|
72
|
+
@found = {}
|
73
|
+
params.each do |string|
|
74
|
+
line_no = 0
|
75
|
+
File.readlines(filename).map do |line|
|
76
|
+
line&.chomp!
|
77
|
+
process_line (line_no += 1).pred, line, string, type
|
78
|
+
end
|
79
|
+
end
|
80
|
+
@info = Result.new @params, filename, @found
|
81
|
+
end
|
82
|
+
|
83
|
+
# Search directory for file/directory name
|
84
|
+
# If found, names are saved in result hash
|
85
|
+
#
|
86
|
+
def in_dir(path, type = :equal)
|
87
|
+
@found = {}
|
88
|
+
Dir.entries(path).each do |file|
|
89
|
+
next if ['.', '..'].include?(file)
|
90
|
+
|
91
|
+
params.each do |string|
|
92
|
+
process_line file, file, string, type
|
93
|
+
end
|
94
|
+
end
|
95
|
+
@info = Result.new @params, path, @found
|
96
|
+
end
|
97
|
+
|
98
|
+
private
|
99
|
+
|
100
|
+
def process_line(line_no, line, string, type)
|
101
|
+
raise ArgumentError, 'Comparation not supported' unless COMPARATION.include?(type)
|
102
|
+
|
103
|
+
line = strip line
|
104
|
+
add_to = check_line line, string, type
|
105
|
+
add string, line_no if add_to
|
106
|
+
end
|
107
|
+
|
108
|
+
def check_line(line, string, type)
|
109
|
+
case type
|
110
|
+
when :include then true if line.include? string
|
111
|
+
when :equal then true if line == string
|
112
|
+
when :start_with then true if line.start_with? string
|
113
|
+
when :end_with then true if line.end_with? string
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def add(param, line_no)
|
118
|
+
@found[param] = Array(@found[param]) | Array(line_no)
|
119
|
+
end
|
120
|
+
|
121
|
+
def strip(line)
|
122
|
+
line[0] = '' until line[0] != ' '
|
123
|
+
line
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'securerandom'
|
4
|
+
|
5
|
+
module Randpass
|
6
|
+
class << self
|
7
|
+
attr_reader :pass
|
8
|
+
|
9
|
+
# Get random password
|
10
|
+
# Add special characters to SecureRandom#base64 random string, and shuffle it
|
11
|
+
#
|
12
|
+
# @note Always shuffle base64 if it has less than 16 chars, because they end with '=='
|
13
|
+
#
|
14
|
+
def [](number_of_chars = 18)
|
15
|
+
random = SecureRandom.base64(number_of_chars)
|
16
|
+
rand(5..10).times { random = add_special_chars(random) }
|
17
|
+
@pass = random.split('').shuffle.join
|
18
|
+
end
|
19
|
+
alias get []
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def add_special_chars(param)
|
24
|
+
count = SecureRandom.random_number 15_000
|
25
|
+
char = case count
|
26
|
+
when 1...1000 then '_'
|
27
|
+
when 1000...2000 then '!'
|
28
|
+
when 2000...3000 then '#'
|
29
|
+
when 3000...4000 then '$'
|
30
|
+
when 4000...5000 then '%'
|
31
|
+
when 6000...7000 then '?'
|
32
|
+
else return param
|
33
|
+
end
|
34
|
+
param[rand(param.size)] = char
|
35
|
+
param
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/rus/admin.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'version' unless defined? Rus::Admin::VERSION
|
4
|
+
require_relative 'admin/find' unless defined? Find
|
5
|
+
require_relative 'admin/randpass' unless defined? Randpass
|
6
|
+
|
7
|
+
module Rus
|
8
|
+
module Admin
|
9
|
+
class << self
|
10
|
+
def override?
|
11
|
+
@override == true
|
12
|
+
end
|
13
|
+
|
14
|
+
def override!
|
15
|
+
require_relative 'override/override'
|
16
|
+
@override = true
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class String
|
4
|
+
def capitalize!
|
5
|
+
self[0] = self[0].upcase
|
6
|
+
self
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class Symbol
|
11
|
+
def capitalize!
|
12
|
+
String.new(name).capitalize!.to_sym
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class Array
|
17
|
+
def capitalize!
|
18
|
+
each do |x|
|
19
|
+
x.capitalize! if x.instance_of?(String) || x.instance_of?(Symbol)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/rus/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rus-admin
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- alx3dev
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-02-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '13.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '13.0'
|
27
|
+
description: |
|
28
|
+
Set of helper methods for system administration.
|
29
|
+
Speed up system tasks with one-liners and IRB.
|
30
|
+
email:
|
31
|
+
- alx3dev@gmail.com
|
32
|
+
executables:
|
33
|
+
- rus-admin
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- LICENSE
|
38
|
+
- README.md
|
39
|
+
- bin/rus-admin
|
40
|
+
- lib/rus/admin.rb
|
41
|
+
- lib/rus/admin/find.rb
|
42
|
+
- lib/rus/admin/randpass.rb
|
43
|
+
- lib/rus/override/override.rb
|
44
|
+
- lib/rus/version.rb
|
45
|
+
homepage: https://www.github.com/alx3dev/rus-admin
|
46
|
+
licenses:
|
47
|
+
- MIT
|
48
|
+
metadata:
|
49
|
+
homepage_uri: https://www.github.com/alx3dev/rus-admin
|
50
|
+
source_code_uri: https://www.github.com/alx3dev/rus-admin
|
51
|
+
changelog_uri: https://www.github.com/alx3dev/rus-admin/CHANGELOG.md
|
52
|
+
documentation_uri: https://www.rubydoc.info/gems/rus-admin/0.1.0
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options: []
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.7'
|
62
|
+
- - "<"
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '3.2'
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
requirements: []
|
71
|
+
rubygems_version: 3.3.6
|
72
|
+
signing_key:
|
73
|
+
specification_version: 4
|
74
|
+
summary: Set of helper methods for system administration with Ruby.
|
75
|
+
test_files: []
|