# $Id$ # configures ica-sessions on the host via mysql db settings fix_whitespaces() { local var="$@" echo "${var//\ /_}" } # helper function to create citrix session files generate_ica_session_file() { local i local num local server local ses_session local ses_filename local ses_username local ses_domain local ses_password local ses_browseradrs local ses_colors local CONFIG # 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) shift; ses_browseradrs="$1" ;; --colordepth) shift; ses_colors="$1" ;; esac shift done # abort if session, filename or server not given [[ -z ${ses_session} ]] && return 1 [[ -z ${ses_filename} ]] && return 1 [[ -z ${ses_browseradrs} ]] && return 1 # write session files CONFIG="${ALX_ICA_SESSIONS}/${ses_filename}" clearconfig addconfig '[WFClient]' addconfig 'Version=2' # use ';' as ifs declare -i i=0 for server in ${ses_browseradrs//;/ } do (( 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}" # convert to ica session file values case ${ses_colors} in 24|32) ses_colors="8";; 16) ses_colors="4";; 8) ses_colors="2";; *) ses_colors="4";; # default to 16bit esac 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' } # generates a sh file to start programs generate_program_sh() { local dest local name local exec local param local workdir local CONFIG # very basic getops for i in $* do case $1 in --name|-n) shift; name="$1" ;; --exec|-x) shift; exec="$1" ;; --param|-p) shift; param="$1" ;; --dest|-d) shift; dest="$1" ;; --workdir|-w) shift; workdir="$1" ;; esac shift done # abort if name, dest or exec not given [[ -z ${name} ]] && return 1 [[ -z ${exec} ]] && return 1 [[ -z ${dest} ]] && return 1 CONFIG="${dest}" addconfig "#!/bin/sh" [ -n "${workdir}" ] && addconfig "cd ${workdir}" addconfig "exec ${exec} ${param}" chmod 0755 "${dest}" } # helper functions for generate all desktop icons generate_icon() { local name local icon local command local dest local yres local xres local iwidth local iheight local deficon local CONFIG local utility # very basic getops for i in $* do case $1 in --name|-n) shift; name="$1" ;; --command|-c) shift; command="$1" ;; --icon|-i) shift; icon="$1" ;; --dest|-d) shift; dest="$1" ;; --xres|-x) shift; xres="$1" ;; --yres|-y) shift; yres="$1" ;; --icon-width|-w) shift; iwidth="$1" ;; --icon-height|-h) shift; iheight="$1" ;; --default-icon) shift; deficon="$1" ;; esac shift done # some sanity checks: # abort if name or command not given [[ -z ${name} ]] && return 1 [[ -z ${command} ]] && return 1 [[ -z ${dest} ]] && dest="${ALX_UNPRIV_HOME}/.idesktop/${name}.lnk" # use some defaults for icon, dest, {x,y}res [[ -z ${xres} ]] && xres=30 [[ -z ${yres} ]] && xres=30 if [[ -z ${icon} ]] || [ ! -f ${icon} ] then # if no default icon is given use default.png [[ -z ${deficon} ]] && deficon="default.png" icon="${ALX_SESSIONS_ICONS}/${deficon}" fi CONFIG="${dest}" clearconfig addconfig 'table Icon' addconfig " Caption: ${name}" addconfig " Command: ${command}" addconfig " Icon: ${icon}" addconfig " X: ${xres}" addconfig " Y: ${yres}" # add these only if not zero if [[ ! -z ${iwidth} ]] && [[ ! -z ${iheight} ]] then addconfig " Width: ${iwidth}" addconfig " Height: ${iheight}" fi addconfig 'end' } generate_all_desktop_icons() { local session_list="$1" local other_menuitem_list="$2" local res local xres local yres local x local y local i local name local progsh_path local utility local dest local rc dest="${ALX_UNPRIV_HOME}/.idesktop" rc="${ALX_UNPRIV_HOME}/.ideskrc" # 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="${res%x*}" yres="${res#*x}" # top left edge of the icon is given in config file # remove a little bit to simulate the bottom-right edge xres="$(( ${xres} - 120 ))" yres="$(( ${yres} - 80 ))" # clean desktop icon location [ -d ${dest} ] && rm -rf ${dest} [ -f ${rc} ] && rm -f ${rc} install -d ${dest} # default settings declare -i x=30 declare -i y=30 # ica icons for i in ${session_list} do # abort if empty [[ -z ${i} ]] && continue # get database information evaluate_table cfg_sessions "where serial='${ALX_SERIAL}' and id='${i}'" # new line if x > xres if [ ${x} -ge ${xres} ] then x=30 y=$((${y} + 80)) fi # new row if y > yres if [ ${y} -ge ${yres} ] then x=$((${x} + 120)) y=30 # re-check x [ ${x} -ge ${xres} ] && x=30 fi generate_icon \ --name "${cfg_sessions_session}" \ --command "nice -n 19 wfica ${ALX_ICA_SESSIONS}/$(fix_whitespaces ${cfg_sessions_filename})" \ --icon "${ALX_SESSIONS_ICONS}/$(fix_whitespaces ${cfg_sessions_session}).png" \ --dest "${dest}/$(fix_whitespaces ${cfg_sessions_session}).lnk" \ --xres "${x}" \ --yres "${y}" y=$((${y} + 80)) done for i in ${other_menuitem_list} do # abort if empty [[ -z ${i} ]] && continue # get database information evaluate_table cfg_other_menuitems "where serial='${ALX_SERIAL}' and id='${i}'" # new line if x > xres if [ ${x} -ge ${xres} ] then x=30 y=$((${y} + 80)) fi # new row if y > yres if [ ${y} -ge ${yres} ] then x=$((${x} + 120)) y=30 # re-check x [ ${x} -ge ${xres} ] && x=30 fi generate_icon \ --name "${cfg_other_menuitems_name}" \ --command "${progsh_path}/$(fix_whitespaces ${cfg_other_menuitems_name})" \ --icon "${ALX_SESSIONS_ICONS}/$(fix_whitespaces ${cfg_other_menuitems_name}).png" \ --dest "${dest}/$(fix_whitespaces ${cfg_other_menuitems_name}).lnk" \ --xres "${x}" \ --yres "${y}" \ --default-icon "default_item.png" y=$((${y} + 80)) done # add shutdown, reboot icons for i in shutdown reboot do # new line if x > xres if [ ${x} -ge ${xres} ] then x=30 y=$((${y} + 80)) fi # new row if y > yres if [ ${y} -ge ${yres} ] then x=$((${x} + 120)) y=30 # re-check x [ ${x} -ge ${xres} ] && x=30 fi case ${i} in shutdown) name="Herunterfahren" ;; reboot) name="Neustarten" ;; esac generate_icon \ --name "${name}" \ --command "/usr/lib/alxconfig-ng/bin/user_${i}.sh" \ --icon "${ALX_SESSIONS_ICONS}/${i}.png" \ --dest "${dest}/${i}.lnk" \ --xres "${x}" \ --yres "${y}" y=$((${y} + 80)) done # last but not least gen a icon with some sys informations local sysinfo local hostname local osversion osversion="$(< /etc/mageversion)" hostname=$(mysqldo "select hostname from cfg_network where serial='${ALX_SERIAL}'") sysinfo="Hostname: ${hostname} Serial: #${ALX_SERIAL} OS: alx-${osversion} Kernel: $(uname -r)" # now get the right position: # restore orig values of xres xres="$(( ${xres} + 120 ))" # default y pos (full yres -22 = cur yres + 58 !) yres="$(( ${yres} + 58 ))" # middle of the screen # (no txt - length required, xtdesk manage that itself) xres="$(( ${xres} / 2))" generate_icon \ --name "${sysinfo}" \ --command "exit 0" \ --icon "${ALX_SESSIONS_ICONS}/sysinfo.png" \ --dest "${dest}/sysinfo.lnk" \ --xres "${xres}" \ --yres "${yres}" \ --icon-width "1" \ --icon-height "1" } config_sessions() { local i local all_ses_ids local all_other_ids local CONFIG local screensaver_passwd_cmd local fbinit local fbkeys # 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 # get current color depth evaluate_table cfg_graphic # now setup fluxbox for user station # create a fresh fluxbox directory [ -d ${ALX_UNPRIV_HOME}/.fluxbox ] && rm -rf ${ALX_UNPRIV_HOME}/.fluxbox install -d ${ALX_UNPRIV_HOME}/.fluxbox # now generate fluxbox config files # fluxbox main config if [ -f ${ALX_SKELETONS}/fluxbox/init ] then fbinit="${ALX_SKELETONS}/fluxbox/init" else fbinit="/usr/share/fluxbox/init" fi cat ${fbinit} > ${ALX_UNPRIV_HOME}/.fluxbox/init # fluxbox autostart CONFIG="${ALX_UNPRIV_HOME}/.fluxbox/apps" # do not show decorations on messages generated with xmessage if [ -x /usr/bin/xmessage ] then addconfig '[app] (xmessage)' addconfig ' [Deco] {NONE}' addconfig '[end]' fi # add icon utility [ -x /usr/bin/idesk ] && addconfig '[startup] {nohup idesk > /dev/null &}' # add numlock utility [ -x /usr/bin/numlockx ] && addconfig '[startup] {nohup numlockx on &}' # add screensaver if [[ ! -z ${cfg_screensaver_screensaver} ]] && [[ ! -z ${cfg_screensaver_screensaver_timeout} ]] then if [[ -z ${cfg_screensaver_password} ]] || [[ ${cfg_screensaver_password} = NULL ]] then screensaver_passwd_cmd="-nolock" else screensaver_passwd_cmd="-cpasswd $(cryptpw -m des ${cfg_screensaver_password})" fi 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 ${cfg_autostart_session} ]] then # sleep one second to wait until busybox is fully initialized and the screen is really centered addconfig "[startup] {sleep 1 && nohup nice -n 19 wfica ${ALX_ICA_SESSIONS}/$(fix_whitespaces ${cfg_autostart_session}) &}" fi # fluxbox hotkeys if [ -f ${ALX_SKELETONS}/fluxbox/keys ] then fbkeys="${ALX_SKELETONS}/fluxbox/keys" else fbkeys="/usr/share/fluxbox/keys" fi cat ${fbkeys} > ${ALX_UNPRIV_HOME}/.fluxbox/keys # generate a fluxbox menu CONFIG="${ALX_UNPRIV_HOME}/.fluxbox/menu" clearconfig # 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 # first generate session files for i in ${all_ses_ids} do evaluate_table cfg_sessions "where serial='${ALX_SERIAL}' and id='${i}'" generate_ica_session_file \ --session "${cfg_sessions_session}" \ --filename "$(fix_whitespaces ${cfg_sessions_filename})" \ --username "${cfg_sessions_username}" \ --password "${cfg_sessions_password}" \ --domain "${cfg_sessions_domain}" \ --server "${cfg_sessions_browseradrs}" \ --colordepth "${cfg_graphic_depth}" # fluxbox menusession addconfig "[exec] (${cfg_sessions_session}) {nice -n 19 wfica ${ALX_ICA_SESSIONS}/$(fix_whitespaces ${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 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}" \ --param "${cfg_other_menuitems_param}" \ --dest "${progsh_path}/$(fix_whitespaces ${cfg_other_menuitems_name})" \ "${workdir}" addconfig "[exec] (${cfg_other_menuitems_name}) {${progsh_path}/$(fix_whitespaces ${cfg_other_menuitems_name})} ${cfg_other_menuitems_icon}" 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 "${all_ses_ids}" "${all_other_ids}" # 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}/.idesktop chmod 0644 ${ALX_UNPRIV_HOME}/.ideskrc }