diff --git a/Gruntfile.js b/Gruntfile.js deleted file mode 100644 index 49c895f2aa047e564ce03cc0ebc11d5d225d4d62..0000000000000000000000000000000000000000 --- a/Gruntfile.js +++ /dev/null @@ -1,383 +0,0 @@ -module.exports = function(grunt) { - - function cbk_dir_size(err, stdout, stderr, cb) { - grunt.config.set('template.deb-control.options.data.package_size', stdout.trim()); - cb(); - } - - function version() { - return '<%= meta.version_major %>.<%= meta.version_minor %>'; - } - - function package_filename_deb(lang) { - return '<%= meta.name %>-' + lang + '_' + version() + '_<%= meta.architecture %>.deb'; - } - function package_filename_tar(lang, nover) { - var vs = ''; - if (nover) { vs = 'latest'; } else { vs = version(); } - return '<%= meta.name %>-' + lang + '_' + vs + '_stable.tar.gz'; - } - - // Project configuration. - grunt.initConfig({ - - pkg: grunt.file.readJSON('package.json'), - meta: grunt.file.readJSON('meta.json'), - - // Python project paths to important directories - project_paths_python: { - 'deploy_dir': 'lib_python/deploy/', - 'package_dir': 'lib_python/deploy/package/', - 'control_dir': 'lib_python/deploy/ctrl/', - 'archive_dir': 'lib_python/deploy/archive/' - }, - // Perl project paths to important directories - project_paths_perl: { - 'deploy_dir': 'lib_perl/deploy/', - 'package_dir': 'lib_perl/deploy/package/', - 'control_dir': 'lib_perl/deploy/ctrl/', - 'archive_dir': 'lib_perl/deploy/archive/' - }, - // Paths related to Python DEB packages - paths_deb_python: { - 'bin_dir': 'usr/local/bin/', - 'etc_dir': 'usr/share/idea/', - 'lib_dir': 'usr/lib/python3/dist-packages/', - 'doc_dir': 'usr/share/doc/idea/', - 'man_dir': 'usr/share/man/' - }, - // Paths related to Perl DEB packages - paths_deb_perl: { - 'bin_dir': 'usr/local/bin/', - 'etc_dir': 'usr/share/idea/', - 'lib_dir': 'usr/local/lib/site_perl/', - 'doc_dir': 'usr/share/doc/idea/', - 'man_dir': 'usr/share/man/' - }, - // Paths related to Python TAR packages - paths_tar_python: { - 'bin_dir': 'opt/idea/bin/', - 'etc_dir': 'opt/idea/etc/', - 'lib_dir': 'opt/idea/lib_python/', - 'doc_dir': 'opt/idea/doc/', - 'man_dir': 'opt/idea/man/' - }, - // Paths related to Perl TAR packages - paths_tar_perl: { - 'bin_dir': 'opt/idea/bin/', - 'etc_dir': 'opt/idea/etc/', - 'lib_dir': 'opt/idea/lib_perl/', - 'doc_dir': 'opt/idea/doc/', - 'man_dir': 'opt/idea/man/' - }, - - // --------------------------------------------------------------------- - // Cleanup various destinations - clean: { - // Cleanup package directory - build_python: { - src: [ - "<%= project_paths_python.package_dir %>" - ] - }, - // Cleanup package directory - build_perl: { - src: [ - "<%= project_paths_perl.package_dir %>" - ] - } - }, - - // --------------------------------------------------------------------- - // Running shel commands - shell: { - // Update NodeJS packages (Grunt, grunt plugins...) - npm: { - command: 'npm update' - }, - // Calculate directory size - dir_size_python: { - command: '/usr/bin/du -k -s <%= project_paths_python.package_dir %> | /usr/bin/cut -f 1', - options: { - callback: cbk_dir_size - } - }, - // Calculate directory size - dir_size_perl: { - command: '/usr/bin/du -k -s <%= project_paths_perl.package_dir %> | /usr/bin/cut -f 1', - options: { - callback: cbk_dir_size - } - }, - // Archive Python DEB packages - archive_deb_python: { - command: 'mv <%= project_paths_python.deploy_dir %>*.deb <%= project_paths_python.archive_dir %>' - }, - // Archive Perl DEB packages - archive_deb_perl: { - command: 'mv <%= project_paths_perl.deploy_dir %>*.deb <%= project_paths_perl.archive_dir %>' - }, - // Archive Python TAR packages - archive_tar_python: { - command: 'mv <%= project_paths_python.deploy_dir %>*.tar.gz <%= project_paths_python.archive_dir %>' - }, - // Archive Perl TAR packages - archive_tar_perl: { - command: 'mv <%= project_paths_perl.deploy_dir %>*.tar.gz <%= project_paths_perl.archive_dir %>' - }, - // Build Python DEB package - build_deb_python: { - command: '/usr/bin/fakeroot /usr/bin/dpkg-deb --build <%= project_paths_python.package_dir %> <%= project_paths_python.deploy_dir %>' + package_filename_deb('python') - }, - // Build Perl DEB package - build_deb_perl: { - command: '/usr/bin/fakeroot /usr/bin/dpkg-deb --build <%= project_paths_perl.package_dir %> <%= project_paths_perl.deploy_dir %>' + package_filename_deb('perl') - }, - // Build Python TAR package - build_tar_python: { - command: '/usr/bin/fakeroot /bin/tar -czf <%= project_paths_python.deploy_dir %>' + package_filename_tar('python', false) + ' -C <%= project_paths_python.package_dir %> .' - }, - // Build Perl TAR package - build_tar_perl: { - command: '/usr/bin/fakeroot /bin/tar -czf <%= project_paths_perl.deploy_dir %>' + package_filename_tar('perl', false) + ' -C <%= project_paths_perl.package_dir %> .' - }, - // FTP deployment - //ftp_deploy: { - // command: 'lftp -f .lftp' - //}, - // SCP Python DEB deployment - scp_upload_deb_python: { - command: '/usr/bin/scp <%= project_paths_python.deploy_dir %>' + package_filename_deb('python') + ' <%= meta.server %>:<%= meta.server_dir_deb %>' - }, - // SCP Perl DEB deployment - scp_upload_deb_perl: { - command: '/usr/bin/scp <%= project_paths_perl.deploy_dir %>' + package_filename_deb('perl') + ' <%= meta.server %>:<%= meta.server_dir_deb %>' - }, - // SCP Python TAR deployment - scp_upload_tar_python: { - command: '/usr/bin/scp <%= project_paths_python.deploy_dir %>' + package_filename_tar('python', false) + ' <%= meta.server %>:<%= meta.server_dir_tar %>' - }, - scp_upload_tar_python_l: { - command: '/usr/bin/scp <%= project_paths_python.deploy_dir %>' + package_filename_tar('python', true) + ' <%= meta.server %>:<%= meta.server_dir_tar %>' - }, - // SCP Perl TAR deployment - scp_upload_tar_perl: { - command: '/usr/bin/scp <%= project_paths_perl.deploy_dir %>' + package_filename_tar('perl', false) + ' <%= meta.server %>:<%= meta.server_dir_tar %>' - }, - scp_upload_tar_perl_l: { - command: '/usr/bin/scp <%= project_paths_perl.deploy_dir %>' + package_filename_tar('perl', true) + ' <%= meta.server %>:<%= meta.server_dir_tar %>' - }, - // SSH install - ssh_install_python: { - command: '/usr/bin/ssh <%= meta.server %> /usr/bin/dpkg -i <%= meta.server_dir_deb %>' + package_filename_deb('python') - }, - // SSH install - ssh_install_perl: { - command: '/usr/bin/ssh <%= meta.server %> /usr/bin/dpkg -i <%= meta.server_dir_deb %>' + package_filename_deb('perl') - }, - // SSH DEB repository update - ssh_aptrepo_update: { - command: '/usr/bin/ssh mach@<%= meta.server %> apt-update mentat' - } - }, - - // --------------------------------------------------------------------- - // Fill in certain template files - template: { - control_deb_python: { - 'options': { - 'data': { - 'package_name': '<%= meta.name %>-python', - 'package_version': version(), - 'package_size': '0', - 'architecture': '<%= meta.architecture %>' - } - }, - 'files': { - '<%= project_paths_python.package_dir %>DEBIAN/control': ['<%= project_paths_python.control_dir %>control.tmpl'] - } - }, - control_deb_perl: { - 'options': { - 'data': { - 'package_name': '<%= meta.name %>-perl', - 'package_version': version(), - 'package_size': '0', - 'architecture': '<%= meta.architecture %>' - } - }, - 'files': { - '<%= project_paths_perl.package_dir %>DEBIAN/control': ['<%= project_paths_perl.control_dir %>control.tmpl'] - } - }, - version_deb_perl: { - 'options': { - 'data': { - 'package_version': version() - } - }, - 'files': { - '<%= project_paths_perl.package_dir %><%= paths_deb_perl.doc_dir %>version': ['<%= project_paths_perl.control_dir %>version.tmpl'] - } - }, - version_tar_perl: { - 'options': { - 'data': { - 'package_version': version() - } - }, - 'files': { - '<%= project_paths_perl.package_dir %><%= paths_tar_perl.doc_dir %>version': ['<%= project_paths_perl.control_dir %>version.tmpl'] - } - } - }, - - // --------------------------------------------------------------------- - // Copy certain files to appropriate locations - copy: { - // Copy components for DEB package - deb_python: { - files: [ - // ----- Move binaries to package location - { - expand: true, - cwd: 'lib_python/bin/', - src: './*', - dest: '<%= project_paths_python.package_dir %><%= paths_deb_python.bin_dir %>' - }, - // ----- Move libraries to package location - { - expand: true, - cwd: 'lib_python/lib/', - src: './**', - dest: '<%= project_paths_python.package_dir %><%= paths_deb_python.lib_dir %>' - }, - // ----- Move etc files to package location - { - expand: true, - cwd: 'schema/', - src: './**', - dest: '<%= project_paths_python.package_dir %><%= paths_deb_python.etc_dir %>' - } - ] - }, - // Copy components for DEB package - deb_perl: { - files: [ - // ----- Move binaries to package location - { - expand: true, - cwd: 'lib_perl/bin/', - src: './*', - dest: '<%= project_paths_perl.package_dir %><%= paths_deb_perl.bin_dir %>' - }, - // ----- Move libraries to package location - { - expand: true, - cwd: 'lib_perl/lib/', - src: './**', - dest: '<%= project_paths_perl.package_dir %><%= paths_deb_perl.lib_dir %>' - }, - // ----- Move etc files to package location - { - expand: true, - cwd: 'schema/', - src: './**', - dest: '<%= project_paths_perl.package_dir %><%= paths_deb_perl.etc_dir %>' - } - ] - }, - // Copy components for DEB package - tar_perl: { - files: [ - // ----- Move binaries to package location - { - expand: true, - cwd: 'lib_perl/bin/', - src: './*', - dest: '<%= project_paths_perl.package_dir %><%= paths_tar_perl.bin_dir %>' - }, - // ----- Move libraries to package location - { - expand: true, - cwd: 'lib_perl/lib/', - src: './**', - dest: '<%= project_paths_perl.package_dir %><%= paths_tar_perl.lib_dir %>' - }, - // ----- Move config to package location - { - expand: true, - cwd: 'schema/', - src: './**', - dest: '<%= project_paths_perl.package_dir %><%= paths_tar_perl.etc_dir %>' - } - ] - }, - latest_tar_perl: { - files: [ - { - src: '<%= project_paths_perl.deploy_dir %>' + package_filename_tar('perl', false), - dest: '<%= project_paths_perl.deploy_dir %>' + package_filename_tar('perl', true), - } - ] - } - }, - - // --------------------------------------------------------------------- - // Make sure all files have necessary file permissions - chmod: { - options: { - mode: '755' - }, - deb_bin_python: { - src: ['<%= project_paths_python.package_dir %><%= paths_deb_python.bin_dir %>/*'] - }, - deb_bin_perl: { - src: ['<%= project_paths_perl.package_dir %><%= paths_deb_perl.bin_dir %>/*'] - }, - tar_bin_python: { - src: ['<%= project_paths_python.package_dir %><%= paths_tar_python.bin_dir %>/*'] - }, - tar_bin_perl: { - src: ['<%= project_paths_perl.package_dir %><%= paths_tar_perl.bin_dir %>/*'] - } - } - - }); - - // --------------------------------------------------------------------- - // Load grunt modules - require('load-grunt-tasks')(grunt, { scope: 'devDependencies' }); - require('time-grunt')(grunt); - - grunt.registerTask('inc-version', function() { - v = grunt.config.get('meta.version_minor'); - grunt.config.set('meta.version_minor', v + 1); - console.log("Incremented version to: " + grunt.template.process(version())); - grunt.config.set('template.deb-control.options.data.package_version', grunt.template.process(version())); - }); - - grunt.registerTask('save-meta', function() { - try { - obj = JSON.parse(JSON.stringify(grunt.config.get('meta'))); - } catch (e){ - grunt.log.error(e); - grunt.fail.warn("Error parsing the JSON data.", 3); - } - grunt.file.write('meta.json', JSON.stringify(obj, null, 4)); - }); - - // --------------------------------------------------------------------- - // Setup custom task(s). - grunt.registerTask('next-version', ['inc-version', 'save-meta']); - grunt.registerTask('build-deb-perl', ['clean:build_perl', 'shell:archive_deb_perl', 'copy:deb_perl', 'chmod:deb_bin_perl', 'shell:dir_size_perl', 'template:control_deb_perl', 'template:version_deb_perl', 'shell:build_deb_perl', 'clean:build_perl']); - grunt.registerTask('build-tar-perl', ['clean:build_perl', 'shell:archive_tar_perl', 'copy:tar_perl', 'chmod:tar_bin_perl', 'template:version_tar_perl', 'shell:build_tar_perl', 'clean:build_perl', 'copy:latest_tar_perl']); - grunt.registerTask('build-perl', ['build-deb-perl', 'build-tar-perl']); - grunt.registerTask('deploy-deb-perl', ['build-deb-perl', 'shell:scp_upload_deb_perl', 'shell:ssh_aptrepo_update']); - grunt.registerTask('deploy-tar-perl', ['build-tar-perl', 'shell:scp_upload_tar_perl', 'shell:scp_upload_tar_perl_l']); - grunt.registerTask('deploy-perl', ['deploy-deb-perl', 'shell:ssh_aptrepo_update', 'deploy-tar-perl']); - //grunt.registerTask('ftp-deploy', ['shell:ftp_deploy']); - - grunt.registerTask('update', ['shell:npm']); - grunt.registerTask('default', ['update']); -}; diff --git a/lib_python/lib/idea-format/LICENSE b/LICENSE similarity index 100% rename from lib_python/lib/idea-format/LICENSE rename to LICENSE diff --git a/lib_python/lib/idea-format/Makefile b/Makefile similarity index 100% rename from lib_python/lib/idea-format/Makefile rename to Makefile diff --git a/lib_python/lib/idea-format/README.rst b/README.rst similarity index 100% rename from lib_python/lib/idea-format/README.rst rename to README.rst diff --git a/lib_python/lib/idea-format/archive/.gitignore b/archive/.gitignore similarity index 100% rename from lib_python/lib/idea-format/archive/.gitignore rename to archive/.gitignore diff --git a/lib_python/lib/idea-format/bench_idea.py b/bench_idea.py similarity index 100% rename from lib_python/lib/idea-format/bench_idea.py rename to bench_idea.py diff --git a/lib_python/bin/json-schema-validate.py b/bin/json-schema-validate.py similarity index 100% rename from lib_python/bin/json-schema-validate.py rename to bin/json-schema-validate.py diff --git a/lib_python/bin/jsonschema2dokudoc.py b/bin/jsonschema2dokudoc.py similarity index 100% rename from lib_python/bin/jsonschema2dokudoc.py rename to bin/jsonschema2dokudoc.py diff --git a/lib_python/bin/jsonschema2mentat.py b/bin/jsonschema2mentat.py similarity index 100% rename from lib_python/bin/jsonschema2mentat.py rename to bin/jsonschema2mentat.py diff --git a/lib_python/bin/jsonschema2moindoc.py b/bin/jsonschema2moindoc.py similarity index 100% rename from lib_python/bin/jsonschema2moindoc.py rename to bin/jsonschema2moindoc.py diff --git a/lib_python/lib/idea-format/dist/.gitignore b/dist/.gitignore similarity index 100% rename from lib_python/lib/idea-format/dist/.gitignore rename to dist/.gitignore diff --git a/lib_python/lib/idea-format/idea/__init__.py b/idea/__init__.py similarity index 100% rename from lib_python/lib/idea-format/idea/__init__.py rename to idea/__init__.py diff --git a/lib_python/lib/idea-format/idea/base.py b/idea/base.py similarity index 100% rename from lib_python/lib/idea-format/idea/base.py rename to idea/base.py diff --git a/lib_python/lib/idea-format/idea/lite.py b/idea/lite.py similarity index 100% rename from lib_python/lib/idea-format/idea/lite.py rename to idea/lite.py diff --git a/lib_python/lib/idea-format/idea/valid.py b/idea/valid.py similarity index 100% rename from lib_python/lib/idea-format/idea/valid.py rename to idea/valid.py diff --git a/lib_perl/bin/idea-validator b/lib_perl/bin/idea-validator deleted file mode 100755 index d2674c430b52f923760b954ce3b3fa3859cb6eab..0000000000000000000000000000000000000000 --- a/lib_perl/bin/idea-validator +++ /dev/null @@ -1,193 +0,0 @@ -#!/usr/bin/perl -T - -use strict; -use warnings; - -#******************************************************************************* -# DOCUMENTATION SECTION -#******************************************************************************* - -=head1 NAME - -idea-validator - Simple IDEA message validator - -=head1 SYNOPSIS - - # Either use the anonymous pipe - cat message.idea | idea-validator - - # Or pass the message file as the first argument - idea-validator message.idea - -=head1 OPTIONS AND ARGUMENTS - -=over - -=item B<--help> - -Display short application help - -=item B<--man> - -Display full man page - -=item B<--strict> - -Turn on the strict mode - -=item B<--schema-file PATH> - -Select different JSON schema file - -=back - -=head1 DESCRIPTION - -The purpose of this program is to validate the IDEA message stored in a given text file, -or passed on standard input. It is intended to be used as a simple tool to test generated -IDEA messages. - -=head1 AUTHOR - - Jan Mach - jan.mach@cesnet.cz - Cesnet, z.s.p.o - http://www.cesnet.cz - -=head1 COPYRIGHT - -This program is free software; you can redistribute -it and/or modify it under the same terms as Perl itself. - -The full text of the license can be found in the -LICENSE file included with this module. - - -=head1 SEE ALSO - -perl(1), Mentat::Message::Validator::IDEA(3). - -=cut - -#******************************************************************************* -# LIBRARY LOADING SECTION -#******************************************************************************* - -#-- Perl core modules ---------------------------------------------------------# -use Getopt::Long; -use Pod::Usage; - -use Data::Dumper; #--- DEVELOPMENT ONLY ---# -#use Smart::Comments; #--- DEVELOPMENT ONLY ---# - -#-- Perl CPAN modules ---------------------------------------------------------# - -#-- Custom application modules ------------------------------------------------# - -# Location of the schema file -my $SCHEMA_FILE; - -# We must add the custom library location to the INC path, if we are in development -# process, or if the package was installed from tarball -use Cwd qw(abs_path); -use FindBin; -unless ($FindBin::Bin =~ m|^/usr/local/bin|) { - # Tarball installation - if ($FindBin::Bin =~ m|^/opt/mentat/bin|) { - use lib "/opt/libcesnet-toolkit-perl/lib"; - use lib "/opt/idea/lib_perl"; - use lib "/opt/mentat/lib"; - $SCHEMA_FILE = '/opt/mentat/etc/schema-idea.conf'; - } - # Development environment - elsif (not $FindBin::Bin =~ m|tests/unit/bin|) { - use lib (abs_path("$FindBin::Bin/../lib") =~ m{^(/.*)$})[0]; - $SCHEMA_FILE = '../etc/schema-idea.conf'; - } - # Unit test environment - else { - use lib (abs_path("$FindBin::Bin/../lib") =~ m{^(/.*)$})[0]; - use lib (abs_path("$FindBin::Bin/../../../lib") =~ m{^(/.*)$})[0]; - $SCHEMA_FILE = '../conf/schema-idea.conf'; - } -} -else { - $SCHEMA_FILE = '/etc/mentat/schema-idea.json'; -} - -use Mentat::Message::Factory; -use Mentat::Message::Validator::IDEA; - -#******************************************************************************* -# CONSTANTS AND GLOBAL VARIABLES DEFINITION SECTION -#******************************************************************************* - -#-- Constants -----------------------------------------------------------------# - -#-- Static public class variables (our) ---------------------------------------# - -#-- Static protected class variables (my) -------------------------------------# - -# Configurations for the environment -my $FLAG_HELP = 0; -my $FLAG_MAN = 0; -my $FLAG_STRICT = 0; - -#******************************************************************************* -# INITIALIZATION AND CLEANUP SECTION -#******************************************************************************* - -#-- Module initializations ----------------------------------------------------# -BEGIN { - use vars qw($VERSION); - $VERSION = '0.1'; - $ENV{PATH} = '/bin:/usr/bin'; - $ENV{ENV} = undef; -} - -#-- Module clean-up code (global destructor) ----------------------------------# -END { - -} - -#******************************************************************************* -# IMPLEMENTATION SECTION -#******************************************************************************* - -# Parse application options -my $result = GetOptions ('help' => \$FLAG_HELP, 'man' => \$FLAG_MAN, 'strict' => \$FLAG_STRICT, 'schema-file=s' => \$SCHEMA_FILE); -pod2usage(-verbose => 0, -exitval => 1) unless $result; -pod2usage(-verbose => 1, -exitval => 0) if $FLAG_HELP; -pod2usage(-verbose => 2, -exitval => 0) if $FLAG_MAN; -die "Invalid schema file '$SCHEMA_FILE'\n" unless -f $SCHEMA_FILE; - -# Prepare the validator -my $validator = Mentat::Message::Validator::IDEA->new($SCHEMA_FILE); - -# Load IDEA message to one string from standard input, or given file -my $idea = ''; -while (my $line = <>) { $idea .= $line; } - -# Check if we have read something -pod2usage(-message => "This simple validator program is expecting one IDEA message either on standard input, or in a file given as first argument...", -verbose => 0, -exitval => 1) unless ($idea); - -# Parse given IDEA message -my $message_idea; -eval { - $message_idea = Mentat::Message::Factory->from_string($idea, 'idea'); -}; -if ($@) { - print "Parser error: $@\n"; - exit(1); -} - -# Validate given string or file -my $error = $validator->validate_s($message_idea, $FLAG_STRICT); -unless ($error) { - print "SUCCESSFULLY PARSED AND VALIDATED GIVEN IDEA MESSAGE:\n\n". $message_idea->to_string(1) . "\n"; - exit(0); -} -else { - print "Validation error: $error\n"; - exit(1); -} diff --git a/lib_perl/deploy/ctrl/conffiles b/lib_perl/deploy/ctrl/conffiles deleted file mode 100755 index 8b137891791fe96927ad78e64b0aad7bded08bdc..0000000000000000000000000000000000000000 --- a/lib_perl/deploy/ctrl/conffiles +++ /dev/null @@ -1 +0,0 @@ - diff --git a/lib_perl/deploy/ctrl/control.tmpl b/lib_perl/deploy/ctrl/control.tmpl deleted file mode 100644 index 328114447bc75a425e98dfa8cfa506e5a6b851f5..0000000000000000000000000000000000000000 --- a/lib_perl/deploy/ctrl/control.tmpl +++ /dev/null @@ -1,10 +0,0 @@ -Package: <%- package_name %> -Version: <%- package_version %> -Section: perl -Installed-Size: <%- package_size %> -Priority: optional -Architecture: <%- architecture %> -Depends: perl -Maintainer: Jan Mach <jan.mach@cesnet.cz> -Description: libidea - Perl library for handling IDEA messages diff --git a/lib_perl/deploy/ctrl/copyright b/lib_perl/deploy/ctrl/copyright deleted file mode 100644 index 85ca39dff4251e49172a2cc5a8356491e1472842..0000000000000000000000000000000000000000 --- a/lib_perl/deploy/ctrl/copyright +++ /dev/null @@ -1,15 +0,0 @@ -Charon - -Copyright 2011-2012 Cesnet, z.s.p.o. (http://www.ces.net) -Authors: Jan Mach <jan.mach@cesnet.cz> - -2011-12-31 - -The entire code base may be distributed under the terms of the GNU General -Public License (GPL), which appears immediately below. Alternatively, all -of the source code as any code derived from that code may instead be -distributed under the GNU Lesser General Public License (LGPL), at the -choice of the distributor. The complete text of the LGPL appears at the -bottom of this file. - -See /usr/share/common-licenses/(GPL|LGPL) diff --git a/lib_perl/deploy/ctrl/postinst b/lib_perl/deploy/ctrl/postinst deleted file mode 100755 index ba407b8b43a2d3d3bb5e29429c7003c4e61fef2f..0000000000000000000000000000000000000000 --- a/lib_perl/deploy/ctrl/postinst +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/perl - -use strict; -use warnings; - -print "postinst script launched with args: '@ARGV'\n"; - -# Create repository storage structure -`/bin/mkdir -p /var/reps/apt`; -`/bin/mkdir -p /var/reps/rpm`; -`/bin/mkdir -p /var/reps/git`; -`/bin/mkdir -p /var/reps/svn`; - -`/bin/mkdir -p /etc/rpm`; - -`/bin/mkdir -p /etc/vsftpd`; - -`/bin/mkdir -p /var/run/vsftpd/chroot`; -`/bin/mkdir -p /var/ftproot/apt`; -`/bin/mkdir -p /var/ftproot/rpm`; -`/bin/mkdir -p /var/ftproot/tar`; - -`/bin/mkdir -p /etc/apache2/repositories.d/`; - -# Change permissions of custom scripts to executable -`/bin/chmod 755 /opt/charon/scripts/*`; - -# Add the init script for incoming queue processing daemon to appropriate runlevels -`/usr/sbin/update-rc.d inc-processing defaults`; -`/usr/sbin/update-rc.d repositories defaults`; - -exit(0); diff --git a/lib_perl/deploy/ctrl/postrm b/lib_perl/deploy/ctrl/postrm deleted file mode 100755 index 4993dc83c6741124e45d7d745f8996fb1827b8cb..0000000000000000000000000000000000000000 --- a/lib_perl/deploy/ctrl/postrm +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/perl - -use strict; -use warnings; - -print "postrm script launched with args: '@ARGV'\n"; - -if ($ARGV[0] and $ARGV[0] eq 'purge') -{ - `/usr/sbin/update-rc.d inc-processing remove`; -} - -exit(0); diff --git a/lib_perl/deploy/ctrl/preinst b/lib_perl/deploy/ctrl/preinst deleted file mode 100755 index 3a308c0afa8b049d79c5762c9a7d668f98fc81b0..0000000000000000000000000000000000000000 --- a/lib_perl/deploy/ctrl/preinst +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/perl - -use strict; -use warnings; - -print "preinst script launched with args: '@ARGV'\n"; - -exit(0); diff --git a/lib_perl/deploy/ctrl/prerm b/lib_perl/deploy/ctrl/prerm deleted file mode 100755 index 280839a9c75e0875f081978de87a1d90af36fc34..0000000000000000000000000000000000000000 --- a/lib_perl/deploy/ctrl/prerm +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/perl - -use strict; -use warnings; - -print "prerm script launched with args: '@ARGV'\n"; - -exit(0); diff --git a/lib_perl/deploy/ctrl/version.tmpl b/lib_perl/deploy/ctrl/version.tmpl deleted file mode 100644 index fed9f5a16269453ca3d76c659935cd23ae83baf6..0000000000000000000000000000000000000000 --- a/lib_perl/deploy/ctrl/version.tmpl +++ /dev/null @@ -1 +0,0 @@ -<%- package_version %> diff --git a/lib_perl/lib/Mentat/Handyman.pm b/lib_perl/lib/Mentat/Handyman.pm deleted file mode 100644 index 820ea1deac188a0c56c8a302799275c4f2f44257..0000000000000000000000000000000000000000 --- a/lib_perl/lib/Mentat/Handyman.pm +++ /dev/null @@ -1,652 +0,0 @@ -package Mentat::Handyman; -use strict; -use warnings; - -# Fix of "smartmatch is experimental" warning -# http://blogs.perl.org/users/mike_b/2013/06/a-little-nicer-way-to-use-smartmatch-on-perl-518.html -no if $] >= 5.017011, warnings => 'experimental::smartmatch'; - -#******************************************************************************* -# DOCUMENTATION SECTION -#******************************************************************************* - -=head1 NAME - -Mentat::Handyman - Utility library for generating IDEA messages using predefined templates - -=head1 SYNOPSIS - - use Mentat::Handyman; - - # Prepare handyman configurations - my %handyman_cfg = ( - "template_file" => "/etc/mentat/msgtmplts.json", # Template file from which to load the message templates [MANDATORY] - "temp_folder" => "/var/mentat/spool/_handyman", # Working directory [MANDATORY] - "pickup_folder" => "/var/mentat/spool/_pickup/incoming", # Target folder to which to store the generated messages [MANDATORY] - "schema_file" => "/etc/mentat/schema-idea.json", # JSON schema for message validation [MANDATORY] - "template_schema_file" => "/etc/mentat/schema-msgtmplts.json", # JSON schema message template validation [MANDATORY] - "user" => "mentat", # Name of the user, which will own the generated messages [MANDATORY] - "message_type" => "idea", # Type of the generated message [MANDATORY] - "strict" => 1, # Switch for strict error checking [OPTIONAL] - "test_mode" => 0, # Switch for test mode [OPTIONAL] - "builder_config" => { - "name" => "cz.cesnet.node", # Name of the detection node node (reverse DNS name is suggested) [MANDATORY] - "type" => "Honeypot, Test", # Type of the detection node (list of comma separated values) [OPTIONAL] - "sw" => "LaBrea", # Name of the detection software [OPTIONAL] - "note" => "Addtional note", # Additional note [OPTIONAL] - } - ); - # Instantinate the handyman object - my $handyman = Mentat::Handyman->new(%handyman_cfg); - - # Instantinate Mentat::Handyman object using the configurations from external JSON file - my $handyman = Mentat::Handyman->load('./handyman-deb.json'); - - eval { - # Arguments to be filled into the template - my @ARGS = (...); - my %ARGS = ('detect_time' => time, ...); - - # Attempt to generate the IDEA message according to the template - commandline like approach - my $idea_message = $handyman->generate('template_id', {'detect_time' => 1356955200}, @ARGS); - print $message->to_string(1); - - # Attempt to generate the IDEA message according to the template - hash like approach - my $idea_message = $handyman->generate('template_id', %ARGS); - print $message->to_string(1); - - # Attempt to generate the IDEA message according to the template and store it directly to the file - commandline like approach - my ($rv, $filename) = $handyman->generate_to_file('template_id', {'detect_time' => 1356955200}, @ARGS); - - # Attempt to generate the IDEA message according to the template and store it directly to the file - hash like approach - my ($rv, $filename) = $handyman->generate_to_file('template_id', %ARGS); - }; - if ($@) { - # SOMEHOW DEAL WITH ERRORS HERE - } - - # For more usage examples please see the handyman.pl example script, which is located - # in package documentation location. - -=head1 DESCRIPTION - -This utility class can be used to easily create complex IDEA messages. These messages -are generated according to the prepared patterns stored in the designated configuration -file (see the section TEMPLATE FILE SYNTAX for details). - -These templates are just lists of Mentat::Message::Builder::IDEA rules (see the -manual page for details). There is the possibility to use variables and macros on -both sides of the rule. These variables and macros will then be replaced/expanded -with given value before the message is about to be created. Few examples: - - Source[1]/IP4[1] => $3 - Description => User $2 logged in from $3 port $4 using the $1 method - -In the examples above strings '$1', '$2', '$3' and '$4' will be replaced with given values: -the '$1' string with value of the first argument, the '$2' string with value of the second -argument and so on. - -Additonally, not only positional, but also named variables are supported. It is possible to -use rules like this: - - Source[1]/IP4[1] => $ip - -If you want to use rules like this, you must either use hash like approach (see SINOPSIS above) -for generating the messages, or you have to provide named variables via positional arguments -like this (please see the Mentat::Message::Builder::IDEA manual page for details and more -examples): - - ip=127.0.0.1 - -When creating the object instance, you have to specify at least the name of the template file -and location of the temporary and pickup directories. Builder configurations may be set up -as well. - -=head1 TEMPLATE FILE SYNTAX - -Template file is JSON file. It should contain array of objects: - - { - # Current version of template schema - "version" : 1, - # List of available templates - "templates" : { - # Unique template identifier - "kippo-001" : { - # Template alias (MANDATORY) - "alias" : "kippo-login", - # Title to display when (MANDATORY) - "title" : "Remote login", - # Name of the analyzer (MANDATORY, must match Node/SW value) - "analyzer" : "Kippo" - # Alert classification (MANDATORY, must match Description value) - "class" : "Remote login", - # Alert categorization (MANDATORY, must match Category value) - "category" : "Malware", - # Reference to external information source (OPTIONAL) - "ref" : "http://www.alert.info", - # Additional event description (OPTIONAL) - "description" : "", - # Additional notes (OPTIONAL) - "note" : "", - - # Label for mentat-reporter - extra IP reports (MANDATORY) - "label_e" : "Pokus o neopravnene pripojeni k SSH serveru", - # Label for mentat-reporter - summary reports (MANDATORY) - "label_s" : "Stroje na nasledujicich IP adresach se pokusily o neopravnene pripojeni k SSH serveru", - - # Number of command line arguments (MANDATORY) - "args" : "6", - # Help for the command line arguments (MANDATORY) - "cmd_help" : "[source IP] [target IP] [target user] [completion] [impact] [event count]", - # Example command line (OPTIONAL, BUT HIGHLY RECOMMENDED) - "cmd_example" : "192.168.0.1 192.168.0.2 root failed \"Someone tried to login as root from 192.168.0.1\" 5", - - # Rules for building IDEA message (MANDATORY) - "rules_idea" : [ - { - "k" : "Source/IP4[1]", - "v" : "$1" - }, - { - "k" : "Target/IP4[1]", - "v" : "$2" - }, - ... - ] - } - } - } - -=head1 CONFIGURATION OPTIONS - -=over - -=item B<template_file> [MANDATORY] - -Template file from which to load the message templates - -=item B<temp_folder> [MANDATORY] - -Working directory for temporary files - -=item B<pickup_folder> [MANDATORY] - -Target folder to which to store the generated messages - -=item B<schema_file> [MANDATORY] - -JSON schema for message validation - -=item B<template_schema_file> [MANDATORY] - -JSON schema message template validation - -=item B<user> [MANDATORY] - -Name of the user, which will own the generated messages - -=item B<message_type> [MANDATORY] - -Type of the generated message - -=item B<strict> [OPTIONAL] - -Switch for strict error checking - -=item B<test_mode> [OPTIONAL] - -Switch for test mode - -=item B<builder_config> [MANDATORY] - -Configurations for Mentat::Message::Builder::IDEA (see the documentation for details) - -=back - -=head1 AUTHOR - - Jan Mach - Cesnet, z.s.p.o - jan.mach@cesnet.cz - http://www.cesnet.cz - -=head1 COPYRIGHT - -This program is free software; you can redistribute -it and/or modify it under the same terms as Perl itself. - -The full text of the license can be found in the -LICENSE file included with this module. - -=head1 SEE ALSO - -perl(1), Config::JSON(3), Mentat::Path::Parser(3), Mentat::Message::IDEA(3), -Mentat::Message::Builder::IDEA(3), Mentat::Message::Validator::IDEA(3). - -=head1 FUNCTION REFERENCE - -=over 4 - -=cut - -#******************************************************************************* -# LIBRARY LOADING SECTION -#******************************************************************************* - -#-- Perl core modules ---------------------------------------------------------# -use Carp; -use Scalar::Util 'blessed'; -use Time::HiRes qw(time); -use Digest::MD5 qw(md5_hex); -use Storable; -use File::Copy; - -#use Smart::Comments; #-+-> DEVEL ONLY <-+-# -use Data::Dumper; #-+-> DEVEL ONLY <-+-# - -#-- Perl CPAN modules ---------------------------------------------------------# - -#-- Custom application modules ------------------------------------------------# - -# Modules from Mentat package -use Config::JSON; -use Mentat::Message::Builder::IDEA; -use Mentat::Message::Validator::IDEA; - -#******************************************************************************* -# CONSTANTS AND GLOBAL VARIABLES DEFINITION SECTION -#******************************************************************************* - -#-- Constants -----------------------------------------------------------------# - -#-- Static public class variables (our) ---------------------------------------# - -#-- Static protected class variables (my) -------------------------------------# - -#******************************************************************************* -# INITIALIZATION AND CLEANUP SECTION -#******************************************************************************* - -#-- Module initializations ----------------------------------------------------# -BEGIN { - use vars qw($VERSION $DEVEL @ISA); - $VERSION = '0.1'; - $DEVEL = 0; - $ENV{PATH} = '/bin:/usr/bin'; -} - - -#-- Module clean-up code (global destructor) ----------------------------------# -END { - -} - -#******************************************************************************* -# IMPLEMENTATION SECTION -#******************************************************************************* - -=item load() [PUBLIC,STATIC] - - Usage : my $instance = Mentat::Handyman->load($config_file); - Purpose : Create and return reference to the new instance with configuration taken from external JSON file - Arguments : STRING $config_file - name of the configuration JSON file - Returns : Mentat::Handyman reference on success, dies on failure - Throws : Dies, if not invoked on class - Comments : Internally uses new() method - See Also : new() method - -=cut - -sub load -{ - my $class = shift; - confess "Class method not invoked on class" if blessed($class); - my ($config_file,) = @_; - die "Handyman configuration file must be given as argument\n" unless $config_file; - die "Handyman configuration file must be existing ordinary file\n" unless -f $config_file; - - # Load configurations from external JSON file - my ($config, $error) = Config::JSON->load($config_file); - die "$error\n" if $error; - - # Instantinate the handyman object - return $class->new(%$config); -} - -=item new() [PUBLIC,STATIC] - - Usage : my $instance = Mentat::Handyman->new(%config); - Purpose : Create and return reference to the new instance - Arguments : HASH %config with follwong keys: - STRING $template_file - name of the template file [MANDATORY] - STRING $temp_folder - name of the folder to store mentat messages [MANDATORY] - STRING $pickup_folder - name of the folder to which to move the successfully created messages [MANDATORY] - STRING $schema_file - name of the JSON schema file for message validation [OPTIONAL] - STRING $template_schema_file - name of the JSON schema file for message template validation [MANDATORY] - STRING $user - name of the user and group, to which to change the ownership of generated messages - STRING $message_type - name of the user, who will own the generated messages [MANDATORY] - BOOL $strict - strict filling of message templates [MANDATORY] - HASH REFERENCE $builder_config - Mentat::Message::Builder::IDEA configurations - Returns : Mentat::Handyman reference on success, dies on failure - Throws : Dies, if not invoked on class - -=cut - -sub new -{ - my $class = shift; - confess "Class method not invoked on class" if blessed($class); - my %config = @_; - - die "Constructor expects configurations as argument\n" unless %config; - die "Handyman configuration 'template_file' is missing\n" unless $config{template_file}; - die "Handyman configuration 'temp_folder' is missing\n" unless $config{temp_folder}; - die "Handyman configuration 'pickup_folder' is missing\n" unless $config{pickup_folder}; - die "Handyman configuration 'user' is missing\n" unless $config{user}; - die "Teplate file '$config{template_file}' is not ordinary file\n" unless -f $config{template_file}; - die "Temp folder '$config{temp_folder}' is not a directory or writable\n" unless -d $config{temp_folder} and -w $config{temp_folder}; - die "Pickup folder '$config{pickup_folder}' is not a directory or writable\n" unless -d $config{pickup_folder} and -w $config{pickup_folder}; - if ($config{schema_file}) { - die "Schema file '$config{schema_file}' is not ordinary file\n" unless -f $config{schema_file}; - } - if ($config{template_schema_file}) { - die "Template schema file '$config{template_schema_file}' is not ordinary file\n" unless -f $config{template_schema_file}; - } - - my $self = bless ({}, $class); - - # Setup temporary and destination directories - $self->{TEMPLATE_FILE} = $config{template_file}; - $self->{TEMP_FOLDER} = $config{temp_folder}; - $self->{PICKUP_FOLDER} = $config{pickup_folder}; - $self->{SCHEMA_FILE} = $config{schema_file}; - $self->{TEMPLATE_SCHEMA_FILE} = $config{template_schema_file}; - - my ($login, $pass, $uid, $gid) = getpwnam($config{user}) or die "User '$config{user}' does not exist in passwd file\n"; - $self->{USER_UID} = $uid; - $self->{USER_GID} = $gid; - $self->{MSGTYPE} = $config{message_type} || 'idea'; - $self->{STRICT} = $config{strict}; - $self->{TEST_MODE} = $config{test_mode}; - - # Setup message builder based on the desired message type - $self->{BUILDER} = Mentat::Message::Builder::IDEA->new($config{builder_config}); - $self->{VALIDATOR} = Mentat::Message::Validator::IDEA->new($self->{SCHEMA_FILE}) if $self->{SCHEMA_FILE}; - - # Load message templates - $self->_load_templates($self->{TEMPLATE_FILE}, $self->{TEMPLATE_SCHEMA_FILE}); - - print STDERR "HANDYMAN UID: '$<', EUID: '$>', GID: '$(', EGID: '$)',\n" if $DEVEL; - print STDERR "TEMPLATES: " . Dumper($self->{TEMPLATES}) if $DEVEL; - - # Perform further initializations (callback for subclassess) - return $self->_init(@_); -} - -=item fill_in_rule($$$$;$) [PUBLIC] - - Usage : my $filled_rule = $handyman->fill_in_rule($key, $value, $hash_variables, $array_variables); - Purpose : Fill in and return single IDEA message building rule with values given in hash and array - Arguments : STRING $key - rule key [MANDATORY] - STRING $value - rule value [MANDATORY] - HASH REFERENCE $hash_variables - hash containing named variables to be filled into the rules [OPTIONAL] - ARRAY REFERENCE $array_variables - array containing indexed variables to be filled into the rules [OPTIONAL] - BOOL $strict - strict fill flag [OPTIONAL] - Returns : ARRAY containing filled $key and $value (SUCCESS) - Throws : Dies, if message rules not given as arguments - See Also : fill_in_rule() method of Mentat::Message::Builder - -=cut - -sub fill_in_rule(@) -{ - my $self = shift; - confess "Instance method not invoked on object instance" unless blessed($self); - return $self->{BUILDER}->fill_in_rule(@_); -} - -=item generate($$@) [PUBLIC] - - Usage : my $idea_message = $instance->generate('template_001', {'detect_time' => 1356955200}, @args); - Purpose : Generate IDEA message according to the given template - Arguments : STRING $template_id - identifier of the template to be used to generate the message [MANDATORY] - HASH REFERENCE $name_args - name arguments and additional message configurations [MANDATORY] - ARRAY @args - positional arguments to be filled to the template [OPTIONAL] - Returns : Mentat::Message reference - Throws : Dies, if not invoked on object - Comments : This method is called from generate_to_file() method - See Also : generate_to_file() method - -=cut - -sub generate($$@) -{ - my $self = shift; - confess "Instance method not invoked on object instance" unless blessed($self); - my ($template_id, $name_args, @args) = @_; - confess "IDEA message builder must be set up prior to message generation" unless $self->{BUILDER}; - - # For convenience, extract the selected template from the template set - my $template = $self->template($template_id); - - # Check the number of given arguments - my $cnt = @args; $cnt = scalar keys %$name_args unless $cnt; - die "Template '$template_id' expects '".$template->{'args'}."' arguments, but '$cnt' given instead\n" unless ($cnt >= $template->{'args'}); - - # Fetch the list of message rules - my $rules = $template->{'template'}; - die "Template '$template_id' does not provide rules to build '$self->{MSGTYPE}' message\n" unless $rules; - - # Build the message and generate the file name - my $message = $self->{BUILDER}->build(rules => $rules, - name_args => $name_args, - pos_args => \@args, - template_id => $template_id, - strict => $self->{STRICT}); - - # When running in test mode, append the 'Test' category to every generated message - if ($self->{TEST_MODE}) { - my $categories = $message->path_values('Category'); - unless ('Test' ~~ @$categories) { - $message->path_node_set('Category[*]', 'Test'); - } - } - - # Validate generated message - if ($self->{VALIDATOR}) { - my $error = $self->{VALIDATOR}->validate_s($message); - die "$error\n".$message->to_string(1)."\n" if $error; - } - - return $message; -} - -=item store_to_file($$@) [PUBLIC] - - Usage : my ($rv, $file_name) = $instance->store_to_file($idea_message); - Purpose : Store given IDEA message to the file in pickup folder - Arguments : IDEA::Message $idea_message - Message to be stored - Returns : Tuple containing following values: - BOOL true on success, false on failure - STRING name of the file containing generated message - Throws : Dies, if not invoked on object - Comments : This method uses generate() method to internally generate the IDEA message object - -=cut - -sub store_to_file($) -{ - my $self = shift; - confess "Instance method not invoked on object instance" unless blessed($self); - my ($idea_message,) = @_; - - # Message creation must be atomic operation, so store the message to the temporary folder first - my ($file_name, $file_path) = $idea_message->to_dir($self->{TEMP_FOLDER}, 1); - - # Prepare the file names in advance - my $from = $file_path; - my $to = $self->{PICKUP_FOLDER} . "/" . $file_name; - - # Clean the tainted file names - $from = $1 if ($from =~ /(.*)/); - $to = $1 if ($to =~ /(.*)/); - - # Change the ownership accordingly (FIXME) - #chown($self->{USER_UID}, $self->{USER_GID}, $from) - # or die "Unable to change ownership of the file '$from' to '".$self->{USER_UID}.":".$self->{USER_GID}."'\n"; - - # Make sure the file access permissions are normalized - my $mode = 0664; chmod($mode, $from) - or die "Unable to change permissions of the message file '$from' to '$mode'\n"; - - # Attempt to change the ownership - chown($self->{USER_UID}, $self->{USER_GID}, $from); - - # And then move it to pickup directory - move($from, $to) - or die "Unable to move the message file '$from' to '$to': $!\n"; - - return (1, $to); -} - -=item generate_to_file($$@) [PUBLIC] - - Usage : my ($rv, $file_name) = $instance->generate_to_file('template_001', {'detect_time' => 1356955200}, @args); - Purpose : Generate IDEA message according to the given template and store it to the file in pickup folder - Arguments : Same as generate() method - Returns : Same as store_to_file() method - Throws : Dies, if not invoked on object - Comments : This method uses generate() method to internally generate the IDEA message object - See Also : generate(), store_to_file() methods - -=cut - -sub generate_to_file($$@) -{ - my $self = shift; - confess "Instance method not invoked on object instance" unless blessed($self); - - # Generate the IDEA message object - my $idea_message = $self->generate(@_); - - # Store it to the file - return $self->store_to_file($idea_message) -} - -=item templates() [PUBLIC] - - Usage : my @templates = $instance->templates(); - Purpose : Get the list of names of all currently known templates - Arguments : None - Returns : ARRAY of STRINGS @templates - Throws : Dies, if not invoked on object - -=cut - -sub templates() -{ - my $self = shift; - confess "Instance method not invoked on object instance" unless blessed($self); - - return sort keys %{$self->{TEMPLATES}}; -} - -=item template($) [PUBLIC] - - Usage : my $template = $instance->template($template_id); - Purpose : Fetch the metadata for given template - Arguments : STRING $template_id - identifier of the template [MANDATORY] - Returns : HASH REFERENCE $template - Throws : Dies, if not invoked on object - -=cut - -sub template($) -{ - my $self = shift; - confess "Instance method not invoked on object instance" unless blessed($self); - my ($template_id,) = @_; - - die "Unknown template '$template_id'\n" unless exists $self->{TEMPLATES}->{$template_id}; - return $self->{TEMPLATES}->{$template_id}; -} - -=item parse_args($) [PUBLIC] - - Usage : my @args = $instance->parse_args($command_line); - Purpose : Separate commandline given as single merged string into list of arguments - Arguments : STRING $command_line - commandline as single merged string - Returns : ARRAY of STRINGS @args - -=cut - -sub parse_args($) -{ - my $invocant = shift; - - return Mentat::Message::Builder->parse_command_args(@_); -} - -#------------------------------------------------------------------------------- -# Private interface -#------------------------------------------------------------------------------- - -# _init [PROTECTED] -# -# Usage : return $self->_init(@_); -# Purpose : Initialize the new Mentat::Handyman instance -# Arguments : None -# Returns : Mentat::Handyman reference -# Throws : Dies, if not invoked on instance -# Comments : This method must never be called directly, it is supposed to be overloaded by subclasses. - -sub _init -{ - my $self = shift; - confess "Instance method not invoked on object instance" unless blessed($self); - return $self; -} - -# _load_templates($$) [PROTECTED] -# -# Usage : $self->{TEMPLATES} = $self->_load_templates($template_file, $template_schema_file); -# Purpose : Load templates from given external file -# Arguments : STRING $template_file - name of the template file [MANDATORY] -# STRING $template_schema_file - name of the template schema file for validation [OPTIONAL] -# Returns : Nothing, changes current object instance -# Throws : Dies, if not invoked on instance - -sub _load_templates($$) -{ - my $self = shift; - confess "Instance method not invoked on object instance" unless blessed($self); - my ($template_file, $template_schema_file) = @_; - - # Fallback - load the message templates and store them to the memory - unless ($self->{TEMPLATES}) { - my $cfg_parser = Config::JSON->new($template_schema_file); - - # Load the templates from external file - my ($config, $error); - ($config, $error) = $cfg_parser->config($template_file, $template_schema_file); - die "Template file '$template_file' syntax error: '$error'\n" unless $config; - - $self->{TEMPLATES} = $config->{templates}; - - my $tkey = "rules_".$self->{MSGTYPE}; - foreach my $key (keys %{$self->{TEMPLATES}}) { - foreach my $rule (@{$self->{TEMPLATES}->{$key}->{$tkey}}) { - push(@{$self->{TEMPLATES}->{$key}->{template}}, [$rule->{k}, $rule->{v}]); - } - } - } -} - -=pod - -=back - -=cut - -1; diff --git a/lib_perl/lib/Mentat/MPath/Parser.pm b/lib_perl/lib/Mentat/MPath/Parser.pm deleted file mode 100644 index 9d74a3be0beef7820cafc1fc7feefa9f21a2120d..0000000000000000000000000000000000000000 --- a/lib_perl/lib/Mentat/MPath/Parser.pm +++ /dev/null @@ -1,189 +0,0 @@ -package Mentat::MPath::Parser; -use strict; -use warnings; - -#******************************************************************************* -# DOCUMENTATION SECTION -#******************************************************************************* - -=head1 NAME - -Mentat::MPath::Parser - Provides methods for handling Mentat message paths (MPath) - -=head1 SYNOPSIS - - use Mentat::MPath::Parser; - - #-------------------------------------- - # Module usage via static class methods - #-------------------------------------- - - # Parse out the first node (chunk) from given message path: - eval { - my ($name, $type, $index, $rest) = Mentat::MPath::Parser->parse_next_chunk($mpath); - }; - if($@) { print "MESSAGE PATH ERROR: $@\n"; } - - # Parse the given message path chunk by chunk: - my @result; - eval { - do { - my ($name, $type, $index, $rest) = Mentat::MPath::Parser->parse_next_chunk($mpath); - push(@result, [$next_node_xpath, $name, $type, $index, $mpath]); - } while ($mpath); - }; - if($@) { print "MESSAGE PATH ERROR: $@\n"; } - - # Parse the given message path in one call: - eval { - my @chunks = Mentat::MPath::Parser->parse($mpath); - }; - if($@) { print "MESSAGE PATH ERROR: $@\n"; } - - # Parse the given message path in one call, but suppress all raised exceptions: - my @chunks = Mentat::MPath::Parser->parse_quiet($mpath); - - # Just validate the given message path - my $result = Mentat::MPath::Parser->validate($mpath); - - #---------------------------------- - # Module usage via instance methods - #---------------------------------- - - my $parser = new Mentat::MPath::Parser(); - - # Parse out the first node (chunk) from given message path: - eval { - my ($name, $type, $index, $rest) = $parser->parse_next_chunk($mpath); - }; - if($@) { print "MESSAGE PATH ERROR: $@\n"; } - - # Parse the given message path chunk by chunk: - my @result; - eval { - do { - my ($name, $type, $index, $rest) = $parser->parse_next_chunk($mpath); - push(@result, [$next_node_xpath, $name, $type, $index, $mpath]); - } while ($mpath); - }; - if($@) { print "MESSAGE PATH ERROR: $@\n"; } - - # Parse the given message path in one call: - eval { - my @chunks = $parser->parse($mpath); - }; - if($@) { print "MESSAGE PATH ERROR: $@\n"; } - - # Parse the given message path in one call, but suppress all raised exceptions: - my @chunks = $parser->parse_quiet($mpath); - - # Just validate the given message path - my $result = $parser->validate($mpath); - -=head1 DESCRIPTION - -This module is used to parse Mentat message path, which can be then used -for manipulating the Mentat message objects. See the message path SYNTAX -section for more details on message path. - -=head1 MESSAGE PATH SYNTAX (MPATH) - -Mentat message path (MPath) syntax is a subset of XPath syntax. Is uses only basic -constructs for identifying the elements in the messages. Names of the nodes are defined -in the RFC 4765, however at this point of implementation this module does validity -check only on the first node in the path: it must be either 'Alert', or 'Heartbeat'. -Any other node (element or atribute) names or the path structure are not checked. - -MPath is a string composed of node identifiers separated by '/' character. -Node identifier is composed of optional '@' character followed by node name -followed by optional integer index enclosed within '[' and ']' the braces. -Character '@' implies, that the node is attribute node and this node must be -the last node in the MPath (attribute nodes may not have any child nodes). -Optional integer index is valid only for element nodes. IDEA standard allows -multiple occurences of certain element nodes, index allows to identify particular -one. MPath must not start with the '/' character. - -Some valid MPath examples: - -Valid message paths: - Node/Name - Source[2]/IP4[1] - -=head1 AUTHOR - - Jan Mach - Cesnet, z.s.p.o - jan.mach@cesnet.cz - http://www.cesnet.cz - -=head1 COPYRIGHT - -This program is free software; you can redistribute -it and/or modify it under the same terms as Perl itself. - -The full text of the license can be found in the -LICENSE file included with this module. - - -=head1 SEE ALSO - -perl(1). - -=head1 FUNCTION REFERENCE - -=over 4 - -=cut - -#******************************************************************************* -# LIBRARY LOADING SECTION -#******************************************************************************* - -#-- Perl core modules ---------------------------------------------------------# -use Carp; - -#use Data::Dumper; #-+-> DEVEL ONLY <-+-# - -#-- Perl CPAN modules ---------------------------------------------------------# - -#-- Custom application modules ------------------------------------------------# -use Data::Path::Parser; - -#******************************************************************************* -# CONSTANTS AND GLOBAL VARIABLES DEFINITION SECTION -#******************************************************************************* - -#-- Constants -----------------------------------------------------------------# - -#-- Static public class variables (our) ---------------------------------------# - -#-- Static protected class variables (my) -------------------------------------# - -#******************************************************************************* -# INITIALIZATION AND CLEANUP SECTION -#******************************************************************************* - -#-- Module initializations ----------------------------------------------------# -BEGIN { - use vars qw($VERSION $DEVEL @ISA); - $VERSION = '0.1'; - $DEVEL = 0; - @ISA = ('Data::Path::Parser'); -} - -#-- Module clean-up code (global destructor) ----------------------------------# -END { - -} - -#******************************************************************************* -# IMPLEMENTATION SECTION -#******************************************************************************* - -=pod - -=back - -=cut - -1; diff --git a/lib_perl/lib/Mentat/Message.pm b/lib_perl/lib/Mentat/Message.pm deleted file mode 100644 index 8e9dfe5a4e984a22560c456360b3f5473359ceb6..0000000000000000000000000000000000000000 --- a/lib_perl/lib/Mentat/Message.pm +++ /dev/null @@ -1,540 +0,0 @@ -package Mentat::Message; -use strict; -use warnings; - -#******************************************************************************* -# DOCUMENTATION SECTION -#******************************************************************************* - -=head1 NAME - -Mentat::Message - Base class defining interface for working with Mentat::Messages - -=head1 SYNOPSIS - - use Mentat::Message; - -=head1 DESCRIPTION - - - -=head1 AUTHOR - - Jan Mach - Cesnet, z.s.p.o - jan.mach@cesnet.cz - http://www.cesnet.cz - -=head1 COPYRIGHT - -This program is free software; you can redistribute -it and/or modify it under the same terms as Perl itself. - -The full text of the license can be found in the -LICENSE file included with this module. - -=head1 SEE ALSO - -perl(1). - -=head1 FUNCTION REFERENCE - -=over 4 - -=cut - -#******************************************************************************* -# LIBRARY LOADING SECTION -#******************************************************************************* - -#-- Perl core modules ---------------------------------------------------------# -use Carp; -use Scalar::Util 'blessed'; -use Digest::MD5 qw(md5_hex); - -#use Smart::Comments; #-+-> DEVEL ONLY <-+-# -#use Data::Dumper; #-+-> DEVEL ONLY <-+-# - -#-- Perl CPAN modules ---------------------------------------------------------# - -#-- Custom application modules ------------------------------------------------# - -#******************************************************************************* -# CONSTANTS AND GLOBAL VARIABLES DEFINITION SECTION -#******************************************************************************* - -#-- Constants -----------------------------------------------------------------# - -#-- Static public class variables (our) ---------------------------------------# - -#-- Static protected class variables (my) -------------------------------------# - -#******************************************************************************* -# INITIALIZATION AND CLEANUP SECTION -#******************************************************************************* - -#-- Module initializations ----------------------------------------------------# -BEGIN { - use vars qw($VERSION $DEVEL); - $VERSION = '0.1'; - $DEVEL = 0; -} - -#-- Module clean-up code (global destructor) ----------------------------------# -END { - -} - -#-- Operator overloading ------------------------------------------------------# -use overload - '""' => 'to_string'; - -#******************************************************************************* -# IMPLEMENTATION SECTION -#******************************************************************************* - -=item new() [PUBLIC,STATIC] - - Usage : my $message = Mentat::Message->new(); - Purpose : Create new empty instance of the Mentat message - Arguments : None - Returns : Reference to the new instance of the Mentat message - Throws : Croaks, if invoked on object - -=cut - -sub new() -{ - my $class = shift; - confess "Class method not invoked on class" if blessed($class); - - my $self = bless ({}, $class); - return $self->_init(@_); -} - -=item unserialize($) [PUBLIC,STATIC] - - Usage : my $message = Mentat::Message->unserialize($string); - Purpose : Recover serialized instance of the Mentat message from given string - Arguments : STRING $string - string containing serialized instance - Returns : Reference to the recovered instance of the Mentat message - Throws : Croaks, if invoked on object - -=cut - -sub unserialize($) -{ - my $class = shift; - confess "Method needs implementation in subclass"; -} - -=item from_file($) [PUBLIC,STATIC] - - Usage : my $message = Mentat::Message->from_file($filename); - Purpose : Recover serialized instance of the Mentat message from given file - Arguments : STRING $filename - name of the file containing serialized instance - Returns : Reference to the recovered instance of the Mentat message - Throws : Croaks, if invoked on object - -=cut - -sub from_file($) -{ - my $class = shift; - confess "Method needs implementation in subclass"; -} - -#------------------------------------------------------------------------------- - -=item class() [PUBLIC] - - Usage : my $class = $message->class(); - Purpose : Determine the class/type of the Mentat::Message - Arguments : None - Returns : STRING $class - Throws : Croaks, if invoked on class - -=cut - -sub class() -{ - my $self = shift; - confess "Instance method not invoked on object instance" unless blessed($self); - - # Determine the type of the message (last part of the class name) - unless ($self->{CLASS}) { - my $name = blessed($self); - my @tmp = split(/:+/, $name); - $self->{CLASS} = lc($tmp[$#tmp]); - } - return $self->{CLASS}; -} - -=item id(;$) [PUBLIC] - - Usage : my $id = $message->id(); - Purpose : Get (and optionally set) the ID attribute of the current Mentat::Message - Arguments : STRING $id - Message ID which to set - Returns : STRING current message ID - Throws : Croaks, if invoked on class - -=cut - -sub id(;$) -{ - my $self = shift; - confess "Method needs implementation in subclass"; -} - -#------------------------------------------------------------------------------- - -=item iterate() [PUBLIC] - - Usage : my ($src_mpath, $value) = $message->iterate(); - while ($src_mpath) { - # Do some processing here - ($src_mpath, $value) = $message->iterate(); - } - Purpose : Iterate through all nodes in the Mentat::Message - Arguments : None - Returns : STRING $src_mpath - MPath address of the node - MIXED $value - value of the node - Throws : Croaks, if invoked on class - -=cut - -sub iterate() -{ - my $self = shift; - confess "Method needs implementation in subclass"; -} - -#------------------------------------------------------------------------------- - -=item path_nodes($) [PUBLIC] - - Usage : my $nodes = $message->path_nodes($mpath); - Purpose : Get all nodes on given message path - Arguments : STRING $mpath - message path to the nodes [MANDATORY] - Returns : reference to array of values - Throws : Croaks, if invoked on class - Croaks, if not given message path - Croaks, if node on given message path does not exist - See Also : Mentat::Message::Path::Parser class - -=cut - -sub path_nodes($) -{ - my $self = shift; - confess "Method needs implementation in subclass"; -} - -=item path_node($) [PUBLIC] - - Usage : my $node = $message->path_node($mpath); - Purpose : Get first node on given message path - Arguments : STRING $mpath - message path to the nodes [MANDATORY] - Returns : STRING $value - node value (SUCCESS) - undef (NODE HAS NO VALUE) - Throws : Croaks, if invoked on class - Croaks, if not given message path - Same as path_nodes() method - Comments : Internally uses path_nodes() method - See Also : path_nodes() method, Mentat::Message::Path::Parser class - -=cut - -sub path_node($) -{ - my $self = shift; - confess "Instance method not invoked on object instance" unless blessed($self); - my ($mpath,) = @_; - confess "Invalid usage, message path must be given as argument" unless defined($mpath); - - # Get all matching nodes - my $nodes = $self->path_nodes($mpath); - - # But return only the first one - return shift @$nodes; -} - -=item path_node_set($$) [PUBLIC] - - Usage : $message->path_node_set($mpath, $value); - Purpose : If it does not exist, append new node to the Mentat message on the given path and set it`s value - Arguments : STRING $mpath - path in the Mentat message structure [MANDATORY] - STRING $value - value of the object [MANDATORY] - Returns : Nothing - Throws : Croaks, if invoked on class - Croaks, if not given message path and value to set - Croaks, if message path is syntactically incorrect - See Also : Mentat::Message::Path::Parser class - -=cut - -sub path_node_set($$) -{ - my $self = shift; - confess "Method needs implementation in subclass"; -} - -=item path_node_delete($) [PUBLIC] - - Usage : my $node = $message->path_delete($mpath); - Purpose : Deletes node on given message path - Arguments : STRING $mpath - message path to the node [MANDATORY] - Returns : Nothing - Throws : Croaks, if invoked on class - Croaks, if not given message path - Croaks, if node on given message path does not exist - See Also : Mentat::Message::Path::Parser class - -=cut - -sub path_node_delete($) -{ - my $self = shift; - confess "Method needs implementation in subclass"; -} - -=item path_node_exists($) [PRIVATE] - - Usage : my $result = $message->path_node_exists($mpath); - Purpose : Tests, if the node on given message path exists - Arguments : STRING $mpath - message path to the node [MANDATORY] - Returns : INTEGER 1 (SUCCESS) - INTEGER 0 (FAILURE) - Throws : Croaks, if invoked on class - Croaks, if not given any message path to test - Comments : Internally uses path_node() method - See Also : path_node() method, Mentat::Message::Path::Parser class - -=cut - -sub path_node_exists($) -{ - my $self = shift; - confess "Instance method not invoked on object instance" unless blessed($self); - my ($mpath,) = @_; - confess "Invalid usage, message path must be given as argument" unless defined($mpath); - - # Try to find node located on the given message path - my $node = $self->path_node($mpath); - - # If the node on given path was not found, return undef - return 0 unless $node; - return 1; -} - -#------------------------------------------------------------------------------- - -=item path_values($) [PUBLIC] - - Usage : my $value = $message->path_values($mpath); - Purpose : Gets values of all nodes on given message path - Arguments : STRING $mpath - message path to the nodes [MANDATORY] - Returns : reference to array of values - Throws : Croaks, if invoked on class - Croaks, if not given message path - Croaks, if node on given message path does not exist - See Also : Mentat::Message::Path::Parser class - -=cut - -sub path_values($) -{ - my $self = shift; - confess "Method needs implementation in subclass"; -} - -=item path_value($) [PUBLIC] - - Usage : my $value = $message->path_value($mpath); - Purpose : Get value of first attribute or element node on given message path - Arguments : STRING $mpath - message path to the nodes [MANDATORY] - Returns : STRING $value - node value (SUCCESS) - undef (NODE HAS NO VALUE) - Throws : Croaks, if invoked on class - Croaks, if not given message path - Same as path_value() method - Comments : Internally uses path_values() method - See Also : path_values() method, Mentat::Message::Path::Parser class - -=cut - -sub path_value($) -{ - my $self = shift; - confess "Instance method not invoked on object instance" unless blessed($self); - my ($mpath,) = @_; - confess "Invalid usage, message path must be given as argument" unless defined($mpath); - - # Get all mathing values - my $values = $self->path_values($mpath); - - # But return only the first one - return shift @$values; -} - -=item path_value_set($$) [PUBLIC] - - Usage : my $value = $message->path_value_set($mpath, $value); - Purpose : Set and return value of first node on given message path - Arguments : STRING $mpath - message path to the node [MANDATORY] - STRING $value - New node value [MANDATORY] - Returns : Nothing - Throws : Croaks, if invoked on class - Croaks, if not given message path - Croaks, if node on given message path does not exist - See Also : Mentat::Message::Path::Parser class - -=cut - -sub path_value_set($$) -{ - my $self = shift; - confess "Method needs implementation in subclass"; -} - -#------------------------------------------------------------------------------- - -=item serialize() [PUBLIC] - - Usage : my $string = $message->serialize(); - Purpose : Export Mentat message into string - Arguments : None - Returns : STRING $string - string containing serialized Mentat message - Throws : Croaks, if invoked on class - -=cut - -sub serialize() -{ - my $self = shift; - confess "Method needs implementation in subclass"; -} - -=item to_string() [PUBLIC] - - Usage : my $string = $message->to_string(); - Purpose : Export Mentat message into readable string - Arguments : None - Returns : STRING $string - string containing serialized Mentat message - Throws : Croaks, if invoked on class - -=cut - -sub to_string() -{ - my $self = shift; - confess "Method needs implementation in subclass"; -} - -=item to_file($;$) [PUBLIC] - - Usage : $message->to_file($file_name); - Purpose : Store Mentat message into external file - Arguments : STRING $file_name - name of the file to which to store the message [MANDATORY] - BOOL $pretty - format message nicely [OPTIONAL] - Returns : STRING $file_name - Throws : Croaks, if invoked on class - Croaks, if given file could not be opened for writing - -=cut - -sub to_file($;$) -{ - my $self = shift; - confess "Instance method not invoked on object instance" unless blessed($self); - my ($file_name, $pretty) = @_; - confess "Name of the file to which to store the message must be given" unless $file_name; - - # Replace the accidental double slashes - $file_name =~ s/\/\//\//g; - - # Untaint the file name - $file_name = $1 if ($file_name =~ /(.*)/); - - # Do not overwrite existing files - die "File '$file_name' already exist and would be ovewritten\n" if -f $file_name; - - ### Nice print: $pretty - open(my $hnd, ">$file_name") or die "Cannot open file '$file_name' to store Mentat message for writing\n"; - print $hnd $self->to_string($pretty); - close($hnd); - - return $file_name; -} - -=item to_dir($;$) [PUBLIC] - - Usage : $message->to_dir($filename); - Purpose : Store Mentat message into external file in designated directory - Arguments : STRING $dirname - name of the directory to which to store the message [MANDATORY] - BOOL $pretty - format message nicely [OPTIONAL] - Returns : ARRAY containing - STRING $file_name - name of the file within the target directory - STRING $file_path - full path to the file - Throws : Croaks, if invoked on class - -=cut - -sub to_dir($;$) -{ - my $self = shift; - confess "Instance method not invoked on object instance" unless blessed($self); - my ($dir_name, $pretty) = @_; - confess "Name of the directory to which to store the message must be given" unless $dir_name; - - # Generate the unique name for the message file - my $fn = $self->_generate_file_name().".".$self->class(); - while (-e $dir_name."/".$fn) { - $fn = $self->_generate_file_name().".".$self->class(); - } - - # Store the message to the file - return ($fn, $self->to_file($dir_name.'/'.$fn)); -} - -#------------------------------------------------------------------------------- -# Private interface -#------------------------------------------------------------------------------- - -# _init [PROTECTED] -# -# Usage : return $self->_init(@_); -# Purpose : Initialize the new Mentat::Message instance -# Arguments : -# Returns : Mentat::Message reference -# Throws : Croaks, if invoked on class -# Comments : This method must never be called directly, it is supposed to be overloaded by subclasses. - -sub _init -{ - my $self = shift; - confess "Method needs implementation in subclass"; -} - -# _generate_file_name() [PROTECTED] -# -# Usage : -# Purpose : Generate unique ID for message file -# Arguments : -# Returns : -# Throws : Dies, if not invoked on instance - -sub _generate_file_name() -{ - my $self = shift; - confess "Instance method not invoked on object instance" unless blessed($self); - return md5_hex(time().sprintf('%04X', int(rand 65536))); -} - -=pod - -=back - -=cut - -1; diff --git a/lib_perl/lib/Mentat/Message/Builder.pm b/lib_perl/lib/Mentat/Message/Builder.pm deleted file mode 100644 index c49960b3e385c11990b22bd22f2a8a0bb67ac88c..0000000000000000000000000000000000000000 --- a/lib_perl/lib/Mentat/Message/Builder.pm +++ /dev/null @@ -1,521 +0,0 @@ -package Mentat::Message::Builder; -use strict; -use warnings; - -#******************************************************************************* -# DOCUMENTATION SECTION -#******************************************************************************* - -=head1 NAME - -Mentat::Message::Builder - Base class for providing methods for easier building messages from scratch - -=head1 SYNOPSIS - - use Mentat::Message::Builder; - -=head1 DESCRIPTION - - - -=head1 AUTHOR - - Jan Mach - Cesnet, z.s.p.o - jan.mach@cesnet.cz - http://www.cesnet.cz - -=head1 COPYRIGHT - -This program is free software; you can redistribute -it and/or modify it under the same terms as Perl itself. - -The full text of the license can be found in the -LICENSE file included with this module. - -=head1 SEE ALSO - -perl(1). - -=head1 FUNCTION REFERENCE - -=over 4 - -=cut - -#******************************************************************************* -# LIBRARY LOADING SECTION -#******************************************************************************* - -#-- Perl core modules ---------------------------------------------------------# -use Carp; -use Scalar::Util 'blessed'; -use Storable qw(dclone); - -use Data::Dumper; #-+-> DEVEL ONLY <-+-# -#use Smart::Comments; #-+-> DEVEL ONLY <-+-# - -#-- Perl CPAN modules ---------------------------------------------------------# -# Original solution used better unique ID generation algorithm, but it used to take -# very long time to generate many IDs in a row -#use Bytes::Random::Secure qw(random_string_from); -use Data::Random qw(rand_chars); - -#-- Custom application modules ------------------------------------------------# - -#******************************************************************************* -# CONSTANTS AND GLOBAL VARIABLES DEFINITION SECTION -#******************************************************************************* - -#-- Constants -----------------------------------------------------------------# - -#-- Static public class variables (our) ---------------------------------------# - -#-- Static protected class variables (my) -------------------------------------# -my $DFLT_CHARS = join('', ('a' .. 'z'), ('A' .. 'Z'), ('0' .. '9')); -my $DFLT_LENGTH = 12; - -#******************************************************************************* -# INITIALIZATION AND CLEANUP SECTION -#******************************************************************************* - -#-- Module initializations ----------------------------------------------------# -BEGIN { - use vars qw($VERSION $DEVEL); - $VERSION = '0.1'; - $DEVEL = 0; -} - - -#-- Module clean-up code (global destructor) ----------------------------------# -END { - -} - -#******************************************************************************* -# IMPLEMENTATION SECTION -#******************************************************************************* - -=item new($) [PUBLIC, STATIC] - - Usage : my $builder = Mentat::Message::Builder->new(); - Purpose : Create new empty instance of the IDEA message builder - Arguments : HASH REFERENCE $config - builder configurations (MANDATORY) - Returns : Mentat::Message::Builder reference - Throws : Dies, if invoked on object - Dies, if mandatory builder configuration value is missing - -=cut - -sub new($) -{ - my $class = shift; - confess "Class method not invoked on class" if blessed($class); - my ($config,) = @_; - confess "Configurations must be given via hash reference" if defined $config and ref $config ne 'HASH'; - - my $self = bless ({}, $class); - $self->{CONFIGS} = ($config)?$config:{}; - return $self->_init(@_); -} - -=item fill_in_rule($$$$;$) [PUBLIC, HYBRID] - - Usage : my $filled_rule = Mentat::Message::Builder->fill_in_rule($key, $value, $hash_variables, $array_variables, $strict); - my $filled_rule = $builder->fill_in_rule($key, $value, $hash_variables, $array_variables); - Purpose : Fill in and return single IDEA message building rule with values given in hash and array - Arguments : STRING $key - rule key [MANDATORY] - STRING $value - rule value [MANDATORY] - HASH REFERENCE $hash_variables - hash containing named variables to be filled into the rules [OPTIONAL] - ARRAY REFERENCE $array_variables - array containing indexed variables to be filled into the rules [OPTIONAL] - BOOL $strict - strict fill flag [OPTIONAL] - Returns : ARRAY containing filled $key and $value (SUCCESS) - Throws : Dies, if message rules not given as arguments - -=cut - -sub fill_in_rule($$$$;$) -{ - my $invocant = shift; - my ($key, $value, $hash_variables, $array_variables, $strict) = @_; - confess "Message rule key must be given as argument" unless $key; - confess "Message rule value must be given as argument" unless $value; - confess "Hash variables must be given as HASH reference" if defined $hash_variables and ref $hash_variables ne 'HASH'; - confess "Array variables must be given as ARRAY reference" if defined $array_variables and ref $array_variables ne 'ARRAY'; - - # IMPORTANT !!! We must make copy of the variables - my $variables = {}; - if (blessed($invocant)) { - # Merge in the per builder configured named variables - map { $variables->{$_} = $invocant->_c($_); } keys(%{$invocant->_c_all()}); - } - # Merge in the per message configured named variables - map { $variables->{$_} = $hash_variables->{$_}; } keys(%$hash_variables); - - # Parse out the positional arguments from array variables - $variables = $invocant->_parse_args($variables, $array_variables); - - $key = $invocant->_fill_in($key, $variables, $strict); - $value = $invocant->_fill_in($value, $variables, $strict); - - return ($key, $value); -} - - -=item fill_in_rules($$$;$) [PUBLIC, HYBRID] - - Usage : my $filled_rules = Mentat::Message::Builder->fill_in_rules($rules, $hash_variables, $array_variables, $strict); - my $filled_rules = $builder->fill_in_rules($rules, $hash_variables, $array_variables); - Purpose : Fill in and return the IDEA message rules building rules with values given in hash and array - Arguments : ARRAY REFERENCE $rules - array containing mentat message rules building rules [MANDATORY] - HASH REFERENCE $hash_variables - hash containing named variables to be filled into the rules - ARRAY REFERENCE $array_variables - array containing indexed variables to be filled into the rules - BOOL $strict - strict fill flag [OPTIONAL] - Returns : ARRAY REFERENCE $filled_message_rules containing filled rules (SUCCESS) - Throws : Dies, if message rules not given as arguments - -=cut - -sub fill_in_rules($$$;$) -{ - my $invocant = shift; - my ($message_rules, $hash_variables, $array_variables, $strict) = @_; - confess "Message rules must be given as argument" unless $message_rules; - confess "Message rules must be given as ARRAY reference" unless ref $message_rules eq 'ARRAY'; - confess "Message rules must not be empty" unless scalar @$message_rules; - confess "Hash variables must be given as HASH reference" if defined $hash_variables and ref $hash_variables ne 'HASH'; - confess "Array variables must be given as ARRAY reference" if defined $array_variables and ref $array_variables ne 'ARRAY'; - - # IMPORTANT !!! We must make copy of the rules, otherwise we would overwrite the templates - my $filled_message_rules = dclone($message_rules); - - # IMPORTANT !!! We must make copy of the variables - my $variables = {}; - if (blessed($invocant)) { - # Merge in the per builder configured named variables - map { $variables->{$_} = $invocant->_c($_); } keys(%{$invocant->_c_all()}); - } - # Merge in the per message configured named variables - map { $variables->{$_} = $hash_variables->{$_}; } keys(%$hash_variables); - - # Parse out the positional arguments from array variables - $variables = $invocant->_parse_args($variables, $array_variables); - - # Fill in all rules - my $result = []; my ($r1, $r2); - foreach my $rule (@$filled_message_rules) { - $r1 = $invocant->_fill_in($rule->[0], $variables, $strict); - $r2 = $invocant->_fill_in($rule->[1], $variables, $strict); - push (@$result, [$r1, $r2]) if defined $r1 and defined $r2; - } - - return $result; -} - -=item build(%) [PUBLIC] - - Usage : my $message = $builder->build(%config); - Purpose : Create message object from rules - Arguments : See appropriate documentation in child classes - Returns : Mentat::Message reference (SUCCESS) - Throws : Dies, if invoked on class - Dies, if invalid message type given as argument - Dies, if variable message configurations not given as argument via hash reference - Dies, if message rules not given as arguments - -=cut - -sub build(%) -{ - my $self = shift; - confess "Method needs to be implemented in subclass"; -} - -=item build_quiet($$$) [PUBLIC] - - Usage : my $message = $builder->build_quiet('Alert', $config, $rules); - Purpose : Create IDEA message object from rules, suppres all exceptions generated by Mentat::Message class - Arguments : Same as build() method - Returns : Mentat::Message reference (SUCCESS) - undef (FAILURE) - Throws : Dies, if invoked on class - Comments : Internally uses build() method - See Also : build() method - -=cut - -sub build_quiet($$$) -{ - my $self = shift; - confess "Instance method not invoked on object instance" unless blessed($self); - - my $message; - eval { - $message = $self->build(@_); - }; - if ($@) { return undef; } - return $message; -} - -=item parse_command_args($) [PUBLIC, HYBRID] - - Usage : - Purpose : - Arguments : - Returns : - Throws : - -=cut - -sub parse_command_args($) -{ - my $invocant = shift; - my ($message_args,) = @_; - confess "Message args must be given as argument" unless $message_args; - - my $tmp = ''; - my @result = (); - my $in = 0; - my $prev = undef; - - # Process the example argument line character by character - foreach my $c (split(//, $message_args)) { - if ($c eq '"') { - if ($in) { - $in = 0; - push(@result, $tmp); - $tmp = ''; - } - else { - $in = 1; - if ($prev eq ' ') { - push(@result, $tmp) if $tmp; - $tmp = ''; - } - } - } - elsif ($in) { - $tmp .= $c; - } - elsif ($c eq ' ') { - push(@result, $tmp) if $tmp; - $tmp = ''; - } - else { - $tmp .= $c; - } - $prev = $c; - } - push(@result, $tmp) if $tmp; - return @result; -} - -#------------------------------------------------------------------------------- -# Private interface -#------------------------------------------------------------------------------- - -# _init [PROTECTED] -# -# Usage : return $self->_init(@_); -# Purpose : Initialize the new Template::Module instance -# Arguments : See the implementation in subclass for details -# Returns : Template::Module reference -# Throws : Dies, if invoked on class -# Comments : This method must never be called directly, it is supposed to be overloaded by subclasses. - -sub _init -{ - my $self = shift; - confess "Method needs to be implemented in subclass"; -} - -# _c($;$) [PROTECTED] -# -# Usage : my $config = $self->_c($key, $default); -# Purpose : Get the given configuration value -# Arguments : STRING $key - name of the configuration [MANDATORY] -# MIXED $default - default value to be returned if not found [OPTIONAL] -# Returns : MIXED $value -# Throws : Dies, if invoked on class - -sub _c($;$) -{ - my $self = shift; - confess "Instance method not invoked on object instance" unless blessed($self); - my ($key, $default) = @_; - - return $self->{CONFIGS}->{$key} if exists $self->{CONFIGS}->{$key}; - return $default; -} - -# _set_c($$) [PROTECTED] -# -# Usage : my $config = $self->_set_c($key, $val); -# Purpose : Set the given configuration value -# Arguments : STRING $key - name of the configuration [MANDATORY] -# MIXED $val - value to be set [MANDATORY] -# Returns : MIXED $value -# Throws : Dies, if invoked on class - -sub _set_c($$) -{ - my $self = shift; - confess "Instance method not invoked on object instance" unless blessed($self); - my ($key, $val) = @_; - - return $self->{CONFIGS}->{$key} = $val; -} - -# _c_all() [PROTECTED] -# -# Usage : my $configs = $self->_c_all(); -# Purpose : Get all configuration values -# Arguments : None -# Returns : HASH REFERENCE $config -# Throws : Dies, if invoked on class - -sub _c_all() -{ - my $self = shift; - confess "Instance method not invoked on object instance" unless blessed($self); - - return $self->{CONFIGS} if $self->{CONFIGS}; - return {}; -} - -# _parse_args(;$$) [PROTECTED] -# -# Usage : my $variables = $self->_parse_args($variables, $array_variables); -# Purpose : Parse the positional arguments and add them to the variable storage hash -# Arguments : HASH REFERENCE $variables - variable storage hash -# ARRAY REFERENCE $array_variables - positional arguments -# Returns : -# Throws : Dies, if not invoked on instance - -sub _parse_args(;$$) -{ - my $invocant = shift; - my ($var, $args) = @_; - - $var = {} unless $var and ref $var eq 'HASH'; - $args = [] unless $args and ref $args eq 'ARRAY'; - - my $index = 0; - foreach my $val (@$args) { - if ($val and $val =~ /^([_a-zA-Z0-9]+?)=(.+)$/) { - $var->{$1} = $2; - } - else { - $var->{++$index} = $val; - } - } - - return $var; -} - -# _fill_in($$$) [PROTECTED,HYBRID] -# -# Usage : return $invocant->_fill_in($rule, $variables, $strict); -# Purpose : Fill in given rule with given variables -# Arguments : STRING $rule - rule to be filled [MANDATORY] -# HASH REFERENCE $variables - variable map [MANDATORY] -# BOOL $strict - die if variable not found flag [OPTIONAL] -# Returns : STRING $rule -# Throws : Dies, if invoked on class - -sub _fill_in($$$) -{ - my $invocant = shift; - my ($rule, $variables, $strict) = @_; - my $tmp; - - # Expand variables in $template, but put an error message inside - # if the variable isn't defined - $rule =~ s{ - \$ # find a literal dollar character - ([a-zA-Z0-9_]+) # find a "word" and store it in $1 - }{ - if (defined $variables->{$1}) { - $variables->{$1}; - } - elsif (exists $variables->{$1}) { - "-+NULL+-"; - } - else { - die "Builder variable '$1' was not found\n" if $strict; - "[NO VARIABLE: $1]"; # error msg - } - }egx; - # Macro expansion - $rule =~ s{ - % # find a literal percentage character - ([a-zA-Z0-9_]+)(?::([^\[/]+))? # find a "macro" and store it in $1 and optional argument to $2 - }{ - $tmp = "_macro_$1"; - if ($invocant->can($tmp)) { - $invocant->$tmp($2); # call the macro - } - else { - die "Builder macro '$1' was not found\n" if $strict; - "[NO MACRO: $1]"; # error msg - } - }egx; - return $rule unless $rule =~ /-\+NULL\+-/; - return undef; -} - -#------------------------------------------------------------------------------- -# Message building macros -#------------------------------------------------------------------------------- - -sub _macro_ts(;$) -{ - my $invocant = shift; - my $utc = shift || time; - - # Parse the timestamp to year, month, day, ... - my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime($utc); - # See http://perldoc.perl.org/functions/localtime.html for explanation of following code - $year += 1900; - $mon += 1; - - return sprintf("%04d-%02d-%02dT%02d:%02d:%02dZ", $year, $mon, $mday, $hour, $min, $sec); -} - -sub _macro_id() -{ - my $invocant = shift; - - # Create random value in UUID ... - my $uuid = ''; - my ($v1, $v2); - for (1 .. 4) { - $v1 = int(rand(65536)) % 65536; - $v2 = int(rand(65536)) % 65536; - $uuid .= pack 'I', ($v1 << 16) | $v2; - } - substr $uuid, 6, 1, chr( ord( substr( $uuid, 6, 1 ) ) & 0x0f | 0x40); - - return $uuid; -} - -sub _macro_ids() -{ - my $invocant = shift; - - use Time::HiRes qw(time); - my @rnd = rand_chars(set => 'alphanumeric', size => $DFLT_LENGTH); - return sprintf('1-%.6f-%'.$DFLT_LENGTH.'s', time, join('', @rnd)); - - # Original solution used better unique ID generation algorithm, but it used to take - # very long time to generate many IDs in a row - #return sprintf('1-%.6f-%'.$DFLT_LENGTH.'s', time, random_string_from($DFLT_CHARS, $DFLT_LENGTH)); -} - -=pod - -=back - -=cut - -1; diff --git a/lib_perl/lib/Mentat/Message/Builder/IDEA.pm b/lib_perl/lib/Mentat/Message/Builder/IDEA.pm deleted file mode 100644 index c540f6c17f347b37e684e2a7765ee476d306434f..0000000000000000000000000000000000000000 --- a/lib_perl/lib/Mentat/Message/Builder/IDEA.pm +++ /dev/null @@ -1,280 +0,0 @@ -package Mentat::Message::Builder::IDEA; -use strict; -use warnings; - -#******************************************************************************* -# DOCUMENTATION SECTION -#******************************************************************************* - -=head1 NAME - -Mentat::Message::Builder::IDEA - Class providing methods for easier building of IDEA messages from scratch - -=head1 SYNOPSIS - - use Mentat::Message::Builder::IDEA; - - # Create builder object - my $builder = Mentat::Message::Builder::IDEA->new(); - - # Message configurations - used to specify values of some variable fields - my $message_config = { - 'detect_time' => 1234567890, # UNIX timestamp of the event detection - 'name' => 'analyzer_name', # STRING value, identifier of the analyzer - }; - - # Build new IDEA message - my $idea = $builder->build($message_config, \@idea_rules); - -=head1 DESCRIPTION - -Instances of this class can be used for easier creation of Mentat::Message::IDEA objects -from scratch. In the IDEA data model there are few elements and attributes, which have -either the same value for all messages coming from given analyzer (like name and type), -or that are impossible to be defined stacically via rules (which is the main concept -used in Mentat::Message::Factory::from_rules method, see the manual page for more information). - -The Mentat::Message::Builder::IDEA object makes use of the rule mechanism mentioned above, -but it adds the ability to B<generate unique message identifiers and timestamps>, and -B<add important elements and attributes to the message> according to the given configurations. -Additionally, it takes care of automatically adding the CreateTime and some other specific -nodes to the message tree structure. - -Message rules given to the I<build()> method of the Mentat::Message::Builder::IDEA object -may overwrite the values set using the configurations listed above. For example, it is -possible for the list of rules to create custom CreateTime value and thus overwrite the -autogenerated CreateTime. - -The rules supplied to the factory method may contain variables and macros, which are expanded -and processed during message generation. Variables can be defined like this: - - B<$[a-zA-Z0-9_]+> - Few examples: - B<$1>, B<$ip>, B<$detect_time>, ... - -Macros are expanded after the variable expansion, so that the parameters may be passed to the macros: - - B<%[a-zA-Z0-9_]+:[a-zA-Z0-9_]> - Few examples: - B<%id>, B<%ts:$detect_time>, ... - -Currently, there are following macros defined: - - B<%id> - generates the unique UUID - B<%ts[:unixts]> - generates the timestamp either from current time, or using given unix timestamp - B<%ipt:$ip> - detects and returns the type of given ip address (IP4|IP6) - -=head1 AUTHOR - - Jan Mach - Cesnet, z.s.p.o - jan.mach@cesnet.cz - http://www.cesnet.cz - -=head1 COPYRIGHT - -This program is free software; you can redistribute -it and/or modify it under the same terms as Perl itself. - -The full text of the license can be found in the -LICENSE file included with this module. - -=head1 SEE ALSO - -perl(1), Mentat::MPath::Parser(3), Mentat::Message(3), Mentat::Message::Factory(3), -Mentat::Message::Builder(3). - -=head1 FUNCTION REFERENCE - -=over 4 - -=cut - -#******************************************************************************* -# LIBRARY LOADING SECTION -#******************************************************************************* - -#-- Perl core modules ---------------------------------------------------------# -use Carp; -use Scalar::Util 'blessed'; -#use Time::HiRes qw(time); - -#use Smart::Comments; #-+-> DEVEL ONLY <-+-# -#use Data::Dumper; #-+-> DEVEL ONLY <-+-# - -#-- Perl CPAN modules ---------------------------------------------------------# - -#-- Custom application modules ------------------------------------------------# -use Value::Convertor; -use Mentat::Message::Builder; -use Mentat::Message::Factory; - -#******************************************************************************* -# CONSTANTS AND GLOBAL VARIABLES DEFINITION SECTION -#******************************************************************************* - -#-- Constants -----------------------------------------------------------------# - -#-- Static public class variables (our) ---------------------------------------# - -#-- Static protected class variables (my) -------------------------------------# - -#******************************************************************************* -# INITIALIZATION AND CLEANUP SECTION -#******************************************************************************* - -#-- Module initializations ----------------------------------------------------# -BEGIN { - use vars qw($VERSION $DEVEL @ISA); - $VERSION = '0.1'; - $DEVEL = 0; - @ISA = ('Mentat::Message::Builder'); -} - - -#-- Module clean-up code (global destructor) ----------------------------------# -END { - -} - -#******************************************************************************* -# IMPLEMENTATION SECTION -#******************************************************************************* - -=item build(%) [PUBLIC] - - Usage : my $message = $builder->build($config, $rules); - Purpose : Create Mentat::Message::IDEA object from rules - Arguments : - Returns : Mentat::Message reference (SUCCESS) - Throws : Dies, if invoked on class - Dies, if invalid message type given as argument - Dies, if variable message configurations not given as argument via hash reference - Dies, if message rules not given as arguments - Comments : Internally uses Mentat::Message::Factory->from_rules() method - See Also : Mentat::Message::Factory->from_rules() method - -=cut - -sub build(%) -{ - my $self = shift; - confess "Instance method not invoked on object instance" unless blessed($self); - my %config = @_; - confess "Message rules must be given as argument" unless $config{rules} and scalar @{$config{rules}}; - confess "Name arguments must be given as HASH reference" unless defined $config{name_args} and ref $config{name_args} eq 'HASH'; - - # Pre-generate the current time for subsequent method calls - $config{name_args}->{current_time} = time; - $config{name_args}->{detect_time} = $config{name_args}->{current_time} unless $config{name_args}->{detect_time}; - - # Generate the list of rules for message creation - my $message_rules_all = []; - push(@$message_rules_all, ["Format", 'IDEA0']); - push(@$message_rules_all, ["ID", '%ids']); - push(@$message_rules_all, ["CreateTime", '%ts:$current_time']); - push(@$message_rules_all, ["DetectTime", '%ts:$detect_time']); - push(@$message_rules_all, $self->_node_rules()); - push(@$message_rules_all, @{$config{rules}}); - push(@$message_rules_all, ['_CESNET/EventTemplate', $config{template_id}]) if $config{template_id}; - - # Fill in the selected message rules - my $filled_message_rules = $self->fill_in_rules($message_rules_all, $config{name_args}, $config{pos_args}, $config{strict}); - - # Finally generate the message object using the rules - return Mentat::Message::Factory->from_rules($filled_message_rules, 'idea'); -} - -#------------------------------------------------------------------------------- -# Private interface -#------------------------------------------------------------------------------- - -# _init [PROTECTED] -# -# Usage : return $self->_init(@_); -# Purpose : Initialize the new Mentat::Message::Builder::IDEA instance -# Arguments : -# Returns : Template::Module reference -# Throws : Dies, if invoked on class -# Comments : This method must never be called directly, it is supposed to be overloaded by subclasses. -# See Also : - -sub _init -{ - my $self = shift; - confess "Instance method not invoked on object instance" unless blessed($self); - my ($config,) = @_; - - # Value postprocessing - if ($self->_c('analyzer_id')) { - my $n = $self->_c('analyzer_id'); - $self->_set_c('name', $n); - } - if ($self->_c('name')) { - my $n = $self->_c('name'); - $n =~ s/[-@]/_/; - $self->_set_c('name', $n); - } - return $self; -} - -# _node_rules() [PRIVATE] -# -# Usage : push(@idea_rules_all, $self->_node_rules()); -# Purpose : Return list of node related rules -# Arguments : None -# Returns : list of Mentat::Message::Factory rules -# Throws : Dies, if invoked on class - -sub _node_rules() -{ - my $self = shift; - confess "Instance method not invoked on object instance" unless blessed($self); - - my @rules = (); - - push(@rules, ["Node[1]/Name", '$name']) if $self->_c('name'); - if ($self->_c('type')) { - my @vals = (); my $i = 0; - if (ref $self->_c('type') eq 'ARRAY') { - push(@vals, @{$self->_c('type')}); - } - else { - push(@vals, split(/[ ,;]+/, $self->_c('type'))); - } - foreach my $v (@vals) { - ++$i; - push(@rules, ["Node[1]/Type[$i]", $v]); - } - } - push(@rules, ["Node[1]/SW", '$sw']) if $self->_c('sw'); - push(@rules, ["Node[1]/AggrWin", '$aggrwin']) if $self->_c('aggrwin'); - push(@rules, ["Node[1]/Note", '$note']) if $self->_c('note'); - - return @rules; -} - -#------------------------------------------------------------------------------- -# Message building macros -#------------------------------------------------------------------------------- - -sub _macro_ipt(;$) -{ - my $invocant = shift; - my $ip = shift; - die "Macro 'ipt' is expecting IP address as argument\n" unless $ip; - - my ($type, @matches) = Value::Convertor->detect_ip($ip); - die "Macro 'ipt' received unknown IP address format '$ip'\n" unless $type; - - return 'IP4' if ($type =~ /IPV4/); - return 'IP6'; -} - -=pod - -=back - -=cut - -1; diff --git a/lib_perl/lib/Mentat/Message/Factory.pm b/lib_perl/lib/Mentat/Message/Factory.pm deleted file mode 100644 index 4289a27674dee4b0ff85bb057c9584a6e5f5189e..0000000000000000000000000000000000000000 --- a/lib_perl/lib/Mentat/Message/Factory.pm +++ /dev/null @@ -1,332 +0,0 @@ -package Mentat::Message::Factory; -use strict; -use warnings; - -#******************************************************************************* -# DOCUMENTATION SECTION -#******************************************************************************* - -=head1 NAME - -Mentat::Message::Factory - Class providing factory methods for creating Mentat messages - -=head1 SYNOPSIS - - use Mentat::Message::Factory; - - # List of message rules according to which to build the Mentat message structure - my @message_rules = ( - ['Alert/Analyzer/@name', 'sshd'], - ['Alert/Source/Node/Address/@category', 'ipv4-addr'], - ['Alert/Source/Node/Address/address', '192.168.0.1'], - ['Alert/Target/Service/name', 'ssh'], - ['Alert/Classification/@text', 'Remote Login'], - ['Alert/Assessment/Impact/@severity', 'low'], - ); - - # Following methods croak, if parser encounters any error - my $message = Mentat::Message::Factory->from_string($string, 'idea'); - my $message = Mentat::Message::Factory->from_file($file_name); - my $message = Mentat::Message::Factory->from_rules($message_rules, 'idea'); - - # These methods make the XML parser silent, they siply return under on failure - my $message = Mentat::Message::Factory->from_string_quiet($string, 'idea'); - my $message = Mentat::Message::Factory->from_file_quiet($file_name); - my $message = Mentat::Message::Factory->from_rules_quiet($message_rules, 'idea'); - -=head1 DESCRIPTION - -This class provides static class methods for creating Mentat message objects from -various sources. There are three pairs of methods provided by the interface. Both -methods in the pair make the same job, but the former one throws exceptions generated -by the parsers and the latter one is silent and catches them, which might be more -convenient in some situations. See the L</"FUNCTION REFERENCE"> section below. - -=head1 MESSAGE RULES - -The I<from_rules()> and I<from_rules_quiet()> method expect list of rules, according -to which to build the Mentat message structure. These rules are simple tuples -(references to arrays with two items), where first item is the MPath of the -desired node and second item is it`s value. Example of the simple rule: - - my $rule = ['Node[1]/Name', 'sshd']; - -=head1 AUTHOR - - Jan Mach - Cesnet, z.s.p.o - jan.mach@cesnet.cz - http://www.cesnet.cz - -=head1 COPYRIGHT - -This program is free software; you can redistribute -it and/or modify it under the same terms as Perl itself. - -The full text of the license can be found in the -LICENSE file included with this module. - - -=head1 SEE ALSO - -perl(1), Mentat::Message::IDEA(3), Mentat::Message::IDEA(3). - -=head1 FUNCTION REFERENCE - -=over 4 - -=cut - -#******************************************************************************* -# LIBRARY LOADING SECTION -#******************************************************************************* - -#-- Perl core modules ---------------------------------------------------------# -use Carp; -use Scalar::Util 'blessed'; - -use Data::Dumper; #-+-> DEVEL ONLY <-+-# -#use Smart::Comments; #-+-> DEVEL ONLY <-+-# - -#-- Perl CPAN modules ---------------------------------------------------------# - -#-- Custom application modules ------------------------------------------------# -use Data::Tree; -use Mentat::Message::IDEA; - -#******************************************************************************* -# CONSTANTS AND GLOBAL VARIABLES DEFINITION SECTION -#******************************************************************************* - -#-- Constants -----------------------------------------------------------------# -use constant VAL_UNDEF => '__UNDEF__'; - -#-- Static public class variables (our) ---------------------------------------# - -#-- Static protected class variables (my) -------------------------------------# - -my %CLASS2CLASS = ( - 'tree' => 'Data::Tree', - 'mongo' => 'Data::Tree', - 'idea' => 'Mentat::Message::IDEA', - ); - -my %EXT2CLASS = ( - 'tree' => 'tree', - 'mongo' => 'mongo', - 'idea' => 'idea', - ); - -#******************************************************************************* -# INITIALIZATION AND CLEANUP SECTION -#******************************************************************************* - -#-- Module initializations ----------------------------------------------------# -BEGIN { - use vars qw($VERSION $DEVEL); - $VERSION = '0.1'; - $DEVEL = 0; -} - - -#-- Module clean-up code (global destructor) ----------------------------------# -END { - -} - -#******************************************************************************* -# IMPLEMENTATION SECTION -#******************************************************************************* - -=item from_string($$) [PUBLIC, STATIC] - - Usage : my $message = Mentat::Message::Factory->from_string($message_string, $message_class); - Purpose : Create Mentat message object from given string - Arguments : STRING $message_string - string containing Mentat message - STRING $message_class - class of the message stored in a string - Returns : Mentat::Message reference (SUCCESS) - Throws : Croaks, if invoked on object - Croaks, if Mentat message string not given as argument - Croaks, if Mentat message type not given as argument - Croaks, if given invalid Mentat message class as argument - Comments : - See Also : from_string_quiet() method - -=cut - -sub from_string($$) -{ - my $class = shift; - confess "Class method not invoked on class" if blessed($class); - my ($message_string, $message_class) = @_; - confess "Mentat message string must be given as argument" unless defined($message_string); - confess "Mentat message type must be given as argument" unless defined($message_class); - confess "Invalid Mentat message class '$message_class'" unless exists($CLASS2CLASS{$message_class}); - - my $message_class_name = $CLASS2CLASS{$message_class}; - return $message_class_name->unserialize($message_string); -} - -=item from_string_quiet($$) [PUBLIC, STATIC] - - Usage : my $message = Mentat::Message::Factory->from_string_quiet($message_string, $message_class); - Purpose : Create Mentat message object from given string, suppres all exceptions - Arguments : Same as from_string() method - Returns : Mentat::Message reference (SUCCESS) - undef (failure) - Throws : Croaks, if invoked on object - Same as from_string() method - Comments : - See Also : from_string() method - -=cut - -sub from_string_quiet($$) -{ - my $class = shift; - confess "Class method not invoked on class" if blessed($class); - - my $message; - eval { - $message = $class->from_string(@_); - }; - if ($@) { return undef; } - return $message; -} - -=item from_file($;$) [PUBLIC, STATIC] - - Usage : my $message = Mentat::Message::Factory->from_file($message_file, $message_class); - Purpose : Create Mentat message object from given file - Arguments : STRING $message_file - name of the file containing Mentat message - STRING $message_class - class of the message stored in a file (OPTIONAL) - Returns : Mentat::Message reference (SUCCESS) - Throws : Croaks, if invoked on object - Croaks, if Mentat message file name not given as argument - Croaks, if Mentat message type not given or detectable - Croaks, if given invalid Mentat message class as argument - Comments : Type of the message is optional argument, if the type can be automatically - detected from the file name - See Also : from_file_quiet() method - -=cut - -sub from_file($;$) -{ - my $class = shift; - confess "Class method not invoked on class" if blessed($class); - my ($message_file, $message_class) = @_; - confess "Invalid usage, Mentat message file name must be given as argument" unless defined($message_file); - confess "Invalid Mentat message class '$message_class'" if defined($message_class) and not exists($CLASS2CLASS{$message_class}); - - # If not explicitly given the message type, try to autodetect it from file extension - unless ($message_class) { - my $ext; - if ($message_file =~ m/\.([\w\d]+)$/) { - $ext = $1; - } - confess "Cannot determine Mentat message type based on the file name" unless defined($ext); - confess "Unknown message file extension '$ext'" unless exists($EXT2CLASS{$ext}); - $message_class = $EXT2CLASS{$ext}; - } - - my $message_class_name = $CLASS2CLASS{$message_class}; - return $message_class_name->from_file($message_file); -} - -=item from_file_quiet($) [PUBLIC, STATIC] - - Usage : my $message = Mentat::Message::Factory->from_file_quiet($message_file, $message_class); - Purpose : Create Mentat message object from given file, suppres all exceptions - Arguments : Same as from_file() method - Returns : Mentat::Message reference (SUCCESS) - undef (FAILURE) - Throws : Croaks, if invoked on object - Same as from_file() method - Comments : - See Also : from_file() method - -=cut - -sub from_file_quiet($) -{ - my $class = shift; - confess "Class method not invoked on class" if blessed($class); - - my $message; - eval { - $message = $class->from_file(@_); - }; - if ($@) { return undef; } - return $message; -} - -=item from_rules($$) [PUBLIC, STATIC] - - Usage : my $message = Mentat::Message::Factory->from_rules($message_rules, $message_class); - Purpose : Create Mentat message object from given rules - Arguments : ARRAY REFERENCE $message_rules - Mentat message rules (each rule is passed as argument to Mentat::Message::path_node_set() method) - STRING $message_class - class of the message - Returns : Mentat::Message reference (SUCCESS) - Throws : Croaks, if invoked on object - Croaks, if Mentat message rules not given as arguments - Croaks, if Mentat message type not given as argument - Croaks, if given invalid Mentat message class as argument - Comments : - See Also : from_rules_quiet() method, Mentat::Message::path_node_set() method - -=cut - -sub from_rules($$) -{ - my $class = shift; - confess "Class method not invoked on class" if blessed($class); - my ($message_rules, $message_class) = @_; - confess "Invalid usage, Mentat message rules must be given as argument" unless $message_rules and scalar @$message_rules; - confess "Mentat message type must be given as argument" unless defined($message_class); - confess "Invalid Mentat message class '$message_class'" unless exists($CLASS2CLASS{$message_class}); - - my $message_class_name = $CLASS2CLASS{$message_class}; - my $message = $message_class_name->new(); - my ($mpath, $value); - foreach my $rule (@$message_rules) { - ($mpath, $value) = @$rule; - $message->path_node_set($mpath, $value) unless uc($value) eq VAL_UNDEF(); - } - return $message; -} - -=item from_rules_quiet(@) [PUBLIC, STATIC] - - Usage : my $message = Mentat::Message::Factory->from_rules_quiet(@message_rules); - Purpose : Create Mentat message object from given rules, suppres all exceptions - Arguments : Same as from_rules() method - Returns : Mentat::Message reference (SUCCESS) - undef (FAILURE) - Throws : Croaks, if invoked on object - Croaks, if Mentat message rules not given as arguments - Comments : - See Also : from_rules() method - -=cut - -sub from_rules_quiet -{ - my $class = shift; - confess "Class method not invoked on class" if blessed($class); - - my $message; - eval { - $message = $class->from_rules(@_); - }; - if ($@) { return undef; } - return $message; -} - -=pod - -=back - -=cut - -1; diff --git a/lib_perl/lib/Mentat/Message/IDEA.pm b/lib_perl/lib/Mentat/Message/IDEA.pm deleted file mode 100644 index ccb77c49302464bec059745315f504672e01887d..0000000000000000000000000000000000000000 --- a/lib_perl/lib/Mentat/Message/IDEA.pm +++ /dev/null @@ -1,1083 +0,0 @@ -package Mentat::Message::IDEA; -use strict; -use warnings; - -#******************************************************************************* -# DOCUMENTATION SECTION -#******************************************************************************* - -=head1 NAME - -Mentat::Message::IDEA - Class for working with Mentat::Message::IDEA objects - -=head1 SYNOPSIS - - use Mentat::Message::IDEA; - - my $instance = Mentat::Message::IDEA->new(); - - my @MESSAGE_RULES = ( - ["Format", "IDEA0"], - ["ID", "2E4A3926-B1B9-41E3-89AE-B6B474EB0A54"], - ["DetectTime", "2014-03-22T10:12:31Z"], - ["Category[1]", "Recon.Scanning"], - ["ConnCount", 633], - ["Description", "EPMAPPER exploitation attempt"], - ["Ref[1]", "cve:CVE-2003-0605"], - ["Source[1]/IP4[1]", "93.184.216.119"], - ["Source[1]/Proto[1]", "tcp"], - ["Source[1]/Proto[2]", "epmap"], - ["Source[1]/Port[1]", "24508"], - ["Target[1]/Proto[1]", "tcp"], - ["Target[1]/Proto[2]", "epmap"], - ["Target[1]/Port[1]", "135"], - ["Node[1]/Name", "kippo-honey"], - ["Node[1]/Realm", "cesnet.cz"], - ["Node[1]/Tags[1]", "Protocol"], - ["Node[1]/Tags[2]", "Honeypot"], - ["Node[1]/SW", "Kippo"], - ["Node[1]/AggrWin", "00:05:00"], - ); - # Create the message structure by hand according to the given rules - foreach my $rule (@MESSAGE_RULES) { - $instance->path_node_set(@$rule); - } - - # Check the existence of given node - if ($instance->path_node_exists('Format')) { ... } - - # Export the message to the string - print STDOUT $instance->to_string($pretty); - - # Get value (first) on given path - my $value = $instance->path_value('Source/IP4'); - # Get list of all values on given path - my $values = $instance->path_values('Source/IP4'); - -=head1 DESCRIPTION - - - -=head1 AUTHOR - - Jan Mach - Cesnet, z.s.p.o - jan.mach@cesnet.cz - http://www.cesnet.cz - -=head1 COPYRIGHT - -This program is free software; you can redistribute -it and/or modify it under the same terms as Perl itself. - -The full text of the license can be found in the -LICENSE file included with this module. - -=head1 SEE ALSO - -perl(1). - -=head1 FUNCTION REFERENCE - -=over 4 - -=cut - -#******************************************************************************* -# LIBRARY LOADING SECTION -#******************************************************************************* - -#-- Perl core modules ---------------------------------------------------------# -use Carp; -use Scalar::Util 'blessed'; - -use Data::Dumper; #-+-> DEVEL ONLY <-+-# -#use Smart::Comments; #-+-> DEVEL ONLY <-+-# - -#-- Perl CPAN modules ---------------------------------------------------------# -use Data::Compare; -use JSON; - -#-- Custom application modules ------------------------------------------------# -use Mentat::Message; -use Value::Convertor; -use Value::IP; -use Value::Timestamp; -use Value::Period; -use Mentat::MPath::Parser; - -#******************************************************************************* -# CONSTANTS AND GLOBAL VARIABLES DEFINITION SECTION -#******************************************************************************* - -#-- Constants -----------------------------------------------------------------# -use constant MPATH_MSGID => 'ID'; -use constant IPV4 => 'IPV4'; -use constant IPV6 => 'IPV6'; - -use constant CONVERSIONS => { - 'CreateTime' => ['_convert_timestamp'], - 'DetectTime' => ['_convert_timestamp'], - 'EventTime' => ['_convert_timestamp'], - 'CeaseTime' => ['_convert_timestamp'], - 'WinStartTime' => ['_convert_timestamp'], - 'WinEndTime' => ['_convert_timestamp'], - - 'Source/IP4' => ['_convert_address', IPV4()], - 'Source/IP6' => ['_convert_address', IPV6()], - 'Target/IP4' => ['_convert_address', IPV4()], - 'Target/IP6' => ['_convert_address', IPV6()], - - 'ConnCount' => ['_convert_int'], - 'FlowCount' => ['_convert_int'], - 'PacketCount' => ['_convert_int'], - 'ByteCount' => ['_convert_int'], - 'Source/Port' => ['_convert_int'], - 'Target/Port' => ['_convert_int'], - 'Source/ASN' => ['_convert_int'], - 'Target/ASN' => ['_convert_int'], - 'Attach/Size' => ['_convert_int'], - }; - -#-- Static public class variables (our) ---------------------------------------# - -#-- Static protected class variables (my) -------------------------------------# - -#******************************************************************************* -# INITIALIZATION AND CLEANUP SECTION -#******************************************************************************* - -#-- Module initializations ----------------------------------------------------# -BEGIN { - use vars qw($VERSION $DEVEL @ISA); - $VERSION = '0.1'; - $DEVEL = 0; - @ISA = ('Mentat::Message'); -} - -#-- Module clean-up code (global destructor) ----------------------------------# -END { - -} - -#-- Operator overloading ------------------------------------------------------# -use overload - '==' => 'cmp_eq', - 'eq' => 'cmp_eq'; - -#******************************************************************************* -# IMPLEMENTATION SECTION -#******************************************************************************* - -=item unserialize($) [PUBLIC, STATIC] - - Usage : my $message = Mentat::Message::IDEA->unserialize($string); - Purpose : Recover serialized instance of the Mentat::Message from given string - Arguments : STRING $string - string containing serialized instance [MANDATORY] - Returns : Mentat::Message::IDEA REFERENCE - Throws : Dies, if not invoked on class - -=cut - -sub unserialize($) -{ - my $class = shift; - confess "Class method not invoked on class" if blessed($class); - my ($string,) = @_; - - my $message = $class->new(decode_json($string)); - $message->_objectify(); - return $message; -} - -=item from_file($) [PUBLIC, STATIC] - - Usage : my $message = Mentat::Message::IDEA->from_file($filename); - Purpose : Recover serialized instance of the Mentat message from given file - Arguments : STRING $filename - name of the file containing serialized instance [MANDATORY] - Returns : Mentat::Message::IDEA REFERENCE - Throws : Dies, if not invoked on class - Comments : Internally uses unserialize() method - See Also : unserialize() method - -=cut - -sub from_file($) -{ - my $class = shift; - confess "Class method not invoked on class" if blessed($class); - my ($filename,) = @_; - confess "Message file name must be given as argument" unless $filename; - confess "Message file '$filename' is not ordinary file" unless -f $filename; - - # Load message from external file to string and untaint it - open (my $mf, $filename) or die "Can`t open message file '$filename'\n"; - my $message = join("", <$mf>); - close($mf); - if ($message =~ /^(.+)$/s) { $message = $1; } - - # Unserialize the message from the string - return $class->unserialize($message); -} - -#------------------------------------------------------------------------------- - -=item id(;$) [PUBLIC] - - Usage : my $id = $message->id(); - Purpose : Get (and optionally set) the ID attribute of the current Mentat message - Arguments : STRING $id - Message ID which to set (OPTIONAL) - Returns : STRING current message ID - Throws : Dies, if not invoked on object - Same as path_node_set() and path_value() methods - Comments : Internally uses path_node_set() and path_value() methods - See Also : path_node_set(), path_value() methods - -=cut - -sub id(;$) -{ - my $self = shift; - confess "Instance method not invoked on object instance" unless blessed($self); - my ($message_id,) = @_; - - # If we have been given the message ID, set it up - if ($message_id) { - $self->path_node_set(MPATH_MSGID(), $message_id) - } - return $self->path_value(MPATH_MSGID()); -} - -=item hash() [PUBLIC] - - Usage : my $hash = $message->hash(); - Purpose : Get the message structure hash - Arguments : None - Returns : HASH REFERENCE $hash - Throws : Dies, if not invoked on object - -=cut - -sub hash() -{ - my $self = shift; - confess "Instance method not invoked on object instance" unless blessed($self); - - return $self->{HASH}; -} - -#------------------------------------------------------------------------------- - -=item iterate(;$$$) [PUBLIC] - - Usage : - Purpose : - Arguments : - Returns : - Throws : Dies, if not invoked on object - Comments : - See Also : - -=cut - -sub iterate(;$$$) -{ - my $self = shift; - confess "Instance method not invoked on object instance" unless blessed($self); - my ($pattern, $nodemode, $fullmode) = @_; - - unless ($self->{ITER}) { - $self->{ITER} = []; - $self->_prepare_iterator($self->{HASH},'', $fullmode); - $self->{ITER} = [sort {$a->[0] cmp $b->[0]} @{$self->{ITER}}] - } - - my $next; - - while ($next = shift(@{$self->{ITER}})) { - my ($mpath, $node) = @$next; - - next if ($pattern) and not $mpath =~ /$pattern/; - - return ($mpath, $$node) unless $nodemode; - return ($mpath, $node); - } - $self->{ITER} = undef; - return (undef, undef); -} - -#------------------------------------------------------------------------------- - -=item path_nodes($) [PUBLIC] - - Usage : my $nodes = $message->path_nodes($mpath); - Purpose : Get all nodes on given message path - Arguments : STRING $mpath - message path to the nodes (MANDATORY) - Returns : reference to array of values - Throws : Dies, if not invoked on object - Dies, if not given message path - Dies, if node on given message path does not exist - Comments : Internally uses private methods _path_nodes() and _get_child_text_node() - See Also : Mentat::Message::Path::Parser class - -=cut - -sub path_nodes($) -{ - my $self = shift; - confess "Instance method not invoked on object instance" unless blessed($self); - my ($mpath,) = @_; - - # Storage for nodes in current processing round - my $nodes_a = [$self->{HASH}]; - - # Storage for nodes in next processing round - my $nodes_b = []; - - # Process the given MPath chunk by chunk - my ($name, $type, $index, $lindex, $tmp_val); - do { - ($name, $type, $index, $mpath) = Mentat::MPath::Parser->parse_next_chunk($mpath); - $name = ($type eq 'attr') ? '@' . $name : $name; - - # Check each node in the storage - foreach my $node (@$nodes_a) { - # Node must be a hash reference, otherwise it does not make any sense - # asking for '$name', and of course '$name' key must exist - next unless (ref $node eq 'HASH' and exists $node->{$name}); - - # If the MPath contained index part - if ($index) { - # Node must be array reference, otherwise it does not make any sense - # and of course array must not be empty - next unless (ref $node->{$name} eq 'ARRAY') and scalar @{$node->{$name}} > 0; - - if ($index eq '#') { - $lindex = $#{$node->{$name}}; - } - else { - $lindex = $index - 1; - } - - # Node on given index must exist - next unless $node->{$name}->[$lindex]; - - # We must pass everything by reference - $tmp_val = (ref $node->{$name}->[$lindex]) ? $node->{$name}->[$lindex] : \$node->{$name}->[$lindex]; - - # Let the node be handled in next round - push(@$nodes_b, $tmp_val); - } - # We do not care about any particular index - else { - # If there are multiple subnodes under current node`s speciffic key, we must - # add all of them - if (ref $node->{$name} eq 'ARRAY') { - # C-like for loop must be used in this case, because we must pass everything by reference - for (my $i = 0; $i < scalar(@{$node->{$name}}); $i++) { - # We must pass everything by reference - $tmp_val = (ref $node->{$name}->[$i]) ? $node->{$name}->[$i] : \$node->{$name}->[$i]; - - # Let the node be handled in next round - push(@$nodes_b, $tmp_val); - } - } - else { - # We must pass everything by reference - $tmp_val = (ref $node->{$name}) ? $node->{$name} : \$node->{$name}; - - # Let the node be handled in next round - push(@$nodes_b, $tmp_val); - } - } - } - - return undef unless scalar $nodes_b; - $nodes_a = $nodes_b; $nodes_b = []; - - } while ($mpath); - - return $nodes_a; -} - -=item path_node_set($$) [PUBLIC] - - Usage : $message->path_node_set($mpath, $value); - Purpose : If it does not exist, append new node to the Mentat message on the given path and set it`s value - Arguments : STRING $mpath - path in the Mentat message structure (MANDATORY) - STRING $value - value of the object (MANDATORY) - Returns : Nothing - Throws : Dies, if not invoked on object - Dies, if not given message path and value to set - Dies, if message path is syntactically incorrect - Comments : Internally uses private recursive method _append_node() - See Also : _append_node() method, Mentat::Message::Path::Parser class - -=cut - -sub path_node_set($$) -{ - my $self = shift; - confess "Instance method not invoked on object instance" unless blessed($self); - my ($mpath, $value) = @_; - - $value = $self->_prepare_value($mpath, $value); - - # Recursively parse the given MPath and create the inner HASH structure - $self->_append_node($self->{HASH}, '', $mpath, $value); -} - -=item path_node_delete($) [PUBLIC] - - Usage : my $node = $message->path_delete($mpath); - Purpose : Deletes node on given message path - Arguments : string $mpath - message path to the node (MANDATORY) - Returns : Nothing - Throws : Dies, if not invoked on object - Dies, if not given message path - Dies, if node on given message path does not exist - Comments : Internally uses private method _path_node() - See Also : _path_node() method, Mentat::Message::Path::Parser class - -=cut - -sub path_node_delete($) -{ - my $self = shift; - confess "Instance method not invoked on object instance" unless blessed($self); - my ($mpath,) = @_; - - # Storage for nodes in current processing round - my $nodes_a = [$self->{HASH}]; - - # Storage for nodes in next processing round - my $nodes_b = []; - - # Parse the given MPath in one call - my @chunks = Mentat::MPath::Parser->parse($mpath); - - my ($name, $type, $index, $tmp_val); - for (my $i = 0; $i < scalar(@chunks); $i++) { - ($name, $type, $index) = @{$chunks[$i]}; - $name = ($type eq 'attr') ? '@' . $name : $name; - - # Check each node in the storage - foreach my $node (@$nodes_a) { - - # Node must be a hash reference, otherwise it does not make any sense - # asking for '$name', and of course '$name' key must exist - next unless (ref $node eq 'HASH' and exists $node->{$name}); - - # If the MPath contained index part - if ($index) { - # '*' and '#' as index value are forbidden for deletion - next if $index eq '*' or $index eq '#'; - - # Node must be array reference, otherwise it does not make any sense - # and of course array element at '$index' must exist - next unless (ref $node->{$name} eq 'ARRAY' and $node->{$name}->[$index-1]); - - # End of the MPath, do the removal - if (($i+1) == scalar(@chunks)) { - splice(@{$node->{$name}}, ($index-1), 1); - } - else { - # We must pass everything by reference - $tmp_val = (ref $node->{$name}->[$index-1]) ? $node->{$name}->[$index-1] : \$node->{$name}->[$index-1]; - - # Let the node be handled in next round - push(@$nodes_b, $tmp_val); - } - } - # We do not care about any particular index - else { - # If there are multiple subnodes under current node`s speciffic key, we must - # add all of them - if (ref $node->{$name} eq 'ARRAY') { - # End of the MPath, do the removal - if (($i+1) == scalar(@chunks)) { - delete $node->{$name}; - } - else { - # C-like for loop must be used in this case, because we must pass everything by reference - for (my $i = 0; $i < scalar(@{$node->{$name}}); $i++) { - # We must pass everything by reference - $tmp_val = (ref $node->{$name}->[$i]) ? $node->{$name}->[$i] : \$node->{$name}->[$i]; - - # Let the node be handled in next round - push(@$nodes_b, $tmp_val); - } - } - } - else { - # End of the MPath, do the removal - if (($i+1) == scalar(@chunks)) { - delete $node->{$name}; - } - else { - # We must pass everything by reference - $tmp_val = (ref $node->{$name}) ? $node->{$name} : \$node->{$name}; - - # Let the node be handled in next round - push(@$nodes_b, $tmp_val); - } - } - } - } - - last unless scalar $nodes_b; - $nodes_a = $nodes_b; $nodes_b = []; - } -} - -#------------------------------------------------------------------------------- - -=item path_values($) [PUBLIC] - - Usage : my $value = $message->path_values($mpath); - Purpose : Gets values of all nodes on given message path - Arguments : STRING $mpath - message path to the nodes (MANDATORY) - Returns : reference to array of values - Throws : Dies, if not invoked on object - Dies, if not given message path - Dies, if node on given message path does not exist - Comments : Internally uses private methods _path_nodes() and _get_child_text_node() - See Also : Mentat::Message::Path::Parser class - -=cut - -sub path_values($) -{ - my $self = shift; - confess "Instance method not invoked on object instance" unless blessed($self); - my ($mpath,) = @_; - - my $nodes = $self->path_nodes($mpath); - my $values = []; - map { push(@$values, ((ref $_ eq 'SCALAR')?$$_:$_)); } @$nodes; - return $values; -} - -=item path_value_set($$) [PUBLIC] - - Usage : my $value = $message->path_value_set($mpath, $value); - Purpose : Set and return value of first node on given message path - Arguments : STRING $mpath - message path to the node (MANDATORY) - STRING $value - New node value (MANDATORY) - Returns : Nothing - Throws : Dies, if not invoked on object - Dies, if not given message path - Dies, if node on given message path does not exist - Comments : Internally uses private methods _path_node() and _get_child_text_node() - See Also : Mentat::Message::Path::Parser class - -=cut - -sub path_value_set($$) -{ - my $self = shift; - confess "Instance method not invoked on object instance" unless blessed($self); - my ($mpath, $value) = @_; - - $value = $self->_prepare_value($mpath, $value); - - my $node = $self->path_node($mpath); - confess "Node on path '$mpath' does not exist" unless $node; - - if (ref $node eq 'SCALAR') { - $$node = $value; - } - else { - confess "Suspicious attempt to assign scalar value instead of previous HASH or ARRAY reference"; - } -} - -#------------------------------------------------------------------------------- - -=item serialize() [PUBLIC] - - Usage : my $string = $message->serialize(); - Purpose : Export Mentat message into string - Arguments : None - Returns : STRING $string - string containing serialized Mentat message - Throws : Dies, if not invoked on object - -=cut - -sub serialize() -{ - my $self = shift; - confess "Instance method not invoked on object instance" unless blessed($self); - - #return encode_json($self->{HASH}); - return JSON->new->utf8->allow_blessed->convert_blessed->encode($self->{HASH}) -} - -=item to_string(;$) [PUBLIC] - - Usage : my $string = $message->to_string(); - Purpose : Export Mentat message into readable string - Arguments : BOOL $pretty - format message nicely (OPTIONAL) - Returns : STRING $string - string containing serialized Mentat message - Throws : Dies, if not invoked on object - Comments : - See Also : - -=cut - -sub to_string(;$) -{ - my $self = shift; - confess "Instance method not invoked on object instance" unless blessed($self); - - my $pretty = (shift @_) ? 1 : 0; - - return to_json($self->{HASH}, {utf8 => 1, pretty => $pretty, allow_blessed => 1, convert_blessed => 1}); -} - -=item cmp_eq($$$) [PUBLIC] - - Usage : Will be used automatically in integer or string equality comparison context (==,eq) - Purpose : Allow integer and string equality comparisons (==,eq) - Arguments : Value::Single $self - left comparison operand - MIXED $other - right comparison operand - BOOL $swap - swap left and right operand - Returns : INTEGER $result (0 or 1) if the operads are equal - Throws : Dies, if not invoked on object - Comments : Must be implemented apropriatelly in subclasses - -=cut - -sub cmp_eq($$$) -{ - my ($self, $other, $swap) = @_; - confess "Instance method not invoked on object instance" unless blessed($self); - - my $left = $self->hash(); - my $right; - if (blessed($other) and (blessed($other) eq 'Mentat::Message::IDEA')) { - $right = $other->hash(); - } - elsif (ref $other and ref $other eq 'HASH') { - $right = $other; - } - else { - die "Unable to compare object with scalar or ARRAY\n"; - } - - ($left, $right) = ($right, $left) if $swap; - - return Compare($left, $right); -} - -=item is_expired($;$$) [PUBLIC] - - Usage : my $result = $message->is_expired($threshold); - Purpose : - Arguments : - Returns : - Throws : Dies, if not invoked on object - -=cut - -sub is_expired($;$$) -{ - my $self = shift; - confess "Instance method not invoked on object instance" unless blessed($self); - my ($threshold, $attribute, $tsc) = @_; - - $attribute = 'DetectTime' unless $attribute; - $tsc = time unless $tsc; - - my $ts = $self->path_value($attribute); - confess "Unable to check expiration" unless $ts; - - $tsc -= $threshold; - - return ($tsc <= $ts) ? 0 : 1; -} - -#------------------------------------------------------------------------------- -# Private interface -#------------------------------------------------------------------------------- - -# _init(;$) [PROTECTED] -# -# Usage : return $self->_init(@_); -# Purpose : Initialize the new Mentat::Message::IDEA instance -# Arguments : -# Returns : -# Throws : Dies, if not invoked on object -# Comments : This method must never be called directly, it is supposed to be overloaded by subclasses. -# See Also : - -sub _init(;$$) -{ - my $self = shift; - confess "Instance method not invoked on object instance" unless blessed($self); - my ($hash, $objectify) = @_; - - # Build default message structure - unless (defined $hash) { - $hash = { - 'Format' => 'IDEA0', - }; - } - else { - confess "Message structure must be given via HASH reference" unless ref $hash eq 'HASH'; - } - - # Structure of hash of hashes - $self->{HASH} = $hash; - - # Objectify, if requested - $self->_objectify() if $objectify; - - return $self; -} - -# _append_node($$$$) [PRIVATE] -# -# Usage : $self->_append_node($self->{HASH}, $mpath, $rest, $value); -# Purpose : Recursively walks through the given MPath and creates all necessary nodes, sets the given value to the last one -# Arguments : HASH REFERENCE $current - current node, we are working with (MANDATORY) -# STRING $mpath - already processed MPath (MANDATORY) -# STRING $rest - rest of the MPath to process (MANDATORY) -# STRING $value - value to assign to the last node in the path (MANDATORY) -# Returns : Nothing -# Throws : Dies, if not invoked on object -# Dies, if MPath was invalid -# Comments : This method is for internal use only, it is called from path_node_set() method -# See Also : path_node_set() method - -sub _append_node($$$$) -{ - my $self = shift; - confess "Instance method not invoked on object instance" unless blessed($self); - my ($current, $mpath, $rest, $value) = @_; - - # Parse next chunk from the rest of the given MPath - my ($name, $type, $index, $ref); - ($name, $type, $index, $rest) = Mentat::MPath::Parser->parse_next_chunk($rest); - $name = ($type eq 'attr') ? '@' . $name : $name; - - # If we are not at the end of the path, build the structure recursively - if ($rest) { - - if (not $index and exists($current->{$name}) and (ref $current->{$name} eq 'ARRAY')) { - # EITHER complain - #confess "Structure at '$name' was already defined as array multivalue: " . Dumper($current); - - # OR handle - $index = 1; - } - - # We must handle multivalues separately - if ($index) { - # Perhaps the node on this MPath already exists and it is not a multivalue - if (exists($current->{$name}) and not (ref $current->{$name} eq 'ARRAY')) { - # EITHER complain - #confess "Structure at '$name' was already defined and not as array"; - - # OR handle - my $tmp = $current->{$name}; $current->{$name} = [$tmp]; - } - # Push new element to the end of existing array - if ($index eq '*') { - my $x = {}; push(@{$current->{$name}}, $x); - $self->_append_node($x, Mentat::MPath::Parser->join($mpath,$name, $index), $rest, $value); - } - # Work with the last element of existing array - elsif ($index eq '#') { - my $l = 0; $l = $#{$current->{$name}} if ref $current->{$name} eq 'ARRAY'; - $current->{$name}->[$l] = {} unless exists $current->{$name}->[$l]; - $self->_append_node($current->{$name}->[$l], Mentat::MPath::Parser->join($mpath, $name, $index), $rest, $value); - } - # Work with the element on specific position within array - else { - $current->{$name}->[$index-1] = {} unless exists $current->{$name}->[$index-1]; - $self->_append_node($current->{$name}->[$index-1], Mentat::MPath::Parser->join($mpath, $name, $index), $rest, $value); - } - } - # Single values are easy to deal with - else { - confess "Structure at '$name' was already defined and not as HASH: " . Dumper($current) if (exists($current->{$name}) and not (ref $current->{$name} eq 'HASH')); - $current->{$name} = {} unless exists $current->{$name}; - $self->_append_node($current->{$name}, Mentat::MPath::Parser->join($mpath,$name), $rest, $value); - } - } - # End of the path, assign the value - else { - if (not $index and exists($current->{$name}) and (ref $current->{$name} eq 'ARRAY')) { - # EITHER complain - confess "Structure at '$name' was already defined as array multivalue: " . Dumper($current); - - # OR handle - $index = 1; - } - - # We must handle multivalues separately - if ($index) { - # Perhaps the node on this MPath already exists and it is not a multivalue - if (exists($current->{$name}) and not (ref $current->{$name} eq 'ARRAY')) { - # EITHER complain - #confess "Structure at '$name' was already defined and not as array"; - - # OR handle - my $tmp = $current->{$name}; $current->{$name} = [$tmp]; - } - # Append new element to existing array - if ($index eq '*') { - push(@{$current->{$name}}, $value); - } - # Replace the value of last element in array - elsif ($index eq '#') { - my $l = 0; $l = $#{$current->{$name}} if ref $current->{$name} eq 'ARRAY'; - $current->{$name}->[$l] = $value; - } - # Put the value to specific position - else { - $current->{$name}->[$index-1] = $value; - } - } - # Single values are easy to deal with - else { - $current->{$name} = $value; - } - } -} - -# _prepare_iterator($$;$) [PROTECTED] -# -# Usage : -# Purpose : -# Arguments : -# Returns : -# Throws : Dies, if not invoked on object -# Comments : -# See Also : - -sub _prepare_iterator($$;$) -{ - my $self = shift; - confess "Instance method not invoked on object instance" unless blessed($self); - my ($hash, $path, $fullmode) = @_; - - my ($mpath, $ref, $i); - foreach my $key (keys(%$hash)) { - # Handle subhashes - if(ref $hash->{$key} eq 'HASH') { - $mpath = Mentat::MPath::Parser->join($path, $key); - $ref = \$hash->{$key}; - push(@{$self->{ITER}}, [$mpath, $ref]) if $fullmode; - $self->_prepare_iterator($hash->{$key}, Mentat::MPath::Parser->join($path, $key), $fullmode); - } - elsif (ref $hash->{$key} eq 'ARRAY') { - - $mpath = Mentat::MPath::Parser->join($path, $key); - $ref = \$hash->{$key}; - push(@{$self->{ITER}}, [$mpath, $ref]) if $fullmode; - - $i = 0; - foreach my $item (@{$hash->{$key}}) { - $mpath = Mentat::MPath::Parser->join($path, $key, $i+1); - if (ref $item eq 'HASH') { - $ref = \$hash->{$key}->[$i]; - push(@{$self->{ITER}}, [$mpath, $ref]) if $fullmode; - $self->_prepare_iterator($item, $mpath, $fullmode); - } - else { - $ref = \$hash->{$key}->[$i]; - push(@{$self->{ITER}}, [$mpath, $ref]); - } - ++$i; - } - } - else { - $ref = \$hash->{$key}; - $mpath = Mentat::MPath::Parser->join($path, $key); - push(@{$self->{ITER}}, [$mpath, $ref]); - } - } -} - -# _prepare_value($$) [PROTECTED] -# -# Usage : -# Purpose : -# Arguments : -# Returns : -# Throws : Dies, if not invoked on object -# Comments : -# See Also : - -sub _prepare_value($$) -{ - my $self = shift; - confess "Instance method not invoked on object instance" unless blessed($self); - my ($mpath, $value) = @_; - - my $mpath_s = $mpath; $mpath_s =~ s/\[\d*\]//g; - - # Handle the MPath unknown to the convertor - return $value unless exists CONVERSIONS()->{$mpath_s}; - - my ($conversion, @args) = @{CONVERSIONS()->{$mpath_s}}; - return $self->$conversion($value, @args); -} - -# _unprepare_value($$) [PROTECTED] -# -# Usage : -# Purpose : -# Arguments : -# Returns : -# Throws : Dies, if not invoked on object -# Comments : -# See Also : - -sub _unprepare_value($$) -{ - my $self = shift; - confess "Instance method not invoked on object instance" unless blessed($self); - my ($mpath, $value) = @_; - - my $mpath_s = $mpath; $mpath_s =~ s/\[\d*\]//g; - - # Handle the MPath unknown to the convertor - return $value unless exists CONVERSIONS()->{$mpath_s}; - return $value->to_string() if blessed($value); - return $value; -} - -# _objectify() [PROTECTED] -# -# Usage : -# Purpose : -# Arguments : -# Returns : -# Throws : Dies, if not invoked on object -# Comments : -# See Also : - -sub _objectify() -{ - my $self = shift; - confess "Instance method not invoked on object instance" unless blessed($self); - - my $value; - my ($mpath, $node) = $self->iterate(undef,1); - do { - $value = $self->_prepare_value($mpath, $$node); - $$node = $value; - ($mpath, $node) = $self->iterate(undef,1); - } while $mpath; -} - -# _deobjectify() [PROTECTED] -# -# Usage : -# Purpose : -# Arguments : -# Returns : -# Throws : Dies, if not invoked on object -# Comments : -# See Also : - -sub _deobjectify() -{ - my $self = shift; - confess "Instance method not invoked on object instance" unless blessed($self); - - my $value; - my ($mpath, $node) = $self->iterate(undef,1); - do { - $value = $self->_unprepare_value($mpath, $$node); - $$node = $value; - ($mpath, $node) = $self->iterate(undef,1); - } while $mpath; -} - -# _convert_address($$) [PROTECTED] -# -# Usage : -# Purpose : -# Arguments : -# Returns : -# Throws : Dies, if not invoked on object -# Comments : -# See Also : - -sub _convert_address($$) -{ - my $self = shift; - confess "Instance method not invoked on object instance" unless blessed($self); - my ($value, $type) = @_; - - if (ref $value eq 'ARRAY') { - my $r = []; - foreach my $v (@$value) { - push(@$r, Value::IP->new($value)); - } - return $r; - } - else { - #return Value::IP->new($value, $type) if $type; - return Value::IP->new($value); - } -} - -# _convert_timestamp($) [PROTECTED] -# -# Usage : -# Purpose : -# Arguments : -# Returns : -# Throws : Dies, if not invoked on object -# Comments : -# See Also : - -sub _convert_timestamp($) -{ - my $self = shift; - confess "Instance method not invoked on object instance" unless blessed($self); - my ($value,) = @_; - - return Value::Timestamp->new($value); -} - -# _convert_int($) [PROTECTED] -# -# Usage : -# Purpose : -# Arguments : -# Returns : -# Throws : Dies, if not invoked on object -# Comments : -# See Also : - -sub _convert_int($) -{ - my $self = shift; - confess "Instance method not invoked on object instance" unless blessed($self); - my ($value,) = @_; - - if (ref $value eq 'ARRAY') { - my $r = []; - foreach my $v (@$value) { - push(@$r, int($value)); - } - return $r; - } - else { - return int($value); - } -} - -=pod - -=back - -=cut - -1; diff --git a/lib_perl/lib/Mentat/Message/Validator.pm b/lib_perl/lib/Mentat/Message/Validator.pm deleted file mode 100644 index 7d3026dd4081ede1c29f64a164af14d067953e74..0000000000000000000000000000000000000000 --- a/lib_perl/lib/Mentat/Message/Validator.pm +++ /dev/null @@ -1,170 +0,0 @@ -package Mentat::Message::Validator; -use strict; -use warnings; - -#******************************************************************************* -# DOCUMENTATION SECTION -#******************************************************************************* - -=head1 NAME - -Mentat::Message::Validator - Base class for all Mentat message validators - -=head1 SYNOPSIS - - use Mentat::Message::Validator; - -=head1 DESCRIPTION - - - -=head1 AUTHOR - - Jan Mach - Cesnet, z.s.p.o - jan.mach@cesnet.cz - http://www.cesnet.cz - -=head1 COPYRIGHT - -This program is free software; you can redistribute -it and/or modify it under the same terms as Perl itself. - -The full text of the license can be found in the -LICENSE file included with this module. - - -=head1 SEE ALSO - -perl(1). - -=head1 FUNCTION REFERENCE - -=over 4 - -=cut - -#******************************************************************************* -# INITIALIZATION AND CLEANUP SECTION -#******************************************************************************* - -#-- Perl core modules ---------------------------------------------------------# -use Carp; -use Scalar::Util 'blessed'; - -#use Smart::Comments; #-+-> DEVEL ONLY <-+-# -#use Data::Dumper; #-+-> DEVEL ONLY <-+-# - -#-- Perl CPAN modules ---------------------------------------------------------# - -#-- Custom application modules ------------------------------------------------# - -#-- Module initializations ----------------------------------------------------# -BEGIN { - use vars qw($VERSION $DEVEL); - $VERSION = '0.1'; - $DEVEL = 0; -} - - -#-- Module clean-up code (global destructor) ----------------------------------# -END { - -} - -#******************************************************************************* -# CONSTANTS AND GLOBAL VARIABLES DEFINITION SECTION -#******************************************************************************* - -#-- Constants -----------------------------------------------------------------# - -#-- Static public class variables (our) ---------------------------------------# - -#-- Static protected class variables (my) -------------------------------------# - -#******************************************************************************* -# IMPLEMENTATION SECTION -#******************************************************************************* - -=item new() [PUBLIC,STATIC] - - Usage : my $validator = Mentat::Message::Validator->new(...); - Purpose : Create and return reference to the new instance - Arguments : Same as _init() method - Returns : Mentat::Message::Validator reference - Throws : Croaks, if invoked on object - Comments : Internally uses _init() method - See Also : _init() method - -=cut - -sub new -{ - my $class = shift; - croak ((caller(0))[3] . ": class method invoked on object") if ref $class; - my $self = bless ({}, $class); - $self->_init(@_); - return $self; -} - -=item validate_s($) [PUBLIC, ABSTRACT] - - Usage : my $error_string = $validator->validate_s($mentat_message); - Purpose : Validate the given Mentat message - Arguments : Mentat::Message $mentat_message - Mentat message object reference - Returns : STRING $error - string describing error on validation FAILURE - STRING '' (empty string) on validation SUCCESS - Throws : Croaks, if invoked on class - -=cut - -sub validate_s($) -{ - my $self = shift; - croak ((caller(0))[3] . ": method needs implementation"); -} - -=item validate_b($) [PUBLIC, ABSTRACT] - - Usage : my $error_flag = $validator->validate_b($mentat_message); - Purpose : Validate the given Mentat message - Arguments : Mentat::Message $mentat_message - Mentat message object reference - Returns : INTEGER 1 on validation FAILURE - INTEGER 0 in validation SUCCESS - Throws : Croaks, if invoked on class - -=cut - -sub validate_b($) -{ - my $self = shift; - croak ((caller(0))[3] . ": method needs implementation"); -} - -#------------------------------------------------------------------------------- -# Private interface -#------------------------------------------------------------------------------- - -# _init [PROTECTED, ABSTRACT] -# -# Usage : In constructor: return $self->_init(@_); -# Purpose : Initialization callback for subclassess -# Arguments : Unknown -# Returns : Mentat::Message::Validator reference -# Throws : -# Comments : -# See Also : - -sub _init -{ - my $self = shift; - croak ((caller(0))[3] . ": class method needs implementation"); -} - -=pod - -=back - -=cut - -1; diff --git a/lib_perl/lib/Mentat/Message/Validator/IDEA.pm b/lib_perl/lib/Mentat/Message/Validator/IDEA.pm deleted file mode 100644 index 5035b1b33fd220865fe9e309595898ae33d60453..0000000000000000000000000000000000000000 --- a/lib_perl/lib/Mentat/Message/Validator/IDEA.pm +++ /dev/null @@ -1,171 +0,0 @@ -package Mentat::Message::Validator::IDEA; -use strict; -use warnings; - -#******************************************************************************* -# DOCUMENTATION SECTION -#******************************************************************************* - -=head1 NAME - -Mentat::Message::Validator::IDEA - JSON Schema based Mentat::Message::IDEA validator - -=head1 SYNOPSIS - - use Mentat::Message::Validator::IDEA; - -=head1 DESCRIPTION - - - -=head1 AUTHOR - - Jan Mach - Cesnet, z.s.p.o - jan.mach@cesnet.cz - http://www.cesnet.cz - -=head1 COPYRIGHT - -This program is free software; you can redistribute -it and/or modify it under the same terms as Perl itself. - -The full text of the license can be found in the -LICENSE file included with this module. - - -=head1 SEE ALSO - -perl(1), Mentat::Message::Validator(3), JSON::Schema::Validator(3). - -=head1 FUNCTION REFERENCE - -=over 4 - -=cut - -#******************************************************************************* -# INITIALIZATION AND CLEANUP SECTION -#******************************************************************************* - -#-- Perl core modules ---------------------------------------------------------# -use Carp; -use Scalar::Util 'blessed'; - -#use Data::Dumper; #-+-> DEVEL ONLY <-+-# -#use Smart::Comments; #-+-> DEVEL ONLY <-+-# - -#-- Perl CPAN modules ---------------------------------------------------------# -use JSON; - -#-- Custom application modules ------------------------------------------------# -use Mentat::Message::Validator; -use JSON::Schema::Validator; - -#-- Module initializations ----------------------------------------------------# -BEGIN { - use vars qw($VERSION $DEVEL @ISA); - $VERSION = '0.1'; - $DEVEL = 0; - @ISA = ('Mentat::Message::Validator'); -} - - -#-- Module clean-up code (global destructor) ----------------------------------# -END { - -} - -#******************************************************************************* -# CONSTANTS AND GLOBAL VARIABLES DEFINITION SECTION -#******************************************************************************* - -#-- Constants -----------------------------------------------------------------# - -#-- Static public class variables (our) ---------------------------------------# - -#-- Static protected class variables (my) -------------------------------------# - -#******************************************************************************* -# IMPLEMENTATION SECTION -#******************************************************************************* - -=item validate_s($) [PUBLIC] - - Usage : my $error_string = $validator->validate_s($mentat_message); - Purpose : Validate the given Mentat message - Arguments : Mentat::Message $mentat_message - Mentat message object reference - Returns : STRING $error - string describing error on validation FAILURE - STRING '' (empty string) on validation SUCCESS - Throws : Dies, if invoked on class - -=cut - -sub validate_s($) -{ - my $self = shift; - confess "Instance method not invoked on object instance" unless blessed($self); - my ($message,) = @_; - confess "Message must be a 'Mentat::Message::IDEA' instance" unless blessed($message) and $message->isa('Mentat::Message::IDEA'); - - # Validate given message structure - my $error = $self->{VALIDATOR}->validate($message->hash()); - return $error if $error; - - return ""; -} - -=item validate_b($) [PUBLIC] - - Usage : my $error_flag = $validator->validate_b($mentat_message); - Purpose : Validate the given Mentat message - Arguments : Mentat::Message $mentat_message - Mentat message object reference - Returns : INTEGER 1 on validation FAILURE - INTEGER 0 in validation SUCCESS - Throws : Dies, if invoked on class - -=cut - -sub validate_b($) -{ - my $self = shift; - confess "Instance method not invoked on object instance" unless blessed($self); - - my $error = $self->validate_s(@_); - return 1 if $error; - return 0; -} - -#------------------------------------------------------------------------------- -# Private interface -#------------------------------------------------------------------------------- - -# _init($) [PROTECTED, ABSTRACT] -# -# Usage : In constructor: return $self->_init(@_); -# Purpose : Initialization callback for subclassess -# Arguments : string $schema_file -# Returns : Mentat::Message::Validator reference -# Throws : -# Comments : -# See Also : - -sub _init($) -{ - my $self = shift; - confess "Instance method not invoked on object instance" unless blessed($self); - my ($schema_file,) = @_; - confess "JSON schema file must be given as argument" unless $schema_file; - - $self->{VALIDATOR} = JSON::Schema::Validator->new($schema_file); - - return $self; -} - -=pod - -=back - -=cut - -1; diff --git a/lib_perl/lib/Mentat/Message/Value.pm b/lib_perl/lib/Mentat/Message/Value.pm deleted file mode 100644 index e3d1e868e211d23eea90e460e11b8086ec51ba61..0000000000000000000000000000000000000000 --- a/lib_perl/lib/Mentat/Message/Value.pm +++ /dev/null @@ -1,168 +0,0 @@ -package Mentat::Message::Value; -use strict; -use warnings; - -#******************************************************************************* -# DOCUMENTATION SECTION -#******************************************************************************* - -=head1 NAME - -Mentat::Message::Value - Utility class for determining datatypes of Mentat message values - -=head1 SYNOPSIS - - use Mentat::Message::Value; - -=head1 DESCRIPTION - -=head1 AUTHOR - - Jan Mach - Cesnet, z.s.p.o - jan.mach@cesnet.cz - http://www.cesnet.cz - -=head1 COPYRIGHT - -This program is free software; you can redistribute -it and/or modify it under the same terms as Perl itself. - -The full text of the license can be found in the -LICENSE file included with this module. - - -=head1 SEE ALSO - -perl(1). - -=head1 FUNCTION REFERENCE - -=over 4 - -=cut - -#******************************************************************************* -# LIBRARY LOADING SECTION -#******************************************************************************* - -#-- Perl core modules ---------------------------------------------------------# -use Carp; - -#use Data::Dumper; #-+-> DEVEL ONLY <-+-# - -#-- Perl CPAN modules ---------------------------------------------------------# - -#-- Custom application modules ------------------------------------------------# - -#******************************************************************************* -# CONSTANTS AND GLOBAL VARIABLES DEFINITION SECTION -#******************************************************************************* - -#-- Constants -----------------------------------------------------------------# - -# !!!! WARNING !!! Some of these datatypes are hardcoded in filter grammar !!!! -# LOW level datatypes -use constant DATATYPE_UNKNOWN => 'UNKNOWN'; -use constant DATATYPE_DEPENDENT => 'DEPENDENT'; -use constant DATATYPE_BOOL => 'BOOL'; -use constant DATATYPE_BYTE => 'BYTE'; -use constant DATATYPE_DATETIME => 'DATETIME'; -use constant DATATYPE_ENUM => 'STRING'; -use constant DATATYPE_INT => 'INT'; -use constant DATATYPE_NTPSTAMP => 'NTPSTAMP'; -use constant DATATYPE_PORTLIST => 'PORTLIST'; -use constant DATATYPE_REAL => 'REAL'; -use constant DATATYPE_STRING => 'STRING'; - -# HIGH level datatypes -use constant DATATYPE_PERIOD => 'PERIOD'; -use constant DATATYPE_NUMERIC => 'NUMERIC'; -use constant DATATYPE_ADDRESS => 'ADDRESS'; -use constant DATATYPE_IPV4 => 'IPV4'; -use constant DATATYPE_IPV6 => 'IPV6'; -use constant DATATYPE_MAC => 'MAC'; -use constant DATATYPE_EMAIL => 'EMAIL'; - -use constant DATATYPE_IPV4_STR => 'IPV4-ADDR'; -use constant DATATYPE_IPV4_HEX => 'IPV4-ADDR-HEX'; -use constant DATATYPE_IPV4_STR_NET => 'IPV4-NET'; -use constant DATATYPE_IPV4_STR_NET_MASK => 'IPV4-NET-MASK'; -use constant DATATYPE_IPV6_STR => 'IPV6-ADDR'; -use constant DATATYPE_IPV6_HEX => 'IPV6-ADDR-HEX'; -use constant DATATYPE_IPV6_STR_NET => 'IPV6-NET'; -use constant DATATYPE_IPV6_STR_NET_MASK => 'IPV6-NET-MASK'; - -#-- Static public class variables (our) ---------------------------------------# - -#-- Static protected class variables (my) -------------------------------------# - -my %MESSAGETYPES2CLASS = ( - 'idea' => 'Mentat::Message::Value::IDEA', - ); - -#******************************************************************************* -# INITIALIZATION AND CLEANUP SECTION -#******************************************************************************* - -#-- Module initializations ----------------------------------------------------# -BEGIN { - use vars qw($VERSION $DEVEL); - $VERSION = '0.1'; - $DEVEL = 0; -} - - -#-- Module clean-up code (global destructor) ----------------------------------# -END { - -} - -#******************************************************************************* -# IMPLEMENTATION SECTION -#******************************************************************************* - -=item path_datatype($) [PUBLIC,STATIC] - - Usage : my $datatype = Mentat::Message::Value->path_datatype($mpath) - Purpose : Determine the data type of the given MPath node - Arguments : STRING containing MPath - Returns : - Throws : Croaks, if invoked on object - Comments : - See Also : - -=cut - -sub path_datatype($) -{ - my $class = shift; - croak ((caller(0))[3] . ": method needs implementation"); -} - -=item value_datatype($$) [PUBLIC,STATIC] - - Usage : my $datatype = Mentat::Message::Value->value_datatype($mpath) - Purpose : Determine the data type of the value on given MPath node in given IDEA message - Arguments : STRING containing MPath - Mentat::Message::IDEA reference - Returns : - Throws : Croaks, if invoked on object - Comments : - See Also : - -=cut - -sub value_datatype($$) -{ - my $class = shift; - croak ((caller(0))[3] . ": method needs implementation"); -} - -=pod - -=back - -=cut - -1; diff --git a/lib_perl/lib/Mentat/Message/Value/IDEA.pm b/lib_perl/lib/Mentat/Message/Value/IDEA.pm deleted file mode 100644 index acd4a237e3a02f1c84543339ed067bf564dc1eda..0000000000000000000000000000000000000000 --- a/lib_perl/lib/Mentat/Message/Value/IDEA.pm +++ /dev/null @@ -1,167 +0,0 @@ -package Mentat::Message::Value::IDEA; -use strict; -use warnings; - -#******************************************************************************* -# DOCUMENTATION SECTION -#******************************************************************************* - -=head1 NAME - -Mentat::Message::Value::IDEA - Utility class for determining datatypes of Mentat message values - -=head1 SYNOPSIS - - use Mentat::Message::Value::IDEA; - -=head1 DESCRIPTION - - - -=head1 AUTHOR - - Jan Mach - Cesnet, z.s.p.o - jan.mach@cesnet.cz - http://www.cesnet.cz - -=head1 COPYRIGHT - -This program is free software; you can redistribute -it and/or modify it under the same terms as Perl itself. - -The full text of the license can be found in the -LICENSE file included with this module. - - -=head1 SEE ALSO - -perl(1). - -=head1 FUNCTION REFERENCE - -=over 4 - -=cut - -#******************************************************************************* -# LIBRARY LOADING SECTION -#******************************************************************************* - -#-- Perl core modules ---------------------------------------------------------# -use Carp; -use Scalar::Util 'blessed'; - -use Data::Dumper; #-+-> DEVEL ONLY <-+-# -#use Smart::Comments; #-+-> DEVEL ONLY <-+-# - -#-- Perl CPAN modules ---------------------------------------------------------# - -#-- Custom application modules ------------------------------------------------# -use Data::Path::Value; -use Data::Core qw(:c_dtypes); - -#******************************************************************************* -# CONSTANTS AND GLOBAL VARIABLES DEFINITION SECTION -#******************************************************************************* - -#-- Constants -----------------------------------------------------------------# - -#-- Static public class variables (our) ---------------------------------------# - -#-- Static protected class variables (my) -------------------------------------# - -# Table containing datatypes of IDEA elements on given paths -my %MPATH2DATATYPE = ( - 'CreateTime' => DT_DATETIME, - 'DetectTime' => DT_DATETIME, - 'EventTime' => DT_DATETIME, - 'CeaseTime' => DT_DATETIME, - 'WinStartTime' => DT_DATETIME, - 'WinEndTime' => DT_DATETIME, - - 'Source/IP4' => DT_IPV4, - 'Source/IP6' => DT_IPV6, - 'Target/IP4' => DT_IPV4, - 'Target/IP6' => DT_IPV6, - - 'Source/Port' => DT_INT, - 'Target/Port' => DT_INT, - 'ConnCount' => DT_INT, - 'FlowCount' => DT_INT, - 'PacketCount' => DT_INT, - 'ByteCount' => DT_INT, -); - -#******************************************************************************* -# INITIALIZATION AND CLEANUP SECTION -#******************************************************************************* - -#-- Module initializations ----------------------------------------------------# -BEGIN { - use vars qw($VERSION $DEVEL @ISA); - $VERSION = '0.1'; - $DEVEL = 0; - @ISA = ('Data::Path::Value'); -} - - -#-- Module clean-up code (global destructor) ----------------------------------# -END { - -} - -#******************************************************************************* -# IMPLEMENTATION SECTION -#******************************************************************************* - -=item path_datatype($) [PUBLIC,STATIC] - - Usage : my $datatype = Mentat::Message::Value->path_datatype($mpath) - Purpose : Determine the data type of the given MPath node - Arguments : STRING containing MPath - Returns : - Throws : Croaks, if invoked on object - -=cut - -sub path_datatype($) -{ - my $self = shift; - confess "Instance method not invoked on object instance" unless blessed($self); - my ($mpath,) = @_; - confess "MPath must be given as argument" unless $mpath; - - return DT_STRING unless exists $MPATH2DATATYPE{$mpath}; - return $MPATH2DATATYPE{$mpath}; -} - -=item value_datatype($$) [PUBLIC,STATIC] - - Usage : my $datatype = Mentat::Message::Value->value_datatype($mpath) - Purpose : Determine the data type of the value on given MPath node in given IDEA message - Arguments : STRING containing MPath - Mentat::Message::IDEA reference - Returns : - Throws : Croaks, if invoked on object - -=cut - -sub value_datatype($$) -{ - my $self = shift; - confess "Instance method not invoked on object instance" unless blessed($self); - my ($mpath, $mentat_message) = @_; - confess "MPath must be given as argument" unless $mpath; - - return DT_STRING unless exists $MPATH2DATATYPE{$mpath}; - return $MPATH2DATATYPE{$mpath}; -} - -=pod - -=back - -=cut - -1; diff --git a/lib_perl/lib/Value/Convertor.pm b/lib_perl/lib/Value/Convertor.pm deleted file mode 100644 index 8dcd8407d67b6b4b48d489bd4c5b18187cdea916..0000000000000000000000000000000000000000 --- a/lib_perl/lib/Value/Convertor.pm +++ /dev/null @@ -1,2757 +0,0 @@ -package Value::Convertor; -use strict; -use warnings; - -#******************************************************************************* -# DOCUMENTATION SECTION -#******************************************************************************* - -=head1 NAME - -Value::Convertor - Short module description - -=head1 SYNOPSIS - - use Value::Convertor; - -=head1 DESCRIPTION - -This is the library class for various conversion functions. All conversions can -be called either as class, or instance methods. - -=head1 AUTHOR - - Jan Mach - Cesnet, z.s.p.o - jan.mach@cesnet.cz - http://www.cesnet.cz - -=head1 COPYRIGHT - -This program is free software; you can redistribute -it and/or modify it under the same terms as Perl itself. - -The full text of the license can be found in the -LICENSE file included with this module. - -=head1 SEE ALSO - -perl(1). - -=head1 FUNCTION REFERENCE - -=over 4 - -=cut - -#******************************************************************************* -# LIBRARY LOADING SECTION -#******************************************************************************* - -#-- Perl core modules ---------------------------------------------------------# -use Carp; -use Scalar::Util 'blessed'; - -use Data::Dumper; #-+-> DEVEL ONLY <-+-# -use Net::CIDR::Lite; # libnet-cidr-lite-perl -use Net::IP; # libnet-ip-perl -#use Smart::Comments; #-+-> DEVEL ONLY <-+-# - -#-- Perl CPAN modules ---------------------------------------------------------# -use Date::Parse; -use DateTime; -use DateTime::TimeZone; - -#-- Custom application modules ------------------------------------------------# - -#******************************************************************************* -# CONSTANTS AND GLOBAL VARIABLES DEFINITION SECTION -#******************************************************************************* - -#-- Constants -----------------------------------------------------------------# - -# Number of seconds between 1.1.1900 and 1.1.1970 (for NTP to unix timestamp conversions) -use constant NTP_TO_EPOCH_DELTA => 2208988800; -use constant MAX_IP_MASK => hex('0xFFFFFFFF'); - -use constant UNKNOWN_TYPE => 'UNKONWN'; - -use constant IPV4ADDR_STRING => 'IPV4ADDR_STRING'; -use constant IPV4ADDR_HEXSTR => 'IPV4ADDR_HEXSTR'; -use constant IPV4ADDR_INTEGER => 'IPV4ADDR_INTEGER'; - -use constant IPV6ADDR_STRING => 'IPV6ADDR_STRING'; -use constant IPV6ADDR_HEXSTR => 'IPV6ADDR_HEXSTR'; -use constant IPV6ADDR_INTEGER => 'IPV6ADDR_INTEGER'; - -use constant IPV4CIDR_STRING => 'IPV4CIDR_STRING'; -use constant IPV4NETM_STRING => 'IPV4NETM_STRING'; -use constant IPV6CIDR_STRING => 'IPV6CIDR_STRING'; - -use constant IPV4RNG_STRING => 'IPV4RNG_STRING'; -use constant IPV4RNG_HEXSTR => 'IPV4RNG_HEXSTR'; -use constant IPV4RNG_INTEGER => 'IPV4RNG_INTEGER'; - -use constant IPV6RNG_STRING => 'IPV6RNG_STRING'; -use constant IPV6RNG_HEXSTR => 'IPV6RNG_HEXSTR'; -use constant IPV6RNG_INTEGER => 'IPV6RNG_INTEGER'; - -use constant TS_UNIXSTAMP => 'TS_UNIXSTAMP'; -use constant TS_NTPSTAMP => 'TS_NTPSTAMP'; -use constant TS_DATETIME => 'TS_DATETIME'; -use constant TS_PERIOD => 'TS_PERIOD'; - -use constant IP_CONVERSIONS => { - IPV4ADDR_STRING() => - {'INT' => 'ipv4str_to_int', 'BIN' => 'ipv4str_to_bin'}, - IPV4ADDR_HEXSTR() => - {'INT' => 'ipv4hex_to_int', 'BIN' => 'ipv4hex_to_bin'}, - IPV4ADDR_INTEGER() => - {'INT' => 'anything_to_samething', 'BIN' => 'ipv4int_to_bin'}, - IPV4CIDR_STRING() => - {'INT' => 'ipv4cidr_to_ints', 'BIN' => 'ipv4cidr_to_bins'}, - IPV4NETM_STRING() => - {'INT' => 'ipv4netm_to_ints', 'BIN' => 'ipv4netm_to_bins'}, - IPV4RNG_STRING() => - {'INT' => 'ipv4rngstr_to_ints', 'BIN' => 'ipv4rngstr_to_bins'}, - IPV4RNG_HEXSTR() => - {}, - IPV4RNG_INTEGER() => - {}, - - IPV6ADDR_STRING() => - {'INT' => 'ipv6str_to_bigint', 'BIN' => 'ipv6str_to_bin'}, - IPV6ADDR_HEXSTR() => - {'INT' => 'hexstr_to_bigint', 'BIN' => 'hexstr_to_bin'}, - IPV6ADDR_INTEGER() => - {'INT' => 'anything_to_samething', 'BIN' => 'bigint_to_bin'}, - IPV6CIDR_STRING() => - {'INT' => 'ipv6cidr_to_bigints', 'BIN' => 'ipv6cidr_to_bins'}, - IPV6RNG_STRING() => - {}, - IPV6RNG_HEXSTR() => - {}, - IPV6RNG_INTEGER() => - {}, - }; - -use constant TS_CONVERSIONS => { - TS_UNIXSTAMP() => 'unixs_to_nbi', - TS_NTPSTAMP() => 'ntps_to_nbi', - TS_DATETIME() => 'datestr_to_nbi', - TS_PERIOD() => 'periodstr_to_nbis', - }; - -#-- Static public class variables (our) ---------------------------------------# - -#-- Static protected class variables (my) -------------------------------------# - -#******************************************************************************* -# INITIALIZATION AND CLEANUP SECTION -#******************************************************************************* - -#-- Module initializations ----------------------------------------------------# -BEGIN { - use vars qw($VERSION $DEVEL $TIME_ZONE_OFFSET $TIME_ZONE $QR_IPV4 $QR_IPV6 $QR_TS %IP_QRS %TS_QRS); - $VERSION = '0.1'; - $DEVEL = 0; - - # Calculate the timezone offset for local timezone - $TIME_ZONE = DateTime::TimeZone->new(name => 'local'); - $TIME_ZONE_OFFSET = DateTime->now(time_zone => $TIME_ZONE)->offset(); - - $QR_IPV4 = [ - [IPV4ADDR_STRING(), qr/^([\d]+\.[\d]+\.[\d]+\.[\d]+)$/], - [IPV4ADDR_HEXSTR(), qr/^(?:0x)?([a-zA-Z0-9]{8})$/], - [IPV4ADDR_INTEGER(), qr/^(0|[1-9][0-9]{0,10})$/], - [IPV4CIDR_STRING(), qr/^([\d]+\.[\d]+\.[\d]+\.[\d]+)\/([\d]+)$/], - [IPV4NETM_STRING(), qr/^([\d]+\.[\d]+\.[\d]+\.[\d]+)\/([\d]+\.[\d]+\.[\d]+\.[\d]+)$/], - [IPV4RNG_STRING(), qr/^([\d]+\.[\d]+\.[\d]+\.[\d]+) ?(?:-|\.\.) ?([\d]+\.[\d]+\.[\d]+\.[\d]+)$/], - [IPV4RNG_HEXSTR(), qr/^(?:0x)?([a-zA-Z0-9]{8}) ?(?:-|\.\.) ?(?:0x)?([a-zA-Z0-9]{8})$/], - [IPV4RNG_INTEGER(), qr/^([0-9]{1,10}) ?(?:-|\.\.) ?([0-9]{1,10})$/], - ]; - - $QR_IPV6 = [ - [IPV6ADDR_STRING(), qr/^([:a-zA-Z0-9]+:[:a-zA-Z0-9]*)$/], - [IPV6ADDR_HEXSTR(), qr/^(?:0x)?([a-zA-Z0-9]{32})$/], - [IPV6ADDR_INTEGER(), qr/^(0|[1-9][0-9]*)$/], - [IPV6CIDR_STRING(), qr/^([:a-zA-Z0-9]+:[:a-zA-Z0-9]+)\/([\d]+)$/], - [IPV6RNG_STRING(), qr/^([:a-zA-Z0-9]+:[:a-zA-Z0-9]+) ?(?:-|\.\.) ?([:a-zA-Z0-9]+:[:a-zA-Z0-9]+)$/], - [IPV6RNG_HEXSTR(), qr/^(?:0x)?([a-zA-Z0-9]{32}) ?(?:-|\.\.) ?(?:0x)?([a-zA-Z0-9]{32})$/], - [IPV6RNG_INTEGER(), qr/^([0-9]+) ?(?:-|\.\.) ?([0-9]+)$/], - ]; - - $QR_TS = [ - [TS_NTPSTAMP(), qr/^(0x[a-zA-Z0-9]+\.0x[a-zA-Z0-9]+)$/], - [TS_UNIXSTAMP(), qr/^([0-9]+(?:\.[0-9]+)?)$/], - [TS_DATETIME(), qr/^(\d{4}-\d{2}-\d{2}(?:T| )\d{2}:\d{2}(?::\d{2})?(?:\.\d+)?(?:Z|\+\d{2}:?\d{2}|-\d{2}:?\d{2})?)$/], - [TS_PERIOD(), qr/^(\d{4}-\d{2}-\d{2}(?:T| )\d{2}:\d{2}(?::\d{2})?(?:Z|\+\d{2}:?\d{2}|-\d{2}:?\d{2})?) ?(?:-|\.\.) ?(\d{4}-\d{2}-\d{2}(?:T| )\d{2}:\d{2}(?::\d{2})?(?:Z|\+\d{2}:?\d{2}|-\d{2}:?\d{2})?)$/], - ]; - - map { $IP_QRS{$_->[0]} = $_->[1] } (@$QR_IPV4, @$QR_IPV6); - map { $TS_QRS{$_->[0]} = $_->[1] } @$QR_TS; -} - - -#-- Module clean-up code (global destructor) ----------------------------------# -END { - -} - -#******************************************************************************* -# IMPLEMENTATION SECTION -#******************************************************************************* - -=item new() [PUBLIC,STATIC] - - Usage : my $instance = Value::Convertor->new() - Purpose : Create and return reference to the new instance - Arguments : Same as the the _init() method - Returns : Value::Convertor reference on success, croaks on failure - Throws : Dies, if invoked on object - Comments : Internally uses _init() method, subclasses should never overload this method. - See Also : _init() method - -=cut - -sub new -{ - my $class = shift; - confess "Class method not invoked on class" if blessed($class); - my $self = bless ({}, $class); - return $self->_init(@_); -} - -#------------------------------------------------------------------------------- -# General conversion methods -#------------------------------------------------------------------------------- - -=item anything_to_samething($) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->anything_to_samething($value); - my $result = $convertor->anything_to_samething($value); - Purpose : Converts anything to same thing (dummy conversion) - Arguments : MIXED $anything - Value to be converted [MANDATORY] - Returns : MIXED $anything - Throws : Dies, if not given any conversion argument - -=cut - -sub anything_to_samething($) -{ - my $invocant = shift; - my ($anything,) = @_; - confess "Expected conversion argument not given" unless defined $anything; - - return $anything; -} - -=item anything_to_int($) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->anything_to_int($value); - my $result = $convertor->anything_to_int($value); - Purpose : Converts anything to integer - Arguments : MIXED $anything - Value to be converted [MANDATORY] - Returns : INTEGER $anything - Throws : Dies, if not given any conversion argument - -=cut - -sub anything_to_int($) -{ - my $invocant = shift; - my ($anything,) = @_; - confess "Expected conversion argument not given" unless defined $anything; - - return int($anything); -} - -=item anything_to_string($) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->anything_to_string($value); - my $result = $convertor->anything_to_string($value); - Purpose : Converts anything to string - Arguments : MIXED $anything - Value to be converted [MANDATORY] - Returns : STRING $anything - Throws : Dies, if not given any conversion argument - -=cut - -sub anything_to_string($) -{ - my $invocant = shift; - my ($anything,) = @_; - confess "Expected conversion argument not given" unless defined $anything; - - return "$anything"; -} - -#------------------------------------------------------------------------------- - -=item hexstr_to_binstr($;$) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->hexstr_to_binstr($value, $width); - my $result = $convertor->hexstr_to_binstr($value, $width); - Purpose : Converts 'hexadecimal string' to 'binary string' - Arguments : STRING $hex - Value to be converted [MANDATORY] - INTEGER $width - Width of the string, pad zeros from left [OPTIONAL, DEFAULT = 0] - Returns : STRING $bin - Throws : Dies, if not given any conversion argument - -=cut - -sub hexstr_to_binstr($;$) -{ - my $invocant = shift; - my ($hexstr, $width) = @_; - confess "Expected conversion argument not given" unless defined $hexstr; - - # Strip out the leading '0x', if present - $hexstr =~ s/^0x//; - - my $binstr = unpack("B*", pack("H*", $invocant->_zero_pad_n($hexstr,2))); - $binstr = $invocant->_zero_pad($binstr, $width) if $width; - - return $binstr; -} - -=item binstr_to_hexstr($;$$) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->binstr_to_hexstr($value, $width, $prefix); - my $result = $convertor->binstr_to_hexstr($value, $width, $prefix); - Purpose : Converts 'hexadecimal string' to 'binary string' - Arguments : STRING $binstr - Value to be converted [MANDATORY] - INTEGER $width - Width of the string, pad zeros from left [OPTIONAL, DEFAULT = 0] - BOOL $prefix - Prepend the '0x' prefix to the result? [OPTIONAL, DEFAULT = 0] - Returns : STRING $hexstr - Throws : Dies, if not given any conversion argument - -=cut - -sub binstr_to_hexstr($;$$) -{ - my $invocant = shift; - my ($binstr, $width, $prefix) = @_; - confess "Expected conversion argument not given" unless defined $binstr; - - my $hexstr = unpack("H*", pack("B*", $invocant->_zero_pad_n($binstr,8))); - $hexstr = $invocant->_zero_pad($hexstr, $width) if $width; - - return (($prefix)?'0x':'') . uc($hexstr); -} - -#------------------------------------------------------------------------------- - -=item hexstr_to_bigint($) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->hexstr_to_bigint($value); - my $result = $convertor->hexstr_to_bigint($value); - Purpose : Converts 'hexadecimal string' to 'big integer' - Arguments : STRING $hexstr - Value to be converted [MANDATORY] - Returns : BIGINT $bigint - Throws : Dies, if not given any conversion argument - -=cut - -sub hexstr_to_bigint($) -{ - my $invocant = shift; - my ($hexstr,) = @_; - confess "Expected conversion argument not given" unless defined $hexstr; - - # Strip out the leading '0x', if present - $hexstr =~ s/^0x//; - - use bigint; - my $bigint = hex("0x$hexstr"); - - return $bigint; -} - -=item bigint_to_hexstr($;$$) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->bigint_to_hexstr($value, $width, $prefix); - my $result = $convertor->bigint_to_hexstr($value, $width,$prefix); - Purpose : Converts 'big integer' to 'hexadecimal string' - Arguments : BIGINT $bigint - Value to be converted [MANDATORY] - INTEGER $width - Width of the string, pad zeros from left [OPTIONAL, DEFAULT = 0] - BOOL $prefix - Prepend the '0x' prefix to the result? [OPTIONAL, DEFAULT = 0] - Returns : STRING $hexstr - Throws : Dies, if not given any conversion argument - -=cut - -sub bigint_to_hexstr($;$$) -{ - my $invocant = shift; - my ($bigint, $width, $prefix) = @_; - confess "Expected conversion argument not given" unless defined $bigint; - - use bigint; - my $hexstr = $bigint->as_hex(); - $hexstr =~ s/^0x//; - $hexstr = $invocant->_zero_pad($hexstr, $width) if $width; - - return (($prefix)?'0x':'') . uc($hexstr); -} - -#------------------------------------------------------------------------------- - -=item hexstr_to_bin($) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->hexstr_to_bin($value); - my $result = $convertor->hexstr_to_bin($value); - Purpose : Converts 'hexadecimal string' to 'binary' - Arguments : STRING $hexstr - Value to be converted [MANDATORY] - Returns : BINARY $data - Throws : Dies, if not given any conversion argument - -=cut - -sub hexstr_to_bin($) -{ - my $invocant = shift; - my ($hexstr,) = @_; - confess "Expected conversion argument not given" unless defined $hexstr; - - # Strip out the leading '0x', if present - $hexstr =~ s/^0x//; - - return pack("H*", $invocant->_zero_pad_n($hexstr,2)); -} - -=item bin_to_hexstr($;$$) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->bin_to_hexstr($value, $width, $prefix); - my $result = $convertor->bin_to_hexstr($value, $width, $prefix); - Purpose : Converts 'binary' to 'hexadecimal string' - Arguments : BINARY $data - Value to be converted [MANDATORY] - INTEGER $width - Width of the string, pad zeros from left [OPTIONAL, DEFAULT = 0] - BOOL $prefix - Prepend the '0x' prefix to the result? [OPTIONAL, DEFAULT = 0] - Returns : STRING $hexstr - Throws : Dies, if not given any conversion argument - -=cut - -sub bin_to_hexstr($;$$) -{ - my $invocant = shift; - my ($data, $width, $prefix) = @_; - confess "Expected conversion argument not given" unless defined $data; - - my $hexstr = unpack("H*", $data); - $hexstr = $invocant->_zero_pad($hexstr, $width) if $width; - - return (($prefix)?'0x':'') . uc($hexstr); -} - -#------------------------------------------------------------------------------- - -=item binstr_to_bin($) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->binstr_to_bin($value); - my $result = $convertor->binstr_to_bin($value); - Purpose : Converts 'binary string' to 'binary' - Arguments : STRING $binstr - Value to be converted [MANDATORY] - Returns : BINARY $bin - Throws : Dies, if not given any conversion argument - -=cut - -sub binstr_to_bin($) -{ - my $invocant = shift; - my ($binstr,) = @_; - confess "Expected conversion argument not given" unless defined $binstr; - - return pack("B*", $invocant->_zero_pad_n($binstr,8)); -} - -=item bin_to_binstr($;$) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->bin_to_binstr($value, $width); - my $result = $convertor->bin_to_binstr($value, $width); - Purpose : Converts 'binary' to 'binary string' - Arguments : BINARY $data - Value to be converted [MANDATORY] - INTEGER $width - Width of the string, pad zeros from left [OPTIONAL, DEFAULT = 0] - Returns : STRING $binstr - Throws : Dies, if not given any conversion argument - -=cut - -sub bin_to_binstr($;$) -{ - my $invocant = shift; - my ($data, $width) = @_; - confess "Expected conversion argument not given" unless defined $data; - - my $binstr = unpack("B*", $data); - $binstr = $invocant->_zero_pad($binstr, $width) if $width; - - return $binstr; -} - -#------------------------------------------------------------------------------- - -=item bin_to_bigint($) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->bin_to_bigint($value); - my $result = $convertor->bin_to_bigint($value); - Purpose : Converts 'binary' to 'big integer' - Arguments : BINARY $bin - Value to be converted [MANDATORY] - Returns : BIGINT $bigint - Throws : Dies, if not given any conversion argument - -=cut - -sub bin_to_bigint($) -{ - my $invocant = shift; - my ($bin,) = @_; - confess "Expected conversion argument not given" unless defined $bin; - - return $invocant->hexstr_to_bigint($invocant->bin_to_hexstr($bin)); -} - -=item bigint_to_bin($;$$) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->bigint_to_bin($value); - my $result = $convertor->bigint_to_bin($value); - Purpose : Converts 'big integer' to 'binary' - Arguments : BIGINT $bigint - Value to be converted [MANDATORY] - Returns : BINARY $bin - Throws : Dies, if not given any conversion argument - -=cut - -sub bigint_to_bin($;$$) -{ - my $invocant = shift; - my ($bigint,) = @_; - confess "Expected conversion argument not given" unless defined $bigint; - - return $invocant->hexstr_to_bin($invocant->bigint_to_hexstr($bigint)); -} - -#------------------------------------------------------------------------------- -# IPv4 conversion methods -#------------------------------------------------------------------------------- - -=item ipv4str_to_int($) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->ipv4str_to_int($value); - my $result = $convertor->ipv4str_to_int($value); - Purpose : Converts 'ipv4str' to 'integer' - Arguments : STRING $ipv4str - Value to be converted [MANDATORY] - Returns : INTEGER $ipv4int - Throws : Dies, if not given any conversion argument - -=cut - -sub ipv4str_to_int($) -{ - my $invocant = shift; - my ($ipv4str,) = @_; - confess "Expected conversion argument not given" unless defined $ipv4str; - - my $ptrn = $IP_QRS{IPV4ADDR_STRING()}; - return undef unless $ipv4str =~ /$ptrn/; - - return unpack('N', pack('C4', split(/\./, $ipv4str))); -} - -=item int_to_ipv4str($) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->int_to_ipv4str($value); - my $result = $convertor->int_to_ipv4str($value); - Purpose : Converts 'integer' to 'ipv4str' - Arguments : INTEGER $ipv4int - Value to be converted [MANDATORY] - Returns : STRING $ipv4str - Throws : Dies, if not given any conversion argument - -=cut - -sub int_to_ipv4str($) -{ - my $invocant = shift; - my ($int,) = @_; - confess "Expected conversion argument not given" unless defined $int; - - return join('.', unpack('C4', pack('N', $int))); -} - -#------------------------------------------------------------------------------- - -=item ipv4hex_to_int($) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->ipv4hex_to_int($value); - my $result = $convertor->ipv4hex_to_int($value); - Purpose : Converts 'ipv4hex' to 'integer' - Arguments : STRING $ipv4hex - Value to be converted [MANDATORY] - Returns : INTEGER $ipv4int - Throws : Dies, if not given any conversion argument - -=cut - -sub ipv4hex_to_int($) -{ - my $invocant = shift; - my ($ipv4hex,) = @_; - confess "Expected conversion argument not given" unless defined $ipv4hex; - - $ipv4hex =~ s/^0x//; - return unpack("N", pack("H*", $ipv4hex)); -} - -=item int_to_ipv4hex($) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->int_to_ipv4hex($value); - my $result = $convertor->int_to_ipv4hex($value); - Purpose : Converts 'integer' to 'ipv4hex' - Arguments : INTEGER $ipv4int - Value to be converted [MANDATORY] - Returns : STRING $ipv4hex - Throws : Dies, if not given any conversion argument - -=cut - -sub int_to_ipv4hex($) -{ - my $invocant = shift; - my ($ipv4int,) = @_; - confess "Expected conversion argument not given" unless defined $ipv4int; - - return uc(unpack("H*", pack("N", $ipv4int))); -} - -#------------------------------------------------------------------------------- - -=item ipv4str_to_bin($) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->ipv4str_to_bin($value); - my $result = $convertor->ipv4str_to_bin($value); - Purpose : Converts 'ipv4str' to 'binary' - Arguments : STRING $ipv4str - Value to be converted [MANDATORY] - Returns : BINARY $ipv4data - Throws : Dies, if not given any conversion argument - -=cut - -sub ipv4str_to_bin($) -{ - my $invocant = shift; - my ($ipv4str,) = @_; - confess "Expected conversion argument not given" unless defined $ipv4str; - - return pack('C4', split(/\./, $ipv4str)); -} - -=item bin_to_ipv4str($) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->bin_to_ipv4str($value); - my $result = $convertor->bin_to_ipv4str($value); - Purpose : Converts 'binary' to 'ipv4str' - Arguments : BINARY $ipv4data - Value to be converted [MANDATORY] - Returns : STRING $ipv4str - Throws : Dies, if not given any conversion argument - -=cut - -sub bin_to_ipv4str($) -{ - my $invocant = shift; - my ($ipv4data,) = @_; - confess "Expected conversion argument not given" unless defined $ipv4data; - - return join('.', unpack('C4', $ipv4data)); -} - -#------------------------------------------------------------------------------- - -=item ipv4hex_to_bin($) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->ipv4hex_to_bin($value); - my $result = $convertor->ipv4hex_to_bin($value); - Purpose : Converts 'ipv4hex' to 'binary' - Arguments : STRING $ipv4hex - Value to be converted [MANDATORY] - Returns : BINARY $ipv4data - Throws : Dies, if not given any conversion argument - -=cut - -sub ipv4hex_to_bin($) -{ - my $invocant = shift; - my ($ipv4hex,) = @_; - confess "Expected conversion argument not given" unless defined $ipv4hex; - - return $invocant->hexstr_to_bin($ipv4hex); -} - -=item bin_to_ipv4hex($) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->bin_to_ipv4hex($value); - my $result = $convertor->bin_to_ipv4hex($value); - Purpose : Converts 'binary' to 'ipv4hex' - Arguments : BINARY $ipv4data - Value to be converted [MANDATORY] - Returns : STRING $ipv4hex - Throws : Dies, if not given any conversion argument - -=cut - -sub bin_to_ipv4hex($) -{ - my $invocant = shift; - my ($ipv4bin,) = @_; - confess "Expected conversion argument not given" unless defined $ipv4bin; - - return $invocant->bin_to_hexstr($ipv4bin); -} - -#------------------------------------------------------------------------------- - -=item ipv4int_to_bin($) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->ipv4int_to_bin($value); - my $result = $convertor->ipv4int_to_bin($value); - Purpose : Converts 'ipv4int' to 'binary' - Arguments : INTEGER $ipv4int - Value to be converted [MANDATORY] - Returns : BINARY $ipv4data - Throws : Dies, if not given any conversion argument - -=cut - -sub ipv4int_to_bin($) -{ - my $invocant = shift; - my ($ipv4int,) = @_; - confess "Expected conversion argument not given" unless defined $ipv4int; - - return pack("N", $ipv4int); -} - -=item bin_to_ipv4int($) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->bin_to_ipv4int($value); - my $result = $convertor->bin_to_ipv4int($value); - Purpose : Converts 'binary' to 'ipv4int' - Arguments : BINARY $ipv4data - Value to be converted [MANDATORY] - Returns : INTEGER $ipv4int - Throws : Dies, if not given any conversion argument - -=cut - -sub bin_to_ipv4int($) -{ - my $invocant = shift; - my ($ipv4bin,) = @_; - confess "Expected conversion argument not given" unless defined $ipv4bin; - - return unpack('N', $ipv4bin); -} - -#------------------------------------------------------------------------------- - -=item ipv4cidr_to_ints($;$) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->ipv4cidr_to_ints($value, $length); - my $result = $convertor->ipv4cidr_to_ints($value, $lenght); - Purpose : Converts 'ipv4cidr string' to 'integers' - Arguments : STRING $ipv4cidr - Value to be converted [MANDATORY] - INTEGER $length - Length of the network, can be parsed out from previous argument [OPTIONAL] - Returns : INTEGER $min - INTEGER $max - Throws : Dies, if not given any conversion argument - -=cut - -sub ipv4cidr_to_ints($;$) -{ - my $invocant = shift; - my ($ipv4cidr,$length) = @_; - confess "Expected conversion argument not given" unless defined $ipv4cidr; - - unless ($length) { - my $ptrn = $IP_QRS{IPV4CIDR_STRING()}; - my @matches = ($ipv4cidr =~ /$ptrn/); - ($ipv4cidr,$length) = @matches if @matches; - } - confess "Invalid network address given as argument" unless defined $ipv4cidr; - confess "Invalid network length given as argument" unless defined $length; - - # Convert the IP address to integer - my $ipv4int = $invocant->ipv4str_to_int($ipv4cidr); - - # Masks must be applied, otherwise this algorithm would fail on 64bit platforms !!! - my $netmask_int = (MAX_IP_MASK() << (32 - $length)) & MAX_IP_MASK(); - my $wildmask_int = (~ $netmask_int) & MAX_IP_MASK(); - - # And now calculate the ranges - my $min = ($ipv4int & $netmask_int); - my $max = ($ipv4int & $netmask_int) + $wildmask_int; - - return ($min, $max); -} - -=item ipv4cidr_to_bins($;$) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->ipv4cidr_to_bins($value); - my $result = $convertor->ipv4cidr_to_bins($value); - Purpose : Converts 'ipv4cidr string' to 'binaries' - Arguments : Same as ipv4cidr_to_ints() method - Returns : BINARY $min - BINARY $max - Throws : Dies, if not given any conversion argument - -=cut - -sub ipv4cidr_to_bins($;$) -{ - my $invocant = shift; - - my ($min, $max) = $invocant->ipv4cidr_to_ints(@_); - return ($invocant->ipv4int_to_bin($min), $invocant->ipv4int_to_bin($max)); -} - -#------------------------------------------------------------------------------- - -=item ipv4rngstr_to_ints($;$) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->ipv4rngstr_to_ints($value, $length); - my $result = $convertor->ipv4rngstr_to_ints($value, $lenght); - Purpose : Converts 'ipv4rngstr string' to 'integers' - Arguments : STRING $ipv4rngstr - Value to be converted [MANDATORY] - INTEGER $second - Length of the network, can be parsed out from previous argument [OPTIONAL] - Returns : INTEGER $min - INTEGER $max - Throws : Dies, if not given any conversion argument - -=cut - -sub ipv4rngstr_to_ints($;$) -{ - my $invocant = shift; - my ($ipv4rngstr,$second) = @_; - confess "Expected conversion argument not given" unless defined $ipv4rngstr; - - unless ($second) - { - my $ptrn = $IP_QRS{IPV4RNG_STRING()}; - my @matches = ($ipv4rngstr =~ /$ptrn/); - ($ipv4rngstr,$second) = @matches if @matches; - } - confess "Invalid network range beginning address given as argument" unless defined $ipv4rngstr; - confess "Invalid network range end address given as argument" unless defined $second; - - # Convert the IP address to integer - my $min = $invocant->ipv4str_to_int($ipv4rngstr); - my $max = $invocant->ipv4str_to_int($second); - - return ($min, $max); -} - -=item ipv4rngstr_to_bins($;$) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->ipv4rngstr_to_bins($value); - my $result = $convertor->ipv4rngstr_to_bins($value); - Purpose : Converts 'ipv4rngstr string' to 'binaries' - Arguments : Same as ipv4rngstr_to_ints() method - Returns : BINARY $min - BINARY $max - Throws : Dies, if not given any conversion argument - -=cut - -sub ipv4rngstr_to_bins($;$) -{ - my $invocant = shift; - - my ($min, $max) = $invocant->ipv4rngstr_to_ints(@_); - return ($invocant->ipv4int_to_bin($min), $invocant->ipv4int_to_bin($max)); -} - -#------------------------------------------------------------------------------- - -=item ipv4netm_to_ints($;$) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->ipv4netm_to_ints($network, $netmask); - my $result = $convertor->ipv4netm_to_ints($value, $lenght); - Purpose : Converts 'ipv4rngstr string' to 'integers' - Arguments : STRING $ipv4rngstr - Value to be converted [MANDATORY] - INTEGER $second - Length of the network, can be parsed out from previous argument [OPTIONAL] - Returns : INTEGER $min - INTEGER $max - Throws : Dies, if not given any conversion argument - -=cut - -sub ipv4netm_to_ints($;$) -{ - my $invocant = shift; - my ($ipv4netm, $netmask) = @_; - confess "Expected conversion argument not given" unless defined $ipv4netm; - - unless ($netmask) - { - my $ptrn = $IP_QRS{IPV4NETM_STRING()}; - my @matches = ($ipv4netm =~ /$ptrn/); - ($ipv4netm, $netmask) = @matches if @matches; - } - confess "Invalid network address given as argument" unless defined $ipv4netm; - confess "Invalid network mask given as argument" unless defined $netmask; - - # Convert the IP address to integer - my $ipv4int = $invocant->ipv4str_to_int($ipv4netm); - my $netmask_int = $invocant->ipv4str_to_int($netmask); - - # This algorithm would be perfect on 32bit platforms, sadly, it fails on 64bit !!! - my $wildmask_int = (~ $netmask_int) & MAX_IP_MASK(); - - # And now calculate the ranges - my $min = ($ipv4int & $netmask_int); - my $max = ($ipv4int & $netmask_int) + $wildmask_int; - - return ($min, $max); -} - -=item ipv4netm_to_bins($;$) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->ipv4netm_to_bins($value); - my $result = $convertor->ipv4netm_to_bins($value); - Purpose : Converts 'ipv4rngstr string' to 'binaries' - Arguments : Same as ipv4rngstr_to_ints() method - Returns : BINARY $min - BINARY $max - Throws : Dies, if not given any conversion argument - -=cut - -sub ipv4netm_to_bins($;$) -{ - my $invocant = shift; - - my ($min, $max) = $invocant->ipv4netm_to_ints(@_); - return ($invocant->ipv4int_to_bin($min), $invocant->ipv4int_to_bin($max)); -} - -#------------------------------------------------------------------------------- - -=item ints_to_ipv4cidr($$) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->ints_to_ipv4cidr($min, $max); - my $result = $convertor->ints_to_ipv4cidr($min, $max); - Purpose : Converts 'integers' to 'ipv4cidr string' - Arguments : INTEGER $min - minimal IP [MANDATORY] - INTEGER $max - maximal IP [MANDATORY] - Returns : STRING $ipv4cidr - Throws : Dies, if not given any conversion argument - -=cut - -sub ints_to_ipv4cidr($$) -{ - my $invocant = shift; - my ($min, $max) = @_; - confess "Expected conversion argument not given" unless defined $min and defined $max; - - my $network = ($min & $max); - my $wildmask = ($min ^ $max); - - my ($size, $i) = (32, 1); - while ($i < $wildmask) { - $size--; - $i = $i << 1; - } - - return $invocant->int_to_ipv4str($network) . "/$size"; -} - -=item ints_to_ipv4netm($$) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->ints_to_ipv4netm($min, $max); - my $result = $convertor->ints_to_ipv4netm($min, $max); - Purpose : Converts 'integers' to 'ipv4netm string' - Arguments : INTEGER $min - minimal IP [MANDATORY] - INTEGER $max - maximal IP [MANDATORY] - Returns : STRING $ipv4cidr - Throws : Dies, if not given any conversion argument - -=cut - -sub ints_to_ipv4netm($;$) -{ - my $invocant = shift; - my ($min,$max) = @_; - confess "Expected conversion argument not given" unless defined $min and defined $max; - - my $network = ($min & $max); - my $wildmask = ($min ^ $max); - my $netmask = (MAX_IP_MASK() ^ $wildmask) & MAX_IP_MASK(); - - return $invocant->int_to_ipv4str($network) . "/" . $invocant->int_to_ipv4str($netmask); -} - -=item ints_to_ipv4rngstr($$) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->ints_to_ipv4rngstr($min, $max); - my $result = $convertor->ints_to_ipv4rngstr($min, $max); - Purpose : Converts 'integers' to 'ipv4rngstr string' - Arguments : INTEGER $min - minimal IP [MANDATORY] - INTEGER $max - maximal IP [MANDATORY] - Returns : STRING $ipv4cidr - Throws : Dies, if not given any conversion argument - -=cut - -sub ints_to_ipv4rngstr($;$) -{ - my $invocant = shift; - my ($min,$max) = @_; - confess "Expected conversion argument not given" unless defined $min and defined $max; - - return $invocant->int_to_ipv4str($min) . '..' . $invocant->int_to_ipv4str($max); -} - -#------------------------------------------------------------------------------- -# IPv6 conversion methods -#------------------------------------------------------------------------------- - -=item ipv6_expand($) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->ipv6_expand($value); - my $result = $convertor->ipv6_expand($value); - Purpose : Expand the shortened IPv6 address string - Arguments : STRING $ipv6str - Value to be converted [MANDATORY] - Returns : STRING $ipv6str - Throws : Dies, if not given any conversion argument - -=cut - -sub ipv6_expand($) -{ - my $invocant = shift; - my ($ipv6str,) = @_; - confess "Expected conversion argument not given" unless defined $ipv6str; - - # Calculate number of IPv6 address sections - my $tmp = $ipv6str; - $tmp =~ s/^:+|:+$//g; - my @sects = split(/:+/, $tmp); - - # If there are too few sections, IPv6 address was in compressed format - if (scalar(@sects) != 8) - { - my @zeros = (); - push(@zeros, 0) while ((scalar(@zeros) + scalar(@sects)) < 8); - my $zeros = join(':', @zeros); - $ipv6str =~ s/::/:$zeros:/; - $ipv6str =~ s/^:|:$//g; - @sects = split(/:+/, $ipv6str); - } - - # Pad with zeroes from the left according to RFC 3513, section 2.3 - # (Internet Protocol Version 6 (IPv6) Addressing Architecture) - my @result = map { $invocant->_zero_pad($_, 4) } @sects; - - return join(':', @result); -} - -=item ipv6_collapse($) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->ipv6_collapse($value); - my $result = $convertor->ipv6_collapse($value); - Purpose : Collapse the expanded IPv6 address string - Arguments : STRING $ipv6str - Value to be converted [MANDATORY] - Returns : STRING $ipv6str - Throws : Dies, if not given any conversion argument - -=cut - -sub ipv6_collapse($) -{ - my $invocant = shift; - my ($ipv6str,) = @_; - confess "Expected conversion argument not given" unless defined $ipv6str; - - # Split IPv6 address to sections - my @sects = split(/:+/, $ipv6str); - - # Remove the leading zeros - my @tmp = map { $_ =~ s/^0*(\d+)$/$1/; $_; } @sects; - $ipv6str = join(':', @tmp); - - # Find the maximal string of zeros - my $max = ""; - while ($ipv6str =~ /(0(:0)+)/gs) { - $max = $1 if length($1) > length($max); - } - if ($max) - { - # Replace it with double colon - $ipv6str =~ s/$max/::/; - # Cleanup after last operation - $ipv6str =~ s/:::+/::/; - } - return $ipv6str; -} - -#------------------------------------------------------------------------------- - -=item ipv6str_to_hexstr($) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->ipv6str_to_hexstr($value); - my $result = $convertor->ipv6str_to_hexstr($value); - Purpose : Converts 'ipv6str' to 'hexadecimal string' - Arguments : STRING $ipv6str - Value to be converted [MANDATORY] - Returns : STRING $hexstr - Throws : Dies, if not given any conversion argument - -=cut - -sub ipv6str_to_hexstr($) -{ - my $invocant = shift; - my ($ipv6str,) = @_; - confess "Expected conversion argument not given" unless defined $ipv6str; - - $ipv6str = $invocant->ipv6_expand($ipv6str); - $ipv6str =~ s/://g; - - return uc($ipv6str); -} - -=item hexstr_to_ipv6str($) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->hexstr_to_ipv6st($value); - my $result = $convertor->hexstr_to_ipv6st($value); - Purpose : Converts 'hexadecimal string' to 'ipv6str' - Arguments : STRING $hexstr - Value to be converted [MANDATORY] - Returns : STRING $ipv6str - Throws : Dies, if not given any conversion argument - -=cut - -sub hexstr_to_ipv6str($) -{ - my $invocant = shift; - my ($ipv6hex,) = @_; - confess "Expected conversion argument not given" unless defined $ipv6hex; - - return $invocant->ipv6_collapse(join(':', unpack('(A4)*', $ipv6hex))); -} - -#------------------------------------------------------------------------------- - -=item ipv6str_to_bin($) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->ipv6str_to_bin($value); - my $result = $convertor->ipv6str_to_bin($value); - Purpose : Converts 'ipv6str' to 'binary' - Arguments : STRING $ipv6str - Value to be converted [MANDATORY] - Returns : BINARY $ipv6bin - Throws : Dies, if not given any conversion argument - -=cut - -sub ipv6str_to_bin($) -{ - my $invocant = shift; - my ($ipv6str,) = @_; - confess "Expected conversion argument not given" unless defined $ipv6str; - - $ipv6str = $invocant->ipv6_expand($ipv6str); - $ipv6str =~ s/://g; - - return $invocant->hexstr_to_bin($ipv6str); -} - -=item bin_to_ipv6str($) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->bin_to_ipv6str($value); - my $result = $convertor->bin_to_ipv6str($value); - Purpose : Converts 'binary' to 'ipv6str' - Arguments : BINARY $ipv6bin - Value to be converted [MANDATORY] - Returns : STRING $ipv6str - Throws : Dies, if not given any conversion argument - -=cut - -sub bin_to_ipv6str($) -{ - my $invocant = shift; - my ($ipv6bin,) = @_; - confess "Expected conversion argument not given" unless defined $ipv6bin; - - return $invocant->ipv6_collapse(join(':', unpack('(A4)*', $invocant->bin_to_hexstr($ipv6bin)))); -} - -#------------------------------------------------------------------------------- - -=item ipv6str_to_bigint($) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->ipv6str_to_bigint($value); - my $result = $convertor->ipv6str_to_bigint($value); - Purpose : Converts 'ipv6str' to 'bigint' - Arguments : STRING $ipv6str - Value to be converted [MANDATORY] - Returns : BIGINT $ipv6bigint - Throws : Dies, if not given any conversion argument - -=cut - -sub ipv6str_to_bigint($) -{ - my $invocant = shift; - my ($ipv6str,) = @_; - confess "Expected conversion argument not given" unless defined $ipv6str; - - $ipv6str = $invocant->ipv6_expand($ipv6str); - $ipv6str =~ s/://g; - - return $invocant->hexstr_to_bigint($ipv6str); -} - -=item bigint_to_ipv6str($) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->bigint_to_ipv6str($value); - my $result = $convertor->bigint_to_ipv6str($value); - Purpose : Converts 'bigint' to 'ipv6str' - Arguments : BIGINT $ipv6bigint - Value to be converted [MANDATORY] - Returns : STRING $ipv6str - Throws : Dies, if not given any conversion argument - -=cut - -sub bigint_to_ipv6str($) -{ - my $invocant = shift; - my ($ipv6bigint,) = @_; - confess "Expected conversion argument not given" unless defined $ipv6bigint; - - use bigint; - return $invocant->ipv6_collapse(join(':', unpack('(A4)*', $invocant->bigint_to_hexstr($ipv6bigint,32)))); -} - -#------------------------------------------------------------------------------- -# IP address detection -#------------------------------------------------------------------------------- - -=item detect_ipv4($) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->detect_ipv4($value); - my $result = $convertor->detect_ipv4($value); - Purpose : Detect type of IPv4 adress/network/range - Arguments : STRING $address - Value to be converted [MANDATORY] - Returns : STRING $type - Throws : Dies, if not given any conversion argument - -=cut - -sub detect_ipv4($) -{ - my $invocant = shift; - my ($address,) = @_; - confess "Expected conversion argument not given" unless defined $address; - - my ($type, $ptrn, @matches); - foreach my $t (@$QR_IPV4) - { - ($type, $ptrn) = @$t; - @matches = ($address =~ /$ptrn/); - return ($type, @matches) if @matches; - } - return undef; -} - -=item detect_ipv6($) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->detect_ipv6($value); - my $result = $convertor->detect_ipv6($value); - Purpose : Detect type of IPv6 adress/network/range - Arguments : STRING $address - Value to be converted [MANDATORY] - Returns : STRING $type - Throws : Dies, if not given any conversion argument - -=cut - -sub detect_ipv6($) -{ - my $invocant = shift; - my ($address,) = @_; - confess "Expected conversion argument not given" unless defined $address; - - my ($type, $ptrn, @matches); - foreach my $t (@$QR_IPV6) - { - ($type, $ptrn) = @$t; - @matches = ($address =~ /$ptrn/); - return ($type, @matches) if @matches; - } - return undef; -} - -=item detect_ip($) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->detect_ip($value); - my $result = $convertor->detect_ip($value); - Purpose : Detect type of IPv4/IPv6 adress/network/range - Arguments : STRING $address - Value to be converted [MANDATORY] - Returns : STRING $type - Throws : Dies, if not given any conversion argument - -=cut - -sub detect_ip($) -{ - my $invocant = shift; - my ($address,) = @_; - confess "Expected conversion argument not given" unless defined $address; - - my ($type, @matches); - ($type, @matches) = $invocant->detect_ipv4($address); - return ($type, @matches) if $type; - ($type, @matches) = $invocant->detect_ipv6($address); - return ($type, @matches); -} - -#------------------------------------------------------------------------------- - -=item ipv4_to_int($;$) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->ipv4_to_int($value); - my $result = $convertor->ipv4_to_int($value); - Purpose : Converts 'ipv4' adress in any representation to 'integer' - Arguments : INTEGER $ipv4 - Value to be converted [MANDATORY] - STRING $type - Type of the argument (bypass autodetection) [OPTIONAL] - Returns : INTEGER $ipv4int - Throws : Dies, if not given any conversion argument - -=cut - -sub ipv4_to_int($) -{ - my $invocant = shift; - my ($ipv4, $type, @matches) = @_; - confess "Expected conversion argument not given" unless defined $ipv4; - - ($type, @matches) = $invocant->detect_ipv4($ipv4) unless $type; - confess "Invalid argument '$ipv4' given" unless $type; - confess "Do not know how to convert $type to integer" unless exists IP_CONVERSIONS()->{$type}->{INT}; - - my $conversion = IP_CONVERSIONS()->{$type}->{INT}; - return ($type, $invocant->$conversion(@matches)) if $conversion; - return (UNKNOWN_TYPE(), $ipv4); -} - -=item ipv4_to_bin($) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->ipv4_to_bin($value); - my $result = $convertor->ipv4_to_bin($value); - Purpose : Converts 'ipv4' adress in any representation to 'binary' - Arguments : Same as ipv4_to_int() method - Returns : BINARY $binary - Throws : Dies, if not given any conversion argument - See also : ipv4_to_int() method - -=cut - -sub ipv4_to_bin($) -{ - my $invocant = shift; - my ($ipv4, $type, @matches) = @_; - confess "Expected conversion argument not given" unless defined $ipv4; - - ($type, @matches) = $invocant->detect_ipv4($ipv4) unless $type; - confess "Invalid argument '$ipv4' given" unless $type; - confess "Do not know how to convert $type to binary" unless exists IP_CONVERSIONS()->{$type}->{BIN}; - - my $conversion = IP_CONVERSIONS()->{$type}->{BIN}; - return ($type, $invocant->$conversion(@matches)) if $conversion; - return (UNKNOWN_TYPE(), $ipv4); -} - -#------------------------------------------------------------------------------- - -=item ipv6_to_bigint($) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->ipv6_to_bigint($value); - my $result = $convertor->ipv6_to_bigint($value); - Purpose : Converts 'ipv6' adress in any representation to 'integer' - Arguments : INTEGER $ipv6 - Value to be converted [MANDATORY] - STRING $type - Type of the argument (bypass autodetection) [OPTIONAL] - Returns : INTEGER $ipv6int - Throws : Dies, if not given any conversion argument - -=cut - -sub ipv6_to_bigint($;$) -{ - my $invocant = shift; - my ($ipv6, $type, @matches) = @_; - confess "Expected conversion argument not given" unless defined $ipv6; - - ($type, @matches) = $invocant->detect_ipv6($ipv6) unless $type; - confess "Invalid argument '$ipv6' given" unless $type; - confess "Do not know how to convert $type" unless exists IP_CONVERSIONS()->{$type}->{INT}; - - my $conversion = IP_CONVERSIONS()->{$type}->{INT}; - return ($type, $invocant->$conversion($ipv6)) if $conversion; - return (UNKNOWN_TYPE(), $ipv6); -} - -=item ipv6_to_bin($) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->ipv6_to_bin($value); - my $result = $convertor->ipv6_to_bin($value); - Purpose : Converts 'ipv6' adress in any representation to 'binary' - Arguments : Same as ipv6_to_bigint() method - Returns : BINARY $binary - Throws : Dies, if not given any conversion argument - See also : ipv6_to_bigint() method - -=cut - -sub ipv6_to_bin($;$) -{ - my $invocant = shift; - my ($ipv6, $type, @matches) = @_; - confess "Expected conversion argument not given" unless defined $ipv6; - - ($type, @matches) = $invocant->detect_ipv6($ipv6) unless $type; - confess "Invalid argument '$ipv6' given" unless $type; - confess "Do not know how to convert $type" unless exists IP_CONVERSIONS()->{$type}->{BIN}; - - my $conversion = IP_CONVERSIONS()->{$type}->{BIN}; - return ($type, $invocant->$conversion($ipv6)) if $conversion; - return (UNKNOWN_TYPE(), $ipv6); -} - -#------------------------------------------------------------------------------- - -=item ipv6cidr_to_bigints($;$) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->ipv6cidr_to_bigints($value, $length); - my $result = $convertor->ipv6cidr_to_bigints($value, $length); - Purpose : Converts 'ipv6cidr string' to 'bigintegers' - Arguments : STRING $ipv6cidr - Value to be converted [MANDATORY] - Returns : BIGINT $min - BIGINT $max - Throws : Dies, if not given any conversion argument - -=cut - -sub ipv6cidr_to_bigints($) -{ - my $invocant = shift; - my ($ipv6cidr) = @_; - confess "Expected conversion argument not given" unless defined $ipv6cidr; - - my $cidr = Net::CIDR::Lite->new; - eval { - $cidr->add($ipv6cidr); - }; - - if ($@) { - confess "Invalid network address given as argument: $@"; - } - - my ($min_str, $max_str) = split (/-/, join ('', $cidr->list_range)); - - # And now calculate the ranges - my $min = $invocant->ipv6str_to_bigint($min_str); - my $max = $invocant->ipv6str_to_bigint($max_str); - - return ($min, $max); -} - -=item bigints_to_ipv6cidr($$) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->bigints_to_ipv6cidr($min, $max); - my $result = $convertor->bigints_to_ipv6cidr($value, $length); - Purpose : - Arguments : - Returns : - Throws : Dies, if not given any conversion argument - -=cut - -sub bigints_to_ipv6cidr($$) -{ - my $invocant = shift; - my ($min, $max) = @_; - confess "Expected conversion argument not given" unless defined $min and defined $max; - - my $min_str = $invocant->bigint_to_ipv6str($min); - my $max_str = $invocant->bigint_to_ipv6str($max); - - my $cidr = Net::CIDR::Lite->new; - eval { - $cidr->add_range("$min_str-$max_str"); - }; - if ($@) { - confess "Invalid IPv6 integer CIDR ranges given as arguments: $@"; - } - - my @cidr_lists = $cidr->list; - - return $cidr_lists[0]; -} - -=item ipv6cidr_to_bins($;$) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->ipv6cidr_to_bins($value); - my $result = $convertor->ipv6cidr_to_bins($value); - Purpose : Converts 'ipv6cidr string' to 'binaries' - Arguments : Same as ipv6cidr_to_bigints() method - Returns : BINARY $min - BINARY $max - Throws : Dies, if not given any conversion argument - -=cut - -sub ipv6cidr_to_bins($) -{ - my $invocant = shift; - my ($ipv6cidr) = @_; - confess "Expected conversion argument not given" unless defined $ipv6cidr; - - my $cidr = Net::CIDR::Lite->new; - eval { - $cidr->add($ipv6cidr); - }; - - if ($@) { - confess "Invalid network address given as argument: $@"; - } - - my ($min_str, $max_str) = split (/-/, join ('', $cidr->list_range)); - - # And now calculate the ranges - my $min = $invocant->ipv6str_to_bin($min_str); - my $max = $invocant->ipv6str_to_bin($max_str); - - return ($min, $max); -} - -=item bins_to_ipv6cidr($$) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->bins_to_ipv6cidr($min, $max); - my $result = $convertor->bins_to_ipv6cidr($value, $length); - Purpose : - Arguments : - Returns : - Throws : Dies, if not given any conversion argument - -=cut - -sub bins_to_ipv6cidr($$) -{ - my $invocant = shift; - my ($min, $max) = @_; - confess "Expected conversion argument not given" unless defined $min and defined $max; - - my $min_str = $invocant->bin_to_ipv6str($min); - my $max_str = $invocant->bin_to_ipv6str($max); - - my $cidr = Net::CIDR::Lite->new; - eval { - $cidr->add_range("$min_str-$max_str"); - }; - if ($@) { - confess "Invalid IPv6 integer CIDR ranges given as arguments: $@"; - } - - my @cidr_lists = $cidr->list; - - return $cidr_lists[0]; -} - -#------------------------------------------------------------------------------- - -=item ip_to_int($;$) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->ip_to_int($value); - my $result = $convertor->ip_to_int($value); - Purpose : Converts 'ipv4' adress in any representation to 'integer' - Arguments : INTEGER $ip - Value to be converted [MANDATORY] - STRING $type - Type of the argument (bypass autodetection) [OPTIONAL] - Returns : INTEGER|GIGINT $ipint - Throws : Dies, if not given any conversion argument - -=cut - -sub ip_to_int($) -{ - my $invocant = shift; - my ($ip, $type, @matches) = @_; - confess "Expected conversion argument not given" unless defined $ip; - - ($type, @matches) = $invocant->detect_ip($ip) unless $type; - confess "Invalid argument '$ip' given" unless $type; - confess "Do not know how to convert $type" unless exists IP_CONVERSIONS()->{$type}->{INT}; - - my $conversion = IP_CONVERSIONS()->{$type}->{INT}; - return ($type, $invocant->$conversion(@matches)) if $conversion; - return (UNKNOWN_TYPE(), $ip); -} - -=item ip_to_bin($) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->ip_to_bin($value); - my $result = $convertor->ip_to_bin($value); - Purpose : Converts 'ip' adress in any representation to 'binary' - Arguments : Same as ip_to_int() method - Returns : BINARY $binary - Throws : Dies, if not given any conversion argument - See also : ip_to_int() method - -=cut - -sub ip_to_bin($) -{ - my $invocant = shift; - my ($ip, $type, @matches) = @_; - confess "Expected conversion argument not given" unless defined $ip; - - ($type, @matches) = $invocant->detect_ip($ip) unless $type; - confess "Invalid argument '$ip' given" unless $type; - confess "Do not know how to convert $type" unless exists IP_CONVERSIONS()->{$type}->{BIN}; - - my $conversion = IP_CONVERSIONS()->{$type}->{BIN}; - return ($type, $invocant->$conversion(@matches)) if $conversion; - return (UNKNOWN_TYPE(), $ip); -} - -#------------------------------------------------------------------------------- -# IP address anonymizations -#------------------------------------------------------------------------------- - -=item ipv4_anonymize($;$) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->ipv4_anonymize($value); - my $result = $convertor->ipv4_anonymize($value); - Purpose : Anonymizes IPv4 address - Arguments : STRING ipv4 - Value to be converted [MANDATORY] - INTEGER $depth - How much to anonymize [OPTIONAL,DEFAULT=1] - Returns : BINARY $binary - Throws : Dies, if not given any conversion argument - See also : ip_to_int() method - -=cut - -sub ipv4_anonymize($;$) -{ - my $invocant = shift; - my ($ipv4, $depth) = @_; - confess "Expected conversion argument not given" unless defined $ipv4; - - my @chunks = split(/\./, $ipv4); - $depth = 1 unless defined $depth; - $depth = int($depth); - $depth = 1 if ($depth < 0 or $depth > 4); - - for (my $i = 0; $i < $depth; $i++) { pop(@chunks); } - for (my $i = 0; $i < $depth; $i++) { push(@chunks, 0); } - - return join('.', @chunks); -} - -#------------------------------------------------------------------------------- -# MAC conversions -#------------------------------------------------------------------------------- - -=item macstr_to_hexstr($) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->macstr_to_hexstr($value); - my $result = $convertor->macstr_to_hexstr($value); - Purpose : Converts 'mac_string' to 'hexadecimal string' - Arguments : STRING $macstr - Value to be converted [MANDATORY] - Returns : STRING $hexstr - Throws : Dies, if not given any conversion argument - -=cut - -sub macstr_to_hexstr($) -{ - my $invocant = shift; - my ($macstr,) = @_; - confess "Expected conversion argument not given" unless defined $macstr; - - $macstr =~ s/://g; - return uc($macstr); -} - -=item hexstr_to_macstr($) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->hexstr_to_macstr($value); - my $result = $convertor->hexstr_to_macstr($value); - Purpose : Converts 'hexadecimal string' to 'mac_string' - Arguments : STRING $hexstr - Value to be converted [MANDATORY] - Returns : STRING $macstr - Throws : Dies, if not given any conversion argument - -=cut - -sub hexstr_to_macstr($) -{ - my $invocant = shift; - my ($machex,) = @_; - confess "Expected conversion argument not given" unless defined $machex; - - return join(':', unpack('(A2)*', $machex)); -} - -#------------------------------------------------------------------------------- - -=item macstr_to_bin($) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->macstr_to_bin($value); - my $result = $convertor->macstr_to_bin($value); - Purpose : Converts 'mac_string' to 'binary' - Arguments : STRING $macstr - Value to be converted [MANDATORY] - Returns : BINARY $macbin - Throws : Dies, if not given any conversion argument - -=cut - -sub macstr_to_bin($) -{ - my $invocant = shift; - my ($macstr,) = @_; - confess "Expected conversion argument not given" unless defined $macstr; - - $macstr =~ s/://g; - return $invocant->hexstr_to_bin($macstr); -} - -=item bin_to_macstr($) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->bin_to_macstr($value); - my $result = $convertor->bin_to_macstr($value); - Purpose : Converts 'binary' to 'mac_string' - Arguments : BINARY $macbin - Value to be converted [MANDATORY] - Returns : STRING $macstr - Throws : Dies, if not given any conversion argument - -=cut - -sub bin_to_macstr($) -{ - my $invocant = shift; - my ($macbin,) = @_; - confess "Expected conversion argument not given" unless defined $macbin; - - return $invocant->hexstr_to_macstr($invocant->bin_to_hexstr($macbin)); -} - -#------------------------------------------------------------------------------- - -=item macstr_to_bigint($) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->macstr_to_bigint($value); - my $result = $convertor->macstr_to_bigint($value); - Purpose : Converts 'macstr' to 'bigint' - Arguments : STRING $macstr - Value to be converted [MANDATORY] - Returns : BIGINT $bigint - Throws : Dies, if not given any conversion argument - -=cut - -sub macstr_to_bigint($) -{ - my $invocant = shift; - my ($macstr,) = @_; - confess "Expected conversion argument not given" unless defined $macstr; - - $macstr =~ s/://g; - - return $invocant->hexstr_to_bigint($macstr); -} - -=item bigint_to_macstr($) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->bigint_to_macstr($value); - my $result = $convertor->bigint_to_macstr($value); - Purpose : Converts 'bigint' to 'macstr' - Arguments : BIGINT $bigint - Value to be converted [MANDATORY] - Returns : STRING $macstr - Throws : Dies, if not given any conversion argument - -=cut - -sub bigint_to_macstr($) -{ - my $invocant = shift; - my ($bigint,) = @_; - confess "Expected conversion argument not given" unless defined $bigint; - - use bigint; - return $invocant->hexstr_to_macstr($invocant->bigint_to_hexstr($bigint,12)); -} - -#------------------------------------------------------------------------------- -# Time and date conversions -#------------------------------------------------------------------------------- - -=item ntps_to_nbi($) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->ntps_to_nbi($value); - my $result = $convertor->ntps_to_nbi($value); - Purpose : Converts 'ntp_stamp' to 'bigint' - Arguments : STRING $ntpstamp - Value to be converted [MANDATORY] - Returns : BIGINT $bigint - Throws : Dies, if not given any conversion argument - -=cut - -sub ntps_to_nbi($) -{ - my $invocant = shift; - my ($ntpstamp,) = @_; - confess "Expected conversion argument not given" unless defined $ntpstamp; - - use bigint; - - my $part = qr/[0-9a-fA-F]+/; - my ($high, $low) = $ntpstamp =~ /^0x($part)\.0x($part)$/; - - my $bigint = hex("0x$low") + (hex("0x$high") << 32); - $bigint =~ /^[0-9]+$/; - - return $bigint; -} - -=item nbi_to_ntps($) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->nbi_to_ntps($value); - my $result = $convertor->nbi_to_ntps($value); - Purpose : Converts 'bigint' to 'ntp_stamp' - Arguments : BIGINT $bigint - Value to be converted [MANDATORY] - Returns : STRING $ntps - Throws : Dies, if not given any conversion argument - -=cut - -sub nbi_to_ntps($) -{ - my $invocant = shift; - my ($bigint,) = @_; - confess "Expected conversion argument not given" unless defined $bigint; - - use bigint; - - my $s = ($bigint >> 32); - my $m = $bigint - ($s <<32); - - return lc(sprintf("0x%x.0x%x", $s, $m)); -} - -#------------------------------------------------------------------------------- - -=item unixs_to_ubi($) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->unixs_to_ubi($value); - my $result = $convertor->unixs_to_ubi($value); - Purpose : Converts 'unix_stamp' to 'bigint' - Arguments : INTEGER|FLOAT $unixstamp - Value to be converted [MANDATORY] - Returns : BIGINT $bigint - Throws : Dies, if not given any conversion argument - -=cut - -sub unixs_to_ubi($) -{ - my $invocant = shift; - my ($unixstamp,) = @_; - confess "Expected conversion argument not given" unless defined $unixstamp; - - use bigint; - - my $result = $invocant->unixs_to_ints($unixstamp); - my ($high, $low) = @$result; - - my $bigint = int($low) + (int($high) << 32); - $bigint =~ /^[0-9]+$/; - - return $bigint; -} - -=item ubi_to_unixs($) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->ubi_to_unixs($value); - my $result = $convertor->ubi_to_unixs($value); - Purpose : Converts 'bigint' to 'unix_stamp' - Arguments : BIGINT $bigint - Value to be converted [MANDATORY] - Returns : INTEGER|FLOAT $unixstamp - Throws : Dies, if not given any conversion argument - -=cut - -sub ubi_to_unixs($) -{ - my $invocant = shift; - my ($bigint,) = @_; - confess "Expected conversion argument not given" unless defined $bigint; - - my $s = ($bigint >> 32); - my $m = $bigint - ($s << 32); - - return $invocant->ints_to_unixs([$s,$m]); -} - -#------------------------------------------------------------------------------- - -=item unixs_to_nbi($) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->unixs_to_nbi($value); - my $result = $convertor->unixs_to_nbi($value); - Purpose : Converts 'unix_stamp' to 'ntp bigint' - Arguments : INTEGER|FLOAT $unixstamp - Value to be converted [MANDATORY] - Returns : BIGINT $bigint - Throws : Dies, if not given any conversion argument - -=cut - -sub unixs_to_nbi($) -{ - my $invocant = shift; - my ($unixstamp,) = @_; - confess "Expected conversion argument not given" unless defined $unixstamp; - - $unixstamp = $invocant->unixs_to_ubi($unixstamp); - $unixstamp = $invocant->unixe_to_ntpe_b($unixstamp); - - return $unixstamp; -} - -=item nbi_to_unixs($) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->nbi_to_unixs($value); - my $result = $convertor->nbi_to_unixs($value); - Purpose : Converts 'bigint' to 'unix_stamp' - Arguments : BIGINT $bigint - Value to be converted [MANDATORY] - Returns : INTEGER|FLOAT $unixstamp - Throws : Dies, if not given any conversion argument - -=cut - -sub nbi_to_unixs($) -{ - my $invocant = shift; - my ($bigint,) = @_; - confess "Expected conversion argument not given" unless defined $bigint; - - $bigint = $invocant->ntpe_to_unixe_b($bigint); - $bigint = $invocant->ubi_to_unixs($bigint); - - return $bigint; -} - -#------------------------------------------------------------------------------- - -=item ntps_to_ints($) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->ntps_to_ints($value); - my $result = $convertor->ntps_to_ints($value); - Purpose : Converts 'ntp_stamp' to 'integers' - Arguments : STRING $ntpstamp - Value to be converted [MANDATORY] - Returns : ARRAY REFERENCE CONTAINING - INTEGER $seconds - INTEGER $fractions - Throws : Dies, if not given any conversion argument - -=cut - -sub ntps_to_ints($) -{ - my $invocant = shift; - my ($ntpstamp,) = @_; - confess "Expected conversion argument not given" unless defined $ntpstamp; - - my $part = qr/[0-9a-fA-F]{1,8}/; - my ($high, $low) = $ntpstamp =~ /^0x($part)\.0x($part)$/; - - return [hex("0x$high"), hex("0x$low")]; -} - -=item ints_to_ntps($) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->ints_to_ntps($value); - my $result = $convertor->ints_to_ntps($value); - Purpose : Converts 'integers' to 'ntp_stamp' - Arguments : ARRAY REFERENCE CONTAINING [MANDATORY] - INTEGER $seconds - INTEGER $fractions - Returns : STRING $ntpstamp - Throws : Dies, if not given any conversion argument - -=cut - -sub ints_to_ntps($) -{ - my $invocant = shift; - my ($ints) = @_; - confess "Expected conversion argument not given" unless defined $ints; - confess "Conversion argument must be given as ARRAY reference" unless ref $ints eq 'ARRAY'; - - $ints->[1] = 0 unless $ints->[1]; - - return sprintf("0x%x.0x%x", $ints->[0], $ints->[1]); -} - -#------------------------------------------------------------------------------- - -=item unixs_to_ints($) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->unixs_to_ints($value); - my $result = $convertor->unixs_to_ints($value); - Purpose : Converts 'unix_stamp' to 'integers' - Arguments : INTEGER|FLOAT $unixstamp - Value to be converted [MANDATORY] - Returns : ARRAY REFERENCE CONTAINING - INTEGER $seconds - INTEGER $fractions - Throws : Dies, if not given any conversion argument - -=cut - -sub unixs_to_ints($) -{ - my $invocant = shift; - my ($unixstamp,) = @_; - confess "Expected conversion argument not given" unless defined $unixstamp; - - my $part = qr/[0-9]+/; - my ($high, $low) = $unixstamp =~ /^($part)(?:\.($part))?$/; - $low = 0 unless $low; - - return [$high, $low]; -} - -=item ints_to_unixs($) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->ints_to_unixs($value); - my $result = $convertor->ints_to_unixs($value); - Purpose : Converts 'integers' to 'unix_stamp' - Arguments : ARRAY REFERENCE CONTAINING [MANDATORY] - INTEGER $seconds - INTEGER $fractions - Returns : INTEGER|FLOAT $unixstamp - Throws : Dies, if not given any conversion argument - -=cut - -sub ints_to_unixs($) -{ - my $invocant = shift; - my ($ints) = @_; - confess "Expected conversion argument not given" unless defined $ints; - confess "Conversion argument must be given as ARRAY reference" unless ref $ints eq 'ARRAY'; - - $ints->[1] = 0 unless $ints->[1]; - my ($s, $m) = @$ints; - - return "$s.0" + "0.$m"; -} - -#------------------------------------------------------------------------------- - -=item ntpe_to_unixe($) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->ntpe_to_unixe($value); - my $result = $convertor->ntpe_to_unixe($value); - Purpose : Converts 'ntp epoch' to 'unix epoch' (1900 -> 1970) - Arguments : INTEGER|FLOAT $ntpepoch - Value to be converted [MANDATORY] - Returns : INTEGER|FLOAT $unixepoch - Throws : Dies, if not given any conversion argument - -=cut - -sub ntpe_to_unixe($) -{ - my $invocant = shift; - my ($ntpepoch,) = @_; - confess "Expected conversion argument not given" unless defined $ntpepoch; - - return $ntpepoch - NTP_TO_EPOCH_DELTA; -} - -=item unixe_to_ntpe($) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->($value); - my $result = $convertor->($value); - Purpose : Converts 'unix epoch' to 'ntp epoch' (1970 -> 1900) - Arguments : INTEGER|FLOAT $unixepoch - Value to be converted [MANDATORY] - Returns : INTEGER|FLOAT $ntpepoc - Throws : Dies, if not given any conversion argument - -=cut - -sub unixe_to_ntpe($) -{ - my $invocant = shift; - my ($unixepoch,) = @_; - confess "Expected conversion argument not given" unless defined $unixepoch; - - return $unixepoch + NTP_TO_EPOCH_DELTA; -} - -#------------------------------------------------------------------------------- - -=item ntpe_to_unixe_b($) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->ntpe_to_unixe_b($value); - my $result = $convertor->ntpe_to_unixe_b($value); - Purpose : Converts 'ntp epoch' to 'unix epoch' in bigint (1900 -> 1970) - Arguments : BIGINT $ntpepoch - Value to be converted [MANDATORY] - Returns : BIGINT $unixepoch - Throws : Dies, if not given any conversion argument - -=cut - -sub ntpe_to_unixe_b($) -{ - my $invocant = shift; - use bigint; - my ($ntpepoch,) = @_; - confess "Expected conversion argument not given" unless defined $ntpepoch; - - return $ntpepoch - (NTP_TO_EPOCH_DELTA() << 32); -} - -=item unixe_to_ntpe_b($) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->unixe_to_ntpe_b($value); - my $result = $convertor->unixe_to_ntpe_b($value); - Purpose : Converts 'unix epoch' to 'ntp epoch' in bigint (1970 -> 1900) - Arguments : BIGINT $unixepoch - Value to be converted [MANDATORY] - Returns : BIGINT $ntpepoch - Throws : Dies, if not given any conversion argument - -=cut - -sub unixe_to_ntpe_b($) -{ - my $invocant = shift; - use bigint; - my ($unixepoch,) = @_; - confess "Expected conversion argument not given" unless defined $unixepoch; - - return $unixepoch + (NTP_TO_EPOCH_DELTA() << 32); -} - -#------------------------------------------------------------------------------- - -=item local_to_utc($) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->local_to_utc($value); - my $result = $convertor->local_to_utc($value); - Purpose : Converts 'local' unix timestamp to 'utc/gmt' unix timestamp - Arguments : INTEGER|FLOAT $unixstamp - Value to be converted [MANDATORY] - Returns : INTEGER|FLOAT $unixstamp - Throws : Dies, if not given any conversion argument - -=cut - -sub local_to_utc($) -{ - my $invocant = shift; - my ($unixstamp,) = @_; - confess "Expected conversion argument not given" unless defined $unixstamp; - - return $unixstamp - $TIME_ZONE_OFFSET; -} - -=item utc_to_local($) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->utc_to_local($value); - my $result = $convertor->utc_to_local($value); - Purpose : Converts 'utc/gmt' unix timestamp to 'local' unix timestamp - Arguments : INTEGER|FLOAT $unixstamp - Value to be converted [MANDATORY] - Returns : INTEGER|FLOAT $unixstamp - Throws : Dies, if not given any conversion argument - -=cut - -sub utc_to_local($) -{ - my $invocant = shift; - my ($unixstamp,) = @_; - confess "Expected conversion argument not given" unless defined $unixstamp; - - return $unixstamp + $TIME_ZONE_OFFSET; -} - -#------------------------------------------------------------------------------- - -=item datestr_to_unixs($) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->datestr_to_unixs($value); - my $result = $convertor->datestr_to_unixs($value); - Purpose : Converts 'date string' to 'integer' timestamp - Arguments : STRING $datestr - Value to be converted [MANDATORY] - Returns : INTEGER $timestamp - Throws : Dies, if not given any conversion argument - -=cut - -sub datestr_to_unixs($) -{ - my $invocant = shift; - my ($datestr,) = @_; - confess "Expected conversion argument not given" unless defined $datestr; - - return str2time($datestr); -} - -=item unixs_to_datestr($;$) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->unixs_to_datestr($value, $print_in_local); - my $result = $convertor->unixs_to_datestr($value, $print_in_local); - Purpose : Converts 'unix_stamp' to 'date string' formated in ISO 8601 - Arguments : INTEGER|FLOAT $unixstamp - Value to be converted [MANDATORY] - BOOL $print_in_local - display the timestamp in local time, not UTC/GMT - Returns : STRING $datestr - Throws : Dies, if not given any conversion argument - -=cut - -sub unixs_to_datestr($;$) -{ - my $invocant = shift; - my ($unixstamp, $print_in_local) = @_; - confess "Expected conversion argument not given" unless defined $unixstamp; - - # Assume all timestamps to be in UTC/GMT - my $dt = DateTime->from_epoch(epoch => $unixstamp, time_zone => 'UTC'); - - # Print time in local time zone? - unless ($print_in_local) - { - $dt->set_time_zone('UTC'); - return $dt->strftime('%F %TZ'); - } - else { - $dt->set_time_zone($TIME_ZONE); - #return $dt->strftime('%F %T%z'); - return $dt->strftime('%F %T'); - } -} - -=item unixs_to_ldatestr($) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->unixs_to_ldatestr($value); - my $result = $convertor->unixs_to_ldatestr($value); - Purpose : Converts 'unix_stamp' to 'date string' formated in local time, not UTC/GMT - Arguments : INTEGER|FLOAT $unixstamp - Value to be converted [MANDATORY] - Returns : STRING $datestr - Throws : Dies, if not given any conversion argument - -=cut - -sub unixs_to_ldatestr($) -{ - my $invocant = shift; - my ($unixstamp) = @_; - confess "Expected conversion argument not given" unless defined $unixstamp; - - return $invocant->unixs_to_datestr($unixstamp, 1); -} - -#------------------------------------------------------------------------------- - -=item unixs_to_datetime($;$) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->unixs_to_datetime($value, $print_in_local); - my $result = $convertor->unixs_to_datestr($value, $print_in_local); - Purpose : Converts 'unix_stamp' to 'DateTime' - Arguments : INTEGER|FLOAT $unixstamp - Value to be converted [MANDATORY] - BOOL $print_in_local - display the timestamp in local time, not UTC/GMT - Returns : DateTime - Throws : Dies, if not given any conversion argument - -=cut - -sub unixs_to_datetime($;$) -{ - my $invocant = shift; - my ($unixstamp, $print_in_local) = @_; - confess "Expected conversion argument not given" unless defined $unixstamp; - - # Assume all timestamps to be in UTC/GMT - my $dt = DateTime->from_epoch(epoch => $unixstamp, time_zone => 'UTC'); - - # Print time in local time zone? - unless ($print_in_local) - { - $dt->set_time_zone('UTC'); - return $dt; - } - else - { - $dt->set_time_zone($TIME_ZONE); - return $dt; - } -} - -#------------------------------------------------------------------------------- - -=item ntps_to_datestr($;$) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->ntps_to_datestr($value, $print_in_local); - my $result = $convertor->ntps_to_datestr($value, $print_in_local); - Purpose : Converts 'ntp_stamp' to 'date string' formated in ISO 8601 - Arguments : STRING $ntpstamp - Value to be converted [MANDATORY] - BOOL $print_in_local - display the timestamp in local time, not UTC/GMT - Returns : STRING $datestr - Throws : Dies, if not given any conversion argument - -=cut - -sub ntps_to_datestr($;$) -{ - my $invocant = shift; - my ($ntpstamp, $print_in_local) = @_; - confess "Expected conversion argument not given" unless defined $ntpstamp; - - # Convert the ntpstamp to bigint representation - $ntpstamp = $invocant->ntps_to_nbi($ntpstamp); - # Change epoch from 1900 to 1970 - $ntpstamp = $invocant->ntpe_to_unixe_b($ntpstamp); - # And format the result - return $invocant->ubi_to_datestr($ntpstamp, $print_in_local); -} - -=item ntps_to_ldatestr($;$) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->ntps_to_ldatestr($value); - my $result = $convertor->ntps_to_ldatestr($value); - Purpose : Converts 'ntp_stamp' to 'date string' formated in ISO 8601 - Arguments : STRING $ntpstamp - Value to be converted [MANDATORY] - Returns : STRING $datestr - Throws : Dies, if not given any conversion argument - -=cut - -sub ntps_to_ldatestr($;$) -{ - my $invocant = shift; - my ($ntpstamp, ) = @_; - confess "Expected conversion argument not given" unless defined $ntpstamp; - - # Convert the ntpstamp to bigint representation - $ntpstamp = $invocant->ntps_to_nbi($ntpstamp); - # Change epoch from 1900 to 1970 - $ntpstamp = $invocant->ntpe_to_unixe_b($ntpstamp); - # And format the result - return $invocant->ubi_to_datestr($ntpstamp, 1); -} - -#------------------------------------------------------------------------------- - -=item datestr_to_ubi($) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->datestr_to_ubi($value); - my $result = $convertor->datestr_to_ubi($value); - Purpose : Converts 'date string' to 'unix bigint' timestamp - Arguments : STRING $datestr - Value to be converted [MANDATORY] - Returns : BIGINT $bigint - Throws : Dies, if not given any conversion argument - -=cut - -sub datestr_to_ubi($) -{ - my $invocant = shift; - my ($datestr,) = @_; - confess "Expected conversion argument not given" unless defined $datestr; - - # Parse the time string and get the epoch timestamp - my $epoch = str2time($datestr); - # Convert epoch to bigint - return $invocant->unixs_to_ubi($epoch); -} - -=item ubi_to_datestr($;$) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->ubi_to_datestr($value, $print_in_local); - my $result = $convertor->ubi_to_datestr($value, $print_in_local); - Purpose : Converts 'unix bigint' timestamp to 'date string' - Arguments : BIGINT $bigint - Value to be converted [MANDATORY] - Returns : STRING $datestr - Throws : Dies, if not given any conversion argument - -=cut - -sub ubi_to_datestr($;$) -{ - my $invocant = shift; - my ($unixstamp, $print_in_local) = @_; - confess "Expected conversion argument not given" unless defined $unixstamp; - - # Separate seconds and fractions from bigint timestamp - my $s = ($unixstamp >> 32); - my $m = $unixstamp - ($s << 32); - - return $invocant->unixs_to_datestr("$s.$m", $print_in_local); -} - -#------------------------------------------------------------------------------- - -=item datestr_to_nbi($) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->datestr_to_nbi($value); - my $result = $convertor->datestr_to_nbi($value); - Purpose : Converts 'date string' to 'ntp bigint' timestamp - Arguments : STRING $datestr - Value to be converted [MANDATORY] - Returns : BIGINT $bigint - Throws : Dies, if not given any conversion argument - -=cut - -sub datestr_to_nbi($) -{ - my $invocant = shift; - my ($datestr,) = @_; - confess "Expected conversion argument not given" unless defined $datestr; - - # Parse the time string and get the epoch timestamp - my $epoch = str2time($datestr); - # Convert epoch from unix to NTP (1970 -> 1900) - $epoch = $invocant->unixe_to_ntpe($epoch); - # Convert epoch to bigint - return $invocant->unixs_to_ubi($epoch); -} - -=item nbi_to_datestr($;$) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->nbi_to_datestr($value, $print_in_local); - my $result = $convertor->nbi_to_datestr($value, $print_in_local); - Purpose : Converts 'ntp bigint' timestamp to 'date string' - Arguments : BIGINT $bigint - Value to be converted [MANDATORY] - Returns : STRING $datestr - Throws : Dies, if not given any conversion argument - -=cut - -sub nbi_to_datestr($;$) -{ - my $invocant = shift; - my ($bigint, $print_in_local) = @_; - confess "Expected conversion argument not given" unless defined $bigint; - - # Convert epoch from NTP to unix (1900 -> 1970) - $bigint = $invocant->ntpe_to_unixe_b($bigint); - return $invocant->ubi_to_datestr($bigint, $print_in_local); -} - -#------------------------------------------------------------------------------- - -=item periodstr_to_nbis($;$) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->periodstr_to_nbis($value); - my $result = $convertor->periodstr_to_nbis($value); - Purpose : Converts 'period string' to 'ntp bigints' timestamp - Arguments : STRING $datestr - Value to be converted [MANDATORY] - STRING $second - Optional second argument [OPTIONAL] - Returns : BIGINT $bigint - Throws : Dies, if not given any conversion argument - -=cut - -sub periodstr_to_nbis($;$) -{ - my $invocant = shift; - my ($datestr,$second) = @_; - confess "Expected conversion argument not given" unless defined $datestr; - - unless ($second) - { - my $ptrn = $TS_QRS{TS_PERIOD()}; - my @matches = ($datestr =~ /$ptrn/); - ($datestr,$second) = @matches if @matches; - } - confess "Invalid period start time given as argument" unless defined $datestr; - confess "Invalid period end time given as argument" unless defined $second; - - # Convert the IP address to integer - my $min = $invocant->datestr_to_nbi($datestr); - my $max = $invocant->datestr_to_nbi($second); - - return ($min, $max); -} - -=item nbis_to_periodstr($$;$) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->nbis_to_periodstr($min, $max, $print_in_local); - my $result = $convertor->nbis_to_periodstr($min, $max, $print_in_local); - Purpose : Converts 'ntp bigint' timestamp to 'date string' - Arguments : BIGINT $min - Value to be converted [MANDATORY] - BIGINT $max - Value to be converted [MANDATORY] - Returns : STRING $datestr - Throws : Dies, if not given any conversion argument - -=cut - -sub nbis_to_periodstr($$;$) -{ - my $invocant = shift; - my ($min, $max, $print_in_local) = @_; - confess "Expected conversion arguments not given" unless defined $min and defined $max; - - # Convert epoch from NTP to unix (1900 -> 1970) - $min = $invocant->ntpe_to_unixe_b($min); - $max = $invocant->ntpe_to_unixe_b($max); - - return $invocant->ubi_to_datestr($min, $print_in_local) . '..' . $invocant->ubi_to_datestr($max, $print_in_local); -} - -#------------------------------------------------------------------------------- - -=item detect_datetime($) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->detect_datetime($value); - my $result = $convertor->detect_datetime($value); - Purpose : Detect type of date/timestamp - Arguments : STRING $timestamp - Value to be converted [MANDATORY] - Returns : STRING $type - Throws : Dies, if not given any conversion argument - -=cut - -sub detect_datetime($) -{ - my $invocant = shift; - my ($timestamp,) = @_; - confess "Expected conversion argument not given" unless defined $timestamp; - - my ($type, $ptrn, @matches); - foreach my $t (@$QR_TS) - { - ($type, $ptrn) = @$t; - @matches = ($timestamp =~ /$ptrn/); - return ($type, @matches) if @matches; - } - return undef; -} - -#------------------------------------------------------------------------------- - -=item datetime_to_nbi($) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->datetime_to_nbii($value); - my $result = $convertor->datetime_to_nbi($value); - Purpose : Converts any 'datetime' to 'ntp bigint' timestamp - Arguments : STRING $datestr - Value to be converted [MANDATORY] - Returns : BIGINT $bigint - Throws : Dies, if not given any conversion argument - -=cut - -sub datetime_to_nbi($) -{ - my $invocant = shift; - my ($timestamp, $type, @matches) = @_; - confess "Expected conversion argument not given" unless defined $timestamp; - - ($type, @matches) = $invocant->detect_datetime($timestamp) unless $type; - confess "Invalid argument '$timestamp' given" unless $type; - confess "Do not know how to convert $type" unless exists TS_CONVERSIONS()->{$type}; - - my $conversion = TS_CONVERSIONS()->{$type}; - - return ($type, $invocant->$conversion(@matches)) if $conversion; - return (UNKNOWN_TYPE(), $timestamp); -} - -#------------------------------------------------------------------------------- - -=item duration_to_string($) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->duration_to_string($value); - my $result = $convertor->duration_to_string($value); - Purpose : Converts numeric 'duration' to 'string' - Arguments : INTEGER $duration - Value to be converted [MANDATORY] - Returns : STRING $duration_str - Throws : Dies, if not given any conversion argument - -=cut - -sub duration_to_string($) -{ - my $invocant = shift; - my ($duration,) = @_; - confess "Expected conversion argument not given" unless defined $duration; - - my @chunks = (); my $tmp; - $tmp = int($duration / 86400); - if ($tmp) { $duration %= 86400; push(@chunks, sprintf('%dd',$tmp)); } - $tmp = int($duration / 3600); - if ($tmp) { $duration %= 3600; push(@chunks, sprintf('%dh',$tmp)); } - $tmp = int($duration / 60); - if ($tmp) { $duration %= 60; push(@chunks, sprintf('%dm',$tmp)); } - - if (scalar @chunks) { push(@chunks, sprintf('%ds', $duration)) if $duration; } - else { push(@chunks, sprintf('%.4fs', $duration)); } - return join(' ', @chunks); -} - -=item string_to_duration($) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->string_to_duration($value); - my $result = $convertor->string_to_duration($value); - Purpose : Converts string 'duration' to numeric representation - Arguments : INTEGER $duration - Value to be converted [MANDATORY] - Returns : STRING $duration_str - Throws : Dies, if not given any conversion argument - -=cut - -sub string_to_duration($) -{ - my $invocant = shift; - my ($duration,) = @_; - confess "Expected conversion argument not given" unless defined $duration; - - my $numduration = 0; - $duration =~ s/\s+//g; - if ($duration =~ /([\d]+)w/) { $numduration += ( 604800 * $1); $duration =~ s/([\d]+w)//; } - if ($duration =~ /([\d]+)d/) { $numduration += ( 86400 * $1); $duration =~ s/([\d]+d)//; } - if ($duration =~ /([\d]+)h/) { $numduration += ( 3600 * $1); $duration =~ s/([\d]+h)//; } - if ($duration =~ /([\d]+)m/) { $numduration += ( 60 * $1); $duration =~ s/([\d]+m)//; } - - $duration =~ s/s//g; - $numduration += $duration; - - return $numduration; -} - -#------------------------------------------------------------------------------- - -=item list_to_array($) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->list_to_array($value); - my $result = $convertor->list_to_array($value); - Purpose : Converts 'list' to 'array' - Arguments : STRING $list - Value to be converted [MANDATORY] - Returns : ARRAY REFERENCE $array - Throws : Dies, if not given any conversion argument - -=cut - -sub list_to_array($) -{ - my $invocant = shift; - my ($list,) = @_; - confess "Expected conversion argument not given" unless defined $list; - - my @items = split(/[,; ]+/, $list); - return \@items; -} - -=item array_to_list($;$) [PUBLIC,HYBRID] - - Usage : my $result = Value::Convertor->array_to_list($value); - my $result = $convertor->array_to_list($value); - Purpose : Converts 'array' to 'list' - Arguments : ARRAY REFERENCE $array - Value to be converted [MANDATORY] - STRING $separator - string separator [OPTIONAL, DEFAULT = ','] - Returns : STRING $list - Throws : Dies, if not given any conversion argument - -=cut - -sub array_to_list($;$) -{ - my $invocant = shift; - my ($array, $separator) = @_; - confess "Expected conversion argument not given" unless defined $array; - - $separator = ',' unless $separator; - - return join($separator, @$array); -} - -#------------------------------------------------------------------------------- -# Private interface -#------------------------------------------------------------------------------- - -# _init [PROTECTED] -# -# Usage : return $self->_init(@_); -# Purpose : Initialize the new Value::Convertor instance -# Arguments : None -# Returns : Value::Convertor reference -# Throws : Dies, if invoked on class -# Comments : This method must never be called directly, it is supposed to be overloaded by subclasses. - -sub _init -{ - my $self = shift; - confess "Instance method not invoked on object instance" unless blessed($self); - return $self; -} - -# _zero_pad($$$) [PROTECTED] -# -# Usage : my $str = $invocant->_zero_pad($str, $lenght); -# Purpose : Pad string from left or right with zeros to specified length -# Arguments : STRING $str - string to be padded -# INTEGER $len - length of resulting string -# BOOL $right - 0 = pad from left, 1 = pad from right -# Returns : STRING $str -# Throws : Nothing - -sub _zero_pad($$$) -{ - my $invocant = shift; - my ($str, $len, $right) = @_; - - return $str unless $len and int($len); - - my $i; - my $strlen = length($str); - for ($i = 0; $i < $len - $strlen; $i++) - { - unless ($right) { $str = "0" . $str; } - else { $str = $str . "0"; } - } - return $str; -} - -# _zero_pad_n($$$) [PROTECTED] -# -# Usage : my $str = $invocant->_zero_pad_n($str, $mod); -# Purpose : Pad string from left or right with zeros to length with specified -# modulus (for example binary to octets, or hexadecimal to pairs) -# Arguments : STRING $str - string to be padded -# INTEGER $mod - modulus of the length of resulting string -# BOOL $right - 0 = pad from left, 1 = pad from right -# Returns : STRING $str -# Throws : Nothing - -sub _zero_pad_n($$$) -{ - my $invocant = shift; - my ($str, $mod, $right) = @_; - - return $str unless $mod and int($mod); - - my $i; - my $strlen = length($str); - my $short = $strlen % $mod; - - return $str unless $short; - - for ($i = 0; $i < $mod - $short; $i++) - { - unless ($right) { $str = "0" . $str; } - else { $str = $str . "0"; } - } - return $str; -} - -=pod - -=back - -=cut - -1; diff --git a/lib_perl/lib/Value/Duration.pm b/lib_perl/lib/Value/Duration.pm deleted file mode 100644 index a4e5862f4645eace7df46085877e6df3b7c0f17a..0000000000000000000000000000000000000000 --- a/lib_perl/lib/Value/Duration.pm +++ /dev/null @@ -1,140 +0,0 @@ -package Value::Duration; -use strict; -use warnings; - -#******************************************************************************* -# DOCUMENTATION SECTION -#******************************************************************************* - -=head1 NAME - -Value::Duration - Short module description - -=head1 SYNOPSIS - - use Value::Duration; - -=head1 DESCRIPTION - -Extensive module description - -=head1 AUTHOR - -Jan Mach -Cesnet, z.s.p.o -jan.mach@cesnet.cz -http://www.cesnet.cz - -=head1 COPYRIGHT - -This program is free software; you can redistribute -it and/or modify it under the same terms as Perl itself. - -The full text of the license can be found in the -LICENSE file included with this module. - -=head1 SEE ALSO - -perl(1), Value::Single(3). - -=head1 FUNCTION REFERENCE - -=over 4 - -=cut - -#******************************************************************************* -# LIBRARY LOADING SECTION -#******************************************************************************* - -#-- Perl core modules ---------------------------------------------------------# -use Carp; -use Scalar::Util 'blessed'; - -#use Data::Dumper; #-+-> DEVEL ONLY <-+-# - -#-- Perl CPAN modules ---------------------------------------------------------# - -#-- Custom application modules ------------------------------------------------# -use Value::Single; -use Value::Convertor; - -#******************************************************************************* -# CONSTANTS AND GLOBAL VARIABLES DEFINITION SECTION -#******************************************************************************* - -#-- Constants -----------------------------------------------------------------# - -#-- Static public class variables (our) ---------------------------------------# - -#-- Static protected class variables (my) -------------------------------------# - -#******************************************************************************* -# INITIALIZATION AND CLEANUP SECTION -#******************************************************************************* - -#-- Module initializations ----------------------------------------------------# -BEGIN { - use vars qw($VERSION $DEVEL @ISA); - $VERSION = '0.1'; - $DEVEL = 0; - @ISA = ('Value::Single'); -} - - -#-- Module clean-up code (global destructor) ----------------------------------# -END { - -} - -#******************************************************************************* -# IMPLEMENTATION SECTION -#******************************************************************************* - - -=item to_string(;$) [PUBLIC] - - Usage : Will be used automatically to convert object to string in string context - Purpose : Convert the object to string - Arguments : None - Returns : STRING $json - Throws : Croaks, if not invoked on object - Comments : Must be implemented apropriatelly in subclasses - -=cut - -sub to_string(;$) -{ - my $self = shift; - croak ((caller(0))[3] . ": instance method invoked on class") unless blessed($self); - - return Value::Convertor->duration_to_string($self->_value()); -} - -#------------------------------------------------------------------------------- -# Private interface -#------------------------------------------------------------------------------- - -# _to_inner($) [PROTECTED] -# -# Usage : my $value = $self->_to_inner($value); -# Purpose : Convert the given value to appropriate inner representation -# Arguments : MIXED $value - value to be converted [MANDATORY] -# Returns : MIXED $inner -# Throws : Croaks, if invoked on class -# Comments : This method must never be called directly, it is supposed to be overloaded by subclasses. - -sub _to_inner($) -{ - my $invocant = shift; - - return Value::Convertor->string_to_duration(@_); -} - -=pod - -=back - -=cut - -1; diff --git a/lib_perl/lib/Value/IP.pm b/lib_perl/lib/Value/IP.pm deleted file mode 100644 index 5da3cbad662dc4194de88c707d26e2c3f21ceb6f..0000000000000000000000000000000000000000 --- a/lib_perl/lib/Value/IP.pm +++ /dev/null @@ -1,159 +0,0 @@ -package Value::IP; -use strict; -use warnings; - -#******************************************************************************* -# DOCUMENTATION SECTION -#******************************************************************************* - -=head1 NAME - -Value::IPv4 - Short module description - -=head1 SYNOPSIS - - use Value::IPv4; - -=head1 DESCRIPTION - -Extensive module description - -=head1 AUTHOR - -Jan Mach -Cesnet, z.s.p.o -jan.mach@cesnet.cz -http://www.cesnet.cz - -=head1 COPYRIGHT - -This program is free software; you can redistribute -it and/or modify it under the same terms as Perl itself. - -The full text of the license can be found in the -LICENSE file included with this module. - -=head1 SEE ALSO - -perl(1). - -=head1 FUNCTION REFERENCE - -=over 4 - -=cut - -#******************************************************************************* -# LIBRARY LOADING SECTION -#******************************************************************************* - -#-- Perl core modules ---------------------------------------------------------# -use Carp; -use Scalar::Util 'blessed'; - -#use Data::Dumper; #-+-> DEVEL ONLY <-+-# -#use Smart::Comments; #-+-> DEVEL ONLY <-+-# - -#-- Perl CPAN modules ---------------------------------------------------------# - -#-- Custom application modules ------------------------------------------------# -use Value::Convertor; - -use Value::IPv4ADDR; -use Value::IPv4CIDR; -use Value::IPv4NETM; -use Value::IPv4RNG; - -use Value::IPv6ADDR; - -#******************************************************************************* -# CONSTANTS AND GLOBAL VARIABLES DEFINITION SECTION -#******************************************************************************* - -#-- Constants -----------------------------------------------------------------# - -#-- Static public class variables (our) ---------------------------------------# - -#-- Static protected class variables (my) -------------------------------------# - -#******************************************************************************* -# INITIALIZATION AND CLEANUP SECTION -#******************************************************************************* - -#-- Module initializations ----------------------------------------------------# -BEGIN { - use vars qw($VERSION $DEVEL $MAPPING); - $VERSION = '0.1'; - $DEVEL = 0; - $MAPPING = { - Value::Convertor::IPV4ADDR_STRING() => 'Value::IPv4ADDR', - Value::Convertor::IPV4ADDR_HEXSTR() => 'Value::IPv4ADDR', - Value::Convertor::IPV4ADDR_INTEGER() => 'Value::IPv4ADDR', - - Value::Convertor::IPV6ADDR_STRING() => 'Value::IPv6ADDR', - Value::Convertor::IPV6ADDR_HEXSTR() => 'Value::IPv6ADDR', - Value::Convertor::IPV6ADDR_INTEGER() => 'Value::IPv6ADDR', - - Value::Convertor::IPV4CIDR_STRING() => 'Value::IPv4CIDR', - Value::Convertor::IPV4NETM_STRING() => 'Value::IPv4NETM', - Value::Convertor::IPV6CIDR_STRING() => '', - - Value::Convertor::IPV4RNG_STRING() => 'Value::IPv4RNG', - Value::Convertor::IPV4RNG_HEXSTR() => '', - Value::Convertor::IPV4RNG_INTEGER() => '', - - Value::Convertor::IPV6RNG_STRING() => '', - Value::Convertor::IPV6RNG_HEXSTR() => '', - Value::Convertor::IPV6RNG_INTEGER() => '', - }; -} - - -#-- Module clean-up code (global destructor) ----------------------------------# -END { - -} - -#******************************************************************************* -# IMPLEMENTATION SECTION -#******************************************************************************* - -=item new [PUBLIC,STATIC] - - Usage : my $instance = Value::IPv4->new($value); - Purpose : Create and return reference to the new instance - Arguments : - Returns : Value::IPv4 reference on success, croaks on failure - Throws : Croaks, if invoked on object - Comments : Internally uses _init() method, subclasses should never overload this method. - See Also : _init() method - -=cut - -sub new -{ - my $class = shift; - confess "Class method not invoked on class" if blessed($class); - my ($value, $type) = @_; - confess "IP address expected to be given as argument" unless $value; - - my (@matches, $class_name); - - # Autodetect the type of the value - ($type, @matches) = Value::Convertor->detect_ip($value) unless $type; - confess "Unknown IP address value '$value', type could not be detected" unless $type; - - # Determine the appropriate class for representing given IP address type - $class_name = $MAPPING->{$type} if exists $MAPPING->{$type}; - confess "Unknown IP address type '$type' for value $value" unless $class_name; - - return $class_name->new($value); -} - -=pod - -=back - -=cut - -1; diff --git a/lib_perl/lib/Value/IPv4ADDR.pm b/lib_perl/lib/Value/IPv4ADDR.pm deleted file mode 100644 index d8e6f4594438e0152e8d7b1c53a75d96c28171c7..0000000000000000000000000000000000000000 --- a/lib_perl/lib/Value/IPv4ADDR.pm +++ /dev/null @@ -1,141 +0,0 @@ -package Value::IPv4ADDR; -use strict; -use warnings; - -#******************************************************************************* -# DOCUMENTATION SECTION -#******************************************************************************* - -=head1 NAME - -Value::IPv4ADDR - Short module description - -=head1 SYNOPSIS - - use Value::IPv4ADDR; - -=head1 DESCRIPTION - -Extensive module description - -=head1 AUTHOR - -Jan Mach -Cesnet, z.s.p.o -jan.mach@cesnet.cz -http://www.cesnet.cz - -=head1 COPYRIGHT - -This program is free software; you can redistribute -it and/or modify it under the same terms as Perl itself. - -The full text of the license can be found in the -LICENSE file included with this module. - -=head1 SEE ALSO - -perl(1), Value::Single(3). - -=head1 FUNCTION REFERENCE - -=over 4 - -=cut - -#******************************************************************************* -# LIBRARY LOADING SECTION -#******************************************************************************* - -#-- Perl core modules ---------------------------------------------------------# -use Carp; -use Scalar::Util 'blessed'; - -#use Data::Dumper; #-+-> DEVEL ONLY <-+-# - -#-- Perl CPAN modules ---------------------------------------------------------# - -#-- Custom application modules ------------------------------------------------# -use Value::Single; -use Value::Convertor; - -#******************************************************************************* -# CONSTANTS AND GLOBAL VARIABLES DEFINITION SECTION -#******************************************************************************* - -#-- Constants -----------------------------------------------------------------# -use constant DEFAULT_FORMATER => 'int_to_ipv4str'; - -#-- Static public class variables (our) ---------------------------------------# - -#-- Static protected class variables (my) -------------------------------------# - -#******************************************************************************* -# INITIALIZATION AND CLEANUP SECTION -#******************************************************************************* - -#-- Module initializations ----------------------------------------------------# -BEGIN { - use vars qw($VERSION $DEVEL @ISA); - $VERSION = '0.1'; - $DEVEL = 0; - @ISA = ('Value::Single'); -} - - -#-- Module clean-up code (global destructor) ----------------------------------# -END { - -} - -#******************************************************************************* -# IMPLEMENTATION SECTION -#******************************************************************************* - -=item to_string(;$) [PUBLIC] - - Usage : Will be used automatically to convert object to string in string context - Purpose : Convert the object to string - Arguments : None - Returns : STRING $json - Throws : Croaks, if not invoked on object - Comments : Must be implemented apropriatelly in subclasses - -=cut - -sub to_string(;$) -{ - my $self = shift; - croak ((caller(0))[3] . ": instance method invoked on class") unless blessed($self); - - return Value::Convertor->int_to_ipv4str($self->_value()); -} - -#------------------------------------------------------------------------------- -# Private interface -#------------------------------------------------------------------------------- - -# _to_inner($) [PROTECTED] -# -# Usage : my $value = $self->_to_inner($value); -# Purpose : Convert the given value to appropriate inner representation -# Arguments : MIXED $value - value to be converted [MANDATORY] -# Returns : MIXED $inner -# Throws : Croaks, if invoked on class -# Comments : This method must never be called directly, it is supposed to be overloaded by subclasses. - -sub _to_inner($) -{ - my $invocant = shift; - - my ($type,$value) = Value::Convertor->ipv4_to_int(@_); - return $value; -} - -=pod - -=back - -=cut - -1; diff --git a/lib_perl/lib/Value/IPv4CIDR.pm b/lib_perl/lib/Value/IPv4CIDR.pm deleted file mode 100644 index b9da59fd5b93a0d111277cbefbde5004e98e11a3..0000000000000000000000000000000000000000 --- a/lib_perl/lib/Value/IPv4CIDR.pm +++ /dev/null @@ -1,140 +0,0 @@ -package Value::IPv4CIDR; -use strict; -use warnings; - -#******************************************************************************* -# DOCUMENTATION SECTION -#******************************************************************************* - -=head1 NAME - -Value::IPv4CIDR - Short module description - -=head1 SYNOPSIS - - use Value::IPv4CIDR; - -=head1 DESCRIPTION - -Extensive module description - -=head1 AUTHOR - -Jan Mach -Cesnet, z.s.p.o -jan.mach@cesnet.cz -http://www.cesnet.cz - -=head1 COPYRIGHT - -This program is free software; you can redistribute -it and/or modify it under the same terms as Perl itself. - -The full text of the license can be found in the -LICENSE file included with this module. - -=head1 SEE ALSO - -perl(1), Value::Range(3). - -=head1 FUNCTION REFERENCE - -=over 4 - -=cut - -#******************************************************************************* -# LIBRARY LOADING SECTION -#******************************************************************************* - -#-- Perl core modules ---------------------------------------------------------# -use Carp; -use Scalar::Util 'blessed'; - -#use Data::Dumper; #-+-> DEVEL ONLY <-+-# - -#-- Perl CPAN modules ---------------------------------------------------------# - -#-- Custom application modules ------------------------------------------------# -use Value::Range; -use Value::Convertor; - -#******************************************************************************* -# CONSTANTS AND GLOBAL VARIABLES DEFINITION SECTION -#******************************************************************************* - -#-- Constants -----------------------------------------------------------------# - -#-- Static public class variables (our) ---------------------------------------# - -#-- Static protected class variables (my) -------------------------------------# - -#******************************************************************************* -# INITIALIZATION AND CLEANUP SECTION -#******************************************************************************* - -#-- Module initializations ----------------------------------------------------# -BEGIN { - use vars qw($VERSION $DEVEL @ISA); - $VERSION = '0.1'; - $DEVEL = 0; - @ISA = ('Value::Range'); -} - - -#-- Module clean-up code (global destructor) ----------------------------------# -END { - -} - -#******************************************************************************* -# IMPLEMENTATION SECTION -#******************************************************************************* - -=item to_string() [PUBLIC] - - Usage : Will be used automatically to convert object to string in string context - Purpose : Convert the object to string - Arguments : None - Returns : STRING $json - Throws : Croaks, if not invoked on object - Comments : Must be implemented apropriatelly in subclasses - -=cut - -sub to_string() -{ - my $self = shift; - croak ((caller(0))[3] . ": instance method invoked on class") unless blessed($self); - - return Value::Convertor->ints_to_ipv4cidr($self->_values()); -} - -#------------------------------------------------------------------------------- -# Private interface -#------------------------------------------------------------------------------- - -# _to_inner($) [PROTECTED] -# -# Usage : my $value = $self->_to_inner($value); -# Purpose : Convert the given value to appropriate inner representation -# Arguments : MIXED $value - value to be converted [MANDATORY] -# Returns : MIXED $inner -# Throws : Croaks, if invoked on class -# Comments : This method must never be called directly, it is supposed to be overloaded by subclasses. - -sub _to_inner($) -{ - my $invocant = shift; - - my ($type,@values) = Value::Convertor->ipv4_to_int(@_); - return @values; -} - -=pod - -=back - -=cut - -1; diff --git a/lib_perl/lib/Value/IPv4NETM.pm b/lib_perl/lib/Value/IPv4NETM.pm deleted file mode 100644 index 2ca2bf9b159fb2c6bf11b1bfd51abcaf5496a400..0000000000000000000000000000000000000000 --- a/lib_perl/lib/Value/IPv4NETM.pm +++ /dev/null @@ -1,140 +0,0 @@ -package Value::IPv4NETM; -use strict; -use warnings; - -#******************************************************************************* -# DOCUMENTATION SECTION -#******************************************************************************* - -=head1 NAME - -Value::IPv4NETM - Short module description - -=head1 SYNOPSIS - - use Value::IPv4NETM; - -=head1 DESCRIPTION - -Extensive module description - -=head1 AUTHOR - -Jan Mach -Cesnet, z.s.p.o -jan.mach@cesnet.cz -http://www.cesnet.cz - -=head1 COPYRIGHT - -This program is free software; you can redistribute -it and/or modify it under the same terms as Perl itself. - -The full text of the license can be found in the -LICENSE file included with this module. - -=head1 SEE ALSO - -perl(1), Value::Range(3). - -=head1 FUNCTION REFERENCE - -=over 4 - -=cut - -#******************************************************************************* -# LIBRARY LOADING SECTION -#******************************************************************************* - -#-- Perl core modules ---------------------------------------------------------# -use Carp; -use Scalar::Util 'blessed'; - -#use Data::Dumper; #-+-> DEVEL ONLY <-+-# - -#-- Perl CPAN modules ---------------------------------------------------------# - -#-- Custom application modules ------------------------------------------------# -use Value::Range; -use Value::Convertor; - -#******************************************************************************* -# CONSTANTS AND GLOBAL VARIABLES DEFINITION SECTION -#******************************************************************************* - -#-- Constants -----------------------------------------------------------------# - -#-- Static public class variables (our) ---------------------------------------# - -#-- Static protected class variables (my) -------------------------------------# - -#******************************************************************************* -# INITIALIZATION AND CLEANUP SECTION -#******************************************************************************* - -#-- Module initializations ----------------------------------------------------# -BEGIN { - use vars qw($VERSION $DEVEL @ISA); - $VERSION = '0.1'; - $DEVEL = 0; - @ISA = ('Value::Range'); -} - - -#-- Module clean-up code (global destructor) ----------------------------------# -END { - -} - -#******************************************************************************* -# IMPLEMENTATION SECTION -#******************************************************************************* - -=item to_string() [PUBLIC] - - Usage : Will be used automatically to convert object to string in string context - Purpose : Convert the object to string - Arguments : None - Returns : STRING $json - Throws : Croaks, if not invoked on object - Comments : Must be implemented apropriatelly in subclasses - -=cut - -sub to_string() -{ - my $self = shift; - croak ((caller(0))[3] . ": instance method invoked on class") unless blessed($self); - - return Value::Convertor->ints_to_ipv4netm($self->_values()); -} - -#------------------------------------------------------------------------------- -# Private interface -#------------------------------------------------------------------------------- - -# _to_inner($) [PROTECTED] -# -# Usage : my $value = $self->_to_inner($value); -# Purpose : Convert the given value to appropriate inner representation -# Arguments : MIXED $value - value to be converted [MANDATORY] -# Returns : MIXED $inner -# Throws : Croaks, if invoked on class -# Comments : This method must never be called directly, it is supposed to be overloaded by subclasses. - -sub _to_inner($) -{ - my $invocant = shift; - - my ($type,@values) = Value::Convertor->ipv4_to_int(@_); - return @values; -} - -=pod - -=back - -=cut - -1; diff --git a/lib_perl/lib/Value/IPv4RNG.pm b/lib_perl/lib/Value/IPv4RNG.pm deleted file mode 100644 index 5409a7ee14eaa22b5956001c482bea5d34199423..0000000000000000000000000000000000000000 --- a/lib_perl/lib/Value/IPv4RNG.pm +++ /dev/null @@ -1,140 +0,0 @@ -package Value::IPv4RNG; -use strict; -use warnings; - -#******************************************************************************* -# DOCUMENTATION SECTION -#******************************************************************************* - -=head1 NAME - -Value::IPv4RNG - Short module description - -=head1 SYNOPSIS - - use Value::IPv4RNG; - -=head1 DESCRIPTION - -Extensive module description - -=head1 AUTHOR - -Jan Mach -Cesnet, z.s.p.o -jan.mach@cesnet.cz -http://www.cesnet.cz - -=head1 COPYRIGHT - -This program is free software; you can redistribute -it and/or modify it under the same terms as Perl itself. - -The full text of the license can be found in the -LICENSE file included with this module. - -=head1 SEE ALSO - -perl(1), Value::Range(3). - -=head1 FUNCTION REFERENCE - -=over 4 - -=cut - -#******************************************************************************* -# LIBRARY LOADING SECTION -#******************************************************************************* - -#-- Perl core modules ---------------------------------------------------------# -use Carp; -use Scalar::Util 'blessed'; - -#use Data::Dumper; #-+-> DEVEL ONLY <-+-# - -#-- Perl CPAN modules ---------------------------------------------------------# - -#-- Custom application modules ------------------------------------------------# -use Value::Range; -use Value::Convertor; - -#******************************************************************************* -# CONSTANTS AND GLOBAL VARIABLES DEFINITION SECTION -#******************************************************************************* - -#-- Constants -----------------------------------------------------------------# - -#-- Static public class variables (our) ---------------------------------------# - -#-- Static protected class variables (my) -------------------------------------# - -#******************************************************************************* -# INITIALIZATION AND CLEANUP SECTION -#******************************************************************************* - -#-- Module initializations ----------------------------------------------------# -BEGIN { - use vars qw($VERSION $DEVEL @ISA); - $VERSION = '0.1'; - $DEVEL = 0; - @ISA = ('Value::Range'); -} - - -#-- Module clean-up code (global destructor) ----------------------------------# -END { - -} - -#******************************************************************************* -# IMPLEMENTATION SECTION -#******************************************************************************* - -=item to_string() [PUBLIC] - - Usage : Will be used automatically to convert object to string in string context - Purpose : Convert the object to string - Arguments : None - Returns : STRING $json - Throws : Croaks, if not invoked on object - Comments : Must be implemented apropriatelly in subclasses - -=cut - -sub to_string() -{ - my $self = shift; - croak ((caller(0))[3] . ": instance method invoked on class") unless blessed($self); - - return Value::Convertor->ints_to_ipv4rngstr($self->_values()); -} - -#------------------------------------------------------------------------------- -# Private interface -#------------------------------------------------------------------------------- - -# _to_inner($) [PROTECTED] -# -# Usage : my $value = $self->_to_inner($value); -# Purpose : Convert the given value to appropriate inner representation -# Arguments : MIXED $value - value to be converted [MANDATORY] -# Returns : MIXED $inner -# Throws : Croaks, if invoked on class -# Comments : This method must never be called directly, it is supposed to be overloaded by subclasses. - -sub _to_inner($) -{ - my $invocant = shift; - - my ($type,@values) = Value::Convertor->ipv4_to_int(@_); - return @values; -} - -=pod - -=back - -=cut - -1; diff --git a/lib_perl/lib/Value/IPv6ADDR.pm b/lib_perl/lib/Value/IPv6ADDR.pm deleted file mode 100644 index 761e76a06232977145f6bc6f0997567866e8107c..0000000000000000000000000000000000000000 --- a/lib_perl/lib/Value/IPv6ADDR.pm +++ /dev/null @@ -1,140 +0,0 @@ -package Value::IPv6ADDR; -use strict; -use warnings; - -#******************************************************************************* -# DOCUMENTATION SECTION -#******************************************************************************* - -=head1 NAME - -Value::IPv6ADDR - Short module description - -=head1 SYNOPSIS - - use Value::IPv6ADDR; - -=head1 DESCRIPTION - -Extensive module description - -=head1 AUTHOR - -Jan Mach -Cesnet, z.s.p.o -jan.mach@cesnet.cz -http://www.cesnet.cz - -=head1 COPYRIGHT - -This program is free software; you can redistribute -it and/or modify it under the same terms as Perl itself. - -The full text of the license can be found in the -LICENSE file included with this module. - -=head1 SEE ALSO - -perl(1), Value::Single(3). - -=head1 FUNCTION REFERENCE - -=over 4 - -=cut - -#******************************************************************************* -# LIBRARY LOADING SECTION -#******************************************************************************* - -#-- Perl core modules ---------------------------------------------------------# -use Carp; -use Scalar::Util 'blessed'; - -#use Data::Dumper; #-+-> DEVEL ONLY <-+-# - -#-- Perl CPAN modules ---------------------------------------------------------# - -#-- Custom application modules ------------------------------------------------# -use Value::Single; -use Value::Convertor; - -#******************************************************************************* -# CONSTANTS AND GLOBAL VARIABLES DEFINITION SECTION -#******************************************************************************* - -#-- Constants -----------------------------------------------------------------# - -#-- Static public class variables (our) ---------------------------------------# - -#-- Static protected class variables (my) -------------------------------------# - -#******************************************************************************* -# INITIALIZATION AND CLEANUP SECTION -#******************************************************************************* - -#-- Module initializations ----------------------------------------------------# -BEGIN { - use vars qw($VERSION $DEVEL @ISA); - $VERSION = '0.1'; - $DEVEL = 0; - @ISA = ('Value::Single'); -} - - -#-- Module clean-up code (global destructor) ----------------------------------# -END { - -} - -#******************************************************************************* -# IMPLEMENTATION SECTION -#******************************************************************************* - -=item to_string() [PUBLIC] - - Usage : Will be used automatically to convert object to string in string context - Purpose : Convert the object to string - Arguments : None - Returns : STRING $json - Throws : Croaks, if not invoked on object - Comments : Must be implemented apropriatelly in subclasses - -=cut - -sub to_string() -{ - my $self = shift; - croak ((caller(0))[3] . ": instance method invoked on class") unless blessed($self); - - return Value::Convertor->bigint_to_ipv6str($self->_value()); -} - -#------------------------------------------------------------------------------- -# Private interface -#------------------------------------------------------------------------------- - -# _to_inner($) [PROTECTED] -# -# Usage : my $value = $self->_to_inner($value); -# Purpose : Convert the given value to appropriate inner representation -# Arguments : MIXED $value - value to be converted [MANDATORY] -# Returns : MIXED $inner -# Throws : Croaks, if invoked on class -# Comments : This method must never be called directly, it is supposed to be overloaded by subclasses. - -sub _to_inner($) -{ - my $invocant = shift; - - my ($type,$value) = Value::Convertor->ipv6_to_bigint(@_); - return $value; -} - -=pod - -=back - -=cut - -1; diff --git a/lib_perl/lib/Value/Period.pm b/lib_perl/lib/Value/Period.pm deleted file mode 100644 index 869c49a5549a83dd2ed28bc329901b62ca9a76bb..0000000000000000000000000000000000000000 --- a/lib_perl/lib/Value/Period.pm +++ /dev/null @@ -1,141 +0,0 @@ -package Value::Period; -use strict; -use warnings; - -#******************************************************************************* -# DOCUMENTATION SECTION -#******************************************************************************* - -=head1 NAME - -Value::Period - Short module description - -=head1 SYNOPSIS - - use Value::Period; - -=head1 DESCRIPTION - -Extensive module description - -=head1 AUTHOR - -Jan Mach -Cesnet, z.s.p.o -jan.mach@cesnet.cz -http://www.cesnet.cz - -=head1 COPYRIGHT - -This program is free software; you can redistribute -it and/or modify it under the same terms as Perl itself. - -The full text of the license can be found in the -LICENSE file included with this module. - -=head1 SEE ALSO - -perl(1), Value::Range(3). - -=head1 FUNCTION REFERENCE - -=over 4 - -=cut - -#******************************************************************************* -# LIBRARY LOADING SECTION -#******************************************************************************* - -#-- Perl core modules ---------------------------------------------------------# -use Carp; -use Scalar::Util 'blessed'; - -#use Data::Dumper; #-+-> DEVEL ONLY <-+-# - -#-- Perl CPAN modules ---------------------------------------------------------# - -#-- Custom application modules ------------------------------------------------# -use Value::Range; -use Value::Convertor; - -#******************************************************************************* -# CONSTANTS AND GLOBAL VARIABLES DEFINITION SECTION -#******************************************************************************* - -#-- Constants -----------------------------------------------------------------# - -#-- Static public class variables (our) ---------------------------------------# - -#-- Static protected class variables (my) -------------------------------------# - -#******************************************************************************* -# INITIALIZATION AND CLEANUP SECTION -#******************************************************************************* - -#-- Module initializations ----------------------------------------------------# -BEGIN { - use vars qw($VERSION $DEVEL @ISA); - $VERSION = '0.1'; - $DEVEL = 0; - @ISA = ('Value::Range'); -} - - -#-- Module clean-up code (global destructor) ----------------------------------# -END { - -} - -#******************************************************************************* -# IMPLEMENTATION SECTION -#******************************************************************************* - -=item to_string(;$) [PUBLIC] - - Usage : Will be used automatically to convert object to string in string context - Purpose : Convert the object to string - Arguments : None - Returns : STRING $json - Throws : Croaks, if not invoked on object - Comments : Must be implemented apropriatelly in subclasses - -=cut - -sub to_string(;$) -{ - my $self = shift; - croak ((caller(0))[3] . ": instance method invoked on class") unless blessed($self); - - return join('..', map { Value::Convertor->nbi_to_datestr($_, @_); } $self->_values()); -} - -#------------------------------------------------------------------------------- -# Private interface -#------------------------------------------------------------------------------- - -# _to_inner($) [PROTECTED] -# -# Usage : my $value = $self->_to_inner($value); -# Purpose : Convert the given value to appropriate inner representation -# Arguments : MIXED $value - value to be converted [MANDATORY] -# Returns : MIXED $inner -# Throws : Croaks, if invoked on class -# Comments : This method must never be called directly, it is supposed to be overloaded by subclasses. - -sub _to_inner($) -{ - my $invocant = shift; - my ($period,) = @_; - - my ($type,@values) = Value::Convertor->datetime_to_nbi(@_); - return @values; -} - -=pod - -=back - -=cut - -1; diff --git a/lib_perl/lib/Value/Range.pm b/lib_perl/lib/Value/Range.pm deleted file mode 100644 index c58a7ff43f5e94767e13734bb39429a4b920c137..0000000000000000000000000000000000000000 --- a/lib_perl/lib/Value/Range.pm +++ /dev/null @@ -1,354 +0,0 @@ -package Value::Range; -use strict; -use warnings; - -#******************************************************************************* -# DOCUMENTATION SECTION -#******************************************************************************* - -=head1 NAME - -Value::Range - Short module description - -=head1 SYNOPSIS - - use Value::Range; - -=head1 DESCRIPTION - -Extensive module description - -=head1 AUTHOR - -Jan Mach -Cesnet, z.s.p.o -jan.mach@cesnet.cz -http://www.cesnet.cz - -=head1 COPYRIGHT - -This program is free software; you can redistribute -it and/or modify it under the same terms as Perl itself. - -The full text of the license can be found in the -LICENSE file included with this module. - -=head1 SEE ALSO - -perl(1). - -=head1 FUNCTION REFERENCE - -=over 4 - -=cut - -#******************************************************************************* -# LIBRARY LOADING SECTION -#******************************************************************************* - -#-- Perl core modules ---------------------------------------------------------# -use Carp; -use Scalar::Util 'blessed'; - -#use Data::Dumper; #-+-> DEVEL ONLY <-+-# - -#-- Perl CPAN modules ---------------------------------------------------------# - -#-- Custom application modules ------------------------------------------------# - -#******************************************************************************* -# CONSTANTS AND GLOBAL VARIABLES DEFINITION SECTION -#******************************************************************************* - -#-- Constants -----------------------------------------------------------------# - -#-- Static public class variables (our) ---------------------------------------# - -#-- Static protected class variables (my) -------------------------------------# - -#******************************************************************************* -# INITIALIZATION AND CLEANUP SECTION -#******************************************************************************* - -#-- Module initializations ----------------------------------------------------# -BEGIN { - use vars qw($VERSION $DEVEL); - $VERSION = '0.1'; - $DEVEL = 0; -} - - -#-- Module clean-up code (global destructor) ----------------------------------# -END { - -} - -# Operator overloading -use overload - '""' => 'to_string', - '<=>' => 'cmp_numeric', - 'cmp' => 'cmp_string'; - -#******************************************************************************* -# IMPLEMENTATION SECTION -#******************************************************************************* - -=item new [PUBLIC,STATIC] - - Usage : my $instance = Value::Range->new(); - Purpose : Create and return reference to the new instance - Arguments : Same as the the _init() method - Returns : Value::Range reference on success, croaks on failure - Throws : Croaks, if invoked on object - Comments : Internally uses _init() method, subclasses should never overload this method. - See Also : _init() method - -=cut - -sub new -{ - my $class = shift; - croak ((caller(0))[3] . ": class method invoked on object") if blessed($class); - my @values = @_; - croak ((caller(0))[3] . ": expecting arguments to be given to constructor") unless @values; - - my $self = bless ({}, $class); - $self->_values($class->_to_inner(@values)); - return $self; -} - -=item type() [PUBLIC] - - Usage : my $name = $value->type(); - Purpose : - Returns : - Arguments : - Throws : - Comments : - See Also : - -=cut - -sub type() -{ - my $self = shift; - croak ((caller(0))[3] . ": instance method invoked on class") unless blessed($self); - - # Determine the type of the value (last part of the class name) - unless ($self->{TYPE}) { - my $name = blessed($self); - my @tmp = split(/:+/, $name); - $self->{TYPE} = lc($tmp[$#tmp]); - } - return $self->{TYPE}; -} - -=item to_numeric() [PUBLIC] - - Usage : Will be used automatically to convert object to integer in numeric context - Purpose : Convert the object to integer - Arguments : None - Returns : INTEGER|BIGINT $numeric - Throws : Croaks, if not invoked on object - -=cut - -sub to_numeric() -{ - my $self = shift; - croak ((caller(0))[3] . ": instance method invoked on class") unless blessed($self); - return $self->_values(); -} - -=item to_string() [PUBLIC] - - Usage : Will be used automatically to convert object to string in string context - Purpose : Convert the object to string - Arguments : None - Returns : STRING $json - Throws : Croaks, if not invoked on object - Comments : Must be implemented apropriatelly in subclasses - -=cut - -sub to_string() -{ - my $self = shift; - croak ((caller(0))[3] . ": instance method invoked on class") unless blessed($self); - my ($min, $max) = $self->_values(); - return "$min-$max"; -} - -=item cmp_numeric() [PUBLIC] - - Usage : Will be used automatically in integer comparison context (==,!=,<,>,<=,>=,<=>) - Purpose : Allow integer comparisons (==,!=,<,>,<=,>=,<=>) - Arguments : Value::Range $self - left comparison operand - MIXED $other - right comparison operand - BOOL $swap - swap left and right operand - Returns : INTEGER $result (-1, 0, or 1) if the left operand is stringwise - (less than, equal, greater than) the right operator - Throws : Croaks, if not invoked on object - Comments : Must be implemented apropriatelly in subclasses - -=cut - -sub cmp_numeric() -{ - my ($self, $other, $swap) = @_; - croak ((caller(0))[3] . ": instance method invoked on class") unless blessed($self); - - if (blessed($other)) { - if ($other->isa('Value::Range')) { - my ($omin, $omax) = $other->to_numeric(); - return $self->_cmp_numeric_range($omin, $omax, $swap); - } - elsif ($other->isa('Value::Single')) { - my $omin = $other->to_numeric(); - return $self->_cmp_numeric_single($omin, $swap); - } - } - else { - my ($omin, $omax) = $self->_to_inner($other); - - return $self->_cmp_numeric_range($omin, $omax, $swap) if $omax; - return $self->_cmp_numeric_single($omin, $swap); - } -} - - -=item cmp_string($$$) [PUBLIC] - - Usage : Will be used automatically in string comparison context (eq,ne,gt,lt,ge,le,cmp) - Purpose : Allow string comparisons (eq,ne,gt,lt,ge,le,cmp) - Arguments : Value::Range $self - left comparison operand - MIXED $other - right comparison operand - BOOL $swap - swap left and right operand - Returns : INTEGER $result (-1, 0, or 1) if the left operand is stringwise - (less than, equal, greater than) the right operator - Throws : Croaks, if not invoked on object - Comments : Must be implemented apropriatelly in subclasses - -=cut - -sub cmp_string($$$) -{ - my ($self, $other, $swap) = @_; - croak ((caller(0))[3] . ": instance method invoked on class") unless blessed($self); - return $self->cmp_numeric($other, $swap); -} - -=item TO_JSON() [PUBLIC] - - Usage : Will be used automatically by Perl's JSON library - Purpose : This method allows exporting objects to JSON - Arguments : None - Returns : STRING $string - Throws : Croaks, if not invoked on object - Comments : Internally uses _init() method, subclasses should never overload this method. - See Also : http://search.cpan.org/~makamaka/JSON-2.57/lib/JSON.pm#allow_blessed - -=cut - -sub TO_JSON() -{ - my $self = shift; - croak ((caller(0))[3] . ": instance method invoked on class") unless blessed($self); - return $self->to_string(); -} - -#------------------------------------------------------------------------------- -# Private interface -#------------------------------------------------------------------------------- - -# _values(;@) [PROTECTED] -# -# Usage : -# Purpose : -# Arguments : -# Returns : -# Throws : Croaks, if invoked on class -# Comments : - -sub _values(;@) -{ - my $self = shift; - croak ((caller(0))[3] . ": instance method invoked on class") unless blessed($self); - my @new_values = @_; - - if (@new_values) { - ($self->{MIN}, $self->{MAX}) = @new_values; - croak ((caller(0))[3] . ": range minimum must be given as first argument") unless defined $self->{MIN}; - $self->{MAX} = $self->{MIN} unless defined $self->{MAX}; - croak ((caller(0))[3] . ": range minimum must be less than or equal maximum") unless $self->{MIN} <= $self->{MAX}; - } - - return ($self->{MIN}, $self->{MAX}); -} - -# _to_inner($) [PROTECTED] -# -# Usage : my @values = $self->_to_inner($value); -# Purpose : Convert the given value to appropriate inner representation -# Arguments : MIXED $value - value to be converted [MANDATORY] -# Returns : MIXED @inner -# Throws : Croaks, if invoked on class -# Comments : This method must never be called directly, it is supposed to be overloaded by subclasses. - -sub _to_inner($) -{ - my $invocant = shift; - - return (map { split('-',$_); } @_); -} - -# _cmp_numeric_range($$$$) [PROTECTED] -# -# Usage : -# Purpose : -# Arguments : -# Returns : -# Throws : Croaks, if invoked on class -# Comments : - -sub _cmp_numeric_range($$$$) -{ - my ($self, $omin, $omax, $swap) = @_; - croak ((caller(0))[3] . ": instance method invoked on class") unless blessed($self); - - my ($min, $max) = $self->to_numeric(); - ($min, $max, $omin, $omax) = ($omin, $omax, $min, $max) if $swap; - - return 0 if (($min == $omin) and ($max == $omax)); - return -1 if (($min >= $omin) and ($max <= $omax)); - return 1; -} - -# _cmp_numeric_single($$$) [PROTECTED] -# -# Usage : -# Purpose : -# Arguments : -# Returns : -# Throws : Croaks, if invoked on class -# Comments : - -sub _cmp_numeric_single($$$) -{ - my ($self, $other_min, $swap) = @_; - croak ((caller(0))[3] . ": instance method invoked on class") unless blessed($self); - - my ($min, $max) = $self->to_numeric(); - - return 0 if ($min <= $other_min) and ($other_min <= $max); - return 1; -} - -=pod - -=back - -=cut - -1; diff --git a/lib_perl/lib/Value/Single.pm b/lib_perl/lib/Value/Single.pm deleted file mode 100644 index 11f5d0d0789e5d4acc6918427b85f30c770249cc..0000000000000000000000000000000000000000 --- a/lib_perl/lib/Value/Single.pm +++ /dev/null @@ -1,310 +0,0 @@ -package Value::Single; -use strict; -use warnings; - -#******************************************************************************* -# DOCUMENTATION SECTION -#******************************************************************************* - -=head1 NAME - -Value::Single - Short module description - -=head1 SYNOPSIS - - use Value::Single; - -=head1 DESCRIPTION - -Extensive module description - -=head1 AUTHOR - -Jan Mach -Cesnet, z.s.p.o -jan.mach@cesnet.cz -http://www.cesnet.cz - -=head1 COPYRIGHT - -This program is free software; you can redistribute -it and/or modify it under the same terms as Perl itself. - -The full text of the license can be found in the -LICENSE file included with this module. - -=head1 SEE ALSO - -perl(1). - -=head1 FUNCTION REFERENCE - -=over 4 - -=cut - -#******************************************************************************* -# LIBRARY LOADING SECTION -#******************************************************************************* - -#-- Perl core modules ---------------------------------------------------------# -use Carp; -use Scalar::Util 'blessed'; - -#use Data::Dumper; #-+-> DEVEL ONLY <-+-# - -#-- Perl CPAN modules ---------------------------------------------------------# - -#-- Custom application modules ------------------------------------------------# - -#******************************************************************************* -# CONSTANTS AND GLOBAL VARIABLES DEFINITION SECTION -#******************************************************************************* - -#-- Constants -----------------------------------------------------------------# - -#-- Static public class variables (our) ---------------------------------------# - -#-- Static protected class variables (my) -------------------------------------# - -#******************************************************************************* -# INITIALIZATION AND CLEANUP SECTION -#******************************************************************************* - -#-- Module initializations ----------------------------------------------------# -BEGIN { - use vars qw($VERSION $DEVEL); - $VERSION = '0.1'; - $DEVEL = 0; -} - - -#-- Module clean-up code (global destructor) ----------------------------------# -END { - -} - -# Operator overloading -use overload - '0+' => 'to_numeric', - '""' => 'to_string', - '<=>' => 'cmp_numeric', - 'cmp' => 'cmp_string'; - -#******************************************************************************* -# IMPLEMENTATION SECTION -#******************************************************************************* - -=item new [PUBLIC,STATIC] - - Usage : my $instance = Value::Single->new($value); - Purpose : Create and return reference to the new instance - Arguments : Same as the the _init() method - Returns : Value::Single reference on success, croaks on failure - Throws : Croaks, if invoked on object - Comments : Internally uses _init() method, subclasses should never overload this method. - See Also : _init() method - -=cut - -sub new -{ - my $class = shift; - confess "Class method invoked on object" if blessed($class); - my ($value,) = @_; - croak ((caller(0))[3] . ": expecting argument to be given to constructor") unless defined $value; - - my $self = bless ({}, $class); - $self->_value($class->_to_inner($value)); - return $self; -} - -=item type() [PUBLIC] - - Usage : my $name = $value->type(); - Purpose : - Returns : - Arguments : - Throws : - Comments : - See Also : - -=cut - -sub type() -{ - my $self = shift; - croak ((caller(0))[3] . ": instance method invoked on class") unless blessed($self); - - # Determine the type of the value (last part of the class name) - unless ($self->{TYPE}) - { - my $name = blessed($self); - my @tmp = split(/:+/, $name); - $self->{TYPE} = lc($tmp[$#tmp]); - } - return $self->{TYPE}; -} - -=item to_numeric() [PUBLIC] - - Usage : Will be used automatically to convert object to integer in numeric context - Purpose : Convert the object to integer - Arguments : None - Returns : INTEGER|BIGINT $numeric - Throws : Croaks, if not invoked on object - -=cut - -sub to_numeric() -{ - my $self = shift; - croak ((caller(0))[3] . ": instance method invoked on class") unless blessed($self); - return $self->_value(); -} - -=item to_string() [PUBLIC] - - Usage : Will be used automatically to convert object to string in string context - Purpose : Convert the object to string - Arguments : None - Returns : STRING $json - Throws : Croaks, if not invoked on object - Comments : Must be implemented apropriatelly in subclasses - -=cut - -sub to_string() -{ - my $self = shift; - croak ((caller(0))[3] . ": instance method invoked on class") unless blessed($self); - return "" . $self->_value(); -} - -=item cmp_numeric($$$) [PUBLIC] - - Usage : Will be used automatically in integer comparison context (==,!=,<,>,<=,>=,<=>) - Purpose : Allow integer comparisons (==,!=,<,>,<=,>=,<=>) - Arguments : Value::Single $self - left comparison operand - MIXED $other - right comparison operand - BOOL $swap - swap left and right operand - Returns : INTEGER $result (-1, 0, or 1) if the left operand is stringwise - (less than, equal, greater than) the right operator - Throws : Croaks, if not invoked on object - Comments : Must be implemented apropriatelly in subclasses - -=cut - -sub cmp_numeric($$$) -{ - my ($self, $other, $swap) = @_; - croak ((caller(0))[3] . ": instance method invoked on class") unless blessed($self); - - my $left = $self->to_numeric(); - my $right; - if (blessed($other)) { - if ($other->isa('Value::Range')) { - return $other->cmp_numeric($self, 1); - } - else { - $right = $other->to_numeric(); - } - } - else { - $right = $self->_to_inner($other); - } - - ($left,$right) = ($right,$left) if $swap; - - return $left <=> $right; -} - - -=item cmp_string($$$) [PUBLIC] - - Usage : Will be used automatically in string comparison context (eq,ne,gt,lt,ge,le,cmp) - Purpose : Allow string comparisons (eq,ne,gt,lt,ge,le,cmp) - Arguments : Value::Single $self - left comparison operand - MIXED $other - right comparison operand - BOOL $swap - swap left and right operand - Returns : INTEGER $result (-1, 0, or 1) if the left operand is stringwise - (less than, equal, greater than) the right operator - Throws : Croaks, if not invoked on object - Comments : Must be implemented apropriatelly in subclasses - -=cut - -sub cmp_string($$$) -{ - my ($self, $other, $swap) = @_; - croak ((caller(0))[3] . ": instance method invoked on class") unless blessed($self); - return $self->cmp_numeric($other, $swap); -} - -=item TO_JSON() [PUBLIC] - - Usage : Will be used automatically by Perl's JSON library - Purpose : This method allows exporting objects to JSON - Arguments : None - Returns : STRING $string - Throws : Croaks, if not invoked on object - Comments : Internally uses _init() method, subclasses should never overload this method. - See Also : http://search.cpan.org/~makamaka/JSON-2.57/lib/JSON.pm#allow_blessed - -=cut - -sub TO_JSON() -{ - my $self = shift; - croak ((caller(0))[3] . ": instance method invoked on class") unless blessed($self); - return $self->to_string(); -} - -#------------------------------------------------------------------------------- -# Private interface -#------------------------------------------------------------------------------- - -# _value(;$) [PROTECTED] -# -# Usage : -# Purpose : -# Arguments : -# Returns : -# Throws : Croaks, if invoked on class -# Comments : - -sub _value(;$) -{ - my $self = shift; - croak ((caller(0))[3] . ": instance method invoked on class") unless blessed($self); - my ($new_value,) = @_; - - $self->{VALUE} = $new_value if defined $new_value; - - return $self->{VALUE}; -} - -# _to_inner($) [PROTECTED] -# -# Usage : my $value = $self->_to_inner($value); -# Purpose : Convert the given value to appropriate inner representation -# Arguments : MIXED $value - value to be converted [MANDATORY] -# Returns : MIXED $inner -# Throws : Croaks, if invoked on class -# Comments : This method must never be called directly, it is supposed to be overloaded by subclasses. - -sub _to_inner($) -{ - my $invocant = shift; - - my ($new_value,) = @_; - return $new_value; -} - -=pod - -=back - -=cut - -1; diff --git a/lib_perl/lib/Value/Tempus.pm b/lib_perl/lib/Value/Tempus.pm deleted file mode 100644 index a310e5ba1726e1182f6003a713acc741d3bb4dac..0000000000000000000000000000000000000000 --- a/lib_perl/lib/Value/Tempus.pm +++ /dev/null @@ -1,134 +0,0 @@ -package Value::Tempus; -use strict; -use warnings; - -#******************************************************************************* -# DOCUMENTATION SECTION -#******************************************************************************* - -=head1 NAME - -Value::Tempusv4 - Short module description - -=head1 SYNOPSIS - - use Value::Tempusv4; - -=head1 DESCRIPTION - -Extensive module description - -=head1 AUTHOR - -Jan Mach -Cesnet, z.s.p.o -jan.mach@cesnet.cz -http://www.cesnet.cz - -=head1 COPYRIGHT - -This program is free software; you can redistribute -it and/or modify it under the same terms as Perl itself. - -The full text of the license can be found in the -LICENSE file included with this module. - -=head1 SEE ALSO - -perl(1). - -=head1 FUNCTION REFERENCE - -=over 4 - -=cut - -#******************************************************************************* -# LIBRARY LOADING SECTION -#******************************************************************************* - -#-- Perl core modules ---------------------------------------------------------# -use Carp; -use Scalar::Util 'blessed'; - -#use Data::Dumper; #-+-> DEVEL ONLY <-+-# - -#-- Perl CPAN modules ---------------------------------------------------------# - -#-- Custom application modules ------------------------------------------------# -use Value::Convertor; - -use Value::Timestamp; -use Value::Period; - -#******************************************************************************* -# CONSTANTS AND GLOBAL VARIABLES DEFINITION SECTION -#******************************************************************************* - -#-- Constants -----------------------------------------------------------------# - -#-- Static public class variables (our) ---------------------------------------# - -#-- Static protected class variables (my) -------------------------------------# - -#******************************************************************************* -# INITIALIZATION AND CLEANUP SECTION -#******************************************************************************* - -#-- Module initializations ----------------------------------------------------# -BEGIN { - use vars qw($VERSION $DEVEL $MAPPING); - $VERSION = '0.1'; - $DEVEL = 0; - $MAPPING = { - Value::Convertor::TS_UNIXSTAMP() => 'Value::Timestamp', - Value::Convertor::TS_NTPSTAMP() => 'Value::Timestamp', - Value::Convertor::TS_DATETIME() => 'Value::Timestamp', - Value::Convertor::TS_PERIOD() => 'Value::Period', - }; -} - - -#-- Module clean-up code (global destructor) ----------------------------------# -END { - -} - -#******************************************************************************* -# IMPLEMENTATION SECTION -#******************************************************************************* - -=item new [PUBLIC,STATIC] - - Usage : my $instance = Value::Tempus->new($value); - Purpose : Create and return reference to the new instance - Arguments : - Returns : Value::Tempus reference on success, croaks on failure - Throws : Croaks, if invoked on object - Comments : Internally uses _init() method, subclasses should never overload this method. - See Also : _init() method - -=cut - -sub new -{ - my $class = shift; - croak ((caller(0))[3] . ": class method invoked on object") if blessed($class); - my ($value, $type) = @_; - croak ((caller(0))[3] . ": expecting argument to be given to constructor") unless $value; - - my (@matches, $class_name); - ($type, @matches) = Value::Convertor->detect_datetime($value) unless $type; - $class_name = $MAPPING->{$type}; - croak ((caller(0))[3] . ": unknown datetime class '$value' => $type") unless $class_name; - - return $class_name->new($value); -} - -=pod - -=back - -=cut - -1; diff --git a/lib_perl/lib/Value/Timestamp.pm b/lib_perl/lib/Value/Timestamp.pm deleted file mode 100644 index 64185638ee3b52624df515818fccde4c1585da31..0000000000000000000000000000000000000000 --- a/lib_perl/lib/Value/Timestamp.pm +++ /dev/null @@ -1,149 +0,0 @@ -package Value::Timestamp; -use strict; -use warnings; - -#******************************************************************************* -# DOCUMENTATION SECTION -#******************************************************************************* - -=head1 NAME - -Value::Timestamp - Short module description - -=head1 SYNOPSIS - - use Value::Timestamp; - -=head1 DESCRIPTION - -Extensive module description - -=head1 AUTHOR - -Jan Mach -Cesnet, z.s.p.o -jan.mach@cesnet.cz -http://www.cesnet.cz - -=head1 COPYRIGHT - -This program is free software; you can redistribute -it and/or modify it under the same terms as Perl itself. - -The full text of the license can be found in the -LICENSE file included with this module. - -=head1 SEE ALSO - -perl(1), Value::Single(3). - -=head1 FUNCTION REFERENCE - -=over 4 - -=cut - -#******************************************************************************* -# LIBRARY LOADING SECTION -#******************************************************************************* - -#-- Perl core modules ---------------------------------------------------------# -use Carp; -use Scalar::Util 'blessed'; - -#use Data::Dumper; #-+-> DEVEL ONLY <-+-# - -#-- Perl CPAN modules ---------------------------------------------------------# - -#-- Custom application modules ------------------------------------------------# -use Value::Single; -use Value::Convertor; - -#******************************************************************************* -# CONSTANTS AND GLOBAL VARIABLES DEFINITION SECTION -#******************************************************************************* - -#-- Constants -----------------------------------------------------------------# - -#-- Static public class variables (our) ---------------------------------------# - -#-- Static protected class variables (my) -------------------------------------# - -#******************************************************************************* -# INITIALIZATION AND CLEANUP SECTION -#******************************************************************************* - -#-- Module initializations ----------------------------------------------------# -BEGIN { - use vars qw($VERSION $DEVEL @ISA); - $VERSION = '0.1'; - $DEVEL = 0; - @ISA = ('Value::Single'); -} - - -#-- Module clean-up code (global destructor) ----------------------------------# -END { - -} - -#******************************************************************************* -# IMPLEMENTATION SECTION -#******************************************************************************* - - -=item to_string(;$) [PUBLIC] - - Usage : Will be used automatically to convert object to string in string context - Purpose : Convert the object to string - Arguments : None - Returns : STRING $json - Throws : Croaks, if not invoked on object - Comments : Must be implemented apropriatelly in subclasses - -=cut - -sub to_string(;$) -{ - my $self = shift; - croak ((caller(0))[3] . ": instance method invoked on class") unless blessed($self); - - return Value::Convertor->nbi_to_datestr($self->_value(), @_); -} - -sub to_unixts(;$) -{ - my $self = shift; - croak ((caller(0))[3] . ": instance method invoked on class") unless blessed($self); - - return Value::Convertor->nbi_to_unixs($self->_value(), @_); -} - -#------------------------------------------------------------------------------- -# Private interface -#------------------------------------------------------------------------------- - -# _to_inner($) [PROTECTED] -# -# Usage : my $value = $self->_to_inner($value); -# Purpose : Convert the given value to appropriate inner representation -# Arguments : MIXED $value - value to be converted [MANDATORY] -# Returns : MIXED $inner -# Throws : Croaks, if invoked on class -# Comments : This method must never be called directly, it is supposed to be overloaded by subclasses. - -sub _to_inner($) -{ - my $invocant = shift; - - my ($type, $value) = Value::Convertor->datetime_to_nbi(@_); - return $value; -} - -=pod - -=back - -=cut - -1; diff --git a/lib_perl/tests/unit/spool/alert01.idea b/lib_perl/tests/unit/spool/alert01.idea deleted file mode 100644 index 98fd46e6443fe8fe70e58402eca2f29047d8aedd..0000000000000000000000000000000000000000 --- a/lib_perl/tests/unit/spool/alert01.idea +++ /dev/null @@ -1,56 +0,0 @@ -{ - "Format": "IDEA0", - "ID": "4390fc3f-c753-4a3e-bc83-1b44f24baf75", - "DetectTime": "2012-11-03T10:00Z", - "WinStartTime": "2012-11-03T05:00Z", - "WinEndTime": "2012-11-03T10:00Z", - "CreateTime": "2012-11-03T10:02Z", - "EventTime": "2012-11-03T07:36Z", - "CeaseTime": "2012-11-03T09:55Z", - "Category": ["Phishing"], - "Ref": ["cve:CVE-1234-5678"], - "Confidence": 1, - "Note": "Synthetic example", - "ConnCount": 20, - "Source": [ - { - "Type": ["Phishing"], - "IP4": ["195.113.144.194", "192.168.0.253"], - "URL": ["http://example.com/cgi-bin/killemall"], - "Attach": ["att1"], - "Netname": ["ripe:IANA-CBLK-RESERVED1"] - } - ], - "Target": [ - { - "Type": ["Backscatter"], - "Email": ["innocent@example.com"], - "Spoofed": 1 - }, - { - "IP4": ["10.2.2.2"], - "Anonymised": 1 - } - ], - "Node": [ - { - "Name": "buldocek", - "Type": ["Network", "Honeypot", "Kippo"], - "SW": ["Kippo"], - "AggrWin": "12:59:00" - } - ], - "_CESNET": { - "EventTemplate": "n6-008" - }, - "Attach": [ - { - "Handle": "att1", - "FileName": ["killemall"], - "Type": ["malware"], - "Hash": ["sha1:0c4a38c3569f0cc632e74f4c"], - "Size": 46, - "Ref": ["Trojan-Spy:W32/FinSpy.A"] - } - ] -} diff --git a/lib_perl/tests/unit/spool/alert02.idea b/lib_perl/tests/unit/spool/alert02.idea deleted file mode 100644 index 717a7db7c92d7cce0f682e6b3ee16a74ed4eaed8..0000000000000000000000000000000000000000 --- a/lib_perl/tests/unit/spool/alert02.idea +++ /dev/null @@ -1 +0,0 @@ -{"DetectTime": "2016-07-31T16:57:32Z", "Node": [{"Type": ["Relay"], "Name": "cz.cesnet.mentat.warden_filer"}, {"SW": ["Nemea", "HostStatsNemea"], "Type": ["Flow", "Statistical"], "Name": "cz.cesnet.nemea.hoststats"}], "EventTime": "2016-07-31T16:52:30Z", "Description": "SSH dictionary/bruteforce attack", "ConnCount": 85, "CeaseTime": "2016-07-31T16:57:29Z", "Format": "IDEA0", "Category": ["Attempt.Login"], "CreateTime": "2016-07-31T16:57:32Z", "Source": [{"IP4": ["82.142.64.117"]}], "FlowCount": 170, "ID": "3dc36d8a-fa6c-44dd-a534-8f794fbb8f36", "Target": [{"Port": [22], "IP4": ["0.0.0.0"], "Proto": ["tcp", "ssh"]}]} diff --git a/lib_perl/tests/unit/spool/msgtmplts.json b/lib_perl/tests/unit/spool/msgtmplts.json deleted file mode 100644 index b29b13e63e584c6abb989cabac4929d6e37c47c9..0000000000000000000000000000000000000000 --- a/lib_perl/tests/unit/spool/msgtmplts.json +++ /dev/null @@ -1,6418 +0,0 @@ -{ - "version" : 1, - "templates" : { - "labrea-003" : { - "_id" : "labrea-003", - "label_e" : "Pokus o odeslání SYN/ACK paketu na takové IP adresy, kde nejsou a nikdy nebyly v provozu žádné síťové servery", - "args" : "7", - "cmd_help" : "[source IP] [source port] [target IP] [target port] [event cease time] [event count] [original log line]", - "cmd_example" : "195.113.134.254 6877 78.00.00.00 1234 1274107160 50 \"1274106860 Inbound SYN/ACK: 195.113.134.254 6877 -> 78.xx.xx.xx 1234\"", - "id" : "labrea-003", - "category" : "Recon.Scanning", - "severity" : "medium", - "enabled" : 1, - "label_s" : "Stroje na následujících IP adresách poslaly SYN/ACK paket na takové IP adresy, kde nejsou a nikdy nebyly v provozu žádné síťové servery", - "ref" : "", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "LaBrea" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "Connection" - }, - { - "k" : "Node[1]/Type[2]", - "v" : "Tarpit" - }, - { - "k" : "Source[1]/%ipt:$1[1]", - "v" : "$1" - }, - { - "k" : "Source[1]/Port[1]", - "v" : "$2" - }, - { - "k" : "Target[1]/%ipt:$3[1]", - "v" : "$3" - }, - { - "k" : "Target[1]/Port[1]", - "v" : "$4" - }, - { - "k" : "CeaseTime", - "v" : "$5" - }, - { - "k" : "Category[1]", - "v" : "Recon.Scanning" - }, - { - "k" : "Description", - "v" : "SYN/ACK scan or DOS attack" - }, - { - "k" : "ConnCount", - "v" : "$6" - }, - { - "k" : "Attach[1]/Type[1]", - "v" : "Syslog" - }, - { - "k" : "Attach[1]/ContentType", - "v" : "text/plain" - }, - { - "k" : "Attach[1]/Content", - "v" : "$7" - }, - { - "k" : "_CESNET/Impact", - "v" : "Unsolicited SYN/ACK packet received from remote host $1:$2" - } - ], - "title" : "SYN/ACK scan or DOS attack", - "class" : "SYN/ACK scan or DOS attack", - "analyzer" : "LaBrea", - "alias" : "labrea-003" - }, - "sserv-018" : { - "_id" : "sserv-018", - "label_e" : "Hlášení o strojích poskytujících službu SSL v.3 v režimu Cipher Block Chaining (CBC) a tedy zranitelných skrze útok MiTM POODLE (Padding Oracle On Downgraded Legacy Encryption) (SSL Scan Report)", - "args" : "6", - "cmd_help" : "[source IP] [source port] [poodle?] [cipher size] [expiration] [original log line]", - "cmd_example" : "195.113.134.254 443 Y 1024 N \"195.113.134.254 443 (Y 1024 N) 2014-12-01_17:05:43 s\"", - "id" : "sserv-018", - "category" : "Vulnerable.Config", - "severity" : "medium", - "enabled" : 1, - "label_s" : "Hlášení o strojích poskytujících službu SSL v.3 v režimu Cipher Block Chaining (CBC) a tedy zranitelných skrze útok MiTM POODLE (Padding Oracle On Downgraded Legacy Encryption) (SSL Scan Report)", - "ref" : "https://csirt.cesnet.cz/cs/services/sserv", - "description" : "", - "note" : "", - "class" : "SSL Scan Report", - "title" : "SSL Scan Report", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "SSERV" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "External" - }, - { - "k" : "Node[1]/Type[2]", - "v" : "Recon" - }, - { - "k" : "Source[1]/%ipt:$1[1]", - "v" : "$1" - }, - { - "k" : "Source[1]/Port[1]", - "v" : "$2" - }, - { - "k" : "Source[1]/Proto[1]", - "v" : "tcp" - }, - { - "k" : "Category[1]", - "v" : "Vulnerable.Config" - }, - { - "k" : "Description", - "v" : "SSL Scan Report" - }, - { - "k" : "Note", - "v" : "Poodle: $3, Cipher size: $4, Expiration $5" - }, - { - "k" : "Ref[1]", - "v" : "urn:cve:CVE-2014-3566" - }, - { - "k" : "Attach[1]/ContentType", - "v" : "text/plain" - }, - { - "k" : "Attach[1]/Note", - "v" : "Original info" - }, - { - "k" : "Attach[1]/Content", - "v" : "$6" - }, - { - "k" : "_CESNET/Impact", - "v" : "System $1 ($2) provides SSLv3 in CBC mode and is vulnerable to MitM POODLE attack" - } - ], - "alias" : "sserv-018", - "analyzer" : "SSERV" - }, - "n6-015" : { - "_id" : "n6-015", - "label_e" : "Hlášení o strojích, které jsou součástí botnetu Zeroaccess (Bots Zeroaccess Report)", - "args" : "2", - "cmd_help" : "[source IP] [original log line]", - "cmd_example" : "195.113.134.254 \"195.113.134.254 | 2014-01-06_15:47:12 | O\"", - "id" : "n6-015", - "category" : "Intrusion.Botnet", - "severity" : "medium", - "enabled" : 1, - "label_s" : "Hlášení o strojích, které jsou součástí botnetu Zeroaccess (Bots Zeroaccess Report)", - "ref" : "https://csirt.cesnet.cz/cs/services/n6", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "N6" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "External" - }, - { - "k" : "Source[1]/%ipt:$1[1]", - "v" : "$1" - }, - { - "k" : "Category[1]", - "v" : "Intrusion.Botnet" - }, - { - "k" : "Description", - "v" : "Bots Zeroaccess Report" - }, - { - "k" : "Attach[1]/ContentType", - "v" : "text/plain" - }, - { - "k" : "Attach[1]/Note", - "v" : "Original info" - }, - { - "k" : "Attach[1]/Content", - "v" : "$2" - }, - { - "k" : "_CESNET/Impact", - "v" : "Host $1 is part of the Zeroaccess botnet" - } - ], - "title" : "Bots Zeroaccess Report", - "class" : "Bots Zeroaccess Report", - "analyzer" : "N6", - "alias" : "n6-015" - }, - "uceprot-001" : { - "_id" : "uceprot-001", - "args" : "2", - "label_e" : "Hlášení o špatně nakonfigurovaném mail serveru (Backscatter Report)", - "cmd_help" : "[source IP] [original log line]", - "cmd_example" : "195.113.134.254 \"195.113.134.254 B\"", - "category" : "Abusive.Spam", - "id" : "uceprot-001", - "severity" : "low", - "enabled" : 1, - "label_s" : "Hlášení o špatně nakonfigurovaných mail serverech (Backscatter Report)", - "ref" : "https://csirt.cesnet.cz/cs/services/uceprot", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "UCEPROT" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "External" - }, - { - "k" : "Node[1]/Type[2]", - "v" : "Data" - }, - { - "k" : "Node[1]/Type[3]", - "v" : "Policy" - }, - { - "k" : "Source[1]/%ipt:$1[1]", - "v" : "$1" - }, - { - "k" : "Category[1]", - "v" : "Abusive.Spam" - }, - { - "k" : "Description", - "v" : "Backscatter Report" - }, - { - "k" : "Attach[1]/ContentType", - "v" : "text/plain" - }, - { - "k" : "Attach[1]/Note", - "v" : "Original info" - }, - { - "k" : "Attach[1]/Content", - "v" : "$2" - }, - { - "k" : "_CESNET/Impact", - "v" : "System $1 contains misconfigured mail server" - } - ], - "title" : "Backscatter Report", - "class" : "Backscatter Report", - "analyzer" : "UCEPROT", - "alias" : "uceprot-001" - }, - "n6-016" : { - "_id" : "n6-016", - "label_e" : "Hlášení o strojích infikovaných malwarem Pushdo (Pushdo Report)", - "args" : "4", - "cmd_help" : "[source IP] [target url] [method] [original log line]", - "cmd_example" : "195.113.134.254 /?Ctrlfunc_qgyF POST \"195.113.134.254 | /?Ctrlfunc_qgyF (HTTP/1.1 POST) 2013-08-08_11:03:50 | P\"", - "id" : "n6-016", - "category" : "Intrusion.Botnet", - "severity" : "medium", - "enabled" : 1, - "label_s" : "Hlášení o strojích infikovaných malwarem Pushdo (Pushdo Report)", - "ref" : "https://csirt.cesnet.cz/cs/services/n6", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "N6" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "External" - }, - { - "k" : "Source[1]/%ipt:$1[1]", - "v" : "$1" - }, - { - "k" : "Source[1]/Type[1]", - "v" : "Malware" - }, - { - "k" : "Source[1]/Proto[1]", - "v" : "tcp" - }, - { - "k" : "Source[1]/Proto[2]", - "v" : "http" - }, - { - "k" : "Source[1]/Note", - "v" : "HTTP method: $3" - }, - { - "k" : "Target[1]/URL[1]", - "v" : "$2" - }, - { - "k" : "Target[1]/Proto[1]", - "v" : "tcp" - }, - { - "k" : "Category[1]", - "v" : "Intrusion.Botnet" - }, - { - "k" : "Description", - "v" : "Pushdo Report" - }, - { - "k" : "Attach[1]/ContentType", - "v" : "text/plain" - }, - { - "k" : "Attach[1]/Note", - "v" : "Original info" - }, - { - "k" : "Attach[1]/Content", - "v" : "$4" - }, - { - "k" : "_CESNET/Impact", - "v" : "Host $1 is infected with Pushdo malware ($3)" - } - ], - "title" : "Pushdo Report", - "class" : "Pushdo Report", - "analyzer" : "N6", - "alias" : "n6-016" - }, - "n6-011" : { - "_id" : "n6-011", - "label_e" : "Hlášení o strojích, které jsou součástí botnetu Kelihos (Kelihos Report)", - "args" : "2", - "cmd_help" : "[source IP] [original log line]", - "cmd_example" : "195.113.134.254 \"195.113.134.254 | 2014-01-06_15:32:27 | K\"", - "id" : "n6-011", - "category" : "Intrusion.Botnet", - "severity" : "medium", - "enabled" : 1, - "label_s" : "Hlášení o strojích, které jsou součástí botnetu Kelihos (Kelihos Report)", - "ref" : "https://csirt.cesnet.cz/cs/services/n6", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "N6" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "External" - }, - { - "k" : "Source[1]/%ipt:$1[1]", - "v" : "$1" - }, - { - "k" : "Source[1]/Type[1]", - "v" : "Botnet" - }, - { - "k" : "Category[1]", - "v" : "Intrusion.Botnet" - }, - { - "k" : "Description", - "v" : "Kelihos Report" - }, - { - "k" : "Attach[1]/ContentType", - "v" : "text/plain" - }, - { - "k" : "Attach[1]/Note", - "v" : "Original info" - }, - { - "k" : "Attach[1]/Content", - "v" : "$2" - }, - { - "k" : "_CESNET/Impact", - "v" : "Host $1 connected to Kelihos botnet" - } - ], - "title" : "Kelihos Report", - "class" : "Kelihos Report", - "analyzer" : "N6", - "alias" : "n6-011" - }, - "x4-001" : { - "_id" : "x4-001", - "label_e" : "Systém je infikován známým malware a součástí botnetu (Botnet Drone)", - "args" : "7", - "cmd_help" : "[source IP] [source port] [target IP] [target port] [botnet] [infection] [original log line]", - "cmd_example" : "195.113.134.254 1821 198.51.100.44 80 Conficker ConfickerC \"2014-02-25_19:21:32 195.113.134.254 1821 -> 198.51.100.44 80\"", - "id" : "x4-001", - "category" : "Malware", - "severity" : "medium", - "enabled" : 1, - "label_s" : "Systémy na následujících IP adresách jsou infikovány známým malware a součástí botnetu (Botnet Drone)", - "ref" : "https://csirt.cesnet.cz/cs/services/x4", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "X4" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "External" - }, - { - "k" : "Source[1]/%ipt:$1[1]", - "v" : "$1" - }, - { - "k" : "Source[1]/Type[1]", - "v" : "Malware" - }, - { - "k" : "Source[1]/Port[1]", - "v" : "$2" - }, - { - "k" : "Source[1]/Note", - "v" : "Malware: $6" - }, - { - "k" : "Target[1]/%ipt:$3[1]", - "v" : "$3" - }, - { - "k" : "Target[1]/Port[1]", - "v" : "$4" - }, - { - "k" : "Note", - "v" : "Botnet: $5" - }, - { - "k" : "Category[1]", - "v" : "Intrusion.Botnet" - }, - { - "k" : "Category[2]", - "v" : "Malware" - }, - { - "k" : "Description", - "v" : "Botnet Drone" - }, - { - "k" : "Attach[1]/ContentType", - "v" : "text/plain" - }, - { - "k" : "Attach[1]/Note", - "v" : "Original info" - }, - { - "k" : "Attach[1]/Content", - "v" : "$7" - }, - { - "k" : "_CESNET/Impact", - "v" : "System $1:$2 connected to $3:$4 and is part of $5 botnet ($6)" - } - ], - "title" : "Botnet Drone", - "class" : "Botnet Drone", - "analyzer" : "X4", - "alias" : "x4-001" - }, - "warden-spam" : { - "_id" : "warden-spam", - "args" : "10", - "label_e" : "Stroj rozesílal nevyžádanou poštu", - "cmd_help" : "[analyzer] [analyzer_class] [ip_category] [src_ip] [proto_name] [proto_num] [tgt_port] [count] [note] [origin]", - "cmd_example" : "analyzer detector ipv4-addr 195.113.134.254 tcp 6 1234 100 \"Additional note\" warden", - "category" : "Abusive.Spam", - "id" : "warden-spam", - "severity" : "low", - "enabled" : 1, - "label_s" : "Stroje na následujících IP adresách rozesílají nevyžádanou poštu", - "ref" : "", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "$1" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "$2" - }, - { - "k" : "Source[1]/%ipt:$4[1]", - "v" : "$4" - }, - { - "k" : "Source[1]/Proto[1]", - "v" : "$5" - }, - { - "k" : "Target[1]/Port[1]", - "v" : "$7" - }, - { - "k" : "Target[1]/Proto[1]", - "v" : "$5" - }, - { - "k" : "Category[1]", - "v" : "Abusive.Spam" - }, - { - "k" : "Description", - "v" : "Spam" - }, - { - "k" : "ConnCount", - "v" : "$8" - }, - { - "k" : "Note", - "v" : "$9" - }, - { - "k" : "_CESNET/Origin", - "v" : "$10" - }, - { - "k" : "_CESNET/Impact", - "v" : "Remote host $4 sent unsolicited emails" - } - ], - "title" : "Spam", - "class" : "Spam", - "analyzer" : "", - "alias" : "warden-spam" - }, - "sserv-014" : { - "_id" : "sserv-014", - "label_e" : "Hlášení o strojích poskytujících službu UDP NETBIOS Name Service, které lze zneužít k útokům typu DDoS (Scan NETBIOS)", - "args" : "3", - "cmd_help" : "[source IP] [source port] [original log line]", - "cmd_example" : "195.113.134.254 137 \"195.113.134.254 (137) 2014-04-22_12:08:24 B\"", - "id" : "sserv-014", - "category" : "Vulnerable.Config", - "severity" : "medium", - "enabled" : 1, - "label_s" : "Hlášení o strojích poskytujících službu UDP NETBIOS Name Service, které lze zneužít k útokům typu DDoS (Scan NETBIOS)", - "ref" : "https://csirt.cesnet.cz/cs/services/sserv", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "SSERV" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "External" - }, - { - "k" : "Node[1]/Type[2]", - "v" : "Recon" - }, - { - "k" : "Source[1]/%ipt:$1[1]", - "v" : "$1" - }, - { - "k" : "Source[1]/Port[1]", - "v" : "$2" - }, - { - "k" : "Source[1]/Type[1]", - "v" : "Backscatter" - }, - { - "k" : "Source[1]/Proto[1]", - "v" : "udp" - }, - { - "k" : "Source[1]/Proto[2]", - "v" : "netbios-ns" - }, - { - "k" : "Category[1]", - "v" : "Vulnerable.Config" - }, - { - "k" : "Description", - "v" : "Scan NETBIOS" - }, - { - "k" : "Note", - "v" : "$3" - }, - { - "k" : "_CESNET/Impact", - "v" : "System provides open NETBIOS service and can be misused for massive DDoS attack" - } - ], - "title" : "Scan NETBIOS", - "class" : "Scan NETBIOS", - "analyzer" : "SSERV", - "alias" : "sserv-014" - }, - "n6-031" : { - "_id" : "n6-031", - "args" : "3", - "label_e" : "Hlášení o zkompromitovaných routerech nebo jiných zařízeních (Router Report)", - "cmd_help" : "[source IP] [source port] [original log line]", - "cmd_example" : "195.113.134.254 23 \"195.113.134.254 | 23 | 2014-10-31_12:50:27 | r\"", - "id" : "n6-031", - "category" : "Intrusion.Botnet", - "severity" : "high", - "enabled" : 1, - "label_s" : "Hlášení o zkompromitovaných routerech nebo jiných zařízeních (Router Report)", - "ref" : "https://csirt.cesnet.cz/cs/services/n6", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "N6" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "External" - }, - { - "k" : "Source[1]/%ipt:$1[1]", - "v" : "$1" - }, - { - "k" : "Source[1]/Type[1]", - "v" : "Malware" - }, - { - "k" : "Source[1]/Type[2]", - "v" : "Botnet" - }, - { - "k" : "Source[1]/Port[1]", - "v" : "$2" - }, - { - "k" : "Category[1]", - "v" : "Intrusion.Botnet" - }, - { - "k" : "Description", - "v" : "Compromised Router Report" - }, - { - "k" : "Attach[1]/ContentType", - "v" : "text/plain" - }, - { - "k" : "Attach[1]/Note", - "v" : "Original info" - }, - { - "k" : "Attach[1]/Content", - "v" : "$3" - }, - { - "k" : "_CESNET/Impact", - "v" : "Router or device $1 is compromised" - } - ], - "title" : "Compromised router or device", - "class" : "Compromised Router Report", - "analyzer" : "N6", - "alias" : "n6-031" - }, - "dio-other" : { - "_id" : "dio-other", - "args" : "8", - "label_e" : "Pokus o skenování portů", - "cmd_help" : "[source IP type] [source IP] [protocol name] [protocol number] [source port] [target IP] [target port] [event count]", - "cmd_example" : "ipv4-addr 195.113.134.254 tcp 6 56 195.113.161.181 56 100", - "category" : "Recon.Scanning", - "id" : "dio-other", - "severity" : "low", - "enabled" : 1, - "label_s" : "Stroje na následujících IP adresách se pokusily o skenování portů", - "ref" : "", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "Dionaea" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "Honeypot" - }, - { - "k" : "Node[1]/Type[2]", - "v" : "Protocol" - }, - { - "k" : "Source[1]/%ipt:$2[1]", - "v" : "$2" - }, - { - "k" : "Source[1]/Proto[1]", - "v" : "$3" - }, - { - "k" : "Source[1]/Port[1]", - "v" : "$5" - }, - { - "k" : "Target[1]/%ipt:$6[1]", - "v" : "$6" - }, - { - "k" : "Target[1]/Proto[1]", - "v" : "$3" - }, - { - "k" : "Target[1]/Port[1]", - "v" : "$7" - }, - { - "k" : "Category[1]", - "v" : "Recon.Scanning" - }, - { - "k" : "Description", - "v" : "Portscan" - }, - { - "k" : "ConnCount", - "v" : "$8" - }, - { - "k" : "_CESNET/Impact", - "v" : "Remote host scanned port $7 from $2:$5" - } - ], - "title" : "Portscan", - "class" : "Portscan", - "analyzer" : "Dionaea", - "alias" : "dio-other" - }, - "n6-022" : { - "_id" : "n6-022", - "label_e" : "Hlášení o strojích infikovaných malwarem Cutwail (Cutwail Report)", - "args" : "2", - "cmd_help" : "[source IP] [original log line]", - "cmd_example" : "195.113.134.254 \"195.113.134.254 | W\"", - "id" : "n6-022", - "category" : "Intrusion.Botnet", - "severity" : "medium", - "enabled" : 1, - "label_s" : "Hlášení o strojích infikovaných malwarem Cutwail (Cutwail Report)", - "ref" : "https://csirt.cesnet.cz/cs/services/n6", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "N6" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "External" - }, - { - "k" : "Source[1]/%ipt:$1[1]", - "v" : "$1" - }, - { - "k" : "Source[1]/Type[1]", - "v" : "Malware" - }, - { - "k" : "Source[1]/Type[2]", - "v" : "Botnet" - }, - { - "k" : "Category[1]", - "v" : "Intrusion.Botnet" - }, - { - "k" : "Description", - "v" : "Cutwail Report" - }, - { - "k" : "Attach[1]/ContentType", - "v" : "text/plain" - }, - { - "k" : "Attach[1]/Note", - "v" : "Original info" - }, - { - "k" : "Attach[1]/Content", - "v" : "$2" - }, - { - "k" : "_CESNET/Impact", - "v" : "Host $1 is infected with Cutwail malware" - } - ], - "title" : "Cutwail Report", - "class" : "Cutwail Report", - "analyzer" : "N6", - "alias" : "n6-022" - }, - "sserv-001" : { - "_id" : "sserv-001", - "args" : "4", - "label_e" : "Stroj byl označen jako pravděpodobný řídící server botnetu (Botnet Command and Control)", - "cmd_help" : "[source IP] [source port] [count] [original log line]", - "cmd_example" : "195.113.134.254 6667 1 \"195.113.134.254 6667 (#crack-me) C\"", - "id" : "sserv-001", - "category" : "Intrusion.Botnet", - "severity" : "medium", - "enabled" : 1, - "label_s" : "Stroje na následujících IP adresách jsou pravděpodobně řídícími servery botnetu (Botnet Command and Control)", - "ref" : "https://csirt.cesnet.cz/cs/services/sserv", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "SSERV" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "External" - }, - { - "k" : "Source[1]/%ipt:$1[1]", - "v" : "$1" - }, - { - "k" : "Source[1]/Type[1]", - "v" : "Botnet" - }, - { - "k" : "Source[1]/Type[1]", - "v" : "CC" - }, - { - "k" : "Source[1]/Port[1]", - "v" : "$2" - }, - { - "k" : "ConnCount", - "v" : "$3" - }, - { - "k" : "Category[1]", - "v" : "Intrusion.Botnet" - }, - { - "k" : "Description", - "v" : "Botnet Command and Control" - }, - { - "k" : "Attach[1]/ContentType", - "v" : "text/plain" - }, - { - "k" : "Attach[1]/Note", - "v" : "Original info" - }, - { - "k" : "Attach[1]/Content", - "v" : "$4" - }, - { - "k" : "_CESNET/Impact", - "v" : "System or service was compromised and is botnet CaC" - } - ], - "title" : "Botnet Command and Control", - "class" : "Botnet Command and Control", - "analyzer" : "SSERV", - "alias" : "sserv-001" - }, - "n6-033" : { - "_id" : "n6-033", - "label_e" : "Hlášení o strojích infikovaných malwarem a zapojených do botnetu (Botnet Infection Report)", - "args" : "3", - "cmd_help" : "[source IP] [botnet name] [log line]", - "cmd_example" : "195.113.134.254 pushdo \"195.113.134.254 2014-11-12_17:54:01 pushdo\"", - "id" : "n6-033", - "category" : "Intrusion.Botnet", - "severity" : "medium", - "enabled" : 1, - "label_s" : "Hlášení o strojích infikovaných malwarem a zapojených do botnetu (Botnet Infection Report)", - "ref" : "https://csirt.cesnet.cz/cs/services/n6", - "description" : "", - "note" : "", - "class" : "Botnet Infection Report", - "title" : "Botnet Infection Report", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "N6" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "External" - }, - { - "k" : "Source[1]/%ipt:$1[1]", - "v" : "$1" - }, - { - "k" : "Source[1]/Type[1]", - "v" : "Malware" - }, - { - "k" : "Source[1]/Type[2]", - "v" : "Botnet" - }, - { - "k" : "Source[1]/Note", - "v" : "Botnet name: $2" - }, - { - "k" : "Category[1]", - "v" : "Intrusion.Botnet" - }, - { - "k" : "Description", - "v" : "Botnet Infection Report" - }, - { - "k" : "Attach[1]/ContentType", - "v" : "text/plain" - }, - { - "k" : "Attach[1]/Note", - "v" : "Original info" - }, - { - "k" : "Attach[1]/Content", - "v" : "$3" - }, - { - "k" : "_CESNET/Impact", - "v" : "Host $1 is infected with $2 malware and part of the botnet" - } - ], - "alias" : "n6-033", - "analyzer" : "N6" - }, - "warden-webattack" : { - "_id" : "warden-webattack", - "label_e" : "Pokus o utok proti webovemu serveru", - "args" : "10", - "cmd_help" : "[analyzer] [analyzer_class] [ip_category] [src_ip] [proto_name] [proto_num] [tgt_port] [count] [note] [origin]", - "cmd_example" : "analyzer detector ipv4-addr 195.113.134.254 tcp 6 1234 100 \"Additional note\" warden", - "category" : "Attempt.Exploit", - "id" : "warden-webattack", - "severity" : "low", - "enabled" : 1, - "label_s" : "Pokus o utok proti webovemu serveru", - "ref" : "", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "$1" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "$2" - }, - { - "k" : "Source[1]/%ipt:$4[1]", - "v" : "$4" - }, - { - "k" : "Source[1]/Proto[1]", - "v" : "$5" - }, - { - "k" : "Target[1]/Port[1]", - "v" : "$7" - }, - { - "k" : "Target[1]/Proto[1]", - "v" : "$5" - }, - { - "k" : "Category[1]", - "v" : "Attempt.Exploit" - }, - { - "k" : "Description", - "v" : "Webattack" - }, - { - "k" : "ConnCount", - "v" : "$8" - }, - { - "k" : "Note", - "v" : "$9" - }, - { - "k" : "_CESNET/Origin", - "v" : "$10" - }, - { - "k" : "_CESNET/Impact", - "v" : "Remote host tried open URLs from $4" - } - ], - "title" : "Webattack", - "class" : "Webattack", - "analyzer" : "", - "alias" : "warden-webattack" - }, - "warden-vulnerability" : { - "_id" : "warden-vulnerability", - "label_e" : "Stroj obsahuje bezpečnostní zranitelnost", - "args" : "10", - "cmd_help" : "[analyzer] [analyzer_class] [ip_category] [src_ip] [proto_name] [proto_num] [tgt_port] [count] [note] [origin]", - "cmd_example" : "analyzer detector ipv4-addr 195.113.134.254 tcp 6 1234 100 \"Additional note\" warden", - "category" : "Vulnerable", - "id" : "warden-vulnerability", - "severity" : "low", - "enabled" : 1, - "label_s" : "Stroje obsahují bezpečnostní zranitelnosti", - "ref" : "", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "$1" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "$2" - }, - { - "k" : "Source[1]/%ipt:$4[1]", - "v" : "$4" - }, - { - "k" : "Source[1]/Proto[1]", - "v" : "$5" - }, - { - "k" : "Target[1]/Port[1]", - "v" : "$7" - }, - { - "k" : "Target[1]/Proto[1]", - "v" : "$5" - }, - { - "k" : "Category[1]", - "v" : "Vulnerable" - }, - { - "k" : "Description", - "v" : "Security vulnerability" - }, - { - "k" : "ConnCount", - "v" : "$8" - }, - { - "k" : "Note", - "v" : "$9" - }, - { - "k" : "_CESNET/Origin", - "v" : "$10" - }, - { - "k" : "_CESNET/Impact", - "v" : "Remote host $4 contains security vulnerability" - } - ], - "title" : "Security vulnerability", - "class" : "Security vulnerability", - "analyzer" : "", - "alias" : "warden-vulnerability" - }, - "n6-017" : { - "_id" : "n6-017", - "label_e" : "Hlášení o strojích infikovaných malwarem Moure (Moure Sinkhole Report I)", - "args" : "5", - "cmd_help" : "[source IP] [source port] [target IP] [target port] [original log line]", - "cmd_example" : "195.113.134.254 1056 198.51.100.71 80 \"195.113.134.254 | 1056 -> 198.51.100.71 | 80 | 2013-08-08_22:55:19 | R\"", - "id" : "n6-017", - "category" : "Intrusion.Botnet", - "severity" : "medium", - "enabled" : 1, - "label_s" : "Hlášení o strojích infikovaných malwarem Moure (Moure Sinkhole Report I)", - "ref" : "https://csirt.cesnet.cz/cs/services/n6", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "N6" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "External" - }, - { - "k" : "Node[1]/Type[2]", - "v" : "Blackhole" - }, - { - "k" : "Source[1]/%ipt:$1[1]", - "v" : "$1" - }, - { - "k" : "Source[1]/Port[1]", - "v" : "$2" - }, - { - "k" : "Target[1]/%ipt:$3[1]", - "v" : "$3" - }, - { - "k" : "Target[1]/Port[1]", - "v" : "$4" - }, - { - "k" : "Category[1]", - "v" : "Intrusion.Botnet" - }, - { - "k" : "Description", - "v" : "Moure Sinkhole Report I" - }, - { - "k" : "Attach[1]/ContentType", - "v" : "text/plain" - }, - { - "k" : "Attach[1]/Note", - "v" : "Original info" - }, - { - "k" : "Attach[1]/Content", - "v" : "$5" - }, - { - "k" : "_CESNET/Impact", - "v" : "Host $1:$2 connected to $3:$4 and is infected with Moure malware" - } - ], - "title" : "Moure Sinkhole Report I", - "class" : "Moure Sinkhole Report I", - "analyzer" : "N6", - "alias" : "n6-017" - }, - "n6-004" : { - "_id" : "n6-004", - "label_e" : "Hlášení o strojích infikovaných malwarem Citadel (Citadel Report)", - "args" : "5", - "cmd_help" : "[source IP] [target host] [target url] [http method] [original log line]", - "cmd_example" : "195.113.134.254 evil.org /c/hluz.php POST \"195.113.134.254 -> evil.org | /c/hluz.php (HTTP/1.1 POST) 2012-11-29_11:03:50 | C\"", - "id" : "n6-004", - "category" : "Intrusion.Botnet", - "severity" : "medium", - "enabled" : 1, - "label_s" : "Hlášení o strojích infikovaných malwarem Citadel (Citadel Report)", - "ref" : "https://csirt.cesnet.cz/cs/services/n6", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "N6" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "External" - }, - { - "k" : "Source[1]/%ipt:$1[1]", - "v" : "$1" - }, - { - "k" : "Source[1]/Type[1]", - "v" : "Botnet" - }, - { - "k" : "Source[1]/Proto[1]", - "v" : "tcp" - }, - { - "k" : "Source[1]/Proto[2]", - "v" : "http" - }, - { - "k" : "Source[1]/Note", - "v" : "HTTP method: $4" - }, - { - "k" : "Target[1]/URL[1]", - "v" : "http://$2/$3" - }, - { - "k" : "Target[1]/Proto[1]", - "v" : "tcp" - }, - { - "k" : "Target[1]/Proto[2]", - "v" : "http" - }, - { - "k" : "Category[1]", - "v" : "Intrusion.Botnet" - }, - { - "k" : "Description", - "v" : "Citadel Report" - }, - { - "k" : "Attach[1]/ContentType", - "v" : "text/plain" - }, - { - "k" : "Attach[1]/Note", - "v" : "Original info" - }, - { - "k" : "Attach[1]/Content", - "v" : "$5" - }, - { - "k" : "_CESNET/Impact", - "v" : "Host $1 connected to $2 ($3) and is infected with Citadel malware" - } - ], - "title" : "Citadel Report", - "class" : "Citadel Report", - "analyzer" : "N6", - "alias" : "n6-004" - }, - "connection-test" : { - "_id" : "connection-test", - "args" : "1", - "label_e" : "Connection test", - "cmd_help" : "[source IP]", - "cmd_example" : "1.1.1.1", - "category" : "Test", - "id" : "connection-test", - "severity" : "low", - "enabled" : 1, - "label_s" : "Connection test", - "ref" : "", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "CONNTEST" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "CONNTEST" - }, - { - "k" : "Source[1]/%ipt:$1[1]", - "v" : "$1" - }, - { - "k" : "Category[1]", - "v" : "Test" - }, - { - "k" : "Description", - "v" : "Connection test" - }, - { - "k" : "_CESNET/Impact", - "v" : "Connection test" - } - ], - "title" : "Connection test", - "class" : "Connection test", - "analyzer" : "Mentat", - "alias" : "connection-test" - }, - "x2-003" : { - "_id" : "x2-003", - "label_e" : "Hlášení o nebezpečném obsahu na infikovaných strojích (Malware URL)", - "args" : "3", - "cmd_help" : "[source IP] [url] [original log line]", - "cmd_example" : "195.113.134.254 hXXp://www.example.org/doc/index.html \"195.113.134.254 | 2013-01-15_13:56:53 | malwareurl: hXXp://www.example.org/doc/index.html\"", - "id" : "x2-003", - "category" : "Malware", - "severity" : "medium", - "enabled" : 1, - "label_s" : "Hlášení o nebezpečném obsahu na infikovaných strojích (Malware URL)", - "ref" : "https://csirt.cesnet.cz/cs/services/x2", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "X2" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "External" - }, - { - "k" : "Source[1]/%ipt:$1[1]", - "v" : "$1" - }, - { - "k" : "Source[1]/Proto[1]", - "v" : "tcp" - }, - { - "k" : "Source[1]/Proto[2]", - "v" : "http" - }, - { - "k" : "Source[1]/URL[1]", - "v" : "$2" - }, - { - "k" : "Category[1]", - "v" : "Malware" - }, - { - "k" : "Description", - "v" : "Malware URL" - }, - { - "k" : "Attach[1]/ContentType", - "v" : "text/plain" - }, - { - "k" : "Attach[1]/Note", - "v" : "Original info" - }, - { - "k" : "Attach[1]/Content", - "v" : "$3" - }, - { - "k" : "_CESNET/Impact", - "v" : "System $1 contains malware at $2" - } - ], - "title" : "Malware URL", - "class" : "Malware URL", - "analyzer" : "X2", - "alias" : "x2-003" - }, - "dio-mysqld" : { - "_id" : "dio-mysqld", - "label_e" : "Pokus o útok na MySQL server", - "args" : "6", - "cmd_help" : "[source IP type] [source IP] [source port] [target IP] [target port] [event count]", - "cmd_example" : "ipv4-addr 195.113.134.254 56 195.113.161.181 56 100", - "category" : "Attempt.Exploit", - "id" : "dio-mysqld", - "severity" : "low", - "enabled" : 1, - "label_s" : "Stroje na následujících IP adresách se pokusily zaútočit na MySQL server", - "ref" : "", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "Dionaea" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "Honeypot" - }, - { - "k" : "Node[1]/Type[2]", - "v" : "Protocol" - }, - { - "k" : "Source[1]/%ipt:$2[1]", - "v" : "$2" - }, - { - "k" : "Source[1]/Proto[1]", - "v" : "tcp" - }, - { - "k" : "Source[1]/Proto[2]", - "v" : "mysql" - }, - { - "k" : "Source[1]/Port[1]", - "v" : "$3" - }, - { - "k" : "Target[1]/%ipt:$4[1]", - "v" : "$4" - }, - { - "k" : "Target[1]/Proto[1]", - "v" : "tcp" - }, - { - "k" : "Target[1]/Proto[2]", - "v" : "sql" - }, - { - "k" : "Target[1]/Port[1]", - "v" : "$5" - }, - { - "k" : "Category[1]", - "v" : "Recon.Scanning" - }, - { - "k" : "Category[2]", - "v" : "Attempt.Exploit" - }, - { - "k" : "Description", - "v" : "SQL query attack attempt" - }, - { - "k" : "ConnCount", - "v" : "$6" - }, - { - "k" : "_CESNET/Impact", - "v" : "Remote host connected to MySQL on port $5 from $2:$3" - } - ], - "title" : "MySQL query attack attempt", - "class" : "SQL query attack attempt", - "analyzer" : "Dionaea", - "alias" : "dio-mysqld" - }, - "sserv-012" : { - "_id" : "sserv-012", - "args" : "4", - "label_e" : "Hlášení o strojích poskytujících službu SSDP, které lze zneužít k masivním útokům typu DDoS (Scan SSDP)", - "cmd_help" : "[source IP] [source port] [system name] [original log line]", - "cmd_example" : "195.113.134.254 1900 \"XRX_OS/1.0 UPnP/1.0 Phaser 8550DP\" \"195.113.134.254 1900 (XRX_OS/1.0 UPnP/1.0 Phaser 8550DP) 2014-03-27_14:03:16 S\"", - "id" : "sserv-012", - "category" : "Vulnerable.Config", - "severity" : "high", - "enabled" : 1, - "label_s" : "Hlášení o strojích poskytujících službu SSDP, které lze zneužít k masivním útokům typu DDoS (Scan SSDP)", - "ref" : "https://csirt.cesnet.cz/cs/services/sserv", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "SSERV" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "External" - }, - { - "k" : "Node[1]/Type[2]", - "v" : "Recon" - }, - { - "k" : "Source[1]/%ipt:$1[1]", - "v" : "$1" - }, - { - "k" : "Source[1]/Port[1]", - "v" : "$2" - }, - { - "k" : "Source[1]/Proto[1]", - "v" : "udp" - }, - { - "k" : "Source[1]/Proto[2]", - "v" : "ssdp" - }, - { - "k" : "Source[1]/Note", - "v" : "System name: $3" - }, - { - "k" : "Category[1]", - "v" : "Vulnerable.Config" - }, - { - "k" : "Description", - "v" : "Scan SSDP" - }, - { - "k" : "Attach[1]/ContentType", - "v" : "text/plain" - }, - { - "k" : "Attach[1]/Note", - "v" : "Original info" - }, - { - "k" : "Attach[1]/Content", - "v" : "$4" - }, - { - "k" : "_CESNET/Impact", - "v" : "System provides SDDP service and can be misused for massive DDoS attack" - } - ], - "title" : "Scan SSDP", - "class" : "Scan SSDP", - "analyzer" : "SSERV", - "alias" : "sserv-012" - }, - "n6-019" : { - "_id" : "n6-019", - "args" : "4", - "label_e" : "Informace o zkompromitovanych Systemech pro spravu obsahu (Compromised CMS Report)", - "cmd_help" : "[source IP] [source url] [CMS name] [original log line]", - "cmd_example" : "195.113.134.254 hXXp://g3.example.eu/wp-login.php:admin Wordpress \"195.113.134.254 | hXXp://g3.example.eu/wp-login.php:admin | Wordpress | S\"", - "id" : "n6-019", - "category" : "Intrusion.AppCompromise", - "severity" : "medium", - "enabled" : 1, - "label_s" : "Informace o zkompromitovanych Systemech pro spravu obsahu (Compromised CMS Report)", - "ref" : "https://csirt.cesnet.cz/cs/services/n6", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "N6" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "External" - }, - { - "k" : "Source[1]/%ipt:$1[1]", - "v" : "$1" - }, - { - "k" : "Source[1]/Proto[1]", - "v" : "tcp" - }, - { - "k" : "Source[1]/Proto[2]", - "v" : "http" - }, - { - "k" : "Source[1]/URL[1]", - "v" : "$2" - }, - { - "k" : "Target[1]/note", - "v" : "CMS name: $3" - }, - { - "k" : "Target[1]/Proto[1]", - "v" : "tcp" - }, - { - "k" : "Target[1]/Proto[2]", - "v" : "http" - }, - { - "k" : "Category[1]", - "v" : "Intrusion.AppCompromise" - }, - { - "k" : "Description", - "v" : "Compromised CMS Report" - }, - { - "k" : "Attach[1]/ContentType", - "v" : "text/plain" - }, - { - "k" : "Attach[1]/Note", - "v" : "Original info" - }, - { - "k" : "Attach[1]/Content", - "v" : "$4" - }, - { - "k" : "_CESNET/Impact", - "v" : "Host $1 contains compromised CMS system $3 at $2" - } - ], - "title" : "Compromised CMS Report", - "class" : "Compromised CMS Report", - "analyzer" : "N6", - "alias" : "n6-019" - }, - "n6-008" : { - "_id" : "n6-008", - "label_e" : "Hlášení o strojích infikovaných malwarem Zeus Gameover (Zeus Gameover Report)", - "args" : "4", - "cmd_help" : "[source IP] [source port] [malware] [original log line]", - "cmd_example" : "195.113.134.254 9073 \"known on p2p network\" \"195.113.134.254 | 9073 (UDP) | known on p2p network | 2013-11-07_17:41:37 | G\"", - "id" : "n6-008", - "category" : "Intrusion.Botnet", - "severity" : "medium", - "enabled" : 1, - "label_s" : "Hlášení o strojích infikovaných malwarem Zeus Gameover (Zeus Gameover Report)", - "ref" : "https://csirt.cesnet.cz/cs/services/n6", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "N6" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "External" - }, - { - "k" : "Source[1]/%ipt:$1[1]", - "v" : "$1" - }, - { - "k" : "Source[1]/Port[1]", - "v" : "$2" - }, - { - "k" : "Note", - "v" : "Malware: $3" - }, - { - "k" : "Category[1]", - "v" : "Intrusion.Botnet" - }, - { - "k" : "Description", - "v" : "Zeus Gameover Report" - }, - { - "k" : "Attach[1]/ContentType", - "v" : "text/plain" - }, - { - "k" : "Attach[1]/Note", - "v" : "Original info" - }, - { - "k" : "Attach[1]/Content", - "v" : "$4" - }, - { - "k" : "_CESNET/Impact", - "v" : "Host $1:$2 is infected with Zeus Gameover malware ($3)" - } - ], - "title" : "Zeus Gameover Report", - "class" : "Zeus Gameover Report", - "analyzer" : "N6", - "alias" : "n6-008" - }, - "sserv-005" : { - "_id" : "sserv-005", - "label_e" : "Stroj funguje jako otevřený DNS resolver a může být zneužit pro masivní DDoS útoky (Open DNS Resolver)", - "args" : "2", - "cmd_help" : "[source IP] [original log line]", - "cmd_example" : "195.113.134.254 \"195.113.134.254 (4.2381 dnsmasq-2.32) 2013-11-12_20:09:31 R\"", - "id" : "sserv-005", - "category" : "Vulnerable.Config", - "severity" : "medium", - "enabled" : 1, - "label_s" : "Stroje na následujících IP adresách fungují jako otevřené DNS resolvery a mohou být zneužity pro masivní DDoS útoky (Open DNS Resolver)", - "ref" : "https://csirt.cesnet.cz/cs/services/sserv", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "SSERV" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "External" - }, - { - "k" : "Node[1]/Type[2]", - "v" : "Recon" - }, - { - "k" : "Source[1]/%ipt:$1[1]", - "v" : "$1" - }, - { - "k" : "Source[1]/Proto[1]", - "v" : "udp" - }, - { - "k" : "Source[1]/Proto[2]", - "v" : "domain" - }, - { - "k" : "Source[1]/Type[1]", - "v" : "Backscatter" - }, - { - "k" : "Category[1]", - "v" : "Vulnerable.Config" - }, - { - "k" : "Description", - "v" : "Open DNS Resolver" - }, - { - "k" : "Attach[1]/ContentType", - "v" : "text/plain" - }, - { - "k" : "Attach[1]/Note", - "v" : "Original info" - }, - { - "k" : "Attach[1]/Content", - "v" : "$2" - }, - { - "k" : "_CESNET/Impact", - "v" : "Host $1 is ORR can be misused to DDoS attack" - } - ], - "title" : "Open DNS Resolver", - "class" : "Open DNS Resolver", - "analyzer" : "SSERV", - "alias" : "sserv-005" - }, - "x2-005" : { - "_id" : "x2-005", - "label_e" : "Hlášení o otevřeném proxy serveru na (typicky) zkompromitovaném počítači (Proxy server)", - "args" : "2", - "cmd_help" : "[source IP] [original log line]", - "cmd_example" : "195.113.134.254 \"195.113.134.254 | 2013-02-27_13:32:11 | proxy: SOCKS4 (21147)\"", - "id" : "x2-005", - "category" : "Vulnerable", - "severity" : "medium", - "enabled" : 1, - "label_s" : "Hlášení o otevřeném proxy serveru na (typicky) zkompromitovaném počítači (Proxy server)", - "ref" : "https://csirt.cesnet.cz/cs/services/x2", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "X2" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "External" - }, - { - "k" : "Source[1]/%ipt:$1[1]", - "v" : "$1" - }, - { - "k" : "Source[1]/Type[1]", - "v" : "Proxy" - }, - { - "k" : "Source[1]/Proto[1]", - "v" : "tcp" - }, - { - "k" : "Category[1]", - "v" : "Vulnerable" - }, - { - "k" : "Description", - "v" : "Proxy server" - }, - { - "k" : "Attach[1]/ContentType", - "v" : "text/plain" - }, - { - "k" : "Attach[1]/Note", - "v" : "Original info" - }, - { - "k" : "Attach[1]/Content", - "v" : "$2" - }, - { - "k" : "_CESNET/Impact", - "v" : "System $1 acts as open proxy" - } - ], - "title" : "Proxy server", - "class" : "Proxy server", - "analyzer" : "X2", - "alias" : "x2-005" - }, - "warden-probe" : { - "_id" : "warden-probe", - "args" : "10", - "label_e" : "Skenování portů vzdáleného stroje", - "cmd_help" : "[analyzer] [analyzer_class] [ip_category] [src_ip] [proto_name] [proto_num] [tgt_port] [count] [note] [origin]", - "cmd_example" : "analyzer detector ipv4-addr 195.113.134.254 tcp 6 1234 100 \"Additional note\" warden", - "category" : "Recon.Scanning", - "id" : "warden-probe", - "severity" : "low", - "enabled" : 1, - "label_s" : "Skenování portů vzdáleného stroje", - "ref" : "", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "$1" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "$2" - }, - { - "k" : "Source[1]/%ipt:$4[1]", - "v" : "$4" - }, - { - "k" : "Source[1]/Proto[1]", - "v" : "$5" - }, - { - "k" : "Target[1]/Port[1]", - "v" : "$7" - }, - { - "k" : "Target[1]/Proto[1]", - "v" : "$5" - }, - { - "k" : "Category[1]", - "v" : "Recon.Scanning" - }, - { - "k" : "Description", - "v" : "Probe" - }, - { - "k" : "ConnCount", - "v" : "$8" - }, - { - "k" : "Note", - "v" : "$9" - }, - { - "k" : "_CESNET/Origin", - "v" : "$10" - }, - { - "k" : "_CESNET/Impact", - "v" : "Remote host $4 performed unrecognized portscan" - } - ], - "title" : "Probe", - "class" : "Probe", - "analyzer" : "", - "alias" : "warden-probe" - }, - "sserv-011" : { - "_id" : "sserv-011", - "label_e" : "Hlášení o strojích poskytujících službu UDP Quote of the Day, které lze zneužít k útokům typu DDoS (Scan QOTD)", - "args" : "3", - "cmd_help" : "[source IP] [source port] [original log line]", - "cmd_example" : "195.113.134.254 17 \"195.113.134.254 (17) 2014-03-28_08:57:09 Q\"", - "id" : "sserv-011", - "category" : "Vulnerable.Config", - "severity" : "medium", - "enabled" : 1, - "label_s" : "Hlášení o strojích poskytujících službu UDP Quote of the Day, které lze zneužít k útokům typu DDoS (Scan QOTD)", - "ref" : "https://csirt.cesnet.cz/cs/services/sserv", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "SSERV" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "External" - }, - { - "k" : "Node[1]/Type[2]", - "v" : "Recon" - }, - { - "k" : "Source[1]/%ipt:$1[1]", - "v" : "$1" - }, - { - "k" : "Source[1]/Port[1]", - "v" : "$2" - }, - { - "k" : "Source[1]/Proto[1]", - "v" : "udp" - }, - { - "k" : "Source[1]/Proto[2]", - "v" : "qotd" - }, - { - "k" : "Category[1]", - "v" : "Vulnerable.Config" - }, - { - "k" : "Description", - "v" : "Scan QOTD" - }, - { - "k" : "Attach[1]/ContentType", - "v" : "text/plain" - }, - { - "k" : "Attach[1]/Note", - "v" : "Original info" - }, - { - "k" : "Attach[1]/Content", - "v" : "$3" - }, - { - "k" : "_CESNET/Impact", - "v" : "System provides UDP QOTD service and can be misused for massive DDoS attack" - } - ], - "title" : "Scan QOTD", - "class" : "Scan QOTD", - "analyzer" : "SSERV", - "alias" : "sserv-011" - }, - "n6-005" : { - "_id" : "n6-005", - "label_e" : "Hlášení o strojích infikovaných malwarem Dorkbot (Dorkbot Report)", - "args" : "5", - "cmd_help" : "[source IP] [target IP] [duration] [bot name] [original log line]", - "cmd_example" : "195.113.134.254 198.51.100.23 2:29:14 {CZ|W7u}inpvqeu!~inpvqeu@will.not.show.it \"195.113.134.254 -> 198.51.100.23 (2:29:14) {CZ|W7u}inpvqeu!~inpvqeu@will.not.show.it | 2012-12-12_18:42:49 | D\"", - "id" : "n6-005", - "category" : "Intrusion.Botnet", - "severity" : "medium", - "enabled" : 1, - "label_s" : "Hlášení o strojích infikovaných malwarem Dorkbot (Dorkbot Report)", - "ref" : "https://csirt.cesnet.cz/cs/services/n6", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "N6" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "External" - }, - { - "k" : "Source[1]/%ipt:$1[1]", - "v" : "$1" - }, - { - "k" : "Source[1]/Type[1]", - "v" : "Botnet" - }, - { - "k" : "Target[1]/%ipt:$2[1]", - "v" : "$2" - }, - { - "k" : "Category[1]", - "v" : "Intrusion.Botnet" - }, - { - "k" : "Description", - "v" : "Dorkbot Report" - }, - { - "k" : "Note", - "v" : "Duration: $3, Bot name: $4" - }, - { - "k" : "Attach[1]/ContentType", - "v" : "text/plain" - }, - { - "k" : "Attach[1]/Note", - "v" : "Original info" - }, - { - "k" : "Attach[1]/Content", - "v" : "$5" - }, - { - "k" : "_CESNET/Impact", - "v" : "Host $1 connected to $2 and is infected with Dorkbot malware ($4)" - } - ], - "title" : "Dorkbot Report", - "class" : "Dorkbot Report", - "analyzer" : "N6", - "alias" : "n6-005" - }, - "sserv-004" : { - "_id" : "sserv-004", - "label_e" : "Stroj slouží jako proxy pro rozesílání spamu, nebo napadání dalších strojů (Botnet Proxy)", - "args" : "3", - "cmd_help" : "[source IP] [source port] [original log line]", - "cmd_example" : "195.113.134.254 80 \"195.113.134.254 80 (HTTPPROXY) 2011-03-10_11:57:00 P\"", - "id" : "sserv-004", - "category" : "Vulnerable", - "severity" : "medium", - "enabled" : 1, - "label_s" : "Stroje na následujících IP adresách jsou infikovány a slouží jako proxy pro rozesílání spamu, nebo napadání dalších strojů (Botnet Proxy)", - "ref" : "https://csirt.cesnet.cz/cs/services/sserv", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "SSERV" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "External" - }, - { - "k" : "Source[1]/%ipt:$1[1]", - "v" : "$1" - }, - { - "k" : "Source[1]/Port[1]", - "v" : "$2" - }, - { - "k" : "Source[1]/Proto[1]", - "v" : "tcp" - }, - { - "k" : "Source[1]/Proto[2]", - "v" : "http" - }, - { - "k" : "Source[1]/Type[1]", - "v" : "Proxy" - }, - { - "k" : "Category[1]", - "v" : "Vulnerable" - }, - { - "k" : "Description", - "v" : "Botnet Proxy" - }, - { - "k" : "Attach[1]/ContentType", - "v" : "text/plain" - }, - { - "k" : "Attach[1]/Note", - "v" : "Original info" - }, - { - "k" : "Attach[1]/Content", - "v" : "$3" - }, - { - "k" : "_CESNET/Impact", - "v" : "Host $1 is compromised and acts as open proxy for botnet, spam etc." - } - ], - "title" : "Botnet Proxy", - "class" : "Botnet Proxy", - "analyzer" : "SSERV", - "alias" : "sserv-004" - }, - "n6-027" : { - "_id" : "n6-027", - "label_e" : "Hlášení o strojích infikovaných malwarem Tinba (Tinba Report)", - "args" : "4", - "cmd_help" : "[source IP] [method] [target domain] [original log line]", - "cmd_example" : "195.113.134.254 GET zy37qwfad93.com \"195.113.134.254 | GET | zy37qwfad93.com | 2014-07-22_14:20:13 | T\"", - "id" : "n6-027", - "category" : "Intrusion.Botnet", - "severity" : "medium", - "enabled" : 1, - "label_s" : "Hlášení o strojích infikovaných malwarem Tinba (Tinba Report)", - "ref" : "https://csirt.cesnet.cz/cs/services/n6", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "N6" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "External" - }, - { - "k" : "Source[1]/%ipt:$1[1]", - "v" : "$1" - }, - { - "k" : "Source[1]/Type[1]", - "v" : "Malware" - }, - { - "k" : "Source[1]/Proto[1]", - "v" : "tcp" - }, - { - "k" : "Source[1]/Proto[2]", - "v" : "http" - }, - { - "k" : "Source[1]/Note", - "v" : "HTTP method: $2" - }, - { - "k" : "Target[1]/Hostname[1]", - "v" : "$3" - }, - { - "k" : "Target[1]/Proto[1]", - "v" : "tcp" - }, - { - "k" : "Target[1]/Proto[2]", - "v" : "http" - }, - { - "k" : "Category[1]", - "v" : "Intrusion.Botnet" - }, - { - "k" : "Description", - "v" : "Tinba Report" - }, - { - "k" : "Attach[1]/ContentType", - "v" : "text/plain" - }, - { - "k" : "Attach[1]/Note", - "v" : "Original info" - }, - { - "k" : "Attach[1]/Content", - "v" : "$4" - }, - { - "k" : "_CESNET/Impact", - "v" : "Host $1 is infected with Tinba malware pointing to domain $3" - } - ], - "title" : "Tinba Report", - "class" : "Tinba Report", - "analyzer" : "N6", - "alias" : "n6-027" - }, - "sserv-015" : { - "_id" : "sserv-015", - "label_e" : "Hlášení o webových serverech zkompromitovaných prostřednictvím botnetů. Mohou na nich běžet staré verze CMS (Joomla/Drupal/Wordpress) nebo užívají zkompromitovaných/slabých hesel správců (Compromised website)", - "args" : "5", - "cmd_help" : "[source IP] [port] [hostname] [URL] [original log line]", - "cmd_example" : "195.113.134.254 80 kariera.utb.cz images/821/72/css.php \"192.0.2.254|80 (hXXp,kariera.utb.cz,images/821/72/css.php) stealrat-t1|spam|2014-06-19_04:30:37|W\"", - "id" : "sserv-015", - "category" : "Intrusion.UserCompromise", - "severity" : "medium", - "enabled" : 1, - "label_s" : "Hlášení o webových serverech zkompromitovaných prostřednictvím botnetů. Mohou na nich běžet staré verze CMS (Joomla/Drupal/Wordpress) nebo užívají zkompromitovaných/slabých hesel správců (Compromised website)", - "ref" : "https://csirt.cesnet.cz/cs/services/sserv", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "SSERV" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "External" - }, - { - "k" : "Source[1]/%ipt:$1[1]", - "v" : "$1" - }, - { - "k" : "Source[1]/Port[1]", - "v" : "$2" - }, - { - "k" : "Source[1]/Proto[1]", - "v" : "tcp" - }, - { - "k" : "Source[1]/Proto[2]", - "v" : "http" - }, - { - "k" : "Source[1]/Hostname[1]", - "v" : "$3" - }, - { - "k" : "Source[1]/URL[1]", - "v" : "$4" - }, - { - "k" : "Category[1]", - "v" : "Intrusion.AppCompromise" - }, - { - "k" : "Category[2]", - "v" : "Intrusion.UserCompromise" - }, - { - "k" : "Description", - "v" : "Compromised website" - }, - { - "k" : "Attach[1]/ContentType", - "v" : "text/plain" - }, - { - "k" : "Attach[1]/Note", - "v" : "Original info" - }, - { - "k" : "Attach[1]/Content", - "v" : "$5" - }, - { - "k" : "_CESNET/Impact", - "v" : "System $1 ($3) provides compromised website at $4" - } - ], - "title" : "Compromised website", - "class" : "Compromised website", - "analyzer" : "SSERV", - "alias" : "sserv-015" - }, - "n6-018" : { - "_id" : "n6-018", - "label_e" : "Hlášení o strojích infikovaných malwarem Moure (Moure Sinkhole Report II)", - "args" : "5", - "cmd_help" : "[source IP] [method] [host] [target url] [original log line]", - "cmd_example" : "195.113.134.254 GET emigit.zz /9c6815ZcJl3an \"195.113.134.254 | GET emigit.zz /9c6815ZcJl3an | RR\"", - "id" : "n6-018", - "category" : "Intrusion.Botnet", - "severity" : "medium", - "enabled" : 1, - "label_s" : "Hlášení o strojích infikovaných malwarem Moure (Moure Sinkhole Report II)", - "ref" : "https://csirt.cesnet.cz/cs/services/n6", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "N6" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "External" - }, - { - "k" : "Node[1]/Type[2]", - "v" : "Blackhole" - }, - { - "k" : "Source[1]/%ipt:$1[1]", - "v" : "$1" - }, - { - "k" : "Source[1]/Type[1]", - "v" : "Malware" - }, - { - "k" : "Source[1]/Proto[1]", - "v" : "tcp" - }, - { - "k" : "Source[1]/Proto[2]", - "v" : "http" - }, - { - "k" : "Source[1]/Note", - "v" : "HTTP method: $2" - }, - { - "k" : "Target[1]/URL[1]", - "v" : "http://$3/$4" - }, - { - "k" : "Target[1]/Proto[1]", - "v" : "tcp" - }, - { - "k" : "Target[1]/Proto[2]", - "v" : "http" - }, - { - "k" : "Category[1]", - "v" : "Intrusion.Botnet" - }, - { - "k" : "Description", - "v" : "Moure Sinkhole Report II" - }, - { - "k" : "Attach[1]/ContentType", - "v" : "text/plain" - }, - { - "k" : "Attach[1]/Note", - "v" : "Original info" - }, - { - "k" : "Attach[1]/Content", - "v" : "$5" - }, - { - "k" : "_CESNET/Impact", - "v" : "Host $1 connected to $3 ($4) and is infected with Moure malware" - } - ], - "title" : "Moure Sinkhole Report II", - "class" : "Moure Sinkhole Report II", - "analyzer" : "N6", - "alias" : "n6-018" - }, - "sserv-013" : { - "_id" : "sserv-013", - "args" : "4", - "label_e" : "Hlášení o otevřených NTP serverech, které lze zneužít k útokům typu DDoS prostřednictvím dotazů typu Mode 6 (Scan NTP)", - "cmd_help" : "[source IP] [source port] [system name] [original log line]", - "cmd_example" : "195.113.134.254 123 \"XRX_OS/1.0 UPnP/1.0 Phaser 8550DP\" \"195.113.134.254 123 (ntpd 4.2.4p5-a1) 2014-03-27_14:03:16 T\"", - "id" : "sserv-013", - "category" : "Vulnerable.Config", - "severity" : "medium", - "enabled" : 1, - "label_s" : "Hlášení o otevřených NTP serverech, které lze zneužít k útokům typu DDoS prostřednictvím dotazů typu Mode 6 (Scan NTP)", - "ref" : "https://csirt.cesnet.cz/cs/services/sserv", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "SSERV" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "External" - }, - { - "k" : "Node[1]/Type[2]", - "v" : "Recon" - }, - { - "k" : "Source[1]/%ipt:$1[1]", - "v" : "$1" - }, - { - "k" : "Source[1]/Port[1]", - "v" : "$2" - }, - { - "k" : "Source[1]/Proto[1]", - "v" : "udp" - }, - { - "k" : "Source[1]/Proto[2]", - "v" : "ntp" - }, - { - "k" : "Source[1]/Note", - "v" : "System name: $3" - }, - { - "k" : "Category[1]", - "v" : "Vulnerable.Config" - }, - { - "k" : "Description", - "v" : "Scan NTP" - }, - { - "k" : "Attach[1]/ContentType", - "v" : "text/plain" - }, - { - "k" : "Attach[1]/Note", - "v" : "Original info" - }, - { - "k" : "Attach[1]/Content", - "v" : "$4" - }, - { - "k" : "_CESNET/Impact", - "v" : "System $3 provides open NTP service and can be misused for massive DDoS attack" - } - ], - "title" : "Scan NTP", - "class" : "Scan NTP", - "analyzer" : "SSERV", - "alias" : "sserv-013" - }, - "n6-024" : { - "_id" : "n6-024", - "label_e" : "Hlášení o strojích infikovaných malwarem Power Zeus (Power Zeus Report)", - "args" : "4", - "cmd_help" : "[source IP] [source url] [method] [original log line]", - "cmd_example" : "195.113.134.254 /dropfilms/data.php POST \"195.113.134.254 | /dropfilms/data.php (HTTP/1.1 POST) 2013-10-22_18:59:21 | Z\"", - "id" : "n6-024", - "category" : "Intrusion.Botnet", - "severity" : "medium", - "enabled" : 1, - "label_s" : "Hlášení o strojích infikovaných malwarem Power Zeus (Power Zeus Report)", - "ref" : "https://csirt.cesnet.cz/cs/services/n6", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "N6" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "External" - }, - { - "k" : "Source[1]/%ipt:$1[1]", - "v" : "$1" - }, - { - "k" : "Source[1]/Type[1]", - "v" : "Malware" - }, - { - "k" : "Source[1]/Proto[1]", - "v" : "tcp" - }, - { - "k" : "Source[1]/Proto[2]", - "v" : "http" - }, - { - "k" : "Source[1]/URL[1]", - "v" : "$2" - }, - { - "k" : "Source[1]/Note", - "v" : "HTTP method: $3" - }, - { - "k" : "Category[1]", - "v" : "Intrusion.Botnet" - }, - { - "k" : "Description", - "v" : "Power Zeus Report" - }, - { - "k" : "Attach[1]/ContentType", - "v" : "text/plain" - }, - { - "k" : "Attach[1]/Note", - "v" : "Original info" - }, - { - "k" : "Attach[1]/Content", - "v" : "$4" - }, - { - "k" : "_CESNET/Impact", - "v" : "Host $1 provides malicious URL $2 and is infected with Power Zeus malware" - } - ], - "title" : "Power Zeus Report", - "class" : "Power Zeus Report", - "analyzer" : "N6", - "alias" : "n6-024" - }, - "sserv-002" : { - "_id" : "sserv-002", - "label_e" : "Komunikace se známými řídícími servery botnetu (Botnet Drone)", - "args" : "6", - "cmd_help" : "[source IP] [source port] [target IP] [target port] [infection] [original log line]", - "cmd_example" : "195.113.134.254 2389 10.12.34.166 80 ConfickerC \"195.113.134.254 2389 -> 10.12.34.166 80 (ConfickerC) 2010-11-18_09:59:56 D\"", - "id" : "sserv-002", - "category" : "Intrusion.Botnet", - "severity" : "medium", - "enabled" : 1, - "label_s" : "Stroje na následujících IP adresách komunikovaly se známými řídícími servery botnetu (Botnet Drone)", - "ref" : "https://csirt.cesnet.cz/cs/services/sserv", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "SSERV" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "External" - }, - { - "k" : "Source[1]/%ipt:$1[1]", - "v" : "$1" - }, - { - "k" : "Source[1]/Port[1]", - "v" : "$2" - }, - { - "k" : "Source[1]/Note", - "v" : "Malware: $5" - }, - { - "k" : "Source[1]/Type[1]", - "v" : "Botnet" - }, - { - "k" : "Target[1]/%ipt:$3[1]", - "v" : "$3" - }, - { - "k" : "Target[1]/Port[1]", - "v" : "$4" - }, - { - "k" : "Target[1]/Type[1]", - "v" : "Botnet" - }, - { - "k" : "Target[1]/Type[2]", - "v" : "CC" - }, - { - "k" : "Category[1]", - "v" : "Intrusion.Botnet" - }, - { - "k" : "Description", - "v" : "Botnet Drone" - }, - { - "k" : "Attach[1]/ContentType", - "v" : "text/plain" - }, - { - "k" : "Attach[1]/Note", - "v" : "Original info" - }, - { - "k" : "Attach[1]/Content", - "v" : "$6" - }, - { - "k" : "_CESNET/Impact", - "v" : "Host $1 connected to $3 and is now part of botnet ($5)" - } - ], - "title" : "Botnet Drone", - "class" : "Botnet Drone", - "analyzer" : "SSERV", - "alias" : "sserv-002" - }, - "n6-025" : { - "_id" : "n6-025", - "label_e" : "Hlášení o strojích, na kterých je nainstalováno zranitelné OpenSSL (Heartbleed Report)", - "args" : "2", - "cmd_help" : "[source IP] [original log line]", - "cmd_example" : "195.113.134.254 \"195.113.134.254 | 2014-04-11_16:13:47 | H\"", - "id" : "n6-025", - "category" : "Vulnerable.Open", - "severity" : "medium", - "enabled" : 1, - "label_s" : "Hlášení o strojích, na kterých je nainstalováno zranitelné OpenSSL (Heartbleed Report)", - "ref" : "https://csirt.cesnet.cz/cs/services/n6", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "N6" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "External" - }, - { - "k" : "Node[1]/Type[2]", - "v" : "Recon" - }, - { - "k" : "Source[1]/%ipt:$1[1]", - "v" : "$1" - }, - { - "k" : "Ref[1]", - "v" : "urn:cve:CVE-2014-0160" - }, - { - "k" : "Category[1]", - "v" : "Vulnerable.Open" - }, - { - "k" : "Description", - "v" : "Heartbleed Report" - }, - { - "k" : "Attach[1]/ContentType", - "v" : "text/plain" - }, - { - "k" : "Attach[1]/Note", - "v" : "Original info" - }, - { - "k" : "Attach[1]/Content", - "v" : "$2" - }, - { - "k" : "_CESNET/Impact", - "v" : "Host $1 contains Heartbleed vulnerability" - } - ], - "title" : "Heartbleed Report", - "class" : "Heartbleed Report", - "analyzer" : "N6", - "alias" : "n6-025" - }, - "x2-004" : { - "_id" : "x2-004", - "label_e" : "Stroj funguje jako otevřený DNS resolver a může být zneužit pro masivní DDoS útoky (Open DNS Resolver)", - "args" : "2", - "cmd_help" : "[source IP] [original log line]", - "cmd_example" : "195.113.134.254 \"195.113.134.254 | 2013-01-16_06:14:20 | openresolver\"", - "id" : "x2-004", - "category" : "Vulnerable.Config", - "severity" : "medium", - "enabled" : 1, - "label_s" : "Stroje na následujících IP adresách fungují jako otevřené DNS resolvery a mohou být zneužity pro masivní DDoS útoky (Open DNS Resolver)", - "ref" : "https://csirt.cesnet.cz/cs/services/x2", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "X2" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "External" - }, - { - "k" : "Source[1]/%ipt:$1[1]", - "v" : "$1" - }, - { - "k" : "Source[1]/Proto[1]", - "v" : "udp" - }, - { - "k" : "Source[1]/Proto[2]", - "v" : "dns" - }, - { - "k" : "Category[1]", - "v" : "Vulnerable.Config" - }, - { - "k" : "Description", - "v" : "Open DNS Resolver" - }, - { - "k" : "Attach[1]/ContentType", - "v" : "text/plain" - }, - { - "k" : "Attach[1]/Note", - "v" : "Original info" - }, - { - "k" : "Attach[1]/Content", - "v" : "$2" - }, - { - "k" : "_CESNET/Impact", - "v" : "System $1 is ORR and can be misused to DDoS attacks" - } - ], - "title" : "Open DNS Resolver", - "class" : "Open DNS Resolver", - "analyzer" : "X2", - "alias" : "x2-004" - }, - "dio-httpd" : { - "_id" : "dio-httpd", - "args" : "6", - "label_e" : "Pokus o zneužití webového serveru prostřednictvím URL", - "cmd_help" : "[source IP type] [source IP] [source port] [target IP] [target port] [event count]", - "cmd_example" : "ipv4-addr 195.113.134.254 56 195.113.161.181 56 100", - "category" : "Attempt.Exploit", - "id" : "dio-httpd", - "severity" : "low", - "enabled" : 1, - "label_s" : "Stroje na následujících IP adresách se pokusily zneužít webový server prostřednictvím URL", - "ref" : "", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "Dionaea" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "Honeypot" - }, - { - "k" : "Node[1]/Type[2]", - "v" : "Protocol" - }, - { - "k" : "Source[1]/%ipt:$2[1]", - "v" : "$2" - }, - { - "k" : "Source[1]/Proto[1]", - "v" : "tcp" - }, - { - "k" : "Source[1]/Proto[2]", - "v" : "http" - }, - { - "k" : "Source[1]/Port[1]", - "v" : "$3" - }, - { - "k" : "Target[1]/%ipt:$4[1]", - "v" : "$4" - }, - { - "k" : "Target[1]/Proto[1]", - "v" : "tcp" - }, - { - "k" : "Target[1]/Proto[2]", - "v" : "http" - }, - { - "k" : "Target[1]/Port[1]", - "v" : "$5" - }, - { - "k" : "Category[1]", - "v" : "Recon.Scanning" - }, - { - "k" : "Category[2]", - "v" : "Attempt.Exploit" - }, - { - "k" : "Description", - "v" : "URL attack attempt" - }, - { - "k" : "ConnCount", - "v" : "$6" - }, - { - "k" : "_CESNET/Impact", - "v" : "Remote host tried to open URLs on port $5 from $2:$3" - } - ], - "title" : "URL attack attempt", - "class" : "URL attack attempt", - "analyzer" : "Dionaea", - "alias" : "dio-httpd" - }, - "x2-001" : { - "_id" : "x2-001", - "label_e" : "Hlášení o infikovaných strojích, které jsou součástí botnetů (Bots)", - "args" : "3", - "cmd_help" : "[source IP] [malware type] [original log line]", - "cmd_example" : "195.113.134.254 Torpig \"195.113.134.254 | 2013-01-14_07:34:34 | bots: mwtype Torpig\"", - "id" : "x2-001", - "category" : "Intrusion.Botnet", - "severity" : "medium", - "enabled" : 1, - "label_s" : "Hlášení o infikovaných strojích, které jsou součástí botnetů (Bots)", - "ref" : "https://csirt.cesnet.cz/cs/services/x2", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "X2" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "External" - }, - { - "k" : "Source[1]/%ipt:$1[1]", - "v" : "$1" - }, - { - "k" : "Source[1]/Note", - "v" : "Malware: $2" - }, - { - "k" : "Category[1]", - "v" : "Intrusion.Botnet" - }, - { - "k" : "Description", - "v" : "Bots" - }, - { - "k" : "Attach[1]/ContentType", - "v" : "text/plain" - }, - { - "k" : "Attach[1]/Note", - "v" : "Original info" - }, - { - "k" : "Attach[1]/Content", - "v" : "$3" - }, - { - "k" : "_CESNET/Impact", - "v" : "System $1 is part of the $2 botnet" - } - ], - "title" : "Bots", - "class" : "Bots", - "analyzer" : "X2", - "alias" : "x2-001" - }, - "sserv-003" : { - "_id" : "sserv-003", - "label_e" : "Stroj slouží jako proxy pro rozesílání spamu, nebo napadání dalších strojů (Open Proxy)", - "args" : "3", - "cmd_help" : "[source IP] [source port] [original log line]", - "cmd_example" : "195.113.134.254 3128 \"195.113.134.254 3128 (HTTP 1.1 192.168.1.1 (Mikrotik HTTPProxy)) 2012-04-24_21:09:20 O\"", - "id" : "sserv-003", - "category" : "Vulnerable", - "severity" : "medium", - "enabled" : 1, - "label_s" : "Stroje na následujících IP adresách jsou infikovány a slouží jako proxy pro rozesílání spamu, nebo napadání dalších strojů (Open Proxy)", - "ref" : "https://csirt.cesnet.cz/cs/services/sserv", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "SSERV" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "External" - }, - { - "k" : "Source[1]/%ipt:$1[1]", - "v" : "$1" - }, - { - "k" : "Source[1]/Port[1]", - "v" : "$2" - }, - { - "k" : "Source[1]/Proto[1]", - "v" : "tcp" - }, - { - "k" : "Source[1]/Proto[2]", - "v" : "http" - }, - { - "k" : "Source[1]/Type[1]", - "v" : "Proxy" - }, - { - "k" : "Category[1]", - "v" : "Vulnerable" - }, - { - "k" : "Description", - "v" : "Open Proxy" - }, - { - "k" : "Attach[1]/ContentType", - "v" : "text/plain" - }, - { - "k" : "Attach[1]/Note", - "v" : "Original info" - }, - { - "k" : "Attach[1]/Content", - "v" : "$3" - }, - { - "k" : "_CESNET/Impact", - "v" : "Host $1 is compromised and acts as open proxy for botnet, spam etc." - } - ], - "title" : "Open Proxy", - "class" : "Open Proxy", - "analyzer" : "SSERV", - "alias" : "sserv-003" - }, - "warden-other" : { - "_id" : "warden-other", - "label_e" : "Jiny problem", - "args" : "10", - "cmd_help" : "[analyzer] [analyzer_class] [ip_category] [src_ip] [proto_name] [proto_num] [tgt_port] [count] [note] [origin]", - "cmd_example" : "analyzer detector ipv4-addr 195.113.134.254 tcp 6 1234 100 \"Additional note\" warden", - "category" : "Other", - "id" : "warden-other", - "severity" : "low", - "enabled" : 1, - "label_s" : "Jiny problem", - "ref" : "", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "$1" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "$2" - }, - { - "k" : "Source[1]/%ipt:$4[1]", - "v" : "$4" - }, - { - "k" : "Source[1]/Proto[1]", - "v" : "$5" - }, - { - "k" : "Target[1]/Port[1]", - "v" : "$7" - }, - { - "k" : "Target[1]/Proto[1]", - "v" : "$5" - }, - { - "k" : "Category[1]", - "v" : "Other" - }, - { - "k" : "Description", - "v" : "Other" - }, - { - "k" : "ConnCount", - "v" : "$8" - }, - { - "k" : "Note", - "v" : "$9" - }, - { - "k" : "_CESNET/Origin", - "v" : "$10" - }, - { - "k" : "_CESNET/Impact", - "v" : "Remote host $4 performed uncategorizable attack" - } - ], - "title" : "Other", - "class" : "Other", - "analyzer" : "", - "alias" : "warden-other" - }, - "n6-026" : { - "_id" : "n6-026", - "label_e" : "Hlášení o strojích infikovaných malwarem Energetic Bear (Energetic Bear Report)", - "args" : "2", - "cmd_help" : "[source IP] [original log line]", - "cmd_example" : "195.113.134.254 \"195.113.134.254 | 2014-07-22_14:15:31 | e \"", - "id" : "n6-026", - "category" : "Intrusion.Botnet", - "severity" : "high", - "enabled" : 1, - "label_s" : "Hlášení o strojích infikovaných malwarem Energetic Bear (Energetic Bear Report)", - "ref" : "https://csirt.cesnet.cz/cs/services/n6", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "N6" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "External" - }, - { - "k" : "Source[1]/%ipt:$1[1]", - "v" : "$1" - }, - { - "k" : "Category[1]", - "v" : "Intrusion.Botnet" - }, - { - "k" : "Description", - "v" : "Energetic Bear Report" - }, - { - "k" : "Attach[1]/ContentType", - "v" : "text/plain" - }, - { - "k" : "Attach[1]/Note", - "v" : "Original info" - }, - { - "k" : "Attach[1]/Content", - "v" : "$2" - }, - { - "k" : "_CESNET/Impact", - "v" : "Host $1 is infected with Energetic Bear malware" - } - ], - "title" : "Energetic Bear Report", - "class" : "Energetic Bear Report", - "analyzer" : "N6", - "alias" : "n6-026" - }, - "warden-copyright" : { - "_id" : "warden-copyright", - "args" : "10", - "label_e" : "Porušování autorských práv", - "cmd_help" : "[analyzer] [analyzer_class] [ip_category] [src_ip] [proto_name] [proto_num] [tgt_port] [count] [note] [origin]", - "cmd_example" : "analyzer detector ipv4-addr 195.113.134.254 tcp 6 1234 100 \"Additional note\" warden", - "category" : "Fraud.Copyright", - "id" : "warden-copyright", - "severity" : "low", - "enabled" : 1, - "label_s" : "Porušování autorských práv", - "ref" : "", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "$1" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "$2" - }, - { - "k" : "Source[1]/%ipt:$4[1]", - "v" : "$4" - }, - { - "k" : "Source[1]/Proto[1]", - "v" : "$5" - }, - { - "k" : "Target[1]/Port[1]", - "v" : "$7" - }, - { - "k" : "Target[1]/Proto[1]", - "v" : "$5" - }, - { - "k" : "Category[1]", - "v" : "Fraud.Copyright" - }, - { - "k" : "Description", - "v" : "Copyright infringement" - }, - { - "k" : "ConnCount", - "v" : "$8" - }, - { - "k" : "Note", - "v" : "$9" - }, - { - "k" : "_CESNET/Origin", - "v" : "$10" - }, - { - "k" : "_CESNET/Impact", - "v" : "Remote host $4 infringed copyrights" - } - ], - "title" : "Copyright infringement", - "class" : "Copyright infringement", - "analyzer" : "", - "alias" : "warden-copyright" - }, - "beekeeper-01" : { - "_id" : "beekeeper-01", - "args" : "6", - "label_e" : "Pokus o útok na sadu SIP honeypotů", - "cmd_help" : "[source IP] [source port] [target IP] [info] [message count] [cease time]", - "cmd_example" : "195.113.134.254 5060 195.113.113.150 \"reg-test\" 25 1424426171", - "id" : "beekeeper-01", - "category" : "Attempt.Exploit", - "severity" : "low", - "enabled" : 1, - "label_s" : "Hlášení o útocích na sadu SIP honeypotů", - "ref" : "", - "description" : "", - "note" : "", - "class" : "SIP attack", - "title" : "SIP attack", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "Beekeeper" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "Protocol" - }, - { - "k" : "Node[1]/Type[2]", - "v" : "Honeypot" - }, - { - "k" : "Source[1]/%ipt:$1[1]", - "v" : "$1" - }, - { - "k" : "Source[1]/Port[1]", - "v" : "$2" - }, - { - "k" : "Target[1]/%ipt:$3[1]", - "v" : "$3" - }, - { - "k" : "Target[1]/Port[1]", - "v" : "5060" - }, - { - "k" : "Category[1]", - "v" : "Attempt.Exploit" - }, - { - "k" : "Description", - "v" : "SIP attack classification: $4" - }, - { - "k" : "Note", - "v" : "Remote host tried to run $4 on SIP honeypot $3 port 5060" - }, - { - "k" : "ConnCount", - "v" : "$5" - }, - { - "k" : "CeaseTime", - "v" : "%ts:$6" - } - ], - "analyzer" : "Beekeeper", - "alias" : "beekeeper-01" - }, - "warden-botnet_c_c" : { - "_id" : "warden-botnet_c_c", - "label_e" : "Stroj byl označen jako pravděpodobný řídící server botnetu (Botnet Command and Control)", - "args" : "10", - "cmd_help" : "[analyzer] [analyzer_class] [ip_category] [src_ip] [proto_name] [proto_num] [src_port] [count] [note] [origin]", - "cmd_example" : "analyzer detector ipv4-addr 195.113.134.254 tcp 6 1234 100 \"Additional note\" warden", - "category" : "Intrusion.Botnet", - "id" : "warden-botnet_c_c", - "severity" : "low", - "enabled" : 1, - "label_s" : "Stroje na následujících IP adresách jsou pravděpodobně řídícími servery botnetu (Botnet Command and Control)", - "ref" : "", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "$1" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "$2" - }, - { - "k" : "Source[1]/%ipt:$4[1]", - "v" : "$4" - }, - { - "k" : "Source[1]/Proto[1]", - "v" : "$5" - }, - { - "k" : "Target[1]/Port[1]", - "v" : "$7" - }, - { - "k" : "Source/Type[1]", - "v" : "Botnet" - }, - { - "k" : "Source/Type[2]", - "v" : "CC" - }, - { - "k" : "Category[1]", - "v" : "Intrusion.Botnet" - }, - { - "k" : "Description", - "v" : "Botnet Command and Control" - }, - { - "k" : "ConnCount", - "v" : "$8" - }, - { - "k" : "Note", - "v" : "$9" - }, - { - "k" : "_CESNET/Origin", - "v" : "$10" - }, - { - "k" : "_CESNET/Impact", - "v" : "Remote host $4 is command & control master machine" - } - ], - "title" : "Botnet Command and Control", - "class" : "Botnet Command and Control", - "analyzer" : "", - "alias" : "warden-botnet_c_c" - }, - "n6-034" : { - "_id" : "n6-034", - "label_e" : "Informace o strojích infikovaných bankovním trojským koněm Geodo (Geodo Trojan Report)", - "args" : "2", - "cmd_help" : "[source IP] [original log line]", - "cmd_example" : "192.0.2.204 \"192.0.2.204 | 2014-12-03_16:17:41 | t\"", - "id" : "n6-034", - "category" : "Malware", - "severity" : "medium", - "enabled" : 1, - "label_s" : "Informace o strojích infikovaných bankovním trojským koněm Geodo (Geodo Trojan Report)", - "ref" : "https://csirt.cesnet.cz/cs/services/n6", - "description" : "", - "note" : "", - "class" : "Geodo Trojan Report", - "title" : "Geodo Trojan Report", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "N6" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "External" - }, - { - "k" : "Source[1]/%ipt:$1[1]", - "v" : "$1" - }, - { - "k" : "Source[1]/Type[1]", - "v" : "Malware" - }, - { - "k" : "Source[1]/Type[2]", - "v" : "trojan" - }, - { - "k" : "Category[1]", - "v" : "Malware" - }, - { - "k" : "Description", - "v" : "Geodo Trojan Report" - }, - { - "k" : "Attach[1]/ContentType", - "v" : "text/plain" - }, - { - "k" : "Attach[1]/Note", - "v" : "Original info" - }, - { - "k" : "Attach[1]/Content", - "v" : "$2" - }, - { - "k" : "_CESNET/Impact", - "v" : "Host $1 is infected with banking Geodo Trojan malware" - } - ], - "alias" : "n6-034", - "analyzer" : "N6" - }, - "n6-003" : { - "_id" : "n6-003", - "label_e" : "Hlášení o strojích, které komunikovaly v rámci sítě P2P trojského koně Zeus (Bot Zeus P2P Report)", - "args" : "3", - "cmd_help" : "[source IP] [source port] [original log line]", - "cmd_example" : "192.0.2.29 22255 \"192.0.2.29 | 22255 | 2014-01-03_07:32:59 | B\"", - "id" : "n6-003", - "category" : "Intrusion.Botnet", - "severity" : "medium", - "enabled" : 1, - "label_s" : "Hlášení o strojích, které komunikovaly v rámci sítě P2P trojského koně Zeus (Bot Zeus P2P Report)", - "ref" : "https://csirt.cesnet.cz/cs/services/n6", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "N6" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "External" - }, - { - "k" : "Source[1]/%ipt:$1[1]", - "v" : "$1" - }, - { - "k" : "Source[1]/Port[1]", - "v" : "$2" - }, - { - "k" : "Category[1]", - "v" : "Intrusion.Botnet" - }, - { - "k" : "Description", - "v" : "Bot Zeus P2P Report" - }, - { - "k" : "Attach[1]/ContentType", - "v" : "text/plain" - }, - { - "k" : "Attach[1]/Note", - "v" : "Original info" - }, - { - "k" : "Attach[1]/Content", - "v" : "$3" - }, - { - "k" : "_CESNET/Impact", - "v" : "Host $1 is infected with Zeus malware" - } - ], - "title" : "Bot Zeus P2P Report", - "class" : "Bot Zeus P2P Report", - "analyzer" : "N6", - "alias" : "n6-003" - }, - "n6-006" : { - "_id" : "n6-006", - "label_e" : "Hlášení o podezřelé komunikaci strojů, vyvolané několika typy malware, např. Citadel a Virut (CERT PL Sinkhole Report)", - "args" : "6", - "cmd_help" : "[source IP] [source port] [target IP] [target port] [malware] [original log line]", - "cmd_example" : "195.113.134.254 3213 198.51.100.55 80 virut \"195.113.134.254 | 3213 -> 198.51.100.55 | 80 | botnet:virut | 2013-09-19_10:06:19 | E\"", - "id" : "n6-006", - "category" : "Intrusion.Botnet", - "severity" : "medium", - "enabled" : 1, - "label_s" : "Hlášení o podezřelé komunikaci strojů, vyvolané několika typy malware, např. Citadel a Virut (CERT PL Sinkhole Report)", - "ref" : "https://csirt.cesnet.cz/cs/services/n6", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "N6" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "External" - }, - { - "k" : "Node[1]/Type[2]", - "v" : "Blackhole" - }, - { - "k" : "Source[1]/%ipt:$1[1]", - "v" : "$1" - }, - { - "k" : "Source[1]/Port[1]", - "v" : "$2" - }, - { - "k" : "Target[1]/%ipt:$3[1]", - "v" : "$3" - }, - { - "k" : "Target[1]/Port[1]", - "v" : "$4" - }, - { - "k" : "Category[1]", - "v" : "Intrusion.Botnet" - }, - { - "k" : "Description", - "v" : "CERT PL Sinkhole Report" - }, - { - "k" : "Note", - "v" : "Malware: $5" - }, - { - "k" : "Attach[1]/ContentType", - "v" : "text/plain" - }, - { - "k" : "Attach[1]/Note", - "v" : "Original info" - }, - { - "k" : "Attach[1]/Content", - "v" : "$6" - }, - { - "k" : "_CESNET/Impact", - "v" : "Host $1:$2 connected to $3:$4 and is infected with $5 malware" - } - ], - "title" : "CERT PL Sinkhole Report", - "class" : "CERT PL Sinkhole Report", - "analyzer" : "N6", - "alias" : "n6-006" - }, - "labrea-002" : { - "_id" : "labrea-002", - "label_e" : "Pokus o PING na takové IP adresy, kde nejsou a nikdy nebyly v provozu žádné síťové servery", - "args" : "5", - "cmd_help" : "[source IP] [target IP] [event cease time] [event count] [original log line]", - "cmd_example" : "195.113.134.254 78.00.00.00 1274107160 50 \"1274106860 Responded to a Ping: 195.113.134.254 -> 78.xx.xx.xx\"", - "id" : "labrea-002", - "category" : "Recon.Scanning", - "severity" : "medium", - "enabled" : 1, - "label_s" : "Stroje na následujících IP adresách se pokusily o PING na takové IP adresy, kde nejsou a nikdy nebyly v provozu žádné síťové servery", - "ref" : "", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "LaBrea" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "Connection" - }, - { - "k" : "Node[1]/Type[2]", - "v" : "Tarpit" - }, - { - "k" : "Source[1]/%ipt:$1[1]", - "v" : "$1" - }, - { - "k" : "Target[1]/%ipt:$2[1]", - "v" : "$2" - }, - { - "k" : "CeaseTime", - "v" : "$3" - }, - { - "k" : "Category[1]", - "v" : "Recon.Scanning" - }, - { - "k" : "Description", - "v" : "Ping scan" - }, - { - "k" : "ConnCount", - "v" : "$4" - }, - { - "k" : "Attach[1]/Type[1]", - "v" : "Syslog" - }, - { - "k" : "Attach[1]/ContentType", - "v" : "text/plain" - }, - { - "k" : "Attach[1]/Content", - "v" : "$5" - }, - { - "k" : "_CESNET/Impact", - "v" : "Honeypot received $4 ping request(s) from remote host $1" - } - ], - "title" : "Ping probe", - "class" : "Ping probe", - "analyzer" : "LaBrea", - "alias" : "labrea-002" - }, - "sserv-010" : { - "_id" : "sserv-010", - "args" : "4", - "label_e" : "Hlášení o strojích poskytujících službu SNMP verze 2, které lze zneužít k masivním útokům typu DDoS (Scan SNMP)", - "cmd_help" : "[source IP] [source port] [system name] [original log line]", - "cmd_example" : "195.113.134.254 161 TIS-HPLJ2055 \"195.113.134.254 161 (TIS-HPLJ2055) 2014-03-27_14:58:12 N\"", - "id" : "sserv-010", - "category" : "Vulnerable.Config", - "severity" : "high", - "enabled" : 1, - "label_s" : "Hlášení o strojích poskytujících službu SNMP verze 2, které lze zneužít k masivním útokům typu DDoS (Scan SNMP)", - "ref" : "https://csirt.cesnet.cz/cs/services/sserv", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "SSERV" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "External" - }, - { - "k" : "Node[1]/Type[2]", - "v" : "Recon" - }, - { - "k" : "Source[1]/%ipt:$1[1]", - "v" : "$1" - }, - { - "k" : "Source[1]/Port[1]", - "v" : "$2" - }, - { - "k" : "Source[1]/Proto[1]", - "v" : "udp" - }, - { - "k" : "Source[1]/Proto[2]", - "v" : "snmp" - }, - { - "k" : "Source[1]/Note", - "v" : "System name: $3" - }, - { - "k" : "Category[1]", - "v" : "Vulnerable.Config" - }, - { - "k" : "Description", - "v" : "Scan SNMP" - }, - { - "k" : "Attach[1]/ContentType", - "v" : "text/plain" - }, - { - "k" : "Attach[1]/Note", - "v" : "Original info" - }, - { - "k" : "Attach[1]/Content", - "v" : "$4" - }, - { - "k" : "_CESNET/Impact", - "v" : "System $3 provides open SNMPv2 and can be misused for massive DDoS attack" - } - ], - "title" : "Scan SNMP", - "class" : "Scan SNMP", - "analyzer" : "SSERV", - "alias" : "sserv-010" - }, - "n6-010" : { - "_id" : "n6-010", - "label_e" : "Hlášení o strojích infikovaných malwarem Citadel (Citadel Sinkhole Report II)", - "args" : "5", - "cmd_help" : "[source IP] [method] [host] [target url] [original log line]", - "cmd_example" : "195.113.134.254 POST infocyber.zz /citdl/newmixplfit/cfgp.php \"195.113.134.254 | POST infocyber.zz /citdl/newmixplfit/cfgp.php | II\"", - "id" : "n6-010", - "category" : "Intrusion.Botnet", - "severity" : "medium", - "enabled" : 1, - "label_s" : "Hlášení o strojích infikovaných malwarem Citadel (Citadel Sinkhole Report II)", - "ref" : "https://csirt.cesnet.cz/cs/services/n6", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "N6" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "External" - }, - { - "k" : "Node[1]/Type[2]", - "v" : "Blackhole" - }, - { - "k" : "Source[1]/%ipt:$1[1]", - "v" : "$1" - }, - { - "k" : "Source[1]/Type[1]", - "v" : "Botnet" - }, - { - "k" : "Source[1]/Proto[1]", - "v" : "tcp" - }, - { - "k" : "Source[1]/Proto[2]", - "v" : "http" - }, - { - "k" : "Source[1]/Note", - "v" : "HTTP method: $2" - }, - { - "k" : "Target[1]/URL[1]", - "v" : "http://$3/$4" - }, - { - "k" : "Target[1]/Proto[1]", - "v" : "tcp" - }, - { - "k" : "Target[1]/Proto[2]", - "v" : "http" - }, - { - "k" : "Category[1]", - "v" : "Intrusion.Botnet" - }, - { - "k" : "Description", - "v" : "Citadel Sinkhole Report II" - }, - { - "k" : "Attach[1]/ContentType", - "v" : "text/plain" - }, - { - "k" : "Attach[1]/Note", - "v" : "Original info" - }, - { - "k" : "Attach[1]/Content", - "v" : "$5" - }, - { - "k" : "_CESNET/Impact", - "v" : "Host $1 connected to $3 ($4) and is infected with Citadel malware" - } - ], - "title" : "Citadel Sinkhole Report II", - "class" : "Citadel Sinkhole Report II", - "analyzer" : "N6", - "alias" : "n6-010" - }, - "warden-bruteforce" : { - "_id" : "warden-bruteforce", - "args" : "10", - "label_e" : "Hlášení o strojích, které se snažily prolomit heslo hrubou silou (Bruteforce)", - "cmd_help" : "[analyzer] [analyzer_class] [ip_category] [src_ip] [proto_name] [proto_num] [tgt_port] [count] [note] [origin]", - "cmd_example" : "analyzer detector ipv4-addr 195.113.134.254 tcp 6 1234 100 \"Additional note\" warden", - "category" : "Attempt.Login", - "id" : "warden-bruteforce", - "severity" : "low", - "enabled" : 1, - "label_s" : "Hlášení o strojích, které se snažily prolomit heslo hrubou silou (Bruteforce)", - "ref" : "", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "$1" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "$2" - }, - { - "k" : "Source[1]/%ipt:$4[1]", - "v" : "$4" - }, - { - "k" : "Source[1]/Proto[1]", - "v" : "$5" - }, - { - "k" : "Target[1]/Port[1]", - "v" : "$7" - }, - { - "k" : "Target[1]/Proto[1]", - "v" : "$5" - }, - { - "k" : "Category[1]", - "v" : "Attempt.Login" - }, - { - "k" : "Description", - "v" : "Bruteforce" - }, - { - "k" : "ConnCount", - "v" : "$8" - }, - { - "k" : "Note", - "v" : "$9" - }, - { - "k" : "_CESNET/Origin", - "v" : "$10" - }, - { - "k" : "_CESNET/Impact", - "v" : "Attack to authentication services from $4" - } - ], - "title" : "Bruteforce", - "class" : "Bruteforce", - "analyzer" : "", - "alias" : "warden-bruteforce" - }, - "n6-030" : { - "_id" : "n6-030", - "args" : "4", - "label_e" : "Hlášení o strojích zapojených do botnetu Andromeda (Andromeda Report)", - "cmd_help" : "[source IP] [botnet installation] [last cac communication] [original log line]", - "cmd_example" : "195.113.134.254 2014-10-30T23:44:56 2014-10-31T08:12:50 \"195.113.134.254 | 2014-10-30T23:44:56 | 2014-10-31T08:12:50 | a\"", - "id" : "n6-030", - "category" : "Intrusion.Botnet", - "severity" : "medium", - "enabled" : 1, - "label_s" : "Hlášení o strojích zapojených do botnetu Andromeda (Andromeda Report)", - "ref" : "https://csirt.cesnet.cz/cs/services/n6", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "N6" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "External" - }, - { - "k" : "Source[1]/%ipt:$1[1]", - "v" : "$1" - }, - { - "k" : "EventTime", - "v" : "$2" - }, - { - "k" : "CeaseTime", - "v" : "$3" - }, - { - "k" : "Category[1]", - "v" : "Intrusion.Botnet" - }, - { - "k" : "Description", - "v" : "Andromeda Botnet Report" - }, - { - "k" : "Attach[1]/ContentType", - "v" : "text/plain" - }, - { - "k" : "Attach[1]/Note", - "v" : "Original info" - }, - { - "k" : "Attach[1]/Content", - "v" : "$4" - }, - { - "k" : "_CESNET/Impact", - "v" : "Host $1 is part of Andromeda botnet, last communication with CaC was $3" - } - ], - "title" : "Andromeda Botnet Report", - "class" : "Andromeda Botnet Report", - "analyzer" : "N6", - "alias" : "n6-030" - }, - "dio-mssqld" : { - "_id" : "dio-mssqld", - "label_e" : "Pokus o útok na MSSQL server", - "args" : "6", - "cmd_help" : "[source IP type] [source IP] [source port] [target IP] [target port] [event count]", - "cmd_example" : "ipv4-addr 195.113.134.254 56 195.113.161.181 56 100", - "category" : "Attempt.Exploit", - "id" : "dio-mssqld", - "severity" : "low", - "enabled" : 1, - "label_s" : "Stroje na následujících IP adresách se pokusily zaútočit na MSSQL server", - "ref" : "", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "Dionaea" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "Honeypot" - }, - { - "k" : "Node[1]/Type[2]", - "v" : "Protocol" - }, - { - "k" : "Source[1]/%ipt:$2[1]", - "v" : "$2" - }, - { - "k" : "Source[1]/Proto[1]", - "v" : "tcp" - }, - { - "k" : "Source[1]/Proto[2]", - "v" : "ms-sql-s" - }, - { - "k" : "Source[1]/Port[1]", - "v" : "$3" - }, - { - "k" : "Target[1]/%ipt:$4[1]", - "v" : "$4" - }, - { - "k" : "Target[1]/Proto[1]", - "v" : "tcp" - }, - { - "k" : "Target[1]/Proto[2]", - "v" : "sql" - }, - { - "k" : "Target[1]/Port[1]", - "v" : "$5" - }, - { - "k" : "Category[1]", - "v" : "Recon.Scanning" - }, - { - "k" : "Category[2]", - "v" : "Attempt.Exploit" - }, - { - "k" : "Description", - "v" : "SQL query attack attempt" - }, - { - "k" : "ConnCount", - "v" : "$6" - }, - { - "k" : "_CESNET/Impact", - "v" : "Remote host connected to MSSQL on port $5 from $2:$3" - } - ], - "title" : "MSSQL query attack attempt", - "class" : "SQL query attack attempt", - "analyzer" : "Dionaea", - "alias" : "dio-mssqld" - }, - "n6-002" : { - "_id" : "n6-002", - "args" : "5", - "label_e" : "Hlášení o strojích, které komunikovaly s řídícími centry botnetů (Bot Report)", - "cmd_help" : "[source IP] [target name] [request uri] [request method] [original log line]", - "cmd_example" : "195.113.134.254 hack.org /image.php POST \"195.113.134.254 -> hack.org | /image.php (HTTP/1.0 POST) 2012-12-10_07:32:59 | b\"", - "id" : "n6-002", - "category" : "Intrusion.Botnet", - "severity" : "medium", - "enabled" : 1, - "label_s" : "Hlášení o strojích, které komunikovaly s řídícími centry botnetů (Bot Report)", - "ref" : "https://csirt.cesnet.cz/cs/services/n6", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "N6" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "External" - }, - { - "k" : "Source[1]/%ipt:$1[1]", - "v" : "$1" - }, - { - "k" : "Source[1]/Type[1]", - "v" : "Botnet" - }, - { - "k" : "Source[1]/Proto[1]", - "v" : "tcp" - }, - { - "k" : "Source[1]/Proto[2]", - "v" : "http" - }, - { - "k" : "Source[1]/Note", - "v" : "HTTP method: $4" - }, - { - "k" : "Target[1]/URL[1]", - "v" : "http://$2/$3" - }, - { - "k" : "Target[1]/Proto[1]", - "v" : "tcp" - }, - { - "k" : "Target[1]/Proto[2]", - "v" : "http" - }, - { - "k" : "Category[1]", - "v" : "Intrusion.Botnet" - }, - { - "k" : "Description", - "v" : "Bot Report" - }, - { - "k" : "Attach[1]/ContentType", - "v" : "text/plain" - }, - { - "k" : "Attach[1]/Note", - "v" : "Original info" - }, - { - "k" : "Attach[1]/Content", - "v" : "$5" - }, - { - "k" : "_CESNET/Impact", - "v" : "Host $1 contacted known CaC at $2 ($3)" - } - ], - "title" : "Bot Report", - "class" : "Bot Report", - "analyzer" : "N6", - "alias" : "n6-002" - }, - "f2b-001" : { - "_id" : "f2b-001", - "args" : "3", - "label_e" : "Pokus o další rozesílání pošty navzdory tomu, že IP adresa je již uvedena na pěti různých blacklistech", - "cmd_help" : "[blacklisted IP] [blaclist time] [impact]", - "cmd_example" : "195.113.134.254 3600 \"Host was blacklisted, too many SSH login attempts\"", - "id" : "f2b-001", - "category" : "Abusive.Spam", - "severity" : "medium", - "enabled" : 1, - "label_s" : "Pokusy o další rozesílání pošty navzdory tomu, že IP adresy jsou již uvedeny na pěti různých blacklistech", - "ref" : "", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "Fail2Ban" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "Log" - }, - { - "k" : "Node[1]/Type[2]", - "v" : "Statistical" - }, - { - "k" : "Source[1]/%ipt:$1[1]", - "v" : "$1" - }, - { - "k" : "Category[1]", - "v" : "Abusive.Spam" - }, - { - "k" : "Description", - "v" : "Remote login" - }, - { - "k" : "Note", - "v" : "Block duration: $2. $3" - }, - { - "k" : "_CESNET/Impact", - "v" : "$3" - } - ], - "title" : "Blacklisted host", - "class" : "Blacklisted host", - "analyzer" : "Fail2Ban", - "alias" : "f2b-001" - }, - "n6-007" : { - "_id" : "n6-007", - "label_e" : "Informace o otevřených DNS resolverech, které se účastnily útoku DDoS a jež detekovala síť Cloudflare (Cloudflare DDoS Open DNS Resolver Report)", - "args" : "2", - "cmd_help" : "[source IP] [original log line]", - "cmd_example" : "195.113.134.254 \"195.113.134.254 | F\"", - "id" : "n6-007", - "category" : "Vulnerable.Config", - "severity" : "high", - "enabled" : 1, - "label_s" : "Informace o otevřených DNS resolverech, které se účastnily útoku DDoS a jež detekovala síť Cloudflare (Cloudflare DDoS Open DNS Resolver Report)", - "ref" : "https://csirt.cesnet.cz/cs/services/n6", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "N6" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "External" - }, - { - "k" : "Source[1]/%ipt:$1[1]", - "v" : "$1" - }, - { - "k" : "Source[1]/Type[1]", - "v" : "Open" - }, - { - "k" : "Source[1]/Type[2]", - "v" : "Backscatter" - }, - { - "k" : "Source[1]/Proto[1]", - "v" : "udp" - }, - { - "k" : "Source[1]/Proto[2]", - "v" : "domain" - }, - { - "k" : "Category[1]", - "v" : "Vulnerable.Config" - }, - { - "k" : "Description", - "v" : "Cloudflare DDoS Open DNS Resolver Report" - }, - { - "k" : "Attach[1]/ContentType", - "v" : "text/plain" - }, - { - "k" : "Attach[1]/Note", - "v" : "Original info" - }, - { - "k" : "Attach[1]/Content", - "v" : "$2" - }, - { - "k" : "_CESNET/Impact", - "v" : "Host $1 is ORR and participated in DDoS attack" - } - ], - "title" : "Cloudflare DDoS Open DNS Resolver Report", - "class" : "Cloudflare DDoS Open DNS Resolver Report", - "analyzer" : "N6", - "alias" : "n6-007" - }, - "x2-006" : { - "_id" : "x2-006", - "label_e" : "Hlášení o strojích, které scanovaly porty počítačů v Internetu - obvykle proto, aby našly určité síťové služby a mohly je poškodit (Scanners)", - "args" : "4", - "cmd_help" : "[source IP] [protocol] [port] [original log line]", - "cmd_example" : "195.113.134.254 tcp 5900 \"195.113.134.254 | 2013-01-17_02:03:18 | scanners: 5900/tcp\"", - "id" : "x2-006", - "category" : "Recon.Scanning", - "severity" : "medium", - "enabled" : 1, - "label_s" : "Hlášení o strojích, které scanovaly porty počítačů v Internetu - obvykle proto, aby našly určité síťové služby a mohly je poškodit (Scanners)", - "ref" : "https://csirt.cesnet.cz/cs/services/x2", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "X2" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "External" - }, - { - "k" : "Node[1]/Type[2]", - "v" : "Policy" - }, - { - "k" : "Source[1]/%ipt:$1[1]", - "v" : "$1" - }, - { - "k" : "Source[1]/Proto[1]", - "v" : "$2" - }, - { - "k" : "Source[1]/Proto[2]", - "v" : "dns" - }, - { - "k" : "Source[1]/Port[1]", - "v" : "$3" - }, - { - "k" : "Category[1]", - "v" : "Recon.Scanning" - }, - { - "k" : "Description", - "v" : "Scanners" - }, - { - "k" : "Attach[1]/ContentType", - "v" : "text/plain" - }, - { - "k" : "Attach[1]/Note", - "v" : "Original info" - }, - { - "k" : "Attach[1]/Content", - "v" : "$4" - }, - { - "k" : "_CESNET/Impact", - "v" : "System $1 scanned remote port $3" - } - ], - "title" : "Scanners", - "class" : "Scanners", - "analyzer" : "X2", - "alias" : "x2-006" - }, - "n6-029" : { - "_id" : "n6-029", - "args" : "5", - "label_e" : "Hlášení o strojích infikovaných malwarem Zeus Gameover (Victim Gameover Zeus)", - "cmd_help" : "[source IP] [source port] [CaC IP] [CaC port] [original log line]", - "cmd_example" : "195.113.134.254 2973 198.51.100.68 7132 \"195.113.134.254 | 2973 <-> 198.51.100.68 | 7132 | 2014-09-04_16:42:56 | g\"", - "id" : "n6-029", - "category" : "Intrusion.Botnet", - "severity" : "medium", - "enabled" : 1, - "label_s" : "Hlášení o strojích infikovaných malwarem Zeus Gameover (Victim Gameover Zeus)", - "ref" : "https://csirt.cesnet.cz/cs/services/n6", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "N6" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "External" - }, - { - "k" : "Source[1]/%ipt:$1[1]", - "v" : "$1" - }, - { - "k" : "Source[1]/Type[1]", - "v" : "Malware" - }, - { - "k" : "Source[1]/Type[2]", - "v" : "Botnet" - }, - { - "k" : "Source[1]/Type[3]", - "v" : "CC" - }, - { - "k" : "Source[1]/Port[1]", - "v" : "$2" - }, - { - "k" : "Target[1]/%ipt:$3[1]", - "v" : "$3" - }, - { - "k" : "Target[1]/Port[1]", - "v" : "$4" - }, - { - "k" : "Target[1]/Type[1]", - "v" : "CC" - }, - { - "k" : "Target[1]/Type[2]", - "v" : "Botnet" - }, - { - "k" : "Category[1]", - "v" : "Intrusion.Botnet" - }, - { - "k" : "Description", - "v" : "Victim Gameover Zeus" - }, - { - "k" : "Attach[1]/ContentType", - "v" : "text/plain" - }, - { - "k" : "Attach[1]/Note", - "v" : "Original info" - }, - { - "k" : "Attach[1]/Content", - "v" : "$5" - }, - { - "k" : "_CESNET/Impact", - "v" : "Host $1 is infected with Zeus Gameover malware, it is communicating with C&C at $3 : $4" - } - ], - "title" : "Victim Gameover Zeus", - "class" : "Victim Gameover Zeus", - "analyzer" : "N6", - "alias" : "n6-029" - }, - "labrea-001" : { - "_id" : "labrea-001", - "args" : "7", - "label_e" : "Pokus o připojení na takové IP adresy, kde nejsou a nikdy nebyly v provozu žádné síťové servery", - "cmd_help" : "[source IP] [source port] [target IP] [target port] [event cease time] [event count] [original log line]", - "cmd_example" : "195.113.134.254 6684 78.00.00.00 1433 1356955500 50 \"1274106860 Initial Connect - tarpitting: 195.113.134.254 6684 -> 78.00.00.00 1433\"", - "id" : "labrea-001", - "category" : "Recon.Scanning", - "severity" : "medium", - "enabled" : 1, - "label_s" : "Stroje na následujících IP adresách se pokusily o připojení na takové IP adresy, kde nejsou a nikdy nebyly v provozu žádné síťové servery", - "ref" : "", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "LaBrea" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "Connection" - }, - { - "k" : "Node[1]/Type[2]", - "v" : "Tarpit" - }, - { - "k" : "Source[1]/%ipt:$1[1]", - "v" : "$1" - }, - { - "k" : "Source[1]/Port[1]", - "v" : "$2" - }, - { - "k" : "Target[1]/%ipt:$3[1]", - "v" : "$3" - }, - { - "k" : "Target[1]/Port[1]", - "v" : "$4" - }, - { - "k" : "CeaseTime", - "v" : "$5" - }, - { - "k" : "Category[1]", - "v" : "Recon.Scanning" - }, - { - "k" : "Description", - "v" : "Connection attempt" - }, - { - "k" : "ConnCount", - "v" : "$6" - }, - { - "k" : "Attach[1]/Type[1]", - "v" : "Syslog" - }, - { - "k" : "Attach[1]/ContentType", - "v" : "text/plain" - }, - { - "k" : "Attach[1]/Content", - "v" : "$7" - }, - { - "k" : "_CESNET/Impact", - "v" : "Remote host $1:$2 connected to honeypot to port $4" - } - ], - "title" : "Connection attempt", - "class" : "Connection attempt", - "analyzer" : "LaBrea", - "alias" : "labrea-001" - }, - "n6-009" : { - "_id" : "n6-009", - "label_e" : "Hlášení o strojích infikovaných malwarem Citadel (Citadel Sinkhole Report I)", - "args" : "5", - "cmd_help" : "[source IP] [source port] [target IP] [target port] [original log line]", - "cmd_example" : "195.113.134.254 60741 198.51.100.71 80 \"195.113.134.254 | 60741 -> 198.51.100.71 | 80 | 2013-08-08_21:01:05 | I\"", - "id" : "n6-009", - "category" : "Intrusion.Botnet", - "severity" : "medium", - "enabled" : 1, - "label_s" : "Hlášení o strojích infikovaných malwarem Citadel (Citadel Sinkhole Report I)", - "ref" : "https://csirt.cesnet.cz/cs/services/n6", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "N6" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "External" - }, - { - "k" : "Node[1]/Type[2]", - "v" : "Blackhole" - }, - { - "k" : "Source[1]/%ipt:$1[1]", - "v" : "$1" - }, - { - "k" : "Source[1]/Port[1]", - "v" : "$2" - }, - { - "k" : "Target[1]/%ipt:$3[1]", - "v" : "$3" - }, - { - "k" : "Target[1]/Port[1]", - "v" : "$4" - }, - { - "k" : "Category[1]", - "v" : "Intrusion.Botnet" - }, - { - "k" : "Description", - "v" : "Citadel Sinkhole Report I" - }, - { - "k" : "Attach[1]/ContentType", - "v" : "text/plain" - }, - { - "k" : "Attach[1]/Note", - "v" : "Original info" - }, - { - "k" : "Attach[1]/Content", - "v" : "$5" - }, - { - "k" : "_CESNET/Impact", - "v" : "Host $1:$2 connected to $3:$4 and is infected with Citadel malware" - } - ], - "title" : "Citadel Sinkhole Report I", - "class" : "Citadel Sinkhole Report I", - "analyzer" : "N6", - "alias" : "n6-009" - }, - "orr-001" : { - "_id" : "orr-001", - "label_e" : "Stroj funguje jako otevřený DNS resolver a může být zneužit pro masivní DDoS útoky (Open DNS Resolver)", - "args" : "2", - "cmd_help" : "[source IP] [original log line]", - "cmd_example" : "195.113.134.254 \"openresolvers|195.113.134.254|2852|2012-04-01 18:46:55||CESNET2 CESNET,z.s.p.o.\"", - "id" : "orr-001", - "category" : "Vulnerable.Config", - "severity" : "medium", - "enabled" : 1, - "label_s" : "Stroje na následujících IP adresách fungují jako otevřené DNS resolvery a mohou být zneužity pro masivní DDoS útoky (Open DNS Resolver)", - "ref" : "https://csirt.cesnet.cz/cs/services/orr", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "ORR" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "External" - }, - { - "k" : "Source[1]/%ipt:$1[1]", - "v" : "$1" - }, - { - "k" : "Source[1]/Type[1]", - "v" : "Backscatter" - }, - { - "k" : "Category[1]", - "v" : "Vulnerable.Config" - }, - { - "k" : "Description", - "v" : "Open DNS Resolver" - }, - { - "k" : "Attach[1]/ContentType", - "v" : "text/plain" - }, - { - "k" : "Attach[1]/Note", - "v" : "Original info" - }, - { - "k" : "Attach[1]/Content", - "v" : "$2" - }, - { - "k" : "_CESNET/Impact", - "v" : "Host $1 is ORR can be misused to DDoS attack" - } - ], - "title" : "Open DNS Resolver", - "class" : "Open DNS Resolver", - "analyzer" : "ORR", - "alias" : "orr-001" - }, - "x2-002" : { - "_id" : "x2-002", - "args" : "3", - "label_e" : "Hlášení o strojích, které se snažily prolomit heslo hrubou silou (Bruteforce)", - "cmd_help" : "[source IP] [service] [original log line]", - "cmd_example" : "195.113.134.254 ssh \"195.113.134.254 | 2013-06-03_12:25:35 | bruteforce: ssh\"", - "id" : "x2-002", - "category" : "Attempt.Login", - "severity" : "medium", - "enabled" : 1, - "label_s" : "Hlášení o strojích, které se snažily prolomit heslo hrubou silou (Bruteforce)", - "ref" : "https://csirt.cesnet.cz/cs/services/x2", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "X2" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "External" - }, - { - "k" : "Source[1]/%ipt:$1[1]", - "v" : "$1" - }, - { - "k" : "Source[1]/Proto[1]", - "v" : "$2" - }, - { - "k" : "Category[1]", - "v" : "Attempt.Login" - }, - { - "k" : "Description", - "v" : "Bruteforce" - }, - { - "k" : "Attach[1]/ContentType", - "v" : "text/plain" - }, - { - "k" : "Attach[1]/Note", - "v" : "Original info" - }, - { - "k" : "Attach[1]/Content", - "v" : "$3" - }, - { - "k" : "_CESNET/Impact", - "v" : "System $1 attempted to bruteforce $2" - } - ], - "title" : "Bruteforce", - "class" : "Bruteforce", - "analyzer" : "X2", - "alias" : "x2-002" - }, - "n6-001" : { - "_id" : "n6-001", - "label_e" : "Hlášení o podezřelém síťovém provozu v síti CESNET2 (Arakis Report)", - "args" : "6", - "cmd_help" : "[source IP] [source port] [target IP] [target port] [event count] [original log line]", - "cmd_example" : "195.113.134.254 7123 198.51.100.12 445 63 \"195.113.134.254 | 7123 -> 198.51.100.12 | 445 (TCP) 2013-04-04_17:26:55 | 63 | A\"", - "category" : "Intrusion.Botnet", - "id" : "n6-001", - "severity" : "low", - "enabled" : 1, - "label_s" : "Hlášení o podezřelém síťovém provozu v síti CESNET2 (Arakis Report)", - "ref" : "https://csirt.cesnet.cz/cs/services/n6", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "N6" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "External" - }, - { - "k" : "Source[1]/%ipt:$1[1]", - "v" : "$1" - }, - { - "k" : "Source[1]/Port[1]", - "v" : "$2" - }, - { - "k" : "Target[1]/%ipt:$3[1]", - "v" : "$3" - }, - { - "k" : "Target[1]/Port[1]", - "v" : "$4" - }, - { - "k" : "Category[1]", - "v" : "Intrusion.Botnet" - }, - { - "k" : "Description", - "v" : "Arakis Report" - }, - { - "k" : "ConnCount", - "v" : "$5" - }, - { - "k" : "Attach[1]/ContentType", - "v" : "text/plain" - }, - { - "k" : "Attach[1]/Note", - "v" : "Original info" - }, - { - "k" : "Attach[1]/Content", - "v" : "$6" - }, - { - "k" : "_CESNET/Impact", - "v" : "Suspicious network activity from $1:$2 to $3:$4 ($5 times)" - } - ], - "title" : "Arakis Report", - "class" : "Arakis Report", - "analyzer" : "N6", - "alias" : "n6-001" - }, - "n6-021" : { - "_id" : "n6-021", - "label_e" : "Hlášení o strojích infikovaných malwarem Virut (Virut Report)", - "args" : "5", - "cmd_help" : "[source IP] [source port] [target IP] [target port] [original log line]", - "cmd_example" : "195.113.134.254 1883 198.51.100.111 80 \"195.113.134.254 | 1883 -> 198.51.100.111 | 80 | 2013-01-21_22:40:08 | V\"", - "id" : "n6-021", - "category" : "Intrusion.Botnet", - "severity" : "medium", - "enabled" : 1, - "label_s" : "Hlášení o strojích infikovaných malwarem Virut (Virut Report)", - "ref" : "https://csirt.cesnet.cz/cs/services/n6", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "N6" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "External" - }, - { - "k" : "Source[1]/%ipt:$1[1]", - "v" : "$1" - }, - { - "k" : "Source[1]/Type[1]", - "v" : "Malware" - }, - { - "k" : "Source[1]/Type[2]", - "v" : "Botnet" - }, - { - "k" : "Source[1]/Port[1]", - "v" : "$2" - }, - { - "k" : "Target[1]/%ipt:$3[1]", - "v" : "$3" - }, - { - "k" : "Target[1]/Port[1]", - "v" : "$4" - }, - { - "k" : "Category[1]", - "v" : "Intrusion.Botnet" - }, - { - "k" : "Description", - "v" : "Virut Report" - }, - { - "k" : "Attach[1]/ContentType", - "v" : "text/plain" - }, - { - "k" : "Attach[1]/Note", - "v" : "Original info" - }, - { - "k" : "Attach[1]/Content", - "v" : "$5" - }, - { - "k" : "_CESNET/Impact", - "v" : "Host $1:$2 connected to $3:$4 and is infected with Virut malware" - } - ], - "title" : "Virut Report", - "class" : "Virut Report", - "analyzer" : "N6", - "alias" : "n6-021" - }, - "sserv-006" : { - "_id" : "sserv-006", - "label_e" : "Stroj buď přímo rozesílal spam, nebo byla jeho IP adresa obsažena v URL v těle spamu (Spam URL)", - "args" : "4", - "cmd_help" : "[source IP in URL] [source IP] [URL] [original log line]", - "cmd_example" : "195.113.134.254 192.0.2.1 hXXp://www.example.com/f.asp?the=9872 \"195.113.134.254 (192.0.2.1) -> hXXp://www.example.com/f.asp?the=9872 2010-11-19_02:13:30 U\"", - "category" : "Abusive.Spam", - "id" : "sserv-006", - "severity" : "low", - "enabled" : 1, - "label_s" : "Stroje na následujících IP adresách buď přímo rozesílaly spam, nebo byla jejich adresa obsažena v URL v těle spamu (Spam URL)", - "ref" : "https://csirt.cesnet.cz/cs/services/sserv", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "SSERV" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "External" - }, - { - "k" : "Node[1]/Type[2]", - "v" : "Data" - }, - { - "k" : "Description", - "v" : "Spam URL" - }, - { - "k" : "Category[1]", - "v" : "Abusive.Spam" - }, - { - "k" : "Source[1]/%ipt:$1[1]", - "v" : "$1" - }, - { - "k" : "Source[1]/Proto[1]", - "v" : "tcp" - }, - { - "k" : "Source[1]/Proto[2]", - "v" : "www" - }, - { - "k" : "Source[1]/URL[1]", - "v" : "$3" - }, - { - "k" : "Source[1]/Type[1]", - "v" : "Spam" - }, - { - "k" : "Source[2]/%ipt:$2[1]", - "v" : "$2" - }, - { - "k" : "Source[2]/Type[1]", - "v" : "OriginSpam" - }, - { - "k" : "Attach[1]/ContentType", - "v" : "text/plain" - }, - { - "k" : "Attach[1]/Note", - "v" : "Original info" - }, - { - "k" : "Attach[1]/Content", - "v" : "$4" - }, - { - "k" : "_CESNET/Impact", - "v" : "Host $1 was contained in spam URL $3, which was sent by $2" - } - ], - "title" : "Spam URL", - "class" : "Spam URL", - "analyzer" : "SSERV", - "alias" : "sserv-006" - }, - "warden-portscan" : { - "_id" : "warden-portscan", - "args" : "10", - "label_e" : "Skenování portů vzdáleného stroje", - "cmd_help" : "[analyzer] [analyzer_class] [ip_category] [src_ip] [proto_name] [proto_num] [tgt_port] [count] [note] [origin]", - "cmd_example" : "analyzer detector ipv4-addr 195.113.134.254 tcp 6 1234 100 \"Additional note\" warden", - "category" : "Recon.Scanning", - "id" : "warden-portscan", - "severity" : "low", - "enabled" : 1, - "label_s" : "Skenování portů vzdáleného stroje", - "ref" : "", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "$1" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "$2" - }, - { - "k" : "Source[1]/%ipt:$4[1]", - "v" : "$4" - }, - { - "k" : "Source[1]/Proto[1]", - "v" : "$5" - }, - { - "k" : "Target[1]/Port[1]", - "v" : "$7" - }, - { - "k" : "Target[1]/Proto[1]", - "v" : "$5" - }, - { - "k" : "Category[1]", - "v" : "Recon.Scanning" - }, - { - "k" : "Description", - "v" : "Portscan" - }, - { - "k" : "ConnCount", - "v" : "$8" - }, - { - "k" : "Note", - "v" : "$9" - }, - { - "k" : "_CESNET/Origin", - "v" : "$10" - }, - { - "k" : "_CESNET/Impact", - "v" : "Remote host scanned port from $4" - } - ], - "title" : "Portscan", - "class" : "Portscan", - "analyzer" : "", - "alias" : "warden-portscan" - }, - "sserv-017" : { - "_id" : "sserv-017", - "label_e" : "Hlášení o serverech, na kterých je služba Intelligent Platform Management Interface dostupná z veřejného internetu (Scan IPMI)", - "args" : "3", - "cmd_help" : "[source IP] [source port] [original log line]", - "cmd_example" : "195.113.134.254 623 \"195.113.134.254 623 2.0 N Y Y Y N default enabled enabled Y Y N 2014-06-27_17:04:59 I\"", - "id" : "sserv-017", - "category" : "Vulnerable.Config", - "severity" : "high", - "enabled" : 1, - "label_s" : "Hlášení o serverech, na kterých je služba Intelligent Platform Management Interface dostupná z veřejného internetu (Scan IPMI)", - "ref" : "https://csirt.cesnet.cz/cs/services/sserv", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "SSERV" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "External" - }, - { - "k" : "Node[1]/Type[2]", - "v" : "Recon" - }, - { - "k" : "Source[1]/%ipt:$1[1]", - "v" : "$1" - }, - { - "k" : "Source[1]/Port[1]", - "v" : "$2" - }, - { - "k" : "Category[1]", - "v" : "Vulnerable.Config" - }, - { - "k" : "Description", - "v" : "Scan IPMI" - }, - { - "k" : "Attach[1]/ContentType", - "v" : "text/plain" - }, - { - "k" : "Attach[1]/Note", - "v" : "Original info" - }, - { - "k" : "Attach[1]/Content", - "v" : "$3" - }, - { - "k" : "_CESNET/Impact", - "v" : "System provides open Intelligent Platform Management Interface service" - } - ], - "title" : "Scan IPMI", - "class" : "Scan IPMI", - "analyzer" : "SSERV", - "alias" : "sserv-017" - }, - "n6-020" : { - "_id" : "n6-020", - "label_e" : "Informace o zkompromitovaných počítačích a URL, na nichž mají externí uživatelé dostupný Shell Account (Shell Account Report)", - "args" : "3", - "cmd_help" : "[source IP] [source url] [original log line]", - "cmd_example" : "195.113.134.254 hXXp://pc.example.zz/wp-content/themes/./cache/deadbeef.php \"195.113.134.254 | hXXp://pc.example.zz/wp-content/themes/./cache/deadbeef.php | S\"", - "id" : "n6-020", - "category" : "Intrusion.AppCompromise", - "severity" : "medium", - "enabled" : 1, - "label_s" : "Informace o zkompromitovaných počítačích a URL, na nichž mají externí uživatelé dostupný Shell Account (Shell Account Report)", - "ref" : "https://csirt.cesnet.cz/cs/services/n6", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "N6" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "External" - }, - { - "k" : "Source[1]/%ipt:$1[1]", - "v" : "$1" - }, - { - "k" : "Source[1]/Proto[1]", - "v" : "tcp" - }, - { - "k" : "Source[1]/Proto[2]", - "v" : "http" - }, - { - "k" : "Source[1]/URL[1]", - "v" : "$2" - }, - { - "k" : "Category[1]", - "v" : "Intrusion.AppCompromise" - }, - { - "k" : "Description", - "v" : "Shell Account Report" - }, - { - "k" : "Attach[1]/ContentType", - "v" : "text/plain" - }, - { - "k" : "Attach[1]/Note", - "v" : "Original info" - }, - { - "k" : "Attach[1]/Content", - "v" : "$3" - }, - { - "k" : "_CESNET/Impact", - "v" : "Host $1 provides shell access on $2" - } - ], - "title" : "Shell Account Report", - "class" : "Shell Account Report", - "analyzer" : "N6", - "alias" : "n6-020" - }, - "x2-007" : { - "_id" : "x2-007", - "args" : "2", - "label_e" : "Hlášení o infikovaných strojích, které rozesílají nevyžádanou hromadnou poštu a které detekoval Composite Blocking List (Spam)", - "cmd_help" : "[source IP] [original log line]", - "cmd_example" : "195.113.134.254 \"195.113.134.254 | 2013-01-17_13:02:06 | spam: cbl\"", - "category" : "Abusive.Spam", - "id" : "x2-007", - "severity" : "low", - "enabled" : 1, - "label_s" : "Hlášení o infikovaných strojích, které rozesílají nevyžádanou hromadnou poštu a které detekoval Composite Blocking List (Spam)", - "ref" : "https://csirt.cesnet.cz/cs/services/x2", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "X2" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "External" - }, - { - "k" : "Node[1]/Type[2]", - "v" : "Data" - }, - { - "k" : "Source[1]/%ipt:$1[1]", - "v" : "$1" - }, - { - "k" : "Source[1]/Type[1]", - "v" : "OriginSpam" - }, - { - "k" : "Source[1]/Proto[1]", - "v" : "tcp" - }, - { - "k" : "Category[1]", - "v" : "Abusive.Spam" - }, - { - "k" : "Description", - "v" : "Spam" - }, - { - "k" : "Attach[1]/ContentType", - "v" : "text/plain" - }, - { - "k" : "Attach[1]/Note", - "v" : "Original info" - }, - { - "k" : "Attach[1]/Content", - "v" : "$2" - }, - { - "k" : "_CESNET/Impact", - "v" : "System $1 was sending spam" - } - ], - "title" : "Spam", - "class" : "Spam", - "analyzer" : "X2", - "alias" : "x2-007" - }, - "n6-013" : { - "_id" : "n6-013", - "label_e" : "Hlášení o otevřených NTP serverech, které lze zneužít k útokům typu DDoS (Open NTP Report)", - "args" : "2", - "cmd_help" : "[source IP] [original log line]", - "cmd_example" : "195.113.134.254 \"195.113.134.254 | N\"", - "id" : "n6-013", - "category" : "Vulnerable.Config", - "severity" : "medium", - "enabled" : 1, - "label_s" : "Hlášení o otevřených NTP serverech, které lze zneužít k útokům typu DDoS (Open NTP Report)", - "ref" : "https://csirt.cesnet.cz/cs/services/n6", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "N6" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "External" - }, - { - "k" : "Source[1]/%ipt:$1[1]", - "v" : "$1" - }, - { - "k" : "Source[1]/Type[1]", - "v" : "Open" - }, - { - "k" : "Source[1]/Type[2]", - "v" : "Backscatter" - }, - { - "k" : "Source[1]/Proto[1]", - "v" : "udp" - }, - { - "k" : "Source[1]/Proto[2]", - "v" : "ntp" - }, - { - "k" : "Category[1]", - "v" : "Vulnerable.Config" - }, - { - "k" : "Description", - "v" : "Open NTP Report" - }, - { - "k" : "Attach[1]/ContentType", - "v" : "text/plain" - }, - { - "k" : "Attach[1]/Note", - "v" : "Original info" - }, - { - "k" : "Attach[1]/Content", - "v" : "$2" - }, - { - "k" : "_CESNET/Impact", - "v" : "Host $1 can be misused to DDoS attack" - } - ], - "title" : "Open NTP Report", - "class" : "Open NTP Report", - "analyzer" : "N6", - "alias" : "n6-013" - }, - "dio-epmapper" : { - "_id" : "dio-epmapper", - "label_e" : "Pokus o zneužití EPMAPPER exploitu", - "args" : "6", - "cmd_help" : "[source IP type] [source IP] [source port] [target IP] [target port] [event count]", - "cmd_example" : "ipv4-addr 195.113.134.254 56 195.113.161.181 56 100", - "category" : "Attempt.Exploit", - "id" : "dio-epmapper", - "severity" : "low", - "enabled" : 1, - "label_s" : "Stroje na následujících IP adresách se pokusily zneužít EPMAPPER exploit", - "ref" : "", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "Dionaea" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "Honeypot" - }, - { - "k" : "Node[1]/Type[2]", - "v" : "Protocol" - }, - { - "k" : "Source[1]/%ipt:$2[1]", - "v" : "$2" - }, - { - "k" : "Source[1]/Proto[1]", - "v" : "tcp" - }, - { - "k" : "Source[1]/Proto[2]", - "v" : "epmap" - }, - { - "k" : "Source[1]/Port[1]", - "v" : "$3" - }, - { - "k" : "Target[1]/%ipt:$4[1]", - "v" : "$4" - }, - { - "k" : "Target[1]/Proto[1]", - "v" : "tcp" - }, - { - "k" : "Target[1]/Proto[2]", - "v" : "epmap" - }, - { - "k" : "Target[1]/Port[1]", - "v" : "$5" - }, - { - "k" : "Category[1]", - "v" : "Recon.Scanning" - }, - { - "k" : "Category[2]", - "v" : "Attempt.Exploit" - }, - { - "k" : "Description", - "v" : "EPMAPPER exploitation attempt" - }, - { - "k" : "ConnCount", - "v" : "$6" - }, - { - "k" : "_CESNET/Impact", - "v" : "Remote host tried to call EPMAPPER on port $5 from $2:$3" - } - ], - "title" : "EPMAPPER exploitation attempt", - "class" : "EPMAPPER exploitation attempt", - "analyzer" : "Dionaea", - "alias" : "dio-epmapper" - }, - "n6-035" : { - "_id" : "n6-035", - "args" : "2", - "label_e" : "Informace o strojich v siti CESNET2 infikovanych bankovnim malwarem Rovnix", - "cmd_help" : "[src ip] [original log line]", - "cmd_example" : "195.113.134.254 \"195.113.134.254 | 2014-12-11_19:20:21 | x\"", - "id" : "n6-035", - "category" : "Malware", - "severity" : "medium", - "enabled" : 1, - "label_s" : "Informace o strojich v siti CESNET2 infikovanych bankovnim malwarem Rovnix", - "ref" : "https://csirt.cesnet.cz/cs/services/n6", - "description" : "", - "note" : "", - "class" : "Rovnix Report", - "title" : "Rovnix Report", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "N6" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "External" - }, - { - "k" : "Source[1]/%ipt:$1[1]", - "v" : "$1" - }, - { - "k" : "Source[1]/Type[1]", - "v" : "Malware" - }, - { - "k" : "Source[1]/Type[2]", - "v" : "trojan" - }, - { - "k" : "Category[1]", - "v" : "Malware" - }, - { - "k" : "Description", - "v" : "Rovnix Report" - }, - { - "k" : "Attach[1]/ContentType", - "v" : "text/plain" - }, - { - "k" : "Attach[1]/Note", - "v" : "Original info" - }, - { - "k" : "Attach[1]/Content", - "v" : "$2" - }, - { - "k" : "_CESNET/Impact", - "v" : "Host $1 is infected with banking malware Rownix" - } - ], - "alias" : "n6-035", - "analyzer" : "N6" - }, - "warden-malware" : { - "_id" : "warden-malware", - "args" : "10", - "label_e" : "Stroj je pravděpodobně infikován malware", - "cmd_help" : "[analyzer] [analyzer_class] [ip_category] [src_ip] [proto_name] [proto_num] [tgt_port] [count] [note] [origin]", - "cmd_example" : "analyzer detector ipv4-addr 195.113.134.254 tcp 6 1234 100 \"Additional note\" warden", - "category" : "Malware", - "id" : "warden-malware", - "severity" : "low", - "enabled" : 1, - "label_s" : "Stroje na následujících IP adresách jsou pravděpodobně infikovány malware", - "ref" : "", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "$1" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "$2" - }, - { - "k" : "Source[1]/%ipt:$4[1]", - "v" : "$4" - }, - { - "k" : "Source[1]/Proto[1]", - "v" : "$5" - }, - { - "k" : "Target[1]/Port[1]", - "v" : "$7" - }, - { - "k" : "Target[1]/Proto[1]", - "v" : "$5" - }, - { - "k" : "Source/Type[1]", - "v" : "Malware" - }, - { - "k" : "Category[1]", - "v" : "Malware" - }, - { - "k" : "Description", - "v" : "Malware" - }, - { - "k" : "ConnCount", - "v" : "$8" - }, - { - "k" : "Note", - "v" : "$9" - }, - { - "k" : "_CESNET/Origin", - "v" : "$10" - }, - { - "k" : "_CESNET/Impact", - "v" : "Remote host $4 tried to upload malware" - } - ], - "title" : "Malware", - "class" : "Malware", - "analyzer" : "", - "alias" : "warden-malware" - }, - "uceprot-002" : { - "_id" : "uceprot-002", - "label_e" : "Stroj rozesila spam (Spam Report)", - "args" : "3", - "cmd_help" : "[source IP] [remove time] [original log line]", - "cmd_example" : "195.113.134.254 2012-05-03_15:00 \"195.113.134.254 | 2012-04-26_12:11:09 | 2012-05-03_15:00 | S\"", - "category" : "Abusive.Spam", - "id" : "uceprot-002", - "severity" : "low", - "enabled" : 1, - "label_s" : "Stroje na nasledujicich IP adresach rozesilaly spam (Spam Report)", - "ref" : "https://csirt.cesnet.cz/cs/services/uceprot", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "UCEPROT" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "External" - }, - { - "k" : "Node[1]/Type[2]", - "v" : "Data" - }, - { - "k" : "Source[1]/%ipt:$1[1]", - "v" : "$1" - }, - { - "k" : "Source[1]/Proto[1]", - "v" : "tcp" - }, - { - "k" : "Category[1]", - "v" : "Abusive.Spam" - }, - { - "k" : "Description", - "v" : "Spam Report" - }, - { - "k" : "Attach[1]/ContentType", - "v" : "text/plain" - }, - { - "k" : "Attach[1]/Note", - "v" : "Original info" - }, - { - "k" : "Attach[1]/Content", - "v" : "$3" - }, - { - "k" : "Attach[2]/ContentType", - "v" : "text/plain" - }, - { - "k" : "Attach[2]/Note", - "v" : "Remove time" - }, - { - "k" : "Attach[2]/Content", - "v" : "$2" - }, - { - "k" : "_CESNET/Impact", - "v" : "System $1 was sending spam" - } - ], - "title" : "Spam Report", - "class" : "Spam Report", - "analyzer" : "UCEPROT", - "alias" : "uceprot-002" - }, - "kippo-001" : { - "_id" : "kippo-001", - "label_e" : "Pokus o neoprávněné připojeni k SSH serveru", - "args" : "6", - "cmd_help" : "[source IP] [target IP] [target user] [completion] [impact] [event count]", - "cmd_example" : "195.113.134.254 192.168.0.2 root failed \"Someone tried to login as root from 195.113.134.254\" 5", - "id" : "kippo-001", - "category" : "Attempt.Login", - "severity" : "medium", - "enabled" : 1, - "label_s" : "Stroje na následujících IP adresách se pokusily o neoprávněné připojení k SSH serveru", - "ref" : "", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "Kippo" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "Honeypot" - }, - { - "k" : "Source[1]/%ipt:$1[1]", - "v" : "$1" - }, - { - "k" : "Target[1]/%ipt:$2[1]", - "v" : "$2" - }, - { - "k" : "Category[1]", - "v" : "Attempt.Login" - }, - { - "k" : "Description", - "v" : "Remote login" - }, - { - "k" : "Note", - "v" : "Completion: $4. $5" - }, - { - "k" : "ConnCount", - "v" : "$6" - }, - { - "k" : "_CESNET/Impact", - "v" : "$5" - } - ], - "title" : "Remote login", - "class" : "Remote login", - "analyzer" : "Kippo", - "alias" : "kippo-login" - }, - "sserv-007" : { - "_id" : "sserv-007", - "args" : "3", - "label_e" : "Na tento stroj se pokoušel připojit malware analyzovaný v laboratorních podmínkách (Sandbox URL)", - "cmd_help" : "[source IP] [url] [original log line]", - "cmd_example" : "195.113.134.254 hXXp://195.113.134.254/~skots0am/grabber/index.php \"195.113.134.254 hXXp://195.113.134.254/~skots0am/grabber/index.php GET X\"", - "category" : "Anomaly.Traffic", - "id" : "sserv-007", - "severity" : "low", - "enabled" : 1, - "label_s" : "Na stroje na následujících IP adresách se pokoušel připojit malware analyzovaný v laboratorních podmínkách (Sandbox URL)", - "ref" : "https://csirt.cesnet.cz/cs/services/sserv", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "SSERV" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "External" - }, - { - "k" : "Description", - "v" : "Sandbox URL" - }, - { - "k" : "Category[1]", - "v" : "Anomaly.Traffic" - }, - { - "k" : "Source[1]/%ipt:$1[1]", - "v" : "$1" - }, - { - "k" : "Source[1]/URL[1]", - "v" : "$2" - }, - { - "k" : "Source[1]/Type[1]", - "v" : "OriginSandbox" - }, - { - "k" : "Source[1]/Proto[1]", - "v" : "tcp" - }, - { - "k" : "Source[1]/Proto[2]", - "v" : "www" - }, - { - "k" : "Attach[1]/ContentType", - "v" : "text/plain" - }, - { - "k" : "Attach[1]/Note", - "v" : "Original info" - }, - { - "k" : "Attach[1]/Content", - "v" : "$3" - }, - { - "k" : "_CESNET/Impact", - "v" : "Malware in sandbox attemted to connect to host $1 to URL $2" - } - ], - "title" : "Sandbox URL", - "class" : "Sandbox URL", - "analyzer" : "SSERV", - "alias" : "sserv-007" - }, - "n6-032" : { - "_id" : "n6-032", - "args" : "2", - "label_e" : "Hlášení o strojích infikovaných malwarem Darkhotel (Darkhotel Report)", - "cmd_help" : "[source IP] [original log line]", - "cmd_example" : "195.113.134.254 \"195.113.134.254 | 2014-11-19_10:31:23 | d\"", - "id" : "n6-032", - "category" : "Intrusion.Botnet", - "severity" : "high", - "enabled" : 1, - "label_s" : "Hlášení o strojích infikovaných malwarem Darkhotel (Darkhotel Report)", - "ref" : "https://csirt.cesnet.cz/cs/services/n6", - "description" : "", - "note" : "", - "class" : "Darkhotel Report", - "title" : "Darkhotel Report", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "N6" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "External" - }, - { - "k" : "Source[1]/%ipt:$1[1]", - "v" : "$1" - }, - { - "k" : "Source[1]/Type[1]", - "v" : "Malware" - }, - { - "k" : "Source[1]/Type[2]", - "v" : "Botnet" - }, - { - "k" : "Category[1]", - "v" : "Intrusion.Botnet" - }, - { - "k" : "Description", - "v" : "Darkhotel Report" - }, - { - "k" : "Attach[1]/ContentType", - "v" : "text/plain" - }, - { - "k" : "Attach[1]/Note", - "v" : "Original info" - }, - { - "k" : "Attach[1]/Content", - "v" : "$2" - }, - { - "k" : "_CESNET/Impact", - "v" : "Host $1 is infected with Darkhotel malware" - } - ], - "analyzer" : "N6", - "alias" : "n6-032" - }, - "n6-012" : { - "_id" : "n6-012", - "label_e" : "Hlášení o strojích poskytujících malware přes URL (Malurl Report)", - "args" : "3", - "cmd_help" : "[source IP] [source url] [original log line]", - "cmd_example" : "195.113.134.254 hXXp://www.example.net/index.php?text=1234 \"195.113.134.254 | hXXp://www.example.net/index.php?text=1234 | M\"", - "id" : "n6-012", - "category" : "Malware", - "severity" : "medium", - "enabled" : 1, - "label_s" : "Hlášení o strojích poskytujících malware přes URL (Malurl Report)", - "ref" : "https://csirt.cesnet.cz/cs/services/n6", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "N6" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "External" - }, - { - "k" : "Source[1]/%ipt:$1[1]", - "v" : "$1" - }, - { - "k" : "Source[1]/Type[1]", - "v" : "Malware" - }, - { - "k" : "Source[1]/Proto[1]", - "v" : "tcp" - }, - { - "k" : "Source[1]/Proto[2]", - "v" : "http" - }, - { - "k" : "Source[1]/URL[1]", - "v" : "$2" - }, - { - "k" : "Category[1]", - "v" : "Malware" - }, - { - "k" : "Description", - "v" : "Malurl Report" - }, - { - "k" : "Attach[1]/ContentType", - "v" : "text/plain" - }, - { - "k" : "Attach[1]/Note", - "v" : "Original info" - }, - { - "k" : "Attach[1]/Content", - "v" : "$3" - }, - { - "k" : "_CESNET/Impact", - "v" : "Host $1 contains malware at $2" - } - ], - "title" : "Malurl Report", - "class" : "Malurl Report", - "analyzer" : "N6", - "alias" : "n6-012" - }, - "n6-028" : { - "_id" : "n6-028", - "args" : "4", - "label_e" : "Hlášení o strojích infikovaných malwarem Zeus (Victim Zeus Report)", - "cmd_help" : "[source IP] [source url] [method] [original log line]", - "cmd_example" : "195.113.134.254 /wp-admin/gate.php POST \"195.113.134.254 | /wp-admin/gate.php (HTTP/1.1 POST) 2014-07-24_12:30:21 | v\"", - "id" : "n6-028", - "category" : "Intrusion.Botnet", - "severity" : "medium", - "enabled" : 1, - "label_s" : "Hlášení o strojích infikovaných malwarem Zeus (Victim Zeus Report)", - "ref" : "https://csirt.cesnet.cz/cs/services/n6", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "N6" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "External" - }, - { - "k" : "Source[1]/%ipt:$1[1]", - "v" : "$1" - }, - { - "k" : "Source[1]/Type[1]", - "v" : "Malware" - }, - { - "k" : "Source[1]/Proto[1]", - "v" : "tcp" - }, - { - "k" : "Source[1]/Proto[2]", - "v" : "http" - }, - { - "k" : "Source[1]/URL[1]", - "v" : "$2" - }, - { - "k" : "Source[1]/Note", - "v" : "HTTP method: $3" - }, - { - "k" : "Category[1]", - "v" : "Intrusion.Botnet" - }, - { - "k" : "Description", - "v" : "Victim Zeus Report" - }, - { - "k" : "Attach[1]/ContentType", - "v" : "text/plain" - }, - { - "k" : "Attach[1]/Note", - "v" : "Original info" - }, - { - "k" : "Attach[1]/Content", - "v" : "$4" - }, - { - "k" : "_CESNET/Impact", - "v" : "Host $1 provides malicious URL $2 and is infected with Zeus malware" - } - ], - "title" : "Victim Zeus Report", - "class" : "Victim Zeus Report", - "analyzer" : "N6", - "alias" : "n6-028" - }, - "warden-dos" : { - "_id" : "warden-dos", - "args" : "10", - "label_e" : "Stroj se pokusil o utok typu (D)DoS", - "cmd_help" : "[analyzer] [analyzer_class] [ip_category] [src_ip] [proto_name] [proto_num] [tgt_port] [count] [note] [origin]", - "cmd_example" : "analyzer detector ipv4-addr 195.113.134.254 tcp 6 1234 100 \"Additional note\" warden", - "category" : "Availability.DDoS", - "id" : "warden-dos", - "severity" : "low", - "enabled" : 1, - "label_s" : "Stroje na nasledujicich IP adresach se pokusily o utoky typu (D)DoS", - "ref" : "", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "$1" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "$2" - }, - { - "k" : "Source[1]/%ipt:$4[1]", - "v" : "$4" - }, - { - "k" : "Source[1]/Proto[1]", - "v" : "$5" - }, - { - "k" : "Target[1]/Port[1]", - "v" : "$7" - }, - { - "k" : "Target[1]/Proto[1]", - "v" : "$5" - }, - { - "k" : "Category[1]", - "v" : "Availability.DDoS" - }, - { - "k" : "Description", - "v" : "(D)DoS" - }, - { - "k" : "ConnCount", - "v" : "$8" - }, - { - "k" : "Note", - "v" : "$9" - }, - { - "k" : "_CESNET/Origin", - "v" : "$10" - }, - { - "k" : "_CESNET/Impact", - "v" : "Remote host $4 tried (D)DoS attack" - } - ], - "title" : "(D)DoS", - "class" : "(D)DoS", - "analyzer" : "", - "alias" : "warden-dos" - }, - "sserv-009" : { - "_id" : "sserv-009", - "label_e" : "Hlášení o strojích poskytujících službu UDP Character Generator, které lze zneužít k útokům typu DDoS (Scan CHARGEN)", - "args" : "3", - "cmd_help" : "[source IP] [source port] [original log line]", - "cmd_example" : "195.113.134.254 19 \"195.113.134.254 (19) 2014-03-27_13:58:51 G\"", - "id" : "sserv-009", - "category" : "Vulnerable.Config", - "severity" : "medium", - "enabled" : 1, - "label_s" : "Hlášení o strojích poskytujících službu UDP Character Generator, které lze zneužít k útokům typu DDoS (Scan CHARGEN)", - "ref" : "https://csirt.cesnet.cz/cs/services/sserv", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "SSERV" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "External" - }, - { - "k" : "Node[1]/Type[2]", - "v" : "Recon" - }, - { - "k" : "Source[1]/%ipt:$1[1]", - "v" : "$1" - }, - { - "k" : "Source[1]/Port[1]", - "v" : "$2" - }, - { - "k" : "Source[1]/Type[1]", - "v" : "Backscatter" - }, - { - "k" : "Source[1]/Proto[1]", - "v" : "udp" - }, - { - "k" : "Source[1]/Proto[2]", - "v" : "chargen" - }, - { - "k" : "Category[1]", - "v" : "Vulnerable.Config" - }, - { - "k" : "Description", - "v" : "Scan CHARGEN" - }, - { - "k" : "Attach[1]/ContentType", - "v" : "text/plain" - }, - { - "k" : "Attach[1]/Note", - "v" : "Original info" - }, - { - "k" : "Attach[1]/Content", - "v" : "$3" - }, - { - "k" : "_CESNET/Impact", - "v" : "System provides CHARGEN service and can be misused for massive DDoS attack" - } - ], - "title" : "Scan CHARGEN", - "class" : "Scan CHARGEN", - "analyzer" : "SSERV", - "alias" : "sserv-009" - }, - "n6-023" : { - "_id" : "n6-023", - "label_e" : "Hlášení o strojích infikovaných trojským koněm Zeus (Zeus Report)", - "args" : "3", - "cmd_help" : "[source IP] [source port] [original log line]", - "cmd_example" : "195.113.134.254 26147 \"195.113.134.254 | 26147 (UDP) 2012-07-16_07:09:37 | z\"", - "id" : "n6-023", - "category" : "Intrusion.Botnet", - "severity" : "medium", - "enabled" : 1, - "label_s" : "Hlášení o strojích infikovaných trojským koněm Zeus (Zeus Report)", - "ref" : "https://csirt.cesnet.cz/cs/services/n6", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "N6" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "External" - }, - { - "k" : "Source[1]/%ipt:$1[1]", - "v" : "$1" - }, - { - "k" : "Source[1]/Type[1]", - "v" : "Malware" - }, - { - "k" : "Source[1]/Type[2]", - "v" : "Botnet" - }, - { - "k" : "Source[1]/Port[1]", - "v" : "$2" - }, - { - "k" : "Category[1]", - "v" : "Intrusion.Botnet" - }, - { - "k" : "Description", - "v" : "Zeus Report" - }, - { - "k" : "Attach[1]/ContentType", - "v" : "text/plain" - }, - { - "k" : "Attach[1]/Note", - "v" : "Original info" - }, - { - "k" : "Attach[1]/Content", - "v" : "$3" - }, - { - "k" : "_CESNET/Impact", - "v" : "Host $1 contains Zeus trojan" - } - ], - "title" : "Zeus Report", - "class" : "Zeus Report", - "analyzer" : "N6", - "alias" : "n6-023" - }, - "sserv-008" : { - "_id" : "sserv-008", - "args" : "3", - "label_e" : "Hlášení o strojích, které se připojily k HTTP serverům projektu Shadowserver zřízeným na adresách, jichž měly používat zločinné domény; tyto stroje uvedly v poli Referer URL, které odkazuje na Váš stroj (Sinkhole HTTP Referer Report)", - "cmd_help" : "[source IP] [infection] [original log line]", - "cmd_example" : "195.113.134.254 downadup \"195.113.134.254 (downadup) 2014-03-12_19:52:34 F\"", - "category" : "Intrusion.Botnet", - "id" : "sserv-008", - "severity" : "low", - "enabled" : 1, - "label_s" : "Hlášení o strojích, které se připojily k HTTP serverům projektu Shadowserver zřízeným na adresách, jichž měly používat zločinné domény; tyto stroje uvedly v poli Referer URL, které odkazuje na Váš stroj (Sinkhole HTTP Referer Report)", - "ref" : "https://csirt.cesnet.cz/cs/services/sserv", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "SSERV" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "External" - }, - { - "k" : "Node[1]/Type[2]", - "v" : "Blackhole" - }, - { - "k" : "Source[1]/%ipt:$1[1]", - "v" : "$1" - }, - { - "k" : "Source[1]/Type[1]", - "v" : "OriginReferer" - }, - { - "k" : "Source[1]/Note", - "v" : "Malware: $2" - }, - { - "k" : "Category[1]", - "v" : "Intrusion.Botnet" - }, - { - "k" : "Description", - "v" : "Sinkhole HTTP Referer Report" - }, - { - "k" : "Attach[1]/ContentType", - "v" : "text/plain" - }, - { - "k" : "Attach[1]/Note", - "v" : "Original info" - }, - { - "k" : "Attach[1]/Content", - "v" : "$3" - }, - { - "k" : "_CESNET/Impact", - "v" : "System $1 was found in referer when honeypot was accessed, possibly infected with $2" - } - ], - "title" : "Sinkhole HTTP Referer Report", - "class" : "Sinkhole HTTP Referer Report", - "analyzer" : "SSERV", - "alias" : "sserv-008" - }, - "dio-smbd" : { - "_id" : "dio-smbd", - "args" : "6", - "label_e" : "Pokus o zneužití SMB exploitu", - "cmd_help" : "[source IP type] [source IP] [source port] [target IP] [target port] [event count]", - "cmd_example" : "ipv4-addr 195.113.134.254 56 195.113.161.181 56 100", - "category" : "Attempt.Exploit", - "id" : "dio-smbd", - "severity" : "low", - "enabled" : 1, - "label_s" : "Stroje na následujících IP adresách se pokusily zneužít SMB exploit", - "ref" : "", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "Dionaea" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "Honeypot" - }, - { - "k" : "Node[1]/Type[2]", - "v" : "Protocol" - }, - { - "k" : "Source[1]/%ipt:$2[1]", - "v" : "$2" - }, - { - "k" : "Source[1]/Proto[1]", - "v" : "tcp" - }, - { - "k" : "Source[1]/Proto[2]", - "v" : "smb" - }, - { - "k" : "Source[1]/Port[1]", - "v" : "$3" - }, - { - "k" : "Target[1]/%ipt:$4[1]", - "v" : "$4" - }, - { - "k" : "Target[1]/Proto[1]", - "v" : "tcp" - }, - { - "k" : "Target[1]/Proto[2]", - "v" : "smb" - }, - { - "k" : "Target[1]/Port[1]", - "v" : "$5" - }, - { - "k" : "Category[1]", - "v" : "Recon.Scanning" - }, - { - "k" : "Category[2]", - "v" : "Attempt.Exploit" - }, - { - "k" : "Description", - "v" : "SMB exploitation attempt" - }, - { - "k" : "ConnCount", - "v" : "$6" - }, - { - "k" : "_CESNET/Impact", - "v" : "Remote host tried to call SMB on port $5 from $2:$3" - } - ], - "title" : "SMB exploitation attempt", - "class" : "SMB exploitation attempt", - "analyzer" : "Dionaea", - "alias" : "dio-smbd" - }, - "warden-phishing" : { - "_id" : "warden-phishing", - "label_e" : "Stroj je zapojen do phishingoveho utoku", - "args" : "10", - "cmd_help" : "[analyzer] [analyzer_class] [ip_category] [src_ip] [proto_name] [proto_num] [tgt_port] [count] [note] [origin]", - "cmd_example" : "analyzer detector ipv4-addr 195.113.134.254 tcp 6 1234 100 \"Additional note\" warden", - "category" : "Fraud.Phishing", - "id" : "warden-phishing", - "severity" : "low", - "enabled" : 1, - "label_s" : "Stroje na nasledujicich IP adresach jsou zapojeny do phishingoveho utoku", - "ref" : "", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "$1" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "$2" - }, - { - "k" : "Source[1]/%ipt:$4[1]", - "v" : "$4" - }, - { - "k" : "Source[1]/Proto[1]", - "v" : "$5" - }, - { - "k" : "Target[1]/Port[1]", - "v" : "$7" - }, - { - "k" : "Target[1]/Proto[1]", - "v" : "$5" - }, - { - "k" : "Category[1]", - "v" : "Fraud.Phishing" - }, - { - "k" : "Description", - "v" : "Phishing" - }, - { - "k" : "ConnCount", - "v" : "$8" - }, - { - "k" : "Note", - "v" : "$9" - }, - { - "k" : "_CESNET/Origin", - "v" : "$10" - }, - { - "k" : "_CESNET/Impact", - "v" : "Remote host $4 tried to scan user to revealing personal information" - } - ], - "title" : "Phishing", - "class" : "Phishing", - "analyzer" : "", - "alias" : "warden-phishing" - }, - "n6-014" : { - "_id" : "n6-014", - "label_e" : "Hlášení o strojích komunikujících v rámci botnetu Zeroaccess (Zeroaccess Report)", - "args" : "2", - "cmd_help" : "[source IP] [original log line]", - "cmd_example" : "195.113.134.254 \"195.113.134.254 (2013-08-18_12:51:31) 2013-11-14_17:59:42 | o\"", - "id" : "n6-014", - "category" : "Intrusion.Botnet", - "severity" : "medium", - "enabled" : 1, - "label_s" : "Hlášení o strojích komunikujících v rámci botnetu Zeroaccess (Zeroaccess Report)", - "ref" : "https://csirt.cesnet.cz/cs/services/n6", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "N6" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "External" - }, - { - "k" : "Source[1]/%ipt:$1[1]", - "v" : "$1" - }, - { - "k" : "Category[1]", - "v" : "Intrusion.Botnet" - }, - { - "k" : "Description", - "v" : "Zeroaccess Report" - }, - { - "k" : "Attach[1]/ContentType", - "v" : "text/plain" - }, - { - "k" : "Attach[1]/Note", - "v" : "Original info" - }, - { - "k" : "Attach[1]/Content", - "v" : "$2" - }, - { - "k" : "_CESNET/Impact", - "v" : "Host $1 is part of the Zeroaccess botnet" - } - ], - "title" : "Zeroaccess Report", - "class" : "Zeroaccess Report", - "analyzer" : "N6", - "alias" : "n6-014" - }, - "sserv-016" : { - "_id" : "sserv-016", - "label_e" : "Hlášení o otevřených NTP serverech, které lze zneužít k ještě masivnějším útokům typu DDoS prostřednictvím dotazů typu Mode 7 (Scan NTPMONITOR)", - "args" : "3", - "cmd_help" : "[source IP] [source port] [original log line]", - "cmd_example" : "195.113.134.254 123 \"195.113.134.254 | 123 (100,44000) 2014-03-27_14:03:16 | t\"", - "id" : "sserv-016", - "category" : "Vulnerable.Config", - "severity" : "high", - "enabled" : 1, - "label_s" : "Hlášení o otevřených NTP serverech, které lze zneužít k ještě masivnějším útokům typu DDoS prostřednictvím dotazů typu Mode 7 (Scan NTPMONITOR)", - "ref" : "https://csirt.cesnet.cz/cs/services/sserv", - "description" : "", - "note" : "", - "rules_idea" : [ - { - "k" : "Node[1]/SW[1]", - "v" : "SSERV" - }, - { - "k" : "Node[1]/Type[1]", - "v" : "External" - }, - { - "k" : "Node[1]/Type[2]", - "v" : "Recon" - }, - { - "k" : "Source[1]/%ipt:$1[1]", - "v" : "$1" - }, - { - "k" : "Source[1]/Port[1]", - "v" : "$2" - }, - { - "k" : "Source[1]/Proto[1]", - "v" : "udp" - }, - { - "k" : "Category[1]", - "v" : "Vulnerable.Config" - }, - { - "k" : "Description", - "v" : "Scan NTPMONITOR" - }, - { - "k" : "Attach[1]/ContentType", - "v" : "text/plain" - }, - { - "k" : "Attach[1]/Note", - "v" : "Original info" - }, - { - "k" : "Attach[1]/Content", - "v" : "$3" - }, - { - "k" : "_CESNET/Impact", - "v" : "System provides open NTP service and can be misused for massive DDoS attack" - } - ], - "title" : "Scan NTPMONITOR", - "class" : "Scan NTPMONITOR", - "analyzer" : "SSERV", - "alias" : "sserv-016" - } - } -} diff --git a/lib_perl/tests/unit/spool/schema-msgtmplts.json b/lib_perl/tests/unit/spool/schema-msgtmplts.json deleted file mode 100644 index 93af36ca75351d80a1db769f0d3ed619db8d53fa..0000000000000000000000000000000000000000 --- a/lib_perl/tests/unit/spool/schema-msgtmplts.json +++ /dev/null @@ -1,118 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-04/schema#", - "description": "Message templates schema", - "type": "object", - "properties": { - "version": { - "description": "Template file version", - "type": "number" - }, - "timestamp": { - "description": "Export timestamp", - "type": "number" - }, - "description": { - "description": "Template file version", - "type": "string" - }, - "templates": { - "description": "Template list", - "type": "object", - "additionalProperties": { - "description": "Template definition", - "type": "object", - "properties": { - "_id": { - "description": "Template unique identifier", - "type": "string" - }, - "id": { - "description": "Template unique identifier", - "type": "string" - }, - "title": { - "description": "Template title", - "type": "string" - }, - "alias": { - "description": "Template alias", - "type": "string" - }, - "label_e": { - "description": "Event label for extra reports", - "type": "string" - }, - "label_s": { - "description": "Event label for summary reports", - "type": "string" - }, - "analyzer": { - "description": "Name of the event analyzer", - "type": "string" - }, - "category": { - "description": "Event categorization", - "type": "string" - }, - "class": { - "description": "Event classification", - "type": "string" - }, - "severity": { - "description": "Event severity", - "enum": [ "low", "medium", "high", "critical" ] - }, - "description": { - "description": "Event description", - "type": "string" - }, - "note": { - "description": "Additional event notes", - "type": "string" - }, - "ref": { - "description": "Event references and more information", - "type": "string" - }, - "args": { - "description": "Number of template arguments", - "type": "number" - }, - "rules_idea": { - "description": "Event schema rules", - "type": "array", - "items": { - "type": "object", - "properties": { - "k": { - "type": "string" - }, - "v": { - "type": "string" - } - }, - "additionalProperties": false - } - }, - "cmd_help": { - "description": "Command help", - "type": "string" - }, - "cmd_example": { - "description": "Example command", - "type": "string" - }, - "enabled": { - "description": "Enable/disable event", - "type": "integer" - }, - "additionalProperties": false - }, - "required": ["title","alias"], - "additionalProperties": false - } - } - }, - "required": ["version","templates"], - "additionalProperties": false -} diff --git a/lib_perl/tests/unit/t/Mentat.Handyman.t b/lib_perl/tests/unit/t/Mentat.Handyman.t deleted file mode 100644 index 83deb8ac0f547e0985fc0d6527bb3d985eeabc1b..0000000000000000000000000000000000000000 --- a/lib_perl/tests/unit/t/Mentat.Handyman.t +++ /dev/null @@ -1,83 +0,0 @@ -#!/usr/bin/perl -T - -use strict; -use warnings; - -#******************************************************************************* -# Mentat::Handyman module/class tests -# -# Author: Jan Mach, jan.mach@cesnet.cz -# Version: 0.1 -# Purpose: -# -#******************************************************************************* - -use Data::Dumper; -#use Smart::Comments; - -use Test::More tests => 10; - -# First test if the module correctly compiles -BEGIN { - use vars qw($TESTED_CLASS); - $TESTED_CLASS = 'Mentat::Handyman'; - - use_ok('Tester'); - use_ok('Config::JSON'); - use_ok('Mentat::Message::Builder::IDEA'); - use_ok('Mentat::Message::Validator::IDEA'); - use_ok($TESTED_CLASS); - } - -# Debug output explicit ON switch -#Tester::DEBUG_ON(); -#Tester::DEBUG_ON(10); - -# Debug output explicit OFF switch -#Tester::DEBUG_OFF(); - -# User should know, which version is beeing tested (just for sure) -diag("$TESTED_CLASS version: " . $Mentat::Handyman::VERSION) if Tester::D(); - -# Prepare builder configurations -my $BUILDER_CONFIG = { - 'name' => 'somehost.domain', - 'type' => 'Honeypot', - 'sw' => 'DetectionSW', - 'note' => 'Note for this detection node', - }; - -# Now attempt to create a class instance and check it -my $instance = $TESTED_CLASS->new(template_file => './spool/msgtmplts.json', - temp_folder => './spool', - pickup_folder => './spool', - cache_folder => './spool', - #schema_file => '../../../schema/idea.schema', - template_schema_file => './spool/schema-msgtmplts.json', - user => 'mentat', - builder_config => $BUILDER_CONFIG, - strict => 1, - test_mode => 1); -isa_ok($instance, $TESTED_CLASS); - -# View the created instance -diag("Instance dump 01: " . Dumper($instance)) if Tester::D(); - -# Attempt to generate the IDEA message according to the template -my $mentat_messageA = $instance->generate('kippo-001', {'detect_time' => 1356955200}, '12.34.56.78', "192.168.0.2", "root", "failed", "Someone tried to login as root from 12.34.56.78", 5); -isa_ok($mentat_messageA, 'Mentat::Message::IDEA'); -diag("Instance dump 02: " . $mentat_messageA->to_string(1)) if Tester::D(); - -my $mentat_messageB = $instance->generate('warden-phishing', {'detect_time' => 1356955200}, 'analyzer', 'detector', 'ipv4-addr', '192.168.0.1', 'tcp', '6', '1234', '100', "Additional note", "warden"); -isa_ok($mentat_messageB, 'Mentat::Message::IDEA'); -diag("Instance dump 02: " . $mentat_messageB->to_string(1)) if Tester::D(); - -# Attempt to store the IDEA message to the file -my ($rvB, $filenameB) = $instance->store_to_file($mentat_messageB); -is($rvB, 1, "Generate to file '$filenameB'"); -unlink($filenameB) if -f $filenameB; - -# Attempt to generate the IDEA message according to the template and store it to the file -my ($rvC, $filenameC) = $instance->generate_to_file('kippo-001', {'detect_time' => 1356955200}, '12.34.56.78', "192.168.0.2", "root", "failed", "Someone tried to login as root from 12.34.56.78", 5); -is($rvC, 1, "Generate to file '$filenameC'"); -unlink($filenameC) if -f $filenameC; diff --git a/lib_perl/tests/unit/t/Mentat.MPath.Parser.t b/lib_perl/tests/unit/t/Mentat.MPath.Parser.t deleted file mode 100644 index 460712c7c413d7b86e4c750b1d5e80968107e1cb..0000000000000000000000000000000000000000 --- a/lib_perl/tests/unit/t/Mentat.MPath.Parser.t +++ /dev/null @@ -1,142 +0,0 @@ -#!/usr/bin/perl -T - -use strict; -use warnings; - -#******************************************************************************* -# Mentat::MPath::Parser class tests -# -# Author: Jan Mach, jan.mach@cesnet.cz -# Version: 0.1 -# Purpose: -# Comments: -#******************************************************************************* - -use Data::Dumper; -#use Smart::Comments; - -use Test::More tests => 21; - -# First test if the module correctly compiles -BEGIN { - use vars qw($TESTED_CLASS); - $TESTED_CLASS = 'Mentat::MPath::Parser'; - - use_ok('Tester'); - use_ok($TESTED_CLASS); - } - -# Debug output explicit ON switch -#Tester::DEBUG_ON(); - -# Debug output explicit OFF switch -#Tester::DEBUG_OFF(); - -# User should know, which version is beeing tested (just for sure) -diag("$TESTED_CLASS version: " . $Template::Module::VERSION) if Tester::D(); - -# Now attempt to create a class instance and check it -my $instance = $TESTED_CLASS->new(); -isa_ok($instance, $TESTED_CLASS); - -# View the created instance -diag("Instance dump 01: " . Dumper($instance)) if Tester::D(); - -# Verify the instance is empty -is(Dumper($instance), -'$VAR1 = bless( {}, \'Mentat::MPath::Parser\' ); -', -"Instance print test 01"); - -# Test Mentat message path -my $message_path = 'Alert/Target[1]/Node/Address/@category'; - -# Expected result -my $expected_result = [ - [ - 'Alert', - 'elem', - undef, - 'Target[1]/Node/Address/@category', - ], - [ - 'Target', - 'elem', - 1, - 'Node/Address/@category', - ], - [ - 'Node', - 'elem', - undef, - 'Address/@category', - ], - [ - 'Address', - 'elem', - undef, - '@category', - ], - [ - 'category', - 'attr', - undef, - undef, - ] - ]; - - -# Result storage variables -my ( $name, $type, $index, $rest, $xpath); - -# Check the error handling -eval { - ($name, $type, $index, $rest) = Data::Path::Parser->parse_next_chunk(''); -}; -if($@) { like($@, qr/Data::Path::Parser::parse_next_chunk: undefined next data path node/, "Error test 02"); } else { fail("Error test 02"); } -eval { - ($name, $type, $index, $rest) = Data::Path::Parser->parse_next_chunk('Alert9]/Target/Node/Address/@category'); -}; -if($@) { like($@, qr/Data::Path::Parser::parse_next_chunk: invalid Mentat message node: 'Alert9]'/, "Error test 03"); } else { fail("Error test 03"); } -eval { - ($name, $type, $index, $rest) = Data::Path::Parser->parse_next_chunk('Target[0]/Node/Address/@category'); -}; -if($@) { like($@, qr/Data::Path::Parser::parse_next_chunk: invalid index value '0', index starts at '1'/, "Error test 03"); } else { fail("Error test 04"); } -eval { - ($name, $type, $index, $rest) = Data::Path::Parser->parse_next_chunk('@category[2]'); -}; -if($@) { like($@, qr/Data::Path::Parser::parse_next_chunk: atribute node '\@category\[2\]' must have only one instance/, "Error test 04"); } else { fail("Error test 05"); } -eval { - ($name, $type, $index, $rest) = Data::Path::Parser->parse_next_chunk('@category/test'); -}; -if($@) { like($@, qr/Data::Path::Parser::parse_next_chunk: atribute node '\@category' may not contain any child nodes/, "Error test 05"); } else { fail("Error test 06"); } - -# Parse the data path chunk by chunk -my @result; -$rest = $message_path; -do { - ($name, $type, $index, $rest) = Data::Path::Parser->parse_next_chunk($rest); - push(@result, [$name, $type, $index, $rest]); -} while ($rest); -is_deeply(\@result, $expected_result, 'Parse test 01'); - -# Parse the whole Mentat message path in one step -my @chunks = Data::Path::Parser->parse($message_path); -is_deeply(\@chunks, $expected_result, 'Parse test 02'); - -# Check the catching variant of parse method -my @chunks2 = Data::Path::Parser->parse_quiet($message_path); -is_deeply(\@chunks2, $expected_result, 'Parse test 03'); -is(Data::Path::Parser->parse_quiet('Alert9]/Target/Node/Address/@category'), undef, 'Parse test 04'); - -# Check the join -is(Data::Path::Parser->join('Alert/Target/Node/Address', '@category'), 'Alert/Target/Node/Address/@category', 'Join test 01'); -is(Data::Path::Parser->join('Alert/Target', 'Node', 2), 'Alert/Target/Node[2]', 'Join test 01'); - -# Check the validation -is(Data::Path::Parser->validate($message_path), 1, 'Validation test 01'); -is(Data::Path::Parser->validate(''), 0, 'Validation test 02'); -is(Data::Path::Parser->validate('Alert9]/Target/Node/Address/@category'), 0, 'Validation test 03'); -is(Data::Path::Parser->validate('Alert/Target/Node/Address/@category[1]'), 0, 'Validation test 04'); -is(Data::Path::Parser->validate('Alert/Target/Node/Address/@category/test'), 0, 'Validation test 05'); -is(Data::Path::Parser->validate('Alert/Target[0]/Node/Address/@category'), 0, 'Validation test 06'); diff --git a/lib_perl/tests/unit/t/Mentat.Message.Builder.IDEA.t b/lib_perl/tests/unit/t/Mentat.Message.Builder.IDEA.t deleted file mode 100644 index bfb57fa5aeddcaed1fdee39b25fb005f10efac81..0000000000000000000000000000000000000000 --- a/lib_perl/tests/unit/t/Mentat.Message.Builder.IDEA.t +++ /dev/null @@ -1,133 +0,0 @@ -#!/usr/bin/perl -T - -use strict; -use warnings; - -#******************************************************************************* -# Mentat::Message::Builder::IDEA class tests -# -# Author: Jan Mach, jan.mach@cesnet.cz -# Version: 0.1 -# Purpose: -# Comments: -#******************************************************************************* - -use Data::Dumper; -#use Smart::Comments; - -use Test::More tests => 37; - -# First test if the module correctly compiles -BEGIN { - use vars qw($TESTED_CLASS); - $TESTED_CLASS = 'Mentat::Message::Builder::IDEA'; - - use_ok('Tester'); - use_ok($TESTED_CLASS); - } - -# Debug output explicit ON switch -#Tester::DEBUG_ON(); - -# Debug output explicit OFF switch -#Tester::DEBUG_OFF(); - -# User should know, which version is beeing tested (just for sure) -diag("$TESTED_CLASS version: " . $Mentat::Message::Builder::IDEA::VERSION) if Tester::D(); - -# Prepare message configurations -my $builder_config = { - 'name' => 'tld.domain.node', - 'type' => 'kippo,honeypot', - 'sw' => 'kippo', - 'note' => 'Some note', - }; -my $message_config = { - 'detect_time' => 1356955200, - '1' => '127.0.0.1', - '2' => '127.0.0.2', - '3' => 'root', - '4' => 'failed', - '5' => 10, - }; - -# IDEA message creation using rules -my $mpath_rules = [ - ['EventTime','%ts:$detect_time'], - ['ConnCount','$5'], - ['Node[1]/SW','Kippo'], - ['Node[1]/Tags[1]','Network'], - ['Node[1]/Tags[2]','Honeypot'], - ['Node[1]/Tags[3]','Kippo'], - ['Source[1]/%ipt:$1[1]','$1'], - ['Target[1]/%ipt:$2[1]','$2'], - ['Target[1]/Port[1]','22'], - ['Category[1]','Intrusion'], - ['Completion','$4'], - ['Description','User $3 $4 login from $1'], - ['Note','Remote login via SSH'], - ]; - -# Now attempt to create a class instance and check it -my $instance = $TESTED_CLASS->new($builder_config); -isa_ok($instance, $TESTED_CLASS); - -# View the created instance -diag("Instance dump 01: " . Dumper($instance)) if Tester::D(); - -# Try to build first IDEA message -my $message1 = $instance->build(rules => $mpath_rules, - name_args => $message_config); - -#open(my $hnd, ">./data/alert01.idea") or croak ((caller(0))[3] . ": cannot open file './data/alert01.idea' to store Mentat message for writing"); -#print $hnd $message1->to_string(); -#close($hnd); -#print Dumper($message1); - -# Verify the builded message -# Retrieve some values -is($message1->path_value('DetectTime'), '2012-12-31 12:00:00Z', 'Get node value test A01'); -is($message1->path_value('EventTime'), '2012-12-31 12:00:00Z', 'Get node value test A02'); -is($message1->path_value('Node[1]/SW'), 'Kippo', 'Get node value test A03'); -is($message1->path_value('Node[1]/Tags[1]'), 'Network', 'Get node value test A04'); -is($message1->path_value('Node[1]/Tags[2]'), 'Honeypot', 'Get node value test A05'); -is($message1->path_value('Node[1]/Tags[3]'), 'Kippo', 'Get node value test A06'); -is($message1->path_value('Source[1]/IP4[1]'), '127.0.0.1', 'Get node value test A07'); -is($message1->path_value('Target[1]/IP4[1]'), '127.0.0.2', 'Get node value test A08'); -is($message1->path_value('Target[1]/Port[1]'), '22', 'Get node value test A09'); -is($message1->path_value('Category'), 'Intrusion', 'Get node value test A10'); -is($message1->path_value('Description'), 'User root failed login from 127.0.0.1', 'Get node value test A11'); -is($message1->path_value('Note'), 'Remote login via SSH', 'Get node value test A12'); -is($message1->path_value('Node/Name'), 'tld.domain.node', 'Get node value test A13'); -is($message1->path_value('Node[1]/Type[1]'), 'kippo', 'Get node value test A14'); -is($message1->path_value('Node[1]/Type[2]'), 'honeypot', 'Get node value test A15'); -is($message1->path_value('Node/SW'), 'Kippo', 'Get node value test A16'); -is($message1->path_value('Node/Note'), 'Some note', 'Get node value test A17'); - -diag("Message 01:" . $message1->to_string(1) . "\n") if Tester::D(); - -# Try to build second IDEA message quietly -my $message2 = $instance->build_quiet(rules => $mpath_rules, - name_args => $message_config); - -# Verify the builded message -# Retrieve some values -is($message2->path_value('DetectTime'), '2012-12-31 12:00:00Z', 'Get node value test A01'); -is($message2->path_value('EventTime'), '2012-12-31 12:00:00Z', 'Get node value test A02'); -is($message2->path_value('Node[1]/SW'), 'Kippo', 'Get node value test A03'); -is($message2->path_value('Node[1]/Tags[1]'), 'Network', 'Get node value test A04'); -is($message2->path_value('Node[1]/Tags[2]'), 'Honeypot', 'Get node value test A05'); -is($message2->path_value('Node[1]/Tags[3]'), 'Kippo', 'Get node value test A06'); -is($message2->path_value('Source[1]/IP4[1]'), '127.0.0.1', 'Get node value test A07'); -is($message2->path_value('Target[1]/IP4[1]'), '127.0.0.2', 'Get node value test A08'); -is($message2->path_value('Target[1]/Port[1]'), '22', 'Get node value test A09'); -is($message2->path_value('Category'), 'Intrusion', 'Get node value test A10'); -is($message2->path_value('Description'), 'User root failed login from 127.0.0.1', 'Get node value test A11'); -is($message2->path_value('Note'), 'Remote login via SSH', 'Get node value test A12'); -is($message2->path_value('Node/Name'), 'tld.domain.node', 'Get node value test A13'); -is($message2->path_value('Node[1]/Type[1]'), 'kippo', 'Get node value test A14'); -is($message2->path_value('Node[1]/Type[2]'), 'honeypot', 'Get node value test A15'); -is($message2->path_value('Node/SW'), 'Kippo', 'Get node value test A16'); -is($message2->path_value('Node/Note'), 'Some note', 'Get node value test A17'); - -diag("Message 02:" . $message2->to_string(1) . "\n") if Tester::D(); diff --git a/lib_perl/tests/unit/t/Mentat.Message.Builder.t b/lib_perl/tests/unit/t/Mentat.Message.Builder.t deleted file mode 100644 index 1ca6432b410e8f696f057fb781b847ef45a73610..0000000000000000000000000000000000000000 --- a/lib_perl/tests/unit/t/Mentat.Message.Builder.t +++ /dev/null @@ -1,180 +0,0 @@ -#!/usr/bin/perl -T - -use strict; -use warnings; - -#******************************************************************************* -# Mentat::Message::Builder class tests -# -# Author: Jan Mach, jan.mach@cesnet.cz -# Version: 0.1 -# Purpose: -# Comments: -#******************************************************************************* - -use Data::Dumper; -#use Smart::Comments; - -use Test::More tests => 13; - -# First test if the module correctly compiles -BEGIN { - use vars qw($TESTED_CLASS); - $TESTED_CLASS = 'Mentat::Message::Builder'; - - use_ok('Tester'); - use_ok($TESTED_CLASS); - } - -# Debug output explicit ON switch -#Tester::DEBUG_ON(); - -# Debug output explicit OFF switch -#Tester::DEBUG_OFF(); - -# User should know, which version is beeing tested (just for sure) -diag("$TESTED_CLASS version: " . $Mentat::Message::Builder::VERSION) if Tester::D(); - -#------------------------------------------------------------------------------- - -# Test build rules -my $rulesA = [ - ['Alert/$1', '$v1'], - ['Alert/$2', '$v2'], - ['Alert/$v3', '$3'], - ['Alert/$v4', '$4'], - ['Alert/$x', '$vx'], - ]; - -# Test variables -my $hash_variablesA = { - 'v1' => 'AAA1', - 'v2' => 'AAA2', - 'v3' => 'AAA3', - 'v4' => 'AAA4', - }; -my $array_variablesA = [ - 'x=UUUU', 'BBB1', 'vx=VVVV', 'BBB2', 'BBB3', 'BBB4' - ]; - -# Expected result -my $expectedA = [ - ['Alert/BBB1', 'AAA1'], - ['Alert/BBB2', 'AAA2'], - ['Alert/AAA3', 'BBB3'], - ['Alert/AAA4', 'BBB4'], - ['Alert/UUUU', 'VVVV'], - ]; - -# Fill in the rules -my $resultA = Mentat::Message::Builder->fill_in_rules($rulesA, $hash_variablesA, $array_variablesA); -is_deeply($resultA, $expectedA, 'Fill in rules test A1'); - -#------------------------------------------------------------------------------- - -my $rules2 = [ - ['CreateTime', '%ts'], - ['DetectTime', '%ts:$1'], - ['ID', '%id'], - ]; - -# Test variables -my $array_variables2 = [ - '1416400968' - ]; - -# Fill in the rules -my $result2 = $TESTED_CLASS->fill_in_rules($rules2, {}, $array_variables2); -isnt($result2->[0]->[1], '%ts', "Macro test 01"); -is($result2->[1]->[1], '2014-11-19T12:42:48Z', "Macro test 02"); -isnt($result2->[2]->[1], '%id', "Macro test 03"); - -is_deeply([$TESTED_CLASS->parse_command_args('78.88.62.212 50 "1274106860 Initial Connect"')], ['78.88.62.212', '50', "1274106860 Initial Connect"], "Parse args test 01"); - -#------------------------------------------------------------------------------- - -# Test build rules with undefined argument -my $rulesB = [ - ['Alert/$1', '$v1'], - ['Alert/$2', '$v2'], - ['Alert/$v3', '$3'], - ['Alert/$v4', '$4'], - ['Alert/$x', '$vx'], - ['Alert/$y', '$5'], - ]; - -# Test variables -my $hash_variablesB = { - 'v1' => 'AAA1', - 'v2' => 'AAA2', - 'v3' => 'AAA3', - 'v4' => 'AAA4', - }; -my $array_variablesB = [ - 'x=UUUU', 'BBB1', 'vx=VVVV', 'BBB2', undef, 'BBB4', 0, 'y=WWWW' - ]; - -# Expected result -my $expectedB = [ - ['Alert/BBB1', 'AAA1'], - ['Alert/BBB2', 'AAA2'], - ['Alert/AAA4', 'BBB4'], - ['Alert/UUUU', 'VVVV'], - ['Alert/WWWW', 0], - ]; - -# Fill in the rules -my $resultB = Mentat::Message::Builder->fill_in_rules($rulesB, $hash_variablesB, $array_variablesB, 1); -is_deeply($resultB, $expectedB, 'Fill in rules test B1'); - -#------------------------------------------------------------------------------- - -# Test build rules -my $rulesC = [ - ['Alert/$1', '$v1'], - ['Alert/$2', '$v2'], - ['Alert/$v3', '$3'], - ['Alert/$v4', '$4'], - ['Alert/$x', '$vx'], - ]; - -# Test variables -my $hash_variablesC = { - 'v1' => 'AAA1', - 'v2' => 'AAA2', - 'v3' => 'AAA3', - 'v4' => 'AAA4', - }; -my $array_variablesC = [ - 'x=UUUU', 'BBB1', 'vx=VVVV', 'BBB2', 'BBB3', 'BBB4' - ]; - -# Expected result -my $expectedC = [ - ['Alert/BBB1', 'AAA1'], - ['Alert/BBB2', 'AAA2'], - ['Alert/AAA3', 'BBB3'], - ['Alert/AAA4', 'BBB4'], - ['Alert/UUUU', 'VVVV'], - ]; - -# Fill in the rules one by one -my ($i, $key, $val); -for ($i=0; $i<@$rulesC; $i++){ - ($key, $val) = Mentat::Message::Builder->fill_in_rule($rulesC->[$i]->[0], $rulesC->[$i]->[1], $hash_variablesC, $array_variablesC); - is_deeply([$key, $val], $expectedC->[$i], 'Fill in rules test C'.($i+1)); -} - -#------------------------------------------------------------------------------- - -diag("ID01: ".Mentat::Message::Builder->_macro_id()) if Tester::D(); -diag("ID02: ".Mentat::Message::Builder->_macro_id()) if Tester::D(); -diag("ID03: ".Mentat::Message::Builder->_macro_id()) if Tester::D(); -diag("ID04: ".Mentat::Message::Builder->_macro_id()) if Tester::D(); -diag("ID05: ".Mentat::Message::Builder->_macro_id()) if Tester::D(); - -diag("IDS01: ".Mentat::Message::Builder->_macro_ids()) if Tester::D(); -diag("IDS02: ".Mentat::Message::Builder->_macro_ids()) if Tester::D(); -diag("IDS03: ".Mentat::Message::Builder->_macro_ids()) if Tester::D(); -diag("IDS04: ".Mentat::Message::Builder->_macro_ids()) if Tester::D(); -diag("IDS05: ".Mentat::Message::Builder->_macro_ids()) if Tester::D(); diff --git a/lib_perl/tests/unit/t/Mentat.Message.Factory.t b/lib_perl/tests/unit/t/Mentat.Message.Factory.t deleted file mode 100644 index 2c0ad494abf3659b8132016cacd41deacfa5d0d1..0000000000000000000000000000000000000000 --- a/lib_perl/tests/unit/t/Mentat.Message.Factory.t +++ /dev/null @@ -1,68 +0,0 @@ -#!/usr/bin/perl -T - -use strict; -use warnings; - -#******************************************************************************* -# Mentat::Message::Factory class tests -# -# Author: Jan Mach, jan.mach@cesnet.cz -# Version: 0.1 -# Purpose: -# Comments: -#******************************************************************************* - -use Data::Dumper; -#use Smart::Comments; - -use Test::More tests => 6; - -# First test if the module correctly compiles -BEGIN { - use vars qw($TESTED_CLASS); - $TESTED_CLASS = 'Mentat::Message::Factory'; - - use_ok('Tester'); - use_ok('Mentat::Message::IDEA'); - use_ok($TESTED_CLASS); - } - -# Debug output explicit ON switch -#Tester::DEBUG_ON(); - -# Debug output explicit OFF switch -#Tester::DEBUG_OFF(); - -# User should know, which version is beeing tested (just for sure) -diag("$TESTED_CLASS version: " . $Mentat::Message::Factory::VERSION) if Tester::D(); - - -# Check IDEA message creation from file -my $idea1 = Mentat::Message::Factory->from_file('./spool/alert01.idea'); -isa_ok($idea1, 'Mentat::Message::IDEA'); -diag("Instance print A01: " . $idea1->to_string(1) . "\n") if Tester::D(); -#is($idea1->to_string(), '{"Target":[{"Email":["innocent@example.com"],"Type":["Backscatter"],"Spoofed":1},{"IP4":["10.2.2.2"],"Anonymised":1}],"Format":"IDEA0","Note":"Synthetic example","Attach":[{"FileName":["killemall"],"Size":46,"Hash":["sha1:0c4a38c3569f0cc632e74f4c"],"Type":["malware"],"Handle":"att1","Ref":["Trojan-Spy:W32/FinSpy.A"]}],"DetectTime":"2012-11-03 10:00:00Z","Source":[{"Netname":["ripe:IANA-CBLK-RESERVED1"],"IP4":["195.113.144.194","192.168.0.253"],"Attach":["att1"],"URL":["http://example.com/cgi-bin/killemall"],"Type":["Phishing"]}],"ConnCount":20,"EventTime":"2012-11-03 07:36:00Z","ID":"4390fc3f-c753-4a3e-bc83-1b44f24baf75","Confidence":1,"WinEndTime":"2012-11-03 10:00:00Z","CeaseTime":"2012-11-03 09:55:00Z","WinStartTime":"2012-11-03 05:00:00Z","CreateTime":"2012-11-03 10:02:00Z","Category":["Phishing"],"Node":[{"AggrWin":"12:59:00","SW":["Kippo"],"Name":"buldocek","Type":["Network","Honeypot","Kippo"]}],"Ref":["cve:CVE-1234-5678"]}', "Instance print test A01"); - - -# Check IDEA message creation using rules -my $idea_rules = [ - ['Node[1]/SW[1]', 'Kippo'], - ['Node[1]/Type[1]', 'Honeypot'], - ['Source[1]/IP4[1]', '192.168.0.1'], - ['Target[1]/IP4[1]', '192.168.0.2'], - ['Category[1]', 'Attempt.Login'], - ['Description', 'Remote login'], - ['Note', 'Completion: failed. Someone tried to login as root from 192.168.0.1'], - ['ConnCount', '5'], - ['_CESNET/Impact', 'Someone tried to login as root from 192.168.0.1'], -]; -my $idea2 = Mentat::Message::Factory->from_rules($idea_rules, 'idea'); -isa_ok($idea2, 'Mentat::Message::IDEA'); -diag("Instance print A02: " . $idea2->to_string(1) . "\n") if Tester::D(); -#is($idea2->to_string(), '{"Note":"Completion: failed. Someone tried to login as root from 192.168.0.1","Description":"Remote login","Target":[{"IP4":["192.168.0.2"]}],"ConnCount":5,"Category":["Attempt.Login"],"Node":[{"SW":["Kippo"],"Type":["Honeypot"]}],"Source":[{"IP4":["192.168.0.1"]}],"_CESNET":{"Impact":"Someone tried to login as root from 192.168.0.1"},"Format":"IDEA0"}', "Instance print test A02"); - -# Check IDEA message creation from file -my $idea3 = Mentat::Message::Factory->from_file('./spool/alert02.idea'); -isa_ok($idea1, 'Mentat::Message::IDEA'); -diag("Instance print A03: " . $idea1->to_string(1) . "\n") if Tester::D(); -#is($idea1->to_string(), '{"Target":[{"Email":["innocent@example.com"],"Type":["Backscatter"],"Spoofed":1},{"IP4":["10.2.2.2"],"Anonymised":1}],"Format":"IDEA0","Note":"Synthetic example","Attach":[{"FileName":["killemall"],"Size":46,"Hash":["sha1:0c4a38c3569f0cc632e74f4c"],"Type":["malware"],"Handle":"att1","Ref":["Trojan-Spy:W32/FinSpy.A"]}],"DetectTime":"2012-11-03 10:00:00Z","Source":[{"Netname":["ripe:IANA-CBLK-RESERVED1"],"IP4":["195.113.144.194","192.168.0.253"],"Attach":["att1"],"URL":["http://example.com/cgi-bin/killemall"],"Type":["Phishing"]}],"ConnCount":20,"EventTime":"2012-11-03 07:36:00Z","ID":"4390fc3f-c753-4a3e-bc83-1b44f24baf75","Confidence":1,"WinEndTime":"2012-11-03 10:00:00Z","CeaseTime":"2012-11-03 09:55:00Z","WinStartTime":"2012-11-03 05:00:00Z","CreateTime":"2012-11-03 10:02:00Z","Category":["Phishing"],"Node":[{"AggrWin":"12:59:00","SW":["Kippo"],"Name":"buldocek","Type":["Network","Honeypot","Kippo"]}],"Ref":["cve:CVE-1234-5678"]}', "Instance print test A01"); diff --git a/lib_perl/tests/unit/t/Mentat.Message.IDEA.t b/lib_perl/tests/unit/t/Mentat.Message.IDEA.t deleted file mode 100644 index 5936f2ae01634371d471558527248e79a5244d65..0000000000000000000000000000000000000000 --- a/lib_perl/tests/unit/t/Mentat.Message.IDEA.t +++ /dev/null @@ -1,295 +0,0 @@ -#!/usr/bin/perl -T - -use strict; -use warnings; - -#******************************************************************************* -# Mentat::Message::IDEA class tests -# -# Author: Jan Mach, jan.mach@cesnet.cz -# Version: 0.1 -# Purpose: -# Comments: -#******************************************************************************* - -use Data::Dumper; -#use Smart::Comments; - -use Test::More tests => 156; - -# First test if the module correctly compiles -BEGIN { - use vars qw($TESTED_CLASS); - $TESTED_CLASS = 'Mentat::Message::IDEA'; - - use_ok('Tester'); - use_ok('Mentat::Message'); - use_ok('Value::Convertor'); - use_ok('Value::IP'); - use_ok('Value::Timestamp'); - use_ok('Value::Period'); - use_ok('Mentat::MPath::Parser'); - use_ok($TESTED_CLASS); - } - -# Debug output explicit ON switch -#Tester::DEBUG_ON(); - -# Debug output explicit OFF switch -#Tester::DEBUG_OFF(); - -# User should know, which version is beeing tested (just for sure) -diag("$TESTED_CLASS version: " . $Mentat::Message::IDEA::VERSION) if Tester::D(); - -# Now attempt to create a class instance and check it -my $instance = $TESTED_CLASS->new(); -isa_ok($instance, $TESTED_CLASS); - -# View the created instance -diag("Instance dump 01: " . Dumper($instance)) if Tester::D(); -is($instance->to_string(1), -'{ - "Format" : "IDEA0" -} -', "Instance dump test 01"); -is($instance == {"Format" => "IDEA0"}, 1, "Instance equality test 01"); - -# Check existence of some nodes -is($instance->path_node_exists('Format'), 1, 'Existence test 01'); -is($instance->path_node_exists('Node/Name'), 0, 'Existence test 02'); -is($instance->path_node_exists('Category'), 0, 'Existence test 03'); - -my @MESSAGE_RULES = ( - ["Format", "IDEA0"], - ["ID", "2E4A3926-B1B9-41E3-89AE-B6B474EB0A54"], - ["DetectTime", "2014-03-22T10:12:31Z"], - ["Category[1]", "Recon.Scanning"], - ["ConnCount", 633], - ["Description", "EPMAPPER exploitation attempt"], - ["Ref[1]", "cve:CVE-2003-0605"], - ["Source[1]/IP4[1]", "93.184.216.119"], - ["Source[1]/Proto[1]", "tcp"], - ["Source[1]/Proto[2]", "epmap"], - ["Source[1]/Port[1]", "24508"], - ["Target[1]/Proto[1]", "tcp"], - ["Target[1]/Proto[2]", "epmap"], - ["Target[1]/Port[1]", "135"], - ["Node[1]/Name", "warden-receiver"], - ["Node[1]/Realm", "cesnet.cz"], - ["Node[1]/Tags[1]", "Warden"], - ["Node[1]/SW", "warden-receiver"], - ["Node[2]/Name", "kippo-honey"], - ["Node[2]/Realm", "cesnet.cz"], - ["Node[2]/Tags[1]", "Protocol"], - ["Node[2]/Tags[2]", "Honeypot"], - ["Node[2]/SW", "Kippo"], - ["Node[2]/AggrWin", "00:05:00"], -); -my %MESSAGE_RULES_H = map { $_->[0] => 1 } @MESSAGE_RULES; - -# Create some message structure -foreach my $rule (@MESSAGE_RULES) { - $instance->path_node_set(@$rule); -} - -my $expected = { - "Format" => "IDEA0", - "ID" => "2E4A3926-B1B9-41E3-89AE-B6B474EB0A54", - "Description" => "EPMAPPER exploitation attempt", - "Category" => ["Recon.Scanning"], - "DetectTime" => "2014-03-22 10:12:31Z", - "Ref" => ["cve:CVE-2003-0605"], - "ConnCount" => 633, - "Source" => [ - { - "Proto" => [ - "tcp", - "epmap" - ], - "Port" => ["24508"], - "IP4" => ["93.184.216.119"], - } - ], - "Target" => [ - { - "Port" => ["135"], - "Proto" => [ - "tcp", - "epmap" - ] - } - ], - "Node" => [ - { - "SW" => "warden-receiver", - "Realm" => "cesnet.cz", - "Tags" => [ - "Warden" - ], - "Name" => "warden-receiver" - }, - { - "SW" => "Kippo", - "AggrWin" => "00:05:00", - "Realm" => "cesnet.cz", - "Tags" => [ - "Protocol", - "Honeypot" - ], - "Name" => "kippo-honey" - } - ], -}; -my $expected2 = [ - { - "Proto" => [ - "tcp", - "epmap" - ], - "Port" => ["24508"], - "IP4" => ["93.184.216.119"], - } -]; - -# View the message structure -diag("Instance dump 02: " . Dumper($instance)) if Tester::D(); -is_deeply($instance->hash(), $expected, "Instance dump test 02"); -is($instance == $expected, 0, "Instance equality test 02"); - -is_deeply($instance->path_values('Source'), $expected2, "Instance partial get test 01"); - -diag("'Source/IP4' result: " . Dumper($instance->path_nodes('Source/IP4'))) if Tester::D(); -diag("'Target' result: " . Dumper($instance->path_nodes('Target'))) if Tester::D(); -diag("'Node' result: " . Dumper($instance->path_values('Node'))) if Tester::D(); - -#my $nodes = $instance->path_nodes('Source/IP4'); -#foreach my $n (@$nodes) { -# $$n = 'xx.xx.xx.xx'; -#} -#diag("Instance dump XX: " . Dumper($instance)) if Tester::D(); - -# Test simple iteration -my ($mpath, $value, $node, $i); -($mpath, $value) = $instance->iterate(); -$i = 0; -do { - ++$i; - diag("ITERATE A: $mpath => $value") if Tester::D(); - is($MESSAGE_RULES_H{$mpath}, 1, "Iteration test A1 $i"); - ($mpath, $value) = $instance->iterate(); -} while $mpath; - -# Test iteration in "NODE" mode (returns references, so you may change the values) -($mpath, $node) = $instance->iterate(undef,1); -$i = 0; -do { - ++$i; - diag("ITERATE B: $mpath => $node") if Tester::D(); - #$$node = 'test'; # Alter the current value to new one - is($MESSAGE_RULES_H{$mpath}, 1, "Iteration test B1 $i"); - isnt(ref $node, '', "Iteration test B2 $i"); - ($mpath, $node) = $instance->iterate(undef,1); -} while $mpath; - -# Check the changes made in previous step -($mpath, $value) = $instance->iterate(); -do { - ++$i; - diag("ITERATE C: $mpath => $value") if Tester::D(); - is($MESSAGE_RULES_H{$mpath}, 1, "Iteration test C1 $i"); - ($mpath, $value) = $instance->iterate(); -} while $mpath; - -# Suply the MPath pattern to iterate only over certain nodes -($mpath, $value) = $instance->iterate('Proto'); -do { - diag("ITERATE D: $mpath => $value") if Tester::D(); - is($MESSAGE_RULES_H{$mpath}, 1, "Iteration test D1 $i"); - is($mpath =~ /Proto/, 1, "Iteration test D2 $i"); - ($mpath, $value) = $instance->iterate('Proto'); -} while $mpath; - -# These calls should now yield 1 -is($instance->path_node_exists('Format'), 1, 'Existence test 04'); -is($instance->path_node_exists('Node/Name'), 1, 'Existence test 05'); -is($instance->path_node_exists('Category'), 1, 'Existence test 06'); - -# Determine the message ID -is($instance->id(), '2E4A3926-B1B9-41E3-89AE-B6B474EB0A54', 'Get message ID test'); - -# Retrieve some values -is($instance->path_value('Node/Name'), 'warden-receiver', 'Get node value test 01'); -is($instance->path_value('Category'), 'Recon.Scanning', 'Get node value test 02'); -is($instance->path_value('Node[2]/Name'), 'kippo-honey', 'Get node value test 03'); -is($instance->path_value('Node[#]/Name'), 'kippo-honey', 'Get node value test 04'); -is($instance->path_value('Node[#]/SW'), 'Kippo', 'Get node value test 05'); -is_deeply($instance->path_values('Node[#]/SW'), ['Kippo'], 'Get node value test 06'); - -# Retrieve multiple values -is_deeply($instance->path_values('Node/Tags'), ['Warden','Protocol', 'Honeypot'], 'Get multiple node values test 01'); - -# Change some values -$instance->path_value_set('Node/Name', 'warden-receiver-updated'); -$instance->path_value_set('Category[1]', 'Recon.Scanning-updated'); - -# Verify the values are new -is($instance->path_value('Node/Name'), 'warden-receiver-updated', 'Get node value test 06'); -is($instance->path_value('Category'), 'Recon.Scanning-updated', 'Get node value test 07'); - -# View the message structure -diag("Instance dump 03: " . Dumper($instance)) if Tester::D(); - -# Delete some nodes -$instance->path_node_delete('Node/Name'); -$instance->path_node_delete('Category[1]'); - -# Verify the nodes are gone -is($instance->path_node_exists('Node/Name'), 0, 'Existence test 07'); -is($instance->path_node_exists('Category'), 0, 'Existence test 08'); - -# Fumble with list nodes a bit -$instance->path_node_delete('Category'); -$instance->path_node_set('Category', 'Recon.Scanning'); -is($instance->path_node_exists('Category'), 1, 'Existence test 09'); -is($instance->path_node_exists('Category[1]'), 0, 'Existence test 10'); -is_deeply($instance->path_values('Category'), ['Recon.Scanning'], 'Get values test 01'); -# Check auto conversion from scalar value to list of values by adding value to list -# Also check the '*' list operator -$instance->path_node_set('Category[*]', 'Login.Attempt'); -is($instance->path_node_exists('Category[1]'), 1, 'Existence test 11'); -is($instance->path_node_exists('Category[2]'), 1, 'Existence test 12'); -is($instance->path_node_exists('Category[3]'), 0, 'Existence test 13'); -is_deeply($instance->path_values('Category'), ['Recon.Scanning','Login.Attempt'], 'Get values test 02'); -# Check the '#' operator -$instance->path_node_set('Category[#]', 'Test'); -is($instance->path_node_exists('Category[1]'), 1, 'Existence test 14'); -is($instance->path_node_exists('Category[2]'), 1, 'Existence test 15'); -is($instance->path_node_exists('Category[3]'), 0, 'Existence test 16'); -is_deeply($instance->path_values('Category'), ['Recon.Scanning','Test'], 'Get values test 03'); -$instance->path_node_delete('Category'); -is($instance->path_node_exists('Category'), 0, 'Existence test 17'); -is($instance->path_node_exists('Category[1]'), 0, 'Existence test 18'); -is($instance->path_node_exists('Category[2]'), 0, 'Existence test 19'); -is($instance->path_node_exists('Category[3]'), 0, 'Existence test 20'); - -# View the message structure -diag("Instance dump 04: " . Dumper($instance)) if Tester::D(); - -# Test the message serialization and deserialization -my $serialization = $instance->serialize(); -my $instance2 = $TESTED_CLASS->unserialize($serialization); - -# View the message structure after deserialization -diag("Instance dump 05: " . Dumper($instance2)) if Tester::D(); -is($instance == $instance2, 1, "Instance equality test 03"); -is($instance eq $instance2, 1, "Instance equality test 04"); - -# More equality tests -my $instance3 = $TESTED_CLASS->new(); -my $instance4 = $TESTED_CLASS->new(); -is($instance3 == $instance4, 1, "Instance equality test 05"); -is($instance3 eq $instance4, 1, "Instance equality test 06"); - -# Check loading from file -my $instance5 = $TESTED_CLASS->from_file('./spool/alert01.idea'); -isa_ok($instance5, $TESTED_CLASS); diff --git a/lib_perl/tests/unit/t/Mentat.Message.Validator.IDEA.t b/lib_perl/tests/unit/t/Mentat.Message.Validator.IDEA.t deleted file mode 100644 index 1475e496591726dde559c92b9bbf8fbfaf259768..0000000000000000000000000000000000000000 --- a/lib_perl/tests/unit/t/Mentat.Message.Validator.IDEA.t +++ /dev/null @@ -1,52 +0,0 @@ -#!/usr/bin/perl -T - -use strict; -use warnings; - -#******************************************************************************* -# Mentat::Message::Validator::IDEA class tests -# -# Author: Jan Mach, jan.mach@cesnet.cz -# Version: 0.1 -# Purpose: -# Comments: -#******************************************************************************* - -use Data::Dumper; -#use Smart::Comments; - -use Test::More tests => 8; - -# First test if the module correctly compiles -BEGIN { - use vars qw($TESTED_CLASS); - $TESTED_CLASS = 'Mentat::Message::Validator::IDEA'; - - use_ok('Tester'); - use_ok('Mentat::Message::Validator'); - use_ok('JSON::Schema::Validator'); - use_ok($TESTED_CLASS); - use_ok('Mentat::Message::Factory'); - } - -# Debug output explicit ON switch -#Tester::DEBUG_ON(); - -# Debug output explicit OFF switch -#Tester::DEBUG_OFF(); - -# User should know, which version is beeing tested (just for sure) -diag("$TESTED_CLASS version: " . $Mentat::Message::Validator::IDEA::VERSION) if Tester::D(); -diag("Mentat::Message::Factory version: " . $Mentat::Message::Factory::VERSION) if Tester::D(); - -# Now attempt to create a class instance and check it -my $instance = $TESTED_CLASS->new('../../../schema/idea.schema'); -isa_ok($instance, $TESTED_CLASS); - -# View the created instance -diag("Instance dump 01: " . Dumper($instance)) if Tester::D(); - -# Check the validations -my $idea = Mentat::Message::Factory->from_file('./spool/alert01.idea'); -is($instance->validate_s($idea), '', 'Validation test 01'); -is($instance->validate_b($idea), 0, 'Validation test 02'); diff --git a/lib_perl/tests/unit/t/Mentat.Message.Validator.t b/lib_perl/tests/unit/t/Mentat.Message.Validator.t deleted file mode 100644 index c63d051c12f9f2b1a5136741dddb133598750a0c..0000000000000000000000000000000000000000 --- a/lib_perl/tests/unit/t/Mentat.Message.Validator.t +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/perl -T - -use strict; -use warnings; - -#******************************************************************************* -# Mentat::Message::Validator class tests -# -# Author: Jan Mach, jan.mach@cesnet.cz -# Version: 0.1 -# Purpose: -# Comments: -#******************************************************************************* - -use Data::Dumper; -#use Smart::Comments; - -use Test::More tests => 2; - -# First test if the module correctly compiles -BEGIN { - use vars qw($TESTED_CLASS); - $TESTED_CLASS = 'Mentat::Message::Validator'; - - use_ok('Tester'); - use_ok($TESTED_CLASS); - } - -# Debug output explicit ON switch -#Tester::DEBUG_ON(); - -# Debug output explicit OFF switch -#Tester::DEBUG_OFF(); - -# User should know, which version is beeing tested (just for sure) -diag("$TESTED_CLASS version: " . $Mentat::Message::Validator::VERSION) if Tester::D(); - -# Now attempt to create a class instance and check it -#my $instance = $TESTED_CLASS->new(); -#isa_ok($instance, $TESTED_CLASS); - -# View the created instance -#diag("Instance dump 01: " . Dumper($instance)) if Tester::D(); diff --git a/lib_perl/tests/unit/t/Mentat.Message.Value.IDEA.t b/lib_perl/tests/unit/t/Mentat.Message.Value.IDEA.t deleted file mode 100644 index 5db416bf9f8d93e0025e7197e138ef15c9e23dc2..0000000000000000000000000000000000000000 --- a/lib_perl/tests/unit/t/Mentat.Message.Value.IDEA.t +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/perl -T - -use strict; -use warnings; - -#******************************************************************************* -# Mentat::Message::Value::IDEA module/class tests -# -# Author: Jan Mach, jan.mach@cesnet.cz -# Version: 0.1 -# Purpose: -# -#******************************************************************************* - -use Data::Dumper; -#use Smart::Comments; - -use Test::More tests => 2; - -# First test if the module correctly compiles -BEGIN { - use vars qw($TESTED_CLASS); - $TESTED_CLASS = 'Mentat::Message::Value::IDEA'; - - use_ok('Tester'); - use_ok($TESTED_CLASS); - } - -# Debug output explicit ON switch -#Tester::DEBUG_ON(); - -# Debug output explicit OFF switch -#Tester::DEBUG_OFF(); - -# User should know, which version is beeing tested (just for sure) -diag("$TESTED_CLASS version: " . $Mentat::Message::Value::IDEA::VERSION) if Tester::D(); - -# Now attempt to create a class instance and check it -#my $instance = $TESTED_CLASS->new(); -#isa_ok($instance, $TESTED_CLASS); - -# View the created instance -#diag("Instance dump 01: " . Dumper($instance)) if Tester::D(); diff --git a/lib_perl/tests/unit/t/Mentat.Message.Value.t b/lib_perl/tests/unit/t/Mentat.Message.Value.t deleted file mode 100644 index d5d286a8a17abf59539a398ac700e74276077f6c..0000000000000000000000000000000000000000 --- a/lib_perl/tests/unit/t/Mentat.Message.Value.t +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/perl -T - -use strict; -use warnings; - -#******************************************************************************* -# Mentat::Message::Value module/class tests -# -# Author: Jan Mach, jan.mach@cesnet.cz -# Version: 0.1 -# Purpose: -# -#******************************************************************************* - -use Data::Dumper; -#use Smart::Comments; - -use Test::More tests => 2; - -# First test if the module correctly compiles -BEGIN { - use vars qw($TESTED_CLASS); - $TESTED_CLASS = 'Mentat::Message::Value'; - - use_ok('Tester'); - use_ok($TESTED_CLASS); - } - -# Debug output explicit ON switch -#Tester::DEBUG_ON(); - -# Debug output explicit OFF switch -#Tester::DEBUG_OFF(); - -# User should know, which version is beeing tested (just for sure) -diag("$TESTED_CLASS version: " . $Mentat::Message::Value::VERSION) if Tester::D(); - -# Now attempt to create a class instance and check it -#my $instance = $TESTED_CLASS->new(); -#isa_ok($instance, $TESTED_CLASS); - -# View the created instance -#diag("Instance dump 01: " . Dumper($instance)) if Tester::D(); diff --git a/lib_perl/tests/unit/t/Mentat.Message.t b/lib_perl/tests/unit/t/Mentat.Message.t deleted file mode 100644 index 5db0cfdcf7363a7a2e9a92424114970545a52542..0000000000000000000000000000000000000000 --- a/lib_perl/tests/unit/t/Mentat.Message.t +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/perl -T - -use strict; -use warnings; - -#******************************************************************************* -# Mentat::Message class tests -# -# Author: Jan Mach, jan.mach@cesnet.cz -# Version: 0.1 -# Purpose: -# Comments: -#******************************************************************************* - -use Data::Dumper; -#use Smart::Comments; - -use Test::More tests => 2; - -# First test if the module correctly compiles -BEGIN { - use vars qw($TESTED_CLASS); - $TESTED_CLASS = 'Mentat::Message'; - - use_ok('Tester'); - use_ok($TESTED_CLASS); - } - -# Debug output explicit ON switch -#Tester::DEBUG_ON(); - -# Debug output explicit OFF switch -#Tester::DEBUG_OFF(); - -# User should know, which version is beeing tested (just for sure) -diag("$TESTED_CLASS version: " . $Mentat::Message::VERSION) if Tester::D(); - -# Now attempt to create a class instance and check it -#my $instance = $TESTED_CLASS->new(); -#isa_ok($instance, $TESTED_CLASS); - -# View the created instance -#diag("Instance dump 01: " . Dumper($instance)) if Tester::D(); diff --git a/lib_perl/tests/unit/t/Value.Convertor.t b/lib_perl/tests/unit/t/Value.Convertor.t deleted file mode 100644 index dbc7c0cea4a25992fb5ae3ebdcf7e561cec30f7a..0000000000000000000000000000000000000000 --- a/lib_perl/tests/unit/t/Value.Convertor.t +++ /dev/null @@ -1,797 +0,0 @@ -#!/usr/bin/perl -T - -use strict; -use warnings; - -#******************************************************************************* -# Value::Convertor module/class tests -# -# Author: Jan Mach, jan.mach@cesnet.cz -# Version: 0.1 -# Purpose: -# -#******************************************************************************* - -use Data::Dumper; -#use Smart::Comments; - -use Test::More tests => 7951; - -use Math::BigInt; - -# First test if the module correctly compiles -BEGIN { - use vars qw($TESTED_CLASS); - $TESTED_CLASS = 'Value::Convertor'; - - use_ok('Tester'); - use_ok($TESTED_CLASS); - } - -# Debug output explicit ON switch -#Tester::DEBUG_ON(); - -# Debug output explicit OFF switch -#Tester::DEBUG_OFF(); - -# User should know, which version is beeing tested (just for sure) -diag("$TESTED_CLASS version: " . $Value::Convertor::VERSION) if Tester::D(); - -#------------------------------------------------------------------------------- -# Define tests -#------------------------------------------------------------------------------- - -# IPv4 addresses to be tested -my %IPV4s = ( - 'A' => { - 'str' => '195.113.144.194', - 'hexstr' => 'C37190C2', - 'int' => 3278999746, - }, - 'B' => { - 'str' => '0.0.0.0', - 'hexstr' => '00000000', - 'int' => 0, - }, - 'C' => { - 'str' => '255.255.255.255', - 'hexstr' => 'FFFFFFFF', - 'int' => 4294967295, - }, - 'D' => { - 'str' => '192.168.0.0', - 'hexstr' => 'C0A80000', - 'int' => 3232235520, - }, - 'E' => { - 'str' => '192.168.0.255', - 'hexstr' => 'C0A800FF', - 'int' => 3232235775, - }, - 'F' => { - 'str' => '255.255.255.0', - 'hexstr' => 'FFFFFF00', - 'int' => 4294967040, - }, - ); - -# IPv6 addresses to be tested -my %IPV6s; -{ -use bigint; -%IPV6s = ( - 'A' => { - 'str' => '2001:718:1:1::2', - 'strlng' => '2001:0718:0001:0001:0000:0000:0000:0002', - 'hexstr' => '20010718000100010000000000000002', - 'bigint' => 42540632040320177608853785003998314498, - }, - 'B' => { - 'str' => '::1', - 'strlng' => '0000:0000:0000:0000:0000:0000:0000:0001', - 'hexstr' => '00000000000000000000000000000001', - 'bigint' => 1, - }, - 'C' => { - 'str' => '::', - 'strlng' => '0000:0000:0000:0000:0000:0000:0000:0000', - 'hexstr' => '00000000000000000000000000000000', - 'bigint' => 0, - }, - 'D' => { - 'str' => 'FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF', - 'strlng' => 'FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF', - 'hexstr' => 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF', - 'bigint' => 340282366920938463463374607431768211455, - }, - 'E' => { - 'str' => '2001:718:1:1::9', - 'strlng' => '2001:0718:0001:0001:0000:0000:0000:0009', - 'hexstr' => '20010718000100010000000000000009', - 'bigint' => 42540632040320177608853785003998314505, - }, - ); -} - -# MAC addresses to be tested -my %MACs; -{ -use bigint; -%MACs = ( - 'A' => { - 'str' => '00:1F:1F:50:76:29', - 'hexstr' => '001F1F507629', - 'bigint' => 133669353001, - }, - 'B' => { - 'str' => '00:00:00:00:00:00', - 'hexstr' => '000000000000', - 'bigint' => 0, - }, - 'C' => { - 'str' => 'FF:FF:FF:FF:FF:FF', - 'hexstr' => 'FFFFFFFFFFFF', - 'bigint' => 281474976710655, - }, - ); -} - -my $TIME_ZONE = DateTime::TimeZone->new(name => 'local'); -my $TIME_ZONE_OFFSET = DateTime->now(time_zone => $TIME_ZONE)->offset(); - -# Timestamps to be tested -my %TSs = ( - 'A' => { - 'str_utc' => '2013-05-28 08:34:46Z', # UTC timestamp string - 'str_lcl' => '2013-05-28 10:34:46', # Local timezone timestamp string - 'unixs' => 1369730086, # Unix timestamp - 'unixs_l' => 1369730086 + $TIME_ZONE_OFFSET, # Unix timestamp for local time - 'ntps' => '0xd54eeaa6.0x0', # NTP timestamp - 'ntps_i' => 3578718886, # NTP timestamp in decimal form - 'ubi' => Math::BigInt->new(5882945923717267456), # Unix timestamp in bigint form - 'nbi' => Math::BigInt->new(15370480576947552256), # NTP timestamp in bigint form - 'uints' => [1369730086,0], # Unix timestamp as two integers - 'nints' => [3578718886,0], # NTP timestamp as two integers - }, - 'B' => { - 'str_utc' => '2013-04-18 10:28:37Z', - 'str_lcl' => '2013-04-18 12:28:37', - 'unixs' => 1366280917, - 'unixs_l' => 1366280917 + $TIME_ZONE_OFFSET, - 'ntps' => '0xd51a4955.0x0', - 'ntps_i' => 3575269717, - 'ubi' => Math::BigInt->new(5868131855663890432), - 'nbi' => Math::BigInt->new(15355666508894175232), - 'uints' => [1366280917,0], - 'nints' => [3575269717,0], - }, - 'C' => { - 'str_utc' => '2013-05-28 11:58:14Z', - 'str_lcl' => '2013-05-28 13:58:14', - 'unixs' => 1369742294, - 'unixs_l' => 1369742294 + $TIME_ZONE_OFFSET, - 'ntps' => '0xd54f1a56.0x0', - 'ntps_i' => 3578731094, - 'ubi' => Math::BigInt->new(5882998356678017024), - 'nbi' => Math::BigInt->new(15370533009908301824), - 'uints' => [1369742294,0], - 'nints' => [3578731094,0], - }, - ); - -# Datetime strings for detection tests -my @DTsA = ( - ['2013-02-03 14:55', Math::BigInt->new(15328259390570496000)], - ['2013-02-03T14:55', Math::BigInt->new(15328259390570496000)], - ['2013-02-03 14:55Z', Math::BigInt->new(15328274852452761600)], - ['2013-02-03T14:55Z', Math::BigInt->new(15328274852452761600)], - ['2013-02-03 14:55:12', Math::BigInt->new(15328259442110103552)], - ['2013-02-03T14:55:12', Math::BigInt->new(15328259442110103552)], - ['2013-02-03 14:55:12Z', Math::BigInt->new(15328274903992369152)], - ['2013-02-03T14:55:12Z', Math::BigInt->new(15328274903992369152)], - ['2013-02-03 14:55+0100', Math::BigInt->new(15328259390570496000)], - ['2013-02-03T14:55+0100', Math::BigInt->new(15328259390570496000)], - ['2013-02-03 14:55:12+0100', Math::BigInt->new(15328259442110103552)], - ['2013-02-03T14:55:12+0100', Math::BigInt->new(15328259442110103552)], - ['2013-02-03 14:55-0100', Math::BigInt->new(15328290314335027200)], - ['2013-02-03T14:55-0100', Math::BigInt->new(15328290314335027200)], - ['2013-02-03 14:55:12-0100', Math::BigInt->new(15328290365874634752)], - ['2013-02-03T14:55:12-0100', Math::BigInt->new(15328290365874634752)], - ); -my @DTsB = ( - ['2013-02-03 18:55', Math::BigInt->new(15328321238099558400)], - ['2013-02-03T18:55', Math::BigInt->new(15328321238099558400)], - ['2013-02-03 18:55Z', Math::BigInt->new(15328336699981824000)], - ['2013-02-03T18:55Z', Math::BigInt->new(15328336699981824000)], - ['2013-02-03 18:55:12', Math::BigInt->new(15328321289639165952)], - ['2013-02-03T18:55:12', Math::BigInt->new(15328321289639165952)], - ['2013-02-03 18:55:12Z', Math::BigInt->new(15328336751521431552)], - ['2013-02-03T18:55:12Z', Math::BigInt->new(15328336751521431552)], - ['2013-02-03 18:55+0100', Math::BigInt->new(15328321238099558400)], - ['2013-02-03T18:55+0100', Math::BigInt->new(15328321238099558400)], - ['2013-02-03 18:55:12+0100', Math::BigInt->new(15328321289639165952)], - ['2013-02-03T18:55:12+0100', Math::BigInt->new(15328321289639165952)], - ['2013-02-03 18:55-0100', Math::BigInt->new(15328352161864089600)], - ['2013-02-03T18:55-0100', Math::BigInt->new(15328352161864089600)], - ['2013-02-03 18:55:12-0100', Math::BigInt->new(15328352213403697152)], - ['2013-02-03T18:55:12-0100', Math::BigInt->new(15328352213403697152)], - ); - -#------------------------------------------------------------------------------- -# Test the object (instance) interface -#------------------------------------------------------------------------------- - -# Now attempt to create a class instance and check it -my $instance = $TESTED_CLASS->new(); -isa_ok($instance, $TESTED_CLASS); - -# View the created instance -diag("Instance dump 01: " . Dumper($instance)) if Tester::D(); - -my %TESTS = ('I' => $instance, 'C' => $TESTED_CLASS); -foreach my $T (sort keys %TESTS) -{ - my $invocant = $TESTS{$T}; - - ## - # Test the helper methods - ## - - is($invocant->_zero_pad('test',10,1), 'test000000', 'Test "'.$T.'" "_zero_pad" 01'); - is($invocant->_zero_pad('test',10), '000000test', 'Test "'.$T.'" "_zero_pad" 02'); - - is($invocant->_zero_pad_n('test',2), 'test', 'Test "'.$T.'" "_zero_pad_n" 01'); - is($invocant->_zero_pad_n('test',2,1), 'test', 'Test "'.$T.'" "_zero_pad_n" 02'); - is($invocant->_zero_pad_n('test2',2,1), 'test20', 'Test "'.$T.'" "_zero_pad_n" 03'); - is($invocant->_zero_pad_n('test2',2), '0test2', 'Test "'.$T.'" "_zero_pad_n" 04'); - is($invocant->_zero_pad_n('test2',4,1), 'test2000', 'Test "'.$T.'" "_zero_pad_n" 05'); - is($invocant->_zero_pad_n('test2',4), '000test2', 'Test "'.$T.'" "_zero_pad_n" 06'); - is($invocant->_zero_pad_n('test',5,1), 'test0', 'Test "'.$T.'" "_zero_pad_n" 07'); - is($invocant->_zero_pad_n('test',5), '0test', 'Test "'.$T.'" "_zero_pad_n" 08'); - is($invocant->_zero_pad_n('test',10,1), 'test000000', 'Test "'.$T.'" "_zero_pad_n" 09'); - is($invocant->_zero_pad_n('test',10), '000000test', 'Test "'.$T.'" "_zero_pad_n" 10'); - - ## - # Test the general conversions - ## - - is($invocant->anything_to_samething('test'), 'test', 'Test "'.$T.'" "anything_to_samething" A01'); - is($invocant->anything_to_int('555'), 555, 'Test "'.$T.'" "anything_to_int" A01'); - is($invocant->anything_to_string(555), '555', 'Test "'.$T.'" "anything_to_string" A01'); - - is($invocant->hexstr_to_binstr('a'), '00001010', 'Test "'.$T.'" "hexstr"-"binstr" pair 01'); - is($invocant->binstr_to_hexstr('1010'), '0A', 'Test "'.$T.'" "hexstr"-"binstr" pair 02'); - is($invocant->hexstr_to_binstr('0'), '00000000', 'Test "'.$T.'" "hexstr"-"binstr" pair 03'); - is($invocant->binstr_to_hexstr('0000'), '00', 'Test "'.$T.'" "hexstr"-"binstr" pair 04'); - is($invocant->hexstr_to_binstr('f'), '00001111', 'Test "'.$T.'" "hexstr"-"binstr" pair 05'); - is($invocant->binstr_to_hexstr('1111'), '0F', 'Test "'.$T.'" "hexstr"-"binstr" pair 06'); - is($invocant->hexstr_to_binstr('ab'), '10101011', 'Test "'.$T.'" "hexstr"-"binstr" pair 07'); - is($invocant->binstr_to_hexstr('10101011'), 'AB', 'Test "'.$T.'" "hexstr"-"binstr" pair 08'); - is($invocant->hexstr_to_binstr('00'), '00000000', 'Test "'.$T.'" "hexstr"-"binstr" pair 09'); - is($invocant->binstr_to_hexstr('00000000'), '00', 'Test "'.$T.'" "hexstr"-"binstr" pair 10'); - is($invocant->hexstr_to_binstr('ff'), '11111111', 'Test "'.$T.'" "hexstr"-"binstr" pair 11'); - is($invocant->binstr_to_hexstr('11111111'), 'FF', 'Test "'.$T.'" "hexstr"-"binstr" pair 12'); - is($invocant->binstr_to_hexstr($invocant->hexstr_to_binstr('abcd')), 'ABCD', 'Test "'.$T.'" "hexstr"-"binstr" pair 13'); - is($invocant->hexstr_to_binstr($invocant->binstr_to_hexstr('1010101111001101')), '1010101111001101', 'Test "'.$T.'" "hexstr"-"binstr" pair 14'); - is($invocant->binstr_to_hexstr($invocant->hexstr_to_binstr('0000')), '0000', 'Test "'.$T.'" "hexstr"-"binstr" pair 15'); - is($invocant->hexstr_to_binstr($invocant->binstr_to_hexstr('0000000000000000')), '0000000000000000', 'Test "'.$T.'" "hexstr"-"binstr" pair 16'); - is($invocant->binstr_to_hexstr($invocant->hexstr_to_binstr('ffff')), 'FFFF', 'Test "'.$T.'" "hexstr"-"binstr" pair 17'); - is($invocant->hexstr_to_binstr($invocant->binstr_to_hexstr('1111111111111111')), '1111111111111111', 'Test "'.$T.'" "hexstr"-"binstr" pair 18'); - - { - use bigint; - is($invocant->hexstr_to_bigint('c37190c2'), 3278999746, 'Test "'.$T.'" "hexstr"-"bigint" pair 01'); - is($invocant->bigint_to_hexstr(3278999746), 'C37190C2', 'Test "'.$T.'" "hexstr"-"bigint" pair 02'); - is($invocant->bigint_to_hexstr($invocant->hexstr_to_bigint('c37190c2')), 'C37190C2', 'Test "'.$T.'" "hexstr"-"bigint" pair 03'); - is($invocant->hexstr_to_bigint($invocant->bigint_to_hexstr(3278999746)), 3278999746, 'Test "'.$T.'" "hexstr"-"bigint" pair 04'); - is($invocant->hexstr_to_bigint('00000000'), 0, 'Test "'.$T.'" "hexstr"-"bigint" pair 05'); - is($invocant->bigint_to_hexstr(0), '0', 'Test "'.$T.'" "hexstr"-"bigint" pair 06'); - is($invocant->bigint_to_hexstr(0, 8), '00000000', 'Test "'.$T.'" "hexstr"-"bigint" pair 07'); - is($invocant->bigint_to_hexstr($invocant->hexstr_to_bigint('00000000')), '0', 'Test "'.$T.'" "hexstr"-"bigint" pair 08'); - is($invocant->bigint_to_hexstr($invocant->hexstr_to_bigint('00000000'),8), '00000000', 'Test "'.$T.'" "hexstr"-"bigint" pair 09'); - is($invocant->hexstr_to_bigint($invocant->bigint_to_hexstr(0)), 0, 'Test "'.$T.'" "hexstr"-"bigint" pair 10'); - is($invocant->hexstr_to_bigint('ffffffff'), 4294967295, 'Test "'.$T.'" "hexstr"-"bigint" pair 11'); - is($invocant->bigint_to_hexstr(4294967295), 'FFFFFFFF', 'Test "'.$T.'" "hexstr"-"bigint" pair 12'); - is($invocant->bigint_to_hexstr($invocant->hexstr_to_bigint('ffffffff')), 'FFFFFFFF', 'Test "'.$T.'" "hexstr"-"bigint" pair 13'); - is($invocant->hexstr_to_bigint($invocant->bigint_to_hexstr(4294967295)), 4294967295, 'Test "'.$T.'" "hexstr"-"bigint" pair 14'); - is($invocant->hexstr_to_bigint('001f1f507629'), 133669353001, 'Test "'.$T.'" "hexstr"-"bigint" pair 15'); - is($invocant->bigint_to_hexstr(133669353001), '1F1F507629', 'Test "'.$T.'" "hexstr"-"bigint" pair 16'); - is($invocant->bigint_to_hexstr($invocant->hexstr_to_bigint('001f1f507629')), '1F1F507629', 'Test "'.$T.'" "hexstr"-"bigint" pair 17'); - is($invocant->hexstr_to_bigint($invocant->bigint_to_hexstr(133669353001)), 133669353001, 'Test "'.$T.'" "hexstr"-"bigint" pair 18'); - is($invocant->hexstr_to_bigint('000000000000'), 0, 'Test "'.$T.'" "hexstr"-"bigint" pair 19'); - is($invocant->bigint_to_hexstr(0), '0', 'Test "'.$T.'" "hexstr"-"bigint" pair 20'); - is($invocant->bigint_to_hexstr(0, 10), '0000000000', 'Test "'.$T.'" "hexstr"-"bigint" pair 21'); - is($invocant->bigint_to_hexstr($invocant->hexstr_to_bigint('000000000000')), '0', 'Test "'.$T.'" "hexstr"-"bigint" pair 22'); - is($invocant->bigint_to_hexstr($invocant->hexstr_to_bigint('000000000000'), 10), '0000000000', 'Test "'.$T.'" "hexstr"-"bigint" pair 23'); - is($invocant->hexstr_to_bigint($invocant->bigint_to_hexstr(0)), 0, 'Test "'.$T.'" "hexstr"-"bigint" pair 24'); - is($invocant->hexstr_to_bigint('ffffffffffff'), 281474976710655, 'Test "'.$T.'" "hexstr"-"bigint" pair 25'); - is($invocant->bigint_to_hexstr(281474976710655), 'FFFFFFFFFFFF', 'Test "'.$T.'" "hexstr"-"bigint" pair 26'); - is($invocant->bigint_to_hexstr($invocant->hexstr_to_bigint('ffffffffffff')), 'FFFFFFFFFFFF', 'Test "'.$T.'" "hexstr"-"bigint" pair 27'); - is($invocant->hexstr_to_bigint($invocant->bigint_to_hexstr(281474976710655)), 281474976710655, 'Test "'.$T.'" "hexstr"-"bigint" pair 28'); - is($invocant->hexstr_to_bigint('20010718000100010000000000000002'), 42540632040320177608853785003998314498, 'Test "'.$T.'" "hexstr"-"bigint" pair 29'); - is($invocant->bigint_to_hexstr(42540632040320177608853785003998314498), '20010718000100010000000000000002', 'Test "'.$T.'" "hexstr"-"bigint" pair 30'); - is($invocant->bigint_to_hexstr($invocant->hexstr_to_bigint('20010718000100010000000000000002')), '20010718000100010000000000000002', 'Test "'.$T.'" "hexstr"-"bigint" pair 31'); - is($invocant->hexstr_to_bigint($invocant->bigint_to_hexstr(42540632040320177608853785003998314498)), 42540632040320177608853785003998314498, 'Test "'.$T.'" "hexstr"-"bigint" pair 32'); - is($invocant->hexstr_to_bigint('00000000000000000000000000000000'), 0, 'Test "'.$T.'" "hexstr"-"bigint" pair 33'); - is($invocant->bigint_to_hexstr(0), '0', 'Test "'.$T.'" "hexstr"-"bigint" pair 34'); - is($invocant->bigint_to_hexstr(0, 32), '00000000000000000000000000000000', 'Test "'.$T.'" "hexstr"-"bigint" pair 35'); - is($invocant->bigint_to_hexstr($invocant->hexstr_to_bigint('00000000000000000000000000000000')), 0, 'Test "'.$T.'" "hexstr"-"bigint" pair 36'); - is($invocant->bigint_to_hexstr($invocant->hexstr_to_bigint('00000000000000000000000000000000'), 32), '00000000000000000000000000000000', 'Test "'.$T.'" "hexstr"-"bigint" pair 37'); - is($invocant->hexstr_to_bigint($invocant->bigint_to_hexstr(0)), 0, 'Test "'.$T.'" "hexstr"-"bigint" pair 38'); - is($invocant->hexstr_to_bigint('ffffffffffffffffffffffffffffffff'), 340282366920938463463374607431768211455, 'Test "'.$T.'" "hexstr"-"bigint" pair 39'); - is($invocant->bigint_to_hexstr(340282366920938463463374607431768211455), 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF', 'Test "'.$T.'" "hexstr"-"bigint" pair 40'); - is($invocant->bigint_to_hexstr($invocant->hexstr_to_bigint('ffffffffffffffffffffffffffffffff')), 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF', 'Test "'.$T.'" "hexstr"-"bigint" pair 41'); - is($invocant->hexstr_to_bigint($invocant->bigint_to_hexstr(340282366920938463463374607431768211455)), 340282366920938463463374607431768211455, 'Test "'.$T.'" "hexstr"-"bigint" pair 42'); - } - - is($invocant->bin_to_hexstr($invocant->hexstr_to_bin('a')), '0A', 'Test "'.$T.'" "hexstr"-"bin" pair 01'); - is($invocant->bin_to_hexstr($invocant->hexstr_to_bin('0')), '00', 'Test "'.$T.'" "hexstr"-"bin" pair 02'); - is($invocant->bin_to_hexstr($invocant->hexstr_to_bin('f')), '0F', 'Test "'.$T.'" "hexstr"-"bin" pair 03'); - is($invocant->bin_to_hexstr($invocant->hexstr_to_bin('ab')), 'AB', 'Test "'.$T.'" "hexstr"-"bin" pair 04'); - is($invocant->bin_to_hexstr($invocant->hexstr_to_bin('00')), '00', 'Test "'.$T.'" "hexstr"-"bin" pair 05'); - is($invocant->bin_to_hexstr($invocant->hexstr_to_bin('ff')), 'FF', 'Test "'.$T.'" "hexstr"-"bin" pair 06'); - is($invocant->bin_to_hexstr($invocant->hexstr_to_bin('abcd')), 'ABCD', 'Test "'.$T.'" "hexstr"-"bin" pair 07'); - is($invocant->bin_to_hexstr($invocant->hexstr_to_bin('0000')), '0000', 'Test "'.$T.'" "hexstr"-"bin" pair 08'); - is($invocant->bin_to_hexstr($invocant->hexstr_to_bin('ffff')), 'FFFF', 'Test "'.$T.'" "hexstr"-"bin" pair 09'); - is($invocant->bin_to_hexstr($invocant->hexstr_to_bin('abcdef')), 'ABCDEF', 'Test "'.$T.'" "hexstr"-"bin" pair 10'); - is($invocant->bin_to_hexstr($invocant->hexstr_to_bin('000000')), '000000', 'Test "'.$T.'" "hexstr"-"bin" pair 11'); - is($invocant->bin_to_hexstr($invocant->hexstr_to_bin('ffffff')), 'FFFFFF', 'Test "'.$T.'" "hexstr"-"bin" pair 12'); - - is($invocant->bin_to_binstr($invocant->binstr_to_bin('1')), '00000001', 'Test "'.$T.'" "binstr"-"bin" pair 01'); - is($invocant->bin_to_binstr($invocant->binstr_to_bin('0')), '00000000', 'Test "'.$T.'" "binstr"-"bin" pair 02'); - is($invocant->bin_to_binstr($invocant->binstr_to_bin('10')), '00000010', 'Test "'.$T.'" "binstr"-"bin" pair 03'); - is($invocant->bin_to_binstr($invocant->binstr_to_bin('00')), '00000000', 'Test "'.$T.'" "binstr"-"bin" pair 04'); - is($invocant->bin_to_binstr($invocant->binstr_to_bin('11')), '00000011', 'Test "'.$T.'" "binstr"-"bin" pair 05'); - is($invocant->bin_to_binstr($invocant->binstr_to_bin('1010')), '00001010', 'Test "'.$T.'" "binstr"-"bin" pair 06'); - is($invocant->bin_to_binstr($invocant->binstr_to_bin('0000')), '00000000', 'Test "'.$T.'" "binstr"-"bin" pair 07'); - is($invocant->bin_to_binstr($invocant->binstr_to_bin('1111')), '00001111', 'Test "'.$T.'" "binstr"-"bin" pair 08'); - is($invocant->bin_to_binstr($invocant->binstr_to_bin('10101010')), '10101010', 'Test "'.$T.'" "binstr"-"bin" pair 09'); - is($invocant->bin_to_binstr($invocant->binstr_to_bin('00000000')), '00000000', 'Test "'.$T.'" "binstr"-"bin" pair 10'); - is($invocant->bin_to_binstr($invocant->binstr_to_bin('11111111')), '11111111', 'Test "'.$T.'" "binstr"-"bin" pair 11'); - - { - use bigint; - is($invocant->bin_to_bigint($invocant->bigint_to_bin(3278999746)), 3278999746, 'Test "'.$T.'" "bigint"-"bin" pair 01'); - is($invocant->bin_to_bigint($invocant->bigint_to_bin(281474976710655)), 281474976710655, 'Test "'.$T.'" "bigint"-"bin" pair 02'); - is($invocant->bin_to_bigint($invocant->bigint_to_bin(42540632040320177608853785003998314498)), 42540632040320177608853785003998314498, 'Test "'.$T.'" "bigint"-"bin" pair 03'); - } - - ## - # Test the IPv4 conversions - ## - - foreach my $IP (sort keys(%IPV4s)) - { - is($invocant->ipv4str_to_int($IPV4s{$IP}->{'str'}), $IPV4s{$IP}->{'int'}, 'Test "'.$T.':'.$IP.':" "ipv4str"-"int" pair 01'); - is($invocant->int_to_ipv4str($IPV4s{$IP}->{'int'}), $IPV4s{$IP}->{'str'}, 'Test "'.$T.':'.$IP.':" "ipv4str"-"int" pair 02'); - is($invocant->int_to_ipv4str($invocant->ipv4str_to_int($IPV4s{$IP}->{'str'})), $IPV4s{$IP}->{'str'}, 'Test "'.$T.':'.$IP.':" "ipv4str"-"int" pair 03'); - is($invocant->ipv4str_to_int($invocant->int_to_ipv4str($IPV4s{$IP}->{'int'})), $IPV4s{$IP}->{'int'}, 'Test "'.$T.':'.$IP.':" "ipv4str"-"int" pair 04'); - - is($invocant->ipv4hex_to_int($IPV4s{$IP}->{'hexstr'}), $IPV4s{$IP}->{'int'}, 'Test "'.$T.':'.$IP.':" "ipv4hex"-"int" pair 01'); - is($invocant->int_to_ipv4hex($IPV4s{$IP}->{'int'}), $IPV4s{$IP}->{'hexstr'}, 'Test "'.$T.':'.$IP.':" "ipv4hex"-"int" pair 02'); - is($invocant->int_to_ipv4hex($invocant->ipv4hex_to_int($IPV4s{$IP}->{'hexstr'})), $IPV4s{$IP}->{'hexstr'}, 'Test "'.$T.':'.$IP.':" "ipv4hex"-"int" pair 03'); - is($invocant->ipv4hex_to_int($invocant->int_to_ipv4hex($IPV4s{$IP}->{'int'})), $IPV4s{$IP}->{'int'}, 'Test "'.$T.':'.$IP.':" "ipv4hex"-"int" pair 04'); - - is($invocant->bin_to_ipv4str($invocant->ipv4str_to_bin($IPV4s{$IP}->{'str'})), $IPV4s{$IP}->{'str'}, 'Test "'.$T.':'.$IP.':" "ipv4str"-"bin" pair 01'); - - is($invocant->bin_to_ipv4hex($invocant->ipv4hex_to_bin($IPV4s{$IP}->{'hexstr'})), $IPV4s{$IP}->{'hexstr'}, 'Test "'.$T.':'.$IP.':" "ipv4hex"-"bin" pair 01'); - - is($invocant->bin_to_ipv4int($invocant->ipv4int_to_bin($IPV4s{$IP}->{'int'})), $IPV4s{$IP}->{'int'}, 'Test "'.$T.':'.$IP.':" "ipv4int"-"bin" pair 01'); - - is_deeply([$invocant->detect_ipv4($IPV4s{$IP}->{'str'})], ['IPV4ADDR_STRING',$IPV4s{$IP}->{'str'}], 'Test "'.$T.':'.$IP.':" "detect_ipv4" 01'); - is_deeply([$invocant->detect_ipv4($IPV4s{$IP}->{'hexstr'})], ['IPV4ADDR_HEXSTR',$IPV4s{$IP}->{'hexstr'}], 'Test "'.$T.':'.$IP.':" "detect_ipv4" 02'); - is_deeply([$invocant->detect_ipv4('0x' . $IPV4s{$IP}->{'hexstr'})], ['IPV4ADDR_HEXSTR',$IPV4s{$IP}->{'hexstr'}], 'Test "'.$T.':'.$IP.':" "detect_ipv4" 03'); - is_deeply([$invocant->detect_ipv4($IPV4s{$IP}->{'int'})], ['IPV4ADDR_INTEGER',$IPV4s{$IP}->{'int'}], 'Test "'.$T.':'.$IP.':" "detect_ipv4" 04'); - - is($invocant->detect_ipv6($IPV4s{$IP}->{'str'}), undef, 'Test "'.$T.':'.$IP.':" "detect_ipv6" 01'); - is($invocant->detect_ipv6($IPV4s{$IP}->{'hexstr'}), undef, 'Test "'.$T.':'.$IP.':" "detect_ipv6" 02'); - is($invocant->detect_ipv6('0x' . $IPV4s{$IP}->{'hexstr'}), undef, 'Test "'.$T.':'.$IP.':" "detect_ipv6" 03'); - is_deeply([$invocant->detect_ipv6($IPV4s{$IP}->{'int'})], ['IPV6ADDR_INTEGER',$IPV4s{$IP}->{'int'}], 'Test "'.$T.':'.$IP.':" "detect_ipv6" 04'); - - is_deeply([$invocant->detect_ip($IPV4s{$IP}->{'str'})], ['IPV4ADDR_STRING',$IPV4s{$IP}->{'str'}], 'Test "'.$T.':'.$IP.':" "detect_ip" 01'); - is_deeply([$invocant->detect_ip($IPV4s{$IP}->{'hexstr'})], ['IPV4ADDR_HEXSTR',$IPV4s{$IP}->{'hexstr'}], 'Test "'.$T.':'.$IP.':" "detect_ip" 02'); - is_deeply([$invocant->detect_ip('0x' . $IPV4s{$IP}->{'hexstr'})], ['IPV4ADDR_HEXSTR',$IPV4s{$IP}->{'hexstr'}], 'Test "'.$T.':'.$IP.':" "detect_ip" 03'); - is_deeply([$invocant->detect_ip($IPV4s{$IP}->{'int'})], ['IPV4ADDR_INTEGER',$IPV4s{$IP}->{'int'}], 'Test "'.$T.':'.$IP.':" "detect_ip" 04'); - - is_deeply([$invocant->ipv4_to_int($IPV4s{$IP}->{'str'})], ['IPV4ADDR_STRING',$IPV4s{$IP}->{'int'}], 'Test "'.$T.':'.$IP.':" "ipv4_to_int" 01'); - is_deeply([$invocant->ipv4_to_int($IPV4s{$IP}->{'hexstr'})], ['IPV4ADDR_HEXSTR',$IPV4s{$IP}->{'int'}], 'Test "'.$T.':'.$IP.':" "ipv4_to_int" 02'); - is_deeply([$invocant->ipv4_to_int($IPV4s{$IP}->{'int'})], ['IPV4ADDR_INTEGER',$IPV4s{$IP}->{'int'}], 'Test "'.$T.':'.$IP.':" "ipv4_to_int" 03'); - - is_deeply([$invocant->ipv4_to_bin($IPV4s{$IP}->{'str'})], ['IPV4ADDR_STRING',$invocant->ipv4hex_to_bin($IPV4s{$IP}->{'hexstr'})], 'Test "'.$T.':'.$IP.':" "ipv4_to_bin" 01'); - is_deeply([$invocant->ipv4_to_bin($IPV4s{$IP}->{'hexstr'})], ['IPV4ADDR_HEXSTR',$invocant->ipv4hex_to_bin($IPV4s{$IP}->{'hexstr'})], 'Test "'.$T.':'.$IP.':" "ipv4_to_bin" 02'); - is_deeply([$invocant->ipv4_to_bin($IPV4s{$IP}->{'int'})], ['IPV4ADDR_INTEGER',$invocant->ipv4hex_to_bin($IPV4s{$IP}->{'hexstr'})], 'Test "'.$T.':'.$IP.':" "ipv4_to_bin" 03'); - - is_deeply([$invocant->ip_to_int($IPV4s{$IP}->{'str'})], ['IPV4ADDR_STRING',$IPV4s{$IP}->{'int'}], 'Test "'.$T.':'.$IP.':" "ip_to_int" 01'); - is_deeply([$invocant->ip_to_int($IPV4s{$IP}->{'hexstr'})], ['IPV4ADDR_HEXSTR',$IPV4s{$IP}->{'int'}], 'Test "'.$T.':'.$IP.':" "ip_to_int" 02'); - is_deeply([$invocant->ip_to_int($IPV4s{$IP}->{'int'})], ['IPV4ADDR_INTEGER',$IPV4s{$IP}->{'int'}], 'Test "'.$T.':'.$IP.':" "ip_to_int" 03'); - - is_deeply([$invocant->ip_to_bin($IPV4s{$IP}->{'str'})], ['IPV4ADDR_STRING',$invocant->ipv4hex_to_bin($IPV4s{$IP}->{'hexstr'})], 'Test "'.$T.':'.$IP.':" "ip_to_bin" 01'); - is_deeply([$invocant->ip_to_bin($IPV4s{$IP}->{'hexstr'})], ['IPV4ADDR_HEXSTR',$invocant->ipv4hex_to_bin($IPV4s{$IP}->{'hexstr'})], 'Test "'.$T.':'.$IP.':" "ip_to_bin" 02'); - is_deeply([$invocant->ip_to_bin($IPV4s{$IP}->{'int'})], ['IPV4ADDR_INTEGER',$invocant->ipv4hex_to_bin($IPV4s{$IP}->{'hexstr'})], 'Test "'.$T.':'.$IP.':" "ip_to_bin" 03'); - } - - is_deeply([$invocant->ipv4cidr_to_ints($IPV4s{'D'}->{'str'}.'/24')], [$IPV4s{'D'}->{'int'}, $IPV4s{'E'}->{'int'}], 'Test "'.$T.'" "ipv4cidr_to_ints" 01'); - is_deeply([$invocant->ipv4cidr_to_ints($IPV4s{'D'}->{'str'},'24')], [$IPV4s{'D'}->{'int'}, $IPV4s{'E'}->{'int'}], 'Test "'.$T.'" "ipv4cidr_to_ints" 02'); - - is_deeply([$invocant->ipv4cidr_to_bins($IPV4s{'D'}->{'str'}.'/24')], [$invocant->ipv4str_to_bin($IPV4s{'D'}->{'str'}), $invocant->ipv4str_to_bin($IPV4s{'E'}->{'str'})], 'Test "'.$T.'" "ipv4cidr_to_bins" 01'); - is_deeply([$invocant->ipv4cidr_to_bins($IPV4s{'D'}->{'str'},'24')], [$invocant->ipv4str_to_bin($IPV4s{'D'}->{'str'}), $invocant->ipv4str_to_bin($IPV4s{'E'}->{'str'})], 'Test "'.$T.'" "ipv4cidr_to_bins" 02'); - - is_deeply([$invocant->ipv4netm_to_ints($IPV4s{'D'}->{'str'}.'/'.$IPV4s{'F'}->{'str'})], [$IPV4s{'D'}->{'int'}, $IPV4s{'E'}->{'int'}], 'Test "'.$T.'" "ipv4netm_to_ints" 01'); - is_deeply([$invocant->ipv4netm_to_ints($IPV4s{'D'}->{'str'},$IPV4s{'F'}->{'str'})], [$IPV4s{'D'}->{'int'}, $IPV4s{'E'}->{'int'}], 'Test "'.$T.'" "ipv4netm_to_ints" 02'); - - is_deeply([$invocant->ipv4netm_to_bins($IPV4s{'D'}->{'str'}.'/'.$IPV4s{'F'}->{'str'})], [$invocant->ipv4str_to_bin($IPV4s{'D'}->{'str'}), $invocant->ipv4str_to_bin($IPV4s{'E'}->{'str'})], 'Test "'.$T.'" "ipv4netm_to_bins" 01'); - is_deeply([$invocant->ipv4netm_to_bins($IPV4s{'D'}->{'str'},$IPV4s{'F'}->{'str'})], [$invocant->ipv4str_to_bin($IPV4s{'D'}->{'str'}), $invocant->ipv4str_to_bin($IPV4s{'E'}->{'str'})], 'Test "'.$T.'" "ipv4netm_to_bins" 02'); - - is_deeply([$invocant->ipv4rngstr_to_ints($IPV4s{'D'}->{'str'}.'-'.$IPV4s{'E'}->{'str'})], [$IPV4s{'D'}->{'int'}, $IPV4s{'E'}->{'int'}], 'Test "'.$T.'" "ipv4rngstr_to_ints" 01'); - is_deeply([$invocant->ipv4rngstr_to_ints($IPV4s{'D'}->{'str'}.'..'.$IPV4s{'E'}->{'str'})], [$IPV4s{'D'}->{'int'}, $IPV4s{'E'}->{'int'}], 'Test "'.$T.'" "ipv4rngstr_to_ints" 02'); - is_deeply([$invocant->ipv4rngstr_to_ints($IPV4s{'D'}->{'str'}.' - '.$IPV4s{'E'}->{'str'})], [$IPV4s{'D'}->{'int'}, $IPV4s{'E'}->{'int'}], 'Test "'.$T.'" "ipv4rngstr_to_ints" 03'); - is_deeply([$invocant->ipv4rngstr_to_ints($IPV4s{'D'}->{'str'}.' .. '.$IPV4s{'E'}->{'str'})], [$IPV4s{'D'}->{'int'}, $IPV4s{'E'}->{'int'}], 'Test "'.$T.'" "ipv4rngstr_to_ints" 04'); - is_deeply([$invocant->ipv4rngstr_to_ints($IPV4s{'D'}->{'str'},$IPV4s{'E'}->{'str'})], [$IPV4s{'D'}->{'int'}, $IPV4s{'E'}->{'int'}], 'Test "'.$T.'" "ipv4rngstr_to_ints" 05'); - - is_deeply([$invocant->ipv4rngstr_to_bins($IPV4s{'D'}->{'str'}.'-'.$IPV4s{'E'}->{'str'})], [$invocant->ipv4str_to_bin($IPV4s{'D'}->{'str'}), $invocant->ipv4str_to_bin($IPV4s{'E'}->{'str'})], 'Test "'.$T.'" "ipv4rngstr_to_bins" 01'); - is_deeply([$invocant->ipv4rngstr_to_bins($IPV4s{'D'}->{'str'}.'..'.$IPV4s{'E'}->{'str'})], [$invocant->ipv4str_to_bin($IPV4s{'D'}->{'str'}), $invocant->ipv4str_to_bin($IPV4s{'E'}->{'str'})], 'Test "'.$T.'" "ipv4rngstr_to_bins" 02'); - is_deeply([$invocant->ipv4rngstr_to_bins($IPV4s{'D'}->{'str'}.' - '.$IPV4s{'E'}->{'str'})], [$invocant->ipv4str_to_bin($IPV4s{'D'}->{'str'}), $invocant->ipv4str_to_bin($IPV4s{'E'}->{'str'})], 'Test "'.$T.'" "ipv4rngstr_to_bins" 03'); - is_deeply([$invocant->ipv4rngstr_to_bins($IPV4s{'D'}->{'str'}.' .. '.$IPV4s{'E'}->{'str'})], [$invocant->ipv4str_to_bin($IPV4s{'D'}->{'str'}), $invocant->ipv4str_to_bin($IPV4s{'E'}->{'str'})], 'Test "'.$T.'" "ipv4rngstr_to_bins" 04'); - is_deeply([$invocant->ipv4rngstr_to_bins($IPV4s{'D'}->{'str'},$IPV4s{'E'}->{'str'})], [$invocant->ipv4str_to_bin($IPV4s{'D'}->{'str'}), $invocant->ipv4str_to_bin($IPV4s{'E'}->{'str'})], 'Test "'.$T.'" "ipv4rngstr_to_bins" 05'); - - is($invocant->ints_to_ipv4cidr($IPV4s{'D'}->{'int'}, $IPV4s{'E'}->{'int'}), $IPV4s{'D'}->{'str'}.'/24', 'Test "'.$T.'" "ints_to_ipv4cidr" 01'); - - is($invocant->ints_to_ipv4netm($IPV4s{'D'}->{'int'}, $IPV4s{'E'}->{'int'}), $IPV4s{'D'}->{'str'}.'/'.$IPV4s{'F'}->{'str'}, 'Test "'.$T.'" "ints_to_ipv4netm" 01'); - - is($invocant->ints_to_ipv4rngstr($IPV4s{'D'}->{'int'}, $IPV4s{'E'}->{'int'}), $IPV4s{'D'}->{'str'}.'..'.$IPV4s{'E'}->{'str'}, 'Test "'.$T.'" "ints_to_ipv4rngstr" 01'); - - ## - # Test the IPv6 conversions - ## - - foreach my $IP (sort keys(%IPV6s)) - { - is($invocant->ipv6_expand($IPV6s{$IP}->{'str'}), $IPV6s{$IP}->{'strlng'}, 'Test "'.$T.':'.$IP.':" "ipv6_expand"-"ipv6_collapse" pair 01'); - is($invocant->ipv6_collapse($IPV6s{$IP}->{'strlng'}), $IPV6s{$IP}->{'str'}, 'Test "'.$T.':'.$IP.':" "ipv6_expand"-"ipv6_collapse" pair 02'); - is($invocant->ipv6_collapse($invocant->ipv6_expand($IPV6s{$IP}->{'str'})), $IPV6s{$IP}->{'str'}, 'Test "'.$T.':'.$IP.':" "ipv6_expand"-"ipv6_collapse" pair 03'); - is($invocant->ipv6_expand($invocant->ipv6_collapse($IPV6s{$IP}->{'strlng'})), $IPV6s{$IP}->{'strlng'}, 'Test "'.$T.':'.$IP.':" "ipv6_expand"-"ipv6_collapse" pair 04'); - - is($invocant->ipv6str_to_hexstr($IPV6s{$IP}->{'str'}), $IPV6s{$IP}->{'hexstr'}, 'Test "'.$T.':'.$IP.':" "ipv6str"-"hexstr" pair 01'); - is($invocant->hexstr_to_ipv6str($IPV6s{$IP}->{'hexstr'}), $IPV6s{$IP}->{'str'}, 'Test "'.$T.':'.$IP.':" "ipv6str"-"hexstr" pair 02'); - is($invocant->hexstr_to_ipv6str($invocant->ipv6str_to_hexstr($IPV6s{$IP}->{'str'})), $IPV6s{$IP}->{'str'}, 'Test "'.$T.':'.$IP.':" "ipv6str"-"hexstr" pair 03'); - is($invocant->ipv6str_to_hexstr($invocant->hexstr_to_ipv6str($IPV6s{$IP}->{'hexstr'})), $IPV6s{$IP}->{'hexstr'}, 'Test "'.$T.':'.$IP.':" "ipv6str"-"hexstr" pair 04'); - is($invocant->ipv6str_to_hexstr($IPV6s{$IP}->{'strlng'}), $IPV6s{$IP}->{'hexstr'}, 'Test "'.$T.':'.$IP.':" "ipv6str"-"hexstr" pair 05'); - is($invocant->hexstr_to_ipv6str($invocant->ipv6str_to_hexstr($IPV6s{$IP}->{'strlng'})), $IPV6s{$IP}->{'str'}, 'Test "'.$T.':'.$IP.':" "ipv6str"-"hexstr" pair 06'); - - is($invocant->bin_to_ipv6str($invocant->ipv6str_to_bin($IPV6s{$IP}->{'str'})), $IPV6s{$IP}->{'str'}, 'Test "'.$T.':'.$IP.':" "ipv6str"-"bin" pair 01'); - is($invocant->bin_to_ipv6str($invocant->ipv6str_to_bin($IPV6s{$IP}->{'strlng'})), $IPV6s{$IP}->{'str'}, 'Test "'.$T.':'.$IP.':" "ipv6str"-"bin" pair 02'); - - is($invocant->ipv6str_to_bigint($IPV6s{$IP}->{'str'}), $IPV6s{$IP}->{'bigint'}, 'Test "'.$T.':'.$IP.':" "ipv6str"-"bigint" pair 01'); - is($invocant->bigint_to_ipv6str($IPV6s{$IP}->{'bigint'}), $IPV6s{$IP}->{'str'}, 'Test "'.$T.':'.$IP.':" "ipv6str"-"bigint" pair 02'); - is($invocant->bigint_to_ipv6str($invocant->ipv6str_to_bigint($IPV6s{$IP}->{'str'})), $IPV6s{$IP}->{'str'}, 'Test "'.$T.':'.$IP.':" "ipv6str"-"bigint" pair 03'); - is($invocant->ipv6str_to_bigint($invocant->bigint_to_ipv6str($IPV6s{$IP}->{'bigint'})), $IPV6s{$IP}->{'bigint'}, 'Test "'.$T.':'.$IP.':" "ipv6str"-"bigint" pair 04'); - is($invocant->ipv6str_to_bigint($IPV6s{$IP}->{'strlng'}), $IPV6s{$IP}->{'bigint'}, 'Test "'.$T.':'.$IP.':" "ipv6str"-"bigint" pair 05'); - is($invocant->bigint_to_ipv6str($invocant->ipv6str_to_bigint($IPV6s{$IP}->{'strlng'})), $IPV6s{$IP}->{'str'}, 'Test "'.$T.':'.$IP.':" "ipv6str"-"bigint" pair 06'); - - is_deeply([$invocant->detect_ipv6($IPV6s{$IP}->{'str'})], ['IPV6ADDR_STRING',$IPV6s{$IP}->{'str'}], 'Test "'.$T.':'.$IP.':" "detect_ipv6" 01'); - is_deeply([$invocant->detect_ipv6($IPV6s{$IP}->{'strlng'})], ['IPV6ADDR_STRING',$IPV6s{$IP}->{'strlng'}], 'Test "'.$T.':'.$IP.':" "detect_ipv6" 02'); - is_deeply([$invocant->detect_ipv6($IPV6s{$IP}->{'hexstr'})], ['IPV6ADDR_HEXSTR',$IPV6s{$IP}->{'hexstr'}], 'Test "'.$T.':'.$IP.':" "detect_ipv6" 03'); - is_deeply([$invocant->detect_ipv6($IPV6s{$IP}->{'bigint'})], ['IPV6ADDR_INTEGER',$IPV6s{$IP}->{'bigint'}], 'Test "'.$T.':'.$IP.':" "detect_ipv6" 04'); - - is_deeply([$invocant->detect_ip($IPV6s{$IP}->{'str'})], ['IPV6ADDR_STRING',$IPV6s{$IP}->{'str'}], 'Test "'.$T.':'.$IP.':" "detect_ip" 01'); - is_deeply([$invocant->detect_ip($IPV6s{$IP}->{'strlng'})], ['IPV6ADDR_STRING',$IPV6s{$IP}->{'strlng'}], 'Test "'.$T.':'.$IP.':" "detect_ip" 02'); - is_deeply([$invocant->detect_ip($IPV6s{$IP}->{'hexstr'})], ['IPV6ADDR_HEXSTR',$IPV6s{$IP}->{'hexstr'}], 'Test "'.$T.':'.$IP.':" "detect_ip" 03'); - #is_deeply([$invocant->detect_ip($IPV6s{$IP}->{'bigint'})], ['IPV4ADDR_INTEGER',$IPV6s{$IP}->{'bigint'}], 'Test "'.$T.':'.$IP.':" "detect_ip" 04'); - - is_deeply([$invocant->ipv6_to_bigint($IPV6s{$IP}->{'str'})], ['IPV6ADDR_STRING',$IPV6s{$IP}->{'bigint'}], 'Test "'.$T.':'.$IP.':" "ipv6_to_bigint" 01'); - is_deeply([$invocant->ipv6_to_bigint($IPV6s{$IP}->{'strlng'})], ['IPV6ADDR_STRING',$IPV6s{$IP}->{'bigint'}], 'Test "'.$T.':'.$IP.':" "ipv6_to_bigint" 02'); - is_deeply([$invocant->ipv6_to_bigint($IPV6s{$IP}->{'hexstr'})], ['IPV6ADDR_HEXSTR',$IPV6s{$IP}->{'bigint'}], 'Test "'.$T.':'.$IP.':" "ipv6_to_bigint" 03'); - is_deeply([$invocant->ipv6_to_bigint($IPV6s{$IP}->{'bigint'})], ['IPV6ADDR_INTEGER',$IPV6s{$IP}->{'bigint'}], 'Test "'.$T.':'.$IP.':" "ipv6_to_bigint" 04'); - - is_deeply([$invocant->ipv6_to_bin($IPV6s{$IP}->{'str'})], ['IPV6ADDR_STRING',$invocant->ipv6str_to_bin($IPV6s{$IP}->{'str'})], 'Test "'.$T.':'.$IP.':" "ipv6_to_bin" 01'); - is_deeply([$invocant->ipv6_to_bin($IPV6s{$IP}->{'strlng'})], ['IPV6ADDR_STRING',$invocant->ipv6str_to_bin($IPV6s{$IP}->{'str'})], 'Test "'.$T.':'.$IP.':" "ipv6_to_bin" 02'); - is_deeply([$invocant->ipv6_to_bin($IPV6s{$IP}->{'hexstr'})], ['IPV6ADDR_HEXSTR',$invocant->ipv6str_to_bin($IPV6s{$IP}->{'str'})], 'Test "'.$T.':'.$IP.':" "ipv6_to_bin" 03'); - #is_deeply([$invocant->ipv6_to_bin($IPV6s{$IP}->{'bigint'})], ['IPV6ADDR_INTEGER',$invocant->ipv6str_to_bin($IPV6s{$IP}->{'str'})], 'Test "'.$T.':'.$IP.':" "ipv6_to_bin" 04'); - - is_deeply([$invocant->ip_to_int($IPV6s{$IP}->{'str'})], ['IPV6ADDR_STRING',$IPV6s{$IP}->{'bigint'}], 'Test "'.$T.':'.$IP.':" "ip_to_int" 01'); - is_deeply([$invocant->ip_to_int($IPV6s{$IP}->{'strlng'})], ['IPV6ADDR_STRING',$IPV6s{$IP}->{'bigint'}], 'Test "'.$T.':'.$IP.':" "ip_to_int" 02'); - is_deeply([$invocant->ip_to_int($IPV6s{$IP}->{'hexstr'})], ['IPV6ADDR_HEXSTR',$IPV6s{$IP}->{'bigint'}], 'Test "'.$T.':'.$IP.':" "ip_to_int" 03'); - #is_deeply([$invocant->ip_to_int($IPV6s{$IP}->{'bigint'})], ['IPV6ADDR_INTEGER',$IPV6s{$IP}->{'bigint'}], 'Test "'.$T.':'.$IP.':" "ip_to_bigint" 04'); - - is_deeply([$invocant->ip_to_bin($IPV6s{$IP}->{'str'})], ['IPV6ADDR_STRING',$invocant->ipv6str_to_bin($IPV6s{$IP}->{'str'})], 'Test "'.$T.':'.$IP.':" "ip_to_bin" 01'); - is_deeply([$invocant->ip_to_bin($IPV6s{$IP}->{'strlng'})], ['IPV6ADDR_STRING',$invocant->ipv6str_to_bin($IPV6s{$IP}->{'str'})], 'Test "'.$T.':'.$IP.':" "ip_to_bin" 02'); - is_deeply([$invocant->ip_to_bin($IPV6s{$IP}->{'hexstr'})], ['IPV6ADDR_HEXSTR',$invocant->ipv6str_to_bin($IPV6s{$IP}->{'str'})], 'Test "'.$T.':'.$IP.':" "ip_to_bin" 03'); - #is_deeply([$invocant->ip_to_bin($IPV6s{$IP}->{'bigint'})], ['IPV6ADDR_INTEGER',$invocant->ipv6str_to_bin($IPV6s{$IP}->{'str'})], 'Test "'.$T.':'.$IP.':" "ip_to_bin" 04'); - } - - ## - # Test the IP address detections and general conversions for CIDR subnets and ranges - ## - - is_deeply([$invocant->detect_ipv4($IPV4s{'A'}->{'str'}.'/32')], ['IPV4CIDR_STRING',$IPV4s{'A'}->{'str'},32], 'Test "'.$T.'" "detect_ipv4" 01'); - is_deeply([$invocant->detect_ipv4($IPV4s{'D'}->{'str'}.'-'.$IPV4s{'E'}->{'str'})], ['IPV4RNG_STRING',$IPV4s{'D'}->{'str'}, $IPV4s{'E'}->{'str'}], 'Test "'.$T.'" "detect_ipv4" 02'); - is_deeply([$invocant->detect_ipv4($IPV4s{'D'}->{'hexstr'}.'-'.$IPV4s{'E'}->{'hexstr'})], ['IPV4RNG_HEXSTR',$IPV4s{'D'}->{'hexstr'},$IPV4s{'E'}->{'hexstr'}], 'Test "'.$T.'" "detect_ipv4" 03'); - is_deeply([$invocant->detect_ipv4($IPV4s{'D'}->{'int'}.'-'.$IPV4s{'E'}->{'int'})], ['IPV4RNG_INTEGER',$IPV4s{'D'}->{'int'},$IPV4s{'E'}->{'int'}], 'Test "'.$T.'" "detect_ipv4" 04'); - is_deeply([$invocant->detect_ipv4($IPV4s{'D'}->{'str'}.'..'.$IPV4s{'E'}->{'str'})], ['IPV4RNG_STRING',$IPV4s{'D'}->{'str'}, $IPV4s{'E'}->{'str'}], 'Test "'.$T.'" "detect_ipv4" 05'); - is_deeply([$invocant->detect_ipv4($IPV4s{'D'}->{'hexstr'}.'..'.$IPV4s{'E'}->{'hexstr'})], ['IPV4RNG_HEXSTR',$IPV4s{'D'}->{'hexstr'},$IPV4s{'E'}->{'hexstr'}], 'Test "'.$T.'" "detect_ipv4" 06'); - is_deeply([$invocant->detect_ipv4($IPV4s{'D'}->{'int'}.'..'.$IPV4s{'E'}->{'int'})], ['IPV4RNG_INTEGER',$IPV4s{'D'}->{'int'},$IPV4s{'E'}->{'int'}], 'Test "'.$T.'" "detect_ipv4" 07'); - is_deeply([$invocant->detect_ipv4($IPV4s{'D'}->{'str'}.' - '.$IPV4s{'E'}->{'str'})], ['IPV4RNG_STRING',$IPV4s{'D'}->{'str'}, $IPV4s{'E'}->{'str'}], 'Test "'.$T.'" "detect_ipv4" 08'); - is_deeply([$invocant->detect_ipv4($IPV4s{'D'}->{'hexstr'}.' - '.$IPV4s{'E'}->{'hexstr'})], ['IPV4RNG_HEXSTR',$IPV4s{'D'}->{'hexstr'},$IPV4s{'E'}->{'hexstr'}], 'Test "'.$T.'" "detect_ipv4" 09'); - is_deeply([$invocant->detect_ipv4($IPV4s{'D'}->{'int'}.' - '.$IPV4s{'E'}->{'int'})], ['IPV4RNG_INTEGER',$IPV4s{'D'}->{'int'},$IPV4s{'E'}->{'int'}], 'Test "'.$T.'" "detect_ipv4" 10'); - is_deeply([$invocant->detect_ipv4($IPV4s{'D'}->{'str'}.' .. '.$IPV4s{'E'}->{'str'})], ['IPV4RNG_STRING',$IPV4s{'D'}->{'str'}, $IPV4s{'E'}->{'str'}], 'Test "'.$T.'" "detect_ipv4" 11'); - is_deeply([$invocant->detect_ipv4($IPV4s{'D'}->{'hexstr'}.' .. '.$IPV4s{'E'}->{'hexstr'})], ['IPV4RNG_HEXSTR',$IPV4s{'D'}->{'hexstr'},$IPV4s{'E'}->{'hexstr'}], 'Test "'.$T.'" "detect_ipv4" 12'); - is_deeply([$invocant->detect_ipv4($IPV4s{'D'}->{'int'}.' .. '.$IPV4s{'E'}->{'int'})], ['IPV4RNG_INTEGER',$IPV4s{'D'}->{'int'},$IPV4s{'E'}->{'int'}], 'Test "'.$T.'" "detect_ipv4" 13'); - - is($invocant->detect_ipv4($IPV6s{'A'}->{'str'}), undef, 'Test "'.$T.'" "detect_ipv4" 14'); - is($invocant->detect_ipv4($IPV6s{'A'}->{'hexstr'}), undef, 'Test "'.$T.'" "detect_ipv4" 15'); - is($invocant->detect_ipv4($IPV6s{'A'}->{'bigint'}), undef, 'Test "'.$T.'" "detect_ipv4" 16'); - - is($invocant->detect_ipv4($IPV6s{'A'}->{'str'}.'/64'), undef, 'Test "'.$T.'" "detect_ipv4" 15'); - is($invocant->detect_ipv4($IPV6s{'A'}->{'str'}."-".$IPV6s{'E'}->{'str'}), undef, 'Test "'.$T.'" "detect_ipv4" 16'); - is($invocant->detect_ipv4($IPV6s{'A'}->{'hexstr'}."-".$IPV6s{'E'}->{'hexstr'}), undef, 'Test "'.$T.'" "detect_ipv4" 17'); - is($invocant->detect_ipv4($IPV6s{'A'}->{'bigint'}."-".$IPV6s{'E'}->{'bigint'}), undef, 'Test "'.$T.'" "detect_ipv4" 18'); - - is($invocant->detect_ipv6($IPV4s{'A'}->{'str'}), undef, 'Test "'.$T.'" "detect_ipv6" 01'); - is($invocant->detect_ipv6($IPV4s{'A'}->{'hexstr'}), undef, 'Test "'.$T.'" "detect_ipv6" 02'); - is_deeply([$invocant->detect_ipv6($IPV4s{'A'}->{'int'})], ['IPV6ADDR_INTEGER',$IPV4s{'A'}->{'int'}], 'Test "'.$T.'" "detect_ipv6" 04'); - - is($invocant->detect_ipv6($IPV4s{'A'}->{'str'}.'/32'), undef, 'Test "'.$T.'" "detect_ipv6" 05'); - is($invocant->detect_ipv6($IPV4s{'D'}->{'str'}.'-'.$IPV4s{'E'}->{'str'}), undef, 'Test "'.$T.'" "detect_ipv6" 06'); - is($invocant->detect_ipv6($IPV4s{'D'}->{'hexstr'}.'-'.$IPV4s{'E'}->{'hexstr'}), undef, 'Test "'.$T.'" "detect_ipv6" 07'); - is_deeply([$invocant->detect_ipv6($IPV4s{'D'}->{'int'}.'-'.$IPV4s{'E'}->{'int'})], ['IPV6RNG_INTEGER',$IPV4s{'D'}->{'int'},$IPV4s{'E'}->{'int'}], 'Test "'.$T.'" "detect_ipv6" 09'); - - is_deeply([$invocant->detect_ipv6($IPV6s{'A'}->{'str'}.'/64')], ['IPV6CIDR_STRING',$IPV6s{'A'}->{'str'},'64'], 'Test "'.$T.'" "detect_ipv6" 10'); - is_deeply([$invocant->detect_ipv6($IPV6s{'A'}->{'str'}."-".$IPV6s{'E'}->{'str'})], ['IPV6RNG_STRING',$IPV6s{'A'}->{'str'},$IPV6s{'E'}->{'str'}], 'Test "'.$T.'" "detect_ipv6" 11'); - is_deeply([$invocant->detect_ipv6($IPV6s{'A'}->{'hexstr'}."-".$IPV6s{'E'}->{'hexstr'})], ['IPV6RNG_HEXSTR',$IPV6s{'A'}->{'hexstr'},$IPV6s{'E'}->{'hexstr'}], 'Test "'.$T.'" "detect_ipv6" 12'); - is_deeply([$invocant->detect_ipv6($IPV6s{'A'}->{'bigint'}."-".$IPV6s{'E'}->{'bigint'})], ['IPV6RNG_INTEGER',$IPV6s{'A'}->{'bigint'},$IPV6s{'E'}->{'bigint'}], 'Test "'.$T.'" "detect_ipv6" 13'); - is_deeply([$invocant->detect_ipv6($IPV6s{'A'}->{'str'}."..".$IPV6s{'E'}->{'str'})], ['IPV6RNG_STRING',$IPV6s{'A'}->{'str'},$IPV6s{'E'}->{'str'}], 'Test "'.$T.'" "detect_ipv6" 14'); - is_deeply([$invocant->detect_ipv6($IPV6s{'A'}->{'hexstr'}."..".$IPV6s{'E'}->{'hexstr'})], ['IPV6RNG_HEXSTR',$IPV6s{'A'}->{'hexstr'},$IPV6s{'E'}->{'hexstr'}], 'Test "'.$T.'" "detect_ipv6" 15'); - is_deeply([$invocant->detect_ipv6($IPV6s{'A'}->{'bigint'}."..".$IPV6s{'E'}->{'bigint'})], ['IPV6RNG_INTEGER',$IPV6s{'A'}->{'bigint'},$IPV6s{'E'}->{'bigint'}], 'Test "'.$T.'" "detect_ipv6" 16'); - is_deeply([$invocant->detect_ipv6($IPV6s{'A'}->{'str'}." - ".$IPV6s{'E'}->{'str'})], ['IPV6RNG_STRING',$IPV6s{'A'}->{'str'},$IPV6s{'E'}->{'str'}], 'Test "'.$T.'" "detect_ipv6" 17'); - is_deeply([$invocant->detect_ipv6($IPV6s{'A'}->{'hexstr'}." - ".$IPV6s{'E'}->{'hexstr'})], ['IPV6RNG_HEXSTR',$IPV6s{'A'}->{'hexstr'},$IPV6s{'E'}->{'hexstr'}], 'Test "'.$T.'" "detect_ipv6" 18'); - is_deeply([$invocant->detect_ipv6($IPV6s{'A'}->{'bigint'}." - ".$IPV6s{'E'}->{'bigint'})], ['IPV6RNG_INTEGER',$IPV6s{'A'}->{'bigint'},$IPV6s{'E'}->{'bigint'}], 'Test "'.$T.'" "detect_ipv6" 19'); - is_deeply([$invocant->detect_ipv6($IPV6s{'A'}->{'str'}." .. ".$IPV6s{'E'}->{'str'})], ['IPV6RNG_STRING',$IPV6s{'A'}->{'str'},$IPV6s{'E'}->{'str'}], 'Test "'.$T.'" "detect_ipv6" 20'); - is_deeply([$invocant->detect_ipv6($IPV6s{'A'}->{'hexstr'}." .. ".$IPV6s{'E'}->{'hexstr'})], ['IPV6RNG_HEXSTR',$IPV6s{'A'}->{'hexstr'},$IPV6s{'E'}->{'hexstr'}], 'Test "'.$T.'" "detect_ipv6" 21'); - is_deeply([$invocant->detect_ipv6($IPV6s{'A'}->{'bigint'}." .. ".$IPV6s{'E'}->{'bigint'})], ['IPV6RNG_INTEGER',$IPV6s{'A'}->{'bigint'},$IPV6s{'E'}->{'bigint'}], 'Test "'.$T.'" "detect_ipv6" 22'); - - is_deeply([$invocant->detect_ip($IPV4s{'A'}->{'str'})], ['IPV4ADDR_STRING',$IPV4s{'A'}->{'str'}], 'Test "'.$T.'" "detect_ip" 01'); - is_deeply([$invocant->detect_ip($IPV4s{'A'}->{'hexstr'})], ['IPV4ADDR_HEXSTR',$IPV4s{'A'}->{'hexstr'}], 'Test "'.$T.'" "detect_ip" 02'); - is_deeply([$invocant->detect_ip($IPV4s{'A'}->{'int'})], ['IPV4ADDR_INTEGER',$IPV4s{'A'}->{'int'}], 'Test "'.$T.'" "detect_ip" 03'); - - is_deeply([$invocant->detect_ip($IPV4s{'A'}->{'str'}.'/32')], ['IPV4CIDR_STRING',$IPV4s{'A'}->{'str'},32], 'Test "'.$T.'" "detect_ip" 04'); - is_deeply([$invocant->detect_ip($IPV4s{'D'}->{'str'}.'-'.$IPV4s{'E'}->{'str'})], ['IPV4RNG_STRING',$IPV4s{'D'}->{'str'}, $IPV4s{'E'}->{'str'}], 'Test "'.$T.'" "detect_ip" 05'); - is_deeply([$invocant->detect_ip($IPV4s{'D'}->{'hexstr'}.'-'.$IPV4s{'E'}->{'hexstr'})], ['IPV4RNG_HEXSTR',$IPV4s{'D'}->{'hexstr'},$IPV4s{'E'}->{'hexstr'}], 'Test "'.$T.'" "detect_ip" 06'); - is_deeply([$invocant->detect_ip($IPV4s{'D'}->{'int'}.'-'.$IPV4s{'E'}->{'int'})], ['IPV4RNG_INTEGER',$IPV4s{'D'}->{'int'},$IPV4s{'E'}->{'int'}], 'Test "'.$T.'" "detect_ip" 07'); - is_deeply([$invocant->detect_ip($IPV4s{'D'}->{'str'}.'..'.$IPV4s{'E'}->{'str'})], ['IPV4RNG_STRING',$IPV4s{'D'}->{'str'}, $IPV4s{'E'}->{'str'}], 'Test "'.$T.'" "detect_ip" 08'); - is_deeply([$invocant->detect_ip($IPV4s{'D'}->{'hexstr'}.'..'.$IPV4s{'E'}->{'hexstr'})], ['IPV4RNG_HEXSTR',$IPV4s{'D'}->{'hexstr'},$IPV4s{'E'}->{'hexstr'}], 'Test "'.$T.'" "detect_ip" 09'); - is_deeply([$invocant->detect_ip($IPV4s{'D'}->{'int'}.'..'.$IPV4s{'E'}->{'int'})], ['IPV4RNG_INTEGER',$IPV4s{'D'}->{'int'},$IPV4s{'E'}->{'int'}], 'Test "'.$T.'" "detect_ip" 10'); - is_deeply([$invocant->detect_ip($IPV4s{'D'}->{'str'}.' - '.$IPV4s{'E'}->{'str'})], ['IPV4RNG_STRING',$IPV4s{'D'}->{'str'}, $IPV4s{'E'}->{'str'}], 'Test "'.$T.'" "detect_ip" 11'); - is_deeply([$invocant->detect_ip($IPV4s{'D'}->{'hexstr'}.' - '.$IPV4s{'E'}->{'hexstr'})], ['IPV4RNG_HEXSTR',$IPV4s{'D'}->{'hexstr'},$IPV4s{'E'}->{'hexstr'}], 'Test "'.$T.'" "detect_ip" 12'); - is_deeply([$invocant->detect_ip($IPV4s{'D'}->{'int'}.' - '.$IPV4s{'E'}->{'int'})], ['IPV4RNG_INTEGER',$IPV4s{'D'}->{'int'},$IPV4s{'E'}->{'int'}], 'Test "'.$T.'" "detect_ip" 13'); - is_deeply([$invocant->detect_ip($IPV4s{'D'}->{'str'}.' .. '.$IPV4s{'E'}->{'str'})], ['IPV4RNG_STRING',$IPV4s{'D'}->{'str'}, $IPV4s{'E'}->{'str'}], 'Test "'.$T.'" "detect_ip" 14'); - is_deeply([$invocant->detect_ip($IPV4s{'D'}->{'hexstr'}.' .. '.$IPV4s{'E'}->{'hexstr'})], ['IPV4RNG_HEXSTR',$IPV4s{'D'}->{'hexstr'},$IPV4s{'E'}->{'hexstr'}], 'Test "'.$T.'" "detect_ip" 15'); - is_deeply([$invocant->detect_ip($IPV4s{'D'}->{'int'}.' .. '.$IPV4s{'E'}->{'int'})], ['IPV4RNG_INTEGER',$IPV4s{'D'}->{'int'},$IPV4s{'E'}->{'int'}], 'Test "'.$T.'" "detect_ip" 16'); - - is_deeply([$invocant->detect_ip($IPV6s{'A'}->{'str'})], ['IPV6ADDR_STRING',$IPV6s{'A'}->{'str'}], 'Test "'.$T.'" "detect_ip" 17'); - is_deeply([$invocant->detect_ip($IPV6s{'A'}->{'hexstr'})], ['IPV6ADDR_HEXSTR',$IPV6s{'A'}->{'hexstr'}], 'Test "'.$T.'" "detect_ip" 18'); - is_deeply([$invocant->detect_ip($IPV6s{'A'}->{'bigint'})], ['IPV6ADDR_INTEGER',$IPV6s{'A'}->{'bigint'}], 'Test "'.$T.'" "detect_ip" 19'); - - is_deeply([$invocant->detect_ip($IPV6s{'A'}->{'str'}.'/64')], ['IPV6CIDR_STRING',$IPV6s{'A'}->{'str'},'64'], 'Test "'.$T.'" "detect_ip" 20'); - is_deeply([$invocant->detect_ip($IPV6s{'A'}->{'str'}."-".$IPV6s{'E'}->{'str'})], ['IPV6RNG_STRING',$IPV6s{'A'}->{'str'},$IPV6s{'E'}->{'str'}], 'Test "'.$T.'" "detect_ip" 21'); - is_deeply([$invocant->detect_ip($IPV6s{'A'}->{'hexstr'}."-".$IPV6s{'E'}->{'hexstr'})], ['IPV6RNG_HEXSTR',$IPV6s{'A'}->{'hexstr'},$IPV6s{'E'}->{'hexstr'}], 'Test "'.$T.'" "detect_ip" 22'); - is_deeply([$invocant->detect_ip($IPV6s{'A'}->{'bigint'}."-".$IPV6s{'E'}->{'bigint'})], ['IPV6RNG_INTEGER',$IPV6s{'A'}->{'bigint'},$IPV6s{'E'}->{'bigint'}], 'Test "'.$T.'" "detect_ip" 23'); - is_deeply([$invocant->detect_ip($IPV6s{'A'}->{'str'}."..".$IPV6s{'E'}->{'str'})], ['IPV6RNG_STRING',$IPV6s{'A'}->{'str'},$IPV6s{'E'}->{'str'}], 'Test "'.$T.'" "detect_ip" 24'); - is_deeply([$invocant->detect_ip($IPV6s{'A'}->{'hexstr'}."..".$IPV6s{'E'}->{'hexstr'})], ['IPV6RNG_HEXSTR',$IPV6s{'A'}->{'hexstr'},$IPV6s{'E'}->{'hexstr'}], 'Test "'.$T.'" "detect_ip" 25'); - is_deeply([$invocant->detect_ip($IPV6s{'A'}->{'bigint'}."..".$IPV6s{'E'}->{'bigint'})], ['IPV6RNG_INTEGER',$IPV6s{'A'}->{'bigint'},$IPV6s{'E'}->{'bigint'}], 'Test "'.$T.'" "detect_ip" 26'); - is_deeply([$invocant->detect_ip($IPV6s{'A'}->{'str'}." - ".$IPV6s{'E'}->{'str'})], ['IPV6RNG_STRING',$IPV6s{'A'}->{'str'},$IPV6s{'E'}->{'str'}], 'Test "'.$T.'" "detect_ip" 27'); - is_deeply([$invocant->detect_ip($IPV6s{'A'}->{'hexstr'}." - ".$IPV6s{'E'}->{'hexstr'})], ['IPV6RNG_HEXSTR',$IPV6s{'A'}->{'hexstr'},$IPV6s{'E'}->{'hexstr'}], 'Test "'.$T.'" "detect_ip" 28'); - is_deeply([$invocant->detect_ip($IPV6s{'A'}->{'bigint'}." - ".$IPV6s{'E'}->{'bigint'})], ['IPV6RNG_INTEGER',$IPV6s{'A'}->{'bigint'},$IPV6s{'E'}->{'bigint'}], 'Test "'.$T.'" "detect_ip" 29'); - is_deeply([$invocant->detect_ip($IPV6s{'A'}->{'str'}." .. ".$IPV6s{'E'}->{'str'})], ['IPV6RNG_STRING',$IPV6s{'A'}->{'str'},$IPV6s{'E'}->{'str'}], 'Test "'.$T.'" "detect_ip" 30'); - is_deeply([$invocant->detect_ip($IPV6s{'A'}->{'hexstr'}." .. ".$IPV6s{'E'}->{'hexstr'})], ['IPV6RNG_HEXSTR',$IPV6s{'A'}->{'hexstr'},$IPV6s{'E'}->{'hexstr'}], 'Test "'.$T.'" "detect_ip" 31'); - is_deeply([$invocant->detect_ip($IPV6s{'A'}->{'bigint'}." .. ".$IPV6s{'E'}->{'bigint'})], ['IPV6RNG_INTEGER',$IPV6s{'A'}->{'bigint'},$IPV6s{'E'}->{'bigint'}], 'Test "'.$T.'" "detect_ip" 32'); - - is_deeply([$invocant->ipv4_to_int($IPV4s{'D'}->{'str'}.'/24')], ['IPV4CIDR_STRING',$IPV4s{'D'}->{'int'},$IPV4s{'E'}->{'int'}], 'Test "'.$T.'" "ipv4_to_int" 01'); - is_deeply([$invocant->ipv4_to_int($IPV4s{'D'}->{'str'}.'-'.$IPV4s{'E'}->{'str'})], ['IPV4RNG_STRING',$IPV4s{'D'}->{'int'},$IPV4s{'E'}->{'int'}], 'Test "'.$T.'" "ipv4_to_int" 02'); - - is_deeply([$invocant->ipv4_to_bin($IPV4s{'D'}->{'str'}.'/24')], ['IPV4CIDR_STRING',$invocant->ipv4str_to_bin($IPV4s{'D'}->{'str'}), $invocant->ipv4str_to_bin($IPV4s{'E'}->{'str'})], 'Test "'.$T.'" "ipv4_to_bin" 01'); - is_deeply([$invocant->ipv4_to_bin($IPV4s{'D'}->{'str'}.'-'.$IPV4s{'E'}->{'str'})], ['IPV4RNG_STRING',$invocant->ipv4str_to_bin($IPV4s{'D'}->{'str'}), $invocant->ipv4str_to_bin($IPV4s{'E'}->{'str'})], 'Test "'.$T.'" "ipv4_to_bin" 02'); - - #is_deeply([$invocant->ipv6_to_int($IPV4s{'D'}->{'str'}.'/24')], ['IPV4CIDR_STRING',$IPV4s{'D'}->{'int'},$IPV4s{'E'}->{'int'}], 'Test "'.$T.'" "ipv4_to_int" 01'); - #is_deeply([$invocant->ipv6_to_int($IPV4s{'D'}->{'str'}.'-'.$IPV4s{'E'}->{'str'})], ['IPV4RNG_STRING',$IPV4s{'D'}->{'int'},$IPV4s{'E'}->{'int'}], 'Test "'.$T.'" "ipv4_to_int" 02'); - - #is_deeply([$invocant->ipv6_to_bin($IPV4s{'D'}->{'str'}.'/24')], ['IPV4CIDR_STRING',$invocant->ipv4str_to_bin($IPV4s{'D'}->{'str'}), $invocant->ipv4str_to_bin($IPV4s{'E'}->{'str'})], 'Test "'.$T.'" "ipv4_to_bin" 01'); - #is_deeply([$invocant->ipv6_to_bin($IPV4s{'D'}->{'str'}.'-'.$IPV4s{'E'}->{'str'})], ['IPV4RNG_STRING',$invocant->ipv4str_to_bin($IPV4s{'D'}->{'str'}), $invocant->ipv4str_to_bin($IPV4s{'E'}->{'str'})], 'Test "'.$T.'" "ipv4_to_bin" 02'); - - is_deeply([$invocant->ip_to_int($IPV4s{'D'}->{'str'}.'/24')], ['IPV4CIDR_STRING',$IPV4s{'D'}->{'int'},$IPV4s{'E'}->{'int'}], 'Test "'.$T.'" "ipv4_to_int" 01'); - is_deeply([$invocant->ip_to_int($IPV4s{'D'}->{'str'}.'-'.$IPV4s{'E'}->{'str'})], ['IPV4RNG_STRING',$IPV4s{'D'}->{'int'},$IPV4s{'E'}->{'int'}], 'Test "'.$T.'" "ipv4_to_int" 02'); - - is_deeply([$invocant->ip_to_bin($IPV4s{'D'}->{'str'}.'/24')], ['IPV4CIDR_STRING',$invocant->ipv4str_to_bin($IPV4s{'D'}->{'str'}), $invocant->ipv4str_to_bin($IPV4s{'E'}->{'str'})], 'Test "'.$T.'" "ipv4_to_bin" 01'); - is_deeply([$invocant->ip_to_bin($IPV4s{'D'}->{'str'}.'-'.$IPV4s{'E'}->{'str'})], ['IPV4RNG_STRING',$invocant->ipv4str_to_bin($IPV4s{'D'}->{'str'}), $invocant->ipv4str_to_bin($IPV4s{'E'}->{'str'})], 'Test "'.$T.'" "ipv4_to_bin" 02'); - - is($invocant->ipv4_anonymize($IPV4s{'A'}->{'str'},0), '195.113.144.194', 'Test "'.$T.'" "ipv4_anonymize" 01'); - is($invocant->ipv4_anonymize($IPV4s{'A'}->{'str'},1), '195.113.144.0', 'Test "'.$T.'" "ipv4_anonymize" 02'); - is($invocant->ipv4_anonymize($IPV4s{'A'}->{'str'},2), '195.113.0.0', 'Test "'.$T.'" "ipv4_anonymize" 03'); - is($invocant->ipv4_anonymize($IPV4s{'A'}->{'str'},3), '195.0.0.0', 'Test "'.$T.'" "ipv4_anonymize" 04'); - is($invocant->ipv4_anonymize($IPV4s{'A'}->{'str'},4), '0.0.0.0', 'Test "'.$T.'" "ipv4_anonymize" 05'); - is($invocant->ipv4_anonymize($IPV4s{'A'}->{'str'}), '195.113.144.0', 'Test "'.$T.'" "ipv4_anonymize" 06'); - - is($invocant->ipv4str_to_int('foobar'), undef, 'Failure test "'.$T.'" "ipv4str_to_int" 01'); - is($invocant->ipv4str_to_int(0), undef, 'Failure test "'.$T.'" "ipv4str_to_int" 02'); - - ## - # Test the MAC conversions - ## - - foreach my $MAC (sort keys(%MACs)) - { - is($invocant->macstr_to_hexstr($MACs{$MAC}->{'str'}), $MACs{$MAC}->{'hexstr'}, 'Test "'.$T.':'.$MAC.'" "macstr"-"hexstr" pair 01'); - is($invocant->hexstr_to_macstr($MACs{$MAC}->{'hexstr'}), $MACs{$MAC}->{'str'}, 'Test "'.$T.':'.$MAC.'" "macstr"-"hexstr" pair 02'); - is($invocant->hexstr_to_macstr($invocant->macstr_to_hexstr($MACs{$MAC}->{'str'})), $MACs{$MAC}->{'str'}, 'Test "'.$T.':'.$MAC.'" "macstr"-"hexstr" pair 03'); - is($invocant->macstr_to_hexstr($invocant->hexstr_to_macstr($MACs{$MAC}->{'hexstr'})), $MACs{$MAC}->{'hexstr'}, 'Test "'.$T.':'.$MAC.'" "macstr"-"hexstr" pair 04'); - - is($invocant->bin_to_macstr($invocant->macstr_to_bin($MACs{$MAC}->{'str'})), $MACs{$MAC}->{'str'}, 'Test "'.$T.':'.$MAC.'" "macstr"-"binary" pair 01'); - - is($invocant->macstr_to_bigint($MACs{$MAC}->{'str'}), $MACs{$MAC}->{'bigint'}, 'Test "'.$T.':'.$MAC.'" "macstr"-"bigint" pair 01'); - is($invocant->bigint_to_macstr($MACs{$MAC}->{'bigint'}), $MACs{$MAC}->{'str'}, 'Test "'.$T.':'.$MAC.'" "macstr"-"bigint" pair 02'); - is($invocant->bigint_to_macstr($invocant->macstr_to_bigint($MACs{$MAC}->{'str'})), $MACs{$MAC}->{'str'}, 'Test "'.$T.':'.$MAC.'" "macstr"-"bigint" pair 03'); - is($invocant->macstr_to_bigint($invocant->bigint_to_macstr($MACs{$MAC}->{'bigint'})), $MACs{$MAC}->{'bigint'}, 'Test "'.$T.':'.$MAC.'" "macstr"-"bigint" pair 04'); - } - - ## - # Test the time and date conversions - ## - - foreach my $TS (sort keys(%TSs)) - { - is($invocant->ntps_to_nbi($TSs{$TS}->{'ntps'}), $TSs{$TS}->{'nbi'}, 'Test "'.$T.':'.$TS.'" "ntps"-"nbi" pair 01'); - is($invocant->nbi_to_ntps($TSs{$TS}->{'nbi'}), $TSs{$TS}->{'ntps'}, 'Test "'.$T.':'.$TS.'" "ntps"-"nbi" pair 02'); - is($invocant->nbi_to_ntps($invocant->ntps_to_nbi($TSs{$TS}->{'ntps'})), $TSs{$TS}->{'ntps'}, 'Test "'.$T.':'.$TS.'" "ntps"-"nbi" pair 03'); - is($invocant->ntps_to_nbi($invocant->nbi_to_ntps($TSs{$TS}->{'nbi'})), $TSs{$TS}->{'nbi'}, 'Test "'.$T.':'.$TS.'" "ntps"-"nbi" pair 04'); - - is($invocant->unixs_to_ubi($TSs{$TS}->{'unixs'}), $TSs{$TS}->{'ubi'}, 'Test "'.$T.':'.$TS.'" "unixs"-"ubi" pair 01'); - is($invocant->ubi_to_unixs($TSs{$TS}->{'ubi'}), $TSs{$TS}->{'unixs'}, 'Test "'.$T.':'.$TS.'" "unixs"-"ubi" pair 02'); - is($invocant->ubi_to_unixs($invocant->unixs_to_ubi($TSs{$TS}->{'unixs'})), $TSs{$TS}->{'unixs'}, 'Test "'.$T.':'.$TS.'" "unixs"-"ubi" pair 03'); - is($invocant->unixs_to_ubi($invocant->ubi_to_unixs($TSs{$TS}->{'ubi'})), $TSs{$TS}->{'ubi'}, 'Test "'.$T.':'.$TS.'" "unixs"-"ubi" pair 04'); - - is($invocant->unixs_to_nbi($TSs{$TS}->{'unixs'}), $TSs{$TS}->{'nbi'}, 'Test "'.$T.':'.$TS.'" "unixs"-"nbi" pair 01'); - is($invocant->nbi_to_unixs($TSs{$TS}->{'nbi'}), $TSs{$TS}->{'unixs'}, 'Test "'.$T.':'.$TS.'" "unixs"-"nbi" pair 02'); - is($invocant->nbi_to_unixs($invocant->unixs_to_nbi($TSs{$TS}->{'unixs'})), $TSs{$TS}->{'unixs'}, 'Test "'.$T.':'.$TS.'" "unixs"-"nbi" pair 03'); - is($invocant->unixs_to_nbi($invocant->nbi_to_unixs($TSs{$TS}->{'nbi'})), $TSs{$TS}->{'nbi'}, 'Test "'.$T.':'.$TS.'" "unixs"-"nbi" pair 04'); - - is_deeply($invocant->ntps_to_ints($TSs{$TS}->{'ntps'}), $TSs{$TS}->{'nints'}, 'Test "'.$T.':'.$TS.'" "ntps"-"ints" pair 01'); - is($invocant->ints_to_ntps($TSs{$TS}->{'nints'}), $TSs{$TS}->{'ntps'}, 'Test "'.$T.':'.$TS.'" "ntps"-"ints" pair 02'); - is($invocant->ints_to_ntps($invocant->ntps_to_ints($TSs{$TS}->{'ntps'})), $TSs{$TS}->{'ntps'}, 'Test "'.$T.':'.$TS.'" "ntps"-"ints" pair 03'); - is_deeply($invocant->ntps_to_ints($invocant->ints_to_ntps($TSs{$TS}->{'nints'})), $TSs{$TS}->{'nints'}, 'Test "'.$T.':'.$TS.'" "ntps"-"ints" pair 04'); - - is_deeply($invocant->unixs_to_ints($TSs{$TS}->{'unixs'}), $TSs{$TS}->{'uints'}, 'Test "'.$T.':'.$TS.'" "unixs"-"ints" pair 01'); - is($invocant->ints_to_unixs($TSs{$TS}->{'uints'}), $TSs{$TS}->{'unixs'}, 'Test "'.$T.':'.$TS.'" "unixs"-"ints" pair 02'); - is($invocant->ints_to_unixs($invocant->unixs_to_ints($TSs{$TS}->{'unixs'})), $TSs{$TS}->{'unixs'}, 'Test "'.$T.':'.$TS.'" "unixs"-"ints" pair 03'); - is_deeply($invocant->unixs_to_ints($invocant->ints_to_unixs($TSs{$TS}->{'uints'})), $TSs{$TS}->{'uints'}, 'Test "'.$T.':'.$TS.'" "unixs"-"ints" pair 04'); - - is($invocant->ntpe_to_unixe($TSs{$TS}->{'ntps_i'}), $TSs{$TS}->{'unixs'}, 'Test "'.$T.':'.$TS.'" "ntpe"-"unixe" pair 01'); - is($invocant->unixe_to_ntpe($TSs{$TS}->{'unixs'}), $TSs{$TS}->{'ntps_i'}, 'Test "'.$T.':'.$TS.'" "ntpe"-"unixe" pair 02'); - is($invocant->unixe_to_ntpe($invocant->ntpe_to_unixe($TSs{$TS}->{'ntps_i'})), $TSs{$TS}->{'ntps_i'}, 'Test "'.$T.':'.$TS.'" "ntpe"-"unixe" pair 03'); - is($invocant->ntpe_to_unixe($invocant->unixe_to_ntpe($TSs{$TS}->{'unixs'})), $TSs{$TS}->{'unixs'}, 'Test "'.$T.':'.$TS.'" "ntpe"-"unixe" pair 04'); - - is($invocant->ntpe_to_unixe_b($TSs{$TS}->{'nbi'}), $TSs{$TS}->{'ubi'}, 'Test "'.$T.':'.$TS.'" "ntpe_b"-"unixe_b" pair 01'); - is($invocant->unixe_to_ntpe_b($TSs{$TS}->{'ubi'}), $TSs{$TS}->{'nbi'}, 'Test "'.$T.':'.$TS.'" "ntpe_b"-"unixe_b" pair 02'); - is($invocant->unixe_to_ntpe_b($invocant->ntpe_to_unixe_b($TSs{$TS}->{'nbi'})), $TSs{$TS}->{'nbi'}, 'Test "'.$T.':'.$TS.'" "ntpe_b"-"unixe_b" pair 03'); - is($invocant->ntpe_to_unixe_b($invocant->unixe_to_ntpe_b($TSs{$TS}->{'ubi'})), $TSs{$TS}->{'ubi'}, 'Test "'.$T.':'.$TS.'" "ntpe_b"-"unixe_b" pair 04'); - - is($invocant->local_to_utc($TSs{$TS}->{'unixs_l'}), $TSs{$TS}->{'unixs'}, 'Test "'.$T.':'.$TS.'" "local"-"utc" pair A01'); - is($invocant->utc_to_local($TSs{$TS}->{'unixs'}), $TSs{$TS}->{'unixs_l'}, 'Test "'.$T.':'.$TS.'" "local"-"utc" pair A02'); - is($invocant->utc_to_local($invocant->local_to_utc($TSs{$TS}->{'unixs_l'})), $TSs{$TS}->{'unixs_l'}, 'Test "'.$T.':'.$TS.'" "local"-"utc" pair A03'); - is($invocant->local_to_utc($invocant->utc_to_local($TSs{$TS}->{'unixs'})), $TSs{$TS}->{'unixs'}, 'Test "'.$T.':'.$TS.'" "local"-"utc" pair A04'); - - is($invocant->unixs_to_datestr($TSs{$TS}->{'unixs'}), $TSs{$TS}->{'str_utc'}, 'Test "'.$T.':'.$TS.'" "unix"-"datestr" pair 01'); - is($invocant->unixs_to_datestr($TSs{$TS}->{'unixs'},1), $TSs{$TS}->{'str_lcl'}, 'Test "'.$T.':'.$TS.'" "unix"-"datestr" pair 02'); - is($invocant->datestr_to_unixs($TSs{$TS}->{'str_utc'}), $TSs{$TS}->{'unixs'}, 'Test "'.$T.':'.$TS.'" "unix"-"datestr" pair 03'); - is($invocant->datestr_to_unixs($TSs{$TS}->{'str_utc'},1), $TSs{$TS}->{'unixs'}, 'Test "'.$T.':'.$TS.'" "unix"-"datestr" pair 04'); - is($invocant->datestr_to_unixs($invocant->unixs_to_datestr($TSs{$TS}->{'unixs'})), $TSs{$TS}->{'unixs'}, 'Test "'.$T.':'.$TS.'" "unix"-"datestr" pair 05'); - is($invocant->unixs_to_datestr($invocant->datestr_to_unixs($TSs{$TS}->{'str_utc'})), $TSs{$TS}->{'str_utc'}, 'Test "'.$T.':'.$TS.'" "unix"-"datestr" pair 06'); - - is($invocant->ntps_to_datestr($TSs{$TS}->{'ntps'}), $TSs{$TS}->{'str_utc'}, 'Test "'.$T.':'.$TS.'" "ntps_to_datestr" 01'); - is($invocant->ntps_to_datestr($TSs{$TS}->{'ntps'},1), $TSs{$TS}->{'str_lcl'}, 'Test "'.$T.':'.$TS.'" "ntps_to_datestr" 02'); - - is($invocant->datestr_to_ubi($TSs{$TS}->{'str_utc'}), $TSs{$TS}->{'ubi'}, 'Test "'.$T.':'.$TS.'" "datestr"-"ubi" pair 01'); - is($invocant->ubi_to_datestr($TSs{$TS}->{'ubi'}), $TSs{$TS}->{'str_utc'}, 'Test "'.$T.':'.$TS.'" "datestr"-"ubi" pair 02'); - is($invocant->ubi_to_datestr($TSs{$TS}->{'ubi'},1), $TSs{$TS}->{'str_lcl'}, 'Test "'.$T.':'.$TS.'" "datestr"-"ubi" pair 03'); - is($invocant->ubi_to_datestr($invocant->datestr_to_ubi($TSs{$TS}->{'str_utc'})), $TSs{$TS}->{'str_utc'}, 'Test "'.$T.':'.$TS.'" "datestr"-"ubi" pair 04'); - is($invocant->datestr_to_ubi($invocant->ubi_to_datestr($TSs{$TS}->{'ubi'})), $TSs{$TS}->{'ubi'}, 'Test "'.$T.':'.$TS.'" "datestr"-"ubi" pair 05'); - is($invocant->datestr_to_ubi($invocant->ubi_to_datestr($TSs{$TS}->{'ubi'},1)), $TSs{$TS}->{'ubi'}, 'Test "'.$T.':'.$TS.'" "datestr"-"ubi" pair 06'); - - is($invocant->datestr_to_nbi($TSs{$TS}->{'str_utc'}), $TSs{$TS}->{'nbi'}, 'Test "'.$T.':'.$TS.'" "datestr"-"nbi" pair 01'); - is($invocant->nbi_to_datestr($TSs{$TS}->{'nbi'}), $TSs{$TS}->{'str_utc'}, 'Test "'.$T.':'.$TS.'" "datestr"-"nbi" pair 02'); - is($invocant->nbi_to_datestr($TSs{$TS}->{'nbi'},1), $TSs{$TS}->{'str_lcl'}, 'Test "'.$T.':'.$TS.'" "datestr"-"nbi" pair 03'); - is($invocant->nbi_to_datestr($invocant->datestr_to_nbi($TSs{$TS}->{'str_utc'})), $TSs{$TS}->{'str_utc'}, 'Test "'.$T.':'.$TS.'" "datestr"-"nbi" pair 04'); - is($invocant->datestr_to_nbi($invocant->nbi_to_datestr($TSs{$TS}->{'nbi'})), $TSs{$TS}->{'nbi'}, 'Test "'.$T.':'.$TS.'" "datestr"-"nbi" pair 05'); - is($invocant->datestr_to_nbi($invocant->nbi_to_datestr($TSs{$TS}->{'nbi'},1)), $TSs{$TS}->{'nbi'}, 'Test "'.$T.':'.$TS.'" "datestr"-"nbi" pair 06'); - - is_deeply([$invocant->detect_datetime($TSs{$TS}->{'str_utc'})], ['TS_DATETIME',$TSs{$TS}->{'str_utc'}], 'Test "'.$T.':'.$TS.'" "detect_datetime" 01'); - is_deeply([$invocant->detect_datetime($TSs{$TS}->{'ntps'})], ['TS_NTPSTAMP',$TSs{$TS}->{'ntps'}], 'Test "'.$T.':'.$TS.'" "detect_datetime" 02'); - is_deeply([$invocant->detect_datetime($TSs{$TS}->{'unixs'})], ['TS_UNIXSTAMP',$TSs{$TS}->{'unixs'}], 'Test "'.$T.':'.$TS.'" "detect_datetime" 03'); - - is_deeply([$invocant->datetime_to_nbi($TSs{$TS}->{'str_utc'})], ['TS_DATETIME',$TSs{$TS}->{'nbi'}], 'Test "'.$T.':'.$TS.'" "datetime_to_nbi" 01'); - is_deeply([$invocant->datetime_to_nbi($TSs{$TS}->{'ntps'})], ['TS_NTPSTAMP',$TSs{$TS}->{'nbi'}], 'Test "'.$T.':'.$TS.'" "datetime_to_nbi" 02'); - is_deeply([$invocant->datetime_to_nbi($TSs{$TS}->{'unixs'})], ['TS_UNIXSTAMP',$TSs{$TS}->{'nbi'}], 'Test "'.$T.':'.$TS.'" "datetime_to_nbi" 03'); - } - - # Test the timestamp string detection and conversion - foreach my $DT (@DTsA) - { - is_deeply([$invocant->detect_datetime($DT->[0])], ['TS_DATETIME',$DT->[0]], 'Test "'.$T.':'.$DT->[0].'" detect_datetime"'); - is_deeply([$invocant->datetime_to_nbi($DT->[0])], ['TS_DATETIME',$DT->[1]], 'Test "'.$T.':'.$DT->[0].'" "datetime_to_nbi"'); - } - foreach my $DT (@DTsB) - { - is_deeply([$invocant->detect_datetime($DT->[0])], ['TS_DATETIME',$DT->[0]], 'Test "'.$T.':'.$DT->[0].'" detect_datetime"'); - is_deeply([$invocant->datetime_to_nbi($DT->[0])], ['TS_DATETIME',$DT->[1]], 'Test "'.$T.':'.$DT->[0].'" "datetime_to_nbi"'); - } - # Test the direct period string conversion - foreach my $DTa (@DTsA) - { - foreach my $DTb (@DTsB) - { - is_deeply([$invocant->periodstr_to_nbis($DTa->[0].'-'.$DTb->[0])], [$DTa->[1],$DTb->[1]], 'Test "'.$T.':'.$DTa->[0].'-'.$DTb->[0].'" periodstr_to_nbis"'); - is_deeply([$invocant->periodstr_to_nbis($DTa->[0].'..'.$DTb->[0])], [$DTa->[1],$DTb->[1]], 'Test "'.$T.':'.$DTa->[0].'-'.$DTb->[0].'" periodstr_to_nbis"'); - is_deeply([$invocant->periodstr_to_nbis($DTa->[0].' - '.$DTb->[0])], [$DTa->[1],$DTb->[1]], 'Test "'.$T.':'.$DTa->[0].'-'.$DTb->[0].'" periodstr_to_nbis"'); - is_deeply([$invocant->periodstr_to_nbis($DTa->[0].' .. '.$DTb->[0])], [$DTa->[1],$DTb->[1]], 'Test "'.$T.':'.$DTa->[0].'-'.$DTb->[0].'" periodstr_to_nbis"'); - } - } - - # Test the time period string detection - foreach my $DTa (@DTsA) - { - foreach my $DTb (@DTsB) - { - is_deeply([$invocant->detect_datetime($DTa->[0].'-'.$DTb->[0])], ['TS_PERIOD',$DTa->[0],$DTb->[0]], 'Test "'.$T.':'.$DTa->[0].'-'.$DTb->[0].'" detect_datetime"'); - is_deeply([$invocant->detect_datetime($DTa->[0].'..'.$DTb->[0])], ['TS_PERIOD',$DTa->[0],$DTb->[0]], 'Test "'.$T.':'.$DTa->[0].'..'.$DTb->[0].'" detect_datetime"'); - is_deeply([$invocant->detect_datetime($DTa->[0].' - '.$DTb->[0])], ['TS_PERIOD',$DTa->[0],$DTb->[0]], 'Test "'.$T.':'.$DTa->[0].' - '.$DTb->[0].'" detect_datetime"'); - is_deeply([$invocant->detect_datetime($DTa->[0].' .. '.$DTb->[0])], ['TS_PERIOD',$DTa->[0],$DTb->[0]], 'Test "'.$T.':'.$DTa->[0].' .. '.$DTb->[0].'" detect_datetime"'); - is_deeply([$invocant->datetime_to_nbi($DTa->[0].'-'.$DTb->[0])], ['TS_PERIOD',$DTa->[1],$DTb->[1]], 'Test "'.$T.':'.$DTa->[0].'-'.$DTb->[0].'" datetime_to_nbi"'); - is_deeply([$invocant->datetime_to_nbi($DTa->[0].'..'.$DTb->[0])], ['TS_PERIOD',$DTa->[1],$DTb->[1]], 'Test "'.$T.':'.$DTa->[0].'..'.$DTb->[0].'" datetime_to_nbi"'); - is_deeply([$invocant->datetime_to_nbi($DTa->[0].' - '.$DTb->[0])], ['TS_PERIOD',$DTa->[1],$DTb->[1]], 'Test "'.$T.':'.$DTa->[0].' - '.$DTb->[0].'" datetime_to_nbi"'); - is_deeply([$invocant->datetime_to_nbi($DTa->[0].' .. '.$DTb->[0])], ['TS_PERIOD',$DTa->[1],$DTb->[1]], 'Test "'.$T.':'.$DTa->[0].' .. '.$DTb->[0].'" datetime_to_nbi"'); - } - } - - is($invocant->ntpe_to_unixe($invocant->ubi_to_unixs($invocant->unixs_to_ubi($invocant->unixe_to_ntpe(1366280917)))), 1366280917, 'Test "'.$T.'" BADASS 01'); - - ## - # Test the duration conversions - ## - - is($invocant->duration_to_string(1.3568), '1.3568s', 'Test duration_to_string "'.$T.':01'); - is($invocant->duration_to_string(12.3568), '12.3568s', 'Test duration_to_string "'.$T.':02'); - is($invocant->duration_to_string(112.3568), '1m 52s', 'Test duration_to_string "'.$T.':03'); - is($invocant->duration_to_string(1112.3568), '18m 32s', 'Test duration_to_string "'.$T.':04'); - is($invocant->duration_to_string(11112.3568), '3h 5m 12s', 'Test duration_to_string "'.$T.':05'); - is($invocant->duration_to_string(111112.3568), '1d 6h 51m 52s', 'Test duration_to_string "'.$T.':06'); - is($invocant->duration_to_string(1111112.3568), '12d 20h 38m 32s', 'Test duration_to_string "'.$T.':07'); - is($invocant->duration_to_string(11111112.3568), '128d 14h 25m 12s', 'Test duration_to_string "'.$T.':08'); - is($invocant->duration_to_string(111111112.3568), '1286d 11m 52s', 'Test duration_to_string "'.$T.':09'); - is($invocant->duration_to_string(1111111112.3568), '12860d 1h 58m 32s', 'Test duration_to_string "'.$T.':10'); - - is($invocant->string_to_duration('1.3568s'), 1.3568, 'Test string_to_duration "'.$T.':01'); - is($invocant->string_to_duration('12.3568s'), 12.3568, 'Test string_to_duration "'.$T.':02'); - is($invocant->string_to_duration('1m 52s'), 112, 'Test string_to_duration "'.$T.':03'); - is($invocant->string_to_duration('18m 32s'), 1112, 'Test string_to_duration "'.$T.':04'); - is($invocant->string_to_duration('3h 5m 12s'), 11112, 'Test string_to_duration "'.$T.':05'); - is($invocant->string_to_duration('1d 6h 51m 52s'), 111112, 'Test string_to_duration "'.$T.':06'); - is($invocant->string_to_duration('12d 20h 38m 32s'), 1111112, 'Test string_to_duration "'.$T.':07'); - is($invocant->string_to_duration('128d 14h 25m 12s'), 11111112, 'Test string_to_duration "'.$T.':08'); - is($invocant->string_to_duration('1286d 11m 52s'), 111111112, 'Test string_to_duration "'.$T.':09'); - is($invocant->string_to_duration('12860d 1h 58m 32s'), 1111111112, 'Test string_to_duration "'.$T.':10'); - - ## - # Test the array conversions - ## - - is_deeply($invocant->list_to_array('1,2,3,4'), [1,2,3,4], 'Test "'.$T.'" "list"-"array" pair A01'); - is($invocant->array_to_list([1,2,3,4]), '1,2,3,4', 'Test "'.$T.'" "list"-"array" pair A02'); - - ## - # Test the IPv6 CIDR conversions - ## - - is($invocant->bigints_to_ipv6cidr($invocant->ipv6cidr_to_bigints("::1/128")), "::1/128", 'Test "'.$T.'" "ipv6cidr"-"bigints" pair A01'); - is($invocant->bigints_to_ipv6cidr($invocant->ipv6cidr_to_bigints("2001:718:1:6::/64")), "2001:718:1:6::/64", 'Test "'.$T.'" "ipv6cidr"-"bigints" pair A02'); - - is($invocant->bins_to_ipv6cidr($invocant->ipv6cidr_to_bins("::1/128")), "::1/128", 'Test "'.$T.'" "ipv6cidr"-"bins" pair A01'); - is($invocant->bins_to_ipv6cidr($invocant->ipv6cidr_to_bins("2001:718:1:6::/64")), "2001:718:1:6::/64", 'Test "'.$T.'" "ipv6cidr"-"bins" pair A02'); -} diff --git a/lib_perl/tests/unit/t/Value.Duration.t b/lib_perl/tests/unit/t/Value.Duration.t deleted file mode 100644 index 833e8e14b66c41464a99e88e8d03ecfa949f8850..0000000000000000000000000000000000000000 --- a/lib_perl/tests/unit/t/Value.Duration.t +++ /dev/null @@ -1,137 +0,0 @@ -#!/usr/bin/perl -T - -use strict; -use warnings; - -#******************************************************************************* -# Value::Duration module/class tests -# -# Author: Jan Mach, jan.mach@cesnet.cz -# Version: 0.1 -# Purpose: -# -#******************************************************************************* - -use Data::Dumper; -#use Smart::Comments; - -use Test::More tests => 70; - -# First test if the module correctly compiles -BEGIN { - use vars qw($TESTED_CLASS); - $TESTED_CLASS = 'Value::Duration'; - - use_ok('Tester'); - use_ok('Value::Convertor'); - use_ok($TESTED_CLASS); - } - -# Debug output explicit ON switch -#Tester::DEBUG_ON(); - -# Debug output explicit OFF switch -#Tester::DEBUG_OFF(); - -# User should know, which version is beeing tested (just for sure) -diag("$TESTED_CLASS version: " . $Value::Duration::VERSION) if Tester::D(); - -# Now attempt to create a class instance and check it -my $instance1 = $TESTED_CLASS->new('1w 5d 20h 38m 32s'); -isa_ok($instance1, $TESTED_CLASS); - -# View the created instance -diag("Instance dump 01: " . Dumper($instance1)) if Tester::D(); - -#------------------------------------------------------------------------------- -# The object internally uses Value::Convertor::datetime_to_nbi conversion, so we should -# test that it accepts all possible value types: -my %TSs = ( - 'A' => { - 'str' => '12.3568s', - 'num' => 12.3568, - }, - 'B' => { - 'str' => '1d 6h 51m 52s', - 'num' => 111112, - }, - ); - -my $instance_a = $TESTED_CLASS->new($TSs{'A'}->{'str'}); -my $instance_b = $TESTED_CLASS->new($TSs{'B'}->{'num'}); - -isa_ok($instance_a, $TESTED_CLASS); -is($instance_a->to_numeric(), $TSs{'A'}->{'num'}, "Instance 'A':a test 01"); -is($instance_a->to_string(), $TSs{'A'}->{'str'}, "Instance 'A':a test 02"); -is($instance_a->TO_JSON(), $TSs{'A'}->{'str'}, "Instance 'A':a test 03"); -is("$instance_a", $TSs{'A'}->{'str'}, "Instance 'A':a test 04"); - -isa_ok($instance_b, $TESTED_CLASS); -is($instance_b->to_numeric(), $TSs{'B'}->{'num'}, "Instance 'B':b test 01"); -is($instance_b->to_string(), $TSs{'B'}->{'str'}, "Instance 'B':b test 02"); -is($instance_b->TO_JSON(), $TSs{'B'}->{'str'}, "Instance 'B':b test 03"); -is("$instance_b", $TSs{'B'}->{'str'}, "Instance 'B':b test 04"); - - -#------------------------------------------------------------------------------- -# Test the comparison functions - -is($instance_a < $instance_b, 1, 'Comparison test 01'); -is($instance_a > $instance_b, '', 'Comparison test 02'); -is($instance_a <= $instance_b, 1, 'Comparison test 03'); -is($instance_a >= $instance_b, '', 'Comparison test 04'); -is($instance_a == $instance_b, '', 'Comparison test 05'); -is($instance_a != $instance_b, 1, 'Comparison test 06'); -is($instance_a <=> $instance_b, -1, 'Comparison test 07'); -is($instance_a lt $instance_b, 1, 'Comparison test 08'); -is($instance_a gt $instance_b, '', 'Comparison test 09'); -is($instance_a le $instance_b, 1, 'Comparison test 10'); -is($instance_a ge $instance_b, '', 'Comparison test 11'); -is($instance_a eq $instance_b, '', 'Comparison test 12'); -is($instance_a ne $instance_b, 1, 'Comparison test 13'); -is($instance_a cmp $instance_b, -1, 'Comparison test 14'); - -is($instance_b < $instance_a, '', 'Comparison test 15'); -is($instance_b > $instance_a, 1, 'Comparison test 16'); -is($instance_b <= $instance_a, '', 'Comparison test 17'); -is($instance_b >= $instance_a, 1, 'Comparison test 18'); -is($instance_b == $instance_a, '', 'Comparison test 19'); -is($instance_b != $instance_a, 1, 'Comparison test 20'); -is($instance_b <=> $instance_a, 1, 'Comparison test 21'); -is($instance_b lt $instance_a, '', 'Comparison test 22'); -is($instance_b gt $instance_a, 1, 'Comparison test 23'); -is($instance_b le $instance_a, '', 'Comparison test 24'); -is($instance_b ge $instance_a, 1, 'Comparison test 25'); -is($instance_b eq $instance_a, '', 'Comparison test 26'); -is($instance_b ne $instance_a, 1, 'Comparison test 27'); -is($instance_b cmp $instance_a, 1, 'Comparison test 28'); - -is($instance_b < '1d 6h 50m 52s', '', 'Comparison test 29'); -is($instance_b > '1d 6h 50m 52s', 1, 'Comparison test 30'); -is($instance_b <= '1d 6h 50m 52s', '', 'Comparison test 31'); -is($instance_b >= '1d 6h 50m 52s', 1, 'Comparison test 32'); -is($instance_b == '1d 6h 50m 52s', '', 'Comparison test 33'); -is($instance_b != '1d 6h 50m 52s', 1, 'Comparison test 34'); -is($instance_b <=> '1d 6h 50m 52s', 1, 'Comparison test 35'); -is($instance_b lt '1d 6h 50m 52s', '', 'Comparison test 36'); -is($instance_b gt '1d 6h 50m 52s', 1, 'Comparison test 37'); -is($instance_b le '1d 6h 50m 52s', '', 'Comparison test 38'); -is($instance_b ge '1d 6h 50m 52s', 1, 'Comparison test 39'); -is($instance_b eq '1d 6h 50m 52s', '', 'Comparison test 40'); -is($instance_b ne '1d 6h 50m 52s', 1, 'Comparison test 41'); -is($instance_b cmp '1d 6h 50m 52s', 1, 'Comparison test 42'); - -is('1d 6h 50m 52s' < $instance_b, 1, 'Comparison test 43'); -is('1d 6h 50m 52s' > $instance_b, '', 'Comparison test 44'); -is('1d 6h 50m 52s' <= $instance_b, 1, 'Comparison test 45'); -is('1d 6h 50m 52s' >= $instance_b, '', 'Comparison test 45'); -is('1d 6h 50m 52s' == $instance_b, '', 'Comparison test 47'); -is('1d 6h 50m 52s' != $instance_b, 1, 'Comparison test 48'); -is('1d 6h 50m 52s' <=> $instance_b, -1, 'Comparison test 49'); -is('1d 6h 50m 52s' lt $instance_b, 1, 'Comparison test 50'); -is('1d 6h 50m 52s' gt $instance_b, '', 'Comparison test 51'); -is('1d 6h 50m 52s' le $instance_b, 1, 'Comparison test 52'); -is('1d 6h 50m 52s' ge $instance_b, '', 'Comparison test 53'); -is('1d 6h 50m 52s' eq $instance_b, '', 'Comparison test 54'); -is('1d 6h 50m 52s' ne $instance_b, 1, 'Comparison test 55'); -is('1d 6h 50m 52s' cmp $instance_b, -1, 'Comparison test 56'); diff --git a/lib_perl/tests/unit/t/Value.IP.t b/lib_perl/tests/unit/t/Value.IP.t deleted file mode 100644 index 49468a5e4160a16709a01b4e7cf12847c055e4e0..0000000000000000000000000000000000000000 --- a/lib_perl/tests/unit/t/Value.IP.t +++ /dev/null @@ -1,80 +0,0 @@ -#!/usr/bin/perl -T - -use strict; -use warnings; - -#******************************************************************************* -# Value::IP module/class tests -# -# Author: Jan Mach, jan.mach@cesnet.cz -# Version: 0.1 -# Purpose: -# -#******************************************************************************* - -use Data::Dumper; -#use Smart::Comments; - -use Test::More tests => 47; - -# First test if the module correctly compiles -BEGIN { - use vars qw($TESTED_CLASS); - $TESTED_CLASS = 'Value::IP'; - - use_ok('Tester'); - use_ok('Value::Convertor'); - use_ok($TESTED_CLASS); - } - -# Debug output explicit ON switch -#Tester::DEBUG_ON(); - -# Debug output explicit OFF switch -#Tester::DEBUG_OFF(); - -# User should know, which version is beeing tested (just for sure) -diag("$TESTED_CLASS version: " . $Value::IP::VERSION) if Tester::D(); - -# Define all IP addresses to be tested -my @IPS = ( - ['195.113.144.194', 'Value::IPv4ADDR', '195.113.144.194'], - ['C37190C2', 'Value::IPv4ADDR', '195.113.144.194'], - [3278999746, 'Value::IPv4ADDR', '195.113.144.194'], - ['195.113.144.194/32', 'Value::IPv4CIDR', '195.113.144.194/32'], - ['195.113.144.194-195.113.144.244', 'Value::IPv4RNG', '195.113.144.194..195.113.144.244'], - ['195.113.144.194..195.113.144.244', 'Value::IPv4RNG', '195.113.144.194..195.113.144.244'], - ['195.113.144.194 - 195.113.144.244', 'Value::IPv4RNG', '195.113.144.194..195.113.144.244'], - ['195.113.144.194 .. 195.113.144.244', 'Value::IPv4RNG', '195.113.144.194..195.113.144.244'], - ['192.168.0.0/255.255.255.0', 'Value::IPv4NETM', '192.168.0.0/255.255.255.0'], - ['2001:718:1:1::2', 'Value::IPv6ADDR', '2001:718:1:1::2'], - ); - -my $instance; -foreach my $IP (@IPS) -{ - $instance = $TESTED_CLASS->new($IP->[0]); - isa_ok($instance, $IP->[1]); - is($instance->to_string(), $IP->[2], "Instance $IP->[0] test 01"); - is($instance->TO_JSON(), $IP->[2], "Instance $IP->[0] test 02"); - is("$instance", $IP->[2], "Instance $IP->[0] test 03"); - - diag("Instance $IP->[1] dump: " . Dumper($instance)) if Tester::D(); -} - -$instance = $TESTED_CLASS->new('195.113.144.194'); -my $t1 = Value::Convertor->ip_to_int('195.113.144.194'); -my $t2 = Value::Convertor->ip_to_bin('195.113.144.194'); -is(Value::Convertor->ip_to_int($instance), $t1, 'Convertor conversion test 01'); -is(Value::Convertor->ip_to_bin($instance), $t2, 'Convertor conversion test 02'); - -# Perform some comparison tests -my @CTESTS = ( - ['195.113.144.194', '195.113.144.194'], - ['195.113.144.194', '195.113.144.0/24'], -); -for my $tc (@CTESTS) { - my $ic1 = $TESTED_CLASS->new($tc->[0]); - my $ic2 = $TESTED_CLASS->new($tc->[1]); - ok($ic1 == $ic2, "Comparison '$tc->[0]' == '$tc->[1]'") -} diff --git a/lib_perl/tests/unit/t/Value.IPv4ADDR.t b/lib_perl/tests/unit/t/Value.IPv4ADDR.t deleted file mode 100644 index 52de75ad5afd7c30216de6827267c802ee0b66bf..0000000000000000000000000000000000000000 --- a/lib_perl/tests/unit/t/Value.IPv4ADDR.t +++ /dev/null @@ -1,184 +0,0 @@ -#!/usr/bin/perl -T - -use strict; -use warnings; - -#******************************************************************************* -# Value::IPv4ADDR module/class tests -# -# Author: Jan Mach, jan.mach@cesnet.cz -# Version: 0.1 -# Purpose: -# -#******************************************************************************* - -use Data::Dumper; -#use Smart::Comments; - -use Test::More tests => 159; - -# First test if the module correctly compiles -BEGIN { - use vars qw($TESTED_CLASS); - $TESTED_CLASS = 'Value::IPv4ADDR'; - - use_ok('Tester'); - use_ok('Value::Convertor'); - use_ok($TESTED_CLASS); - } - -# Debug output explicit ON switch -#Tester::DEBUG_ON(); - -# Debug output explicit OFF switch -#Tester::DEBUG_OFF(); - -# User should know, which version is beeing tested (just for sure) -diag("$TESTED_CLASS version: " . $Value::IPv4ADDR::VERSION) if Tester::D(); - -#------------------------------------------------------------------------------- -# The object internally uses Value::Convertor::ipv4_to_int conversion, so we should -# test that it accepts all possible value types: -my %IPV4s = ( - 'A' => { - 'str' => '195.113.144.194', - 'hexstr' => 'C37190C2', - 'int' => 3278999746, - }, - 'B' => { - 'str' => '0.0.0.0', - 'hexstr' => '00000000', - 'int' => 0, - }, - 'C' => { - 'str' => '255.255.255.255', - 'hexstr' => 'FFFFFFFF', - 'int' => 4294967295, - }, - 'D' => { - 'str' => '192.168.0.0', - 'hexstr' => 'C0A80000', - 'int' => 3232235520, - }, - 'E' => { - 'str' => '192.168.0.255', - 'hexstr' => 'C0A800FF', - 'int' => 3232235775, - }, - 'F' => { - 'str' => '255.255.255.0', - 'hexstr' => 'FFFFFF00', - 'int' => 4294967040, - }, - ); - -my $instance_a; -my $instance_b; -my $instance_c; -foreach my $IP (sort keys(%IPV4s)) -{ - $instance_a = $TESTED_CLASS->new($IPV4s{$IP}->{'str'}); - isa_ok($instance_a, $TESTED_CLASS); - is($instance_a->to_numeric(), $IPV4s{$IP}->{'int'}, "Instance $IP:a test 01"); - is($instance_a->to_string(), $IPV4s{$IP}->{'str'}, "Instance $IP:a test 02"); - is($instance_a->TO_JSON(), $IPV4s{$IP}->{'str'}, "Instance $IP:a test 03"); - is("$instance_a", $IPV4s{$IP}->{'str'}, "Instance $IP:a test 04"); - - $instance_b = $TESTED_CLASS->new($IPV4s{$IP}->{'hexstr'}); - isa_ok($instance_b, $TESTED_CLASS); - is($instance_b->to_numeric(), $IPV4s{$IP}->{'int'}, "Instance $IP:b test 01"); - is($instance_b->to_string(), $IPV4s{$IP}->{'str'}, "Instance $IP:b test 02"); - is($instance_b->TO_JSON(), $IPV4s{$IP}->{'str'}, "Instance $IP:b test 03"); - is("$instance_b", $IPV4s{$IP}->{'str'}, "Instance $IP:b test 04"); - - $instance_c = $TESTED_CLASS->new($IPV4s{$IP}->{'int'}); - isa_ok($instance_c, $TESTED_CLASS); - is($instance_c->to_numeric(), $IPV4s{$IP}->{'int'}, "Instance $IP:c test 01"); - is($instance_c->to_string(), $IPV4s{$IP}->{'str'}, "Instance $IP:c test 02"); - is($instance_c->TO_JSON(), $IPV4s{$IP}->{'str'}, "Instance $IP:c test 03"); - is("$instance_c", $IPV4s{$IP}->{'str'}, "Instance $IP:c test 04"); -} - -#------------------------------------------------------------------------------- -# Create couple of other instances and test the comparison functions -my $instance1 = $TESTED_CLASS->new('195.113.144.194'); -isa_ok($instance1, $TESTED_CLASS); - -# View the created instance -diag("Instance dump 01: " . Dumper($instance1)) if Tester::D(); - -is($instance1->to_numeric(), 3278999746, 'Instance 1 test 01'); -is($instance1->to_string(), '195.113.144.194', 'Instance 1 test 02'); -is($instance1->TO_JSON(), '195.113.144.194', 'Instance 1 test 03'); -is("$instance1", '195.113.144.194', 'Instance 1 test 04'); - -my $instance2 = $TESTED_CLASS->new('195.113.144.244'); -isa_ok($instance2, $TESTED_CLASS); - -# View the created instance -diag("Instance dump 02: " . Dumper($instance2)) if Tester::D(); - -is($instance2->to_numeric(), 3278999796, 'Instance 2 test 01'); -is($instance2->to_string(), '195.113.144.244', 'Instance 2 test 02'); -is($instance2->TO_JSON(), '195.113.144.244', 'Instance 2 test 03'); -is("$instance2", '195.113.144.244', 'Instance 2 test 04'); - -is($instance1 < $instance2, 1, 'Comparison test 01'); -is($instance1 > $instance2, '', 'Comparison test 02'); -is($instance1 <= $instance2, 1, 'Comparison test 03'); -is($instance1 >= $instance2, '', 'Comparison test 04'); -is($instance1 == $instance2, '', 'Comparison test 05'); -is($instance1 != $instance2, 1, 'Comparison test 06'); -is($instance1 <=> $instance2, -1, 'Comparison test 07'); -is($instance1 lt $instance2, 1, 'Comparison test 08'); -is($instance1 gt $instance2, '', 'Comparison test 09'); -is($instance1 le $instance2, 1, 'Comparison test 10'); -is($instance1 ge $instance2, '', 'Comparison test 11'); -is($instance1 eq $instance2, '', 'Comparison test 12'); -is($instance1 ne $instance2, 1, 'Comparison test 13'); -is($instance1 cmp $instance2, -1, 'Comparison test 14'); - -is($instance2 < $instance1, '', 'Comparison test 15'); -is($instance2 > $instance1, 1, 'Comparison test 16'); -is($instance2 <= $instance1, '', 'Comparison test 17'); -is($instance2 >= $instance1, 1, 'Comparison test 18'); -is($instance2 == $instance1, '', 'Comparison test 19'); -is($instance2 != $instance1, 1, 'Comparison test 20'); -is($instance2 <=> $instance1, 1, 'Comparison test 21'); -is($instance2 lt $instance1, '', 'Comparison test 22'); -is($instance2 gt $instance1, 1, 'Comparison test 23'); -is($instance2 le $instance1, '', 'Comparison test 24'); -is($instance2 ge $instance1, 1, 'Comparison test 25'); -is($instance2 eq $instance1, '', 'Comparison test 26'); -is($instance2 ne $instance1, 1, 'Comparison test 27'); -is($instance2 cmp $instance1, 1, 'Comparison test 28'); - -is($instance2 < 3278999746, '', 'Comparison test 29'); -is($instance2 > '195.113.144.194', 1, 'Comparison test 30'); -is($instance2 <= 'c37190c2', '', 'Comparison test 31'); -is($instance2 >= '195.113.144.194', 1, 'Comparison test 32'); -is($instance2 == 3278999746, '', 'Comparison test 33'); -is($instance2 != '195.113.144.194', 1, 'Comparison test 34'); -is($instance2 <=> 'c37190c2', 1, 'Comparison test 35'); -is($instance2 lt '195.113.144.194', '', 'Comparison test 36'); -is($instance2 gt 3278999746, 1, 'Comparison test 37'); -is($instance2 le '195.113.144.194', '', 'Comparison test 38'); -is($instance2 ge 'c37190c2', 1, 'Comparison test 39'); -is($instance2 eq '195.113.144.194', '', 'Comparison test 40'); -is($instance2 ne 3278999746, 1, 'Comparison test 41'); -is($instance2 cmp '195.113.144.194', 1, 'Comparison test 42'); - -is(3278999746 < $instance2, 1, 'Comparison test 43'); -is('195.113.144.194' > $instance2, '', 'Comparison test 44'); -is('c37190c2' <= $instance2, 1, 'Comparison test 45'); -is('195.113.144.194' >= $instance2, '', 'Comparison test 45'); -is(3278999746 == $instance2, '', 'Comparison test 47'); -is('195.113.144.194' != $instance2, 1, 'Comparison test 48'); -is('c37190c2' <=> $instance2, -1, 'Comparison test 49'); -is('195.113.144.194' lt $instance2, 1, 'Comparison test 50'); -is(3278999746 gt $instance2, '', 'Comparison test 51'); -is('195.113.144.194' le $instance2, 1, 'Comparison test 52'); -is('c37190c2' ge $instance2, '', 'Comparison test 53'); -is('195.113.144.194' eq $instance2, '', 'Comparison test 54'); -is(3278999746 ne $instance2, 1, 'Comparison test 55'); -is('195.113.144.194' cmp $instance2, -1, 'Comparison test 56'); diff --git a/lib_perl/tests/unit/t/Value.IPv4CIDR.t b/lib_perl/tests/unit/t/Value.IPv4CIDR.t deleted file mode 100644 index 60eea7db158747cc313fb5aa2cba63f18e70b5bc..0000000000000000000000000000000000000000 --- a/lib_perl/tests/unit/t/Value.IPv4CIDR.t +++ /dev/null @@ -1,99 +0,0 @@ -#!/usr/bin/perl -T - -use strict; -use warnings; - -#******************************************************************************* -# Value::IPv4CIDR module/class tests -# -# Author: Jan Mach, jan.mach@cesnet.cz -# Version: 0.1 -# Purpose: -# -#******************************************************************************* - -use Data::Dumper; -#use Smart::Comments; - -use Test::More tests => 38; - -# First test if the module correctly compiles -BEGIN { - use vars qw($TESTED_CLASS); - $TESTED_CLASS = 'Value::IPv4CIDR'; - - use_ok('Tester'); - use_ok('Value::Convertor'); - use_ok($TESTED_CLASS); - use_ok('Value::IPv4ADDR'); - } - -# Debug output explicit ON switch -#Tester::DEBUG_ON(); - -# Debug output explicit OFF switch -#Tester::DEBUG_OFF(); - -# User should know, which version is beeing tested (just for sure) -diag("$TESTED_CLASS version: " . $Value::IPv4CIDR::VERSION) if Tester::D(); - -# Now attempt to create a class instance and check it -my $instance1 = $TESTED_CLASS->new('195.113.144.194'); -isa_ok($instance1, $TESTED_CLASS); - -# View the created instance -diag("Instance dump 01: " . Dumper($instance1)) if Tester::D(); - -is_deeply([$instance1->to_numeric()], [3278999746,3278999746], 'Instance 1 test 01'); -is($instance1->to_string(), '195.113.144.194/32', 'Instance 1 test 02'); -is($instance1->TO_JSON(), '195.113.144.194/32', 'Instance 1 test 03'); -is("$instance1", '195.113.144.194/32', 'Instance 1 test 04'); - -my $instance2 = $TESTED_CLASS->new('195.113.144.244/32'); -isa_ok($instance2, $TESTED_CLASS); - -# View the created instance -diag("Instance dump 02: " . Dumper($instance2)) if Tester::D(); - -is_deeply([$instance2->to_numeric()], [3278999796,3278999796], 'Instance 2 test 01'); -is($instance2->to_string(), '195.113.144.244/32', 'Instance 2 test 02'); -is($instance2->TO_JSON(), '195.113.144.244/32', 'Instance 2 test 03'); -is("$instance2", '195.113.144.244/32', 'Instance 2 test 04'); - -my $instance3 = $TESTED_CLASS->new('192.168.0.0/24'); -isa_ok($instance3, $TESTED_CLASS); - -# View the created instance -diag("Instance dump 03: " . Dumper($instance3)) if Tester::D(); - -is_deeply([$instance3->to_numeric()], [3232235520,3232235775], 'Instance 3 test 01'); -is($instance3->to_string(), '192.168.0.0/24', 'Instance 3 test 02'); -is($instance3->TO_JSON(), '192.168.0.0/24', 'Instance 3 test 03'); -is("$instance3", '192.168.0.0/24', 'Instance 3 test 04'); - -is($instance3 == '192.168.0.1', 1, 'Comparison test 01'); -is($instance3 == '192.168.1.1', '', 'Comparison test 02'); -is($instance3 != '192.168.0.1', '', 'Comparison test 03'); -is($instance3 != '192.168.1.1', 1, 'Comparison test 04'); - -is('192.168.0.1' == $instance3, 1, 'Comparison test 05'); -is('192.168.1.1' == $instance3, '', 'Comparison test 06'); -is('192.168.0.1' != $instance3, '', 'Comparison test 07'); -is('192.168.1.1' != $instance3, 1, 'Comparison test 08'); - -is($instance3 < '192.168.0.1/32', '', 'Comparison test 09'); -is($instance3 <= '192.168.0.1/32', '', 'Comparison test 10'); -is($instance3 > '192.168.0.1/32', 1, 'Comparison test 11'); -is($instance3 >= '192.168.0.1/32', 1, 'Comparison test 12'); - -is('192.168.0.1/32' < $instance3, 1, 'Comparison test 11'); -is('192.168.0.1/32' <= $instance3, 1, 'Comparison test 12'); -is('192.168.0.1/32' > $instance3, '', 'Comparison test 13'); -is('192.168.0.1/32' >= $instance3, '', 'Comparison test 14'); - -my $instancex = $TESTED_CLASS->new('78.128.160.0/19'); -is($instancex == '78.128.186.125', 1, 'Comparison test 15'); - -my $instancey = Value::IPv4ADDR->new('78.128.186.125'); -is($instancex == $instancey, 1, 'Comparison test 16'); -is($instancey == $instancex, 1, 'Comparison test 17'); diff --git a/lib_perl/tests/unit/t/Value.IPv4NETM.t b/lib_perl/tests/unit/t/Value.IPv4NETM.t deleted file mode 100644 index 0d1760549d058dde2a694c60bbe4449b475f2509..0000000000000000000000000000000000000000 --- a/lib_perl/tests/unit/t/Value.IPv4NETM.t +++ /dev/null @@ -1,81 +0,0 @@ -#!/usr/bin/perl -T - -use strict; -use warnings; - -#******************************************************************************* -# Value::IPv4NETM module/class tests -# -# Author: Jan Mach, jan.mach@cesnet.cz -# Version: 0.1 -# Purpose: -# -#******************************************************************************* - -use Data::Dumper; -#use Smart::Comments; - -use Test::More tests => 29; - -# First test if the module correctly compiles -BEGIN { - use vars qw($TESTED_CLASS); - $TESTED_CLASS = 'Value::IPv4NETM'; - - use_ok('Tester'); - use_ok('Value::Convertor'); - use_ok($TESTED_CLASS); - } - -# Debug output explicit ON switch -#Tester::DEBUG_ON(); - -# Debug output explicit OFF switch -#Tester::DEBUG_OFF(); - -# User should know, which version is beeing tested (just for sure) -diag("$TESTED_CLASS version: " . $Value::IPv4NETM::VERSION) if Tester::D(); - -# Now attempt to create a class instance and check it -my $instance1 = $TESTED_CLASS->new('192.168.0.0/255.255.255.0'); -isa_ok($instance1, $TESTED_CLASS); - -# View the created instance -diag("Instance dump 01: " . Dumper($instance1)) if Tester::D(); - -is_deeply([$instance1->to_numeric()], [3232235520,3232235775], 'Instance 1 test 01'); -is($instance1->to_string(), '192.168.0.0/255.255.255.0', 'Instance 1 test 02'); -is($instance1->TO_JSON(), '192.168.0.0/255.255.255.0', 'Instance 1 test 03'); -is("$instance1", '192.168.0.0/255.255.255.0', 'Instance 1 test 04'); - -# Now attempt to create a class instance and check it -my $instance2 = $TESTED_CLASS->new('192.168.1.0/255.255.255.0'); -isa_ok($instance2, $TESTED_CLASS); - -# View the created instance -diag("Instance dump 02: " . Dumper($instance2)) if Tester::D(); - -is_deeply([$instance2->to_numeric()], [3232235776,3232236031], 'Instance 1 test 01'); -is($instance2->to_string(), '192.168.1.0/255.255.255.0', 'Instance 1 test 02'); -is($instance2->TO_JSON(), '192.168.1.0/255.255.255.0', 'Instance 1 test 03'); -is("$instance2", '192.168.1.0/255.255.255.0', 'Instance 1 test 04'); - -is($instance1 == '192.168.0.1', 1, 'Comparison test 01'); -is($instance1 == '192.168.1.1', '', 'Comparison test 02'); -is($instance1 != '192.168.0.1', '', 'Comparison test 03'); -is($instance1 != '192.168.1.1', 1, 'Comparison test 04'); - -is('192.168.0.1' == $instance1, 1, 'Comparison test 05'); -is('192.168.1.1' == $instance1, '', 'Comparison test 06'); -is('192.168.0.1' != $instance1, '', 'Comparison test 07'); -is('192.168.1.1' != $instance1, 1, 'Comparison test 08'); - -is($instance1 < '192.168.0.1/32', '', 'Comparison test 09'); -is($instance1 <= '192.168.0.1/32', '', 'Comparison test 10'); -is($instance1 > '192.168.0.1/32', 1, 'Comparison test 11'); -is($instance1 >= '192.168.0.1/32', 1, 'Comparison test 12'); - -is('192.168.0.1/32' < $instance1, 1, 'Comparison test 11'); -is('192.168.0.1/32' <= $instance1, 1, 'Comparison test 12'); -is('192.168.0.1/32' > $instance1, '', 'Comparison test 13'); -is('192.168.0.1/32' >= $instance1, '', 'Comparison test 14'); diff --git a/lib_perl/tests/unit/t/Value.IPv4RNG.t b/lib_perl/tests/unit/t/Value.IPv4RNG.t deleted file mode 100644 index a8056560b0a4b9bffc8ab7869673e4538dadbd7c..0000000000000000000000000000000000000000 --- a/lib_perl/tests/unit/t/Value.IPv4RNG.t +++ /dev/null @@ -1,91 +0,0 @@ -#!/usr/bin/perl -T - -use strict; -use warnings; - -#******************************************************************************* -# Value::IPv4RNG module/class tests -# -# Author: Jan Mach, jan.mach@cesnet.cz -# Version: 0.1 -# Purpose: -# -#******************************************************************************* - -use Data::Dumper; -#use Smart::Comments; - -use Test::More tests => 34; - -# First test if the module correctly compiles -BEGIN { - use vars qw($TESTED_CLASS); - $TESTED_CLASS = 'Value::IPv4RNG'; - - use_ok('Tester'); - use_ok('Value::Convertor'); - use_ok($TESTED_CLASS); - } - -# Debug output explicit ON switch -#Tester::DEBUG_ON(); - -# Debug output explicit OFF switch -#Tester::DEBUG_OFF(); - -# User should know, which version is beeing tested (just for sure) -diag("$TESTED_CLASS version: " . $Value::IPv4RNG::VERSION) if Tester::D(); - -# Now attempt to create a class instance and check it -my $instance1 = $TESTED_CLASS->new('195.113.144.194'); -isa_ok($instance1, $TESTED_CLASS); - -# View the created instance -diag("Instance dump 01: " . Dumper($instance1)) if Tester::D(); - -is_deeply([$instance1->to_numeric()], [3278999746,3278999746], 'Instance 1 test 01'); -is($instance1->to_string(), '195.113.144.194..195.113.144.194', 'Instance 1 test 02'); -is($instance1->TO_JSON(), '195.113.144.194..195.113.144.194', 'Instance 1 test 03'); -is("$instance1", '195.113.144.194..195.113.144.194', 'Instance 1 test 04'); - -my $instance2 = $TESTED_CLASS->new('195.113.144.244/32'); -isa_ok($instance2, $TESTED_CLASS); - -# View the created instance -diag("Instance dump 02: " . Dumper($instance2)) if Tester::D(); - -is_deeply([$instance2->to_numeric()], [3278999796,3278999796], 'Instance 2 test 01'); -is($instance2->to_string(), '195.113.144.244..195.113.144.244', 'Instance 2 test 02'); -is($instance2->TO_JSON(), '195.113.144.244..195.113.144.244', 'Instance 2 test 03'); -is("$instance2", '195.113.144.244..195.113.144.244', 'Instance 2 test 04'); - -my $instance3 = $TESTED_CLASS->new('192.168.0.0/24'); -isa_ok($instance3, $TESTED_CLASS); - -# View the created instance -diag("Instance dump 03: " . Dumper($instance3)) if Tester::D(); - -is_deeply([$instance3->to_numeric()], [3232235520,3232235775], 'Instance 3 test 01'); -is($instance3->to_string(), '192.168.0.0..192.168.0.255', 'Instance 3 test 02'); -is($instance3->TO_JSON(), '192.168.0.0..192.168.0.255', 'Instance 3 test 03'); -is("$instance3", '192.168.0.0..192.168.0.255', 'Instance 3 test 04'); - -is($instance3 == '192.168.0.1', 1, 'Comparison test 01'); -is($instance3 == '192.168.1.1', '', 'Comparison test 02'); -is($instance3 != '192.168.0.1', '', 'Comparison test 03'); -is($instance3 != '192.168.1.1', 1, 'Comparison test 04'); - -is('192.168.0.1' == $instance3, 1, 'Comparison test 05'); -is('192.168.1.1' == $instance3, '', 'Comparison test 06'); -is('192.168.0.1' != $instance3, '', 'Comparison test 07'); -is('192.168.1.1' != $instance3, 1, 'Comparison test 08'); - -is($instance3 < '192.168.0.1/32', '', 'Comparison test 09'); -is($instance3 <= '192.168.0.1/32', '', 'Comparison test 10'); -is($instance3 > '192.168.0.1/32', 1, 'Comparison test 11'); -is($instance3 >= '192.168.0.1/32', 1, 'Comparison test 12'); - -is('192.168.0.1/32' < $instance3, 1, 'Comparison test 13'); -is('192.168.0.1/32' <= $instance3, 1, 'Comparison test 14'); -is('192.168.0.1/32' > $instance3, '', 'Comparison test 15'); -is('192.168.0.1/32' >= $instance3, '', 'Comparison test 16'); diff --git a/lib_perl/tests/unit/t/Value.IPv6ADDR.t b/lib_perl/tests/unit/t/Value.IPv6ADDR.t deleted file mode 100644 index 3835b0dbbe295f260b36aff23a10692f1f5af711..0000000000000000000000000000000000000000 --- a/lib_perl/tests/unit/t/Value.IPv6ADDR.t +++ /dev/null @@ -1,127 +0,0 @@ -#!/usr/bin/perl -T - -use strict; -use warnings; - -#******************************************************************************* -# Value::IPv6ADDR module/class tests -# -# Author: Jan Mach, jan.mach@cesnet.cz -# Version: 0.1 -# Purpose: -# -#******************************************************************************* - -use Data::Dumper; -#use Smart::Comments; - -use Test::More tests => 69; - -# First test if the module correctly compiles -BEGIN { - use vars qw($TESTED_CLASS); - $TESTED_CLASS = 'Value::IPv6ADDR'; - - use_ok('Tester'); - use_ok('Value::Convertor'); - use_ok($TESTED_CLASS); - } - -# Debug output explicit ON switch -#Tester::DEBUG_ON(); - -# Debug output explicit OFF switch -#Tester::DEBUG_OFF(); - -# User should know, which version is beeing tested (just for sure) -diag("$TESTED_CLASS version: " . $Value::IPv6ADDR::VERSION) if Tester::D(); - -# Now attempt to create a class instance and check it -my $instance1 = $TESTED_CLASS->new('2001:718:1:1::2'); -isa_ok($instance1, $TESTED_CLASS); - -# View the created instance -diag("Instance dump 01: " . Dumper($instance1)) if Tester::D(); - -{ -use bigint; -is($instance1->to_numeric(), 42540632040320177608853785003998314498, 'Instance 1 test 01'); -is($instance1->to_string(), '2001:718:1:1::2', 'Instance 1 test 02'); -is($instance1->TO_JSON(), '2001:718:1:1::2', 'Instance 1 test 03'); -is("$instance1", '2001:718:1:1::2', 'Instance 1 test 04'); -} - -# Now attempt to create a class instance and check it -my $instance2 = $TESTED_CLASS->new('2001:718:1:1::55:5'); -isa_ok($instance2, $TESTED_CLASS); - -# View the created instance -diag("Instance dump 02: " . Dumper($instance2)) if Tester::D(); - -{ -use bigint; -is($instance2->to_numeric(), 42540632040320177608853785004003885061, 'Instance 2 test 01'); -is($instance2->to_string(), '2001:718:1:1::55:5', 'Instance 2 test 02'); -is($instance2->TO_JSON(), '2001:718:1:1::55:5', 'Instance 2 test 03'); -is("$instance2", '2001:718:1:1::55:5', 'Instance 2 test 04'); -} - -is($instance1 < $instance2, 1, 'Comparison test 01'); -is($instance1 > $instance2, '', 'Comparison test 02'); -is($instance1 <= $instance2, 1, 'Comparison test 03'); -is($instance1 >= $instance2, '', 'Comparison test 04'); -is($instance1 == $instance2, '', 'Comparison test 05'); -is($instance1 != $instance2, 1, 'Comparison test 06'); -is($instance1 <=> $instance2, -1, 'Comparison test 07'); -is($instance1 lt $instance2, 1, 'Comparison test 08'); -is($instance1 gt $instance2, '', 'Comparison test 09'); -is($instance1 le $instance2, 1, 'Comparison test 10'); -is($instance1 ge $instance2, '', 'Comparison test 11'); -is($instance1 eq $instance2, '', 'Comparison test 12'); -is($instance1 ne $instance2, 1, 'Comparison test 13'); -is($instance1 cmp $instance2, -1, 'Comparison test 14'); - -is($instance2 < $instance1, '', 'Comparison test 15'); -is($instance2 > $instance1, 1, 'Comparison test 16'); -is($instance2 <= $instance1, '', 'Comparison test 17'); -is($instance2 >= $instance1, 1, 'Comparison test 18'); -is($instance2 == $instance1, '', 'Comparison test 19'); -is($instance2 != $instance1, 1, 'Comparison test 20'); -is($instance2 <=> $instance1, 1, 'Comparison test 21'); -is($instance2 lt $instance1, '', 'Comparison test 22'); -is($instance2 gt $instance1, 1, 'Comparison test 23'); -is($instance2 le $instance1, '', 'Comparison test 24'); -is($instance2 ge $instance1, 1, 'Comparison test 25'); -is($instance2 eq $instance1, '', 'Comparison test 26'); -is($instance2 ne $instance1, 1, 'Comparison test 27'); -is($instance2 cmp $instance1, 1, 'Comparison test 28'); - -is($instance2 < '2001:718:1:1::2', '', 'Comparison test 29'); -is($instance2 > '2001:718:1:1::2', 1, 'Comparison test 30'); -is($instance2 <= '2001:718:1:1::2', '', 'Comparison test 31'); -is($instance2 >= '2001:718:1:1::2', 1, 'Comparison test 32'); -is($instance2 == '2001:718:1:1::2', '', 'Comparison test 33'); -is($instance2 != '2001:718:1:1::2', 1, 'Comparison test 34'); -is($instance2 <=> '2001:718:1:1::2', 1, 'Comparison test 35'); -is($instance2 lt '2001:718:1:1::2', '', 'Comparison test 36'); -is($instance2 gt '2001:718:1:1::2', 1, 'Comparison test 37'); -is($instance2 le '2001:718:1:1::2', '', 'Comparison test 38'); -is($instance2 ge '2001:718:1:1::2', 1, 'Comparison test 39'); -is($instance2 eq '2001:718:1:1::2', '', 'Comparison test 40'); -is($instance2 ne '2001:718:1:1::2', 1, 'Comparison test 41'); -is($instance2 cmp '2001:718:1:1::2', 1, 'Comparison test 42'); - -is('2001:718:1:1::2' < $instance2, 1, 'Comparison test 43'); -is('2001:718:1:1::2' > $instance2, '', 'Comparison test 44'); -is('2001:718:1:1::2' <= $instance2, 1, 'Comparison test 45'); -is('2001:718:1:1::2' >= $instance2, '', 'Comparison test 45'); -is('2001:718:1:1::2' == $instance2, '', 'Comparison test 47'); -is('2001:718:1:1::2' != $instance2, 1, 'Comparison test 48'); -is('2001:718:1:1::2' <=> $instance2, -1, 'Comparison test 49'); -is('2001:718:1:1::2' lt $instance2, 1, 'Comparison test 50'); -is('2001:718:1:1::2' gt $instance2, '', 'Comparison test 51'); -is('2001:718:1:1::2' le $instance2, 1, 'Comparison test 52'); -is('2001:718:1:1::2' ge $instance2, '', 'Comparison test 53'); -is('2001:718:1:1::2' eq $instance2, '', 'Comparison test 54'); -is('2001:718:1:1::2' ne $instance2, 1, 'Comparison test 55'); -is('2001:718:1:1::2' cmp $instance2, -1, 'Comparison test 56'); diff --git a/lib_perl/tests/unit/t/Value.Period.t b/lib_perl/tests/unit/t/Value.Period.t deleted file mode 100644 index eb80918b1f94111ebf0f5256fac7ed2d5eafa6ff..0000000000000000000000000000000000000000 --- a/lib_perl/tests/unit/t/Value.Period.t +++ /dev/null @@ -1,138 +0,0 @@ -#!/usr/bin/perl -T - -use strict; -use warnings; - -#******************************************************************************* -# Value::Period module/class tests -# -# Author: Jan Mach, jan.mach@cesnet.cz -# Version: 0.1 -# Purpose: -# -#******************************************************************************* - -use Data::Dumper; -#use Smart::Comments; - -use Test::More tests => 2072; - -# First test if the module correctly compiles -BEGIN { - use vars qw($TESTED_CLASS); - $TESTED_CLASS = 'Value::Period'; - - use_ok('Tester'); - use_ok('Value::Convertor'); - use_ok($TESTED_CLASS); - } - -# Debug output explicit ON switch -#Tester::DEBUG_ON(); - -# Debug output explicit OFF switch -#Tester::DEBUG_OFF(); - -# User should know, which version is beeing tested (just for sure) -diag("$TESTED_CLASS version: " . $Value::Period::VERSION) if Tester::D(); - -#------------------------------------------------------------------------------- -# Datetime strings for time period tests -my @DTsA = ( - ['2013-02-03 14:55', Math::BigInt->new(15328259390570496000)], - ['2013-02-03T14:55', Math::BigInt->new(15328259390570496000)], - ['2013-02-03 14:55Z', Math::BigInt->new(15328274852452761600)], - ['2013-02-03T14:55Z', Math::BigInt->new(15328274852452761600)], - ['2013-02-03 14:55:12', Math::BigInt->new(15328259442110103552)], - ['2013-02-03T14:55:12', Math::BigInt->new(15328259442110103552)], - ['2013-02-03 14:55:12Z', Math::BigInt->new(15328274903992369152)], - ['2013-02-03T14:55:12Z', Math::BigInt->new(15328274903992369152)], - ['2013-02-03 14:55+0100', Math::BigInt->new(15328259390570496000)], - ['2013-02-03T14:55+0100', Math::BigInt->new(15328259390570496000)], - ['2013-02-03 14:55:12+0100', Math::BigInt->new(15328259442110103552)], - ['2013-02-03T14:55:12+0100', Math::BigInt->new(15328259442110103552)], - ['2013-02-03 14:55-0100', Math::BigInt->new(15328290314335027200)], - ['2013-02-03T14:55-0100', Math::BigInt->new(15328290314335027200)], - ['2013-02-03 14:55:12-0100', Math::BigInt->new(15328290365874634752)], - ['2013-02-03T14:55:12-0100', Math::BigInt->new(15328290365874634752)], - ); -my @DTsB = ( - ['2013-02-03 18:55', Math::BigInt->new(15328321238099558400)], - ['2013-02-03T18:55', Math::BigInt->new(15328321238099558400)], - ['2013-02-03 18:55Z', Math::BigInt->new(15328336699981824000)], - ['2013-02-03T18:55Z', Math::BigInt->new(15328336699981824000)], - ['2013-02-03 18:55:12', Math::BigInt->new(15328321289639165952)], - ['2013-02-03T18:55:12', Math::BigInt->new(15328321289639165952)], - ['2013-02-03 18:55:12Z', Math::BigInt->new(15328336751521431552)], - ['2013-02-03T18:55:12Z', Math::BigInt->new(15328336751521431552)], - ['2013-02-03 18:55+0100', Math::BigInt->new(15328321238099558400)], - ['2013-02-03T18:55+0100', Math::BigInt->new(15328321238099558400)], - ['2013-02-03 18:55:12+0100', Math::BigInt->new(15328321289639165952)], - ['2013-02-03T18:55:12+0100', Math::BigInt->new(15328321289639165952)], - ['2013-02-03 18:55-0100', Math::BigInt->new(15328352161864089600)], - ['2013-02-03T18:55-0100', Math::BigInt->new(15328352161864089600)], - ['2013-02-03 18:55:12-0100', Math::BigInt->new(15328352213403697152)], - ['2013-02-03T18:55:12-0100', Math::BigInt->new(15328352213403697152)], - ); - -# Test the time period string detection -my ($instance_a, $instance_b, $instance_c, $instance_d); -foreach my $DTa (@DTsA) -{ - foreach my $DTb (@DTsB) - { - $instance_a = $TESTED_CLASS->new($DTa->[0].'-'.$DTb->[0]); - isa_ok($instance_a, $TESTED_CLASS); - is_deeply([$instance_a->to_numeric()], [$DTa->[1],$DTb->[1]], "Instance $DTa->[0]..$DTb->[0]:a test"); - - $instance_b = $TESTED_CLASS->new($DTa->[0].'..'.$DTb->[0]); - isa_ok($instance_b, $TESTED_CLASS); - is_deeply([$instance_b->to_numeric()], [$DTa->[1],$DTb->[1]], "Instance $DTa->[0]..$DTb->[0]:a test"); - - $instance_c = $TESTED_CLASS->new($DTa->[0].' - '.$DTb->[0]); - isa_ok($instance_c, $TESTED_CLASS); - is_deeply([$instance_c->to_numeric()], [$DTa->[1],$DTb->[1]], "Instance $DTa->[0]..$DTb->[0]:a test"); - - $instance_d = $TESTED_CLASS->new($DTa->[0].' .. '.$DTb->[0]); - isa_ok($instance_d, $TESTED_CLASS); - is_deeply([$instance_d->to_numeric()], [$DTa->[1],$DTb->[1]], "Instance $DTa->[0]..$DTb->[0]:a test"); - } -} - -#------------------------------------------------------------------------------- -# Create couple of other instances and test the comparison functions - -# Now attempt to create a class instance and check it -my $instance1 = $TESTED_CLASS->new('2013-04-18T08:28:37Z..2013-04-18T10:28:37Z'); -isa_ok($instance1, $TESTED_CLASS); - -# View the created instance -diag("Instance dump 01: " . Dumper($instance1)) if Tester::D(); - -{ -use bigint; -is_deeply([$instance1->to_numeric()], [15355635585129644032,15355666508894175232], 'Instance 1 test 01'); -is($instance1->to_string(), '2013-04-18 08:28:37Z..2013-04-18 10:28:37Z', 'Instance 1 test 02'); -is($instance1->TO_JSON(), '2013-04-18 08:28:37Z..2013-04-18 10:28:37Z', 'Instance 1 test 03'); -is("$instance1", '2013-04-18 08:28:37Z..2013-04-18 10:28:37Z', 'Instance 1 test 04'); -} - -is($instance1 == '2013-04-18T08:28:37Z', 1, 'Comparison test 01'); -is($instance1 == '2013-04-18T18:28:37Z', '', 'Comparison test 02'); -is($instance1 != '2013-04-18T08:28:37Z', '', 'Comparison test 03'); -is($instance1 != '2013-04-18T18:28:37Z', 1, 'Comparison test 04'); - -is('2013-04-18T08:28:37Z' == $instance1, 1, 'Comparison test 05'); -is('2013-04-18T18:28:37Z' == $instance1, '', 'Comparison test 06'); -is('2013-04-18T08:28:37Z' != $instance1, '', 'Comparison test 07'); -is('2013-04-18T18:28:37Z' != $instance1, 1, 'Comparison test 08'); - -is($instance1 < '2013-04-18T08:28:37Z', '', 'Comparison test 09'); -is($instance1 <= '2013-04-18T08:28:37Z', 1, 'Comparison test 10'); -is($instance1 > '2013-04-18T08:28:37Z', '', 'Comparison test 11'); -is($instance1 >= '2013-04-18T08:28:37Z', 1, 'Comparison test 12'); - -is('2013-04-18T08:28:37Z' < $instance1, '', 'Comparison test 13'); -is('2013-04-18T08:28:37Z' <= $instance1, 1, 'Comparison test 14'); -is('2013-04-18T08:28:37Z' > $instance1, '', 'Comparison test 15'); -is('2013-04-18T08:28:37Z' >= $instance1, 1, 'Comparison test 16'); diff --git a/lib_perl/tests/unit/t/Value.Range.t b/lib_perl/tests/unit/t/Value.Range.t deleted file mode 100644 index c251ec68d133f7710e8c54762d77319b5b18bded..0000000000000000000000000000000000000000 --- a/lib_perl/tests/unit/t/Value.Range.t +++ /dev/null @@ -1,242 +0,0 @@ -#!/usr/bin/perl -T - -use strict; -use warnings; - -#******************************************************************************* -# Value::Range module/class tests -# -# Author: Jan Mach, jan.mach@cesnet.cz -# Version: 0.1 -# Purpose: -# -#******************************************************************************* - -use Data::Dumper; -#use Smart::Comments; - -use Test::More tests => 167; - -# First test if the module correctly compiles -BEGIN { - use vars qw($TESTED_CLASS); - $TESTED_CLASS = 'Value::Range'; - - use_ok('Tester'); - use_ok($TESTED_CLASS); - } - -# Debug output explicit ON switch -#Tester::DEBUG_ON(); - -# Debug output explicit OFF switch -#Tester::DEBUG_OFF(); - -# User should know, which version is beeing tested (just for sure) -diag("$TESTED_CLASS version: " . $Value::Range::VERSION) if Tester::D(); - -# Now attempt to create a class instance and check it -my $instance1 = $TESTED_CLASS->new(500,1000); -isa_ok($instance1, $TESTED_CLASS); - -# View the created instance -diag("Instance dump 01: " . Dumper($instance1)) if Tester::D(); - -is_deeply([$instance1->to_numeric()], [500,1000], 'Instance 1 test 01'); -is($instance1->to_string(), "500-1000", 'Instance 1 test 02'); -is($instance1->TO_JSON(), "500-1000", 'Instance 1 test 03'); -is("$instance1", "500-1000", 'Instance 1 test 04'); - -my $instance2 = $TESTED_CLASS->new(5000,10000); -isa_ok($instance2, $TESTED_CLASS); - -# View the created instance -diag("Instance dump 02: " . Dumper($instance2)) if Tester::D(); - -is_deeply([$instance2->to_numeric()], [5000,10000], 'Instance 2 test 01'); -is($instance2->to_string(), "5000-10000", 'Instance 2 test 02'); -is($instance2->TO_JSON(), "5000-10000", 'Instance 2 test 03'); -is("$instance2", "5000-10000", 'Instance 2 test 04'); - -my $instance3 = $TESTED_CLASS->new('6000-8000'); -isa_ok($instance3, $TESTED_CLASS); - -# View the created instance -diag("Instance dump 03: " . Dumper($instance3)) if Tester::D(); - -is_deeply([$instance3->to_numeric()], [6000,8000], 'Instance 3 test 01'); -is($instance3->to_string(), "6000-8000", 'Instance 3 test 02'); -is($instance3->TO_JSON(), "6000-8000", 'Instance 3 test 03'); -is("$instance3", "6000-8000", 'Instance 3 test 04'); - -my $instance4 = $TESTED_CLASS->new(4000,11000); -isa_ok($instance4, $TESTED_CLASS); - -# View the created instance -diag("Instance dump 04: " . Dumper($instance4)) if Tester::D(); - -is_deeply([$instance4->to_numeric()], [4000,11000], 'Instance 4 test 01'); -is($instance4->to_string(), "4000-11000", 'Instance 4 test 02'); -is($instance4->TO_JSON(), "4000-11000", 'Instance 4 test 03'); -is("$instance4", "4000-11000", 'Instance 4 test 04'); - -my $instance5 = $TESTED_CLASS->new(4000); -isa_ok($instance5, $TESTED_CLASS); - -# View the created instance -diag("Instance dump 05: " . Dumper($instance4)) if Tester::D(); - -is_deeply([$instance5->to_numeric()], [4000,4000], 'Instance 5 test 01'); -is($instance5->to_string(), "4000-4000", 'Instance 5 test 02'); -is($instance5->TO_JSON(), "4000-4000", 'Instance 5 test 03'); -is("$instance5", "4000-4000", 'Instance 5 test 04'); - -is($instance1 < $instance2, '', 'Comparison test 001'); -is($instance1 lt $instance2, '', 'Comparison test 002'); -is($instance1 > $instance2, 1, 'Comparison test 003'); -is($instance1 gt $instance2, 1, 'Comparison test 004'); -is($instance1 <= $instance2, '', 'Comparison test 005'); -is($instance1 le $instance2, '', 'Comparison test 006'); -is($instance1 >= $instance2, 1, 'Comparison test 007'); -is($instance1 ge $instance2, 1, 'Comparison test 008'); -is($instance1 == $instance2, '', 'Comparison test 009'); -is($instance1 eq $instance2, '', 'Comparison test 010'); -is($instance1 != $instance2, 1, 'Comparison test 011'); -is($instance1 ne $instance2, 1, 'Comparison test 012'); -is($instance1 <=> $instance2, 1, 'Comparison test 013'); -is($instance1 cmp $instance2, 1, 'Comparison test 014'); - -is($instance3 < $instance2, 1, 'Comparison test 015'); -is($instance3 lt $instance2, 1, 'Comparison test 016'); -is($instance3 > $instance2, '', 'Comparison test 017'); -is($instance3 gt $instance2, '', 'Comparison test 018'); -is($instance3 <= $instance2, 1, 'Comparison test 019'); -is($instance3 le $instance2, 1, 'Comparison test 020'); -is($instance3 >= $instance2, '', 'Comparison test 021'); -is($instance3 ge $instance2, '', 'Comparison test 022'); -is($instance3 == $instance2, '', 'Comparison test 023'); -is($instance3 eq $instance2, '', 'Comparison test 024'); -is($instance3 != $instance2, 1, 'Comparison test 025'); -is($instance3 ne $instance2, 1, 'Comparison test 026'); -is($instance3 <=> $instance2, -1, 'Comparison test 027'); -is($instance3 cmp $instance2, -1, 'Comparison test 028'); - -is($instance2 < 5000, '', 'Comparison test 029'); -is($instance2 > 5000, '', 'Comparison test 030'); -is($instance2 <= 5000, 1, 'Comparison test 031'); -is($instance2 >= 5000, 1, 'Comparison test 032'); -is($instance2 == 5000, 1, 'Comparison test 033'); -is($instance2 != 5000, '', 'Comparison test 034'); -is($instance2 <=> 5000, 0, 'Comparison test 035'); -is($instance2 lt 5000, '', 'Comparison test 036'); -is($instance2 gt 5000, '', 'Comparison test 037'); -is($instance2 le 5000, 1, 'Comparison test 038'); -is($instance2 ge 5000, 1, 'Comparison test 039'); -is($instance2 eq 5000, 1, 'Comparison test 040'); -is($instance2 ne 5000, '', 'Comparison test 041'); -is($instance2 cmp 5000, 0, 'Comparison test 042'); - -is($instance2 < 1000, '', 'Comparison test 043'); -is($instance2 > 1000, 1, 'Comparison test 044'); -is($instance2 <= 1000, '', 'Comparison test 045'); -is($instance2 >= 1000, 1, 'Comparison test 046'); -is($instance2 == 1000, '', 'Comparison test 047'); -is($instance2 != 1000, 1, 'Comparison test 048'); -is($instance2 <=> 1000, 1, 'Comparison test 049'); -is($instance2 lt 1000, '', 'Comparison test 050'); -is($instance2 gt 1000, 1, 'Comparison test 051'); -is($instance2 le 1000, '', 'Comparison test 052'); -is($instance2 ge 1000, 1, 'Comparison test 053'); -is($instance2 eq 1000, '', 'Comparison test 054'); -is($instance2 ne 1000, 1, 'Comparison test 055'); -is($instance2 cmp 1000, 1, 'Comparison test 056'); - -is($instance2 < 50000, '', 'Comparison test 057'); -is($instance2 > 50000, 1, 'Comparison test 058'); -is($instance2 <= 50000, '', 'Comparison test 059'); -is($instance2 >= 50000, 1, 'Comparison test 060'); -is($instance2 == 50000, '', 'Comparison test 061'); -is($instance2 != 50000, 1, 'Comparison test 062'); -is($instance2 <=> 50000, 1, 'Comparison test 063'); -is($instance2 lt 50000, '', 'Comparison test 064'); -is($instance2 gt 50000, 1, 'Comparison test 065'); -is($instance2 le 50000, '', 'Comparison test 066'); -is($instance2 ge 50000, 1, 'Comparison test 067'); -is($instance2 eq 50000, '', 'Comparison test 068'); -is($instance2 ne 50000, 1, 'Comparison test 069'); -is($instance2 cmp 50000, 1, 'Comparison test 070'); - -is($instance2 < 7000, '', 'Comparison test 071'); -is($instance2 > 7000, '', 'Comparison test 072'); -is($instance2 <= 7000, 1, 'Comparison test 073'); -is($instance2 >= 7000, 1, 'Comparison test 074'); -is($instance2 == 7000, 1, 'Comparison test 075'); -is($instance2 != 7000, '', 'Comparison test 076'); -is($instance2 <=> 7000, 0, 'Comparison test 077'); -is($instance2 lt 7000, '', 'Comparison test 078'); -is($instance2 gt 7000, '', 'Comparison test 079'); -is($instance2 le 7000, 1, 'Comparison test 080'); -is($instance2 ge 7000, 1, 'Comparison test 081'); -is($instance2 eq 7000, 1, 'Comparison test 082'); -is($instance2 ne 7000, '', 'Comparison test 083'); -is($instance2 cmp 7000, 0, 'Comparison test 084'); - -is(5000 < $instance2, '', 'Comparison test 085'); -is(5000 > $instance2, '', 'Comparison test 086'); -is(5000 <= $instance2, 1, 'Comparison test 087'); -is(5000 >= $instance2, 1, 'Comparison test 088'); -is(5000 == $instance2, 1, 'Comparison test 089'); -is(5000 != $instance2, '', 'Comparison test 090'); -is(5000 <=> $instance2, 0, 'Comparison test 091'); -is(5000 lt $instance2, '', 'Comparison test 092'); -is(5000 gt $instance2, '', 'Comparison test 093'); -is(5000 le $instance2, 1, 'Comparison test 094'); -is(5000 ge $instance2, 1, 'Comparison test 095'); -is(5000 eq $instance2, 1, 'Comparison test 096'); -is(5000 ne $instance2, '', 'Comparison test 097'); -is(5000 cmp $instance2, 0, 'Comparison test 098'); - -is(1000 < $instance2, '', 'Comparison test 099'); -is(1000 > $instance2, 1, 'Comparison test 100'); -is(1000 <= $instance2, '', 'Comparison test 101'); -is(1000 >= $instance2, 1, 'Comparison test 102'); -is(1000 == $instance2, '', 'Comparison test 103'); -is(1000 != $instance2, 1, 'Comparison test 104'); -is(1000 <=> $instance2, 1, 'Comparison test 105'); -is(1000 lt $instance2, '', 'Comparison test 106'); -is(1000 gt $instance2, 1, 'Comparison test 107'); -is(1000 le $instance2, '', 'Comparison test 108'); -is(1000 ge $instance2, 1, 'Comparison test 109'); -is(1000 eq $instance2, '', 'Comparison test 110'); -is(1000 ne $instance2, 1, 'Comparison test 111'); -is(1000 cmp $instance2, 1, 'Comparison test 112'); - -is(50000 < $instance2, '', 'Comparison test 113'); -is(50000 > $instance2, 1, 'Comparison test 114'); -is(50000 <= $instance2, '', 'Comparison test 115'); -is(50000 >= $instance2, 1, 'Comparison test 116'); -is(50000 == $instance2, '', 'Comparison test 117'); -is(50000 != $instance2, 1, 'Comparison test 118'); -is(50000 <=> $instance2, 1, 'Comparison test 119'); -is(50000 lt $instance2, '', 'Comparison test 120'); -is(50000 gt $instance2, 1, 'Comparison test 121'); -is(50000 le $instance2, '', 'Comparison test 122'); -is(50000 ge $instance2, 1, 'Comparison test 123'); -is(50000 eq $instance2, '', 'Comparison test 124'); -is(50000 ne $instance2, 1, 'Comparison test 125'); -is(50000 cmp $instance2, 1, 'Comparison test 126'); - -is(7000 < $instance2, '', 'Comparison test 127'); -is(7000 > $instance2, '', 'Comparison test 128'); -is(7000 <= $instance2, 1, 'Comparison test 129'); -is(7000 >= $instance2, 1, 'Comparison test 130'); -is(7000 == $instance2, 1, 'Comparison test 131'); -is(7000 != $instance2, '', 'Comparison test 132'); -is(7000 <=> $instance2, 0, 'Comparison test 133'); -is(7000 lt $instance2, '', 'Comparison test 134'); -is(7000 gt $instance2, '', 'Comparison test 135'); -is(7000 le $instance2, 1, 'Comparison test 136'); -is(7000 ge $instance2, 1, 'Comparison test 137'); -is(7000 eq $instance2, 1, 'Comparison test 138'); -is(7000 ne $instance2, '', 'Comparison test 139'); -is(7000 cmp $instance2, 0, 'Comparison test 140'); diff --git a/lib_perl/tests/unit/t/Value.Single.t b/lib_perl/tests/unit/t/Value.Single.t deleted file mode 100644 index 422ddbde1d37d807044ec0ba543c453652745e8b..0000000000000000000000000000000000000000 --- a/lib_perl/tests/unit/t/Value.Single.t +++ /dev/null @@ -1,119 +0,0 @@ -#!/usr/bin/perl -T - -use strict; -use warnings; - -#******************************************************************************* -# Value::Single module/class tests -# -# Author: Jan Mach, jan.mach@cesnet.cz -# Version: 0.1 -# Purpose: -# -#******************************************************************************* - -use Data::Dumper; -#use Smart::Comments; - -use Test::More tests => 68; - -# First test if the module correctly compiles -BEGIN { - use vars qw($TESTED_CLASS); - $TESTED_CLASS = 'Value::Single'; - - use_ok('Tester'); - use_ok($TESTED_CLASS); - } - -# Debug output explicit ON switch -#Tester::DEBUG_ON(); - -# Debug output explicit OFF switch -#Tester::DEBUG_OFF(); - -# User should know, which version is beeing tested (just for sure) -diag("$TESTED_CLASS version: " . $Value::Single::VERSION) if Tester::D(); - -# Now attempt to create a class instance and check it -my $instance1 = $TESTED_CLASS->new(500); -isa_ok($instance1, $TESTED_CLASS); - -# View the created instance -diag("Instance dump 01: " . Dumper($instance1)) if Tester::D(); - -is($instance1->to_numeric(), 500, 'Instance 1 test 01'); -is($instance1->to_string(), 500, 'Instance 1 test 02'); -is($instance1->TO_JSON(), 500, 'Instance 1 test 03'); -is("$instance1", 500, 'Instance 1 test 04'); - -my $instance2 = $TESTED_CLASS->new(5000); -isa_ok($instance2, $TESTED_CLASS); - -# View the created instance -diag("Instance dump 02: " . Dumper($instance2)) if Tester::D(); - -is($instance2->to_numeric(), 5000, 'Instance 2 test 01'); -is($instance2->to_string(), 5000, 'Instance 2 test 02'); -is($instance2->TO_JSON(), 5000, 'Instance 2 test 03'); -is("$instance2", 5000, 'Instance 2 test 04'); - -is($instance1 < $instance2, 1, 'Comparison test 01'); -is($instance1 > $instance2, '', 'Comparison test 02'); -is($instance1 <= $instance2, 1, 'Comparison test 03'); -is($instance1 >= $instance2, '', 'Comparison test 04'); -is($instance1 == $instance2, '', 'Comparison test 05'); -is($instance1 != $instance2, 1, 'Comparison test 06'); -is($instance1 <=> $instance2, -1, 'Comparison test 07'); -is($instance1 lt $instance2, 1, 'Comparison test 08'); -is($instance1 gt $instance2, '', 'Comparison test 09'); -is($instance1 le $instance2, 1, 'Comparison test 10'); -is($instance1 ge $instance2, '', 'Comparison test 11'); -is($instance1 eq $instance2, '', 'Comparison test 12'); -is($instance1 ne $instance2, 1, 'Comparison test 13'); -is($instance1 cmp $instance2, -1, 'Comparison test 14'); - -is($instance2 < $instance1, '', 'Comparison test 15'); -is($instance2 > $instance1, 1, 'Comparison test 16'); -is($instance2 <= $instance1, '', 'Comparison test 17'); -is($instance2 >= $instance1, 1, 'Comparison test 18'); -is($instance2 == $instance1, '', 'Comparison test 19'); -is($instance2 != $instance1, 1, 'Comparison test 20'); -is($instance2 <=> $instance1, 1, 'Comparison test 21'); -is($instance2 lt $instance1, '', 'Comparison test 22'); -is($instance2 gt $instance1, 1, 'Comparison test 23'); -is($instance2 le $instance1, '', 'Comparison test 24'); -is($instance2 ge $instance1, 1, 'Comparison test 25'); -is($instance2 eq $instance1, '', 'Comparison test 26'); -is($instance2 ne $instance1, 1, 'Comparison test 27'); -is($instance2 cmp $instance1, 1, 'Comparison test 28'); - -is($instance2 < 500, '', 'Comparison test 29'); -is($instance2 > 500, 1, 'Comparison test 30'); -is($instance2 <= 500, '', 'Comparison test 31'); -is($instance2 >= 500, 1, 'Comparison test 32'); -is($instance2 == 500, '', 'Comparison test 33'); -is($instance2 != 500, 1, 'Comparison test 34'); -is($instance2 <=> 500, 1, 'Comparison test 35'); -is($instance2 lt 500, '', 'Comparison test 36'); -is($instance2 gt 500, 1, 'Comparison test 37'); -is($instance2 le 500, '', 'Comparison test 38'); -is($instance2 ge 500, 1, 'Comparison test 39'); -is($instance2 eq 500, '', 'Comparison test 40'); -is($instance2 ne 500, 1, 'Comparison test 41'); -is($instance2 cmp 500, 1, 'Comparison test 42'); - -is(500 < $instance2, 1, 'Comparison test 43'); -is(500 > $instance2, '', 'Comparison test 44'); -is(500 <= $instance2, 1, 'Comparison test 45'); -is(500 >= $instance2, '', 'Comparison test 45'); -is(500 == $instance2, '', 'Comparison test 47'); -is(500 != $instance2, 1, 'Comparison test 48'); -is(500 <=> $instance2, -1, 'Comparison test 49'); -is(500 lt $instance2, 1, 'Comparison test 50'); -is(500 gt $instance2, '', 'Comparison test 51'); -is(500 le $instance2, 1, 'Comparison test 52'); -is(500 ge $instance2, '', 'Comparison test 53'); -is(500 eq $instance2, '', 'Comparison test 54'); -is(500 ne $instance2, 1, 'Comparison test 55'); -is(500 cmp $instance2, -1, 'Comparison test 56'); diff --git a/lib_perl/tests/unit/t/Value.Tempus.t b/lib_perl/tests/unit/t/Value.Tempus.t deleted file mode 100644 index 6309665f1c6d3e25dbfef8fca135ddf241537e4a..0000000000000000000000000000000000000000 --- a/lib_perl/tests/unit/t/Value.Tempus.t +++ /dev/null @@ -1,64 +0,0 @@ -#!/usr/bin/perl -T - -use strict; -use warnings; - -#******************************************************************************* -# Value::Tempus module/class tests -# -# Author: Jan Mach, jan.mach@cesnet.cz -# Version: 0.1 -# Purpose: -# -#******************************************************************************* - -use Data::Dumper; -#use Smart::Comments; - -use Test::More tests => 32; - -# First test if the module correctly compiles -BEGIN { - use vars qw($TESTED_CLASS); - $TESTED_CLASS = 'Value::Tempus'; - - use_ok('Tester'); - use_ok('Value::Convertor'); - use_ok($TESTED_CLASS); - } - -# Debug output explicit ON switch -#Tester::DEBUG_ON(); - -# Debug output explicit OFF switch -#Tester::DEBUG_OFF(); - -# User should know, which version is beeing tested (just for sure) -diag("$TESTED_CLASS version: " . $Value::Tempus::VERSION) if Tester::D(); - -# Define all IP addresses to be tested -my @TSS = ( - ['2013-05-28 08:34:46Z', 'Value::Timestamp', '2013-05-28 08:34:46Z'], - [1369730086, 'Value::Timestamp', '2013-05-28 08:34:46Z'], - ['0xd54eeaa6.0x0', 'Value::Timestamp', '2013-05-28 08:34:46Z'], - ['2013-05-28 08:34:46Z-2013-05-28 18:34:46Z', 'Value::Period', '2013-05-28 08:34:46Z..2013-05-28 18:34:46Z'], - ['2013-05-28 08:34:46Z..2013-05-28 18:34:46Z', 'Value::Period', '2013-05-28 08:34:46Z..2013-05-28 18:34:46Z'], - ['2013-05-28 08:34:46Z - 2013-05-28 18:34:46Z', 'Value::Period', '2013-05-28 08:34:46Z..2013-05-28 18:34:46Z'], - ['2013-05-28 08:34:46Z .. 2013-05-28 18:34:46Z', 'Value::Period', '2013-05-28 08:34:46Z..2013-05-28 18:34:46Z'], - ); - -my $instance; -foreach my $TS (@TSS) -{ - $instance = $TESTED_CLASS->new($TS->[0]); - isa_ok($instance, $TS->[1]); - is($instance->to_string(), $TS->[2], "Instance $TS->[0] test 01"); - is($instance->TO_JSON(), $TS->[2], "Instance $TS->[0] test 02"); - is("$instance", $TS->[2], "Instance $TS->[0] test 03"); - - diag("Instance $TS->[1] dump: " . Dumper($instance)) if Tester::D(); -} - -$instance = $TESTED_CLASS->new('2013-05-28 08:34:46Z'); -my $t1 = Value::Convertor->datetime_to_nbi('2013-05-28 08:34:46Z'); -is(Value::Convertor->datetime_to_nbi($instance), $t1, 'Convertor conversion test 01'); diff --git a/lib_perl/tests/unit/t/Value.Timestamp.t b/lib_perl/tests/unit/t/Value.Timestamp.t deleted file mode 100644 index e5431f91f3a1ae7cb7ca562df5fe50268ca565be..0000000000000000000000000000000000000000 --- a/lib_perl/tests/unit/t/Value.Timestamp.t +++ /dev/null @@ -1,209 +0,0 @@ -#!/usr/bin/perl -T - -use strict; -use warnings; - -#******************************************************************************* -# Value::Timestamp module/class tests -# -# Author: Jan Mach, jan.mach@cesnet.cz -# Version: 0.1 -# Purpose: -# -#******************************************************************************* - -use Data::Dumper; -#use Smart::Comments; - -use Test::More tests => 146; - -# First test if the module correctly compiles -BEGIN { - use vars qw($TESTED_CLASS); - $TESTED_CLASS = 'Value::Timestamp'; - - use_ok('Tester'); - use_ok('Value::Convertor'); - use_ok($TESTED_CLASS); - } - -# Debug output explicit ON switch -#Tester::DEBUG_ON(); - -# Debug output explicit OFF switch -#Tester::DEBUG_OFF(); - -# User should know, which version is beeing tested (just for sure) -diag("$TESTED_CLASS version: " . $Value::Timestamp::VERSION) if Tester::D(); - -# Now attempt to create a class instance and check it -my $instance1 = $TESTED_CLASS->new('2013-04-18T08:28:37Z'); -isa_ok($instance1, $TESTED_CLASS); - -# View the created instance -diag("Instance dump 01: " . Dumper($instance1)) if Tester::D(); - -#------------------------------------------------------------------------------- -# The object internally uses Value::Convertor::datetime_to_nbi conversion, so we should -# test that it accepts all possible value types: -my %TSs = ( - 'A' => { - 'str' => '2013-05-28 08:34:46Z', # UTC timestamp string - 'unixs' => 1369730086, # Unix timestamp - 'ntps' => '0xd54eeaa6.0x0', # NTP timestamp - 'nbi' => Math::BigInt->new(15370480576947552256), # NTP timestamp in bigint form - }, - 'B' => { - 'str' => '2013-04-18 10:28:37Z', - 'unixs' => 1366280917, - 'ntps' => '0xd51a4955.0x0', - 'nbi' => Math::BigInt->new(15355666508894175232), - }, - 'C' => { - 'str' => '2013-05-28 11:58:14Z', - 'unixs' => 1369742294, - 'ntps' => '0xd54f1a56.0x0', - 'nbi' => Math::BigInt->new(15370533009908301824), - }, - ); - -my $instance_a; -my $instance_b; -my $instance_c; -foreach my $TS (sort keys(%TSs)) -{ - $instance_a = $TESTED_CLASS->new($TSs{$TS}->{'str'}); - isa_ok($instance_a, $TESTED_CLASS); - is($instance_a->to_numeric(), $TSs{$TS}->{'nbi'}, "Instance $TS:a test 01"); - is($instance_a->to_string(), $TSs{$TS}->{'str'}, "Instance $TS:a test 02"); - is($instance_a->TO_JSON(), $TSs{$TS}->{'str'}, "Instance $TS:a test 03"); - is("$instance_a", $TSs{$TS}->{'str'}, "Instance $TS:a test 04"); - - $instance_b = $TESTED_CLASS->new($TSs{$TS}->{'unixs'}); - isa_ok($instance_b, $TESTED_CLASS); - is($instance_b->to_numeric(), $TSs{$TS}->{'nbi'}, "Instance $TS:b test 01"); - is($instance_b->to_string(), $TSs{$TS}->{'str'}, "Instance $TS:b test 02"); - is($instance_b->TO_JSON(), $TSs{$TS}->{'str'}, "Instance $TS:b test 03"); - is("$instance_b", $TSs{$TS}->{'str'}, "Instance $TS:b test 04"); - - $instance_c = $TESTED_CLASS->new($TSs{$TS}->{'ntps'}); - isa_ok($instance_c, $TESTED_CLASS); - is($instance_c->to_numeric(), $TSs{$TS}->{'nbi'}, "Instance $TS:c test 01"); - is($instance_c->to_string(), $TSs{$TS}->{'str'}, "Instance $TS:c test 02"); - is($instance_c->TO_JSON(), $TSs{$TS}->{'str'}, "Instance $TS:c test 03"); - is("$instance_c", $TSs{$TS}->{'str'}, "Instance $TS:c test 04"); -} - -#------------------------------------------------------------------------------- -# Check all possible ways of specifying the datetime string -my @DTs = ( - ['2013-02-03 14:55', Math::BigInt->new(15328259390570496000)], - ['2013-02-03T14:55', Math::BigInt->new(15328259390570496000)], - ['2013-02-03 14:55Z', Math::BigInt->new(15328274852452761600)], - ['2013-02-03T14:55Z', Math::BigInt->new(15328274852452761600)], - ['2013-02-03 14:55:12', Math::BigInt->new(15328259442110103552)], - ['2013-02-03T14:55:12', Math::BigInt->new(15328259442110103552)], - ['2013-02-03 14:55:12Z', Math::BigInt->new(15328274903992369152)], - ['2013-02-03T14:55:12Z', Math::BigInt->new(15328274903992369152)], - ['2013-02-03 14:55+0100', Math::BigInt->new(15328259390570496000)], - ['2013-02-03T14:55+0100', Math::BigInt->new(15328259390570496000)], - ['2013-02-03 14:55:12+0100', Math::BigInt->new(15328259442110103552)], - ['2013-02-03T14:55:12+0100', Math::BigInt->new(15328259442110103552)], - ['2013-02-03 14:55-0100', Math::BigInt->new(15328290314335027200)], - ['2013-02-03T14:55-0100', Math::BigInt->new(15328290314335027200)], - ['2013-02-03 14:55:12-0100', Math::BigInt->new(15328290365874634752)], - ['2013-02-03T14:55:12-0100', Math::BigInt->new(15328290365874634752)], - ); - -my $instance; -foreach my $DT (@DTs) -{ - $instance = $TESTED_CLASS->new($DT->[0]); - isa_ok($instance, $TESTED_CLASS); - is($instance->to_numeric(), $DT->[1], "Instance $DT->[1] test"); -} - -#------------------------------------------------------------------------------- -# Create couple of other instances and test the comparison functions -{ -use bigint; -is($instance1->to_numeric(), 15355635585129644032, 'Instance 1 test 01'); -is($instance1->to_string(), '2013-04-18 08:28:37Z', 'Instance 1 test 02'); -is($instance1->TO_JSON(), '2013-04-18 08:28:37Z', 'Instance 1 test 03'); -is("$instance1", '2013-04-18 08:28:37Z', 'Instance 1 test 04'); -} - -# Now attempt to create a class instance and check it -my $instance2 = $TESTED_CLASS->new('2013-04-18 10:28:37Z'); -isa_ok($instance2, $TESTED_CLASS); - -# View the created instance -diag("Instance dump 02: " . Dumper($instance2)) if Tester::D(); - -{ -use bigint; -is($instance2->to_numeric(), 15355666508894175232, 'Instance 2 test 01'); -is($instance2->to_string(), '2013-04-18 10:28:37Z', 'Instance 2 test 02'); -is($instance2->TO_JSON(), '2013-04-18 10:28:37Z', 'Instance 2 test 03'); -is("$instance2", '2013-04-18 10:28:37Z', 'Instance 2 test 04'); -} - -is($instance1 < $instance2, 1, 'Comparison test 01'); -is($instance1 > $instance2, '', 'Comparison test 02'); -is($instance1 <= $instance2, 1, 'Comparison test 03'); -is($instance1 >= $instance2, '', 'Comparison test 04'); -is($instance1 == $instance2, '', 'Comparison test 05'); -is($instance1 != $instance2, 1, 'Comparison test 06'); -is($instance1 <=> $instance2, -1, 'Comparison test 07'); -is($instance1 lt $instance2, 1, 'Comparison test 08'); -is($instance1 gt $instance2, '', 'Comparison test 09'); -is($instance1 le $instance2, 1, 'Comparison test 10'); -is($instance1 ge $instance2, '', 'Comparison test 11'); -is($instance1 eq $instance2, '', 'Comparison test 12'); -is($instance1 ne $instance2, 1, 'Comparison test 13'); -is($instance1 cmp $instance2, -1, 'Comparison test 14'); - -is($instance2 < $instance1, '', 'Comparison test 15'); -is($instance2 > $instance1, 1, 'Comparison test 16'); -is($instance2 <= $instance1, '', 'Comparison test 17'); -is($instance2 >= $instance1, 1, 'Comparison test 18'); -is($instance2 == $instance1, '', 'Comparison test 19'); -is($instance2 != $instance1, 1, 'Comparison test 20'); -is($instance2 <=> $instance1, 1, 'Comparison test 21'); -is($instance2 lt $instance1, '', 'Comparison test 22'); -is($instance2 gt $instance1, 1, 'Comparison test 23'); -is($instance2 le $instance1, '', 'Comparison test 24'); -is($instance2 ge $instance1, 1, 'Comparison test 25'); -is($instance2 eq $instance1, '', 'Comparison test 26'); -is($instance2 ne $instance1, 1, 'Comparison test 27'); -is($instance2 cmp $instance1, 1, 'Comparison test 28'); - -is($instance2 < '2013-04-18T08:28:37Z', '', 'Comparison test 29'); -is($instance2 > '2013-04-18T08:28:37Z', 1, 'Comparison test 30'); -is($instance2 <= '2013-04-18T08:28:37Z', '', 'Comparison test 31'); -is($instance2 >= '2013-04-18T08:28:37Z', 1, 'Comparison test 32'); -is($instance2 == '2013-04-18T08:28:37Z', '', 'Comparison test 33'); -is($instance2 != '2013-04-18T08:28:37Z', 1, 'Comparison test 34'); -is($instance2 <=> '2013-04-18T08:28:37Z', 1, 'Comparison test 35'); -is($instance2 lt '2013-04-18T08:28:37Z', '', 'Comparison test 36'); -is($instance2 gt '2013-04-18T08:28:37Z', 1, 'Comparison test 37'); -is($instance2 le '2013-04-18T08:28:37Z', '', 'Comparison test 38'); -is($instance2 ge '2013-04-18T08:28:37Z', 1, 'Comparison test 39'); -is($instance2 eq '2013-04-18T08:28:37Z', '', 'Comparison test 40'); -is($instance2 ne '2013-04-18T08:28:37Z', 1, 'Comparison test 41'); -is($instance2 cmp '2013-04-18T08:28:37Z', 1, 'Comparison test 42'); - -is('2013-04-18T08:28:37Z' < $instance2, 1, 'Comparison test 43'); -is('2013-04-18T08:28:37Z' > $instance2, '', 'Comparison test 44'); -is('2013-04-18T08:28:37Z' <= $instance2, 1, 'Comparison test 45'); -is('2013-04-18T08:28:37Z' >= $instance2, '', 'Comparison test 45'); -is('2013-04-18T08:28:37Z' == $instance2, '', 'Comparison test 47'); -is('2013-04-18T08:28:37Z' != $instance2, 1, 'Comparison test 48'); -is('2013-04-18T08:28:37Z' <=> $instance2, -1, 'Comparison test 49'); -is('2013-04-18T08:28:37Z' lt $instance2, 1, 'Comparison test 50'); -is('2013-04-18T08:28:37Z' gt $instance2, '', 'Comparison test 51'); -is('2013-04-18T08:28:37Z' le $instance2, 1, 'Comparison test 52'); -is('2013-04-18T08:28:37Z' ge $instance2, '', 'Comparison test 53'); -is('2013-04-18T08:28:37Z' eq $instance2, '', 'Comparison test 54'); -is('2013-04-18T08:28:37Z' ne $instance2, 1, 'Comparison test 55'); -is('2013-04-18T08:28:37Z' cmp $instance2, -1, 'Comparison test 56'); diff --git a/lib_perl/tests/unit/test b/lib_perl/tests/unit/test deleted file mode 100755 index 896c25f701da34c5fd13b173af98c75a46b1380e..0000000000000000000000000000000000000000 --- a/lib_perl/tests/unit/test +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/bash - -#******************************************************************************* -# CTTT LAUNCHER SCRIPT -#******************************************************************************* - -# Try to find the cttt tool in system -CTTT=`/usr/bin/which cttt` -# Try to autodetect the cttt location -if [ "X$CTTT" != "X" ] ; then - $CTTT $@ -# Check system package location -elif [ -x "/usr/local/bin/cttt" ] ; then - /usr/local/bin/cttt $@ -# It might be installed from TAR package -elif [ -x "/opt/libcesnet-toolkit-perl/bin/cttt" ] ; then - /opt/libcesnet-toolkit-perl/bin/cttt $@ -# Or we might be in development environment -elif [ -x "../../bin/cttt" ] ; then - ../../bin/cttt $@ -else - echo "ERROR: cttt utility script was not found on the system" 1>&2 -fi diff --git a/lib_perl/tests/unit/test.conf b/lib_perl/tests/unit/test.conf deleted file mode 100644 index 0faf073287348a575ab422bc6052e89462b75f0b..0000000000000000000000000000000000000000 --- a/lib_perl/tests/unit/test.conf +++ /dev/null @@ -1,37 +0,0 @@ -{ - "name": "libidea", - - "tests": [ - ["Value::Convertor", "t/Value.Convertor.t"], - - ["Value::Single", "t/Value.Single.t"], - ["Value::IPv4ADDR", "t/Value.IPv4ADDR.t"], - ["Value::IPv6ADDR", "t/Value.IPv6ADDR.t"], - ["Value::Timestamp", "t/Value.Timestamp.t"], - ["Value::Duration", "t/Value.Duration.t"], - ["Value::Range", "t/Value.Range.t"], - ["Value::IPv4CIDR", "t/Value.IPv4CIDR.t"], - ["Value::IPv4NETM", "t/Value.IPv4NETM.t"], - ["Value::IPv4RNG", "t/Value.IPv4RNG.t"], - ["Value::Period", "t/Value.Period.t"], - ["Value::IP", "t/Value.IP.t"], - ["Value::Tempus", "t/Value.Tempus.t"], - - ["Mentat::MPath::Parser", "t/Mentat.MPath.Parser.t"], - - ["Mentat::Message::Value", "t/Mentat.Message.Value.t"], - ["Mentat::Message::Value::IDEA", "t/Mentat.Message.Value.IDEA.t"], - - ["Mentat::Message", "t/Mentat.Message.t"], - ["Mentat::Message::IDEA", "t/Mentat.Message.IDEA.t"], - - ["Mentat::Message::Factory", "t/Mentat.Message.Factory.t"], - ["Mentat::Message::Builder", "t/Mentat.Message.Builder.t"], - ["Mentat::Message::Builder::IDEA", "t/Mentat.Message.Builder.IDEA.t"], - - ["Mentat::Message::Validator", "t/Mentat.Message.Validator.t"], - ["Mentat::Message::Validator::IDEA", "t/Mentat.Message.Validator.IDEA.t"], - - ["Mentat::Handyman", "t/Mentat.Handyman.t"] - ] -} diff --git a/lib_python/lib/ipranges/LICENSE b/lib_python/lib/ipranges/LICENSE deleted file mode 100644 index 3b5855771461e3c727e9f97bbe8e06671efc3778..0000000000000000000000000000000000000000 --- a/lib_python/lib/ipranges/LICENSE +++ /dev/null @@ -1,13 +0,0 @@ -Copyright (c) 2016, CESNET, z. s. p. o. - -Permission to use, copy, modify, and/or distribute this software for any -purpose with or without fee is hereby granted, provided that the above -copyright notice and this permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. \ No newline at end of file diff --git a/lib_python/lib/ipranges/Makefile b/lib_python/lib/ipranges/Makefile deleted file mode 100644 index fa28678c697d22282cc58f18361c280263627548..0000000000000000000000000000000000000000 --- a/lib_python/lib/ipranges/Makefile +++ /dev/null @@ -1,62 +0,0 @@ -#------------------------------------------------------------------------------- -# Copyright (c) since 2016, CESNET, z. s. p. o. -# Authors: Pavel Kácha <pavel.kacha@cesnet.cz> -# Jan Mach <jan.mach@cesnet.cz> -# Use of this source is governed by an ISC license, see LICENSE file. -#------------------------------------------------------------------------------- - -all: archive bdist deploy - -build: archive bdist - -help: - $(info List of possible make targets:) - $(info ) - $(info * all: archive previous packages, build new distribution and deploy to PyPI [default]) - $(info * build: archive previous packages and build new distribution) - $(info * test: run unit tests) - $(info * archive: archive previous packages) - $(info * bdist: build new distribution) - $(info * install: install distribution on local machine) - $(info * deploy: deploy to PyPI) - $(info ) - -# Perform unit tests -test: FORCE - $(info Testing source code) - nosetests - -# Move old distribution files to archive directory -archive: FORCE - $(info Checking if dist archivation is needed) - @if ! [ `ls dist/ipranges* | wc -l` = "0" ]; then\ - echo "Moving old distribution files to local archive";\ - mv -f dist/ipranges* archive;\ - fi - -# Build various Python package distributions -bdist: - $(info Building distributions) - - # Build and upload (insecure) - #python3 setup.py sdist bdist_wheel upload - - # Build only - python3 setup.py sdist bdist_wheel --universal - -# Perform installation from local files for both Python 2 and 3 -install: FORCE - $(info Local installation) - pip install dist/ipranges*.whl - pip3 install dist/ipranges*.whl - -# Deploy latest packages to PyPI -deploy: FORCE - $(info PyPI deployment) - - # Secure upload with Twine - twine upload dist/ipranges* - -# Empty rule as dependency wil force make to always perform target -# Source: https://www.gnu.org/software/make/manual/html_node/Force-Targets.html -FORCE: diff --git a/lib_python/lib/ipranges/README.rst b/lib_python/lib/ipranges/README.rst deleted file mode 100644 index 95a313a3826218a11fee0941bd7ff1f156dd5f20..0000000000000000000000000000000000000000 --- a/lib_python/lib/ipranges/README.rst +++ /dev/null @@ -1,8 +0,0 @@ -ipranges -================================================================================ - -Python 2 and 3 compatible library for working with IPv4 and IPv6 addressess in -many notations (sible IP, CIDR, range). - -This README file is work in progress, for more information please visit home page -at https://idea.cesnet.cz/en/index. diff --git a/lib_python/lib/ipranges/archive/.gitignore b/lib_python/lib/ipranges/archive/.gitignore deleted file mode 100644 index 5e7d2734cfc60289debf74293817c0a8f572ff32..0000000000000000000000000000000000000000 --- a/lib_python/lib/ipranges/archive/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -# Ignore everything in this directory -* -# Except this file -!.gitignore diff --git a/lib_python/lib/ipranges/dist/.gitignore b/lib_python/lib/ipranges/dist/.gitignore deleted file mode 100644 index 5e7d2734cfc60289debf74293817c0a8f572ff32..0000000000000000000000000000000000000000 --- a/lib_python/lib/ipranges/dist/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -# Ignore everything in this directory -* -# Except this file -!.gitignore diff --git a/lib_python/lib/ipranges/ipranges.py b/lib_python/lib/ipranges/ipranges.py deleted file mode 100644 index c36607165ca79febc2f155e32edbd4041307bce2..0000000000000000000000000000000000000000 --- a/lib_python/lib/ipranges/ipranges.py +++ /dev/null @@ -1,267 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- -# -# Copyright (c) 2016, CESNET, z. s. p. o. -# Use of this source is governed by an ISC license, see LICENSE file. - -__version__ = '0.1.7' -__author__ = 'Pavel Kácha <pavel.kacha@cesnet.cz>' - -import socket -import struct -import numbers - -try: - basestring -except NameError: - basestring = str - -class Range(object): - __slots__ = () - - single = int - - def __len__(self): - return self.high() - self.low() + 1 - - def __eq__(self, other): - return (self.low() == other.low() and self.high() == other.high()) - - def __ne__(self, other): - return not self.__eq__(other) - - def __contains__(self, other): - return (self.low() <= other.low() and self.high() >= other.high()) - - def __iter__(self): - for i in range(self.low(), self.high()+1): - yield self.util.single(i) - - def __getitem__(self, key): - if isinstance(key, slice): - return (self.util.single(self.low() + i) for i in range(*key.indices(len(self)))) - else: - if key < 0: - idx = self.high() + key + 1 - else: - idx = self.low() + key - if self.low() <= idx <= self.high(): - return self.util.single(idx) - else: - raise IndexError - - def __repr__(self): - return "%s('%s')" % (type(self).__name__, str(self)) - - -class IPBase(Range): - __slots__ = () - - def __init__(self, s): - if isinstance(s, basestring): - rng = self._from_str(s) - elif isinstance(s, IPBase): - rng = self._from_range(s) - else: - rng = self._from_val(s) - self._assign(rng) - - def cidr_split(self): - lo, hi = self.low(), self.high() - lo, hi = min(lo, hi), max(lo, hi) - while lo<=hi: - lower_bits = (~lo & (lo-1)).bit_length() - size = hi - lo + 1 - size_bits = size.bit_length() - 1 - bits = min(lower_bits, size_bits) - yield self.util.net((lo, self.util.bit_length-bits)) - lo += 1 << bits - - def _from_val(self, v): - try: - a, b = v - return int(a), int(b) - except Exception: - raise ValueError("Two value tuple expected, got %s" % v) - - -class IPRangeBase(IPBase): - __slots__ = ("lo", "hi") - - def _from_range(self, r): - return (r.low(), r.high()) - - def _from_str(self, s): - try: - ip1, ip2 = s.split("-") - return (self.util.from_str(ip1), self.util.from_str(ip2)) - except Exception: - raise ValueError("Wrong range format: %s" % s) - - def _assign(self, v): - self.lo = min(v) - self.hi = max(v) - - def low(self): return self.lo - - def high(self): return self.hi - - def __str__(self): - return "%s-%s" % (self.util.to_str(self.lo), self.util.to_str(self.hi)) - - -class IPNetBase(IPBase): - __slots__ = ("base", "cidr", "mask") - - def _from_range(self, r): - lo = r.low() - mask = len(r) - 1 - if (len(r) & mask) or (lo & mask): - raise ValueError("%s is not a proper network prefix" % r) - return lo, self.util.bit_length - mask.bit_length() - - def _from_str(self, s): - try: - net, cidr = s.split("/") - base = self.util.from_str(net) - cidr = int(cidr) - return base, cidr - except Exception: - raise ValueError("Wrong network format: %s" % s) - - def _assign(self, v): - self.base, self.cidr = v - self.mask = (self.util.full_mask << (self.util.bit_length - self.cidr)) & self.util.full_mask - - def low(self): return self.base & self.mask - - def high(self): return self.base | (self.mask ^ self.util.full_mask) - - def __str__(self): - return "%s/%i" % (self.util.to_str(self.base), self.cidr) - - -class IPAddrBase(IPBase): - __slots__ = ("ip") - - def _from_range(self, r): - if len(r)!=1: - raise ValueError("Unable to convert network %s to one ip address" % r) - return r.low() - - def _from_str(self, s): return self.util.from_str(s) - - def _from_val(self, r): - try: - return int(r) - except Exception: - raise ValueError("Integer expected as IP") - - def _assign(self, v): self.ip = v - - def __str__(self): return self.util.to_str(self.ip) - - def __int__(self): return self.ip - - def low(self): return self.ip - - def high(self): return self.ip - - -class IP4Util(object): - __slots__ = () - - bit_length = 32 - full_mask = 2**bit_length-1 - - @staticmethod - def from_str(s): - try: - return struct.unpack("!L", socket.inet_pton(socket.AF_INET, s))[0] - except Exception: - raise ValueError("Wrong IPv4 address format: %s" % s) - - @staticmethod - def to_str(i): - try: - return socket.inet_ntop(socket.AF_INET, struct.pack('!L', i)) - except Exception: - raise ValueError("Unable to convert to IPv6 address: %s" % i) - - -class IP6Util(object): - __slots__ = () - - bit_length = 128 - full_mask = 2**bit_length-1 - - @staticmethod - def from_str(s): - try: - hi, lo = struct.unpack("!QQ", socket.inet_pton(socket.AF_INET6, s)) - return hi << 64 | lo - except Exception: - raise ValueError("Wrong IPv6 address format: %s" % s) - - @staticmethod - def to_str(i): - try: - hi = i >> 64 - lo = i & 0xFFFFFFFFFFFFFFFF - return socket.inet_ntop(socket.AF_INET6, struct.pack('!QQ', hi, lo)) - except Exception: - raise ValueError("Unable to convert to IPv6 address: %s" % i) - - -class IP4(IPAddrBase): - __slots__ = () - util = IP4Util - -class IP6(IPAddrBase): - __slots__ = () - util = IP6Util - -class IP4Range(IPRangeBase): - __slots__ = () - util = IP4Util - -class IP6Range(IPRangeBase): - __slots__ = () - util = IP6Util - -class IP4Net(IPNetBase): - __slots__ = () - util = IP4Util - -class IP6Net(IPNetBase): - __slots__ = () - util = IP6Util - -IP4Util.single = IP4 -IP6Util.single = IP6 -IP4Util.net = IP4Net -IP6Util.net = IP6Net - -def from_str(s): - for t in IP4Net, IP4Range, IP4, IP6Net, IP6Range, IP6: - try: - return t(s) - except ValueError: - pass - raise ValueError("%s does not appear as IP address, network or range string" % s) - -def from_str_v4(s): - for t in IP4Net, IP4Range, IP4: - try: - return t(s) - except ValueError: - pass - raise ValueError("%s does not appear as IPv4 address, network or range string" % s) - -def from_str_v6(s): - for t in IP6Net, IP6Range, IP6: - try: - return t(s) - except ValueError: - pass - raise ValueError("%s does not appear as IPv6 address, network or range string" % s) diff --git a/lib_python/lib/ipranges/setup.py b/lib_python/lib/ipranges/setup.py deleted file mode 100644 index 6c6abe070ea0f48460ff364ac587330b544e3e89..0000000000000000000000000000000000000000 --- a/lib_python/lib/ipranges/setup.py +++ /dev/null @@ -1,47 +0,0 @@ -#!/usr/bin/python3 -# -*- coding: utf-8 -*- -#------------------------------------------------------------------------------- -# Copyright (c) since 2016, CESNET, z. s. p. o. -# Authors: Pavel Kácha <pavel.kacha@cesnet.cz> -# Jan Mach <jan.mach@cesnet.cz> -# Use of this source is governed by an ISC license, see LICENSE file. -#------------------------------------------------------------------------------- - -# Resources: -# https://packaging.python.org/en/latest/ -# http://python-packaging-user-guide.readthedocs.io/distributing/ - -# Always prefer setuptools over distutils -from setuptools import setup, find_packages -# To use a consistent encoding -from codecs import open -from os import path - -here = path.abspath(path.dirname(__file__)) - -# Get the long description from the README file -with open(path.join(here, 'README.rst'), encoding='utf-8') as f: - long_description = f.read() - -setup( - name = 'ipranges', - version = '0.1.7', - description = 'Python library for working with IP addressess.', - long_description = long_description, - classifiers = [ - 'Development Status :: 4 - Beta', - 'License :: OSI Approved :: ISC License (ISCL)', - 'Programming Language :: Python', - ], - keywords = 'library', - url = 'https://homeproj.cesnet.cz/git/idea.git', - author = 'Pavel Kacha', - author_email = 'pavel.kacha@cesnet.cz', - license = 'ISC', - py_modules = ['ipranges'], - test_suite = 'nose.collector', - tests_require = [ - 'nose' - ], - zip_safe = True -) diff --git a/lib_python/lib/ipranges/test_ipranges.py b/lib_python/lib/ipranges/test_ipranges.py deleted file mode 100755 index 90b4b05ccdc4199a16af56047ac3808a2ed6e3e1..0000000000000000000000000000000000000000 --- a/lib_python/lib/ipranges/test_ipranges.py +++ /dev/null @@ -1,272 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- -# -# Copyright (c) 2016, CESNET, z. s. p. o. -# Use of this source is governed by an ISC license, see LICENSE file. - -import unittest -from ipranges import IP4, IP6, IP4Range, IP6Range, IP4Net, IP6Net, from_str - -class TestIPRange(unittest.TestCase): - - def testIP4(self): - for ip in ["0.0.0.0", "192.0.2.100", "255.255.255.255"]: - self.assertEqual(str(IP4(ip)), ip) - - def testIP4Fail(self): - for ip in ["", "-", "/", "0", "123", "1.2.3.4.5"]: - with self.assertRaises(ValueError): - IP4(ip) - - def testIP6(self): - for ip in ["::", "2001:db8:220:1:248:1893:25c8:1946", "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"]: - self.assertEqual(str(IP6(ip)), ip) - - def testIP6Fail(self): - for ip in ["", "-", "/", "0", "123", "1:2::3::"]: - with self.assertRaises(ValueError): - IP6(ip) - - def testIP4Range(self): - for r in ["0.0.0.0-255.255.255.255", "192.0.2.64-192.0.2.127", "192.0.2.5-192.0.2.5"]: - self.assertEqual(str(IP4Range(r)), r) - - def testIP4RangeFail(self): - for r in ["", "0.0.0.0", "asdf"]: - with self.assertRaises(ValueError): - IP4Range(r) - - def testIP4RangeFail2(self): - for r in ["192.0.2.64-", "-192.0.2.5", "-"]: - with self.assertRaises(ValueError): - IP4Range(r) - - def testIP6Range(self): - for r in ["::-ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", "2001:db8:220:1:248:1893:25c8:1946-2001:db8:230:1:248:1893:25c8:1946", "2001:db8:230::25c8:1946-2001:db8:230::25c8:1946"]: - self.assertEqual(str(IP6Range(r)), r) - - def testIP6RangeFail(self): - for r in ["", "::", "asdf"]: - with self.assertRaises(ValueError): - IP6Range(r) - - def testIP6RangeFail2(self): - for r in ["2001:db8:220:1:248:1893:25c8:1946-", "-2001:db8:220:1:248:1893:25c8:1946", "-"]: - with self.assertRaises(ValueError): - IP6Range(r) - - def testIP4Net(self): - for n in ["0.0.0.0/0", "192.0.2.64/26", "192.0.2.5/32"]: - self.assertEqual(str(IP4Net(n)), n) - - def testIP4NetFail(self): - for r in ["", "0.0.0.0", "asdf", "192.0.2.64/", "192.0.2.64/?"]: - with self.assertRaises(ValueError): - IP4Net(r) - - def testIP4NetFail2(self): - for r in ["/26", "/"]: - with self.assertRaises(ValueError): - IP4Net(r) - - def testIP6Net(self): - for n in ["::/0", "2001:db8:220:1::/64", "2001:db8:230::25c8:1946/32"]: - self.assertEqual(str(IP6Net(n)), n) - - def testIP6NetFail(self): - for r in ["", "0.0.0.0", "asdf", "2001:db8:220:1::/", "2001:db8:220:1::/?"]: - with self.assertRaises(ValueError): - IP6Net(r) - - def testIP6NetFail2(self): - for r in ["/26", "/"]: - with self.assertRaises(ValueError): - IP6Net(r) - - def test4SameNetRange(self): - net1 = IP4Net("192.0.2.64/26") - net2 = IP4Range("192.0.2.64-192.0.2.127") - self.assertTrue(net1 == net2) - self.assertFalse(net1 != net2) - - def test4SameOne(self): - ip1 = IP4Net("192.0.2.65/32") - ip2 = IP4Range("192.0.2.65-192.0.2.65") - ip3 = IP4("192.0.2.65") - self.assertTrue(ip1 == ip2) - self.assertTrue(ip2 == ip3) - self.assertTrue(ip1 == ip3) - self.assertFalse(ip1 != ip2) - self.assertFalse(ip2 != ip3) - self.assertFalse(ip1 != ip3) - - def test6SameNetRange(self): - net1 = IP6Net("2001:db8:220:1::/64") - net2 = IP6Range("2001:db8:220:1::-2001:db8:220:1:ffff:ffff:ffff:ffff") - self.assertTrue(net1 == net2) - self.assertFalse(net1 != net2) - - def test6SameOne(self): - ip1 = IP6Net("2001:db8:220:1:248:1893:25c8:1946/128") - ip2 = IP6Range("2001:db8:220:1:248:1893:25c8:1946-2001:db8:220:1:248:1893:25c8:1946") - ip3 = IP6("2001:db8:220:1:248:1893:25c8:1946") - self.assertTrue(ip1 == ip2) - self.assertTrue(ip2 == ip3) - self.assertTrue(ip1 == ip3) - self.assertFalse(ip1 != ip2) - self.assertFalse(ip2 != ip3) - self.assertFalse(ip1 != ip3) - - def test4Contains(self): - self.assertTrue(IP4Net("192.0.2.64/28") in IP4Net("192.0.2.64/26")) - self.assertTrue(IP4Net("192.0.2.64/28") in IP4Range("192.0.2.64-192.0.2.127")) - self.assertTrue(IP4Net("192.0.2.65/32") in IP4("192.0.2.65")) - - self.assertTrue(IP4Range("192.0.2.65-192.0.2.126") in IP4Range("192.0.2.64-192.0.2.127")) - self.assertTrue(IP4Range("192.0.2.65-192.0.2.126") in IP4Net("192.0.2.64/26")) - self.assertTrue(IP4Range("192.0.2.65-192.0.2.65") in IP4("192.0.2.65")) - - self.assertTrue(IP4("192.0.2.65") in IP4Range("192.0.2.64-192.0.2.127")) - self.assertTrue(IP4("192.0.2.65") in IP4Net("192.0.2.64/26")) - self.assertTrue(IP4("192.0.2.65") in IP4("192.0.2.65")) - - def test6Contains(self): - self.assertTrue(IP6Net("2001:db8:220:1::/64") in IP6Net("2001:db8:220:1::/64")) - self.assertTrue(IP6Net("2001:db8:220:1::/64") in IP6Range("2001:db8:220:1::-2001:db8:220:1:ffff:ffff:ffff:ffff")) - self.assertTrue(IP6Net("2001:db8:220:1:248:1893:25c8:1946/128") in IP6("2001:db8:220:1:248:1893:25c8:1946")) - - self.assertTrue(IP6Range("2001:db8:220:1::-2001:db8:220:1:ffff:ffff:ffff:ffff") in IP6Range("2001:db8:220:1::-2001:db8:220:1:ffff:ffff:ffff:ffff")) - self.assertTrue(IP6Range("2001:db8:220:1::-2001:db8:220:1:ffff:ffff:ffff:ffff") in IP6Net("2001:db8:220:1::/64")) - self.assertTrue(IP6Range("2001:db8:220:1:248:1893:25c8:1946-2001:db8:220:1:248:1893:25c8:1946") in IP6("2001:db8:220:1:248:1893:25c8:1946")) - - self.assertTrue(IP6("2001:db8:220:1:248:1893:25c8:1946") in IP6Range("2001:db8:220:1::-2001:db8:220:1:ffff:ffff:ffff:ffff")) - self.assertTrue(IP6("2001:db8:220:1:248:1893:25c8:1946") in IP6Net("2001:db8:220:1::/64")) - self.assertTrue(IP6("2001:db8:220:1:248:1893:25c8:1946") in IP6("2001:db8:220:1:248:1893:25c8:1946")) - - def test4Iter(self): - self.assertEqual( - tuple(str(ip) for ip in IP4Net("192.0.2.64/30")), - ("192.0.2.64", "192.0.2.65", "192.0.2.66", "192.0.2.67")) - self.assertEqual( - tuple(str(ip) for ip in IP4Range("192.0.2.64-192.0.2.67")), - ("192.0.2.64", "192.0.2.65", "192.0.2.66", "192.0.2.67")) - self.assertEqual( - tuple(str(ip) for ip in IP4("192.0.2.65")), - ("192.0.2.65",)) - - def test6Iter(self): - self.assertEqual( - tuple(str(ip) for ip in IP6Net("2001:db8:220:1:248:1893:25c8:1944/126")), - ("2001:db8:220:1:248:1893:25c8:1944", - "2001:db8:220:1:248:1893:25c8:1945", - "2001:db8:220:1:248:1893:25c8:1946", - "2001:db8:220:1:248:1893:25c8:1947")) - self.assertEqual( - tuple(str(ip) for ip in IP6Range("2001:db8:220:1:248:1893:25c8:1944-2001:db8:220:1:248:1893:25c8:1947")), - ("2001:db8:220:1:248:1893:25c8:1944", - "2001:db8:220:1:248:1893:25c8:1945", - "2001:db8:220:1:248:1893:25c8:1946", - "2001:db8:220:1:248:1893:25c8:1947")) - self.assertEqual( - tuple(str(ip) for ip in IP6("2001:db8:220:1:248:1893:25c8:1947")), - ("2001:db8:220:1:248:1893:25c8:1947",)) - - def testGetItem(self): - for rng in ( - IP4Range("192.0.2.64-192.0.2.67"), - IP4Net("192.0.2.64/30"), - IP4("192.0.2.65"), - IP6Range("2001:db8:220:1:248:1893:25c8:1944-2001:db8:220:1:248:1893:25c8:1947"), - IP6Net("2001:db8:220:1:248:1893:25c8:1944/126"), - IP6("2001:db8:220:1:248:1893:25c8:1947")): - for idx in (0, -1): - res = [str(rng[i]) for i in range(len(rng))][idx] - res2 = str(rng[idx]) - self.assertEqual(res, res2) - - def testGetSlice(self): - for rng in ( - IP4Range("192.0.2.64-192.0.2.67"), - IP4Net("192.0.2.64/30"), - IP4("192.0.2.65"), - IP6Range("2001:db8:220:1:248:1893:25c8:1944-2001:db8:220:1:248:1893:25c8:1947"), - IP6Net("2001:db8:220:1:248:1893:25c8:1944/126"), - IP6("2001:db8:220:1:248:1893:25c8:1947")): - for idx in (slice(None, None, None), slice(-3, -1), slice(0, -1, 2)): - res = [str(rng[i]) for i in range(len(rng))][idx] - res2 = [str(ip) for ip in rng[idx]] - self.assertEqual(res, res2) - - def testConvToIP(self): - self.assertEqual(IP4(IP4Range("192.0.2.64-192.0.2.64")), IP4("192.0.2.64")) - self.assertEqual(IP4(IP4Net("192.0.2.64/32")), IP4("192.0.2.64")) - with self.assertRaises(ValueError): - IP4(IP4Net("192.0.2.64/30")) - - self.assertEqual(IP6(IP6Range("2001:db8:220:1:248:1893:25c8:1944-2001:db8:220:1:248:1893:25c8:1944")), IP6("2001:db8:220:1:248:1893:25c8:1944")) - self.assertEqual(IP6(IP6Net("2001:db8:220:1:248:1893:25c8:1944/128")), IP6("2001:db8:220:1:248:1893:25c8:1944")) - with self.assertRaises(ValueError): - IP6(IP6Net("2001:db8:220:1:248:1893:25c8:1944/126")) - - def testConvToNet(self): - self.assertEqual(IP4Net(IP4Range("192.0.2.64-192.0.2.127")), IP4Net("192.0.2.64/26")) - self.assertEqual(IP4Net(IP4("192.0.2.64")), IP4Net("192.0.2.64/32")) - with self.assertRaises(ValueError): - IP4Net(IP4Range("192.0.2.64-192.0.2.120")) - - self.assertEqual(IP4Net(IP4Range("192.0.2.64-192.0.2.127")), IP4Net("192.0.2.64/26")) - self.assertEqual(IP4Net(IP4("192.0.2.64")), IP4Net("192.0.2.64/32")) - with self.assertRaises(ValueError): - IP4Net(IP4Range("192.0.2.64-192.0.2.120")) - - self.assertEqual(IP6Net(IP6Range("2001:db8:220:1:248:1893:25c8:1944-2001:db8:220:1:248:1893:25c8:1947")), IP6Net("2001:db8:220:1:248:1893:25c8:1944/126")) - self.assertEqual(IP6Net(IP6("2001:db8:220:1:248:1893:25c8:1947")), IP6Net("2001:db8:220:1:248:1893:25c8:1947/128")) - with self.assertRaises(ValueError): - IP6Net(IP6Range("2001:db8:220:1:248:1893:25c8:1944-2001:db8:220:1:248:1893:25c8:1948")) - - def testFromStr(self): - fs = from_str("192.0.2.64") - obj = IP4("192.0.2.64") - self.assertEqual(fs, obj) - self.assertTrue(isinstance(fs, IP4)) - - fs = from_str("192.0.2.64-192.0.2.127") - obj = IP4Range("192.0.2.64-192.0.2.127") - self.assertEqual(fs, obj) - self.assertTrue(isinstance(fs, IP4Range)) - - fs = from_str("192.0.2.64/26") - obj = IP4Net("192.0.2.64/26") - self.assertEqual(fs, obj) - self.assertTrue(isinstance(fs, IP4Net)) - - fs = from_str("2001:db8:220:1:248:1893:25c8:1947") - obj = IP6("2001:db8:220:1:248:1893:25c8:1947") - self.assertEqual(fs, obj) - self.assertTrue(isinstance(fs, IP6)) - - fs = from_str("2001:db8:220:1:248:1893:25c8:1944-2001:db8:220:1:248:1893:25c8:1947") - obj = IP6Range("2001:db8:220:1:248:1893:25c8:1944-2001:db8:220:1:248:1893:25c8:1947") - self.assertEqual(fs, obj) - self.assertTrue(isinstance(fs, IP6Range)) - - fs = from_str("2001:db8:220:1:248:1893:25c8:1947/128") - obj = IP6Net("2001:db8:220:1:248:1893:25c8:1947/128") - self.assertEqual(fs, obj) - self.assertTrue(isinstance(fs, IP6Net)) - - def testFromStrInvalid(self): - with self.assertRaises(ValueError): - from_str("192.0.2.500") - with self.assertRaises(ValueError): - from_str(":::") - with self.assertRaises(ValueError): - from_str("asdf") - with self.assertRaises(ValueError): - from_str("-") - with self.assertRaises(ValueError): - from_str("/") - - -if __name__ == "__main__": - unittest.main() diff --git a/lib_python/lib/typedcols/LICENSE b/lib_python/lib/typedcols/LICENSE deleted file mode 100644 index 3b5855771461e3c727e9f97bbe8e06671efc3778..0000000000000000000000000000000000000000 --- a/lib_python/lib/typedcols/LICENSE +++ /dev/null @@ -1,13 +0,0 @@ -Copyright (c) 2016, CESNET, z. s. p. o. - -Permission to use, copy, modify, and/or distribute this software for any -purpose with or without fee is hereby granted, provided that the above -copyright notice and this permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. \ No newline at end of file diff --git a/lib_python/lib/typedcols/Makefile b/lib_python/lib/typedcols/Makefile deleted file mode 100644 index 3b73ca303fcbf8b556b6671d54a0fcce20d9be36..0000000000000000000000000000000000000000 --- a/lib_python/lib/typedcols/Makefile +++ /dev/null @@ -1,62 +0,0 @@ -#------------------------------------------------------------------------------- -# Copyright (c) since 2016, CESNET, z. s. p. o. -# Authors: Pavel Kácha <pavel.kacha@cesnet.cz> -# Jan Mach <jan.mach@cesnet.cz> -# Use of this source is governed by an ISC license, see LICENSE file. -#------------------------------------------------------------------------------- - -all: archive bdist deploy - -build: archive bdist - -help: - $(info List of possible make targets:) - $(info ) - $(info * all: archive previous packages, build new distribution and deploy to PyPI [default]) - $(info * build: archive previous packages and build new distribution) - $(info * test: run unit tests) - $(info * archive: archive previous packages) - $(info * bdist: build new distribution) - $(info * install: install distribution on local machine) - $(info * deploy: deploy to PyPI) - $(info ) - -# Perform unit tests -test: FORCE - $(info Testing source code) - nosetests - -# Move old distribution files to archive directory -archive: FORCE - $(info Checking if dist archivation is needed) - @if ! [ `ls dist/typedcols* | wc -l` = "0" ]; then\ - echo "Moving old distribution files to local archive";\ - mv -f dist/typedcols* archive;\ - fi - -# Build various Python package distributions -bdist: - $(info Building distributions) - - # Build and upload (insecure) - #python3 setup.py sdist bdist_wheel upload - - # Build only - python3 setup.py sdist bdist_wheel --universal - -# Perform installation from local files for both Python 2 and 3 -install: FORCE - $(info Local installation) - pip install dist/typedcols*.whl - pip3 install dist/typedcols*.whl - -# Deploy latest packages to PyPI -deploy: FORCE - $(info PyPI deployment) - - # Secure upload with Twine - twine upload dist/typedcols* - -# Empty rule as dependency wil force make to always perform target -# Source: https://www.gnu.org/software/make/manual/html_node/Force-Targets.html -FORCE: diff --git a/lib_python/lib/typedcols/README.rst b/lib_python/lib/typedcols/README.rst deleted file mode 100644 index c443fc8658f23c331731ed7ecab5f65b20d3e5ce..0000000000000000000000000000000000000000 --- a/lib_python/lib/typedcols/README.rst +++ /dev/null @@ -1,7 +0,0 @@ -typedcols -================================================================================ - -Python 2 and 3 compatible library providing typed collections. - -This README file is work in progress, for more information please visit home page -at https://idea.cesnet.cz/en/index. diff --git a/lib_python/lib/typedcols/archive/.gitignore b/lib_python/lib/typedcols/archive/.gitignore deleted file mode 100644 index 5e7d2734cfc60289debf74293817c0a8f572ff32..0000000000000000000000000000000000000000 --- a/lib_python/lib/typedcols/archive/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -# Ignore everything in this directory -* -# Except this file -!.gitignore diff --git a/lib_python/lib/typedcols/dist/.gitignore b/lib_python/lib/typedcols/dist/.gitignore deleted file mode 100644 index 5e7d2734cfc60289debf74293817c0a8f572ff32..0000000000000000000000000000000000000000 --- a/lib_python/lib/typedcols/dist/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -# Ignore everything in this directory -* -# Except this file -!.gitignore diff --git a/lib_python/lib/typedcols/setup.py b/lib_python/lib/typedcols/setup.py deleted file mode 100644 index a34b8223e3339fb8bfbf8164ceaa355c6c8e4873..0000000000000000000000000000000000000000 --- a/lib_python/lib/typedcols/setup.py +++ /dev/null @@ -1,47 +0,0 @@ -#!/usr/bin/python3 -# -*- coding: utf-8 -*- -#------------------------------------------------------------------------------- -# Copyright (c) since 2016, CESNET, z. s. p. o. -# Authors: Pavel Kácha <pavel.kacha@cesnet.cz> -# Jan Mach <jan.mach@cesnet.cz> -# Use of this source is governed by an ISC license, see LICENSE file. -#------------------------------------------------------------------------------- - -# Resources: -# https://packaging.python.org/en/latest/ -# http://python-packaging-user-guide.readthedocs.io/distributing/ - -# Always prefer setuptools over distutils -from setuptools import setup, find_packages -# To use a consistent encoding -from codecs import open -from os import path - -here = path.abspath(path.dirname(__file__)) - -# Get the long description from the README file -with open(path.join(here, 'README.rst'), encoding='utf-8') as f: - long_description = f.read() - -setup( - name = 'typedcols', - version = '0.1.7', - description = 'Python library providing typed collections.', - long_description = long_description, - classifiers = [ - 'Development Status :: 4 - Beta', - 'License :: OSI Approved :: ISC License (ISCL)', - 'Programming Language :: Python', - ], - keywords = 'library', - url = 'https://homeproj.cesnet.cz/git/idea.git', - author = 'Pavel Kacha', - author_email = 'pavel.kacha@cesnet.cz', - license = 'ISC', - py_modules = ['typedcols'], - test_suite = 'nose.collector', - tests_require = [ - 'nose' - ], - zip_safe = True -) diff --git a/lib_python/lib/typedcols/test_typedcols.py b/lib_python/lib/typedcols/test_typedcols.py deleted file mode 100755 index c9f845e1c04d067f3b802507d14c960b1a444482..0000000000000000000000000000000000000000 --- a/lib_python/lib/typedcols/test_typedcols.py +++ /dev/null @@ -1,164 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- -# -# Copyright (c) 2016, CESNET, z. s. p. o. -# Use of this source is governed by an ISC license, see LICENSE file. - -from typedcols import TypedDict, TypedList, KeyNotAllowed, KeysRequired, Discard, Any -from sys import version_info -import unittest - - -class AddressDict(TypedDict): - typedef = { - "street": {"type": str}, - "num": {"type": int, "description": "Street number"}, - "city": str, - "state": {"type": str, "required": True} - } - allow_unknown = True - -def raise_discard(x=None): - raise Discard - -class PersonDict(TypedDict): - typedef = { - "name": {"type": str, "default": "_Default_Value_"}, - "age": int, - "address": {"type": AddressDict}, - "tel": {"type": int, "required": True}, - "note": {}, - "discard1": Discard, - "discard2": {"type": Discard, "default": "asdf"}, - "discard3": lambda x: Discard, - "discard4": raise_discard, - "discard_default1": {"type": Any, "default": Discard}, # Same as no default - "discard_default2": {"type": Any, "default": raise_discard}, # Same as no default - } - allow_unknown = False - - -# Monkeypatching for cheap Py 2 & 3 compatibility -if not hasattr(unittest.TestCase, "assertRaisesRegex"): - unittest.TestCase.assertRaisesRegex = unittest.TestCase.assertRaisesRegexp - - -class TestTypedDict(unittest.TestCase): - - def setUp(self): - self.person = PersonDict({ - "age": "34", - "note": None, - "address": { - "street": "Vrchlikova", - "num": 12.3, - "city": "Kocourkov" - }, - "discard1": "junk", - "discard2": "garbage", - "discard3": "rubbish", - "discard4": "scrap" - }) - - def testTypedefNormalization(self): - self.assertEqual(self.person.typedef["age"], {"type": int}) - - def testInit(self): - self.assertEqual(self.person, { - "name": "_Default_Value_", - "age": 34, - "note": None, - "address": { - "street": "Vrchlikova", - "num": 12, - "city": "Kocourkov"}}) - - def testSetGetKnownOk(self): - self.person["address"]["city"] = "Brno" - self.assertEqual(self.person["address"]["city"], "Brno") - - def testSetKnownBadType(self): - with self.assertRaisesRegex(ValueError, r"\(\('num',\), \"invalid literal for int\(\) with base 10: 'WRONG'\", 'Street number'\)"): - self.person["address"]["num"] = "WRONG" - - def testUpdate(self): - self.person.clear() - with self.assertRaisesRegex(ValueError, r"\(\('age',\), \"invalid literal for int\(\) with base 10: 'bla'\"\)"): - self.person.update({ - "age": "bla" - }) - - def testUpdateNested(self): - self.person.clear() - with self.assertRaisesRegex(ValueError, r"\(\('address', 'num'\), \"invalid literal for int\(\) with base 10: 'asdf'\", 'Street number'\)"): - self.person.update({ - "address": { - "num": "asdf" - } - }) - - def testRequired(self): - with self.assertRaises(KeysRequired): - self.person.checkRequired() - - def testUnknown(self): - with self.assertRaisesRegex(KeyNotAllowed, r'unknown'): - self.person["unknown"] = "WRONG" - - def testDel(self): - del self.person["address"]["city"] - with self.assertRaisesRegex(KeyError, r"'city'"): - self.person["address"]["city"] - - def testDelDefault(self): - del self.person["name"] - self.assertEqual(self.person["name"], "_Default_Value_") - - def testIter(self): - try: - it = self.person.iteritems() - except AttributeError: - it = self.person.items() - res = sorted([v for v in it]) - self.assertEqual(res, [ - ("address", {"city": "Kocourkov", "street": "Vrchlikova", "num": 12}), - ("age", 34), - ("name", "_Default_Value_"), - ("note", None) - ]) - -class IntList(TypedList): - item_type = int - - -class TestTypedList(unittest.TestCase): - - def setUp(self): - self.intlist = IntList((1, 2.1, "3")) - - def testInit(self): - self.assertEqual(list(self.intlist), [1, 2, 3]) - - def testSetGetKnownOk(self): - self.intlist[2] = "4" - self.assertEqual(self.intlist[-1], 4) - - def testSetKnownBadType(self): - with self.assertRaisesRegex(ValueError, r"invalid literal for int\(\) with base 10: 'WRONG'"): - self.intlist[2] = "WRONG" - - def testDel(self): - del self.intlist[1] - self.assertEqual(list(self.intlist), [1, 3]) - - def testDelOutOfBounds(self): - with self.assertRaisesRegex(IndexError, r"list assignment index out of range"): - del self.intlist[3] - - def testIter(self): - res = [val for val in self.intlist] - self.assertEqual(res, [1, 2, 3]) - - -if __name__ == '__main__': - unittest.main() diff --git a/lib_python/lib/typedcols/typedcols.py b/lib_python/lib/typedcols/typedcols.py deleted file mode 100644 index e26ab15753e49608b5608259c405e74f6544061d..0000000000000000000000000000000000000000 --- a/lib_python/lib/typedcols/typedcols.py +++ /dev/null @@ -1,290 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- -# -# Copyright (c) 2016, CESNET, z. s. p. o. -# Use of this source is governed by an ISC license, see LICENSE file. - -"""Simple typed collections library. - -Defines TypedDict and TypedList, which enforce inserted types based on simple -type definition. -""" - -__version__ = '0.1.7' -__author__ = 'Pavel Kácha <pavel.kacha@cesnet.cz>' - -import collections -import abc - - -class KeyNotAllowed(LookupError): - """ Raised when untyped key is inserted on type, which does not allow - for untyped keys. - """ - - -class KeysRequired(LookupError): - """ Raised when required keys are missing in dictionary (usually on the - call of checkRequired method. - """ - -class Discard(Exception): - """ Sentinel class to signal expected dropping of the key. - Can be returned or raised from type enforcing callable, - and can itself be used as type enforcing callable. - """ - - @classmethod - def __call__(cls, x=None): - return cls - -def Any(v): - return v - - -class TypedDictMetaclass(abc.ABCMeta): - """ Metaclass for TypedDict, allowing simplified typedefs - if typedef is not - dict, simple type object is assumed and correct dict is created. - Metaclassed to be run just once for the class, not for each instance. - """ - - def dictifyTypedef(self, typedef): - for key in typedef: - tdef = typedef[key] - if not isinstance(tdef, collections.Mapping): - typedef[key] = {"type": tdef} - - def __init__(cls, name, bases, dct): - super(TypedDictMetaclass, cls).__init__(name, bases, dct) - cls.dictifyTypedef(cls.typedef) - - -class TypedDict(collections.MutableMapping): - """ Dictionary type abstract class, which supports checking of inserted - types, based on simple type definition. - - Must be subclassed, and subclass must populate 'typedef' dict, and may - also reassign allow_unknown and dict_class class attributes. - - typedef: dictionary with keys and their type definitions. Type definition - may be simple callable (int, string, check_func, - AnotherTypedDict), or dict with the following members: - "type": - type enforcing callable. If callable returns, raises - or is Discard, key will be silently discarded - "default": - new TypedDict subclass will be initialized with keys - with this value; deleted keys will also revert to it - "required": - bool, checkRequired method will report the key if not present - "description": - string, explaining field type in human readable terms - (will be used in exception explanations) - Type enforcing callable must take one argument, and return value, - coerced to expected type. Coercion may even be conversion, for example - arbitrary date string, converted to DateTime. - - allow_unknown: boolean, specifies whether dictionary allows unknown keys, - that means keys, which are not defined in 'typedef' - - dict_class: class or factory for underlying dict implementation - """ - - typedef = {} - allow_unknown = False - dict_class = dict - - def __init__(self, init_data=None): - self.data = self.dict_class() - self.clear() - self.update(init_data or {}) - - def clear(self): - self.data.clear() - for key in self.typedef.keys(): - self.initItemDefault(key) - - def initItemDefault(self, key): - """ Sets 'key' to the default value from typedef (if defined) """ - tdef = self.getTypedef(key) - try: - default = tdef["default"] - except KeyError: - pass - else: - if default is Discard: - return - try: - # Call if callable - default = default() - except Discard: - return - except TypeError: - pass - self[key] = default - - def getTypedef(self, key): - """ Get type definition for 'key'. - If key is not defined and allow_unknown is True, empty - definition is returned, otherwise KeyNotAllowed gets raised. - """ - tdef = {} - try: - tdef = self.typedef[key] - except KeyError: - if not self.allow_unknown: - raise KeyNotAllowed(key) - return tdef - - def checkRequired(self): - """ The class does not check missing items by itself (we need it to - be incomplete during creation and manipulation), so this checks - and return list of missing required keys explicitly. - - Note that the check is not recursive (as instance dictionary - may contain another subclasses of TypedDict), so care must - be taken if there is such concern. - """ - missing = () - for key, tdef in self.typedef.items(): - if tdef.get("required", False) and not key in self.data: - missing = missing + (key,) - if missing: - raise KeysRequired(missing) - - def __setitem__(self, key, value): - """ Setter with type coercion. - Any exception, raised from type enforcing callable, will get - modified - first .arg will be tuple of key hierarchy, last - .arg will be message from "description" field in type definition - """ - tdef = self.getTypedef(key) - valuetype = tdef.get("type", Any) - if valuetype is Discard: - return - try: - fvalue = valuetype(value) - except Discard: - return - except Exception as e: - if isinstance(e.args[0], tuple): - e.args = ((key,) + e.args[0],) + e.args[1:] - else: - e.args = ((key,),) + e.args - if len(e.args) < 3: - desc = tdef.get("description", None) - if desc is not None: - e.args = e.args + (desc,) - raise - if fvalue is Discard: - return - self.data[key] = fvalue - - def __getitem__(self, key): - return self.data[key] - - def __delitem__(self, key): - """ Deleter with reverting to defaults """ - del self.data[key] - self.initItemDefault(key) - - # Following definitions are not strictly necessary as MutableMapping - # already defines them, however we can override them by calling to - # possibly more optimized underlying implementations. - def __iter__(self): return iter(self.data) - - def itervalues(self): return self.data.itervalues() - - def iteritems(self): return self.data.iteritems() - - def keys(self): return self.data.keys() - - def values(self): return self.data.values() - - def __len__(self): return len(self.data) - - def __str__(self): return "%s(%s)" % (type(self).__name__, str(self.data)) - - def __repr__(self): return "%s(%s)" % (type(self).__name__, repr(self.data)) - - -# Py 2 requires metaclassing by __metaclass__ attribute, whereas Py 3 -# needs metaclass argument. What actually happens is the following, -# so we will do it explicitly, to be compatible with both versions. -TypedDict = TypedDictMetaclass("TypedDict", (TypedDict,), {}) - - -class TypedList(collections.MutableSequence): - """ List type abstract class, which supports checking of inserted items - type. - - Must be subclassed, and subclass must populate 'item_type' class - variable, and may also reassign list_class class attributes. - - item_type: type enforcing callable, wich must take one argument, and - return value, coerced to expected type. Coercion may even be - conversion, for example arbitrary date string, converted to - DateTime. Because defined within class, Python authomatically - makes it object method, so it must be wrapped in staticmethod(...) - explicitly. - list_class: class or factory for underlying list implementation - """ - - item_type = staticmethod(Any) - list_class = list - - def __init__(self, iterable): - self.data = self.list_class() - self.extend(iterable) - - def __getitem__(self, val): return self.data[val] - - def __delitem__(self, val): del self.data[val] - - def __len__(self): return len(self.data) - - def __setitem__(self, idx, val): - tval = self.item_type(val) - self.data[idx] = tval - - def insert(self, idx, val): - tval = self.item_type(val) - self.data.insert(idx, tval) - - # Following definitions are not strictly necessary as MutableSequence - # already defines them, however we can override them by calling to - # possibly more optimized underlying implementations. - - def __contains__(self, val): - tval = self.item_type(val) - return tval in self.data - - def index(self, val): - tval = self.item_type(val) - return self.data.index(tval) - - def count(self, val): - tval = self.item_type(val) - return self.data.count(tval) - - def __iter__(self): return iter(self.data) - - def reverse(self): return self.data.reverse() - - def __reversed__(self): return reversed(self.data) - - def pop(self, index=-1): return self.data.pop(index) - - def __str__(self): return "%s(%s)" % (type(self).__name__, str(self.data)) - - def __repr__(self): return "%s(%s)" % (type(self).__name__, repr(self.data)) - - -def typed_list(name, item_type): - """ Helper for oneshot type definition """ - return type(name, (TypedList,), dict(item_type=staticmethod(item_type))) - - -def typed_dict(name, allow_unknown, typedef): - """ Helper for oneshot type definition """ - return type(name, (TypedDict,), dict(allow_unknown=allow_unknown, typedef=typedef)) diff --git a/meta.json b/meta.json deleted file mode 100644 index 6af2717a6e158bb32fbfd8166f5f816456ab90ad..0000000000000000000000000000000000000000 --- a/meta.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "name": "libidea", - "version_minor": 19, - "version_major": "0.0", - "architecture": "all", - "server": "homeproj", - "server_dir_deb": "/var/reps/apt/mentat/incoming/squeeze/", - "server_dir_tar": "/var/reps/tar/mentat/" -} \ No newline at end of file diff --git a/package.json b/package.json deleted file mode 100644 index 280f73756d9fcc2d939e9830494ef08bffb91997..0000000000000000000000000000000000000000 --- a/package.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "name": "libidea", - "version": "0.0.1", - "devDependencies": { - "grunt": "~0.4.5", - "grunt-contrib-clean": "~0.6.0", - "grunt-contrib-concat": "~0.5.1", - "grunt-contrib-copy": "~0.8.0", - "grunt-contrib-rename": "0.0.3", - "grunt-ftp-deploy": "~0.1.10", - "grunt-shell": "~1.1.2", - "load-grunt-tasks": "~3.2.0", - "npm-shrinkwrap": "~5.4.0", - "time-grunt": "~1.2.1", - "grunt-template": "~0.2.3", - "grunt-chmod": "~1.1.1" - } -} diff --git a/lib_python/lib/idea-format/setup.py b/setup.py similarity index 100% rename from lib_python/lib/idea-format/setup.py rename to setup.py diff --git a/lib_python/lib/idea-format/test_idea.py b/test_idea.py similarity index 100% rename from lib_python/lib/idea-format/test_idea.py rename to test_idea.py