Add clang-format style file and format accordingly

remotes/origin/HEAD
markuspg 3 years ago
parent ea2e335f8f
commit d5fe3526d1
  1. 118
      .clang-format
  2. 606
      src/Lib/client.cpp
  3. 217
      src/Lib/client.h
  4. 163
      src/Lib/clienthelpnotificationserver.cpp
  5. 18
      src/Lib/clienthelpnotificationserver.h
  6. 67
      src/Lib/clientpinger.cpp
  7. 55
      src/Lib/clientpinger.h
  8. 34
      src/Lib/global.h
  9. 280
      src/Lib/lablib.cpp
  10. 138
      src/Lib/lablib.h
  11. 58
      src/Lib/netstatagent.cpp
  12. 33
      src/Lib/netstatagent.h
  13. 476
      src/Lib/receipts_handler.cpp
  14. 99
      src/Lib/receipts_handler.h
  15. 25
      src/Lib/receiptsprinter.cpp
  16. 253
      src/Lib/receiptsprinter.h
  17. 161
      src/Lib/session.cpp
  18. 75
      src/Lib/session.h
  19. 84
      src/Lib/sessionsmodel.cpp
  20. 24
      src/Lib/sessionsmodel.h
  21. 675
      src/Lib/settings.cpp
  22. 163
      src/Lib/settings.h
  23. 43
      src/Lib/ztree.cpp
  24. 18
      src/Lib/ztree.h
  25. 62
      src/localzleafstarter.cpp
  26. 15
      src/localzleafstarter.h
  27. 18
      src/main.cpp
  28. 1653
      src/mainwindow.cpp
  29. 175
      src/mainwindow.h
  30. 109
      src/manualprintingsetup.cpp
  31. 32
      src/manualprintingsetup.h

@ -0,0 +1,118 @@
---
Language: Cpp
# BasedOnStyle: LLVM
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Right
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: MultiLine
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 80
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
- Regex: '.*'
Priority: 1
IncludeIsMainRegex: '(Test)?$'
IndentCaseLabels: false
IndentPPDirectives: None
IndentWidth: 2
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Right
ReflowComments: true
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
TabWidth: 8
UseTab: Never
...

@ -25,366 +25,374 @@
#include <QRegularExpression>
#include "client.h"
#include "settings.h"
#include "lablib.h"
#include "settings.h"
extern std::unique_ptr< lc::Settings > settings;
extern std::unique_ptr< lc::Lablib > lablib;
lc::Client::Client( const QString &argIP, const QString &argMAC, const QString &argName,
unsigned short int argXPosition, unsigned short int argYPosition,
const QString &argPingCmd ):
ip{ argIP },
mac{ argMAC },
name{ argName },
xPosition{ argXPosition },
yPosition{ argYPosition },
protectedCycles{ 0 }
{
qRegisterMetaType< state_t >( "STATE" );
if ( !argPingCmd.isEmpty() ) {
pinger = new ClientPinger{ ip, argPingCmd };
pinger->moveToThread( &pingerThread );
connect( &pingerThread, &QThread::finished,
pinger, &QObject::deleteLater );
connect( this, &Client::PingWanted,
pinger, &ClientPinger::doPing );
connect( pinger, &ClientPinger::PingFinished,
this, &Client::GotStatusChanged );
pingerThread.start();
pingTimer = new QTimer{ this };
connect( pingTimer, &QTimer::timeout,
this, &Client::RequestAPing ) ;
pingTimer->start( 3000 );
}
qDebug() << "Created client" << name << "with MAC" << mac << "and IP" << ip
<< "at position" << QString{ QString::number( xPosition ) + "x"
+ QString::number( yPosition ) };
extern std::unique_ptr<lc::Settings> settings;
extern std::unique_ptr<lc::Lablib> lablib;
lc::Client::Client(const QString &argIP, const QString &argMAC,
const QString &argName, unsigned short int argXPosition,
unsigned short int argYPosition, const QString &argPingCmd)
: ip{argIP}, mac{argMAC}, name{argName}, xPosition{argXPosition},
yPosition{argYPosition}, protectedCycles{0} {
qRegisterMetaType<state_t>("STATE");
if (!argPingCmd.isEmpty()) {
pinger = new ClientPinger{ip, argPingCmd};
pinger->moveToThread(&pingerThread);
connect(&pingerThread, &QThread::finished, pinger, &QObject::deleteLater);
connect(this, &Client::PingWanted, pinger, &ClientPinger::doPing);
connect(pinger, &ClientPinger::PingFinished, this,
&Client::GotStatusChanged);
pingerThread.start();
pingTimer = new QTimer{this};
connect(pingTimer, &QTimer::timeout, this, &Client::RequestAPing);
pingTimer->start(3000);
}
qDebug() << "Created client" << name << "with MAC" << mac << "and IP" << ip
<< "at position"
<< QString{QString::number(xPosition) + "x" +
QString::number(yPosition)};
}
lc::Client::~Client() {
if ( pingTimer ) {
pingTimer->stop();
}
delete pingTimer;
pingerThread.quit();
pingerThread.wait();
if (pingTimer) {
pingTimer->stop();
}
delete pingTimer;
pingerThread.quit();
pingerThread.wait();
}
void lc::Client::BeamFile( const QString &argFileToBeam, const QString * const argPublickeyPathUser, const QString * const argUserNameOnClients ) {
if ( state < state_t::RESPONDING ) {
return;
}
QStringList arguments;
arguments << "-2" << "-i" << *argPublickeyPathUser << "-l" << "32768" << "-r"
<< argFileToBeam << QString{ *argUserNameOnClients + "@" + ip + ":media4ztree" };
// Start the process
QProcess beamFileProcess;
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
beamFileProcess.setProcessEnvironment( env );
beamFileProcess.startDetached( settings->scpCmd, arguments );
qDebug() << settings->scpCmd << arguments.join( " " );
void lc::Client::BeamFile(const QString &argFileToBeam,
const QString *const argPublickeyPathUser,
const QString *const argUserNameOnClients) {
if (state < state_t::RESPONDING) {
return;
}
QStringList arguments;
arguments << "-2"
<< "-i" << *argPublickeyPathUser << "-l"
<< "32768"
<< "-r" << argFileToBeam
<< QString{*argUserNameOnClients + "@" + ip + ":media4ztree"};
// Start the process
QProcess beamFileProcess;
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
beamFileProcess.setProcessEnvironment(env);
beamFileProcess.startDetached(settings->scpCmd, arguments);
qDebug() << settings->scpCmd << arguments.join(" ");
}
void lc::Client::Boot() {
QStringList arguments{ QStringList{} << "-i" << settings->netwBrdAddr << mac };
QStringList arguments{QStringList{} << "-i" << settings->netwBrdAddr << mac};
// Start the process
QProcess wakeonlanProcess;
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
wakeonlanProcess.setProcessEnvironment( env );
wakeonlanProcess.startDetached( settings->wakeonlanCmd, arguments );
// Start the process
QProcess wakeonlanProcess;
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
wakeonlanProcess.setProcessEnvironment(env);
wakeonlanProcess.startDetached(settings->wakeonlanCmd, arguments);
// Output message via the debug messages tab
qDebug() << settings->wakeonlanCmd << arguments.join( " " );
// Output message via the debug messages tab
qDebug() << settings->wakeonlanCmd << arguments.join(" ");
pingTimer->start( 3000 );
pingTimer->start(3000);
protectedCycles = 7;
GotStatusChanged( state_t::BOOTING );
protectedCycles = 7;
GotStatusChanged(state_t::BOOTING);
}
void lc::Client::GotStatusChanged( state_t argState ) {
if ( ( protectedCycles > 0 ) && ( state == state_t::BOOTING ) && ( argState != state_t::RESPONDING ) ) {
return;
}
if ( ( protectedCycles > 0 ) && ( state == state_t::SHUTTING_DOWN ) && argState != state_t::NOT_RESPONDING ) {
return;
}
state = argState;
qDebug() << name << "status changed to:" << static_cast< unsigned short int >( argState );
void lc::Client::GotStatusChanged(state_t argState) {
if ((protectedCycles > 0) && (state == state_t::BOOTING) &&
(argState != state_t::RESPONDING)) {
return;
}
if ((protectedCycles > 0) && (state == state_t::SHUTTING_DOWN) &&
argState != state_t::NOT_RESPONDING) {
return;
}
state = argState;
qDebug() << name
<< "status changed to:" << static_cast<unsigned short int>(argState);
}
void lc::Client::KillZLeaf() {
QStringList arguments;
arguments << "-i" << settings->pkeyPathUser
<< QString{ settings->userNameOnClients + "@" + ip }
<< settings->killallCmd << "-I" << "-q" << "zleaf.exe";
// Start the process
QProcess killZLeafProcess;
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
killZLeafProcess.setProcessEnvironment( env );
killZLeafProcess.startDetached( settings->sshCmd, arguments );
// Output message via the debug messages tab
qDebug() << settings->sshCmd << arguments.join( " " );
QStringList arguments;
arguments << "-i" << settings->pkeyPathUser
<< QString{settings->userNameOnClients + "@" + ip}
<< settings->killallCmd << "-I"
<< "-q"
<< "zleaf.exe";
// Start the process
QProcess killZLeafProcess;
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
killZLeafProcess.setProcessEnvironment(env);
killZLeafProcess.startDetached(settings->sshCmd, arguments);
// Output message via the debug messages tab
qDebug() << settings->sshCmd << arguments.join(" ");
// Restart the ping_timer, because it is stopped when a zLeaf is started
pingTimer->start(3000);
}
// Restart the ping_timer, because it is stopped when a zLeaf is started
pingTimer->start( 3000 );
void lc::Client::OpenFilesystem(const QString *const argUserToBeUsed) {
if (state < state_t::RESPONDING) {
return;
}
QStringList arguments = QStringList{}
<< QString{"sftp://" + *argUserToBeUsed + "@" + ip};
QProcess openFilesystemProcess;
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
openFilesystemProcess.setProcessEnvironment(env);
openFilesystemProcess.startDetached(settings->fileMngr, arguments);
qDebug() << settings->fileMngr << arguments.join(" ");
}
void lc::Client::OpenFilesystem( const QString * const argUserToBeUsed ) {
if ( state < state_t::RESPONDING ) {
return;
void lc::Client::OpenTerminal(const QString &argCommand,
const bool &argOpenAsRoot) {
if (!settings->termEmulCmd.isEmpty()) {
if (state < state_t::RESPONDING) {
return;
}
QStringList arguments = QStringList{} << QString{ "sftp://" + *argUserToBeUsed + "@" + ip };
QProcess openFilesystemProcess;
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
openFilesystemProcess.setProcessEnvironment( env );
openFilesystemProcess.startDetached( settings->fileMngr, arguments );
qDebug() << settings->fileMngr << arguments.join( " " );
}
QStringList *arguments = nullptr;
arguments = new QStringList;
if (!argOpenAsRoot) {
*arguments << "-e"
<< QString{settings->sshCmd + " -i " + settings->pkeyPathUser +
" " + settings->userNameOnClients + "@" + ip};
} else {
*arguments << "-e"
<< QString{settings->sshCmd + " -i " + settings->pkeyPathRoot +
" " + "root@" + ip};
}
void lc::Client::OpenTerminal( const QString &argCommand, const bool &argOpenAsRoot ) {
if ( !settings->termEmulCmd.isEmpty() ) {
if ( state < state_t::RESPONDING ) {
return;
}
QStringList *arguments = nullptr;
arguments = new QStringList;
if ( !argOpenAsRoot ) {
*arguments << "-e"
<< QString{ settings->sshCmd + " -i " + settings->pkeyPathUser + " "
+ settings->userNameOnClients + "@" + ip };
} else {
*arguments << "-e" <<
QString{ settings->sshCmd + " -i " + settings->pkeyPathRoot
+ " " + "root@" + ip};
}
if ( !argCommand.isEmpty() ) {
arguments->last().append( " '" + argCommand + "'" );
}
QProcess openTerminalProcess;
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
openTerminalProcess.setProcessEnvironment( env );
openTerminalProcess.startDetached( settings->termEmulCmd, *arguments );
qDebug() << settings->termEmulCmd << arguments->join( " " );
delete arguments;
if (!argCommand.isEmpty()) {
arguments->last().append(" '" + argCommand + "'");
}
QProcess openTerminalProcess;
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
openTerminalProcess.setProcessEnvironment(env);
openTerminalProcess.startDetached(settings->termEmulCmd, *arguments);
qDebug() << settings->termEmulCmd << arguments->join(" ");
delete arguments;
}
}
void lc::Client::RequestAPing() {
if ( protectedCycles > 0 ) {
--protectedCycles;
}
emit PingWanted();
if (protectedCycles > 0) {
--protectedCycles;
}
emit PingWanted();
}
void lc::Client::SetStateToZLEAF_RUNNING( QString argClientIP ) {
if ( argClientIP != ip ) {
return;
}
if ( state != state_t::ZLEAF_RUNNING ) {
pingTimer->stop();
// Inform the ClientPinger instance, that zLeaf is now running
pinger->setStateToZLEAF_RUNNING();
this->GotStatusChanged( state_t::ZLEAF_RUNNING );
qDebug() << "Client" << name << "got 'ZLEAF_RUNNING' signal.";
}
void lc::Client::SetStateToZLEAF_RUNNING(QString argClientIP) {
if (argClientIP != ip) {
return;
}
if (state != state_t::ZLEAF_RUNNING) {
pingTimer->stop();
// Inform the ClientPinger instance, that zLeaf is now running
pinger->setStateToZLEAF_RUNNING();
this->GotStatusChanged(state_t::ZLEAF_RUNNING);
qDebug() << "Client" << name << "got 'ZLEAF_RUNNING' signal.";
}
}
void lc::Client::ShowDesktopViewOnly() {
QStringList arguments;
arguments << ip;
QStringList arguments;
arguments << ip;
QProcess showDesktopProcess;
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
showDesktopProcess.setProcessEnvironment( env );
showDesktopProcess.startDetached( settings->vncViewer, arguments );
QProcess showDesktopProcess;
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
showDesktopProcess.setProcessEnvironment(env);
showDesktopProcess.startDetached(settings->vncViewer, arguments);
// Output message via the debug messages tab
qDebug() << settings->vncViewer << arguments.join( " " );
// Output message via the debug messages tab
qDebug() << settings->vncViewer << arguments.join(" ");
}
void lc::Client::ShowDesktopFullControl() {
QStringList arguments;
arguments << ip + ":5901";
QStringList arguments;
arguments << ip + ":5901";
QProcess showDesktopProcess;
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
showDesktopProcess.setProcessEnvironment( env );
showDesktopProcess.startDetached( settings->vncViewer, arguments );
QProcess showDesktopProcess;
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
showDesktopProcess.setProcessEnvironment(env);
showDesktopProcess.startDetached(settings->vncViewer, arguments);
// Output message via the debug messages tab
qDebug() << settings->vncViewer << arguments.join( " " );
// Output message via the debug messages tab
qDebug() << settings->vncViewer << arguments.join(" ");
}
void lc::Client::Shutdown() {
if ( state == state_t::NOT_RESPONDING || state == state_t::BOOTING
|| state == state_t::SHUTTING_DOWN ) {
return;
}
QStringList arguments;
arguments << "-i" << settings->pkeyPathUser
<< QString{ settings->userNameOnClients + "@" + ip } << "sudo shutdown -P now";
// Start the process
QProcess shutdownProcess;
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
shutdownProcess.setProcessEnvironment( env );
shutdownProcess.startDetached( settings->sshCmd, arguments );
// Output message via the debug messages tab
qDebug() << settings->sshCmd << arguments.join( " " );
// This additional 'ping_timer' start is needed for the case that the clients are shut down without prior closing of zLeaves
pingTimer->start( 3000 );
protectedCycles = 3;
GotStatusChanged( state_t::SHUTTING_DOWN );
if (state == state_t::NOT_RESPONDING || state == state_t::BOOTING ||
state == state_t::SHUTTING_DOWN) {
return;
}
QStringList arguments;
arguments << "-i" << settings->pkeyPathUser
<< QString{settings->userNameOnClients + "@" + ip}
<< "sudo shutdown -P now";
// Start the process
QProcess shutdownProcess;
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
shutdownProcess.setProcessEnvironment(env);
shutdownProcess.startDetached(settings->sshCmd, arguments);
// Output message via the debug messages tab
qDebug() << settings->sshCmd << arguments.join(" ");
// This additional 'ping_timer' start is needed for the case that the clients
// are shut down without prior closing of zLeaves
pingTimer->start(3000);
protectedCycles = 3;
GotStatusChanged(state_t::SHUTTING_DOWN);
}
void lc::Client::StartZLeaf( const QString * argFakeName, QString cmd ) {
if ( state < state_t::RESPONDING || zLeafVersion.isEmpty() || GetSessionPort() < 7000 ) {
return;
}
// Create a QMessageBox for user interaction if there is already a zLeaf running
std::unique_ptr< QMessageBox > messageBoxRunningZLeafFound;
if ( state == state_t::ZLEAF_RUNNING ) {
messageBoxRunningZLeafFound.reset( new QMessageBox{ QMessageBox::Warning, "Running zLeaf found",
QString{ "There is already a zLeaf running on " + name + "." },
QMessageBox::No | QMessageBox::Yes } );
messageBoxRunningZLeafFound->setInformativeText( "Do you want to start a zLeaf on client "
+ name + " nonetheless?" );
messageBoxRunningZLeafFound->setDefaultButton( QMessageBox::No );
messageBoxRunningZLeafFound->exec();
}
if ( ( messageBoxRunningZLeafFound.get() != nullptr
&& messageBoxRunningZLeafFound->clickedButton()
== messageBoxRunningZLeafFound->button( QMessageBox::Yes ) )
|| state != state_t::ZLEAF_RUNNING ) {
QStringList arguments;
if ( argFakeName == nullptr ) {
arguments << "-i" << settings->pkeyPathUser
<< QString{ settings->userNameOnClients + "@" + ip }
<< cmd;
} else {
arguments << "-i" << settings->pkeyPathUser
<< QString{ settings->userNameOnClients + "@" + ip }
<< cmd
<< "/name" << *argFakeName;
}
// Start the process
QProcess startZLeafProcess;
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
startZLeafProcess.setProcessEnvironment( env );
startZLeafProcess.startDetached( settings->sshCmd, arguments );
// Output message via the debug messages tab
qDebug() << settings->sshCmd << arguments.join( " " );
}
}
void lc::Client::StartClientBrowser( const QString * const argURL, const bool * const argFullscreen, const QString * const argBrowser ) {
//Declarations
void lc::Client::StartZLeaf(const QString *argFakeName, QString cmd) {
if (state < state_t::RESPONDING || zLeafVersion.isEmpty() ||
GetSessionPort() < 7000) {
return;
}
// Create a QMessageBox for user interaction if there is already a zLeaf
// running
std::unique_ptr<QMessageBox> messageBoxRunningZLeafFound;
if (state == state_t::ZLEAF_RUNNING) {
messageBoxRunningZLeafFound.reset(new QMessageBox{
QMessageBox::Warning, "Running zLeaf found",
QString{"There is already a zLeaf running on " + name + "."},
QMessageBox::No | QMessageBox::Yes});
messageBoxRunningZLeafFound->setInformativeText(
"Do you want to start a zLeaf on client " + name + " nonetheless?");
messageBoxRunningZLeafFound->setDefaultButton(QMessageBox::No);
messageBoxRunningZLeafFound->exec();
}
if ((messageBoxRunningZLeafFound.get() != nullptr &&
messageBoxRunningZLeafFound->clickedButton() ==
messageBoxRunningZLeafFound->button(QMessageBox::Yes)) ||
state != state_t::ZLEAF_RUNNING) {
QStringList arguments;
QString processedArgUrl(*argURL);
QRegularExpression clientRegEx(QStringLiteral("%CLIENT%"));
processedArgUrl.replace(clientRegEx,this->name);
//qDebug() << processedArgUrl;
if(argBrowser==QString("firefox")){
// Build arguments list for SSH command
arguments << "-i" << settings->pkeyPathUser
<< QString{ settings->userNameOnClients + "@" + ip }
<< "DISPLAY=:0.0"
<< settings->clientBrowserCmd
<< processedArgUrl;
// Add fullscreen toggle if checked
if (*argFullscreen == true){
arguments << "& sleep 3 && DISPLAY=:0.0 xdotool key --clearmodifiers F11";
}
} else if (argBrowser==QString("chromium")) {
// Build arguments list for SSH command
arguments << "-i" << settings->pkeyPathUser
<< QString{ settings->userNameOnClients + "@" + ip }
<< "DISPLAY=:0.0"
<< settings->clientChromiumCmd
<< "--noerrdialogs --kiosk"
<< "--app='" + processedArgUrl + "'"
<< "> /dev/null 2>&1 &disown";
if (argFakeName == nullptr) {
arguments << "-i" << settings->pkeyPathUser
<< QString{settings->userNameOnClients + "@" + ip} << cmd;
} else {
arguments << "-i" << settings->pkeyPathUser
<< QString{settings->userNameOnClients + "@" + ip} << cmd
<< "/name" << *argFakeName;
}
// Start the process
QProcess startClientBrowserProcess;
QProcess startZLeafProcess;
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
startClientBrowserProcess.setProcessEnvironment( env );
startClientBrowserProcess.startDetached( settings->sshCmd, arguments );
startZLeafProcess.setProcessEnvironment(env);
startZLeafProcess.startDetached(settings->sshCmd, arguments);
// Output message via the debug messages tab
qDebug() << settings->sshCmd << arguments.join( " " );
qDebug() << settings->sshCmd << arguments.join(" ");
}
}
void lc::Client::StopClientBrowser() {
//Declarations
QStringList arguments;
void lc::Client::StartClientBrowser(const QString *const argURL,
const bool *const argFullscreen,
const QString *const argBrowser) {
// Declarations
QStringList arguments;
QString processedArgUrl(*argURL);
QRegularExpression clientRegEx(QStringLiteral("%CLIENT%"));
processedArgUrl.replace(clientRegEx, this->name);
// qDebug() << processedArgUrl;
//Build arguments list
if (argBrowser == QString("firefox")) {
// Build arguments list for SSH command
arguments << "-i" << settings->pkeyPathUser
<< QString{ settings->userNameOnClients + "@" + ip }
<< "killall"
<< settings->clientBrowserCmd
<< "& sleep 1 && rm -R /home/ewfuser/.mozilla/firefox/*"
<< "& killall"
<< settings->clientChromiumCmd;
<< QString{settings->userNameOnClients + "@" + ip}
<< "DISPLAY=:0.0" << settings->clientBrowserCmd
<< processedArgUrl;
// Start the process
QProcess startClientBrowserProcess;
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
startClientBrowserProcess.setProcessEnvironment( env );
startClientBrowserProcess.startDetached( settings->sshCmd, arguments );
// Add fullscreen toggle if checked
if (*argFullscreen == true) {
arguments << "& sleep 3 && DISPLAY=:0.0 xdotool key --clearmodifiers F11";
}
} else if (argBrowser == QString("chromium")) {
// Build arguments list for SSH command
arguments << "-i" << settings->pkeyPathUser
<< QString{settings->userNameOnClients + "@" + ip}
<< "DISPLAY=:0.0" << settings->clientChromiumCmd
<< "--noerrdialogs --kiosk"
<< "--app='" + processedArgUrl + "'"
<< "> /dev/null 2>&1 &disown";
}
// Start the process
QProcess startClientBrowserProcess;
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
startClientBrowserProcess.setProcessEnvironment(env);
startClientBrowserProcess.startDetached(settings->sshCmd, arguments);
// Output message via the debug messages tab
qDebug() << settings->sshCmd << arguments.join(" ");
}
// Output message via the debug messages tab
qDebug() << settings->sshCmd << arguments.join( " " );
void lc::Client::StopClientBrowser() {
// Declarations
QStringList arguments;
// Build arguments list
arguments << "-i" << settings->pkeyPathUser
<< QString{settings->userNameOnClients + "@" + ip} << "killall"
<< settings->clientBrowserCmd
<< "& sleep 1 && rm -R /home/ewfuser/.mozilla/firefox/*"
<< "& killall" << settings->clientChromiumCmd;
// Start the process
QProcess startClientBrowserProcess;
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
startClientBrowserProcess.setProcessEnvironment(env);
startClientBrowserProcess.startDetached(settings->sshCmd, arguments);
// Output message via the debug messages tab
qDebug() << settings->sshCmd << arguments.join(" ");
}
void lc::Client::ControlRMB(bool enable) {
//Declarations
QStringList arguments;
// Declarations
QStringList arguments;
//Build arguments list
if(enable){
arguments << "-i" << settings->pkeyPathUser
<< QString{ settings->userNameOnClients + "@" + ip }
<< "DISPLAY=:0 xinput set-button-map 'Microsoft Basic Optical Mouse' 1 2 3 4 5 6 7 8 9 10 11 12 > /dev/null 2>&1 &disown;";
} else {
arguments << "-i" << settings->pkeyPathUser
<< QString{ settings->userNameOnClients + "@" + ip }
<< "DISPLAY=:0 xinput set-button-map 'Microsoft Basic Optical Mouse' 1 2 0 4 5 6 7 8 9 10 11 12 > /dev/null 2>&1 &disown;";
}
// Start the process
QProcess startClientBrowserProcess;
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
startClientBrowserProcess.setProcessEnvironment( env );
startClientBrowserProcess.startDetached( settings->sshCmd, arguments );
// Output message via the debug messages tab
qDebug() << settings->sshCmd << arguments.join( " " );
// Build arguments list
if (enable) {
arguments << "-i" << settings->pkeyPathUser
<< QString{settings->userNameOnClients + "@" + ip}
<< "DISPLAY=:0 xinput set-button-map 'Microsoft Basic Optical "
"Mouse' 1 2 3 4 5 6 7 8 9 10 11 12 > /dev/null 2>&1 &disown;";
} else {
arguments << "-i" << settings->pkeyPathUser
<< QString{settings->userNameOnClients + "@" + ip}
<< "DISPLAY=:0 xinput set-button-map 'Microsoft Basic Optical "
"Mouse' 1 2 0 4 5 6 7 8 9 10 11 12 > /dev/null 2>&1 &disown;";
}
// Start the process
QProcess startClientBrowserProcess;
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
startClientBrowserProcess.setProcessEnvironment(env);
startClientBrowserProcess.startDetached(settings->sshCmd, arguments);
// Output message via the debug messages tab
qDebug() << settings->sshCmd << arguments.join(" ");
}

@ -28,129 +28,140 @@
#include <QThread>
#include <QTimer>
#include "global.h"
#include "clientpinger.h"
#include "global.h"
namespace lc {
//! Class which represents the clients in the lab
/*!
This class contains elements and functions needed to represent all functions of a client.
This class contains elements and functions needed to represent all functions
of a client.
*/
class Client : public QObject {
Q_OBJECT
Q_OBJECT
public slots:
//! Sets the STATE of the client to 'ZLEAF_RUNNING'
void SetStateToZLEAF_RUNNING( QString argClientIP );
//! Sets the STATE of the client to 'ZLEAF_RUNNING'
void SetStateToZLEAF_RUNNING(QString argClientIP);
public:
const QString ip;
const QString mac;
const QString name;
const unsigned short int xPosition = 1;
const unsigned short int yPosition = 1;
/*!
* \brief Client's constructor
* \param argIP The IP address the represented client has
* \param argMAC The MAC address the represented client has
* \param argName The hostname of the represented client
* \param argXPosition The client's x coordinate in the lab's grid
* \param argYPosition The client's y coordinate in the lab's grid
*/
Client( const QString &argIP, const QString &argMAC, const QString &argName,
unsigned short int argXPosition, unsigned short int argYPosition,
const QString &argPingCmd );
//! Client's destructor
~Client();
//! Beams the chosen file to the client's 'media4ztree' directory
/*!
@param argFileToBeam The file which shall be beamed to the client's 'media4ztree' directory
@param argPublickeyPathUser The path to the publickey for user login on the clients
@param argUserNameOnClients The name of the user on the clients
*/
void BeamFile( const QString &argFileToBeam, const QString * const argPublickeyPathUser, const QString * const argUserNameOnClients );
/*!
* \brief Boots the client
*/
void Boot();
/*!
* \brief DeactiveScreensaver deactivates potentially running screensavers on the client
*/
void DeactiveScreensaver();
//! Returns the current state of the client
/*!
@return The current state of the client
*/
state_t GetClientState() const { return state; }
int GetSessionPort() const { return sessionPort; }
/*!
* \brief Kills all processes 'zleaf.exe' on the client
*/
void KillZLeaf();
//! Opens a file manager for the client's file system
/*!
@param argUserToBeUsed The name of the user on the clients
*/
void OpenFilesystem( const QString * const argUserToBeUsed );
/*!
* \brief Opens a terminal for the client
* \param argCommand A command which shall be executed in the terminal window (Pass an empty QString if not wanted)
* \param argOpenAsRoot Run the terminal session as root (true) or as normal user (false)
*/
void OpenTerminal( const QString &argCommand, const bool &argOpenAsRoot );
void SetSessionPort( int argSP ) { sessionPort = argSP; }
void SetzLeafVersion( const QString &argzLeafV ) { zLeafVersion = argzLeafV; }
//! Shows the desktop of the given client
void ShowDesktopViewOnly();
void ShowDesktopFullControl();
/*!
* \brief Shuts down the client
*/
void Shutdown();
/*!
* \brief Starts a zLeaf instance on the client
* @param argFakeName The name the zLeaf instance shall have (if not the default, which is the hostname of the client)
*/
void StartZLeaf(const QString *argFakeName = nullptr, QString cmd = "" );
/*!
* \brief Opens a browser window on the client
* @param argURL URL to open in clients browser
*/
void StartClientBrowser( const QString *argURL = nullptr, const bool *argFullscreen = nullptr, const QString *argBrowser = nullptr );
/*!
* \brief Closes all browser instances
*/
void StopClientBrowser();
/*!
* \brief Enable/Disable right mouse button
*/
void ControlRMB(bool enable = true);
const QString ip;
const QString mac;
const QString name;
const unsigned short int xPosition = 1;
const unsigned short int yPosition = 1;
/*!
* \brief Client's constructor
* \param argIP The IP address the represented client has
* \param argMAC The MAC address the represented client has
* \param argName The hostname of the represented client
* \param argXPosition The client's x coordinate in the lab's grid
* \param argYPosition The client's y coordinate in the lab's grid
*/
Client(const QString &argIP, const QString &argMAC, const QString &argName,
unsigned short int argXPosition, unsigned short int argYPosition,
const QString &argPingCmd);
//! Client's destructor
~Client();
//! Beams the chosen file to the client's 'media4ztree' directory
/*!
@param argFileToBeam The file which shall be beamed to the
client's 'media4ztree' directory
@param argPublickeyPathUser The path to the publickey for user
login on the clients
@param argUserNameOnClients The name of the user on the clients
*/
void BeamFile(const QString &argFileToBeam,
const QString *const argPublickeyPathUser,
const QString *const argUserNameOnClients);
/*!
* \brief Boots the client
*/
void Boot();
/*!
* \brief DeactiveScreensaver deactivates potentially running screensavers on
* the client
*/
void DeactiveScreensaver();
//! Returns the current state of the client
/*!
@return The current state of the client
*/
state_t GetClientState() const { return state; }
int GetSessionPort() const { return sessionPort; }
/*!
* \brief Kills all processes 'zleaf.exe' on the client
*/
void KillZLeaf();
//! Opens a file manager for the client's file system
/*!
@param argUserToBeUsed The name of the user on the clients
*/
void OpenFilesystem(const QString *const argUserToBeUsed);
/*!
* \brief Opens a terminal for the client
* \param argCommand A command which shall be executed in the terminal window
* (Pass an empty QString if not wanted) \param argOpenAsRoot Run the terminal
* session as root (true) or as normal user (false)
*/
void OpenTerminal(const QString &argCommand, const bool &argOpenAsRoot);
void SetSessionPort(int argSP) { sessionPort = argSP; }
void SetzLeafVersion(const QString &argzLeafV) { zLeafVersion = argzLeafV; }
//! Shows the desktop of the given client
void ShowDesktopViewOnly();
void ShowDesktopFullControl();
/*!
* \brief Shuts down the client
*/
void Shutdown();
/*!
* \brief Starts a zLeaf instance on the client
* @param argFakeName The name the zLeaf instance shall have (if not the
* default, which is the hostname of the client)
*/
void StartZLeaf(const QString *argFakeName = nullptr, QString cmd = "");
/*!
* \brief Opens a browser window on the client
* @param argURL URL to open in clients browser
*/
void StartClientBrowser(const QString *argURL = nullptr,
const bool *argFullscreen = nullptr,
const QString *argBrowser = nullptr);
/*!
* \brief Closes all browser instances
*/
void StopClientBrowser();
/*!
* \brief Enable/Disable right mouse button
*/
void ControlRMB(bool enable = true);
private:
const QString &GetzLeafVersion() const { return zLeafVersion; }
const QString &GetzLeafVersion() const { return zLeafVersion; }
unsigned short int protectedCycles;
ClientPinger *pinger = nullptr;
QThread pingerThread;
state_t state = state_t::UNINITIALIZED;
QTimer *pingTimer = nullptr; //! QTimer used to trigger pings by pinger's ClientPinger instance
int sessionPort = 0;
QString zLeafVersion;
unsigned short int protectedCycles;
ClientPinger *pinger = nullptr;
QThread pingerThread;
state_t state = state_t::UNINITIALIZED;
QTimer *pingTimer = nullptr; //! QTimer used to trigger pings by pinger's
//! ClientPinger instance
int sessionPort = 0;
QString zLeafVersion;
private slots:
void GotStatusChanged( state_t argState );
void RequestAPing();
void GotStatusChanged(state_t argState);
void RequestAPing();
signals:
void PingWanted();
void PingWanted();
};
}
} // namespace lc
#endif // CLIENT_H

@ -22,93 +22,108 @@
#include "clienthelpnotificationserver.h"
#include "settings.h"
extern std::unique_ptr< lc::Settings > settings;
extern std::unique_ptr<lc::Settings> settings;
lc::ClientHelpNotificationServer::ClientHelpNotificationServer( QObject *argParent ) :
QObject{ argParent },
hostAddress{ settings->serverIP }
{
QNetworkConfigurationManager manager;
if ( manager.capabilities() & QNetworkConfigurationManager::NetworkSessionRequired ) {
// Get saved network configuration
QSettings settings{ QSettings::UserScope, QLatin1String{ "QtProject" } };
settings.beginGroup( QLatin1String{ "QtNetwork" } );
const QString id = settings.value( QLatin1String{ "DefaultNetworkConfiguration" } ).toString();
settings.endGroup();
lc::ClientHelpNotificationServer::ClientHelpNotificationServer(
QObject *argParent)
: QObject{argParent}, hostAddress{settings->serverIP} {
QNetworkConfigurationManager manager;
if (manager.capabilities() &
QNetworkConfigurationManager::NetworkSessionRequired) {
// Get saved network configuration
QSettings settings{QSettings::UserScope, QLatin1String{"QtProject"}};
settings.beginGroup(QLatin1String{"QtNetwork"});
const QString id =
settings.value(QLatin1String{"DefaultNetworkConfiguration"}).toString();
settings.endGroup();
// If the saved network configuration is not currently discovered use the system default
QNetworkConfiguration config = manager.configurationFromIdentifier( id );
if ( ( config.state() & QNetworkConfiguration::Discovered ) != QNetworkConfiguration::Discovered ) {
config = manager.defaultConfiguration();
}
networkSession = new QNetworkSession{ config, this };
connect( networkSession, &QNetworkSession::opened,
this, &ClientHelpNotificationServer::OpenSession );
networkSession->open();
} else {
OpenSession();
// If the saved network configuration is not currently discovered use the
// system default
QNetworkConfiguration config = manager.configurationFromIdentifier(id);
if ((config.state() & QNetworkConfiguration::Discovered) !=
QNetworkConfiguration::Discovered) {
config = manager.defaultConfiguration();
}
networkSession = new QNetworkSession{config, this};
connect(networkSession, &QNetworkSession::opened, this,
&ClientHelpNotificationServer::OpenSession);
networkSession->open();
} else {
OpenSession();
}
connect( helpMessageServer, &QTcpServer::newConnection,
this, &ClientHelpNotificationServer::SendReply );
connect(helpMessageServer, &QTcpServer::newConnection, this,
&ClientHelpNotificationServer::SendReply);
}
void lc::ClientHelpNotificationServer::OpenSession() {
// Save the used configuration
if ( networkSession ) {
QNetworkConfiguration config = networkSession->configuration();
QString id;
if ( config.type() == QNetworkConfiguration::UserChoice ) {
id = networkSession->sessionProperty( QLatin1String{ "UserChoiceConfiguration" } ).toString();
} else {
id = config.identifier();
}
QSettings settings( QSettings::UserScope, QLatin1String{ "QtProject" } );
settings.beginGroup( QLatin1String{ "QtNetwork" } );
settings.setValue( QLatin1String{ "DefaultNetworkConfiguration" }, id );
settings.endGroup();
// Save the used configuration
if (networkSession) {
QNetworkConfiguration config = networkSession->configuration();
QString id;
if (config.type() == QNetworkConfiguration::UserChoice) {
id = networkSession
->sessionProperty(QLatin1String{"UserChoiceConfiguration"})
.toString();
} else {
id = config.identifier();
}
helpMessageServer = new QTcpServer{ this };
if ( !helpMessageServer->listen( hostAddress, settings->clientHelpNotificationServerPort ) ) {
QMessageBox messageBox{ QMessageBox::Critical, tr( "Unable to start the client help notification server" ),
tr( "Unable to start the client help notification server.\nThe following error occurred:\n\n%1." ).arg( helpMessageServer->errorString() ), QMessageBox::Ok };
messageBox.exec();
return;
}
QSettings settings(QSettings::UserScope, QLatin1String{"QtProject"});
settings.beginGroup(QLatin1String{"QtNetwork"});
settings.setValue(QLatin1String{"DefaultNetworkConfiguration"}, id);
settings.endGroup();
}
helpMessageServer = new QTcpServer{this};
if (!helpMessageServer->listen(hostAddress,
settings->clientHelpNotificationServerPort)) {
QMessageBox messageBox{
QMessageBox::Critical,
tr("Unable to start the client help notification server"),
tr("Unable to start the client help notification server.\nThe "
"following error occurred:\n\n%1.")
.arg(helpMessageServer->errorString()),
QMessageBox::Ok};
messageBox.exec();
return;
}
}
void lc::ClientHelpNotificationServer::SendReply() {
QByteArray block;
QDataStream out{ &block, QIODevice::WriteOnly };
out.setVersion( QDataStream::Qt_5_2 );
out << ( quint16 )0;
out << QString{ "Help demand retrieved." };
out.device()->seek( 0 );
out << ( quint16 )( block.size() - sizeof( quint16 ) );
QByteArray block;
QDataStream out{&block, QIODevice::WriteOnly};
out.setVersion(QDataStream::Qt_5_2);
out << (quint16)0;
out << QString{"Help demand retrieved."};
out.device()->seek(0);
out << (quint16)(block.size() - sizeof(quint16));
QTcpSocket *clientConnection = helpMessageServer->nextPendingConnection();
QString peerAddress = clientConnection->peerAddress().toString();
QString peerName;
bool unknownClient = false;
if ( settings->clIPsToClMap.contains( peerAddress ) ) {
peerName = settings->clIPsToClMap[ peerAddress ]->name;
} else {
unknownClient = true;
}
QTcpSocket *clientConnection = helpMessageServer->nextPendingConnection();
QString peerAddress = clientConnection->peerAddress().toString();
QString peerName;
bool unknownClient = false;
if (settings->clIPsToClMap.contains(peerAddress)) {
peerName = settings->clIPsToClMap[peerAddress]->name;
} else {
unknownClient = true;
}
connect( clientConnection, &QTcpSocket::disconnected, clientConnection, &QTcpSocket::deleteLater );
clientConnection->write( block );
clientConnection->disconnectFromHost();
connect(clientConnection, &QTcpSocket::disconnected, clientConnection,
&QTcpSocket::deleteLater);
clientConnection->write(block);
clientConnection->disconnectFromHost();
if ( unknownClient ) {
QMessageBox requestReceivedBox{ QMessageBox::Information, tr( "Unknown client asked for help."),
tr( "An unknown client with IP '%1' asked for help.").arg( peerAddress ), QMessageBox::Ok };
requestReceivedBox.exec();
} else {
QMessageBox requestReceivedBox{ QMessageBox::Information, tr( "'%1' asked for help.").arg( peerName ),
tr( "'%1' asked for help.").arg( peerName ), QMessageBox::Ok };
requestReceivedBox.exec();
}
if (unknownClient) {
QMessageBox requestReceivedBox{
QMessageBox::Information, tr("Unknown client asked for help."),
tr("An unknown client with IP '%1' asked for help.").arg(peerAddress),
QMessageBox::Ok};
requestReceivedBox.exec();
} else {
QMessageBox requestReceivedBox{
QMessageBox::Information, tr("'%1' asked for help.").arg(peerName),
tr("'%1' asked for help.").arg(peerName), QMessageBox::Ok};
requestReceivedBox.exec();
}
}

@ -22,32 +22,32 @@
#include "src/Lib/client.h"
#include <QObject>
#include <QHostAddress>
#include <QMessageBox>
#include <QObject>
#include <QtNetwork>
namespace lc {
class ClientHelpNotificationServer : public QObject {
Q_OBJECT
Q_OBJECT
public:
explicit ClientHelpNotificationServer( QObject *argParent = nullptr );
explicit ClientHelpNotificationServer(QObject *argParent = nullptr);
signals:
public slots:
private:
QTcpServer *helpMessageServer = nullptr;
const QHostAddress hostAddress;
QNetworkSession *networkSession = nullptr;
QTcpServer *helpMessageServer = nullptr;
const QHostAddress hostAddress;
QNetworkSession *networkSession = nullptr;
private slots:
void OpenSession();
void SendReply();
void OpenSession();
void SendReply();
};
}
} // namespace lc
#endif // CLIENTHELPNOTIFICATIONSERVER_H

@ -19,45 +19,48 @@
#include "clientpinger.h"
lc::ClientPinger::ClientPinger( const QString &argIP,
const QString &argPingCommand, QObject *argParent ) :
QObject{ argParent },
// Arguments: -c 1 (send 1 ECHO_REQUEST packet) -w 1 (timeout after 1 second) -q (quiet output)
pingArguments{ QStringList{} << "-c" << "1" << "-w" << "1" << "-q" << argIP },
pingCommand{ argPingCommand },
pingProcess{ new QProcess{ this } },
state{ state_t::UNINITIALIZED }
{
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
pingProcess->setProcessEnvironment(env);
// emit ping_string(new QString(*ping_command + " " + ping_arguments->join(" ")));
lc::ClientPinger::ClientPinger(const QString &argIP,
const QString &argPingCommand,
QObject *argParent)
: QObject{argParent},
// Arguments: -c 1 (send 1 ECHO_REQUEST packet) -w 1 (timeout after 1
// second) -q (quiet output)
pingArguments{QStringList{} << "-c"
<< "1"
<< "-w"
<< "1"
<< "-q" << argIP},
pingCommand{argPingCommand},
pingProcess{new QProcess{this}}, state{state_t::UNINITIALIZED} {
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
pingProcess->setProcessEnvironment(env);
// emit ping_string(new QString(*ping_command + " " + ping_arguments->join("
// ")));
}
lc::ClientPinger::~ClientPinger() {
delete pingProcess;
}
lc::ClientPinger::~ClientPinger() { delete pingProcess; }
void lc::ClientPinger::doPing() {
// Initialize the new state to be queried
state_t newState = state_t::UNINITIALIZED;
// Initialize the new state to be queried
state_t newState = state_t::UNINITIALIZED;
// Query the current state of the client
pi