Добавлено: ведение истории подключения

This commit is contained in:
Alexander Zhirov 2022-08-03 11:22:23 +03:00
parent d3ae4794c8
commit 6d58ccb46c
4 changed files with 46 additions and 5 deletions

37
db.c
View File

@ -9,6 +9,7 @@
//#include <sqlite3.h> //#include <sqlite3.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <time.h>
#include "db.h" #include "db.h"
#include "node_settings.h" #include "node_settings.h"
@ -561,3 +562,39 @@ int dbSaveMonitors(char *name)
return result; return result;
} }
int dbInsertHistory(char *login, char *host)
{
int result = 0;
if (!(login && strlen(login)) || !(host && strlen(host)))
return -1;
sqlite3 *db = dbGetBase(getPathDB(NULL));
if (!db)
{
return -2;
}
sqlite3_stmt *res;
char *sql = "INSERT INTO `history` (`login`, `host`, `time`) VALUES (?, ?, ?)";
if (sqlite3_prepare_v2(db, sql, -1, &res, 0) == SQLITE_OK)
{
sqlite3_bind_text(res, 1, login, -1, 0);
sqlite3_bind_text(res, 2, host, -1, 0);
sqlite3_bind_int(res, 3, (unsigned)time(NULL));
}
if (sqlite3_step(res) == SQLITE_DONE)
{
sqlite3_finalize(res);
sqlite3_close(db);
return 0;
}
sqlite3_finalize(res);
sqlite3_close(db);
return result;
}

1
db.h
View File

@ -52,5 +52,6 @@ bool dbWriteParameter(Parameter name, bool set);
bool dbWriteValue(Value name, bool set); bool dbWriteValue(Value name, bool set);
bool dbSetUserNameCurrent(char *current); bool dbSetUserNameCurrent(char *current);
int dbAddServer(char *ip, char *dns); int dbAddServer(char *ip, char *dns);
int dbInsertHistory(char *login, char *host);
#endif /* DB_H_ */ #endif /* DB_H_ */

Binary file not shown.

13
gui.c
View File

@ -27,13 +27,15 @@ static int guiExit(Ihandle *self)
static int guiConnect(Ihandle *self) static int guiConnect(Ihandle *self)
{ {
char *result = getHostIP(IupGetAttribute(IupGetDialogChild(self, "SERVER"), "VALUE")); char *host = IupGetAttribute(IupGetDialogChild(self, "SERVER"), "VALUE");
char *login = IupGetAttribute(IupGetDialogChild(self, "USER"), "LINEVALUE");
char *result = getHostIP(host);
if (!result) if (!result)
return IUP_DEFAULT; return IUP_DEFAULT;
setParameterValue(PARAMETER_SERVER, VALUE_SERVER, result); setParameterValue(PARAMETER_SERVER, VALUE_SERVER, result);
setParameterValue(PARAMETER_USERNAME, VALUE_USERNAME, IupGetAttribute(IupGetDialogChild(self, "USER"), "LINEVALUE")); setParameterValue(PARAMETER_USERNAME, VALUE_USERNAME, login);
setParameterValue(PARAMETER_PASSWORD, VALUE_PASSWORD, IupGetAttribute(IupGetDialogChild(self, "PASSWORD"), "LINEVALUE")); setParameterValue(PARAMETER_PASSWORD, VALUE_PASSWORD, IupGetAttribute(IupGetDialogChild(self, "PASSWORD"), "LINEVALUE"));
Arguments args; Arguments args;
@ -45,11 +47,12 @@ static int guiConnect(Ihandle *self)
// if (free_rdp_connect(args.argc, args.argv) != XF_EXIT_DNS_NAME_NOT_FOUND) // if (free_rdp_connect(args.argc, args.argv) != XF_EXIT_DNS_NAME_NOT_FOUND)
// { // {
if (!dbAddServer(result, IupGetAttribute(IupGetDialogChild(self, "SERVER"), "VALUE"))) dbInsertHistory(login, host);
if (!dbAddServer(result, host))
{ {
IupSetAttribute(IupGetDialogChild(self, "SERVER"), "APPENDITEM", IupGetAttribute(IupGetDialogChild(self, "SERVER"), "VALUE")); IupSetAttribute(IupGetDialogChild(self, "SERVER"), "APPENDITEM", host);
} }
dbSetUserNameCurrent(IupGetAttribute(IupGetDialogChild(self, "USER"), "LINEVALUE")); dbSetUserNameCurrent(login);
// } // }
freeArguments(&args); freeArguments(&args);