File: Service_Main.cc

package info (click to toggle)
postman 2.1-6
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 8,248 kB
  • ctags: 3,249
  • sloc: cpp: 33,376; ansic: 2,014; sh: 768; makefile: 300
file content (622 lines) | stat: -rw-r--r-- 29,892 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
/*                               
Service_Main.cc
*/

#include "Service_Main.h"
#include "Service_Cclient.h"
#include "Service_PopPass.h"
#include "Service_ForwardMail.h"
#include "Service_FileBrowser.h"
#include "Service_SecVirtual.h"
#include "Service_Dotlearn.h"
#include "Service_Databases.h"
#include "Service_Finger.h"
#include "Service_PersonalData.h"
#include "Service_UserAccounts.h"
#include "Service_Config.h"
#include "Service_Sieve.h"
#include "Service_Calendar.h"

extern Language *L;
extern CCLIENT *cclient;
extern Configuration *Conf;
extern Authentication *auth;
extern Skin *skin;

//retrieve the url for the Service icon
const char *GetService_Main_ICO_URL (void)
  {
  return skin->getI(L_MAIN);
  }

//Retrieve the ALT tag for the Service icon
const char *GetService_Main_ICO_ALT (void)
  {
  return L->get(L_MAIN);
  }

//Retrieve the Service name
const char *GetService_Main_NAME (void)
  {
  return L->get(L_MAIN);
  }

//Retrieve the Service Description
const char *GetService_Main_DESCRIPTION (void)
  {
  return L->get(L_MAIN_DESCRIPTION);
  }

//Entry point to service init
bool DoService_Main_BEGIN (TProgData *pd)
  {
  LOG ("Initializating Service Main for user=%s", pd->username);
  return true;
  }

//Entry point to service end
bool DoService_Main_END (TProgData *pd)
  {
  return true;
  }

//Entry point to execute a service command
bool DoService_Main_CMD (TProgData *pd)
  {
  TBuffer tmp;
  switch (pd->cmd)
    {
    case (CMD_SPECIAL_CHECK_COOKIE): 
      {
      CheckCookie (pd);
      return false;
      break;
      }
    case (CMD_MAIN_HELP):
      {
      pd->uo->InitStatusLine ();
      pd->html->PrintHelpPage (getiServiceFromCmd(pd->uo->getLastCmd()), pd->stsubcmd, pd->username);
      return false;
      break;
      }   
    case (CMD_MAIN_ABOUT):
      {
      pd->uo->InitStatusLine ();
      pd->html->PrintHelpPage (iSERVICE_MAIN, "about", pd->username);
      return false;
      break;
      }         
    case (CMD_MAIN_ROOT):       
    case (CMD_MAIN_HOME):
      {
      pd->uo->clearPila();
      pd->uo->InitStatusLine ();
      PrintHomePage (pd);
      return false;
      break;
      }              
    case (CMD_SPECIAL_INVALIDPAGE):
      {
      pd->html->PrintInvalidPage (pd->stlang, pd->username, pd->connid, pd->uo);
      return false;
      break;
      }              
    case (CMD_MAIN_LOGOUT):
      {
      LOG ("Logout from IP=%s, user=%s", pd->ipclient, pd->username);
      cclient->saveFlagsRCNewsFile ();
      cclient->CloseMailbox ();
      xsnprintf (tmp, CMAXBUFFER, "%s/%s?lang=%s", PATH_CGI, SERVICE_MAIN, pd->stlang);
      ClearCookie (pd);
      pd->html->Redirect(tmp);
      return true;
      break;
      }
    case (CMD_MAIN_CONF_ACT):
      {
      cgienv_GetSimpleVarDef (pd->envfile, "mailboxname", pd->parm2, "");
      pd->uo->InitStatusLine ();
      pd->html->PrintConfirmPage (iSERVICE_MAIN, pd->stsubcmd, pd->stlang, pd->parm2, pd->username, pd->connid, 
                                  pd->uo->getValidator(), pd->uo->getPageId(), pd->uo);
      return false;
      break;   
      }
    default: 
      {    
      LOG ("ERROR: Service_Main: Here we can not go!! cmd=%s, subcmd=%s", pd->stcmd, pd->stsubcmd);
      pd->html->PrintInvalidCommand (pd->stlang, pd->username, pd->connid, pd->uo);
      return false;
      break;
      }         
    }
  }  

void CheckCookie (TProgData *pd)
  {      
  if (Conf->getInt ("main", "use_cookies", 0) == 1)
    {
    if (pd->cmd_counter == 1)  //LA PRIMERA VEZ SI EL BROWSER NO SOPORTA/ACEPTA COOKIES ME LO DEVUELVE VACIO
      {
      if (auth->isGoodCookie (pd->parm1) == false) pd->uo->setWorkingWithCookies (false);
      else pd->uo->setWorkingWithCookies (true);
      }
    else
      { 
      if (pd->uo->IsWorkingWithCookies () == true) 
        {
        if (auth->isGoodCookie (pd->parm1) == false) 
          {
          LOG ("SECURITY PROBLEM: Bad cookie from IP=%s, user=%s", pd->ipclient, pd->username);
          pd->html->PrintBadCookiePage (pd->stlang, pd->username, pd->connid, pd->uo);
          }
        }
      }
    }
  }

void ClearCookie (TProgData *pd)
  {
  if (Conf->getInt ("main", "use_cookies", 0) == 1)
    {
    if (pd->uo->IsWorkingWithCookies () == true) 
      {
      pd->html->printCookie (auth->cookie_getSetClearFullCookieLine());
      }
    }
  }
  
bool doLogin (TProgData *pd)
  {
  bool VALIDLOGIN = false;
  TBuffer tmp;
  
  //ENTRY EMPTY IN CGI imapserver FIELD. WE CORRECT IT.
  if ((pd->imapserver == NULL) || (strcmp (pd->imapserver, "") == 0) || (strcmp (pd->imapserver, " ") == 0))
    {
    xstrncpy (pd->imapserver, CMAXBUFFER, "#");
    LOG ("Field IMAP server EMPTY. Forcing '#'. IP=%s, User '%s'.", pd->ipclient, pd->username);
    }     
  //ENTRY # IN CGI imapserver FIELD AND WE MUST USE DB.
  if ((strcmp (pd->imapserver, "#") == 0) && (Conf->getInt ("main", "usedbforconf", 0) == 1))
    {
    //USER DO NOT EXIST IN DB. DEFAULT TO SECTION def_user_not_in_db
    if (exist_user (Conf->getString ("main", "dbfile", "/var/"APPNAME"/"APPNAME".db", CMAXBUFFER), pd->username) == 0)
      {
      TBuffer xbuf;
      xstrncpy (xbuf, CMAXBUFFER, Conf->getString ("main", "def_user_not_in_db", "", CMAXBUFFER));
      AddSuffixToIPName (xbuf);
      pd->uo->setImapServer (Conf->getString (xbuf, "imapserver", "imap.xx.xx", CMAXIPNAME));
      pd->uo->setImapPort   (Conf->getInt    (xbuf, "imapport", DEFIMAPPORT));
      pd->uo->setAuthService   (Conf->getString    (xbuf, "auth_service", "cclient", CMAXBUFFER));            
      pd->uo->setMailDomain (Conf->getString (xbuf, "maildomain", "xx.xx", CMAXIPNAME));
      pd->uo->setSMTPServer (Conf->getString (xbuf, "smtpserver", "smtp.xx.xx", CMAXIPNAME));  
      pd->uo->setAuthSMTP   (Conf->getInt    (xbuf, "authsmtp", 0));
      pd->uo->setNNTPServer (Conf->getString (xbuf, "nntpserver", "news", CMAXIPNAME));        
      cclient->setMailboxPrefix (Conf->getString (xbuf, "mailboxprefix", "", CMAXBUFFER));
      pd->uo->setMailboxPrefix (Conf->getString (xbuf, "mailboxprefix", "", CMAXBUFFER));
      cclient->setPathToRemoteFolder (Conf->getString (xbuf, "remotepath", "", CMAXBUFFER));
      pd->uo->setPoppassPort    (Conf->getInt    (xbuf, "poppassport", DEFPOPPASSPORT));          
      pd->uo->setPoppassServer  (Conf->getString (xbuf, "poppassserver", "poppass.xx.xx", CMAXIPNAME));
      pd->uo->setForwardsPort   (Conf->getInt    (xbuf, "forwardsport", DEFFORWARDPORT));
      pd->uo->setForwardsServer (Conf->getString (xbuf, "forwardsserver", "forwards.xx.xx", CMAXIPNAME));
      pd->uo->setSievePort    (Conf->getInt    (xbuf, "sieveport", DEFSIEVEPORT));
      pd->uo->setSieveServer  (Conf->getString (xbuf, "sieveserver", "sieve.xx.xx", CMAXIPNAME));
      pd->uo->setLDAPPort    (Conf->getInt    (xbuf, "ldapport", DEFLDAPPORT));
      pd->uo->setLDAPServer  (Conf->getString (xbuf, "ldapserver", "ldap.xx.xx", CMAXIPNAME));      
      pd->uo->setDeniedServices (Conf->getString (xbuf, "deniedservices", "", CMAXBUFFER));
      pd->uo->setTrueEmail ("");
      }
    //USER EXISTS IN DB
    else
      {
      TBuffer xbuf, aliasemail;
      int aimapport;
      IPNAME asmtpserver, amaildomain;
      db_get_data_from_user (Conf->getString ("main", "dbfile", "/var/"APPNAME"/"APPNAME".db", CMAXBUFFER), pd->username, 
                             pd->imapserver, &aimapport, asmtpserver, amaildomain, aliasemail);
      xstrncpy (xbuf, CMAXBUFFER, pd->imapserver);
      AddSuffixToIPName (xbuf);
      pd->uo->setImapServer (xbuf);
      pd->uo->setImapPort   (aimapport);
      pd->uo->setAuthService   (Conf->getString    (xbuf, "auth_service", "cclient", CMAXBUFFER));            
      pd->uo->setSMTPServer (asmtpserver);
      pd->uo->setAuthSMTP   (Conf->getInt    (xbuf, "authsmtp", 0));
      pd->uo->setMailDomain (amaildomain);
      pd->uo->setNNTPServer (Conf->getString (xbuf, "nntpserver", "news", CMAXIPNAME));        
      cclient->setMailboxPrefix (Conf->getString (xbuf, "mailboxprefix", "", CMAXBUFFER));
      pd->uo->setMailboxPrefix (Conf->getString (xbuf, "mailboxprefix", "", CMAXBUFFER));
      cclient->setPathToRemoteFolder (Conf->getString (xbuf, "remotepath", "", CMAXBUFFER));
      pd->uo->setPoppassPort    (Conf->getInt    (xbuf, "poppassport", DEFPOPPASSPORT));
      pd->uo->setPoppassServer  (Conf->getString (xbuf, "poppassserver", "poppass.xx.xx", CMAXIPNAME));
      pd->uo->setForwardsPort   (Conf->getInt    (xbuf, "forwardsport", DEFFORWARDPORT));
      pd->uo->setForwardsServer (Conf->getString (xbuf, "forwardsserver", "forwards.xx.xx", CMAXIPNAME));
      pd->uo->setSievePort    (Conf->getInt    (xbuf, "sieveport", DEFSIEVEPORT));
      pd->uo->setSieveServer  (Conf->getString (xbuf, "sieveserver", "sieve.xx.xx", CMAXIPNAME));
      pd->uo->setLDAPPort    (Conf->getInt    (xbuf, "ldapport", DEFLDAPPORT));
      pd->uo->setLDAPServer  (Conf->getString (xbuf, "ldapserver", "ldap.xx.xx", CMAXIPNAME));      
      pd->uo->setDeniedServices (Conf->getString (xbuf, "deniedservices", "", CMAXBUFFER));
      pd->uo->setTrueEmail (aliasemail);
      }        
    }    
  //ENTRY # IN CGI imapserver FIELD AND WE DO NOT MUST USE DB. DEFAULT TO SECTION def_user_not_in_db
  else if ((strcmp (pd->imapserver, "#") == 0) && (Conf->getInt ("main", "usedbforconf", 0) == 0))
    {
    TBuffer xbuf;
    xstrncpy (xbuf, CMAXBUFFER, Conf->getString ("main", "def_user_not_in_db", "", CMAXBUFFER));
    AddSuffixToIPName (xbuf);
    pd->uo->setImapServer (Conf->getString (xbuf, "imapserver", "imap.xx.xx", CMAXIPNAME));
    pd->uo->setImapPort   (Conf->getInt    (xbuf, "imapport", DEFIMAPPORT));
    pd->uo->setAuthService   (Conf->getString    (xbuf, "auth_service", "cclient", CMAXBUFFER));            
    pd->uo->setMailDomain (Conf->getString (xbuf, "maildomain", "xx.xx", CMAXIPNAME));
    pd->uo->setSMTPServer (Conf->getString (xbuf, "smtpserver", "smtp.xx.xx", CMAXIPNAME));  
    pd->uo->setAuthSMTP   (Conf->getInt    (xbuf, "authsmtp", 0));
    pd->uo->setNNTPServer (Conf->getString (xbuf, "nntpserver", "news", CMAXIPNAME));        
    cclient->setMailboxPrefix (Conf->getString (xbuf, "mailboxprefix", "", CMAXBUFFER));
    pd->uo->setMailboxPrefix (Conf->getString (xbuf, "mailboxprefix", "", CMAXBUFFER));
    cclient->setPathToRemoteFolder (Conf->getString (xbuf, "remotepath", "", CMAXBUFFER));
    pd->uo->setPoppassPort    (Conf->getInt    (xbuf, "poppassport", DEFPOPPASSPORT));
    pd->uo->setPoppassServer  (Conf->getString (xbuf, "poppassserver", "poppass.xx.xx", CMAXIPNAME));
    pd->uo->setForwardsPort   (Conf->getInt    (xbuf, "forwardsport", DEFFORWARDPORT));
    pd->uo->setForwardsServer (Conf->getString (xbuf, "forwardsserver", "forwards.xx.xx", CMAXIPNAME));
    pd->uo->setSievePort    (Conf->getInt    (xbuf, "sieveport", DEFSIEVEPORT));
    pd->uo->setSieveServer  (Conf->getString (xbuf, "sieveserver", "sieve.xx.xx", CMAXIPNAME));
    pd->uo->setLDAPPort    (Conf->getInt    (xbuf, "ldapport", DEFLDAPPORT));
    pd->uo->setLDAPServer  (Conf->getString (xbuf, "ldapserver", "ldap.xx.xx", CMAXIPNAME));      
    pd->uo->setDeniedServices (Conf->getString (xbuf, "deniedservices", "", CMAXBUFFER));    
    pd->uo->setTrueEmail ("");
    }        
  //TEXT ENTRY IN CGI imapserver FIELD
  else
    {
    TBuffer xbuf;
    xstrncpy (xbuf, CMAXBUFFER, pd->imapserver);
    AddSuffixToIPName (xbuf);
    //EXISTS imapserver SECTION
    if (Conf->IsThereSection (xbuf) == true)
      {
      pd->uo->setImapServer (Conf->getString (xbuf, "imapserver", "imap.xx.xx", CMAXIPNAME));
      pd->uo->setImapPort   (Conf->getInt    (xbuf, "imapport", DEFIMAPPORT));
      pd->uo->setAuthService   (Conf->getString    (xbuf, "auth_service", "cclient", CMAXBUFFER));            
      pd->uo->setMailDomain (Conf->getString (xbuf, "maildomain", "xx.xx", CMAXIPNAME));
      pd->uo->setSMTPServer (Conf->getString (xbuf, "smtpserver", pd->uo->getImapServer(), CMAXIPNAME));  
      pd->uo->setAuthSMTP   (Conf->getInt    (xbuf, "authsmtp", 0));
      pd->uo->setNNTPServer (Conf->getString (xbuf, "nntpserver", "news", CMAXIPNAME));        
      cclient->setMailboxPrefix (Conf->getString (xbuf, "mailboxprefix", "", CMAXBUFFER));
      pd->uo->setMailboxPrefix (Conf->getString (xbuf, "mailboxprefix", "", CMAXBUFFER));
      cclient->setPathToRemoteFolder (Conf->getString (xbuf, "remotepath", "", CMAXBUFFER));
      pd->uo->setPoppassPort    (Conf->getInt    (xbuf, "poppassport", DEFPOPPASSPORT));
      pd->uo->setPoppassServer  (Conf->getString (xbuf, "poppassserver", "poppass.xx.xx", CMAXIPNAME));
      pd->uo->setForwardsPort   (Conf->getInt    (xbuf, "forwardsport", DEFFORWARDPORT));
      pd->uo->setForwardsServer (Conf->getString (xbuf, "forwardsserver", "forwards.xx.xx", CMAXIPNAME));
      pd->uo->setSievePort    (Conf->getInt    (xbuf, "sieveport", DEFSIEVEPORT));
      pd->uo->setSieveServer  (Conf->getString (xbuf, "sieveserver", "sieve.xx.xx", CMAXIPNAME));
      pd->uo->setLDAPPort    (Conf->getInt    (xbuf, "ldapport", DEFLDAPPORT));
      pd->uo->setLDAPServer  (Conf->getString (xbuf, "ldapserver", "ldap.xx.xx", CMAXIPNAME));      
      pd->uo->setDeniedServices (Conf->getString (xbuf, "deniedservices", "", CMAXBUFFER));
      pd->uo->setTrueEmail ("");
      }
    //DO NOT EXIST imapserver SECTION IN interdaemon.cfg FILE
    else
      {
      //WE DO NOT ALLOW LOGINS IF imapserver SECTION DO NOT EXIST
      if (Conf->getInt ("main", "allowotherimapservers", 0) == 0)
        {
        LOG ("IMAP server '%s' is not allowed. IP=%s, User=%s. Exiting.", pd->imapserver, pd->ipclient, pd->username);
        pd->html->ErrorPage (L->get(L_NOTALLOWED_IMAPSERVER));
        exit(0);
        }
      //WE ALLOW LOGINS TO EVERY imapserver, BUT OVERWRITING SOME FIELDS
      else
        {
        pd->uo->setImapServer (xbuf);
        if (strcmp (Conf->getString ("*", "imapport", "*", CMAXIPNAME), "*") == 0)  
          {pd->uo->setImapPort (DEFIMAPPORT);}
        else 
          {pd->uo->setImapPort (Conf->getInt ("*", "imapport", DEFIMAPPORT));}
        if (strcmp (Conf->getString ("*", "smtpserver", "*", CMAXIPNAME), "*") == 0)  
          {pd->uo->setSMTPServer (pd->imapserver);}
        else 
          {pd->uo->setSMTPServer (Conf->getString ("*", "smtpserver", "smtp.xx.xx", CMAXIPNAME));}                                  
        if (strcmp (Conf->getString ("*", "authsmtp", "*", 0), "*") == 0)  
          {pd->uo->setAuthSMTP (0);}
        else 
          {pd->uo->setAuthSMTP (Conf->getInt ("*", "authsmtp", 0));}
        if (strcmp (Conf->getString ("*", "nntpserver", "*", CMAXIPNAME), "*") == 0)  
          {pd->uo->setNNTPServer (pd->imapserver);}
        else 
          {pd->uo->setNNTPServer (Conf->getString ("*", "nntpserver", "news", CMAXIPNAME));}                                  
        if (strcmp (Conf->getString ("*", "maildomain", "*", CMAXIPNAME), "*") == 0)  
          {pd->uo->setMailDomain (pd->imapserver);}
        else                       
          {pd->uo->setMailDomain (Conf->getString ("*", "maildomain", "xx.xx", CMAXIPNAME));}                                                  
        pd->uo->setAuthService   (Conf->getString    (xbuf, "auth_service", "cclient", CMAXBUFFER));            
        cclient->setMailboxPrefix (Conf->getString (xbuf, "mailboxprefix", "", CMAXBUFFER));
        pd->uo->setMailboxPrefix (Conf->getString (xbuf, "mailboxprefix", "", CMAXBUFFER));
        cclient->setPathToRemoteFolder (Conf->getString (xbuf, "remotepath", "", CMAXBUFFER));
        pd->uo->setSievePort    (Conf->getInt    (xbuf, "sieveport", DEFSIEVEPORT));
        pd->uo->setSieveServer  (Conf->getString (xbuf, "sieveserver", "sieve.xx.xx", CMAXIPNAME));
        pd->uo->setLDAPPort    (Conf->getInt    (xbuf, "ldapport", DEFLDAPPORT));
        pd->uo->setLDAPServer  (Conf->getString (xbuf, "ldapserver", "ldap.xx.xx", CMAXIPNAME));      
        pd->uo->setDeniedServices (Conf->getString (xbuf, "deniedservices", "", CMAXBUFFER));
        pd->uo->setTrueEmail ("");
        }
      }
    }   
  sm_setproctitle (PROGNAME, true, "%s   (Before Authentication)", pd->username);  

  //DEBUG ("--%s--%d--", pd->uo->getAuthService(), pd->uo->getiAuthService());
  if (pd->uo->getiAuthService() == iSERVICE_CCLIENT)
     {
     //DEBUG ("--%s--%d--%s--%s--",  pd->uo->getImapServer(), pd->uo->getImapPort(), pd->username, pd->password);
     xstrncpy (pd->connid, CMAXBUFFER, make_session_id (pd->imapserver, tmp));
     auth = new Authentication(iSERVICE_CCLIENT, pd->uo->getImapServer(), pd->uo->getImapPort(), pd->username, pd->password, pd->connid);
     VALIDLOGIN = auth->doFirstAuthentication();
     }
   else
     {//Default: ldap
     //DEBUG ("--%s--%d--%s--%s--",  pd->uo->getLDAPServer(), pd->uo->getLDAPPort(), pd->username, pd->password);
     xstrncpy (pd->connid, CMAXBUFFER, make_session_id (pd->imapserver, tmp));
     auth = new Authentication(iSERVICE_LDAP, pd->uo->getLDAPServer(), pd->uo->getLDAPPort(), pd->username, pd->password, pd->connid);
     VALIDLOGIN = auth->doFirstAuthentication();     
     } 

  sm_setproctitle (PROGNAME, true, "%s   (After Authentication)", pd->username);  
  cclient->setNNTPServer (pd->uo->getNNTPServer());
  return VALIDLOGIN;
  }

//WE ADD A DEFAULT SUFFIX TO IMAPSERVER IF THIS HAVE NOT IT (post -> post.uv.es).
void AddSuffixToIPName (TBuffer server)
  {
  if (strchr (server, '.') == NULL) 
    {
    xstrncat (server, CMAXBUFFER, Conf->getString ("main", "defaultipdomain", "", CMAXIPNAME)); 
    }
  }   

void PrintHomePage (TProgData *pd)
  {
  TBuffer tmp;
  int pageid, validator, actualcmd; 
  long unread_msgs;

  validator = pd->uo->getValidator();
  pageid    = pd->uo->getPageId();
  actualcmd = CMD_CCLIENT_MG_DISPLAY;

  pd->html->Head ("text/html", "", "");
  pd->html->HTMLBegin ();                
  pd->html->Title (L->get(TIT_SERVICES), skin->getSkinAtribProp("COLOR_BGBODY"), skin->getSkinAtribProp("COLOR_BGTEXTO"),
                   skin->getSkinAtribProp("IMG_BG"), pd->uo->get_use_javascript(), 0, NULL);
  
  pd->html->BotoneraHomePage (actualcmd, pd->stlang, pd->username, pd->connid, pd->uo); 
  
  pd->html->Linea();
  
  pd->html->WRITE ("<CENTER><TABLE BGCOLOR=\"#FFFFFF\" BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"5\" WIDTH=\"100%%\">\n");
    
  //BUTTON OPEN MAIL
  pd->html->WRITE ("<TR>\n");   

  //***********************
  //This is the left column (for Personal Data Service, Identification)
  //***********************

  pd->html->WRITE ("<TD WIDTH=\"30%%\" rowspan=\"30\" align=\"center\">\n");
  if (isAllowedService (pd->uo->SLAllowedServices, pd->uo->getDeniedServices(), iSERVICE_PERSONALDATA, NULL))
    {  
    if (pd->uo->getDisplayPersonalInfo() == true)
      {
      TBuffer tokeninfo;
      DoService_PersonalData_BEGIN (pd);      
      pd->html->WRITE ("<CENTER>\n");
         
      if (getPersonalInfo ("URLFOTO", tokeninfo))    
        {pd->html->WRITE ("<IMG BORDER=\"0\" width=\"70\" height=\"90\" SRC=\"%s\">", tokeninfo);}
      
      if (getPersonalInfo ("NAME", tokeninfo))        
        {pd->html->WRITE ("<BR><B>%s</B>", tokeninfo);} 

      pd->html->WRITE ("</CENTER>\n");
      }
    }
  pd->html->WRITE ("</TD>\n");   
 
    
  if (isAllowedService (pd->uo->SLAllowedServices, pd->uo->getDeniedServices(), -1, "cclient"))
    {
    //BUTTON MAIL  
    pd->html->WRITE ("<TD align=\"left\">\n");
    pd->html->WRITE ("<A HREF=\"%s/%s/mb_change/noop/%s/%s/%s/%d/%d/%d/\">", PATH_CGI, SERVICE_CCLIENT, pd->stlang, pd->username, pd->connid, validator, pageid, actualcmd);
    pd->html->Image (GetService_Cclient_ICO_URL(), GetService_Cclient_ICO_ALT(), skin->getISize());
    unread_msgs = cclient->getMsgsUnreadIMAPINBOX ();

    if (unread_msgs == -1) 
      {
      //Possible I am validating with other than imap service. I need connect to imap for retrieve unread msgs.
      DoService_Cclient_BEGIN (pd); 
      unread_msgs = cclient->getMsgsUnreadIMAPINBOX ();
      }

    pd->html->WRITE ("<FONT face=\"%s\" SIZE=\"-1\"><B>%s</B></A>", skin->getSkinAtribProp("FONT_TABLE"), GetService_Cclient_NAME());
    switch (unread_msgs)
      {
      case -1: /*ERROR*/ 
               break;
      case 0:  pd->html->WRITE ("  <FONT SIZE=\"-1\">(%s)</FONT>\n", L->get(MSG_NEWMSGS_0));
               break;
      case 1:  pd->html->WRITE ("  <FONT SIZE=\"-1\">(%s)</FONT>\n", L->get(MSG_NEWMSGS_1));
               break;
      default: xsnprintf (tmp, CMAXBUFFER, L->get(MSG_NEWMSGS_n), unread_msgs);
               pd->html->WRITE ("  <FONT SIZE=\"-1\">(%s)</FONT>\n", tmp);
               break;                
      }
    pd->html->WRITE ("</FONT></TD>\n"); 
    pd->html->WRITE ("</TR>\n");   
    }
    
  if (isAllowedService (pd->uo->SLAllowedServices, pd->uo->getDeniedServices(), -1, "nntp"))
    {
    //BUTTON OPEN SUBSCRIBED NEWS
    pd->html->WRITE ("<TR>\n");                          
    pd->html->WRITE ("<TD align=\"left\">\n");    
    pd->html->WRITE ("<A HREF=\"%s/%s/nw_subscribed/noop/%s/%s/%s/%d/%d/%d/:%s/\">", PATH_CGI, SERVICE_CCLIENT, pd->stlang, pd->username, pd->connid, validator, pageid, actualcmd, DEFAULTBEGINNNTPGROUP);
    pd->html->Image (skin->getI(L_NNTP), L->get(ALT_NNTP), skin->getISize());
    pd->html->WRITE ("<FONT face=\"%s\" SIZE=\"-1\"><B>%s</B></FONT>\n", skin->getSkinAtribProp("FONT_TABLE"),  L->get(L_NNTP));
    pd->html->WRITE ("</A>\n");
    pd->html->WRITE ("</TD>\n");    
    pd->html->WRITE ("</TR>\n");    
    }
  
  if (isAllowedService (pd->uo->SLAllowedServices, pd->uo->getDeniedServices(), iSERVICE_POPPASS, NULL))
    {
    //BUTTON CHANGE PW
    pd->html->WRITE ("<TR>\n");
    pd->html->WRITE ("<TD align=\"left\">\n");
    pd->html->WRITE ("<A HREF=\"%s/%s/displaypage/noop/%s/%s/%s/%d/%d/%d/\">", PATH_CGI, SERVICE_POPPASS, pd->stlang, pd->username, pd->connid, validator, pageid, actualcmd);
    pd->html->Image (GetService_PopPass_ICO_URL(),  GetService_PopPass_ICO_ALT(), skin->getISize());
    pd->html->WRITE ("<FONT face=\"%s\" SIZE=\"-1\"><B>%s</B></FONT>\n", skin->getSkinAtribProp("FONT_TABLE"), GetService_PopPass_NAME());
    pd->html->WRITE ("</A>\n");
    pd->html->WRITE ("</TD>\n");    
    pd->html->WRITE ("</TR>\n");
    }

  if (isAllowedService (pd->uo->SLAllowedServices, pd->uo->getDeniedServices(), iSERVICE_FORWARDMAIL, NULL))
    {
    //BUTTON MESSAGE FORWARDING
    pd->html->WRITE ("<TR>\n");
    pd->html->WRITE ("<TD align=\"left\">\n");
    pd->html->WRITE ("<A HREF=\"%s/%s/displaypage/noop/%s/%s/%s/%d/%d/%d/\">", PATH_CGI, SERVICE_FORWARDMAIL, pd->stlang, pd->username, pd->connid, validator, pageid, actualcmd);
    pd->html->Image (GetService_ForwardMail_ICO_URL(),  GetService_ForwardMail_ICO_ALT(), skin->getISize());
    pd->html->WRITE ("<FONT face=\"%s\" SIZE=\"-1\"><B>%s</B></FONT>\n", skin->getSkinAtribProp("FONT_TABLE"), GetService_ForwardMail_NAME());
    pd->html->WRITE ("</A>\n");
    pd->html->WRITE ("</TD>\n");    
    pd->html->WRITE ("</TR>\n");
    }
        
  if (isAllowedService (pd->uo->SLAllowedServices, pd->uo->getDeniedServices(), iSERVICE_FILEBROWSER, NULL))
    {
    //ONLY DISPLAY THAT SERVICE IF THERE ARE DISKS TO MOUNT
    if (strcmp (pd->uo->getMountPoints(), "") != 0)
      {
      //BUTTON FILE MANAGER
      pd->html->WRITE ("<TR>\n");
      pd->html->WRITE ("<TD align=\"left\">\n");
      pd->html->WRITE ("<A HREF=\"%s/%s/displaypage/noop/%s/%s/%s/%d/%d/%d/\">", PATH_CGI, SERVICE_FILEBROWSER, pd->stlang, pd->username, pd->connid, validator, pageid, actualcmd);
      pd->html->Image (GetService_FileBrowser_ICO_URL(),  GetService_FileBrowser_ICO_ALT(), skin->getISize());
      pd->html->WRITE ("<FONT face=\"%s\" SIZE=\"-1\"><B>%s</B></FONT>\n", skin->getSkinAtribProp("FONT_TABLE"), GetService_FileBrowser_NAME());
      pd->html->WRITE ("</A>\n");
      pd->html->WRITE ("</TD>\n");    
      pd->html->WRITE ("</TR>\n");
      }  
    }                     
    
  if (isAllowedService (pd->uo->SLAllowedServices, pd->uo->getDeniedServices(), iSERVICE_SECVIRTUAL, NULL))
    {
    //BUTTON SECVIRTUAL
    pd->html->WRITE ("<TR>\n");
    pd->html->WRITE ("<TD align=\"left\">\n");
    pd->html->WRITE ("<A HREF=\"%s/%s/goto/noop/%s/%s/%s/%d/%d/%d/\">", PATH_CGI, SERVICE_SECVIRTUAL, pd->stlang, pd->username, pd->connid, validator, pageid, actualcmd);
    pd->html->Image (GetService_SecVirtual_ICO_URL(),  GetService_SecVirtual_ICO_ALT(), skin->getISize());
    pd->html->WRITE ("<FONT face=\"%s\" SIZE=\"-1\"><B>%s</B></FONT>\n", skin->getSkinAtribProp("FONT_TABLE"), GetService_SecVirtual_NAME());
    pd->html->WRITE ("</A>\n");
    pd->html->WRITE ("</TD>\n");    
    pd->html->WRITE ("</TR>\n");
    }                         
    
  if (isAllowedService (pd->uo->SLAllowedServices, pd->uo->getDeniedServices(), iSERVICE_DOTLEARN, NULL))
    {
    //BUTTON SECVIRTUAL
    pd->html->WRITE ("<TR>\n");
    pd->html->WRITE ("<TD align=\"left\">\n");
    pd->html->WRITE ("<A HREF=\"%s/%s/goto/noop/%s/%s/%s/%d/%d/%d/\">", PATH_CGI, SERVICE_DOTLEARN, pd->stlang, pd->username, pd->connid, validator, pageid, actualcmd);
    pd->html->Image (GetService_Dotlearn_ICO_URL(),  GetService_Dotlearn_ICO_ALT(), skin->getISize());
    pd->html->WRITE ("<FONT face=\"%s\" SIZE=\"-1\"><B>%s</B></FONT>\n", skin->getSkinAtribProp("FONT_TABLE"), GetService_Dotlearn_NAME());
    pd->html->WRITE ("</A>\n");
    pd->html->WRITE ("</TD>\n");    
    pd->html->WRITE ("</TR>\n");
    }                             
    
  if (isAllowedService (pd->uo->SLAllowedServices, pd->uo->getDeniedServices(), iSERVICE_USERACCOUNTS, NULL))
    {
    //BUTTON USERACCOUNTS
    pd->html->WRITE ("<TR>\n");
    pd->html->WRITE ("<TD align=\"left\">\n");
    pd->html->WRITE ("<A HREF=\"%s/%s/goto/noop/%s/%s/%s/%d/%d/%d/\">", PATH_CGI, SERVICE_USERACCOUNTS, pd->stlang, pd->username, pd->connid, validator, pageid, actualcmd);
    pd->html->Image (GetService_UserAccounts_ICO_URL(),  GetService_UserAccounts_ICO_ALT(), skin->getISize());
    pd->html->WRITE ("<FONT face=\"%s\" SIZE=\"-1\"><B>%s</B></FONT>\n", skin->getSkinAtribProp("FONT_TABLE"), GetService_UserAccounts_NAME());    
    pd->html->WRITE ("</A>\n");
    pd->html->WRITE ("</TD>\n");    
    pd->html->WRITE ("</TR>\n");
    }                             
    
  if (isAllowedService (pd->uo->SLAllowedServices, pd->uo->getDeniedServices(), iSERVICE_DATABASES, NULL))
    {
    //BUTTON URLS
    pd->html->WRITE ("<TR>\n");
    pd->html->WRITE ("<TD align=\"left\">\n");
    pd->html->WRITE ("<A HREF=\"%s/%s/mainpage/noop/%s/%s/%s/%d/%d/%d/\">", PATH_CGI, SERVICE_DATABASES, pd->stlang, pd->username, pd->connid, validator, pageid, actualcmd);
    pd->html->Image (GetService_Databases_ICO_URL(), GetService_Databases_ICO_ALT(), skin->getISize());
    pd->html->WRITE ("<FONT face=\"%s\" SIZE=\"-1\"><B>%s</B></FONT>\n", skin->getSkinAtribProp("FONT_TABLE"), GetService_Databases_DESCRIPTION());
    pd->html->WRITE ("</A>\n");
    pd->html->WRITE ("</TD>\n");    
    pd->html->WRITE ("</TR>\n");
    }    
    
  if (isAllowedService (pd->uo->SLAllowedServices, pd->uo->getDeniedServices(), iSERVICE_FINGER, NULL))
    {
    //BUTTON FINGER
    pd->html->WRITE ("<TR>\n");
    pd->html->WRITE ("<TD align=\"left\">\n");
    pd->html->WRITE ("<A HREF=\"%s/%s/displaypage/noop/%s/%s/%s/%d/%d/%d/\">", PATH_CGI, SERVICE_FINGER, pd->stlang, pd->username, pd->connid, validator, pageid, actualcmd);
    pd->html->Image (GetService_Finger_ICO_URL(),  GetService_Finger_ICO_ALT(), skin->getISize());
    pd->html->WRITE ("<FONT face=\"%s\" SIZE=\"-1\"><B>%s</B></FONT>\n", skin->getSkinAtribProp("FONT_TABLE"), GetService_Finger_NAME());
    pd->html->WRITE ("</A>\n");
    pd->html->WRITE ("</TD>\n");    
    pd->html->WRITE ("</TR>\n");
    }        
    
  if (isAllowedService (pd->uo->SLAllowedServices, pd->uo->getDeniedServices(), iSERVICE_CALENDAR, NULL))
    {
    //BUTTON CALENDAR
    pd->html->WRITE ("<TR>\n");
    pd->html->WRITE ("<TD align=\"left\">\n");
    pd->html->WRITE ("<A HREF=\"%s/%s/year_show/noop/%s/%s/%s/%d/%d/%d/\">", PATH_CGI, SERVICE_CALENDAR, pd->stlang, pd->username, pd->connid, validator, pageid, actualcmd);
    pd->html->Image (GetService_Calendar_ICO_URL(),  GetService_Calendar_ICO_ALT(), skin->getISize());
    pd->html->WRITE ("<FONT face=\"%s\" SIZE=\"-1\"><B>%s</B></FONT>\n", skin->getSkinAtribProp("FONT_TABLE"), GetService_Calendar_NAME());
    pd->html->WRITE ("</A>\n");
    pd->html->WRITE ("</TD>\n");    
    pd->html->WRITE ("</TR>\n");
    if (pd->uo->getShowCalendarTodayEvents() == true)
      {
      TBuffer events_warning;
      DoService_Calendar_BEGIN (pd);                  
      if (getWarningToday (events_warning) > 0)          
        {
        pd->html->WRITE ("<TR>\n");               
        pd->html->WRITE ("<TD align=\"center\">\n");               
        pd->html->WRITE ("<FONT SIZE=1 COLOR=#FF0000>%s</FONT>", events_warning);
        pd->html->WRITE ("</TD>\n");    
        pd->html->WRITE ("</TR>\n");
        }
      }
    }            
    
  if (isAllowedService (pd->uo->SLAllowedServices, pd->uo->getDeniedServices(), iSERVICE_CONFIG, NULL))
    {
    //BUTTON CONFIG
    pd->html->WRITE ("<TR>\n");
    pd->html->WRITE ("<TD align=\"left\">\n");
    pd->html->WRITE ("<A HREF=\"%s/%s/config/noop/%s/%s/%s/%d/%d/%d/\">", PATH_CGI, SERVICE_CONFIG, pd->stlang, pd->username, pd->connid, validator, pageid, actualcmd);
    pd->html->Image (GetService_Config_ICO_URL(),  GetService_Config_ICO_ALT(), skin->getISize());
    pd->html->WRITE ("<FONT face=\"%s\" SIZE=\"-1\"><B>%s</B></FONT>\n", skin->getSkinAtribProp("FONT_TABLE"), GetService_Config_NAME());
    pd->html->WRITE ("</A>\n");
    pd->html->WRITE ("</TD>\n");    
    pd->html->WRITE ("</TR>\n");
    }            
    
  pd->html->WRITE ("</TABLE></CENTER>\n");
  
  pd->html->HTMLEnd(skin->getSkinAtribProp("COLOR_BGTABLECOPYRIGHT"));      
  }