Subversion Repositories Kolibri OS

Rev

Rev 4153 | Go to most recent revision | 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,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. void StopConnect(dword message)
  16. {
  17.         if (message) notify(message);
  18.         aim = STOP;
  19. }
  20.  
  21.  
  22. void LoginBoxLoop()
  23. {
  24.         int key, id;
  25.         char socket_char;
  26.  
  27.         SetLoginStatus(NULL);
  28.  
  29.         goto _LB_DRAW;
  30.         loop()
  31.         {
  32.                 WaitEventTimeout(2);
  33.                 switch(EAX & 0xFF)
  34.                 {
  35.                         case evMouse:
  36.                                 if (!CheckActiveProcess(Form.ID)) break;
  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();
  44.                                 if (id==11)     SettingsDialog();
  45.                                 if (id==12)
  46.                                 {
  47.                                         if (!aim) aim=RESOLVE; else aim=NULL;
  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.                                 }
  65.                                 if (key==13) && (!aim)
  66.                                 {
  67.                                         aim=RESOLVE;
  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:
  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");
  86.                                
  87.                                 if (aim == RESOLVE)
  88.                                 {
  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);                                 
  94.                                         if (!sockaddr.sin_addr) { StopConnect("Can't obtain server IP."); break;}
  95.                                         aim = OPEN_CONNECTION;
  96.                                         break;
  97.                                 }
  98.                                
  99.                                 if (aim == OPEN_CONNECTION)
  100.                                 {
  101.                                         socketnum = Socket(AF_INET4, SOCK_STREAM, 0);
  102.                                         if (socketnum == 0xffffffff) { StopConnect("Cannot open socket."); break;}
  103.                                         Connect(socketnum, #sockaddr, 16);
  104.                                         aim = GET_ANSWER_CONNECT;
  105.                                         break;
  106.                                 }
  107.  
  108.                
  109.                                 if (aim == GET_ANSWER_CONNECT)
  110.                                 {
  111.                                         ticks = Receive(socketnum, #immbuffer, BUFFERSIZE, 0);
  112.                                         if ((ticks == 0xffffff) || (ticks < 2)) { StopConnect("Connection failed"); break;}
  113.                                         immbuffer[ticks]='\0';                                 
  114.                                        
  115.                                         if (immbuffer[ticks-2]=='\n')
  116.                                         {
  117.                                                 if (strstr(#immbuffer,"+OK"))
  118.                                                         aim = SEND_USER;
  119.                                                 else
  120.                                                         StopConnect("Failed to connect to server. Retry...");
  121.                                         }
  122.                                 }
  123.  
  124.                                 if (aim == SEND_USER)
  125.                                 {
  126.                                         request_len = GetRequest("USER", #login);
  127.                                         if (Send(socketnum, #request, request_len, 0) == 0xffffffff)
  128.                                         {
  129.                                                 SetLoginStatus("Failed to send USER. Retry...");
  130.                                                 break;
  131.                                         }
  132.                                         aim = GET_ANSWER_USER;
  133.                                 }
  134.  
  135.                                 if (aim == GET_ANSWER_USER)
  136.                                 {
  137.                                         ticks = Receive(socketnum, #immbuffer, BUFFERSIZE, 0);
  138.                                         if ((ticks == 0xffffffff) || (ticks < 2)) { SetLoginStatus("Connection failed"); break;}
  139.                                         immbuffer[ticks]='\0';                                         
  140.                                        
  141.                                         if (immbuffer[ticks-2]=='\n')
  142.                                         {
  143.                                                 if (strstr(#immbuffer,"+OK"))
  144.                                                         aim = SEND_PASS;
  145.                                                 else
  146.                                                 {
  147.                                                         debug(#immbuffer);
  148.                                                         StopConnect("Wrong username");
  149.                                                 }
  150.                                         }
  151.                                         else
  152.                                         {
  153.                                                 StopConnect("Connection failed");
  154.                                         }
  155.                                 }
  156.  
  157.                                 if (aim == SEND_PASS)
  158.                                 {              
  159.                                         request_len = GetRequest("PASS", #pass_text);
  160.                                         if (Send(socketnum, #request, request_len, 0) == 0xffffffff)
  161.                                         {
  162.                                                 SetLoginStatus("Failed to send PASS. Retry...");
  163.                                                 break;
  164.                                         }
  165.                                         aim = GET_ANSWER_PASS;
  166.                                 }
  167.  
  168.                                 if (aim == GET_ANSWER_PASS)
  169.                                 {      
  170.                                         ticks = Receive(socketnum, #immbuffer, BUFFERSIZE, 0);
  171.                                         if ((ticks == 0xffffff) || (ticks < 2)) { SetLoginStatus("Server disconnected"); break;}
  172.                                         immbuffer[ticks]='\0';                                         
  173.                                        
  174.                                         if (immbuffer[ticks-2]=='\n')
  175.                                         {
  176.                                                 if (strstr(#immbuffer,"+OK")) MailBoxLoop();
  177.                                                 else
  178.                                                 {
  179.                                                         StopConnect("Wrong password or POP3 disabled");
  180.                                                         debug(#immbuffer);
  181.                                                 }
  182.                                         }
  183.                                         else
  184.                                         {
  185.                                                 StopConnect("Connection failed");
  186.                                         }
  187.                                
  188.                                 }
  189.                                
  190.                 }
  191.         }
  192. }
  193.  
  194.  
  195.  
  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.        
  226.         SetLoginStatus(cur_st_text);
  227. }
  228.  
  229.  
  230. int GetRequest(dword command, text)
  231. {
  232.         strcpy(#request, command);
  233.         if (text)
  234.         {
  235.                 chrcat(#request, ' ');
  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. {
  260.         GetServerPathAndLogin();
  261.         if (checked[CUSTOM])
  262.         {
  263.                 POP_server_port = DEFAULT_POP_PORT;
  264.         }
  265.         if (checked[MANUAL])
  266.         {
  267.                 strcpy(#POP_server_path, #POP_server1);
  268.                 POP_server_port = atoi(#POP_server_port1);
  269.         }
  270.         if (!strcmp(#POP_server_path, "pop.gmail.com")) StopConnect("Can't connect GMAIL servers. Not support SSL/TLS encryption");
  271. }
  272.  
  273. void SetLoginStatus(dword text1)
  274. {
  275.         if (text1) WriteText(10, Form.cheight-22, 0x80, sc.work_text, text1);
  276.         cur_st_text = text1;
  277. }