|
|
|
@ -24,6 +24,8 @@ import cl_utils2
|
|
|
|
|
import cl_utils
|
|
|
|
|
|
|
|
|
|
import ldap
|
|
|
|
|
import types
|
|
|
|
|
import getpass
|
|
|
|
|
|
|
|
|
|
Version = "calculate-client 0.0.1"
|
|
|
|
|
|
|
|
|
@ -95,7 +97,7 @@ class cl_client(imp_cl_err, imp_cl_xml, imp_cl_help, imp_cl_smcon):
|
|
|
|
|
{
|
|
|
|
|
'progAccess':(0,),
|
|
|
|
|
'helpChapter':_("Usage"),
|
|
|
|
|
'help': cmdName + " [" + _("options") + "] " + _("user")
|
|
|
|
|
'help': cmdName + " [" + _("options") + "] " + _("domain")
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
'progAccess':(1,),
|
|
|
|
@ -106,15 +108,16 @@ class cl_client(imp_cl_err, imp_cl_xml, imp_cl_help, imp_cl_smcon):
|
|
|
|
|
{
|
|
|
|
|
'progAccess':(0,),
|
|
|
|
|
'helpChapter':"Function",
|
|
|
|
|
'help':_("Client for the calculate-server")
|
|
|
|
|
'help':_("Changes settings for connecting to domain \
|
|
|
|
|
(calculate-server)")
|
|
|
|
|
},
|
|
|
|
|
# Examples
|
|
|
|
|
{
|
|
|
|
|
'progAccess':(0,),
|
|
|
|
|
'helpChapter':_("Examples"),
|
|
|
|
|
'help':pcs( " cl-client -m test", self.column_width,
|
|
|
|
|
"# " + _("mounts a test user directory on the server \
|
|
|
|
|
calculate-server"),
|
|
|
|
|
'help':pcs( " cl-client 192.168.0.1", self.column_width,
|
|
|
|
|
"# " + _("Adds settings for connecting to domain \
|
|
|
|
|
(ip 192.168.0.1)"),
|
|
|
|
|
self.consolewidth-self.column_width )
|
|
|
|
|
},
|
|
|
|
|
# Options
|
|
|
|
@ -124,31 +127,28 @@ calculate-server"),
|
|
|
|
|
'help':_("display this help and exit")
|
|
|
|
|
},
|
|
|
|
|
{'progAccess':(0,),
|
|
|
|
|
'shortOption':"m",
|
|
|
|
|
'longOption':"create-home",
|
|
|
|
|
'shortOption':"r",
|
|
|
|
|
'helpChapter':_("Common options"),
|
|
|
|
|
'help':_("create home directory for the new user account")
|
|
|
|
|
'help':_("Removes the settings for connecting to a domain")
|
|
|
|
|
},
|
|
|
|
|
{'progAccess':(1,),
|
|
|
|
|
{'progAccess':(0,1,),
|
|
|
|
|
'longOption':"vars",
|
|
|
|
|
'optVal':_("TYPE_VAR"),
|
|
|
|
|
'helpChapter':_("Common options"),
|
|
|
|
|
'help':_("print variables (TYPE_VAR - all:full var)")
|
|
|
|
|
},
|
|
|
|
|
{'progAccess':(0,),
|
|
|
|
|
'shortOption':"s",
|
|
|
|
|
'longOption':"cl-server",
|
|
|
|
|
'optVal':_("CL_SERVER"),
|
|
|
|
|
'longOption':"mount",
|
|
|
|
|
'helpChapter':_("Common options"),
|
|
|
|
|
'help':_("name or ip calculate server")
|
|
|
|
|
},
|
|
|
|
|
{'progAccess':(0,),
|
|
|
|
|
'shortOption':"p",
|
|
|
|
|
'longOption':"prvar",
|
|
|
|
|
'optVal':_("TYPES_VAR"),
|
|
|
|
|
'helpChapter':_("Common options"),
|
|
|
|
|
'help':_("print variable (filter type - comma delimited)")
|
|
|
|
|
'help':_("mount [remote] resource for Samba (calculate-server)")
|
|
|
|
|
},
|
|
|
|
|
#{'progAccess':(0,),
|
|
|
|
|
#'shortOption':"p",
|
|
|
|
|
#'longOption':"prvar",
|
|
|
|
|
#'optVal':_("TYPES_VAR"),
|
|
|
|
|
#'helpChapter':_("Common options"),
|
|
|
|
|
#'help':_("print variable (filter type - comma delimited)")
|
|
|
|
|
#},
|
|
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
@ -312,6 +312,17 @@ calculate-server"),
|
|
|
|
|
else:
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
def getUserPassword(self, pwDialog=False):
|
|
|
|
|
"""Получить пароль у пользователя
|
|
|
|
|
|
|
|
|
|
pwDialog - приглашение ввода пароля
|
|
|
|
|
"""
|
|
|
|
|
if not pwDialog:
|
|
|
|
|
pwDialog = _("Password")
|
|
|
|
|
userPwd = getpass.getpass(pwDialog+":")
|
|
|
|
|
userPwd = re.sub("(\W)", r"\\\1",userPwd)
|
|
|
|
|
return userPwd
|
|
|
|
|
|
|
|
|
|
def chownR(self, directory, uid, gid):
|
|
|
|
|
"""изменяет владельца и группу
|
|
|
|
|
|
|
|
|
@ -367,6 +378,7 @@ calculate-server"),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def createHome(self, userName=False):
|
|
|
|
|
"""Создание пользовательской директории с настройками для kde4"""
|
|
|
|
|
# Подсоединяемся к movie
|
|
|
|
|
#if not self.getLdapObjBind(server):
|
|
|
|
|
#return False
|
|
|
|
@ -401,6 +413,146 @@ calculate-server"),
|
|
|
|
|
self.printSUCCESS(_("created home dir %s")%homeDir)
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
def mountRemote(self):
|
|
|
|
|
self.createClVars()
|
|
|
|
|
foudMountRemote = False
|
|
|
|
|
reFoundMount = re.compile("on\s+/var/calculate/remote\s+type\s+cifs")
|
|
|
|
|
resMount = self.execProg("mount",False,False)
|
|
|
|
|
if resMount and type(resMount) == types.ListType:
|
|
|
|
|
for string in resMount:
|
|
|
|
|
if reFoundMount.search(string):
|
|
|
|
|
foudMountRemote = True
|
|
|
|
|
break
|
|
|
|
|
if not foudMountRemote and not self.clVars.Get("cl_remote_host"):
|
|
|
|
|
self.printERROR("The computer is not in domain")
|
|
|
|
|
return False
|
|
|
|
|
if foudMountRemote:
|
|
|
|
|
self.printWARNING(_("Samba resource [remote] is mount") + \
|
|
|
|
|
" ...")
|
|
|
|
|
return True
|
|
|
|
|
pathRemote = "/var/calculate/remote"
|
|
|
|
|
domain = self.clVars.Get("cl_remote_host")
|
|
|
|
|
pwdRemote = self.clVars.Get("cl_remote_pw")
|
|
|
|
|
if not (domain and pwdRemote):
|
|
|
|
|
self.printERROR(_("Not found vaiables:cl_remote_host or \
|
|
|
|
|
cl_remote_pw") + " ...")
|
|
|
|
|
return False
|
|
|
|
|
if not os.path.exists(pathRemote):
|
|
|
|
|
os.makedirs(pathRemote)
|
|
|
|
|
mountStr = "mount -t cifs -o user=client,password=%s \
|
|
|
|
|
//%s/remote %s" %(pwdRemote,domain,pathRemote)
|
|
|
|
|
textLine = self.execProg(mountStr)
|
|
|
|
|
if not (textLine == None):
|
|
|
|
|
self.printERROR(_("Can not mount Samba resource [remote]") + \
|
|
|
|
|
" ...")
|
|
|
|
|
return False
|
|
|
|
|
else:
|
|
|
|
|
self.printSUCCESS(_("Mount Samba resource [remote]") + \
|
|
|
|
|
" ...")
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
def delDomain(self):
|
|
|
|
|
"""выводим из домена"""
|
|
|
|
|
self.createClVars()
|
|
|
|
|
foudMountRemote = False
|
|
|
|
|
reFoundMount = re.compile("on\s+/var/calculate/remote\s+type\s+cifs")
|
|
|
|
|
resMount = self.execProg("mount",False,False)
|
|
|
|
|
if resMount and type(resMount) == types.ListType:
|
|
|
|
|
for string in resMount:
|
|
|
|
|
if reFoundMount.search(string):
|
|
|
|
|
foudMountRemote = True
|
|
|
|
|
break
|
|
|
|
|
if not foudMountRemote and not self.clVars.Get("cl_remote_host"):
|
|
|
|
|
self.printWARNING("The computer is not in domain")
|
|
|
|
|
return True
|
|
|
|
|
self.execProg("calculate -P install/6intranet")
|
|
|
|
|
pathRemote = "/var/calculate/remote"
|
|
|
|
|
umountStr = "umount %s"%(pathRemote)
|
|
|
|
|
textLine = self.execProg(umountStr)
|
|
|
|
|
if not (textLine == None):
|
|
|
|
|
self.printERROR(_("Can not umount Samba resource [remote]") + \
|
|
|
|
|
" ...")
|
|
|
|
|
return False
|
|
|
|
|
self.clVars.Delete("cl_remote_host","local")
|
|
|
|
|
self.clVars.Delete("cl_remote_pw","local")
|
|
|
|
|
self.printOK(_("Deleted in domain") + " ...")
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
def addDomain(self, domain):
|
|
|
|
|
"""Вводим в домен"""
|
|
|
|
|
# Создаем объект переменных
|
|
|
|
|
self.createClVars()
|
|
|
|
|
resPing = self.execProg("ping -c 2 -i 0.3 %s" %domain,False,False)
|
|
|
|
|
foudHost = False
|
|
|
|
|
foudHostSamba = False
|
|
|
|
|
foudMountRemote = False
|
|
|
|
|
reFoundHost = re.compile("(\d+)\% packet loss")
|
|
|
|
|
if resPing and type(resPing) == types.ListType and len(resPing)>=2:
|
|
|
|
|
pingStr = resPing[-2].strip()
|
|
|
|
|
reSearch = reFoundHost.search(pingStr)
|
|
|
|
|
if reSearch and reSearch.group(1) == "0":
|
|
|
|
|
foudHost = True
|
|
|
|
|
if not foudHost:
|
|
|
|
|
self.printERROR(_("Not found domain %s")%domain)
|
|
|
|
|
return False
|
|
|
|
|
reFoundHostSamba = re.compile("Server=\[Samba.+\]")
|
|
|
|
|
resSmbClient = self.execProg("smbclient -N -L %s" %domain,
|
|
|
|
|
False,False)
|
|
|
|
|
if resSmbClient and type(resSmbClient) == types.ListType:
|
|
|
|
|
for string in resSmbClient:
|
|
|
|
|
if reFoundHostSamba.search(string):
|
|
|
|
|
foudHostSamba = True
|
|
|
|
|
break
|
|
|
|
|
if not foudHostSamba:
|
|
|
|
|
self.printERROR(_("Not found Samba server in %s")%domain)
|
|
|
|
|
return False
|
|
|
|
|
reFoundMount = re.compile("on\s+/var/calculate/remote\s+type\s+cifs")
|
|
|
|
|
resMount = self.execProg("mount",False,False)
|
|
|
|
|
if resMount and type(resMount) == types.ListType:
|
|
|
|
|
for string in resMount:
|
|
|
|
|
if reFoundMount.search(string):
|
|
|
|
|
foudMountRemote = True
|
|
|
|
|
break
|
|
|
|
|
if foudMountRemote:
|
|
|
|
|
self.printWARNING(_("Samba resource [remote] mount") + \
|
|
|
|
|
" ...")
|
|
|
|
|
else:
|
|
|
|
|
userPwd = self.getUserPassword("Domain password for the desktop")
|
|
|
|
|
pathRemote = "/var/calculate/remote"
|
|
|
|
|
pwdRemote = userPwd
|
|
|
|
|
if not os.path.exists(pathRemote):
|
|
|
|
|
os.makedirs(pathRemote)
|
|
|
|
|
mountStr = "mount -t cifs -o user=client,password=%s \
|
|
|
|
|
//%s/remote %s" %(pwdRemote,domain,pathRemote)
|
|
|
|
|
textLine = self.execProg(mountStr)
|
|
|
|
|
if not (textLine == None):
|
|
|
|
|
self.printERROR(_("Can not mount Samba resource [remote]") + \
|
|
|
|
|
" ...")
|
|
|
|
|
return False
|
|
|
|
|
else:
|
|
|
|
|
self.printSUCCESS(_("Mount Samba resource [remote]") + \
|
|
|
|
|
" ...")
|
|
|
|
|
self.clVars.Write("cl_remote_host", domain, False, "local")
|
|
|
|
|
self.clVars.Write("cl_remote_pw", userPwd, False, "local")
|
|
|
|
|
self.clVars.flIniFile()
|
|
|
|
|
#считаем переменные для клиента
|
|
|
|
|
servDn = self.clVars.Get("ld_services_dn")
|
|
|
|
|
unixDN = self.clVars.Get("ld_unix_dn")
|
|
|
|
|
bindDn = self.clVars.Get("ld_bind_dn")
|
|
|
|
|
bindPw = self.clVars.Get("ld_bind_pw")
|
|
|
|
|
# запишем их
|
|
|
|
|
if not (servDn and unixDN and bindDn and bindPw):
|
|
|
|
|
self.printERROR(_("Not found variables:"))
|
|
|
|
|
self.printERROR("ld_services_dn or ld_unix_dn \
|
|
|
|
|
or ld_bind_dn or ld_bind_pw")
|
|
|
|
|
return False
|
|
|
|
|
execStr = "calculate --set-server_url=%s --set-ldap_base=%s \
|
|
|
|
|
--set-ldap_root=%s --set-ldap_bind=%s --set-ldap_bindpw=%s -P \
|
|
|
|
|
install/6intranet" %(domain,servDn,unixDN,bindDn,bindPw)
|
|
|
|
|
self.execProg(execStr)
|
|
|
|
|
self.printOK(_("Added in domain %s")%domain + " ...")
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
class tsOpt(cl_base.opt):
|
|
|
|
|
"""Класс для обработки параметров и вывода help
|
|
|
|
|
|
|
|
|
|