home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume26 / pcomm-2.0.2 / part02 / admin.c next >
Encoding:
C/C++ Source or Header  |  1993-04-13  |  2.9 KB  |  143 lines

  1. /*
  2.  * Perform administrative functions.  Check to see if the user has
  3.  * permission to make long distance calls, and record all phone calls
  4.  * made by Pcomm.
  5.  */
  6.  
  7. #include <stdio.h>
  8. #include <grp.h>
  9. #include "config.h"
  10. #include "dial_dir.h"
  11. #include "param.h"
  12.  
  13. static char *build_num();
  14.  
  15. /*
  16.  * Make a log of all calls made by Pcomm.  The argument is the index
  17.  * into the queue.
  18.  */
  19.  
  20. /* ARGSUSED */
  21. void
  22. log_calls(i)
  23. int i;
  24. {
  25. #ifdef LOG_CALLS
  26.     FILE *fp;
  27.     char *number, *date, *ctime(), *getlogin(), buf[80];
  28.     long now, time();
  29.     void error_win();
  30.                     /* build the complete phone number */
  31.     number = build_num(i);
  32.                     /* build date and time */
  33.     time(&now);
  34.     date = ctime(&now);
  35.     date[10] = '\0';
  36.     date[16] = '\0';
  37.  
  38.     if (!(fp = fopen(LOG_FILE, "a+"))) {
  39.                     /* fatal! (to prevent hanky panky) */
  40.         sprintf(buf, "Can't open log file \"%s\"", LOG_FILE);
  41.         error_win(1, buf, "Contact your system administrator");
  42.     }
  43.  
  44.     fprintf(fp, "pcomm: %s called %s at %s on %s\n", getlogin(), number, &date[11], date);
  45.     fclose(fp);
  46. #endif /* LOG_CALLS */
  47.     return;
  48. }
  49.  
  50. /*
  51.  * Check to see if long distance (toll) call is authorized.  The argument
  52.  * is the index into the queue.
  53.  */
  54.  
  55. /* ARGSUSED */
  56. int
  57. limit_ld(i)
  58. int i;
  59. {
  60. #ifdef LIMIT_LD
  61.     char *number, *name, *getlogin();
  62.     struct group *getgrnam(), *grpbuf;
  63.  
  64.                     /* if no group, don't bother */
  65.     grpbuf = getgrnam(GROUP_NAME);
  66.     if (grpbuf == NULL || *grpbuf->gr_mem == '\0')
  67.         return(0);
  68.                     /* are you in the group? */
  69.     name = getlogin();
  70.     for (; *grpbuf->gr_mem!='\0'; grpbuf->gr_mem++) {
  71.         if (!strcmp(*grpbuf->gr_mem, name))
  72.             return(0);
  73.     }
  74.                     /* numbers only... */
  75.     number = build_num(i);
  76.  
  77.     /*
  78.      * VERY SITE SPECIFIC!!!  We use a "9" to get an outside line,
  79.      * so any 9 followed by a 1 is a toll call (except for 1-800
  80.      * numbers).
  81.      */
  82.     if (!strncmp(number, "91", 2) && strncmp(number, "91800", 5)) {
  83.         error_win(0, "You are not authorized to place long distance (toll) calls", "");
  84.         return(1);
  85.     }
  86.  
  87.     if (*number == '\0') {
  88.         error_win(0, "You are not authorized direct access to the line", "Use the automatic dialing feature");
  89.         return(1);
  90.     }
  91. #endif /* LIMIT_LD */
  92.     return(0);
  93. }
  94.  
  95. #if defined(LOG_CALLS) || defined(LIMIT_LD)
  96. /*
  97.  * Put together the complete phone number but strip out the extraneous
  98.  * characters.
  99.  */
  100.  
  101. static char *
  102. build_num(i)
  103. int i;
  104. {
  105.     int j;
  106.     char *t, temp[80], *strcpy(), *strcat();
  107.     static char ans[80];
  108.  
  109.     temp[0] = '\0';
  110.                     /* add LD codes? */
  111.     switch (dir->q_ld[i]) {
  112.         case 0:
  113.             break;
  114.         case '+':
  115.             strcpy(temp, param->ld_plus);
  116.             break;
  117.         case '-':
  118.             strcpy(temp, param->ld_minus);
  119.             break;
  120.         case '@':
  121.             strcpy(temp, param->ld_at);
  122.             break;
  123.         case '#':
  124.             strcpy(temp, param->ld_pound);
  125.             break;
  126.     }
  127.                     /* add the number */
  128.     strcat(temp, dir->number[dir->q_num[i]]);
  129.  
  130.                     /* copy only digits */
  131.     j = 0;
  132.     t = temp;
  133.     while (*t) {
  134.         if (*t >= '0' && *t <= '9')
  135.             ans[j++] = *t;
  136.         t++;
  137.     }
  138.     ans[j] = '\0';
  139.  
  140.     return(ans);
  141. }
  142. #endif /* LOG_CALLS || LIMIT_LD */
  143.