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