From 6cbf7b19d7bb3fcd2471dbaa531a7b2ae05f0fcc Mon Sep 17 00:00:00 2001 From: dwmw2 Date: Fri, 20 Sep 2002 12:59:59 +0000 Subject: Works now --- (limited to 'noncore/settings') diff --git a/noncore/settings/sshkeys/main.cpp b/noncore/settings/sshkeys/main.cpp index 37be8bf..a7b1d56 100644 --- a/noncore/settings/sshkeys/main.cpp +++ b/noncore/settings/sshkeys/main.cpp @@ -1,14 +1,30 @@ #include #include "sshkeys.h" +#include +#include +#include +#include +#include +#include + int main(int argc, char *argv[]) { - QPEApplication a(argc, argv); - SSHKeysApp app; + QPEApplication a(argc, argv); + SSHKeysApp app; + int fd; + + /* If we had a controlling TTY, detach from it. + This is to ensure the SSH uses ssh-askpass */ + fd = open("/dev/tty", O_RDONLY); + if (fd != -1) { + ioctl(fd, TIOCNOTTY, NULL); + close(fd); + } - a.showMainWidget(&app); + a.showMainWidget(&app); - return a.exec(); + return a.exec(); } diff --git a/noncore/settings/sshkeys/sshkeys.cpp b/noncore/settings/sshkeys/sshkeys.cpp index 08ce18d..5095d16 100644 --- a/noncore/settings/sshkeys/sshkeys.cpp +++ b/noncore/settings/sshkeys/sshkeys.cpp @@ -4,19 +4,47 @@ #include #include #include -#include +#include +#include + +#include +#include +#include +#include +#include +#include + +static char *keynames[] = { "identity", "id_rsa", "id_dsa" }; SSHKeysApp::SSHKeysApp( QWidget* parent, const char* name, WFlags fl ) : SSHKeysBase( parent, name, fl ) { + char *home = getenv("HOME"); + unsigned i; connect(AddButton, SIGNAL(clicked()), this, SLOT(doAddButton())); connect(RefreshListButton, SIGNAL(clicked()), this, SLOT(doRefreshListButton())); connect(RemoveAllButton, SIGNAL(clicked()), this, SLOT(doRemoveAllButton())); - KeyList->horizontalHeader()->setLabel(0, tr("Key")); - KeyList->horizontalHeader()->setLabel(1, tr("Size")); - KeyList->horizontalHeader()->setLabel(2, tr("Fingerprint")); + connect(&addprocess, SIGNAL(receivedStdout(OProcess*,char*,int)), + this, SLOT(log_sshadd_output(OProcess*,char*,int))); + connect(&addprocess, SIGNAL(processExited(OProcess*)), + this, SLOT(ssh_add_exited(OProcess*))); + + connect(KeyFileName, SIGNAL(textChanged(const QString&)), + this, SLOT(add_text_changed(const QString&))); + + if (home) { + for (i = 0; i < sizeof(keynames)/sizeof(keynames[0]); i++) { + char thiskeyname[32]; + + thiskeyname[31] = 0; + snprintf(thiskeyname, 31, "%s/.ssh/%s", home, keynames[i]); + if (!access(thiskeyname, R_OK)) { + KeyFileName->insertItem(thiskeyname); + } + } + } doRefreshListButton(); } @@ -28,31 +56,172 @@ SSHKeysApp::~SSHKeysApp() void SSHKeysApp::doRefreshListButton() { OProcess sshadd_process; + QListViewItem *t = KeyList->firstChild(); + while(t) { + QListViewItem *next = t->nextSibling(); + KeyList->takeItem(t); + delete(t); + t = next; + } + connect(&sshadd_process, SIGNAL(receivedStdout(OProcess*,char*,int)), this, SLOT(get_list_keys_output(OProcess*,char*,int))); - - TextOutput->append("Running ssh-add -l\n"); + + keystate = KeySize; + incoming_keyname=""; + incoming_keysize=""; + incoming_keyfingerprint=""; + +// log_text("Running ssh-add -l"); sshadd_process << "ssh-add" << "-l"; bool ret = sshadd_process.start(OProcess::Block, OProcess::AllOutput); - if (!ret) - TextOutput->append("Error running ssh-add\n"); - KeyList->setText(0, 0, "dwmw2@infradead.org (RSA v1)"); - KeyList->setText(0, 1, "1024"); - KeyList->setText(0, 2, "78:24:04:95:40:fc:b2:80:9b:94:d5:ae:19:56:19:65"); + if (!ret) { + log_text("Error running ssh-add"); + return; + } + } void SSHKeysApp::get_list_keys_output(OProcess *proc, char *buffer, int buflen) { - TextOutput->append(buffer); + int i; + (void) proc; + + for (i=0; iinsertItem(new + QListViewItem(KeyList, incoming_keyname, incoming_keysize, incoming_keyfingerprint)); + incoming_keysize = ""; + incoming_keyfingerprint = ""; + incoming_keyname = ""; + keystate = KeySize; + } else if (isprint(buffer[i])) { + incoming_keyname += buffer[i]; + } else { + incoming_keysize = ""; + incoming_keyfingerprint = ""; + incoming_noise = ""; + keystate = Noise; + goto noise; + } + break; + } + } } +void SSHKeysApp::log_sshadd_output(OProcess *proc, char *buffer, int buflen) +{ + (void)proc; + (void)buflen; + + log_text(buffer); +} + +void SSHKeysApp::ssh_add_exited(OProcess *proc) +{ + (void)proc; + + doRefreshListButton(); + setEnabled(TRUE); + if (proc->exitStatus()) { + + log_text(QString("ssh-add failed")); + } +} + +void SSHKeysApp::add_text_changed(const QString &text) +{ + struct stat sbuf; + + if (!text.length() || (!access(text.ascii(), R_OK) && + !stat(text.ascii(), &sbuf) && + S_ISREG(sbuf.st_mode))) + AddButton->setEnabled(TRUE); + else + AddButton->setEnabled(FALSE); +} void SSHKeysApp::doAddButton() { + addprocess.clearArguments(); + + setEnabled(FALSE); + + if (KeyFileName->currentText().length()) { + addprocess << "ssh-add" << "--" << KeyFileName->currentText(); + log_text(QString("Running ssh-add -- ") + KeyFileName->currentText()); + } else { + addprocess << "ssh-add"; + log_text("Running ssh-add"); + } + bool ret = addprocess.start(OProcess::NotifyOnExit, OProcess::AllOutput); + if (!ret) { + log_text("Error running ssh-add"); + doRefreshListButton(); + setEnabled(TRUE); + } +} +void SSHKeysApp::log_text(const char *text) +{ + TextOutput->append(text); + TextOutput->setCursorPosition(TextOutput->numLines()+1, 0, FALSE); } + void SSHKeysApp::doRemoveAllButton() { - + OProcess sshadd_process; + + connect(&sshadd_process, SIGNAL(receivedStdout(OProcess*,char*,int)), + this, SLOT(log_sshadd_output(OProcess*,char*,int))); + + log_text("Running ssh-add -D"); + sshadd_process << "ssh-add" << "-D"; + bool ret = sshadd_process.start(OProcess::Block, OProcess::AllOutput); + if (!ret) { + log_text("Error running ssh-add"); + } + doRefreshListButton(); } diff --git a/noncore/settings/sshkeys/sshkeys.h b/noncore/settings/sshkeys/sshkeys.h index 4a9f2fe..9a39a2c 100644 --- a/noncore/settings/sshkeys/sshkeys.h +++ b/noncore/settings/sshkeys/sshkeys.h @@ -3,8 +3,7 @@ #define SSHKEYSAPP_H #include "sshkeysbase.h" - -class OProcess; +#include class SSHKeysApp : public SSHKeysBase { @@ -15,13 +14,22 @@ class SSHKeysApp : public SSHKeysBase ~SSHKeysApp(); private: - void sshadd(char **args); + void log_text(const char *text); + enum { Noise, KeyName, KeySize, KeyFingerprint } keystate; + QString incoming_keyname; + QString incoming_keysize; + QString incoming_keyfingerprint; + QString incoming_noise; + OProcess addprocess; private slots: void doAddButton(); void doRefreshListButton(); void doRemoveAllButton(); void get_list_keys_output(OProcess *proc, char *buffer, int buflen); + void log_sshadd_output(OProcess *proc, char *buffer, int buflen); + void ssh_add_exited(OProcess *proc); + void add_text_changed(const QString &text); }; #endif diff --git a/noncore/settings/sshkeys/sshkeysbase.ui b/noncore/settings/sshkeys/sshkeysbase.ui index dc1df28..4c9daa9 100644 --- a/noncore/settings/sshkeys/sshkeysbase.ui +++ b/noncore/settings/sshkeys/sshkeysbase.ui @@ -28,8 +28,14 @@ spacing 6 - + QComboBox + + + text + + + name KeyFileName @@ -83,20 +89,24 @@ enabled - false + true text Clear Keys - + QMultiLineEdit name TextOutput + enabled + true + + sizePolicy 7 @@ -104,12 +114,61 @@ + font + + adobe-helvetica + 8 + + + readOnly true - - QTable + + QListView + + + text + Key Name + + + clickable + true + + + resizeable + true + + + + + text + Size + + + clickable + true + + + resizeable + true + + + + + text + Fingerprint + + + clickable + true + + + resizeable + true + + name KeyList @@ -118,25 +177,9 @@ font adobe-helvetica - 9 + 8 - - resizePolicy - AutoOneFit - - - numRows - 1 - - - numCols - 3 - - - showGrid - false - -- cgit v0.9.0.2