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
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
|
# vim: set et ts=4 sw=4:
package AdminPanel::Module::Users;
#============================================================= -*-perl-*-
=head1 NAME
AdminPanel::Module::Users - This module aims to manage service
with GUI
=head1 SYNOPSIS
my $userManager = AdminPanel::Module::Users->new();
$userManager->start();
=head1 DESCRIPTION
This module is a tool to manage users on the system.
From the original code adduserdrake and userdrake.
=head1 SUPPORT
You can find documentation for this module with the perldoc command:
perldoc AdminPanel::Module::Users
=head1 SEE ALSO
AdminPanel::Module
=head1 AUTHOR
Angelo Naselli <anaselli@linux.it>
=head1 COPYRIGHT and LICENSE
Copyright (C) 2013, Angelo Naselli.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2, as
published by the Free Software Foundation.
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
=head1 VERSION
Version 1.0.0
=cut
our $VERSION = '1.0.0';
###############################################
##
## graphic related routines for managing user
##
###############################################
use strict;
use POSIX qw(ceil);
use Config::Auto;
use File::ShareDir ':ALL';
## USER is from userdrake
use USER;
use utf8;
use Sys::Syslog;
use Glib;
use yui;
use AdminPanel::Shared::GUI;
use AdminPanel::Shared::Locales;
use AdminPanel::Shared::Users;
use Moose;
extends qw( AdminPanel::Module );
has '+icon' => (
default => "/usr/share/icons/userdrake.png",
);
# main dialog
has 'dialog' => (
is => 'rw',
init_arg => undef,
);
has 'widgets' => (
traits => ['Hash'],
default => sub { {} },
is => 'rw',
isa => 'HashRef',
handles => {
set_widget => 'set',
get_widget => 'get',
widget_pairs => 'kv',
},
init_arg => undef,
);
has 'action_menu' => (
traits => ['Hash'],
default => sub { {} },
is => 'rw',
isa => 'HashRef',
handles => {
set_action_menu => 'set',
get_action_menu => 'get',
action_menu_pairs => 'kv',
},
init_arg => undef,
);
## Used by USER (for getting values? TODO need explanations, where?)
has 'USER_GetValue' => (
default => -65533,
is => 'ro',
isa => 'Int',
init_arg => undef,
);
## Used by USER (for getting values? TODO need explanations, where?)
has 'ctx' => (
default => sub {USER::ADMIN->new},
is => 'ro',
init_arg => undef,
);
has 'edit_tab_widgets' => (
traits => ['Hash'],
default => sub { {} },
is => 'rw',
isa => 'HashRef',
handles => {
set_edit_tab_widget => 'set',
get_edit_tab_widget => 'get',
edit_tab_pairs => 'kv',
},
init_arg => undef,
);
has 'sh_users' => (
is => 'rw',
init_arg => undef,
builder => '_SharedUsersInitialize'
);
sub _SharedUsersInitialize {
my $self = shift();
$self->sh_users(AdminPanel::Shared::Users->new() );
}
has 'sh_gui' => (
is => 'rw',
init_arg => undef,
builder => '_SharedUGUIInitialize'
);
sub _SharedUGUIInitialize {
my $self = shift();
$self->sh_gui(AdminPanel::Shared::GUI->new() );
}
has 'loc' => (
is => 'rw',
init_arg => undef,
builder => '_localeInitialize'
);
sub _localeInitialize {
my $self = shift();
# TODO fix domain binding for translation
$self->loc(AdminPanel::Shared::Locales->new(domain_name => 'userdrake') );
# TODO if we want to give the opportunity to test locally add dir_name => 'path'
}
#=============================================================
=head1 METHODS
=cut
=head2 new - additional parameters
=head3 config_file
optional parameter to set the configuration file name
=cut
has 'config_file' => (
is => 'rw',
isa => 'Str',
default => '/etc/sysconfig/adminuser',
);
#=============================================================
=head2 start
=head3 INPUT
$self: this object
=head3 DESCRIPTION
This method extends Module::start and is invoked to
start adminService
=cut
#=============================================================
sub start {
my $self = shift;
$self->_manageUsersDialog();
};
# TODO move to Shared?
sub _labeledFrameBox {
my ($parent, $label) = @_;
my $factory = yui::YUI::widgetFactory;
my $frame = $factory->createFrame($parent, $label);
$frame->setWeight( $yui::YD_HORIZ, 1);
$frame->setWeight( $yui::YD_VERT, 2);
$frame = $factory->createHVCenter( $frame );
$frame = $factory->createVBox( $frame );
return $frame;
}
# usefull local variable to avoid duplicating
# translation point for user edit labels
my %userEditLabel;
# usefull local variable to avoid duplicating
# translation point for group edit labels
my %groupEditLabel;
#=============================================================
=head2 BUILD
=head3 INPUT
$self: this object
=head3 DESCRIPTION
The BUILD method is called after a Moose object is created,
Into this method additional data are initialized.
=cut
#=============================================================
sub BUILD {
my $self = shift;
if (! $self->name) {
$self->name ($self->loc->N("Log viewer"));
}
%userEditLabel = (
user_data => $self->loc->N("User Data"),
account_info => $self->loc->N("Account Info"),
password_info => $self->loc->N("Password Info"),
groups => $self->loc->N("Groups"),
);
%groupEditLabel = (
group_data => $self->loc->N("Group Data"),
group_users => $self->loc->N("Group Users"),
);
}
#=============================================================
=head2 ChooseGroup
=head3 INPUT
$self: this object
=head3 OUTPUT
$choice: 0 or 1 (choice)
-1 cancel or exit
=head3 DESCRIPTION
creates a popup dialog to ask if adding user to an existing
group or to the 'users' group
=cut
#=============================================================
sub ChooseGroup {
my $self = shift;
my $choice = -1;
## push application title
my $appTitle = yui::YUI::app()->applicationTitle();
## set new title to get it in dialog
yui::YUI::app()->setApplicationTitle($self->loc->N("Choose group"));
my $factory = yui::YUI::widgetFactory;
my $dlg = $factory->createPopupDialog();
my $layout = $factory->createVBox($dlg);
my $frame = _labeledFrameBox($layout, $self->loc->N("A group with this name already exists. What would you like to do?"));
my $rbg = $factory->createRadioButtonGroup( $frame );
$frame = $factory->createVBox( $rbg );
my $align = $factory->createLeft($frame);
my $rb1 = $factory->createRadioButton( $align, $self->loc->N("Add to the existing group"), 1);
$rb1->setNotify(1);
$rbg->addRadioButton( $rb1 );
$align = $factory->createLeft($frame);
my $rb2 = $factory->createRadioButton( $align, $self->loc->N("Add to the 'users' group"), 0);
$rb2->setNotify(1);
$rbg->addRadioButton( $rb2 );
my $hbox = $factory->createHBox($layout);
$align = $factory->createRight($hbox);
my $cancelButton = $factory->createPushButton($align, $self->loc->N("Cancel"));
my $okButton = $factory->createPushButton($hbox, $self->loc->N("Ok"));
while(1) {
my $event = $dlg->waitForEvent();
my $eventType = $event->eventType();
#event type checking
if ($eventType == $yui::YEvent::CancelEvent) {
last;
}
elsif ($eventType == $yui::YEvent::WidgetEvent) {
# widget selected
my $widget = $event->widget();
if ($widget == $cancelButton) {
last;
}
if ($widget == $okButton) {
$choice = $rb1->value() ? 0 : 1 ;
last;
}
}
}
destroy $dlg;
#restore old application title
yui::YUI::app()->setApplicationTitle($appTitle);
return $choice;
}
#=============================================================
=head2 _updateOrDelUsersInGroup
=head3 INPUT
$name: username
=head3 DESCRIPTION
Fixes user deletion into groups.
=cut
#=============================================================
sub _updateOrDelUserInGroup {
my ($self, $name) = @_;
my $groups = $self->ctx->GroupsEnumerateFull;
foreach my $g (@$groups) {
my $members = $g->MemberName(1, 0);
if ($self->_inArray($name, $members)) {
eval { $g->MemberName($name, 2) };
eval { $self->ctx->GroupModify($g) };
}
}
}
#=============================================================
=head2 _deleteGroupDialog
=head3 INPUT
$self: this object
=head3 DESCRIPTION
This method open a dialog to delete the selected group.
=cut
#=============================================================
sub _deleteGroupDialog {
my $self = shift;
my $item = $self->get_widget('table')->selectedItem();
if (! $item) {
return;
}
my $groupname = $item->label();
## push application title
my $appTitle = yui::YUI::app()->applicationTitle();
## set new title to get it in dialog
yui::YUI::app()->setApplicationTitle($self->loc->N("Warning"));
my $factory = yui::YUI::widgetFactory;
my $dlg = $factory->createPopupDialog();
my $layout = $factory->createVBox($dlg);
my $align = $factory->createLeft($layout);
$factory->createLabel($align, $self->loc->N("Do you really want to delete the group %s?",
$groupname));
$align = $factory->createRight($layout);
my $hbox = $factory->createHBox($align);
my $cancelButton = $factory->createPushButton($hbox, $self->loc->N("Cancel"));
my $deleteButton = $factory->createPushButton($hbox, $self->loc->N("Delete"));
while(1) {
my $event = $dlg->waitForEvent();
my $eventType = $event->eventType();
#event type checking
if ($eventType == $yui::YEvent::CancelEvent) {
last;
}
elsif ($eventType == $yui::YEvent::WidgetEvent) {
# widget selected
my $widget = $event->widget();
if ($widget == $cancelButton) {
last;
}
elsif ($widget == $deleteButton) {
my $groupEnt = $self->ctx->LookupGroupByName($groupname);
my $members = $self->ctx->EnumerateUsersByGroup($groupname);
my $continue = 1;
GLOOP: foreach my $username (@$members) {
my $userEnt = $self->ctx->LookupUserByName($username);
if ($userEnt && $userEnt->Gid($self->USER_GetValue) == $groupEnt->Gid($self->USER_GetValue)) {
$self->sh_gui->msgBox({text => $self->loc->N("%s is a primary group for user %s\n Remove the user first",
$groupname, $username)});
$continue = 0;
last GLOOP;
}
}
if ($continue) {
Sys::Syslog::syslog('info|local1', $self->loc->N("Removing group: %s", $groupname));
eval { $self->ctx->GroupDel($groupEnt) };
$self->_refresh();
}
last;
}
}
}
destroy $dlg;
#restore old application title
yui::YUI::app()->setApplicationTitle($appTitle);
}
#=============================================================
=head2 _deleteUserDialog
=head3 INPUT
$self: this object
=head3 DESCRIPTION
This method open a dialog to delete the selected user.
It also asks for additional information to be removed.
=cut
#=============================================================
sub _deleteUserDialog {
my $self = shift;
my $item = $self->get_widget('table')->selectedItem();
if (! $item) {
return;
}
my $username = $item->label();
my $userEnt = $self->ctx->LookupUserByName($username);
my $homedir = $userEnt->HomeDir($self->USER_GetValue);
## push application title
my $appTitle = yui::YUI::app()->applicationTitle();
## set new title to get it in dialog
yui::YUI::app()->setApplicationTitle($self->loc->N("Delete files or not?"));
my $factory = yui::YUI::widgetFactory;
my $dlg = $factory->createPopupDialog();
my $layout = $factory->createVBox($dlg);
my $align = $factory->createLeft($layout);
$factory->createLabel($align, $self->loc->N("Deleting user %s\nAlso perform the following actions\n",
$username));
$align = $factory->createLeft($layout);
my $checkhome = $factory->createCheckBox($align, $self->loc->N("Delete Home Directory: %s", $homedir), 0);
$align = $factory->createLeft($layout);
my $checkspool = $factory->createCheckBox($align, $self->loc->N("Delete Mailbox: /var/spool/mail/%s",
$username), 0);
$align = $factory->createRight($layout);
my $hbox = $factory->createHBox($align);
my $cancelButton = $factory->createPushButton($hbox, $self->loc->N("Cancel"));
my $deleteButton = $factory->createPushButton($hbox, $self->loc->N("Delete"));
if ($homedir !~ m!(?:/home|/var/spool)!) {
$checkhome->setDisabled();
$checkspool->setDisabled();
}
while(1) {
my $event = $dlg->waitForEvent();
my $eventType = $event->eventType();
#event type checking
if ($eventType == $yui::YEvent::CancelEvent) {
last;
}
elsif ($eventType == $yui::YEvent::WidgetEvent) {
# widget selected
my $widget = $event->widget();
if ($widget == $cancelButton) {
last;
}
elsif ($widget == $deleteButton) {
Sys::Syslog::syslog('info|local1', $self->loc->N("Removing user: %s", $username));
$self->ctx->UserDel($userEnt);
$self->_updateOrDelUserInGroup($username);
#Let's check out the user's primary group
my $usergid = $userEnt->Gid($self->USER_GetValue);
my $groupEnt = $self->ctx->LookupGroupById($usergid);
if ($groupEnt) {
my $member = $groupEnt->MemberName(1, 0);
if (scalar(@$member) == 0 && $groupEnt->Gid($self->USER_GetValue) > 499) {
$self->ctx->GroupDel($groupEnt);
}
}
if ($checkhome->isChecked()) {
eval { $self->ctx->CleanHome($userEnt) };
$@ and $self->sh_gui->msgBox({text => $@}) and last;
}
if ($checkspool->isChecked()) {
eval { $self->ctx->CleanSpool($userEnt) };
$@ and $self->sh_gui->msgBox({text => $@}) and last;
}
$self->_refresh();
last;
}
}
}
destroy $dlg;
#restore old application title
yui::YUI::app()->setApplicationTitle($appTitle);
}
sub _addGroupDialog {
my $self = shift;
my $is_system = 0;
## push application title
my $appTitle = yui::YUI::app()->applicationTitle();
## set new title to get it in dialog
yui::YUI::app()->setApplicationTitle($self->loc->N("Create New Group"));
my $factory = yui::YUI::widgetFactory;
my $optional = yui::YUI::optionalWidgetFactory;
my $dlg = $factory->createPopupDialog();
my $layout = $factory->createVBox($dlg);
## 'group name'
my $align = $factory->createRight($layout);
my $hbox = $factory->createHBox($align);
my $label = $factory->createLabel($hbox, $self->loc->N("Group Name:") );
my $groupName = $factory->createInputField($hbox, "", 0);
$label->setWeight($yui::YD_HORIZ, 1);
$groupName->setWeight($yui::YD_HORIZ, 2);
$factory->createVSpacing($layout, 1);
# Specify group id manually
$align = $factory->createLeft($layout);
$hbox = $factory->createHBox($align);
my $gidManually = $factory->createCheckBox($hbox, $self->loc->N("Specify group ID manually"), 0);
$factory->createHSpacing($hbox, 2);
my $GID = $factory->createIntField($hbox, $self->loc->N("GID"), 1, 65000, 500);
$GID->setEnabled($gidManually->value());
$gidManually->setNotify(1);
$hbox = $factory->createHBox($layout);
$align = $factory->createRight($hbox);
my $cancelButton = $factory->createPushButton($align, $self->loc->N("Cancel"));
my $okButton = $factory->createPushButton($hbox, $self->loc->N("Ok"));
while(1) {
my $event = $dlg->waitForEvent();
my $eventType = $event->eventType();
#event type checking
if ($eventType == $yui::YEvent::CancelEvent) {
last;
}
elsif ($eventType == $yui::YEvent::WidgetEvent) {
# widget selected
my $widget = $event->widget();
if ($widget == $cancelButton) {
last;
}
elsif ($widget == $gidManually) {
# GID inserction enabled?
$GID->setEnabled($gidManually->value());
}
elsif ($widget == $okButton) {
## check data
my $groupname = $groupName->value();
my ($continue, $errorString) = $self->sh_users->valid_groupname($groupname);
my $nm = $continue && $self->ctx->LookupGroupByName($groupname);
if ($nm) {
$groupName->setValue("");
$errorString = $self->loc->N("Group already exists, please choose another Group Name");
$continue = 0;
}
my $groupEnt = $self->ctx->InitGroup($groupname, $is_system);
my $gid = 0;
if ($continue && $gidManually->value()) {
if (($gid = $GID->value()) < 500) {
$errorString = "";
my $gidchoice = $self->sh_gui->ask_YesOrNo({ title => $self->loc->N(" Group Gid is < 500"),
text => $self->loc->N("Creating a group with a GID less than 500 is not recommended.\n Are you sure you want to do this?\n\n")});
$continue = $gidchoice and $groupEnt->Gid($gid);
} else {
my $g = $self->ctx->LookupGroupById($gid);
if ($g) {
$errorString = "";
my $gidchoice = $self->sh_gui->ask_YesOrNo({title => $self->loc->N(" Group ID is already used "),
text => $self->loc->N("Creating a group with a non unique GID?\n\n")});
$continue = $gidchoice and $groupEnt->Gid($gid);
}
else {
$groupEnt and $groupEnt->Gid($gid);
}
}
}
if (!$continue) {
#--- raise error
$self->sh_gui->msgBox({text => $errorString}) if ($errorString);
}
else {
Sys::Syslog::syslog('info|local1', $self->loc->N("Adding group: %s ", $groupname));
$self->ctx->GroupAdd($groupEnt);
$self->_refresh();
last;
}
}
}
}
destroy $dlg;
#restore old application title
yui::YUI::app()->setApplicationTitle($appTitle);
}
#=============================================================
=head2 _buildUserData
=head3 INPUT
$self: this object
$layout : layout in wich drawing graphic user data
=head3 OUTPUT
%userData: hash containing reference to graphical object
such as:
full_name, login_name, password, password1,
login_shell
full_name, login_name, password, password1,
weakness (icon), login_shell
=head3 DESCRIPTION
This method is used by addUserDialog and _editUserDialog
to create User Data dialog
=cut
#=============================================================
sub _buildUserData {
my ($self, $layout, $selected_shell) = @_;
my @shells = @{$self->ctx->GetUserShells};
my $factory = yui::YUI::widgetFactory;
## user 'full name'
my $align = $factory->createRight($layout);
my $hbox = $factory->createHBox($align);
my $label = $factory->createLabel($hbox, $self->loc->N("Full Name:") );
$factory->createHSpacing($hbox, 2.0);
my $fullName = $factory->createInputField($hbox, "", 0);
$label->setWeight($yui::YD_HORIZ, 1);
$fullName->setWeight($yui::YD_HORIZ, 2);
## user 'login name'
$align = $factory->createRight($layout);
$hbox = $factory->createHBox($align);
$label = $factory->createLabel($hbox, $self->loc->N("Login:") );
$factory->createHSpacing($hbox, 2.0);
my $loginName = $factory->createInputField($hbox, "", 0);
$label->setWeight($yui::YD_HORIZ, 1);
$loginName->setWeight($yui::YD_HORIZ, 2);
$loginName->setNotify(1);
## user 'Password'
$align = $factory->createRight($layout);
$hbox = $factory->createHBox($align);
$label = $factory->createLabel($hbox, $self->loc->N("Password:") );
my $weakness = undef;
if (yui::YUI::app()->hasImageSupport()) {
$factory->createHSpacing($hbox, 2.0);
my $file = dist_file('AdminPanel', 'images/Blank16x16.png');
$weakness = $factory->createImage($hbox, $file);
}
else {
$factory->createHSpacing($hbox, 1.0);
$weakness = $factory->createLabel($hbox, " ");
$factory->createHSpacing($hbox, 1.0);
}
my $password = $factory->createInputField($hbox, "", 1);
$weakness->setWeight($yui::YD_HORIZ, 1);
$label->setWeight($yui::YD_HORIZ, 1);
$password->setWeight($yui::YD_HORIZ, 4);
# notify input to check weakness
$password->setNotify(1);
## user 'confirm Password'
$align = $factory->createRight($layout);
$hbox = $factory->createHBox($align);
$label = $factory->createLabel($hbox, $self->loc->N("Confirm Password:") );
$factory->createHSpacing($hbox, 2.0);
my $password1 = $factory->createInputField($hbox, "", 1);
$label->setWeight($yui::YD_HORIZ, 1);
$password1->setWeight($yui::YD_HORIZ, 2);
## user 'Login Shell'
$align = $factory->createRight($layout);
$hbox = $factory->createHBox($align);
$label = $factory->createLabel($hbox, $self->loc->N("Login Shell:") );
$factory->createHSpacing($hbox, 2.0);
my $loginShell = $factory->createComboBox($hbox, "", 0);
my $itemColl = new yui::YItemCollection;
foreach my $shell (@shells) {
my $item = new yui::YItem ($shell, 0);
$item->setSelected(1) if ($selected_shell && $selected_shell eq $shell);
$itemColl->push($item);
$item->DISOWN();
}
$loginShell->addItems($itemColl);
$label->setWeight($yui::YD_HORIZ, 1);
$loginShell->setWeight($yui::YD_HORIZ, 2);
my %userData = (
full_name => $fullName,
login_name => $loginName,
password => $password,
password1 => $password1,
weakness => $weakness,
login_shell => $loginShell,
);
return ( %userData );
}
#=============================================================
=head2 addUserDialog
=head3 INPUT
$self: this object
$standalone: if set the application title is set
from the name set in costructor
=head3 DESCRIPTION
This method creates and manages the dialog to add a new
user.
=cut
#=============================================================
sub addUserDialog {
my $self = shift;
my $standalone = shift;
my $dontcreatehomedir = 0;
my $is_system = 0;
## push application title
my $appTitle = yui::YUI::app()->applicationTitle();
## set new title to get it in dialog
if ($standalone) {
yui::YUI::app()->setApplicationTitle($self->name);
}
else {
yui::YUI::app()->setApplicationTitle($self->loc->N("Create New User"));
}
my $factory = yui::YUI::widgetFactory;
my $optional = yui::YUI::optionalWidgetFactory;
my $dlg = $factory->createPopupDialog();
my $layout = $factory->createVBox($dlg);
my %userData = $self->_buildUserData($layout);
##### add a separator
## Create Home directory
my $align = $factory->createLeft($layout);
my $hbox = $factory->createHBox($align);
my $createHome = $factory->createCheckBox($hbox, $self->loc->N("Create Home Directory"), 1);
## Home directory
$align = $factory->createLeft($layout);
$hbox = $factory->createHBox($align);
my $label = $factory->createLabel($hbox, $self->loc->N("Home Directory:") );
$factory->createHSpacing($hbox, 2.0);
my $homeDir = $factory->createInputField($hbox, "", 0);
$label->setWeight($yui::YD_HORIZ, 1);
$homeDir->setWeight($yui::YD_HORIZ, 2);
# Create private group
$align = $factory->createLeft($layout);
$hbox = $factory->createHBox($align);
my $createGroup = $factory->createCheckBox($hbox, $self->loc->N("Create a private group for the user"), 1);
# Specify user id manually
$align = $factory->createRight($layout);
$hbox = $factory->createHBox($align);
my $uidManually = $factory->createCheckBox($hbox, $self->loc->N("Specify user ID manually"), 0);
$factory->createHSpacing($hbox, 2.0);
my $UID = $factory->createIntField($hbox, $self->loc->N("UID"), 1, 65000, 500);
$UID->setEnabled($uidManually->value());
$uidManually->setNotify(1);
# $uidManually->setWeight($yui::YD_HORIZ, 2);
$UID->setWeight($yui::YD_HORIZ, 1);
## user 'icon'
$hbox = $factory->createHBox($layout);
$factory->createLabel($hbox, $self->loc->N("Click on icon to change it") );
my $iconFace = $self->sh_users->GetFaceIcon();
my $icon = $factory->createPushButton($hbox, "");
$icon->setIcon($self->sh_users->face2png($iconFace));
$icon->setLabel($iconFace);
$hbox = $factory->createHBox($layout);
$align = $factory->createRight($hbox);
my $cancelButton = $factory->createPushButton($align, $self->loc->N("Cancel"));
my $okButton = $factory->createPushButton($hbox, $self->loc->N("Ok"));
while(1) {
my $event = $dlg->waitForEvent();
my $eventType = $event->eventType();
#event type checking
if ($eventType == $yui::YEvent::CancelEvent) {
last;
}
elsif ($eventType == $yui::YEvent::WidgetEvent) {
# widget selected
my $widget = $event->widget();
if ($widget == $cancelButton) {
last;
}
elsif ($widget == $icon) {
#remove shortcut from label
my $iconLabel = $self->_skipShortcut($icon->label());
my $nextIcon = $self->sh_users->GetFaceIcon($icon->label(), 1);
$icon->setLabel($nextIcon);
$icon->setIcon($self->sh_users->face2png($nextIcon));
}
elsif ($widget == $uidManually) {
# UID inserction enabled?
$UID->setEnabled($uidManually->value());
}
elsif ($widget == $userData{ login_name }) {
my $username = $userData{ login_name }->value();
$homeDir->setValue("/home/$username");
}
elsif ($widget == $userData{password}) {
my $pass = $userData{ password }->value();
$self->_checkWeaknessPassword($pass, $userData{ weakness });
}
elsif ($widget == $okButton) {
## check data
my $username = $userData{ login_name }->value();
my ($continue, $errorString) = $self->sh_users->valid_username($username);
my $nm = $continue && $self->ctx->LookupUserByName($username);
if ($nm) {
$userData{ login_name }->setValue("");
$homeDir->setValue("");
$errorString = $self->loc->N("User already exists, please choose another User Name");
$continue = 0;
}
my $passwd = $continue && $userData{ password }->value();
if ($continue && $passwd ne $userData{ password1 }->value()) {
$errorString = $self->loc->N("Password Mismatch");
$continue = 0;
}
if ($self->sh_users->weakPasswordForSecurityLevel($passwd)) {
$errorString = $self->loc->N("This password is too simple. \n Good passwords should be > 6 characters");
$continue = 0;
}
my $userEnt = $continue && $self->ctx->InitUser($username, $is_system);
if ($continue && $createHome->value()) {
$dontcreatehomedir = 0;
my $homedir = $homeDir->value();
$userEnt and $userEnt->HomeDir($homedir);
} else {
$dontcreatehomedir = 1;
}
my $uid = 0;
if ($continue && $uidManually->value()) {
if (($uid = $UID->value()) < 500) {
$errorString = "";
my $uidchoice = $self->sh_gui->ask_YesOrNo({title => $self->loc->N("User Uid is < 500"),
text => $self->loc->N("Creating a user with a UID less than 500 is not recommended.\nAre you sure you want to do this?\n\n")});
$continue = $uidchoice and $userEnt->Uid($uid);
} else {
$userEnt and $userEnt->Uid($uid);
}
}
my $gid = 0;
if ($createGroup->value()) {
if ($continue) {
#Check if group exist
my $gr = $self->ctx->LookupGroupByName($username);
if ($gr) {
my $groupchoice = $self->ChooseGroup();
if ($groupchoice == 0 ) {
#You choose to put it in the existing group
$gid = $gr->Gid($self->USER_GetValue);
} elsif ($groupchoice == 1) {
# Put it in 'users' group
Sys::Syslog::syslog('info|local1', $self->loc->N("Putting %s to 'users' group",
$username));
$gid = $self->sh_users->Add2UsersGroup($username, $self->ctx);
}
else {
$errorString = "";
$continue = 0;
}
} else {
#it's a new group: Add it
my $newgroup = $self->ctx->InitGroup($username,$is_system);
Sys::Syslog::syslog('info|local1', $self->loc->N("Creating new group: %s", $username));
$gid = $newgroup->Gid($self->USER_GetValue);
$self->ctx->GroupAdd($newgroup);
}
}
} else {
$continue and $gid = $self->sh_users->Add2UsersGroup($username, $self->ctx);
}
if (!$continue) {
#---rasie error
$self->sh_gui->msgBox({text => $errorString}) if ($errorString);
}
else {
## OK let's create the user
print $self->loc->N("Adding user: ") . $username . " \n";
Sys::Syslog::syslog('info|local1', $self->loc->N("Adding user: %s", $username));
my $loginshell = $userData{ login_shell }->value();
my $fullname = $userData{ full_name }->value();
utf8::decode($fullname);
$userEnt->Gecos($fullname); $userEnt->LoginShell($loginshell);
$userEnt->Gid($gid);
$userEnt->ShadowMin(-1); $userEnt->ShadowMax(99999);
$userEnt->ShadowWarn(-1); $userEnt->ShadowInact(-1);
$self->ctx->UserAdd($userEnt, $is_system, $dontcreatehomedir);
$self->ctx->UserSetPass($userEnt, $passwd);
defined $icon->label() and
$self->sh_users->addKdmIcon($username, $icon->label());
### TODO Migration wizard
#
# Refresh($sysfilter, $stringsearch);
# transfugdrake::get_windows_disk()
# and $in->ask_yesorno($self->loc->N("Migration wizard"),
# $self->loc->N("Do you want to run the migration wizard in order to import Windows documents and settings in your Mageia distribution?"))
# and run_program::raw({ detach => 1 }, 'transfugdrake');
last;
}
}
}
}
destroy $dlg;
#restore old application title
yui::YUI::app()->setApplicationTitle($appTitle) if $appTitle;
}
#=============================================================
=head2 _createUserTable
=head3 INPUT
$self: this object
=head3 DESCRIPTION
This function create the User table to be added to the replace
point of the tab widget. Note this function is meant for internal
use only
=cut
#=============================================================
sub _createUserTable {
my $self = shift;
$self->dialog->startMultipleChanges();
$self->get_widget('replace_pnt')->deleteChildren();
my $parent = $self->get_widget('replace_pnt');
my $factory = yui::YUI::widgetFactory;
my $yTableHeader = new yui::YTableHeader();
$yTableHeader->addColumn($self->loc->N("User Name"), $yui::YAlignBegin);
$yTableHeader->addColumn($self->loc->N("User ID"), $yui::YAlignBegin);
$yTableHeader->addColumn($self->loc->N("Primary Group"), $yui::YAlignBegin);
$yTableHeader->addColumn($self->loc->N("Full Name"), $yui::YAlignBegin);
$yTableHeader->addColumn($self->loc->N("Login Shell"), $yui::YAlignBegin);
$yTableHeader->addColumn($self->loc->N("Home Directory"), $yui::YAlignBegin);
$yTableHeader->addColumn($self->loc->N("Status"), $yui::YAlignBegin);
$yTableHeader->DISOWN();
$self->set_widget(table => $factory->createTable($parent, $yTableHeader));
$self->get_widget('table')->setImmediateMode(1);
$self->get_widget('table')->DISOWN();
$self->get_widget('replace_pnt')->showChild();
$self->dialog->recalcLayout();
$self->dialog->doneMultipleChanges();
$self->_refreshUsers();
}
#=============================================================
=head2 _createGroupTable
=head3 INPUT
$self: this object
=head3 DESCRIPTION
This function create the Group table to be added to the replace
point of the tab widget. Note this function is meant for internal
use only
=cut
#=============================================================
sub _createGroupTable {
my $self = shift;
$self->dialog->startMultipleChanges();
$self->get_widget('replace_pnt')->deleteChildren();
my $parent = $self->get_widget('replace_pnt');
my $factory = yui::YUI::widgetFactory;
my $yTableHeader = new yui::YTableHeader();
$yTableHeader->addColumn($self->loc->N("Group Name"), $yui::YAlignBegin);
$yTableHeader->addColumn($self->loc->N("Group ID"), $yui::YAlignBegin);
$yTableHeader->addColumn($self->loc->N("Group Members"), $yui::YAlignBegin);
$yTableHeader->DISOWN();
$self->set_widget(table => $factory->createTable($parent, $yTableHeader));
$self->get_widget('table')->setImmediateMode(1);
$self->get_widget('table')->DISOWN();
$self->get_widget('replace_pnt')->showChild();
$self->dialog->recalcLayout();
$self->dialog->doneMultipleChanges();
$self->_refreshGroups();
}
#=============================================================
=head2 _computeLockExpire
=head3 INPUT
$l: login user info
=head3 OUTPUT
$status: Locked, Expired, or empty string
=head3 DESCRIPTION
This method returns if the login is Locked, Expired or ok.
Note this function is meant for internal use only
=cut
#=============================================================
sub _computeLockExpire {
my ( $self, $l ) = @_;
my $ep = $l->ShadowExpire($self->USER_GetValue);
my $tm = ceil(time()/(24*60*60));
$ep = -1 if int($tm) <= $ep;
my $status = $self->ctx->IsLocked($l) ? $self->loc->N("Locked") : ($ep != -1 ? $self->loc->N("Expired") : '');
$status;
}
#=============================================================
=head2 _refreshUsers
=head3 INPUT
$self: this object
=head3 DESCRIPTION
This method refresh user info into User tab widget.
Note this function is meant for internal use only
=cut
#=============================================================
sub _refreshUsers {
my $self = shift;
my $strfilt = $self->get_widget('filter')->value();
my $filterusers = $self->get_widget('filter_system')->isChecked();
my ($users, $group, $groupnm, $expr);
defined $self->ctx and $users = $self->ctx->UsersEnumerateFull;
$self->dialog->startMultipleChanges();
#for some reasons QT send an event using table->selectItem()
# WA remove notification immediate
$self->get_widget('table')->setImmediateMode(0);
$self->get_widget('table')->deleteAllItems();
my @UserReal;
LOOP: foreach my $l (@$users) {
next LOOP if $filterusers && $l->Uid($self->USER_GetValue) <= 499 || $l->Uid($self->USER_GetValue) == 65534;
push @UserReal, $l if $l->UserName($self->USER_GetValue) =~ /^\Q$strfilt/;
}
my $i;
my $itemColl = new yui::YItemCollection;
foreach my $l (@UserReal) {
$i++;
my $uid = $l->Uid($self->USER_GetValue);
if (!defined $uid) {
warn "bogus user at line $i\n";
next;
}
my $a = $l->Gid($self->USER_GetValue);
$group = $self->ctx->LookupGroupById($a);
$groupnm = '';
$expr = $self->_computeLockExpire($l);
$group and $groupnm = $group->GroupName($self->USER_GetValue);
my $fulln = $l->Gecos($self->USER_GetValue);
utf8::decode($fulln);
my $username = $l->UserName($self->USER_GetValue);
my $Uid = $l->Uid($self->USER_GetValue);
my $shell = $l->LoginShell($self->USER_GetValue);
my $homedir = $l->HomeDir($self->USER_GetValue);
my $item = new yui::YTableItem ("$username",
"$Uid",
"$groupnm",
"$fulln",
"$shell",
"$homedir",
"$expr");
# TODO workaround to get first cell at least until we don't
# a cast from YItem
$item->setLabel( $username );
$itemColl->push($item);
$item->DISOWN();
}
$self->get_widget('table')->addItems($itemColl);
my $item = $self->get_widget('table')->selectedItem();
$self->get_widget('table')->selectItem($item, 0) if $item;
$self->dialog->recalcLayout();
$self->dialog->doneMultipleChanges();
$self->_refreshActions();
$self->get_widget('table')->setImmediateMode(1);
}
#=============================================================
=head2 _refreshGroups
=head3 INPUT
$self: this object
=head3 DESCRIPTION
This method refresh group info into Group tab widget.
Note this function is meant for internal use only
=cut
#=============================================================
sub _refreshGroups {
my $self = shift;
my $strfilt = $self->get_widget('filter')->value();
my $filtergroups = $self->get_widget('filter_system')->isChecked();
my $groups;
defined $self->ctx and $groups = $self->ctx->GroupsEnumerateFull;
$self->dialog->startMultipleChanges();
#for some reasons QT send an event using table->selectItem()
# WA remove notification immediate
$self->get_widget('table')->setImmediateMode(0);
$self->get_widget('table')->deleteAllItems();
my @GroupReal;
LOOP: foreach my $g (@$groups) {
next LOOP if $filtergroups && $g->Gid($self->USER_GetValue) <= 499 || $g->Gid($self->USER_GetValue) == 65534;
push @GroupReal, $g if $g->GroupName($self->USER_GetValue) =~ /^\Q$strfilt/;
}
my $itemColl = new yui::YItemCollection;
foreach my $g (@GroupReal) {
my $a = $g->GroupName($self->USER_GetValue);
#my $group = $ctx->LookupGroupById($a);
my $u_b_g = $a && $self->ctx->EnumerateUsersByGroup($a);
my $listUbyG = join(',', @$u_b_g);
my $group_id = $g->Gid($self->USER_GetValue);
my $groupname = $g->GroupName($self->USER_GetValue);
my $item = new yui::YTableItem ("$groupname",
"$group_id",
"$listUbyG");
$item->setLabel( $groupname );
$itemColl->push($item);
$item->DISOWN();
}
$self->get_widget('table')->addItems($itemColl);
my $item = $self->get_widget('table')->selectedItem();
$self->get_widget('table')->selectItem($item, 0) if $item;
$self->dialog->recalcLayout();
$self->dialog->doneMultipleChanges();
$self->_refreshActions();
$self->get_widget('table')->setImmediateMode(1);
}
#=============================================================
=head2 _getUserInfo
=head3 INPUT
$self: this object
=head3 OUTPUT
%userData: selected user info as:
username: username
full_name: full name of user
shell: shell used
homedir: home dir path
UID: User identifier
acc_check_exp: account expiration enabling
acc_expy: account expiration year
acc_expm: account expiration month
acc_expd: account expiration day
lockuser: account locked
pwd_check_exp: password expiration enabling
pwd_exp_min: days before changing password
is allowed
pwd_exp_max: days before changing password
is required
pwd_exp_warn: warning days before changing
pwd_exp_inact: days before account becomes
inact
members: Array containing groups the user
belongs to.
primary_group: primary group ID for the user
=head3 DESCRIPTION
Retrieves the selected user info from the system
Note that acc_expy, acc_expm and acc_expd are valid if
acc_check_exp is enabled.
Note that pwd_exp_min, pwd_exp_max, pwd_exp_warn,
pwd_exp_inact are valid if pwd_check_exp is enabled.
=cut
#=============================================================
sub _getUserInfo {
my $self = shift;
my $label = $self->_skipShortcut($self->get_widget('tabs')->selectedItem()->label());
if ($label ne $self->loc->N("Users") ) {
return undef;
}
my $item = $self->get_widget('table')->selectedItem();
if (! $item) {
return undef;
}
my %userData;
$userData{username} = $item->label();
my $userEnt = $self->ctx->LookupUserByName($userData{username});
my $s = $userEnt->Gecos($self->USER_GetValue);
utf8::decode($s);
$userData{full_name} = $s;
$userData{shell} = $userEnt->LoginShell($self->USER_GetValue);
$userData{homedir} = $userEnt->HomeDir($self->USER_GetValue);
$userData{UID} = $userEnt->Uid($self->USER_GetValue);
# default expiration time
my ($day, $mo, $ye) = (localtime())[3, 4, 5];
$userData{acc_expy} = $ye+1900;
$userData{acc_expm} = $mo+1;
$userData{acc_expd} = $day;
$userData{acc_check_exp} = 0;
my $expire = $userEnt->ShadowExpire($self->USER_GetValue);
if ($expire && $expire != -1) {
my $times = _TimeOfArray($expire, 1);
$userData{acc_expy} = $times->{year};
$userData{acc_expm} = $times->{month};
$userData{acc_expd} = $times->{dayint};
$userData{acc_check_exp} = 1;
}
# user password are not retrieved if admin wants
# to change it has to insert a new one
$userData{password} = undef;
$userData{password1} = undef;
# Check if user account is locked
$userData{lockuser} = $self->ctx->IsLocked($userEnt);
$userData{icon_face} = $self->sh_users->GetFaceIcon($userData{username});
$userData{pwd_check_exp} = 0;
$userData{pwd_exp_min} = $userEnt->ShadowMin($self->USER_GetValue);
$userData{pwd_exp_max} = $userEnt->ShadowMax($self->USER_GetValue);
$userData{pwd_exp_warn} = $userEnt->ShadowWarn($self->USER_GetValue);
$userData{pwd_exp_inact} = $userEnt->ShadowInact($self->USER_GetValue);
if ($userData{pwd_exp_min} && $userData{pwd_exp_min} != -1 ||
$userData{pwd_exp_max} && $userData{pwd_exp_max} != 99999 ||
$userData{pwd_exp_warn} && $userData{pwd_exp_warn} != 7 && $userData{pwd_exp_warn} != -1 ||
$userData{pwd_exp_inact} && $userData{pwd_exp_inact} != -1) {
$userData{pwd_check_exp} = 1;
}
$userData{members} = $self->ctx->EnumerateGroupsByUser($userData{username});
$userData{primary_group} = $userEnt->Gid($self->USER_GetValue);
return %userData;
}
#=============================================================
=head2 _getUserInfo
=head3 INPUT
$self: this object
=head3 OUTPUT
%groupData: selected group info as:
$groupname: group name
$members: users that are members of this group
=head3 DESCRIPTION
Retrieves the selected group info from the system
=cut
#=============================================================
sub _getGroupInfo {
my $self = shift;
my $label = $self->_skipShortcut($self->get_widget('tabs')->selectedItem()->label());
if ($label ne $self->loc->N("Groups") ) {
return undef;
}
my $item = $self->get_widget('table')->selectedItem();
if (! $item) {
return undef;
}
my %groupData;
$groupData{start_groupname} = $item->label();
$groupData{groupname} = $item->label();
my $groupEnt = $self->ctx->LookupGroupByName($groupData{groupname});
$groupData{members} = $self->ctx->EnumerateUsersByGroup($groupData{groupname});
return %groupData;
}
sub _storeDataFromGroupEditPreviousTab {
my ($self, %groupData) = @_;
my $previus_tab = $self->get_edit_tab_widget('edit_tab_label');
if (!$previus_tab) {
return %groupData;
}
elsif ($previus_tab eq $groupEditLabel{group_data}) {
$groupData{groupname} = $self->get_edit_tab_widget('groupname')->value();
}
elsif ($previus_tab eq $groupEditLabel{group_users}) {
my $tbl = $self->get_edit_tab_widget('members');
$groupData{members} = undef;
my @members;
my $i;
for($i=0;$i<$tbl->itemsCount();$i++) {
push (@members, $tbl->item($i)->label()) if $tbl->toCBYTableItem($tbl->item($i))->checked();
}
$groupData{members} = [ @members ];
}
return %groupData;
}
sub _storeDataFromUserEditPreviousTab {
my ($self, %userData) = @_;
my $previus_tab = $self->get_edit_tab_widget('edit_tab_label');
if (!$previus_tab) {
return %userData;
}
elsif ($previus_tab eq $userEditLabel{user_data}) {
$userData{full_name} = $self->get_edit_tab_widget('full_name')->value();
$userData{username} = $self->get_edit_tab_widget('login_name')->value() ;
$userData{shell} = $self->get_edit_tab_widget('login_shell')->value();
$userData{homedir} = $self->get_edit_tab_widget('homedir')->value();
my $passwd = $self->get_edit_tab_widget('password')->value();
$userData{password} = $passwd;
$passwd = $self->get_edit_tab_widget('password1')->value();
$userData{password1} = $passwd;
}
elsif ($previus_tab eq $userEditLabel{account_info}) {
$userData{acc_check_exp} = $self->get_edit_tab_widget('acc_check_exp')->value();
$userData{acc_expy} = $self->get_edit_tab_widget('acc_expy')->value();
$userData{acc_expm} = $self->get_edit_tab_widget('acc_expm')->value();
$userData{acc_expd} = $self->get_edit_tab_widget('acc_expd')->value();
$userData{lockuser} = $self->get_edit_tab_widget('lockuser')->value();
$userData{icon_face} = $self->get_edit_tab_widget('icon_face')->label();
}
elsif ($previus_tab eq $userEditLabel{password_info}) {
$userData{pwd_check_exp} = $self->get_edit_tab_widget('pwd_check_exp')->value();
$userData{pwd_exp_min} = $self->get_edit_tab_widget('pwd_exp_min')->value();
$userData{pwd_exp_max} = $self->get_edit_tab_widget('pwd_exp_max')->value();
$userData{pwd_exp_warn} = $self->get_edit_tab_widget('pwd_exp_warn')->value();
$userData{pwd_exp_inact} = $self->get_edit_tab_widget('pwd_exp_inact')->value();
}
elsif ($previus_tab eq $userEditLabel{groups}) {
my $tbl = $self->get_edit_tab_widget('members');
$userData{members} = undef;
my @members;
my $i;
for($i=0;$i<$tbl->itemsCount();$i++) {
push (@members, $tbl->item($i)->label()) if $tbl->toCBYTableItem($tbl->item($i))->checked();
}
$userData{members} = [ @members ];
if ($self->get_edit_tab_widget('primary_group')->selectedItem()) {
my $Gent = $self->ctx->LookupGroupByName($self->get_edit_tab_widget('primary_group')->selectedItem()->label());
my $primgroup = $Gent->Gid($self->USER_GetValue);
$userData{primary_group} = $primgroup;
}
else {
$userData{primary_group} = -1;
}
}
return %userData;
}
#=============================================================
=head2 _userDataTabWidget
=head3 INPUT
$self: this object
$dialog: YUI dialog that owns the YUI replace point
$replace_pnt: YUI replace point, needed to add a new tab
widget
%userData: hash containing user data info, tabs are
removed and added again on selection, so
data must be saved outside of widgets.
$previus_tab: previous tab widget label, needed to store
user data from the old tab before removing
it, if user changed something.
=head3 OUTPUT
%userDataWidget: hash containing new YUI widget objects
such as:
returned onject from _buildUserData and
homedir.
=head3 DESCRIPTION
This internal method removes old tab widget saving its
relevant data into userData and creates new selected table
to be shown.
=cut
#=============================================================
sub _userDataTabWidget {
my ($self, $dialog, $replace_pnt, %userData) = @_;
my $factory = yui::YUI::widgetFactory;
$dialog->startMultipleChanges();
$replace_pnt->deleteChildren();
my $layout = $factory->createVBox($replace_pnt);
my %userDataWidget = $self->_buildUserData($layout, $userData{shell});
## user 'login name'
my $align = $factory->createRight($layout);
my $hbox = $factory->createHBox($align);
my $label = $factory->createLabel($hbox, $self->loc->N("Home:") );
$factory->createHSpacing($hbox, 2.0);
$userDataWidget{homedir} = $factory->createInputField($hbox, "", 0);
$label->setWeight($yui::YD_HORIZ, 1);
$userDataWidget{homedir}->setWeight($yui::YD_HORIZ, 2);
# fill data into widgets
##
# full_name, login_name, password, password1,
# login_shell
$userDataWidget{full_name}->setValue($userData{full_name});
$userDataWidget{login_name}->setValue($userData{username});
yui::YUI::ui()->blockEvents();
$userDataWidget{password}->setValue($userData{password}) if $userData{password};
yui::YUI::ui()->unblockEvents();
$userDataWidget{password1}->setValue($userData{password1}) if $userData{password1};
$userDataWidget{homedir}->setValue($userData{homedir});
$replace_pnt->showChild();
$dialog->recalcLayout();
$dialog->doneMultipleChanges();
return %userDataWidget;
}
#=============================================================
=head2 _groupDataTabWidget
=head3 INPUT
$self: this object
$dialog: YUI dialog that owns the YUI replace point
$replace_pnt: YUI replace point, needed to add a new tab
widget
%groupData: hash containing group data info, tabs are
removed and added again on selection, so
data must be saved outside of widgets.
$previus_tab: previous tab widget label, needed to store
group data from the old tab before removing
it, if user changed something.
=head3 OUTPUT
%groupDataWidget: hash containing new YUI widget objects
such as:
groupname.
=head3 DESCRIPTION
This internal method removes old tab widget saving its
relevant data into groupData and creates new selected table
to be shown.
=cut
#=============================================================
sub _groupDataTabWidget {
my ($self, $dialog, $replace_pnt, %groupData) = @_;
my $factory = yui::YUI::widgetFactory;
$dialog->startMultipleChanges();
$replace_pnt->deleteChildren();
my $layout = $factory->createVBox($replace_pnt);
my %groupDataWidget;
## user 'login name'
my $align = $factory->createRight($layout);
my $hbox = $factory->createHBox($align);
my $label = $factory->createLabel($hbox, $self->loc->N("Group Name:") );
$groupDataWidget{groupname} = $factory->createInputField($hbox, "", 0);
$label->setWeight($yui::YD_HORIZ, 1);
$groupDataWidget{groupname}->setWeight($yui::YD_HORIZ, 2);
$groupDataWidget{groupname}->setValue($groupData{groupname});
$replace_pnt->showChild();
$dialog->recalcLayout();
$dialog->doneMultipleChanges();
return %groupDataWidget;
}
sub _userAccountInfoTabWidget {
my ($self, $dialog, $replace_pnt, %userData) = @_;
my $factory = yui::YUI::widgetFactory;
$dialog->startMultipleChanges();
$replace_pnt->deleteChildren();
my $layout = $factory->createVBox($replace_pnt);
my %userAccountWidget;
$userAccountWidget{acc_check_exp} = $factory->createCheckBoxFrame($layout, $self->loc->N("Enable account expiration"), 1);
my $align = $factory->createRight($userAccountWidget{acc_check_exp});
my $hbox = $factory->createHBox($align);
my $label = $factory->createLabel($hbox, $self->loc->N("Account expires (YYYY-MM-DD):"));
$userAccountWidget{acc_expy} = $factory->createIntField($hbox, "", 1970, 9999, $userData{acc_expy});
$userAccountWidget{acc_expm} = $factory->createIntField($hbox, "", 1, 12, $userData{acc_expm});
$userAccountWidget{acc_expd} = $factory->createIntField($hbox, "", 1, 31, $userData{acc_expd});
$userAccountWidget{acc_check_exp}->setValue($userData{acc_check_exp});
$label->setWeight($yui::YD_HORIZ, 2);
$align = $factory->createLeft($layout);
$userAccountWidget{lockuser} = $factory->createCheckBox($align, $self->loc->N("Lock User Account"), $userData{lockuser});
$align = $factory->createLeft($layout);
$hbox = $factory->createHBox($align);
$label = $factory->createLabel($hbox, $self->loc->N("Click on the icon to change it"));
$userAccountWidget{icon_face} = $factory->createPushButton($hbox, "");
$userAccountWidget{icon_face}->setIcon($self->sh_users->face2png($userData{icon_face}));
$userAccountWidget{icon_face}->setLabel($userData{icon_face});
$replace_pnt->showChild();
$dialog->recalcLayout();
$dialog->doneMultipleChanges();
return %userAccountWidget;
}
sub _userPasswordInfoTabWidget {
my ($self, $dialog, $replace_pnt, %userData) = @_;
my $factory = yui::YUI::widgetFactory;
$dialog->startMultipleChanges();
$replace_pnt->deleteChildren();
my $layout = $factory->createVBox($replace_pnt);
my %userPasswordWidget;
my $userEnt = $self->ctx->LookupUserByName($userData{username});
my $lastchg = $userEnt->ShadowLastChange($self->USER_GetValue);
my $align = $factory->createLeft($layout);
my $hbox = $factory->createHBox($align);
my $label = $factory->createLabel($hbox, $self->loc->N("User last changed password on: "));
my $dayStr = $factory->createLabel($hbox, "");
my $month = $factory->createLabel($hbox, "");
my $dayInt = $factory->createLabel($hbox, "");
my $year = $factory->createLabel($hbox, "");
if ($lastchg) {
my $times = _TimeOfArray($lastchg, 0);
$dayStr->setValue($times->{daystr});
$month->setValue($times->{month});
$dayInt->setValue($times->{dayint});
$year->setValue($times->{year});
}
$userPasswordWidget{pwd_check_exp} = $factory->createCheckBoxFrame($layout, $self->loc->N("Enable Password Expiration"), 1);
$layout = $factory->createVBox($userPasswordWidget{pwd_check_exp});
$align = $factory->createLeft($layout);
$hbox = $factory->createHBox($align);
$label = $factory->createLabel($hbox, $self->loc->N("Days before change allowed:"));
$userPasswordWidget{pwd_exp_min} = $factory->createInputField($hbox, "", 0);
$userPasswordWidget{pwd_exp_min}->setValue("$userData{pwd_exp_min}");
$label->setWeight($yui::YD_HORIZ, 1);
$userPasswordWidget{pwd_exp_min}->setWeight($yui::YD_HORIZ, 2);
$align = $factory->createLeft($layout);
$hbox = $factory->createHBox($align);
$label = $factory->createLabel($hbox, $self->loc->N("Days before change required:"));
$userPasswordWidget{pwd_exp_max} = $factory->createInputField($hbox, "", 0);
$userPasswordWidget{pwd_exp_max}->setValue("$userData{pwd_exp_max}");
$label->setWeight($yui::YD_HORIZ, 1);
$userPasswordWidget{pwd_exp_max}->setWeight($yui::YD_HORIZ, 2);
$align = $factory->createLeft($layout);
$hbox = $factory->createHBox($align);
$label = $factory->createLabel($hbox, $self->loc->N("Days warning before change:"));
$userPasswordWidget{pwd_exp_warn} = $factory->createInputField($hbox, "", 0);
$userPasswordWidget{pwd_exp_warn}->setValue("$userData{pwd_exp_warn}");
$label->setWeight($yui::YD_HORIZ, 1);
$userPasswordWidget{pwd_exp_warn}->setWeight($yui::YD_HORIZ, 2);
$align = $factory->createLeft($layout);
$hbox = $factory->createHBox($align);
$label = $factory->createLabel($hbox, $self->loc->N("Days before account inactive:"));
$userPasswordWidget{pwd_exp_inact} = $factory->createInputField($hbox, "", 0);
$userPasswordWidget{pwd_exp_inact}->setValue("$userData{pwd_exp_inact}");
$label->setWeight($yui::YD_HORIZ, 1);
$userPasswordWidget{pwd_exp_inact}->setWeight($yui::YD_HORIZ, 2);
$userPasswordWidget{pwd_check_exp}->setValue($userData{pwd_check_exp});
$replace_pnt->showChild();
$dialog->recalcLayout();
$dialog->doneMultipleChanges();
return %userPasswordWidget;
}
sub _groupUsersTabWidget {
my ($self, $dialog, $replace_pnt, %groupData) = @_;
my $factory = yui::YUI::widgetFactory;
my $mageiaPlugin = "mga";
my $mgaFactory = yui::YExternalWidgets::externalWidgetFactory($mageiaPlugin);
$mgaFactory = yui::YMGAWidgetFactory::getYMGAWidgetFactory($mgaFactory);
$dialog->startMultipleChanges();
$replace_pnt->deleteChildren();
my %groupUsersWidget;
my $layout = _labeledFrameBox($replace_pnt, $self->loc->N("Select the users to join this group:"));
my $yTableHeader = new yui::YTableHeader();
$yTableHeader->addColumn("", $yui::YAlignBegin);
$yTableHeader->addColumn($self->loc->N("User"), $yui::YAlignBegin);
$groupUsersWidget{members} = $mgaFactory->createCBTable($layout, $yTableHeader, $yui::YCBTableCheckBoxOnFirstColumn);
my $groupEnt = $self->ctx->LookupGroupByName($groupData{groupname});
my $users = $self->ctx->UsersEnumerate;
my @susers = sort(@$users);
my $itemCollection = new yui::YItemCollection;
my $members = $groupData{members};
foreach my $user (@susers) {
my $item = new yui::YCBTableItem($user);
$item->check(member($user, @$members));
$item->setLabel($user);
$itemCollection->push($item);
$item->DISOWN();
}
$groupUsersWidget{members}->addItems($itemCollection);
$replace_pnt->showChild();
$dialog->recalcLayout();
$dialog->doneMultipleChanges();
return %groupUsersWidget;
}
sub _userGroupsTabWidget {
my ($self, $dialog, $replace_pnt, %userData) = @_;
my $factory = yui::YUI::widgetFactory;
my $mageiaPlugin = "mga";
my $mgaFactory = yui::YExternalWidgets::externalWidgetFactory($mageiaPlugin);
$mgaFactory = yui::YMGAWidgetFactory::getYMGAWidgetFactory($mgaFactory);
$dialog->startMultipleChanges();
$replace_pnt->deleteChildren();
my %userGroupsWidget;
my $userEnt = $self->ctx->LookupUserByName($userData{username});
my $lastchg = $userEnt->ShadowLastChange($self->USER_GetValue);
my $layout = _labeledFrameBox($replace_pnt, $self->loc->N("Select groups that the user will be member of:"));
my $yTableHeader = new yui::YTableHeader();
$yTableHeader->addColumn("", $yui::YAlignBegin);
$yTableHeader->addColumn($self->loc->N("Group"), $yui::YAlignBegin);
$userGroupsWidget{members} = $mgaFactory->createCBTable($layout, $yTableHeader, $yui::YCBTableCheckBoxOnFirstColumn);
my $grps = $self->ctx->GroupsEnumerate;
my @sgroups = sort @$grps;
my $itemCollection = new yui::YItemCollection;
my $members = $userData{members};
foreach my $group (@sgroups) {
my $item = new yui::YCBTableItem($group);
$item->check(member($group, @$members));
$item->setLabel($group);
$itemCollection->push($item);
$item->DISOWN();
}
$userGroupsWidget{members}->addItems($itemCollection);
$userGroupsWidget{members}->setNotify(1);
my $primgroup = '';
if ($userData{primary_group} != -1) {
my $Gent = $self->ctx->LookupGroupById($userData{primary_group});
$primgroup = $Gent->GroupName($self->USER_GetValue);
}
my $align = $factory->createLeft($layout);
my $hbox = $factory->createHBox($align);
my $label = $factory->createLabel($hbox, $self->loc->N("Primary Group"));
$userGroupsWidget{primary_group} = $factory->createComboBox($hbox, "", 0);
my $itemColl = new yui::YItemCollection;
foreach my $member (@$members) {
my $item = new yui::YItem ($member, 0);
$item->setSelected(1) if ($item->label() eq $primgroup);
$itemColl->push($item);
$item->DISOWN();
}
$userGroupsWidget{primary_group}->addItems($itemColl);
$label->setWeight($yui::YD_HORIZ, 1);
$userGroupsWidget{primary_group}->setWeight($yui::YD_HORIZ, 2);
$replace_pnt->showChild();
$dialog->recalcLayout();
$dialog->doneMultipleChanges();
return %userGroupsWidget;
}
sub _groupEdit_Ok {
my ($self, %groupData) = @_;
# update last changes if any
%groupData = $self->_storeDataFromGroupEditPreviousTab(%groupData);
my ($continue, $errorString) = $self->sh_users->valid_groupname($groupData{groupname});
if (!$continue) {
$self->sh_gui->msgBox({text => $errorString}) if ($errorString);
return $continue;
}
my $groupEnt = $self->ctx->LookupGroupByName($groupData{start_groupname});
if ($groupData{start_groupname} ne $groupData{groupname}) {
$groupEnt->GroupName($groupData{groupname});
}
my $members = $groupData{members};
my $gid = $groupEnt->Gid($self->USER_GetValue);
my $users = $self->ctx->UsersEnumerate;
my @susers = sort(@$users);
foreach my $user (@susers) {
my $uEnt = $self->ctx->LookupGroupByName($user);
if ($uEnt) {
my $ugid = $uEnt->Gid($self->USER_GetValue);
my $m = $self->ctx->EnumerateUsersByGroup($groupData{start_groupname});
if (member($user, @$members)) {
if (!$self->_inArray($user, $m)) {
if ($ugid != $gid) {
eval { $groupEnt->MemberName($user,1) };
}
}
}
else {
if ($self->_inArray($user, $m)) {
if ($ugid == $gid) {
$self->sh_gui->msgBox({text => $self->loc->N("You cannot remove user '%s' from their primary group", $user)});
return 0;
}
else {
eval { $groupEnt->MemberName($user,2) };
}
}
}
}
}
$self->ctx->GroupModify($groupEnt);
$self->_refresh();
return 1;
}
sub _userEdit_Ok {
my ($self, %userData) = @_;
# update last changes if any
%userData = $self->_storeDataFromUserEditPreviousTab(%userData);
my ($continue, $errorString) = $self->sh_users->valid_username($userData{username});
if (!$continue) {
$self->sh_gui->msgBox({text => $errorString}) if ($errorString);
return $continue;
}
if ( $userData{password} ne $userData{password1}) {
$self->sh_gui->msgBox({text => $self->loc->N("Password Mismatch")});
return 0;
}
my $userEnt = $self->ctx->LookupUserByName($userData{username});
if ($userData{password} ne '') {
if ($self->sh_users->weakPasswordForSecurityLevel($userData{password})) {
$self->sh_gui->msgBox({text => $self->loc->N("This password is too simple. \n Good passwords should be > 6 characters")});
return 0;
}
$self->ctx->UserSetPass($userEnt, $userData{password});
}
$userEnt->UserName($userData{username});
$userEnt->Gecos($userData{full_name});
$userEnt->HomeDir($userData{homedir});
$userEnt->LoginShell($userData{shell});
my $username = $userEnt->UserName($self->USER_GetValue);
my $grps = $self->ctx->GroupsEnumerate;
my @sgroups = sort @$grps;
my $members = $userData{members};
foreach my $group (@sgroups) {
my $gEnt = $self->ctx->LookupGroupByName($group);
my $ugid = $gEnt->Gid($self->USER_GetValue);
my $m = $gEnt->MemberName(1,0);
if (member($group, @$members)) {
if (!$self->_inArray($username, $m) && $userData{primary_group} != $ugid) {
eval { $gEnt->MemberName($username, 1) };
$self->ctx->GroupModify($gEnt);
}
}
else {
if ($self->_inArray($username, $m)) {
eval { $gEnt->MemberName($username, 2) };
$self->ctx->GroupModify($gEnt);
}
}
}
if ($userData{primary_group} == -1) {
$self->sh_gui->msgBox({ text => $self->loc->N("Please select at least one group for the user")});
return 0;
}
$userEnt->Gid($userData{primary_group});
if ($userData{acc_check_exp}) {
my $yr = $userData{acc_expy};
my $mo = $userData{acc_expm};
my $dy = $userData{acc_expd};
if (!_ValidInt($yr, $dy, $mo)) {
$self->sh_gui->msgBox({text => $self->loc->N("Please specify Year, Month and Day \n for Account Expiration ")});
return 0;
}
my $Exp = _ConvTime($dy, $mo, $yr);
$userEnt->ShadowExpire($Exp);
}
else {
$userEnt->ShadowExpire(ceil(-1))
}
if ($userData{pwd_check_exp}) {
my $allowed = int($userData{pwd_exp_min});
my $required = int($userData{pwd_exp_max});
my $warning = int($userData{pwd_exp_warn});
my $inactive = int($userData{pwd_exp_inact});
if ($allowed && $required && $warning && $inactive) {
$userEnt->ShadowMin($allowed);
$userEnt->ShadowMax($required);
$userEnt->ShadowWarn($warning);
$userEnt->ShadowInact($inactive);
}
else {
$self->sh_gui->msgBox({text => $self->loc->N("Please fill up all fields in password aging\n")});
return 0;
}
}
else {
$userEnt->ShadowMin(-1);
$userEnt->ShadowMax(99999);
$userEnt->ShadowWarn(-1);
$userEnt->ShadowInact(-1);
}
$self->ctx->UserModify($userEnt);
if ($userData{lockuser}) {
!$self->ctx->IsLocked($userEnt) and $self->ctx->Lock($userEnt);
}
else {
$self->ctx->IsLocked($userEnt) and $self->ctx->UnLock($userEnt);
}
defined $userData{icon_face} and $self->sh_users->addKdmIcon($userData{username}, $userData{icon_face});
$self->_refresh();
return 1;
}
# check the password and set the widget accordingly
sub _checkWeaknessPassword {
my ($self, $password, $weakness_widget) = @_;
my $strongp = $self->sh_users->strongPassword($password);
if (yui::YUI::app()->hasImageSupport()) {
my $file = dist_file('AdminPanel', 'images/Warning_Shield_Grey16x16.png');
if ($strongp) {
$file = dist_file('AdminPanel', 'images/Checked_Shield_Green16x16.png');
}
$weakness_widget->setImage($file);
}
else {
# For ncurses set a label
$weakness_widget->setValue(($strongp ? $self->loc->N("Strong") : $self->loc->N("Weak")));
}
}
sub _editUserDialog {
my $self = shift;
my $dontcreatehomedir = 0;
my $is_system = 0;
## push application title
my $appTitle = yui::YUI::app()->applicationTitle();
## set new title to get it in dialog
yui::YUI::app()->setApplicationTitle($self->loc->N("Edit User"));
my $factory = yui::YUI::widgetFactory;
my $optional = yui::YUI::optionalWidgetFactory;
my $dlg = $factory->createPopupDialog();
my $layout = $factory->createVBox($dlg);
my %tabs;
if ($optional->hasDumbTab()) {
my $hbox = $factory->createHBox($layout);
my $align = $factory->createHCenter($hbox);
$tabs{widget} = $optional->createDumbTab($align);
$tabs{user_data} = new yui::YItem($userEditLabel{user_data});
$tabs{user_data}->setSelected();
$tabs{used} = $tabs{user_data}->label();
$tabs{widget}->addItem( $tabs{user_data} );
$tabs{user_data}->DISOWN();
$tabs{account_info} = new yui::YItem($userEditLabel{account_info});
$tabs{widget}->addItem( $tabs{account_info} );
$tabs{account_info}->DISOWN();
$tabs{password_info} = new yui::YItem($userEditLabel{password_info});
$tabs{widget}->addItem( $tabs{password_info} );
$tabs{password_info}->DISOWN();
$tabs{groups} = new yui::YItem($userEditLabel{groups});
$tabs{widget}->addItem( $tabs{groups} );
$tabs{groups}->DISOWN();
my $vbox = $factory->createVBox($tabs{widget});
$align = $factory->createLeft($vbox);
$tabs{replace_pnt} = $factory->createReplacePoint($align);
$hbox = $factory->createHBox($vbox);
$align = $factory->createRight($hbox);
my $cancelButton = $factory->createPushButton($align, $self->loc->N("Cancel"));
my $okButton = $factory->createPushButton($hbox, $self->loc->N("Ok"));
my %userData = $self->_getUserInfo();
# userData here should be tested because it could be undef
# Useful entry point for the current edit user/group tab widget
$self->set_edit_tab_widget( $self->_userDataTabWidget($dlg, $tabs{replace_pnt}, %userData) );
$self->set_edit_tab_widget( edit_tab_label => $userEditLabel{user_data});
while(1) {
my $event = $dlg->waitForEvent();
my $eventType = $event->eventType();
#event type checking
if ($eventType == $yui::YEvent::CancelEvent) {
last;
}
elsif ($eventType == $yui::YEvent::MenuEvent) {
### MENU ###
my $item = $event->item();
if ($item->label() eq $tabs{user_data}->label()) {
%userData = $self->_storeDataFromUserEditPreviousTab(%userData);
my %edit_tab = $self->_userDataTabWidget($dlg, $tabs{replace_pnt}, %userData );
$self->edit_tab_widgets( {} );
$self->set_edit_tab_widget(%edit_tab);
$self->set_edit_tab_widget( edit_tab_label => $userEditLabel{user_data});
}
elsif ($item->label() eq $tabs{account_info}->label()) {
%userData = $self->_storeDataFromUserEditPreviousTab(%userData);
my %edit_tab = $self->_userAccountInfoTabWidget($dlg, $tabs{replace_pnt}, %userData );
$self->edit_tab_widgets( {} );
$self->set_edit_tab_widget(%edit_tab);
$self->set_edit_tab_widget( edit_tab_label => $userEditLabel{account_info});
}
elsif ($item->label() eq $tabs{password_info}->label()) {
%userData = $self->_storeDataFromUserEditPreviousTab(%userData);
my %edit_tab = $self->_userPasswordInfoTabWidget($dlg, $tabs{replace_pnt}, %userData );
$self->edit_tab_widgets( {} );
$self->set_edit_tab_widget(%edit_tab);
$self->set_edit_tab_widget( edit_tab_label => $userEditLabel{password_info});
}
elsif ($item->label() eq $tabs{groups}->label()) {
%userData = $self->_storeDataFromUserEditPreviousTab(%userData);
my %edit_tab = $self->_userGroupsTabWidget($dlg, $tabs{replace_pnt}, %userData );
$self->edit_tab_widgets( {} );
$self->set_edit_tab_widget(%edit_tab);
$self->set_edit_tab_widget( edit_tab_label => $userEditLabel{groups});
}
}
elsif ($eventType == $yui::YEvent::WidgetEvent) {
### widget
my $widget = $event->widget();
if ($widget == $cancelButton) {
last;
}
elsif ($widget == $self->get_edit_tab_widget('password')) {
my $pass = $self->get_edit_tab_widget('password')->value();
$self->_checkWeaknessPassword($pass, $self->get_edit_tab_widget('weakness'));
}
elsif ($widget == $okButton) {
## save changes
if ($self->_userEdit_Ok(%userData)) {
last;
}
}
# last: managing tab widget events
else {
my $current_tab = $self->get_edit_tab_widget('edit_tab_label');
if ($current_tab && $current_tab eq $userEditLabel{account_info}) {
if ($widget == $self->get_edit_tab_widget('icon_face')) {
my $iconLabel = $self->_skipShortcut($self->get_edit_tab_widget('icon_face')->label());
my $nextIcon = $self->sh_users->GetFaceIcon($iconLabel, 1);
$self->get_edit_tab_widget('icon_face')->setLabel($nextIcon);
$self->get_edit_tab_widget('icon_face')->setIcon($self->sh_users->face2png($nextIcon));
}
}
elsif ($current_tab && $current_tab eq $userEditLabel{groups}) {
if ($widget == $self->get_edit_tab_widget('members')) {
my $item = $self->get_edit_tab_widget('members')->changedItem();
if ($item) {
if ($item->checked()) {
# add it to possible primary groups
my $pgItem = new yui::YItem ($item->label(), 0);
$self->get_edit_tab_widget('primary_group')->addItem($pgItem);
}
else {
# remove it to possible primary groups
$dlg->startMultipleChanges();
my $itemColl = new yui::YItemCollection;
my $tbl = $self->get_edit_tab_widget('members');
for(my $i=0;$i < $tbl->itemsCount();$i++) {
if ($tbl->toCBYTableItem($tbl->item($i))->checked()) {
my $pgItem = new yui::YItem ($tbl->item($i)->label(), 0);
my $Gent = $self->ctx->LookupGroupById($userData{primary_group});
my $primgroup = $Gent->GroupName($self->USER_GetValue);
$pgItem->setSelected(1) if ($pgItem->label() eq $primgroup);
$itemColl->push($pgItem);
$pgItem->DISOWN();
}
}
$self->get_edit_tab_widget('primary_group')->deleteAllItems();
$self->get_edit_tab_widget('primary_group')->addItems($itemColl);
$dlg->recalcLayout();
$dlg->doneMultipleChanges();
}
}
}
}
}
}
}
}
else {
$self->sh_gui->warningMsgBox({text => $self->loc->N("Cannot create tab widgets")});
}
destroy $dlg;
#restore old application title
yui::YUI::app()->setApplicationTitle($appTitle);
}
sub _editGroupDialog {
my $self = shift;
## push application title
my $appTitle = yui::YUI::app()->applicationTitle();
## set new title to get it in dialog
yui::YUI::app()->setApplicationTitle($self->loc->N("Edit Group"));
my $factory = yui::YUI::widgetFactory;
my $optional = yui::YUI::optionalWidgetFactory;
my $dlg = $factory->createPopupDialog();
my $layout = $factory->createVBox($dlg);
my %tabs;
if ($optional->hasDumbTab()) {
my $hbox = $factory->createHBox($layout);
my $align = $factory->createHCenter($hbox);
$tabs{widget} = $optional->createDumbTab($align);
$tabs{group_data} = new yui::YItem($groupEditLabel{group_data});
$tabs{group_data}->setSelected();
$tabs{widget}->addItem( $tabs{group_data} );
$tabs{group_data}->DISOWN();
$tabs{group_users} = new yui::YItem($groupEditLabel{group_users});
$tabs{widget}->addItem( $tabs{group_users} );
$tabs{group_users}->DISOWN();
my $vbox = $factory->createVBox($tabs{widget});
$align = $factory->createLeft($vbox);
$tabs{replace_pnt} = $factory->createReplacePoint($align);
$hbox = $factory->createHBox($vbox);
$align = $factory->createRight($hbox);
my $cancelButton = $factory->createPushButton($align, $self->loc->N("Cancel"));
my $okButton = $factory->createPushButton($hbox, $self->loc->N("Ok"));
my %groupData = $self->_getGroupInfo();
# groupData here should be tested because it could be undef
# %groupData: selected group info as:
# $groupname: group name
# $members: users that are members of this group
# Useful entry point for the current edit user/group tab widget
$self->set_edit_tab_widget( $self->_groupDataTabWidget($dlg, $tabs{replace_pnt}, %groupData) );
$self->set_edit_tab_widget( edit_tab_label => $groupEditLabel{group_data});
while(1) {
my $event = $dlg->waitForEvent();
my $eventType = $event->eventType();
#event type checking
if ($eventType == $yui::YEvent::CancelEvent) {
last;
}
elsif ($eventType == $yui::YEvent::MenuEvent) {
### MENU ###
my $item = $event->item();
if ($item->label() eq $tabs{group_data}->label()) {
%groupData = $self->_storeDataFromGroupEditPreviousTab(%groupData);
my %edit_tab = $self->_groupDataTabWidget($dlg, $tabs{replace_pnt}, %groupData );
$self->edit_tab_widgets( {} );
$self->set_edit_tab_widget(%edit_tab);
$self->set_edit_tab_widget( edit_tab_label => $groupEditLabel{group_data});
}
elsif ($item->label() eq $tabs{group_users}->label()) {
%groupData = $self->_storeDataFromGroupEditPreviousTab(%groupData);
my %edit_tab = $self->_groupUsersTabWidget($dlg, $tabs{replace_pnt}, %groupData );
$self->edit_tab_widgets( {} );
$self->set_edit_tab_widget(%edit_tab);
$self->set_edit_tab_widget( edit_tab_label => $groupEditLabel{group_users});
}
}
elsif ($eventType == $yui::YEvent::WidgetEvent) {
### widget
my $widget = $event->widget();
if ($widget == $cancelButton) {
last;
}
elsif ($widget == $okButton) {
## save changes
if ($self->_groupEdit_Ok(%groupData)) {
last;
}
}
}
}
}
else {
$self->sh_gui->warningMsgBox({text => $self->loc->N("Cannot create tab widgets")});
}
destroy $dlg;
#restore old application title
yui::YUI::app()->setApplicationTitle($appTitle);
}
sub _editUserOrGroup {
my $self = shift;
# TODO item management avoid label if possible
my $label = $self->_skipShortcut($self->get_widget('tabs')->selectedItem()->label());
if ($label eq $self->loc->N("Users") ) {
$self->_editUserDialog();
}
else {
$self->_editGroupDialog();
}
$self->_refresh();
}
sub _deleteUserOrGroup {
my $self = shift;
# TODO item management avoid label if possible
my $label = $self->_skipShortcut($self->get_widget('tabs')->selectedItem()->label());
if ($label eq $self->loc->N("Users") ) {
$self->_deleteUserDialog();
$self->_refresh();
}
else {
$self->_deleteGroupDialog();
$self->_refresh();
}
}
sub _refresh {
my $self = shift;
# TODO item management avoid label if possible
my $label = $self->_skipShortcut($self->get_widget('tabs')->selectedItem()->label());
if ($label eq $self->loc->N("Users") ) {
$self->_refreshUsers();
}
else {
$self->_refreshGroups();
}
# TODO xguest
# RefreshXguest(1);
}
# TODO context menu creation is missed in libyui
sub _contextMenuActions {
my $self = shift;
my $item = $self->get_widget('table')->selectedItem();
if ($item) {
}
}
sub _refreshActions {
my $self = shift;
my $item = $self->get_widget('table')->selectedItem();
$self->dialog->startMultipleChanges();
$self->get_widget('action_menu')->deleteAllItems();
# do we need to undef them first?
$self->set_action_menu(
add_user => undef,
add_group => undef,
edit => undef,
del => undef,
inst => undef,
);
$self->set_action_menu(
add_user => new yui::YMenuItem($self->loc->N("Add User")),
add_group => new yui::YMenuItem($self->loc->N("Add Group")),
edit => new yui::YMenuItem($self->loc->N("&Edit")),
del => new yui::YMenuItem($self->loc->N("&Delete")),
inst => new yui::YMenuItem($self->loc->N("Install guest account")),
);
my $itemColl = new yui::YItemCollection;
for my $pair ( $self->action_menu_pairs ) {
my $menuItem = $pair->[1];
if ($pair->[0] eq 'edit' || $pair->[0] eq 'del') {
if ($item) {
$itemColl->push($menuItem);
}
}
else {
$itemColl->push($menuItem);
}
$menuItem->DISOWN();
}
$self->get_widget('action_menu')->addItems($itemColl);
$self->get_widget('action_menu')->rebuildMenuTree();
if ($item) {
$self->get_widget('edit')->setEnabled();
$self->get_widget('del')->setEnabled();
}
else {
$self->get_widget('edit')->setDisabled();
$self->get_widget('del')->setDisabled();
}
$self->dialog->doneMultipleChanges();
}
sub _manageUsersDialog {
my $self = shift;
## TODO fix for adminpanel
my $pixdir = '/usr/share/userdrake/pixmaps/';
## push application title
my $appTitle = yui::YUI::app()->applicationTitle();
## set new title to get it in dialog
yui::YUI::app()->setApplicationTitle($self->name);
## set icon if not already set by external launcher
yui::YUI::app()->setApplicationIcon($self->icon);
my $factory = yui::YUI::widgetFactory;
my $optional = yui::YUI::optionalWidgetFactory;
$self->dialog($factory->createMainDialog());
my $layout = $factory->createVBox($self->dialog);
my $hbox_headbar = $factory->createHBox($layout);
my $head_align_left = $factory->createLeft($hbox_headbar);
my $head_align_right = $factory->createRight($hbox_headbar);
my $headbar = $factory->createHBox($head_align_left);
my $headRight = $factory->createHBox($head_align_right);
my %fileMenu = (
widget => $factory->createMenuButton($headbar,$self->loc->N("File")),
refresh => new yui::YMenuItem($self->loc->N("Refresh")),
quit => new yui::YMenuItem($self->loc->N("&Quit")),
);
$fileMenu{ widget }->addItem($fileMenu{ refresh });
$fileMenu{ widget }->addItem($fileMenu{ quit });
$fileMenu{ widget }->rebuildMenuTree();
my $actionMenu = $factory->createMenuButton($headbar, $self->loc->N("Actions"));
$actionMenu->DISOWN();
my %helpMenu = (
widget => $factory->createMenuButton($headRight, $self->loc->N("&Help")),
help => new yui::YMenuItem($self->loc->N("Help")),
report_bug => new yui::YMenuItem($self->loc->N("Report Bug")),
about => new yui::YMenuItem($self->loc->N("&About")),
);
while ( my ($key, $value) = each(%helpMenu) ) {
if ($key ne 'widget' ) {
$helpMenu{ widget }->addItem($value);
}
}
$helpMenu{ widget }->rebuildMenuTree();
my $hbox = $factory->createHBox($layout);
$hbox = $factory->createHBox($factory->createLeft($hbox));
$self->set_widget(
add_user => $factory->createIconButton($hbox, $pixdir . 'user_add.png', $self->loc->N("Add User")),
add_group => $factory->createIconButton($hbox, $pixdir . 'group_add.png', $self->loc->N("Add Group")),
edit => $factory->createIconButton($hbox, $pixdir . 'user_conf.png', $self->loc->N("Edit")),
del => $factory->createIconButton($hbox, $pixdir . 'user_del.png', $self->loc->N("Delete")),
refresh => $factory->createIconButton($hbox, $pixdir . 'refresh.png', $self->loc->N("Refresh")),
action_menu => $actionMenu,
);
$hbox = $factory->createHBox($layout);
$head_align_left = $factory->createLeft($hbox);
my $sysfilter = 1;
if (-e $self->config_file) {
my $prefs = Config::Auto::parse($self->config_file);
$sysfilter = ($prefs->{FILTER} eq 'true' or $prefs->{FILTER} eq 'true' or $prefs->{FILTER} eq '1');
}
$self->set_widget(filter_system => $factory->createCheckBox($head_align_left, $self->loc->N("Filter system users"),
$sysfilter));
$factory->createHSpacing($hbox, 3);
$head_align_right = $factory->createRight($hbox);
$headRight = $factory->createHBox($head_align_right);
$factory->createLabel($headRight, $self->loc->N("Search:"));
$self->set_widget(filter => $factory->createInputField($headRight, "", 0));
$self->set_widget(apply_filter => $factory->createPushButton($headRight, $self->loc->N("Apply filter")));
$self->get_widget('filter')->setWeight($yui::YD_HORIZ, 2);
$self->get_widget('apply_filter')->setWeight($yui::YD_HORIZ, 1);
$self->get_widget('filter_system')->setNotify(1);
my %tabs;
if ($optional->hasDumbTab()) {
$hbox = $factory->createHBox($layout);
my $align = $factory->createHCenter($hbox);
$self->set_widget(tabs => $optional->createDumbTab($align));
$tabs{users} = new yui::YItem($self->loc->N("Users"));
$tabs{users}->setSelected();
$self->get_widget('tabs')->addItem( $tabs{users} );
$tabs{users}->DISOWN();
$tabs{groups} = new yui::YItem($self->loc->N("Groups"));
$self->get_widget('tabs')->addItem( $tabs{groups} );
$tabs{groups}->DISOWN();
my $vbox = $factory->createVBox($self->get_widget('tabs'));
$align = $factory->createLeft($vbox);
$self->set_widget(replace_pnt => $factory->createReplacePoint($align));
$self->_createUserTable();
$self->get_widget('table')->setImmediateMode(1);
$self->get_widget('table')->DISOWN();
}
$self->_refreshActions();
# main loop
while(1) {
my $event = $self->dialog->waitForEvent();
my $eventType = $event->eventType();
#event type checking
if ($eventType == $yui::YEvent::CancelEvent) {
last;
}
elsif ($eventType == $yui::YEvent::MenuEvent) {
### MENU ###
my $item = $event->item();
my $menuLabel = $item->label();
if ($menuLabel eq $fileMenu{ quit }->label()) {
last;
}
elsif ($menuLabel eq $helpMenu{about}->label()) {
my $translators = $self->loc->N("_: Translator(s) name(s) & email(s)\n");
$translators =~ s/\</\<\;/g;
$translators =~ s/\>/\>\;/g;
$self->sh_gui->AboutDialog({ name => $self->loc->N("AdminUser"),
version => $self->VERSION,
credits => $self->loc->N("Copyright (C) %s Mageia community", '2013-2014'),
license => $self->loc->N("GPLv2"),
description => $self->loc->N("AdminUser is a Mageia user management tool \n(from the original idea of Mandriva userdrake)."),
authors => $self->loc->N("<h3>Developers</h3>
<ul><li>%s</li>
<li>%s</li>
</ul>
<h3>Translators</h3>
<ul><li>%s</li></ul>",
"Angelo Naselli <anaselli\@linux.it>",
"Matteo Pasotti <matteo.pasotti\@gmail.com>",
$translators
),
}
);
}
elsif ($menuLabel eq $self->get_action_menu('add_user')->label()) {
$self->addUserDialog();
$self->_refresh();
}
elsif ($menuLabel eq $self->get_action_menu('add_group')->label()) {
$self->_addGroupDialog();
$self->_refresh();
}
elsif ($menuLabel eq $self->get_action_menu('del')->label()) {
$self->_deleteUserOrGroup();
}
elsif ($menuLabel eq $self->get_action_menu('edit')->label()) {
$self->_editUserOrGroup();
}
elsif ($self->get_widget('tabs') && $menuLabel eq $tabs{groups}->label()) {
$self->_createGroupTable();
}
elsif ($self->get_widget('tabs') && $menuLabel eq $tabs{users}->label()) {
$self->_createUserTable();
}
elsif ($menuLabel eq $fileMenu{refresh}->label()) {
$self->_refresh();
}
}
elsif ($eventType == $yui::YEvent::WidgetEvent) {
### Buttons and widgets ###
my $widget = $event->widget();
if ($widget == $self->get_widget('add_user')) {
$self->addUserDialog();
$self->_refresh();
}
elsif ($widget == $self->get_widget('del')) {
$self->_deleteUserOrGroup();
}
elsif ($widget == $self->get_widget('table')) {
$self->_refreshActions();
my $wEvent = yui::YMGAWidgetFactory::getYWidgetEvent($event);
if ($wEvent && $wEvent->reason() == $yui::YEvent::Activated) {
$self->_editUserOrGroup();
}
}
elsif ($widget == $self->get_widget('add_group')) {
$self->_addGroupDialog();
$self->_refresh();
}
elsif ($widget == $self->get_widget('edit')) {
$self->_editUserOrGroup();
}
elsif ( $widget == $self->get_widget('filter_system') ||
$widget == $self->get_widget('refresh') ||
$widget == $self->get_widget('apply_filter') ) {
$self->_refresh();
}
}
}
$self->dialog->destroy() ;
#restore old application title
yui::YUI::app()->setApplicationTitle($appTitle) if $appTitle;
}
#=============================================================
=head2 _skipShortcut
=head3 INPUT
$self: this object
$label: an item label to be cleaned by keyboard shortcut "&"
=head3 OUTPUT
$label: cleaned label
=head3 DESCRIPTION
This internal method is a workaround to label that are
changed by "&" due to keyborad shortcut.
=cut
#=============================================================
sub _skipShortcut {
my ($self, $label) = @_;
$label =~ s/&// if ($label);
return ($label);
}
#=============================================================
=head2 _inArray
=head3 INPUT
$self: this object
$item: item to search
$arr: array container
=head3 OUTPUT
true: if the array contains the item
=head3 DESCRIPTION
This method returns if an item is into the array container
=cut
#=============================================================
sub _inArray {
my ($self, $item, $arr) = @_;
return grep( /^$item$/, @$arr );
}
sub _ValidInt {
foreach my $i (@_) { $i =~ /\d+/ or return 0 }
return 1;
}
sub _ConvTime {
my ($day, $month, $year) = @_;
my ($tm, $days, $mon, $yr);
$mon = $month - 1; $yr = $year - 1900;
$tm = POSIX::mktime(0, 0, 0, $day, $mon, $yr);
$days = ceil($tm / (24 * 60 * 60));
return $days;
}
sub _TimeOfArray {
my ($reltime, $cm) = @_;
my $h; my %mth = (Jan => 1, Feb => 2, Mar => 3, Apr => 4, May => 5, Jun => 6, Jul => 7, Aug => 8, Sep => 9, Oct => 10, Nov => 11, Dec => 12);
my $_t = localtime($reltime * 24 * 60 * 60) =~ /(\S+)\s+(\S+)\s+(\d+)\s+(\S+)\s+(\d+)/;
$h->{daystr} = $1;
$h->{month} = $2;
$h->{dayint} = $3;
$h->{year} = $5;
$cm and $h->{month} = $mth{$2};
$h;
}
no Moose;
__PACKAGE__->meta->make_immutable;
1;
|