2013-03-12 17:19:10 +01:00
|
|
|
//Leency & SoUrcerer, LGPL
|
|
|
|
|
|
|
|
//LoginPanel
|
|
|
|
#define PANEL_W 220
|
|
|
|
#define PANEL_H 140
|
|
|
|
int panel_x, panel_y;
|
|
|
|
|
|
|
|
//edit_boxes at LoginPanel
|
|
|
|
int mouse_dd;
|
|
|
|
unsigned char email_text[128];
|
|
|
|
unsigned char pass_text[32];
|
|
|
|
edit_box login_box= {PANEL_W-6,207,16,0xffffff,0x94AECE,0xffffff,0xffffff,0,sizeof(email_text)+2,#email_text,#mouse_dd,0b10};
|
|
|
|
edit_box pass_box= {PANEL_W-6,207,16,0xffffff,0x94AECE,0xffffff,0xffffff,0,sizeof(pass_text)+2,#pass_text,#mouse_dd,0b1};
|
|
|
|
|
2013-11-05 00:27:39 +01:00
|
|
|
|
2013-11-05 20:38:16 +01:00
|
|
|
void LoginNetworkProcess()
|
2013-03-12 17:19:10 +01:00
|
|
|
{
|
2013-11-05 20:38:16 +01:00
|
|
|
if (aim) switch(aim)
|
2013-03-12 17:19:10 +01:00
|
|
|
{
|
2013-11-05 20:38:16 +01:00
|
|
|
case RESOLVE:
|
|
|
|
if (!email_text) StopConnect("Enter email!");
|
|
|
|
if (!pass_text) StopConnect("Enter password!");
|
|
|
|
if ((!login) || (!POP_server_path)) StopConnect("Email should be such as username@somesite.com");
|
|
|
|
if (!aim) return;
|
2013-03-12 17:19:10 +01:00
|
|
|
|
2013-10-31 19:40:41 +01:00
|
|
|
sockaddr.sin_family = AF_INET4;
|
|
|
|
AX = POP_server_port;
|
|
|
|
$xchg al, ah
|
|
|
|
sockaddr.sin_port = AX;
|
|
|
|
sockaddr.sin_addr = GetIPfromAdress(#POP_server_path);
|
2013-11-04 22:40:13 +01:00
|
|
|
if (!sockaddr.sin_addr) { StopConnect("Can't obtain server IP."); break;}
|
2013-11-05 20:38:16 +01:00
|
|
|
else aim = OPEN_CONNECTION;
|
2013-11-04 22:40:13 +01:00
|
|
|
break;
|
2013-11-05 20:38:16 +01:00
|
|
|
case OPEN_CONNECTION:
|
2013-10-31 19:40:41 +01:00
|
|
|
socketnum = Socket(AF_INET4, SOCK_STREAM, 0);
|
2013-11-04 22:40:13 +01:00
|
|
|
if (socketnum == 0xffffffff) { StopConnect("Cannot open socket."); break;}
|
2013-10-31 19:40:41 +01:00
|
|
|
Connect(socketnum, #sockaddr, 16);
|
2013-11-04 22:40:13 +01:00
|
|
|
aim = GET_ANSWER_CONNECT;
|
|
|
|
break;
|
2013-11-05 20:38:16 +01:00
|
|
|
case GET_ANSWER_CONNECT:
|
2013-10-31 19:40:41 +01:00
|
|
|
ticks = Receive(socketnum, #immbuffer, BUFFERSIZE, 0);
|
2013-11-04 22:40:13 +01:00
|
|
|
if ((ticks == 0xffffff) || (ticks < 2)) { StopConnect("Connection failed"); break;}
|
2013-10-31 19:40:41 +01:00
|
|
|
immbuffer[ticks]='\0';
|
|
|
|
if (immbuffer[ticks-2]=='\n')
|
2013-03-12 17:19:10 +01:00
|
|
|
{
|
|
|
|
if (strstr(#immbuffer,"+OK"))
|
|
|
|
aim = SEND_USER;
|
|
|
|
else
|
2013-11-04 22:40:13 +01:00
|
|
|
StopConnect("Failed to connect to server. Retry...");
|
2013-10-31 19:40:41 +01:00
|
|
|
}
|
2013-11-05 20:38:16 +01:00
|
|
|
break;
|
|
|
|
case SEND_USER:
|
2013-03-12 17:19:10 +01:00
|
|
|
request_len = GetRequest("USER", #login);
|
2013-11-04 22:40:13 +01:00
|
|
|
if (Send(socketnum, #request, request_len, 0) == 0xffffffff)
|
|
|
|
{
|
|
|
|
SetLoginStatus("Failed to send USER. Retry...");
|
|
|
|
break;
|
|
|
|
}
|
2013-11-05 20:38:16 +01:00
|
|
|
else aim = GET_ANSWER_USER;
|
|
|
|
break;
|
|
|
|
case GET_ANSWER_USER:
|
2013-10-31 19:40:41 +01:00
|
|
|
ticks = Receive(socketnum, #immbuffer, BUFFERSIZE, 0);
|
2013-11-04 22:40:13 +01:00
|
|
|
if ((ticks == 0xffffffff) || (ticks < 2)) { SetLoginStatus("Connection failed"); break;}
|
2013-10-31 19:40:41 +01:00
|
|
|
immbuffer[ticks]='\0';
|
|
|
|
if (immbuffer[ticks-2]=='\n')
|
2013-03-12 17:19:10 +01:00
|
|
|
{
|
|
|
|
if (strstr(#immbuffer,"+OK"))
|
2013-11-04 22:40:13 +01:00
|
|
|
aim = SEND_PASS;
|
2013-03-12 17:19:10 +01:00
|
|
|
else
|
2013-11-04 22:40:13 +01:00
|
|
|
{
|
|
|
|
debug(#immbuffer);
|
|
|
|
StopConnect("Wrong username");
|
|
|
|
}
|
2013-10-31 19:40:41 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-11-04 22:40:13 +01:00
|
|
|
StopConnect("Connection failed");
|
2013-03-12 17:19:10 +01:00
|
|
|
}
|
2013-11-05 20:38:16 +01:00
|
|
|
break;
|
|
|
|
case SEND_PASS:
|
2013-03-12 17:19:10 +01:00
|
|
|
request_len = GetRequest("PASS", #pass_text);
|
2013-11-04 22:40:13 +01:00
|
|
|
if (Send(socketnum, #request, request_len, 0) == 0xffffffff)
|
|
|
|
{
|
|
|
|
SetLoginStatus("Failed to send PASS. Retry...");
|
|
|
|
break;
|
|
|
|
}
|
2013-11-05 20:38:16 +01:00
|
|
|
else aim = GET_ANSWER_PASS;
|
|
|
|
break;
|
|
|
|
case GET_ANSWER_PASS:
|
2013-10-31 19:40:41 +01:00
|
|
|
ticks = Receive(socketnum, #immbuffer, BUFFERSIZE, 0);
|
2013-11-04 22:40:13 +01:00
|
|
|
if ((ticks == 0xffffff) || (ticks < 2)) { SetLoginStatus("Server disconnected"); break;}
|
2013-10-31 19:40:41 +01:00
|
|
|
immbuffer[ticks]='\0';
|
2013-03-12 17:19:10 +01:00
|
|
|
|
2013-10-31 19:40:41 +01:00
|
|
|
if (immbuffer[ticks-2]=='\n')
|
2013-03-12 17:19:10 +01:00
|
|
|
{
|
2013-11-04 22:40:13 +01:00
|
|
|
if (strstr(#immbuffer,"+OK")) MailBoxLoop();
|
2013-03-12 17:19:10 +01:00
|
|
|
else
|
|
|
|
{
|
2013-11-04 22:40:13 +01:00
|
|
|
StopConnect("Wrong password or POP3 disabled");
|
|
|
|
debug(#immbuffer);
|
2013-03-12 17:19:10 +01:00
|
|
|
}
|
|
|
|
}
|
2013-10-31 19:40:41 +01:00
|
|
|
else
|
|
|
|
{
|
2013-11-04 22:40:13 +01:00
|
|
|
StopConnect("Connection failed");
|
2013-10-31 19:40:41 +01:00
|
|
|
}
|
2013-11-05 20:38:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LoginBoxLoop()
|
|
|
|
{
|
2015-08-11 13:29:31 +02:00
|
|
|
int id;
|
2013-11-05 20:38:16 +01:00
|
|
|
|
|
|
|
SetLoginStatus(NULL);
|
|
|
|
goto _LB_DRAW;
|
|
|
|
loop()
|
|
|
|
{
|
|
|
|
WaitEventTimeout(2);
|
|
|
|
switch(EAX & 0xFF)
|
|
|
|
{
|
|
|
|
case evMouse:
|
|
|
|
if (!CheckActiveProcess(Form.ID)) break;
|
|
|
|
edit_box_mouse stdcall (#login_box);
|
|
|
|
edit_box_mouse stdcall (#pass_box);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case evButton:
|
|
|
|
id = GetButtonID();
|
|
|
|
if (id==1) SaveAndExit();
|
|
|
|
if (id==11) SettingsDialog();
|
|
|
|
if (id==12)
|
|
|
|
{
|
|
|
|
if (!aim) aim=RESOLVE; else aim=NULL;
|
|
|
|
GetSettings();
|
|
|
|
DrawLoginScreen();
|
|
|
|
}
|
|
|
|
break;
|
2013-03-12 17:19:10 +01:00
|
|
|
|
2013-11-05 20:38:16 +01:00
|
|
|
case evKey:
|
2015-08-11 13:29:31 +02:00
|
|
|
GetKeys();
|
|
|
|
if (key_scancode==SCAN_CODE_TAB)
|
2013-11-05 20:38:16 +01:00
|
|
|
{
|
|
|
|
if (login_box.flags & 0b10)
|
|
|
|
{ pass_box.flags = 0b11; login_box.flags = 0; }
|
|
|
|
else
|
|
|
|
{ pass_box.flags = 0b1; login_box.flags = 0b10; }
|
|
|
|
edit_box_draw stdcall(#login_box);
|
|
|
|
edit_box_draw stdcall(#pass_box);
|
|
|
|
break;
|
2013-03-12 17:19:10 +01:00
|
|
|
}
|
2015-08-11 13:29:31 +02:00
|
|
|
if (key_scancode==SCAN_CODE_ENTER) && (!aim)
|
2013-11-05 20:38:16 +01:00
|
|
|
{
|
|
|
|
aim=RESOLVE;
|
|
|
|
GetSettings();
|
|
|
|
DrawLoginScreen();
|
|
|
|
}
|
2015-08-11 13:29:31 +02:00
|
|
|
EAX=key_ascii<<8;
|
2013-11-05 20:38:16 +01:00
|
|
|
edit_box_key stdcall(#login_box);
|
|
|
|
edit_box_key stdcall(#pass_box);
|
|
|
|
break;
|
2013-03-12 17:19:10 +01:00
|
|
|
|
2013-11-05 20:38:16 +01:00
|
|
|
case evReDraw: _LB_DRAW:
|
|
|
|
if !(DefineWindow(LOGIN_HEADER)) break;
|
|
|
|
DrawLoginScreen();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
LoginNetworkProcess();
|
2013-03-12 17:19:10 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-04 22:40:13 +01:00
|
|
|
|
2013-03-12 17:19:10 +01:00
|
|
|
void DrawLoginScreen()
|
|
|
|
{
|
|
|
|
panel_x = Form.cwidth - PANEL_W /2;
|
|
|
|
panel_y = Form.cheight - PANEL_H /2 - 5;
|
|
|
|
|
2015-08-04 16:36:07 +02:00
|
|
|
DrawBar(0,0, Form.cwidth, Form.cheight, system.color.work);
|
2013-03-12 17:19:10 +01:00
|
|
|
|
2015-08-04 16:36:07 +02:00
|
|
|
WriteText(panel_x,panel_y,0x80,system.color.work_text,"Your Email:");
|
2013-03-12 17:19:10 +01:00
|
|
|
login_box.left = panel_x+3;
|
|
|
|
login_box.top = panel_y+15;
|
|
|
|
edit_box_draw stdcall(#login_box);
|
2016-02-11 03:22:34 +01:00
|
|
|
EditBox(#login_box);
|
2013-03-12 17:19:10 +01:00
|
|
|
|
2015-08-04 16:36:07 +02:00
|
|
|
WriteText(panel_x,panel_y+40,0x80,system.color.work_text,"Password:");
|
2013-03-12 17:19:10 +01:00
|
|
|
pass_box.left = panel_x+3;
|
|
|
|
pass_box.top = panel_y+55;
|
|
|
|
edit_box_draw stdcall(#pass_box);
|
2016-02-11 03:22:34 +01:00
|
|
|
EditBox(#pass_box);
|
2013-03-12 17:19:10 +01:00
|
|
|
|
|
|
|
if (!aim)
|
|
|
|
{
|
2016-02-09 02:43:58 +01:00
|
|
|
DrawCaptButton(panel_x,panel_y+90,100,22,11,system.color.work_button, system.color.work_button_text,"Settings");
|
|
|
|
DrawCaptButton(panel_x+120,panel_y+90,100,22,12,system.color.work_button, system.color.work_button_text,"Enter >");
|
2013-03-12 17:19:10 +01:00
|
|
|
}
|
2016-02-09 02:43:58 +01:00
|
|
|
else DrawCaptButton(panel_x+120,panel_y+90,100,22,12,system.color.work_button, system.color.work_button_text,"Stop");
|
2013-03-12 17:19:10 +01:00
|
|
|
|
2013-11-04 22:40:13 +01:00
|
|
|
SetLoginStatus(cur_st_text);
|
2013-03-12 17:19:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GetSettings()
|
|
|
|
{
|
2015-07-29 22:06:46 +02:00
|
|
|
strcpy(#login, #email_text);
|
|
|
|
ESBYTE[strchr(#login,'@')] = NULL;
|
|
|
|
|
2013-03-12 17:19:10 +01:00
|
|
|
if (checked[CUSTOM])
|
|
|
|
{
|
2013-11-05 20:38:16 +01:00
|
|
|
strcpy(#POP_server_path, "pop.");
|
2015-07-29 22:06:46 +02:00
|
|
|
strcat(#POP_server_path, strchr(#email_text,'@')+1);
|
2013-11-04 22:40:13 +01:00
|
|
|
POP_server_port = DEFAULT_POP_PORT;
|
2013-03-12 17:19:10 +01:00
|
|
|
}
|
|
|
|
if (checked[MANUAL])
|
|
|
|
{
|
|
|
|
strcpy(#POP_server_path, #POP_server1);
|
|
|
|
POP_server_port = atoi(#POP_server_port1);
|
|
|
|
}
|
2013-11-04 22:40:13 +01:00
|
|
|
if (!strcmp(#POP_server_path, "pop.gmail.com")) StopConnect("Can't connect GMAIL servers. Not support SSL/TLS encryption");
|
2013-03-12 17:19:10 +01:00
|
|
|
}
|
|
|
|
|
2013-11-04 22:40:13 +01:00
|
|
|
void SetLoginStatus(dword text1)
|
2013-03-12 17:19:10 +01:00
|
|
|
{
|
2015-08-04 16:36:07 +02:00
|
|
|
if (text1) WriteText(10, Form.cheight-22, 0x80, system.color.work_text, text1);
|
2013-03-12 17:19:10 +01:00
|
|
|
cur_st_text = text1;
|
|
|
|
}
|