---- Original Message -----
From: "Rafael R.Sevilla" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, December 09, 2002 1:32 PM
Subject: Re: [plug] internet metering


> Depends on how your Internet connections are made.  If you have a
> campus-wide Ethernet, you can use PPPoe to get them to connect to the
> Internet, and then use a RADIUS system similar to the way a dialup ISP
> would generate billing statements.
>

makikisingit lang since I am a PPPOE fan.  Here's what I did to make it
work:

1) download the PPP source (i used ppp-2.4.1)
2) do the usual ./configure, make, make install
3) since you just recompiled your PPPD daemon, make sure PPPD is still
working before you proceed to the next steps
4) write a plugin to intercept the login procedure and the connection time
procedure (see the end of this message for the exact source code)
5) compile the plugin as a shared object (.so)
6) add the following entry to your "/etc/ppp/options" file:  "plugin
/mypath/akin_hook.so"

Thats it, no need for RADIUS or any other packages.  Nice and clean and
works with PPPOE or dialup connections (source code provided below).  HTH.

From,
Carlos Yu
CYWare Inc.


Sample Code

/*
 * akin_hook.c - pppd plugin to enable customized tracking
*                        binary version is compiled as akin_hook.so
 *
 *
 * Redistribution and use in source and binary forms are permitted
 * provided that the above copyright notice and this paragraph are
 * duplicated in all such forms.  The name of the author
 * may not be used to endorse or promote products derived
 * from this software without specific prior written permission.
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 */

#include <stddef.h>
#include <time.h>
#include "pppd.h"

char pppd_version[] = VERSION;

static int hook_ko = 0;

static option_t my_options[] = {
 { "hook_ko", o_int, &hook_ko,
   "Enable prepaid features" },
 { NULL }
};

/*******************************************************************
   FUNCTION:            subok_passwd
   DESCRIPTION:         Validates username/password and assigns
                        an IP address
 *******************************************************************/

static int              subok_passwd (char *user,
                                      char *passwd,
                 char **msgp,
          struct wordlist **paddrs,
          struct wordlist **popts)
{
    /********************************************
       Replace this code with your own to
       retrieve the password from any source.
       For example:  a database or even just a
                     flat text file
       In this example, I am hardcoding for
       illustration purposes only
     ********************************************/

    struct wordlist*    pWordList;    /*  Holds the IP address  */

    char                szIp [] = "*",
                        szUser [] = "loginko",
                        szPasswd [] = "passwdko";


    /*********************************************
       Compare the user/passwd passed
       NOTE:  the password passed is encrypted
              which is why we need to call the
              function "cryptpap" for comparison
     *********************************************/

    if (0 == strcmp (user, szUser) &&
        0 == (cryptpap || strcmp(passwd, secret))  {

        /*********************************************
           If you want to assign a specific IP addr,
           do so by changing the assigned value "*"
           for variable szIp
         *********************************************/

        pWordList = (struct wordlist*) malloc (sizeof (struct wordlist));
        pWordList->word = (char*) malloc (strlen(szIp)+1);
        strcpy (pWordList->word,szIp);
        pWordList->next = 0x00;
        *paddrs = pWordList;

        /*****************************************************
           Finally, if you want to limit the connection time
           set the global variable maxconnect to the number of
           seconds the user can connect (i.e. 180 for 3 minutes
           maximum connect time).
         *****************************************************/

        maxconnect = 180;  /*  disconnect after 3 minutes  */
        return 1;   /* success  */

    }  else  {
         /*  authentication failed  */
         warn("PAP authentication failure for %s", user);
  return 0;
    }
}


/*******************************************************************
   FUNCTION:            subok_logout
   DESCRIPTION:         Tracks the amount of time the user was
                        connected and the number of bytes used
 *******************************************************************/

static void             subok_logout ()
{
    /****************************************************
       The code saves to the logfile, however, you can
       use this to log the amount of time and the number
       of bytes the user consumed.  Normally, I save this
       info into PostgreSQL
     ****************************************************/
  if (link_stats_valid) {
     int t = (link_connect_time + 5) / 6;    /* 1/10ths of minutes */
     info("LOGOUT: Connect time %d.%d minutes.", t/10, t%10);
     info("LOGOUT: Sent %u bytes, received %u bytes.",
  link_stats.bytes_out, link_stats.bytes_in);
 }
}

/*******************************************************************
   FUNCTION:            plugin_init
   DESCRIPTION:         Assign our plugin function addresses to the
                        PPPD global function pointer variables so it can be
called
                        by the PPP daemon
 *******************************************************************/

void                    plugin_init(void)
{
 info("plugin_init");
 add_options(my_options);
 pap_auth_hook = subok_passwd;
 pap_logout_hook = subok_logout;
}





_
Philippine Linux Users Group. Web site and archives at http://plug.linux.org.ph
To leave: send "unsubscribe" in the body to [EMAIL PROTECTED]

Fully Searchable Archives With Friendly Web Interface at http://marc.free.net.ph

To subscribe to the Linux Newbies' List: send "subscribe" in the body to 
[EMAIL PROTECTED]

Reply via email to