home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / MISC / LO241SRV.ZIP / config.c < prev    next >
C/C++ Source or Header  |  1998-08-01  |  16KB  |  655 lines

  1.  
  2. // LoraBBS Version 2.41 Free Edition
  3. // Copyright (C) 1987-98 Marco Maccaferri
  4. //
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation; either version 2 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. // GNU General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU General Public License
  16. // along with this program; if not, write to the Free Software
  17. // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include <string.h>
  22. #include <ctype.h>
  23. #include <time.h>
  24. #include <process.h>
  25. #include <conio.h>
  26. #include <io.h>
  27. #include <dos.h>
  28. #include <fcntl.h>
  29. #include <sys\stat.h>
  30.  
  31. #define INCL_DOS
  32. #include <os2.h>
  33.  
  34. #include <cxl\cxlvid.h>
  35. #include <cxl\cxlwin.h>
  36.  
  37. #include "lsetup.h"
  38. #include "sched.h"
  39. #include "msgapi.h"
  40. #include "externs.h"
  41. #include "prototyp.h"
  42. #include "zmodem.h"
  43. #include "exec.h"
  44.  
  45. extern HFILE hfComHandle;
  46.  
  47. extern int blank_timer, socket, lastread_need_save;
  48. extern short tcpip;
  49. extern long exectime;
  50.  
  51. int spawn_program (int swapout, char *outstring);
  52. void update_lastread_pointers (void);
  53. char *config_file = "CONFIG.DAT", **dos_argv, nopoll = 0, nomailproc = 0, nonetmail = 0;
  54.  
  55. static MDM_TRNS *mm_head;
  56.  
  57. int far parse_config()
  58. {
  59.    FILE *fp;
  60.    char linea[256], *p, *pc;
  61.  
  62.    _vinfo.dvcheck = 0;
  63.    videoinit();
  64.  
  65.    pc = config_file;
  66.  
  67.    fp = fopen (config_file, "rb");
  68.    if (fp == NULL) {
  69.       if ((p=getenv ("LORA")) != NULL) {
  70.          strcpy (linea, p);
  71.          append_backslash (linea);
  72.          strcat (linea, config_file);
  73.          config_file = linea;
  74.       }
  75.       fp = fopen (config_file, "rb");
  76.    }
  77.  
  78. try_setup:
  79.    if (fp != NULL) {
  80.       fread ((char *)config, sizeof (struct _configuration), 1, fp);
  81.       fclose (fp);
  82.  
  83.       if (config->version != CONFIG_VERSION) {
  84.          printf ("\n\aConfiguration file error. Run LSETUP.\n");
  85.          exit (0);
  86.       }
  87.  
  88.       hold_area = config->outbound;
  89.       netmail_dir = config->netmail_dir;
  90.       if (config->bad_msgs[0])
  91.          bad_msgs = config->bad_msgs;
  92.       if (config->dupes[0])
  93.          dupes = config->dupes;
  94.       pip_msgpath = config->pip_msgpath;
  95.       fido_msgpath = config->quick_msgpath;
  96.       ipc_path = config->ipc_path;
  97.       sysop = config->sysop;
  98.       system_name = config->system_name;
  99.       location = config->location;
  100.       phone = config->phone;
  101.       flags = config->flags;
  102.       lock_baud = config->lock_baud;
  103.         terminal = config->terminal;
  104.  
  105.         if(config->areachange_key[0])
  106.             strncpy(area_change_key,config->areachange_key,4);
  107.  
  108.       if (config->modem_busy[0])
  109.          modem_busy = config->modem_busy;
  110.       if (config->mustbezero) {
  111.          strcpy (config->answer, (char *)&config->mustbezero);
  112.          memset (&config->mustbezero, 0, 20);
  113.       }
  114.       if (config->answer[0])
  115.          answer = config->answer;
  116.       init = config->init;
  117.       dial = config->dial;
  118.       log_name = config->log_name;
  119.       frontdoor = config->log_style;
  120.       filepath = config->norm_filepath;
  121.       if (config->norm_okfile[0])
  122.          request_list = norm_request_list = config->norm_okfile;
  123.       if (config->prot_okfile[0])
  124.          prot_request_list = config->prot_okfile;
  125.       if (config->know_okfile[0])
  126.          know_request_list = config->know_okfile;
  127.       norm_max_kbytes = config->norm_max_kbytes;
  128.       prot_max_kbytes = config->prot_max_kbytes;
  129.       know_max_kbytes = config->know_max_kbytes;
  130.       norm_max_requests = config->norm_max_requests;
  131.       prot_max_requests = config->prot_max_requests;
  132.       know_max_requests = config->know_max_requests;
  133.       blank_timer = config->blank_timer;
  134.       if (config->line_offset == 0)
  135.          config->line_offset = 1;
  136.       line_offset = config->line_offset;
  137.       snooping = config->snooping;
  138.       aftercaller_exit = config->aftercaller_exit;
  139.       aftermail_exit = config->aftermail_exit;
  140.         dateformat = config->dateformat;
  141.       timeformat = config->timeformat;
  142.  
  143.       if (config->no_direct)
  144.          setvparam (VP_BIOS);
  145.       else
  146.          setvparam (VP_DMA);
  147.       if (config->snow_check)
  148.          setvparam (VP_CGA);
  149.       if (config->mono_attr)
  150.          setvparam (VP_MONO);
  151.  
  152.       if (!config->speed)
  153.          config->speed = config->old_speed;
  154.       if (!speed)
  155.          speed = rate = config->speed;
  156.       if (com_port == -1)
  157.          com_port = config->com_port;
  158.  
  159.       if (!config->carrier_mask) {
  160.          config->carrier_mask = 128;
  161.          config->dcd_timeout = 1;
  162.       }
  163.  
  164.       Txbuf = Secbuf = (byte *) malloc (WAZOOMAX + 16);
  165.       if (Txbuf == NULL)
  166.          exit (250);
  167.    }
  168.    else {
  169.       config_file = pc;
  170.       spawn_program (1, config_file);
  171.  
  172.       fp = fopen (config_file, "rb");
  173.         if (fp != NULL)
  174.            goto try_setup;
  175.  
  176.       exit (1);
  177.    }
  178.  
  179.    config_file = pc;
  180.    return(1);
  181. }
  182.  
  183. void init_system()
  184. {
  185.    log_name = NULL;
  186.    sysop = system_name = request_list = NULL;
  187.    availist = about = hold_area = NULL;
  188.    password = NULL;
  189.    pip_msgpath = timeformat = dateformat = text_path = ipc_path = NULL;
  190.    answer = ext_mail_cmd = NULL;
  191.    norm_about = norm_availist = NULL;
  192.    norm_request_list = prot_request_list = prot_availist = prot_about = NULL;
  193.    know_request_list = know_availist = know_about = NULL;
  194.    bad_msgs = dupes = netmail_dir = location = phone = flags = NULL;
  195.    modem_busy = NULL;
  196.    hslink_exe = puma_exe = NULL;
  197.    mm_head = NULL;
  198.    msg_list = NULL;
  199.  
  200.    blank_timer = 0;
  201.    tcpip = 0;
  202.  
  203.    vote_priv = up_priv = down_priv = 0;
  204.  
  205.    norm_max_kbytes = prot_max_kbytes = know_max_kbytes = max_kbytes = 0;
  206.    CurrentReqLim = max_call = speed_graphics = max_requests = 0;
  207.    registered = line_offset = no_logins = next_call = 0;
  208.    norm_max_requests = prot_max_requests = know_max_requests = 0;
  209.    allowed = assumed = remote_capabilities = 0;
  210.    target_up = target_down = 0;
  211.    remote_zone = remote_net = remote_node = remote_point = 0;
  212.    com_port = -1;
  213.  
  214.    emulator = answer_flag = lock_baud = terminal = use_tasker = 0;
  215.    got_arcmail = sliding = ackless_ok = do_chksum = may_be_seadog = 0;
  216.    did_nak = netmail = who_is_he = overwrite = allow_reply = 0;
  217.    frontdoor = local_mode = user_status = caller = 0;
  218.    snooping = 1;
  219.  
  220.    rate = speed = 0L;
  221.  
  222.    max_readpriv = ASSTSYSOP;
  223.    sq_ptr = NULL;
  224.  
  225.    strcpy (area_change_key, "[]?");
  226.    config = (struct _configuration *)malloc (sizeof (struct _configuration));
  227.    if (config == NULL) {
  228.       printf ("\a\a\a");
  229.       exit (0);
  230.    }
  231.  
  232.    hfComHandle = NULLHANDLE;
  233. }
  234.  
  235. int get_priv(txt)
  236. char *txt;
  237. {
  238.    int i, priv;
  239.  
  240.    priv = HIDDEN;
  241.  
  242.    for (i=0;i<12;i++)
  243.       if (!stricmp(levels[i].p_string, txt) ||
  244.           levels[i].p_string[0] == txt[0] )
  245.       {
  246.          priv = levels[i].p_length;
  247.          break;
  248.       }
  249.  
  250.    return (priv);
  251. }
  252.  
  253. char *get_priv_text (priv)
  254. int priv;
  255. {
  256.    int i;
  257.    char *txt;
  258.  
  259.    txt = "???";
  260.  
  261.    for (i=0;i<12;i++)
  262.       if (levels[i].p_length == priv)
  263.       {
  264.          txt = levels[i].p_string;
  265.          break;
  266.       }
  267.  
  268.    return (txt);
  269. }
  270.  
  271. char *replace_blank(s)
  272. char *s;
  273. {
  274.    char *p;
  275.  
  276.    while ((p=strchr(s,'_')) != NULL)
  277.       *p = ' ';
  278.  
  279.    return (s);
  280. }
  281.  
  282. int get_class(p)
  283. int p;
  284. {
  285.    int m;
  286.    for(m=0;m<MAXCLASS;m++) if(config->class[m].priv == p)
  287.       return(m);
  288.    for(m=0;m<MAXCLASS;m++) if(config->class[m].priv == 255)
  289.    {
  290.       config->class[m].priv=p;
  291.       return(m);
  292.    }
  293.    return(-1);
  294. }
  295.  
  296. void detect_line_number (void)
  297. {
  298.    int fd;
  299.    char filename[80];
  300.    struct _useron useron;
  301.  
  302.    sprintf (filename, USERON_NAME, config->sys_path);
  303.    if ((fd = sh_open (filename, SH_DENYNONE, O_RDONLY|O_BINARY, S_IREAD|S_IWRITE)) != -1) {
  304.       while (read (fd, (char *)&useron, sizeof (struct _useron)) == sizeof (struct _useron)) {
  305.          if (useron.line == line_offset) {
  306.             line_offset++;
  307.             lseek (fd, 0L, SEEK_SET);
  308.          }
  309.       }
  310.       close (fd);
  311.    }
  312. }
  313.  
  314. void parse_command_line(argc, argv)
  315. int argc;
  316. char **argv;
  317. {
  318.    int i, errors;
  319.  
  320.    errors = 0;
  321.    dos_argv = argv;
  322.    nopoll = nomailproc = 0;
  323.  
  324.    for (i = 1; i < argc; i++) {
  325.       if (argv[i][0] != '-' && argv[i][0] != '/')
  326.          continue;
  327.  
  328.       else if (!stricmp (argv[i], "-NP"))
  329.      nopoll = 1;
  330.       else if (!stricmp (argv[i], "-NM"))
  331.      nomailproc = 1;
  332.       else if (!stricmp (argv[i], "-XN"))
  333.      nonetmail = 1;
  334. #if defined (__OCC__) || defined (__TCPIP__)
  335.       else if (!stricmp (argv[i], "-TCPIP")) {
  336.      socket = atoi (argv[++i]);
  337.      tcpip = 1;
  338.      caller = 1;
  339.      snooping = 1;
  340.      dos_argv = NULL;
  341.      continue;
  342.       }
  343. #endif
  344.  
  345.       switch (toupper (argv[i][1])) {
  346.          case 'B':
  347.             speed = rate = atoi(&argv[i][2]);
  348.             caller = 1;
  349.             if (rate == 0)
  350.                local_mode = 1;
  351.             dos_argv = NULL;
  352.             break;
  353.  
  354.          case 'C':
  355.             config_file = &argv[i][2];
  356.             break;
  357.  
  358.          case 'F':
  359.             mdm_flags = &argv[i][2];
  360.             break;
  361.  
  362.      case 'H':
  363.         hfComHandle = atol (&argv[i][2]);
  364.         break;
  365.  
  366.          case 'I':
  367.             init = &argv[i][2];
  368.             break;
  369.  
  370.          case 'L':
  371.             if (toupper (argv[i][2]) == 'F') {
  372.                local_mode = 2;
  373.                caller = 1;
  374.                snooping = 1;
  375.             }
  376.             else
  377.                local_mode = 1;
  378.             dos_argv = NULL;
  379.             break;
  380.  
  381.          case 'M':
  382.             no_logins = 1;
  383.             if (argv[i][2])
  384.                ext_mail_cmd = (char *)&argv[i][2];
  385.             break;
  386.  
  387.          case 'N':
  388.             if (isdigit (argv[i][2]))
  389.                     line_offset = atoi (&argv[i][2]);
  390.             else if (toupper (argv[i][2]) == 'A') {
  391.                if (isdigit (argv[i][3]))
  392.                   line_offset = atoi (&argv[i][3]);
  393.                else
  394.                   line_offset = 1;
  395.                detect_line_number ();
  396.             }
  397.             break;
  398.  
  399.          case 'O':
  400.             dos_argv = NULL;
  401.             parse_netnode (&argv[i][2], &remote_zone, &remote_net, &remote_node, &remote_point);
  402.             break;
  403.  
  404.          case 'T':
  405.             if (isdigit (argv[i][2]))
  406.                allowed = atoi (&argv[i][2]);
  407.             break;
  408.  
  409.          case 'P':
  410.             com_port = atoi(&argv[i][2]);
  411.             com_port--;
  412.             break;
  413.  
  414.          case 'R':
  415.             log_name = (char *)&argv[i][2];
  416.             break;
  417.  
  418.          default:
  419.             errors = 1;
  420.             printf (msgtxt[M_UNRECOGNIZED_OPTION], argv[i]);
  421.             break;
  422.         }
  423.    }
  424.  
  425.    if (errors)
  426.       sleep (5);
  427. }
  428.  
  429.  
  430. void parse_config_line (argc, argv)
  431. int argc;
  432. char **argv;
  433. {
  434.    int i;
  435.  
  436.    for (i = 1; i < argc; i++) {
  437.       if (argv[i][0] != '-' && argv[i][0] != '/')
  438.          continue;
  439.  
  440.       switch (toupper (argv[i][1])) {
  441.          case 'C':
  442.             config_file = &argv[i][2];
  443.             break;
  444.       }
  445.    }
  446. }
  447.  
  448. void append_backslash (s)
  449. char *s;
  450. {
  451.    int i;
  452.  
  453.    i = strlen(s) - 1;
  454.    if (s[i] != '\\')
  455.       strcat (s, "\\");
  456. }
  457.  
  458. void dial_number (type, phone)
  459. byte type;
  460. char *phone;
  461. {
  462.    char *predial, *postdial;
  463.  
  464.    predial = config->dial;
  465.    if (config->dial_suffix[0])
  466.       postdial = config->dial_suffix;
  467.    else
  468.       postdial = "|";
  469.  
  470.    if (type) {
  471.       if (type < 20) {
  472.          if (config->altdial[type - 1].prefix[0])
  473.             predial = config->altdial[type - 1].prefix;
  474.          if (config->altdial[type - 1].suffix[0])
  475.             postdial = config->altdial[type - 1].suffix;
  476.       }
  477.       else {
  478.          type -= 20;
  479.             if (config->prefixdial[type].prefix[0])
  480.             predial = config->prefixdial[type].prefix;
  481.       }
  482.    }
  483.  
  484.    mdm_sendcmd (predial);
  485.    mdm_sendcmd (phone);
  486.    mdm_sendcmd (postdial);
  487. }
  488.  
  489. long get_flags (char *p)
  490. {
  491.    long flag;
  492.  
  493.    flag = 0L;
  494.  
  495.    while (*p && *p != ' ')
  496.       switch (toupper(*p++))
  497.       {
  498.       case 'V':
  499.          flag |= 0x00000001L;
  500.          break;
  501.       case 'U':
  502.          flag |= 0x00000002L;
  503.          break;
  504.       case 'T':
  505.          flag |= 0x00000004L;
  506.          break;
  507.       case 'S':
  508.          flag |= 0x00000008L;
  509.          break;
  510.       case 'R':
  511.          flag |= 0x00000010L;
  512.             break;
  513.       case 'Q':
  514.          flag |= 0x00000020L;
  515.          break;
  516.       case 'P':
  517.          flag |= 0x00000040L;
  518.          break;
  519.       case 'O':
  520.          flag |= 0x00000080L;
  521.          break;
  522.       case 'N':
  523.          flag |= 0x00000100L;
  524.          break;
  525.       case 'M':
  526.          flag |= 0x00000200L;
  527.          break;
  528.       case 'L':
  529.          flag |= 0x00000400L;
  530.          break;
  531.       case 'K':
  532.          flag |= 0x00000800L;
  533.          break;
  534.       case 'J':
  535.          flag |= 0x00001000L;
  536.          break;
  537.       case 'I':
  538.          flag |= 0x00002000L;
  539.          break;
  540.       case 'H':
  541.          flag |= 0x00004000L;
  542.          break;
  543.       case 'G':
  544.          flag |= 0x00008000L;
  545.             break;
  546.       case 'F':
  547.          flag |= 0x00010000L;
  548.          break;
  549.       case 'E':
  550.          flag |= 0x00020000L;
  551.          break;
  552.         case 'D':
  553.             flag |= 0x00040000L;
  554.             break;
  555.         case 'C':
  556.             flag |= 0x00080000L;
  557.             break;
  558.         case 'B':
  559.             flag |= 0x00100000L;
  560.             break;
  561.         case 'A':
  562.             flag |= 0x00200000L;
  563.             break;
  564.         case '9':
  565.             flag |= 0x00400000L;
  566.             break;
  567.         case '8':
  568.             flag |= 0x00800000L;
  569.             break;
  570.         case '7':
  571.             flag |= 0x01000000L;
  572.             break;
  573.         case '6':
  574.             flag |= 0x02000000L;
  575.             break;
  576.         case '5':
  577.             flag |= 0x04000000L;
  578.             break;
  579.         case '4':
  580.             flag |= 0x08000000L;
  581.             break;
  582.         case '3':
  583.             flag |= 0x10000000L;
  584.             break;
  585.         case '2':
  586.             flag |= 0x20000000L;
  587.             break;
  588.         case '1':
  589.             flag |= 0x40000000L;
  590.             break;
  591.         case '0':
  592.             flag |= 0x80000000L;
  593.             break;
  594.         }
  595.  
  596.     return (flag);
  597. }
  598.  
  599. extern int ox, oy, wh1;
  600.  
  601. void get_down (int errlev, int flag)
  602. {
  603.     char filename[80];
  604.  
  605.     sysinfo.today.exectime += time (NULL) - exectime;
  606.     sysinfo.week.exectime += time (NULL) - exectime;
  607.     sysinfo.month.exectime += time (NULL) - exectime;
  608.     sysinfo.year.exectime += time (NULL) - exectime;
  609.  
  610.     if(lastread_need_save)          // Aggiorna se necessario i puntatori
  611.         update_lastread_pointers (); // Lastread per il qwk/BW
  612.  
  613.  
  614.     if(something_wrong){
  615.     bad_call (sw_net, sw_node, 1, ABORTED);
  616.     }
  617.  
  618.     MsgCloseApi ();
  619.     write_sysinfo();
  620.     sprintf (filename, "F-TAG%d.TMP", config->line_offset);
  621.     unlink (filename);
  622.     sprintf (filename, "DL-REP%d.BBS", line_offset);
  623.     unlink (filename);
  624.     sprintf (filename, "REP%d.TXT", line_offset);
  625.     unlink (filename);
  626.     update_user ();
  627.  
  628.     if (!frontdoor) {
  629.         status_line(":End");
  630.         fprintf(logf, "\n");
  631.     }
  632.  
  633.     fclose (logf);
  634.  
  635.     if (errlev || dos_argv == NULL) {
  636.         if (!local_mode) {
  637.             if (modem_busy != NULL)
  638.                 mdm_sendcmd (modem_busy);
  639.         }
  640.  
  641.         MDM_DISABLE();
  642.  
  643.         wcloseall ();
  644.         cclrscrn(LGREY|_BLACK);
  645.         showcur();
  646.         gotoxy (1, 10);
  647.         exit ((errlev == -1) ? config->altx_errorlevel : errlev);
  648.     }
  649.     else {
  650.         MDM_DISABLE();
  651.         exit (255);
  652.     }
  653. }
  654.  
  655.