home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Archives / Shells / UsrInf13.lha / UserInfo.C next >
Encoding:
C/C++ Source or Header  |  1994-01-06  |  5.7 KB  |  243 lines

  1. ;/*
  2. DCC UserInfo.C -o UserInfo -lm
  3. Quit
  4. */
  5.  
  6. /*                          _
  7.     UserInfo for AXsh by Guru Gnosis Sahib
  8.     v1.0 - 15-Oct-93 - First working implementation
  9.     v1.1 - 12-Dec-93 - Added xpr.log analysis, moved in questionnaire
  10.                        and recent calls code from another utility
  11.     v1.2 - 26-Dec-93 - Now uses System() instead of Execute()
  12.     v1.3 - 06-Jan-93 - Superuser commands now allowed for assistant,
  13.                        superuser, wizard and system
  14.  
  15.     Written with DICE C registered, should compile relatively nicely
  16.     with other systems as well, just link in a math library.  For DICE,
  17.     just type "Execute UserInfo.C" and the rest is magic.
  18. */
  19.  
  20. #include <stdio.h>
  21. #include <string.h>
  22. #include <libraries/dos.h>
  23. #include <dos/dostags.h>
  24. #include <dos/var.h>
  25.  
  26. #define TRUE        1
  27. #define FALSE        0
  28. #define NORMAL        0
  29. #define SUPERUSER    1
  30.  
  31. main(argc,argv)
  32. int argc;
  33. char *argv[];
  34. {
  35.     FILE *input, *input2;
  36.     BPTR in, out;
  37.     char user[80], level[80], first[80], temp[80], answers[80];
  38.     long byte, ulbyte = 0, dlbyte = 0;
  39.     int ulfile = 0, dlfile = 0, tcps = 0, times = 0, ttime = 0;
  40.     int cps, first_ch = TRUE, utype = NORMAL, success, ques, foo;
  41.  
  42.     if(!(success = GetVar("user", user, 80, GVF_LOCAL_ONLY)))
  43.     {
  44.         puts("UserInfo - couldn't open local variable 'user'");
  45.         exit(5);
  46.     }
  47.     if(!strcmp(user, ""))
  48.     {
  49.         puts("UserInfo - couldn't open local variable 'user'");
  50.         exit(5);
  51.     }
  52.     if(argc > 1)
  53.     {
  54.         if(!(success = GetVar("accesslevel", level, 80, GVF_LOCAL_ONLY)))
  55.         {
  56.             puts("UserInfo - couldn't open local variable 'accesslevel'");
  57.             exit(5);
  58.         }
  59.         if(!stricmp(level, "superuser") || !stricmp(level, "assistant") ||
  60.             !stricmp(level, "wizard") || !stricmp(level, "system"))
  61.         {
  62.             if(!strcmp(argv[1], "?") || !strncmp(argv[1], "-", 1))
  63.             {
  64.                 puts("\nUserInfo v1.3 for AXsh by Guru Gnosis Sahib");
  65.                 puts("Usage: UserInfo [username]\n");
  66.                 exit(0);
  67.             }
  68.             strcpy(user, argv[1]);
  69.             utype = SUPERUSER;
  70.         }
  71.         else
  72.         {
  73.             puts("Access denied!");
  74.             exit(5);
  75.         }
  76.     }
  77.     puts("\nUserInfo v1.3 by Guru Gnosis Sahib\n");
  78.     sprintf(temp, "AXsh:bin/passwd -d %s", user);
  79.     success = System(temp, TAG_END);
  80.     if(success != 0)
  81.     {
  82.         puts("Scan usage.log and xpr.log anyway? (y/N)");
  83.         gets(temp);
  84.         if(stricmp(temp, "y")) exit(0);        /* if not 'y' then exit */
  85.     }
  86.     if(!(input = fopen("AXsh:etc/adm/usage.log", "r")))
  87.     {
  88.         puts("UserInfo - could not open AXsh:etc/adm/usage.log");
  89.         exit(0);
  90.     }
  91.     while(!(feof(input)))
  92.     {
  93.         fscanf(input, "%s", temp);
  94.         if(!(strnicmp(user, temp, strlen(user))))
  95.         {
  96.             fscanf(input, "%s", temp);    /* Date */
  97.             if(first_ch == TRUE)
  98.             {
  99.                 first_ch = FALSE;
  100.                 strcpy(first, temp);
  101.             }
  102.             fscanf(input, "%s", temp);    /* Login */
  103.             fscanf(input, "%s", temp);    /* Logout */
  104.             fscanf(input, "%s", temp);    /* Time! */
  105.             ttime += atoi(temp);
  106.             times++;
  107.         }
  108.     }
  109.     fclose(input);
  110.     printf("Total login time: %d minutes online\n", ttime);
  111.     printf("Total logins    : %d logins\n", times);
  112.     printf("Av. login length: %d minutes\n", ttime / times);
  113.     printf("First login     : %s\n\n", first);
  114.     if(!(input = fopen("AXsh:etc/adm/xpr.log", "r")))
  115.     {
  116.         puts("UserInfo - could not open AXsh:etc/adm/xpr.log");
  117.         exit(0);
  118.     }
  119.     fgets(temp, 80, input);        /* Header */
  120.     fgets(temp, 80, input);        /* Blank line */
  121.     while(!(feof(input)))
  122.     {
  123.         fscanf(input, "%d %d %d %s", &foo, &byte, &cps, temp);        /* Date */
  124.         if(!strcmp(temp, user) && !feof(input))
  125.         {
  126.             fscanf(input, "%s", temp);
  127.             if(!strcmp(temp, "Rcvd"))
  128.             {
  129.                 ulbyte += byte;
  130.                 ulfile++;
  131.             }
  132.             else
  133.             {
  134.                 dlbyte += byte;
  135.                 dlfile++;
  136.             }
  137.             tcps += cps;
  138.         }
  139.         if(!feof(input)) fgets(temp, 80, input); /* Read in the rest */
  140.     }
  141.     fclose(input);
  142.     printf("Bytes downloaded: %-8ld             Files downloaded: %-4d\n",
  143.         dlbyte, dlfile);
  144.     printf("Bytes uploaded  : %-8ld             Files uploaded  : %-4d\n",
  145.         ulbyte, ulfile);
  146.     if(dlfile != 0)
  147.     {
  148.         printf("Byte UL/DL ratio: %2.4f               File UL/DL ratio: %2.4f\n",
  149.             (float) ulbyte / dlbyte, (float) ulfile / dlfile);
  150.     }
  151.     else
  152.         puts("Byte UL/DL ratio: N/A                  File UL/DL ratio: N/A");
  153.     if(dlfile + ulfile != 0)
  154.         printf("Average CPS rate: %d\n\n", tcps / (ulfile + dlfile));
  155.     else
  156.         puts("Average CPS rate: N/A\n");
  157.  
  158.     if(utype != SUPERUSER) exit(0);
  159.     puts("--- Q to quit, ENTER for more ---");
  160.     gets(temp);
  161.     if(!stricmp(temp, "q")) exit(0);
  162.  
  163.     if(!(input = fopen("AXsh:etc/rc", "r")))
  164.     {
  165.         puts("UserInfo: could not open AXsh:etc/rc");
  166.         exit(1);
  167.     }
  168.     while(!(feof(input)))
  169.     {
  170.         fgets(temp, 80, input);
  171.         if(!(strnicmp(temp, "%answers:", 9)))
  172.             fscanf(input, "%s", answers);
  173.     }
  174.     fclose(input);
  175.  
  176.     if(strlen(answers) == 1) strcpy(answers, "AXsh:etc/adm/Answers");
  177.     if(!(input = fopen("AXsh:etc/Questionnaire", "r")))
  178.     {
  179.         puts("UserInfo: could not open AXsh:etc/Questionnaire");
  180.         exit(1);
  181.     }
  182.     if(!(input2 = fopen(answers, "r")))
  183.     {
  184.         printf("UserInfo: could not open %s", answers);
  185.         exit(1);
  186.     }
  187.  
  188.     puts("Questionnaire answers:\n");
  189.     ques = FALSE;
  190.     while(!(feof(input2)))
  191.     {
  192.         fscanf(input2, "%s", temp);
  193.         if(!(strcmp(temp, "User:")))
  194.         {
  195.             fscanf(input2, "%s", temp);
  196.             if(!(stricmp(temp, user)))
  197.             {
  198.                 ques = TRUE;
  199.                 fgets(temp, 80, input2);
  200.                 while(!(feof(input)))
  201.                 {
  202.                     fgets(temp, 80, input);
  203.                     if (!(feof(input)))
  204.                     {
  205.                         printf("- %s", temp);
  206.                         fgets(temp, 80, input2);
  207.                         printf("%s", temp);
  208.                     }
  209.                 }
  210.             }
  211.         }
  212.     }
  213.     if (ques == FALSE)
  214.         puts("No questionnaire answers found.");
  215.     fclose(input);
  216.     fclose(input2);
  217.  
  218.     puts("\n--- Q to quit, ENTER for more ---");
  219.     gets(temp);
  220.     if(!stricmp(temp, "q")) exit(0);
  221.  
  222.     puts("Recent calls:\n");
  223.     ques = FALSE;
  224.     if(!(input = fopen("AXsh:etc/last", "r")))
  225.     {
  226.         puts("UserInfo: could not open AXsh:etc/last");
  227.         exit(0);
  228.     }
  229.     while(!feof(input))
  230.     {
  231.         fgets(temp, 80, input);
  232.         if(!(strnicmp(user, temp, strlen(user))))
  233.         {
  234.             ques = TRUE;
  235.             printf("%s", temp);
  236.         }
  237.     }
  238.     if(ques == FALSE) puts("No recent calls found.");
  239.     fclose(input);
  240.     puts("");
  241.     exit(0);
  242. }
  243.