Esempio n. 1
0
int main(int argc, const char * argv[])
{
	Bool result = TRUE;

	if ((argc < 2) || (argc > 3))
	{
		printf(USAGE);
		return -1;
	}


	if (strcmp(argv[1], LOAD_RULES) == 0)
	{
		if (argc != 3)
		{
			printf("A path to a rules file must be specified in order to load rules.\n");
			return -1;
		}
		else
		{
			result = loadRules(argv[2]);
			if (!result)
			{
				return -1;
			}
			return 0;
		}
	}
	else if (strcmp(argv[1], LOAD_HOSTS) == 0)
	{
		if (argc != 3)
		{
			printf("A path to a hosts file must be specified in order to load hosts.\n");
			return -1;
		}
		else
		{
			result = loadHosts(argv[2]);
			if (!result)
			{
				return -1;
			}
			return 0;
		}
	}
	else if (argc != 2)
	{
		printf("Any action other than %s, %s must not take any parameters.\n", LOAD_RULES, LOAD_HOSTS);
		return -1;
	}

	if (strcmp(argv[1], ACTIVATE) == 0)
	{
		result = activate();
	}
	else if (strcmp(argv[1], DEACTIVATE) == 0)
	{
		result = deactivate();
	}
	else if (strcmp(argv[1], SHOW_RULES) == 0)
	{
		result = showRules();
	}
	else if (strcmp(argv[1], CLEAR_RULES) == 0)
	{
		result = clearRules();
	}
	else if (strcmp(argv[1], SHOW_LOG) == 0)
	{
		result = showLog();
	}
	else if (strcmp(argv[1], CLEAR_LOG) == 0)
	{
		result = clearLog();
	}
	else if (strcmp(argv[1], SHOW_CONNECTION_TABLE) == 0)
	{
		result = showConnectionTable();
	}
	else if (strcmp(argv[1], SHOW_HOSTS) == 0)
	{
		result = showHosts();
	}
	else
	{
		printf("The only valid actions are: %s, %s, %s, %s, %s, %s, %s, %s\n",
			   ACTIVATE, DEACTIVATE, SHOW_RULES, CLEAR_RULES, LOAD_RULES, SHOW_LOG, 
			   CLEAR_LOG, SHOW_CONNECTION_TABLE, SHOW_HOSTS, LOAD_HOSTS);
	}

	if (result)
	{
		return 0;
	}
	else
	{
		return -1;
	}
}
Esempio n. 2
0
KSSH::KSSH(QWidget *parent)
    : QDialog(parent)
{
    setupUi(this);

    QLayout *lay;
    lay = layout();
    if (lay)
        lay->setSizeConstraint(QLayout::SetFixedSize);

    opt = false;
    mopt = false;

    editorF->hide();

    QSize s = size();

    QPoint p(s.width(), s.height());
    QPoint po = pos();
    QDesktopWidget *d = QApplication::desktop();
    int w = d->width();                   // returns desktop width
    int h = d->height ();                  // returns desktop height
    int x = 0, y = 0;
    if ((p + po).x()>w)
        po.setX(x = w-p.x());
    if ((p + po).y()>h)
        po.setY(y = h-p.y());

    if (x<0)
        po.setX(0);
    if (y<0)
        po.setY(0);

    move(po);
    optionsGB->hide();
    moreF->hide();

    adjustSize();

    compUser = new KCompletion();
    userCB->setCompletionObject(compUser);

    compHost = new KCompletion();

    hostCB->setCompletionObject(compHost);

    hostCB->setFocus();

    connect(hostCB, SIGNAL(editTextChanged(const QString&)), this, SLOT(userFor(const QString&)));

    connect(compHost, SIGNAL(match(const QString&)), this, SLOT(userFor(const QString&)));

    userCB->insertItem(1, "");
    hostCB->insertItem(2, "");

    loadHosts();

    loadOptions("DefaultConfig");

    connect(aboutPB, SIGNAL(clicked()), this, SLOT(about()));
    connect(optionsPB, SIGNAL(clicked()), this, SLOT(options()));
    connect(morePB, SIGNAL(clicked()), this, SLOT(moreOptions()));

    connect(hostTB, SIGNAL(clicked()), this, SLOT(hostEditor()));
    connect(userTB, SIGNAL(clicked()), this, SLOT(userEditor()));
    connect(cancelPB, SIGNAL(clicked()), this, SLOT(cancelEditor()));
    connect(okPB, SIGNAL(clicked()), this, SLOT(okEditor()));

    connect(connectPB, SIGNAL(clicked()), this, SLOT(ssh()));
    connect(savePB, SIGNAL(clicked()), this, SLOT(saveAsDefault()));
    connect(quitPB, SIGNAL(clicked()), this, SLOT(exitHandler()));

    KConfigGroup general_group = KGlobal::config()->group("General");

    int fi = hostCB->findText(general_group.readEntry("LastHost"));
    if (fi)
        hostCB->setCurrentIndex(fi);

    int def = KGlobalSettings::completionMode();
    int mode = general_group.readEntry("HostCompletionMode", def);
    hostCB->setCompletionMode((KGlobalSettings::Completion) mode);

    mode = general_group.readEntry("UserCompletionMode", def);
    userCB->setCompletionMode((KGlobalSettings::Completion)mode);
    setWindowIcon(KIcon("kssh.png"));
}