{"action":"created","comment":{"url":"https://api.github.com/repos/inverse-inc/packetfence/pulls/comments/26386371","id":26386371,"diff_hunk":"@@ -0,0 +1,241 @@\n+package pf::scan::wmi::rules;\n+\n+=head1 NAME\n+\n+pf::scan::wmi::rules - Test wmi rules\n+\n+=cut\n+\n+=head1 DESCRIPTION\n+\n+pf::scan::wmi::rules deny or allow based on rules.\n+\n+=cut\n+\n+use strict;\n+use warnings;\n+\n+use Log::Log4perl;\n+use Net::WMIClient qw(wmiclient);\n+use Config::IniFiles;\n+use pf::api::jsonrpcclient;\n+use pf::ConfigStore::WMI();\n+\n+our %RULE_OPS = (\n+    is => sub { $_[0] eq $_[1] ? 1 : 0  },\n+    is_not => sub { $_[0] ne $_[1] ? 1 : 0  },\n+    match => sub { $_[0] =~ $_[1] ? 1 : 0  },\n+    match_not => sub { $_[0] !~ $_[1] ? 1 : 0  },\n+);\n+\n+=head1 SUBROUTINES\n+\n+=over\n+\n+=item new\n+\n+=cut\n+\n+sub new {\n+   my $logger = Log::Log4perl::get_logger(\"pf::scan::wmi::rules\");\n+   $logger->debug(\"instantiating new pf::scan::wmi::rules\");\n+   my ( $class, %argv ) = @_;\n+   my $self = bless {}, $class;\n+   return $self;\n+}\n+\n+=item test\n+\n+Test all the rules\n+\n+=cut\n+\n+sub test {\n+    my ($self, $rules) = @_;\n+    my $logger = Log::Log4perl::get_logger( ref($self) );\n+    my $wmics = pf::ConfigStore::WMI->new();\n+\n+    foreach my $rule  ( @{$rules->{'_rules'}} ) {\n+        $logger->warn($rule);\n+        my $rule_config = $wmics->read($rule);\n+        my ($rc, $result) = $self->runWmi($rules,$rule_config);\n+        return $rc if (!$rc);\n+        my $action = join(\"\\n\", @{$rule_config->{'action'}});\n+        my %cfg;\n+        tie %cfg, 'Config::IniFiles', ( -file => \\$action );\n+        foreach my $test  ( sort keys %cfg ) {\n+            if ($test =~ /^\\w+:(.*)$/) {\n+                my $condition = $1;\n+                $condition =~ s/(\\w+)/$self->parse($cfg{$1},$result)/gee;\n+                $condition =~ s/\\|/ \\|\\| /g;\n+                $condition =~ s/\\&/ \\&\\& /g;\n+                $logger->warn($condition);\n+                if (eval $condition) {\n+                    $logger->info(\"Match WMI \".$rule.\" rule: \".$test.\" for \". $rules->{'_scanMac'});\n+                    if ( defined($cfg{$test}->{'action'}) && $cfg{$test}->{'action'} ne '' ) {\n+                        last if ($cfg{$test}->{'action'} =~ /allow/i);\n+                        $self->dispatchAction($cfg{$test},$rules,shift @$result);\n+                    }\n+                }\n+            }\n+        }\n+    }\n+    return 0;\n+}\n+\n+=item runWMI\n+\n+execute WMI command on the remote device\n+\n+=cut\n+\n+sub runWmi {\n+    my ($self, $rules, $rule) = @_;\n+\n+    my $request = {};\n+    $request->{'Username'} = $rules->{'_domain'} .'/'. $rules->{'_username'} .'%'. $rules->{'_password'};\n+    $request->{'Host'} = $rules->{'_scanIp'};\n+    $request->{'Query'} = $rule->{'request'};\n+    my ($rc, $ret_string) = wmiclient($request);\n+    return ($rc,$self->parseResult($ret_string));\n+\n+}\n+\n+=item parseResult\n+\n+Parse the result of the wmicli\n+\n+=cut\n+\n+sub parseResult {\n+    my ($self, $string) = @_;\n+    $string =~ s/\\r\\n/\\n/g;\n+\n+    my @ans = split('\\n', $string);","path":"lib/pf/scan/wmi/rules.pm","position":114,"original_position":114,"commit_id":"fd072a190c5e486302b9a0f7c5d8452554738879","original_commit_id":"fd072a190c5e486302b9a0f7c5d8452554738879","user":{"login":"Ans","id":1011060,"avatar_url":"https://avatars.githubusercontent.com/u/1011060?v=3","gravatar_id":"","url":"https://api.github.com/users/Ans","html_url":"https://github.com/Ans","followers_url":"https://api.github.com/users/Ans/followers","following_url":"https://api.github.com/users/Ans/following{/other_user}","gists_url":"https://api.github.com/users/Ans/gists{/gist_id}","starred_url":"https://api.github.com/users/Ans/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Ans/subscriptions","organizations_url":"https://api.github.com/users/Ans/orgs","repos_url":"https://api.github.com/users/Ans/repos","events_url":"https://api.github.com/users/Ans/events{/privacy}","received_events_url":"https://api.github.com/users/Ans/received_events","type":"User","site_admin":false},"body":"Liked this (y)","created_at":"2015-03-13T13:49:26Z","updated_at":"2015-03-13T13:49:26Z","html_url":"https://github.com/inverse-inc/packetfence/pull/419#discussion_r26386371","pull_request_url":"https://api.github.com/repos/inverse-inc/packetfence/pulls/419","_links":{"self":{"href":"https://api.github.com/repos/inverse-inc/packetfence/pulls/comments/26386371"},"html":{"href":"https://github.com/inverse-inc/packetfence/pull/419#discussion_r26386371"},"pull_request":{"href":"https://api.github.com/repos/inverse-inc/packetfence/pulls/419"}}},"pull_request":{"url":"https://api.github.com/repos/inverse-inc/packetfence/pulls/419","id":31070392,"html_url":"https://github.com/inverse-inc/packetfence/pull/419","diff_url":"https://github.com/inverse-inc/packetfence/pull/419.diff","patch_url":"https://github.com/inverse-inc/packetfence/pull/419.patch","issue_url":"https://api.github.com/repos/inverse-inc/packetfence/issues/419","number":419,"state":"open","locked":false,"title":"WMI integration and reworked scan configuration","user":{"login":"fdurand","id":1553962,"avatar_url":"https://avatars.githubusercontent.com/u/1553962?v=3","gravatar_id":"","url":"https://api.github.com/users/fdurand","html_url":"https://github.com/fdurand","followers_url":"https://api.github.com/users/fdurand/followers","following_url":"https://api.github.com/users/fdurand/following{/other_user}","gists_url":"https://api.github.com/users/fdurand/gists{/gist_id}","starred_url":"https://api.github.com/users/fdurand/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fdurand/subscriptions","organizations_url":"https://api.github.com/users/fdurand/orgs","repos_url":"https://api.github.com/users/fdurand/repos","events_url":"https://api.github.com/users/fdurand/events{/privacy}","received_events_url":"https://api.github.com/users/fdurand/received_events","type":"User","site_admin":false},"body":"Description\r\n-----------\r\nCreated a new scan engine (WMI) only for windows device that are member of a domain.\r\nReworked the scan configuration, now we are able to create multiples scan definition and are able to trigger a scan when a device reach the registration vlan or after registration or on the production vlan.\r\nAdded an external action in the violation.\r\n\r\nImpacts\r\n-------\r\n- Scan engine must be redifined \r\n\r\nNEWS file entries\r\n-------\r\nNew Features\r\n++++++++++++\r\n- Added WMI as a scan engine.\r\n- Multiples scan engine definition based on the OS type, category.\r\n- Scan definition per portal profiles\r\n- New external command action in violation \r\n\r\nDelete branch after merge\r\n-------------------------\r\nYES","created_at":"2015-03-12T19:40:08Z","updated_at":"2015-03-13T13:49:26Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a8795a07bce3b2d7d251189820d14a7071097025","assignee":null,"milestone":{"url":"https://api.github.com/repos/inverse-inc/packetfence/milestones/3","html_url":"https://github.com/inverse-inc/packetfence/milestones/packetfence-5","labels_url":"https://api.github.com/repos/inverse-inc/packetfence/milestones/3/labels","id":981503,"number":3,"title":"packetfence-5","description":"","creator":{"login":"julsemaan","id":3857942,"avatar_url":"https://avatars.githubusercontent.com/u/3857942?v=3","gravatar_id":"","url":"https://api.github.com/users/julsemaan","html_url":"https://github.com/julsemaan","followers_url":"https://api.github.com/users/julsemaan/followers","following_url":"https://api.github.com/users/julsemaan/following{/other_user}","gists_url":"https://api.github.com/users/julsemaan/gists{/gist_id}","starred_url":"https://api.github.com/users/julsemaan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/julsemaan/subscriptions","organizations_url":"https://api.github.com/users/julsemaan/orgs","repos_url":"https://api.github.com/users/julsemaan/repos","events_url":"https://api.github.com/users/julsemaan/events{/privacy}","received_events_url":"https://api.github.com/users/julsemaan/received_events","type":"User","site_admin":false},"open_issues":30,"closed_issues":5,"state":"open","created_at":"2015-02-16T15:52:29Z","updated_at":"2015-03-13T00:25:53Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/inverse-inc/packetfence/pulls/419/commits","review_comments_url":"https://api.github.com/repos/inverse-inc/packetfence/pulls/419/comments","review_comment_url":"https://api.github.com/repos/inverse-inc/packetfence/pulls/comments{/number}","comments_url":"https://api.github.com/repos/inverse-inc/packetfence/issues/419/comments","statuses_url":"https://api.github.com/repos/inverse-inc/packetfence/statuses/fd072a190c5e486302b9a0f7c5d8452554738879","head":{"label":"inverse-inc:feature/wmi","ref":"feature/wmi","sha":"fd072a190c5e486302b9a0f7c5d8452554738879","user":{"login":"inverse-inc","id":1203154,"avatar_url":"https://avatars.githubusercontent.com/u/1203154?v=3","gravatar_id":"","url":"https://api.github.com/users/inverse-inc","html_url":"https://github.com/inverse-inc","followers_url":"https://api.github.com/users/inverse-inc/followers","following_url":"https://api.github.com/users/inverse-inc/following{/other_user}","gists_url":"https://api.github.com/users/inverse-inc/gists{/gist_id}","starred_url":"https://api.github.com/users/inverse-inc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/inverse-inc/subscriptions","organizations_url":"https://api.github.com/users/inverse-inc/orgs","repos_url":"https://api.github.com/users/inverse-inc/repos","events_url":"https://api.github.com/users/inverse-inc/events{/privacy}","received_events_url":"https://api.github.com/users/inverse-inc/received_events","type":"Organization","site_admin":false},"repo":{"id":3595658,"name":"packetfence","full_name":"inverse-inc/packetfence","owner":{"login":"inverse-inc","id":1203154,"avatar_url":"https://avatars.githubusercontent.com/u/1203154?v=3","gravatar_id":"","url":"https://api.github.com/users/inverse-inc","html_url":"https://github.com/inverse-inc","followers_url":"https://api.github.com/users/inverse-inc/followers","following_url":"https://api.github.com/users/inverse-inc/following{/other_user}","gists_url":"https://api.github.com/users/inverse-inc/gists{/gist_id}","starred_url":"https://api.github.com/users/inverse-inc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/inverse-inc/subscriptions","organizations_url":"https://api.github.com/users/inverse-inc/orgs","repos_url":"https://api.github.com/users/inverse-inc/repos","events_url":"https://api.github.com/users/inverse-inc/events{/privacy}","received_events_url":"https://api.github.com/users/inverse-inc/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/inverse-inc/packetfence","description":"PacketFence is a fully supported, trusted, Free and Open Source network access control (NAC) solution. Boasting an impressive feature set including a captive-portal for registration and remediation, centralized wired and wireless management, powerful guest management options, 802.1X support, layer-2 isolation of problematic devices; PacketFence can be used to effectively secure networks small to very large heterogeneous networks.","fork":false,"url":"https://api.github.com/repos/inverse-inc/packetfence","forks_url":"https://api.github.com/repos/inverse-inc/packetfence/forks","keys_url":"https://api.github.com/repos/inverse-inc/packetfence/keys{/key_id}","collaborators_url":"https://api.github.com/repos/inverse-inc/packetfence/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/inverse-inc/packetfence/teams","hooks_url":"https://api.github.com/repos/inverse-inc/packetfence/hooks","issue_events_url":"https://api.github.com/repos/inverse-inc/packetfence/issues/events{/number}","events_url":"https://api.github.com/repos/inverse-inc/packetfence/events","assignees_url":"https://api.github.com/repos/inverse-inc/packetfence/assignees{/user}","branches_url":"https://api.github.com/repos/inverse-inc/packetfence/branches{/branch}","tags_url":"https://api.github.com/repos/inverse-inc/packetfence/tags","blobs_url":"https://api.github.com/repos/inverse-inc/packetfence/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/inverse-inc/packetfence/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/inverse-inc/packetfence/git/refs{/sha}","trees_url":"https://api.github.com/repos/inverse-inc/packetfence/git/trees{/sha}","statuses_url":"https://api.github.com/repos/inverse-inc/packetfence/statuses/{sha}","languages_url":"https://api.github.com/repos/inverse-inc/packetfence/languages","stargazers_url":"https://api.github.com/repos/inverse-inc/packetfence/stargazers","contributors_url":"https://api.github.com/repos/inverse-inc/packetfence/contributors","subscribers_url":"https://api.github.com/repos/inverse-inc/packetfence/subscribers","subscription_url":"https://api.github.com/repos/inverse-inc/packetfence/subscription","commits_url":"https://api.github.com/repos/inverse-inc/packetfence/commits{/sha}","git_commits_url":"https://api.github.com/repos/inverse-inc/packetfence/git/commits{/sha}","comments_url":"https://api.github.com/repos/inverse-inc/packetfence/comments{/number}","issue_comment_url":"https://api.github.com/repos/inverse-inc/packetfence/issues/comments{/number}","contents_url":"https://api.github.com/repos/inverse-inc/packetfence/contents/{+path}","compare_url":"https://api.github.com/repos/inverse-inc/packetfence/compare/{base}...{head}","merges_url":"https://api.github.com/repos/inverse-inc/packetfence/merges","archive_url":"https://api.github.com/repos/inverse-inc/packetfence/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/inverse-inc/packetfence/downloads","issues_url":"https://api.github.com/repos/inverse-inc/packetfence/issues{/number}","pulls_url":"https://api.github.com/repos/inverse-inc/packetfence/pulls{/number}","milestones_url":"https://api.github.com/repos/inverse-inc/packetfence/milestones{/number}","notifications_url":"https://api.github.com/repos/inverse-inc/packetfence/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/inverse-inc/packetfence/labels{/name}","releases_url":"https://api.github.com/repos/inverse-inc/packetfence/releases{/id}","created_at":"2012-03-01T20:21:13Z","updated_at":"2015-03-13T12:31:51Z","pushed_at":"2015-03-13T12:31:51Z","git_url":"git://github.com/inverse-inc/packetfence.git","ssh_url":"git@github.com:inverse-inc/packetfence.git","clone_url":"https://github.com/inverse-inc/packetfence.git","svn_url":"https://github.com/inverse-inc/packetfence","homepage":"http://www.packetfence.org","size":111286,"stargazers_count":107,"watchers_count":107,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":57,"mirror_url":null,"open_issues_count":55,"forks":57,"open_issues":55,"watchers":107,"default_branch":"devel"}},"base":{"label":"inverse-inc:devel","ref":"devel","sha":"b5582f238f3bee5bb95fb3942596d458d7080ea7","user":{"login":"inverse-inc","id":1203154,"avatar_url":"https://avatars.githubusercontent.com/u/1203154?v=3","gravatar_id":"","url":"https://api.github.com/users/inverse-inc","html_url":"https://github.com/inverse-inc","followers_url":"https://api.github.com/users/inverse-inc/followers","following_url":"https://api.github.com/users/inverse-inc/following{/other_user}","gists_url":"https://api.github.com/users/inverse-inc/gists{/gist_id}","starred_url":"https://api.github.com/users/inverse-inc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/inverse-inc/subscriptions","organizations_url":"https://api.github.com/users/inverse-inc/orgs","repos_url":"https://api.github.com/users/inverse-inc/repos","events_url":"https://api.github.com/users/inverse-inc/events{/privacy}","received_events_url":"https://api.github.com/users/inverse-inc/received_events","type":"Organization","site_admin":false},"repo":{"id":3595658,"name":"packetfence","full_name":"inverse-inc/packetfence","owner":{"login":"inverse-inc","id":1203154,"avatar_url":"https://avatars.githubusercontent.com/u/1203154?v=3","gravatar_id":"","url":"https://api.github.com/users/inverse-inc","html_url":"https://github.com/inverse-inc","followers_url":"https://api.github.com/users/inverse-inc/followers","following_url":"https://api.github.com/users/inverse-inc/following{/other_user}","gists_url":"https://api.github.com/users/inverse-inc/gists{/gist_id}","starred_url":"https://api.github.com/users/inverse-inc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/inverse-inc/subscriptions","organizations_url":"https://api.github.com/users/inverse-inc/orgs","repos_url":"https://api.github.com/users/inverse-inc/repos","events_url":"https://api.github.com/users/inverse-inc/events{/privacy}","received_events_url":"https://api.github.com/users/inverse-inc/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/inverse-inc/packetfence","description":"PacketFence is a fully supported, trusted, Free and Open Source network access control (NAC) solution. Boasting an impressive feature set including a captive-portal for registration and remediation, centralized wired and wireless management, powerful guest management options, 802.1X support, layer-2 isolation of problematic devices; PacketFence can be used to effectively secure networks small to very large heterogeneous networks.","fork":false,"url":"https://api.github.com/repos/inverse-inc/packetfence","forks_url":"https://api.github.com/repos/inverse-inc/packetfence/forks","keys_url":"https://api.github.com/repos/inverse-inc/packetfence/keys{/key_id}","collaborators_url":"https://api.github.com/repos/inverse-inc/packetfence/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/inverse-inc/packetfence/teams","hooks_url":"https://api.github.com/repos/inverse-inc/packetfence/hooks","issue_events_url":"https://api.github.com/repos/inverse-inc/packetfence/issues/events{/number}","events_url":"https://api.github.com/repos/inverse-inc/packetfence/events","assignees_url":"https://api.github.com/repos/inverse-inc/packetfence/assignees{/user}","branches_url":"https://api.github.com/repos/inverse-inc/packetfence/branches{/branch}","tags_url":"https://api.github.com/repos/inverse-inc/packetfence/tags","blobs_url":"https://api.github.com/repos/inverse-inc/packetfence/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/inverse-inc/packetfence/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/inverse-inc/packetfence/git/refs{/sha}","trees_url":"https://api.github.com/repos/inverse-inc/packetfence/git/trees{/sha}","statuses_url":"https://api.github.com/repos/inverse-inc/packetfence/statuses/{sha}","languages_url":"https://api.github.com/repos/inverse-inc/packetfence/languages","stargazers_url":"https://api.github.com/repos/inverse-inc/packetfence/stargazers","contributors_url":"https://api.github.com/repos/inverse-inc/packetfence/contributors","subscribers_url":"https://api.github.com/repos/inverse-inc/packetfence/subscribers","subscription_url":"https://api.github.com/repos/inverse-inc/packetfence/subscription","commits_url":"https://api.github.com/repos/inverse-inc/packetfence/commits{/sha}","git_commits_url":"https://api.github.com/repos/inverse-inc/packetfence/git/commits{/sha}","comments_url":"https://api.github.com/repos/inverse-inc/packetfence/comments{/number}","issue_comment_url":"https://api.github.com/repos/inverse-inc/packetfence/issues/comments{/number}","contents_url":"https://api.github.com/repos/inverse-inc/packetfence/contents/{+path}","compare_url":"https://api.github.com/repos/inverse-inc/packetfence/compare/{base}...{head}","merges_url":"https://api.github.com/repos/inverse-inc/packetfence/merges","archive_url":"https://api.github.com/repos/inverse-inc/packetfence/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/inverse-inc/packetfence/downloads","issues_url":"https://api.github.com/repos/inverse-inc/packetfence/issues{/number}","pulls_url":"https://api.github.com/repos/inverse-inc/packetfence/pulls{/number}","milestones_url":"https://api.github.com/repos/inverse-inc/packetfence/milestones{/number}","notifications_url":"https://api.github.com/repos/inverse-inc/packetfence/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/inverse-inc/packetfence/labels{/name}","releases_url":"https://api.github.com/repos/inverse-inc/packetfence/releases{/id}","created_at":"2012-03-01T20:21:13Z","updated_at":"2015-03-13T12:31:51Z","pushed_at":"2015-03-13T12:31:51Z","git_url":"git://github.com/inverse-inc/packetfence.git","ssh_url":"git@github.com:inverse-inc/packetfence.git","clone_url":"https://github.com/inverse-inc/packetfence.git","svn_url":"https://github.com/inverse-inc/packetfence","homepage":"http://www.packetfence.org","size":111286,"stargazers_count":107,"watchers_count":107,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":57,"mirror_url":null,"open_issues_count":55,"forks":57,"open_issues":55,"watchers":107,"default_branch":"devel"}},"_links":{"self":{"href":"https://api.github.com/repos/inverse-inc/packetfence/pulls/419"},"html":{"href":"https://github.com/inverse-inc/packetfence/pull/419"},"issue":{"href":"https://api.github.com/repos/inverse-inc/packetfence/issues/419"},"comments":{"href":"https://api.github.com/repos/inverse-inc/packetfence/issues/419/comments"},"review_comments":{"href":"https://api.github.com/repos/inverse-inc/packetfence/pulls/419/comments"},"review_comment":{"href":"https://api.github.com/repos/inverse-inc/packetfence/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/inverse-inc/packetfence/pulls/419/commits"},"statuses":{"href":"https://api.github.com/repos/inverse-inc/packetfence/statuses/fd072a190c5e486302b9a0f7c5d8452554738879"}}}}