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

(-)univention-thin-client-flash/univention-thin-client-flash-status (+150 lines)
Line 0    Link Here 
1
#!/usr/bin/python2.4
2
#
3
# Univention Thin Client Flash status
4
#
5
# Copyright (C) 2011 Univention GmbH
6
#
7
# http://www.univention.de/
8
#
9
# All rights reserved.
10
#
11
# This program is free software; you can redistribute it and/or modify
12
# it under the terms of the GNU General Public License version 2 as
13
# published by the Free Software Foundation.
14
#
15
# Binary versions of this file provided by Univention to you as
16
# well as other copyrighted, protected or trademarked materials like
17
# Logos, graphics, fonts, specific documentations and configurations,
18
# cryptographic keys etc. are subject to a license agreement between
19
# you and Univention.
20
#
21
# This program is distributed in the hope that it will be useful,
22
# but WITHOUT ANY WARRANTY; without even the implied warranty of
23
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	See the
24
# GNU General Public License for more details.
25
#
26
# You should have received a copy of the GNU General Public License
27
# along with this program; if not, write to the Free Software
28
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA	 02110-1301	 USA
29
30
LOG_DIR = '/var/log/univention-thin-client-flash-status/'
31
DATE_FORMAT = '%Y-%m-%d %H:%M'
32
FORMAT = 'hostname,mac,ip,image,version,status,time'
33
34
import sys
35
import univention.config_registry
36
import csv
37
import time
38
import optparse
39
import gzip
40
import glob
41
42
# usage
43
usage = "usage: %prog [options]\n\n"
44
usage += "This program reads the thin-client status logs from\n"
45
usage += "%s*\n" % LOG_DIR
46
usage += "and prints the newest status line for each thin-client \n"
47
usage += "to stdout or into a tab separated csv file."
48
49
# options
50
parser = optparse.OptionParser(usage=usage)
51
parser.add_option("-o", "--output-file", dest="outFile", help="write status to csv file")
52
parser.add_option("-f", "--format", dest="format", help="output format, ,-separated list of elements time, hostname, mac, ip, domainname, nameserver, ldapserver, image, version, newversion, url, partition, rootpart, bootpart, status (default: %s)" % FORMAT)
53
parser.add_option("-d", "--date-format", dest="dateFormat", help="date format in output (default: %s)" % DATE_FORMAT)
54
parser.add_option("-i", "--input-directory", dest="directory", help="directory to look for *.log and *.gz log files (default: %s)" % LOG_DIR)
55
parser.add_option("-n", "--host-history", dest="hostname", help="show all log messages for HOSTNAME")
56
parser.set_defaults(format = FORMAT, dateFormat = DATE_FORMAT, directory = LOG_DIR)
57
options, args = parser.parse_args()
58
59
# output format
60
format = options.format.split(",")
61
62
# get files in log dir
63
files = glob.glob(options.directory + "/*.gz") + glob.glob(options.directory + "/*.log")
64
65
# open log and read data into data dict
66
data = {}
67
lineCounter = 0
68
for file in files:
69
70
	# open the log or gzip file
71
	try:
72
		if file.endswith(".gz"):
73
			fh = gzip.open(file, "rb")
74
		else:
75
			fh = open(file, "rb")
76
	except IOError, e:
77
		print e
78
		sys.exit(1)
79
80
	# read csv file line per line
81
	reader = csv.reader(fh, delimiter='\t', quotechar='|', quoting=csv.QUOTE_MINIMAL)
82
	for row in reader:
83
84
		# get key=value elements
85
		tmp = {}
86
		for element in row:
87
			keyValue = element.split("=", 1)
88
			if len(keyValue) >= 2:
89
				tmp[keyValue[0]] = keyValue[1]
90
	
91
		tmp["logfile"] = file
92
		hostname = tmp.get("hostname", "")
93
94
		if options.hostname:
95
			if options.hostname == hostname:
96
				hostname = hostname + str(lineCounter)
97
			else:
98
				continue
99
100
		# convert time
101
		if tmp.get("time", ""):
102
			tmp["time"] = time.strftime(options.dateFormat, time.localtime(float(tmp["time"])))
103
104
		# ignore entries without hostname and store data in data dict
105
		if hostname:
106
			data[hostname] = tmp
107
108
		lineCounter += 1
109
	fh.close()
110
111
if options.hostname:
112
	# sort entries by time (if time is not present ==> order is untouched)
113
	clients = data.items()
114
	clients.sort(lambda x,y: cmp(x[1].get('time'), y[1].get('time')))
115
	clients = [ x[0] for x in clients ]
116
else:
117
	# sort entries by hostname
118
	clients = sorted(data.keys())
119
120
# print output to csv file
121
if options.outFile:
122
	try:
123
		header = {}
124
		for e in format:
125
			header[e] = 1
126
		out = csv.DictWriter(open(options.outFile, 'wb'), 
127
				delimiter="\t", quotechar='|', 
128
				quoting=csv.QUOTE_MINIMAL, fieldnames=format)
129
	except IOError, e:
130
		print e
131
		sys.exit(1)
132
133
	# write header
134
	header = {}
135
	for i in format:
136
		header[i] = i
137
	out.writerow(header)
138
139
	# write data
140
	for client in clients:
141
		row = {}
142
		for element in format:
143
			row[element] = data[client].get(element, "None")
144
		out.writerow(row)
145
# print output to stdout
146
else:
147
	for client in clients:
148
		print "Hostname: " + data[client].get("hostname", "None")
149
		for element in format:
150
			print "\t" + element + ": " + data[client].get(element, "None")
0
  + *
151
  + *
(-)univention-thin-client-flash/debian/logrotate (+7 lines)
Line 0    Link Here 
1
/var/log/univention-thin-client-flash-status/*.log {
2
	weekly
3
	rotate 12
4
	create 640 www-data adm
5
	compress
6
	missingok
7
}
(-)univention-thin-client-flash/debian/dirs (+2 lines)
 Lines 5-7    Link Here 
5
usr/share/univention-thin-client-flash/
5
usr/share/univention-thin-client-flash/
6
var/www/univention-thin-client-flash/
6
var/www/univention-thin-client-flash/
7
usr/lib/univention-install/
7
usr/lib/univention-install/
8
var/log/univention-thin-client-flash-status
9
etc/logrotate.d
(-)univention-thin-client-flash/debian/postinst (+3 lines)
 Lines 40-45    Link Here 
40
40
41
univention-config-registry set thinclient/flashupdate/via/flash?yes
41
univention-config-registry set thinclient/flashupdate/via/flash?yes
42
42
43
touch /var/log/univention-thin-client-flash-status/thin-client-flash-status.log
44
chown www-data:adm /var/log/univention-thin-client-flash-status/thin-client-flash-status.log
45
43
/etc/univention/templates/scripts/thin-client-bootsplash.py || true
46
/etc/univention/templates/scripts/thin-client-bootsplash.py || true
44
47
45
if [ "$server_role" = "domaincontroller_master" ]; then
48
if [ "$server_role" = "domaincontroller_master" ]; then
(-)univention-thin-client-flash/debian/changelog (+100 lines)
 Lines 1-3    Link Here 
1
univention-thin-client-flash (6.1.14-1) unstable; urgency=low
2
3
  * respect pxe/loglevel in tc's extlinux.conf Ticket: #2011030910000975 
4
5
 -- Felix Botner <botner@univention.de>  Thu, 18 Aug 2011 09:42:09 +0200
6
7
univention-thin-client-flash (6.1.13-1) unstable; urgency=low
8
9
  * fixed flashupdate script in initrd Ticket: #2011030710000906
10
11
 -- Felix Botner <botner@univention.de>  Wed, 17 Aug 2011 09:10:51 +0200
12
13
univention-thin-client-flash (6.1.12-1) unstable; urgency=low
14
15
  * stop usplash on flashupdate Ticket: #2011041210005499 
16
17
 -- Felix Botner <botner@univention.de>  Tue, 16 Aug 2011 11:32:04 +0200
18
19
univention-thin-client-flash (6.1.11-1) unstable; urgency=low
20
21
  * merged changes from customer scope Ticket: #2011041210005499
22
23
 -- Felix Botner <botner@univention.de>  Mon, 15 Aug 2011 16:09:40 +0200
24
25
univention-thin-client-flash (6.1.10-1) unstable; urgency=low
26
27
  * fixed flashupdate Ticket #2011030710000906 
28
29
 -- Felix Botner <botner@univention.de>  Thu, 14 Apr 2011 09:06:50 +0200
30
31
univention-thin-client-flash (6.1.9-1) unstable; urgency=low
32
33
  * fixed flashupdate.py Ticket #2011030710000906
34
35
 -- Felix Botner <botner@univention.de>  Wed, 13 Apr 2011 13:55:43 +0200
36
37
univention-thin-client-flash (6.1.8-1) unstable; urgency=low
38
39
  * fixed flashupdate.py and thin-client-flash-update Ticket
40
    #2011030710000906 
41
42
 -- Felix Botner <botner@univention.de>  Mon, 11 Apr 2011 14:49:32 +0200
43
44
univention-thin-client-flash (6.1.7-1) unstable; urgency=low
45
46
  * support multiple ldap server for thin clients 
47
    Ticket #2011030710000906
48
49
 -- Felix Botner <botner@univention.de>  Tue, 05 Apr 2011 15:12:09 +0200
50
51
univention-thin-client-flash (6.1.6-2) unstable; urgency=low
52
53
  * fixed last commit Ticket #2011030710000899
54
55
 -- Felix Botner <botner@univention.de>  Tue, 29 Mar 2011 10:55:08 +0200
56
57
univention-thin-client-flash (6.1.5-1) unstable; urgency=low
58
59
  * sort output in univention-thin-client-flash-status by time 
60
    Ticket #2011030710000899
61
62
 -- Felix Botner <botner@univention.de>  Tue, 29 Mar 2011 10:01:02 +0200
63
64
univention-thin-client-flash (6.1.4-1) unstable; urgency=low
65
66
  * added throtteling to flashstatus.py Ticket #2011030710000899
67
68
 -- Felix Botner <botner@univention.de>  Fri, 25 Mar 2011 09:36:26 +0100
69
70
univention-thin-client-flash (6.1.3-1) unstable; urgency=low
71
72
  * minor fix in thin-client-flash-update 
73
  * process all log files (*.gz and *.log) in
74
    log directory in univention-thin-client-flash-status
75
    Ticket #2011030710000899
76
77
 -- Felix Botner <botner@univention.de>  Wed, 23 Mar 2011 10:12:58 +0100
78
79
univention-thin-client-flash (6.1.2-1) unstable; urgency=low
80
81
  * minor fixes in thin-client-flash-update
82
  * removed redundant missingok from logrotate config
83
  * fixed element mapping in univention-thin-client-flash-status
84
    and flashstatus.py Ticket #2011030710000899
85
86
 -- Felix Botner <botner@univention.de>  Tue, 22 Mar 2011 15:24:16 +0100
87
88
univention-thin-client-flash (6.1.1-1) unstable; urgency=low
89
90
  * added -n|--host-history to univention-thin-client-flash-status 
91
    Ticket #2011030710000899
92
93
 -- Felix Botner <botner@univention.de>  Wed, 16 Mar 2011 15:31:08 +0100
94
95
univention-thin-client-flash (6.1.0-1) unstable; urgency=low
96
97
  * added thin client flash status log Ticket #2011030710000899
98
99
 -- Felix Botner <botner@univention.de>  Wed, 16 Mar 2011 14:16:41 +0100
100
1
univention-thin-client-flash (6.0.13-1) unstable; urgency=low
101
univention-thin-client-flash (6.0.13-1) unstable; urgency=low
2
102
3
  * Don't overwrite linked libraries while creating the thin client
103
  * Don't overwrite linked libraries while creating the thin client
(-)univention-thin-client-flash/debian/rules (+4 lines)
 Lines 58-63    Link Here 
58
	install -m 755 usr/share/univention-thin-client-flash/dhclient-script debian/univention-thin-client-flash/usr/share/univention-thin-client-flash/
58
	install -m 755 usr/share/univention-thin-client-flash/dhclient-script debian/univention-thin-client-flash/usr/share/univention-thin-client-flash/
59
	install -m 755 var/www/univention-thin-client-flash/flashupdate.py debian/univention-thin-client-flash/var/www/univention-thin-client-flash/
59
	install -m 755 var/www/univention-thin-client-flash/flashupdate.py debian/univention-thin-client-flash/var/www/univention-thin-client-flash/
60
60
61
	install -m 755 var/www/univention-thin-client-flash/flashstatus.py debian/univention-thin-client-flash/var/www/univention-thin-client-flash/
62
	install -m 755 univention-thin-client-flash-status debian/univention-thin-client-flash/usr/bin/
63
	chown root:adm debian/univention-thin-client-flash/var/log/univention-thin-client-flash-status
64
	cp debian/logrotate debian/univention-thin-client-flash/etc/logrotate.d/univention-thin-client-flash-status
61
65
62
	univention-install-config-registry
66
	univention-install-config-registry
63
	univention-thin-client-download-debs -d `pwd`/debian/univention-thin-client-flash/var/lib/univention-client-root/thin-client-archive/flash -p syslinux mtools dosfstools
67
	univention-thin-client-download-debs -d `pwd`/debian/univention-thin-client-flash/var/lib/univention-client-root/thin-client-archive/flash -p syslinux mtools dosfstools
(-)univention-thin-client-flash/conffiles/usr/share/univention-thin-client-flash/flashupdate (-11 / +23 lines)
 Lines 54-65    Link Here 
54
54
55
# Spaces in servernames are not allowed with this code
55
# Spaces in servernames are not allowed with this code
56
CMDLINE="$(cat /proc/cmdline)"
56
CMDLINE="$(cat /proc/cmdline)"
57
flashserver="$(sed -e 's|.* flashServer=\([^ ]*\) .*|\1|' /proc/cmdline)"
57
flashServer="$(sed -e 's|.* flashServer=\([^ ]*\) .*|\1|' /proc/cmdline)"
58
ldapserver="$(sed -e 's|.* ldapServer=\([^ ]*\) .*|\1|' /proc/cmdline)"
58
# new ldapServer syntax
59
ldapServer="$(sed -e 's|.*ldapServer="\([^"]*\)".*|\1|' /proc/cmdline)"
60
# old ldapServer syntax
61
oldLdapServer="$(sed -e 's|.* ldapServer=\([^ ]*\) .*|\1|' /proc/cmdline)"
62
59
if [ -n "$flashServer" -a "$flashServer" != "$CMDLINE" ]; then
63
if [ -n "$flashServer" -a "$flashServer" != "$CMDLINE" ]; then
60
	server="$flashServer"
64
	server="$flashServer"
61
elif [ -n "$ldapServer" -a "$ldapServer" != "$CMDLINE" ]; then
65
elif [ -n "$ldapServer" -a "$ldapServer" != "$CMDLINE" ]; then
62
	server="$ldapServer"
66
	server="$ldapServer"
67
elif [ -n "$oldLdapServer" -a "$oldLdapServer" != "$CMDLINE" ]; then
68
	server="$oldLdapServer"
63
else
69
else
64
	server="univention-flash-server"
70
	server="univention-flash-server"
65
fi
71
fi
 Lines 72-93    Link Here 
72
78
73
echo "SERVER: $server" >>/dev/tty9 2>&1
79
echo "SERVER: $server" >>/dev/tty9 2>&1
74
80
75
server_ip=$(host $server | sed -n "s|.* has address ||p")
81
mac=$(LC_ALL=C ifconfig eth0 | sed -n 's|.*HWaddr \([^ ]*\) .*|\1|p')
76
if [ -z "$server_ip" ]; then
77
	server_ip="$server"
78
fi
79
82
80
rm -f /tmp/flashupdate.sh
83
for i in $server; do
84
	server_ip=$(host $i | sed -n "s|.* has address ||p")
85
	if [ -z "$server_ip" ]; then
86
		server_ip="$i"
87
	fi
81
88
82
echo "IP: $server_ip" >>/dev/tty9 2>&1
89
	rm -f /tmp/flashupdate.sh
83
90
84
mac=$(LC_ALL=C ifconfig eth0 | sed -n 's|.*HWaddr \([^ ]*\) .*|\1|p')
91
	echo "IP: $server_ip" >>/dev/tty9 2>&1
85
92
86
wget -O /tmp/flashupdate.sh http://$server_ip/univention-thin-client-flash/flashupdate.py?mac=$mac >>/dev/tty9 2>&1
87
93
94
	wget -O /tmp/flashupdate.sh http://$server_ip/univention-thin-client-flash/flashupdate.py?mac=$mac >>/dev/tty9 2>&1
95
96
	if [ -s /tmp/flashupdate.sh ]; then
97
		break
98
	fi
99
done
100
88
if [ -e /tmp/flashupdate.sh ]; then
101
if [ -e /tmp/flashupdate.sh ]; then
89
	chmod +x /tmp/flashupdate.sh
102
	chmod +x /tmp/flashupdate.sh
90
91
	/tmp/flashupdate.sh
103
	/tmp/flashupdate.sh
92
fi
104
fi
93
105
(-)univention-thin-client-flash/conffiles/etc/univention/flash/thin-client-flash-update (-12 / +129 lines)
 Lines 1-3    Link Here 
1
#!/bin/sh
1
@%@BCWARNING=# @%@
2
@%@BCWARNING=# @%@
2
#
3
#
3
# Univention Thin Client Flash
4
# Univention Thin Client Flash
 Lines 27-32    Link Here 
27
# along with this program; if not, write to the Free Software
28
# along with this program; if not, write to the Free Software
28
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA	 02110-1301	 USA
29
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA	 02110-1301	 USA
29
30
31
encode_url ()
32
{
33
	echo "$1" | sed \
34
		-e 's/%/%25/g' \
35
		-e 's/ /%20/g' \
36
		-e 's/!/%21/g' \
37
		-e 's/"/%22/g' \
38
		-e 's/#/%23/g' \
39
		-e 's/\$/%24/g' \
40
		-e 's/\&/%26/g' \
41
		-e 's/'\''/%27/g' \
42
		-e 's/(/%28/g' \
43
		-e 's/)/%29/g' \
44
		-e 's/\*/%2a/g' \
45
		-e 's/+/%2b/g' \
46
		-e 's/,/%2c/g' \
47
		-e 's/-/%2d/g' \
48
		-e 's/\./%2e/g' \
49
		-e 's/\//%2f/g' \
50
		-e 's/:/%3a/g' \
51
		-e 's/;/%3b/g' \
52
		-e 's//%3e/g' \
53
		-e 's/?/%3f/g' \
54
		-e 's/@/%40/g' \
55
		-e 's/\[/%5b/g' \
56
		-e 's/\\/%5c/g' \
57
		-e 's/\]/%5d/g' \
58
		-e 's/\^/%5e/g' \
59
		-e 's/_/%5f/g' \
60
		-e 's/`/%60/g' \
61
		-e 's/{/%7b/g' \
62
		-e 's/|/%7c/g' \
63
		-e 's/}/%7d/g' \
64
		-e 's/~/%7e/g'
65
}
66
67
append_to_url ()
68
{
69
	local url="$1"
70
	local item="$2"
71
	local value="$3"
72
	local delim="$4"
73
	
74
	if [ -z "$delim" ]; then
75
		delim="&"
76
	fi
77
	
78
	if [ -z "$value" ]; then
79
		value=None
80
	fi
81
	
82
	if [ -n "$item" ]; then
83
		value=$(encode_url "$value")
84
		url="$url$delim$item=$value"
85
	fi
86
87
	echo "$url"
88
}
89
90
ALREADY_LOGGED=0
91
flash_status ()
92
{
93
	# to log or not to log ...
94
	case "$thinclient_flash_status_log" in
95
		0|no|off|false|disable|disabled) return 0;;
96
	esac
97
	
98
	# check if we already logged the status
99
	if [ $ALREADY_LOGGED -ne 0 ]; then
100
		return
101
	fi
102
	
103
	# $1 is the status of the thin client (up-to-dat, updated, installation failed, ...)
104
	local status=$1
105
	if [ -z "$status" ]; then
106
		status=unknown
107
	fi
108
	
109
	# collect data
110
	local mac=$(LC_ALL=C ifconfig eth0 | sed -n 's|.*HWaddr \([^ ]*\) .*|\1|p')
111
	local ip=$(LC_ALL=C ifconfig eth0|sed -n 's| *inet addr:\([^ ]*\) .*|\1|p')
112
	local uri="$url/flashstatus.py"
113
	
114
	# setup url
115
	uri=$(append_to_url "$uri" "mac" "$mac" "?")
116
	uri=$(append_to_url "$uri" "ip" "$ip")
117
	uri=$(append_to_url "$uri" "hostname" "$hostname")
118
	uri=$(append_to_url "$uri" "domainname" "$domainname")
119
	uri=$(append_to_url "$uri" "nameserver" "$nameserver")
120
	uri=$(append_to_url "$uri" "ldapserver" "$ldapserver")
121
	uri=$(append_to_url "$uri" "image" "$image")
122
	uri=$(append_to_url "$uri" "version" "$version")
123
	uri=$(append_to_url "$uri" "newversion" "$new_version")
124
	uri=$(append_to_url "$uri" "url" "$url")
125
	uri=$(append_to_url "$uri" "partition" "$partition")
126
	uri=$(append_to_url "$uri" "rootpart" "$rootpart")
127
	uri=$(append_to_url "$uri" "bootpart" "$bootpart")
128
	uri=$(append_to_url "$uri" "status" "$status")
129
	
130
	# do it
131
	wget -q -O - "$uri"
132
	
133
	ALREADY_LOGGED=1
134
}
135
	
136
30
flash_abort ()
137
flash_abort ()
31
{
138
{
32
	echo 
139
	echo 
 Lines 37-42    Link Here 
37
144
38
flash_reboot ()
145
flash_reboot ()
39
{
146
{
147
	# log status
148
	flash_status "$1"
149
	
40
	#See https://forge.univention.org/bugzilla/show_bug.cgi?id=18792 for details
150
	#See https://forge.univention.org/bugzilla/show_bug.cgi?id=18792 for details
41
151
42
	#soft-reset:
152
	#soft-reset:
 Lines 61-67    Link Here 
61
	print '	echo "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"'
171
	print '	echo "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"'
62
@!@
172
@!@
63
	sleep ${thinclient_flash_update_panic_timeout}s
173
	sleep ${thinclient_flash_update_panic_timeout}s
64
	flash_reboot
174
	flash_reboot "installation failed"
65
}
175
}
66
176
67
flash_panic_upgrade ()
177
flash_panic_upgrade ()
 Lines 81-87    Link Here 
81
	print '	echo "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"'
191
	print '	echo "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"'
82
@!@
192
@!@
83
	sleep ${thinclient_flash_update_panic_timeout}s
193
	sleep ${thinclient_flash_update_panic_timeout}s
84
	flash_reboot
194
	flash_reboot "upgrade failed"
85
}
195
}
86
196
87
print_done ()
197
print_done ()
 Lines 98-103    Link Here 
98
print_header ()
208
print_header ()
99
{
209
{
100
	clear
210
	clear
211
	usplash_write QUIT
101
	echo "verbose" > /proc/splash
212
	echo "verbose" > /proc/splash
102
	clear
213
	clear
103
	echo
214
	echo
 Lines 123-128    Link Here 
123
234
124
if [ -z "$thinclient_flash_update_url" ]; then
235
if [ -z "$thinclient_flash_update_url" ]; then
125
	thinclient_flash_server_ip=$(host ${thinclient_flash_server} | sed -n "s|.* has address ||p")
236
	thinclient_flash_server_ip=$(host ${thinclient_flash_server} | sed -n "s|.* has address ||p")
237
	# is name a ip?
238
	ip="$(echo $thinclient_flash_server | sed -n 's|[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*|'$thinclient_flash_server'|p')"
239
	if [ -n "$ip" ]; then
240
		thinclient_flash_server_ip="$thinclient_flash_server"
241
	else
242
		thinclient_flash_server_ip=$(host ${thinclient_flash_server} | sed -n "s|.* has address ||p")
243
	fi
126
	url="http://${thinclient_flash_server_ip}/univention-thin-client-flash/"
244
	url="http://${thinclient_flash_server_ip}/univention-thin-client-flash/"
127
else
245
else
128
	# Busybox can not resolve dns names ...
246
	# Busybox can not resolve dns names ...
 Lines 131-136    Link Here 
131
		# is name a ip?
249
		# is name a ip?
132
		ip="$(echo $name | sed -n 's|[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*|'$name'|p')"
250
		ip="$(echo $name | sed -n 's|[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*|'$name'|p')"
133
		if [ -n "$ip" ]; then
251
		if [ -n "$ip" ]; then
252
			thinclient_flash_server_ip="$name"
134
			url="$thinclient_flash_update_url"
253
			url="$thinclient_flash_update_url"
135
		else
254
		else
136
			thinclient_flash_server_ip=$(host $name | sed -n "s|.* has address ||p")
255
			thinclient_flash_server_ip=$(host $name | sed -n "s|.* has address ||p")
 Lines 151-156    Link Here 
151
echo -n "Retrieve version information: " >>/dev/tty9
270
echo -n "Retrieve version information: " >>/dev/tty9
152
new_version=$(wget -qqq -O - "$url/$image.vers")
271
new_version=$(wget -qqq -O - "$url/$image.vers")
153
if [ -z "$new_version" ]; then
272
if [ -z "$new_version" ]; then
273
	flash_status "image version not found"
154
	echo "Not found" >>/dev/tty9
274
	echo "Not found" >>/dev/tty9
155
	exit 0
275
	exit 0
156
else
276
else
 Lines 227-240    Link Here 
227
	partition=0
347
	partition=0
228
fi
348
fi
229
349
230
nameserver=$(cat /proc/cmdline | grep DNSSERVER | sed -e 's/.*DNSSERVER=//g' | awk '{print $1;}')
350
# save flash server's ip as boot parameter
231
ldapserver=$(cat /proc/cmdline | grep ldapServer | sed -e 's/.*ldapServer=//g' | awk '{print "ldapServer="$1;}')
351
if [ -n "$thinclient_flash_server_ip" ]; then
232
ldapport=$(cat /proc/cmdline | grep ldapPort | sed -e 's/.*ldapPort=//g' | awk '{print "ldapPort="$1;}')
352
	flashserverCmdline="flashServer=$thinclient_flash_server_ip"
233
vga=$(cat /proc/cmdline | grep vga | sed -e 's/.*vga=//g' | awk '{print "vga="$1;}')
353
	flashserver="$thinclient_flash_server_ip"
234
quiet_cmdline=$(cat /proc/cmdline | grep " quiet")
235
quiet=""
236
if [ -n "$quiet_cmdline" ]; then
237
	quiet="quiet"
238
fi
354
fi
239
355
240
356
 Lines 291-297    Link Here 
291
    PATH_BASE=/mnt
407
    PATH_BASE=/mnt
292
    PATH_MBR=/usr/lib/syslinux/mbr.bin
408
    PATH_MBR=/usr/lib/syslinux/mbr.bin
293
409
294
    echo "default linux initrd=initrd.splash root=$rootpart DNSSERVER=$nameserver $vga $quiet splash=silent $ldapserver $ldapport" > $PATH_EXTLINUX
410
    echo "default linux initrd=initrd.splash root=$rootpart $nameserverCmdline $vga $quiet splash=silent $flashserverCmdline $ldapserverCmdline $ldapport $loglevel" > $PATH_EXTLINUX
295
411
296
    # store current network configuration
412
    # store current network configuration
297
    echo "FLASH_HOSTNAME=$hostname" > $PATH_NETWORKCONFIG
413
    echo "FLASH_HOSTNAME=$hostname" > $PATH_NETWORKCONFIG
 Lines 353-361    Link Here 
353
469
354
	echo
470
	echo
355
	sync
471
	sync
356
	flash_reboot
472
	flash_reboot "updated"
357
    log_action_end_msg 0
473
    log_action_end_msg 0
358
else
474
else
475
	flash_status "up-to-date"
359
@!@
476
@!@
360
if baseConfig.get('locale/default', 'us').startswith('de_'):
477
if baseConfig.get('locale/default', 'us').startswith('de_'):
361
	print '	echo "Das System ist aktuell."'
478
	print '	echo "Das System ist aktuell."'
(-)univention-thin-client-flash/var/www/univention-thin-client-flash/flashstatus.py (+115 lines)
Line 0    Link Here 
1
#!/usr/bin/python2.4
2
#
3
# Univention Thin Client Flash status logging
4
#
5
# Copyright (C) 2011 Univention GmbH
6
#
7
# http://www.univention.de/
8
#
9
# All rights reserved.
10
#
11
# This program is free software; you can redistribute it and/or modify
12
# it under the terms of the GNU General Public License version 2 as
13
# published by the Free Software Foundation.
14
#
15
# Binary versions of this file provided by Univention to you as
16
# well as other copyrighted, protected or trademarked materials like
17
# Logos, graphics, fonts, specific documentations and configurations,
18
# cryptographic keys etc. are subject to a license agreement between
19
# you and Univention.
20
#
21
# This program is distributed in the hope that it will be useful,
22
# but WITHOUT ANY WARRANTY; without even the implied warranty of
23
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	See the
24
# GNU General Public License for more details.
25
#
26
# You should have received a copy of the GNU General Public License
27
# along with this program; if not, write to the Free Software
28
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA	 02110-1301	 USA
29
30
LOG_FILENAME = '/var/log/univention-thin-client-flash-status/thin-client-flash-status.log'
31
ACCESS_DB = '/var/tmp/thin-client-flash-status.pickle'
32
ACCESS_DB_LOCK = '/var/tmp/thin-client-flash-status.pickle.lock'
33
LAST_SEEN_DIFF = 2
34
35
import sys
36
import cgi
37
import univention.config_registry
38
import csv
39
import time
40
import pickle
41
import os
42
import time
43
import fcntl
44
45
def updateAccessDb (access):
46
	# save access db
47
	output = open(ACCESS_DB, 'wb')
48
	pickle.dump(access, output)
49
	output.close()
50
51
print 'Content-type: text/plain'
52
print 
53
54
myTime = time.time()
55
myIp = os.environ.get("REMOTE_ADDR", "")
56
57
# do nothing if no remote address can be found
58
if not myIp:
59
	sys.exit(0)
60
61
# get lock
62
lockFile = open(ACCESS_DB_LOCK, 'wb')
63
fcntl.flock(lockFile.fileno(), fcntl.LOCK_EX)
64
65
# read access db into access dict
66
access = {}
67
try:
68
	input = open(ACCESS_DB, 'rb')
69
	access = pickle.load(input)
70
	input.close()
71
except Exception, e:
72
	pass
73
74
# check clients last access time
75
lastSeen = access.get(myIp, 0)
76
77
# ignore clients which accessed us in the last LAST_SEEN_DIFF seconds
78
# save timestamp for others
79
if lastSeen:
80
	if (myTime - lastSeen) <= LAST_SEEN_DIFF:
81
		sys.exit(0)
82
access[myIp] = myTime
83
84
# clean up access db
85
for client in access.keys():
86
	if (myTime - access[client]) > LAST_SEEN_DIFF:
87
		del access[client]
88
89
# get data
90
form = cgi.FieldStorage()
91
data = []
92
size = 0
93
for key in form.keys():
94
	tmp = key + "=" +form.getvalue(key)
95
	size += len(tmp)
96
	data.append(tmp)
97
98
99
# simple test to restrict the size of post
100
if size > 4096:
101
	updateAccessDb(access)
102
	sys.exit(0)
103
104
data.append("time=" + str(time.time()))
105
106
# write to log
107
log = csv.writer(open(LOG_FILENAME, 'ab'), delimiter="\t", quotechar='|', quoting=csv.QUOTE_MINIMAL)
108
log.writerow(data)
109
110
# update access db
111
updateAccessDb(access)
112
113
# release lock
114
lockFile.close()
115
0
  + *
116
  + *
(-)univention-thin-client-flash/var/www/univention-thin-client-flash/flashupdate.py (-1 / +42 lines)
 Lines 100-113    Link Here 
100
			print ''
100
			print ''
101
			#print 'eval "$(univention-config-registry shell)"'
101
			#print 'eval "$(univention-config-registry shell)"'
102
102
103
			# hostname and domain
103
			print 'hostname=\"%s\"' % clientObject[0][1].get('cn')[0]
104
			print 'hostname=\"%s\"' % clientObject[0][1].get('cn')[0]
104
			print 'domainname=\"%s\"' % ucr.get('domainname')
105
			print 'domainname=\"%s\"' % ucr.get('domainname')
105
			print 'thinclient_flash_server=\"%s.%s\"' % (ucr.get('hostname'), ucr.get('domainname'))
106
107
			# boot paramter -> use values from pxe/* vars
108
			
109
			# flash server from ucr var, default fqdn
110
			flashServer = ucr.get('pxe/thinclient/flash/server', "")
111
			if flashServer:
112
				print 'thinclient_flash_server="%s"' % flashServer
113
			else:
114
				print 'thinclient_flash_server="%s.%s"' % (ucr.get('hostname'), ucr.get('domainname'))
115
116
			# ldap server
117
			ldapServer = ucr.get('pxe/ldapserver', "")
118
			if ldapServer:
119
				print 'ldapserverCmdline="ldapServer=\\"%s\\""' % ldapServer
120
				print 'ldapserver="%s"' % ldapServer
121
122
			# ldap port
123
			ldapPort = ucr.get('pxe/ldapport', "")
124
			if ldapPort:
125
				print 'ldapport="ldapPort=%s"' % ldapPort
126
127
			# vga
128
			vga = ucr.get('pxe/vga', "")
129
			if vga:
130
				print 'vga="vga=%s"' % vga
131
132
			# quiet
133
			if ucr.get('pxe/quiet', "no").lower() in ['yes', 'true', '1']:
134
				print 'quiet="quiet"'
135
136
			# loglevel
137
			loglevel = ucr.get('pxe/loglevel', "")
138
			if loglevel:
139
				print 'loglevel="loglevel=%s"' % loglevel
140
141
			# nameserver
142
			print 'nameserverCmdline="DNSSERVER=%s"' % ucr.get('pxe/nameserver')
143
			print 'nameserver="%s"' % ucr.get('pxe/nameserver')
144
145
			# ucr policies
106
			for k in results.keys():
146
			for k in results.keys():
107
				# 7468696e636c69656e742f666c6173682f ==> thinclient/flash/
147
				# 7468696e636c69656e742f666c6173682f ==> thinclient/flash/
108
				if k.startswith('univentionRegistry;entry-hex-7468696e636c69656e742f666c6173682f'):
148
				if k.startswith('univentionRegistry;entry-hex-7468696e636c69656e742f666c6173682f'):
109
					print '%s=\'%s\'' % (k.split('univentionRegistry;entry-hex-')[-1].decode('hex').replace('/','_'), results[k][0])
149
					print '%s=\'%s\'' % (k.split('univentionRegistry;entry-hex-')[-1].decode('hex').replace('/','_'), results[k][0])
110
150
151
			# add flash script
111
			lines = open('/etc/univention/flash/thin-client-flash-update').readlines()
152
			lines = open('/etc/univention/flash/thin-client-flash-update').readlines()
112
			for line in lines:
153
			for line in lines:
113
				print line,
154
				print line,

Return to bug 22152