Add user selectable host information

You can now specify --pdftag to enable the
display of system UUID and system serial
number information on the PDF report.

Nwipe defaults to not displaying system IDs
but some users like to record the system UUID
or serial number on the Erasure Report along
with the disk information.
This commit is contained in:
PartialVolume
2025-11-18 18:44:41 +00:00
parent ae3a8a51d1
commit 0801ca7ae8
7 changed files with 129 additions and 15 deletions

View File

@@ -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. Nowait option is automatically invoked with the nogui option.
SIGUSR1 can be used to retrieve the current wiping statistics. SIGUSR1 can be used to retrieve the current wiping statistics.
.TP .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 \fB\-v\fR, \fB\-\-verbose\fR
Log more messages, useful for debugging. Log more messages, useful for debugging.
.TP .TP

View File

@@ -122,6 +122,7 @@ int nwipe_conf_init()
*/ */
nwipe_conf_populate( "PDF_Certificate.PDF_Enable", "ENABLED" ); nwipe_conf_populate( "PDF_Certificate.PDF_Enable", "ENABLED" );
nwipe_conf_populate( "PDF_Certificate.PDF_Preview", "DISABLED" ); 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 * The currently selected customer that will be printed on the report

View File

@@ -50,8 +50,9 @@
struct pdf_doc* pdf; struct pdf_doc* pdf;
struct pdf_object* page; struct pdf_object* page;
char model_header[50] = ""; /* Model text in the header */ char model_header[55] = ""; /* Model text in the header */
char serial_header[30] = ""; /* Serial number 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 barcode[100] = ""; /* Contents of the barcode, i.e model:serial */
char pdf_footer[MAX_PDF_FOOTER_TEXT_LENGTH]; char pdf_footer[MAX_PDF_FOOTER_TEXT_LENGTH];
float height; float height;
@@ -129,10 +130,19 @@ int create_pdf( nwipe_context_t* ptr )
/* Obtain page page_width */ /* Obtain page page_width */
page_width = pdf_page_width( page_1 ); 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 * Create header and footer on page 1, with the exception of the green
* tick/red icon which is set from the 'status' section below * tick/red icon which is set from the 'status' section below
*/ */
pdf_header_footer_text( c, "Page 1 - Erasure Status" ); pdf_header_footer_text( c, "Page 1 - Erasure Status" );
/* ------------------------ */ /* ------------------------ */
@@ -228,10 +238,6 @@ int create_pdf( nwipe_context_t* ptr )
* Serial no. * Serial no.
*/ */
pdf_add_text( pdf, NULL, "Serial:", 12, 340, 410, PDF_GRAY ); 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_set_font( pdf, "Helvetica-Bold" );
pdf_add_text( pdf, NULL, c->device_serial_no, text_size_data, 380, 410, PDF_BLACK ); pdf_add_text( pdf, NULL, c->device_serial_no, text_size_data, 380, 410, PDF_BLACK );
pdf_set_font( pdf, "Helvetica" ); 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 ) 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_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, 50, 550, 50, 3, PDF_BLACK ); // Footer full width Line
pdf_add_line( pdf, NULL, 50, 650, 550, 650, 3, PDF_BLACK ); 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_add_image_data( pdf, NULL, 45, 665, 100, 100, bin2c_shred_db_jpg, 27063 );
pdf_set_font( pdf, "Helvetica-Bold" ); 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 ); if( nwipe_options.PDFtag )
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 ); 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_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 ); 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 ); pdf_add_barcode( pdf, NULL, PDF_BARCODE_128A, 100, 790, 400, 25, barcode, PDF_BLACK );
} }

View File

@@ -507,6 +507,11 @@ void nwipe_log_OSinfo()
return; 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() int nwipe_log_sysinfo()
{ {
FILE* fp; FILE* fp;
@@ -559,9 +564,16 @@ int nwipe_log_sysinfo()
char cmd[sizeof( dmidecode_keywords ) + sizeof( dmidecode_command2 )]; char cmd[sizeof( dmidecode_keywords ) + sizeof( dmidecode_command2 )];
unsigned int keywords_idx; unsigned int keywords_idx;
unsigned int i;
keywords_idx = 0; 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; p_dmidecode_command = 0;
if( system( "which dmidecode > /dev/null 2>&1" ) ) if( system( "which dmidecode > /dev/null 2>&1" ) )
@@ -619,11 +631,35 @@ int nwipe_log_sysinfo()
else else
{ {
nwipe_log( NWIPE_LOG_INFO, "%s = %s", &dmidecode_keywords[keywords_idx][0][0], path ); 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 else
{ {
nwipe_log( NWIPE_LOG_INFO, "%s = %s", &dmidecode_keywords[keywords_idx][0][0], path ); 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 */ /* close */

View File

@@ -29,6 +29,8 @@
#define OS_info_Line_offset 31 /* OS_info line offset in log */ #define OS_info_Line_offset 31 /* OS_info line offset in log */
#define OS_info_Line_Length 48 /* OS_info line length */ #define OS_info_Line_Length 48 /* OS_info line length */
#define DMIDECODE_RESULT_LENGTH 64
typedef enum nwipe_log_t_ { typedef enum nwipe_log_t_ {
NWIPE_LOG_NONE = 0, NWIPE_LOG_NONE = 0,
NWIPE_LOG_DEBUG, // Output only when --verbose option used on cmd line. NWIPE_LOG_DEBUG, // Output only when --verbose option used on cmd line.

View File

@@ -117,6 +117,9 @@ int nwipe_options_parse( int argc, char** argv )
/* Verify that wipe patterns are being written to the device. */ /* Verify that wipe patterns are being written to the device. */
{ "verify", required_argument, 0, 0 }, { "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. */ /* Display program version. */
{ "verbose", no_argument, 0, 'v' }, { "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.sync = DEFAULT_SYNC_RATE;
nwipe_options.verbose = 0; nwipe_options.verbose = 0;
nwipe_options.verify = NWIPE_VERIFY_LAST; nwipe_options.verify = NWIPE_VERIFY_LAST;
nwipe_options.PDFtag = 0;
memset( nwipe_options.logfile, '\0', sizeof( nwipe_options.logfile ) ); memset( nwipe_options.logfile, '\0', sizeof( nwipe_options.logfile ) );
memset( nwipe_options.PDFreportpath, '\0', sizeof( nwipe_options.PDFreportpath ) ); memset( nwipe_options.PDFreportpath, '\0', sizeof( nwipe_options.PDFreportpath ) );
strncpy( nwipe_options.PDFreportpath, ".", 2 ); 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 ) ) ) if( ( ret = nwipe_conf_read_setting( "PDF_Certificate.PDF_Enable", &read_value ) ) )
{ {
/* error occurred */ /* 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 */ /* PDF Preview enable/disable */
if( ( ret = nwipe_conf_read_setting( "PDF_Certificate.PDF_Preview", &read_value ) ) ) 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 ); 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. */ /* getopt_long should raise on invalid option, so we should never get here. */
exit( EINVAL ); exit( EINVAL );
@@ -732,6 +776,8 @@ void display_help()
puts( " option. Send SIGUSR1 to log current stats.\n" ); puts( " option. Send SIGUSR1 to log current stats.\n" );
puts( " --nousb Do NOT show or wipe any USB devices whether in GUI" ); puts( " --nousb Do NOT show or wipe any USB devices whether in GUI" );
puts( " mode, --nogui or --autonuke modes.\n" ); 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( " -e, --exclude=DEVICES Up to ten comma separated devices to be excluded." );
puts( " --exclude=/dev/sdc" ); puts( " --exclude=/dev/sdc" );
puts( " --exclude=/dev/sdc,/dev/sdd" ); puts( " --exclude=/dev/sdc,/dev/sdd" );

View File

@@ -68,6 +68,7 @@ typedef struct
int verbose; // Make log more verbose int verbose; // Make log more verbose
int PDF_enable; // 0=PDF creation disabled, 1=PDF creation enabled 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 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_verify_t verify; // A flag to indicate whether writes should be verified.
} nwipe_options_t; } nwipe_options_t;