Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2426 - (show annotations) (download)
Thu Sep 3 07:54:18 2015 UTC (8 years, 7 months ago) by niro
File size: 3187 byte(s)
-inform the user about the fingerprint authentication method too
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 # use an echo here not read -p '>' because sslsvd ignores the prompt pattern
93 echo -n '> '
94 read line
95 eval "GLOBAL_ARGV=( ${line} )"
96
97 case ${GLOBAL_ARGV[0]} in
98 quit) run=quit ;;
99
100 # only react on the globals -> import|get|set|auth
101 import) run_class ;;
102 control) run_class ;;
103 get) run_class ;;
104 set) run_class ;;
105 auth) validate_auth ${GLOBAL_ARGV[*]:1} ;;
106 certauth) validate_auth_certificate ${GLOBAL_ARGV[*]:1} ;;
107 provide) valid_session && print_provide ;;
108 require) valid_session && verify_requirements ;;
109 reload) valid_session && mecho "reloading client classes ..." && load_classes client ;;
110 restart) valid_session && restart_service ;;
111 stop) valid_session && stop_service ;;
112 nocolors) export NOCOLORS="true" ;;
113 colors) export NOCOLORS="false" ;;
114 webcrlf) export WEBCRLF="true" ;;
115 quiet) export QUIET="true" ;;
116 # version does not need auth
117 version) print_version ;;
118 help)
119 if valid_session
120 then
121 if [[ ${line} = help ]]
122 then
123 help_topics
124 else
125 run_class ${line}
126 fi
127 else
128 mecho "You must authenticate yourself first!"
129 mecho " auth [username] [password]"
130 mecho "or"
131 mecho " certauth [certificate fingerprint]"
132 fi
133 ;;
134
135 *)
136 mecho "Unknown command '${line}'"
137 mecho "Type 'help' for more information."
138 #echo "$line" >> /root/lala.log
139 ;;
140 esac
141
142 # unset argvs to be safe
143 unset GLOBAL_ARGS
144 unset CLASS_ARGS
145 done

Properties

Name Value
svn:executable *