Index: sources/device/DeviceController.cpp =================================================================== diff -u -r2a0e56982ad45cdd98a6d0425c53e52610c29961 -r5a4a26f106ba03759e3a89b19690fa678f8a3aca --- sources/device/DeviceController.cpp (.../DeviceController.cpp) (revision 2a0e56982ad45cdd98a6d0425c53e52610c29961) +++ sources/device/DeviceController.cpp (.../DeviceController.cpp) (revision 5a4a26f106ba03759e3a89b19690fa678f8a3aca) @@ -30,6 +30,8 @@ #include "ApplicationController.h" #include "FileHandler.h" #include "DeviceModels.h" +#include "Settings.h" +#include "encryption.h" // namespace using namespace Model; @@ -106,11 +108,20 @@ connect(&_fileSystemWatcher , SIGNAL( fileChanged(const QString &)), this , SLOT( onWatchFileChanged(const QString &))); - connect(&_ApplicationController , SIGNAL(didPOSTInformationReady(const QString &, const QString &, const QString &)), - this , SLOT( onPOSTInformationReady(const QString &, const QString &, const QString &))); + connect(&_ApplicationController , SIGNAL(didPOSTEthernetData (const QString &)), + this , SLOT( onPOSTEthernetData (const QString &))); + connect(&_ApplicationController , SIGNAL(didPOSTWirelessData (const QString &)), + this , SLOT( onPOSTWirelessData (const QString &))); + connect(&_ApplicationController , SIGNAL(didPOSTBluetoothData (const QString &)), + this , SLOT( onPOSTBluetoothData (const QString &))); + connect(&_ApplicationController , SIGNAL(didPOSTCloudSyncData (const QString &)), + this , SLOT( onPOSTCloudSyncData (const QString &))); DEVICE_DEV_INIT_CONNECTIONS_LIST + connect(this, SIGNAL(didEventThreadChange()), + this, SLOT( onEventThreadChange())); + } /*! @@ -129,6 +140,8 @@ connect(qApp, SIGNAL(aboutToQuit()), this, SLOT(quit())); _thread->start(); moveToThread(_thread); + + emit didEventThreadChange( QPrivateSignal() ); } /*! @@ -552,6 +565,74 @@ } } + +///////////////////////////////////////////// DeviceRootSSHAccess +/*! + * \brief DeviceController::onAttributeRequest + * \details Sets the RootSSHAccess + * \param vRootSSHAccess + */ +void DeviceController::onAttributeRequest(const DeviceRootSSHAccessRequestData &vData) +{ + // ----- initializing the member variable models + _deviceRootSSHAccessRequest._data = vData; + LOG_APPED( _deviceRootSSHAccessRequest.toString()); + + // ----- check that script exists. + QString script; + if ( checkError( DeviceError::checkScript(script, vData.mIsGet ? RootSSHAccess_Get : RootSSHAccess_Set), _deviceRootSSHAccessResponse, script) ) + return; + + // ----- check if the process is not running + if ( _processRootSSHAccess.state() != QProcess::NotRunning ) { + checkError(DeviceError::eDevice_Scripts_Error_IsRunning, _deviceRootSSHAccessResponse); + return; + } + + // ----- run the process + + TimedProcess *timedProcess = new TimedProcess(&_processRootSSHAccess, script, 1000, { _deviceRootSSHAccessRequest._data.mRootSSHAccess ? "YES": "no" }); + timedProcess->start(); +} + +/*! + * \brief DeviceController::onProcessRootSSHAccessFinished + * \details Called when the process to set the RootSSHAccess has finished + * \param vExitCode (int) the exit code + * \note exit code -> 0 : set Accept [MBase] -> Log -> emit + * !0 : set Attrib [MBrgh] -> Log -> emit + * 1 - get an error when in onAttributeRequest : scriptErrorText([Gui Enum ]) + * 2 - get an error when in onProcessRootSSHAccessExitCode : scriptErrorText([vExitCode]) + * 3 - get no error when in onProcessRootSSHAccessExitCode : MDeviceResponse.toString() + * - in case 3 the specific model _data has to be filled prior to the toString to have it in the log. + */ +void DeviceController::onProcessRootSSHAccessExitCode(int vExitCode, QProcess::ExitStatus) +{ + if ( ! checkError(static_cast(vExitCode), _deviceRootSSHAccessResponse, _deviceRootSSHAccessResponse.toString()) ) { // has no error + if (_deviceRootSSHAccessRequest._data.mIsGet) { + bool ok = false; + bool rootSSHAccess = _processRootSSHAccess.readLine().toUInt(&ok); + if ( ok ) { + _deviceRootSSHAccessResponse._data.mMessage = _deviceRootSSHAccessResponse.toString(); + _deviceRootSSHAccessResponse._data.mRootSSHAccess = rootSSHAccess; + } + else { + checkError(DeviceError::eDevice_Scripts_Error_Incorrect_Rsp, _deviceRootSSHAccessResponse, _deviceRootSSHAccessResponse.toString()); + return; + } + } + else { + _deviceRootSSHAccessResponse._data.mMessage = _deviceRootSSHAccessResponse.toString(); + _deviceRootSSHAccessResponse._data.mRootSSHAccess = _deviceRootSSHAccessRequest._data.mRootSSHAccess; + } + LOG_APPED(_deviceRootSSHAccessResponse._data.mMessage); + emit didAttributeResponse(_deviceRootSSHAccessResponse._data); + } + else { + // the error in this case is handled in the checkError + } +} + ///////////////////////////////////////////// DeviceCryptSetup /*! * \brief DeviceController::onAttributeRequest @@ -560,6 +641,8 @@ */ void DeviceController::onAttributeRequest(const DeviceCryptSetupRequestData &vData) { + //DEBUG qDebug() << " ---------- " << vData.mCommand << vData.mPassword; + _deviceCryptSetupRequest._data = vData; // ----- check that script exists. @@ -580,10 +663,11 @@ _processCryptSetup.setEnvironment(QProcess::systemEnvironment() << QString("PASSWORD=%1").arg(_deviceCryptSetupRequest._data.mPassword)); timedProcess->start(); + // Update UI with a response MDeviceCryptSetupResponse model; - model._data.mAccepted = false; - model._data.mMessage = tr("Encrypted Partition %1 started.").arg(_deviceCryptSetupRequest._data.mCommand); - didAttributeResponse(model.data()); + model._data.mAccepted = false; + model._data.mMessage = tr("Encrypted Partition %1 started.").arg(_deviceCryptSetupRequest._data.mCommand); + emit didAttributeResponse(model.data()); } /*! @@ -602,8 +686,26 @@ else deviceInfo = _processCryptSetup.readAll(); model.fromByteArray( deviceInfo, &vExitCode ); // DEBUG: qDebug() << model._data.mEchoInfo; - didAttributeResponse(model.data()); + emit didAttributeResponse(model.data()); LOG_APPED_UI(model.data().mMessage); + + if ( _deviceCryptSetupRequest._data.mCommand == "mount" ) emit didCryptSetupMount(model._data.mAccepted); + + // move the configuration files if the encrypted partition creation was successful. + if ( _deviceCryptSetupRequest._data.mCommand != "setup" ) return; + if ( ! model._data.mAccepted ) return; + QString msg = ""; + int err = 0 ; + //TODO The Settings shall be the Singleton SettingsController and modify the MSettings like the others. + Storage::Settings settings; + err = settings.configurationsMove(&msg); + if ( err ) { + model._data.mAccepted = false ; + model._data.mReason = err ; + model._data.mMessage = msg ; + emit didAttributeResponse(model.data()); + LOG_APPED_UI(model.data().mMessage); + } } ///////////////////////////////////////////// DeviceBluetoothPaired @@ -634,7 +736,7 @@ else deviceInfo = _processBluetoothPairedReset.readAll(); model.fromByteArray( deviceInfo, &vExitCode ); LOG_APPED_UI(model.data().mMessage); - didAttributeResponse(model.data()); + emit didAttributeResponse(model.data()); } ///////////////////////////////////////////// DeviceBluetoothPairedQuery @@ -666,7 +768,7 @@ if ( vStatus ) vExitCode = Device::DeviceError::eDevice_Scripts_Error_Status; else deviceInfo = _processBluetoothPairedQuery.readAll(); model.fromByteArray( deviceInfo, &vExitCode ); - didAttributeResponse(model.data()); + emit didAttributeResponse(model.data()); LOG_APPED_UI(model.data().mMessage); } @@ -718,13 +820,73 @@ emit didWatchFileChange(vFile); } -void DeviceController::onPOSTInformationReady(const QString &vMacEthernet, const QString &vMacWireless, const QString &vMacBluetooth) +void DeviceController::onEventThreadChange() { - _macEthernet = vMacEthernet .trimmed(); - _macWireless = vMacWireless .trimmed(); - _macBluetooth = vMacBluetooth .trimmed(); + //DEBUG qDebug() << " ---------- " << __FUNCTION__ << QThread::currentThread()->objectName() << QThread::currentThread() << qApp->thread(); + if ( QThread::currentThread() != &Threads::_DeviceController_Thread ) { + qCritical() << " ***** Device controller thread not initialized correctly ***** "; + return; + } + _hasThread = true; + checkConfugurationMountReady(); } +void DeviceController::onPOSTEthernetData(const QString &vMacAddress) { + _macEthernet = vMacAddress; + emit didPOSTEthernetData (vMacAddress); +} + +void DeviceController::onPOSTWirelessData(const QString &vMacAddress) { + _macWireless = vMacAddress; + + encryption::varSalt(vMacAddress); + _hasSalt = ! vMacAddress.trimmed().isEmpty(); + checkConfugurationMountReady(); + + emit didPOSTWirelessData (vMacAddress); +} + +void DeviceController::onPOSTBluetoothData(const QString &vMacAddress) { + _macBluetooth = vMacAddress; + emit didPOSTBluetoothData (vMacAddress); +} + +void DeviceController::onPOSTCloudSyncData(const QString &vNetAddress) { + _netCloudSync = vNetAddress; + emit didPOSTCloudSyncData (vNetAddress); +} + +void DeviceController::checkConfugurationMountReady() +{ + /// in manufacturing the system is logged with root and configurations are in /home/root + /// therefore no need to mount the cononfiguraiton partition. + /// also for in manufacturing the partition is being set up + /// and is less steps for setup if the partition is not mounted. + if ( gEnableManufacturing ) return; + + + if ( ! ( _hasThread && _hasSalt ) ) return; + + DeviceCryptSetupRequestData data; + data.mCommand = "mount"; + bool ok = false; + data.mPassword = encryption::configurationsPassword( ok ); + if ( ! ok ) { // not enough infromation to create a secure passowrd + // status(tr("Not enough secure information provided")); + } + else { + onAttributeRequest(data); + } + + // I_AM_HERE + // HERE move the settings read from ApplicationController to here + // here is when the DeviceController is moved to its thread + // and now can start mounting the encrypted partition + // and then read the settings. + // TODO don't forget to check for the required configurations files and parameters in the settings class. + // and take care of the security flag in the Storage class. +} + ///////////////////////////////////////////// DeviceFactoryReset /*! * \brief DeviceController::onAttributeRequest