mirror of
https://github.com/martijnvanbrummelen/nwipe.git
synced 2026-02-20 13:42:14 +00:00
Merge pull request #684 from PartialVolume/add_hostid_option_to_pdf
Add user selectable host information to the PDF
This commit is contained in:
@@ -72,6 +72,9 @@ Do not show the GUI interface. Can only be used with the autonuke option.
|
||||
Nowait option is automatically invoked with the nogui option.
|
||||
SIGUSR1 can be used to retrieve the current wiping statistics.
|
||||
.TP
|
||||
\fB\-\-pdftag\fR
|
||||
Enables a field on the PDF that holds a tag that identifies the host computer
|
||||
.TP
|
||||
\fB\-v\fR, \fB\-\-verbose\fR
|
||||
Log more messages, useful for debugging.
|
||||
.TP
|
||||
|
||||
@@ -122,6 +122,7 @@ int nwipe_conf_init()
|
||||
*/
|
||||
nwipe_conf_populate( "PDF_Certificate.PDF_Enable", "ENABLED" );
|
||||
nwipe_conf_populate( "PDF_Certificate.PDF_Preview", "DISABLED" );
|
||||
nwipe_conf_populate( "PDF_Certificate.PDF_tag", "DISABLED" );
|
||||
|
||||
/**
|
||||
* The currently selected customer that will be printed on the report
|
||||
|
||||
@@ -50,8 +50,9 @@
|
||||
struct pdf_doc* pdf;
|
||||
struct pdf_object* page;
|
||||
|
||||
char model_header[50] = ""; /* Model text in the header */
|
||||
char serial_header[30] = ""; /* Serial number text in the header */
|
||||
char model_header[55] = ""; /* Model text in the header */
|
||||
char serial_header[35] = ""; /* Serial number text in the header */
|
||||
char hostid_header[DMIDECODE_RESULT_LENGTH + 15] = ""; /* host identification, UUID, serial number, system tag */
|
||||
char barcode[100] = ""; /* Contents of the barcode, i.e model:serial */
|
||||
char pdf_footer[MAX_PDF_FOOTER_TEXT_LENGTH];
|
||||
float height;
|
||||
@@ -129,10 +130,19 @@ int create_pdf( nwipe_context_t* ptr )
|
||||
/* Obtain page page_width */
|
||||
page_width = pdf_page_width( page_1 );
|
||||
|
||||
/**********************************************
|
||||
* Initialise serial no. to unknown if empty
|
||||
*/
|
||||
if( c->device_serial_no[0] == 0 )
|
||||
{
|
||||
snprintf( c->device_serial_no, sizeof( c->device_serial_no ), "Unknown" );
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* Create header and footer on page 1, with the exception of the green
|
||||
* tick/red icon which is set from the 'status' section below
|
||||
*/
|
||||
|
||||
pdf_header_footer_text( c, "Page 1 - Erasure Status" );
|
||||
|
||||
/* ------------------------ */
|
||||
@@ -228,10 +238,6 @@ int create_pdf( nwipe_context_t* ptr )
|
||||
* Serial no.
|
||||
*/
|
||||
pdf_add_text( pdf, NULL, "Serial:", 12, 340, 410, PDF_GRAY );
|
||||
if( c->device_serial_no[0] == 0 )
|
||||
{
|
||||
snprintf( c->device_serial_no, sizeof( c->device_serial_no ), "Unknown" );
|
||||
}
|
||||
pdf_set_font( pdf, "Helvetica-Bold" );
|
||||
pdf_add_text( pdf, NULL, c->device_serial_no, text_size_data, 380, 410, PDF_BLACK );
|
||||
pdf_set_font( pdf, "Helvetica" );
|
||||
@@ -994,19 +1000,38 @@ void create_header_and_footer( nwipe_context_t* c, char* page_title )
|
||||
|
||||
void pdf_header_footer_text( nwipe_context_t* c, char* page_title )
|
||||
{
|
||||
extern char dmidecode_system_serial_number[DMIDECODE_RESULT_LENGTH];
|
||||
extern char dmidecode_system_uuid[DMIDECODE_RESULT_LENGTH];
|
||||
|
||||
pdf_add_text_wrap( pdf, NULL, pdf_footer, 12, 0, 30, PDF_BLACK, page_width, PDF_ALIGN_CENTER, &height );
|
||||
pdf_add_line( pdf, NULL, 50, 50, 550, 50, 3, PDF_BLACK );
|
||||
pdf_add_line( pdf, NULL, 50, 650, 550, 650, 3, PDF_BLACK );
|
||||
pdf_add_line( pdf, NULL, 50, 50, 550, 50, 3, PDF_BLACK ); // Footer full width Line
|
||||
pdf_add_line( pdf, NULL, 50, 650, 550, 650, 3, PDF_BLACK ); // Header full width Line
|
||||
pdf_add_line( pdf, NULL, 175, 728, 425, 728, 3, PDF_BLACK ); // Header Page number, disk model divider line
|
||||
pdf_add_image_data( pdf, NULL, 45, 665, 100, 100, bin2c_shred_db_jpg, 27063 );
|
||||
pdf_set_font( pdf, "Helvetica-Bold" );
|
||||
snprintf( model_header, sizeof( model_header ), " %s: %s ", "Model", c->device_model );
|
||||
pdf_add_text_wrap( pdf, NULL, model_header, 14, 0, 755, PDF_BLACK, page_width, PDF_ALIGN_CENTER, &height );
|
||||
snprintf( serial_header, sizeof( serial_header ), " %s: %s ", "S/N", c->device_serial_no );
|
||||
pdf_add_text_wrap( pdf, NULL, serial_header, 14, 0, 735, PDF_BLACK, page_width, PDF_ALIGN_CENTER, &height );
|
||||
|
||||
if( nwipe_options.PDFtag )
|
||||
{
|
||||
snprintf( model_header, sizeof( model_header ), " %s: %s ", "Disk Model", c->device_model );
|
||||
pdf_add_text_wrap( pdf, NULL, model_header, 11, 0, 710, PDF_BLACK, page_width, PDF_ALIGN_CENTER, &height );
|
||||
snprintf( serial_header, sizeof( serial_header ), " %s: %s ", "Disk S/N", c->device_serial_no );
|
||||
pdf_add_text_wrap( pdf, NULL, serial_header, 11, 0, 695, PDF_BLACK, page_width, PDF_ALIGN_CENTER, &height );
|
||||
snprintf( hostid_header, sizeof( hostid_header ), " %s: %s ", "System S/N", dmidecode_system_serial_number );
|
||||
pdf_add_text_wrap( pdf, NULL, hostid_header, 11, 0, 680, PDF_BLACK, page_width, PDF_ALIGN_CENTER, &height );
|
||||
snprintf( hostid_header, sizeof( hostid_header ), " %s: %s ", "System uuid", dmidecode_system_uuid );
|
||||
pdf_add_text_wrap( pdf, NULL, hostid_header, 11, 0, 665, PDF_BLACK, page_width, PDF_ALIGN_CENTER, &height );
|
||||
}
|
||||
else
|
||||
{
|
||||
snprintf( model_header, sizeof( model_header ), " %s: %s ", "Disk Model", c->device_model );
|
||||
pdf_add_text_wrap( pdf, NULL, model_header, 11, 0, 695, PDF_BLACK, page_width, PDF_ALIGN_CENTER, &height );
|
||||
snprintf( serial_header, sizeof( serial_header ), " %s: %s ", "Disk S/N", c->device_serial_no );
|
||||
pdf_add_text_wrap( pdf, NULL, serial_header, 11, 0, 680, PDF_BLACK, page_width, PDF_ALIGN_CENTER, &height );
|
||||
}
|
||||
pdf_set_font( pdf, "Helvetica" );
|
||||
|
||||
pdf_add_text_wrap( pdf, NULL, "Disk Erasure Report", 24, 0, 695, PDF_BLACK, page_width, PDF_ALIGN_CENTER, &height );
|
||||
pdf_add_text_wrap( pdf, NULL, "Disk Erasure Report", 24, 0, 760, PDF_BLACK, page_width, PDF_ALIGN_CENTER, &height );
|
||||
snprintf( barcode, sizeof( barcode ), "%s:%s", c->device_model, c->device_serial_no );
|
||||
pdf_add_text_wrap( pdf, NULL, page_title, 14, 0, 670, PDF_BLACK, page_width, PDF_ALIGN_CENTER, &height );
|
||||
pdf_add_text_wrap( pdf, NULL, page_title, 14, 0, 740, PDF_BLACK, page_width, PDF_ALIGN_CENTER, &height );
|
||||
pdf_add_barcode( pdf, NULL, PDF_BARCODE_128A, 100, 790, 400, 25, barcode, PDF_BLACK );
|
||||
}
|
||||
|
||||
@@ -507,6 +507,11 @@ void nwipe_log_OSinfo()
|
||||
return;
|
||||
}
|
||||
|
||||
/* Globally accessable dmidecode host identifiable data. */
|
||||
char dmidecode_system_serial_number[DMIDECODE_RESULT_LENGTH];
|
||||
char dmidecode_system_uuid[DMIDECODE_RESULT_LENGTH];
|
||||
char dmidecode_baseboard_serial_number[DMIDECODE_RESULT_LENGTH];
|
||||
|
||||
int nwipe_log_sysinfo()
|
||||
{
|
||||
FILE* fp;
|
||||
@@ -559,9 +564,16 @@ int nwipe_log_sysinfo()
|
||||
char cmd[sizeof( dmidecode_keywords ) + sizeof( dmidecode_command2 )];
|
||||
|
||||
unsigned int keywords_idx;
|
||||
unsigned int i;
|
||||
|
||||
keywords_idx = 0;
|
||||
|
||||
/* Initialise every character in the string with zero */
|
||||
for( i = 0; i < DMIDECODE_RESULT_LENGTH; i++ )
|
||||
{
|
||||
dmidecode_system_serial_number[i] = 0;
|
||||
}
|
||||
|
||||
p_dmidecode_command = 0;
|
||||
|
||||
if( system( "which dmidecode > /dev/null 2>&1" ) )
|
||||
@@ -619,11 +631,35 @@ int nwipe_log_sysinfo()
|
||||
else
|
||||
{
|
||||
nwipe_log( NWIPE_LOG_INFO, "%s = %s", &dmidecode_keywords[keywords_idx][0][0], path );
|
||||
|
||||
/* if system-serial-number copy result to extern string */
|
||||
if( keywords_idx == 5 )
|
||||
{
|
||||
strncpy( dmidecode_system_serial_number, path, DMIDECODE_RESULT_LENGTH );
|
||||
dmidecode_system_serial_number[DMIDECODE_RESULT_LENGTH - 1] = 0;
|
||||
}
|
||||
if( keywords_idx == 6 )
|
||||
{
|
||||
strncpy( dmidecode_system_uuid, path, DMIDECODE_RESULT_LENGTH );
|
||||
dmidecode_system_uuid[DMIDECODE_RESULT_LENGTH - 1] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
nwipe_log( NWIPE_LOG_INFO, "%s = %s", &dmidecode_keywords[keywords_idx][0][0], path );
|
||||
|
||||
/* if system-serial-number copy result to extern string */
|
||||
if( keywords_idx == 5 )
|
||||
{
|
||||
strncpy( dmidecode_system_serial_number, path, DMIDECODE_RESULT_LENGTH );
|
||||
dmidecode_system_serial_number[DMIDECODE_RESULT_LENGTH - 1] = 0;
|
||||
}
|
||||
if( keywords_idx == 6 )
|
||||
{
|
||||
strncpy( dmidecode_system_uuid, path, DMIDECODE_RESULT_LENGTH );
|
||||
dmidecode_system_uuid[DMIDECODE_RESULT_LENGTH - 1] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* close */
|
||||
|
||||
@@ -29,6 +29,8 @@
|
||||
#define OS_info_Line_offset 31 /* OS_info line offset in log */
|
||||
#define OS_info_Line_Length 48 /* OS_info line length */
|
||||
|
||||
#define DMIDECODE_RESULT_LENGTH 64
|
||||
|
||||
typedef enum nwipe_log_t_ {
|
||||
NWIPE_LOG_NONE = 0,
|
||||
NWIPE_LOG_DEBUG, // Output only when --verbose option used on cmd line.
|
||||
|
||||
@@ -117,6 +117,9 @@ int nwipe_options_parse( int argc, char** argv )
|
||||
/* Verify that wipe patterns are being written to the device. */
|
||||
{ "verify", required_argument, 0, 0 },
|
||||
|
||||
/* Enables a field on the PDF that holds a tag that identifies the host computer */
|
||||
{ "pdftag", no_argument, 0, 0 },
|
||||
|
||||
/* Display program version. */
|
||||
{ "verbose", no_argument, 0, 'v' },
|
||||
|
||||
@@ -142,11 +145,12 @@ int nwipe_options_parse( int argc, char** argv )
|
||||
nwipe_options.sync = DEFAULT_SYNC_RATE;
|
||||
nwipe_options.verbose = 0;
|
||||
nwipe_options.verify = NWIPE_VERIFY_LAST;
|
||||
nwipe_options.PDFtag = 0;
|
||||
memset( nwipe_options.logfile, '\0', sizeof( nwipe_options.logfile ) );
|
||||
memset( nwipe_options.PDFreportpath, '\0', sizeof( nwipe_options.PDFreportpath ) );
|
||||
strncpy( nwipe_options.PDFreportpath, ".", 2 );
|
||||
|
||||
/* Read PDF settings from nwipe.conf if available */
|
||||
/* Read PDF Enable/Disable settings from nwipe.conf if available */
|
||||
if( ( ret = nwipe_conf_read_setting( "PDF_Certificate.PDF_Enable", &read_value ) ) )
|
||||
{
|
||||
/* error occurred */
|
||||
@@ -180,6 +184,40 @@ int nwipe_options_parse( int argc, char** argv )
|
||||
}
|
||||
}
|
||||
|
||||
/* Read PDF tag Enable/Disable settings from nwipe.conf if available */
|
||||
if( ( ret = nwipe_conf_read_setting( "PDF_Certificate.PDF_tag", &read_value ) ) )
|
||||
{
|
||||
/* error occurred */
|
||||
nwipe_log( NWIPE_LOG_ERROR,
|
||||
"nwipe_conf_read_setting():Error reading PDF_Certificate.PDF_tag from nwipe.conf, ret code %i",
|
||||
ret );
|
||||
|
||||
/* Use default values */
|
||||
nwipe_options.PDFtag = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( !strcmp( read_value, "ENABLED" ) )
|
||||
{
|
||||
nwipe_options.PDFtag = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( !strcmp( read_value, "DISABLED" ) )
|
||||
{
|
||||
nwipe_options.PDFtag = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
// error occurred
|
||||
nwipe_log(
|
||||
NWIPE_LOG_ERROR,
|
||||
"PDF_Certificate.PDF_tag in nwipe.conf returned a value that was neither ENABLED or DISABLED" );
|
||||
nwipe_options.PDFtag = 0; // Default to Enabled
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* PDF Preview enable/disable */
|
||||
if( ( ret = nwipe_conf_read_setting( "PDF_Certificate.PDF_Preview", &read_value ) ) )
|
||||
{
|
||||
@@ -321,6 +359,12 @@ int nwipe_options_parse( int argc, char** argv )
|
||||
exit( EINVAL );
|
||||
}
|
||||
|
||||
if( strcmp( nwipe_options_long[i].name, "pdftag" ) == 0 )
|
||||
{
|
||||
nwipe_options.PDFtag = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
/* getopt_long should raise on invalid option, so we should never get here. */
|
||||
exit( EINVAL );
|
||||
|
||||
@@ -739,6 +783,8 @@ void display_help()
|
||||
puts( " option. Send SIGUSR1 to log current stats.\n" );
|
||||
puts( " --nousb Do NOT show or wipe any USB devices whether in GUI" );
|
||||
puts( " mode, --nogui or --autonuke modes.\n" );
|
||||
puts( " --pdftag Enables a field on the PDF that holds a tag that\n" );
|
||||
puts( " identifies the host computer\n" );
|
||||
puts( " -e, --exclude=DEVICES Up to ten comma separated devices to be excluded." );
|
||||
puts( " --exclude=/dev/sdc" );
|
||||
puts( " --exclude=/dev/sdc,/dev/sdd" );
|
||||
|
||||
@@ -67,6 +67,7 @@ typedef struct
|
||||
int verbose; // Make log more verbose
|
||||
int PDF_enable; // 0=PDF creation disabled, 1=PDF creation enabled
|
||||
int PDF_preview_details; // 0=Disable preview Org/Cust/date/time before drive selection, 1=Enable Preview
|
||||
int PDFtag; // Enable display of hostID, such as UUID or serial no. on PDF report.
|
||||
nwipe_verify_t verify; // A flag to indicate whether writes should be verified.
|
||||
} nwipe_options_t;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user