%
% anyremote configuration file for  customization of GUI of Java client. (Server-mode)
%

% STATUS stable
% XTEST no
% SOUND no
% ENV no

GuiAppName=Admin
GuiAppType=Example
GuiAppBinary=true
GuiAppProtocols=Server
GuiAppDesc=Show free space on disks, system uptime, user processes. Allows ro reboot PC.

[Protocol]=Server

(Init)=\
	Include($(CfgDir)/Utils/aliases-server.cfg);

(Connect)=\
	ExecAndSet(status,uname -n);\
	ExecAndSet(title,whoami);\
	Set(icons,ADMIN,1,plus,2,default,3,default,4,default,5,default,6,default,7,default,8,default,9,default,*,default,0,default,#,default);

* *=Set(text,replace,Help,1 - Show list of features\n0 - Exit)
Back=Set(text,close);

1=Make(mode,LIST);

[Mode]=LIST

ADM_LIST=Set(list,replace,Available commands,Disk free space,Uptime, User Processes,File List,Dmesg output,Reboot,Shutdown);

(EnterMode)=\
	Macro(ADM_LIST);\
	Set(menu,replace,Choose);
	
Back($$)=Set(list,close);Make(mode,default);

TOP_TIMER=ExecAndSet(text,replace,top,top -bn 1|head -10|tr -s ' '|cut -f 2,3,10,13 -d ' '|tail -5);

Choose(Disk free space)=ExecAndSet(text,replace,Free Space,df -kl|tr -s ' '|cut -f 1,4 -d ' ');Make(mode,TXT);
%Choose(Run Top)        =Make(mode,TXT);Macro(TOP_TIMER);Timer(TOP_TIMER,5,0);
%Choose(Stop Top)       =Timer(TOP_TIMER,cancel);
Choose(Uptime)         =Set(list,close);ExecAndSet(title,uptime|tr -s ' '|cut -d ' ' -f 3,4,5);Make(mode,default);
Choose(File List)      =Make(mode,FILES);
Choose(User Processes) =Make(mode,PROCS);
Choose(Dmesg output)   =ExecAndSet(text,replace,Dmesg output, dmesg|tail -50);Make(mode,TXT);
Choose(Reboot)	       =Exec(reboot)
Choose(Shutdown)       =Exec(poweroff)

Push(Disk free space) =ExecAndSet(text,replace,Free Space,df -kl|tr -s ' '|cut -f 1,4 -d ' ');Make(mode,TXT);
%Push(Run Top)        =Make(mode,TXT);Macro(TOP_TIMER);Timer(TOP_TIMER,5,0);
%Push(Stop Top)       =Timer(TOP_TIMER,cancel);
Push(Uptime)          =Set(list,close);ExecAndSet(title,uptime|tr -s ' '|cut -d ' ' -f 3,4,5);Make(mode,default);
Push(File List)       =Make(mode,FILES);
Push(User Processes)  =Make(mode,PROCS);
Push(Dmesg output)    =ExecAndSet(text,replace,Dmesg output, dmesg|tail -50);Make(mode,TXT);
Push(Reboot)	      = =Exec(reboot)
Push(Shutdown)        =Exec(poweroff)

[ModeEnd]

[Mode]=TXT
Back=Set(text,close);Timer(TOP_TIMER,cancel);Make(mode,LIST);
[ModeEnd]

[Mode]=FILES

(EnterMode)=ExecAndSet(list,replace,Files,cd `cat $HOME/.anyRemote/ar_storedir.tmp`;echo `pwd`>$HOME/.anyRemote/ar_storedir.tmp;ls -F| sed 's/$/,/'|sed 's/(/openbrace/g'|sed 's/)/closebrace/g');Set(list,add,SAME,..);Set(menu,replace,Choose,File info);

File info($$)=ExecAndSet(text,replace,File info,cd `cat $HOME/.anyRemote/ar_storedir.tmp`;file $(Param));Set(text,add,SAME,\n);ExecAndSet(text,add,File info,cd `cat $HOME/.anyRemote/ar_storedir.tmp`;ls -l $(Param));Make(mode,TXT2);
Choose($$)=ExecAndSet(list,replace,SAME,echo 'cd `cat $HOME/.anyRemote/ar_storedir.tmp`;if [ -d $(Param) ]; then cd $(Param);fi;pwd>$HOME/.anyRemote/ar_storedir.tmp;ls -F| sed "s/$/,/"|sed "s/(/openbrace/g"|sed "s/)/closebrace/g";'|bash -f -s);Set(list,add,SAME,..)

Back($$)=\
	Make(mode,LIST);\
	Macro(ADM_LIST);\
	Set(menu,replace,Choose);

[ModeEnd]

[Mode]=TXT2
Back=Set(text,close);Make(mode,FILES);
[ModeEnd]

[Mode]=PROCS

(EnterMode)=ExecAndSet(list,replace,User Processes, ps -o pid -o command -u `whoami`|tr -s ' '|cut -d ' ' -f 1,2,3|sed 's/$/,/'|grep -v sed|grep -v cut);Set(menu,replace,Kill);

Kill($$)=Exec(kill `echo $(Param)|cut -d ' ' -f 1`);ExecAndSet(list,replace,SAME,ps -o pid -o command -u `whoami`|tr -s ' '|cut -d ' ' -f 1,2,3|sed 's/$/,/'|grep -v sed|grep -v cut);
Back($$)=Make(mode,LIST);

[ModeEnd]

[End]
