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