Subversion Repositories Kolibri OS

Rev

Rev 7506 | 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];
6678 leency 12
edit_box login_box= {PANEL_W-6,207,16,0xffffff,0x94AECE,0xffffff,0xffffff,0x10000000,sizeof(email_text)+2,#email_text,#mouse_dd,0b10};
13
edit_box pass_box= {PANEL_W-6,207,16,0xffffff,0x94AECE,0xffffff,0xffffff,0x10000000,sizeof(pass_text)+2,#pass_text,#mouse_dd,0b1};
3368 leency 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
				edit_box_mouse stdcall (#login_box);
124
				edit_box_mouse stdcall (#pass_box);
125
				break;
3368 leency 126
 
4169 leency 127
			case evButton:
128
				id = GetButtonID();
129
				if (id==1) SaveAndExit();
130
				if (id==11)	SettingsDialog();
131
				if (id==12)
132
				{
133
					if (!aim) aim=RESOLVE; else aim=NULL;
134
					GetSettings();
135
					DrawLoginScreen();
3368 leency 136
				}
4169 leency 137
				break;
3368 leency 138
 
4169 leency 139
			case evKey:
5714 punk_joker 140
				GetKeys();
141
				if (key_scancode==SCAN_CODE_TAB)
4169 leency 142
				{
143
					if (login_box.flags & 0b10)
144
						{ pass_box.flags = 0b11; login_box.flags = 0; }
145
					else
146
						{ pass_box.flags = 0b1; login_box.flags = 0b10; }
147
					edit_box_draw stdcall(#login_box);
148
					edit_box_draw stdcall(#pass_box);
149
					break;
150
				}
5714 punk_joker 151
				if (key_scancode==SCAN_CODE_ENTER) && (!aim)
4169 leency 152
				{
153
					aim=RESOLVE;
154
					GetSettings();
155
					DrawLoginScreen();
156
				}
6641 leency 157
				EAX = key_editbox;
4169 leency 158
				edit_box_key stdcall(#login_box);
159
				edit_box_key stdcall(#pass_box);
160
				break;
161
 
162
			case evReDraw: _LB_DRAW:
163
				if !(DefineWindow(LOGIN_HEADER)) break;
164
				DrawLoginScreen();
165
				break;
166
 
167
			default:
168
				LoginNetworkProcess();
3368 leency 169
		}
170
	}
171
}
172
 
173
 
4164 leency 174
 
3368 leency 175
void DrawLoginScreen()
176
{
177
	panel_x = Form.cwidth - PANEL_W /2;
178
	panel_y = Form.cheight - PANEL_H /2 - 5;
179
 
7806 leency 180
	DrawBar(0,0, Form.cwidth, Form.cheight, sc.work);
3368 leency 181
 
7806 leency 182
	WriteText(panel_x,panel_y-3,0x80,sc.work_text,"Your Email:");
7245 leency 183
	DrawEditBoxPos(panel_x+3, panel_y+12, #login_box);
3368 leency 184
 
7806 leency 185
	WriteText(panel_x,panel_y+45,0x80,sc.work_text,"Password:");
7245 leency 186
	DrawEditBoxPos(panel_x+3, panel_y+60, #pass_box);
3368 leency 187
 
188
	if (!aim)
189
	{
7806 leency 190
		DrawCaptButton(panel_x,panel_y+100,100,26,11,sc.button, sc.button_text,"Settings");
191
		DrawCaptButton(panel_x+120,panel_y+100,100,26,12,sc.button, sc.button_text,"Enter >");
3368 leency 192
	}
7806 leency 193
	else DrawCaptButton(panel_x+120,panel_y+100,100,26,12,sc.button, sc.button_text,"Stop");
3368 leency 194
 
4164 leency 195
	SetLoginStatus(cur_st_text);
3368 leency 196
}
197
 
198
 
4169 leency 199
void GetSettings()
3368 leency 200
{
5625 leency 201
	strcpy(#login, #email_text);
202
	ESBYTE[strchr(#login,'@')] = NULL;
203
 
7244 leency 204
	if (automatic.checked)
3368 leency 205
	{
206
		strcpy(#POP_server_path, "pop.");
5625 leency 207
		strcat(#POP_server_path, strchr(#email_text,'@')+1);
4164 leency 208
		POP_server_port = DEFAULT_POP_PORT;
3368 leency 209
	}
7244 leency 210
	else
3368 leency 211
	{
212
		strcpy(#POP_server_path, #POP_server1);
213
		POP_server_port = atoi(#POP_server_port1);
214
	}
4164 leency 215
	if (!strcmp(#POP_server_path, "pop.gmail.com"))	StopConnect("Can't connect GMAIL servers. Not support SSL/TLS encryption");
3368 leency 216
}
217
 
4164 leency 218
void SetLoginStatus(dword text1)
3368 leency 219
{
7806 leency 220
	if (text1) WriteText(10, Form.cheight-22, 0x80, sc.work_text, text1);
3368 leency 221
	cur_st_text = text1;
222
}