You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

739 lines
26 KiB

12 years ago
11 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
  1. #-*- coding: utf-8 -*-
  2. # Copyright 2008-2010 Calculate Ltd. http://www.calculate-linux.org
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. import re
  16. import os
  17. import types
  18. import pwd, grp
  19. import cl_overriding
  20. from cl_vars_share import varsShare, clLocale
  21. from os.path import exists as pathexists
  22. from os import path
  23. from cl_utils import isMount, genpassword, \
  24. getAvailableVideo, process, \
  25. listDirectory,isPkgInstalled,lspci, readLinesFile, \
  26. getUdevDeviceInfo
  27. from utils import ip
  28. from encrypt import getHash
  29. class fillVars(varsShare):
  30. """Auxilary object for creating variables
  31. Contains filling methods"""
  32. addDn = lambda x,*y: ",".join(y)
  33. genDn = lambda x,*y: "=".join(y)
  34. def get_cl_env_path(self):
  35. """Path to env files"""
  36. envData = self.Get("cl_env_data")
  37. if envData:
  38. return map(lambda x: x[1], envData)
  39. else:
  40. cl_overriding.printERROR(_("Error:") + " " +\
  41. _("Template variable cl_env_data is empty"))
  42. cl_overriding.exit(1)
  43. def get_cl_env_location(self):
  44. """Aliases to env files"""
  45. envData = self.Get("cl_env_data")
  46. if envData:
  47. return map(lambda x: x[0], envData)
  48. else:
  49. cl_overriding.printERROR(_("Error:") + " " +\
  50. _("Template variable cl_env_data is empty"))
  51. cl_overriding.exit(1)
  52. def get_cl_env_server_path(self):
  53. """Paths to clt-template files"""
  54. return '/var/calculate/remote/server.env'
  55. def get_cl_template_path(self):
  56. """Paths to template files"""
  57. return ["/usr/share/calculate/templates",
  58. "/var/calculate/templates",
  59. "/var/calculate/remote/templates"]
  60. def get_cl_template_clt_path(self):
  61. """Path to 'clt' files"""
  62. if "CONFIG_PROTECT" in os.environ:
  63. protectPaths = ["/etc"] + filter(lambda x: x.strip(),
  64. os.environ["CONFIG_PROTECT"].split(" "))
  65. else:
  66. protectPaths = ["/etc", "/usr/share/X11/xkb", "var/lib/hsqldb",
  67. "/usr/share/config"]
  68. return filter(path.exists, protectPaths)
  69. def get_os_net_domain(self):
  70. """Get net domain name"""
  71. textLines = self._runos("hostname -d 2>&1")
  72. if textLines is False:
  73. cl_overriding.printERROR(_("Error executing 'hostname -d'"))
  74. return cl_overriding.exit(1)
  75. domain = ""
  76. if textLines:
  77. domain = textLines[0]
  78. if not domain:
  79. cl_overriding.printERROR(_("Error:") + " " +\
  80. _("Domain name not found"))
  81. cl_overriding.printERROR(\
  82. _("Command 'hostname -d' returns an empty value"))
  83. return cl_overriding.exit(1)
  84. elif re.search("^hostname: ",domain):
  85. return "local"
  86. else:
  87. return domain
  88. def get_os_linux_shortname(self):
  89. """Get short system name"""
  90. systemRoot = "/"
  91. return self.getShortnameByMakeprofile(systemRoot) or \
  92. self.getShortnameByIni(systemRoot) or \
  93. self.detectOtherShortname(systemRoot) or \
  94. "Linux"
  95. def get_os_linux_name(self):
  96. """Get full system name"""
  97. linuxShortName = self.Get("os_linux_shortname")
  98. return self.dictLinuxName.get(linuxShortName,"Linux")
  99. def get_os_linux_subname(self):
  100. """Get posfix name of system"""
  101. linuxShortName = self.Get("os_linux_shortname")
  102. return self.dictLinuxSubName.get(linuxShortName,"")
  103. def get_os_linux_ver(self):
  104. """Get system version"""
  105. linuxShortName = self.Get("os_linux_shortname")
  106. return self.getVersionFromMetapackage('/',linuxShortName) or \
  107. self.getVersionFromCalculateIni('/') or \
  108. self.getVersionFromGentooFiles('/') or \
  109. self.getVersionFromUname() or "0"
  110. def get_os_net_hostname(self):
  111. """Get hostname of computer"""
  112. textLines = self._runos("hostname -s 2>&1")
  113. hostname = ""
  114. if textLines:
  115. hostname = textLines[0]
  116. if not hostname:
  117. return ""
  118. if re.search("^hostname: ",hostname):
  119. textLines = self._runos("hostname 2>&1")
  120. if not textLines:
  121. return ""
  122. hostname = textLines[0]
  123. if re.search("^hostname: ",hostname):
  124. return self.Get('os_linux_shortname')
  125. else:
  126. if hostname=='livecd':
  127. return self.Get('os_linux_shortname')
  128. return hostname
  129. def get_os_net_ip(self):
  130. """All computer ip addresses, comma delimeter"""
  131. IPs = []
  132. netInterfaces=self.Get("os_net_interfaces")
  133. for i in netInterfaces:
  134. ipaddr, mask = ip.receiveIpAndMask(i)
  135. if ipaddr:
  136. IPs.append(ipaddr)
  137. return ",".join(IPs)
  138. def get_os_net_interfaces(self):
  139. """All net interfaces"""
  140. return filter(lambda x: x!="lo", self.getDirList("/sys/class/net"))
  141. def get_os_net_allow(self):
  142. """Allowed networks"""
  143. networks=[]
  144. netInterfaces=self.Get("os_net_interfaces")
  145. for i in netInterfaces:
  146. ipaddr, mask = ip.receiveIpAndMask(i)
  147. if ipaddr and mask:
  148. networks.append(ip.getIpNet(ipaddr, mask))
  149. else:
  150. networks.append("")
  151. return ",".join(filter(lambda x:x,networks))
  152. def get_os_arch_machine(self):
  153. """Processor architecture"""
  154. textLines = self._runos("uname -m")
  155. if not textLines:
  156. return ""
  157. march = textLines[0]
  158. return march
  159. def get_os_root_dev(self):
  160. """Root filesystem device"""
  161. record = open('/proc/cmdline','rb').read().strip()
  162. re_resRealRoot=re.search('(?:^|\s)real_root=(\S+)(\s|$)',record)
  163. re_resFakeRoot=re.search('(?:^|\s)root=(\S+)(\s|$)',record)
  164. # param real_root priority that root
  165. re_res = re_resRealRoot or re_resFakeRoot
  166. if re_res:
  167. rootparam=re_res.group(1)
  168. # check root for /dev/sd view
  169. if re.match("^\/dev\/[a-z]+.*$", rootparam):
  170. return getUdevDeviceInfo(
  171. name=rootparam.strip()).get('DEVNAME',rootparam)
  172. # check root set by uuid
  173. if re.match("^UUID=.*$",rootparam):
  174. uuid = rootparam[5:].strip("\"'")
  175. blkidProcess = process('/sbin/blkid','-c','/dev/null','-U',
  176. uuid)
  177. if blkidProcess.success():
  178. return getUdevDeviceInfo(
  179. name=blkidProcess.read().strip()).get('DEVNAME','')
  180. # check root set by label
  181. if re.match("^LABEL=.*$",rootparam):
  182. uuid = rootparam[6:].strip("\"'")
  183. blkidProcess = process('/sbin/blkid','-c','/dev/null','-L',
  184. uuid)
  185. if blkidProcess.success():
  186. return getUdevDeviceInfo(
  187. name=blkidProcess.read().strip()).get('DEVNAME','')
  188. # get device mounted to root
  189. dfLines = self._runos("LANG=C df /")
  190. if not dfLines:
  191. return ""
  192. if type(dfLines) == types.ListType and len(dfLines)>1:
  193. root_dev = dfLines[1].split(" ")[0].strip()
  194. if root_dev:
  195. return {'none':'/dev/ram0'}.get(root_dev,root_dev)
  196. return ""
  197. def get_os_root_type(self):
  198. """Root device type (ram, hdd, livecd)"""
  199. def link2pair(linkfile):
  200. """Return pair (target,link) from link"""
  201. basedir = os.path.dirname(linkfile)
  202. targetfile = os.readlink(linkfile)
  203. return (path.normpath(os.path.join(basedir,targetfile)),linkfile)
  204. rootDev = self.Get("os_root_dev")
  205. if rootDev:
  206. if "/dev/ram" in rootDev or "/dev/nfs" in rootDev:
  207. return "livecd"
  208. idDict = dict(map(link2pair,
  209. filter(lambda x:path.islink(x),
  210. map(lambda x:path.join('/dev/disk/by-id',x),
  211. listDirectory('/dev/disk/by-id')))))
  212. if "usb-" in idDict.get(rootDev,""):
  213. return "usb-hdd"
  214. return "hdd"
  215. def get_hr_cdrom_set(self):
  216. """Cdrom variable"""
  217. if os.path.exists('/sys/block/sr0'):
  218. textLines = self._runos(
  219. "udevadm info --query=all --name=/dev/dvdrw")
  220. if not textLines is False:
  221. for line in textLines:
  222. if "ID_CDROM=1" in line:
  223. return "on"
  224. return "off"
  225. def get_hr_virtual(self):
  226. """Virtual machine name (virtualbox, vmware, qemu)"""
  227. pciLines = self._runos("/usr/sbin/lspci")
  228. if not pciLines:
  229. return False
  230. virtSysDict = {'VirtualBox':'virtualbox',
  231. 'VMware':'vmware',
  232. 'Qumranet':'qemu'}
  233. virtName = ''
  234. for vName in virtSysDict.keys():
  235. if filter(lambda x: vName in x, pciLines):
  236. virtName = virtSysDict[vName]
  237. break
  238. return virtName
  239. def get_hr_board_model(self):
  240. """Get motherboard model"""
  241. modelFile = "/sys/class/dmi/id/board_name"
  242. try:
  243. return open(modelFile,"r").read().strip()
  244. except:
  245. return ""
  246. def get_hr_board_vendor(self):
  247. """Get motherboard vendor"""
  248. vendorFile = "/sys/class/dmi/id/board_vendor"
  249. try:
  250. return open(vendorFile,"r").read().strip()
  251. except:
  252. return ""
  253. def get_hr_cpu_num(self):
  254. """Get processors count"""
  255. cpuinfoFile = "/proc/cpuinfo"
  256. try:
  257. return len(["" for line in open(cpuinfoFile,"r").readlines()
  258. if line.startswith("processor")])
  259. except:
  260. return 1
  261. def get_os_locale_locale(self):
  262. """locale (example: ru_RU.UTF-8)"""
  263. locale = clLocale()
  264. # get locale from boot calculate param
  265. localeVal = self.getValueFromCmdLine("calculate",0)
  266. if locale.isLangExists(localeVal):
  267. return locale.getFieldByLang('locale',localeVal)
  268. else:
  269. localeVal = self.getValueFromConfig('/etc/env.d/02locale','LANG')
  270. if locale.isValueInFieldExists('locale',localeVal):
  271. return localeVal
  272. if os.environ.has_key("LANG") and os.environ["LANG"] != "C":
  273. return os.environ["LANG"]
  274. return locale.getFieldByLang("locale","default")
  275. def get_os_locale_lang(self):
  276. """lang (example: ru_RU)"""
  277. locale = clLocale()
  278. return locale.getLangByField("locale",self.Get('os_locale_locale'))
  279. def get_os_locale_language(self):
  280. """language (example: ru)"""
  281. locale = clLocale()
  282. return locale.getFieldByLang("language",self.Get('os_locale_lang'))
  283. def get_os_locale_xkb(self):
  284. """xkb layouts (example: en,ru)"""
  285. locale = clLocale()
  286. return locale.getFieldByLang("xkblayout",
  287. self.Get('os_locale_lang'))
  288. def get_os_locale_xkbname(self):
  289. """названия используемых раскладок клавиатуры для X"""
  290. localeXkb = self.Get("os_locale_xkb")
  291. if localeXkb:
  292. return localeXkb.split("(")[0]
  293. return ""
  294. def get_ur_login(self):
  295. """User login"""
  296. uid = os.getuid()
  297. try:
  298. userName = pwd.getpwuid(uid).pw_name
  299. except:
  300. return ""
  301. return userName
  302. def get_ur_group(self):
  303. """User group"""
  304. userName = self.Get('ur_login')
  305. groupName = ""
  306. if userName:
  307. try:
  308. gid = pwd.getpwnam(userName).pw_gid
  309. groupName = grp.getgrgid(gid).gr_name
  310. except:
  311. return ""
  312. return groupName
  313. def get_ur_fullname(self):
  314. """Full user name"""
  315. userName = self.Get('ur_login')
  316. fullName = ""
  317. if userName:
  318. try:
  319. fullName = pwd.getpwnam(userName).pw_gecos
  320. except:
  321. return ""
  322. return fullName
  323. def get_ur_jid(self):
  324. """Get user Jabber id"""
  325. userInfo = self.getUserInfo()
  326. userJID = ""
  327. if userInfo:
  328. userJID = userInfo["jid"]
  329. return userJID
  330. def get_ur_mail(self):
  331. """Get user email"""
  332. userInfo = self.getUserInfo()
  333. userMail = ""
  334. if userInfo:
  335. userMail = userInfo["mail"]
  336. return userMail
  337. def get_ur_home_path(self):
  338. """Get user home directory"""
  339. userName = self.Get('ur_login')
  340. homeDir = ""
  341. if userName:
  342. try:
  343. homeDir = pwd.getpwnam(userName).pw_dir
  344. except:
  345. return ""
  346. return homeDir
  347. def get_os_linux_system(self):
  348. """Get linux system (server or desktop)"""
  349. shortName = self.Get('os_linux_shortname')
  350. return self.dictNameSystem.get(shortName,"")
  351. def get_os_x11_video_drv(self):
  352. """Get video driver used by xorg"""
  353. xorg_conf = '/etc/X11/xorg.conf'
  354. # Try analize Xorg.{DISPLAY}.log
  355. display = os.environ.get('DISPLAY')
  356. list_available_drivers = \
  357. getAvailableVideo(prefix=self.Get('cl_chroot_path'))
  358. if display and list_available_drivers:
  359. reDriver = re.compile('|'.join(map(lambda x: "%s_drv.so"%x,
  360. list_available_drivers)))
  361. display_number = re.search(r':(\d+)(\..*)?', display)
  362. reDriverName = re.compile(r'([^/]+)_drv.so')
  363. if display_number:
  364. xorg_log_file = '/var/log/Xorg.%s.log' % \
  365. display_number.group(1)
  366. if path.exists(xorg_log_file):
  367. matchStrs = \
  368. map(lambda x:x.group(1),
  369. filter(lambda x:x,
  370. map(reDriverName.search,
  371. filter(lambda x:"drv" in x and reDriver.search(x),
  372. readLinesFile(xorg_log_file)))))
  373. if matchStrs:
  374. return matchStrs[-1]
  375. # analize /etc/X11/xorg.conf
  376. if path.exists(xorg_conf):
  377. matchSect = re.search(r'Section "Device".*?EndSection',
  378. open('/etc/X11/xorg.conf').read(),re.S)
  379. if matchSect:
  380. resDriver = re.search(r'^\S*Driver\s*"([^"]+)"',
  381. matchSect.group(0),re.S)
  382. if resDriver and resDriver.group(1) in list_available_drivers:
  383. return resDriver.group(1)
  384. videoVal = self.getValueFromCmdLine("calculate","video")
  385. videoVal = {'i915':'intel'}.get(videoVal,videoVal)
  386. if not isPkgInstalled('xorg-server') or \
  387. videoVal in list_available_drivers:
  388. return videoVal
  389. return self.getVideoByDefault(list_available_drivers)
  390. def getResByXDpyInfo(self):
  391. """Get resolution by xdpyinfo utility"""
  392. lines=self._runos("xdpyinfo")
  393. if not lines:
  394. return ""
  395. reRes = re.compile("dimensions:\s+(\d+)x(\d+)\s+pixels")
  396. searchRes=False
  397. for line in lines:
  398. searchRes = reRes.search(line)
  399. if searchRes:
  400. break
  401. if searchRes:
  402. return "%sx%s"%(searchRes.group(1), searchRes.group(2))
  403. return ""
  404. def get_os_x11_resolution(self):
  405. """
  406. Return current screen resolution (width, height).
  407. Try detect by xdpyinfo, then Xorg.log, xorg.conf
  408. """
  409. resolution = self.getResByXDpyInfo()
  410. if resolution:
  411. return resolution
  412. if self.Get('os_root_type') != 'usb-hdd':
  413. xlog = "/var/log/Xorg.0.log"
  414. if os.access(xlog,os.R_OK):
  415. reXorgLogParser = re.compile("""
  416. Virtual\ screen\ size\ determined\ to\ be
  417. \ ([0-9]+)\s*x\s*([0-9]+)|
  418. Setting\ mode\ "(\d+)x(\d+)[0-9\@]"|
  419. Output\ [\S]+\ using\ initial\ mode\ (\d+)x(\d+)|
  420. Virtual\ size\ is\ (\d+)x(\d+)""", re.X | re.S)
  421. resXorgLogParser = reXorgLogParser.search(open(xlog,'r').read())
  422. if resXorgLogParser:
  423. return "%sx%s"%filter(lambda x:x,
  424. resXorgLogParser.groups())[:2]
  425. # get resolution from xorg.conf
  426. xorgconf = "/etc/X11/xorg.conf"
  427. reScreenSections = re.compile('Section "Screen"(.*?)EndSection',
  428. re.S)
  429. reModes = re.compile('Modes\s+"(\d+x\d+)')
  430. if os.access(xorgconf,os.R_OK):
  431. sectionsScreen = filter(lambda x:"Modes" in x,
  432. reScreenSections.findall(open('/etc/X11/xorg.conf',
  433. 'r').read()))
  434. modes = map(lambda x:x.groups()[0],
  435. filter(lambda x:x,
  436. map(reModes.search, sectionsScreen)))
  437. if modes:
  438. return max(modes,key=lambda x:int(x.partition('x')[0]))
  439. # get resolution from command line
  440. reRightResolution = re.compile("^(\d+x\d+|auto)$",re.S)
  441. kernelResolution = self.getValueFromCmdLine("calculate",3)
  442. if kernelResolution and reRightResolution.match(kernelResolution):
  443. return {'auto':''}.get(kernelResolution,kernelResolution)
  444. else:
  445. return ""
  446. def get_os_x11_height(self):
  447. """Get screen height in pixeles"""
  448. return self.Get('os_x11_resolution').partition('x')[2] or "768"
  449. def get_os_x11_width(self):
  450. """Get screen width in pixeles"""
  451. return self.Get('os_x11_resolution').partition('x')[0] or "1024"
  452. def get_os_x11_standart(self):
  453. """Get the nearest standard size of image relative current
  454. screen resolution"""
  455. #Стандартные разрешения
  456. widthVal = self.Get('os_x11_width')
  457. heightVal = self.Get('os_x11_height')
  458. if not widthVal or not heightVal:
  459. return ""
  460. width = int(widthVal)
  461. height = int(heightVal)
  462. res = [(1024,600),
  463. (1024,768),
  464. (1280,1024),
  465. (1280,800),
  466. (1366,768),
  467. (1440,900),
  468. (1600,1200),
  469. (1680,1050),
  470. (1920,1200)]
  471. resolution = []
  472. formats = []
  473. for w, h in res:
  474. formats.append(float(w)/float(h))
  475. listFr = list(set(formats))
  476. listFormats = {}
  477. for fr in listFr:
  478. listFormats[fr] = []
  479. for w, h in res:
  480. for fr in listFormats.keys():
  481. if fr == float(w)/float(h):
  482. listFormats[fr].append((w,h))
  483. break
  484. format = float(width)/float(height)
  485. deltaFr = {}
  486. for fr in listFormats.keys():
  487. deltaFr[abs(format - fr)] = fr
  488. resolution = listFormats[deltaFr[min(deltaFr.keys())]]
  489. flagFound = False
  490. stResol = []
  491. stHeights = []
  492. stWidths = []
  493. stWidth = False
  494. stHeight = False
  495. for w, h in resolution:
  496. if w >= width and h >= height:
  497. stResol.append((w,h))
  498. stHeights.append(h)
  499. if stHeights:
  500. stHeight = min(stHeights)
  501. for w, h in stResol:
  502. if stHeight == h:
  503. stWidths.append(w)
  504. if stWidths:
  505. stWidth = min(stWidths)
  506. if (not stWidth) or (not stHeight):
  507. return "%sx%s"%(resolution[-1][0],resolution[-1][1])
  508. else:
  509. return "%sx%s"%(stWidth,stHeight)
  510. def get_os_x11_composite(self):
  511. """On or off composite mode"""
  512. state = self.get_composite_from_xorgconf()
  513. return state or "off"
  514. def get_hr_laptop(self):
  515. """Laptop vendor"""
  516. chassisType = '/sys/class/dmi/id/chassis_type'
  517. boardVendor = '/sys/class/dmi/id/board_vendor'
  518. if os.access(chassisType,os.R_OK) and \
  519. os.access(boardVendor,os.R_OK):
  520. chassis = open(chassisType,'r').read().strip()
  521. notebookChassis = ['1','8','10']
  522. if chassis in notebookChassis:
  523. valBoardVendor = open(boardVendor,'r').read().strip()
  524. return valBoardVendor.split(" ")[0].lower() or \
  525. "unknown"
  526. return ""
  527. def get_hr_laptop_model(self):
  528. """Laptop name"""
  529. boardName = '/sys/class/dmi/id/board_name'
  530. if self.Get('hr_laptop') and os.access(boardName,os.R_OK):
  531. valBoardName = open(boardName,'r').read().strip()
  532. return valBoardName or "unknown"
  533. return ""
  534. def get_hr_video_name(self):
  535. """Get video name"""
  536. pciVideo = list(sorted(lspci("VGA compatible").items()))
  537. if pciVideo:
  538. pciVideo = pciVideo[0][1]
  539. vendor=pciVideo.get("vendor","").split(" ")[0]
  540. name=pciVideo.get("name","")
  541. if "[" in name and "]" in name:
  542. name = name.partition("[")[2].partition("]")[0]
  543. return "{vendor} {name}".format(vendor=vendor,name=name)
  544. return ""
  545. def get_hr_video(self):
  546. """Videocard vendor"""
  547. line = self.Get('hr_video_name')
  548. if "nVidia" in line or "GeForce" in line:
  549. return "nvidia"
  550. elif "ATI" in line:
  551. return "ati"
  552. elif "Intel" in line:
  553. return "intel"
  554. elif "VIA" in line:
  555. return "via"
  556. elif "VMware" in line:
  557. return "vmware"
  558. else:
  559. return "other"
  560. def get_cl_kernel_uid(self):
  561. """Get UID of symlink kernel, initramfs and System.map"""
  562. return self.getKernelUid(self.Get('os_root_dev'))
  563. def get_cl_chroot_status(self):
  564. """Detect chroot mode by mtab content"""
  565. try:
  566. return "on" if self.isChroot(os.getpid()) else "off"
  567. except:
  568. return "off"
  569. def get_os_scratch(self):
  570. """Current system is scratch"""
  571. if self.Get('os_root_type') == 'livecd':
  572. return "on" if isMount('/mnt/scratch/workspace') else "off"
  573. else:
  574. return "on" if isMount('/mnt/scratch') else "off"
  575. def get_cl_root_path(self):
  576. """Path to directory relative which perform joining templates to
  577. system files (sandbox)"""
  578. return '/'
  579. def get_cl_chroot_path(self):
  580. """Path to directory which contain other system"""
  581. return '/'
  582. def get_cl_autoupdate_set(self):
  583. """(on or off) autoupdate config from install program"""
  584. return 'off'
  585. def get_cl_api(self):
  586. """The path to the module api,
  587. and additional parameters caluclate packages"""
  588. return {}
  589. def get_ld_encrypt(self):
  590. """hash crypto algoritm"""
  591. return 'ssha'
  592. def get_ld_bind_login(self):
  593. """bind login"""
  594. return 'proxyuser'
  595. def get_ld_base_root(self):
  596. """base name LDAP"""
  597. return 'calculate'
  598. def get_ld_base_dn(self):
  599. """base DN LDAP"""
  600. return self.genDn("dc", self.Get('ld_base_root'))
  601. def get_ld_bind_dn(self):
  602. """bind DN LDAP"""
  603. return self.addDn(self.genDn("cn", self.Get('ld_bind_login')),
  604. self.Get('ld_base_dn'))
  605. def get_ld_bind_pw(self):
  606. """bind password"""
  607. return 'calculate'
  608. def get_ld_bind_hash(self):
  609. """hash bind"""
  610. return getHash(self.Get('ld_bind_pw'), self.Get('ld_encrypt'))
  611. def get_ld_admin_login(self):
  612. """administrator name"""
  613. return 'ldapadmin'
  614. def get_ld_admin_dn(self):
  615. """root DN"""
  616. return self.addDn(self.genDn("cn", self.Get('ld_admin_login')),
  617. self.Get('ld_base_dn'))
  618. def get_ld_admin_hash(self):
  619. """root hash"""
  620. return getHash(self.Get('ld_admin_pw'), self.Get('ld_encrypt'))
  621. def get_ld_admin_pw(self):
  622. """password root"""
  623. return genpassword()
  624. def get_ld_services(self):
  625. """Name from all services"""
  626. return 'Services'
  627. def get_ld_services_dn(self):
  628. """DN from all services"""
  629. return self.addDn(self.genDn("ou", self.Get('ld_services')),
  630. self.Get('ld_base_dn'))
  631. def get_cl_ca_cert(self):
  632. """CA certificate"""
  633. return 'CA.crt'
  634. def get_cl_ca_key(self):
  635. """CA key"""
  636. return 'CA.key'
  637. def get_cl_ca_path(self):
  638. """CA path"""
  639. return '/var/calculate/ssl/main'
  640. def get_os_clock_timezone(self):
  641. """Current clock timezone"""
  642. zoneinfodir = "/usr/share/zoneinfo/"
  643. localtimefile = "/etc/localtime"
  644. timezonefile = "/etc/timezone"
  645. # try get timezone from kernel calculate param
  646. timezone = self.getValueFromCmdLine("calculate",2)
  647. if timezone and \
  648. path.exists(path.join(zoneinfodir,timezone)):
  649. return timezone
  650. # get timezone from /etc/timezone
  651. if path.exists(timezonefile):
  652. return open(timezonefile,"r").read().strip()
  653. return "UTC"
  654. def get_os_lang(self):
  655. """Supported languages"""
  656. return list(sorted(list(set(clLocale().getLangs()) &
  657. set(["en_US","de_DE","es_ES","fr_FR","it_IT","pl_PL","pt_BR",
  658. "uk_UA","bg_BG","ru_RU","ro_RO","pt_PT"]))))