change configuration file layout to support multiple distinct databases (with
[freeside.git] / htdocs / view / svc_acct.cgi
1 #!/usr/bin/perl -Tw
2 #
3 # View svc_acct records
4 #
5 # Usage: svc_acct.cgi svcnum
6 #        http://server.name/path/svc_acct.cgi?svcnum
7 #
8 # Note: Should be run setuid freeside as user nobody.
9 #
10 # ivan@voicenet.com 96-dec-17
11 #
12 # added link to send info
13 # ivan@voicenet.com 97-jan-4
14 #
15 # added navigation bar and ability to change username, etc.
16 # ivan@voicenet.com 97-jan-30
17 #
18 # activate 800 service
19 # ivan@voicenet.com 97-feb-10
20 #
21 # modified navbar code (should be a subroutine?), added link to cancel account (only if not audited)
22 # ivan@voicenet.com 97-apr-16
23 #
24 # INCOMPLETELY rewrote some things for new API
25 # ivan@voicenet.com 97-jul-29
26 #
27 # FS::Search became FS::Record, use strict, etc. ivan@sisd.com 98-mar-9
28 #
29 # Changes to allow page to work at a relative position in server
30 # Changed 'password' to '_password' because Pg6.3 reserves the password word
31 #       bmccane@maxbaud.net     98-apr-3
32 #
33 # /var/spool/freeside/conf/domain ivan@sisd.com 98-jul-17
34 #
35 # displays arbitrary radius attributes ivan@sisd.com 98-aug-16
36
37 use strict;
38 use CGI::Base qw(:DEFAULT :CGI);
39 use CGI::Carp qw(fatalsToBrowser);
40 use FS::UID qw(cgisuidsetup);
41 use FS::Record qw(qsearchs fields);
42
43 my($conf_domain)="/var/spool/freeside/conf/domain";
44 open(DOMAIN,$conf_domain) or die "Can't open $conf_domain: $!";
45 my($mydomain)=map {
46   /^(.*)$/ or die "Illegal line in $conf_domain!"; #yes, we trust the file
47   $1;
48 } grep $_ !~ /^(#|$)/, <DOMAIN>;
49
50 my($cgi) = new CGI::Base;
51 $cgi->get;
52 &cgisuidsetup($cgi);
53
54 #untaint svcnum
55 $QUERY_STRING =~ /^(\d+)$/;
56 my($svcnum)=$1;
57 my($svc_acct)=qsearchs('svc_acct',{'svcnum'=>$svcnum});
58 die "Unkonwn svcnum" unless $svc_acct;
59
60 my($cust_svc)=qsearchs('cust_svc',{'svcnum'=>$svcnum});
61 my($pkgnum)=$cust_svc->getfield('pkgnum');
62 my($cust_pkg,$custnum);
63 if ($pkgnum) {
64   $cust_pkg=qsearchs('cust_pkg',{'pkgnum'=>$pkgnum});
65   $custnum=$cust_pkg->getfield('custnum');
66 }
67
68 my($part_svc)=qsearchs('part_svc',{'svcpart'=> $cust_svc->svcpart } );
69 die "Unkonwn svcpart" unless $part_svc;
70
71 SendHeaders(); # one guess.
72 print <<END;
73 <HTML>
74   <HEAD>
75     <TITLE>Account View</TITLE>
76   </HEAD>
77   <BODY>
78     <CENTER><H1>Account View</H1>
79     <BASEFONT SIZE=3>
80 <CENTER>
81 END
82
83 if ($pkgnum || $custnum) {
84   print <<END;
85 <A HREF="../view/cust_pkg.cgi?$pkgnum">View this package (#$pkgnum)</A> | 
86 <A HREF="../view/cust_main.cgi?$custnum">View this customer (#$custnum)</A> | 
87 END
88 } else {
89   print <<END;
90 <A HREF="../misc/cancel-unaudited.cgi?$svcnum">Cancel this (unaudited)account</A> |
91 END
92 }
93
94 print <<END;
95 <A HREF="../">Main menu</A></CENTER><BR>
96 <FONT SIZE=+1>Service #$svcnum</FONT>
97 END
98
99 print qq!<BR><A HREF="../edit/svc_acct.cgi?$svcnum">Edit this information</A>!;
100 #print qq!<BR><A HREF="../misc/sendconfig.cgi?$svcnum">Send account information</A>!;
101 print qq!<BR><BR><A HREF="#general">General</A> | <A HREF="#shell">Shell account</A> | !;
102 print qq!<A HREF="#slip">SLIP/PPP account</A></CENTER>!;
103
104 #formatting
105 print qq!<HR><CENTER><FONT SIZE=+1><A NAME="general">General</A></FONT></CENTER>!;
106
107 #svc
108 print "Service: <B>", $part_svc->svc, "</B>";
109
110 #username
111 print "<BR>Username: <B>", $svc_acct->username, "</B>";
112
113 #password
114 if (substr($svc_acct->_password,0,1) eq "*") {
115   print "<BR>Password: <I>(Login disabled)</I><BR>";
116 } else {
117   print "<BR>Password: <I>(hidden)</I><BR>";
118 }
119
120 # popnum -> svc_acct_pop record
121 my($svc_acct_pop)=qsearchs('svc_acct_pop',{'popnum'=>$svc_acct->popnum});
122
123 #pop
124 print "POP: <B>", $svc_acct_pop->city, ", ", $svc_acct_pop->state,
125       " (", $svc_acct_pop->ac, ")/", $svc_acct_pop->exch, "<\B>"
126   if $svc_acct_pop;
127
128 #shell account
129 print qq!<HR><CENTER><FONT SIZE=+1><A NAME="shell">!;
130 if ($svc_acct->uid ne '') {
131   print "Shell account";
132   print "</A></FONT></CENTER>";
133   print "Uid: <B>", $svc_acct->uid, "</B>";
134   print "<BR>Gid: <B>", $svc_acct->gid, "</B>";
135
136   print qq!<BR>Finger name: <B>!, $svc_acct->finger, qq!</B><BR>!;
137
138   print "Home directory: <B>", $svc_acct->dir, "</B><BR>";
139
140   print "Shell: <B>", $svc_acct->shell, "</B><BR>";
141
142   print "Quota: <B>", $svc_acct->quota, "</B> <I>(unimplemented)</I>";
143 } else {
144   print "No shell account.</A></FONT></CENTER>";
145 }
146
147 # SLIP/PPP
148 print qq!<HR><CENTER><FONT SIZE=+1><A NAME="slip">!;
149 if ($svc_acct->slipip) {
150   print "SLIP/PPP account</A></FONT></CENTER>";
151   print "IP address: <B>", ( $svc_acct->slipip eq "0.0.0.0" || $svc_acct->slipip eq '0e0' ) ? "<I>(Dynamic)</I>" : $svc_acct->slipip ,"</B>";
152   my($attribute);
153   foreach $attribute ( grep /^radius_/, fields('svc_acct') ) {
154     #warn $attribute;
155     $attribute =~ /^radius_(.*)$/;
156     my($pattribute) = ($1);
157     $pattribute =~ s/_/-/g;
158     print "<BR>Radius $pattribute: <B>". $svc_acct->getfield($attribute), "</B>";
159   }
160 } else {
161   print "No SLIP/PPP account</A></FONT></CENTER>"
162 }
163
164 print "<HR>";
165
166         #formatting
167         print <<END;
168
169   </BODY>
170 </HTML>
171 END
172