codesake-commons 0.80.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/.document +5 -0
- data/.gitignore +18 -0
- data/.rspec +1 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/codesake-commons.gemspec +21 -0
- data/lib/codesake-commons.rb +3 -0
- data/lib/codesake/commons/io.rb +22 -0
- data/lib/codesake/commons/logging.rb +99 -0
- data/lib/codesake/commons/version.rb +5 -0
- data/spec/codesake_commons_spec.rb +7 -0
- data/spec/logging_spec.rb +9 -0
- data/spec/spec_helper.rb +12 -0
- metadata +80 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c1e14abf73528a87db938dcba416280c60514d51
|
4
|
+
data.tar.gz: a5a3738e1f7d24a6e592db346c915d4c1b7eb27f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 489c5f8b6de78aa309ddae1fc1ffc16db2389eba15adeee67e3f6136986ddb08070b612cf5c809ce7b7d32e8fbe06ef4b53380c0690e24f6014f1ba4918a4725
|
7
|
+
data.tar.gz: ebbe704e9f06ec16efcecf8e7fbad06269e0e8535d37843eef7da0cae375df7dd96ad213f280f84fa7980ad52741d2d81c4776a8b9234ef71bcdba8243ed97f6
|
data/.document
ADDED
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
codesake
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-1.9.3-p429
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Paolo Perego
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# CodesakeCommons
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'codesake_commons'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install codesake_commons
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'codesake/commons/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "codesake-commons"
|
8
|
+
gem.version = Codesake::Commons::VERSION
|
9
|
+
gem.authors = ["Paolo Perego"]
|
10
|
+
gem.email = ["thesp0nge@gmail.com"]
|
11
|
+
gem.description = %q{codesake.com is an application security startup providing code review and penetration test services for Ruby powered web applications. codesake_commons is the gem containing common ground routines useful across the project}
|
12
|
+
gem.summary = %q{codesake_commons is the gem containing common ground routines useful across the codesake.com project}
|
13
|
+
gem.homepage = "http://codesake.com"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_dependency 'rainbow'
|
21
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Codesake
|
2
|
+
module Commons
|
3
|
+
class Io
|
4
|
+
def self.remove_pid_file(pid_file)
|
5
|
+
File.delete(pid_file) if File.exists?(pid_file)
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.create_pid_file(pid_file)
|
9
|
+
f = File.new(pid_file, "w")
|
10
|
+
f.write("#{Process.pid}")
|
11
|
+
f.close
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.read_pid_file(pid_file)
|
15
|
+
f = File.new(pid_file, "r")
|
16
|
+
pid=f.read
|
17
|
+
f.close
|
18
|
+
pid
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
require 'rainbow'
|
2
|
+
require 'syslog'
|
3
|
+
require 'singleton'
|
4
|
+
|
5
|
+
module Codesake
|
6
|
+
module Commons
|
7
|
+
class Logging
|
8
|
+
include Singleton
|
9
|
+
|
10
|
+
attr_reader :silencer
|
11
|
+
attr_reader :verbose
|
12
|
+
attr_reader :syslog
|
13
|
+
attr_accessor :filename
|
14
|
+
|
15
|
+
def initialize
|
16
|
+
super
|
17
|
+
@silencer = false
|
18
|
+
@verbose = true
|
19
|
+
@syslog = true
|
20
|
+
@filename = nil
|
21
|
+
end
|
22
|
+
|
23
|
+
def die(msg, pid_file=nil)
|
24
|
+
STDERR.print "#{Time.now.strftime("%H:%M:%S")} [!] #{msg}\n".color(:red)
|
25
|
+
send_to_syslog(msg, :helo)
|
26
|
+
send_to_file(msg, :helo)
|
27
|
+
Codesake::Commons::Io.remove_pid_file(pid_file) unless pid_file.nil?
|
28
|
+
Kernel.exit(-1)
|
29
|
+
end
|
30
|
+
|
31
|
+
def err(msg)
|
32
|
+
STDERR.print "#{Time.now.strftime("%H:%M:%S")} [!] #{msg}\n".color(:red)
|
33
|
+
send_to_syslog(msg, :err)
|
34
|
+
send_to_file(msg, :err)
|
35
|
+
end
|
36
|
+
|
37
|
+
def warn(msg)
|
38
|
+
STDOUT.print "#{Time.now.strftime("%H:%M:%S")} [!] #{msg}\n".color(:yellow)
|
39
|
+
send_to_syslog(msg, :warn)
|
40
|
+
send_to_file(msg, :warn)
|
41
|
+
end
|
42
|
+
|
43
|
+
def ok(msg)
|
44
|
+
STDOUT.print "#{Time.now.strftime("%H:%M:%S")} [*] #{msg}\n".color(:green)
|
45
|
+
send_to_syslog(msg, :log)
|
46
|
+
send_to_file(msg, :log)
|
47
|
+
end
|
48
|
+
|
49
|
+
def log(msg)
|
50
|
+
return if @silencer
|
51
|
+
STDOUT.print "#{Time.now.strftime("%H:%M:%S")}: #{msg}\n".color(:white)
|
52
|
+
send_to_syslog(msg, :debug)
|
53
|
+
send_to_file(msg, :debug)
|
54
|
+
end
|
55
|
+
|
56
|
+
def helo(msg, pid_file = nil)
|
57
|
+
STDOUT.print "[*] #{msg} at #{Time.now.strftime("%H:%M:%S")}\n".color(:white)
|
58
|
+
send_to_syslog(msg, :helo)
|
59
|
+
send_to_file(msg, :helo)
|
60
|
+
Codesake::Commons::Io.create_pid_file(pid_file) unless pid_file.nil?
|
61
|
+
end
|
62
|
+
|
63
|
+
def toggle_silence
|
64
|
+
@silencer = ! @silencer
|
65
|
+
@verbose = ! @silencer
|
66
|
+
end
|
67
|
+
|
68
|
+
def toggle_syslog
|
69
|
+
@syslog = ! @syslog
|
70
|
+
warn("codesake messages to syslog are now disabled") unless @syslog
|
71
|
+
ok("codesake messages to syslog are now enabled") if @syslog
|
72
|
+
end
|
73
|
+
|
74
|
+
private
|
75
|
+
def send_to_file(msg, level)
|
76
|
+
return false if @filename.nil?
|
77
|
+
f = File.open(@filename, "a")
|
78
|
+
f.write("#{Time.now.strftime("[%d/%m/%Y %H:%M:%S]")} - #{level.to_s} - #{msg}\n")
|
79
|
+
f.close
|
80
|
+
end
|
81
|
+
|
82
|
+
def send_to_syslog(msg, level)
|
83
|
+
return false unless @syslog
|
84
|
+
|
85
|
+
log = Syslog.open("codesake") unless Syslog.opened?
|
86
|
+
log = Syslog.reopen("codesake") if Syslog.opened?
|
87
|
+
log.debug(msg.to_s) if level == :debug
|
88
|
+
log.warn(msg.to_s) if level == :warn
|
89
|
+
log.info(msg.to_s) if level == :helo
|
90
|
+
log.notice(msg.to_s) if level == :log
|
91
|
+
log.err(msg.to_s) if level == :error
|
92
|
+
|
93
|
+
true
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'codesake_commons'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: codesake-commons
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.80.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Paolo Perego
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-09-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rainbow
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: codesake.com is an application security startup providing code review
|
28
|
+
and penetration test services for Ruby powered web applications. codesake_commons
|
29
|
+
is the gem containing common ground routines useful across the project
|
30
|
+
email:
|
31
|
+
- thesp0nge@gmail.com
|
32
|
+
executables: []
|
33
|
+
extensions: []
|
34
|
+
extra_rdoc_files: []
|
35
|
+
files:
|
36
|
+
- .document
|
37
|
+
- .gitignore
|
38
|
+
- .rspec
|
39
|
+
- .ruby-gemset
|
40
|
+
- .ruby-version
|
41
|
+
- Gemfile
|
42
|
+
- LICENSE.txt
|
43
|
+
- README.md
|
44
|
+
- Rakefile
|
45
|
+
- codesake-commons.gemspec
|
46
|
+
- lib/codesake-commons.rb
|
47
|
+
- lib/codesake/commons/io.rb
|
48
|
+
- lib/codesake/commons/logging.rb
|
49
|
+
- lib/codesake/commons/version.rb
|
50
|
+
- spec/codesake_commons_spec.rb
|
51
|
+
- spec/logging_spec.rb
|
52
|
+
- spec/spec_helper.rb
|
53
|
+
homepage: http://codesake.com
|
54
|
+
licenses: []
|
55
|
+
metadata: {}
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options: []
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - '>='
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
requirements: []
|
71
|
+
rubyforge_project:
|
72
|
+
rubygems_version: 2.0.4
|
73
|
+
signing_key:
|
74
|
+
specification_version: 4
|
75
|
+
summary: codesake_commons is the gem containing common ground routines useful across
|
76
|
+
the codesake.com project
|
77
|
+
test_files:
|
78
|
+
- spec/codesake_commons_spec.rb
|
79
|
+
- spec/logging_spec.rb
|
80
|
+
- spec/spec_helper.rb
|