Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2438 - (hide annotations) (download)
Thu Sep 3 12:50:25 2015 UTC (8 years, 8 months ago) by niro
File size: 3314 byte(s)
-added missing mcore.conf include
1 niro 2051 #!/bin/sh
2    
3 niro 2304 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 niro 2051 # globals
12 niro 2304 # 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 niro 2051
19 niro 2304 # load control classes plugins
20     load_classes control
21 niro 2051
22 niro 2438 # config settings
23     include @@SYSCONFDIR@@/mcore/mcore.conf
24    
25 niro 2051 SQL_USER=alx
26     SQL_PASS=@lx
27     SQL_HOST=localhost
28     SQL_DB=alx_web
29    
30     import_resource()
31     {
32     local table="$1"
33     local serial="$2"
34     local resource="$3"
35     local value="$4"
36    
37     if [[ ${DEBUG} = 1 ]]
38     then
39     echo "${table}->${resource}=${value}" >> /root/lala.log
40     echo "mysqldo \"update ${table} set ${resource}='${value}' where serial=${serial};\"" >> /root/lala.log
41     fi
42    
43     mysql_insert "${table}",serial="${serial}","${resource}"="${value}"
44     }
45    
46     nsslsay()
47     {
48     nssl "${IP}" "${PORT}" << EOF
49     auth ${SSLSAY_USER} ${SSLSAY_PASS}
50     $@
51     quit
52     EOF
53     }
54    
55     control_client()
56     {
57     local serial="$1"
58     local command="${@/$1/}"
59     local IP
60    
61     IP=$(mysqldo "select ip from state_connected where serial='${serial}'")
62     if [[ -z ${IP} ]]
63     then
64     echo "no ip found for client '${serial}'"
65     return 1
66     fi
67    
68     nsslsay "${command}"
69     }
70    
71     #IP="192.168.0.6"
72     PORT="6666"
73     SSLSAY_USER="foo"
74     SSLSAY_PASS="bar"
75    
76 niro 2304 DEBUG=1
77     NOCOLORS="false"
78     WEBCRLF="false"
79     QUIET="false"
80    
81     # argvs are global variables - this fixes issues with whitespaces
82     # global argvs, the whole command line
83     export GLOBAL_ARGV
84     # class specific argvs which are given to the class as parameters
85     export CLASS_ARGV
86    
87 niro 2051 run=run
88     valid_session=no
89    
90 niro 2304 # tell what we are
91     echo "Connected to $(print_version)"
92    
93 niro 2051 while [[ ${run} = run ]]
94     do
95 niro 2421 # use an echo here not read -p '>' because sslsvd ignores the prompt pattern
96     echo -n '> '
97 niro 2051 read line
98 niro 2304 eval "GLOBAL_ARGV=( ${line} )"
99 niro 2051
100 niro 2304 case ${GLOBAL_ARGV[0]} in
101 niro 2051 quit) run=quit ;;
102 niro 2304
103     # only react on the globals -> import|get|set|auth
104     import) run_class ;;
105     control) run_class ;;
106     get) run_class ;;
107     set) run_class ;;
108     auth) validate_auth ${GLOBAL_ARGV[*]:1} ;;
109 niro 2423 certauth) validate_auth_certificate ${GLOBAL_ARGV[*]:1} ;;
110 niro 2432 register) valid_session && validate_client ${GLOBAL_ARGV[*]:1} ;;
111 niro 2304 provide) valid_session && print_provide ;;
112     require) valid_session && verify_requirements ;;
113     reload) valid_session && mecho "reloading client classes ..." && load_classes client ;;
114     restart) valid_session && restart_service ;;
115     stop) valid_session && stop_service ;;
116     nocolors) export NOCOLORS="true" ;;
117     colors) export NOCOLORS="false" ;;
118     webcrlf) export WEBCRLF="true" ;;
119     quiet) export QUIET="true" ;;
120     # version does not need auth
121     version) print_version ;;
122     help)
123     if valid_session
124     then
125     if [[ ${line} = help ]]
126     then
127     help_topics
128     else
129     run_class ${line}
130     fi
131     else
132     mecho "You must authenticate yourself first!"
133     mecho " auth [username] [password]"
134 niro 2426 mecho "or"
135     mecho " certauth [certificate fingerprint]"
136 niro 2304 fi
137     ;;
138    
139     *)
140     mecho "Unknown command '${line}'"
141     mecho "Type 'help' for more information."
142     #echo "$line" >> /root/lala.log
143     ;;
144 niro 2051 esac
145 niro 2304
146     # unset argvs to be safe
147     unset GLOBAL_ARGS
148     unset CLASS_ARGS
149 niro 2051 done

Properties

Name Value
svn:executable *