develop
asamoukin 16 years ago
parent 1d030c0ad8
commit 402cc2a116

@ -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

@ -28,9 +28,13 @@
class Data:
#базовый суффикс LDAP
#Vl soft_ldap_base
ld_base_dn = {}
#DN всех сервисов
#V soft_ldap_sevices_dn
ld_services_dn = {}
#DN админстратора сервиса Unix (он, же DN сервиса)
#V soft_ldap_admin_unix
ld_unix_dn = {}
#bind суффикс LDAP
#Vl soft_ldap_bind
@ -59,10 +63,16 @@ class Data:
#Разрешение X по вертикали
hr_x11_height = {'mode':"w"}
#Разрешение X по горизонтали
hr_x11_width = {'mode':"w"}
#Пароль пользователя client
cl_remote_pw = {'mode':'w'}
# ip или имя домена (под управлением calculate-server)
cl_remote_host = {'mode':'w'}
#ближайший стандартный размер изображения к текущему разрешению
hr_x11_standart = {}
# Calculate плюс версия калкулэйта для записи в заголовок файла

@ -0,0 +1,56 @@
#!/usr/bin/python
#-*- coding: utf-8 -*-
#Copyright 2008 Calculate Pack, http://www.calculate-linux.ru
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import sys
import os
sys.path.insert(0,os.path.abspath('/usr/lib/calculate/calculate-lib/pym'))
sys.path.insert(0,os.path.abspath('/usr/lib/calculate/calculate-client/pym'))
import cl_base
import cl_client
tr = cl_base.lang()
tr.setGlobalDomain('cl_client')
tr.setLanguage(sys.modules[__name__])
if __name__ == "__main__":
ldapObj = cl_client.cl_client("cl-client")
optObj = cl_client.tsOpt(ldapObj)
flagError = False
if not optObj.flagHelp and optObj.opt.has_key('vars'):
terms = optObj.opt['vars'].split(",")
clVars = cl_base.DataVars()
clVars.flClient()
clVars.flIniFile()
if terms == ["all"]:
clVars.printVars()
else:
clVars.printVars(terms)
elif not optObj.flagHelp:
if optObj.params.has_key('user'):
if not optObj.opt.has_key('r') or not optObj.opt.has_key('mount'):
domain = optObj.params['user']
if not ldapObj.addDomain(domain):
flagError = True
if optObj.opt.has_key('r'):
if not ldapObj.delDomain():
flagError = True
elif optObj.opt.has_key('mount'):
if not ldapObj.mountRemote():
flagError = True
if flagError:
sys.exit(1)
else:
sys.exit(0)

@ -33,6 +33,7 @@ if __name__ == "__main__":
terms = optObj.opt['vars'].split(",")
clVars = cl_base.DataVars()
clVars.flClient()
clVars.flIniFile()
if terms == ["all"]:
clVars.printVars()
else:

@ -119,6 +119,7 @@ setup(
package_dir = {'calculate-client': "."},
packages = ['calculate-client.pym'],
data_files = data_files,
scripts=["./scripts/cl-createhome"],
scripts=["./scripts/cl-createhome",
"./scripts/cl-client"],
ext_modules = [module1],
)

Loading…
Cancel
Save