generators/date_generator: added mysql_datetime format

This commit is contained in:
thomashaw
2017-05-13 16:29:19 +01:00
parent 58907d171d
commit 034c2ec409
4 changed files with 65 additions and 0 deletions

View File

View File

@@ -0,0 +1,43 @@
#!/usr/bin/ruby
require 'json'
require 'time'
require_relative '../../../../../lib/objects/local_string_encoder.rb'
class DateGenerator < StringEncoder
attr_accessor :format
def initialize
super
self.module_name = 'Person Hash Builder'
self.format = ''
end
def encode_all
# Generate random date from epoch -> current time
date = Time.at(rand * Time.now.to_i)
if format == 'mysql_datetime'
date = Time.now.strftime('%Y-%m-%d %H:%M:%S')
end
self.outputs << date
end
def get_options_array
super + [['--format', GetoptLong::REQUIRED_ARGUMENT]]
end
def process_options(opt, arg)
super
case opt
when '--format'
self.format << arg;
end
end
def encoding_print_string
'format: ' + self.format.to_s
end
end
DateGenerator.new.run

View File

@@ -0,0 +1,22 @@
<?xml version="1.0"?>
<generator xmlns="http://www.github/cliffe/SecGen/generator"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.github/cliffe/SecGen/generator">
<name>Date Generator</name>
<author>Thomas Shaw</author>
<module_license>MIT</module_license>
<description>Date generator.</description>
<type>date_generator</type>
<platform>linux</platform>
<platform>windows</platform>
<read_fact>format</read_fact>
<default_input into="format">
<value>mysql_datetime</value>
</default_input>
<output_type>date</output_type>
</generator>