1#!/usr/local/bin/perl
2# edit_pshare.cgi
3# Display a form for editing or creating a new printer share
4
5require './samba-lib.pl';
6&ReadParse();
7$s = $in{'share'};
8# check acls
9
10&error_setup("$text{'eacl_aviol'}ask_epass.cgi");
11if(!$s) {
12	&error("$text{'eacl_np'} $text{'eacl_pcps'}")
13        unless $access{'c_ps'};
14	}
15else {
16	&error("$text{'eacl_np'} $text{'eacl_paps'}")
17        unless &can('r', \%access, $in{'share'});
18	}
19# display
20if ($s) {
21	&ui_print_header(undef, $s eq 'global' ? $text{'pshare_title1'} : $text{'pshare_title2'}, "");
22	&get_share($s);
23	}
24else {
25	&ui_print_header(undef, $text{'pshare_title3'}, "");
26	}
27
28print &ui_form_start("save_pshare.cgi", "post");
29if ($s) {
30	print &ui_hidden("old_name", $s);
31	}
32
33# Vital share options..
34print &ui_table_start($text{'pshare_info'}, undef, 2);
35if ($s ne "global") {
36	if ($copy = &getval("copy")) {
37		print &ui_table_row(undef, &text('share_copy', $copy), 2);
38		}
39	print &ui_table_row($text{'pshare_name'},
40		&ui_radio("printers", $s eq "printers" ? 1 : 0,
41		  [ [ 0, &ui_textbox("share", $s eq "printers" ? "" : $s, 20) ],
42		    [ 1, $text{'pshare_all'} ] ]));
43	}
44
45if (&foreign_check("lpadmin")) {
46	&foreign_require("lpadmin", "lpadmin-lib.pl");
47	@plist = &foreign_call("lpadmin", "list_printers");
48	}
49elsif ($config{'list_printers_command'}) {
50	@plist = split(/\s+/ , `$config{'list_printers_command'}`);
51	}
52if (@plist) {
53	local $printer = &getval("printer");
54	push(@plist, $printer)
55		if ($printer && &indexof($printer, @plist) == -1);
56	@opts = ( );
57	push(@opts, [ "", $s eq "global" ? $text{'config_none'}
58					 : $text{'default'} ]);
59	foreach $p (@plist) {
60		push(@opts, [ $p, $p ]);
61		}
62	print &ui_table_row($text{'pshare_unixprn'},
63		&ui_select("printer", $printer, \@opts));
64	}
65else {
66	print &ui_table_row($text{'pshare_unixprn'},
67		&ui_textbox("printer", undef, 15));
68	}
69
70print &ui_table_row($text{'pshare_spool'},
71	&ui_textbox("path", &getval("path"), 60)." ".
72	&file_chooser_button("path", 1));
73
74print &ui_table_row($text{'share_available'},
75	&yesno_input("available"));
76
77print &ui_table_row($text{'share_browseable'},
78	&yesno_input("browseable"));
79
80print &ui_table_row($text{'share_comment'},
81	&ui_textbox("comment", &getval("comment"), 60));
82
83if ($s eq "global") {
84	print &ui_table_row(undef, $text{'share_samedesc1'}, 2);
85	}
86print &ui_table_end();
87
88@buts = ( );
89if ($s eq "global") {
90	push(@buts, [ undef, $text{'save'} ]);
91	}
92elsif ($s) {
93	if (&can('rw', \%access, $s)) {
94		push(@buts, [ undef, $text{'save'} ]);
95		}
96	if (&can('rv', \%access, $s)) {
97		push(@buts, [ "view", $text{'share_view'} ]);
98		}
99	if (&can('rw', \%access, $s)) {
100		push(@buts, [ "delete", $text{'delete'} ]);
101		}
102	}
103else {
104	push(@buts, [ undef, $text{'create'} ]);
105	}
106print &ui_form_end(\@buts);
107
108if ($s) {
109	# Icons for other share options
110	$us = "share=".&urlize($s)."&printer=1";
111	local (@url, @text, @icon, $disp);
112	if (&can('rs',\%access, $s)) {
113		push(@url,  "edit_sec.cgi?$us");
114		push(@text, $text{'share_security'});
115		push(@icon, "images/icon_2.gif");
116		$disp++;
117		}
118	if (&can('ro',\%access, $s)) {
119		push(@url,  "edit_popts.cgi?$us");
120		push(@text, $text{'print_option'});
121		push(@icon, "images/icon_3.gif");
122		$disp++;
123        }
124	if ($disp) {
125		print &ui_hr();
126		print &ui_subheading($text{'share_option'});
127		&icons_table(\@url, \@text, \@icon);
128		}
129	}
130
131&ui_print_footer("", $text{'index_sharelist'});
132