home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 May / Chip_2000-05_cd2.bin / suse / inst-sys / lib / YaST2 / clients / remotechooser.ycp < prev    next >
Encoding:
Text File  |  2000-03-30  |  2.9 KB  |  94 lines

  1. // Demo module that displays a list of all hostnames,
  2. // Lets you choose one host and starts on that host
  3. // a module
  4. {
  5.     // Menuentry
  6.     if ( Args() == [ "get_menuentry" ] )
  7.     return [ "remotechooser",
  8.         $[
  9.          `menuentry    : "YaST2/Remote Administration",
  10.          `arguments    : [ ],
  11.          `widget       : `RichText(_(
  12. "This module lets you start YaST2 components on a remote machine 
  13. via a network connection or on the local machine as a differnt
  14. user. Several protocols are supported.")),
  15.          `codefragment : nil
  16.         ]
  17.         ];
  18.  
  19.     UI(``{
  20.     define ProtocolSelection() ``{
  21.         return `Left(`HSquash(`RadioButtonGroup(`id(`protocol), 
  22.                           `VBox(
  23.                           `Left(`RadioButton(`id("telnet"), "telnet", true)),
  24.                           `Left(`RadioButton(`id("rlogin"), "rlogin")),
  25.                           `Left(`RadioButton(`id("rsh"),    "rsh")),
  26.                           `Left(`RadioButton(`id("ssh"),    "ssh")),
  27.                           `Left(`RadioButton(`id("su"),     "su")),
  28.                           `Left(`RadioButton(`id("sudo"),   "sudo"))))));
  29.     };
  30.         
  31.     define HostDialog(string username, list hostnames) ``{
  32.         list answer = [];
  33.         term selbox = `SelectionBox(`id(`hosts), `opt(`notify, `immediate), _("remote host"), hostnames);
  34.  
  35.         OpenDialog(`HBox(selbox, 
  36.                  `VBox(
  37.                    `TextEntry(`id(`hostname), _("Host"),            ""),
  38.                    `TextEntry(`id(`login),    _("Login name"),      username),
  39.                    `TextEntry(`id(`module),   _("Module to start"), "menu"),
  40.                    `VCenter(ProtocolSelection()),
  41.                    `HBox(
  42.                      `PushButton(`id(`ok),    `opt(`default), _("&Do it now")),
  43.                      `HStretch(),
  44.                      `PushButton(`id(`cancel),                _("&Cancel"))))));
  45.         while (true) {
  46.         any ret = UserInput();
  47.         if (ret == `hosts) {
  48.             ChangeWidget(`id(`hostname), `Value, QueryWidget(`id(`hosts), `CurrentItem));
  49.             continue;
  50.         }
  51.         
  52.         else if (ret == `ok) {
  53.             string protocol   = QueryWidget(`id(`protocol), `CurrentButton);
  54.             string loginname  = QueryWidget(`id(`login),  `Value);
  55.             string hostname   = QueryWidget(`id(`hostname),  `Value);
  56.             if (hostname == "") hostname = "localhost";
  57.             string modulename = QueryWidget(`id(`module), `Value);
  58.             answer = [ protocol, loginname, hostname, modulename ];
  59.         }
  60.         else answer = [];
  61.         break;
  62.         }
  63.         CloseDialog();
  64.         return answer;
  65.     };
  66.     });
  67.  
  68.     UI(`OpenDialog(`Label(_("Scanning for hosts on this LAN..."))));
  69.     list hostnames = sort(SCR(`Read(.net.hostnames)));
  70.     UI(`CloseDialog());
  71.  
  72.     string username = SCR(`Read(.runtime.username));
  73.  
  74.     while (true) {
  75.     list answer = UI(`HostDialog(username, hostnames));
  76.     if (size(answer) == 4) 
  77.     {
  78.         username = select(answer, 1);
  79.         string m = select(answer, 0) + "://" + select(answer, 1);
  80.  
  81.             if ( select(answer, 0) != "su" && select(answer, 0) != "sudo" )
  82.             {
  83.         m = m + "@" + select(answer, 2);
  84.             }
  85.             
  86.             m = m + "/" + select(answer, 3);
  87.         
  88.         CallModule(m,[]);
  89.         UI(`SetModulename("remotechooser"));
  90.     }
  91.     else break;
  92.     }
  93. }
  94.