You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
164 lines
6.3 KiB
164 lines
6.3 KiB
#include "main.h" |
|
|
|
// Main sets up the Application/GUI, and tries to retrieveLogin() |
|
int main(int argc, char *argv[]) { |
|
QApplication app(argc,argv); |
|
QWidget *window = new QWidget; |
|
|
|
domainLE = new QLineEdit; |
|
tokenUsername = new QLineEdit; |
|
tokenCode = new QLineEdit; |
|
ntUsername = new QLineEdit; |
|
ntPassword = new QLineEdit; |
|
authSystemLE = new QLineEdit; |
|
rememberCredentials = new QCheckBox; |
|
vboxLayout = new QVBoxLayout; |
|
vdiLoginLayout = new QFormLayout; |
|
|
|
domainLE->setPlaceholderText("Horizon Domain"); |
|
tokenUsername->setPlaceholderText("Email address"); |
|
tokenUsername->setMinimumWidth(250); |
|
tokenCode->setPlaceholderText("RSA Token code"); |
|
ntUsername->setPlaceholderText("Windows username"); |
|
ntPassword->setPlaceholderText("Windows password"); |
|
ntPassword->setEchoMode(QLineEdit::Password); |
|
QPushButton loginBtn("Log In"); |
|
loginBtn.setToolTip("Click here to log in using the data entered."); |
|
authSystemLE->setPlaceholderText("Optional Auth System"); |
|
// Try to populate form before adding to the layout |
|
retrieveLogin(); |
|
|
|
vdiLoginLayout->addRow("Domain: ", domainLE); |
|
vdiLoginLayout->addRow("Token Username:", tokenUsername); |
|
vdiLoginLayout->addRow("RSA Token:", tokenCode); |
|
vdiLoginLayout->addRow("NT Username:", ntUsername); |
|
vdiLoginLayout->addRow("NT Password:", ntPassword); |
|
vdiLoginLayout->addRow("Auth System:", authSystemLE); |
|
vdiLoginLayout->addRow("Remember Credentials:", rememberCredentials); |
|
|
|
vboxLayout->addItem(vdiLoginLayout); |
|
vboxLayout->addWidget(&loginBtn); |
|
|
|
QObject::connect(&loginBtn, &QPushButton::released, tryLogin); |
|
|
|
window->setLayout(vboxLayout); |
|
window->show(); |
|
return app.exec(); |
|
|
|
} |
|
|
|
// walletOpen() returns a pointer to the kwallet, or throws an error if the wallet is unable to open. |
|
KWallet::Wallet* walletOpen() { |
|
KWallet::Wallet *wallet = KWallet::Wallet::openWallet(KWallet::Wallet::NetworkWallet(), 0, KWallet::Wallet::Synchronous); |
|
if (wallet->hasFolder(KWallet::Wallet::FormDataFolder())) { |
|
if (!wallet->setFolder(KWallet::Wallet::FormDataFolder())) { |
|
std::cout << "Wallet folder could not be set." << std::endl; |
|
throw -1; |
|
} |
|
} else { |
|
std::cout << "Wallet did not have folder, creating." << std::endl; |
|
if(wallet->createFolder(KWallet::Wallet::FormDataFolder())) { |
|
if (!wallet->setFolder(KWallet::Wallet::FormDataFolder())) { |
|
std::cout << "Wallet folder could not be set." << std::endl; |
|
throw -1; |
|
} |
|
} else { |
|
std::cout << "Could not create folder." << std::endl; |
|
throw -1; |
|
} |
|
} |
|
return wallet; |
|
} |
|
|
|
// retrieve login information from kwallet using walletOpen() or die |
|
void retrieveLogin() { |
|
try { |
|
wallet = walletOpen(); |
|
} catch (int e) { |
|
exit(-1); |
|
} |
|
QMap<QString, QString> map; |
|
if (wallet->readMap("http://rsa-vdi.nightmare.haus/#authInfo", map) == 0) { |
|
domainLE->setText(map[QString("domain")]); |
|
tokenUsername->setText(map[QString("tokenUsername")]); |
|
ntUsername->setText(map[QString("ntUsername")]); |
|
ntPassword->setText(map[QString("ntPassword")]); |
|
authSystemLE->setText(map[QString("authSystem")]); |
|
if (tokenUsername->text().length() > 0) { |
|
rememberCredentials->setChecked(true); |
|
} |
|
} else { |
|
std::cout << "Error loading from wallet, is it populated?" << std::endl; |
|
} |
|
} |
|
// save login information to kwallet using walletOpen() or die |
|
void saveLogin() { |
|
try { |
|
wallet = walletOpen(); |
|
} catch (int e) { |
|
exit(-1); |
|
} |
|
QMap<QString, QString> map; |
|
map[QString("domain")] = domainLE->text(); |
|
map[QString("tokenUsername")] = tokenUsername->text(); |
|
map[QString("ntUsername")] = ntUsername->text(); |
|
map[QString("ntPassword")] = ntPassword->text(); |
|
map[QString("authSystem")] = authSystemLE->text(); |
|
|
|
if (!wallet->writeMap("http://rsa-vdi.nightmare.haus/#authInfo", map)) { |
|
std::cout << "Error writing to Wallet!" << std::endl; |
|
} |
|
|
|
} |
|
|
|
void tryLogin() { |
|
if (rememberCredentials->isChecked()) { |
|
saveLogin(); |
|
} |
|
if(debug) { |
|
std::cout << "tryLogin()" << std::endl; |
|
std::cout << "\tToken Username: " << tokenUsername->text().toStdString() << std::endl; |
|
std::cout << "\tToken Code: " << tokenCode->text().toStdString() << std::endl; |
|
std::cout << "\tntUsername: " << ntUsername->text().toStdString() << std::endl; |
|
std::cout << "\tntPassword Length: " << ntPassword->text().length() << std::endl; |
|
std::cout << "\tAuth System: " << authSystemLE->text().toStdString() << std::endl; |
|
if (rememberCredentials->isChecked()) { |
|
std::cout << "\tRemember creds: true" << std::endl; |
|
} else { |
|
std::cout << "\tRemember creds: false" << std::endl; |
|
} |
|
} |
|
|
|
// -q, --nonInteractive Connect automatically if enough values are given on the command line. |
|
QString command = "vmware-view -q"; |
|
if (domainLE->text().length() > 0) { |
|
// -s, --serverURL=<broker URL> Specify connection broker. |
|
command += " -s \'" + domainLE->text() + "\'"; |
|
} |
|
if (authSystemLE->text().length() > 0) { |
|
// -d, --domainName=<domain name> Specify domain for password authentication |
|
command += " -d \'" + authSystemLE->text() + "\'"; |
|
} |
|
if (tokenUsername->text().length() > 0) { |
|
// -t, --tokenUserName=<token user name> Specify user name for RSA or Radius authentication. |
|
command += " -t \'" + tokenUsername->text() + "\'"; |
|
} |
|
if (tokenCode->text().length() > 0 ) { |
|
// -c, --passcode=<passcode> Specify passcode for RSA or Radius authentication. |
|
command += " -c \'" + tokenCode->text() + "\'"; |
|
} |
|
if (ntUsername->text().length() > 0) { |
|
// -u, --userName=<user name> Specify user name for password authentication. |
|
command += " -u \'" + ntUsername->text() + "\'"; |
|
} |
|
if (ntPassword->text().length() > 0) { |
|
//-p, --password=<password> Specify password for password authentication. |
|
command += " -p \'" + ntPassword->text() + "\'"; |
|
} |
|
if (debug) { |
|
std::cout << command.toStdString() << std::endl; |
|
} else { |
|
system(command.toStdString().c_str()); |
|
} |
|
exit(0); |
|
}
|
|
|