ACC SHELL
/* ------------------------------------------------------------------------------
* Copyright (c) 2006 Novell, Inc. All Rights Reserved.
*
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of version 2 of the GNU General Public License as published by the
* Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, contact Novell, Inc.
*
* To contact Novell about this file by physical or electronic mail, you may find
* current contact information at www.novell.com.
* ------------------------------------------------------------------------------
*/
/**
* File: include/sudo/complex.ycp
* Package: Configuration of sudo
* Summary: Dialogs definitions
* Authors: Bubli <kmachalkova@suse.cz>
*
* $Id: complex.ycp 29363 2006-03-24 08:20:43Z mzugec $
*/
{
textdomain "sudo";
import "Label";
import "Popup";
import "Wizard";
import "Confirm";
import "Sudo";
import "Report";
import "Address";
import "Netmask";
import "FileUtils";
include "sudo/helps.ycp";
string current_alias_name = "";
integer current_spec_idx = -1;
string initial_screen = "user_specs";
void EnableDisableButtons( string edit_button, string delete_button, list <term> items )
{
UI::ChangeWidget(`id(edit_button), `Enabled, (items != []) );
UI::ChangeWidget(`id(delete_button), `Enabled, (items != []) );
}
boolean ValidateHost(string hostname) {
string netmask = "";
if ( findfirstof(hostname,"/") != nil ) {
list <string> tmp = splitstring(hostname,"/");
hostname = tmp[0]:"";
netmask = tmp[1]:"";
if( !Netmask::Check(netmask)){
netmask = "";
Popup::Error( _("A valid netmask is either in dotted quad notation
(4 integers in the range 128 - 255 separated by dots)
or single integer in the range 0 - 32") );
return false;
}
}
if ( !Address::Check(hostname)) {
Popup::Error( Address::Valid4() );
return false;
}
return true;
}
string AddHostDialog(string host) {
string new_host = host;
UI::OpenDialog(`opt(`decorated), `VBox(
`Frame(
_("Add New Host to the Alias"),
`MarginBox(1,1,
`InputField(`id("host_name"),_("Hostname or Network"), new_host)
)
),
`ButtonBox(
`PushButton(`id(`ok), `opt(`default, `okButton), Label::OKButton()),
`PushButton(`id(`cancel), `opt(`cancelButton), Label::CancelButton())
)
));
any ret = nil;
while (true) {
ret = UI::UserInput();
if (ret == `ok) {
new_host = (string) UI::QueryWidget(`id("host_name"), `Value);
if( !ValidateHost(new_host)) {
UI::SetFocus(`id("host_name"));
continue;
}
break;
} else if (ret == `cancel) {
break;
}
}
UI::CloseDialog();
return (new_host) ;
}
string AddUserDialog( list <string> users ) {
string new_user ="";
UI::OpenDialog(`opt(`decorated), `VBox(
`Frame(
_("Add New User to the Alias"),
`MarginBox(1,1,
`ComboBox(`id("user_name"),_("Local and System Users (Groups)"), users)
)
),
`ButtonBox(
`PushButton(`id(`ok), `opt(`default, `okButton), Label::OKButton()),
`PushButton(`id(`cancel), `opt(`cancelButton), Label::CancelButton())
)
));
any ret = nil;
while (true) {
ret = UI::UserInput();
if (ret == `ok) {
new_user = (string) UI::QueryWidget(`id("user_name"), `Value);
break;
} else if (ret == `cancel) {
break;
}
}
UI::CloseDialog();
return (new_user) ;
}
boolean ValidateCommand(string cmd){
if(FileUtils::Exists(cmd) || contains(Sudo::GetAliasNames("command"), cmd) || cmd == "ALL" )
return true;
else {
Popup::Error(sformat(_("File, directory or command alias '%1' does not exist."), cmd));
return false;
}
}
string AddCommandDialog(string c, string p) {
string new_command = "";
list <string> items = Sudo::GetAliasNames("command");
items = prepend( items, "ALL");
UI::OpenDialog(`opt(`decorated), `VBox(
`Frame(
_("Add new command with optional parameters"),
`VBox(
`VSpacing(0.5),
`VBox(
`HBox(
`MinWidth(40,`ComboBox(`id("cmd"), `opt(`editable), _("Command"), items)),
`VBox(
`VSpacing(1.1),
`PushButton(`id("browse_c"),_("Browse"))
)
),
`Left(`TextEntry(`id("params"),_("Parameters (optional)"), p))
),
`VSpacing(0.5)
)
),
`VSpacing(0.5),
`ButtonBox(
`PushButton(`id(`ok), `opt(`default, `okButton), Label::OKButton()),
`PushButton(`id(`cancel), `opt(`cancelButton), Label::CancelButton())
)
));
UI::ChangeWidget(`id("cmd"), `Value, c);
any ret = nil;
while (true) {
ret = UI::UserInput();
if (ret == `ok) {
string cmd = (string) UI::QueryWidget(`id("cmd"), `Value);
string params = (string) UI::QueryWidget(`id("params"), `Value);
if (!ValidateCommand(cmd)){
UI::SetFocus(`id("cmd"));
continue;
}
new_command = cmd + " " + params;
break;
} else if (ret == `cancel) {
break;
} else if (ret == "browse_c") {
string new_cmd = UI::AskForExistingFile("/", "*", "Choose a command");
UI::ChangeWidget(`id("cmd"),`Value, new_cmd);
}
}
UI::CloseDialog();
return new_command;
}
list <term> UpdateCmdList (list <string> members) {
integer idx = 0;
list <term> items = [];
foreach(string it, members, {
integer pos = findfirstof(it," \t");
string cmd = "";
string param = "";
if(pos != nil) {
cmd = substring(it,0, pos);
param = substring(it,pos+1);
}
else {
cmd = it;
param = "";
}
items = add(items, `item(`id(idx),cmd,param));
idx = idx+1;
});
return items;
}
/* Read settings dialog (currently unused)
* @return `abort if aborted and `next otherwisea
*
symbol ReadDialog() {
Wizard::RestoreHelp(HELPS["read"]:"");
//Check if user is root
if (!Confirm::MustBeRoot())
return `abort;
boolean ret = Sudo::Read();
return ret ? `next : `abort;
}*/
/**
* Write settings dialog
* @return `abort if aborted and `next otherwise
*/
symbol WriteDialog() {
Wizard::RestoreHelp(HELPS["write"]:"");
boolean ret = Sudo::Write();
//yes-no popup - an error occured when saving the configuration
if ( !ret && Popup::YesNo(_("Saving sudoer's configuration failed. Change the settings?")) )
return `back;
return ret ? `next : `abort;
}
}
ACC SHELL 2018