View | Details | Raw Unified | Return to bug 33008
Collapse All | Expand All

(-)a/branches/ucs-3.2/ucs-3.2-0/base/univention-system-setup/umc/python/setup/util.py (-5 / +45 lines)
Lines 46-51 import psutil Link Here
46
import csv
46
import csv
47
import imp
47
import imp
48
import os.path
48
import os.path
49
import socket
49
50
50
from univention.lib.i18n import Translation
51
from univention.lib.i18n import Translation
51
from univention.management.console.log import MODULE
52
from univention.management.console.log import MODULE
Lines 96-104 UCR_VARIABLES = [ Link Here
96
	'ssl/organization', 'ssl/organizationalunit', 'ssl/email',
97
	'ssl/organization', 'ssl/organizationalunit', 'ssl/email',
97
]
98
]
98
99
100
99
def timestamp():
101
def timestamp():
100
	return time.strftime('%Y-%m-%d %H:%M:%S')
102
	return time.strftime('%Y-%m-%d %H:%M:%S')
101
103
104
102
def load_values():
105
def load_values():
103
	# load UCR variables
106
	# load UCR variables
104
	ucr.load()
107
	ucr.load()
Lines 128-133 def load_values(): Link Here
128
131
129
	return values
132
	return values
130
133
134
131
def _xkeymap(keymap):
135
def _xkeymap(keymap):
132
	'''Determine the x-keymap which belongs to 'keymap' by
136
	'''Determine the x-keymap which belongs to 'keymap' by
133
	parsing /lib/univention-installer/locale/all-kmaps'''
137
	parsing /lib/univention-installer/locale/all-kmaps'''
Lines 176-185 def pre_save(newValues): Link Here
176
		installComponents = list(allComponents & (selectedComponents - currentComponents))
180
		installComponents = list(allComponents & (selectedComponents - currentComponents))
177
		newValues['packages_install'] = ' '.join([ i.replace(':', ' ') for i in installComponents ])
181
		newValues['packages_install'] = ' '.join([ i.replace(':', ' ') for i in installComponents ])
178
182
179
#	if 'locale' in newValues:
180
#		# js returns locale as list
181
#		newValues['locale'] = ' '.join(newValues['locale'])
182
183
	if 'locale/keymap' in newValues:
183
	if 'locale/keymap' in newValues:
184
		xkeymap = _xkeymap(newValues['locale/keymap'])
184
		xkeymap = _xkeymap(newValues['locale/keymap'])
185
		if xkeymap:
185
		if xkeymap:
Lines 196-201 def write_profile(values): Link Here
196
	finally:
196
	finally:
197
		os.umask(old_umask)
197
		os.umask(old_umask)
198
198
199
199
class ProgressState( object ):
200
class ProgressState( object ):
200
	def __init__( self ):
201
	def __init__( self ):
201
		self.reset()
202
		self.reset()
Lines 225-230 class ProgressState( object ): Link Here
225
	def __nonzero__( self ):
226
	def __nonzero__( self ):
226
		return bool( self.name or self.message or self.percentage or self._join_error or self._misc_error )
227
		return bool( self.name or self.message or self.percentage or self._join_error or self._misc_error )
227
228
229
228
class ProgressParser( object ):
230
class ProgressParser( object ):
229
	# regular expressions
231
	# regular expressions
230
	NAME = re.compile( '^__NAME__: *(?P<key>[^ ]*) (?P<name>.*)\n$' )
232
	NAME = re.compile( '^__NAME__: *(?P<key>[^ ]*) (?P<name>.*)\n$' )
Lines 339-344 class ProgressParser( object ): Link Here
339
341
340
		return False
342
		return False
341
343
344
342
def sorted_files_in_subdirs( directory ):
345
def sorted_files_in_subdirs( directory ):
343
	for entry in sorted(os.listdir(directory)):
346
	for entry in sorted(os.listdir(directory)):
344
		path = os.path.join(directory, entry)
347
		path = os.path.join(directory, entry)
Lines 346-357 def sorted_files_in_subdirs( directory ): Link Here
346
			for filename in sorted(os.listdir(path)):
349
			for filename in sorted(os.listdir(path)):
347
				yield os.path.join(path, filename)
350
				yield os.path.join(path, filename)
348
351
352
353
LDAP_STATE_FILE = "/var/run/univention-system-setup.ldap"
354
def check_ldap_access():
355
	sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
356
	sock.settimeout(10)
357
	try:
358
		sock.connect((ucr["ldap/master"], 7389))
359
		value = "ldap"
360
	except socket.error:
361
		value = "no-ldap"
362
	sock.close()
363
	with open(LDAP_STATE_FILE, "w") as state_file:
364
		print >> state_file, value
365
366
349
def run_scripts( progressParser, restartServer = False ):
367
def run_scripts( progressParser, restartServer = False ):
350
	# write header before executing scripts
368
	# write header before executing scripts
351
	f = open(LOG_FILE, 'a')
369
	f = open(LOG_FILE, 'a')
352
	f.write('\n\n=== RUNNING SETUP SCRIPTS (%s) ===\n\n' % timestamp())
370
	f.write('\n\n=== RUNNING SETUP SCRIPTS (%s) ===\n\n' % timestamp())
353
	f.flush()
371
	f.flush()
354
372
373
	check_ldap_access()
374
355
	# make sure that UMC servers and apache will not be restartet
375
	# make sure that UMC servers and apache will not be restartet
356
	subprocess.call( CMD_DISABLE_EXEC, stdout = f, stderr = f )
376
	subprocess.call( CMD_DISABLE_EXEC, stdout = f, stderr = f )
357
377
Lines 370-375 def run_scripts( progressParser, restartServer = False ): Link Here
370
	# enable execution of servers again
390
	# enable execution of servers again
371
	subprocess.call(CMD_ENABLE_EXEC, stdout=f, stderr=f)
391
	subprocess.call(CMD_ENABLE_EXEC, stdout=f, stderr=f)
372
392
393
	os.unlink(LDAP_STATE_FILE)
394
373
	if restartServer:
395
	if restartServer:
374
		f.write('=== Restart of UMC server and web server (%s) ===\n' % timestamp())
396
		f.write('=== Restart of UMC server and web server (%s) ===\n' % timestamp())
375
		f.flush()
397
		f.flush()
Lines 379-384 def run_scripts( progressParser, restartServer = False ): Link Here
379
	f.write('\n=== DONE (%s) ===\n\n' % timestamp())
401
	f.write('\n=== DONE (%s) ===\n\n' % timestamp())
380
	f.close()
402
	f.close()
381
403
404
382
def run_joinscript( progressParser, _username, password ):
405
def run_joinscript( progressParser, _username, password ):
383
	# write header before executing join script
406
	# write header before executing join script
384
	f = open(LOG_FILE, 'a')
407
	f = open(LOG_FILE, 'a')
Lines 421-426 def run_joinscript( progressParser, _username, password ): Link Here
421
	f.write('\n=== DONE (%s) ===\n\n' % timestamp())
444
	f.write('\n=== DONE (%s) ===\n\n' % timestamp())
422
	f.close()
445
	f.close()
423
446
447
424
def cleanup():
448
def cleanup():
425
	# write header before executing scripts
449
	# write header before executing scripts
426
	f = open(LOG_FILE, 'a')
450
	f = open(LOG_FILE, 'a')
Lines 472-477 def cleanup(): Link Here
472
496
473
	return True
497
	return True
474
498
499
475
def detect_interfaces():
500
def detect_interfaces():
476
	"""
501
	"""
477
	Function to detect network interfaces in local sysfs.
502
	Function to detect network interfaces in local sysfs.
Lines 505-510 def detect_interfaces(): Link Here
505
530
506
	return interfaces
531
	return interfaces
507
532
533
508
def dhclient(interface, timeout=None):
534
def dhclient(interface, timeout=None):
509
	"""
535
	"""
510
	perform DHCP request for specified interface. If succesful, returns a dict
536
	perform DHCP request for specified interface. If succesful, returns a dict
Lines 564-569 def dhclient(interface, timeout=None): Link Here
564
	os.unlink(tempfilename)
590
	os.unlink(tempfilename)
565
	return dhcp_dict
591
	return dhcp_dict
566
592
593
567
def get_components(role=None):
594
def get_components(role=None):
568
	'''Returns a list of components that may be installed on the current system.'''
595
	'''Returns a list of components that may be installed on the current system.'''
569
596
Lines 597-613 def get_components(role=None): Link Here
597
624
598
	return pkglist
625
	return pkglist
599
626
627
600
def get_installed_packages():
628
def get_installed_packages():
601
	'''Returns a list of all installed packages on the system.'''
629
	'''Returns a list of all installed packages on the system.'''
602
	cache = apt.Cache()
630
	cache = apt.Cache()
603
	return [ p.name for p in cache if p.is_installed ]
631
	return [ p.name for p in cache if p.is_installed ]
604
632
633
605
def get_installed_components():
634
def get_installed_components():
606
	'''Returns a list of components that are currently fully installed on the system.'''
635
	'''Returns a list of components that are currently fully installed on the system.'''
607
	allPackages = set(get_installed_packages())
636
	allPackages = set(get_installed_packages())
608
	allComponents = get_components()
637
	allComponents = get_components()
609
	return [ icomp for icomp in allComponents if not len(set(icomp['Packages']) - allPackages) ]
638
	return [ icomp for icomp in allComponents if not len(set(icomp['Packages']) - allPackages) ]
610
639
640
611
# from univention-installer/installer/modules/70_net.py
641
# from univention-installer/installer/modules/70_net.py
612
def is_proxy(proxy):
642
def is_proxy(proxy):
613
	if proxy and proxy != 'http://' and proxy != 'https://':
643
	if proxy and proxy != 'http://' and proxy != 'https://':
Lines 615-620 def is_proxy(proxy): Link Here
615
			return False
645
			return False
616
	return True
646
	return True
617
647
648
618
def is_ipaddr(addr):
649
def is_ipaddr(addr):
619
	try:
650
	try:
620
		ipaddr.IPAddress(addr)
651
		ipaddr.IPAddress(addr)
Lines 622-627 def is_ipaddr(addr): Link Here
622
		return False
653
		return False
623
	return True
654
	return True
624
655
656
625
def is_ipv4addr(addr):
657
def is_ipv4addr(addr):
626
	try:
658
	try:
627
		ipaddr.IPv4Address(addr)
659
		ipaddr.IPv4Address(addr)
Lines 629-634 def is_ipv4addr(addr): Link Here
629
		return False
661
		return False
630
	return True
662
	return True
631
663
664
632
def is_ipv4netmask(addr_netmask):
665
def is_ipv4netmask(addr_netmask):
633
	try:
666
	try:
634
		ipaddr.IPv4Network(addr_netmask)
667
		ipaddr.IPv4Network(addr_netmask)
Lines 636-641 def is_ipv4netmask(addr_netmask): Link Here
636
		return False
669
		return False
637
	return True
670
	return True
638
671
672
639
def is_ipv6addr(addr):
673
def is_ipv6addr(addr):
640
	try:
674
	try:
641
		ipaddr.IPv6Address(addr)
675
		ipaddr.IPv6Address(addr)
Lines 643-648 def is_ipv6addr(addr): Link Here
643
		return False
677
		return False
644
	return True
678
	return True
645
679
680
646
def is_ipv6netmask(addr_netmask):
681
def is_ipv6netmask(addr_netmask):
647
	try:
682
	try:
648
		ipaddr.IPv6Network(addr_netmask)
683
		ipaddr.IPv6Network(addr_netmask)
Lines 650-660 def is_ipv6netmask(addr_netmask): Link Here
650
		return False
685
		return False
651
	return True
686
	return True
652
687
688
653
# from univention-installer/installer/objects.py
689
# from univention-installer/installer/objects.py
654
def is_hostname(hostname):
690
def is_hostname(hostname):
655
	return is_hostname.RE.match(hostname) is not None
691
	return is_hostname.RE.match(hostname) is not None
656
is_hostname.RE = re.compile("^[a-z]([a-z0-9-]*[a-z0-9])*$")
692
is_hostname.RE = re.compile("^[a-z]([a-z0-9-]*[a-z0-9])*$")
657
693
694
658
def is_domainname(domainname):
695
def is_domainname(domainname):
659
	"""
696
	"""
660
	Check if domainname is a valid DNS domainname accoring to RFC952/1123.
697
	Check if domainname is a valid DNS domainname accoring to RFC952/1123.
Lines 676-689 def is_domainname(domainname): Link Here
676
	return all(is_domainname.RE.match(_) for _ in domainname.split('.'))
713
	return all(is_domainname.RE.match(_) for _ in domainname.split('.'))
677
is_domainname.RE = re.compile(r'^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$', re.I)
714
is_domainname.RE = re.compile(r'^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$', re.I)
678
715
716
679
def is_windowsdomainname(domainname):
717
def is_windowsdomainname(domainname):
680
	return is_windowsdomainname.RE.match(domainname) is not None
718
	return is_windowsdomainname.RE.match(domainname) is not None
681
is_windowsdomainname.RE = re.compile(r"^[A-Z](?:[A-Z0-9-]*[A-Z0-9])?$")
719
is_windowsdomainname.RE = re.compile(r"^[A-Z](?:[A-Z0-9-]*[A-Z0-9])?$")
682
720
721
683
def is_domaincontroller(domaincontroller):
722
def is_domaincontroller(domaincontroller):
684
	return is_domaincontroller.RE.match(domaincontroller) is not None
723
	return is_domaincontroller.RE.match(domaincontroller) is not None
685
is_domaincontroller.RE = re.compile("^[a-zA-Z].*\..*$")
724
is_domaincontroller.RE = re.compile("^[a-zA-Z].*\..*$")
686
725
726
687
# new defined methods
727
# new defined methods
688
def is_ascii(str):
728
def is_ascii(str):
689
	try:
729
	try:
Lines 692-697 def is_ascii(str): Link Here
692
	except:
732
	except:
693
		return False
733
		return False
694
734
735
695
def get_available_locales(pattern, category='language_en'):
736
def get_available_locales(pattern, category='language_en'):
696
	'''Return a list of all available locales.'''
737
	'''Return a list of all available locales.'''
697
	try:
738
	try:
Lines 760-763 def get_available_locales(pattern, category='language_en'): Link Here
760
			})
801
			})
761
802
762
	return locales
803
	return locales
763

Return to bug 33008