[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: BillMax questions -- CPanel integration



I guess I will start this.. Billmax needs more goodies to promote its 
widespread use :)
Here is a C program I wrote that runs on the remote server that allows you 
to make changes to /etc/raddb/users file
you might be able to modify it to work with your application

// Billmax Radius provisioning routine
//
// This program was written for the people who use the flat text based
// radius file located at /etc/raddb/user
//
// This File Copyright Under The GNU Public License
// To ALTAZIP INC - improvements greatly appreciated to kent@altazip.com
// This program is specific to Hotspot and MAC address authentication
// where the password is blank. worst case scenario the password
// is a universal type which could be specified and used with
// the sister verstion of this program Bx_DSLhook which does
// allow username and passwords to be added to the radius file as well
// as other attributes for the Terminal server
//
// usage
// /Bx_Macauth -a (action) -p (userpass) -i (ipaddress) -c (speed) 
(username)
// the logic it follows is simple. and will require a few changes to your
// services_hook file in your billmax server. on the disable line of your 
hook
// when calling this program change the Susp- to a simple @ symbol. this
// program looks for the @ symbol and on that premise determines if the 
passwor
// should be written, at that point the users mac address will fail to
// authenticate and optionally be firewalled/mangle rules to
// the page showing the reason for their account being turned off.
// or a page where they may place their cc number and payment options to 
allow
// them to get back online.
// Also the standard "username" paramater in billmax is switched for your
// $ENV{NEW_d0x) database paramater which holds your customers Mac address
//
#include <stdio.h>
//
// Create variable arrays
//
char user[100];
char pass[100];
char ip[100];
char mac[100];
char spd[100];
char act[100];
char anum[100];
char lnam[100];
FILE *fr, *fw;
char filename[100];
int passa;
main(int argc,char *argv[])
{
int i;
int found;


  *lnam=*user=*act=*anum=*pass=*ip=*spd=*mac=0;
  passa=1;
  for(i=1;i<argc-1;i++)
    {
    if (strcmp(argv[i],"-a")==0) strcpy(act ,argv[i+1]);
    if (strcmp(argv[i],"-p")==0) strcpy(pass,argv[i+1]);
    if (strcmp(argv[i],"-n")==0) strcpy(anum ,argv[i+1]);
    if (strcmp(argv[i],"-i")==0) strcpy(ip ,argv[i+1]);
    if (strcmp(argv[i],"-m")==0) strcpy(mac ,argv[i+1]);
    if (strcmp(argv[i],"-c")==0) strcpy(spd ,argv[i+1]);
    if (strcmp(argv[i],"-u")==0) strcpy(lnam ,argv[i+1]);
    }
  if (argc>1)
  strcpy(user,argv[argc-1]);
//
// Add User to File
//
  if (strcmp(act,"add")==0)
    {
    found = finduser(user);
    if (found)
      {
      printf("Already a User\n");
      }
//
//  This determines if there is both IP and Data Rate to add the trailing
//  comma on the end of the first attribute line so Radius doesnt puke
//
      else
      if (*ip&&*spd)
      {
      fprintf(fw, "%s Password = \"\"\n", user);
      fprintf(fw, "   Framed-IP-Address = %s,\n",ip);
      fprintf(fw, "   Ascend-Data-Rate = %s\n",spd);
      fprintf(fw, "# Account %s %s\n", anum, lnam);
      }
//
//  This asks if there is IP and no speed setting, write the IP attribute
//
      else
      if (*ip&&!*spd)
      {
      fprintf(fw, "%s Password = \"\"\n", user);
      fprintf(fw, "   Framed-IP-Address = %s\n",ip);
      fprintf(fw, "# Account %s %s\n", anum, lnam);
      }
//
// Same rule as above but do the speed in case their is no IP passed
//
      else
      if (!*ip&&*spd)
      {
      fprintf(fw, "%s Password = \"\"\n", user);
      fprintf(fw, "   Ascend-Data-Rate = %s\n",spd);
      fprintf(fw, "# Account %s %s\n", anum, lnam);
      }
//
//   Catch all for what is left over
//
      else
      {
      fprintf(fw, "%s Password = \"\"\n", user);
      fprintf(fw, "# Account %s %s\n", anum, lnam);
      }
      writeend();
      exit(0);
      }
//
// Modify file data
//
  if (strcmp(act,"modify")==0)
    {
    found = finduser(user);
    if (found)
//    {
     if (*pass=='~'&&(*ip&&*spd))
    {
//
//  This determines if there is both IP and Data Rate to add the trailing
//  comma on the end of the first attribute line so Radius doesnt puke
//
      strcpy(pass,"OFFLINE");
      fprintf(fw, "%s Password = \"%s\"\n", user, pass);
      fprintf(fw, "   Framed-IP-Address = %s,\n",ip); // first attribute 
line
      fprintf(fw, "   Ascend-Data-Rate = %s\n",spd);  // second attribute
      fprintf(fw, "# Account %s %s\n", anum, lnam);
      fprintf(fw, "# Account %s %s\n", anum, lnam);
      }
//
//  This asks if there is IP and no speed setting, write the IP attribute
//
//
     else
     if (*pass=='~' && *ip&&!*spd)
      {
      strcpy(pass,"OFFLINE");

      fprintf(fw, "%s Password = \"%s\"\n", user, pass);
      fprintf(fw, "   Framed-IP-Address = %s\n",ip);
      fprintf(fw, "# Account %s %s\n", anum, lnam);
      }
//
// Same rule as above but do the speed in case their is no IP passed
//
     else
     if (*pass=='~' && !*ip&&*spd)
      {
      strcpy(pass,"OFFLINE");
      fprintf(fw, "%s Password = \"%s\"\n", user, pass);
      fprintf(fw, "   Ascend-Data-Rate = %s\n",spd);
      fprintf(fw, "# Account %s %s\n", anum, lnam);
      }
//
//   Begin Simple Mac Address Changes Section
//
     else
   {
     if (*pass&&*ip&&*spd)     /* A lot like Adding A user */
     {
//
//  This determines if there is both IP and Data Rate to add the trailing
//  comma on the end of the first attribute line so Radius doesnt puke crash
//  and burn down
//
      fprintf(fw, "%s Password = \"\"\n", user);
      fprintf(fw, "   Framed-IP-Address = %s,\n",ip);
      fprintf(fw, "   Ascend-Data-Rate = %s\n",spd);
      fprintf(fw, "# Account %s %s\n", anum, lnam);
      }
//
//  This asks if there is IP and no speed setting, write the IP attribute
//
     else
     if (*ip&&!*spd)
      {
      fprintf(fw, "%s Password = \"\"\n", user);
      fprintf(fw, "   Framed-IP-Address = %s\n",ip);
      fprintf(fw, "# Account %s %s\n", anum, lnam);
      }
//
// Same rule as above but do the speed in case their is no IP passed
//
     else
     if (!*ip&&*spd)
      {
      fprintf(fw, "%s Password = \"\"\n", user);
      fprintf(fw, "   Ascend-Data-Rate = %s\n",spd);
      fprintf(fw, "# Account %s %s\n", anum, lnam);
      }
     else
     if (*user)
      {
      fprintf(fw, "%s Password = \"\"\n", user);
      fprintf(fw, "# Account %s %s\n", anum, lnam);
      }
    } else
      {
      printf("User not found\n");
      }
    writeend();
    exit(0);
    }
//
// This Section Removes User Data from Radius File
//
//
  if (strcmp(act,"delete")==0)
    {
    found = finduser(user);
    if (!found) printf("User not found\n");

    writeend();
    exit(0);
    }

  printf("Syntax: ./Bx_Macauth -a -p -n -i -c -m -u  username\n");
  printf(" -a add or modify or delete\n");
  printf(" -p password\n");
  printf(" -n account number\n");
  printf(" -i IP address\n");
  printf(" -c Speed Setting in Kbs\n");
  printf(" -m Mac Address\n");
  printf(" -u account last name\n");
  exit(1);
  return;
}



int finduser(char *user1)
{
int found;
long fp;
int write;
char txt[110];
char user2[100];

#ifdef unix
  strcpy(filename, "/etc/raddb/users");
#else
  strcpy(filename, "users.txt");
#endif

  write = 1;
  found = 0;
  fr = fopen(filename,"r+");
  if (!fr)
    {
    printf("%s file not found\n", filename);
    exit(0);
    }

  fw = fopen("temp.txt","w+");
  while(1)
    {
    fp = ftell(fr);

    fgets(txt, 100, fr);
    if (feof(fr))
      {
      fseek(fr, fp, 0);
      break;
      }


    if (strstr(txt, " Password = "))    /* new user line */
      {
      sscanf(txt, "%s", user2);
      if (strcmp(user1, user2)==0)      /* found user */
        {
        found = 1;
        if (strcmp(act,"add")!=0) write = 0;
        }
      if (strcmp(user1, user2)<0)       /* past user */
        {
        fseek(fr, fp, 0);
        break;
        }
      }
    if (write) fprintf(fw, txt);
    }
  return(found);
}


int writeend()
{
char txt[110];

  while(1)
    {
    fgets(txt, 100, fr);if (feof(fr)) break;
    fprintf(fw, txt);
    }
  fclose(fr);
  fclose(fw);
  unlink(filename);
  rename("temp.txt", filename);
  return;
}




----- Original Message ----- 
From: "Chris Snyder" <casnyder@pennswoods.net>
To: <questions@billmax.com>
Sent: Thursday, September 20, 2007 12:58 PM
Subject: RE: BillMax questions -- CPanel integration


> I'd love to share some advice/tips/code samples on integrating billmax
> with cpanel.  Unfortunately it seems rare for anyone to want information
> on any of the customizations I have been involved in.
>
> Truthfully, the crew at Billmax.com have been exceptionally helpful, and
> if you've got the cash, you won't go wrong buying some support directly
> from them.
>
> Do yourself a favor and run a command like:
> ls /PATH/TO/BILLMAX/local/*hook
>
> And investigate the files you see there.  Remember that the billmax
> library is not re-entrant, so occasionally the solution to a problem is
> to simply log certain bits, and then act on them later outside of the
> hook file (cron perhaps?).
>
> I seem to have: runhook, account_hook, bmuid_createcust_hook,
> payhist_hook, service_hook, tax_hook.  Adding code to some of these
> (payhist_hook) will slow down the processing though.  We seem to only
> notice if I am trying to batch import a large number of new customers.
>
> In fact, there are a whole bunch of fun things to play with in that
> directory, provided you have a reasonable tolerance to self-inflicted
> baldness.  The LoopBack.ccpost.conf and related default cc processing
> was interesting to look at.
>
> You can also do interesting things with replacing the lpr and sendmail
> in billmax's config interface with scripts.  I manage to store
> statements (postal and email both) in a database so that our techs can
> tell the customer when their last bill was sent, for how much, etc.
> Don't forget to actually forward it to the printer / MTS after you store
> it.
>
> A quick google search indicates that there is a (3rd party?) cPanel api.
> I also found this:
> http://mail.cpanel.net/mailman/listinfo/api_cpanel.net
>
> It wouldn't surprise me at all if there was (relatively simple) a way to
> tie calls to the cPanel api into the service_hook to
> create/enable/disable access to the cPanel based on
> creation/payment/suspension in billmax.
>
> In cases where the local billmax machine needs to control a remote
> machine, I find the perl's LWP module works nicely to operate http(s)
> calls.  If you don't control the wire, you likely want to make sure that
> the machine being called out to runs an ssl-enabled web server (https),
> and you probably want to use some sort of user/pass and restrict by ip
> as well.  Alternatively you might prefer ssh-keyed bash scripts.
>
> Just for the record, I am not looking for, and do not accept,
> consultation / contract work.  Contact billmax.com if you feel the need
> for that.  The number of such requests I get after posting to this list
> may be part of the reason why people are not quicker to offer assistance
> on this list, Ted.
>
> Chris
>
> On Wed, 2007-09-19 at 20:18 -0700, Ted Mittelstaedt wrote:
>> Most of the advanced customizations that have been done with
>> Billmax have not been made publically available.  The ones
>> that have been done by the company aren't available for obvious
>> reasons - Billmax makes money customizing them, so to get them
>> you have to contact them and get on a support agreement.  This
>> is all in agreement with the principles of open source software
>> (Billmax was after all developed on an open source operating
>> system, and uses mysql, and OSS database program) which states
>> that developers of OSS projects can make a moral living customizing
>> their packages for people.
>>
>>   But, I am always mystified why posters on the public mailing
>> list here do not post details of their own customizations.  It
>> sure isn't in accord with most of the principles of open source
>> software.
>>
>>   Good luck in your quest.  I don't think you will get much
>> help from the community on this mailing list, however, based on
>> past experience.  I certainly don't use cpanel and
>> so cannot help you.
>>
>> Ted Mittelstaedt
>> Internet Partners Inc.
>>
>> >-----Original Message-----
>> >From: owner-questions@billmax.com [mailto:owner-questions@billmax.com]On
>> >Behalf Of Craig Thompson
>> >Sent: Wednesday, September 19, 2007 3:38 PM
>> >To: questions@billmax.com
>> >Subject: BillMax questions -- CPanel integration
>> >
>> >
>> >I'm interested in using Billmax with CPanel to add/suspend/remove
>> >accounts, plans, etc.  The website says that this has been done.
>> >
>> >Does anyone have any hooks / scripts / documentation on this?  I
>> >couldn't find anything in the archives.
>> >
>> >Any help at all would be appreciated.
>> >
>> >Thanks!
>> >
>> >CT
>> >-------------------------------------------------------------------
>> >----------
>> >To unsubscribe from the "BillMax Questions" mailing list, please
>> >send a message to "majordomo@billmax.com" with "unsubscribe questions"
>> >in the message body. The message must be sent from the exact email
>> >address on the list.
>> >
>> -----------------------------------------------------------------------------
>> To unsubscribe from the "BillMax Questions" mailing list, please
>> send a message to "majordomo@billmax.com" with "unsubscribe questions"
>> in the message body. The message must be sent from the exact email
>> address on the list.
>
> -----------------------------------------------------------------------------
> To unsubscribe from the "BillMax Questions" mailing list, please
> send a message to "majordomo@billmax.com" with "unsubscribe questions"
> in the message body. The message must be sent from the exact email
> address on the list.
> 

-----------------------------------------------------------------------------
To unsubscribe from the "BillMax Questions" mailing list, please
send a message to "majordomo@billmax.com" with "unsubscribe questions"
in the message body. The message must be sent from the exact email
address on the list.