ACC SHELL

Path : /usr/share/YaST2/clients/
File Upload :
Current File : //usr/share/YaST2/clients/samba-server.ycp

/**
 * File:	clients/samba-server.ycp
 * Package:	Configuration of samba-server
 * Summary:	Main file
 * Authors:	Stanislav Visnovsky <visnov@suse.cz>
 *
 * $Id: samba-server.ycp 23799 2005-06-27 12:08:30Z mlazar $
 *
 * Main file for samba-server configuration. Uses all other files.
 */
 
/* TODO:
 *  - Read/Write only needed modules (if command line is used)
 *  - allow set more options on command line (ldap server, ...)
 */
 

{

/***
 * <h3>Configuration of the samba-server</h3>
 */

textdomain "samba-server";

import "CommandLine";
import "Popup";
import "Report";

import "SambaRole";
import "SambaServer";
import "SambaConfig";
import "SambaService";
import "SambaBackend";


/**
 * Command line "share" commands handler.
 *
 * @param options	map of options from command line
 * @return boolean	true on success
 */
boolean ShareHandler(map<string,string> options) {
    string share = (string) (options["name"]:nil);
    
    // check the "command" to be present exactly once
    string command = CommandLine::UniqueOption( options, 
	["add", "delete", "enable", "disable", "options", "show" ] );
    if( command == nil ) return false;

    // validate the options
    if( share == nil ) {	
	// translators: error message for share command line action
	// must provide the share name
	Report::Error(_("Specify the share name."));
	return false;
    }
    
    if( !SambaConfig::ShareExists(share) && command != "add" ) {
	// translators: error message for "share add" command line action, %1 is share name
	Report::Error( sformat( _("The share %1 does not exist."), share ) );
	return false;
    }
    
    // process the commands
    if( command == "enable" ) {
	SambaConfig::ShareEnable(share);
    } else if( command == "disable" ) {
	SambaConfig::ShareDisable(share);
    } else if( command == "delete" ) {
	SambaConfig::ShareRemove(share);
    } else if( command == "add" )  {
	if( ! haskey( options, "path" ) ) {
	    // translators: error message for "add share" command line action
	    Report::Error( _("Provide the path of a directory to share.") );
	    return false;
	}
	
	if (SambaConfig::ShareExists(share)) {
	    // translators: error message for "add share" command line action, %1 is share name
	    Report::Error( sformat( _("Share %1 already exists."), share ) );
	    return false;
	}
	SambaConfig::ShareSetStr(share, "path", options["path"]:"");
	SambaConfig::ShareSetStr(share, "comment", options["comment"]:sformat("Share for %1", options["path"]:"path"));
    } else if( command == "show" ) {
	CommandLine::Print( sformat("[%1]", share) );
	
	foreach(string key, string val, SambaConfig::ShareGetMap(share), {
	    if (val != nil)
		CommandLine::Print( sformat( "\t%1 = %2", key, val ) );
	});
    } else if( command == "options" ) {
	foreach(string key, ["comment", "path", "printable", "write list", "browseable", "guest ok", "valid users"], {
	    string value = (string) (options[key]:nil);
	    if (value != nil) {
		SambaConfig::ShareSetStr(share, key, value);
	    }
	});
    }
    
    return true;
}

/**
 * Command line "list" command handler.
 *
 * @param options	map of options from command line
 * @return boolean	true on success
 */
boolean ListHandler( map <string,string>options ) {

    // translators: heading for "list" shares command line action
    // try to keep alignment
    CommandLine::Print( _("Status  \tType\tName
=============================="));

    map<string, map<string,any> > printers = $[];
    
    foreach( string share, SambaConfig::GetShares(), ``{
	if (!SambaConfig::ShareGetTruth(share, "printable", false)) {
	    // translators: share is a disk. %1 is the status, %2 comment
	    CommandLine::Print( sformat( _("%1\tDisk\t%2"), 
		// translators: share status
		SambaConfig::ShareEnabled(share) ? _("Disabled")
		// translators: share status
		    : _("Enabled")+"  ", share ) );
	}
    });
    

    foreach( string share, SambaConfig::GetShares(), ``{
	if (SambaConfig::ShareGetTruth(share, "printable", false)) {
	    // translators: share is a printer. %1 is the status, %2 comment
	    CommandLine::Print( sformat( _("%1\tPrinter\t%2"), 
		SambaConfig::ShareEnabled(share) ? 
		    // translators: share status
		    _("Disabled")
		    // translators: share status
		    : _("Enabled")+"  ", share ) );
	}
    });
    
    return true;
}

/**
 * Command line "backend" command handler.
 *
 * @param options	map of options from command line
 * @return boolean	true on success
 */
boolean BackendHandler( map<string,string> options )
{
    string command = CommandLine::UniqueOption(options, ["smbpasswd", "tdbsam", "ldapsam"]);
    if (command == nil) return false;
    SambaBackend::SetPassdbBackends([command]);
    return true;
}

/**
 * Command line "role" command handler.
 *
 * @param options	map of options from command line
 * @return boolean	true on success
 */
boolean RoleHandler( map<string,string> options ) {
    // check the role to be present exactly once
    string command = CommandLine::UniqueOption( options,  ["pdc", "bdc", "standalone", "member" ]);
    if( command == nil ) return false;
    SambaRole::SetRole(command);
    return true;
}

/**
 * Command line "service" command handler.
 *
 * @param options	map of options from command line
 * @return boolean	true on success
 */
boolean SambaServerEnableHandler( map<string,string> options ) {
    // check the "command" to be present exactly once
    string command = CommandLine::UniqueOption( options, ["enable", "disable" ] );
    if( command == nil ) return false;
    SambaService::SetServiceAutoStart(command == "enable");
    return true;
}

/**
 * Command line "configure" command handler.
 *
 * @param options	map of options from command line
 * @return boolean	true on success
 */
boolean ChangeConfiguration( map<string,string> options ) {
	
    string value = (string) (options["workgroup"]:nil);
    if( value != nil ) SambaConfig::GlobalSetStr("workgroup", value);

    value = (string) (options["description"]:nil);
    if( value != nil ) SambaConfig::GlobalSetStr("server string", value);

    value = (string) (options["ldap_suffix"]:nil);
    if( value != nil ) SambaConfig::GlobalSetStr("ldap suffix", value);

    value = (string) (options["ldap_admin_dn"]:nil);
    if( value != nil ) SambaConfig::GlobalSetStr("ldap admin dn", value);

    return true;
}

/* The main () */
y2milestone ("----------------------------------------");
y2milestone ("Samba-server module started");

include "samba-server/wizards.ycp";

/* main ui function */
any ret = nil;

map cmdline = $[
    "id" 		: "samba-server",
    // translators: command line help text for samba-server module
    "help" 		: _("Samba server configuration module (see Samba documentation for details)"),
    "guihandler" 	: SambaServerSequence,
    "initialize"	: SambaServer::Read,
    "finish"		: SambaServer::Write,
    "actions"		: $[
	"share"	:$[
	    "handler"	: ShareHandler,
	    // translators: command line help text for share action
	    "help"	: _("Manipulate a single share")
	],
	"list"	:$[
	    "handler"	: ListHandler,
	    // translators: command line help text for list action
	    "help"	: _("Show the list of available shares")
	],
	"role"	:$[
	    "handler"	: RoleHandler,
	    // translators: command line help text for role action
	    "help"	: _("Set the role of the server")
	],
	"backend" :$[
	    "handler"	: BackendHandler,
	    // translators: command line help text for backend selection action
	    "help"	: _("Set the back-end for storing user information")
	],
	"service" :$[
	    "handler"	: SambaServerEnableHandler,
	    // translators: command line help text for service activation action
	    "help"	: _("Enable or disable the Samba services (smb and nmb)")
	],
	"configure"	: $[
	    "handler"	: ChangeConfiguration,
	    // translators: command line help text for configure action
	    "help"	: _("Change the global settings of the Samba server")
	]
    ],
    "options"		: $[
	"enable" 	:$[
	    // translators: command line help text for enable option
	    "help"	: _("Enable the share or a service")
	],
	"disable"	:$[
	    // translators: command line help text for disable option
	    "help"	: _("Disable the share or a service")
	],
	"delete"	:$[
	    // translators: command line help text for delete share option
	    "help"	: _("Remove the share from the configuration file")
	],
	"name"		:$[
	    // translators: command line help text for share name option
	    "help"	: _("The name of a share"),
	    "type"	: "string"
	],
	"add"		:$[
	    // translators: command line help text for "share add" subaction
	    "help"	: _("Add a new share"),
	], 
	"options"	:$[
	    // translators: command line help text for "share options" subaction
	    "help"	: _("Change options of a share"),
	], 
	"show"		:$[
	    // translators: command line help text for "share show" subaction
	    "help"	: _("Show the options of a share"),
	], 
	"comment"	:$[
	    // translators: command line help text for share comment option
	    "help"	: _("The comment of a share"),
	    "type"	: "string"
	], 
	"path"		:$[
	    // translators: command line help text for share path option
	    "help"	: _("The path (directory) to share"),
	    "type"	: "string"
	], 
	"printable"	:$[
	    // translators: command line help text for share printable option
	    "help"	: _("Flag if the share should act as a printer"),
	    "type"	: "boolean"
	], 
	"read_list"	:$[
	    // translators: command line help text for share read_list option
	    "help"	: _("A comma-separated list of users allowed to read from the share"),
	    "type"	: "string"
	], 
	"write_list"	:$[
	    // translators: command line help text for share write_list option
	    "help"	: _("A comma-separated list of users allowed to write to the share"),
	    "type"	: "string"
	], 
	"browseable"	:$[
	    // translators: command line help text for share browseable option
	    "help"	: _("Flag if the share should be visible when browsing the LAN"),
	    "type"	: "boolean"
	], 
	"guest_ok"	:$[
	    // translators: command line help text for share guest_ok option
	    "help"	: _("Flag if the share should allow guest access"),
	    "type"	: "boolean"
	], 
	"valid_users"	:$[
	    // translators: command line help text for share valid_users option
	    "help"	: _("A comma-separated list of users allowed to access the share"),
	    "type"	: "string"
	],
	"pdc"		:$[
	    // translators: command line help text for PDC role option
	    "help"	: _("Server should act as a primary domain controller"),
	], 
	"bdc"		:$[
	    // translators: command line help text for BDC role option
	    "help"	: _("Server should act as a backup domain controller"),
	], 
	"member"	:$[
	    // translators: command line help text for Domain Member role option
	    "help"	: _("Server should act as a domain member"),
	], 
	"standalone"	:$[
	    // translators: command line help text for standalone server role option
	    "help"	: _("Server should provide shares, but should not allow domain logins"),
	],
	"smbpasswd"	:$[
	    // translators: command line help text for smbpasswd option
	    "help"	: _("Use the 'smbpasswd' file to store user information"),
	],
	"tdbsam"	:$[
	    // translators: command line help text for tdbsam option
	    "help"	: _("Use the 'passdb.tdb' file to store user information"),
	],
	"ldapsam"		:$[
	    // translators: command line help text for ldapsam option
	    "help"	: _("Use the LDAP server to store user information"),
	],
	"password"		:$[
	    // translators: command line help text for password option
	    "help"	: _("Password for the LDAP server"),
	],
	"workgroup"	:$[
	    // translators: command line help text for workgroup option
	    "help"	: _("The name of a workgroup"),
	    "type"	: "string"
	], 
	"description"	:$[
	    // translators: command line help text for description option
	    "help"	: _("The human-readable description of the Samba server"),
	    "type"	: "string"
	], 
	"ldap_suffix"	:$[
	    // translators: command line help text for ldap_suffix option
	    "help"	: _("The LDAP suffix DN for manipulating the user information on the LDAP server"),
	    "type"	: "string"
	], 
	"ldap_admin_dn"	:$[
	    // translators: command line help text for ldap_admin_dn option
	    "help"	: _("The LDAP DN for modifying contents of the LDAP server (for example, changing passwords)"),
	    "type"	: "string"
	]
    ],
    "mappings"		: $[
	"share"		: [ "enable", "disable", "delete", "add", "options", "show", 
	    "name", "comment", "path", 
	    "printable", "read_list", "write_list", "browseable", "guest_ok", "valid_users" ],
	"list"		: [ ],
	"role"		: [ "pdc", "bdc", "standalone", "member" ],
	"backend" 	: [ "smbpasswd", "tdbsam", "ldapsam" ],
	"service" 	: [ "enable", "disable" ],
	"configure"	: [ "workgroup", "description", "ldap_suffix", "ldap_admin_dn" ]
    ]
];

ret = CommandLine::Run( cmdline );

y2debug("ret=%1", ret);

/* Finish */
y2milestone("Samba-server module finished");
y2milestone("----------------------------------------");

return ret;

/* EOF */
}

ACC SHELL 2018