12 Commits

8 changed files with 102 additions and 11 deletions

View File

@ -9,7 +9,7 @@
* process multiple drives at once * process multiple drives at once
## Download USB Image ## ## Download USB Image ##
[2.5GB image v1.0.0](https://schuttercloud.com/s/ggxGH9sA326aRfK) (`wget` is your friend) See reHDD-Bootable how the live image created: https://git.mosad.xyz/localhorst/reHDD-Bootable
Use [Etcher](https://www.balena.io/etcher/#download) or `dd` to create an bootable USB drive . Use [Etcher](https://www.balena.io/etcher/#download) or `dd` to create an bootable USB drive .

View File

@ -34,6 +34,7 @@ public:
} sShredSpeed; } sShredSpeed;
bool bWasShredded = false; // all shred iterations done bool bWasShredded = false; // all shred iterations done
bool bWasShredStarted = false; // shred was atleast once started
bool bWasChecked = false; // all shred iterations and optional checking done bool bWasChecked = false; // all shred iterations and optional checking done
bool bWasDeleted = false; bool bWasDeleted = false;
bool bIsOffline = false; bool bIsOffline = false;

View File

@ -8,7 +8,7 @@
#ifndef REHDD_H_ #ifndef REHDD_H_
#define REHDD_H_ #define REHDD_H_
#define REHDD_VERSION "V1.1.2" #define REHDD_VERSION "V1.1.3"
// Drive handling Settings // Drive handling Settings
#define WORSE_HOURS 19200 // mark drive if at this limit or beyond #define WORSE_HOURS 19200 // mark drive if at this limit or beyond
@ -31,7 +31,7 @@
#endif #endif
// Logic // Logic
//#define DRYRUN //don´t touch the drives //#define DRYRUN // don't touch the drives
#define FROZEN_ALERT // show alert if drive is frozen #define FROZEN_ALERT // show alert if drive is frozen
#define ZERO_CHECK // check drive after shred if all bytes are zero, show alert if this fails #define ZERO_CHECK // check drive after shred if all bytes are zero, show alert if this fails
@ -101,6 +101,7 @@ private:
static void handleESC(); static void handleESC();
static void handleAbort(); static void handleAbort();
static Drive *getSelectedDrive(); static Drive *getSelectedDrive();
static bool getSystemDrive(string &systemDrive);
}; };
#endif // REHDD_H_ #endif // REHDD_H_

View File

@ -32,6 +32,9 @@ void Delete::deleteDrive(Drive *drive)
const char *cpComand = sCMD.c_str(); const char *cpComand = sCMD.c_str();
// cout << "delete: " << cpComand << endl; // cout << "delete: " << cpComand << endl;
if (drive->bWasShredStarted == false)
{
//only start delete if the drive was not shredded before
FILE *deleteCmdOutput = popen(cpComand, "r"); FILE *deleteCmdOutput = popen(cpComand, "r");
while ((getline(&cLine, &len, deleteCmdOutput)) != -1) while ((getline(&cLine, &len, deleteCmdOutput)) != -1)
@ -40,3 +43,4 @@ void Delete::deleteDrive(Drive *drive)
} }
pclose(deleteCmdOutput); pclose(deleteCmdOutput);
} }
}

View File

@ -344,6 +344,26 @@ void reHDD::searchDrives(list<Drive> *plistDrives)
*/ */
void reHDD::filterIgnoredDrives(list<Drive> *plistDrives) void reHDD::filterIgnoredDrives(list<Drive> *plistDrives)
{ {
string systemDrivePath;
if (getSystemDrive(systemDrivePath))
{
// Logger::logThis()->info("Found system drive: " + systemDrivePath);
list<Drive>::iterator it;
for (it = plistDrives->begin(); it != plistDrives->end(); ++it)
{
if (it->getPath().find(systemDrivePath) != std::string::npos) // compare found system drive and current drive
{
// system drive found --> ignore this drive
#ifdef LOG_LEVEL_HIGH
Logger::logThis()->info("system drive found --> ignore this drive: " + it->getPath());
#endif
it = plistDrives->erase(it);
it--;
}
}
}
list<tuple<string>> vtlIgnoredDevices; // store drives from ignore file list<tuple<string>> vtlIgnoredDevices; // store drives from ignore file
ifstream input("ignoreDrives.conf"); // read ignore file ifstream input("ignoreDrives.conf"); // read ignore file
@ -605,3 +625,59 @@ void reHDD::handleAbort()
} }
} }
} }
bool reHDD::getSystemDrive(string &systemDrive)
{
char *cLine = NULL;
size_t len = 0;
bool systemDriveFound = false;
FILE *outputfileHwinfo = popen("lsblk -e 11 -o NAME,MOUNTPOINT", "r");
if (outputfileHwinfo == NULL)
{
Logger::logThis()->error("Unable to scan attached drives for system drive");
exit(EXIT_FAILURE);
}
while ((getline(&cLine, &len, outputfileHwinfo)) != -1)
{
string currentLine = cLine;
if (currentLine.find("NAME") != std::string::npos)
{
continue;
}
// Logger::logThis()->info(currentLine);
if ((cLine[0U] != '|') && (cLine[0U] != '`'))
{
systemDrive = currentLine;
systemDrive.erase(std::remove(systemDrive.begin(), systemDrive.end(), '\n'), systemDrive.end()); // remove newline
systemDrive.erase(std::remove(systemDrive.begin(), systemDrive.end(), ' '), systemDrive.end()); // remove spaces
// Logger::logThis()->info("Drive found: " + systemDrive);
}
if (currentLine.ends_with(" /boot/efi\n"s))
{
systemDriveFound = true;
break;
}
if (currentLine.ends_with(" /run/overlay/live\n"s))
{
systemDriveFound = true;
break;
}
if (currentLine.ends_with(" /\n"s))
{
systemDriveFound = true;
break;
}
}
pclose(outputfileHwinfo);
return systemDriveFound;
}

View File

@ -36,6 +36,7 @@ int Shred::shredDrive(Drive *drive, int *ipSignalFd)
ostringstream address; ostringstream address;
address << (void const *)&(*drive); address << (void const *)&(*drive);
Logger::logThis()->info("Shred-Task started - Drive: " + drive->getModelName() + "-" + drive->getSerial() + " @" + address.str()); Logger::logThis()->info("Shred-Task started - Drive: " + drive->getModelName() + "-" + drive->getSerial() + " @" + address.str());
drive->bWasShredStarted = true; //Mark drive as partly shredded
#ifdef DRYRUN #ifdef DRYRUN
for (int i = 0; i <= 500; i++) for (int i = 0; i <= 500; i++)
@ -48,6 +49,7 @@ int Shred::shredDrive(Drive *drive, int *ipSignalFd)
write(*ipSignalFd, "A", 1); write(*ipSignalFd, "A", 1);
usleep(20000); usleep(20000);
} }
drive->bWasShredded = true;
#endif #endif
#ifndef DRYRUN #ifndef DRYRUN

View File

@ -613,6 +613,7 @@ void TUI::vTruncateText(string *psText, uint16_t u16MaxLenght)
void TUI::displaySelectedDrive(Drive drive, int stdscrX, int stdscrY) void TUI::displaySelectedDrive(Drive drive, int stdscrX, int stdscrY)
{ {
struct MenuState menustate; struct MenuState menustate;
static bool dialogIsActive;
menustate.bAbort = false; menustate.bAbort = false;
menustate.bConfirmDelete = false; menustate.bConfirmDelete = false;
menustate.bConfirmShred = false; menustate.bConfirmShred = false;
@ -659,15 +660,21 @@ void TUI::displaySelectedDrive(Drive drive, int stdscrX, int stdscrY)
{ {
dialog = createDialog(40, 10, ((stdscrX) - (int)(stdscrX / 3) - 7) - (int)((stdscrX / 3) + 5) / 2, (int)(stdscrY / 2) - 5, "Confirm SHRED", "Press ENTER for SHRED", "Press ESC for cancel"); dialog = createDialog(40, 10, ((stdscrX) - (int)(stdscrX / 3) - 7) - (int)((stdscrX / 3) + 5) / 2, (int)(stdscrY / 2) - 5, "Confirm SHRED", "Press ENTER for SHRED", "Press ESC for cancel");
wrefresh(dialog); wrefresh(dialog);
dialogIsActive = true;
} }
else if (menustate.bConfirmDelete == true) else if (menustate.bConfirmDelete == true)
{ {
dialog = createDialog(40, 10, ((stdscrX) - (int)(stdscrX / 3) - 7) - (int)((stdscrX / 3) + 5) / 2, (int)(stdscrY / 2) - 5, "Confirm DELETE", "Press ENTER for DELETE", "Press ESC for cancel"); dialog = createDialog(40, 10, ((stdscrX) - (int)(stdscrX / 3) - 7) - (int)((stdscrX / 3) + 5) / 2, (int)(stdscrY / 2) - 5, "Confirm DELETE", "Press ENTER for DELETE", "Press ESC for cancel");
wrefresh(dialog); wrefresh(dialog);
dialogIsActive = true;
} }
else else
{
if (dialogIsActive)
{ {
delwin(dialog); delwin(dialog);
dialogIsActive = false;
}
} }
} }