File: CipUX.pm

package info (click to toggle)
cipux 3.4.0.11-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 316 kB
  • ctags: 59
  • sloc: perl: 1,064; makefile: 13
file content (1713 lines) | stat: -rw-r--r-- 53,240 bytes parent folder | download
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
# +==========================================================================+
# || CipUX                                                                  ||
# ||                                                                        ||
# || Common CipUX functions                                                 ||
# ||                                                                        ||
# || Copyright (C) 2007 - 2009 by Christian Kuelker                         ||
# ||                                                                        ||
# || License: GNU GPL version 2 or any later version.                       ||
# ||                                                                        ||
# +==========================================================================+
# ID:       $Id$
# Revision: $Revision$
# Head URL: $HeadURL$
# Date:     $Date$
# Source:   $Source$

package CipUX;

use strict;
use warnings;
use utf8;
use 5.008001;
use Array::Unique;
use Carp;
use Class::Std;
use Config::Any;
use Data::Dumper;
use Date::Manip;
use Digest::MD5;
use English qw( -no_match_vars);
use File::Basename;
use File::Glob;
use File::Path qw(make_path);
use Hash::Merge qw/merge/;
use Log::Log4perl qw(:easy);
use Pod::Usage;
use Readonly;
use Storable qw(store retrieve freeze thaw dclone);
use Term::ReadKey;
use Unicode::String;

{    # BEGIN CLASS

    use version; our $VERSION = qv('3.4.0.11');
    use re 'taint';    # Keep data captured by parens tainted
    delete @ENV{qw(PATH IFS CDPATH ENV BASH_ENV)};    # Make %ENV safe

    # +======================================================================+
    # || CONST                                                              ||
    # +======================================================================+
    Readonly::Scalar my $EMPTY_STRING => q{};
    Readonly::Scalar my $DT => UnixDate( 'today', '%Y-%m-%dT%H:%M:%S' );
    my $L = q{=================================================};
    $L .= "$L\n";
    Readonly::Scalar my $CFGBASE             => 'cipux';
    Readonly::Scalar my $PASSWD_LENGTH_START => 1;
    Readonly::Scalar my $PASSWD_LENGTH_END   => 9;
    Readonly::Array my @PASSWD_CHARS =>
        ( 'A' .. 'Z', 'a' .. 'z', 0 .. 9, qw(! @ $ % &) );
    Readonly::Array my @MODSALT_CHARS =>
        ( q{.}, q{/}, 0 .. 9, 'A' .. 'Z', 'a' .. 'z' );
    Readonly::Scalar my $MODSALT_BASE => 64;
    Readonly::Scalar my $LINEWIDTH    => 78;
    Readonly::Scalar my $STRICT_UMASK => oct 77;
    Readonly::Scalar my $CACHE_DIR    => '/var/cache/cipux';

    # +======================================================================+
    # || GLOBAL                                                             ||
    # +======================================================================+
    ## no critic (ProhibitPackageVars)
    use vars qw($config_hr0 $config_hr1 $config_hr2);

    ## use critic
    my %mattrvalue = ();
    my %opt        = ();
    my $str        = "%s ->  %s: %s\n";
    my $exc_hr     = {
        'UNKNOWN' => 'Unknown exception! Please fix CipUX!',
        '1010'    => sprintf( $str, 'a', 'b', 'c' ),
        '1015'    => 'value of "scope" in methode should be "all" or "one"!',
    };

    # +======================================================================+
    # || open module features                                               ||
    # +======================================================================+

    # +======================================================================+
    # || linewidth                                                          ||
    # +======================================================================+

    sub get_linewidth {

        # +------------------------------------------------------------------+
        # | API
        return $LINEWIDTH;

    } ## end sub get_linewidth

    # +======================================================================+
    # || perr                                                               ||
    # +======================================================================+
    sub perr {

        # +------------------------------------------------------------------+
        # | API
        my ( $self, $param, $oline ) = @_;

        if ( not defined $param ) {
            $param = 'UNKNOWN PARAMETER';
        }

        my (
            $package,   $filename, $line,       $subroutine, $hasargs,
            $wantarray, $evaltext, $is_require, $hints,      $bitmask
        ) = caller 1;

        my $msg = "perr called by [$subroutine] with undef parameter! \n";
        if ( not defined $param ) {
            $self->exc( { msg => $msg } );
        }

        $msg = "perr called by [$subroutine] with unknown parameter! \n";
        if ( $param eq 'UNKNOWN PARAMETER' ) {
            $self->exc( { msg => $msg } );
        }

        chomp $param;
        $msg = "Missing parameter [$param] in function [$subroutine]! \n";
        if ( defined $oline ) {
            $msg .= "You should look at line [$oline].\n";
        }

        # TODO think about: (AdcMon!)
        # $self->exc( { msg => $msg } ) if $param <> 0;
        $self->exc( { msg => $msg } );

        # +------------------------------------------------------------------+
        # | API
        exit 1;

    } ## end sub perr

    # +======================================================================+
    # || exc                                                                ||
    # +======================================================================+
    sub exc {

        # +------------------------------------------------------------------+
        # | API
        my ( $self, $arg_r ) = @_;
        my $nr    = $arg_r->{nr}    || 'UNKNOWN';
        my $value = $arg_r->{value} || $EMPTY_STRING;
        my $msg   = $arg_r->{msg}   || $EMPTY_STRING;

        # +------------------------------------------------------------------+
        # | main
        chomp $nr;
        chomp $value;

        my $txt
            = $nr  ne 'UNKNOWN'     ? $exc_hr->{$nr}
            : $msg ne $EMPTY_STRING ? $msg
            :                         'UNKNOWN';

        if ( $value ne $EMPTY_STRING ) {
            croak sprintf "%s (EXCEPTION) %s [%s]\n", $DT, $txt, $value;
        }
        else {
            croak sprintf "%s (EXCEPTION) %s\n", $DT, $txt;
        }

        # +------------------------------------------------------------------+
        # | API
        return 1;

    } ## end sub exc

    # +======================================================================+
    # || config                                                             ||
    # +======================================================================+
    # OLD config space, will be dropped in 3.4.2.x
    sub config {

        # +------------------------------------------------------------------+
        # | API
        my ( $self, $arg_r ) = @_;
        my $config_ar
            = exists $arg_r->{config_ar}
            ? $self->a( $arg_r->{config_ar} )
            : $self->perr('config_ar');

        # +------------------------------------------------------------------+
        # | prepare
        my $logger = get_logger('CipUX');

        my $config;

        # +------------------------------------------------------------------+
        # | main
        foreach my $cfg ( @{$config_ar} ) {
            $config = $cfg;
            last if -e $cfg;
        }
        my ( $cfg0_hr, $cfg1_hr, $cfg2_hr );

        # source conf file
        if ( $config and -e $config ) {
            ( $cfg0_hr, $cfg1_hr, $cfg2_hr )
                = $self->source( { cfg => $config } );
        }
        else {
            my $msg = 'Did not find any configuration file. ';
            $msg .= 'Last attempt was:';
            $self->exc( { msg => $msg, value => $config } );
        }

        my $msg = 'Variable not defined in configuration file. ';
        $msg .= 'Please provide a valid configuration file.';
        if ( not defined $cfg0_hr ) {
            $self->exc( { msg => $msg, value => 'config_hr0' } );
        }
        if ( not defined $cfg1_hr ) {
            $self->exc( { msg => $msg, value => 'config_hr1' } );
        }
        if ( not defined $cfg1_hr ) {
            $self->exc( { msg => $msg, value => 'config_hr1' } );
        }

        # +------------------------------------------------------------------+
        # | API
        return ( $cfg0_hr, $cfg1_hr, $cfg2_hr );

    } ## end sub config

    # +======================================================================+
    # || source                                                             ||
    # +======================================================================+
    # OLD config space, will be dropped in 3.4.2.x
    sub source {

        # +------------------------------------------------------------------+
        # | API
        my ( $self, $arg_r ) = @_;
        my $cfg = $self->l( $arg_r->{cfg} );

        # +------------------------------------------------------------------+
        # | main
        my $logger = get_logger('CipUX');

        $logger->debug( 'use configuration file: ', $cfg );

        #$cfg = './' . $cfg if not $cfg =~ m%^/%;
        my ( $file, $dir ) = fileparse($cfg);
        $logger->debug( 'file: ', $file );
        $logger->debug( 'dir: ',  $dir );

        # test if file is readable
        if ( not -r $cfg ) {
            $logger->debug( '-> file not readable!: ', $cfg );
            $self->exc( { msg => '-> file not readable!', value => $cfg } );
        }

        my $msg = "While processing conf. [$cfg], the file can not be";
        if ( -e $cfg ) {
            if ( not my $r = do $cfg ) {    # $r = return
                if ($EVAL_ERROR) {
                    pod2usage( -msg => "$msg parsed! $@" );
                }
                if ( not defined $r ) {
                    pod2usage( -msg => "$msg sourced! $!" );
                }
                if ( not $r ) {
                    pod2usage( -msg => "$msg executed! $cfg" );
                }
            } ## end if ( not my $r = do $cfg)
        } ## end if ( -e $cfg )

        # +------------------------------------------------------------------+
        # | API
        return $config_hr0, $config_hr1, $config_hr2;

    } ## end sub source

    # +======================================================================+
    # ||store_mattrvalue                                                    ||
    # +======================================================================+
    sub store_mattrvalue {    ## no critic (ProhibitManyArgs)

        # +------------------------------------------------------------------+
        # | API
        my ( $self, $attr_hr, $opt_hr, $option, $key, $value ) = @_;

        return if not defined $option;

        my $logger = get_logger('CipUX');
        $logger->debug( '> attr_hr: ',
            { filter => \&Dumper, value => $attr_hr } );
        $logger->debug( '> opt_hr : ',
            { filter => \&Dumper, value => $opt_hr } );
        $logger->debug( '> option : ', $option );
        $logger->debug( '> key    : ', $key );
        $logger->debug( '> value  : ', $value );

        my $opt = $self->l($option);

        if (    ( $opt eq 'x' or $opt eq 'mattrvalue' )
            and ( defined $key and defined $value ) )
        {

            my $attr = $self->l($key);
            my $obj  = $self->l($value);
            $logger->debug( 'attr: ', $attr );
            $logger->debug( 'obj: ',  $obj );

            # store in $attr_hr
            push @{ $attr_hr->{$attr} }, $obj;
            $opt_hr->{x}          = 1;
            $opt_hr->{mattrvalue} = 1;

            $logger->debug('end 1');

            return $attr_hr;
        } ## end if ( ( $opt eq 'x' or ...

        $logger->debug('end 2');

        return;

    } ## end sub store_mattrvalue

    # +======================================================================+
    # ||store_attrvalue                                                    ||
    # +======================================================================+
    sub store_attrvalue {    ## no critic (ProhibitManyArgs)

        # +------------------------------------------------------------------+
        # | API
        my ( $self, $attr_hr, $opt_hr, $option, $key, $value ) = @_;

        return if not defined $option;

        my $logger = get_logger('CipUX');
        $logger->debug( '> attr_hr: ',
            { filter => \&Dumper, value => $attr_hr } );
        $logger->debug( '> opt_hr : ',
            { filter => \&Dumper, value => $opt_hr } );
        $logger->debug( '> option : ', $option );
        $logger->debug( '> key    : ', $key );
        $logger->debug( '> value  : ', $value );

        my $opt = $self->l($option);

        if ( ( $opt eq 'y' or $opt eq 'attrvalue' ) and defined $key ) {

            my $attr = $self->l($key);
            my $obj = defined $value ? $self->l($value) : undef;

            $logger->debug( 'attr: ', $attr );
            if ( defined $obj ) {
                $logger->debug( 'obj: ', $obj );
            }

            # store in $attr_hr
            push @{ $attr_hr->{$attr} }, $obj;
            $opt_hr->{y}         = 1;
            $opt_hr->{attrvalue} = 1;

            $logger->debug('end 1');

            return $attr_hr;
        } ## end if ( ( $opt eq 'y' or ...

        $logger->debug('end 2');

        return;

    } ## end sub store_attrvalue

    # +======================================================================+
    # || homedir                                                            ||
    # +======================================================================+
    sub homedir {

        # +------------------------------------------------------------------+
        # | API
        my $self     = shift;
        my $filename = shift;

        $filename =~ s{ ^ ~ ( [^/]* ) }
                  { $1
                            ? (getpwnam($1))[7]
                            : ( $ENV{HOME} || $ENV{LOGDIR}
                                           || (getpwuid($>))[7]
                              )
                  }exms;

        # +------------------------------------------------------------------+
        # | API
        return $filename;

    } ## end sub homedir

    # +======================================================================+
    # || lf                                                                 ||
    # +======================================================================+
    # laundering LDAP filter
    sub lf {

        # +------------------------------------------------------------------+
        # | API
        # example: &(cn=?)(objectClass=cipuxCatModule)
        my ( $self, $o ) = @_;
        return if not defined $o;

        my $x = undef;

        {

            # untaint data captured by parens tainted
            no re 'taint';

            if ( $o =~ m{^([=-\?\(\)&\w.]+)$}smx ) {
                $x = $1;    # data OK
            }
            elsif ( $o eq $EMPTY_STRING ) {
                $x = $EMPTY_STRING;
            }
            else {
                my $caller = caller;
                croak "Bad LDAP filter data [$o] at '$caller'\n";
            }
        }

        undef $o;

        # +------------------------------------------------------------------+
        # | API
        return $x;

    } ## end sub lf

    # laundering passwords
    sub lp {

        # +------------------------------------------------------------------+
        # | API
        # example: &(cn=?)(objectClass=cipuxCatModule)
        my ( $self, $o ) = @_;
        return if not defined $o;

        my $x = undef;

        {

            # untaint data captured by parens tainted
            no re 'taint';

            # if you change that, please also change
            # CipUX::CAT::Web sub cw_password
            #if ( $l =~ m{^([a-z0-9A-Z!#$%&=-_\@+*]+)$}smx ) {
            if ( $o =~ m{^([[:alnum:]!#$%&=-_\@+*]+)$}smx ) {
                $x = $1;    # data OK
            }
            elsif ( $o eq $EMPTY_STRING ) {
                $x = $EMPTY_STRING;
            }
            else {
                my $caller = caller;
                croak "Bad password data [$o] at '$caller'\n";
            }
        }

        undef $o;

        # +------------------------------------------------------------------+
        # | API
        return $x;

    } ## end sub lp

    # laundering integer
    sub li {

        # +------------------------------------------------------------------+
        # | API
        # example: &(cn=?)(objectClass=cipuxCatModule)
        my ( $self, $o ) = @_;
        return if not defined $o;

        my $x = undef;
        {

            # untaint data captured by parens tainted
            no re 'taint';

            # if you change that, please also change
            # CipUX::CAT::Web sub cw_password
            if ( $o =~ m{^(\d+)$}smx ) {
                $x = $1;    # data OK
            }
            elsif ( $o eq $EMPTY_STRING ) {
                $x = $EMPTY_STRING;
            }
            else {
                my $caller = caller;
                croak "Bad integer data [$o] at '$caller'\n";
            }
        }

        undef $o;

        # +------------------------------------------------------------------+
        # | API
        return $x;

    } ## end sub li

    # normal data
    sub l {

        # +------------------------------------------------------------------+
        # | API

        #my ( $self, $arg_r ) = @_;
        my ( $self, $o ) = @_;

        return if not defined $o;

        my $x = undef;

        {

            # untaint data captured by parens tainted
            no re 'taint';

            # if you change that, please also change
            # CipUX::CAT::Web sub cw_password

            # Allows: [ at the beginning (sambaAcctFlags)
            #         ] at the end (sambaAcctFlags)
            #         -:,_=/@.! and \w\s inbetween
            #         * inbetween for CipUX::Storage <212> p{*} LDAP filter
            #         % inbetween for message (%s)
            #         ' inbetween for quoting
            #         " inbetween for quoting
            #         () inbetween for function name quoting
            #         $ inbetween for Windows Machine Accounts
            #         & inbetween for passwords

            if ( $o =~ m{^(\[*[*-:,=_/\@\s\w.\$"!'\&\(%\)]+\]*)$}smx ) {
                $x = $1;    # data OK
            }
            elsif ( $o eq $EMPTY_STRING ) {
                $x = $EMPTY_STRING;
            }
            else {
                my $caller = caller;
                my $msg    = 'A bad letter/character was found inside';
                $msg .= " this input data [$o]. If you want to have";
                $msg .= ' support for this input data, please contact';
                $msg .= ' the mailing list cipux-devel' . q{@} . 'cipux.org';
                $msg .= " The Problem was found at: $caller\n";
                croak $msg;

            }
        }

        undef $o;

        # +------------------------------------------------------------------+
        # | API
        return $x;

    } ## end sub l

    # +======================================================================+
    # || h                                                                  ||
    # +======================================================================+
    sub h {

        # +------------------------------------------------------------------+
        # | API
        my ( $self, $h, $oline ) = @_;

        if ( not ref($h) eq 'HASH' ) {
            my (
                $package,   $filename, $line,       $subroutine, $hasargs,
                $wantarray, $evaltext, $is_require, $hints,      $bitmask
            ) = caller 1;
            my $type = ref $h;
            my $l = defined $h ? $self->l($h) : 'UNKNOWN HASH';

            my $msg = 'The argument is not a HASH or a reference to one. ';
            $msg .= "h() called by [$subroutine] with wrong argument! ";
            if ( defined $oline ) {
                $msg .= "You should have a look at line [$oline] ...";
            }
            $self->exc( { msg => $msg, value => $l } );
            exit 1;
        } ## end else [ if ( ref($h) eq 'HASH')

        # +------------------------------------------------------------------+
        # | API
        return $h;

    } ## end sub h

    # +======================================================================+
    # || a                                                                  ||
    # +======================================================================+
    sub a {

        # +------------------------------------------------------------------+
        # | API
        my ( $self, $o, $oline ) = @_;

        if ( not ref($o) eq 'ARRAY' ) {
            my (
                $package,   $filename, $line,       $subroutine, $hasargs,
                $wantarray, $evaltext, $is_require, $hints,      $bitmask
            ) = caller 1;
            my $type = ref $o;
            my $l = defined $o ? $self->l($o) : 'UNKNOWN ARRAY';

            my $msg = 'The argument is not an ARRAY or reference to one. ';
            $msg .= "a() called by [$subroutine] with wrong argument! ";
            if ( defined $oline ) {
                $msg .= "You should have a look at line [$oline] ...";
            }
            $self->exc( { msg => $msg, value => $l } );
            exit 1;
        } ## end else [ if ( ref($o) eq 'ARRAY')

        # +------------------------------------------------------------------+
        # | API
        return $o;

    } ## end sub a

    # +======================================================================+
    # || test_cli_option                                                    ||
    # +======================================================================+

    # common function for checking CLI logic
    # used by cipux_task_client
    # used by cipux_object_client
    # used by cipux_ldap_client

    sub test_cli_option {

        # +------------------------------------------------------------------+
        # | API

        my ( $self, $arg_r ) = @_;

        my $script
            = exists $arg_r->{script}
            ? $self->l( $arg_r->{script} )
            : 'UNKONW SCRIPT';

        my $opt_hr
            = exists $arg_r->{opt_hr}
            ? $self->h( $arg_r->{opt_hr} )
            : $self->perr('opt_hr');

        my $logic_hr
            = exists $arg_r->{logic_hr}
            ? $self->h( $arg_r->{logic_hr} )
            : $self->perr('logic_hr');

        # +------------------------------------------------------------------+
        # | main
        my $logger = get_logger('CipUX');

        $logger->debug( '> script: ', $script );
        if ( defined $opt_hr ) {
            $logger->debug( '> opt_hr: ',
                { filter => \&Dumper, value => $opt_hr } );
        }
        if ( defined $logic_hr ) {
            $logger->debug( '> logic_hr: ',
                { filter => \&Dumper, value => $logic_hr } );
        }

        # test the given CLI options
        foreach my $s ( sort keys %{$logic_hr} ) {

            # we test only the actual running script
            next if $script ne $s;
            $logger->debug( 'will test: ', $s );

            foreach my $line ( @{ $logic_hr->{$s}->{must} } ) {
                $logger->debug( 'line: ', $line );

                my @s = split /=/smx, $line;
                my $croak_msg = '[' . join( '] or [', @s ) . ']';
                my $must_have = 0;

                foreach my $m (@s) {
                    $logger->debug( 'must have option: ', $m );

                    if ( exists $opt_hr->{$m} ) {
                        $logger->debug('      OK (exists), ');
                    }
                    if ( defined $opt_hr->{$m} ) {
                        $logger->debug(' (defined),');
                    }
                    if ( exists $opt_hr->{$m} ) {
                        $logger->debug( ' value: ', $opt_hr->{$m} );
                    }
                    $logger->debug("\n");
                    if ( exists $opt_hr->{$m} ) {
                        $must_have = 1;
                    }
                } ## end foreach my $m (@s)
                if ( not $must_have ) {

                    my $msg = "$L EXCEPTION: mandatory";
                    $msg .= " parameter $croak_msg missing!\n$L";
                    pod2usage(
                        -verbose => 0,
                        -msg     => $msg
                    );
                    croak $msg;
                } ## end if ( not $must_have )
            } ## end foreach my $line ( @{ $logic_hr...
            foreach my $n ( @{ $logic_hr->{$s}->{not} } ) {
                $logger->debug( 'must not have option: ', $n );

                if ( exists $opt_hr->{$n} ) {
                    my $msg
                        = "\n$L EXCEPTION: you should not provide option [$n]!\n$L";
                    pod2usage(
                        -verbose => 0,
                        -msg     => $msg
                    );
                    croak $msg;
                }
                else {
                    my $msg = 'OK (we do not have option): ';
                    if ( defined $n ) {
                        $logger->debug( $msg, $n );
                    }
                    else {
                        $logger->debug( $msg, 'empty array ref' );
                    }
                } ## end else [ if ( exists $opt_hr->{...
            } ## end foreach my $n ( @{ $logic_hr...
        } ## end foreach my $s ( sort keys %...

        # +------------------------------------------------------------------+
        # | API
        return;

    } ## end sub test_cli_option

    # +======================================================================+
    # || date_time                                                          ||
    # +======================================================================+
    sub date_time {

        # +------------------------------------------------------------------+
        # | API

        my ( $self, $arg_r ) = @_;
        my $today = $arg_r->{today} || 0;

        my $return = $EMPTY_STRING;

        if ($today) {
            $return = UnixDate( 'today', '%Y-%m-%dT%H:%M:%S' );
        }

        # +------------------------------------------------------------------+
        # | API
        return $return;

    } ## end sub date_time

    # +======================================================================+
    # || date_epoch                                                          ||
    # +======================================================================+
    sub date_epoch {

        # +------------------------------------------------------------------+
        # | API

        my ( $self, $arg_r ) = @_;
        my $today = $arg_r->{today} || 0;

        my $return = $EMPTY_STRING;

        if ($today eq '1') {
            $return = UnixDate( 'today', '%s' );
        }elsif($today){
            $return = UnixDate( ParseDate($today), '%s' );
        }
        # +------------------------------------------------------------------+
        # | API
        return $return;

    } ## end sub date_epoch

    # +======================================================================+
    # || latin1_to_utf8                                                     ||
    # +======================================================================+
    sub latin1_to_utf8 {

        # +------------------------------------------------------------------+
        # | API

        my ( $self, $arg_r ) = @_;
        my $latin1 = $arg_r->{latin1} || $EMPTY_STRING;

        # utf8 already is the default
        Unicode::String->stringify_as('utf8');
        my $utf8 = Unicode::String::latin1($latin1);

        # +------------------------------------------------------------------+
        # | API
        return $utf8;
    } ## end sub latin1_to_utf8

    # +======================================================================+
    # || login_prompt                                                       ||
    # +======================================================================+
    sub login_prompt {

        # +------------------------------------------------------------------+
        # | API

        my ( $self, $arg_r ) = @_;
        my $prompt = $self->l( $arg_r->{prompt} ) || 'Login: ';

        ReadMode('normal');
        print $prompt or croak "Can not print prompt to STDOUT\n";
        my $login = ReadLine 0;
        chomp $login;
        ReadMode('normal');

        # +------------------------------------------------------------------+
        # | API
        return $login;
    } ## end sub login_prompt

    # +======================================================================+
    # || password_prompt                                                    ||
    # +======================================================================+
    sub password_prompt {

        # +------------------------------------------------------------------+
        # | API

        my ( $self, $arg_r ) = @_;
        my $prompt = $self->l( $arg_r->{prompt} ) || 'Password: ';

        ReadMode('noecho');
        print $prompt or croak "Can not print promt to STDOUT\n";
        my $password = ReadLine 0;
        chomp $password;
        print "\n" or croak "Can not print CR to STDOUT\n";
        ReadMode('normal');

        # +------------------------------------------------------------------+
        # | API
        return $password;

    } ## end sub password_prompt

    # +======================================================================+
    # || random_password                                                    ||
    # +======================================================================+
    sub random_password {

        # +------------------------------------------------------------------+
        # | API
        # see cookbook, de <55>
        my @chars = @PASSWD_CHARS;
        my $password = join $EMPTY_STRING, @chars[ map { rand @chars }
            ( $PASSWD_LENGTH_START .. $PASSWD_LENGTH_END ) ];

        # +------------------------------------------------------------------+
        # | API
        return $password;

    } ## end sub random_password

    # +======================================================================+
    # || hash_password                                                      ||
    # +======================================================================+
    sub hash_password {

        # +------------------------------------------------------------------+
        # | API
        my ( $self, $arg_r ) = @_;
        my $password = $self->l( $arg_r->{password} )
            || $self->perr('password');
        my $mode = $self->l( $arg_r->{mode} ) || $self->perr('mode');

        my $l = get_logger(__PACKAGE__);
        if ( $mode eq 'crypt' ) {
            $l->debug("crypt|md5 mode eq [$mode]");
            my $modsalt = join $EMPTY_STRING,
                @MODSALT_CHARS[ rand $MODSALT_BASE, rand $MODSALT_BASE ];
            $l->debug("modsalt  [$modsalt]");

            $password = crypt $password, $modsalt;
            $l->debug("password [$password]");

        }
        elsif ( $mode eq 'md5' ) {

            use Digest::MD5 qw(md5);
            my $ctx = Digest::MD5->new;
            $ctx->add($password);
            $password = encode_base64( '{MD5}' . $ctx->b64digest );
            $l->debug("password [$password]");

            #$self->exc( { msg => 'not supported', value => $mode } );

        }
        else {
            $self->exc(
                { msg => 'unknown password hash mode', value => $mode } );
        }

        # +------------------------------------------------------------------+
        # | API
        return $password;    # without prefix like {crypt}

    } ## end sub hash_password

    # +======================================================================+
    # || min                                                                ||
    # +======================================================================+
    sub min {

        # +------------------------------------------------------------------+
        # | API
        my ( $self, $x, $y ) = @_;

        if ( defined $x and defined $y ) {
            return $x < $y ? $x : $y;
        }
        else {

            return $x if defined $x;
            return $y if defined $y;

        } ## end else [ if ( defined $x and defined...

        # +------------------------------------------------------------------+
        # | API
        return;

    } ## end sub min

    # +======================================================================+
    # || max                                                                ||
    # +======================================================================+
    sub max {

        # +------------------------------------------------------------------+
        # | API
        my ( $self, $x, $y ) = @_;

        if ( defined $x and defined $y ) {
            return $x > $y ? $x : $y;
        }
        else {

            return $x if defined $x;
            return $y if defined $y;

        }

        # +------------------------------------------------------------------+
        # | API
        return;

    } ## end sub max

    sub out {

        # +------------------------------------------------------------------+
        # | API
        my $self = shift;
        my $msg  = shift;

        print $msg or croak 'Can not print to STDOUT!';

        # +------------------------------------------------------------------+
        # | API
        return;
    }

    sub _merge_array : PRIVATE {

        # +------------------------------------------------------------------+
        # | API
        my $a_ar = shift;
        my $b_ar = shift;

        # +------------------------------------------------------------------+
        # | main
        tie my @u, 'Array::Unique';   ## no critic (Miscellanea::ProhibitTies)
        @u = ( @{$b_ar}, @{$a_ar} );

        undef $b_ar;
        undef $a_ar;

        # +------------------------------------------------------------------+
        # | API
        return \@u;

    }

    # +======================================================================+
    # || _hash_merge_setup                                                  ||
    # +======================================================================+
    sub _hash_merge_setup {

        # +------------------------------------------------------------------+
        # | main

        # derived from:
        #Hash::Merge::set_behavior('RIGHT_PRECEDENT');

        Hash::Merge::specify_behavior(
            {
                'SCALAR' => {
                    'SCALAR' => sub { $_[1] },
                    'ARRAY'  => sub { [ $_[0], @{ $_[1] } ] },
                    'HASH'   => sub { $_[1] },
                },
                'ARRAY' => {
                    'SCALAR' => sub { $_[1] },

                    # default:
                    # 'ARRAY'  => sub { [ @{ $_[0] }, @{ $_[1] } ] },
                    'ARRAY' => sub { _merge_array( $_[0], $_[1] ) },
                    'HASH'  => sub { $_[1] },
                },
                'HASH' => {
                    'SCALAR' => sub { $_[1] },
                    'ARRAY'  => sub { [ values %{ $_[0] }, @{ $_[1] } ] },
                    ## no critic (Subroutines::ProtectPrivateSubs)
                    'HASH' =>
                        sub { Hash::Merge::_merge_hashes( $_[0], $_[1] ) },
                },
            },
            'ARRAY_SPLICE',
        );

        # +------------------------------------------------------------------+
        # | API
        return;

    }

    # +======================================================================+
    # || cfg_ext                                                            ||
    # +======================================================================+
    sub cfg_ext {

        # +------------------------------------------------------------------+
        # | API
        my ( $self, $arg_r ) = @_;

        # OK: .cnf .json .jsn .xml .yml .yaml .ini .pl .perl ...
        # BAD: .conf
        #my @extension = grep { !m/conf/smx } @{ Config::Any->extensions };
        my @extension = qw(ini perl);    # reduced to used .ini and .perl

        # +------------------------------------------------------------------+
        # | API
        return @extension;
    }

    # +======================================================================+
    # || cfg                                                                ||
    # +======================================================================+
    # NEW config space, will be used after 3.4.0.0
    sub cfg {

        # +------------------------------------------------------------------+
        # | API
        my ( $self, $arg_r ) = @_;

        my $pkg = exists $arg_r->{pkg} ? $arg_r->{pkg} : 'cipux';
        my $sub = exists $arg_r->{sub} ? $arg_r->{sub} : $EMPTY_STRING;
        my $cfg = exists $arg_r->{cfg} ? $arg_r->{cfg} : undef; # only one cfg
        my $cache_dir
            = (     exists $arg_r->{cache_dir}
                and defined $arg_r->{cache_dir}
                and $arg_r->{cache_dir} ne $EMPTY_STRING )
            ? $self->l( $arg_r->{cache_dir} )
            : $CACHE_DIR;

        # +------------------------------------------------------------------+
        # | prepare
        my $logger = get_logger(__PACKAGE__);
        $logger->debug("pkg [$pkg]");
        $logger->debug("sub [$sub]");

        my $cfgbase
            = (     defined $pkg
                and $pkg
                and defined $sub
                and $sub
                and $sub ne $EMPTY_STRING )
            ? "$pkg-$sub"
            : $pkg;

        $self->create_cache_dir_if_not_present( { cache_dir => $cache_dir } );

        # determine cfg space quantity
        my $loadcfg_ar = $self->iterate_config_space(
            {
                cfg     => $cfg,
                cfgbase => $cfgbase,
            }
        );
        $logger->debug( 'loadcfg_ar: ',
            { filter => \&Dumper, value => $loadcfg_ar } );

        # determine cfg space quality
        my $clean = $self->evaluate_config_space(
            {
                loadcfg_ar => $loadcfg_ar,
                cache_dir  => $cache_dir,
                cfgbase    => $cfgbase,
            }
        );

        if ( -e "$cache_dir/$cfgbase.cache" and $clean and not defined $cfg )
        {
            $logger->debug("use disk: $cache_dir/$cfgbase.cache");
            my $cfg_hr = retrieve("$cache_dir/$cfgbase.cache")
                or croak
                "Can not load $cfgbase.cache in $cache_dir/$cfgbase.cache";
            return $cfg_hr;
        }

        $logger->debug("use Config::Any $cfgbase");

        # +------------------------------------------------------------------+
        # | main
        my @loadcfg = @{$loadcfg_ar};
        my $cfg_hr  = Config::Any->load_files(
            {
                files           => \@loadcfg,
                use_ext         => 1,
                override        => 1,
                flatten_to_hash => 1
            }
        );

        #$logger->debug( 'cfg_hr: ',
        #    { filter => \&Dumper, value => $cfg_hr } );

        $self->_hash_merge_setup();

        #Hash::Merge::set_behavior( 'ARRAY_SPLICE' );

        my $merged_hr = {};
        foreach my $filename (@loadcfg) {
            $merged_hr = merge( $merged_hr, $cfg_hr->{$filename} );
        }

        store( $merged_hr, "$cache_dir/$cfgbase.cache" )
            or croak "Can not save $cfgbase in $cache_dir/$cfgbase";

        # +------------------------------------------------------------------+
        # | API
        return $merged_hr;

    }

    sub create_cache_dir_if_not_present {

        my ( $self, $arg_r ) = @_;

        my $cache_dir
            = (     exists $arg_r->{cache_dir}
                and defined $arg_r->{cache_dir}
                and $arg_r->{cache_dir} ne $EMPTY_STRING )
            ? $self->l( $arg_r->{cache_dir} )
            : $CACHE_DIR;

        if ( not -d $cache_dir ) {

            # mkdir $cache_dir
            # or croak "Can not crate $cache_dir $!";
            my $umask = umask;
            umask $STRICT_UMASK;
            make_path( $cache_dir, { error => \my $err } );
            umask $umask;
            if ( scalar @{$err} ) {
                for my $diag ( @{$err} ) {
                    my ( $file, $message ) = %{$diag};
                    if ( $file eq $EMPTY_STRING ) {
                        warn "general error: $message\n";
                    }
                    else {
                        warn "problem createing $file: $message\n";
                    }
                }
            }

            # chown 0, 0, $cache_dir
            #   or croak 'Can not chown 0,0,$cache_dir';
            # chmod 0700, $cache_dir
            #  or croak 'Can not chmod 0700,$cache_dir';
        }

        return;

    }

    sub iterate_config_space {

        my ( $self, $arg_r ) = @_;
        my $cfg
            = ( exists $arg_r->{cfg} )
            ? $self->l( $arg_r->{cfg} )
            : $self->perr('cfg');
        my $cfgbase
            = ( exists $arg_r->{cfgbase} )
            ? $self->l( $arg_r->{cfgbase} )
            : $self->perr('cfgbase');

        my $l         = get_logger(__PACKAGE__);
        my @extension = $self->cfg_ext();
        my @suffix    = ();
        my @cfg_space = ();

        if ( defined $cfg ) {
            @cfg_space = ($cfg);
            $l->debug("add to config space [$cfg]");
        }
        else {
            @suffix = (
                "/usr/share/cipux/etc/$cfgbase.",
                "/usr/share/cipux/etc/$cfgbase.d/*.",
                "/etc/cipux/$cfgbase.",
                "/etc/cipux/$cfgbase.d/*.",
                "~/.cipux/$cfgbase.",
            );

            foreach my $s (@suffix) {
                foreach my $e (@extension) {
                    $l->debug("add to config space [$s$e]");
                    push @cfg_space, $s . $e;
                }
            }
        }
        my @filename = ();
        foreach my $g (@cfg_space) {
            $l->debug("glob [$g]");
            my @f = sort glob $g;
            push @filename, @f;
        }

        my @loadcfg = ();
        foreach my $f (@filename) {
            $f = $self->l($f);
            if ( -e $f ) {
                $l->debug("add file [$f] to cfg space");
                push @loadcfg, $f;
            }
        }
        return \@loadcfg;
    }

    sub evaluate_config_space {

        my ( $self, $arg_r ) = @_;
        my $loadcfg_ar
            = ( exists $arg_r->{loadcfg_ar} )
            ? $self->a( $arg_r->{loadcfg_ar} )
            : $self->perr('loadcfg_ar');
        my $cache_dir
            = ( exists $arg_r->{cache_dir} )
            ? $self->l( $arg_r->{cache_dir} )
            : $self->perr('cache_dir');
        my $cfgbase
            = ( exists $arg_r->{cfgbase} )
            ? $self->l( $arg_r->{cfgbase} )
            : $self->perr('cfgbase');
        my $l = get_logger(__PACKAGE__);

        my $eval_dir = "$cache_dir/$cfgbase";
        $self->create_cache_dir_if_not_present( { cache_dir => $eval_dir } );

        my $dirty   = 0;
        my %ndigest = ();
        my %odigest = ();
        foreach my $f ( @{$loadcfg_ar} ) {

            #  /etc/cipux/cipux-cat-web.ini
            $l->debug("evaluate cfg file [$f]");

            # calc md5 of cfg file
            open my $RF1, q{<}, $f or croak "Can not open $f for reading!";
            binmode $RF1;
            $ndigest{$f} = Digest::MD5->new->addfile($RF1)->hexdigest;
            close $RF1 or croak "Unable to close $!";

            #|  cache_dir  |cfgbase|name
            #/var/cache/cipux/cipux/3c9f65e4f1c5d05638f63da289e78eb3
            my $fn = "$eval_dir/$ndigest{$f}";
            $l->debug("evaluate md5 file [$fn]");

            if ( -e $fn ) {

                # clean
                $l->debug("[$f] found to be clean");
            }
            else {
                $l->debug("[$f] found to be dirty");
                $dirty = 1;

                # overwrite with clean version
                open my $WF, q{>}, $fn
                    or croak "Can not open $fn for writing!";
                print {$WF} $ndigest{$f}
                    or croak "print to [$fn] failed $1";
                close $WF or croak "Unable to close $!";
            }

        }

        return not $dirty;
    }

}    # END INSIDE-OUT CLASS

1;

__END__


=pod

=for stopwords CipUX Kuelker perr VARNAME API exc STDERR config getopt homedir lf LDAP lp li latin UTF UTF-8 login STDOUT TODO cfg

=head1 NAME

CipUX - Common CipUX functions

=head1 VERSION

version 3.4.0.11

=head1 SYNOPSIS

  use CipUX;

  my $cipux = $CipUX->new();

  my $max = $cipux->max(5,6);

Or use as base class:

  use base(CipUX);

  my $max = $self->max(5,6);


=head1 DESCRIPTION

Provides functions common to all CipUX classes and scripts.

=head1 CONSTRUCTOR

=head2 new

Constructor

  my $cipux = CipUX->new();

=head1 SUBROUTINES/METHODS

The following functions will be exported by CipUX.

=head2 get_linewidth

Returns the CipUX line width.

=head2 perr

Prints an exception that variable name VARNAME was not
used in subroutine API. This is used to discover internal
programming errors.

  $cipux->perr('<NAME OF PARAMETER>');
  $cipux->perr('<NAME OF PARAMETER>','<LINE NUMBER>');

Example:

  $cipux->perr('parameter_x');
  $cipux->perr('parameter_x', 98);

=head2 exc

Prints a CipUX default exception on STDERR and exits.

 $self->exc({nr=>$nr, value=>$value, msg=>$msg });

=head2 config

Central function to retrieve config space.

  my ($x_hr, $y_hr, $z_hr) = $self->config({config_ar=>$config_ar});

Local <NAME>_config subroutine should be use to fill $config_ar

  Example:

  sub task_config {
      my $config_ar = [];
      push @{$config_ar}, '/home/dummmy/cipux-task.conf';
      my ($x_hr, $y_hr, $z_hr) =
        $self->config({config_ar=>$config_ar});
      return ($x_hr, $y_hr, $z_hr);
  }

=head2 source

Incorporates a config file.

=head2 store_mattrvalue

Helper function for multiple getopt parameter with values.

=head2 store_attrvalue

Helper function for single getopt parameter with value.

=head2 homedir

This is an auxiliary method replacing ~ with $ENV{HGOME}.

B<Syntax:>

 my $file1  =  $common->homedir($file2);

B<Example:>

 if $file1  =  ~/.cipux/cipux-object.conf
 and $ENV{HOME} = /root
 then file2 =  /root/.cipux/cipux-object.conf

=head2 lf

Laundering LDAP filter.

=head2 lp

Laundering passwords.

=head2 li

Laundering integer values.

=head2 l

Laundering of a scalar

 my $scalar = $self->l($input);

=head2 h

Check if type is hash or hash reference.

 my $hash_hr = $self->a($input_hr);

=head2 a

Check if type is array or array reference.

 my $array_ar = $self->a($input_ar);

=head2 test_cli_option

Executes some basic test on command line option regarding a hash.

=head2 date_time

returns date time format of today

=head2 latin1_to_utf8

Converts latin to UTF-8 encoding.

=head2 login_prompt

Prints a login prompt on STDOUT.

=head2 password_prompt

Prints a password prompt on STDOUT.

=head2 random_password

Calculates and returns a relatively random password.

=head2 hash_password

Calculates and returns a hashed password.

=head2 min

Calculate the minimum of two integer values.

=head2 max

Calculate the maximum of two integer values.

=head2 out

Prints content to STDOUT.


=head2 _merge_array

Helper subroutine for _hash_merge_setup. It uses Array::Unique to return a
merged unique array reference.

=head2 _hash_merge_setup

Perform setup for Hash::Merge. The main change is that Arrays are also merged
with uniq values.

=head2 cfg_ext

Gets all supported extensions from Config::Any and remove non supported
extensions.

=head2 cfg

Query the CipUX config space to load configuration in various formats.

 0. Set cfgbase to "cipux" (+ "-$submodule" if not core module)

 1. Set cfgpaths to...:
    1. /usr/share/cipux/etc/$cfgbase.$ext
    2. /usr/share/cipux/etc/$cfgbase.d/*.$ext
    3. /etc/cipux/$cfgbase.$ext
    4. /etc/cipux/$cfgbase.d/*.$ext
    5. ~/.cipux/$cfgbase.$ext

 2. Possible $ext are: cnf .conf .json .jsn .xml .yml .yaml .ini .pl .perl

 #3. Optionally parse and validate uppercase "$cfgbase_cfg" environment
     variable [fail if validation fails]

 #4. Optionally parse and validate "cfg" commandline option
     [fail if validation fails]

 5. Resolve configfile list as cfgpaths, with "$cfgbase_cfg" and "cfg" appended
    if there

 6. Resolve bootstrap file through parsing and validating "bootstrap" option
    from all available files in cfgpaths, later declaration overriding earlier
    ones

 7. Resolve all options through executing bootstrap file

 #8. Optionally override subset of options through parsing and validating
    environment variables starting with uppercase "$cfgbase_"
    [fail if any validation fails]

 9. Optionally override subset of options through parsing and validating all
    options from all available files in cfgpaths [fail if any validation fails]

Notes about the above:

 * Number with leading "#" are not implemented.

 * config files are "layered", allowing overrides. Personal configfile
   is included last, not first, and more locations are supported.

 #* (subset of) options can be provided through ENV

 #* commandline and environment options are validated as part of parsing

Recommendation:

Even if several formats are supported, that does not mean they are all suited
for this task.

 * Some configuration formats for example are too simple to express the complex
   cipux-task.perl configuration.

 * The CPAN Perl modules used for this configuration space are rather young
   Config::Any 2006 - 2009, Hash::Merge 2001 - 2009  and not every
   configuration file type mixture was tested. As a recommendation, you should
   not mix to many files and formats.

=head2 create_cache_dir_if_not_present

Creates a directory 'cipux' under /var/cache if not present. This is used to
store serialized objects.

=head2 iterate_config_space

Takes a single config file $cfg (can be undef, but must be present) and a
string representing the configuration base $cfgbase. It will then just use $cfg
or it will find out regarding to $cfgbase what files should be considered.

  my $loadcfg_ar = $self->iterate_config_space(
      {
          cfg     => $cfg,
          cfgbase => $cfgbase,
      }
  );

returns a list of all configuration files which should be evaluated.

=head2 evaluate_config_space

Takes a araay ref to a list of configuration files $loadcfg_ar, preferably
cunstructed by iterate_config_space. It also taks a string $cache_dir to the
temporary location of a cache_dir. This value can be empty but not undef and
has to be provided. It also require the $cfgbase string, the "domain" of the
configuration.

It will calculate for every config file the MD5sum for later comparison.

        my $clean = $self->evaluate_config_space(
            {
                loadcfg_ar => $loadcfg_ar,
                cache_dir  => $cache_dir,
                cfgbase    => $cfgbase,
            }
        );

It will return 0 if changed files are found and 1 if no changed files are
found.


=head1 DIAGNOSTICS

This module generates the following exceptions:

TODO


=head1 CONFIGURATION AND ENVIRONMENT

Not applicable.

=head1 DEPENDENCIES

 Array::Unique
 Carp
 Class::Std
 Config::Any
 Data::Dumper
 Date::Manip
 English
 File::Basename
 File::Glob
 File::Path
 Hash::Merge
 Log::Log4perl
 Pod::Usage
 Readonly
 Storable
 Term::ReadKey
 Unicode::String
 version

=head1 INCOMPATIBILITIES

Not known.

=head1 BUGS AND LIMITATIONS

Not known.

=head1 SEE ALSO

See the CipUX web page and the manual at L<http://www.cipux.org>

See the mailing list L<http://sympa.cipworx.org/wws/info/cipux-devel>

=head1 AUTHOR

Christian Kuelker  E<lt>christian.kuelker@cipworx.orgE<gt>

=head1 LICENSE AND COPYRIGHT

Copyright (C) 2007 - 2009 by Christian Kuelker

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.

This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA

=cut