This repository has been archived by the owner on May 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
dsapp-test.sh
executable file
·5803 lines (5087 loc) · 194 KB
/
dsapp-test.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
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
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
##################################################################################################
#
# dsapp was created to help customers and support engineers troubleshoot
# and solve common issues for the Novell GroupWise Mobility product.
#
# by Tyler Harris and Shane Nielson
#
##################################################################################################
dsappversion='227'
##################################################################################################
# Set up banner logo
##################################################################################################
function datasyncBanner {
s=`cat << "EOF"
_
__| |___ __ _ _ __ _ __
/ _' / __|/ _' | '_ \\| '_ \\
| (_| \__ | (_| | |_) | |_) |
\__,_|___/\__,_| .__/| .__/
|_| |_|
EOF
`
clear; echo -e "$s\n\t\t\t v$dsappversion\n"
}
##################################################################################################
# Start up Checks
##################################################################################################
# Get dsapp PID
pidFile=/opt/novell/datasync/tools/dsapp/conf/dsapp.pid
echo $$ >> $pidFile
# Clean up previous PIDs if not found
while IFS='' read -r line || [[ -n "$line" ]]; do
if [ -z `ps -p $line -o comm=` ];then
sed -i "/$line/d" $pidFile
fi
done < $pidFile
# Running in interactive shell?
INTERACTIVE_USER=false
tty -s
if [ $? -eq 0 ];then
INTERACTIVE_USER=true;
fi
function cleanup_exit {
# Clear dsapp/tmp
rm -f /opt/novell/datasync/tools/dsapp/tmp/* 2>/dev/null
# Removes .pgpass if pgpass=true in dsapp.conf
if ($pgpass);then
if [ `cat /opt/novell/datasync/tools/dsapp/conf/dsapp.pid | wc -l` -eq '1' ];then
rm -f ~/.pgpass;
fi
fi
# Remove PID from dsapp.pid
sed -i '/'$$'/d' /opt/novell/datasync/tools/dsapp/conf/dsapp.pid
# Reset the terminal (clear silent mode)
stty sane
}
function trapCall {
# Exit watch while staying in dsapp
if ($monitorValue);then
monitorValue=false;
else
# Clean up and exit script
clear;
# clean up files
cleanup_exit;
exit 1;
fi
}
# Trap ^Cctrl c
trap trapCall INT TERM SIGINT
monitorValue=false;
# Clean up on exit
trap cleanup_exit EXIT
# Make sure user is root
if [ "$(id -u)" != "0" ];then
datasyncBanner;
read -p "Please login as root to run this script.";
exit 1;
fi
function eContinue {
local reply="."
echo -n "Press [Enter] to continue"
while [ -n "$reply" ];do
read -n1 -s reply;
done
clear;
}
function eContinueTime {
local reply="."
echo -n "Press [Enter] to continue"
while [ -n "$reply" ];do
read -t5 -n1 -s reply;
if [ $? -eq 1 ];then
break;
fi
done
clear;
}
# Window Size check
if [ `tput lines` -lt '24' ] && [ `tput cols` -lt '85' ];then
echo -e "Terminal window to small [`tput cols` x `tput lines`]\nPlease resize window to [80 x 24] or greater."
echo; eContinue;
exit 1;
fi
# Make sure switch passed in, is valid.
switchArray=('-h' '--help' '--version' '--debug' '--bug' '-au' '--autoUpdate' '-ghc' '--gHealthCheck' '-f' '--force' '-ul' '--uploadLogs' '-c' '--check' '-s' '--status' '-up' '--update' '-v' '--vacuum' '-i' '--index' '-u' '--users' '-d' '--devices' '-db' '--database' '-ch' '--changeHost' '-re' '--restore' '--updateDsapp')
switchCheck="$@"
switchError=false
while IFS= read -r line
do
for word in $line
do
switchFound=`echo ${switchArray[@]} | grep -w -- "$word"`
if [ -z "$switchFound" ];then
echo "dsapp: '"$word"' is not a valid command. See '--help'."
switchError=true
fi
done
done <<< "$switchCheck"
if ($switchError);then
exit 1;
fi
# Check and set force to true
if [ "$1" == "--force" ] || [ "$1" == "-f" ] || [ "$1" == "?" ] || [ "$1" == "-h" ] || [ "$1" == "--help" ] || [ "$1" == "-db" ] || [ "$1" == "--database" ] || [ "$1" == "-re" ] || [ "$1" == "--restore" ];then
forceMode=1;
if [[ "$forceMode" -eq "1" && ( "$1" = "-f" || "$1" = "--force" ) ]];then
datasyncBanner;
echo -e "Running force mode. Some options may not work properly.\n"
read -p "Press [Enter] to continue"
fi
fi
function checkInstall {
# Check if Mobility is installed.
if [[ "$forceMode" -ne "1" ]];then
local dsInstalled=`/sbin/chkconfig | grep -iom 1 datasync`;
if [ "$dsInstalled" != "datasync" ];then
datasyncBanner;
read -p "Mobility is not installed."
clear;
exit 1;
fi
fi
}
checkInstall;
##################################################################################################
# Declaration of Variables
##################################################################################################
# Assign folder variables
dsappDirectory="/opt/novell/datasync/tools/dsapp"
dsappConf="$dsappDirectory/conf"
dsappLogs="$dsappDirectory/logs"
dsapplib="/opt/novell/datasync/tools/dsapp/lib"
dsappBackup="$dsappDirectory/backup"
dsapptmp="$dsappDirectory/tmp"
dsappupload="$dsappDirectory/upload"
rootDownloads="/root/Downloads"
#Create folders to store script files
rm -R -f /tmp/novell/ 2>/dev/null;
rm -r -f $dsapptmp/* 2>/dev/null;
mkdir -p $dsappDirectory 2>/dev/null;
mkdir -p $dsappConf 2>/dev/null;
mkdir -p $dsappLogs 2>/dev/null;
mkdir -p $dsappBackup 2>/dev/null;
mkdir -p $dsapptmp 2>/dev/null;
mkdir -p $dsappupload 2>/dev/null;
mkdir -p $rootDownloads 2>/dev/null;
mkdir -p $dsapplib 2>/dev/null;
# Version
function getVersion {
if ($dsInstalledCheck);then
version="/opt/novell/datasync/version"
mobilityVersion=`cat $version`
fi
}
getVersion;
# Random Global Variables
serverinfo="/etc/*release"
rpminfo="datasync"
dsapp_tar="dsapp.tgz"
isNum='^[0-9]+$'
ds_1x='1'
ds_2x='2'
ds_14x='14'
previousVersion="210230"
latestVersion="1420228"
# Configuration Files
mconf="/etc/datasync/configengine/engines/default/pipelines/pipeline1/connectors/mobility/connector.xml"
gconf="/etc/datasync/configengine/engines/default/pipelines/pipeline1/connectors/groupwise/connector.xml"
ceconf="/etc/datasync/configengine/configengine.xml"
econf="/etc/datasync/configengine/engines/default/engine.xml"
wconf="/etc/datasync/webadmin/server.xml"
# Configure / Set dsapp.conf
if [ ! -f "$dsappConf/dsapp.conf" ];then
echo -e "#Configuration for dsapp\n\n#Auto update dsapp [boolean: true | false]\nautoUpdate=true" > $dsappConf/dsapp.conf
echo -e "\n#Log level for dsapp [boolean: true | false]\ndebug=false" >> $dsappConf/dsapp.conf
fi
# Add new configurations to existing dsapp.conf file
if [ -f "$dsappConf/dsapp.conf" ];then
# Add into array to check conf file
dsappConfArray=('pgpass' 'newFeature')
for ((i=0;i<`echo ${#dsappConfArray[@]}`;i++))
do
dsappConfLoop=`grep "${dsappConfArray[$i]}" $dsappConf/dsapp.conf`
if [ -z "$dsappConfLoop" ];then
# Add if statement for each new conf setting inside this IF block
if [ "${dsappConfArray[$i]}" = "pgpass" ];then
echo -e "\n#Delete ~/.pgpass after dsapp closes [boolean: true | false]\npgpass=true" >> $dsappConf/dsapp.conf
fi
if [ "${dsappConfArray[$i]}" = "newFeature" ];then
echo -e "\n#Promp new feature on load [boolean: true | false]\nnewFeature=true" >> $dsappConf/dsapp.conf
fi
# if [ "${dsappConfArray[$i]}" = "Array Item" ];then
# echo -e "Text to conf file" >> $dsappConf/dsapp.conf
# fi
fi
done
fi
# Mobility Directories
dirOptMobility="/opt/novell/datasync"
dirEtcMobility="/etc/datasync"
dirVarMobility="/var/lib/datasync"
log="/var/log/datasync"
dirPGSQL="/var/lib/pgsql"
mAttach="$dirVarMobility/mobility/attachments/"
# Mobility logs
configenginelog="$log/configengine/configengine.log"
connectormanagerlog="$log/syncengine/connectorManager.log"
syncenginelog="$log/syncengine/engine.log"
monitorlog="$log/monitorengine/monitor.log"
systemagentlog="$log/monitorengine/systemagent.log"
updatelog="$log/update.log"
webadminlog="$log/webadmin/server.log"
sudslog="$log/connectors/suds.log"
# System logs
messages="/var/log/messages"
warn="/var/log/warn"
# dsapp Conf / Logs
dsappconfFile="$dsappConf/dsapp.conf"
source "$dsappconfFile"
dsappLog="$dsappLogs/dsapp.log"
ghcLog="$dsappLogs/generalHealthCheck.log"
function setXML {
# $1 = XML file
# $2 = path to node (/config/configengine/source/provisioning)
# $3 = New value
# Example: setXML "$ceconf" '/config/configengine/source/provisioning' 'groupwise'
xmllint --shell $1 <<EOF >/dev/null
cd $2
set $3
save
quit
EOF
xmllint --format $1 --output $1
}
# Fetch variables from confs
function xmlpath() {
local expr="${1//\// }"
local path=()
local chunk tag data
while IFS='' read -r -d '<' chunk; do
IFS='>' read -r tag data <<< "$chunk"
case "$tag" in
'?'*) ;;
'!–-'*) ;;
'![CDATA['*) data="${tag:8:${#tag}-10}" ;;
?*'/') ;;
'/'?*) unset path[${#path[@]}-1] ;;
?*) path+=("$tag") ;;
esac
[[ "${path[@]}" == "$expr" ]] && echo "$data"
done
}
# Global variable for verifyUser
vuid="";
uid="";
simpleUID="";
# Get Hostname of server
if [ ! -f "$dsappConf/dsHostname.conf" ];then
echo `hostname -f` > $dsappConf/dsHostname.conf
fi
dsHostname=`cat $dsappConf/dsHostname.conf`
# Store dsapp version
if [ ! -f "$dsappConf/dsappVersion" ];then
echo $dsappversion > $dsappConf/dsappVersion
fi
function getDSVersion {
local header="[${FUNCNAME[0]}] :"; log_debug "$header Funcation call";
if ($dsInstalledCheck);then
dsVersion=`cat $version | cut -f1 -d '.'`
fi
}
##################################################################################################
# Begin Logging Section
##################################################################################################
# Disable color from logging
INTERACTIVE_MODE=off
if [[ "${INTERACTIVE_MODE}" == "off" ]]
then
# Then we don't care about log colors
declare -r LOG_DEFAULT_COLOR=""
declare -r LOG_ERROR_COLOR=""
declare -r LOG_INFO_COLOR=""
declare -r LOG_SUCCESS_COLOR=""
declare -r LOG_WARN_COLOR=""
declare -r LOG_DEBUG_COLOR=""
else
declare -r LOG_DEFAULT_COLOR="\e[0m"
declare -r LOG_ERROR_COLOR="\e[31m"
declare -r LOG_INFO_COLOR="\e[0m"
declare -r LOG_SUCCESS_COLOR="\e[32m"
declare -r LOG_WARN_COLOR="\e[33m"
declare -r LOG_DEBUG_COLOR="\e[34m"
fi
# This function scrubs the output of any control characters used in colorized output
# It's designed to be piped through with text that needs scrubbing. The scrubbed
# text will come out the other side!
prepare_log_for_nonterminal() {
# Essentially this strips all the control characters for log colors
sed "s/[[:cntrl:]]\[[0-9;]*m//g"
}
log() {
local log_text="$1"
local log_level="$2"
local log_color="$3"
# Default level to "info"
[[ -z ${log_level} ]] && log_level="INFO";
[[ -z ${log_color} ]] && log_color="${LOG_INFO_COLOR}";
echo -e "${log_color}[$(date +"%Y-%m-%d %H:%M:%S %Z")] [${log_level}] ${log_text} ${LOG_DEFAULT_COLOR}" >> "$dsappLog";
return 0;
}
log_info() { log "$@"; }
log_success() { log "$1" "SUCCESS" "${LOG_SUCCESS_COLOR}"; }
log_error() { log "$1" "ERROR" "${LOG_ERROR_COLOR}"; }
log_warning() { log "$1" "WARNING" "${LOG_WARN_COLOR}"; }
log_debug() { if ($debug); then log "$1" "DEBUG" "${LOG_DEBUG_COLOR}"; fi }
##################################################################################################
# Any errors are displayed to console and written to $dsappLog
##################################################################################################
# exec 2>> >(while read data; do echo "$data"; log_error "$data"; done)
##################################################################################################
# Version: Eenou+
##################################################################################################
function declareVariables2 {
log_debug "[Init] [declareVariables2] Declaring variables for 2.x"
mAlog=$log"/connectors/mobility-agent.log"
gAlog=$log"/connectors/groupwise-agent.log"
mlog=$log"/connectors/mobility.log"
glog=$log"/connectors/groupwise.log"
rcScript="rcgms"
}
##################################################################################################
# Version: Pre-Eenou
##################################################################################################
function declareVariables1 {
log_debug "[Init] [declareVariables1] Declaring variables for 1.x"
mAlog=$log"/connectors/default.pipeline1.mobility-AppInterface.log"
gAlog=$log"/connectors/default.pipeline1.groupwise-AppInterface.log"
mlog=$log"/connectors/default.pipeline1.mobility.log"
glog=$log"/connectors/default.pipeline1.groupwise.log"
rcScript="rcdatasync"
}
##################################################################################################
# Colors
##################################################################################################
bRED='\e[1;31m' #Bold Red
red='\e[31m' # Red
bGREEN='\e[1;32m' #Bold Green
yellow='\e[33m' #Yellow
bYELLOW='\e[1;33m'
URED='\e[4;91m' #Underline Red
UGREEN='\e[4;92m' #Underline Green
BOLD='\e[1m' #Bold
UBOLD=`tput bold; tput smul` #Underline Bold
STRIKE='\e[9m' # Strike
BLINKON='\e[5m' # Blinking
NC='\e[0m' # No Color - default
##################################################################################################
#
# Initialization
#
##################################################################################################
log_debug "[Section] : Loading Initialization section"
#Get datasync version.
getDSVersion;
# Load Menu (Get all needed variables)
if [ -z "$1" ];then
datasyncBanner; echo "Loading Menu..."; else clear;
fi
if ($dsInstalledCheck);then
log_debug "===== Variable Assignment ====="
log_debug "Assigning ldapAddress from mconf"
ldapAddress=`xmlpath 'connector/settings/custom/ldapAddress' < $mconf`
log_debug "Assigning ldapPort from mconf"
ldapPort=`xmlpath 'connector/settings/custom/ldapPort' < $mconf`
log_debug "Assigning ldapSecure from ceconf"
ldapSecure=`xmlpath 'config/configengine/ldap/secure' < $ceconf`
log_debug "Assigning mPort from mconf"
mPort=`xmlpath 'connector/settings/custom/listenPort' < $mconf`
log_debug "Assigning mSecure from mconf"
mSecure=`xmlpath 'connector/settings/custom/ssl' < $mconf`
log_debug "Assigning mlistenAddress from mconf"
mlistenAddress=`xmlpath 'connector/settings/custom/listenAddress' < $mconf`
log_debug "Assigning sListenAddress from gconf"
sListenAddress=`xmlpath 'connector/settings/custom/listeningLocation' < $gconf`
log_debug "Assigning gListenAddress from gconf"
gListenAddress=`xmlpath 'connector/settings/custom/soapServer' < $gconf | cut -f3 -d '/' | cut -f1 -d ':'`
log_debug "Assigning trustedName from gconf"
trustedName=`xmlpath 'connector/settings/custom/trustedAppName' < $gconf`
log_debug "Assigning gPort from gconf"
gPort=`xmlpath 'connector/settings/custom/port' < $gconf`
log_debug "Assigning sPort from gconf"
sPort=`xmlpath 'connector/settings/custom/soapServer' < $gconf | rev | cut -f1 -d ':' | cut -f2 -d '/' | rev`
log_debug "Assigning sSecure from gconf"
if [ "$dsVersion" -ge "$ds_14x" ];then
log_debug "Assigning sslPOA from gconf"
sslPOAs=`xmlpath 'connector/settings/custom/sslPOAs' < $gconf`
if [ "$sslPOAs" -eq '0' ];then
sSecure='http'
elif [ "$sslPOAs" -eq '1' ];then
sSecure='https'
fi
else
sSecure=`xmlpath 'connector/settings/custom/soapServer' < $gconf | cut -f1 -d ':'`
fi
log_debug "Assigning wPort from wconf"
wPort=`xmlpath 'config/server/port' < $wconf`
log_debug "Assigning ldapAdmin from ceconf"
ldapAdmin=`xmlpath 'config/configengine/ldap/login/dn' < $ceconf`
log_debug "Assigning provisioning from ceconf"
provisioning=`xmlpath 'config/configengine/source/provisioning' < $ceconf`
log_debug "Assigning authentication from ceconf"
authentication=`xmlpath 'config/configengine/source/authentication' < $ceconf`
log_debug "Assigning ldapEnabled from ceconf"
ldapEnabled=`xmlpath 'config/configengine/ldap/enabled' < $ceconf`
log_debug "Assigning galUserName from mconf"
galUserName=`xmlpath 'connector/settings/custom/galUserName' < $mconf`
log_debug "Assigning groupContainer from ceconf"
groupContainer=`xmlpath 'config/configengine/ldap/groupContainer' < $ceconf`
log_debug "Assigning userContainer from ceconf"
userContainer=`xmlpath 'config/configengine/ldap/userContainer' < $ceconf`
log_debug "Assigning mAttachSize from mconf"
mAttachSize=`xmlpath 'connector/settings/custom/attachmentMaxSize' < $mconf`
log_debug "Assigning gAttachSize from gconf"
gAttachSize=`xmlpath 'connector/settings/custom/attachmentMaxSize' < $gconf`
log_debug "Assigning webAdmins from ceconf"
webAdmins=`xmlpath 'config/configengine/ldap/admins/dn' < $ceconf`
log_debug "===== End Variable Assignment ====="
fi
# Set PATH environment for script to include /usr/sbin
PATH=$PATH:/usr/sbin/
#Getting Present Working Directory
cPWD=${PWD};
# Check dsapp logging file
if [ ! -f "$dsappLog" ]; then
touch "$dsappLog"
fi
if [[ $forceMode -eq 1 ]];then
log_debug "[Initialization] Launching dsapp with --force..."
fi
function pushConf {
local header="[pushConf] [$dsappconfFile] :"
# $1 = variableName | $2 = value
sed -i "s|$1=.*|$1=$2|g" "$dsappconfFile";
if [ $? -eq 0 ];then
log_debug "$header $1 has been reconfigured to $2"
else
log_error "$header Failed to reconfigure $1 to $2"
fi
}
function dsappLogRotate {
local header="[${FUNCNAME[0]}] :"; log_debug "$header Funcation call";
logRotate="$(cat <<EOF
/opt/novell/datasync/tools/dsapp/logs/*.log {
compress
compresscmd /usr/bin/gzip
dateext
maxage 14
rotate 99
missingok
notifempty
size +4096k
create 640 root root
}
EOF
)"
if [ ! -f "/etc/logrotate.d/dsapp" ];then
log_debug "[Init] [logRotate] Creating /etc/logrotate.d/dsapp"
echo -e "$logRotate" > /etc/logrotate.d/dsapp
fi
}
function askYesOrNo {
# If $2 = "skip" Will default return 0;
if [ "$2" = "skip" ];then return 0; fi
REPLY=""
while [ -z "$REPLY" ] ; do
read -ep "$1 $YES_NO_PROMPT" -n1 REPLY
REPLY=$(echo ${REPLY}|tr [:lower:] [:upper:])
log "[askYesOrNo] $1 $REPLY"
case $REPLY in
$YES_CAPS ) return 0 ;;
$NO_CAPS ) return 1 ;;
* ) REPLY=""
esac
done
}
# Initialize the yes/no prompt
YES_STRING=$"y"
NO_STRING=$"n"
YES_NO_PROMPT=$"[y/n]: "
YES_CAPS=$(echo ${YES_STRING}|tr [:lower:] [:upper:])
NO_CAPS=$(echo ${NO_STRING}|tr [:lower:] [:upper:])
# Toggle announceNewFeature to true
# Put dsapp version in newFeatureVersion that will have the new feature
newFeatureVersion='196'
if [ `cat $dsappConf/dsappVersion` -lt $newFeatureVersion ];then
pushConf "newFeature" true
newFeature=true
fi
function announceNewFeature {
local header="[${FUNCNAME[0]}] :"; log_debug "$header Funcation call";
if($newFeature);then
clear; datasyncBanner
# Start Code for new feature -----
echo -e "\tNew Feature\n\nGeneral Health Check.\nLocated in the Checks & Queries menu.\n"
if askYesOrNo "Would you like to run it now?"; then
generalHealthCheck
fi
# End Code for new feature ------
fi
}
function checkFTP {
local header="[${FUNCNAME[0]}] :"; log_debug "$header Funcation call";
# To call/use: if (checkFTP);then
netcat -z -w 2 ftp.novell.com 21;
if [ $? -eq 0 ]; then
log_success "$header Passed ftp.novell.com:21"
return 0;
else
log_warning "$header Failed ftp.novell.com:21"
return 1;
fi
}
function updateDsapp {
local header="[${FUNCNAME[0]}] :"; log_debug "$header Funcation call";
echo -e "\nUpdating dsapp..."
log_info "$header Updating dsapp..."
# Download new version & extract
local tmpVersion=`curl -s ftp://ftp.novell.com/outgoing/$dsapp_tar | tar -zxv 2>/dev/null | egrep -o '(dsapp.*.rpm)'`;
if [ $? -eq 0 ];then
rpm -Uvh "$tmpVersion"
if [ $? -ne 0 ];then
log_error "$header $tmpVersion failed to update"
echo -e "$tmpVersion failed to update\n\nRun the following:\nrpm --force -ivh $tmpVersion\n"
eContinue;
else
log_success "$header $tmpVersion successfully updated."
echo "$tmpVersion successfully updated."
if [ "$PWD" != "$dsappDirectory" ];then
rm -f dsapp.sh
fi
rm -f $tmpVersion;
eContinueTime;
if [ $? -eq 0 ];then
$dsappDirectory/dsapp.sh && exit 0
else
exit 0;
fi
fi
else log_error "$header Failed to download and extract ftp://ftp.novell.com/outgoing/$dsapp_tar"
fi
}
function autoUpdateDsapp {
local header="[${FUNCNAME[0]}] :"; log_debug "$header Funcation call";
# Variable declared above autoUpdate=true
if ($autoUpdate); then
log_debug "[Init] autoUpdateDsapp ($autoUpdate)..."
# Check FTP connectivity
if (checkFTP);then
# Fetch online dsapp and store to memory, check version
publicVersion=`curl --connect-timeout 3 -s ftp://ftp.novell.com/outgoing/dsapp-version.info | grep -m1 dsappversion= | cut -f2 -d "'"`
log_debug "[Init] [autoUpdateDsapp] publicVersion: $publicVersion, currentVersion: $dsappversion"
# publicVersion=`curl -s ftp://ftp.novell.com/outgoing/$dsapp_tar | tar -Oxz 2>/dev/null | grep -m1 dsappversion= | cut -f2 -d "'"`
clear; echo -e "\nChecking for new dsapp..."
# Download if newer version is available
if [ -n "$publicVersion" ];then
if [ "$dsappversion" -lt "$publicVersion" ];then
echo -e "v$dsappversion (v$publicVersion available)"
updateDsapp
fi
else
clear; echo -e "Connection timed out.";
fi
fi
fi
}
#Get database username (datasync_user by default)
dbUsername=`cat $ceconf | grep database -A 7 | grep "<username>" | cut -f2 -d '>' | cut -f1 -d '<'`
function checkDBPass {
local header="[${FUNCNAME[0]}] :"; log_debug "$header Funcation call";
# Return of 1 indicates a bad file, needs to be recreated
if [ -f "/root/.pgpass" ];then
# If the file is there, does it have a password?
if [[ -n `cat /root/.pgpass | cut -d ':' -f5` ]]; then
dbLogin=`psql -U $dbUsername -l 2>/dev/null`;
if [ $? -eq '0' ];then
echo "0";
else
echo "1";
fi
else echo "1"
fi
else
echo "1";
fi
}
function encodeString {
local header="[${FUNCNAME[0]}] :"; log_debug "$header Funcation call";
echo "$1" | openssl enc -aes-256-cbc -a -k $dsHostname | base64 | tr -d '\040\011\012\015'
}
function decodeString {
local header="[${FUNCNAME[0]}] :"; log_debug "$header Funcation call";
local decodeVar1=`echo "$1" | base64 -d`;
local decodeVar2=`echo "$decodeVar1" | openssl enc -aes-256-cbc -base64 -k $dsHostname -d 2>>$dsapptmp/error`;
if [ -f "$dsapptmp/error" ];then
local var=`grep "bad decrypt" $dsapptmp/error`
if [ -n "$var" ];then
echo -e "$2\n" >> $dsapptmp/error
fi
fi
echo $decodeVar2;
}
function isStringProtected {
local header="[${FUNCNAME[0]}] :"; log_debug "$header Funcation call";
# $1 = xml path
# $2 = file to check
# This will echo 1 if it is protected
echo "cat $1" | xmllint --shell $2 | sed '1d;$d' | grep -i "<protected>" | grep -o '[0-9]*'
}
# Get & Decode dbpass
function getDBPassword {
local header="[${FUNCNAME[0]}] :"; log_debug "$header Funcation call";
#Grabbing password from configengine.xml
dbPassword=`xmlpath 'config/configengine/database/password' < $ceconf`
if [[ $(isStringProtected /config/configengine/database $ceconf) -eq 1 ]];then
dbPassword=$(decodeString $dbPassword "Database")
fi
if [ -f "$dsapptmp/error" ];then
local var=`grep "Database" $dsapptmp/error`
if [ -n "$var" ];then echo -e "Encryption on Database wrong.";
decodeProblem=true;
fi
fi
}
# Get & decode trustedAppKey
function getTrustedAppKey {
local header="[${FUNCNAME[0]}] :"; log_debug "$header Funcation call";
trustedAppKey=`xmlpath 'connector/settings/custom/trustedAppKey' < $gconf`
if [[ $(isStringProtected /connector/settings/custom $gconf) -eq 1 ]];then
trustedAppKey=$(decodeString $trustedAppKey "Trusted Application")
fi
if [ -f "$dsapptmp/error" ];then
local var=`grep "Trusted Application" $dsapptmp/error`
if [ -n "$var" ];then echo -e "Encryption on Trusted Application wrong.";
decodeProblem=true;
fi
fi
}
# Get & decode ldapLogin password
function getldapPassword {
local header="[${FUNCNAME[0]}] :"; log_debug "$header Funcation call";
# Keeping protected for General Health Check Log
protectedldapPassword=`xmlpath 'config/configengine/ldap/login/password' < $ceconf`
ldapPassword="$protectedldapPassword"
if [[ $(isStringProtected /config/configengine/ldap/login $ceconf) -eq 1 ]];then
ldapPassword=$(decodeString $ldapPassword "LDAP")
fi
if [ -f "$dsapptmp/error" ];then
local var=`grep "LDAP" $dsapptmp/error`
if [ -n "$var" ];then echo -e "Encryption on LDAP wrong.";
decodeProblem=true;
fi
fi
}
function getsmtpPassword {
local header="[${FUNCNAME[0]}] :"; log_debug "$header Funcation call";
smtpPassword=`xmlpath 'config/configengine/notification/smtpPassword' < $ceconf`
if [[ $(isStringProtected /config/configengine/notification $ceconf) -eq 1 ]];then
smtpPassword=$(decodeString $smtpPassword "SMTP")
fi
if [ -f "$dsapptmp/error" ];then
local var=`grep "SMTP" $dsapptmp/error`
if [ -n "$var" ];then echo -e "Encryption on SMTP wrong.";
decodeProblem=true;
fi
fi
}
function createPGPASS {
local header="[${FUNCNAME[0]}] :"; log_debug "$header Funcation call";
getDBPassword;
#Creating new .pgpass file
echo "*:*:*:*:"$dbPassword > /root/.pgpass;
chmod 0600 /root/.pgpass;
}
function checkPGPASS {
local header="[${FUNCNAME[0]}] :"; log_debug "$header Funcation call";
#Database .pgpass file / version check.
if [ $dsVersion -ge $ds_1x ];then
#Log into database or create .pgpass file to login.
dbRunning=`rcpostgresql status`;
if [ $? -eq '0' ];then
if [ $(checkDBPass) -eq 1 ];then
createPGPASS;
fi
else
read -p "Postgresql is not running";exit 1;
fi
else
createPGPASS;
fi
}
if [[ "$forceMode" -ne "1" ]];then
checkPGPASS;
fi
function backupConf { # $1 = function name calling this function.
local header="[${FUNCNAME[0]}] :"; log_debug "$header Funcation call";
local now=$(date '+%X_%F')
mkdir -p $dsappBackup/$1/$now/
cp $ceconf $econf $dsappBackup/$1/$now/
mkdir -p $dsappBackup/$1/$now/gConnector/
cp $gconf $dsappBackup/$1/$now/gConnector/
mkdir -p $dsappBackup/$1/$now/mConnector/
cp $mconf $dsappBackup/$1/$now/mConnector/
echo -e "\nBackup of configuration files at $dsappBackup/$1/$now"
}
# Compare dsHostname hostname, with server hostname
function checkHostname {
local header="[${FUNCNAME[0]}] :"; log_debug "$header Funcation call";
local lineNumber
if [ -n "$1" ];then
echo "$1" > $dsappConf/dsHostname.conf;
dsHostname=`cat $dsappConf/dsHostname.conf`
local var="skip"
else local var="";
fi
if [[ "$dsHostname" != `hostname -f` ]] || [ "$var" = "skip" ];then
if [ "$var" != "skip" ];then echo -e "\nHostname differs from last time dsapp ran.";
echo -e "\nReconfigure Mobility password encryption";
fi
if askYesOrNo "using [$dsHostname] to decrypt? " "$var";then
rm -f $dsapptmp/error
decodeProblem=false
getDBPassword;
getTrustedAppKey;
getldapPassword;
if [ $dsVersion -ge $ds_1x ]; then
getsmtpPassword;
fi
if ($decodeProblem);then
echo -e "\nUnable to reconfigure encryption... Aborting reconfigure.";
return 1;
fi
# Setting dsHostname to new hostname
echo `hostname -f` > $dsappConf/dsHostname.conf
dsHostname=`cat $dsappConf/dsHostname.conf`
# Storing passwords with new encode
dbPassword=$(encodeString $dbPassword)
trustedAppKey=$(encodeString $trustedAppKey)
ldapPassword=$(encodeString $ldapPassword)
smtpPassword=$(encodeString $smtpPassword)
# Backup all configuration files
backupConf "checkHostname"
# Setting database password in multiple files
if [[ $(isStringProtected /config/configengine/database $ceconf) -eq 1 ]];then
lineNumber=`cat --number $ceconf | sed -n "/<database>/,/<\/database>/p" | grep -i password | awk '{print $1}'`
sed -i ""$lineNumber"s|<password>.*</password>|<password>"$dbPassword"</password>|g" $ceconf
fi
if [[ $(isStringProtected /engine/settings/database $econf) -eq 1 ]];then
sed -i "s|<password>.*</password>|<password>"$dbPassword"</password>|g" $econf
fi
if [[ $(isStringProtected /connector/settings/custom $mconf) -eq 1 ]];then
sed -i "s|<dbpass>.*</dbpass>|<dbpass>"$dbPassword"</dbpass>|g" $mconf
fi
# Setting TrustedAppKey with new hostname encoding
if [[ $(isStringProtected /connector/settings/custom $gconf) -eq 1 ]];then
sed -i "s|<trustedAppKey>.*</trustedAppKey>|<trustedAppKey>"$trustedAppKey"</trustedAppKey>|g" $gconf
fi
# Setting ldapPassword with new hostname encoding
if [[ $(isStringProtected /config/configengine/ldap/login $ceconf) -eq 1 ]];then
lineNumber=`cat --number $ceconf | sed -n "/<ldap>/,/<\/ldap>/p" | grep -i password | awk '{print $1}'`
sed -i ""$lineNumber"s|<password>.*</password>|<password>"$ldapPassword"</password>|g" $ceconf
fi
# Setting smtp password with new encoding
if [[ $(isStringProtected /config/configengine/notification $ceconf) -eq 1 ]];then
lineNumber=`cat --number $ceconf | sed -n "/<notification>/,/<\/notification>/p" | grep -i password | awk '{print $1}'`
sed -i ""$lineNumber"s|<smtpPassword>>.*</smtpPassword>>|<smtpPassword>>"$smtpPassword"</smtpPassword>>|g" $ceconf
fi
echo -e "\nConfiguration files updated.\nPlease restart Mobility."
exit 0;
fi
fi
}
# Skips auto-update if file is not called dsapp.sh (good for testing purposes when using dsapp-test.sh)
if [ -z "$1" ];then
if [[ "$0" = *dsapp.sh ]]; then
autoUpdateDsapp;
fi
fi
##################################################################################################
# Initialize Variables
##################################################################################################
log_debug "[Section] : Loading Initialize Variables section"
function setVariables {
local header="[${FUNCNAME[0]}] :"; log_debug "$header Funcation call";
# Depends on version 1.x or 2.x
if ($dsInstalledCheck);then
if [ $dsVersion -ge $ds_1x ]; then
declareVariables2
else
declareVariables1
fi
fi
}
setVariables;
# Things to run in initialization
decodeProblem=false
dsappLogRotate;
if [ "$1" != "-ch" ] && [ "$1" != "--changeHost" ] && [ "$1" != "-h" ] && [ "$1" != "--help" ];then
getldapPassword;
getTrustedAppKey;
getDBPassword;
if [ $dsVersion -ge $ds_1x ]; then
getsmtpPassword;
fi
checkHostname;
if ($decodeProblem);then echo -e "\nPossible hostname change";eContinue;fi
fi
log "[Init] dsapp v$dsappversion | Mobility version: $mobilityVersion"
log_debug "[Init] dsHostname: $dsHostname"
log_debug "[Init] ldapAddress: $ldapAddress:$ldapPort"
log_debug "[Init] GroupWise-Agent: $sListenAddress:$gPort | Mobility-Agent: $mlistenAddress:$mPort"
log_debug "[Init] [checkDBPass] $dbUsername:$dbPassword"
log_debug "[Init] [getTrustedAppKey] $trustedName:$trustedAppKey"
log_debug "[Init] [getldapPassword] $ldapAdmin:$ldapPassword"
log_debug "[Init] [getsmtpPassword] $smtpPassword"
##################################################################################################
#
# Declaration of Functions
#
##################################################################################################
log_debug "[Section] : Loading Declaration of Function section"
function promptVerifyPath {
local header="[${FUNCNAME[0]}] :"; log_debug "$header Funcation call";
while [ true ];do
read -ep "$1" path;
if [ ! -d "$path" ]; then
if askYesOrNo $"Path does not exist, would you like to create it now?"; then
mkdir -p $path;
break;
fi
else break;