Subversion Repositories Kolibri OS

Rev

Rev 7244 | Blame | Last modification | View Log | Download | RSS feed

  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,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};
  14.  
  15.  
  16. void LoginNetworkProcess()
  17. {
  18.         if (aim) switch(aim)
  19.         {
  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;
  25.  
  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);                                 
  31.                                         if (!sockaddr.sin_addr) { StopConnect("Can't obtain server IP."); break;}
  32.                                         else aim = OPEN_CONNECTION;
  33.                                         break;
  34.                 case OPEN_CONNECTION:
  35.                                         socketnum = Socket(AF_INET4, SOCK_STREAM, 0);
  36.                                         if (socketnum == 0xffffffff) { StopConnect("Cannot open socket."); break;}
  37.                                         Connect(socketnum, #sockaddr, 16);
  38.                                         aim = GET_ANSWER_CONNECT;
  39.                                         break;
  40.                 case GET_ANSWER_CONNECT:
  41.                                         ticks = Receive(socketnum, #immbuffer, BUFFERSIZE, 0);
  42.                                         if ((ticks == 0xffffff) || (ticks < 2)) { StopConnect("Connection failed"); break;}
  43.                                         immbuffer[ticks]='\0';                                 
  44.                                         if (immbuffer[ticks-2]=='\n')
  45.                                         {
  46.                                                 if (strstr(#immbuffer,"+OK"))
  47.                                                         aim = SEND_USER;
  48.                                                 else
  49.                                                         StopConnect("Failed to connect to server. Retry...");
  50.                                         }
  51.                                         break;
  52.                 case SEND_USER:
  53.                                         request_len = GetRequest("USER", #login);
  54.                                         if (Send(socketnum, #request, request_len, 0) == 0xffffffff)
  55.                                         {
  56.                                                 SetLoginStatus("Failed to send USER. Retry...");
  57.                                                 break;
  58.                                         }
  59.                                         else aim = GET_ANSWER_USER;
  60.                                         break;
  61.                 case GET_ANSWER_USER:
  62.                                         ticks = Receive(socketnum, #immbuffer, BUFFERSIZE, 0);
  63.                                         if ((ticks == 0xffffffff) || (ticks < 2)) { SetLoginStatus("Connection failed"); break;}
  64.                                         immbuffer[ticks]='\0';                                         
  65.                                         if (immbuffer[ticks-2]=='\n')
  66.                                         {
  67.                                                 if (strstr(#immbuffer,"+OK"))
  68.                                                         aim = SEND_PASS;
  69.                                                 else
  70.                                                 {
  71.                                                         debug(#immbuffer);
  72.                                                         StopConnect("Wrong username");
  73.                                                 }
  74.                                         }
  75.                                         else
  76.                                         {
  77.                                                 StopConnect("Connection failed");
  78.                                         }
  79.                                         break;
  80.                 case SEND_PASS:
  81.                                         request_len = GetRequest("PASS", #pass_text);
  82.                                         if (Send(socketnum, #request, request_len, 0) == 0xffffffff)
  83.                                         {
  84.                                                 SetLoginStatus("Failed to send PASS. Retry...");
  85.                                                 break;
  86.                                         }
  87.                                         else aim = GET_ANSWER_PASS;
  88.                                         break;
  89.                 case GET_ANSWER_PASS:
  90.                                         ticks = Receive(socketnum, #immbuffer, BUFFERSIZE, 0);
  91.                                         if ((ticks == 0xffffff) || (ticks < 2)) { SetLoginStatus("Server disconnected"); break;}
  92.                                         immbuffer[ticks]='\0';                                         
  93.                                        
  94.                                         if (immbuffer[ticks-2]=='\n')
  95.                                         {
  96.                                                 if (strstr(#immbuffer,"+OK")) MailBoxLoop();
  97.                                                 else
  98.                                                 {
  99.                                                         StopConnect("Wrong password or POP3 disabled");
  100.                                                         debug(#immbuffer);
  101.                                                 }
  102.                                         }
  103.                                         else
  104.                                         {
  105.                                                 StopConnect("Connection failed");
  106.                                         }
  107.         }
  108. }
  109.  
  110.  
  111. void LoginBoxLoop()
  112. {
  113.         int id;
  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;
  127.                                
  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();
  137.                                 }
  138.                                 break;
  139.                                
  140.                         case evKey:
  141.                                 GetKeys();
  142.                                 if (key_scancode==SCAN_CODE_TAB)
  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.                                 }
  152.                                 if (key_scancode==SCAN_CODE_ENTER) && (!aim)
  153.                                 {
  154.                                         aim=RESOLVE;
  155.                                         GetSettings();
  156.                                         DrawLoginScreen();
  157.                                 }
  158.                                 EAX = key_editbox;
  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();                         
  170.                 }
  171.         }
  172. }
  173.  
  174.  
  175.  
  176. void DrawLoginScreen()
  177. {                              
  178.         panel_x = Form.cwidth - PANEL_W /2;
  179.         panel_y = Form.cheight - PANEL_H /2 - 5;
  180.  
  181.         DrawBar(0,0, Form.cwidth, Form.cheight, system.color.work);
  182.        
  183.         WriteText(panel_x,panel_y-3,0x80,system.color.work_text,"Your Email:");
  184.         DrawEditBoxPos(panel_x+3, panel_y+12, #login_box);
  185.        
  186.         WriteText(panel_x,panel_y+45,0x80,system.color.work_text,"Password:");
  187.         DrawEditBoxPos(panel_x+3, panel_y+60, #pass_box);
  188.        
  189.         if (!aim)
  190.         {
  191.                 DrawCaptButton(panel_x,panel_y+100,100,26,11,system.color.work_button, system.color.work_button_text,"Settings");
  192.                 DrawCaptButton(panel_x+120,panel_y+100,100,26,12,system.color.work_button, system.color.work_button_text,"Enter >");
  193.         }
  194.         else DrawCaptButton(panel_x+120,panel_y+100,100,26,12,system.color.work_button, system.color.work_button_text,"Stop");
  195.        
  196.         SetLoginStatus(cur_st_text);
  197. }
  198.  
  199.  
  200. void GetSettings()
  201. {
  202.         strcpy(#login, #email_text);
  203.         ESBYTE[strchr(#login,'@')] = NULL;
  204.        
  205.         if (automatic.checked)
  206.         {
  207.                 strcpy(#POP_server_path, "pop.");
  208.                 strcat(#POP_server_path, strchr(#email_text,'@')+1);
  209.                 POP_server_port = DEFAULT_POP_PORT;
  210.         }
  211.         else
  212.         {
  213.                 strcpy(#POP_server_path, #POP_server1);
  214.                 POP_server_port = atoi(#POP_server_port1);
  215.         }
  216.         if (!strcmp(#POP_server_path, "pop.gmail.com")) StopConnect("Can't connect GMAIL servers. Not support SSL/TLS encryption");
  217. }
  218.  
  219. void SetLoginStatus(dword text1)
  220. {
  221.         if (text1) WriteText(10, Form.cheight-22, 0x80, system.color.work_text, text1);
  222.         cur_st_text = text1;
  223. }