Subversion Repositories Kolibri OS

Rev

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