Checkin of disparate changes from working on the road:
[freeside.git] / httemplate / edit / part_export.cgi
1 <!-- mason kludge -->
2 <%
3
4 #if ( $cgi->param('clone') && $cgi->param('clone') =~ /^(\d+)$/ ) {
5 #  $cgi->param('clone', $1);
6 #} else {
7 #  $cgi->param('clone', '');
8 #}
9 #if ( $cgi->param('svcpart') && $cgi->param('svcpart') =~ /^(\d+)$/ ) {
10 #  $cgi->param('svcpart', $1);
11 #} else {
12 #  $cgi->param('svcpart', '');
13 #}
14
15 my($query) = $cgi->keywords;
16 my $action = '';
17 my $part_export = '';
18 my $options = {};
19 if ( $cgi->param('error') ) {
20   $part_export = new FS::part_export ( {
21     map { $_, scalar($cgi->param($_)) } fields('part_export')
22   } );
23 }
24
25 #warn "***$query***";
26 if ( $cgi->param('clone') && $cgi->param('clone') =~ /^(\d+)$/ ) {
27   $action = 'Add';
28   my $old_part_export = qsearchs('part_export', { 'exportnum' => $1 } );
29   unless ( $part_export ) {
30     ($part_export, $options) = $old_part_export->clone($cgi->param('svcpart'));
31   }
32 } elsif ( $cgi->param('new_with_svcpart') 
33           && $cgi->param('new_with_svcpart') =~ /^(\d+)$/ ) {
34   $part_export ||= new FS::part_export ( { 'svcpart' => $1 } );
35 } elsif ( $query =~ /^(\d+)$/ ) {
36   $part_export ||= qsearchs('part_export', { 'exportnum' => $1 } );
37 }
38 $action ||= $part_export->exportnum ? 'Edit' : 'Add';
39
40 my %exports = (
41   'svc_acct' => {
42     'sysvshell' => {
43       'desc' =>
44         'Batch export of /etc/passwd and /etc/shadow files (Linux/SysV)',
45       'options' => {},
46     },
47     'bsdshell' => {
48       'desc' =>
49         'Batch export of /etc/passwd and /etc/master.passwd files (BSD)',
50       'options' => {},
51     },
52 #    'nis' => {
53 #      'desc' =>
54 #        'Batch export of /etc/global/passwd and /etc/global/shadow for NIS ',
55 #      'options' => {},
56 #    },
57     'bsdshell' => {
58       'desc' =>
59         'Batch export of /etc/passwd and /etc/master.passwd files (BSD)',
60       'options' => {},
61     },
62     'textradius' => {
63       'desc' => 'Batch export of a text /etc/raddb/users file (Livingston, Cistron)',
64     },
65     'sqlradius' => {
66       'desc' => 'Real-time export to SQL-backed RADIUS (ICRADIUS, FreeRADIUS)',
67       'options' => {
68         'datasrc'  => { label=>'DBI data source' },
69         'username' => { label=>'Database username' },
70         'password' => { label=>'Database password' },
71       },
72       'nodomain' => 'Y',
73       'notes' => 'Not specifying datasrc will export to the freeside database? (no...  notes on MySQL replication, DBI::Proxy, etc., from Conf.pm && export.html etc., reset with bin/sqlradius_reset',
74     },
75     'cyrus' => {
76       'desc' => 'Real-time export to Cyrus IMAP server',
77     },
78     'cp' => {
79       'desc' => 'Real-time export to Critical Path Account Provisioning Protocol',
80     },
81     'infostreet' => {
82       'desc' => 'Real-time export to InfoStreet streetSmartAPI',
83       'options' => {
84         'url'      => { label=>'XML-RPC Access URL', },
85         'login'    => { label=>'InfoStreet login', },
86         'password' => { label=>'InfoStreet password', },
87         'groupID'  => { label=>'InfoStreet groupID', },
88       },
89       'nodomain' => 'Y',
90       'notes' => 'Real-time export to <a href="http://www.infostreet.com/">InfoStreet</a> streetSmartAPI.  Requires installation of <a href="http://search.cpan.org/search?dist=Frontier-Client">Frontier::Client</a> from CPAN.',
91     }
92   },
93
94   'svc_domain' => {},
95
96   'svc_acct_sm' => {},
97
98   'svc_forward' => {},
99
100   'svc_www' => {},
101
102 );
103
104 my $svcdb = $part_export->part_svc->svcdb;
105 my %layers = map { $_ => "$_ - ". $exports{$svcdb}{$_}{desc} }
106                keys %{$exports{$svcdb}};
107 $layers{''}='';
108
109 my $widget = new HTML::Widgets::SelectLayers(
110   'selected_layer' => $part_export->exporttype,
111   'selected_layer' => $part_export->exporttype,
112   'options'        => \%layers,
113   'form_name'      => 'dummy',
114   'form_action'    => 'process/part_export.cgi',
115   'form_text'      => [qw( exportnum svcpart machine )],
116 #  'form_checkbox'  => [qw()],
117   'html_between'    => "</TD></TR></TABLE>\n",
118   'layer_callback'  => sub {
119     my $layer = shift;
120     my $html = qq!<INPUT TYPE="hidden" NAME="exporttype" VALUE="$layer">!.
121                ntable("#cccccc",2);
122     foreach my $option ( keys %{$exports{$svcdb}->{$layer}{options}} ) {
123 #    foreach my $option ( qw(url login password groupID ) ) {
124       my $optinfo = $exports{$svcdb}->{$layer}{options}{$option};
125       my $label = $optinfo->{label};
126       my $value = $part_export->option($option);
127       $html .= qq!<TR><TD ALIGN="right">$label</TD><TD>!.
128                qq!<TD><INPUT TYPE="text" NAME="$option" VALUE="$value"></TD>!.
129                '</TR>';
130     }
131     $html .= '</TABLE>';
132
133     $html .= '<INPUT TYPE="hidden" NAME="options" VALUE="'.
134              join(',', keys %{$exports{$svcdb}->{$layer}{options}} ). '">';
135
136     $html .= '<INPUT TYPE="hidden" NAME="nodomain" VALUE="'.
137              $exports{$svcdb}->{$layer}{nodomain}. '">';
138
139     $html .= '<INPUT TYPE="submit" VALUE="'.
140              ( $part_export->exportnum ? "Apply changes" : "Add export" ).
141              '">';
142
143     $html;
144   },
145 );
146
147 %>
148 <%= header("$action Export", menubar(
149   'Main Menu' => popurl(2),
150 ), ' onLoad="visualize()"')
151 %>
152
153 <% if ( $cgi->param('error') ) { %>
154   <FONT SIZE="+1" COLOR="#ff0000">Error: <%= $cgi->param('error') %></FONT>
155   <BR><BR>
156 <% } %>
157
158 <FORM NAME="dummy">
159 <INPUT TYPE="hidden" NAME="exportnum" VALUE="<%= $part_export->exportnum %>">
160
161 <%= ntable("#cccccc",2) %>
162 <TR>
163   <TD ALIGN="right">Service</TD>
164   <TD BGCOLOR="#ffffff">
165     <%= $part_export->svcpart %> - <%= $part_export->part_svc->svc %>
166     <INPUT TYPE="hidden" NAME="svcpart" VALUE="<%= $part_export->svcpart %>">
167   </TD>
168 </TR>
169 <TR>
170   <TD ALIGN="right">Export host</TD>
171   <TD>
172     <INPUT TYPE="text" NAME="machine" VALUE="<%= $part_export->machine %>">
173   </TD>
174 </TR>
175 <TR>
176   <TD ALIGN="right">Export</TD>
177   <TD><%= $widget->html %>
178 </BODY>
179 </HTML>
180