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.

730 lines
26 KiB

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