RT# 39340 - configured the minimal selfservice to get mac address from radius account...
[freeside.git] / min_selfservice / login.php
1 <?
2
3 require('freeside.class.php');
4 $freeside = new FreesideSelfService();
5
6 $ip = $_SERVER['REMOTE_ADDR'];
7
8 $mac_addr = $freeside->get_mac_address( array('ip' => $ip, ) );
9
10 $response = $freeside->login( array( 
11   'username' => $mac_addr['mac_address'],
12   'domain'   => 'ip_mac',
13 ) );
14
15 $error = $response['error'];
16
17 if ( $error ) {
18
19   header('Location:index.php?username='. urlencode($mac).
20                            '&domain='.   urlencode($domain).
21                            '&email='.    urlencode($email).
22                            '&error='.    urlencode($error)
23         );
24   die();
25
26 }
27
28 // sucessful login
29
30 $session_id = $response['session_id'];
31
32 error_log("[login] logged into freeside with session_id=$session_id, setting cookie");
33
34 // now what?  for now, always redirect to the main page (or the select a
35 // customer diversion).
36 // eventually, other options?
37
38 setcookie('session_id', $session_id);
39
40 if ( $response['custnum'] || $response['svcnum'] ) {
41
42   header("Location:main.php");
43   die();
44   //1;
45
46 } elseif ( $response['customers'] ) {
47 var_dump($response['customers']);
48 ?>
49
50   <? $title ='Select customer'; include('elements/header.php'); ?>
51   <? include('elements/error.php'); ?>
52
53   <FORM NAME="SelectCustomerForm" ACTION="process_select_cust.php" METHOD=POST>
54   <INPUT TYPE="hidden" NAME="action" VALUE="switch_cust">
55
56   <TABLE BGCOLOR="#c0c0c0" BORDER=0 CELLSPACING=2 CELLPADDING=0>
57
58     <TR>
59       <TH ALIGN="right">Customer </TH>
60       <TD>
61         <SELECT NAME="custnum" ID="custnum" onChange="custnum_changed()">
62           <OPTION VALUE="">Select a customer
63           <? foreach ( $response['customers'] AS $custnum => $customer ) { ?>
64             <OPTION VALUE="<? echo $custnum ?>"><? echo htmlspecialchars( $customer ) ?>
65           <? } ?>
66         </SELECT>
67       </TD>
68     </TR>
69
70     <TR>
71       <TD COLSPAN=2 ALIGN="center"><INPUT TYPE="submit" ID="submit" VALUE="Select customer" DISABLED></TD>
72     </TR>
73
74   </TABLE>
75   </FORM>
76
77   <SCRIPT TYPE="text/javascript">
78
79   function custnum_changed () {
80     var form = document.SelectCustomerForm;
81     if ( form.custnum.selectedIndex > 0 ) {
82       form.submit.disabled = false;
83     } else {
84       form.submit.disabled = true;
85     }
86   }
87
88   </SCRIPT>
89
90   <? include('elements/footer.php'); ?>
91
92 <?
93
94 // } else {
95 // 
96 //   die 'login successful, but unrecognized info (no custnum, svcnum or customers)';
97   
98 }
99
100 ?>