Magellan Linux

Contents of /mcore-src/trunk/mcore-tools/src/mcore-controld.in

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2304 - (show annotations) (download)
Mon Jan 20 14:07:32 2014 UTC (10 years, 3 months ago) by niro
File size: 2970 byte(s)
-modified to match new classes and includes
1 #!/bin/sh
2
3 MCORE_LIBDIR="@@MCORE_LIBDIR@@"
4
5 # respect system env (proxy settings etc)
6 if [ -e @@SYSCONFDIR@@/profile ]
7 then
8 source @@SYSCONFDIR@@/profile
9 fi
10
11 # globals
12 # include function comes with common.global class
13 source ${MCORE_LIBDIR}/include/common.global.class
14 include ${MCORE_LIBDIR}/include/daemon.global.class
15 include ${MCORE_LIBDIR}/include/sessionauth.global.class
16 include ${MCORE_LIBDIR}/include/mysqlfunctions.global.class
17 #include ${MCORE_LIBDIR}/include/hwdetection.global.class
18
19 # load control classes plugins
20 load_classes control
21
22 SQL_USER=alx
23 SQL_PASS=@lx
24 SQL_HOST=localhost
25 SQL_DB=alx_web
26
27 import_resource()
28 {
29 local table="$1"
30 local serial="$2"
31 local resource="$3"
32 local value="$4"
33
34 if [[ ${DEBUG} = 1 ]]
35 then
36 echo "${table}->${resource}=${value}" >> /root/lala.log
37 echo "mysqldo \"update ${table} set ${resource}='${value}' where serial=${serial};\"" >> /root/lala.log
38 fi
39
40 mysql_insert "${table}",serial="${serial}","${resource}"="${value}"
41 }
42
43 nsslsay()
44 {
45 nssl "${IP}" "${PORT}" << EOF
46 auth ${SSLSAY_USER} ${SSLSAY_PASS}
47 $@
48 quit
49 EOF
50 }
51
52 control_client()
53 {
54 local serial="$1"
55 local command="${@/$1/}"
56 local IP
57
58 IP=$(mysqldo "select ip from state_connected where serial='${serial}'")
59 if [[ -z ${IP} ]]
60 then
61 echo "no ip found for client '${serial}'"
62 return 1
63 fi
64
65 nsslsay "${command}"
66 }
67
68 #IP="192.168.0.6"
69 PORT="6666"
70 SSLSAY_USER="foo"
71 SSLSAY_PASS="bar"
72
73 DEBUG=1
74 NOCOLORS="false"
75 WEBCRLF="false"
76 QUIET="false"
77
78 # argvs are global variables - this fixes issues with whitespaces
79 # global argvs, the whole command line
80 export GLOBAL_ARGV
81 # class specific argvs which are given to the class as parameters
82 export CLASS_ARGV
83
84 run=run
85 valid_session=no
86
87 # tell what we are
88 echo "Connected to $(print_version)"
89
90 while [[ ${run} = run ]]
91 do
92 read line
93 eval "GLOBAL_ARGV=( ${line} )"
94
95 case ${GLOBAL_ARGV[0]} in
96 quit) run=quit ;;
97
98 # only react on the globals -> import|get|set|auth
99 import) run_class ;;
100 control) run_class ;;
101 get) run_class ;;
102 set) run_class ;;
103 auth) validate_auth ${GLOBAL_ARGV[*]:1} ;;
104 provide) valid_session && print_provide ;;
105 require) valid_session && verify_requirements ;;
106 reload) valid_session && mecho "reloading client classes ..." && load_classes client ;;
107 restart) valid_session && restart_service ;;
108 stop) valid_session && stop_service ;;
109 nocolors) export NOCOLORS="true" ;;
110 colors) export NOCOLORS="false" ;;
111 webcrlf) export WEBCRLF="true" ;;
112 quiet) export QUIET="true" ;;
113 # version does not need auth
114 version) print_version ;;
115 help)
116 if valid_session
117 then
118 if [[ ${line} = help ]]
119 then
120 help_topics
121 else
122 run_class ${line}
123 fi
124 else
125 mecho "You must authenticate yourself first!"
126 mecho " auth [username] [password]"
127 fi
128 ;;
129
130 *)
131 mecho "Unknown command '${line}'"
132 mecho "Type 'help' for more information."
133 #echo "$line" >> /root/lala.log
134 ;;
135 esac
136
137 # unset argvs to be safe
138 unset GLOBAL_ARGS
139 unset CLASS_ARGS
140 done

Properties

Name Value
svn:executable *