/*------------------------------------------------------------------*/
/*    Programmers Group & Management Resource    Copyright  2002    */
/*                                                                  */
/*                             \\\\\\\                              */
/*                            ( o   o )                             */
/*------------------------oOO----(_)----OOo-------------------------*/
/*                                                                  */
/*  System name  . . . :   IT Operations                            */
/*  Program name . . . :   SETUPSMTP                                */
/*  Text . . . . . . . :   Called to setup SMTP on a system.        */
/*                                                                  */
/*                     ooooO              Ooooo                     */
/*                     (    )             (    )                    */
/*----------------------(   )-------------(   )---------------------*/
/*                       (_)               (_)                      */
/*                                                                  */
/*  Author . . . . . . :   Alexander Nubla                          */
/*  Description  . . . :   This program retrieves the attributes    */
/*                         of SMTP & POP prior to making changes.   */
/*                         These files are copied to QRPLOBJ --     */
/*                         QATMSMTP, QATMPOPA, QATOCHOST.           */
/*                                                                  */
/*------------------------------------------------------------------*/
/*  Modification Log:                                               */
/*                                                                  */
/*           Mod                                                    */
/* Date    No.  Programmer/Description                          */
/*  12/04/01       Alex Nubla                                       */
/*                 Created                                          */
/*                                                                  */
/*------------------------------------------------------------------*/
             pgm        (&MailRtrIP    /* Mail Router IP        */   +
                         &MailRtr)     /* Mail Router           */

/*--------------------------------------------------------*/
/*  declaration                                           */
/*--------------------------------------------------------*/
             dcl        &MailRtrIP *char   15
             dcl        &MailRtr   *char  256

             dcl        &interactv *char    1

/*--------------------------------------------------------*/
/*  parameter for Error Handling routine                  */
/*--------------------------------------------------------*/
             dcl        &error     *lgl                   /* std err */
             dcl        &msgid     *char    7             /* std err */
             dcl        &msgkey    *char    4             /* std err */
             dcl        &msgdta    *char  100             /* std err */
             dcl        &msgf      *char   10             /* std err */
             dcl        &msgflib   *char   10             /* std err */
             dcl        &msgtyp    *char   10  '*DIAG'    /* std err */
             dcl        &msgtypctr *char    4 X'00000001' /* std err */
             dcl        &pgmmsgq   *char   10  '*'        /* std err */
             dcl        &stkctr    *char    4 X'00000001' /* std err */
             dcl        &errbytes  *char    4 X'00000000' /* std err */

             monmsg     msgid(cpf0000) exec(goto error)

/*--------------------------------------------------------*/
/*  Send message - this will take a while                 */
/*--------------------------------------------------------*/
             rtvjoba    type(&interactv)
             if         (&interactv = '1')  then(do)
               rmvmsg     clear(*all)
               sndpgmmsg  msgid(cpf9898)                   +
                            msgf(qcpfmsg)                  +
                            msgtype(*status)               +
                            topgmq(*ext)                   +
                            msgdta('SMTP setup in progress. +
                            Please wait')
             enddo
             chgjob     logclpgm(*Yes)                     +
                          stsmsg(*None)

/*--------------------------------------------------------*/
/*  Make sure mail server is connected to the system.     */
/*--------------------------------------------------------*/
             qsys/ping  rmtsys(&MailRtrIP)                 +
                          msgmode(*Quiet)
             monmsg     TCP3202    exec(do)
               if         (&Interactv = '0')     goto error
               rcvmsg     msgtype(*last)                   +
                            msgdta(&msgdta)                +
                            msgid(&msgid)                  +
                            msgf(&msgf)                    +
                            msgflib(&msgflib)
               sndpgmmsg  msgid(&msgid)                    +
                            msgf(&msgflib/&msgf)           +
                            msgdta(&msgdta)
               goto       end
             enddo
             rmvmsg     clear(*all)

/*--------------------------------------------------------*/
/*  Setup *LIBL for SMTP                                  */
/*--------------------------------------------------------*/
             addlible   QusrSys
             monmsg     cpf0000

/*--------------------------------------------------------*/
/*  Copy all Attributes to QRPLOBJ library                */
/*--------------------------------------------------------*/
             crtdupobj  obj(QATMSMTP)                      +
                          fromlib(QUsrSys)                 +
                          objtype(*file)                   +
                          tolib(QRplObj)                   +
                          data(*yes)
             monmsg     cpf0000

             crtdupobj  obj(QATMPOPA)                      +
                          fromlib(QUsrSys)                 +
                          objtype(*file)                   +
                          tolib(QRplObj)                   +
                          data(*yes)
             monmsg     cpf0000

             crtdupobj  obj(QTOCHOST)                      +
                          fromlib(QUsrSys)                 +
                          objtype(*file)                   +
                          tolib(QRplObj)                   +
                          data(*yes)
             monmsg     cpf0000

/*--------------------------------------------------------*/
/*  Change the attributes                                 */
/*--------------------------------------------------------*/

          /*----------------------------------------------*/
          /*  SMTP                                        */
          /*----------------------------------------------*/
             chgsmtpa   autostart(*Yes)                    +
                          mailrouter(&MailRtr)             +
                          ccsid(00819)
             monmsg     cpf0000
          /*----------------------------------------------*/
          /*  Host Table Entry                            */
          /*----------------------------------------------*/
             addtcphte  intnetadr(&MailRtrIP)              +
                          hostname(&MailRtr)
             monmsg     cpf0000
          /*----------------------------------------------*/
          /*  POP                                         */
          /*----------------------------------------------*/
             chgpopa    msgsplit(1024)                     +
                          mimeccsid(00819 *BESTFIT)
             monmsg     cpf0000
          /*----------------------------------------------*/
          /*  Message Split                               */
          /*----------------------------------------------*/
             crtdtaara  dtaara(Qusrsys/QtmsNoSplt)         +
                          type(*char)                      +
                          len(1)
             monmsg     cpf0000

/*--------------------------------------------------------*/
/*  Add directory entries used by SMTP                    */
/*--------------------------------------------------------*/
             adddire    usrid(internet gateway)            +
                          usrd('Internet SMTP gateway')    +
                          sysname(INTERNET)                +
                          prefadr(Netusrid *IBM Gateway)
             monmsg       cpf0000

             chgdsta    smtprte(internet gateway)          +

/*--------------------------------------------------------*/
/*  Start the SMTP server                                 */
/*--------------------------------------------------------*/
             endtcpsvr  server(*smtp *pop)
             monmsg       cpf0000

             strtcpsvr  server(*smtp *pop)
             monmsg       cpf0000


 finish:
             goto       end

/*--------------------------------------------------------*/
/*  error routine:                                        */
/*--------------------------------------------------------*/
 error:
             if         &error     (goto errordone)
               else      chgvar       &error  '1'
          /*----------------------------------------------*/
          /*  move all *DIAG message to *PRV program queue*/
          /*----------------------------------------------*/
             call       QMHMOVPM   (&msgkey      +
                                    &msgtyp      +
                                    &msgtypctr   +
                                    &pgmmsgq     +
                                    &stkctr      +
                                    &errbytes)
          /*----------------------------------------------*/
          /*  resend the last *ESCAPE message             */
          /*----------------------------------------------*/
 errordone:
             call       QMHRSNEM   (&msgkey      +
                                    &errbytes)
             monmsg     cpf0000    exec(do)
               sndpgmmsg  msgid(cpf3cf2) msgf(QCFPMSG) +
                            msgdta('QMHRSNEM') msgtype(*escape)
               monmsg     cpf0000
             enddo
 end:        endpgm
