bandwidth charges from sqlradius
[freeside.git] / httemplate / view / svc_acct.cgi
1 <!-- mason kludge -->
2 <%
3
4 my $conf = new FS::Conf;
5 my $mydomain = $conf->config('domain');
6
7 my($query) = $cgi->keywords;
8 $query =~ /^(\d+)$/;
9 my $svcnum = $1;
10 my $svc_acct = qsearchs('svc_acct',{'svcnum'=>$svcnum});
11 die "Unknown svcnum" unless $svc_acct;
12
13 #false laziness w/all svc_*.cgi
14 my $cust_svc = qsearchs( 'cust_svc' , { 'svcnum' => $svcnum } );
15 my $pkgnum = $cust_svc->getfield('pkgnum');
16 my($cust_pkg, $custnum);
17 if ($pkgnum) {
18   $cust_pkg = qsearchs( 'cust_pkg', { 'pkgnum' => $pkgnum } );
19   $custnum = $cust_pkg->custnum;
20 } else {
21   $cust_pkg = '';
22   $custnum = '';
23 }
24 #eofalse
25
26 my $part_svc = qsearchs('part_svc',{'svcpart'=> $cust_svc->svcpart } );
27 die "Unknown svcpart" unless $part_svc;
28
29 my $domain;
30 if ( $svc_acct->domsvc ) {
31   my $svc_domain = qsearchs('svc_domain', { 'svcnum' => $svc_acct->domsvc } );
32   die "Unknown domain" unless $svc_domain;
33   $domain = $svc_domain->domain;
34 } else {
35   unless ( $mydomain ) {
36     die "No legacy domain config file and no svc_domain.svcnum record ".
37         "for svc_acct.domsvc: ". $cust_svc->domsvc;
38   }
39   $domain = $mydomain;
40 }
41
42 %>
43
44 <SCRIPT>
45 function areyousure(href) {
46     if (confirm("Permanently delete this account?") == true)
47         window.location.href = href;
48 }
49 </SCRIPT>
50
51 <%= header('Account View', menubar(
52   ( ( $pkgnum || $custnum )
53     ? ( "View this package (#$pkgnum)" => "${p}view/cust_pkg.cgi?$pkgnum",
54         "View this customer (#$custnum)" => "${p}view/cust_main.cgi?$custnum",
55       )
56     : ( "Cancel this (unaudited) account" =>
57           "javascript:areyousure(\'${p}misc/cancel-unaudited.cgi?$svcnum\')" )
58   ),
59   "Main menu" => $p,
60 )) %>
61
62 <%
63
64 #if ( $cust_pkg && $cust_pkg->part_pkg->plan eq 'sqlradacct_hour' ) {
65 if ( $part_svc->part_export('sqlradius') ) {
66
67   my $last_bill;
68   my %plandata;
69   if ( $cust_pkg ) {
70     #false laziness w/httemplate/edit/part_pkg... this stuff doesn't really
71     #belong in plan data
72     %plandata = map { /^(\w+)=(.*)$/; ( $1 => $2 ); }
73                     split("\n", $cust_pkg->part_pkg->plandata );
74
75     $last_bill = $cust_pkg->last_bill;
76   } else {
77     $last_bill = 0;
78     %plandata = ();
79   }
80
81   my $seconds = $svc_acct->seconds_since_sqlradacct( $last_bill, time );
82   my $h = int($seconds/3600);
83   my $m = int( ($seconds%3600) / 60 );
84   my $s = $seconds%60;
85
86   my $input = $svc_acct->attribute_since_sqlradacct(
87     $last_bill, time, 'Acct-Input-Octets'
88   ) / 1048576;
89   my $output = $svc_acct->attribute_since_sqlradacct(
90     $last_bill, time, 'Acct-Output-Octets'
91   ) / 1048576;
92
93   if ( $seconds ) {
94     print "Online <B>$h</B>h <B>$m</B>m <B>$s</B>s";
95   } else {
96     print 'Has not logged on';
97   }
98
99   if ( $cust_pkg ) {
100     print ' this billing cycle (since '. time2str("%C", $last_bill). ') - '. 
101           $plandata{recur_included_hours}. ' total hours in plan<BR>';
102   } else {
103     print ' (no billing cycle available for unaudited account)<BR>';
104   }
105
106   print 'Input: <B>'. sprintf("%.3f", $input). ' megabytes<BR>';
107   print 'Output: <B>'. sprintf("%.3f", $output). ' megabytes<BR>';
108
109   print '<BR>';
110
111 }
112
113 #print qq!<BR><A HREF="../misc/sendconfig.cgi?$svcnum">Send account information</A>!;
114
115 print qq!<A HREF="${p}edit/svc_acct.cgi?$svcnum">Edit this information</A><BR>!.
116       &ntable("#cccccc"). '<TR><TD>'. &ntable("#cccccc",2).
117       "<TR><TD ALIGN=\"right\">Service number</TD>".
118         "<TD BGCOLOR=\"#ffffff\">$svcnum</TD></TR>".
119       "<TR><TD ALIGN=\"right\">Service</TD>".
120         "<TD BGCOLOR=\"#ffffff\">". $part_svc->svc. "</TD></TR>".
121       "<TR><TD ALIGN=\"right\">Username</TD>".
122         "<TD BGCOLOR=\"#ffffff\">". $svc_acct->username. "</TD></TR>"
123 ;
124
125 print "<TR><TD ALIGN=\"right\">Domain</TD>".
126         "<TD BGCOLOR=\"#ffffff\">". $domain, "</TD></TR>";
127
128 print "<TR><TD ALIGN=\"right\">Password</TD><TD BGCOLOR=\"#ffffff\">";
129 my $password = $svc_acct->_password;
130 if ( $password =~ /^\*\w+\* (.*)$/ ) {
131   $password = $1;
132   print "<I>(login disabled)</I> ";
133 }
134 if ( $conf->exists('showpasswords') ) {
135   print '<PRE>'. encode_entities($password). '</PRE>';
136 } else {
137   print "<I>(hidden)</I>";
138 }
139 print "</TR></TD>";
140 $password = '';
141
142 if ( $conf->exists('security_phrase') ) {
143   my $sec_phrase = $svc_acct->sec_phrase;
144   print '<TR><TD ALIGN="right">Security phrase</TD><TD BGCOLOR="#ffffff">'.
145         $svc_acct->sec_phrase. '</TD></TR>';
146 }
147
148 my $svc_acct_pop = qsearchs('svc_acct_pop',{'popnum'=>$svc_acct->popnum});
149 print "<TR><TD ALIGN=\"right\">Access number</TD>".
150       "<TD BGCOLOR=\"#ffffff\">". $svc_acct_pop->text. '</TD></TR>'
151   if $svc_acct_pop;
152
153 if ($svc_acct->uid ne '') {
154   print "<TR><TD ALIGN=\"right\">Uid</TD>".
155           "<TD BGCOLOR=\"#ffffff\">". $svc_acct->uid. "</TD></TR>",
156         "<TR><TD ALIGN=\"right\">Gid</TD>".
157           "<TD BGCOLOR=\"#ffffff\">". $svc_acct->gid. "</TD></TR>",
158         "<TR><TD ALIGN=\"right\">GECOS</TD>".
159           "<TD BGCOLOR=\"#ffffff\">". $svc_acct->finger. "</TD></TR>",
160         "<TR><TD ALIGN=\"right\">Home directory</TD>".
161           "<TD BGCOLOR=\"#ffffff\">". $svc_acct->dir. "</TD></TR>",
162         "<TR><TD ALIGN=\"right\">Shell</TD>".
163           "<TD BGCOLOR=\"#ffffff\">". $svc_acct->shell. "</TD></TR>",
164         "<TR><TD ALIGN=\"right\">Quota</TD>".
165           "<TD BGCOLOR=\"#ffffff\">". $svc_acct->quota. "</TD></TR>"
166   ;
167 } else {
168   print "<TR><TH COLSPAN=2>(No shell account)</TH></TR>";
169 }
170
171 if ($svc_acct->slipip) {
172   print "<TR><TD ALIGN=\"right\">IP address</TD><TD BGCOLOR=\"#ffffff\">".
173         ( ( $svc_acct->slipip eq "0.0.0.0" || $svc_acct->slipip eq '0e0' )
174           ? "<I>(Dynamic)</I>"
175           : $svc_acct->slipip
176         ). "</TD>";
177   my($attribute);
178   foreach $attribute ( grep /^radius_/, fields('svc_acct') ) {
179     #warn $attribute;
180     $attribute =~ /^radius_(.*)$/;
181     my $pattribute = $FS::raddb::attrib{$1};
182     print "<TR><TD ALIGN=\"right\">Radius (reply) $pattribute</TD>".
183           "<TD BGCOLOR=\"#ffffff\">". $svc_acct->getfield($attribute).
184           "</TD></TR>";
185   }
186   foreach $attribute ( grep /^rc_/, fields('svc_acct') ) {
187     #warn $attribute;
188     $attribute =~ /^rc_(.*)$/;
189     my $pattribute = $FS::raddb::attrib{$1};
190     print "<TR><TD ALIGN=\"right\">Radius (check) $pattribute: </TD>".
191           "<TD BGCOLOR=\"#ffffff\">". $svc_acct->getfield($attribute).
192           "</TD></TR>";
193   }
194 } else {
195   print "<TR><TH COLSPAN=2>(No SLIP/PPP account)</TH></TR>";
196 }
197
198 print '<TR><TD ALIGN="right">RADIUS groups</TD><TD BGCOLOR="#ffffff">'.
199       join('<BR>', $svc_acct->radius_groups). '</TD></TR>';
200
201 print '</TABLE></TD></TR></TABLE><BR><BR>';
202
203 print join("\n", $conf->config('svc_acct-notes') ). '<BR><BR>'.
204       joblisting({'svcnum'=>$svcnum}, 1). '</BODY></HTML>';
205
206 %>