-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustom_permission.sh
executable file
·133 lines (110 loc) · 4.47 KB
/
custom_permission.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/bin/sh
# dynamic fields for user_name
MYDIR="$( /usr/bin/dirname $0 )"
FORM_PATH="$( /bin/realpath ${MYDIR} )"
HELPER="rabbitmq"
: ${distdir="/usr/local/cbsd"}
# MAIN
if [ -z "${workdir}" ]; then
[ -z "${cbsd_workdir}" ] && . /etc/rc.conf
[ -z "${cbsd_workdir}" ] && exit 0
workdir="${cbsd_workdir}"
fi
set -e
. ${distdir}/cbsd.conf
. ${subrdir}/tools.subr
. ${subr}
set +e
FORM_PATH="${workdir}/formfile"
[ ! -d "${FORM_PATH}" ] && err 1 "No such ${FORM_PATH}"
###
groupname="permissionsgroup"
err() {
exitval=$1
shift
echo "$*"
exit $exitval
}
add()
{
if [ -r "${formfile}" ]; then
/usr/local/bin/cbsd ${miscdir}/updatesql ${formfile} /usr/local/cbsd/share/forms_yesno.schema purge_truefalse${index}
${SQLITE3_CMD} ${formfile} <<EOF
BEGIN TRANSACTION;
INSERT INTO forms ( mytable,group_id,order_id,param,desc,def,cur,new,mandatory,attr,xattr,type,link,groupname ) VALUES ( 'forms', ${index},${order_id},'permission_user_vhost${index}','user_vhost part ${index}','','','',1, 'maxlen=60', 'dynamic', 'inputbox', '', '${groupname}' );
INSERT INTO forms ( mytable,group_id,order_id,param,desc,def,cur,new,mandatory,attr,xattr,type,link,groupname ) VALUES ( 'forms', ${index},${order_id},'permission_configure_permission${index}','configure_permission part ${index}','.*','','',1, 'maxlen=60', 'dynamic', 'inputbox', '', '${groupname}' );
INSERT INTO forms ( mytable,group_id,order_id,param,desc,def,cur,new,mandatory,attr,xattr,type,link,groupname ) VALUES ( 'forms', ${index},${order_id},'permission_read_permission${index}','read_permission part ${index}','false','.*','',1, 'maxlen=60', 'dynamic', 'inputbox', '', '${groupname}' );
INSERT INTO forms ( mytable,group_id,order_id,param,desc,def,cur,new,mandatory,attr,xattr,type,link,groupname ) VALUES ( 'forms', ${index},${order_id},'permission_write_permission${index}','write_permission part ${index}','false','.*','',1, 'maxlen=60', 'dynamic', 'inputbox', '', '${groupname}' );
COMMIT;
EOF
else
/bin/cat <<EOF
BEGIN TRANSACTION;
INSERT INTO forms ( mytable,group_id,order_id,param,desc,def,cur,new,mandatory,attr,xattr,type,link,groupname ) VALUES ( 'forms', ${index},${order_id},'permission_user_vhost${index}','user_vhost part ${index}','','','',1, 'maxlen=60', 'dynamic', 'inputbox', '', '${groupname}' );
INSERT INTO forms ( mytable,group_id,order_id,param,desc,def,cur,new,mandatory,attr,xattr,type,link,groupname ) VALUES ( 'forms', ${index},${order_id},'permission_configure_permission${index}','configure_permission part ${index}','.*','','',1, 'maxlen=60', 'dynamic', 'inputbox', '', '${groupname}' );
INSERT INTO forms ( mytable,group_id,order_id,param,desc,def,cur,new,mandatory,attr,xattr,type,link,groupname ) VALUES ( 'forms', ${index},${order_id},'permission_read_permission${index}','read_permission part ${index}','false','.*','',1, 'maxlen=60', 'dynamic', 'inputbox', '', '${groupname}' );
INSERT INTO forms ( mytable,group_id,order_id,param,desc,def,cur,new,mandatory,attr,xattr,type,link,groupname ) VALUES ( 'forms', ${index},${order_id},'permission_write_permission${index}','write_permission part ${index}','false','.*','',1, 'maxlen=60', 'dynamic', 'inputbox', '', '${groupname}' );
COMMIT;
EOF
fi
}
del()
{
if [ -r "${formfile}" ]; then
${SQLITE3_CMD} ${formfile} <<EOF
BEGIN TRANSACTION;
DELETE FROM forms WHERE group_id = "${index}" AND groupname = "${groupname}";
COMMIT;
EOF
else
/bin/cat <<EOF
BEGIN TRANSACTION;
DELETE FROM forms WHERE group_id = "${index}" AND groupname = "${groupname}";
COMMIT;
EOF
fi
}
usage()
{
echo "$0 -a add/remove -i index"
}
get_index()
{
local new_index
[ ! -r "${formfile}" ] && err 1 "formfile not readable: ${formfile}"
new_index=$( ${SQLITE3_CMD} ${formfile} "SELECT group_id FROM forms WHERE groupname = '${groupname}' ORDER BY group_id DESC LIMIT 1" )
case "${action}" in
add|create)
index=$(( new_index + 1 ))
;;
del*|remove)
index=$new_index
;;
esac
[ "${index}" = "0" ] && index=1 # protect ADD custom button
}
while getopts "a:i:f:o:" opt; do
case "$opt" in
a) action="${OPTARG}" ;;
i) index="${OPTARG}" ;;
f) formfile="${OPTARG}" ;;
o) order_id="${OPTARG}" ;;
esac
shift $(($OPTIND - 1))
done
[ -z "${action}" ] && usage
[ -z "${index}" -a -n "${formfile}" ] && get_index
[ -z "${index}" -a -z "${formfile}" ] && index=1
[ -z "${order_id}" -a -z "${formfile}" ] && order_id=1
#echo "Index: $index, Action: $action, Groupname: $groupname"
case "${action}" in
add|create)
add
;;
del*|remove)
del
;;
*)
echo "Unknown action: must be 'add' or 'del'"
;;
esac