mirror of
https://github.com/cliffe/SecGen.git
synced 2026-02-21 19:28:02 +00:00
generators/date_generator: added mysql_datetime format
This commit is contained in:
0
modules/generators/content/date/date.pp
Normal file
0
modules/generators/content/date/date.pp
Normal file
43
modules/generators/content/date/secgen_local/local.rb
Normal file
43
modules/generators/content/date/secgen_local/local.rb
Normal 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
|
||||
22
modules/generators/content/date/secgen_metadata.xml
Normal file
22
modules/generators/content/date/secgen_metadata.xml
Normal 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>
|
||||
Reference in New Issue
Block a user