rework edit/part_svc.cgi so it doesn't use a separate process/ file, this allows...
[freeside.git] / fs_sesmon / FS-SessionClient / SessionClient.pm
1 package FS::SessionClient;
2
3 use strict;
4 use vars qw($AUTOLOAD $VERSION @ISA @EXPORT_OK $fs_sessiond_socket);
5 use Exporter;
6 use Socket;
7 use FileHandle;
8 use IO::Handle;
9
10 $VERSION = '0.01';
11
12 @ISA = qw( Exporter );
13 @EXPORT_OK = qw( login logout portnum );
14
15 $fs_sessiond_socket = "/usr/local/freeside/fs_sessiond_socket";
16
17 $ENV{'PATH'} ='/usr/bin:/bin';
18 $ENV{'SHELL'} = '/bin/sh';
19 $ENV{'IFS'} = " \t\n";
20 $ENV{'CDPATH'} = '';
21 $ENV{'ENV'} = '';
22 $ENV{'BASH_ENV'} = '';
23
24 my $freeside_uid = scalar(getpwnam('freeside'));
25 die "not running as the freeside user\n" if $> != $freeside_uid;
26
27 =head1 NAME
28
29 FS::SessionClient - Freeside session client API
30
31 =head1 SYNOPSIS
32
33   use FS::SessionClient qw( login portnum logout );
34
35   $error = login ( {
36     'username' => $username,
37     'password' => $password,
38     'login'    => $timestamp,
39     'portnum'  => $portnum,
40   } );
41
42   $portnum = portnum( { 'ip' => $ip } ) or die "unknown ip!"
43   $portnum = portnum( { 'nasnum' => $nasnum, 'nasport' => $nasport } )
44     or die "unknown nasnum/nasport";
45
46   $error = logout ( {
47     'username' => $username,
48     'password' => $password,
49     'logout'   => $timestamp,
50     'portnum'  => $portnum,
51   } );
52
53 =head1 DESCRIPTION
54
55 This modules provides an API for a remote session application.
56
57 It needs to be run as the freeside user.  Because of this, the program which
58 calls these subroutines should be written very carefully.
59
60 =head1 SUBROUTINES
61
62 =over 4
63
64 =item login HASHREF
65
66 HASHREF should have the following keys: username, password, login and portnum.
67 login is a UNIX timestamp; if not specified, will default to the current time.
68 Starts a new session for the specified user and portnum.  The password is
69 optional, but must be correct if specified.
70
71 Returns a scalar error message, or the empty string for success.
72
73 =item portnum
74
75 HASHREF should contain a single key: ip, or the two keys: nasnum and nasport.
76 Returns a portnum suitable for the login and logout subroutines, or false
77 on error.
78
79 =item logout HASHREF
80
81 HASHREF should have the following keys: usrename, password, logout and portnum.
82 logout is a UNIX timestamp; if not specified, will default to the current time.
83 Starts a new session for the specified user and portnum.  The password is
84 optional, but must be correct if specified.
85
86 Returns a scalar error message, or the empty string for success.
87
88 =cut
89
90 sub AUTOLOAD {
91   my $hashref = shift;
92   my $method = $AUTOLOAD;
93   $method =~ s/^.*:://;
94   socket(SOCK, PF_UNIX, SOCK_STREAM, 0) or die "socket: $!";
95   connect(SOCK, sockaddr_un($fs_sessiond_socket)) or die "connect: $!";
96   print SOCK "$method\n";
97
98   print SOCK join("\n", %{$hashref}, 'END' ), "\n";
99   SOCK->flush;
100
101   chomp( my $r = <SOCK> );
102   $r;
103 }
104
105 =back
106
107 =head1 VERSION
108
109 $Id: SessionClient.pm,v 1.3 2000-12-03 20:25:20 ivan Exp $
110
111 =head1 BUGS
112
113 =head1 SEE ALSO
114
115 L<fs_sessiond>
116
117 =cut
118
119 1;
120
121
122