--- alx-src/branches/alxconf-060/functions/config_sessions.sh 2011/05/11 09:11:02 2035 +++ alx-src/branches/alxconf-060/functions/config_sessions.sh 2011/05/17 11:47:17 2149 @@ -1,62 +1,11 @@ # $Id$ # configures ica-sessions on the host via mysql db settings -get_sessions_settings() +# helper function to create citrix session files +generate_ica_session_file() { - 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 local i - local x - local browser_address_num + local num local server local ses_session local ses_filename @@ -64,69 +13,59 @@ local ses_domain local ses_password local ses_browseradrs - local ses_colors local CONFIG - # get settings from database - all_ids=$(mysqldo "select id from cfg_sessions where serial='${ALX_SERIAL}'") + # very basic getops + for i in $* + do + case $1 in + --session) shift; ses_session="$1" ;; + --filename) shift; ses_filename="$1" ;; + --username) shift; ses_username="$1" ;; + --password) shift; ses_password="$1" ;; + --domain) shift; ses_domain="$1" ;; + --server) ses_browseradrs="$1" ;; + esac + shift + done + + # abort if session, filename or server not given + [[ -z ${session} ]] && return 1 + [[ -z ${file} ]] && return 1 + [[ -z ${server} ]] && return 1 + + # write session files + CONFIG="${ALX_ICA_SESSIONS}/${ses_filename}" + clearconfig + + addconfig '[WFClient]' + addconfig 'Version=2' - for i in ${all_ids} + # use ';' as ifs + declare -i i=0 + for server in ${ses_browseradrs//;/ } do - # get settings - ses_session=$(mysqldo "select session from cfg_sessions where serial='${ALX_SERIAL}' and id='${i}'") - ses_filename=$(mysqldo "select filename from cfg_sessions where serial='${ALX_SERIAL}' and id='${i}'") - ses_username=$(mysqldo "select username from cfg_sessions where serial='${ALX_SERIAL}' and id='${i}'") - ses_domain=$(mysqldo "select domain from cfg_sessions where serial='${ALX_SERIAL}' and id='${i}'") - ses_password=$(mysqldo "select password from cfg_sessions where serial='${ALX_SERIAL}' and id='${i}'") - 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' + (( i++ )) + num="${i}" + # support newer ica-clients: + # the first address must be named TcpBrowserAddress, but not TcpBrowserAddress1 !! + [[ ${i} -eq 1 ]] && num="" + addconfig "TcpBrowserAddress${num}=${server}" done + + addconfig 'ScreenPercent=0' + addconfig '[ApplicationServers]' + addconfig "${ses_session}=" + addconfig "[${ses_session}]" + addconfig "Address=${ses_session}" + addconfig "InitialProgram=#${ses_session}" + 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' } # generates a sh file to start programs @@ -151,62 +90,16 @@ done # abort if name, dest or exec not given - [ -z "${name}" ] && return 1 - [ -z "${exec}" ] && return 1 - [ -z "${dest}" ] && return 1 + [[ -z ${name} ]] && return 1 + [[ -z ${exec} ]] && return 1 + [[ -z ${dest} ]] && return 1 - CONFIG=${dest} + CONFIG="${dest}" addconfig "#!/bin/sh" [ -n "${workdir}" ] && addconfig "cd ${workdir}" addconfig "exec ${exec}" - 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 + chmod 0755 "${dest}" } # helper functions for generate all desktop icons @@ -240,7 +133,7 @@ shift done - # some sanity checks : + # some sanity checks: # abort if name or command not given [[ -z ${name} ]] && return 1 @@ -280,22 +173,26 @@ generate_all_desktop_icons() { + local session_list="$1" + local other_menuitem_list="$2" local res local xres local yres - local icon_list local x local y local item - local basename_item + local name local progsh_path + # progsh path + progsh_path=${ALX_UNPRIV_HOME}/.alxprogs + # get the resolution res=$(mysqldo "select resolution from cfg_graphic where serial='${ALX_SERIAL}'") # split res to x & y - xres="$(echo ${res} | cut -dx -f1)" - yres="$(echo ${res} | cut -dx -f2)" + xres="${res%x*}" + xres="${res#*x}" # top left edge of the icon is given in config file # remove a little bit to simulate the bottom-right edge @@ -309,20 +206,12 @@ [ -d ${ALX_UNPRIV_HOME}/.xtdesktop ] && rm -rf ${ALX_UNPRIV_HOME}/.xtdesktop install -d ${ALX_UNPRIV_HOME}/.xtdesktop - # default settings declare -i x=30 declare -i y=30 - # first all ica sessions - local count=${#ALX_SESSIONS[*]} - for (( i=0; i < count; i++ )) - do - # filenames ! - icon_list="${icon_list} ${ALX_SESSIONS[${i}]}" - done - - for item in ${icon_list} + # ica icons + for item in ${session_list} do # abort if empty [[ -z ${item} ]] && continue @@ -344,27 +233,19 @@ [ ${x} -ge ${xres} ] && x=30 fi - # ica icons - # get basename (.ica must be suffix) - basename_item="$(basename ${item} .ica)" + name="$(basename ${item} .ica)" generate_icon \ - --name "${basename_item}" \ + --name "${name}" \ --command "nice -n 19 wfica ${ALX_ICA_SESSIONS}/${item}" \ - --icon "${ALX_SESSIONS_ICONS}/${basename_item}.png" \ - --dest "${ALX_UNPRIV_HOME}/.xtdesktop/${basename_item}.lnk" \ + --icon "${ALX_SESSIONS_ICONS}/${name}.png" \ + --dest "${ALX_UNPRIV_HOME}/.xtdesktop/${name}.lnk" \ --xres "${x}" \ --yres "${y}" y=$((${y} + 80)) done - - # generate program icons - icon_list="${ALX_PROGRAMS}" - - progsh_path=${ALX_UNPRIV_HOME}/.alxprogs - - for item in ${icon_list} + for item in ${other_menuitem_list} do # abort if empty [[ -z ${item} ]] && continue @@ -398,8 +279,6 @@ y=$((${y} + 80)) done - - # last but not least gen a icon with some sys informations local sysinfo local hostname @@ -431,18 +310,23 @@ config_sessions() { - # 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 local i + local all_ses_ids + local all_other_ids local CONFIG + local screensaver_passwd_cmd + local all_sessions + local all_other_menuitems + + # get all session ids from database + all_ses_ids=$(mysqldo "select id from cfg_sessions where serial='${ALX_SERIAL}'") + # get all other_menutiem ids from database + all_other_ids=$(mysqldo "select id from cfg_other_menuitems where serial='${ALX_SERIAL}'") + + # get screensaver settings + evaluate_table cfg_screensaver + # get autostart settings + evaluate_table cfg_autostart # now setup fluxbox for user station @@ -453,33 +337,29 @@ # now generate fluxbox config files # fluxbox main config - cat ${ALX_SKELETONS}/fluxbox/init \ - > ${ALX_UNPRIV_HOME}/.fluxbox/init + cat ${ALX_SKELETONS}/fluxbox/init > ${ALX_UNPRIV_HOME}/.fluxbox/init # fluxbox autostart - cat ${ALX_SKELETONS}/fluxbox/apps \ - > ${ALX_UNPRIV_HOME}/.fluxbox/apps + cat ${ALX_SKELETONS}/fluxbox/apps > ${ALX_UNPRIV_HOME}/.fluxbox/apps - CONFIG=${ALX_UNPRIV_HOME}/.fluxbox/apps + CONFIG="${ALX_UNPRIV_HOME}/.fluxbox/apps" # add screensaver - if [[ ! -z ${ALX_SCRN_SAVER} ]] && [[ ! -z ${ALX_SCRN_TIMEOUT} ]] + if [[ ! -z ${cfg_screensaver_screensaver} ]] && [[ ! -z ${cfg_screensaver_screensaver_timeout} ]] then - local ALX_PASSWD_CMD - - if [[ -z ${ALX_SCRN_PASSWD} ]] || [[ ${ALX_SCRN_PASSWD} = NULL ]] + if [[ -z ${cfg_screensaver_password} ]] || [[ ${cfg_screensaver_password} = NULL ]] then - ALX_PASSWD_CMD="-nolock" + screensaver_passwd_cmd="-nolock" else - ALX_PASSWD_CMD="-cpasswd $(cryptpw -m des ${ALX_SCRN_PASSWD})" + screensaver_passwd_cmd="-cpasswd $(cryptpw -m des ${cfg_screensaver_password})" fi - 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 &}" fi # add autostart session - if [[ ! -z ${ALX_AUTOSTART} ]] + if [[ ! -z ${cfg_autostart_session} ]] then - 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} &}" fi # fluxbox hotkeys @@ -491,46 +371,77 @@ # fluxbox menu header cat ${ALX_SKELETONS}/fluxbox/menu.header >> ${ALX_UNPRIV_HOME}/.fluxbox/menu - # now fix it with proper messages :P local ver="$(< /etc/mageversion)" sed -i "s:@CHANGEME@:alx-${ver} #${ALX_SERIAL}:g" ${ALX_UNPRIV_HOME}/.fluxbox/menu - # add a newline (maybe there is no crlf in the header) addconfig - # fluxbox menu sessions - for (( i=0; i < count; i++ )) + # first generate session files + for i in ${all_ses_ids} do - if [[ ! -z ${ALX_SESSIONS[${i}]} ]] - then - addconfig "[exec] ($(basename ${ALX_SESSIONS[${i}]} .ica)) {nice -n 19 wfica ${ALX_ICA_SESSIONS}/${ALX_SESSIONS[${i}]}}" - fi + evaluate_table cfg_sessions "where serial='${ALX_SERIAL}' and id='${i}'" + generate_ica_session_file \ + --session "${cfg_sessions_session}" \ + --filename "${cfg_sessions_filename}" \ + --username "${cfg_sessions_username}" \ + --password "${cfg_sessions_password}" \ + --domain "${cfg_sessions_domain}" \ + --server "${cfg_sessions_browseradrs}" + + # fluxbox menusession + addconfig "[exec] (${cfg_sessions_session}) {nice -n 19 wfica ${ALX_ICA_SESSIONS}/${cfg_sessions_filename}}" + + # add to all_sessions variable to create icons later for these + all_sessions="${all_sessions} ${cfg_sessions_filename}" done + # delete all progs + progsh_path="${ALX_UNPRIV_HOME}/.alxprogs" + [ -d ${progsh_path} ] && rm -rf ${progsh_path} + install -d ${progsh_path} + # add other menuitems - addconfig $(get_other_menuitems) + for i in ${all_other_ids} + do + evaluate_table cfg_other_menuitems "where serial='${ALX_SERIAL}' and id='${i}'" + + # now echo config line for fluxbox-menu + # make it "configureable" :p + if [[ -n ${cfg_other_menuitems_workdir} ]] + then + workdir="--workdir ${cfg_other_menuitems_workdir}" + fi + if [[ -n ${cfg_other_menuitems_icon} ]] + then + cfg_other_menuitems_icon="<${cfg_other_menuitems_icon}>" + fi + + # gen prog startup wrapper + generate_program_sh \ + --name "${cfg_other_menuitems_name}" \ + --exec "${cfg_other_menuitems_exec}" \ + --dest "${progsh_path}/${cfg_other_menuitems_name}" \ + "${cfg_other_menuitems_workdir}" + + addconfig "[exec] (${cfg_other_menuitems_name}) {${progsh_path}/${cfg_other_menuitems_name}} ${cfg_other_menuitems_icon}" + + # add to all_other_menuitems variable to create icons later for these + all_other_menuitems="${all_other_menuitems} ${cfg_other_menuitems_name}" + done # fluxbox menu footer cat ${ALX_SKELETONS}/fluxbox/menu.footer >> ${ALX_UNPRIV_HOME}/.fluxbox/menu - # add a newline (maybe there is no crlf in the footer) addconfig # now it's a good time to generate *all* icons :) - generate_all_desktop_icons + generate_all_desktop_icons "${all_sessions}" "${all_other_menuitems}" - # set correct permissions + # fix permissions chown ${ALX_UNPRIV_USER}:${ALX_UNPRIV_GROUP} ${ALX_UNPRIV_HOME} chown ${ALX_UNPRIV_USER}:${ALX_UNPRIV_GROUP} ${ALX_UNPRIV_HOME}/.fluxbox chmod 0755 ${ALX_UNPRIV_HOME}/.fluxbox chmod 0755 ${ALX_UNPRIV_HOME}/.xtdesktop 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 }