Magellan Linux

Diff of /alx-src/branches/alxconf-060/functions/config_sessions.sh

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2148 by niro, Wed May 11 09:11:02 2011 UTC revision 2149 by niro, Tue May 17 11:47:17 2011 UTC
# Line 1  Line 1 
1  # $Id$  # $Id$
2  # configures ica-sessions on the host via mysql db settings  # configures ica-sessions on the host via mysql db settings
3    
4  get_sessions_settings()  # helper function to create citrix session files
5    generate_ica_session_file()
6  {  {
  local x i all count  
   
  # all arrays:  
  # ->  session1 session2 ... sessionN  
   
  # get settings from database  
  all=$(mysqldo "select filename from cfg_sessions where serial='${ALX_SERIAL}'")  
   
  # split'em up and put in an array (only if $all not zero)  
  declare -i i=0  
  if [ -n "${all}" ]  
  then  
  for x in ${all}  
  do  
  ALX_SESSIONS[${i}]=${x}  
  ((i++))  
  done  
  count=${i}  
  else  
  count=0  
  fi  
   
  # get settings from database  
  ALX_PROGRAMS=$(mysqldo "select name from cfg_other_menuitems where serial='${ALX_SERIAL}'")  
   
  export ALX_SESSIONS  
  export ALX_PROGRAMS  
 }  
   
 get_autostart_settings()  
 {  
  # get settings from database  
  ALX_AUTOSTART=$(mysqldo "select session from cfg_autostart where serial='${ALX_SERIAL}'")  
   
  export ALX_AUTOSTART  
 }  
   
 get_screensaver_settings()  
 {  
  ALX_SCRN_SAVER=$(mysqldo "select screensaver from cfg_screensaver where serial='${ALX_SERIAL}'")  
  ALX_SCRN_TIMEOUT=$(mysqldo "select timeout from cfg_screensaver where serial='${ALX_SERIAL}'")  
  ALX_SCRN_PASSWD=$(mysqldo "select password from cfg_screensaver where serial='${ALX_SERIAL}'")  
   
  export ALX_SCRN_SAVER  
  export ALX_SCRN_TIMEOUT  
  export ALX_SCRN_PASSWD  
 }  
   
 generate_ica_session_files()  
 {  
  local all_ids  
7   local i   local i
8   local x   local num
  local browser_address_num  
9   local server   local server
10   local ses_session   local ses_session
11   local ses_filename   local ses_filename
# Line 64  generate_ica_session_files() Line 13  generate_ica_session_files()
13   local ses_domain   local ses_domain
14   local ses_password   local ses_password
15   local ses_browseradrs   local ses_browseradrs
  local ses_colors  
16   local CONFIG   local CONFIG
17    
18   # get settings from database   # very basic getops
19   all_ids=$(mysqldo "select id from cfg_sessions where serial='${ALX_SERIAL}'")   for i in $*
20     do
21     case $1 in
22     --session) shift; ses_session="$1" ;;
23     --filename) shift; ses_filename="$1" ;;
24     --username) shift; ses_username="$1" ;;
25     --password) shift; ses_password="$1" ;;
26     --domain) shift; ses_domain="$1" ;;
27     --server) ses_browseradrs="$1" ;;
28             esac
29     shift
30     done
31    
32     # abort if session, filename or server not given
33     [[ -z ${session} ]] && return 1
34     [[ -z ${file} ]] && return 1
35     [[ -z ${server} ]] && return 1
36    
37     # write session files
38     CONFIG="${ALX_ICA_SESSIONS}/${ses_filename}"
39     clearconfig
40    
41     addconfig '[WFClient]'
42     addconfig 'Version=2'
43    
44   for i in ${all_ids}   # use ';' as ifs
45     declare -i i=0
46     for server in ${ses_browseradrs//;/ }
47   do   do
48   # get settings   (( i++ ))
49   ses_session=$(mysqldo "select session from cfg_sessions where serial='${ALX_SERIAL}' and id='${i}'")   num="${i}"
50   ses_filename=$(mysqldo "select filename from cfg_sessions where serial='${ALX_SERIAL}' and id='${i}'")   # support newer ica-clients:
51   ses_username=$(mysqldo "select username from cfg_sessions where serial='${ALX_SERIAL}' and id='${i}'")   # the first address must be named TcpBrowserAddress, but not TcpBrowserAddress1 !!
52   ses_domain=$(mysqldo "select domain from cfg_sessions where serial='${ALX_SERIAL}' and id='${i}'")   [[ ${i} -eq 1 ]] && num=""
53   ses_password=$(mysqldo "select password from cfg_sessions where serial='${ALX_SERIAL}' and id='${i}'")   addconfig "TcpBrowserAddress${num}=${server}"
  ses_browseradrs=$(mysqldo "select browseradrs from cfg_sessions where serial='${ALX_SERIAL}' and id='${i}'")  
   
  # get the right colors  
  ses_colors=$(mysqldo "select depth from cfg_graphic where serial='${ALX_SERIAL}'")  
  # convert to ica session file values  
  case ${ses_colors} in  
  24) ses_colors="8";;  
  16) ses_colors="4";;  
  8) ses_colors="2";;  
  *) ses_colors="2";;  
  esac  
   
  # write session files  
  CONFIG=${ALX_ICA_SESSIONS}/${ses_filename}  
  clearconfig  
   
  addconfig '[WFClient]'  
  addconfig 'Version=2'  
  OLD_IFS="$IFS"  
  IFS=";"  
  declare -i x=0  
  for server in ${ses_browseradrs}  
  do  
  (( x++ ))  
  browser_address_num="${x}"  
  # support newer ica-clients:  
  # the first address must be named TcpBrowserAddress, but not TcpBrowserAddress1 !!  
  [[ ${x} -eq 1 ]] && browser_address_num=""  
  addconfig "TcpBrowserAddress${browser_address_num}=${server}"  
  done  
  IFS="${OLD_IFS}"  
  unset x  
  unset OLD_IFS  
   
  addconfig 'ScreenPercent=0'  
  addconfig '[ApplicationServers]'  
  addconfig "${ses_session}="  
  addconfig "[${ses_session}]"  
  addconfig "Address=${ses_session}"  
  addconfig "InitialProgram=#${ses_session}"  
  addconfig "DesiredColor=${ses_colors}"  
  addconfig 'TransportDriver=TCP/IP'  
  addconfig 'WinStationDriver=ICA 3.0'  
  addconfig "ClearPassword=${ses_password}"  
  addconfig "Username=${ses_username}"  
  addconfig "Domain=${ses_domain}"  
  addconfig 'UseFullScreen=Yes'  
  addconfig 'NoWindowManager=True'  
54   done   done
55    
56     addconfig 'ScreenPercent=0'
57     addconfig '[ApplicationServers]'
58     addconfig "${ses_session}="
59     addconfig "[${ses_session}]"
60     addconfig "Address=${ses_session}"
61     addconfig "InitialProgram=#${ses_session}"
62     addconfig 'TransportDriver=TCP/IP'
63     addconfig 'WinStationDriver=ICA 3.0'
64     addconfig "ClearPassword=${ses__password}"
65     addconfig "Username=${ses_username}"
66     addconfig "Domain=${ses_domain}"
67     addconfig 'UseFullScreen=Yes'
68     addconfig 'NoWindowManager=True'
69  }  }
70    
71  # generates a sh file to start programs  # generates a sh file to start programs
# Line 151  generate_program_sh() Line 90  generate_program_sh()
90   done   done
91    
92   # abort if name, dest or exec not given   # abort if name, dest or exec not given
93   [ -z "${name}" ] && return 1   [[ -z ${name} ]] && return 1
94   [ -z "${exec}" ] && return 1   [[ -z ${exec} ]] && return 1
95   [ -z "${dest}" ] && return 1   [[ -z ${dest} ]] && return 1
96    
97   CONFIG=${dest}   CONFIG="${dest}"
98   addconfig "#!/bin/sh"   addconfig "#!/bin/sh"
99   [ -n "${workdir}" ] && addconfig "cd ${workdir}"   [ -n "${workdir}" ] && addconfig "cd ${workdir}"
100   addconfig "exec ${exec}"   addconfig "exec ${exec}"
101    
102   chmod 0755 ${dest}   chmod 0755 "${dest}"
 }  
   
 get_other_menuitems()  
 {  
  local x i progsh_path name exec icon workdir  
   
  # all arrays:  
  # ->  session1 session2 ... sessionN  
   
  # get settings from database -> now stored in ALX_PROGRAMS  
   
  # abort if empty  
  [ -z "${ALX_PROGRAMS}" ] && return 0  
   
  progsh_path=${ALX_UNPRIV_HOME}/.alxprogs  
  [ -d ${progsh_path} ] && rm -rf ${progsh_path}  
  install -d ${progsh_path}  
   
  # gen menu items  
  for x in ${ALX_PROGRAMS}  
  do  
  # to be sure  
  unset name  
  unset exec  
  unset workdir  
  unset icon  
   
  name=$(mysqldo "select name from cfg_other_menuitems where serial='${ALX_SERIAL}' and name='${x}'")  
  exec=$(mysqldo "select exec from cfg_other_menuitems where serial='${ALX_SERIAL}' and name='${x}'")  
  workdir=$(mysqldo "select workdir from cfg_other_menuitems where serial='${ALX_SERIAL}' and name='${x}'")  
  icon=$(mysqldo "select icon from cfg_other_menuitems where serial='${ALX_SERIAL}' and name='${x}'")  
   
  # now echo config line for fluxbox-menu  
  # make it "configureable" :P  
  [ -n "${workdir}" ] && workdir="--workdir ${workdir}"  
  [ -n "${icon}" ] && icon="<${icon}>"  
   
  # gen prog startup wrapper  
  generate_program_sh \  
  --name "${name}" \  
  --exec "${exec}" \  
  --dest "${progsh_path}/${name}" \  
  "${workdir}"  
   
  echo "[exec] (${name}) {${progsh_path}/${name}} ${icon}"  
  done  
103  }  }
104    
105  # helper functions for generate all desktop icons  # helper functions for generate all desktop icons
# Line 240  generate_icon() Line 133  generate_icon()
133   shift   shift
134   done   done
135    
136   # some sanity checks :   # some sanity checks:
137    
138   # abort if name or command not given   # abort if name or command not given
139   [[ -z ${name} ]] && return 1   [[ -z ${name} ]] && return 1
# Line 280  generate_icon() Line 173  generate_icon()
173    
174  generate_all_desktop_icons()  generate_all_desktop_icons()
175  {  {
176     local session_list="$1"
177     local other_menuitem_list="$2"
178   local res   local res
179   local xres   local xres
180   local yres   local yres
  local icon_list  
181   local x   local x
182   local y   local y
183   local item   local item
184   local basename_item   local name
185   local progsh_path   local progsh_path
186    
187     # progsh path
188     progsh_path=${ALX_UNPRIV_HOME}/.alxprogs
189    
190   # get the resolution   # get the resolution
191   res=$(mysqldo "select resolution from cfg_graphic where serial='${ALX_SERIAL}'")   res=$(mysqldo "select resolution from cfg_graphic where serial='${ALX_SERIAL}'")
192    
193   # split res to x & y   # split res to x & y
194   xres="$(echo ${res} | cut -dx -f1)"   xres="${res%x*}"
195   yres="$(echo ${res} | cut -dx -f2)"   xres="${res#*x}"
196    
197   # top left edge of the icon is given in config file   # top left edge of the icon is given in config file
198   # remove a little bit to simulate the bottom-right edge   # remove a little bit to simulate the bottom-right edge
# Line 309  generate_all_desktop_icons() Line 206  generate_all_desktop_icons()
206   [ -d ${ALX_UNPRIV_HOME}/.xtdesktop ] && rm -rf ${ALX_UNPRIV_HOME}/.xtdesktop   [ -d ${ALX_UNPRIV_HOME}/.xtdesktop ] && rm -rf ${ALX_UNPRIV_HOME}/.xtdesktop
207   install -d ${ALX_UNPRIV_HOME}/.xtdesktop   install -d ${ALX_UNPRIV_HOME}/.xtdesktop
208    
   
209   # default settings   # default settings
210   declare -i x=30   declare -i x=30
211   declare -i y=30   declare -i y=30
212    
213   # first all ica sessions   # ica icons
214   local count=${#ALX_SESSIONS[*]}   for item in ${session_list}
  for (( i=0; i < count; i++ ))  
  do  
  # filenames !  
  icon_list="${icon_list} ${ALX_SESSIONS[${i}]}"  
  done  
   
  for item in ${icon_list}  
215   do   do
216   # abort if empty   # abort if empty
217   [[ -z ${item} ]] && continue   [[ -z ${item} ]] && continue
# Line 344  generate_all_desktop_icons() Line 233  generate_all_desktop_icons()
233   [ ${x} -ge ${xres} ] && x=30   [ ${x} -ge ${xres} ] && x=30
234   fi   fi
235    
236   # ica icons   name="$(basename ${item} .ica)"
  # get basename (.ica must be suffix)  
  basename_item="$(basename ${item} .ica)"  
237   generate_icon \   generate_icon \
238   --name "${basename_item}" \   --name "${name}" \
239   --command "nice -n 19 wfica ${ALX_ICA_SESSIONS}/${item}" \   --command "nice -n 19 wfica ${ALX_ICA_SESSIONS}/${item}" \
240   --icon "${ALX_SESSIONS_ICONS}/${basename_item}.png" \   --icon "${ALX_SESSIONS_ICONS}/${name}.png" \
241   --dest "${ALX_UNPRIV_HOME}/.xtdesktop/${basename_item}.lnk" \   --dest "${ALX_UNPRIV_HOME}/.xtdesktop/${name}.lnk" \
242   --xres "${x}" \   --xres "${x}" \
243   --yres "${y}"   --yres "${y}"
244    
245   y=$((${y} + 80))   y=$((${y} + 80))
246   done   done
247    
248     for item in ${other_menuitem_list}
  # generate program icons  
  icon_list="${ALX_PROGRAMS}"  
   
  progsh_path=${ALX_UNPRIV_HOME}/.alxprogs  
   
  for item in ${icon_list}  
249   do   do
250   # abort if empty   # abort if empty
251   [[ -z ${item} ]] && continue   [[ -z ${item} ]] && continue
# Line 398  generate_all_desktop_icons() Line 279  generate_all_desktop_icons()
279   y=$((${y} + 80))   y=$((${y} + 80))
280   done   done
281    
   
   
282   # last but not least gen a icon with some sys informations   # last but not least gen a icon with some sys informations
283   local sysinfo   local sysinfo
284   local hostname   local hostname
# Line 431  generate_all_desktop_icons() Line 310  generate_all_desktop_icons()
310    
311  config_sessions()  config_sessions()
312  {  {
  # generate ica session files  
  generate_ica_session_files  
   
  # first of all get the vars  
  get_sessions_settings  
  get_autostart_settings  
  get_screensaver_settings  
   
  local count=${#ALX_SESSIONS[*]}  
  local icon  
313   local i   local i
314     local all_ses_ids
315     local all_other_ids
316   local CONFIG   local CONFIG
317     local screensaver_passwd_cmd
318     local all_sessions
319     local all_other_menuitems
320    
321     # get all session ids from database
322     all_ses_ids=$(mysqldo "select id from cfg_sessions where serial='${ALX_SERIAL}'")
323     # get all other_menutiem ids from database
324     all_other_ids=$(mysqldo "select id from cfg_other_menuitems where serial='${ALX_SERIAL}'")
325    
326     # get screensaver settings
327     evaluate_table cfg_screensaver
328     # get autostart settings
329     evaluate_table cfg_autostart
330    
331   # now setup fluxbox for user station   # now setup fluxbox for user station
332    
# Line 453  config_sessions() Line 337  config_sessions()
337   # now generate fluxbox config files   # now generate fluxbox config files
338    
339   # fluxbox main config   # fluxbox main config
340   cat ${ALX_SKELETONS}/fluxbox/init \   cat ${ALX_SKELETONS}/fluxbox/init > ${ALX_UNPRIV_HOME}/.fluxbox/init
  > ${ALX_UNPRIV_HOME}/.fluxbox/init  
341    
342   # fluxbox autostart   # fluxbox autostart
343   cat ${ALX_SKELETONS}/fluxbox/apps \   cat ${ALX_SKELETONS}/fluxbox/apps > ${ALX_UNPRIV_HOME}/.fluxbox/apps
  > ${ALX_UNPRIV_HOME}/.fluxbox/apps  
344    
345   CONFIG=${ALX_UNPRIV_HOME}/.fluxbox/apps   CONFIG="${ALX_UNPRIV_HOME}/.fluxbox/apps"
346   # add screensaver   # add screensaver
347   if [[ ! -z ${ALX_SCRN_SAVER} ]] && [[ ! -z ${ALX_SCRN_TIMEOUT} ]]   if [[ ! -z ${cfg_screensaver_screensaver} ]] && [[ ! -z ${cfg_screensaver_screensaver_timeout} ]]
348   then   then
349   local ALX_PASSWD_CMD   if [[ -z ${cfg_screensaver_password} ]] || [[ ${cfg_screensaver_password} = NULL ]]
   
  if [[ -z ${ALX_SCRN_PASSWD} ]] || [[ ${ALX_SCRN_PASSWD} = NULL ]]  
350   then   then
351   ALX_PASSWD_CMD="-nolock"   screensaver_passwd_cmd="-nolock"
352   else   else
353   ALX_PASSWD_CMD="-cpasswd $(cryptpw -m des ${ALX_SCRN_PASSWD})"   screensaver_passwd_cmd="-cpasswd $(cryptpw -m des ${cfg_screensaver_password})"
354   fi   fi
355    
356   addconfig "[startup] {nohup xautolock -time ${ALX_SCRN_TIMEOUT} -locker 'xlock -mode ${ALX_SCRN_SAVER} ${ALX_PASSWD_CMD}' > /dev/null &}"   addconfig "[startup] {nohup xautolock -time ${cfg_screensaver_timeout} -locker 'xlock -mode ${cfg_screensaver_screensaver} ${screensaver_passwd_cmd}' > /dev/null &}"
357   fi   fi
358    
359   # add autostart session   # add autostart session
360   if [[ ! -z ${ALX_AUTOSTART} ]]   if [[ ! -z ${cfg_autostart_session} ]]
361   then   then
362   addconfig "[startup] {nohup nice -n 19 wfica ${ALX_ICA_SESSIONS}/${ALX_AUTOSTART} &}"   addconfig "[startup] {nohup nice -n 19 wfica ${ALX_ICA_SESSIONS}/${cfg_autostart_session} &}"
363   fi   fi
364    
365   # fluxbox hotkeys   # fluxbox hotkeys
# Line 491  config_sessions() Line 371  config_sessions()
371    
372   # fluxbox menu header   # fluxbox menu header
373   cat ${ALX_SKELETONS}/fluxbox/menu.header >> ${ALX_UNPRIV_HOME}/.fluxbox/menu   cat ${ALX_SKELETONS}/fluxbox/menu.header >> ${ALX_UNPRIV_HOME}/.fluxbox/menu
   
374   # now fix it with proper messages :P   # now fix it with proper messages :P
375   local ver="$(< /etc/mageversion)"   local ver="$(< /etc/mageversion)"
376   sed -i "s:@CHANGEME@:alx-${ver}  #${ALX_SERIAL}:g" ${ALX_UNPRIV_HOME}/.fluxbox/menu   sed -i "s:@CHANGEME@:alx-${ver}  #${ALX_SERIAL}:g" ${ALX_UNPRIV_HOME}/.fluxbox/menu
   
377   # add a newline (maybe there is no crlf in the header)   # add a newline (maybe there is no crlf in the header)
378   addconfig   addconfig
379    
380   # fluxbox menu sessions   # first generate session files
381   for (( i=0; i < count; i++ ))   for i in ${all_ses_ids}
382   do   do
383   if [[ ! -z ${ALX_SESSIONS[${i}]} ]]   evaluate_table cfg_sessions "where serial='${ALX_SERIAL}' and id='${i}'"
384   then   generate_ica_session_file \
385   addconfig "[exec] ($(basename ${ALX_SESSIONS[${i}]} .ica)) {nice -n 19 wfica ${ALX_ICA_SESSIONS}/${ALX_SESSIONS[${i}]}}"   --session "${cfg_sessions_session}" \
386   fi   --filename "${cfg_sessions_filename}" \
387     --username "${cfg_sessions_username}" \
388     --password "${cfg_sessions_password}" \
389     --domain "${cfg_sessions_domain}" \
390     --server "${cfg_sessions_browseradrs}"
391    
392     # fluxbox menusession
393     addconfig "[exec] (${cfg_sessions_session}) {nice -n 19 wfica ${ALX_ICA_SESSIONS}/${cfg_sessions_filename}}"
394    
395     # add to all_sessions variable to create icons later for these
396     all_sessions="${all_sessions} ${cfg_sessions_filename}"
397   done   done
398    
399     # delete all progs
400     progsh_path="${ALX_UNPRIV_HOME}/.alxprogs"
401     [ -d ${progsh_path} ] && rm -rf ${progsh_path}
402     install -d ${progsh_path}
403    
404   # add other menuitems   # add other menuitems
405   addconfig $(get_other_menuitems)   for i in ${all_other_ids}
406     do
407     evaluate_table cfg_other_menuitems "where serial='${ALX_SERIAL}' and id='${i}'"
408    
409     # now echo config line for fluxbox-menu
410     # make it "configureable" :p
411     if [[ -n ${cfg_other_menuitems_workdir} ]]
412     then
413     workdir="--workdir ${cfg_other_menuitems_workdir}"
414     fi
415     if [[ -n ${cfg_other_menuitems_icon} ]]
416     then
417     cfg_other_menuitems_icon="<${cfg_other_menuitems_icon}>"
418     fi
419    
420     # gen prog startup wrapper
421     generate_program_sh \
422     --name "${cfg_other_menuitems_name}" \
423     --exec "${cfg_other_menuitems_exec}" \
424     --dest "${progsh_path}/${cfg_other_menuitems_name}" \
425     "${cfg_other_menuitems_workdir}"
426    
427     addconfig "[exec] (${cfg_other_menuitems_name}) {${progsh_path}/${cfg_other_menuitems_name}} ${cfg_other_menuitems_icon}"
428    
429     # add to all_other_menuitems variable to create icons later for these
430     all_other_menuitems="${all_other_menuitems} ${cfg_other_menuitems_name}"
431     done
432    
433   # fluxbox menu footer   # fluxbox menu footer
434   cat ${ALX_SKELETONS}/fluxbox/menu.footer >> ${ALX_UNPRIV_HOME}/.fluxbox/menu   cat ${ALX_SKELETONS}/fluxbox/menu.footer >> ${ALX_UNPRIV_HOME}/.fluxbox/menu
   
435   # add a newline (maybe there is no crlf in the footer)   # add a newline (maybe there is no crlf in the footer)
436   addconfig   addconfig
437    
438   # now it's a good time to generate *all* icons :)   # now it's a good time to generate *all* icons :)
439   generate_all_desktop_icons   generate_all_desktop_icons "${all_sessions}" "${all_other_menuitems}"
440    
441   # set correct permissions   # fix permissions
442   chown ${ALX_UNPRIV_USER}:${ALX_UNPRIV_GROUP} ${ALX_UNPRIV_HOME}   chown ${ALX_UNPRIV_USER}:${ALX_UNPRIV_GROUP} ${ALX_UNPRIV_HOME}
443   chown ${ALX_UNPRIV_USER}:${ALX_UNPRIV_GROUP} ${ALX_UNPRIV_HOME}/.fluxbox   chown ${ALX_UNPRIV_USER}:${ALX_UNPRIV_GROUP} ${ALX_UNPRIV_HOME}/.fluxbox
444   chmod 0755 ${ALX_UNPRIV_HOME}/.fluxbox   chmod 0755 ${ALX_UNPRIV_HOME}/.fluxbox
445   chmod 0755 ${ALX_UNPRIV_HOME}/.xtdesktop   chmod 0755 ${ALX_UNPRIV_HOME}/.xtdesktop
446   chmod 0644 ${ALX_UNPRIV_HOME}/.xtdeskrc   chmod 0644 ${ALX_UNPRIV_HOME}/.xtdeskrc
   
  # unset vars  
  unset ALX_SESSIONS  
  unset ALX_PROGRAMS  
  unset ALX_SCRN_SAVER  
  unset ALX_SCRN_TIMEOUT  
  unset ALX_SCRN_PASSWD  
447  }  }

Legend:
Removed from v.2148  
changed lines
  Added in v.2149