Subversion Repositories Kolibri OS

Rev

Rev 4164 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3368 leency 1
//Leency & SoUrcerer, LGPL
2
 
3
//LoginPanel
4
#define PANEL_W 220
5
#define PANEL_H 140
6
int panel_x, panel_y;
7
 
8
//edit_boxes at LoginPanel
9
int	mouse_dd;
10
unsigned char email_text[128];
11
unsigned char pass_text[32];
12
edit_box login_box= {PANEL_W-6,207,16,0xffffff,0x94AECE,0xffffff,0xffffff,0,sizeof(email_text)+2,#email_text,#mouse_dd,0b10};
13
edit_box pass_box= {PANEL_W-6,207,16,0xffffff,0x94AECE,0xffffff,0xffffff,0,sizeof(pass_text)+2,#pass_text,#mouse_dd,0b1};
14
 
15
 
4164 leency 16
 
4166 leency 17
 
3368 leency 18
void LoginBoxLoop()
19
{
20
	int key, id;
21
	char socket_char;
22
 
4164 leency 23
	SetLoginStatus(NULL);
3368 leency 24
 
25
	goto _LB_DRAW;
26
	loop()
27
	{
28
		WaitEventTimeout(2);
29
		switch(EAX & 0xFF)
30
		{
31
			case evMouse:
4164 leency 32
				if (!CheckActiveProcess(Form.ID)) break;
3368 leency 33
				edit_box_mouse stdcall (#login_box);
34
				edit_box_mouse stdcall (#pass_box);
35
				break;
36
 
37
			case evButton:
38
				id = GetButtonID();
39
				if (id==1) SaveAndExit();
4164 leency 40
				if (id==11)	SettingsDialog();
3368 leency 41
				if (id==12)
42
				{
4139 hidnplayr 43
					if (!aim) aim=RESOLVE; else aim=NULL;
3368 leency 44
					GetSettings();
45
					DrawLoginScreen();
46
				}
47
				break;
48
 
49
			case evKey:
50
				key = GetKey();
51
				if (key==9)
52
				{
53
					if (login_box.flags & 0b10)
54
						{ pass_box.flags = 0b11; login_box.flags = 0; }
55
					else
56
						{ pass_box.flags = 0b1; login_box.flags = 0b10; }
57
					edit_box_draw stdcall(#login_box);
58
					edit_box_draw stdcall(#pass_box);
59
					break;
60
				}
4164 leency 61
				if (key==13) && (!aim)
3368 leency 62
				{
4139 hidnplayr 63
					aim=RESOLVE;
3368 leency 64
					GetSettings();
65
					DrawLoginScreen();
66
				}
67
				EAX=key<<8;
68
				edit_box_key stdcall(#login_box);
69
				edit_box_key stdcall(#pass_box);
70
				break;
71
 
72
			case evReDraw: _LB_DRAW:
73
				if !(DefineWindow(LOGIN_HEADER)) break;
74
				DrawLoginScreen();
75
				break;
76
 
77
			default:
4164 leency 78
				if (!aim) break;
79
				if (!email_text) StopConnect("Enter email!");
80
				if (!pass_text) StopConnect("Enter password!");
81
				if ((!login) || (!POP_server_path)) StopConnect("Email should be such as username@somesite.com");
3368 leency 82
 
4139 hidnplayr 83
				if (aim == RESOLVE)
3368 leency 84
				{
4139 hidnplayr 85
					sockaddr.sin_family = AF_INET4;
86
					AX = POP_server_port;
87
					$xchg	al, ah
88
					sockaddr.sin_port = AX;
89
					sockaddr.sin_addr = GetIPfromAdress(#POP_server_path);
4164 leency 90
					if (!sockaddr.sin_addr) { StopConnect("Can't obtain server IP."); break;}
91
					aim = OPEN_CONNECTION;
92
					break;
3368 leency 93
				}
4139 hidnplayr 94
 
95
				if (aim == OPEN_CONNECTION)
3368 leency 96
				{
4139 hidnplayr 97
					socketnum = Socket(AF_INET4, SOCK_STREAM, 0);
4164 leency 98
					if (socketnum == 0xffffffff) { StopConnect("Cannot open socket."); break;}
4139 hidnplayr 99
					Connect(socketnum, #sockaddr, 16);
4164 leency 100
					aim = GET_ANSWER_CONNECT;
101
					break;
3368 leency 102
				}
103
 
4139 hidnplayr 104
 
3368 leency 105
				if (aim == GET_ANSWER_CONNECT)
106
				{
4139 hidnplayr 107
					ticks = Receive(socketnum, #immbuffer, BUFFERSIZE, 0);
4164 leency 108
					if ((ticks == 0xffffff) || (ticks < 2)) { StopConnect("Connection failed"); break;}
4139 hidnplayr 109
					immbuffer[ticks]='\0';
3368 leency 110
 
4139 hidnplayr 111
					if (immbuffer[ticks-2]=='\n')
3368 leency 112
					{
113
						if (strstr(#immbuffer,"+OK"))
114
							aim = SEND_USER;
115
						else
4164 leency 116
							StopConnect("Failed to connect to server. Retry...");
3368 leency 117
					}
118
				}
119
 
120
				if (aim == SEND_USER)
121
				{
122
					request_len = GetRequest("USER", #login);
4164 leency 123
					if (Send(socketnum, #request, request_len, 0) == 0xffffffff)
124
					{
125
						SetLoginStatus("Failed to send USER. Retry...");
126
						break;
127
					}
3368 leency 128
					aim = GET_ANSWER_USER;
129
				}
130
 
131
				if (aim == GET_ANSWER_USER)
132
				{
4139 hidnplayr 133
					ticks = Receive(socketnum, #immbuffer, BUFFERSIZE, 0);
4164 leency 134
					if ((ticks == 0xffffffff) || (ticks < 2)) { SetLoginStatus("Connection failed"); break;}
4139 hidnplayr 135
					immbuffer[ticks]='\0';
3368 leency 136
 
4139 hidnplayr 137
					if (immbuffer[ticks-2]=='\n')
3368 leency 138
					{
139
						if (strstr(#immbuffer,"+OK"))
4164 leency 140
							aim = SEND_PASS;
3368 leency 141
						else
4164 leency 142
						{
143
							debug(#immbuffer);
144
							StopConnect("Wrong username");
145
						}
3368 leency 146
					}
4139 hidnplayr 147
					else
148
					{
4164 leency 149
						StopConnect("Connection failed");
4139 hidnplayr 150
					}
3368 leency 151
				}
152
 
153
				if (aim == SEND_PASS)
154
				{
155
					request_len = GetRequest("PASS", #pass_text);
4164 leency 156
					if (Send(socketnum, #request, request_len, 0) == 0xffffffff)
157
					{
158
						SetLoginStatus("Failed to send PASS. Retry...");
159
						break;
160
					}
3368 leency 161
					aim = GET_ANSWER_PASS;
162
				}
163
 
164
				if (aim == GET_ANSWER_PASS)
165
				{
4139 hidnplayr 166
					ticks = Receive(socketnum, #immbuffer, BUFFERSIZE, 0);
4164 leency 167
					if ((ticks == 0xffffff) || (ticks < 2)) { SetLoginStatus("Server disconnected"); break;}
4139 hidnplayr 168
					immbuffer[ticks]='\0';
3368 leency 169
 
4139 hidnplayr 170
					if (immbuffer[ticks-2]=='\n')
3368 leency 171
					{
4164 leency 172
						if (strstr(#immbuffer,"+OK")) MailBoxLoop();
3368 leency 173
						else
174
						{
4164 leency 175
							StopConnect("Wrong password or POP3 disabled");
176
							debug(#immbuffer);
3368 leency 177
						}
178
					}
4139 hidnplayr 179
					else
180
					{
4164 leency 181
						StopConnect("Connection failed");
4139 hidnplayr 182
					}
3368 leency 183
 
184
				}
185
 
186
		}
187
	}
188
}
189
 
190
 
4164 leency 191
 
3368 leency 192
void DrawLoginScreen()
193
{
194
	panel_x = Form.cwidth - PANEL_W /2;
195
	panel_y = Form.cheight - PANEL_H /2 - 5;
196
 
197
	DrawBar(0,0, Form.cwidth, Form.cheight, sc.work);
198
 
199
	WriteText(panel_x,panel_y,0x80,sc.work_text,"Your Email:");
200
	DrawRectangle(panel_x, panel_y+12, PANEL_W,20, sc.work_graph); //border
201
	DrawRectangle3D(panel_x+1, panel_y+13, PANEL_W-2,18, 0xDDDddd, 0xFFFfff); //shadow
202
	DrawRectangle(panel_x+2, panel_y+14, PANEL_W-4,16, 0xFFFfff);
203
	login_box.left = panel_x+3;
204
	login_box.top = panel_y+15;
205
	edit_box_draw stdcall(#login_box);
206
 
207
	WriteText(panel_x,panel_y+40,0x80,sc.work_text,"Password:");
208
	DrawRectangle(panel_x, panel_y+52, PANEL_W,20, sc.work_graph); //border
209
	DrawRectangle3D(panel_x+1, panel_y+53, PANEL_W-2,18, 0xDDDddd, 0xFFFfff); //shadow
210
	DrawRectangle(panel_x+2, panel_y+54, PANEL_W-4,16, 0xFFFfff);
211
	pass_box.left = panel_x+3;
212
	pass_box.top = panel_y+55;
213
	edit_box_draw stdcall(#pass_box);
214
 
215
	if (!aim)
216
	{
217
		DrawCaptButton(panel_x,panel_y+90,100,20,11,sc.work_button, sc.work_button_text,"Settings");
218
		DrawCaptButton(panel_x+120,panel_y+90,100,20,12,sc.work_button, sc.work_button_text,"Enter >");
219
	}
220
	else DrawCaptButton(panel_x+120,panel_y+90,100,20,12,sc.work_button, sc.work_button_text,"Stop");
221
 
4164 leency 222
	SetLoginStatus(cur_st_text);
3368 leency 223
}
224
 
225
 
226
void GetServerPathAndLogin()
227
{
228
	int i=strchr(#email_text,'@');
229
 
230
	POP_server_path=login=NULL;
231
 
232
	if (i)
233
	{
234
		strcpy(#POP_server_path, "pop.");
235
		strcat(#POP_server_path, #email_text+i);
236
	}
237
	strcpy(#login, #email_text);
238
	login[i-1]=NULL;
239
}
240
 
241
 
242
void GetSettings()
243
{
4164 leency 244
	GetServerPathAndLogin();
3368 leency 245
	if (checked[CUSTOM])
246
	{
4164 leency 247
		POP_server_port = DEFAULT_POP_PORT;
3368 leency 248
	}
249
	if (checked[MANUAL])
250
	{
251
		strcpy(#POP_server_path, #POP_server1);
252
		POP_server_port = atoi(#POP_server_port1);
253
	}
4164 leency 254
	if (!strcmp(#POP_server_path, "pop.gmail.com"))	StopConnect("Can't connect GMAIL servers. Not support SSL/TLS encryption");
3368 leency 255
}
256
 
4164 leency 257
void SetLoginStatus(dword text1)
3368 leency 258
{
4164 leency 259
	if (text1) WriteText(10, Form.cheight-22, 0x80, sc.work_text, text1);
3368 leency 260
	cur_st_text = text1;
261
}