This file is indexed.

/usr/sbin/kamdbctl is in kamailio 4.2.0-2+deb8u3.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
#!/bin/bash 
#
# control tool for maintaining Kamailio databases
#
#===================================================================

### version for this script
VERSION='4.2.0'

PATH=$PATH:/

# for testing only, please don't enable this in production environments
# as this introduce security risks
TEST="false"

### include resource files, if any

# check for rc file at same location with kamdbctl
which greadlink > /dev/null
ret=$?
if [ $ret -eq 0 ] ; then
	KAMCTLFULLPATH=$(greadlink -f "$0")
else
	which readlink > /dev/null
	ret=$?
	if [ $ret -eq 0 ] ; then
		KAMCTLFULLPATH=$(readlink -f "$0")
	fi
fi
if [ -n "$KAMCTLFULLPATH" ] ; then
	KAMCTLDIRPATH=$(dirname "$KAMCTLFULLPATH")
	if [ -f $KAMCTLDIRPATH/kamctlrc ]; then
		. $KAMCTLDIRPATH/kamctlrc
	fi
fi

# check for rc file at standard locations
if [ -f /etc/kamailio/kamctlrc ]; then
	. /etc/kamailio/kamctlrc
fi
if [ -f /etc/kamailio//kamctlrc ]; then
	. /etc/kamailio//kamctlrc
fi
if [ -f ~/.kamctlrc ]; then
	. ~/.kamctlrc
fi

if [ $TEST = "true" ]; then
	if [ -f ./kamctlrc ]; then
		. ./kamctlrc
	fi
fi


if [ -z "$MYDIR" ] ; then
	MYDIR=`dirname $0`
fi

if [ -z "$MYLIBDIR" ] ; then
	MYLIBDIR="/usr/lib/x86_64-linux-gnu/kamailio//kamctl"
	if [ ! -d "$MYLIBDIR" ]; then
		MYLIBDIR=$MYDIR
	fi
fi


##### ------------------------------------------------ #####
### load base functions
#
if [ -f "$MYLIBDIR/kamdbctl.base" ]; then
	. "$MYLIBDIR/kamdbctl.base"
else
	echo -e "Cannot load core functions '$MYLIBDIR/kamdbctl.base' - exiting ...\n"
	exit -1
fi

#
##### ------------------------------------------------ #####
### DBENGINE
#
unset USED_DBENGINE
if [ -z "$DBENGINE" ] ; then
	merr "database engine not specified, please setup one in the config script"
	exit 1
fi

case $DBENGINE in
	MYSQL|mysql|MySQL)
		if [ -f "$MYLIBDIR/kamdbctl.mysql" ]; then
			. "$MYLIBDIR/kamdbctl.mysql"
			USED_DBENGINE="mysql"
		else
			merr "could not load the script in $MYLIBDIR/kamdbctl.mysql for database engine $DBENGINE"
		fi
		;;
	PGSQL|pgsql|postgres|postgresql|POSTGRESQL)
		if [ -f "$MYLIBDIR/kamdbctl.pgsql" ]; then
			. "$MYLIBDIR/kamdbctl.pgsql"
			USED_DBENGINE="postgres"
		else
			merr "could not load the script in $MYLIBDIR/kamdbctl.pgsql for database engine $DBENGINE"
		fi
		;;
	ORACLE|oracle|Oracle)
		if [ -f "$MYLIBDIR/kamdbctl.oracle" ]; then
			. "$MYLIBDIR/kamdbctl.oracle"
			USED_DBENGINE="oracle"
		else
			merr "could not load the script in $MYLIBDIR/kamdbctl.oracle for database engine $DBENGINE"
		fi
		;;
	DBTEXT|dbtext|textdb)
		if [ -f "$MYLIBDIR/kamdbctl.dbtext" ]; then
			. "$MYLIBDIR/kamdbctl.dbtext"
			USED_DBENGINE="dbtext"
			DBNAME=$DB_PATH
		else
			merr "could not load the script in $MYLIBDIR/kamdbctl.dbtext for database engine $DBENGINE"
		fi
		;;
	DB_BERKELEY|db_berkeley|BERKELEY|berkeley)
		if [ -f "$MYLIBDIR/kamdbctl.db_berkeley" ]; then
			. "$MYLIBDIR/kamdbctl.db_berkeley"
			USED_DBENGINE="berkeley"
			DBNAME=$DB_PATH
		else
			merr "could not load the script in $MYLIBDIR/kamdbctl.db_berkeley for database engine $DBENGINE"
		fi
		;;
	SQLITE|sqlite)
		if [ -f "$MYLIBDIR/kamdbctl.sqlite" ]; then
			. "$MYLIBDIR/kamdbctl.sqlite"
			USED_DBENGINE="sqlite"
			DBNAME=$DB_PATH
		else
			merr "could not load the script in $MYLIBDIR/kamdbctl.sqlite for database engine $DBENGINE"
		fi
		;;
esac

if [ -z "$USED_DBENGINE" ] ; then
	merr "database engine not loaded - tried '$DBENGINE'"
	exit 1
else
	mdbg "database engine '$USED_DBENGINE' loaded"
fi


# dump all rows
kamailio_dump()  # pars: <database name>
{
	if [ $# -ne 2 ] ; then
		merr "kamailio_dump function takes two param"
		exit 1
	fi
	if [ "$USED_DBENGINE" == "oracle" ]; then
		oracle_dump $1 $2
	elif [ "$PW" = "" ] ; then
		$DUMP_CMD $1 > $2
	else
		$DUMP_CMD "-p$PW" $1 > $2
	fi
	if [ "$?" -ne 0 ]; then
			merr "db dump failed"
			exit 1
	fi
	minfo "db dump successful"
}


kamailio_restore() #pars: <database name> <filename>
{
	if [ $# -ne 2 ] ; then
		merr "kamailio_restore function takes two params"
		exit 1
	fi
	if [ "$USED_DBENGINE" == "oracle" ]; then
		oracle_restore $1 $2
	else
		sql_query $1 < $2
	fi
	if [ "$?" -ne 0 ]; then
			merr "db restore failed"
			exit 1
	fi
	minfo "db restore successful"
}


kamailio_pframework_create() #pars: none
{
	if [ -e $DEFAULT_CFG_DIR/pi_framework_sample ] ; then
		get_answer ask "Sample already exists. Overwrite? (y/n): "
		if [ "$ANSWER" != "y" ]; then
			exit 1
		fi
	fi
	touch $DEFAULT_CFG_DIR/pi_framework_sample
	if [ $? -ne 0 ] ; then
		merr "Unable to create $DEFAULT_CFG_DIR/pi_framework_sample"
		exit 1
	fi

	if [ -d "$DATA_DIR/xhttp_pi" ] ; then
		PI_MODULES="$STANDARD_MODULES"
	else
		merr "Please install first the xhttp_pi module"
		exit 1
	fi


	get_answer $INSTALL_EXTRA_TABLES "Add provisionning framework for extra tables? (y/n): "
	if [ "$ANSWER" = "y" ]; then
		PI_MODULES="$PI_MODULES $EXTRA_MODULES"
	fi

	get_answer $INSTALL_PRESENCE_TABLES "Add provisionning framework for presence tables? (y/n): "
	if [ "$ANSWER" = "y" ]; then
		PI_PRESENCE_MODULES="TRUE"
	fi

	cat $DATA_DIR/xhttp_pi/pi_framework-00 > $DEFAULT_CFG_DIR/pi_framework_sample
	for TABLE in $PI_MODULES; do
		if [ -e $DATA_DIR/xhttp_pi/$TABLE-table ]; then
			cat $DATA_DIR/xhttp_pi/$TABLE-table >> $DEFAULT_CFG_DIR/pi_framework_sample
		else
			merr "Unable to configure: $TABLE - missing table descriptor"
		fi
	done
	if [ "$PI_PRESENCE_MODULES" = "TRUE" ]; then
		if [ -e $DATA_DIR/xhttp_pi/presence-table ]; then
			cat $DATA_DIR/xhttp_pi/presence-table >> $DEFAULT_CFG_DIR/pi_framework_sample
		else
			merr "Unable to configure: presence - missing table descriptor"
		fi
		if [ -e $DATA_DIR/xhttp_pi/rls-table ]; then
			cat $DATA_DIR/xhttp_pi/rls-table >> $DEFAULT_CFG_DIR/pi_framework_sample
		else
			merr "Unable to configure: rls - missing table descriptor"
		fi
	fi
	cat $DATA_DIR/xhttp_pi/pi_framework-01 >> $DEFAULT_CFG_DIR/pi_framework_sample
	for TABLE in $PI_MODULES; do
		if [ -e $DATA_DIR/xhttp_pi/$TABLE-mod ]; then
			cat $DATA_DIR/xhttp_pi/$TABLE-mod >> $DEFAULT_CFG_DIR/pi_framework_sample
		else
			merr "Unable to configure: $TABLE - missing mod descriptor"
		fi
	done
	if [ "$PI_PRESENCE_MODULES" = "TRUE" ]; then
		if [ -e $DATA_DIR/xhttp_pi/presence-mod ]; then
			cat $DATA_DIR/xhttp_pi/presence-mod >> $DEFAULT_CFG_DIR/pi_framework_sample
		else
			merr "Unable to configure: presence - missing mod descriptor"
		fi
		if [ -e $DATA_DIR/xhttp_pi/rls-mod ]; then
			cat $DATA_DIR/xhttp_pi/rls-mod >> $DEFAULT_CFG_DIR/pi_framework_sample
		else
			merr "Unable to configure: rls - missing mod descriptor"
		fi
	fi
	cat $DATA_DIR/xhttp_pi/pi_framework-02 >> $DEFAULT_CFG_DIR/pi_framework_sample

	minfo "Sample provisionning framework saved as: $DEFAULT_CFG_DIR/pi_framework_sample"
}

kamailio_pframework() #pars: <action>
{
	if [ $# -ne 1 ] ; then
		merr "kamailio_pframework function takes one parameter"
		exit 1
	fi

	case $1 in
		create)
			shift
			kamailio_pframework_create "$@"
			exit $?
			;;
		*)
			merr "Unexpected pframework action: $1"
			usage
			exit 1
			;;
	esac
}



case $1 in
	migrate)
		if [ "$USED_DBENGINE" != "mysql" ] ; then
			merr "$USED_DBENGINE don't support migrate operation"
			exit 1
		fi
		if [ $# -ne 3 ] ; then
			merr "migrate requires 2 parameters: old and new database"
			exit 1
		fi
		# create new database
		minfo "Creating new Database $3...."
		NO_USER_INIT="yes"
		kamailio_create $3
		if [ "$?" -ne 0 ] ; then
			echo "migrate: creating new database failed"
			exit 1
		fi
		# migrate data
		minfo "Migrating data from $2 to $3...."
		migrate_db $2 $3
		minfo "Migration successfully completed."
		exit 0;
		;;
	copy)
		# copy database to some other name
		if [ "$USED_DBENGINE" == "berkeley" -o "$USED_DBENGINE" == "dbtext" ] ; then
			merr "$USED_DBENGINE don't support this operation"
			exit 1
		fi
		shift
		if [ $# -ne 1 ]; then
			usage
			exit 1
		fi
		if [ "$USED_DBENGINE" = "sqlite" ]; then
			cp $DB_PATH $1
			exit $?
		fi
		tmp_file=`mktemp /tmp/kamdbctl.XXXXXXXXXX` || exit 1
		kamailio_dump $DBNAME $tmp_file
		ret=$?
		if [ "$ret" -ne 0 ]; then
			rm $tmp_file
			exit $ret
		fi
		NO_USER_INIT="yes"
		kamailio_create $1
		ret=$?
		if [ "$ret" -ne 0 ]; then
			rm $tmp_file
			exit $ret
		fi
		kamailio_restore $1 $tmp_file
		ret=$?
		rm -f $tmp_file
		exit $ret
		;;
	backup)
		if [ "$USED_DBENGINE" == "berkeley" -o "$USED_DBENGINE" == "dbtext" ] ; then
			merr "$USED_DBENGINE don't support this operation"
			exit 1
		fi
		# backup current database
		shift
		if [ $# -ne 1 ]; then
			usage
			exit 1
		fi
		kamailio_dump $DBNAME $1
		exit $?
		;;
	restore)
		if [ "$USED_DBENGINE" == "berkeley" -o "$USED_DBENGINE" == "dbtext" ] ; then
			merr "$USED_DBENGINE don't support this operation"
			exit 1
		fi
		# restore database from a backup
		shift
		if [ $# -ne 1 ]; then
			usage
			exit 1
		fi
		kamailio_restore $DBNAME $1
		exit $?
		;;
	create)
		# create new database structures
		shift
		if [ $# -eq 1 ] ; then
			DBNAME="$1"
		fi

		kamailio_create $DBNAME
		exit $?
		;;
	presence)
		presence_create $DBNAME
		exit $?
		;;
	extra)
		extra_create $DBNAME
		exit $?
		;;
	dbuid)
		dbuid_create $DBNAME
		exit $?
		;;
	drop)
		# delete kamailio database
		# create new database structures
		shift
		if [ $# -eq 1 ] ; then
			DBNAME="$1"
		fi

		kamailio_drop $DBNAME
		exit $?
		;;
	reinit)
		# delete database and create a new one
		# create new database structures
		shift
		if [ $# -eq 1 ] ; then
			DBNAME="$1"
		fi
		kamailio_drop $DBNAME
		ret=$?
		if [ "$ret" -ne 0 ]; then
			exit $ret
		fi
		kamailio_create $DBNAME
		exit $?
		;;
	dbonly)
		# create only an empty database
		if [ "$USED_DBENGINE" != "mysql" ] ; then
			merr "$USED_DBENGINE db engine doesn't support this operation"
			exit 1
		fi
		shift
		if [ $# -eq 1 ] ; then
			DBNAME="$1"
		fi

		kamailio_db_create $DBNAME
		exit $?
		;;
	grant)
		# grant privileges to database
		if [ "$USED_DBENGINE" != "mysql" ] ; then
			merr "$USED_DBENGINE db engine doesn't support this operation"
			exit 1
		fi
		shift
		if [ $# -eq 1 ] ; then
			DBNAME="$1"
		fi

		kamailio_db_grant $DBNAME
		exit $?
		;;
	revoke)
		# revoke privileges to database
		if [ "$USED_DBENGINE" != "mysql" ] ; then
			merr "$USED_DBENGINE db engine doesn't support this operation"
			exit 1
		fi
		shift
		if [ $# -eq 1 ] ; then
			DBNAME="$1"
		fi

		kamailio_db_revoke $DBNAME
		exit $?
		;;
	add-tables)
		if [ "$USED_DBENGINE" != "mysql" ] ; then
			merr "$USED_DBENGINE don't support add-tables operation"
			exit 1
		fi
		if [ $# -ne 2 ] ; then
			merr "add-tables requires 1 parameter: group id of tables"
			exit 1
		fi
		if [ -z "$DBNAME" ] ; then
			merr "DBNAME is not set"
			exit 1
		fi

		kamailio_add_tables $DBNAME $2
		exit $?
		;;
	bdb|db_berkeley)
		shift
		kamailio_berkeley "$@"
		exit $?
		;;
	pframework)
		shift
		kamailio_pframework "$@"
		exit $?
		;;
	version)
		echo  "$0 $VERSION"
		;;
	*)
		usage
		exit 1;
		;;
esac