wiot_parser 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9c64084c9d6c1c1e04c1f454c2789623c0e16af6
4
+ data.tar.gz: 0f77c70c7c6842f852b91a921a59b98550360e8d
5
+ SHA512:
6
+ metadata.gz: 8bb3c27ff23cbdb445215b787c2181f6a1fe24ab5e19b2e21328d972143a3376d12a5c19c4766f85185bb09bca6e91f76f6851f59e0fab1babb83d9e80a965f9
7
+ data.tar.gz: 9c99633a096726c920a2416c740de14a50ba981e1783b474c116c49ffcb825f66f8b3a831a796df4aa9ae2eeb68775fd0aed2ac274b117ca69b68becb6847fe1
data/.gitignore ADDED
@@ -0,0 +1,38 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ ## Specific to RubyMotion:
14
+ .dat*
15
+ .repl_history
16
+ build/
17
+
18
+ ## Documentation cache and generated files:
19
+ /.yardoc/
20
+ /_yardoc/
21
+ /doc/
22
+ /rdoc/
23
+
24
+ ## Environment normalization:
25
+ /.bundle/
26
+ /vendor/bundle
27
+ /lib/bundler/man/
28
+
29
+ # for a library or gem, you might want to ignore these files since the code is
30
+ # intended to run in multiple environments; otherwise, check them in:
31
+ Gemfile.lock
32
+ # .ruby-version
33
+ # .ruby-gemset
34
+
35
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
36
+ .rvmrc
37
+
38
+ .idea/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in wiot-parser.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 watchiot
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,2 @@
1
+ # wiot-evaluator
2
+ Web Monitor System
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "wiot_parser"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,34 @@
1
+ require 'wiot_parser/errors'
2
+ require 'wiot_parser/yaml/yaml_line'
3
+ require 'wiot_parser/yaml/yaml_security'
4
+ require 'wiot_parser/yaml/yaml_parser'
5
+
6
+ module WiotParser
7
+ def self.parse(yaml, constrainers)
8
+
9
+ # try to put more difficult the possible yml exploit with basic validations
10
+ errors = YamlSecurity.valid(yaml)
11
+ return errors unless errors.empty?
12
+
13
+ begin
14
+ obj = YamlParser.parser yaml
15
+ errors = parser_obj obj, constrainers
16
+ rescue => e
17
+ return ParserError.yaml_exception e.message
18
+ end
19
+
20
+ errors
21
+ end
22
+
23
+ def self.token
24
+ %w(ip url params condition critical if less less_equal repeat_min email template)
25
+ end
26
+
27
+ private
28
+
29
+ def self.parser_obj(obj, constrainers)
30
+ errors = {}
31
+ errors['error-' + errors.size.to_s] = ParserError.new(1, 1, 'bafd token')
32
+ errors
33
+ end
34
+ end
@@ -0,0 +1,26 @@
1
+ ##
2
+ #
3
+ #
4
+ module WiotParser
5
+ class Constrainer
6
+
7
+ def initialize(values)
8
+ @params_max = values[:params_max]
9
+ @valid_emails = values[:valid_emails]
10
+ @repeat_email_min = values[:repeat_email_min]
11
+ end
12
+
13
+ def params_max
14
+ @params_max
15
+ end
16
+
17
+ def valid_emails
18
+ @valid_emails
19
+ end
20
+
21
+ def repeat_email_min
22
+ @repeat_email_min
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,27 @@
1
+ ##
2
+ #
3
+ #
4
+ module WiotParser
5
+ class ParserError
6
+ def initialize(row, column, text)
7
+ @row=row
8
+ @column=column
9
+ @text=text
10
+ @type='error'
11
+ end
12
+
13
+ def row
14
+ @row
15
+ end
16
+
17
+ def row=(row)
18
+ @row = row
19
+ end
20
+
21
+ def self.yaml_exception(msg)
22
+ errors = {}
23
+ errors['error-' + errors.size.to_s] = ParserError.new(1, 1, msg)
24
+ errors
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ module WiotParser
2
+ VERSION = "0.1.6"
3
+ end
@@ -0,0 +1,62 @@
1
+ require 'psych'
2
+
3
+ ##
4
+ #
5
+ #
6
+ module WiotParser
7
+
8
+ # Psych's first step is to parse the Yaml into an AST of Node objects
9
+ # so we open the Node class and add a way to track the line.
10
+ class Psych::Nodes::Node
11
+ attr_accessor :line
12
+ end
13
+
14
+ # We need to provide a handler that will add the line to the node
15
+ # as it is parsed. TreeBuilder is the "usual" handler, that
16
+ # creates the AST.
17
+ class LineNumberHandler < Psych::TreeBuilder
18
+
19
+ # The handler needs access to the parser in order to call mark
20
+ attr_accessor :parser
21
+
22
+ # We are only interested in scalars, so here we override
23
+ # the method so that it calls mark and adds the line info
24
+ # to the node.
25
+ def scalar value, anchor, tag, plain, quoted, style
26
+ mark = parser.mark
27
+ s = super
28
+ s.line = mark.line
29
+ s
30
+ end
31
+ end
32
+
33
+ # The next step is to convert the AST to a Ruby object.
34
+ # Psych does this using the visitor pattern with the ToRuby
35
+ # visitor. Here we patch ToRuby rather than inherit from it
36
+ # as it makes the last step a little easier.
37
+ class Psych::Visitors::ToRuby
38
+
39
+ # This is the method for creating hashes. There may be problems
40
+ # with Yaml mappings that have tags.
41
+ def revive_hash hash, o
42
+ o.children.each_slice(2) { |k,v|
43
+ key = accept(k)
44
+ val = accept(v)
45
+
46
+ # This is the important bit. If the value is a scalar,
47
+ # we replace it with the desired hash.
48
+ if v.is_a? ::Psych::Nodes::Scalar
49
+ val = { "value" => val, "line" => v.line}
50
+ end
51
+
52
+ # Code dealing with << (for merging hashes) omitted.
53
+ # If you need this you will probably need to copy it
54
+ # in here. See the method:
55
+ # https://github.com/tenderlove/psych/blob/v2.0.13/lib/psych/visitors/to_ruby.rb#L333-L365
56
+
57
+ hash[key] = val
58
+ }
59
+ hash
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,17 @@
1
+ ##
2
+ #
3
+ #
4
+ module WiotParser
5
+ class YamlParser
6
+ def self.parser(yaml)
7
+ # Put it all together
8
+ handler = LineNumberHandler.new
9
+ parser = Psych::Parser.new(handler)
10
+ # Provide the handler with a reference to the parser
11
+ handler.parser = parser
12
+
13
+ parser.parse yaml
14
+ handler.root.to_ruby[0]
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,12 @@
1
+ ##
2
+ #
3
+ #
4
+ module WiotParser
5
+ class YamlSecurity
6
+ def self.valid(yml)
7
+ errors = {}
8
+ errors['error-' + errors.size.to_s] = ParserError.new(1, 1, 'bafd token')
9
+ errors
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'wiot_parser/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'wiot_parser'
8
+ spec.version = WiotParser::VERSION
9
+ spec.authors = ['gorums']
10
+ spec.email = ['acksecurity@hotmail.com']
11
+
12
+ spec.summary = %q{Yaml configuration parser.}
13
+ spec.description = %q{This gem parse the watchiot yaml configuration.}
14
+ spec.homepage = 'http://www.watchiot.org'
15
+ spec.license = 'MIT'
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+
20
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ spec.bindir = 'exe'
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ['lib']
24
+
25
+ spec.add_development_dependency 'bundler', '~> 1.11'
26
+ spec.add_development_dependency 'rake', '~> 10.0'
27
+ spec.add_development_dependency 'rspec', '~> 3.0'
28
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wiot_parser
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.6
5
+ platform: ruby
6
+ authors:
7
+ - gorums
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-05-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: This gem parse the watchiot yaml configuration.
56
+ email:
57
+ - acksecurity@hotmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE
65
+ - README.md
66
+ - Rakefile
67
+ - bin/console
68
+ - bin/setup
69
+ - lib/wiot_parser.rb
70
+ - lib/wiot_parser/constrainer.rb
71
+ - lib/wiot_parser/errors.rb
72
+ - lib/wiot_parser/version.rb
73
+ - lib/wiot_parser/yaml/yaml_line.rb
74
+ - lib/wiot_parser/yaml/yaml_parser.rb
75
+ - lib/wiot_parser/yaml/yaml_security.rb
76
+ - wiot_parser.gemspec
77
+ homepage: http://www.watchiot.org
78
+ licenses:
79
+ - MIT
80
+ metadata: {}
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 2.6.4
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: Yaml configuration parser.
101
+ test_files: []