This commit was manufactured by cvs2svn to create branch
[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      || $part_svc->part_export('sqlradius_withdomain')
67 ) {
68
69   my $last_bill;
70   my %plandata;
71   if ( $cust_pkg ) {
72     #false laziness w/httemplate/edit/part_pkg... this stuff doesn't really
73     #belong in plan data
74     %plandata = map { /^(\w+)=(.*)$/; ( $1 => $2 ); }
75                     split("\n", $cust_pkg->part_pkg->plandata );
76
77     $last_bill = $cust_pkg->last_bill;
78   } else {
79     $last_bill = 0;
80     %plandata = ();
81   }
82
83   my $seconds = $svc_acct->seconds_since_sqlradacct( $last_bill, time );
84   my $hour = int($seconds/3600);
85   my $min = int( ($seconds%3600) / 60 );
86   my $sec = $seconds%60;
87
88   my $input = $svc_acct->attribute_since_sqlradacct(
89     $last_bill, time, 'AcctInputOctets'
90   ) / 1048576;
91   my $output = $svc_acct->attribute_since_sqlradacct(
92     $last_bill, time, 'AcctOutputOctets'
93   ) / 1048576;
94
95   if ( $seconds ) {
96     print "Online <B>$hour</B>h <B>$min</B>m <B>$sec</B>s";
97   } else {
98     print 'Has not logged on';
99   }
100
101   if ( $cust_pkg ) {
102     print ' since last bill ('. time2str("%C", $last_bill). ') - '. 
103           $plandata{recur_included_hours}. ' total hours in plan<BR>';
104   } else {
105     print ' (no billing cycle available for unaudited account)<BR>';
106   }
107
108   print 'Input: <B>'. sprintf("%.3f", $input). '</B> megabytes<BR>';
109   print 'Output: <B>'. sprintf("%.3f", $output). '</B> megabytes<BR>';
110
111   print '<BR>';
112
113 }
114
115 #print qq!<BR><A HREF="../misc/sendconfig.cgi?$svcnum">Send account information</A>!;
116
117 print qq!<A HREF="${p}edit/svc_acct.cgi?$svcnum">Edit this information</A><BR>!.
118       &ntable("#cccccc"). '<TR><TD>'. &ntable("#cccccc",2).
119       "<TR><TD ALIGN=\"right\">Service number</TD>".
120         "<TD BGCOLOR=\"#ffffff\">$svcnum</TD></TR>".
121       "<TR><TD ALIGN=\"right\">Service</TD>".
122         "<TD BGCOLOR=\"#ffffff\">". $part_svc->svc. "</TD></TR>".
123       "<TR><TD ALIGN=\"right\">Username</TD>".
124         "<TD BGCOLOR=\"#ffffff\">". $svc_acct->username. "</TD></TR>"
125 ;
126
127 print "<TR><TD ALIGN=\"right\">Domain</TD>".
128         "<TD BGCOLOR=\"#ffffff\">". $domain, "</TD></TR>";
129
130 print "<TR><TD ALIGN=\"right\">Password</TD><TD BGCOLOR=\"#ffffff\">";
131 my $password = $svc_acct->_password;
132 if ( $password =~ /^\*\w+\* (.*)$/ ) {
133   $password = $1;
134   print "<I>(login disabled)</I> ";
135 }
136 if ( $conf->exists('showpasswords') ) {
137   print '<PRE>'. encode_entities($password). '</PRE>';
138 } else {
139   print "<I>(hidden)</I>";
140 }
141 print "</TR></TD>";
142 $password = '';
143
144 if ( $conf->exists('security_phrase') ) {
145   my $sec_phrase = $svc_acct->sec_phrase;
146   print '<TR><TD ALIGN="right">Security phrase</TD><TD BGCOLOR="#ffffff">'.
147         $svc_acct->sec_phrase. '</TD></TR>';
148 }
149
150 my $svc_acct_pop = $svc_acct->popnum
151                      ? qsearchs('svc_acct_pop',{'popnum'=>$svc_acct->popnum})
152                      : '';
153 print "<TR><TD ALIGN=\"right\">Access number</TD>".
154       "<TD BGCOLOR=\"#ffffff\">". $svc_acct_pop->text. '</TD></TR>'
155   if $svc_acct_pop;
156
157 if ($svc_acct->uid ne '') {
158   print "<TR><TD ALIGN=\"right\">Uid</TD>".
159           "<TD BGCOLOR=\"#ffffff\">". $svc_acct->uid. "</TD></TR>",
160         "<TR><TD ALIGN=\"right\">Gid</TD>".
161           "<TD BGCOLOR=\"#ffffff\">". $svc_acct->gid. "</TD></TR>",
162         "<TR><TD ALIGN=\"right\">GECOS</TD>".
163           "<TD BGCOLOR=\"#ffffff\">". $svc_acct->finger. "</TD></TR>",
164         "<TR><TD ALIGN=\"right\">Home directory</TD>".
165           "<TD BGCOLOR=\"#ffffff\">". $svc_acct->dir. "</TD></TR>",
166         "<TR><TD ALIGN=\"right\">Shell</TD>".
167           "<TD BGCOLOR=\"#ffffff\">". $svc_acct->shell. "</TD></TR>",
168         "<TR><TD ALIGN=\"right\">Quota</TD>".
169           "<TD BGCOLOR=\"#ffffff\">". $svc_acct->quota. "</TD></TR>"
170   ;
171 } else {
172   print "<TR><TH COLSPAN=2>(No shell account)</TH></TR>";
173 }
174
175 if ($svc_acct->slipip) {
176   print "<TR><TD ALIGN=\"right\">IP address</TD><TD BGCOLOR=\"#ffffff\">".
177         ( ( $svc_acct->slipip eq "0.0.0.0" || $svc_acct->slipip eq '0e0' )
178           ? "<I>(Dynamic)</I>"
179           : $svc_acct->slipip
180         ). "</TD>";
181   my($attribute);
182   foreach $attribute ( grep /^radius_/, fields('svc_acct') ) {
183     #warn $attribute;
184     $attribute =~ /^radius_(.*)$/;
185     my $pattribute = $FS::raddb::attrib{$1};
186     print "<TR><TD ALIGN=\"right\">Radius (reply) $pattribute</TD>".
187           "<TD BGCOLOR=\"#ffffff\">". $svc_acct->getfield($attribute).
188           "</TD></TR>";
189   }
190   foreach $attribute ( grep /^rc_/, fields('svc_acct') ) {
191     #warn $attribute;
192     $attribute =~ /^rc_(.*)$/;
193     my $pattribute = $FS::raddb::attrib{$1};
194     print "<TR><TD ALIGN=\"right\">Radius (check) $pattribute: </TD>".
195           "<TD BGCOLOR=\"#ffffff\">". $svc_acct->getfield($attribute).
196           "</TD></TR>";
197   }
198 } else {
199   print "<TR><TH COLSPAN=2>(No SLIP/PPP account)</TH></TR>";
200 }
201
202 print '<TR><TD ALIGN="right">RADIUS groups</TD><TD BGCOLOR="#ffffff">'.
203       join('<BR>', $svc_acct->radius_groups). '</TD></TR>';
204
205 print '</TABLE></TD></TR></TABLE><BR><BR>';
206
207 print join("\n", $conf->config('svc_acct-notes') ). '<BR><BR>'.
208       joblisting({'svcnum'=>$svcnum}, 1). '</BODY></HTML>';
209
210 %>