diff --git a/README.md b/README.md index 84fbfa0..1ee20cb 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,11 @@ Use [Etcher](https://www.balena.io/etcher/#download) or `dd` to create an bootab * `git submodule update` * `make release` +## Enable Label Printer ## + +Just install [reHDDPrinter](https://git.mosad.xyz/localhorst/reHDDPrinter). +No further settings needed. + ## Create Standalone with Debian 11 Instructions how to create a standalone machine that boots directly to reHDD. This is aimed for production use, like several drives a day shredding. diff --git a/include/drive.h b/include/drive.h index 25ab646..72037fe 100644 --- a/include/drive.h +++ b/include/drive.h @@ -33,9 +33,9 @@ public: bool bWasShredded = false; //all shred iterations done bool bWasChecked = false; //all shred iterations and optional checking done - bool bWasDeleteted = false; + bool bWasDeleted = false; bool bIsOffline = false; - uint32_t u32DriveChecksumAferShredding = 0U; + uint32_t u32DriveChecksumAfterShredding = 0U; private: string sPath; diff --git a/include/printer.h b/include/printer.h new file mode 100644 index 0000000..638c3e7 --- /dev/null +++ b/include/printer.h @@ -0,0 +1,60 @@ +/** + * @file printer.h + * @brief Send drive data to printer service using ipc msg queue + * @author Hendrik Schutter + * @date 24.11.2022 + */ + +#ifndef PRINTER_H_ +#define PRINTER_H_ + +#include "reHDD.h" + +#include +#include + +#define STR_BUFFER_SIZE 64U +#define IPC_MSG_QUEUE_KEY 0x1B11193C0 + +typedef struct +{ + char caDriveIndex[STR_BUFFER_SIZE]; + char caDriveHours[STR_BUFFER_SIZE]; + char caDriveCycles[STR_BUFFER_SIZE]; + char caDriveErrors[STR_BUFFER_SIZE]; + char caDriveShredTimestamp[STR_BUFFER_SIZE]; + char caDriveShredDuration[STR_BUFFER_SIZE]; + char caDriveCapacity[STR_BUFFER_SIZE]; + char caDriveState[STR_BUFFER_SIZE]; + char caDriveModelFamily[STR_BUFFER_SIZE]; + char caDriveModelName[STR_BUFFER_SIZE]; + char caDriveSerialnumber[STR_BUFFER_SIZE]; + char caDriveReHddVersion[STR_BUFFER_SIZE]; + +} t_driveData; + +typedef struct +{ + long msg_queue_type; + t_driveData driveData; +} t_msgQueueData; + + +class Printer +{ +protected: + +public: + static Printer* getPrinter(); + void print(Drive* drive); + +private: + static bool instanceFlag; + static Printer *single; + int msqid; + Printer(); + ~Printer(); + + +}; +#endif // PRINTER_H_ \ No newline at end of file diff --git a/include/reHDD.h b/include/reHDD.h index c15069b..2b88277 100644 --- a/include/reHDD.h +++ b/include/reHDD.h @@ -8,7 +8,7 @@ #ifndef REHDD_H_ #define REHDD_H_ -#define REHDD_VERSION "V1.0.0" +#define REHDD_VERSION "V1.1.0" // Drive handling Settings #define WORSE_HOURS 19200 //mark drive if at this limit or beyond @@ -64,6 +64,7 @@ using namespace std; #include "shred.h" #include "delete.h" #include "tui.h" +#include "printer.h" #include "logger/logger.h" extern Logger* logging; @@ -90,7 +91,7 @@ private: static void filterIgnoredDrives(list * plistDrives); static void filterNewDrives(list * plistOldDrives, list * plistNewDrives); static void addSMARTData(list * plistDrives); - static void ThreadScannDevices(); + static void ThreadScanDevices(); static void ThreadUserInput(); static void ThreadShred(Drive* const pDrive); static void ThreadDelete(); diff --git a/include/shred.h b/include/shred.h index c423d36..3da43bb 100644 --- a/include/shred.h +++ b/include/shred.h @@ -21,7 +21,7 @@ #define CHUNK_SIZE 1024*1024*32 //amount of bytes that are overwritten at once --> 32MB #define TFNG_DATA_SIZE CHUNK_SIZE //amount of bytes used by tfng -//#define DEMO_DRIVE_SIZE 1024*1024*256L // 256MB +#define DEMO_DRIVE_SIZE 1024*1024*256L // 256MB //#define DEMO_DRIVE_SIZE 1024*1024*1024L // 1GB //#define DEMO_DRIVE_SIZE 5*1024*1024*1024L // 5GB //#define DEMO_DRIVE_SIZE 1024*1024*1024*10L // 10GB diff --git a/src/drive.cpp b/src/drive.cpp index f31367f..b2190a0 100644 --- a/src/drive.cpp +++ b/src/drive.cpp @@ -182,7 +182,7 @@ void Drive::checkFrozenDrive(void) if((u32localtime - this->u32Timestamp) >= (FROZEN_TIMEOUT*60) && (this->u32Timestamp > 0) && (this->getTaskPercentage() < 100.0)) { Logger::logThis()->warning("Drive Frozen: " + this->getModelName() + " " + this->getSerial()); - this->bWasDeleteted = false; + this->bWasDeleted = false; this->bWasShredded = false; this->state = Drive::FROZEN; } diff --git a/src/logger/logger.cpp b/src/logger/logger.cpp index 5708359..f77021d 100644 --- a/src/logger/logger.cpp +++ b/src/logger/logger.cpp @@ -18,8 +18,6 @@ Logger* Logger::single = NULL; /** * \brief create new logger instance - * \param path to log file - * \param struct with data * \return instance of Logger */ Logger::Logger() diff --git a/src/printer.cpp b/src/printer.cpp new file mode 100644 index 0000000..e8db0bb --- /dev/null +++ b/src/printer.cpp @@ -0,0 +1,83 @@ +/** + * @file printer.cpp + * @brief Send drive data to printer service using ipc msg queue + * @author Hendrik Schutter + * @date 24.11.2022 + */ + +#include "../include/reHDD.h" + +bool Printer::instanceFlag = false; +Printer* Printer::single = NULL; + +/** + * \brief create new Printer instance + * \param path to log file + * \param struct with data + * \return instance of Printer + */ +Printer::Printer() +{ + if (-1 == (this->msqid = msgget((key_t)IPC_MSG_QUEUE_KEY, IPC_CREAT | 0666))) + { + Logger::logThis()->error("Printer: Create mgs queue failed!"); + } +} + +/** + * \brief deconstructor + * \return void + */ +Printer::~Printer() +{ + instanceFlag = false; +} + +/** + * \brief send data to msg queue + * \return void + */ +void Printer::print(Drive* drive) +{ + t_msgQueueData msgQueueData; + msgQueueData.msg_queue_type = 1; + + sprintf(msgQueueData.driveData.caDriveIndex, "%i",42); //TODO: get from tui + sprintf(msgQueueData.driveData.caDriveState, "shredded"); + strcpy(msgQueueData.driveData.caDriveModelFamily, drive->getModelFamily().c_str()); + strcpy(msgQueueData.driveData.caDriveModelName, drive->getModelName().c_str()); + sprintf(msgQueueData.driveData.caDriveCapacity, "%li", drive->getCapacity()); + strcpy(msgQueueData.driveData.caDriveSerialnumber, drive->getSerial().c_str()); + sprintf(msgQueueData.driveData.caDriveHours, "%i",drive->getPowerOnHours()); + sprintf(msgQueueData.driveData.caDriveCycles, "%i",drive->getPowerCycles()); + sprintf(msgQueueData.driveData.caDriveErrors, "%i",drive->getErrorCount()); + sprintf(msgQueueData.driveData.caDriveShredTimestamp, "%li",drive->getActionStartTimestamp()); + sprintf(msgQueueData.driveData.caDriveShredDuration, "%li",drive->getTaskDuration()); + sprintf(msgQueueData.driveData.caDriveReHddVersion, REHDD_VERSION); + + if (-1 == msgsnd(this->msqid, &msgQueueData, sizeof(t_msgQueueData) - sizeof(long), 0)) + { + Logger::logThis()->error("Printer: Send mgs queue failed!"); + }else{ + Logger::logThis()->info("Printer: print triggered - Drive: " + drive->getSerial()); + } +} + + +/** + * \brief return a instance of the printer + * \return printer obj + */ +Printer* Printer::getPrinter() +{ + if (!instanceFlag) + { + single = new Printer(); //create new obj + instanceFlag = true; + return single; + } + else + { + return single; //return existing obj + } +} \ No newline at end of file diff --git a/src/reHDD.cpp b/src/reHDD.cpp index 9f359b6..4ed5f68 100644 --- a/src/reHDD.cpp +++ b/src/reHDD.cpp @@ -15,7 +15,7 @@ static std::mutex mxDrives; list listNewDrives; //store found drives that are updated every 5sec -static list listDrives; //stores all drive data from scann thread +static list listDrives; //stores all drive data from scan thread TUI *ui; @@ -46,7 +46,7 @@ void reHDD::app_logic(void) pipe(fdNewDrivesInformPipe); pipe(fdShredInformPipe); - thread thDevices(ThreadScannDevices); //start thread that scanns for drives + thread thDevices(ThreadScanDevices); //start thread that scans for drives thread thUserInput(ThreadUserInput); //start thread that reads user input thread thCheckFrozenDrives(ThreadCheckFrozenDrives); //start thread that checks timeout for drives @@ -98,7 +98,7 @@ Drive* reHDD::getSelectedDrive() } } -void reHDD::ThreadScannDevices() +void reHDD::ThreadScanDevices() { while(true) { @@ -221,7 +221,7 @@ void reHDD::ThreadDelete() getSelectedDrive()->setActionStartTimestamp(); //save timestamp at start of deleting Delete::deleteDrive(getSelectedDrive()); //blocking, no thread getSelectedDrive()->state = Drive::TaskState::NONE; //delete finished - getSelectedDrive()->bWasDeleteted = true; + getSelectedDrive()->bWasDeleted = true; Logger::logThis()->info("Finished delete for: " + getSelectedDrive()->getModelName() + "-" + getSelectedDrive()->getSerial()); ui->updateTUI(&listDrives, u8SelectedEntry); } @@ -230,7 +230,7 @@ void reHDD::ThreadDelete() void reHDD::filterNewDrives(list * plistOldDrives, list * plistNewDrives) { list ::iterator itOld; //Iterator for current (old) drive list - list ::iterator itNew; //Iterator for new drive list that was created from to scann thread + list ::iterator itNew; //Iterator for new drive list that was created from to scan thread //remove offline old drives from previously run for (itOld = plistOldDrives->begin(); itOld != plistOldDrives->end();) @@ -263,9 +263,9 @@ void reHDD::filterNewDrives(list * plistOldDrives, list * plistNew //copy new smart data to existing drive itOld->setDriveSMARTData(itNew->getModelFamily(), itNew->getModelName(), itNew->getSerial(), itNew->getCapacity(), itNew->getErrorCount(), itNew->getPowerOnHours(), itNew->getPowerCycles(), itNew->getTemperature()); #ifdef LOG_LEVEL_HIGH - Logger::logThis()->info("Delete new drive, because allready attached: " + itNew->getModelName()); + Logger::logThis()->info("Delete new drive, because already attached: " + itNew->getModelName()); #endif - itNew = plistNewDrives->erase(itNew); //This drive is allready attached, remove from new list + itNew = plistNewDrives->erase(itNew); //This drive is already attached, remove from new list } else { @@ -334,15 +334,15 @@ void reHDD::searchDrives(list * plistDrives) */ void reHDD::filterIgnoredDrives(list * plistDrives) { - list> vtlIgnoredDevices; //store drives from ingnore file - ifstream input( "ignoreDrives.conf" ); //read ingnore file + list> vtlIgnoredDevices; //store drives from ignore file + ifstream input( "ignoreDrives.conf" ); //read ignore file for(string sLine; getline( input, sLine );) { //Logger::logThis()->info("read uuid: " + sLine); vtlIgnoredDevices.emplace_back(sLine); //add found path and uuid from ignore file to vector } - //loop through found entries in ingnore file + //loop through found entries in ignore file for(auto row : vtlIgnoredDevices) { list ::iterator it; diff --git a/src/shred.cpp b/src/shred.cpp index f8d92c1..65bf219 100644 --- a/src/shred.cpp +++ b/src/shred.cpp @@ -182,15 +182,15 @@ int Shred::shredDrive(Drive* drive, int* ipSignalFd) #ifdef ZERO_CHECK drive->state=Drive::CHECK_ACTIVE; Logger::logThis()->info("Check-Task started - Drive: " + drive->getModelName() + "-" + drive->getSerial() + " @" + address.str()); - drive->u32DriveChecksumAferShredding = uiCalcChecksum(driveFileDiscr, drive, ipSignalFd); + drive->u32DriveChecksumAfterShredding = uiCalcChecksum(driveFileDiscr, drive, ipSignalFd); #ifdef LOG_LEVEL_HIGH if (drive->u32DriveChecksumAferShredding != 0) { - Logger::logThis()->info("Shred-Task: Checksum not zero: " + to_string(drive->u32DriveChecksumAferShredding) + " - Drive: " + drive->getSerial()); + Logger::logThis()->info("Shred-Task: Checksum not zero: " + to_string(drive->u32DriveChecksumAfterShredding) + " - Drive: " + drive->getSerial()); } else { - Logger::logThis()->info("Shred-Task: Checksum zero: " + to_string(drive->u32DriveChecksumAferShredding) + " - Drive: " + drive->getSerial()); + Logger::logThis()->info("Shred-Task: Checksum zero: " + to_string(drive->u32DriveChecksumAfterShredding) + " - Drive: " + drive->getSerial()); } #endif #endif @@ -202,6 +202,7 @@ int Shred::shredDrive(Drive* drive, int* ipSignalFd) { drive->state= Drive::NONE; drive->setTaskPercentage(0.0); + Printer::getPrinter()->print(drive); Logger::logThis()->info("Finished shred/check for: " + drive->getModelName() + "-" + drive->getSerial()); } return 0; diff --git a/src/tui.cpp b/src/tui.cpp index 699d8f0..ae43f4a 100644 --- a/src/tui.cpp +++ b/src/tui.cpp @@ -128,7 +128,7 @@ void TUI::updateTUI(list * plistDrives, uint8_t u8SelectedEntry) case Drive::NONE: case Drive::SHRED_SELECTED: case Drive::DELETE_SELECTED: - if (it->bWasDeleteted) + if (it->bWasDeleted) { sState = "DELETED"; //mark drive as deleted previously } @@ -148,9 +148,9 @@ void TUI::updateTUI(list * plistDrives, uint8_t u8SelectedEntry) } #ifdef ZERO_CHECK - if(bSelectedEntry && it->bWasChecked && (it->u32DriveChecksumAferShredding != 0U)) + if(bSelectedEntry && it->bWasChecked && (it->u32DriveChecksumAfterShredding != 0U)) { - dialog=createZeroChecksumWarning(70, 16, ((u16StdscrX)-(int)(u16StdscrX/2)-20),(int)(u16StdscrY/2)-8, it->getPath(), it->getModelFamily(), it->getModelName(), it->getSerial(), it->u32DriveChecksumAferShredding); + dialog=createZeroChecksumWarning(70, 16, ((u16StdscrX)-(int)(u16StdscrX/2)-20),(int)(u16StdscrY/2)-8, it->getPath(), it->getModelFamily(), it->getModelName(), it->getSerial(), it->u32DriveChecksumAfterShredding); wrefresh(dialog); } #endif @@ -275,7 +275,7 @@ WINDOW* TUI::createDetailViewWindow( int iXSize, int iYSize, int iXStart, Drive centerTitle(newWindow, title.c_str()); string sPath = "Path: " +drive.getPath(); - string sModelFamlily = "ModelFamily: " + drive.getModelFamily(); + string sModelFamily = "ModelFamily: " + drive.getModelFamily(); string sModelName = "ModelName: " + drive.getModelName(); string sCapacity = "Capacity: " + drive.sCapacityToText(); string sSerial = "Serial: " + drive.getSerial(); @@ -286,7 +286,7 @@ WINDOW* TUI::createDetailViewWindow( int iXSize, int iYSize, int iXStart, Drive uint16_t u16Line = 2; mvwaddstr(newWindow,u16Line++, 3, sPath.c_str()); - mvwaddstr(newWindow,u16Line++, 3, sModelFamlily.c_str()); + mvwaddstr(newWindow,u16Line++, 3, sModelFamily.c_str()); mvwaddstr(newWindow,u16Line++, 3, sModelName.c_str()); mvwaddstr(newWindow,u16Line++, 3, sCapacity.c_str()); mvwaddstr(newWindow,u16Line++, 3, sSerial.c_str()); @@ -315,7 +315,7 @@ WINDOW* TUI::overwriteDetailViewWindow( int iXSize, int iYSize, int iXStart) string sLine03 = "Available under GPL 3.0"; string sLine04 = "https://git.mosad.xyz/localhorst/reHDD"; string sLine05 = "Delete: Wipe format table - this is NOT secure"; - string sLine06 = "Shred: Overwite drive " + to_string(SHRED_ITERATIONS) + " iterations - this is secure"; + string sLine06 = "Shred: Overwrite drive " + to_string(SHRED_ITERATIONS) + " iterations - this is secure"; uint16_t u16Line = 5; @@ -544,7 +544,7 @@ WINDOW* TUI::createZeroChecksumWarning(int iXSize, int iYSize, int iXStart, int string sLine01 = "Please detach this drive and check it manually:"; string sShredChecksum = "After shredding the checksum was: " + to_string(u32Checksum); string sLinePath = "Path: " +sPath; - string sLineModelFamlily = "ModelFamily: " + sModelFamily; + string sLineModelFamily = "ModelFamily: " + sModelFamily; string sLineModelName = "ModelName: " + sModelName; string sLineSerial = "Serial: " + sSerial; @@ -557,7 +557,7 @@ WINDOW* TUI::createZeroChecksumWarning(int iXSize, int iYSize, int iXStart, int mvwaddstr(newWindow,u16Line++, 3, sLine01.c_str()); u16Line++; mvwaddstr(newWindow,u16Line++, 3, sLinePath.c_str()); - mvwaddstr(newWindow,u16Line++, 3, sLineModelFamlily.c_str()); + mvwaddstr(newWindow,u16Line++, 3, sLineModelFamily.c_str()); mvwaddstr(newWindow,u16Line++, 3, sLineModelName.c_str()); mvwaddstr(newWindow,u16Line++, 3, sLineSerial.c_str()); u16Line++; @@ -695,7 +695,7 @@ WINDOW* TUI::createSmartWarning(int iXSize, int iYSize, int iXStart, int iYStart if(u32ErrorCount > 0) { - string sLineTmp = "S.M.A.R.T. erros detected: " + to_string(u32ErrorCount); + string sLineTmp = "S.M.A.R.T. errors detected: " + to_string(u32ErrorCount); mvwaddstr(newWindow,u16Line++, (iXSize/2)-(sLine01.size()/2), sLineTmp.c_str()); u16Line++; }