Bazaar/SysExecGui : gui password frontend for SysExec

git-svn-id: svn://ultimatepp.org/upp/trunk@3059 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
micio 2011-01-22 09:37:43 +00:00
parent d3bdd3741d
commit fde39c3d75
6 changed files with 280 additions and 0 deletions

View file

@ -0,0 +1,161 @@
#include "SysExecGui.h"
#include <CtrlLib/CtrlLib.h>
NAMESPACE_UPP
#ifdef PLATFORM_POSIX
#define IMAGECLASS SysExecGuiImg
#define IMAGEFILE <SysExecGui/SysExecGui.iml>
#include <Draw/iml.h>
#define LAYOUTFILE <SysExecGui/SysExecGui.lay>
#include <CtrlCore/lay.h>
///////////////////////////////////////////////////////////////////////////////////////
// password dialog
class PasswordDlg : public WithPasswordDlgLayout<TopWindow>
{
private:
String user;
protected:
public:
typedef PasswordDlg CLASSNAME;
// constructor
PasswordDlg();
String GetPassword(void) { return pwd; }
// starts dialog, return true on success
bool Run(String const &u = "root");
};
PasswordDlg::PasswordDlg()
{
CtrlLayout(*this, GetExeTitle());
pwd.Password();
title.SetLabel(t_("Please enter password for ") + GetUserName() + " :");
okBtn.Ok() <<= Acceptor(IDOK);
cancelBtn.Cancel() <<= Rejector(IDCANCEL);
VCenterPos().HCenterPos();
}
bool PasswordDlg::Run(String const &u)
{
// ask for password
user = u;
while(true)
{
pwd.Clear();
PopUp(NULL, false, true, true);
CenterScreen();
switch(Execute())
{
case IDOK:
// check the password running pwd
if(SysExecUser(user, pwd, "/bin/pwd", ""))
return true;
PromptOK(DeQtf(t_("Wrong password -- Try again")));
break;
case IDCANCEL:
return false;
default:
NEVER();
}
}
return true;
}
static PasswordDlg &pDlg()
{
static PasswordDlg p;
return p;
}
///////////////////////////////////////////////////////////////////////////////////////////////
// executes an external command as Admin user, passing a command line to it without waiting for its termination
// it WILL prompt for user intervention on windows secure systems (Vista+ OSes), on which the password is useless
// on linux, will return an error if password is wrong
// return true on success, false otherwise
bool SysStartAdmin(String const &command, String const &args, const VectorMap<String, String> &Environ)
{
if(!pDlg().Run())
return false;
return SysStartAdmin(pDlg().GetPassword(), command, args, Environ);
}
bool SysStartAdmin(String const &command, String const &args)
{
if(!pDlg().Run())
return false;
return SysStartAdmin(pDlg().GetPassword(), command, args);
}
///////////////////////////////////////////////////////////////////////////////////////////////
// executes an external command as required user, passing a command line to it without waiting for its termination
// on linux, will return an error if password is required AND wrong
// on windows, by now... it just spawn the process without changing security level
// I still shall find a way to go back to user mode on windows
// return true on success, false otherwise
bool SysStartUser(String const &user, String const &command, String const &args, const VectorMap<String, String> &Environ)
{
if(!pDlg().Run(user))
return false;
return SysStartUser(user, pDlg().GetPassword(), command, args, Environ);
}
bool SysStartUser(String const &user, String const &command, String const &args)
{
if(!pDlg().Run(user))
return false;
return SysStartUser(user, pDlg().GetPassword(), command, args);
}
///////////////////////////////////////////////////////////////////////////////////////////////
// executes an external command as Admin user, passing a command line to it waiting for its termination
// it WILL prompt for user intervention on windows secure systems (Vista+ OSes), on which the password is useless
// on linux, will return an error if password is wrong
// return true on success, false otherwise
bool SysExecAdmin(String const &command, String const &args, const VectorMap<String, String> &Environ)
{
if(!pDlg().Run())
return false;
return SysExecAdmin(pDlg().GetPassword(), command, args, Environ);
}
bool SysExecAdmin(String const &command, String const &args)
{
if(!pDlg().Run())
return false;
return SysExecAdmin(pDlg().GetPassword(), command, args);
}
///////////////////////////////////////////////////////////////////////////////////////////////
// executes an external command as required user, passing a command line to it waiting for its termination
// on linux, will return an error if password is required AND wrong
// on windows, by now... it just spawn the process without changing security level
// I still shall find a way to go back to user mode on windows
// return true on success, false otherwise
bool SysExecUser(String const &user, String const &command, String const &args, const VectorMap<String, String> &Environ)
{
if(!pDlg().Run(user))
return false;
return SysExecUser(user, pDlg().GetPassword(), command, args, Environ);
}
bool SysExecUser(String const &user, String const &command, String const &args)
{
if(!pDlg().Run(user))
return false;
return SysExecUser(user, pDlg().GetPassword(), command, args);
}
END_UPP_NAMESPACE
#endif

View file

@ -0,0 +1,51 @@
#ifndef _SysExecGui_SysExecGui_h
#define _SysExecGui_SysExecGui_h
#include <SysExec/SysExec.h>
NAMESPACE_UPP
#ifdef PLATFORM_POSIX
///////////////////////////////////////////////////////////////////////////////////////////////
// SysXXXAdmin and SysXXXUser function with gui password frontend
///////////////////////////////////////////////////////////////////////////////////////////////
// executes an external command as Admin user, passing a command line to it without waiting for its termination
// it WILL prompt for user intervention on windows secure systems (Vista+ OSes), on which the password is useless
// on linux, will return an error if password is wrong
// return true on success, false otherwise
bool SysStartAdmin(String const &command, String const &args, const VectorMap<String, String> &Environ);
bool SysStartAdmin(String const &command, String const &args);
///////////////////////////////////////////////////////////////////////////////////////////////
// executes an external command as required user, passing a command line to it without waiting for its termination
// on linux, will return an error if password is required AND wrong
// on windows, by now... it just spawn the process without changing security level
// I still shall find a way to go back to user mode on windows
// return true on success, false otherwise
bool SysStartUser(String const &user, String const &command, String const &args, const VectorMap<String, String> &Environ);
bool SysStartUser(String const &user, String const &command, String const &args);
///////////////////////////////////////////////////////////////////////////////////////////////
// executes an external command as Admin user, passing a command line to it waiting for its termination
// it WILL prompt for user intervention on windows secure systems (Vista+ OSes), on which the password is useless
// on linux, will return an error if password is wrong
// return true on success, false otherwise
bool SysExecAdmin(String const &command, String const &args, const VectorMap<String, String> &Environ);
bool SysExecAdmin(String const &command, String const &args);
///////////////////////////////////////////////////////////////////////////////////////////////
// executes an external command as required user, passing a command line to it waiting for its termination
// on linux, will return an error if password is required AND wrong
// on windows, by now... it just spawn the process without changing security level
// I still shall find a way to go back to user mode on windows
// return true on success, false otherwise
bool SysExecUser(String const &user, String const &command, String const &args, const VectorMap<String, String> &Environ);
bool SysExecUser(String const &user, String const &command, String const &args);
#endif
END_UPP_NAMESPACE
#endif

View file

@ -0,0 +1,43 @@
PREMULTIPLIED
IMAGE_ID(lock_secure)
IMAGE_BEGIN_DATA
IMAGE_DATA(120,156,189,151,123,76,91,85,24,192,251,0,202,163,5,218,82,161,208,23,143,210,7,143,74,11,148,118,148,148,18,30)
IMAGE_DATA(227,33,176,241,114,27,136,99,12,24,206,68,18,231,132,193,54,182,241,216,162,40,123,169,25,35,155,131,77,65,178,205)
IMAGE_DATA(37,123,7,135,50,162,17,99,66,230,116,154,184,17,157,81,22,179,197,68,50,205,246,121,206,113,173,237,108,225,182,226)
IMAGE_DATA(78,242,251,167,253,238,247,59,231,251,206,189,247,92,154,140,38,163,121,58,124,188,25,130,167,2,253,50,69,60,246,74)
IMAGE_DATA(49,143,93,142,137,224,177,75,249,108,63,35,147,78,247,247,56,241,34,35,130,203,46,201,78,144,94,125,214,168,4,87)
IMAGE_DATA(84,164,197,206,27,228,194,99,129,190,222,138,37,84,51,83,162,66,15,225,252,235,205,82,216,82,200,133,222,21,126,240)
IMAGE_DATA(90,153,143,29,44,232,42,9,128,77,121,2,168,73,151,67,185,94,254,187,52,36,112,205,82,200,53,210,144,158,85,200)
IMAGE_DATA(221,86,192,131,195,107,125,97,178,59,26,190,58,168,129,175,223,78,178,49,179,47,1,198,183,73,97,224,57,22,244,87)
IMAGE_DATA(120,65,115,150,8,170,210,20,15,194,131,217,21,255,197,29,192,242,142,170,52,40,254,196,235,58,215,26,14,179,71,211)
IMAGE_DATA(96,124,187,20,70,94,228,194,112,35,199,198,201,150,16,152,234,141,33,255,191,255,66,48,236,173,100,64,67,166,4,138)
IMAGE_DATA(117,49,119,208,158,144,122,234,87,139,248,173,171,141,10,56,82,207,129,91,71,245,112,100,157,63,236,175,162,67,79,169)
IMAGE_DATA(63,169,7,166,29,245,163,163,40,24,246,148,249,146,121,225,184,119,170,189,73,143,112,207,36,33,156,46,148,202,163,125)
IMAGE_DATA(105,148,135,15,215,155,101,164,182,147,187,162,136,27,215,194,233,254,91,166,132,173,104,30,95,244,169,225,244,203,161,36)
IMAGE_DATA(182,198,20,3,73,50,193,24,74,149,228,137,63,67,37,58,179,1,245,242,106,119,12,169,63,206,185,206,28,9,102,149)
IMAGE_DATA(104,154,65,167,149,162,144,2,140,23,131,94,158,155,40,253,174,17,213,252,74,167,12,46,117,136,73,108,29,138,53,196)
IMAGE_DATA(132,143,163,152,60,4,195,19,127,243,99,126,146,51,150,228,196,110,19,66,139,65,177,31,55,100,74,137,255,242,86,137)
IMAGE_DATA(179,216,128,165,242,103,197,75,174,73,248,156,110,49,159,93,99,125,6,229,37,202,166,23,241,115,220,113,211,81,189,178)
IMAGE_DATA(226,197,19,206,252,174,158,63,206,252,70,185,240,138,187,126,111,38,131,139,215,179,38,93,9,125,117,10,7,255,141,17)
IMAGE_DATA(11,252,124,169,196,41,215,134,76,14,254,142,42,37,121,14,40,133,220,1,119,252,218,72,65,223,90,75,28,204,156,200)
IMAGE_DATA(135,155,31,152,28,252,119,46,230,2,124,89,225,148,219,103,44,14,254,185,11,185,48,178,51,131,212,38,44,200,127,21)
IMAGE_DATA(85,255,51,186,168,217,119,219,211,73,206,91,200,143,239,189,179,155,221,247,91,99,95,42,73,132,212,232,208,115,40,181)
IMAGE_DATA(136,138,31,207,247,250,225,28,114,237,111,19,133,48,240,60,11,222,90,205,132,67,181,44,248,227,179,21,46,253,247,62)
IMAGE_DATA(42,128,99,13,28,242,156,58,136,226,231,167,138,201,239,219,170,117,214,125,152,139,96,82,241,127,51,152,227,176,174,79)
IMAGE_DATA(251,227,96,238,124,182,75,183,149,111,143,27,224,226,14,25,124,63,154,110,251,205,206,143,247,97,48,21,255,84,151,105)
IMAGE_DATA(81,23,85,118,87,107,237,253,60,42,254,83,77,58,128,177,60,128,233,114,207,221,159,151,1,140,230,194,166,252,120,123)
IMAGE_DATA(63,151,178,127,47,170,193,129,12,128,65,11,192,48,170,253,241,28,106,12,161,216,193,44,128,125,25,36,199,99,254,69)
IMAGE_DATA(239,67,7,191,11,30,190,137,238,203,218,4,56,85,25,15,215,59,210,22,140,253,63,252,239,233,36,112,82,200,37,116)
IMAGE_DATA(170,197,240,225,6,215,241,75,237,159,219,174,183,185,49,35,17,124,168,55,171,224,97,255,147,241,255,212,158,250,47,127)
IMAGE_DATA(163,69,253,196,252,164,254,90,177,205,223,173,20,193,249,141,201,46,99,219,139,220,243,175,76,149,255,58,84,167,93,208)
IMAGE_DATA(127,119,75,138,205,255,138,70,6,63,236,52,184,140,109,45,68,126,185,240,50,85,127,166,90,124,161,13,93,179,144,255)
IMAGE_DATA(94,251,63,254,205,200,63,187,195,185,31,247,164,214,164,178,158,195,40,249,165,130,192,106,220,131,233,87,245,46,253,247)
IMAGE_DATA(123,13,48,138,250,62,38,228,65,115,114,52,220,221,179,204,105,220,76,91,26,121,255,161,239,151,78,26,197,115,16,57)
IMAGE_DATA(123,196,73,62,193,243,158,104,73,133,7,253,233,78,115,255,210,99,36,249,127,220,229,124,237,183,187,140,176,49,91,13)
IMAGE_DATA(203,159,142,188,137,210,22,33,242,105,20,222,63,120,160,51,101,144,89,37,158,196,115,111,66,123,251,245,202,68,24,89)
IMAGE_DATA(175,133,211,77,201,139,50,218,160,131,55,170,52,80,141,206,47,197,186,232,57,142,175,79,227,163,181,167,82,113,219,13)
IMAGE_DATA(159,176,160,128,150,148,232,208,179,232,124,123,163,92,175,184,191,208,247,159,21,244,253,53,143,215,156,40,17,156,240,241)
IMAGE_DATA(98,86,61,114,47,71,4,186,233,39,115,64,104,104,127,215,174,192,67,178,16,124,15,220,246,131,133,8,67,196,34,18)
IMAGE_DATA(40,162,66,132,211,22,232,249,95,1,117,30,154,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)
IMAGE_END_DATA(1216, 1)

View file

@ -0,0 +1,8 @@
LAYOUT(PasswordDlgLayout, 356, 200)
ITEM(Label, title, SetLabel(t_("Please enter password for")).LeftPosZ(56, 284).TopPosZ(4, 72))
ITEM(EditString, pwd, LeftPosZ(132, 208).TopPosZ(92, 20))
ITEM(Label, dv___2, SetLabel(t_("Password :")).LeftPosZ(56, 72).VSizePosZ(92, 85))
ITEM(Button, cancelBtn, SetLabel(t_("Cancel")).LeftPosZ(200, 68).TopPosZ(168, 20))
ITEM(Button, okBtn, SetLabel(t_("Ok")).LeftPosZ(276, 68).TopPosZ(168, 20))
END_LAYOUT

View file

@ -0,0 +1,12 @@
description "Gui password frontend for SysExec package\377";
uses
CtrlLib,
SysExec;
file
SysExecGui.iml,
SysExecGui.lay,
SysExecGui.h,
SysExecGui.cpp;

5
bazaar/SysExecGui/init Normal file
View file

@ -0,0 +1,5 @@
#ifndef _SysExecGui_icpp_init_stub
#define _SysExecGui_icpp_init_stub
#include "CtrlLib/init"
#include "SysExec/init"
#endif