This file is indexed.

/usr/share/perl5/CipUX/RPC/Server.pm is in libcipux-rpc-perl 3.4.0.9-3.1.

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

The actual contents of the file can be viewed below.

   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 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
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
# +==========================================================================+
# || CipUX::RPC::Server                                                     ||
# ||                                                                        ||
# || CipUX RPC Server Class                                                 ||
# ||                                                                        ||
# || Copyright (C) 2007 - 2010 by Christian Kuelker                         ||
# ||                                                                        ||
# || License: GNU GPL - GNU general public license - version 2              ||
# ||          or (at your opinion) any later version.                       ||
# ||                                                                        ||
# +==========================================================================+
# ID:       $Id$
# Revision: $Revision$
# Head URL: $HeadURL$
# Date:     $Date$
# Source:   $Source$

package CipUX::RPC::Server;

use 5.008001;
use strict;
use warnings;
use utf8;

use Authen::Simple::PAM;
use Authen::Simple::Password;
use Carp;
use CipUX 3.4.0.4;    ##no critic
use CipUX::Task;
use CipUX::RBAC::Simple;
use Class::Std;
use Data::Dumper;
use English qw( -no_match_vars);
use Frontier::Daemon;
use Frontier::RPC2;
use List::MoreUtils qw(any none);
use Log::Dispatch;
use Log::Log4perl qw(get_logger :levels);
use Readonly;
use Ticket::Simple;

use base qw(CipUX::RPC);
{    # BEGIN CLASS

    # CONSTRUCTOR
    # DESTRUCTOR
    # PRIVATE METHODS
    # * privacy cathegory 1
    #   - check_authentication
    #   - is_ticket_bad
    # * privacy cathegory 2
    #   - signal_handler
    #   - answer_requests
    #   - check_access_to_task
    #   - check_access_to_rpc_intern
    #   - check_access_to_cat_module
    #   - error
    #   - evaluate_access
    #   - update_task
    #   - update_cat_module
    # PUBLIC METHODS
    # - get_config
    # - rpc_list_functions
    # - rpc_start
    # XML-RPC METHODS
    # - ping
    # - version
    # - sum
    # - login
    # - logout
    # - session
    # - ttl
    # - rpc_task
    # - rpc_info
    # - rpc_intern

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

    # +======================================================================+
    # || CONST                                                              ||
    # +======================================================================+
    Readonly::Scalar my $EMPTY_STRING => q{};
    Readonly::Scalar my $SCRIPT       => 'CipUX::RPC::Server';
    Readonly::Scalar my $HEADER_HREF  => {
        'cipux_version'  => '3.4.0.0',
        'server_name'    => 'cipux_rpcd',
        'server_version' => '3.4.0.0',
        'rpc_version'    => '2.0',
        'server_key'     => $EMPTY_STRING,
        'server_cred'    => $EMPTY_STRING,
        'gmt_time'       => time,
    };
    Readonly::Scalar my $A_SHORT_WHILE      => 3;          # in sec
    Readonly::Scalar my $INTERN_ADMIN_GROUP => 'admin';    # last resort

    Readonly::Array my @ADMIN_GROUP_CLIENT =>
        qw(cipux_cat_web_module cipux_rpc_test_client cipux_rpc_test_repetition cipuxpasswd);
    Readonly::Array my @RPC_INTERN_CMD    => qw(rpc_intern);
    Readonly::Array my @RPC_INTERN_SUBCMD => qw(flush
        cat_module_cache_size
        rpc_intern_cache_size
        task_cache_size
        user_task_access
        user_task_access_survey
        user_cat_module_access
        user_cat_module_access_survey
        user_rpc_intern_access
        user_rpc_intern_access_survey
    );

    # +======================================================================+
    # || OBJECT                                                             ||
    # +======================================================================+

    # +======================================================================+
    # || GLOBAL                                                             ||
    # +======================================================================+
    my $cipux_task         = undef;
    my $cipux_task_list_ar = undef;
    my $rpc_cfg_hr         = undef;  # undef means: load it at the first time.
    my $rpc                = undef;
    my $rbac               = undef;
    my $ts                 = undef;
    my $time_to_die        = 0;      # shutdown server with SIG handler

    # +======================================================================+
    # || CONSTRUCTOR                                                        ||
    # +======================================================================+
    sub BUILD {

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

        $cache_dir
            = exists $arg_r->{cache_dir}
            ? $self->l( $arg_r->{cache_dir} )
            : $EMPTY_STRING;

        # +------------------------------------------------------------------+
        # | main
        my $cipux_task = CipUX::Task->new( { cache_dir => $cache_dir } );
        $cipux_task_list_ar = $cipux_task->list_task();
        $rpc                = CipUX::RPC->new( { cache_dir => $cache_dir } );
        $rbac               = CipUX::RBAC::Simple->new();
        my $ttl = $self->get_config('xml_rpc_ticket_ttl');
        $ts = Ticket::Simple->new( { ttl => $ttl } );

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

    }

    # +======================================================================+
    # || DESTRUCTOR                                                         ||
    # +======================================================================+
    sub DEMOLISH {

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

        # +------------------------------------------------------------------+
        # | main
        undef $cipux_task;
        undef $cipux_task_list_ar;
        undef $rpc_cfg_hr;
        undef $rpc;
        undef $rbac;
        undef $time_to_die;
        undef $ts;

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

    }

    # +======================================================================+
    # || PRIVATE functions to the server (also not exported via XML-RPC)    ||
    # +======================================================================+

    # +----------------------------------------------------------------------+
    # |  PRIVACY CATEGORY 1 (have to keep them private)                      |
    # +----------------------------------------------------------------------+

    # +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
    # :  check_authentication                                                :
    # +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
    sub check_authentication : PRIVATE {

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

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

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

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

        # unsuccessfully authentication return 0 (FALSE)
        my $authenticated = 0;

        # check for empty password, return 0 (FALSE) if empty
        if ( $password eq $EMPTY_STRING ) {
            $logger->debug('Empty password');
            $logger->info("authentication not sucessfully for [$login]");

            # unsuccessfully authentication return 0 (FALSE)
            $authenticated = 0;
            return $authenticated;    # we do not want further tests
        }

        $logger->debug('using PAM to authenticate login');
        my $pam = Authen::Simple::PAM->new( service => 'password' );
        if ( $pam->authenticate( $login, $password ) ) {

            # successfully authentication return 1 (TRUE)
            $logger->info("authentication sucessfully for [$login]");
            $authenticated = 1;

        }

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

    # +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
    # :  is_ticket_bad                                                       :
    # +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
    sub is_ticket_bad : PRIVATE {

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

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

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

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

        # +------------------------------------------------------------------+
        # | prepare
        my $logger = get_logger(__PACKAGE__);
        $logger->debug( 'got login: ',     $login );
        $logger->debug( 'got ticket: ',    $ticket );
        $logger->debug( 'got answer_hr: ', 'not printed' );

        # +------------------------------------------------------------------+
        # | main
        if (
            not $ts->is_ticket_valid_now(
                { login => $login, ticket => $ticket }
            )
            )
        {
            $logger->warn("ticket [$ticket] is not valid for [$login] now");

            my $msg = 'Your ticket is not valid!';
            $msg .= ' This can have serveral reasons:';
            $msg .= ' (1) the ticket expired. (2) an error in programming  ';
            $msg .= ' (3) you never logged in';

            # reset cookie => print login dialog
            $answer_hr->{ticket}  = 'test';
            $answer_hr->{login}   = 'test';
            $answer_hr->{msg}     = $msg;
            $answer_hr->{problem} = 2;        # NO TIME
            $answer_hr->{ltarget} = 'NULL';
            return { result => 1, answer_hr => $answer_hr };
        }

        # OK, time and ticket an SEED match, must be ours!

        $answer_hr->{msg}     = $EMPTY_STRING;
        $answer_hr->{problem} = 0;               # no problem

        $logger->debug('Is the ticket bad? NO!! Ticket is not bad.');
        $logger->debug('problem 0: no problem');

        $logger->warn("ticket [$ticket] is good for [$login]");

        # +------------------------------------------------------------------+
        # | API
        return { result => 0, answer_hr => $answer_hr };

    } ## end sub is_ticket_bad

    # +----------------------------------------------------------------------+
    # |  PRIVACY CATEGORY 2 (might change to public if needed)               |
    # +----------------------------------------------------------------------+

    # +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
    # :  signal_handler                                                      :
    # +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
    sub signal_handler : PRIVATE {

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

        $time_to_die = 1;

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

    } ## end sub signal_handler

    # +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
    # :  answer_requests                                                     :
    # +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
    sub answer_requests : PRIVATE {

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

        my $logger = get_logger(__PACKAGE__);

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

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

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

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

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

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

        # +------------------------------------------------------------------+
        # | main
        $logger->debug( 'port: ',    $port );
        $logger->debug( 'address: ', $address );
        $logger->debug( 'reuse: ',   $reuse );
        $logger->debug( 'proto: ',   $proto );
        $logger->debug( 'meth_hr: ', $meth_hr );
        $logger->debug( 'task_hr: ', $task_hr );

        my $z = 0;
        $logger->debug( 'try to bind to LocalAddr: ', $address );
        $logger->debug( 'using LocalPort: ',          $port );

        my $daemon = 0;
        while ( not $time_to_die ) {
            sleep $A_SHORT_WHILE;
            my $msg = 'Running - if this value counts up continiously,';
            $msg .= 'the server did not start correctly. Probably ';
            $msg .= 'the port is in use. If you see this message only ';
            $msg .= 'one time everything is OK.';

            $logger->info( $msg, $z );
            $z++;

            # LocalPort => "https(8001)",
            # LocalAddr => "127.0.0.1:8001",
            $daemon = Frontier::Daemon->new(
                LocalPort => "https($port)",      # 8001
                LocalAddr => "$address:$port",    # localhost:8001
                ReuseAddr => $reuse,              # 1,
                Proto     => $proto,              # tcp
                methods   => $meth_hr             # href to sub refs
            );

            # not implemented for Debian sarge
            # ReusePort => 1,

            # On plain debian there is also no support compiled in:
            # "Your vendor has not defined Socket macro SO_REUSEPORT,
            # used at /usr/lib/perl/5.8/IO/Socket/INET.pm line 160"

            $logger->debug( 'daemon: ', $daemon );
        } ## end while ( not $time_to_die )

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

    } ## end sub answer_requests

    # +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
    # :  check_access_to_task                                                :
    # +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
    sub check_access_to_task : PRIVATE {

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

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

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

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

        if ( $login eq $EMPTY_STRING ) {
            $logger->info("Access DENIED for [$login] to [$cmd]");
            $logger->debug('Empty login: Access DENIED');
            return 0;
        }

        if ( $cmd eq 'cipux_task_sum' ) {
            $logger->info("Access GRANTED for [$login] to [$cmd]!");
            return 1;
        }
        elsif ( $rbac->access_to_task( { task => $cmd, user => $login } ) ) {
            $logger->info("Access GRANTED for [$login] to [$cmd]");
            return 1;
        }
        else {
            $logger->info("Access DENIED for [$login] to [$cmd]");
            $logger->debug('Empty login: Access DENIED');
        }

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

    # +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
    # :  check_access_to_cat_module                                          :
    # +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
    sub check_access_to_cat_module : PRIVATE {

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

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

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

        # +------------------------------------------------------------------+
        # | main
        my $logger = get_logger(__PACKAGE__);
        $logger->debug("login [$login]");
        $logger->debug("cmd [$cmd]");

        if ( $cmd eq 'index.cgi' ) {
            return 1;
        }
        elsif (
            $rbac->access_to_cat_module(
                { cat_module => $cmd, user => $login }
            )
            )
        {
            $logger->debug('ACCESS');
            return 1;
        }
        else {
            $logger->debug('NO ACCESS');
        }

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

    # +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
    # :  check_access_to_rpc_intern                                          :
    # +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
    sub check_access_to_rpc_intern : PRIVATE {

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

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

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

        # +------------------------------------------------------------------+
        # | main
        my $logger = get_logger(__PACKAGE__);
        $logger->debug("login [$login]");
        $logger->debug("cmd [$cmd]");

        my $role
            = ( $self->get_config('xml_rpc_intern_admin_group') )
            ? $self->get_config('xml_rpc_intern_admin_group')
            : $INTERN_ADMIN_GROUP;

        $logger->debug("role [$role]");

        if ( none {m/^$cmd$/smx} @RPC_INTERN_CMD ) {
            $logger->debug("rpc_intern command not valid [$cmd]");
        }
        elsif ( ( any {m/^$cmd$/smx} @RPC_INTERN_CMD )
            and
            $rbac->access_to_rpc_intern( { role => $role, user => $login } ) )
        {
            $logger->debug('ACCESS');
            return 1;
        }
        else {
            $logger->debug('NO ACCESS');
        }

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

    # +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
    # :  error                                                               :
    # +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
    sub error : PRIVATE {

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

        my $logger = get_logger(__PACKAGE__);

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

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

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

        my $msg = "No access for [$login] to [$cmd]";

        # answer
        my $answer_hr = {
            header_hr => $HEADER_HREF,
            cmd       => $cmd,
            login     => $login,
            ticket    => $ticket,
            status    => 'FALSE',
            msg       => $msg,
            type      => 'href',
            cmdres_r  => {},
            ltarget   => 'NULL',
        };

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

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

    # +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
    # :  evaluate_access                                                 :
    # +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
    sub evaluate_access : PRIVATE {

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

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

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

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

        # +------------------------------------------------------------------+
        # | main
        my $check_access_disp_hr = {
            'task'       => \&check_access_to_task,
            'cat_module' => \&check_access_to_cat_module,
            'rpc_intern' => \&check_access_to_rpc_intern,
        };
        my $logger = get_logger(__PACKAGE__);
        $logger->debug("login [$login]");
        $logger->debug("realm [$realm]");
        if ( not exists $check_access_disp_hr->{$realm} ) {
            croak "Realm [$realm] do not exists in dispatch table!\n";
        }

        # 'entity' => 'task',
        # 'to'     =>  'cipadmin',
        # 'to_ar' => [
        #            'cipux_task_list_user_accounts'
        #          ],
        # 'subcmd' => 'user_task_access',
        # 'rcpmode' => 'rpc_intern',
        # 'scope' => 'single'

        $logger->debug("login [$login]");

        my $cmdres_r = {};

        my $subcmd
            = ( exists $param_hr->{subcmd} )
            ? $param_hr->{subcmd}
            : return $cmdres_r;

        # we do not trust the "from" param.
        my $from
            = (
                   $subcmd eq 'task_access'
                or $subcmd eq 'task_access_survey'
            ) ? $login
            : (    $subcmd eq 'user_task_access'
                or $subcmd eq 'user_task_access_survey'
                or $subcmd eq 'user_cat_module_access'
                or $subcmd eq 'user_cat_module_access_survey'
                or $subcmd eq 'user_rpc_intern_access'
                or $subcmd eq 'user_rpc_intern_access_survey'
                and exists $param_hr->{from} ) ? $param_hr->{from}
            : $login;

        $logger->debug("from [$from]");

        my $to_ar = exists $param_hr->{to_ar} ? $param_hr->{to_ar} : [];

        my %access = ();
        foreach my $to ( @{$to_ar} ) {
            $logger->debug("examine to [$to]");
            my $disp = $check_access_disp_hr->{$realm};
            my $r = $self->$disp( { login => $from, cmd => $to } );
            $logger->debug("access result [$to] for [$from]: [$r]");
            $access{$to} = $r;
        }

        $cmdres_r = { from => $from, access_hr => \%access, };

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

    }

    # +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
    # :  update_task                                                         :
    # +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
    sub update_task : PRIVATE {

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

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

        my %task       = ();
        my $cipux_task = CipUX::Task->new( { cache_dir => $cache_dir } );
        my $return_r   = $cipux_task->task(
            {
                script  => __PACKAGE__,
                task    => 'cipux_task_list_tasks',
                mode    => 'rpc',
                object  => undef,
                attr_hr => {},
            }
        );

        # $return_r = {
        #     'taskres_r' => {
        #         '<NAME>' => {
        #             'cn' => [
        #                 '<NAME>'
        #             ]
        #         }
        #     },
        #     'status' => 'OK',
        #     'type' => 'href'
        # };
        if ( exists $return_r->{status}
            and $return_r->{status} eq 'OK' )
        {
            my @task = keys %{ $return_r->{taskres_r} };
            %task = map { $_ => 1 } @task;
        }
        else {
            confess 'Can not get tasks by cipux_task_list_tasks!';
        }

        foreach my $task ( sort @{$cipux_task_list_ar} ) {
            if ( $task{$task} ) {
                $logger->debug("task exists [$task]");
            }
            else {
                $logger->debug("task [$task] do not exist");

                my $return_r = $cipux_task->task(
                    {
                        script  => __PACKAGE__,
                        task    => 'cipux_task_register_task',
                        mode    => 'rpc',
                        object  => $task,
                        attr_hr => {},
                    }
                );
                if (
                    not( exists $return_r->{status}
                        and $return_r->{status} eq 'OK' )
                    )
                {
                    confess "failure cipux_task_register_task [$task]!";
                }

            }
        }

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

    # +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
    # :  update_cat                                                          :
    # +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
    sub update_cat_module : PRIVATE {

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

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

        my %cat        = ();
        my $cipux_task = CipUX::Task->new( { cache_dir => $cache_dir } );
        my $return_r   = $cipux_task->task(
            {
                script  => __PACKAGE__,
                task    => 'cipux_task_list_cat_modules',
                mode    => 'rpc',
                object  => undef,
                attr_hr => {},
            }
        );

        # $return_r = {
        #     'taskres_r' => {
        #         '<NAME>' => {
        #             'cn' => [
        #                 '<NAME>'
        #             ]
        #         }
        #     },
        #     'status' => 'OK',
        #     'type' => 'href'
        # };
        if ( exists $return_r->{status}
            and $return_r->{status} eq 'OK' )
        {
            my @cat = keys %{ $return_r->{taskres_r} };
            %cat = map { $_ => 1 } @cat;
        }
        else {
            confess 'Can not get modules by cipux_task_list_cat_modules!';
        }

        foreach my $mod (@ADMIN_GROUP_CLIENT) {
            if ( $cat{$mod} ) {
                $logger->debug("module exists [$mod]");
            }
            else {
                $logger->debug("module [$mod] do not exist");

                # default 'admin' (could be other)
                my $role
                    = ( $self->get_config('xml_rpc_intern_admin_group') )
                    ? $self->get_config('xml_rpc_intern_admin_group')
                    : $INTERN_ADMIN_GROUP;

                my $attr_hr = {
                    cipuxName             => $mod,
                    cipuxTemplate         => 'none',
                    cipuxTemplateDir      => 'none',
                    cipuxEntity           => 'none',
                    cipuxModality         => 'none',
                    cipuxIsModuleArray    => 'FALSE',
                    cipuxAuthor           => 'same as CipUX',
                    cipuxLicense          => 'same as CipUX',
                    cipuxYear             => 'same as CipUX',
                    cipuxScript           => $mod,
                    cipuxIcon             => 'shell.png',
                    cipuxShortDescription => 'CAT on the command line',
                    cipuxIsEnabled        => 'yes',
                    cipuxMemberRid        => $role,
                };

                my $return_r = $cipux_task->task(
                    {
                        script  => __PACKAGE__,
                        task    => 'cipux_task_register_cat_module',
                        mode    => 'rpc',
                        object  => $mod,
                        attr_hr => {},
                    }
                );
                if (
                    not( exists $return_r->{status}
                        and $return_r->{status} eq 'OK' )
                    )
                {
                    confess "failure cipux_task_register_cat_module [$mod]!";
                }

            }
        }

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

    # +======================================================================+
    # || PUBLIC METHODS                                                     ||
    # +======================================================================+

    # +----------------------------------------------------------------------+
    # |  log2syslog                                                          |
    # +----------------------------------------------------------------------+
    sub log2syslog {

        my $message = shift;

        my $log = Log::Dispatch->new(
            outputs => [ [ 'Syslog', min_level => 'info', ] ] );
        $log->emerg($message);

        return;
    }

    # +----------------------------------------------------------------------+
    # |  get_config                                                          |
    # +----------------------------------------------------------------------+
    sub get_config {

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

        my $logger = get_logger(__PACKAGE__);
        $logger->debug("asked for configuration key [$key]");

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

        if ( not defined $rpc_cfg_hr ) {
            $logger->debug('get_rpc_cfg');
            $rpc_cfg_hr = $rpc->get_rpc_cfg();
        }

        my $return = $rpc_cfg_hr->{$key};

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

    } ## end sub get_config
     # +---------------------------------------------------------------------+
     # |  rpc_list_functions                                                 |
     # +---------------------------------------------------------------------+

    sub rpc_list_functions {

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

        my $logger = get_logger(__PACKAGE__);

        my $scope
            = exists $arg_r->{scope}
            ? $self->l( $arg_r->{scope} )
            : $self->perr('scope');    # all |

        # +------------------------------------------------------------------+
        # | main
        $logger->debug( 'scope: ', $scope );

        my @cmd = @{$cipux_task_list_ar};

        # add generic RPC commands:
        push @cmd, qw( ping version sum login logout session ttl);
        push @cmd, qw( task rpc_info rpc_intern );

        # +------------------------------------------------------------------+
        # | API
        return @cmd;

    }

    # +----------------------------------------------------------------------+
    # |  rpc_start                                                           |
    # +----------------------------------------------------------------------+
    sub rpc_start {

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

        my $logger = get_logger(__PACKAGE__);

        # +------------------------------------------------------------------+
        # | main
        my @obj = qw(/var/cache/cipux/cipux-access
            /var/cache/cipux/cipux-object
            /var/cache/cipux/cipux-rbac
            /var/cache/cipux/cipux-rpc
            /var/cache/cipux/cipux-storage
            /var/cache/cipux/cipux-task);
        my $l = unlink @obj;

        $self->create_cache_dir_if_not_present();

        my $msg             = 'start server with address';
        my $xml_rpc_address = $self->get_config('xml_rpc_address');
        $logger->debug( $msg . q{: }, $xml_rpc_address );

        if (
            not(   $xml_rpc_address eq 'localhost'
                or $xml_rpc_address eq '127.0.0.1' )
            )
        {
            my $msg = 'xml_rpc_address other then localhost or 127.0.0.1 ';
            $msg .= 'are not supported. ';
            $msg .= 'Please choose a different value in configuration file. ';
            $msg .= 'The value which was given was';
            $self->exc( { msg => $msg, value => $xml_rpc_address } );
        }

        $msg = 'start server with port';
        my $xml_rpc_port = $self->get_config('xml_rpc_port');
        $logger->debug( $msg . q{: }, $xml_rpc_port );

        $msg = 'start server with ticket ttl';
        my $xml_rpc_ticket_ttl = $self->get_config('xml_rpc_ticket_ttl');
        $logger->debug( $msg . q{: }, $xml_rpc_ticket_ttl );

        if ( $xml_rpc_ticket_ttl <= 0 ) {
            my $msg = 'xml_rpc_ticket_ttl is less or equal then 0';
            $msg .= 'Please choose a different value in configuration file.';
            $self->exc( { msg => $msg, value => $xml_rpc_address } );
        }

        $msg = 'start server with use_pam';
        my $xml_rpc_use_pam = $self->get_config('xml_rpc_use_pam');
        $logger->debug( $msg . q{: }, $xml_rpc_use_pam );

        $msg = 'start server with pid_file';
        my $xml_rpc_pid_file = $self->get_config('xml_rpc_pid_file');
        $logger->debug( $msg . q{: }, $xml_rpc_pid_file );

        $msg = 'start server with proto';
        my $xml_rpc_proto = $self->get_config('xml_rpc_proto');
        $logger->debug( $msg . q{: }, $xml_rpc_proto );

        $msg = 'start server with reuse';
        my $xml_rpc_reuse = $self->get_config('xml_rpc_reuse');
        $logger->debug( $msg . q{: }, $xml_rpc_reuse );

        #  $msg = 'start server with TTL';
        #  my $xml_rpc_ticket_ttl = $self->get_config('xml_rpc_ticket_ttl');
        #  $logger->debug($msg.q{: }, $xml_rpc_ticket_ttl  ,"\n");

        # as everybody, who got killed, we have to sleep 3 seconds
        # to regenerate our self to awake again ;-)
        sleep $A_SHORT_WHILE;

        # check all given tasks.
        $self->update_task();

        # check RPC own CAT modules.
        $self->update_cat_module();

        my @list = $self->rpc_list_functions( { scope => 'all' } );
        my $task_hr = {};
        foreach my $task (@list) {
            $task_hr->{$task} = 1;
        }

        # methode_hr
        my $meth_hr = {
            ping    => sub { $self->ping(@_); },
            version => sub { $self->version(@_); },
            sum     => sub { $self->sum(@_); },
            login   => sub { $self->login(@_); },
            logout  => sub { $self->logout(@_); },
            session => sub { $self->session(@_); },
            ttl     => sub { $self->ttl(@_); },
            task    => sub {

                #my $logger = get_logger(__PACKAGE__);
                #foreach my $x (@_) {
                #    $logger->debug("X [$x]");
                #    foreach my $h ( keys %{$x} ) {
                #        $logger->debug("h [$h] -> [$x->{$h}]");
                #    }
                #}
                if ( $self->check_access_to_task(@_) ) {
                    $self->rpc_task(@_);
                }
                else { $self->error(@_); }
            },
            rpc_info   => sub { $self->rpc_info(@_); },
            rpc_intern => sub {
                if ( $self->check_access_to_rpc_intern(@_) ) {
                    $self->rpc_intern(@_);
                }
                else { $self->error(@_); }
            },
        };

        $self->answer_requests(
            {
                address => $xml_rpc_address,
                port    => $xml_rpc_port,
                reuse   => $xml_rpc_reuse,
                proto   => $xml_rpc_proto,
                meth_hr => $meth_hr,
                task_hr => $task_hr,
            }
        );

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

    } ## end sub rpc_start

    # +======================================================================+
    # || XML-RPC METHODS (exported via XML-RPC server)                      ||
    # +======================================================================+

    # +----------------------------------------------------------------------+
    # | ping                                                                 |
    # +----------------------------------------------------------------------+
    sub ping : PRIVATE {

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

        my $logger = get_logger(__PACKAGE__);

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

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

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

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

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

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

        # answer
        my $answer_hr = {
            header_hr => $HEADER_HREF,
            cmd       => 'ping',
            login     => $login,
            ticket    => $ticket,
            status    => 'TRUE',          # use this to test if available
            msg       => $EMPTY_STRING,
            type      => 'href',
            cmdres_r  => {},
            ltarget   => 'NULL',
        };

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

    } ## end sub ping

    # +----------------------------------------------------------------------+
    # |  version                                                             |
    # +----------------------------------------------------------------------+
    sub version : PRIVATE {

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

        my $logger = get_logger(__PACKAGE__);

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

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

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

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

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

        # +------------------------------------------------------------------+
        # | main
        my $cmdres_r = {
            cipux_version  => '3.4.0.0',
            server_version => '3.4.0.0',
            rpc_version    => '2.0',
        };

        # answer
        my $answer_hr = {
            header_hr => $HEADER_HREF,
            cmd       => 'version',
            login     => $login,
            ticket    => $ticket,
            status    => 'TRUE',
            msg       => $EMPTY_STRING,
            type      => 'href',
            cmdres_r  => $cmdres_r,
            ltarget   => 'NULL',
        };

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

    } ## end sub version

    # +----------------------------------------------------------------------+
    # |  sum  (alias sum1)                                                   |
    # +----------------------------------------------------------------------+
    sub sum : PRIVATE {

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

        my $logger = get_logger(__PACKAGE__);

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

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

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

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

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

        my $summand1
            = exists $param_hr->{summand1}
            ? $self->l( $param_hr->{summand1} )
            : $self->perr('summand1 in param_hr not arg_r');

        my $summand2
            = exists $param_hr->{summand2}
            ? $self->l( $param_hr->{summand2} )
            : $self->perr('summand2 in param_hr not arg_r');

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

        # main
        my $sum      = $summand1 + $summand2;
        my $cmdres_r = [$sum];

        # answer
        my $answer_hr = {
            header_hr => $HEADER_HREF,
            cmd       => 'sum',
            login     => $login,
            ticket    => $ticket,
            status    => 'TRUE',
            msg       => $EMPTY_STRING,
            type      => 'aref',
            cmdres_r  => $cmdres_r,
            ltarget   => 'NULL',
        };

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

    } ## end sub sum

    # +----------------------------------------------------------------------+
    # |  login                                                               |
    # +----------------------------------------------------------------------+
    sub login : PRIVATE {

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

        my $logger = get_logger(__PACKAGE__);

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

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

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

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

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

        my $password
            = exists $param_hr->{password}
            ? $self->l( $param_hr->{password} )
            : $self->perr('password');

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

        # +------------------------------------------------------------------+
        # | debug
        my $msg = 'we got login';
        $logger->debug( $msg . q{: }, $login );
        $msg = 'given password was defined - no print here -';
        $logger->debug($msg);

        $msg = 'start use login with ticket ttl';
        my $xml_rpc_ticket_ttl = $self->get_config('xml_rpc_ticket_ttl');
        $logger->debug( $msg . q{: }, $xml_rpc_ticket_ttl );

        # answer
        my $answer_hr = {
            header_hr => $HEADER_HREF,
            cmd       => 'login',
            login     => $login,
            ticket    => $ticket,
            status    => 'FALSE',
            msg       => $EMPTY_STRING,
            type      => 'href',
            cmdres_r  => {},
            ltarget   => 'NULL',
        };

        if ( $password eq $EMPTY_STRING ) {
            my $msg = 'empty password given.';
            $logger->debug($msg);

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

        $msg = 'password was given for login';
        $logger->debug( $msg . q{: }, $login );

        # check if login is authenticated
        my $is_authenticated = $self->check_authentication(
            { login => $login, password => $password } );

        if ($is_authenticated) {
            $logger->debug('password is valid for login');
            $logger->debug("login is_authenticated:  $login");

            #$logger->debug("old login ticket: [$ticket]");
            # create new ticket, no test
            my ( $ticket, $valid )
                = $ts->create_ticket( { login => $login } );
            $ts->store_ticket(
                { login => $login, ticket => $ticket, valid => $valid } );

            #$logger->debug("new login ticket: [$ticket]");
            $logger->debug( 'ticket: ', $ticket );

            # differnt answer
            $answer_hr->{status}   = 'TRUE';
            $answer_hr->{type}     = 'href';
            $answer_hr->{cmdres_r} = {
                login  => $login,
                ticket => $ticket,
                ttl    => $xml_rpc_ticket_ttl,
            };
            $answer_hr->{ltarget} = 'NULL';

          # +----------------------------------------------------------------+
          # | API
            return $answer_hr;
        }
        else {
            my $msg = 'WARN password is valid NOT for login ';
            $logger->debug( $msg . q{: }, $login );

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

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

    } ## end sub login

    # +----------------------------------------------------------------------+
    # |  logout                                                              |
    # +----------------------------------------------------------------------+
    sub logout : PRIVATE {

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

        my $logger = get_logger(__PACKAGE__);

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

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

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

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

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

        # +------------------------------------------------------------------+
        # | main
        # answer
        my $answer_hr = {
            header_hr => $HEADER_HREF,
            cmd       => 'logout',
            login     => $login,
            ticket    => $ticket,
            status    => 'FALSE',
            msg       => $EMPTY_STRING,
            type      => 'href',
            cmdres_r  => {},
            ltarget   => 'NULL',
        };

        # check the ticket
        my $bad_hr = $self->is_ticket_bad(
            {
                login     => $login,
                ticket    => $ticket,
                answer_hr => $answer_hr
            }
        );

        # +------------------------------------------------------------------+
        # | API
        if ( $bad_hr->{result} ) {
            $logger->debug('bad result');
            return $bad_hr->{answer_hr};
        }

        # main
        $ts->wipe_ticket( { login => $login } );

        # answer
        $answer_hr->{status}   = 'TRUE';
        $answer_hr->{type}     = 'href';
        $answer_hr->{cmdres_r} = {};

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

    } ## end sub logout

    # +----------------------------------------------------------------------+
    # |  session                                                             |
    # +----------------------------------------------------------------------+
    sub session : PRIVATE {

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

        my $logger = get_logger(__PACKAGE__);

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

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

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

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

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

        # +------------------------------------------------------------------+
        # | main
        # answer
        my $answer_hr = {
            header_hr => $HEADER_HREF,
            cmd       => 'session',
            login     => $login,
            ticket    => $ticket,
            status    => 'FALSE',
            msg       => $EMPTY_STRING,
            type      => 'href',
            cmdres_r  => {},
            ltarget   => 'NULL',
        };

        # check the ticket
        my $bad_hr = $self->is_ticket_bad(
            {
                login     => $login,
                ticket    => $ticket,
                answer_hr => $answer_hr
            }
        );

        if ( $bad_hr->{result} ) {
            $logger->debug('bad result');

            # +--------------------------------------------------------------+
            # | API
            return $bad_hr->{answer_hr};
        }

        my ( $t, $v ) = $ts->create_ticket( { login => $login } );
        $ts->store_ticket( { login => $login, ticket => $t, valid => $v } );

        # answer
        #$answer_hr->{ticket}   = $t;
        $answer_hr->{status}   = 'TRUE';
        $answer_hr->{type}     = 'href';
        $answer_hr->{cmdres_r} = { ticket => $t, };

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

    } ## end sub session

    # +----------------------------------------------------------------------+
    # |  ttl                                                                 |
    # +----------------------------------------------------------------------+
    sub ttl : PRIVATE {

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

        my $logger = get_logger(__PACKAGE__);

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

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

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

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

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

        # +------------------------------------------------------------------+
        # | main
        # answer
        my $answer_hr = {
            header_hr => $HEADER_HREF,
            cmd       => 'ttl',
            login     => $login,
            ticket    => $ticket,
            status    => 'FALSE',
            msg       => $EMPTY_STRING,
            type      => 'href',
            cmdres_r  => {},
            ltarget   => 'NULL',
        };

        # check the ticket
        my $bad_hr = $self->is_ticket_bad(
            {
                login     => $login,
                ticket    => $ticket,
                answer_hr => $answer_hr
            }
        );

        if ( $bad_hr->{result} ) {
            $logger->debug('bad result');

            # +--------------------------------------------------------------+
            # | API
            return $bad_hr->{answer_hr};
        }

        # main
        my $ttl = $ts->get_ttl;

        # answer
        $answer_hr->{login}    = $login;
        $answer_hr->{ticket}   = $ticket;
        $answer_hr->{status}   = 'TRUE';
        $answer_hr->{type}     = 'href';
        $answer_hr->{cmdres_r} = { ttl => $ttl };

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

    } ## end sub ttl

    # +----------------------------------------------------------------------+
    # |  rpc_task (uses CipUX::Task)                                         |
    # +----------------------------------------------------------------------+
    sub rpc_task : PRIVATE {

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

        my $logger = get_logger(__PACKAGE__);

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

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

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

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

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

        # API layer 2
        my $object = $self->l( $param_hr->{object} )
            || $EMPTY_STRING;

        # +------------------------------------------------------------------+
        # | main
        $logger->debug("cmd [$cmd]");

        # collect valid tasks
        my @task_list = $self->rpc_list_functions( { scope => 'all' } );
        my %valid_task = map { $_ => 1 } @task_list;
        $logger->debug( 'param_hr,: ',
            { filter => \&Dumper, value => $param_hr } );

        # answer
        my $answer_hr = {
            header_hr => $HEADER_HREF,
            cmd       => $cmd,
            login     => $login,
            ticket    => $ticket,
            status    => 'FALSE',
            msg       => $EMPTY_STRING,
            type      => 'href',
            cmdres_r  => {},
            ltarget   => 'NULL',
        };

        # check if the task is valid, if not return FALSE
        if ( not $valid_task{$cmd} ) {
            my $msg = "Not a valid task $cmd.";
            $answer_hr->{msg} = $cmd;

            $logger->debug($cmd);

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

        # you have to be logged in only for non test tasks
        if ( not $cmd eq 'cipux_task_sum' ) {

            # check the ticket
            my $bad_hr = $self->is_ticket_bad(
                {
                    login     => $login,
                    ticket    => $ticket,
                    answer_hr => $answer_hr
                }
            );

            if ( $bad_hr->{result} ) {
                $logger->debug('bad result');

                # +----------------------------------------------------------+
                # | API
                return $bad_hr->{answer_hr};
            }

            $logger->debug("create new ticket for $login");

        }

        if ( $cmd eq 'cipux_task_change_own_password_interactive' ) {

            my $password
                = ( exists $param_hr->{userPassword} )
                ? $param_hr->{userPassword}
                : ( exists $param_hr->{value} ) ? $param_hr->{value}
                :                                 $self->random_password();

            $param_hr = {
                object       => $login,
                userPassword => $password,
            };

        }
        else {

            # do work
            foreach my $attr ( sort keys %{$param_hr} ) {
                if ( ref $param_hr->{$attr} ne 'ARRAY' ) {
                    $param_hr->{$attr} = [ $param_hr->{$attr} ];
                }
            }

        }

        my $cipux_task = CipUX::Task->new( { cache_dir => $cache_dir } );
        my $return_r = $cipux_task->task(
            {
                script  => $SCRIPT,
                task    => $cmd,
                mode    => 'rpc',
                object  => $object,
                attr_hr => $param_hr,
            }
        );

        # main
        $answer_hr->{login}  = $login;
        $answer_hr->{ticket} = $ticket;
        if ( $return_r->{status} eq 'OK' ) {
            $answer_hr->{status}   = 'TRUE';
            $answer_hr->{type}     = ref $return_r->{taskres_r};
            $answer_hr->{cmdres_r} = $return_r->{taskres_r};
            $answer_hr->{ltarget}  = $return_r->{ltarget};
        }

        if ( ref $answer_hr eq 'HASH' ) {
            $logger->debug('got a answer_hr hash.');
            $logger->debug( 'storage answer_hr ',
                { filter => \&Dumper, value => $answer_hr } );
        }
        else {
            $logger->debug('got something else (not a hash) as answer_hr');
        }

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

    } ## end sub rpc_task

    # +----------------------------------------------------------------------+
    # |  rpc_info                                                            |
    # +----------------------------------------------------------------------+
    sub rpc_info : PRIVATE {

        #        $arg_r => {
        #           'param_hr' => {
        #                        'source' => 'cipadmin',
        #                        'destination' => 'index.cgi',
        #                        'rbac' => 'access',
        #                        'ticket' => 'test',
        #                        'login' => 'cipadmin'
        #                      },
        #          'cmd' => 'cipux_rbac',
        #                    'header_hr' => {
        #                         'cipux_version' => '3.4.0.0',
        #                         'client_key' => '',
        #                         'gmt_time' => '1222543779',
        #                         'client_cred' => '',
        #                         'client_name' => 'cipux_cat_web',
        #                         'client_version' => '3.4.0.0',
        #                         'rpc_version' => '2.0'
        #                       },
        #          'ticket' => 'dummy',
        #          'login' => 'dummy'
        #   }

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

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

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

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

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

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

        $logger->debug("> login:     $login");
        $logger->debug( 'ticket: ', $ticket );
        $logger->debug('> header_hr: (not printed)');
        $logger->debug( '> param_hr',
            { filter => \&Dumper, value => $param_hr } );

        # check_access_task()
        # check_access_task_survey()

        # valid_cat_module_for_user(user, cat_module_list)
        # evaluate_access(cat_module_list) # nicht?  (user, cat_module_list)
        # check_access_to_task(task)              # nicht? (user,task)
        # check_access_to_cat_module(cat_module)  #(user,cat_module)
        # check_access_to_rpc_intern()            # (user)

        my $subcmd
            = ( exists $param_hr->{subcmd} )
            ? $param_hr->{subcmd}
            : $EMPTY_STRING;
        $logger->debug("subcmd [$subcmd]");

        my $cmdres_r = {};

        # rpc_info   | rpc_intern
        my $rpcmode
            = ( exists $param_hr->{rpcmode} )
            ? $param_hr->{rpcmode}
            : $EMPTY_STRING;
        $logger->debug("rpcmode [$rpcmode]");

        # task   | rpc_intern | cat_module
        my $entity
            = ( exists $param_hr->{entity} )
            ? $param_hr->{entity}
            : $EMPTY_STRING;
        $logger->debug("entity [$entity]");

        # single | manifold
        my $scope
            = ( exists $param_hr->{scope} )
            ? $param_hr->{scope}
            : $EMPTY_STRING;
        $logger->debug("scope [$scope]");

        my $status = 'FALSE';

        # -------------------- check_access_to_task ------------------
        if (   $subcmd eq 'task_access'
            or $subcmd eq 'task_access_survey' )
        {
            $cmdres_r = $self->evaluate_access(
                {
                    realm    => 'task',
                    login    => $login,
                    param_hr => $param_hr
                }
            );
            $status = 'TRUE';
        }

        # -------------------- check_access_to_cat_module ------------
        if (   $subcmd eq 'cat_module_access'
            or $subcmd eq 'cat_module_access_survey' )
        {
            $cmdres_r = $self->evaluate_access(
                {
                    realm    => 'cat_module',
                    login    => $login,
                    param_hr => $param_hr
                }
            );
            $status = 'TRUE';
        }

        # -------------------- check_access_to_rpc_intern ------------
        if (   $subcmd eq 'rpc_intern_access'
            or $subcmd eq 'rpc_intern_access_survey' )
        {
            $cmdres_r = $self->evaluate_access(
                {
                    realm    => 'rpc_intern',
                    login    => $login,
                    param_hr => $param_hr
                }
            );
            $status = 'TRUE';
        }

        # answer
        my $answer_hr = {
            header_hr => $HEADER_HREF,
            cmd       => 'rpc_info',
            login     => $login,
            ticket    => $ticket,
            status    => $status,
            msg       => $EMPTY_STRING,
            type      => 'href',
            cmdres_r  => $cmdres_r,
            ltarget   => 'NULL',
        };

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

    }

    # +----------------------------------------------------------------------+
    # |  rpc_intern                                                          |
    # +----------------------------------------------------------------------+
    sub rpc_intern : PRIVATE {

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

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

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

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

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

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

        $logger->debug("> login:     $login");
        $logger->debug( '> ticket: ', $ticket );
        $logger->debug('> header_hr: (not printed)');
        $logger->debug( '> param_hr',
            { filter => \&Dumper, value => $param_hr } );

        my $status = 'FALSE';

        my $subcmd
            = ( exists $param_hr->{subcmd} )
            ? $self->l( $param_hr->{subcmd} )
            : $EMPTY_STRING;

        $logger->debug("subcmd [$subcmd]");

        my $cmdres_r = {};

        if ( $subcmd eq 'flush' ) {
            $cmdres_r = { refresh => 1, };
            $status = 'TRUE';
            $logger->debug('flush cache triggered');

            #$self->rbac_graph_cache( { force => 1 } );
            $rbac->flush();
            $status = 'TRUE';

        }
        if ( $subcmd eq 'cat_module_cache_size' ) {
            $logger->debug('cat_module_cache_size triggered');
            my $size = $rbac->cat_module_cache_size();
            $logger->debug("cat_module cache size [$size]");
            $cmdres_r = { cat_module_cache_size => $size, };
            $status = 'TRUE';
        }
        if ( $subcmd eq 'rpc_intern_cache_size' ) {
            $logger->debug('rpc_intern_cache_size triggered');
            my $size = $rbac->rpc_intern_cache_size();
            $logger->debug("rpc_intern cache size [$size]");
            $cmdres_r = { rpc_intern_cache_size => $size, };
            $status = 'TRUE';
        }
        if ( $subcmd eq 'task_cache_size' ) {
            $logger->debug('task_cache_size triggered');
            my $size = $rbac->task_cache_size();
            $logger->debug("task cache size [$size]");
            $cmdres_r = { task_cache_size => $size, };
            $status = 'TRUE';
        }

        # ----------------- evaluate_access for task ---------------
        if (   $subcmd eq 'user_task_access'
            or $subcmd eq 'user_task_access_survey' )
        {

            $cmdres_r = $self->evaluate_access(
                {
                    realm    => 'task',
                    login    => $login,
                    param_hr => $param_hr
                }
            );
            $status = 'TRUE';

        }

        # ----------------- evaluate_access for cat_module ---------
        if (   $subcmd eq 'user_cat_module_access'
            or $subcmd eq 'user_cat_module_access_survey' )
        {

            $cmdres_r = $self->evaluate_access(
                {
                    realm    => 'cat_module',
                    login    => $login,
                    param_hr => $param_hr
                }
            );
            $status = 'TRUE';

        }

        # ----------------- evaluate_access for rpc_intern ---------
        if (   $subcmd eq 'user_rpc_intern_access'
            or $subcmd eq 'user_rpc_intern_access_survey' )
        {

            $cmdres_r = $self->evaluate_access(
                {
                    realm    => 'rpc_intern',
                    login    => $login,
                    param_hr => $param_hr
                }
            );
            $status = 'TRUE';

        }

        # answer
        my $answer_hr = {
            header_hr => $HEADER_HREF,
            cmd       => 'rpc_intern',
            login     => $login,
            ticket    => $ticket,
            status    => $status,
            msg       => $EMPTY_STRING,
            type      => 'href',
            cmdres_r  => $cmdres_r,
            ltarget   => 'NULL',
        };

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

}    # END INSIDE-OUT CLASS

1;

__END__

=pod

=for stopwords RPC CipUX rpc Destructor login subcmd syslog logout ttl TTL RBAC uid TODO cipux ini webpage Kuelker log2syslog cipux-rpc.ini CipUX::RPC::Server XML-RPC

=head1 NAME

CipUX::RPC::Server - RPC server class for CipUX

=head1 VERSION

version 3.4.0.9

=head1 SYNOPSIS

  use CipUX::RPC::Server;

=head1 DESCRIPTION

Provides the functions for CipUX RPC server.

=head1 ABSTRACT

The CipUX rpc server is a generic abstract class, which can be used by other
classes or scripts.

=head1 SUBROUTINES/METHODS

The following functions are implemented or supported by CipUX::RPC::Server.

=head2 BUILD

Constructor, see new.

=head2 DEMOLISH

Destructor.

=head2 new

Constructor

B<Syntax:>

  my $cipux_rpc = CipUX::RPC::Server->new();


=head2 check_authentication

Check weather the login has access or not.

=head2 is_ticket_bad

Return 1 if a ticket is OK otherwise 0;

=head2 signal_handler

Install signal_handler alias time to die.

B<Syntax:>

 $server->signal_handler({});

=head2 answer_requests

Answer Requests.

B<Syntax:>

 $server->answer_requests({
     port=>8000,
     address=>'localhost',
     reuse=>0,
     proto=>'tcp',
     meth_hr=>TODO
     task_hr=>TODO
 });

=head2 check_access_to_task

Check the access for login to a task.


=head2 check_access_to_rpc_intern

Check the access for login to the rpc_intern section.

=head2 check_access_to_cat_module

Check the access for login to a CAT module.

=head2 error

Construct an error message.

=head2 evaluate_access

Evaluate the access to login or a given user depending on the sub command
(subcmd) of rpc_info or rpc_intern for one or more realms. Known realms are:
task, cat_module, rpc_intern.

=head2 update_task

Check and update tasks entries.

=head2 update_cat_module

Check and update CAT modules entries.

=head2 log2syslog

Log a given message to syslog.

=head2 get_config

Return the value for a given configuration variable.

=head2 rpc_list_functions

List the rpc functions.

=head2 rpc_start

Start the RPC server.

B<Syntax:>

 $server->rpc_start({});


=head2 ping

The function 'ping' is for testing the connection. It requires not to log in
and no arguments. It returns 'OK'.

=head2 version

Return the CipUX version.

=head2 sum

The function 'sum' is for testing the connection. It requires not to log in and
2 arguments. It returns the sum of the arguments as a hash reference with a
single line.

=head2 login

Perform a login.

=head2 logout

Perform a logout.

=head2 session

Check the ticket and if it is valid update and return a new ticket.

=head2 ttl

Return the Time To Live. Default 900 seconds.

=head2 rpc_task

Execute a CipUX::Task.

=head2 rpc_info

Execute a rpc_info sub-command.

=head3 task_access

Needs parameter: TASK

=head3 task_access_survey

Needs parameter: TASK [TASK] ...

=head3 cat_module_access

Needs parameter: MODULE

=head3 cat_module_access_survey

Needs parameter: MODULE [MODULE] ...

=head3 rpc_intern_access

Needs parameter: COMMAND

=head3 rpc_intern_access_survey

Needs parameter: COMMAND [COMMAND] ...

=head2 rpc_intern

Execute a rpc_intern sub-command.

=head3 ttl

Prints current TTL in seconds

=head3 cat_module_cache_size

Prints current cat module cache size

=head3 rpc_intern_cache_size

Prints current rpc intern cache size

=head3 task_cache_size

Prints current task_cache_size of cache

=head3 user_task_access

Needs parameter: USER TASK

=head3 user_task_access_survey

Needs parameter: $USER TASK [TASK] ...

=head3 user_cat_module_access

Needs parameter: USER MODULE

=head3 user_cat_module_access_survey

Needs parameter: USER MODULE [MODULE] ...

=head3 user_rpc_intern_access

Needs parameter: USER COMMAND

=head3 user_rpc_intern_access_survey

Needs parameter: USER COMMAND [COMMAND] ...

=head3 flush_cache

Flush RPC server RBAC cache


=head1 Public XML-RPC functions.

All the following CipUX::Task methods are public. Public means that they could
be executed remotely. Public means not that everybody can do this remotely.

There are two kinds of public functions:

(1) Functions without authorization

 - login
 - ping
 - sum

(2) Every other function is available only after using 'login' function, with a
uid as first parameter and a valid ticket as second parameter.

Examples (pseudo code):

 - (reference to user list) = cipux_task_list_users( uid, ticket );
 - (true|false) = logout( uid, ticket );
 - (new ticket|false) = session( uid, ticket );

If the uid do not match, or the uid has not the authorization to use the
function, or the group of the uid has not the authorization to use the
function, or the ticket is expired, or the ticket is not valid the request will
not be fulfilled.

In other words: if the uid match and has the right and the role also has the
right and the ticket is valid and is not expired, the request will be executed.

To see real examples have a look at CipUX::RPC::Client client.

=head1 DIAGNOSTICS

TODO

=head1 CONFIGURATION AND ENVIRONMENT

Need no environment variables. But do need a configuration file. For example
cipux-rpc.ini

=head1 DEPENDENCIES

 Authen::Simple::PAM
 Authen::Simple::Password
 Carp
 CipUX::Task
 CipUX::RBAC::Simple
 Class::Std
 Data::Dumper
 English
 Frontier::Daemon
 Frontier::RPC2
 List::MoreUtils
 Log::Log4perl
 Log::Dispatch
 POSIX
 Readonly
 Ticket::Simple

=head1 INCOMPATIBILITIES

Not known.

=head1 BUGS AND LIMITATIONS

Not known.

=head1 SEE ALSO

See the CipUX webpage 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 - 2010 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