Subversion Repositories Kolibri OS

Rev

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