2022-07-06 17:51:51 +00:00
|
|
|
|
/*
|
|
|
|
|
* gui.c
|
|
|
|
|
*
|
|
|
|
|
* Created on: 6 июл. 2022 г.
|
|
|
|
|
* Author: alexander
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
|
|
#include "gui.h"
|
|
|
|
|
#include "settings.h"
|
|
|
|
|
#include "node_settings.h"
|
|
|
|
|
#include "images.h"
|
|
|
|
|
#include "arguments.h"
|
2022-07-15 14:16:58 +00:00
|
|
|
|
#include "address.h"
|
2023-02-20 06:41:03 +00:00
|
|
|
|
#include "keylang.h"
|
2022-07-06 17:51:51 +00:00
|
|
|
|
|
2022-07-14 10:40:51 +00:00
|
|
|
|
#include "db.h"
|
2022-07-15 15:53:03 +00:00
|
|
|
|
#include "xrdp.h"
|
2023-02-02 16:33:19 +00:00
|
|
|
|
#include "../xfreerdp.h"
|
2022-07-14 10:40:51 +00:00
|
|
|
|
|
2022-07-06 17:51:51 +00:00
|
|
|
|
static int guiExit(Ihandle *self)
|
|
|
|
|
{
|
|
|
|
|
return IUP_CLOSE;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-02 05:47:23 +00:00
|
|
|
|
int isEmptyFieldServerUser(Ihandle *self)
|
|
|
|
|
{
|
|
|
|
|
char *name = IupGetAttribute(self, "NAME");
|
|
|
|
|
if (!strcmp(name, "SERVER"))
|
|
|
|
|
return !strcmp(IupGetAttribute(IupGetDialogChild(self, "USER"), "LINEVALUE"), "\0");
|
|
|
|
|
else
|
|
|
|
|
return !strcmp(IupGetAttribute(IupGetDialogChild(self, "SERVER"), "VALUE"), "\0");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int activeBtnConnect(Ihandle *self, int c, char *value)
|
|
|
|
|
{
|
|
|
|
|
if (!strcmp(value, "\0") || isEmptyFieldServerUser(self))
|
|
|
|
|
{
|
|
|
|
|
IupSetInt(IupGetDialogChild(self, "CONNECT"), "ACTIVE", 0);
|
2023-02-16 12:38:49 +00:00
|
|
|
|
#ifdef IUP_WITH_COLOR_BUTTONS
|
2023-02-02 05:47:23 +00:00
|
|
|
|
IupSetAttribute(IupGetDialogChild(self, "CONNECT"), "BGCOLOR", "49 54 61");
|
|
|
|
|
IupSetAttribute(IupGetDialogChild(self, "CONNECT"), "FGCOLOR", "238 238 238");
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
IupSetInt(IupGetDialogChild(self, "CONNECT"), "ACTIVE", 1);
|
2023-02-16 12:38:49 +00:00
|
|
|
|
#ifdef IUP_WITH_COLOR_BUTTONS
|
2023-02-02 05:47:23 +00:00
|
|
|
|
IupSetAttribute(IupGetDialogChild(self, "CONNECT"), "BGCOLOR", "0 179 0");
|
|
|
|
|
IupSetAttribute(IupGetDialogChild(self, "CONNECT"), "FGCOLOR", "255 255 255");
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
return IUP_DEFAULT;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-06 17:51:51 +00:00
|
|
|
|
static int guiConnect(Ihandle *self)
|
|
|
|
|
{
|
2022-08-03 08:22:23 +00:00
|
|
|
|
char *host = IupGetAttribute(IupGetDialogChild(self, "SERVER"), "VALUE");
|
|
|
|
|
char *result = getHostIP(host);
|
2022-07-15 14:16:58 +00:00
|
|
|
|
|
|
|
|
|
if (!result)
|
2023-02-02 05:47:23 +00:00
|
|
|
|
return IUP_IGNORE;
|
|
|
|
|
|
|
|
|
|
char *login = IupGetAttribute(IupGetDialogChild(self, "USER"), "LINEVALUE");
|
|
|
|
|
|
|
|
|
|
if (!strcmp(login, "\0"))
|
|
|
|
|
return IUP_IGNORE;
|
2022-07-15 14:16:58 +00:00
|
|
|
|
|
|
|
|
|
setParameterValue(PARAMETER_SERVER, VALUE_SERVER, result);
|
2022-08-03 08:22:23 +00:00
|
|
|
|
setParameterValue(PARAMETER_USERNAME, VALUE_USERNAME, login);
|
2022-07-08 16:45:45 +00:00
|
|
|
|
setParameterValue(PARAMETER_PASSWORD, VALUE_PASSWORD, IupGetAttribute(IupGetDialogChild(self, "PASSWORD"), "LINEVALUE"));
|
2022-07-06 17:51:51 +00:00
|
|
|
|
|
2022-07-08 16:45:45 +00:00
|
|
|
|
Arguments args;
|
|
|
|
|
buildArguments(&args);
|
|
|
|
|
for (int i = 0; i < args.argc; ++i)
|
2022-07-06 17:51:51 +00:00
|
|
|
|
{
|
2022-07-08 16:45:45 +00:00
|
|
|
|
printf("%s\n", args.argv[i]);
|
2022-07-06 17:51:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-02-23 15:30:16 +00:00
|
|
|
|
// Добавление в историю любой попытки подключиться к удаленному серверу
|
|
|
|
|
dbInsertHistory(login, host);
|
|
|
|
|
|
2023-02-02 05:47:23 +00:00
|
|
|
|
enum XF_EXIT_CODE xCode = free_rdp_connect(args.argc, args.argv);
|
|
|
|
|
|
|
|
|
|
if (!(xCode == XF_EXIT_DNS_NAME_NOT_FOUND || xCode == XF_EXIT_CONNECT_FAILED || xCode == XF_EXIT_TLS_CONNECT_FAILED))
|
|
|
|
|
{
|
|
|
|
|
IupSetAttribute(IupGetDialogChild(self, "PASSWORD"), "VALUE", "");
|
|
|
|
|
|
2022-08-03 08:22:23 +00:00
|
|
|
|
if (!dbAddServer(result, host))
|
2022-07-15 15:53:03 +00:00
|
|
|
|
{
|
2022-08-03 08:22:23 +00:00
|
|
|
|
IupSetAttribute(IupGetDialogChild(self, "SERVER"), "APPENDITEM", host);
|
2022-07-15 15:53:03 +00:00
|
|
|
|
}
|
2022-08-03 08:22:23 +00:00
|
|
|
|
dbSetUserNameCurrent(login);
|
2023-02-02 05:47:23 +00:00
|
|
|
|
}
|
2022-07-15 14:16:58 +00:00
|
|
|
|
|
2022-07-15 15:53:03 +00:00
|
|
|
|
freeArguments(&args);
|
|
|
|
|
|
2022-07-06 17:51:51 +00:00
|
|
|
|
return IUP_DEFAULT;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-22 15:40:30 +00:00
|
|
|
|
static char* createHostsList(Ihandle *iupList)
|
2022-07-15 14:16:58 +00:00
|
|
|
|
{
|
|
|
|
|
Hosts *hosts = dbGetHostsList();
|
|
|
|
|
char *indexItem = NULL;
|
|
|
|
|
char *serverName = NULL;
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < hosts->size; ++i)
|
|
|
|
|
{
|
|
|
|
|
Host *host = hosts->host[i];
|
2022-07-19 10:13:57 +00:00
|
|
|
|
size_t size = strlen(host->data[0]) + 1;
|
|
|
|
|
indexItem = (char *)malloc(sizeof(char) * size);
|
|
|
|
|
strncpy(indexItem, host->data[0], size);
|
|
|
|
|
size = strlen(host->data[1]) + 1;
|
|
|
|
|
serverName = (char *)malloc(sizeof(char) * size);
|
|
|
|
|
strncpy(serverName, host->data[1], size);
|
2022-07-15 14:16:58 +00:00
|
|
|
|
|
|
|
|
|
IupSetAttribute(iupList, indexItem, serverName);
|
|
|
|
|
if (atoi(host->data[2]))
|
|
|
|
|
IupSetAttribute(iupList, "VALUE", serverName);
|
|
|
|
|
}
|
|
|
|
|
dbFreeHosts(hosts);
|
2023-02-22 15:40:30 +00:00
|
|
|
|
|
|
|
|
|
return serverName;
|
2022-07-15 14:16:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 06:41:03 +00:00
|
|
|
|
#ifdef IUP_WITH_LANGUAGE_KEYBOARD_ICON
|
|
|
|
|
static int k_any(Ihandle *self, int key)
|
|
|
|
|
{
|
|
|
|
|
int langcode = getKeyboardLanguage();
|
|
|
|
|
if (langcode)
|
|
|
|
|
{
|
|
|
|
|
if (langcode == 1)
|
|
|
|
|
IupSetAttribute(IupGetDialogChild(self, "KEYBOARD"), "IMAGE", "keyboardUs");
|
|
|
|
|
else if (langcode == 2)
|
|
|
|
|
IupSetAttribute(IupGetDialogChild(self, "KEYBOARD"), "IMAGE", "keyboardRu");
|
|
|
|
|
else
|
|
|
|
|
IupSetAttribute(IupGetDialogChild(self, "KEYBOARD"), "IMAGE", "keyboardEmpty");
|
|
|
|
|
}
|
|
|
|
|
return IUP_DEFAULT;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2022-07-06 17:51:51 +00:00
|
|
|
|
Ihandle* guiStart()
|
|
|
|
|
{
|
|
|
|
|
Ihandle *dlg;
|
|
|
|
|
Ihandle *icon, *bgHead;
|
|
|
|
|
Ihandle *vBoxMain, *hBoxServer, *hBoxUser, *hBoxPassword, *hBoxButtons; // Boxes
|
|
|
|
|
Ihandle *labelImage;
|
|
|
|
|
Ihandle *labelServer, *inputServer;
|
|
|
|
|
Ihandle *labelUser, *inputUser;
|
|
|
|
|
Ihandle *labelPassword, *inputPassword;
|
|
|
|
|
Ihandle *btnConnect, *btnClose, *btnSettings;
|
|
|
|
|
|
|
|
|
|
icon = IupImageRGBA(64, 64, idata_icon);
|
|
|
|
|
IupSetHandle("icon", icon);
|
|
|
|
|
|
|
|
|
|
labelImage = IupLabel(NULL);
|
|
|
|
|
|
|
|
|
|
bgHead = IupImageRGBA(405, 72, idata_head);
|
|
|
|
|
IupSetAttributeHandle(labelImage, "IMAGE", bgHead);
|
|
|
|
|
|
|
|
|
|
labelServer = IupLabel("Компьютер:");
|
|
|
|
|
IupSetAttribute(labelServer, "SIZE", "80x16");
|
|
|
|
|
IupSetAttribute(labelServer, "ALIGNMENT", "ARIGHT:ACENTER");
|
|
|
|
|
IupSetAttribute(labelServer, "PADDING", "5");
|
2022-07-15 14:16:58 +00:00
|
|
|
|
|
|
|
|
|
inputServer = IupList(NULL);
|
2022-07-06 17:51:51 +00:00
|
|
|
|
IupSetAttribute(inputServer, "NAME", "SERVER");
|
2023-02-02 05:47:23 +00:00
|
|
|
|
IupSetAttribute(inputServer, "TIP", "IP-адрес или имя удаленного сервера\n(обязательное для заполнения поле)");
|
2023-02-22 15:40:30 +00:00
|
|
|
|
char *hostname = createHostsList(inputServer);
|
2022-07-06 17:51:51 +00:00
|
|
|
|
IupSetAttribute(inputServer, "SIZE", "100");
|
2022-07-15 14:16:58 +00:00
|
|
|
|
IupSetAttribute(inputServer, "EDITBOX", "YES");
|
|
|
|
|
IupSetAttribute(inputServer, "DROPDOWN", "YES");
|
2023-02-02 05:47:23 +00:00
|
|
|
|
IupSetAttribute(inputServer, "MASK", "[A-Za-z0-9/./-]*");
|
|
|
|
|
IupSetCallback(inputServer, "EDIT_CB", (Icallback) activeBtnConnect);
|
2022-07-06 17:51:51 +00:00
|
|
|
|
hBoxServer = IupHbox(labelServer, inputServer, NULL);
|
|
|
|
|
IupSetAttribute(hBoxServer, "MARGIN", "10x10");
|
2022-07-19 10:13:57 +00:00
|
|
|
|
|
2022-07-06 17:51:51 +00:00
|
|
|
|
labelUser = IupLabel("Пользователь:");
|
|
|
|
|
IupSetAttribute(labelUser, "SIZE", "80x16");
|
|
|
|
|
IupSetAttribute(labelUser, "ALIGNMENT", "ARIGHT:ACENTER");
|
|
|
|
|
IupSetAttribute(labelUser, "PADDING", "5");
|
|
|
|
|
inputUser = IupText(NULL);
|
|
|
|
|
IupSetAttribute(inputUser, "NAME", "USER");
|
2023-02-02 16:33:19 +00:00
|
|
|
|
IupSetAttribute(inputUser, "TIP", "<домен>\\<имя пользователя>\n<имя пользователя>@<домен>\n(обязательное для заполнения поле)");
|
2023-02-22 15:40:30 +00:00
|
|
|
|
char *username = getSetValueCurrent(PARAMETER_USERNAME);
|
|
|
|
|
IupSetAttribute(inputUser, "VALUE", username);
|
2022-07-06 17:51:51 +00:00
|
|
|
|
IupSetAttribute(inputUser, "SIZE", "100");
|
2023-02-02 05:47:23 +00:00
|
|
|
|
IupSetAttribute(inputUser, "MASK", "(/w|[/./\\/@/-])*");
|
|
|
|
|
IupSetCallback(inputUser, "ACTION", (Icallback) activeBtnConnect);
|
2022-07-06 17:51:51 +00:00
|
|
|
|
hBoxUser = IupHbox(labelUser, inputUser, NULL);
|
|
|
|
|
IupSetAttribute(hBoxUser, "MARGIN", "10x0");
|
2022-07-19 10:13:57 +00:00
|
|
|
|
|
2022-07-06 17:51:51 +00:00
|
|
|
|
labelPassword = IupLabel("Пароль:");
|
|
|
|
|
IupSetAttribute(labelPassword, "SIZE", "80x16");
|
|
|
|
|
IupSetAttribute(labelPassword, "ALIGNMENT", "ARIGHT:ACENTER");
|
|
|
|
|
IupSetAttribute(labelPassword, "PADDING", "5");
|
|
|
|
|
inputPassword = IupText(NULL);
|
|
|
|
|
IupSetAttribute(inputPassword, "SIZE", "100");
|
|
|
|
|
IupSetAttribute(inputPassword, "NAME", "PASSWORD");
|
2022-07-14 10:40:51 +00:00
|
|
|
|
IupSetAttribute(inputPassword, "TIP", "Пароль пользователя (необязательно)");
|
|
|
|
|
IupSetAttribute(inputPassword, "VALUE", getSetValueCurrent(PARAMETER_PASSWORD));
|
2022-07-06 17:51:51 +00:00
|
|
|
|
IupSetAttribute(inputPassword, "PASSWORD", "YES");
|
|
|
|
|
hBoxPassword = IupHbox(labelPassword, inputPassword, NULL);
|
|
|
|
|
IupSetAttribute(hBoxPassword, "MARGIN", "10x10");
|
2022-07-19 10:13:57 +00:00
|
|
|
|
|
2023-02-20 06:41:03 +00:00
|
|
|
|
#ifdef IUP_WITH_LANGUAGE_KEYBOARD_ICON
|
|
|
|
|
Ihandle *keyboardRu, *keyboardUs, *keyboardEmpty, *iconLang;
|
|
|
|
|
keyboardEmpty = IupImageRGBA(32, 32, empty_keyboard);
|
|
|
|
|
IupSetHandle("keyboardEmpty", keyboardEmpty);
|
|
|
|
|
keyboardRu = IupImageRGBA(32, 32, ru_keyboard);
|
|
|
|
|
IupSetHandle("keyboardRu", keyboardRu);
|
|
|
|
|
keyboardUs = IupImageRGBA(32, 32, us_keyboard);
|
|
|
|
|
IupSetHandle("keyboardUs", keyboardUs);
|
|
|
|
|
iconLang = IupLabel(NULL);
|
|
|
|
|
IupSetAttribute(iconLang, "NAME", "KEYBOARD");
|
|
|
|
|
IupSetAttribute(iconLang, "IMAGE", "keyboardRu");
|
|
|
|
|
IupSetAttribute(iconLang, "FLOATING", "YES");
|
|
|
|
|
IupSetAttribute(iconLang, "POSITION", "13,222");
|
|
|
|
|
IupSetAttribute(iconLang, "TIP", "Текущая раскладка клавиатуры (Alt+Shift)");
|
|
|
|
|
#endif
|
|
|
|
|
|
2022-07-06 17:51:51 +00:00
|
|
|
|
btnConnect = IupButton("Подключение", NULL);
|
|
|
|
|
IupSetHandle("CONNECT", btnConnect);
|
|
|
|
|
IupSetAttribute(btnConnect, "NAME", "CONNECT");
|
2022-07-14 10:40:51 +00:00
|
|
|
|
IupSetAttribute(btnConnect, "TIP", "Выполнить подключение");
|
2023-02-22 15:40:30 +00:00
|
|
|
|
if (username && hostname)
|
|
|
|
|
IupSetAttribute(btnConnect, "ACTIVE", "YES");
|
|
|
|
|
else
|
|
|
|
|
IupSetAttribute(btnConnect, "ACTIVE", "NO");
|
2023-02-16 12:38:49 +00:00
|
|
|
|
#ifdef IUP_WITH_COLOR_BUTTONS
|
2022-07-14 10:40:51 +00:00
|
|
|
|
IupSetAttribute(btnConnect, "BGCOLOR", "0 179 0");
|
|
|
|
|
IupSetAttribute(btnConnect, "FGCOLOR", "255 255 255");
|
2023-02-02 05:47:23 +00:00
|
|
|
|
#endif
|
2022-07-19 10:13:57 +00:00
|
|
|
|
|
2022-07-06 17:51:51 +00:00
|
|
|
|
btnClose = IupButton("Закрыть", NULL);
|
|
|
|
|
IupSetHandle("CLOSE", btnClose);
|
|
|
|
|
IupSetAttribute(btnClose, "NAME", "CLOSE");
|
2022-07-14 10:40:51 +00:00
|
|
|
|
IupSetAttribute(btnClose, "TIP", "Закрыть FreeRDP");
|
2023-02-16 12:38:49 +00:00
|
|
|
|
#ifdef IUP_WITH_COLOR_BUTTONS
|
2022-07-14 10:40:51 +00:00
|
|
|
|
IupSetAttribute(btnClose, "BGCOLOR", "204 0 0");
|
|
|
|
|
IupSetAttribute(btnClose, "FGCOLOR", "255 255 255");
|
2023-02-02 05:47:23 +00:00
|
|
|
|
#endif
|
2022-07-19 10:13:57 +00:00
|
|
|
|
|
2022-07-06 17:51:51 +00:00
|
|
|
|
btnSettings = IupButton("Настройки", NULL);
|
|
|
|
|
IupSetAttribute(btnSettings, "NAME", "SETTINGS");
|
2022-07-14 10:40:51 +00:00
|
|
|
|
IupSetAttribute(btnSettings, "TIP", "Перейти в настройки");
|
2023-02-16 12:38:49 +00:00
|
|
|
|
#ifdef IUP_WITH_COLOR_BUTTONS
|
2022-07-14 10:40:51 +00:00
|
|
|
|
IupSetAttribute(btnSettings, "BGCOLOR", "0 136 204");
|
|
|
|
|
IupSetAttribute(btnSettings, "FGCOLOR", "255 255 255");
|
2023-02-02 05:47:23 +00:00
|
|
|
|
#endif
|
2022-07-19 10:13:57 +00:00
|
|
|
|
|
2022-07-14 10:40:51 +00:00
|
|
|
|
hBoxButtons = IupHbox(IupFill(), btnSettings, btnConnect, btnClose, IupFill(), NULL);
|
2022-07-06 17:51:51 +00:00
|
|
|
|
IupSetAttribute(hBoxButtons, "ALIGNMENT", "ACENTER:ACENTER");
|
|
|
|
|
IupSetAttribute(hBoxButtons, "GAP", "10");
|
|
|
|
|
IupSetAttribute(hBoxButtons, "MARGIN", "10x10");
|
2022-07-19 10:13:57 +00:00
|
|
|
|
|
2023-02-20 06:41:03 +00:00
|
|
|
|
vBoxMain = IupVbox(
|
|
|
|
|
#ifdef IUP_WITH_LANGUAGE_KEYBOARD_ICON
|
|
|
|
|
iconLang,
|
|
|
|
|
#endif
|
|
|
|
|
labelImage, hBoxServer, hBoxUser, hBoxPassword, hBoxButtons, NULL);
|
2022-07-06 17:51:51 +00:00
|
|
|
|
|
|
|
|
|
IupSetCallback(btnConnect, "ACTION", (Icallback) guiConnect);
|
|
|
|
|
IupSetCallback(btnClose, "ACTION", (Icallback) guiExit);
|
2022-07-07 16:35:48 +00:00
|
|
|
|
IupSetCallback(btnSettings, "ACTION", (Icallback) settingsMainWindow);
|
2022-07-19 10:13:57 +00:00
|
|
|
|
|
2022-07-06 17:51:51 +00:00
|
|
|
|
dlg = IupDialog(vBoxMain);
|
|
|
|
|
IupSetAttribute(dlg, "IMAGE", "BG_HEAD");
|
|
|
|
|
IupSetAttribute(dlg, "ICON", "icon");
|
|
|
|
|
IupSetAttribute(dlg, "TITLE", "GUI FreeRDP");
|
|
|
|
|
IupSetAttribute(dlg, "RESIZE", "NO");
|
|
|
|
|
IupSetAttribute(dlg, "PARENTDIALOG", "MAIN_WINDOW");
|
|
|
|
|
IupSetAttribute(dlg, "DEFAULTENTER", "CONNECT");
|
|
|
|
|
IupSetAttribute(dlg, "DEFAULTESC", "CLOSE");
|
2023-02-20 06:41:03 +00:00
|
|
|
|
#ifdef IUP_WITH_LANGUAGE_KEYBOARD_ICON
|
|
|
|
|
IupSetCallback(dlg, "iup_XkeyAlt(K_LSHIFT)", (Icallback) k_any);
|
|
|
|
|
IupSetCallback(dlg, "GETFOCUS_CB", (Icallback) k_any);
|
|
|
|
|
#endif
|
2022-07-19 10:13:57 +00:00
|
|
|
|
|
2022-07-06 17:51:51 +00:00
|
|
|
|
return dlg;
|
|
|
|
|
}
|