baze 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +13 -0
- data/bin/fixperms +41 -0
- data/bin/hex2ip +22 -0
- data/bin/ip2hex +25 -0
- data/bin/randmac +18 -0
- data/bin/shellescape +19 -0
- data/bin/shost +27 -0
- data/bin/urldecode +19 -0
- data/bin/urlencode +19 -0
- metadata +63 -0
data/COPYING
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright (c) 2012, Pierre Carrier
|
2
|
+
|
3
|
+
Permission to use, copy, modify, and/or distribute this software
|
4
|
+
for any purpose with or without fee is hereby granted, provided that
|
5
|
+
the above copyright notice and this permission notice appear in all copies.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
8
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
9
|
+
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
10
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
11
|
+
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
12
|
+
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
|
13
|
+
THIS SOFTWARE.
|
data/bin/fixperms
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
require 'fileutils'
|
5
|
+
require 'yaml'
|
6
|
+
|
7
|
+
optparse = OptionParser.new do |opts|
|
8
|
+
opts.banner = "Usage: fixperms [config file ...]\n" \
|
9
|
+
" Apply files permissions and ownership rules using YAML specifications"
|
10
|
+
opts.on '-l', '--lowercase', 'Use lowercase digits' do
|
11
|
+
format = '%x'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
optparse.parse!
|
16
|
+
|
17
|
+
if ARGV.empty?
|
18
|
+
specpaths = Dir.glob '/etc/fixperms.d/*'
|
19
|
+
else
|
20
|
+
specpaths = ARGV
|
21
|
+
end
|
22
|
+
|
23
|
+
specpaths.each do |specpath|
|
24
|
+
spec = YAML::load File::read specpath
|
25
|
+
|
26
|
+
spec.each do |glob, infos|
|
27
|
+
files = Dir.glob glob
|
28
|
+
|
29
|
+
user, group, mod = infos['user'], infos['group'], infos['mod']
|
30
|
+
|
31
|
+
user_grp = "#{user}:#{group}" if user or group
|
32
|
+
descr = [user_grp, mod].compact.join ', '
|
33
|
+
|
34
|
+
puts "#{files.join ', '} -> #{descr}"
|
35
|
+
|
36
|
+
next if files.empty?
|
37
|
+
|
38
|
+
FileUtils.chown user, group, files
|
39
|
+
FileUtils.chmod mod, files if mod
|
40
|
+
end
|
41
|
+
end
|
data/bin/hex2ip
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
|
5
|
+
optparse = OptionParser.new do |opts|
|
6
|
+
opts.banner = "Usage: hex2ip IP\n" \
|
7
|
+
" Converts an IPv4 from hexadecimal to dotted representation"
|
8
|
+
end
|
9
|
+
|
10
|
+
optparse.parse!
|
11
|
+
|
12
|
+
raise 'Hexadecimal IP expected' if ARGV.empty?
|
13
|
+
raise 'Invalid IP' unless ARGV[0] =~ /^[0-9a-fA-F]+$/
|
14
|
+
|
15
|
+
n = ARGV[0].hex
|
16
|
+
raise 'Impossibly high IP' unless (0..1<<32).include? n
|
17
|
+
|
18
|
+
d = n % 256
|
19
|
+
c = (n >> 8) % 256
|
20
|
+
b = (n >> 16) % 256
|
21
|
+
a = (n >> 24) % 256
|
22
|
+
puts "#{a}.#{b}.#{c}.#{d}"
|
data/bin/ip2hex
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
|
5
|
+
format = '%X'
|
6
|
+
|
7
|
+
optparse = OptionParser.new do |opts|
|
8
|
+
opts.banner = "Usage: ip2hex [-l] IP\n" \
|
9
|
+
" Converts an IPv4 from dotted to hexadecimal representation"
|
10
|
+
opts.on '-l', '--lowercase', 'Use lowercase digits' do
|
11
|
+
format = '%x'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
optparse.parse!
|
16
|
+
raise 'IP expected' if ARGV.empty?
|
17
|
+
|
18
|
+
parts = ARGV[0].split('.').collect{|n| n.to_i}
|
19
|
+
raise 'IP does not have 4 integers' unless parts.length == 4
|
20
|
+
|
21
|
+
ACCEPTED = 0..255
|
22
|
+
parts.each {|p| raise 'Integer not in 0..255' unless ACCEPTED.include? p}
|
23
|
+
|
24
|
+
num = parts.reverse.inject(0){|r,e| (r<<8)+e}
|
25
|
+
printf "#{format}\n", num
|
data/bin/randmac
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
|
5
|
+
format = '%02X:%02X:%02X:%02X:%02X:%02X'
|
6
|
+
|
7
|
+
optparse = OptionParser.new do |opts|
|
8
|
+
opts.banner = "Usage: randmac [-l]\n" \
|
9
|
+
" Generates a completely random MAC address"
|
10
|
+
|
11
|
+
opts.on '-l', '--lowercase', 'Use lowercase digits' do
|
12
|
+
format = '%02x:%02x:%02x:%02x:%02x:%02x'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
optparse.parse!
|
17
|
+
|
18
|
+
printf "#{format}\n", *(6.times.map{rand(256)})
|
data/bin/shellescape
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
require 'shellwords'
|
5
|
+
|
6
|
+
optparse = OptionParser.new do |opts|
|
7
|
+
opts.banner = "Usage: shellescape [string]\n" \
|
8
|
+
" Escapes the provided string (or standard input) for unquoted Bourne shell usage"
|
9
|
+
end
|
10
|
+
|
11
|
+
optparse.parse!
|
12
|
+
|
13
|
+
if ARGV.empty?
|
14
|
+
str = STDIN.read
|
15
|
+
else
|
16
|
+
str = ARGV.join ' '
|
17
|
+
end
|
18
|
+
|
19
|
+
puts Shellwords::escape str
|
data/bin/shost
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'socket'
|
4
|
+
require 'optparse'
|
5
|
+
|
6
|
+
reverse = false
|
7
|
+
|
8
|
+
optparse = OptionParser.new do |opts|
|
9
|
+
opts.banner = "Usage: hosthost host\n" \
|
10
|
+
" Resolves names"
|
11
|
+
|
12
|
+
opts.on '-r', '--reverse', 'Display reverse lookups' do
|
13
|
+
reverse = true
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
optparse.parse!
|
18
|
+
|
19
|
+
raise 'host expected' if ARGV.empty?
|
20
|
+
|
21
|
+
infos = Socket.getaddrinfo(ARGV[0], 0, Socket::AF_UNSPEC, Socket::SOCK_STREAM, nil, 0, reverse)
|
22
|
+
|
23
|
+
if reverse
|
24
|
+
infos.each {|r| puts r[2]}
|
25
|
+
else
|
26
|
+
infos.each {|r| puts r[3]}
|
27
|
+
end
|
data/bin/urldecode
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
require 'cgi'
|
5
|
+
|
6
|
+
optparse = OptionParser.new do |opts|
|
7
|
+
opts.banner = "Usage: urldecode [string]\n" \
|
8
|
+
" URL-decodes the provided string (or standard input)"
|
9
|
+
end
|
10
|
+
|
11
|
+
optparse.parse!
|
12
|
+
|
13
|
+
if ARGV.empty?
|
14
|
+
str = STDIN.read
|
15
|
+
else
|
16
|
+
str = ARGV.join ' '
|
17
|
+
end
|
18
|
+
|
19
|
+
puts CGI::unescape str
|
data/bin/urlencode
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
require 'cgi'
|
5
|
+
|
6
|
+
optparse = OptionParser.new do |opts|
|
7
|
+
opts.banner = "Usage: urlencode [string]\n" \
|
8
|
+
" URL-encodes the provided string (or standard input)"
|
9
|
+
end
|
10
|
+
|
11
|
+
optparse.parse!
|
12
|
+
|
13
|
+
if ARGV.empty?
|
14
|
+
str = STDIN.read
|
15
|
+
else
|
16
|
+
str = ARGV.join ' '
|
17
|
+
end
|
18
|
+
|
19
|
+
puts CGI::escape str
|
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: baze
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Pierre Carrier
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-10-23 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description:
|
15
|
+
email:
|
16
|
+
- pierre@spotify.com
|
17
|
+
executables:
|
18
|
+
- fixperms
|
19
|
+
- hex2ip
|
20
|
+
- ip2hex
|
21
|
+
- randmac
|
22
|
+
- shellescape
|
23
|
+
- shost
|
24
|
+
- urldecode
|
25
|
+
- urlencode
|
26
|
+
extensions: []
|
27
|
+
extra_rdoc_files: []
|
28
|
+
files:
|
29
|
+
- bin/fixperms
|
30
|
+
- bin/hex2ip
|
31
|
+
- bin/ip2hex
|
32
|
+
- bin/randmac
|
33
|
+
- bin/shellescape
|
34
|
+
- bin/shost
|
35
|
+
- bin/urldecode
|
36
|
+
- bin/urlencode
|
37
|
+
- COPYING
|
38
|
+
homepage: https://github.com/pcarrier/baze
|
39
|
+
licenses:
|
40
|
+
- ISC
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options: []
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
none: false
|
47
|
+
requirements:
|
48
|
+
- - ! '>='
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ! '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 1.2.0
|
57
|
+
requirements: []
|
58
|
+
rubyforge_project: baze
|
59
|
+
rubygems_version: 1.8.24
|
60
|
+
signing_key:
|
61
|
+
specification_version: 3
|
62
|
+
summary: Base utilities for POSIX system
|
63
|
+
test_files: []
|