"Fossies" - the Fresh Open Source Software Archive

Member "tcpproxy-2.0.0-beta15/proxylogger" (16 Nov 2005, 1930 Bytes) of package /linux/privat/old/tcpproxy-2.0.0-beta15.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) (G)AWK source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #!/usr/bin/gawk -f
    2 #
    3 
    4 function p(name, val,   w) {
    5     w = ENVIRON[name];
    6     if (w == "")
    7         w = val;
    8 
    9     return (w);
   10     }
   11 
   12 function setstatus(host, port, name, status,   obj, message) {
   13     if (smd == "")
   14         return (0);
   15 
   16     if (host == ""  ||  host == "-")
   17         return (1);
   18 
   19     if (status == "OK") {
   20         status = "ok";
   21         message = "server ready";
   22         }
   23     else if (status == "CONNECT") {
   24         status = "major";
   25         message = "connection refused";
   26         }
   27     else {
   28         status = "minor";
   29         message = "unknown error";
   30         }
   31 
   32     obj = (name != "")? name: "tcp+" port+0;
   33     printf ("%s server %s %s %s\n", host, obj, status, message) | smd;
   34 
   35     return (0);
   36     }
   37 
   38 
   39 BEGIN {
   40     date = strftime("%Y%m%d", systime());
   41     LOGFILE = sprintf ("/tmp/proxy-xfer-%s.log", date);
   42 
   43 #   smd = "cat >>" LOGFILE;
   44     smd = "/usr/local/sbin/sm status";
   45 
   46     date = strftime("%d.%m.%Y %H:%M:%S", systime());
   47     status = p("PROXY_STATUS", "-");
   48     name = p("PROXY_NAME");
   49 
   50     if ((client = p("PROXY_CLIENTNAME")) == "")
   51         client = p("PROXY_CLIENT", "-");
   52 
   53     if ((server = p("PROXY_SERVERNAME")) == "")
   54         server = p("PROXY_SERVER", "-");
   55 
   56     line = sprintf ("%s %s %s %s", date, p("PROXY_LOGNAME", "-"), p("PROXY_CONFIG", "-"), p("PROXY_STATUS", "-"));
   57     if (status == "CONNECT") {
   58         n = split(ENVIRON["PROXY_SERVERARG"], x, /[ ,]+/);
   59         if (n == 0)
   60             printf ("%s %s -- no server argument\n", date, status) >>LOGFILE;
   61         else {
   62             for (i=1; i<=n; i++) {
   63                 server = x[i];
   64                 if (match(x[i], /:/) == 0)
   65                     x[i] = x[i] ":" (port = p("PROXY_PORT", 0));
   66                 else
   67                     port = substr(x[i], RSTART) + 0;
   68 
   69                 printf ("%s %s\n", line, x[i]) >>LOGFILE;
   70                 setstatus(server, port, name, "CONNECT");
   71                 }
   72             }
   73         }
   74 
   75     if (status != "ACCESS"  &&  status != "CONNECT") {
   76         printf ("%s %s %s:%d %d %d %d\n", line,
   77             client,
   78             server, (port = p("PROXY_SERVERPORT", 0)),
   79             p("PROXY_BYTES_CTS"), p("PROXY_BYTES_STC"),
   80             p("PROXY_DURATION")) >>LOGFILE;
   81 
   82         if (status == "OK")
   83             setstatus(server, port, name, "OK");
   84         }
   85 
   86     exit (0);
   87     }
   88