summaryrefslogtreecommitdiffstats
path: root/mdk-stage1/rp-pppoe/gui/tkpppoe.in
blob: 37dbf8cc14873de832d5329fd6018258c6f09e87 (plain)
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
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
#!/bin/sh
# -*-Mode: TCL;-*-

#--------------------------------------------------------------
#   tkpppoe
#
#   A graphical front-end for configuring and using rp-pppoe.
#
#   Copyright (C) 2001 by Roaring Penguin Software Inc.
#   This file may be distributed under the terms of the GNU General Public
#   License, Version 2, or (at your option) any later version.
#
#   The "Roaring Penguin" logo is a trademark of Roaring Penguin Software Inc.
#
#   http://www.roaringpenguin.com
#
#--------------------------------------------------------------

# $Id$

# the next line restarts using wish \
umask 022; \
exec wish "$0" "$@" || clear; echo "*****"; echo "Cannot find 'wish' -- you need Tcl/Tk installed to run this program"; exit 1

# Set app name
tk appname TkPPPoE

# Set this to one if you want to allow multiple instances of TkPPPoE
set AllowMultipleInstances 0

# Check for other instances
if {"[tk appname]" != "TkPPPoE"} {
    # Must be another instance running...
    if {!$AllowMultipleInstances} {
	send TkPPPoE AnotherInstance
	exit 0
    }
}

# Location of config directory
set ConfigDir /etc/ppp/rp-pppoe-gui

# Are we running as root?
set Admin 0

# Location of connection info file
set ConnectionInfoFile [file join $ConfigDir connection-info]

# Location of password file
set PasswordFile [file join $ConfigDir passwd]

# Location of "already run" file
set AlreadyRunFile [file join $ConfigDir gui-already-run]

# Connection information
set ConnectionInfo {}

# Connection options
set OPTS(nonroot) 0
set OPTS(sync) 1

# Location of wrapper
set Wrapper "@WRAPPER@"

# Timer token for UpdateConnectionState
set UpdateToken {}

# Update interval in milliseconds
set UpdateInterval 500

# Packet counters for signalling activity
set Packets(in) 0
set Packets(out) 0
set Bytes(in) 0
set Bytes(out) 0
set MeasureTime 0

# Set up some options to make it look better
option add *Button.borderWidth 1
option add *Button.Pad 1
option add *Menubutton.borderWidth 1
option add *Menubutton.Pad 1
option add *Entry.Background white

# Array holding help strings for windows
array set HelpData {}

bind HelpWin <Enter> "HelpWindowEntered %W"
bind HelpWin <Leave> "HelpWindowLeft %W"

proc AnotherInstance {} {
    wm deiconify .
    raise .
}

#***********************************************************************
# %PROCEDURE: HelpWindowEntered
# %ARGUMENTS:
#  w -- window
# %RETURNS:
#  Nothing
# %DESCRIPTION:
#  Looks for procedure in HelpData; evals it if found.
#***********************************************************************
proc HelpWindowEntered { w } {
    global HelpData
    if {[info exists HelpData($w)]} {
	set cmd "$HelpData($w) Enter"
	uplevel #0 $cmd
    }
}

#***********************************************************************
# %PROCEDURE: HelpWindowLeft
# %ARGUMENTS:
#  w -- window
# %RETURNS:
#  Nothing
# %DESCRIPTION:
#  Looks for procedure in HelpData; evals it if found.
#***********************************************************************
proc HelpWindowLeft { w } {
    global HelpData
    if {[info exists HelpData($w)]} {
	set cmd "$HelpData($w) Leave"
	uplevel #0 $cmd
    }
}

#***********************************************************************
# %PROCEDURE: RegisterHelpWindow
# %ARGUMENTS:
#  w -- window we need help about
#  helptext -- the help text
#  win -- window in which to put help messages
# %RETURNS:
#  Nothing
# %DESCRIPTION:
#  Sets things up so help text appears in "$win" when mouse enters "$w"
#***********************************************************************
proc RegisterHelpWindow {w helptext win} {
    global HelpData
    set tags [bindtags $w]
    if {[lsearch -exact $tags HelpWin] < 0} {
	lappend tags HelpWin
	bindtags $w $tags
    }
    set HelpData($w) [list HelpInTextWin $helptext $win]
}

#***********************************************************************
# %PROCEDURE: HelpInTextWin
# %ARGUMENTS:
#  text -- help text
#  tw -- window in which to write text
#  what -- one of "Enter" or "Leave"
# %RETURNS:
#  Nothing
# %DESCRIPTION:
#  Clears out $tw; if $what is "Enter", puts $text in $tw.
#***********************************************************************
proc HelpInTextWin {text tw what} {
    $tw configure -state normal
    $tw delete 1.0 end
    if {"$what" == "Enter"} {
	$tw insert end $text
    }
    $tw configure -state disabled
}


#***********************************************************************
# %PROCEDURE: drawLogo
# %ARGUMENTS:
#  c -- canvas to draw logo in
#  bg -- background color of canvas
#  pencolor -- color of the word "Penguin"
# %RETURNS:
#  Nothing
# %DESCRIPTION:
#  Draws Roaring Penguin logo in a Tcl canvas
#***********************************************************************
proc drawLogo { c bg {pengcolor #6699cc} } {
    $c create polygon 372.249 5.182 361.23 5.519 \
	    346.164 8.892 316.482 20.023 305.463 17.774 296.468 \
	    19.573 288.935 24.97 282.864 33.177 267.348 55.102 \
	    254.531 77.814 236.204 125.26 225.635 174.844 \
	    221.026 226.113 213.605 228.025 208.658 232.634 \
	    225.523 240.28 250.708 243.316 282.752 242.416 \
	    320.079 238.818 330.985 193.17 338.181 146.735 \
	    338.743 99.963 335.483 76.577 329.524 53.191 345.602 \
	    48.131 353.135 45.995 359.768 41.048 342.679 43.184 \
	    324.689 40.036 334.583 28.905 348.3 18.674 372.249 \
	    5.182 -fill #000000 -outline {} -width 1 -tags logo

    $c create line 372.249 5.182 361.23 5.519 \
	    346.164 8.892 316.482 20.023 305.463 17.774 296.468 \
	    19.573 288.935 24.97 282.864 33.177 267.348 55.102 \
	    254.531 77.814 236.204 125.26 225.635 174.844 \
	    221.026 226.113 213.605 228.025 208.658 232.634 \
	    225.523 240.28 250.708 243.316 282.752 242.416 \
	    320.079 238.818 330.985 193.17 338.181 146.735 \
	    338.743 99.963 335.483 76.577 329.524 53.191 345.602 \
	    48.131 353.135 45.995 359.768 41.048 342.679 43.184 \
	    324.689 40.036 334.583 28.905 348.3 18.674 372.249 \
	    5.182  -tags logo

    $c create polygon 298.605 109.632 290.734 \
	    159.328 282.752 182.939 271.958 205.65 262.851 \
	    171.133 263.75 138.752 264.537 164.5 271.958 192.833 \
	    286.687 157.192 298.605 109.632 -fill #ffffff \
	    -outline {} -width 1  -tags logo

    $c create line 298.605 109.632 290.734 159.328 \
	    282.752 182.939 271.958 205.65 262.851 171.133 \
	    263.75 138.752 264.537 164.5 271.958 192.833 286.687 \
	    157.192 298.605 109.632  -tags logo

    $c create polygon 312.546 30.592 315.132 35.876 \
	    310.747 39.586 308.161 34.414 312.546 30.592 -fill \
	    #ffffff -outline {} -width 1  -tags logo

    $c create line 312.546 30.592 315.132 35.876 \
	    310.747 39.586 308.161 34.414 312.546 30.592  -tags logo

    $c create polygon 328.624 54.427 322.665 58.7 \
	    314.458 61.286 289.16 59.15 284.55 74.665 285.338 \
	    90.181 303.214 98.951 308.499 106.259 310.523 \
	    116.378 305.913 130.208 312.771 141.563 308.049 \
	    167.76 299.729 192.158 279.041 238.593 313.558 \
	    233.871 327.388 185.75 335.033 139.989 335.82 96.253 \
	    328.624 54.427 -fill #ffffff -outline {} -width 1  -tags logo

    $c create line 328.624 54.427 322.665 58.7 \
	    314.458 61.286 289.16 59.15 284.55 74.665 285.338 \
	    90.181 303.214 98.951 308.499 106.259 310.523 \
	    116.378 305.913 130.208 312.771 141.563 308.049 \
	    167.76 299.729 192.158 279.041 238.593 313.558 \
	    233.871 327.388 185.75 335.033 139.989 335.82 96.253 \
	    328.624 54.427  -tags logo

    $c create polygon 53.837 185.412 54.399 185.862 \
	    53.837 188.223 54.399 188.673 53.837 188.673 53.837 \
	    189.572 53.837 190.472 53.387 191.034 52.938 192.833 \
	    50.577 195.644 49.677 196.656 49.677 197.105 48.215 \
	    198.455 47.316 198.904 46.866 198.904 44.505 200.816 \
	    43.606 200.366 42.594 201.265 42.144 201.715 41.245 \
	    202.277 40.795 202.727 40.345 202.277 39.783 202.277 \
	    36.972 203.177 36.522 203.177 36.073 203.177 35.623 \
	    203.627 34.723 203.627 34.161 203.627 34.161 204.076 \
	    30.901 204.526 28.54 205.538 26.291 205.088 25.729 \
	    205.088 24.829 205.088 24.38 204.526 23.93 204.526 \
	    23.48 204.526 22.918 205.088 22.918 206.437 22.918 \
	    206.887 22.918 207.337 22.468 207.337 22.468 208.798 \
	    22.018 209.248 22.018 211.16 22.018 211.609 21.569 \
	    213.521 21.119 215.769 21.569 216.781 20.669 218.13 \
	    20.669 219.592 20.669 220.042 20.107 220.941 20.107 \
	    221.953 20.107 223.752 19.657 225.664 19.208 226.113 \
	    19.657 227.013 18.308 230.835 17.858 240.167 17.296 \
	    248.15 17.296 249.05 16.846 250.062 15.947 250.062 \
	    15.048 250.062 15.048 250.511 12.686 251.86 12.237 \
	    251.86 11.675 251.411 11.675 250.511 11.675 246.689 \
	    11.225 245.339 11.225 243.878 10.775 240.617 11.225 \
	    239.268 11.225 238.818 10.775 238.256 10.325 237.357 \
	    10.325 236.007 9.876 232.634 9.876 231.735 9.876 \
	    231.285 9.876 230.835 9.876 230.386 9.876 229.824 \
	    9.426 229.374 9.426 226.113 9.876 226.113 9.876 \
	    225.664 9.426 224.202 9.426 223.752 9.426 223.302 \
	    10.325 221.953 9.426 220.941 9.426 219.592 9.426 \
	    219.142 9.426 218.58 9.426 217.681 9.426 217.231 \
	    9.426 216.781 8.864 216.332 8.864 214.42 8.864 \
	    213.97 8.414 213.521 8.414 210.148 8.414 209.248 \
	    7.964 207.899 8.414 205.988 8.414 204.526 7.065 \
	    201.265 7.515 200.816 9.426 201.715 10.325 201.265 \
	    10.775 200.816 10.775 198.904 11.225 198.005 11.225 \
	    197.555 10.775 197.555 9.876 196.094 9.426 194.744 \
	    7.515 194.295 6.615 193.845 6.053 193.845 5.153 \
	    193.283 3.804 191.484 3.804 190.022 3.804 189.572 \
	    3.804 189.123 3.242 188.673 3.242 186.762 3.804 \
	    185.412 4.254 184.85 4.704 184.4 7.964 180.24 10.325 \
	    178.779 11.225 178.779 12.237 177.879 14.036 176.98 \
	    15.497 175.968 21.569 173.607 22.918 173.157 23.48 \
	    173.157 24.38 172.707 24.829 172.707 29.102 171.808 \
	    29.551 171.808 30.001 171.358 31.35 170.796 31.913 \
	    171.358 32.362 170.796 39.783 171.358 40.345 170.796 \
	    42.144 171.358 47.766 174.619 48.778 176.418 49.227 \
	    176.418 49.677 176.98 50.127 176.98 51.588 178.329 \
	    52.038 179.228 52.488 180.69 52.038 181.14 52.038 \
	    181.59 52.488 182.039 52.938 182.039 53.387 182.601 \
	    53.837 183.051 53.837 183.501 53.837 185.412 -fill \
	    $pengcolor -outline {} -width 1  -tags logo

    $c create polygon 42.594 222.853 43.156 221.953 \
	    41.694 222.403 39.783 224.202 39.783 224.764 39.783 \
	    225.214 40.345 225.214 41.245 224.202 41.694 223.752 \
	    42.594 222.853 -fill $pengcolor -outline {} -width 1  -tags logo

    $c create polygon 58.559 234.096 59.009 234.096 \
	    59.009 234.546 58.559 234.995 58.559 235.445 57.21 \
	    236.907 56.648 237.806 52.938 241.067 52.038 241.629 \
	    52.038 242.079 51.026 242.529 50.577 242.978 50.127 \
	    242.978 49.227 244.44 45.405 246.239 44.055 246.689 \
	    43.606 246.689 43.606 247.251 42.144 247.251 41.694 \
	    247.7 40.795 247.7 38.434 248.15 36.522 248.15 \
	    35.173 247.7 34.161 246.689 33.711 246.239 32.812 \
	    244.44 32.362 241.629 32.812 239.718 32.812 239.268 \
	    33.711 234.995 36.522 229.824 35.623 228.474 35.623 \
	    227.013 36.522 225.664 37.534 224.202 38.883 222.853 \
	    41.694 220.492 42.594 219.592 43.156 219.592 43.606 \
	    219.142 45.405 217.681 45.967 217.681 46.416 217.231 \
	    48.778 215.769 52.038 214.87 53.387 214.42 54.849 \
	    214.87 55.299 214.87 56.198 215.769 56.198 217.681 \
	    56.198 218.58 54.399 221.953 53.837 222.853 53.837 \
	    223.302 53.387 223.752 50.577 226.113 49.677 226.563 \
	    47.316 228.474 43.156 230.386 41.245 230.835 40.795 \
	    230.835 40.345 230.835 39.333 230.835 38.883 230.835 \
	    38.883 229.824 39.783 229.374 40.795 228.474 41.694 \
	    228.025 42.594 227.575 45.967 227.013 46.866 226.563 \
	    50.127 224.764 51.588 223.302 52.488 221.953 52.488 \
	    220.492 52.488 219.142 51.026 218.13 49.677 218.13 \
	    48.778 218.13 47.766 219.142 47.316 219.142 47.316 \
	    219.592 46.866 219.592 45.967 220.941 44.505 221.953 \
	    44.055 222.403 43.606 222.853 42.594 223.752 41.694 \
	    225.664 41.245 225.664 41.245 226.113 40.345 226.563 \
	    39.333 227.575 39.333 228.474 38.434 229.374 36.522 \
	    233.197 35.623 236.457 35.623 237.357 35.623 238.256 \
	    35.173 241.067 35.623 242.079 36.522 243.428 37.534 \
	    243.878 37.984 244.44 38.434 244.89 38.883 244.89 \
	    39.783 245.339 43.156 245.339 45.967 244.44 49.227 \
	    242.529 50.127 241.629 50.577 241.067 54.399 238.818 \
	    54.399 238.256 54.399 237.806 56.198 236.907 58.559 \
	    234.096 -fill $pengcolor -outline {} -width 1  -tags logo

    $c create polygon 92.289 248.6 92.739 249.05 \
	    92.289 249.05 91.84 249.05 90.94 248.6 90.378 248.6 \
	    89.478 247.7 89.029 247.251 88.129 246.689 87.117 \
	    245.789 85.768 244.89 85.318 244.44 85.768 244.44 \
	    85.318 242.529 84.756 242.079 84.756 240.617 84.756 \
	    240.167 84.756 239.718 84.756 239.268 83.857 236.457 \
	    83.407 234.096 83.407 233.197 83.407 231.735 83.407 \
	    223.302 83.407 221.391 82.957 220.941 82.508 221.953 \
	    80.596 226.113 80.146 226.563 80.146 227.013 79.697 \
	    228.025 79.135 228.474 79.697 228.474 76.324 234.096 \
	    75.874 234.995 75.424 236.457 74.975 236.457 74.975 \
	    236.907 74.975 237.357 74.075 239.268 73.513 239.718 \
	    73.063 240.167 72.613 241.067 72.164 242.529 71.714 \
	    242.529 71.714 243.878 70.252 245.789 69.803 246.689 \
	    68.903 246.689 68.903 247.251 67.891 247.7 66.542 \
	    247.7 66.092 247.7 65.643 247.7 65.08 247.251 65.08 \
	    246.689 65.08 245.789 64.631 242.079 65.08 242.079 \
	    64.631 241.629 65.08 241.067 65.08 238.818 64.631 \
	    237.806 64.631 236.457 64.631 234.546 64.631 233.197 \
	    64.631 232.634 64.631 232.185 64.631 231.735 64.631 \
	    228.924 64.631 227.575 64.631 225.664 64.631 225.214 \
	    64.631 224.764 64.631 223.302 64.631 217.231 65.08 \
	    216.332 65.643 215.769 69.803 214.87 70.252 215.32 \
	    70.252 216.332 70.252 217.681 70.252 218.58 69.803 \
	    219.142 69.803 220.492 69.353 220.941 69.353 221.391 \
	    68.903 221.953 68.903 225.664 68.453 226.563 68.453 \
	    228.025 68.453 228.474 67.891 228.924 67.891 230.835 \
	    68.453 236.457 68.453 237.806 68.453 238.818 68.453 \
	    240.617 68.453 241.067 68.903 241.067 68.903 241.629 \
	    69.353 241.629 70.702 241.067 70.702 240.617 71.264 \
	    240.167 71.264 239.268 72.164 238.256 73.063 236.457 \
	    74.525 234.546 74.975 233.197 76.324 230.835 77.336 \
	    229.824 78.235 227.575 78.235 227.013 78.685 226.563 \
	    78.685 225.664 79.135 225.214 79.697 224.764 79.697 \
	    224.202 80.146 222.403 81.046 220.941 81.945 217.681 \
	    82.957 215.769 85.318 214.87 85.768 214.87 87.567 \
	    214.42 87.567 215.769 87.117 216.332 87.567 216.781 \
	    88.129 219.592 87.567 219.592 87.567 220.492 87.567 \
	    221.391 87.567 224.764 87.567 225.664 87.567 226.113 \
	    87.117 226.113 87.117 227.575 87.567 229.374 88.579 \
	    235.445 89.029 239.268 89.029 239.718 89.029 241.067 \
	    89.478 242.529 89.478 242.978 89.928 243.878 89.928 \
	    244.44 90.378 244.89 90.94 246.239 92.289 248.6 \
	    -fill $pengcolor -outline {} -width 1  -tags logo

    $c create polygon 117.587 220.492 118.037 \
	    222.403 117.587 222.853 117.587 224.764 116.687 \
	    226.113 116.687 227.013 116.238 228.025 114.776 \
	    229.374 113.877 231.285 112.865 231.735 109.154 \
	    234.995 106.343 236.457 105.444 237.357 103.982 \
	    237.806 103.083 238.256 102.633 238.818 102.183 \
	    238.818 101.172 239.268 99.822 239.718 98.361 \
	    239.268 97.461 239.718 96.562 239.268 96.0 238.818 \
	    95.55 238.818 94.201 236.907 94.201 235.445 94.201 \
	    233.646 94.65 233.197 94.65 232.634 95.1 232.185 \
	    95.1 231.735 95.55 231.735 96.0 230.386 97.461 \
	    228.025 97.461 227.575 98.361 226.563 99.822 224.764 \
	    101.172 223.302 101.172 222.853 102.633 221.391 \
	    103.083 220.941 104.432 219.592 103.982 218.58 \
	    103.982 217.231 103.982 216.781 103.982 215.32 \
	    104.432 214.42 103.982 210.148 103.982 209.698 \
	    103.982 209.248 104.432 208.798 104.432 207.899 \
	    104.432 205.988 104.432 205.538 104.994 203.177 \
	    104.994 202.277 104.994 201.265 104.994 200.816 \
	    104.994 200.366 104.994 199.916 105.894 199.467 \
	    106.343 198.904 106.793 198.455 107.243 198.904 \
	    108.255 198.904 108.255 199.467 108.705 199.467 \
	    108.705 202.727 108.255 204.076 108.255 205.538 \
	    108.255 205.988 107.805 205.988 107.805 206.887 \
	    107.805 209.698 107.243 210.71 106.793 212.059 \
	    106.343 214.87 106.343 215.32 106.343 215.769 \
	    105.894 217.681 106.343 217.681 106.793 217.681 \
	    107.243 217.231 108.705 215.32 109.604 215.32 \
	    110.054 214.42 110.054 213.97 110.616 213.97 110.616 \
	    214.42 111.965 214.87 112.415 214.87 112.865 215.32 \
	    114.326 216.332 116.238 217.681 116.687 218.58 \
	    117.137 219.592 117.587 220.042 117.587 220.492 \
	    -fill $pengcolor -outline {} -width 1  -tags logo

    $c create polygon 123.658 258.944 123.658 \
	    259.394 123.658 260.293 123.658 261.755 123.658 \
	    262.654 123.658 263.104 123.209 266.364 123.209 \
	    267.376 122.759 269.175 122.309 269.737 121.859 \
	    271.087 121.859 271.536 121.859 271.986 121.297 \
	    271.986 121.297 272.548 120.847 273.448 120.398 \
	    273.448 120.398 273.897 118.486 276.259 118.037 \
	    276.708 117.587 277.608 117.137 278.17 116.687 \
	    278.17 115.675 278.62 115.675 279.069 113.427 \
	    280.419 112.865 280.981 112.415 280.981 111.965 \
	    281.43 110.054 282.33 109.154 282.33 108.705 282.78 \
	    108.255 282.78 107.805 283.229 104.994 283.792 \
	    104.432 283.792 103.982 283.792 103.533 283.792 \
	    103.083 283.792 102.633 283.792 102.183 283.792 \
	    101.172 283.792 100.722 283.792 99.822 283.792 98.81 \
	    283.792 96.562 282.33 96.0 282.78 95.1 281.88 94.201 \
	    281.43 91.84 279.969 92.289 279.519 92.289 278.62 \
	    93.751 279.069 93.751 279.519 94.201 279.519 94.65 \
	    279.969 95.1 279.969 96.0 280.981 98.81 281.88 \
	    101.172 281.88 101.621 281.88 102.633 281.88 103.083 \
	    281.88 103.533 281.88 104.432 281.43 104.994 281.88 \
	    105.444 281.43 106.793 281.43 107.805 280.981 \
	    108.705 280.419 109.154 280.419 109.604 279.969 \
	    110.054 279.969 110.616 279.969 111.066 279.519 \
	    112.865 278.17 113.427 277.608 113.877 277.608 \
	    113.877 277.158 114.326 277.158 114.326 276.708 \
	    114.776 276.259 115.226 276.259 116.238 274.347 \
	    116.687 274.347 116.687 273.897 117.587 272.998 \
	    117.587 272.548 118.037 271.986 119.498 267.826 \
	    120.398 265.015 120.398 262.204 119.948 259.843 \
	    119.948 259.394 119.948 258.944 119.498 257.482 \
	    118.486 254.222 118.037 253.772 117.587 251.86 \
	    115.675 249.05 115.226 248.6 114.776 248.15 113.877 \
	    247.251 111.965 246.239 111.515 246.239 110.616 \
	    246.239 110.054 246.239 109.154 246.239 107.243 \
	    247.251 106.343 247.251 105.444 247.7 104.994 247.7 \
	    103.083 248.15 102.183 248.6 101.621 248.6 101.172 \
	    249.05 100.722 249.499 99.822 250.062 98.361 250.062 \
	    97.461 249.499 97.012 249.499 96.562 249.05 96.562 \
	    248.6 97.012 248.15 99.822 245.789 100.272 245.339 \
	    101.621 244.44 101.621 243.878 102.183 243.428 \
	    102.633 243.428 102.633 242.978 103.982 241.629 \
	    103.982 241.067 103.982 240.617 103.982 240.167 \
	    105.444 239.268 108.705 236.907 108.705 236.457 \
	    109.154 236.457 110.054 235.445 111.066 234.546 \
	    112.415 234.096 112.865 233.646 113.427 233.646 \
	    113.877 233.646 113.877 234.096 114.326 234.995 \
	    114.776 235.445 114.776 236.457 114.326 237.357 \
	    113.427 238.818 112.415 239.268 112.415 240.167 \
	    111.965 240.167 111.515 240.617 110.054 241.629 \
	    110.054 242.079 109.604 242.529 108.705 242.978 \
	    110.054 242.978 113.427 242.079 114.326 242.529 \
	    115.226 242.978 116.687 244.44 119.048 246.689 \
	    119.498 247.7 119.498 248.15 119.948 248.6 119.948 \
	    249.05 120.398 249.05 120.398 249.499 120.847 \
	    249.499 120.847 250.062 121.297 250.511 121.297 \
	    251.411 121.859 252.31 122.759 252.872 122.759 \
	    254.222 122.759 254.671 123.658 258.494 123.658 \
	    258.944 -fill $pengcolor -outline {} -width 1  -tags logo

    $c create polygon 147.607 215.769 148.506 215.32 \
	    148.506 217.231 148.506 217.681 148.506 218.13 \
	    148.956 218.58 148.506 220.492 148.506 220.941 \
	    148.506 222.853 148.956 224.764 148.956 226.113 \
	    148.506 226.563 148.956 226.563 148.506 228.924 \
	    148.956 229.824 148.956 231.285 148.506 232.185 \
	    148.956 232.634 148.956 233.646 149.405 234.995 \
	    148.956 234.995 149.405 235.445 149.405 236.907 \
	    149.405 237.357 149.968 238.818 150.867 240.167 \
	    150.867 240.617 151.317 242.079 152.216 243.428 \
	    153.228 245.339 154.128 245.789 155.027 246.239 \
	    156.939 245.789 157.388 246.239 156.489 246.689 \
	    155.027 247.7 154.128 247.7 153.228 247.7 152.216 \
	    247.7 151.767 247.7 150.867 247.251 150.417 246.239 \
	    149.405 246.239 148.056 245.339 147.607 244.44 \
	    147.157 243.428 145.695 241.629 145.695 240.617 \
	    145.245 240.167 145.245 239.718 144.796 238.256 \
	    144.346 236.907 144.346 235.445 143.784 234.546 \
	    143.784 233.197 143.784 232.185 143.784 230.835 \
	    143.334 229.824 143.784 229.374 143.334 229.374 \
	    143.334 228.474 142.884 230.386 141.985 231.735 \
	    140.973 233.197 140.523 234.096 140.523 234.546 \
	    140.523 234.995 139.624 236.457 139.174 237.806 \
	    138.162 239.718 137.263 241.067 136.813 242.079 \
	    135.913 242.978 134.452 244.89 134.002 245.789 \
	    133.552 245.789 132.091 246.689 131.191 247.251 \
	    129.73 248.15 129.28 248.15 128.38 247.7 128.38 \
	    248.15 126.919 247.7 126.019 247.251 125.12 246.239 \
	    125.12 245.339 124.67 244.89 124.67 244.44 124.67 \
	    243.428 124.67 242.529 124.67 241.067 124.67 239.718 \
	    125.12 239.268 124.67 239.268 124.67 238.256 125.12 \
	    237.806 125.12 237.357 125.12 236.907 125.12 236.007 \
	    125.12 234.096 125.57 233.197 125.57 232.185 126.019 \
	    232.185 126.019 231.285 126.019 230.386 126.019 \
	    229.374 126.469 228.474 126.469 227.013 126.469 \
	    225.214 126.019 225.214 126.469 225.214 126.019 \
	    223.302 126.019 221.953 126.019 220.492 125.57 \
	    220.042 125.12 219.592 124.108 219.142 123.209 \
	    219.142 121.859 220.042 121.297 220.042 120.398 \
	    220.941 119.498 221.391 119.048 221.391 118.486 \
	    221.953 118.037 221.953 118.037 221.391 118.486 \
	    220.941 119.498 220.042 120.847 219.142 122.759 \
	    217.681 124.108 216.781 125.12 215.769 126.469 \
	    214.87 126.919 214.87 127.481 214.87 128.38 214.87 \
	    128.83 214.87 129.73 214.87 129.73 215.769 130.292 \
	    215.769 130.742 216.781 130.742 217.681 130.292 \
	    219.142 130.292 221.953 130.292 223.302 130.292 \
	    224.202 129.73 225.214 129.28 227.013 128.83 227.575 \
	    129.28 227.575 129.28 228.474 128.83 229.374 129.28 \
	    229.824 129.28 230.386 128.83 231.735 128.38 234.096 \
	    128.38 234.995 127.931 236.457 127.931 239.268 \
	    127.931 240.167 127.931 241.629 128.83 242.978 \
	    129.28 243.878 129.73 244.44 130.742 244.44 131.191 \
	    244.44 132.091 244.44 133.103 243.878 134.002 \
	    242.978 134.902 242.079 135.351 241.067 135.913 \
	    240.167 136.363 239.268 136.813 238.818 137.263 \
	    237.806 137.712 236.907 138.162 235.445 138.724 \
	    234.546 139.174 233.646 139.624 232.634 140.523 \
	    230.835 140.973 228.924 141.535 227.013 142.435 \
	    225.664 142.884 223.302 143.334 221.391 143.334 \
	    220.941 143.334 219.142 144.346 217.681 144.796 \
	    216.781 145.695 216.332 146.595 216.332 147.607 \
	    215.769 -fill $pengcolor -outline {} -width 1  -tags logo

    $c create polygon 165.371 241.067 165.371 \
	    241.067 164.921 243.878 164.921 246.239 163.46 \
	    246.689 161.211 247.251 160.649 247.251 160.199 \
	    244.44 160.199 243.878 160.199 243.428 160.199 \
	    242.079 160.199 240.167 160.199 239.718 159.749 \
	    239.268 160.199 237.806 159.749 237.357 159.749 \
	    236.007 159.749 230.835 159.749 229.824 159.749 \
	    228.924 159.749 226.113 159.749 225.664 159.749 \
	    223.752 159.749 222.853 159.749 218.58 159.749 \
	    218.13 159.749 217.681 160.199 217.231 161.661 \
	    216.781 162.11 216.781 162.56 216.781 163.46 216.781 \
	    164.022 219.142 163.46 222.403 163.46 222.853 163.46 \
	    224.202 163.46 225.664 163.46 226.563 163.46 227.013 \
	    163.46 228.924 163.01 230.835 163.01 232.634 163.46 \
	    233.197 164.022 232.634 164.472 232.634 164.921 \
	    232.185 164.921 231.735 165.371 231.735 165.821 \
	    232.185 165.371 233.646 165.821 236.007 165.371 \
	    238.256 165.371 238.818 165.371 240.617 165.371 \
	    241.067 -fill $pengcolor -outline {} -width 1  -tags logo

    $c create polygon 165.821 214.42 166.833 215.32 \
	    166.271 215.32 165.821 216.332 165.371 216.332 \
	    165.371 216.781 165.821 217.681 165.821 218.13 \
	    165.371 219.142 165.371 220.042 164.921 222.853 \
	    165.371 224.764 164.921 225.664 165.371 227.575 \
	    165.371 228.474 164.921 228.474 164.472 227.575 \
	    164.472 226.113 164.022 224.764 164.472 224.202 \
	    164.472 223.752 164.472 222.403 164.921 214.87 \
	    164.472 213.521 164.472 212.959 164.472 212.509 \
	    164.022 212.509 163.46 212.509 163.01 212.959 162.56 \
	    212.959 161.661 212.959 161.211 212.059 161.211 \
	    211.609 160.649 211.609 160.199 209.698 160.649 \
	    208.349 163.46 206.437 164.472 206.437 165.821 \
	    207.899 165.821 208.349 166.833 210.148 166.833 \
	    210.71 165.821 211.609 165.371 212.059 165.371 \
	    212.959 165.821 213.97 165.821 214.42 -fill $pengcolor \
	    -outline {} -width 1  -tags logo

    $c create polygon 201.462 248.6 201.462 249.05 \
	    201.012 249.05 200.563 249.05 200.001 248.6 199.551 \
	    248.6 198.651 247.7 197.752 247.251 196.74 246.689 \
	    196.29 245.789 194.379 244.89 194.379 244.44 194.379 \
	    242.529 193.929 242.079 193.479 240.617 193.479 \
	    240.167 193.929 239.718 193.479 239.268 193.03 \
	    236.457 192.58 234.096 192.58 233.197 192.58 231.735 \
	    192.58 223.302 192.58 221.391 192.13 220.941 191.568 \
	    221.953 189.769 226.113 189.319 226.563 189.319 \
	    227.013 188.757 228.025 188.307 228.474 188.757 \
	    228.474 185.497 234.096 185.047 234.995 184.597 \
	    236.457 184.147 236.457 184.147 236.907 184.147 \
	    237.357 183.136 239.268 182.686 239.268 182.686 \
	    239.718 182.236 240.167 181.786 241.067 181.337 \
	    242.529 180.887 242.529 180.887 243.878 179.425 \
	    245.789 178.975 246.689 178.076 246.689 178.076 \
	    247.251 177.064 247.7 175.715 247.7 175.265 247.7 \
	    174.703 247.7 174.253 247.251 174.253 246.689 \
	    174.253 245.789 173.804 242.079 174.253 242.079 \
	    173.804 241.629 173.804 241.067 173.804 238.818 \
	    173.804 237.806 173.804 236.457 173.354 234.546 \
	    173.354 233.197 173.804 232.634 173.804 232.185 \
	    173.804 231.735 173.804 228.924 173.354 227.575 \
	    173.804 227.575 173.804 225.664 173.804 225.214 \
	    173.804 224.764 173.804 223.302 173.804 217.231 \
	    174.253 216.332 174.703 215.769 178.526 214.87 \
	    179.425 215.32 179.425 216.332 179.425 217.681 \
	    179.425 218.58 178.975 219.142 178.526 220.492 \
	    178.526 220.941 178.076 221.391 178.076 221.953 \
	    178.076 225.664 177.514 226.563 177.514 228.025 \
	    177.064 228.474 177.064 228.924 177.064 230.835 \
	    177.514 236.457 177.064 237.806 177.514 237.806 \
	    177.514 238.818 177.514 240.617 177.514 241.067 \
	    178.076 241.629 178.526 241.629 179.425 241.067 \
	    179.875 240.617 179.875 240.167 180.325 239.268 \
	    181.337 238.256 182.236 236.457 183.698 234.546 \
	    184.147 233.197 185.497 230.835 186.509 229.824 \
	    187.408 227.575 187.408 227.013 187.408 226.563 \
	    187.858 225.664 188.307 225.214 188.757 224.764 \
	    188.757 224.202 189.319 222.403 190.219 220.941 \
	    191.118 217.681 192.13 215.769 194.379 214.87 \
	    194.941 214.87 196.74 214.42 196.74 215.769 196.29 \
	    215.769 196.29 216.332 196.29 216.781 196.74 219.592 \
	    196.74 220.492 196.29 221.391 196.74 224.764 196.29 \
	    225.664 196.29 226.113 196.29 227.575 196.74 229.374 \
	    197.19 235.445 198.202 239.268 198.202 239.718 \
	    198.202 241.067 198.202 242.529 198.651 242.978 \
	    199.101 243.878 199.101 244.44 199.551 244.89 \
	    200.001 246.239 201.462 248.6 -fill $pengcolor -outline \
	    {} -width 1  -tags logo

    $c create polygon 71.714 185.412 71.714 110.869 \
	    81.496 110.869 82.845 110.981 83.969 111.431 85.094 \
	    112.106 86.105 113.118 86.893 114.467 87.567 116.041 \
	    88.017 117.39 88.242 118.065 88.467 118.852 88.579 \
	    119.639 88.804 120.538 88.916 121.438 89.029 122.337 \
	    89.141 123.349 89.254 124.361 89.366 125.485 89.366 \
	    126.61 89.478 127.734 89.478 128.971 89.478 130.208 \
	    89.478 131.444 89.478 132.456 89.478 133.468 89.478 \
	    134.48 89.366 135.492 89.254 136.391 89.254 137.291 \
	    89.141 138.19 89.029 139.09 88.916 139.877 88.804 \
	    140.664 88.691 141.451 88.579 142.238 88.354 143.362 \
	    88.129 144.374 87.904 145.386 87.567 146.398 87.342 \
	    147.297 87.005 148.197 86.668 148.984 86.218 149.771 \
	    87.005 151.233 87.342 152.02 87.68 152.919 87.904 \
	    153.931 88.129 154.943 88.129 155.505 88.354 156.854 \
	    88.354 157.641 88.354 158.428 88.467 159.328 88.467 \
	    160.34 88.467 161.352 88.467 162.476 88.579 163.6 \
	    88.579 164.837 88.579 166.186 88.579 166.973 88.691 \
	    167.873 88.804 168.885 88.916 169.897 89.029 171.021 \
	    89.029 172.258 89.029 173.719 89.029 175.068 89.029 \
	    176.305 89.029 177.542 89.141 178.554 89.141 179.566 \
	    89.141 180.353 89.141 181.14 89.254 181.814 89.366 \
	    182.714 89.478 183.051 89.478 185.412 83.857 185.412 \
	    83.857 184.738 83.744 183.951 83.744 183.276 83.744 \
	    182.489 83.744 180.803 83.857 179.791 83.857 178.891 \
	    83.857 177.879 83.857 176.867 83.857 175.743 83.857 \
	    174.619 83.857 173.27 83.857 172.033 83.744 170.908 \
	    83.744 170.009 83.632 169.109 83.632 168.322 83.52 \
	    166.973 83.407 166.524 83.407 166.186 83.407 165.062 \
	    83.407 164.05 83.295 163.151 83.295 162.251 83.295 \
	    161.464 83.182 160.789 82.957 159.553 81.945 158.203 \
	    80.596 157.754 76.886 157.754 76.886 185.412 71.714 \
	    185.412 -fill #000000 -outline {} -width 1  -tags logo

    $c create polygon 92.289 148.309 92.289 147.185 \
	    92.289 146.061 92.289 145.049 92.402 143.924 92.402 \
	    142.8 92.402 141.788 92.402 140.664 92.514 139.652 \
	    92.514 138.64 92.627 137.628 92.627 136.616 92.739 \
	    135.717 92.739 134.705 92.851 133.805 92.964 132.793 \
	    92.964 131.894 93.076 130.995 93.301 129.196 93.414 \
	    128.409 93.526 127.509 93.639 126.722 93.751 125.935 \
	    93.863 125.148 93.976 124.361 94.313 122.787 94.426 \
	    122.112 94.65 121.325 94.763 120.651 95.1 119.301 \
	    95.55 117.615 96.112 116.041 96.674 114.692 97.236 \
	    113.455 97.799 112.443 98.361 111.544 99.035 110.757 \
	    99.71 110.082 100.385 109.632 101.059 109.295 \
	    101.846 109.07 102.633 108.958 104.207 109.295 \
	    104.882 109.632 105.556 110.082 106.231 110.757 \
	    106.906 111.544 107.468 112.443 108.03 113.455 \
	    108.592 114.692 109.154 116.041 109.604 117.615 \
	    110.054 119.301 110.279 119.976 110.616 121.325 \
	    110.841 122.112 110.953 122.787 111.178 123.574 \
	    111.403 125.148 111.628 125.935 111.74 126.722 \
	    111.853 127.622 111.965 128.409 112.078 129.308 \
	    112.19 130.208 112.302 130.995 112.415 132.006 \
	    112.64 133.805 112.752 134.817 112.865 135.717 \
	    112.977 136.729 112.977 137.741 113.089 138.752 \
	    113.089 139.764 113.202 140.776 113.202 141.788 \
	    113.314 142.912 113.314 143.924 113.314 145.049 \
	    113.427 146.061 113.427 147.185 113.427 148.309 \
	    113.427 149.546 113.314 150.783 113.314 151.907 \
	    113.314 153.032 113.314 154.156 113.202 155.28 \
	    113.202 156.405 113.089 157.529 113.089 158.541 \
	    112.977 159.553 112.865 160.565 112.752 161.576 \
	    112.64 162.588 112.527 163.6 112.415 164.5 112.302 \
	    165.512 112.19 166.411 112.078 167.311 111.965 \
	    168.21 111.853 169.109 111.628 169.897 111.515 \
	    170.796 111.403 171.583 111.178 172.37 111.066 \
	    173.157 110.616 174.731 110.504 175.518 110.279 \
	    176.193 110.054 176.98 109.604 178.666 109.154 \
	    180.128 108.592 181.59 108.03 182.826 107.468 \
	    183.951 106.906 184.963 106.231 185.75 105.556 \
	    186.424 104.882 186.986 104.207 187.436 103.42 \
	    187.661 102.633 187.661 101.846 187.661 101.059 \
	    187.436 100.385 186.986 99.71 186.424 99.035 185.75 \
	    98.361 184.963 97.799 183.951 97.236 182.826 96.674 \
	    181.59 96.112 180.128 95.55 178.666 95.1 176.98 \
	    94.988 176.193 94.763 175.518 94.538 174.731 94.426 \
	    173.944 94.088 172.37 93.976 171.583 93.863 170.796 \
	    93.639 169.897 93.526 169.109 93.414 168.21 93.301 \
	    167.311 93.189 166.411 93.076 165.512 92.964 164.5 \
	    92.964 163.6 92.851 162.588 92.739 161.576 92.627 \
	    160.565 92.627 159.553 92.514 158.541 92.514 157.529 \
	    92.514 156.405 92.402 155.28 92.402 154.156 92.402 \
	    153.032 92.289 151.907 92.289 150.783 92.289 149.546 \
	    92.289 148.309 -fill #000000 -outline {} -width 1  -tags logo

    $c create polygon 121.859 110.869 127.481 \
	    110.869 134.902 185.412 129.28 185.412 127.931 \
	    171.808 120.847 171.808 119.948 185.412 114.326 \
	    185.412 121.859 110.869 -fill #000000 -outline {} \
	    -width 1  -tags logo

    $c create polygon 137.263 185.412 137.263 \
	    110.869 147.157 110.869 148.394 110.981 149.518 \
	    111.431 150.417 112.106 151.317 113.118 152.104 \
	    114.467 152.778 116.041 153.228 117.39 153.341 \
	    118.065 153.566 118.852 153.903 120.538 154.015 \
	    121.438 154.128 122.337 154.24 123.349 154.353 \
	    124.361 154.465 125.485 154.465 126.61 154.577 \
	    127.734 154.577 128.971 154.577 130.208 154.577 \
	    131.444 154.577 132.456 154.577 133.468 154.577 \
	    134.48 154.577 135.492 154.577 136.391 154.577 \
	    137.291 154.577 138.19 154.465 139.09 154.465 \
	    139.877 154.353 140.664 154.24 141.451 154.128 \
	    142.238 153.903 143.362 153.678 144.374 153.341 \
	    145.386 153.003 146.398 152.554 147.297 152.216 \
	    148.197 151.767 148.984 151.317 149.771 152.104 \
	    151.233 152.441 152.02 152.778 152.919 153.003 \
	    153.931 153.228 154.943 153.341 155.505 153.453 \
	    156.854 153.566 157.641 153.678 158.428 153.79 \
	    159.328 153.903 160.34 154.015 161.352 154.015 \
	    162.476 154.128 163.6 154.128 164.837 154.128 \
	    166.186 154.128 166.973 154.128 167.873 154.128 \
	    168.885 154.128 169.897 154.128 171.021 154.128 \
	    172.258 154.128 173.719 154.24 175.068 154.24 \
	    176.305 154.353 177.542 154.353 178.554 154.465 \
	    179.566 154.577 180.353 154.69 181.14 154.69 181.814 \
	    154.915 182.714 155.027 183.051 155.027 185.412 \
	    149.405 185.412 149.405 184.738 149.293 183.951 \
	    149.293 183.276 149.181 182.489 149.181 180.803 \
	    149.068 179.791 149.068 178.891 149.068 177.879 \
	    149.068 176.867 148.956 175.743 148.956 174.619 \
	    148.956 173.27 148.956 172.033 148.956 170.908 \
	    148.956 170.009 148.956 169.109 148.956 168.322 \
	    148.956 166.973 148.956 166.524 148.956 166.186 \
	    148.956 165.062 148.843 164.05 148.731 163.151 \
	    148.618 162.251 148.506 161.464 148.394 160.789 \
	    148.056 159.553 147.269 158.203 146.145 157.754 \
	    142.435 157.754 142.435 185.412 137.263 185.412 \
	    -fill #000000 -outline {} -width 1  -tags logo

    $c create polygon 158.4 185.412 158.4 110.869 \
	    164.022 110.869 164.022 185.412 158.4 185.412 -fill \
	    #000000 -outline {} -width 1  -tags logo

    $c create polygon 168.182 185.412 168.182 \
	    110.869 173.804 110.869 177.514 135.267 177.739 \
	    136.054 177.851 136.954 177.964 137.853 178.076 \
	    138.752 178.301 139.539 178.413 140.439 178.526 \
	    141.338 178.751 143.137 178.975 144.037 179.088 \
	    144.824 179.2 145.723 179.313 146.623 179.425 147.41 \
	    179.538 148.422 179.763 149.321 179.875 150.333 \
	    180.1 151.233 180.212 152.132 180.437 153.032 180.55 \
	    154.043 180.774 154.943 180.887 155.842 180.999 \
	    156.742 181.224 157.754 181.337 158.653 181.337 \
	    157.641 181.224 156.629 181.224 155.617 181.224 \
	    154.606 181.224 153.594 181.112 152.582 181.112 \
	    151.682 181.112 150.67 180.999 149.771 180.999 \
	    148.759 180.999 147.86 180.887 146.96 180.887 \
	    145.948 180.887 145.049 180.887 144.149 180.887 \
	    143.25 180.887 142.125 180.887 141.114 180.887 \
	    140.102 180.887 139.09 180.887 138.078 180.887 \
	    137.178 180.887 136.166 180.887 135.267 180.887 \
	    134.368 180.887 133.468 180.887 132.569 180.887 \
	    131.669 180.887 130.882 180.887 130.095 180.887 \
	    110.869 185.946 110.869 185.946 185.412 180.325 \
	    185.412 176.165 160.565 176.052 159.778 175.94 \
	    158.99 175.827 158.203 175.602 156.517 175.49 \
	    155.617 175.378 154.718 175.265 153.931 175.153 \
	    153.032 175.04 152.02 174.928 151.12 174.703 150.221 \
	    174.591 149.321 174.478 148.422 174.366 147.41 \
	    174.141 146.51 174.028 145.611 173.804 144.599 \
	    173.691 143.587 173.579 142.575 173.354 141.676 \
	    173.241 140.551 173.017 139.539 172.904 138.528 \
	    172.904 139.539 172.904 140.551 173.017 141.563 \
	    173.017 142.575 173.017 143.587 173.129 144.599 \
	    173.129 145.498 173.129 146.51 173.241 147.41 \
	    173.241 148.422 173.241 149.321 173.354 150.221 \
	    173.354 151.233 173.354 152.132 173.354 153.144 \
	    173.354 154.156 173.354 155.055 173.354 156.067 \
	    173.354 156.967 173.354 157.866 173.354 158.766 \
	    173.354 159.553 173.354 160.452 173.354 161.239 \
	    173.354 162.026 173.354 162.926 173.354 185.412 \
	    168.182 185.412 -fill #000000 -outline {} -width 1  -tags logo

    $c create polygon 206.184 185.412 205.622 \
	    175.968 205.397 177.092 205.172 178.217 204.948 \
	    179.228 204.61 180.128 204.385 181.027 204.048 \
	    181.814 203.823 182.489 203.486 183.164 203.149 \
	    183.838 202.811 184.4 202.024 185.75 201.125 186.762 \
	    200.113 187.436 199.101 187.661 198.089 187.549 \
	    197.19 186.986 196.29 186.087 195.391 184.85 194.941 \
	    184.176 194.491 183.389 194.042 182.489 193.592 \
	    181.477 193.255 180.465 192.805 179.341 192.467 \
	    178.217 192.13 176.98 191.905 176.193 191.68 175.406 \
	    191.568 174.619 191.456 173.832 191.231 172.932 \
	    191.118 172.145 191.006 171.246 190.781 169.559 \
	    190.669 168.66 190.556 167.648 190.444 166.748 \
	    190.331 165.736 190.219 164.725 190.106 163.825 \
	    189.994 162.926 189.994 162.026 189.882 161.127 \
	    189.769 160.227 189.769 159.215 189.657 158.316 \
	    189.544 157.304 189.544 156.405 189.432 155.393 \
	    189.432 154.381 189.319 153.369 189.319 152.357 \
	    189.319 151.345 189.319 150.333 189.319 149.321 \
	    189.319 148.197 189.319 146.96 189.319 145.948 \
	    189.319 144.824 189.319 143.7 189.319 142.688 \
	    189.432 141.563 189.432 140.551 189.544 139.539 \
	    189.544 138.528 189.544 137.516 189.657 136.504 \
	    189.769 135.492 189.769 134.592 189.882 133.581 \
	    189.994 132.681 189.994 131.782 190.106 130.882 \
	    190.219 129.983 190.331 129.083 190.556 127.397 \
	    190.669 126.61 190.781 125.823 191.006 124.923 \
	    191.118 124.136 191.231 123.462 191.568 121.887 \
	    191.793 121.213 191.905 120.426 192.13 119.751 \
	    192.58 117.952 193.142 116.378 193.704 114.917 \
	    194.266 113.567 194.941 112.443 195.616 111.431 \
	    196.29 110.532 196.965 109.857 197.752 109.295 \
	    198.426 108.845 199.214 108.62 200.001 108.508 \
	    201.799 108.958 202.699 109.407 203.374 110.194 \
	    204.161 111.094 204.835 112.218 205.51 113.567 \
	    206.184 115.141 206.634 116.491 206.859 117.165 \
	    206.971 117.952 207.421 119.526 207.534 120.426 \
	    207.758 121.325 207.871 122.225 207.983 123.124 \
	    208.096 124.136 208.208 125.036 208.321 126.047 \
	    208.433 127.172 208.545 128.184 208.658 129.308 \
	    208.77 130.32 208.77 131.557 208.883 132.681 208.995 \
	    133.805 204.273 133.805 204.161 132.681 203.936 \
	    131.557 203.711 130.432 203.486 129.533 203.261 \
	    128.633 202.924 127.734 202.699 126.947 202.362 \
	    126.385 201.35 124.586 200.001 124.024 199.438 \
	    124.136 198.989 124.361 198.426 124.923 197.977 \
	    125.598 197.527 126.497 197.077 127.622 196.628 \
	    128.971 196.29 130.545 196.178 131.219 195.953 \
	    132.681 195.84 133.356 195.728 134.143 195.616 \
	    134.93 195.503 135.829 195.278 137.516 195.278 \
	    138.303 195.166 139.315 195.166 140.214 195.053 \
	    141.114 195.053 142.125 194.941 143.137 194.941 \
	    144.149 194.941 145.161 194.941 146.173 194.941 \
	    147.297 194.941 148.309 194.941 149.546 194.941 \
	    150.67 194.941 151.907 194.941 152.919 195.053 \
	    154.043 195.053 155.168 195.166 156.18 195.166 \
	    157.192 195.278 158.091 195.391 159.103 195.391 \
	    160.002 195.503 160.902 195.616 161.801 195.728 \
	    162.588 195.84 163.375 196.065 164.162 196.178 \
	    164.949 196.29 165.736 196.628 167.198 197.077 \
	    168.547 197.527 169.672 197.977 170.571 198.426 \
	    171.246 198.989 171.808 199.438 172.145 200.001 \
	    172.258 200.9 171.92 201.575 171.246 202.249 170.009 \
	    202.811 168.547 203.149 167.76 203.374 166.973 \
	    203.598 166.186 203.823 165.399 204.048 164.5 \
	    204.273 163.488 204.385 162.476 204.498 161.464 \
	    204.61 160.34 204.723 159.103 200.001 159.103 \
	    200.001 145.049 209.445 145.049 209.445 185.412 \
	    206.184 185.412 -fill #000000 -outline {} -width 1  -tags logo

    $c create polygon 148.506 261.305 148.506 \
	    263.554 143.784 263.554 143.784 261.305 143.671 \
	    260.068 143.334 259.394 142.772 259.056 141.985 \
	    258.944 141.085 259.056 140.523 259.394 140.074 \
	    261.755 140.074 263.104 140.523 264.678 141.085 \
	    265.465 141.985 266.364 146.145 270.637 147.607 \
	    271.874 148.506 272.998 148.843 274.01 148.956 \
	    275.359 148.956 277.158 148.843 278.507 148.506 \
	    279.632 147.944 280.643 147.157 281.43 146.482 \
	    281.88 145.695 282.218 144.796 282.442 143.784 \
	    282.667 142.659 282.78 141.535 282.78 140.298 282.78 \
	    139.286 282.78 138.387 282.667 137.6 282.442 136.925 \
	    282.218 136.363 281.88 135.576 281.093 135.014 \
	    280.194 134.564 278.957 134.452 277.608 134.452 \
	    275.359 139.624 275.359 139.624 277.608 139.736 \
	    279.069 140.074 279.969 141.535 280.419 142.659 \
	    280.081 143.334 279.519 143.671 278.62 143.784 \
	    277.158 143.784 275.809 143.671 275.022 143.334 \
	    274.235 142.772 273.448 141.985 272.548 137.263 \
	    267.376 136.251 266.364 135.351 265.465 135.014 \
	    264.565 134.902 263.554 134.902 261.755 135.014 \
	    260.518 135.464 259.506 136.026 258.719 136.813 \
	    257.932 137.488 257.595 138.275 257.145 139.174 \
	    256.92 140.186 256.695 141.31 256.583 142.435 \
	    256.583 143.447 256.583 144.458 256.583 145.245 \
	    256.695 145.92 256.92 147.157 257.482 147.719 \
	    258.157 148.169 258.944 148.394 260.068 148.506 \
	    261.305 -fill #000000 -outline {} -width 1  -tags logo

    $c create polygon 165.821 270.187 165.821 \
	    276.708 165.821 277.833 165.708 278.957 165.483 \
	    279.856 165.259 280.643 164.921 281.318 164.472 \
	    281.88 163.909 282.218 163.235 282.555 162.448 \
	    282.667 161.548 282.78 160.536 282.78 159.3 282.78 \
	    158.175 282.78 157.051 282.78 156.151 282.667 \
	    155.364 282.555 154.69 282.218 154.128 281.88 \
	    153.678 281.318 153.341 280.643 153.116 279.856 \
	    152.891 278.845 152.778 277.833 152.778 276.708 \
	    152.778 270.187 152.778 269.063 152.891 268.051 \
	    153.116 267.264 153.341 266.589 154.128 265.465 \
	    155.364 264.678 156.151 264.453 157.051 264.228 \
	    158.063 264.116 159.3 264.116 160.424 264.116 \
	    161.548 264.228 162.448 264.453 163.235 264.678 \
	    163.909 265.015 164.472 265.465 164.921 265.915 \
	    165.483 267.264 165.708 268.051 165.821 269.063 \
	    165.821 270.187 -fill #000000 -outline {} -width 1  -tags logo

    $c create polygon 177.514 256.583 177.514 \
	    258.494 177.064 258.494 176.165 258.606 175.715 \
	    258.944 175.378 259.281 175.265 259.843 175.265 \
	    264.565 177.514 264.565 177.514 266.927 175.265 \
	    266.927 175.265 282.78 170.543 282.78 170.543 \
	    266.927 168.632 266.927 168.632 264.565 170.543 \
	    264.565 170.543 261.305 170.655 259.843 170.993 \
	    258.606 171.442 257.707 171.892 257.032 173.579 \
	    256.358 174.703 256.133 176.165 256.133 176.727 \
	    256.133 177.064 256.133 177.514 256.583 -fill \
	    #000000 -outline {} -width 1  -tags logo

    $c create polygon 185.946 259.843 185.946 \
	    264.565 188.757 264.565 188.757 266.927 185.946 \
	    266.927 185.946 278.62 186.171 279.407 186.509 \
	    279.969 187.071 280.306 187.858 280.419 188.307 \
	    280.419 188.757 280.419 188.757 282.78 188.645 \
	    282.78 188.307 282.78 187.183 282.78 186.509 282.78 \
	    185.159 282.78 183.923 282.555 182.911 282.33 \
	    182.236 281.88 181.786 281.206 181.561 280.419 \
	    181.337 279.407 181.337 278.17 181.337 266.927 \
	    179.425 266.927 179.425 264.565 181.337 264.565 \
	    181.337 261.305 185.946 259.843 -fill #000000 \
	    -outline {} -width 1  -tags logo

    $c create polygon 190.219 264.565 194.379 \
	    264.565 196.29 279.519 196.74 279.519 199.101 \
	    264.565 204.723 264.565 207.084 279.519 207.534 \
	    279.519 209.895 264.565 213.605 264.565 209.895 \
	    282.78 204.723 282.78 201.912 267.376 201.462 \
	    267.376 199.101 282.78 193.479 282.78 190.219 \
	    264.565 -fill #000000 -outline {} -width 1  -tags logo

    $c create polygon 229.121 269.175 229.121 282.78 \
	    224.848 282.78 224.848 280.981 224.061 281.768 \
	    223.049 282.33 221.925 282.667 220.688 282.78 \
	    219.564 282.78 218.44 282.555 217.54 282.33 216.866 \
	    281.88 216.528 281.318 216.191 280.531 216.079 \
	    279.632 215.966 278.62 215.966 275.359 216.079 \
	    274.347 216.978 272.998 217.877 272.548 218.44 \
	    272.211 219.114 271.986 219.789 271.761 220.688 \
	    271.536 221.588 271.424 222.6 271.311 223.724 \
	    271.199 224.848 271.087 224.848 269.175 224.736 \
	    267.826 224.399 266.927 223.612 266.477 222.487 \
	    266.364 221.7 266.477 221.138 266.927 220.688 \
	    268.726 220.688 269.175 216.416 269.175 216.528 \
	    267.938 216.753 266.702 217.203 265.69 217.877 \
	    265.015 218.44 264.678 219.114 264.453 219.901 \
	    264.228 220.801 264.116 221.925 264.116 223.049 \
	    264.116 224.061 264.116 225.073 264.116 225.86 \
	    264.228 226.535 264.453 227.659 265.015 228.334 \
	    265.69 228.783 266.702 229.008 267.938 229.121 \
	    269.175 -fill #000000 -outline {} -width 1  -tags logo

    $c create polygon 243.175 264.565 243.175 \
	    266.927 242.725 266.927 241.601 266.927 240.701 \
	    267.151 239.914 267.489 239.352 267.826 239.015 \
	    268.276 238.678 268.95 238.565 269.737 238.453 \
	    270.637 238.453 282.78 233.731 282.78 233.731 \
	    264.565 238.453 264.565 238.453 265.915 239.352 \
	    265.128 240.364 264.565 242.163 264.116 242.725 \
	    264.565 243.175 264.565 -fill #000000 -outline {} \
	    -width 1  -tags logo

    $c create polygon 258.129 270.187 258.129 \
	    274.347 249.696 274.347 249.696 278.17 249.809 \
	    279.294 250.146 279.969 250.708 280.643 251.607 \
	    280.981 252.732 280.643 253.406 279.969 253.744 \
	    279.294 253.969 278.17 253.969 276.708 258.129 \
	    276.708 258.129 277.608 258.129 278.957 257.904 \
	    280.081 257.454 281.093 256.779 281.88 256.217 \
	    282.218 254.643 282.667 253.744 282.78 252.732 \
	    282.78 251.607 282.78 250.371 282.78 249.359 282.78 \
	    248.459 282.667 247.672 282.442 246.436 281.88 \
	    245.986 281.318 245.649 280.643 245.424 279.856 \
	    245.199 278.957 245.086 277.833 244.974 276.708 \
	    244.974 270.187 245.086 269.063 245.199 268.051 \
	    245.311 267.264 245.649 266.589 245.986 265.915 \
	    246.436 265.465 246.998 265.015 247.672 264.678 \
	    248.459 264.453 249.359 264.228 250.371 264.116 \
	    251.607 264.116 252.732 264.116 253.744 264.228 \
	    254.756 264.453 255.543 264.678 256.217 265.015 \
	    256.779 265.465 257.229 265.915 257.566 266.589 \
	    257.791 267.264 258.016 268.051 258.129 269.063 \
	    258.129 270.187 -fill #000000 -outline {} -width 1  -tags logo

    $c create polygon 272.183 256.583 277.355 \
	    256.583 277.355 282.78 272.183 282.78 272.183 \
	    256.583 -fill #000000 -outline {} -width 1  -tags logo

    $c create polygon 295.569 268.726 295.569 282.78 \
	    290.959 282.78 290.959 269.175 290.847 268.051 \
	    290.509 267.376 289.947 266.702 289.048 266.364 \
	    287.923 266.702 287.136 267.376 287.024 268.051 \
	    287.136 269.175 287.136 282.78 282.527 282.78 \
	    282.527 264.565 286.687 264.565 287.136 265.915 \
	    288.036 265.128 289.048 264.565 290.172 264.228 \
	    291.409 264.116 292.533 264.116 293.433 264.341 \
	    294.107 264.565 294.669 265.015 295.344 266.477 \
	    295.569 267.489 295.569 268.726 -fill #000000 \
	    -outline {} -width 1  -tags logo

    $c create polygon 312.434 269.737 312.434 \
	    270.637 308.274 270.637 308.274 269.175 308.161 \
	    267.826 307.824 266.927 307.262 266.477 306.363 \
	    266.364 305.576 266.477 305.013 266.927 304.676 \
	    267.826 304.564 269.175 304.564 278.17 304.676 \
	    279.294 305.013 279.969 306.363 280.981 307.262 \
	    280.643 307.824 279.969 307.937 279.294 307.824 \
	    278.17 307.824 276.259 312.434 276.259 312.434 \
	    277.608 312.434 278.957 312.209 280.081 311.759 \
	    281.093 311.085 281.88 310.523 282.218 309.173 \
	    282.667 308.386 282.78 307.374 282.78 306.363 282.78 \
	    305.238 282.78 304.226 282.78 303.327 282.667 \
	    302.427 282.442 301.753 282.218 301.191 281.88 \
	    300.853 281.318 300.516 280.643 300.179 279.856 \
	    299.954 278.957 299.841 277.833 299.841 276.708 \
	    299.841 270.187 299.841 269.063 299.954 268.051 \
	    300.179 267.264 300.404 266.589 301.191 265.465 \
	    302.427 264.678 303.327 264.453 304.226 264.228 \
	    305.238 264.116 306.363 264.116 307.374 264.116 \
	    308.386 264.228 309.173 264.453 309.96 264.678 \
	    310.523 265.015 311.085 265.465 311.759 266.252 \
	    312.209 267.264 312.434 268.388 312.434 269.737 \
	    -fill #000000 -outline {} -width 1  -tags logo

    $c create polygon 316.706 279.069 320.866 \
	    279.069 320.866 282.78 316.706 282.78 316.706 \
	    279.069 -fill #000000 -outline {} -width 1  -tags logo

    $c create polygon 48.215 186.312 48.215 185.412 \
	    47.766 184.4 47.766 183.501 47.316 183.501 47.316 \
	    182.601 46.416 181.59 46.416 181.14 45.967 180.24 \
	    45.405 179.791 44.955 179.228 44.055 178.329 43.606 \
	    177.879 43.156 177.43 42.144 176.98 41.694 176.418 \
	    41.245 175.968 38.883 175.068 36.972 174.169 36.522 \
	    174.169 35.173 173.607 34.723 174.169 31.913 173.607 \
	    31.913 174.169 29.551 173.607 29.551 174.169 28.54 \
	    174.169 28.09 174.619 27.19 174.169 27.19 174.619 \
	    26.741 174.619 25.729 175.068 23.93 175.518 22.918 \
	    175.068 22.468 175.518 20.669 176.418 19.657 176.418 \
	    15.048 178.779 14.036 179.228 12.686 180.24 12.237 \
	    180.69 11.225 181.59 10.775 182.039 10.325 182.601 \
	    10.775 182.601 10.325 184.4 10.775 184.85 11.225 \
	    186.312 14.036 188.223 14.485 188.673 16.846 190.022 \
	    17.296 190.472 17.296 191.034 15.947 191.933 15.048 \
	    192.383 14.485 192.833 14.036 193.283 13.136 193.845 \
	    12.237 194.295 12.686 195.644 12.686 196.094 12.237 \
	    197.555 12.237 198.005 11.675 198.904 12.237 200.816 \
	    12.237 202.277 12.237 204.526 11.675 205.988 12.237 \
	    205.988 12.237 206.437 12.237 207.337 12.686 208.349 \
	    12.686 209.248 13.136 209.698 12.686 211.16 13.136 \
	    212.509 13.136 213.521 13.586 215.32 13.586 216.781 \
	    13.586 217.681 14.036 220.492 14.485 222.403 15.048 \
	    222.853 15.947 222.853 15.947 222.403 16.397 221.953 \
	    16.846 216.781 17.296 215.32 17.858 211.609 18.308 \
	    210.71 18.308 210.148 18.308 209.248 17.858 208.798 \
	    17.858 207.899 18.308 206.437 18.308 205.538 18.308 \
	    205.088 18.308 203.627 16.846 203.627 15.947 203.177 \
	    15.947 202.727 15.947 202.277 16.397 201.715 16.846 \
	    201.715 17.858 201.715 18.308 201.715 18.758 201.265 \
	    18.308 200.816 17.858 199.916 18.308 198.455 17.858 \
	    198.455 17.858 193.283 19.208 192.383 20.107 191.933 \
	    21.569 191.484 22.018 191.484 22.918 192.383 22.918 \
	    192.833 23.48 192.833 23.93 198.005 23.48 199.467 \
	    23.93 202.277 25.279 202.277 29.551 202.727 30.001 \
	    202.277 30.901 202.277 31.913 202.277 35.623 201.265 \
	    36.522 201.265 36.972 200.816 37.984 200.816 38.883 \
	    200.816 39.333 200.366 40.345 199.916 40.795 199.916 \
	    42.594 198.455 44.055 198.005 44.055 197.555 44.505 \
	    197.105 46.416 195.644 46.416 194.744 46.866 194.295 \
	    47.316 193.845 47.766 193.283 47.316 192.833 48.215 \
	    190.472 48.215 190.022 48.215 189.572 48.215 188.673 \
	    48.215 187.211 48.215 186.762 48.215 186.312 -fill \
	    $bg -outline {} -width 1  -tags logo

    $c create polygon 76.886 142.688 81.046 142.688 \
	    82.508 142.35 83.407 140.889 83.632 140.327 83.969 \
	    138.865 84.082 137.965 84.194 137.066 84.307 136.054 \
	    84.307 134.93 84.307 133.805 84.307 132.456 84.194 \
	    131.332 84.082 130.208 83.857 129.308 83.632 128.409 \
	    83.407 127.734 82.395 126.272 81.046 125.823 76.886 \
	    125.823 76.886 142.688 -fill $bg -outline {} -width \
	    1  -tags logo

    $c create polygon 97.461 148.309 97.461 149.546 \
	    97.461 150.783 97.461 152.02 97.574 153.144 97.574 \
	    154.268 97.686 155.28 97.686 156.405 97.799 157.416 \
	    97.799 158.316 97.911 159.328 98.023 160.227 98.136 \
	    161.127 98.361 162.701 98.473 163.488 98.586 164.275 \
	    98.698 164.949 98.81 165.736 99.373 167.535 99.822 \
	    169.109 100.497 170.234 101.059 171.133 101.846 \
	    171.583 102.633 171.808 104.095 171.133 104.769 \
	    170.234 105.332 169.109 105.894 167.535 106.343 \
	    165.736 106.456 164.949 106.681 164.275 106.793 \
	    163.488 106.906 162.701 107.018 161.914 107.243 \
	    160.227 107.355 159.328 107.355 158.316 107.468 \
	    157.416 107.58 156.405 107.58 155.28 107.693 154.268 \
	    107.693 153.144 107.693 152.02 107.693 150.783 \
	    107.805 149.546 107.805 148.309 107.805 147.073 \
	    107.693 145.836 107.693 144.711 107.693 143.587 \
	    107.693 142.463 107.58 141.338 107.58 140.327 \
	    107.468 139.315 107.355 138.303 107.355 137.403 \
	    107.243 136.504 107.131 135.604 106.906 133.918 \
	    106.793 133.131 106.681 132.456 106.456 131.669 \
	    106.343 130.995 105.894 129.196 105.332 127.622 \
	    104.769 126.497 104.095 125.598 103.42 125.148 \
	    102.633 124.923 101.846 125.148 101.059 125.598 \
	    100.497 126.497 99.822 127.622 99.373 129.196 98.81 \
	    130.995 98.698 131.669 98.586 132.456 98.473 133.131 \
	    98.361 133.918 98.248 134.817 98.023 136.504 97.911 \
	    137.403 97.799 138.303 97.799 139.315 97.686 140.327 \
	    97.686 141.338 97.574 142.463 97.574 143.587 97.461 \
	    144.711 97.461 145.836 97.461 147.073 97.461 148.309 \
	    -fill $bg -outline {} -width 1  -tags logo

    $c create polygon 122.309 156.292 126.919 \
	    156.292 124.67 130.545 122.309 156.292 -fill $bg \
	    -outline {} -width 1  -tags logo

    $c create polygon 142.435 142.688 146.145 \
	    142.688 147.607 142.35 148.506 140.889 148.731 \
	    140.327 149.068 138.865 149.181 137.965 149.293 \
	    137.066 149.405 136.054 149.405 134.93 149.405 \
	    133.805 149.405 132.456 149.405 131.332 149.405 \
	    130.208 149.293 129.308 149.181 128.409 148.956 \
	    127.734 148.056 126.272 146.595 125.823 142.435 \
	    125.823 142.435 142.688 -fill $bg -outline {} -width \
	    1  -tags logo

    $c create polygon 111.515 228.924 111.515 \
	    227.575 111.066 225.664 108.705 221.391 108.255 \
	    220.042 108.255 219.142 108.255 218.58 108.255 \
	    218.13 107.805 217.681 106.793 218.58 104.994 \
	    220.941 104.432 221.953 102.633 224.202 102.183 \
	    224.764 101.621 225.214 99.822 228.474 97.461 \
	    233.197 97.461 234.096 97.461 234.995 97.911 235.445 \
	    98.361 236.007 99.822 236.457 102.633 236.457 \
	    104.432 235.445 105.894 234.995 106.343 234.546 \
	    106.793 234.546 107.805 233.646 110.616 230.835 \
	    111.515 229.824 111.515 229.374 111.515 228.924 \
	    -fill $bg -outline {} -width 1  -tags logo

    $c create polygon 161.211 269.175 160.986 \
	    267.826 160.649 266.927 160.199 266.477 159.3 \
	    266.364 158.4 266.477 157.838 266.927 157.613 \
	    267.826 157.388 269.175 157.388 278.17 157.613 \
	    279.294 157.838 279.969 159.3 280.981 160.199 \
	    280.643 160.649 279.969 160.986 279.294 161.211 \
	    278.17 161.211 269.175 -fill $bg -outline {} -width \
	    1  -tags logo

    $c create polygon 224.848 273.448 223.836 \
	    273.448 222.825 273.56 222.15 273.673 221.588 \
	    273.897 220.913 274.684 220.688 275.809 220.688 \
	    278.17 220.801 279.294 221.138 279.969 221.7 280.643 \
	    222.487 280.981 223.612 280.643 224.399 279.969 \
	    224.736 279.294 224.848 278.17 224.848 273.448 -fill \
	    $bg -outline {} -width 1  -tags logo

    $c create polygon 253.969 269.175 253.744 \
	    267.826 253.406 266.927 252.732 266.477 251.607 \
	    266.364 250.708 266.477 250.146 266.927 249.696 \
	    269.175 249.696 272.548 253.969 272.548 253.969 \
	    269.175 -fill $bg -outline {} -width 1  -tags logo

}

#***********************************************************************
# %PROCEDURE: LoadConnectionInfo
# %ARGUMENTS:
#  None
# %RETURNS:
#  Nothing
# %DESCRIPTION:
#  Loads the connection information into the global ConnectionInfo variable
#***********************************************************************
proc LoadConnectionInfo {} {
    global ConnectionInfoFile ConnectionInfo PasswordFile
    set ConnectionInfo {}
    if {![file exists $ConnectionInfoFile]} {
	return
    }
    set problem [catch {
	set fp [open $ConnectionInfoFile "r"]
	while {1} {
	    if {[gets $fp line] < 0} {
		break
	    }
	    set line [string trim $line]
	    if {[string match "#*" $line]} {
		continue
	    }
	    if {"$line" == ""} {
		continue
	    }
	    set ConnectionInfo $line
	    break
	}
	close $fp
    } err]
    if {$problem} {
	tk_dialog .err Error "Error loading configuration file: $err" error 0 OK
    }
    # Try loading and merging passwords if the password file is readable
    if {![file readable $PasswordFile]} {
	return
    }

    set fp [open $PasswordFile "r"]
    while {1} {
	if {[gets $fp line] < 0} {
	    break
	}
	set line [string trim $line]
	if {[string match "#*" $line]} {
	    continue
	}
	if {"$line" == ""} {
	    continue
	}
	set passwords $line
	break
    }
    close $fp

    # Merge passwords
    foreach thing $passwords {
	set name [value $thing ConnectionName]
	set password [value $thing Password]
	set conn [GetConnection $name]
	if {"$conn" != ""} {
	    lappend conn Password $password
	    ReplaceConnection $conn
	}
    }
}

#***********************************************************************
# %PROCEDURE: GetConnection
# %ARGUMENTS:
#  name -- name of connection
# %RETURNS:
#  key/value pair listing connection configuration, or "" if not found.
#***********************************************************************
proc GetConnection { name } {
    global ConnectionInfo
    foreach thing $ConnectionInfo {
	if {[value $thing ConnectionName] == "$name"} {
	    return $thing
	}
    }
    return ""
}
    

#***********************************************************************
# %PROCEDURE: DeleteConnection
# %ARGUMENTS:
#  name -- name of connection
# %RETURNS:
#  Nothing, but deletes connection named "$name"
#***********************************************************************
proc DeleteConnection { name } {
    global ConnectionInfo ConfigDir
    set newInfo {}
    set found 0
    foreach thing $ConnectionInfo {
	if {[value $thing ConnectionName] == "$name"} {
	    set found 1
	} else {
	    lappend newInfo $thing
	}
    }
    if {!$found} {
	return
    }
    set ConnectionInfo $newInfo
    SaveConnectionInfo

    # Delete the config file
    set fname [file join $ConfigDir conf.$name]
    catch { file delete $fname }

    BuildConnectionMenu
    if {[GetCurrentConnection] == $name} {
	if {[llength $ConnectionInfo] == 0} {
	    SwitchConnection ""
	} else {
	    set name [value [lindex $ConnectionInfo 0] ConnectionName]
	    SwitchConnection $name
	}
    }
}

#***********************************************************************
# %PROCEDURE: ReplaceConnection
# %ARGUMENTS:
#  conn -- new name/value pairs
# %RETURNS:
#  Nothing, but replaces connection in ConnectionInfo.  If no such
#  connection exists, appends new connection.
#***********************************************************************
proc ReplaceConnection { conn } {
    global ConnectionInfo
    set name [value $conn ConnectionName]
    set newInfo {}
    set found 0
    foreach thing $ConnectionInfo {
	if {[value $thing ConnectionName] == "$name"} {
	    lappend newInfo $conn
	    set found 1
	} else {
	    lappend newInfo $thing
	}
    }
    if {!$found} {
	lappend newInfo $conn
    }
    set ConnectionInfo $newInfo
}

proc DeletePPPoEConnection {} {
    set conn [GetCurrentConnection]
    if {"$conn" == ""} {
	return
    }
    set ans [tk_dialog .confirm "Confirm Deletion - RP-PPPoE" "Are you sure you wish to delete the connection `$conn'?" warning 0 No Yes]
    if {$ans} {
	DeleteConnection $conn
    }
}

#***********************************************************************
# %PROCEDURE: CreateMainDialog
# %ARGUMENTS:
#  None
# %RETURNS:
#  Nothing
# %DESCRIPTION:
#  Creates the main window
#***********************************************************************
proc CreateMainDialog {} {
    global ConnectionInfoFile
    global ConnectionInfo
    global Admin
    wm title . "RP-PPPoE"
    wm iconname . "PPPoE"
    frame .f1
    label .l1 -text "Connection: "
    menubutton .m1 -text "" -indicatoron 1 -menu .m1.menu -relief raised
    menu .m1.menu -tearoff 0
    pack .l1 .m1 -in .f1 -side left -expand 0 -fill x
    canvas .c -width 40 -height 20
    pack .c -in .f1 -side left -expand 0 -fill none

    # Draw the LED's
    .c create rectangle 10 1 30 8 -outline "#808080" -fill "#A0A0A0" -tags xmitrect
    .c create rectangle 10 10 30 18 -outline "#808080" -fill "#A0A0A0" -tags recvrect

    frame .buttons
    button .start -text "Start" -command "StartPPPoEConnection"
    button .stop -text "Stop" -command "StopPPPoEConnection"
    button .exit -text "Exit" -command "exit"
    canvas .graph -width 1 -height 1
    if {[file writable $ConnectionInfoFile]} {
	set Admin 1
	pack .f1 -side top -expand 1 -fill both
	pack .buttons -side top -expand 0 -fill x
	button .delete -text "Delete" -command "DeletePPPoEConnection"
	button .new -text "New Connection..." -command "NewPPPoEConnection"
	button .props -text "Properties..." -command "EditConnectionProps"
	pack .graph -in .f1 -side left -expand 1 -fill both
	pack .start .stop .delete .props .new .exit -in .buttons -side left -expand 0 -fill none
    } else {
	set Admin 0
	pack .f1 -side top -expand 0 -fill x
	pack .buttons -side top -expand 1 -fill both
	pack .start .stop .exit -in .buttons -side left -expand 0 -fill none
	pack .graph -in .buttons -side left -expand 1 -fill both
    }

    LoadConnectionInfo
    BuildConnectionMenu
    # If no connections exist, pop up new connection dialog
    if {[llength $ConnectionInfo] == 0} {
	SwitchConnection ""
	if {$Admin} {
	    update idletasks
	    NewPPPoEConnection
	} else {
	    tk_dialog .note Note "Note: There are no connections defined.  You must run this program as root to define connections" warning 0 OK
	}
    } else {
	set con [lindex $ConnectionInfo 0]
	set name [value $con ConnectionName]
	SwitchConnection $name
    }
}

#***********************************************************************
# %PROCEDURE: GetCurrentConnection
# %ARGUMENTS:
#  None
# %RETURNS:
#  The name of the current connection in the GUI.
#***********************************************************************
proc GetCurrentConnection {} {
    .m1 cget -text
}

#***********************************************************************
# %PROCEDURE: value
# %ARGUMENTS:
#  lst -- a list of key/value pairs
#  key -- key we're looking for
# %RETURNS:
#  value corresponding to $key, or "" if not found.
#***********************************************************************
proc value { lst key } {
    set idx [lsearch -exact $lst $key]
    if {$idx >= 0} {
	return [lindex $lst [expr $idx+1]]
    }
    return ""
}

#***********************************************************************
# %PROCEDURE: SwitchConnection
# %ARGUMENTS:
#  name -- new connection name
# %DESCRIPTION:
#  Makes $name the active connection
#***********************************************************************
proc SwitchConnection { name } {
    .m1 configure -text $name
    SetButtonStates
    UpdateConnectionState 0
}

#***********************************************************************
# %PROCEDURE: EditConnectionProps
# %ARGUMENTS:
#  None
# %DESCRIPTION:
#  Pops up edit window for current connection
#***********************************************************************
proc EditConnectionProps {} {
    global ConnectionInfo
    set conn [GetCurrentConnection]
    NewPPPoEConnection $conn
}

#***********************************************************************
# %PROCEDURE: FillConnectionGui
# %ARGUMENTS:
#  w -- connection property GUI
#  name -- name of connection
# %DESCRIPTION:
#  Fills GUI with values corresponding to $name.
#***********************************************************************
proc FillConnectionGui { w name } {
    global ConnectionInfo
    set found [GetConnection $name]
    if {"$found" != ""} {
	ListToSetupGui $w $found
    }
}
    
#***********************************************************************
# %PROCEDURE: BuildConnectionMenu
# %ARGUMENTS:
#  None
# %RETURNS:
#  Nothing
# %DESCRIPTION:
#  Builds the connection menu
#***********************************************************************
proc BuildConnectionMenu {} {
    global ConnectionInfo
    .m1.menu delete 0 end
    foreach connection $ConnectionInfo {
	set name [value $connection ConnectionName]
	.m1.menu add command -label $name -command [list SwitchConnection $name]
    }
    .m1.menu add separator
    .m1.menu add command -label "User's Manual" -command Help
}

#***********************************************************************
# %PROCEDURE: SetButtonStates
# %ARGUMENTS:
#  None
# %RETURNS:
#  Nothing
# %DESCRIPTION:
#  Enables or disables buttons, as appropriate
#***********************************************************************
proc SetButtonStates {} {
    global Admin
    set conn [GetCurrentConnection]
    if {"$conn" == ""} {
	.start configure -state disabled
	.stop configure -state disabled
	catch {
	    .delete configure -state disabled
	    .props configure -state disabled
	    .new configure -state normal
	}
    } else {
	foreach {startstop updown interface} [GetConnectionStatus $conn] {break}
	if {"$startstop" == "started"} {
	    .start configure -state disabled
	    .stop configure -state normal
	} else {
	    .start configure -state normal
	    .stop configure -state disabled
	}
	catch {
	    .delete configure -state normal
	    .props configure -state normal
	    .new configure -state normal
	}
	if {!$Admin} {
	    set ok [value [GetConnection $conn] NonrootOK]
	    if {!$ok} {
		.start configure -state disabled
		.stop configure -state disabled
	    }
	}
    }
}

#***********************************************************************
# %PROCEDURE: GetEthernetInterfaces
# %ARGUMENTS:
#  None
# %RETURNS:
#  A list of Ethernet interfaces
#***********************************************************************
proc GetEthernetInterfaces {} {
    set ifs {}
    set fp [open "|/sbin/ifconfig" "r"]
    while {[gets $fp line] >= 0} {
	if {[regexp {^eth[0-9]+} $line eth]} {
	    lappend ifs $eth
	}
    }
    return $ifs
}

#***********************************************************************
# %PROCEDURE: StartPPPoEConnection
# %ARGUMENTS:
#  None
# %RETURNS:
#  Nothing
# %DESCRIPTION:
#  Starts currently-selected PPPoE connection.
#***********************************************************************
proc StartPPPoEConnection {} {
    global Wrapper
    global StartState
    global UpdateToken

    set conn [GetCurrentConnection]
    if {"$conn" == ""} {
	return
    }

    if {"$UpdateToken" != ""} {
	after cancel $UpdateToken
	set UpdateToken ""
    }

    catch { unset StartState }
    set StartState(chars) ""
    set StartState(status) ""
    set StartState(msg) ""
    set StartState(flip) 0

    set fp [open "|$Wrapper start $conn" "r"]

    # Set fileevent
    fileevent $fp readable [list StartFPReadable $fp]

    LockGui $fp
    vwait StartState(status)
    UnlockGui

    if {$StartState(status) == "failed"} {
	tk_dialog .err Error "Error starting connection: $StartState(msg)" error 0 OK
    }
    SetButtonStates
    UpdateConnectionState 0
}

proc LockGui { fp } {
    .start configure -state disabled
    .stop configure -state normal -command [list AbortConnection $fp]
    .exit configure -state disabled
    .m1 configure -state disabled
    grab set .stop
}

proc UnlockGui {} {
    .start configure -state normal
    .stop configure -state disabled -command StopPPPoEConnection
    .exit configure -state normal
    .m1 configure -state normal
    grab release .stop
}

proc AbortConnection { fp } {
    global StartState
    catch { StopPPPoEConnection }
    catch { close $fp }
    set StartState(msg) "Connection aborted by user"
    set StartState(status) "failed"
}
    
#***********************************************************************
# %PROCEDURE: StartFPReadable
# %ARGUMENTS:
#  fp -- file handle
# %RETURNS:
#  Nothing
# %DESCRIPTION:
#  Called when the "adsl-start" file handle is readable.
#***********************************************************************
proc StartFPReadable { fp } {
    global StartState
    set char [read $fp 1]
    if {$char == ""} {
	set uhoh [catch {close $fp} err]
	if {$uhoh} {
	    set StartState(status) "failed"
	    set StartState(msg) $err
	} else {
	    set StartState(status) "succeeded"
	}
	return
    }
    append StartState(chars) $char
    if {$StartState(flip)} {
	ConnectionStateDown
    } else {
	ConnectionStateOff
    }
    set StartState(flip) [expr 1 - $StartState(flip)]
}

#***********************************************************************
# %PROCEDURE: StopPPPoEConnection
# %ARGUMENTS:
#  None
# %RETURNS:
#  Nothing
# %DESCRIPTION:
#  Stops currently-selected PPPoE connection.
#***********************************************************************
proc StopPPPoEConnection {} {
    global Wrapper
    set conn [GetCurrentConnection]
    if {"$conn" == ""} {
	return
    }
    set fp [open "|$Wrapper stop $conn" "r"]
    while {1} {
	set char [read $fp 1]
	if {"$char" == ""} {
	    break;
	}
    }
    set uhoh [catch {close $fp} err]
    if {$uhoh} {
	# Ignore a common error
	if {![string match "*appears to have died*" $err]} {
	    tk_dialog .err Error "Error stopping connection: $err" error 0 OK
	}
    }
    SetButtonStates
    UpdateConnectionState 0
}

#***********************************************************************
# %PROCEDURE: NewPPPoEConnection
# %ARGUMENTS:
#  name -- if supplied, we're editing the existing connection "name"
# %RETURNS:
#  Nothing
# %DESCRIPTION:
#  Creates a new PPPoE connection
#***********************************************************************
proc NewPPPoEConnection {{name ""}} {
    set w .newcon
    if {[winfo exists $w]} {
	wm deiconify $w
	raise $w
	return
    }

    toplevel $w
    if {"$name" == ""} {
	wm title $w "New Connection - RP-PPPoE"
	wm iconname $w "New Connection"
    } else {
	wm title $w "Edit Connection - RP-PPPoE"
	wm iconname $w "Edit Connection"
    }
    wm withdraw $w

    tabnotebook_create $w.tn
    set basic [tabnotebook_page $w.tn "Basic"]
    set interface [tabnotebook_page $w.tn "NIC and DNS"]
    set opts [tabnotebook_page $w.tn "Options"]
    set advanced [tabnotebook_page $w.tn "Advanced"]

    # ----------- BASIC PAGE -------------
    label $w.lconName -text "Connection Name: " -anchor e
    if {"$name" != ""} {
	label $w.conName -text $name -anchor w
    } else {
	entry $w.conName -width 15
	RegisterHelpWindow $w.lconName "Enter a name for this connection.  It can contain letters, numbers, undescores and the minus-sign." $w.help
	RegisterHelpWindow $w.conName "Enter a name for this connection.  It can contain letters, numbers, undescores and the minus-sign." $w.help
    }

    label $w.luser -text "User Name: " -anchor e
    entry $w.user -width 15
    RegisterHelpWindow $w.luser "Enter your user name.  Do not add a domain-name after the user name." $w.help
    RegisterHelpWindow $w.user "Enter your user name.  Do not add a domain-name after the user name." $w.help

    label $w.lnet -text "Network: " -anchor e
    entry $w.network -width 15
    RegisterHelpWindow $w.lnet "Some ISP's require you to enter their domain-name here (e.g. \"sympatico.ca\")." $w.help
    RegisterHelpWindow $w.network "Some ISP's require you to enter their domain-name here (e.g. \"sympatico.ca\")." $w.help

    label $w.lpass -text "Password: " -anchor e
    entry $w.pass -width 15 -show "*"
    RegisterHelpWindow $w.lpass "Enter your password." $w.help
    RegisterHelpWindow $w.pass "Enter your password." $w.help

    grid $w.lconName $w.conName -in $basic -sticky nsew
    grid $w.luser $w.user -in $basic -sticky nsew
    grid $w.lnet $w.network -in $basic -sticky nsew
    grid $w.lpass $w.pass -in $basic -sticky nsew
    grid columnconfigure $basic 1 -weight 1

    # ----------- INTERFACES PAGE -------------
    set ifs {}
    catch {set ifs [GetEthernetInterfaces]}

    label $w.lifname -text "Ethernet Interface: " -anchor e
    entry $w.ifname -width 8
    RegisterHelpWindow $w.lifname "Enter Ethernet interface to which DSL modem is attached." $w.help
    RegisterHelpWindow $w.ifname "Enter Ethernet interface to which DSL modem is attached." $w.help

    if {[llength $ifs] > 0} {
	menubutton $w.ifmb -relief raised -text "..." -menu $w.ifmb.menu
	RegisterHelpWindow $w.ifmb "Browse detected Ethernet interface names." $w.help
	menu $w.ifmb.menu -tearoff 0
	foreach if $ifs {
	    $w.ifmb.menu add command -label $if -command "$w.ifname delete 0 end; $w.ifname insert end [list $if]"
	}
	grid $w.lifname $w.ifname $w.ifmb -in $interface -sticky nsew
    } else {
	grid $w.lifname $w.ifname - -in $interface -sticky nsew
    }

    label $w.ldns -text "DNS Setup: " -anchor e
    menubutton $w.dns -text "From Server" -menu $w.dns.menu -relief raised -indicatoron 1
    menu $w.dns.menu -tearoff 0
    foreach thing {"From Server" "Specify" "Do not Adjust"} {
	$w.dns.menu add command -label $thing -command [list SetDNSOption $w $thing]
    }
    RegisterHelpWindow $w.ldns "DNS server options:\n'From Server'   - Let PPPoE server specify DNS servers\n'Specify'       - Enter IP addresses of DNS servers yourself\n'Do not Adjust' - Leave your DNS setup alone." $w.help
    RegisterHelpWindow $w.dns "DNS server options:\n'From Server'   - Let PPPoE server specify DNS servers\n'Specify'       - Enter IP addresses of DNS servers yourself\n'Do not Adjust' - Leave your DNS setup alone." $w.help

    label $w.ldns1 -text "Primary DNS: " -anchor e
    entry $w.dns1 -width 16
    RegisterHelpWindow $w.ldns1 "Enter the IP address of the primary DNS server." $w.help
    RegisterHelpWindow $w.dns1 "Enter the IP address of the primary DNS server." $w.help
    label $w.ldns2 -text "Secondary DNS: " -anchor e
    entry $w.dns2 -width 16
    RegisterHelpWindow $w.ldns2 "Enter the IP address of the secondary DNS server." $w.help
    RegisterHelpWindow $w.dns2 "Enter the IP address of the secondary DNS server." $w.help

    SetDNSOption $w "From Server"
    grid $w.ldns $w.dns - -in $interface -sticky nsew
    grid $w.ldns1 $w.dns1 - -in $interface -sticky nsew
    grid $w.ldns2 $w.dns2 - -in $interface -sticky nsew

    # If only one Ethernet interface, select it by default
    if {[llength $ifs] == 1} {
	$w.ifname insert end [lindex $ifs 0]
    }

    grid columnconfigure $interface 1 -weight 1
    # ----------- OPTS PAGE -------------
    checkbutton $w.nonroot -text "Allow use by non-root users" -variable OPTS(nonroot) -anchor w
    RegisterHelpWindow $w.nonroot "If enabled, ordinary users can start and stop this connection." $w.help
    checkbutton $w.sync -text "Use synchronous PPP" -variable OPTS(sync) -anchor w
    RegisterHelpWindow $w.sync "Use synchronous PPP (recommended -- easier on the CPU.)" $w.help
    label $w.lfw -text "Firewalling: " -anchor e
    if {[llength $ifs] == 1} {
	set defaultFW "Stand-Alone"
    } else {
	set defaultFW "Masquerading"
    }
    menubutton $w.fw -text $defaultFW -menu $w.fw.menu -indicatoron 1 -relief raised
    menu $w.fw.menu -tearoff 0
    foreach type {Stand-Alone Masquerading None} {
	$w.fw.menu add command -label $type -command [list $w.fw configure -text $type]
    }
    
    RegisterHelpWindow $w.lfw "Firewalling options:\nStand-Alone  - A stand-alone machine.\nMasquerading - A gateway machine used for Internet sharing.\nNone         - Use if you already have your own firewall rules or want to run servers." $w.help
    RegisterHelpWindow $w.fw "Firewalling options:\nStand-Alone  - A stand-alone machine.\nMasquerading - A gateway machine used for Internet sharing.\nNone         - Use if you already have your own firewall rules or want to run servers." $w.help
    grid $w.nonroot - -in $opts -sticky nsew
    grid $w.sync - -in $opts -sticky nsew
    grid $w.lfw $w.fw -in $opts -sticky nsw
    grid columnconfigure $opts 1 -weight 1

    # ----------- ADVANCED PAGE -------------
    label $w.lsn -text "Service-Name: " -anchor e
    entry $w.servicename -width 24

    label $w.lac -text "AC-Name: " -anchor e
    entry $w.acname -width 24

    RegisterHelpWindow $w.lac "Enter access concentrator name if required.  Most ISPs do not require this; try leaving it blank." $w.help
    RegisterHelpWindow $w.acname "Enter access concentrator name if required.  Most ISPs do not require this; try leaving it blank." $w.help
    grid $w.lsn $w.servicename -in $advanced -sticky nsew
    grid $w.lac $w.acname -in $advanced -sticky nsew
    RegisterHelpWindow $w.lsn "Enter service name if required.  Most ISPs do not require this; try leaving it blank." $w.help
    RegisterHelpWindow $w.servicename "Enter service name if required.  Most ISPs do not require this; try leaving it blank." $w.help

    grid columnconfigure $advanced 1 -weight 1

    # ----------- BUTTONS -------------
    frame $w.buttons
    button $w.ok -text "OK" -command [list NewPPPoEConnectionOK $name $w]
    button $w.cancel -text "Cancel" -command [list destroy $w]
    pack $w.ok $w.cancel -in $w.buttons -expand 0 -fill none -side left

    pack $w.tn -side top -expand 1 -fill both

    text $w.help -width 60 -wrap word -state disabled -height 6
    pack $w.help -side top -expand 0 -fill both
    pack $w.buttons -side top -expand 0 -fill x

    # If we're editing existing connection, fill GUI with current values
    if {"$name" != ""} {
	FillConnectionGui $w $name
    }
    wm deiconify $w
    update idletasks
    raise $w
}

#***********************************************************************
# %PROCEDURE: SetDNSOption
# %ARGUMENTS:
#  w -- connection-editing window
#  opt -- value of DNS option
# %RETURNS:
#  Nothing
# %DESCRIPTION:
#  Adjusts GUI for specified option
#***********************************************************************
proc SetDNSOption { w opt } {
    $w.dns configure -text $opt
    if {"$opt" == "Specify"} {
	$w.dns1 configure -state normal -background white
	$w.dns2 configure -state normal -background white
    } else {
	$w.dns1 configure -state disabled -background "#d9d9d9"
	$w.dns2 configure -state disabled -background "#d9d9d9"
    }
}

# ----------------------------------------------------------------------
# Tabbed notebook code from "Effective Tcl/Tk Programming"
# ----------------------------------------------------------------------
#  EXAMPLE: tabnotebook that can dial up pages
# ----------------------------------------------------------------------
#  Effective Tcl/Tk Programming
#    Mark Harrison, DSC Communications Corp.
#    Michael McLennan, Bell Labs Innovations for Lucent Technologies
#    Addison-Wesley Professional Computing Series
# ======================================================================
#  Copyright (c) 1996-1997  Lucent Technologies Inc. and Mark Harrison
# ======================================================================

option add *Tabnotebook.tabs.background #666666 widgetDefault
option add *Tabnotebook.margin 6 widgetDefault
option add *Tabnotebook.tabColor #a6a6a6 widgetDefault
option add *Tabnotebook.activeTabColor #d9d9d9 widgetDefault
option add *Tabnotebook.tabFont \
    -*-helvetica-bold-r-normal--*-120-* widgetDefault

proc tabnotebook_create {win} {
    global tnInfo

    frame $win -class Tabnotebook
    canvas $win.tabs -highlightthickness 0
    pack $win.tabs -fill x

    notebook_create $win.notebook
    pack $win.notebook -expand yes -fill both

    set tnInfo($win-tabs) ""
    set tnInfo($win-current) ""
    set tnInfo($win-pending) ""
    return $win
}

proc tabnotebook_page {win name} {
    global tnInfo

    set page [notebook_page $win.notebook $name]
    lappend tnInfo($win-tabs) $name

    if {$tnInfo($win-pending) == ""} {
        set id [after idle [list tabnotebook_refresh $win]]
        set tnInfo($win-pending) $id
    }
    return $page
}

proc tabnotebook_refresh {win} {
    global tnInfo

    $win.tabs delete all

    set margin [option get $win margin Margin]
    set color [option get $win tabColor Color]
    set font [option get $win tabFont Font]
    set x 2
    set maxh 0

    foreach name $tnInfo($win-tabs) {
        set id [$win.tabs create text \
            [expr $x+$margin+2] [expr -0.5*$margin] \
            -anchor sw -text $name -font $font \
            -tags [list $name]]

        set bbox [$win.tabs bbox $id]
        set wd [expr [lindex $bbox 2]-[lindex $bbox 0]]
        set ht [expr [lindex $bbox 3]-[lindex $bbox 1]]
        if {$ht > $maxh} {
            set maxh $ht
        }

        $win.tabs create polygon 0 0  $x 0 \
            [expr $x+$margin] [expr -$ht-$margin] \
            [expr $x+$margin+$wd] [expr -$ht-$margin] \
            [expr $x+$wd+2*$margin] 0 \
            2000 0  2000 10  0 10 \
            -outline black -fill $color \
            -tags [list $name tab tab-$name]

        $win.tabs raise $id

        $win.tabs bind $name <ButtonPress-1> \
            [list tabnotebook_display $win $name]

        set x [expr $x+$wd+2*$margin]
    }
    set height [expr $maxh+2*$margin]
    $win.tabs move all 0 $height

    $win.tabs configure -width $x -height [expr $height+4]

    if {$tnInfo($win-current) != ""} {
        tabnotebook_display $win $tnInfo($win-current)
    } else {
        tabnotebook_display $win [lindex $tnInfo($win-tabs) 0]
    }
    set tnInfo($win-pending) ""
}

proc tabnotebook_display {win name} {
    global tnInfo

    notebook_display $win.notebook $name

    set normal [option get $win tabColor Color]
    $win.tabs itemconfigure tab -fill $normal

    set active [option get $win activeTabColor Color]
    $win.tabs itemconfigure tab-$name -fill $active
    $win.tabs raise $name

    set tnInfo($win-current) $name
}

# ----------------------------------------------------------------------
#  EXAMPLE: simple notebook that can dial up pages
# ----------------------------------------------------------------------
#  Effective Tcl/Tk Programming
#    Mark Harrison, DSC Communications Corp.
#    Michael McLennan, Bell Labs Innovations for Lucent Technologies
#    Addison-Wesley Professional Computing Series
# ======================================================================
#  Copyright (c) 1996-1997  Lucent Technologies Inc. and Mark Harrison
# ======================================================================

option add *Notebook.borderWidth 2 widgetDefault
option add *Notebook.relief sunken widgetDefault

proc notebook_create {win} {
    global nbInfo

    frame $win -class Notebook
    pack propagate $win 0

    set nbInfo($win-count) 0
    set nbInfo($win-pages) ""
    set nbInfo($win-current) ""
    return $win
}

proc notebook_page {win name} {
    global nbInfo

    set page "$win.page[incr nbInfo($win-count)]"
    lappend nbInfo($win-pages) $page
    set nbInfo($win-page-$name) $page

    frame $page

    if {$nbInfo($win-count) == 1} {
        after idle [list notebook_display $win $name]
    }
    return $page
}

proc notebook_display {win name} {
    global nbInfo

    set page ""
    if {[info exists nbInfo($win-page-$name)]} {
        set page $nbInfo($win-page-$name)
    } elseif {[winfo exists $win.page$name]} {
        set page $win.page$name
    }
    if {$page == ""} {
        error "bad notebook page \"$name\""
    }

    notebook_fix_size $win

    if {$nbInfo($win-current) != ""} {
        pack forget $nbInfo($win-current)
    }
    pack $page -expand yes -fill both
    set nbInfo($win-current) $page
}

proc notebook_fix_size {win} {
    global nbInfo

    update idletasks

    set maxw 0
    set maxh 0
    foreach page $nbInfo($win-pages) {
        set w [winfo reqwidth $page]
        if {$w > $maxw} {
            set maxw $w
        }
        set h [winfo reqheight $page]
        if {$h > $maxh} {
            set maxh $h
        }
    }
    set bd [$win cget -borderwidth]
    set maxw [expr $maxw+2*$bd]
    set maxh [expr $maxh+2*$bd]
    $win configure -width $maxw -height $maxh
}

#***********************************************************************
# %PROCEDURE: SetupGuiToList
# %ARGUMENTS:
#  w -- the PPPoE connection setup window
# %RETURNS:
#  A list of (name value) pairs for the connection.
# %DESCRIPTION:
#  Reads values from the GUI; makes a list.
#***********************************************************************
proc SetupGuiToList { w } {
    global OPTS
    set ans {}
    if {[catch {lappend ans ConnectionName [$w.conName get]}]} {
	lappend ans ConnectionName [$w.conName cget -text]
    }
    lappend ans UserName       [$w.user get]
    lappend ans NetworkName    [$w.network get]
    lappend ans Password       [$w.pass get]
    lappend ans Interface      [$w.ifname get]
    lappend ans DNSType        [$w.dns cget -text]
    lappend ans DNS1           [$w.dns1 get]
    lappend ans DNS2           [$w.dns2 get]
    lappend ans NonrootOK      $OPTS(nonroot)
    lappend ans Sync           $OPTS(sync)
    lappend ans FirewallType   [$w.fw cget -text]
    lappend ans ServiceName    [$w.servicename get]
    lappend ans ACName         [$w.acname get]

    # Validate
    set name [value $ans ConnectionName]
    if {![regexp -nocase {^[-a-z0-9_]+$} $name]} {
	error "Connection name must be non-blank and contain only letters, digits, `_' and `-'"
    }

    # Check DNS
    set type [value $ans DNSType]
    if {"$type" == "Specify"} {
	set dns [value $ans DNS1]
	if {![regexp {[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+} "$dns"]} {
	    error "Primary DNS entry must consist of four dot-separated decimal numbers"
	}
	set dns [value $ans DNS2]
	if {"$dns" != "" && ![regexp {[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+} "$dns"]} {
	    error "Secondary DNS entry must consist of four dot-separated decimal numbers"
	}
    }
    return $ans
}

#***********************************************************************
# %PROCEDURE: ListToSetupGui
# %ARGUMENTS:
#  w -- the PPPoE connection setup window
#  lst -- a list of name/value pairs
# %RETURNS:
#  Nothing
# %DESCRIPTION:
#  Updates GUI to reflect lst
#***********************************************************************
proc ListToSetupGui { w lst } {
    global OPTS
    foreach {key value} $lst {
	switch -exact -- $key {
	    ConnectionName {
		catch {
		    $w.conName delete 0 end
		    $w.conName insert end $value
		}
		catch {
		    $w.conName configure -text $value
		}
	    }
	    UserName {
		$w.user delete 0 end
		$w.user insert end $value
	    }
	    NetworkName {
		$w.network delete 0 end
		$w.network insert end $value
	    }
	    Password {
		$w.pass delete 0 end
		$w.pass insert end $value
	    }
	    Interface {
		$w.ifname delete 0 end
		$w.ifname insert end $value
	    }
	    DNSType {
		SetDNSOption $w $value
	    }
	    DNS1 {
		set oldstate [$w.dns1 cget -state]
		$w.dns1 configure -state normal
		$w.dns1 delete 0 end
		$w.dns1 insert end $value
		$w.dns1 configure -state $oldstate
	    }
	    DNS2 {
		set oldstate [$w.dns2 cget -state]
		$w.dns2 configure -state normal
		$w.dns2 delete 0 end
		$w.dns2 insert end $value
		$w.dns2 configure -state $oldstate
	    }
	    NonrootOK {
		set OPTS(nonroot) $value
	    }
	    Sync {
		set OPTS(sync) $value
	    }
	    FirewallType {
		$w.fw configure -text $value
	    }
	    ServiceName {
		$w.servicename delete 0 end
		$w.servicename insert end $value
	    }
	    ACName {
		$w.acname delete 0 end
		$w.acname insert end $value
	    }
	}
    }
}

proc NewPPPoEConnectionOK { name w } {
    if {[catch {set conn [SetupGuiToList $w]} err]} {
	tk_dialog .err "Invalid Parameters" "$err" error 0 OK
	return
    }
    if {"$name" == ""} {
	set name [value $conn ConnectionName]
	set tmp [GetConnection $name]
	if {"$tmp" != ""} {
	tk_dialog .err "Connection Exists" "The connection `$name' already exists.  Pick another name." error 0 OK
	return
	}
    }
    ReplaceConnection $conn
    SaveConnectionInfo
    BuildConnectionMenu
    SwitchConnection $name
    destroy $w
}

proc SaveConnectionInfo {} {
    global ConnectionInfo ConnectionInfoFile PasswordFile
    set fp [open "$ConnectionInfoFile.new" "w"]
    puts $fp "# RP-PPPoE GUI Configuration Information."
    puts $fp "# This file may *look* human-editable, but it is NOT."
    puts $fp "# So, you with the text editor:  Keep away from this file."
    puts $fp "#"
    set expunged {}
    set passwords {}
    foreach thing $ConnectionInfo {
	set name [value $thing ConnectionName]
	set password [value $thing Password]
	set pwindex [lsearch -exact $thing Password]
	set safe [lreplace $thing $pwindex [expr $pwindex+1]]
	set pwd [list ConnectionName $name Password $password]
	lappend expunged $safe
	lappend passwords $pwd
    }
    puts $fp $expunged
    close $fp
    set fp [open "$PasswordFile.new" "w"]
    exec chmod 600 "$PasswordFile.new"
    puts $fp "# RP-PPPoE GUI Configuration Information."
    puts $fp "# This file may *look* human-editable, but it is NOT."
    puts $fp "# So, you with the text editor:  Keep away from this file."
    puts $fp "#"
    puts $fp $passwords
    close $fp
    file rename -force "$ConnectionInfoFile.new" "$ConnectionInfoFile"
    file rename -force "$PasswordFile.new" "$PasswordFile"

    # Generate config files for adsl-start for each connection
    foreach thing $ConnectionInfo {
	GenerateConfigFile $thing
    }

    # Now update /etc/ppp/pap-secrets and /etc/ppp/chap-secrets
    foreach thing $ConnectionInfo {
	GenerateSecretsEntry $thing
    }
}

#***********************************************************************
# %PROCEDURE: ReadShellEscapedWord
# %ARGUMENTS:
#  str -- a string
# %RETURNS:
#  A two-element list -- the first element is a shell-escaped word
#  extracted from $str, just the way pppd parses /etc/ppp/pap-secrets.
#  The second element is the remaining portion of $str
#***********************************************************************
proc ReadShellEscapedWord { str } {
    set ans {}
    set rest $str

    # Chew up leading spaces
    set rest [string trimleft $rest]

    # If first char is a quote, read until a quote
    if {"[string index $rest 0]" == "\""} {
	set rest [string range $rest 1 end]
	set nextquote [string first "\"" $rest]
	# If no following quote, pretend we haven't seen a quote, I guess.
	if {$nextquote >= 0} {
	    set ans [string range $rest 0 [expr $nextquote-1]]
	    set rest [string range $rest [expr $nextquote+1] end]
	    return [list $ans $rest]
	}
    }

    # Not a quote; chew through the string until an unescaped space
    while {[string length $rest] > 0} {
	set char [string index $rest 0]
	set rest [string range $rest 1 end]
	# Sneaky test for whitespace in Tcl 8.0
	if {"[string trim $char]" == ""} {
	    return [list $ans $rest]
	}
	if {"$char" == "\\"} {
	    set char [string index $rest 0]
	    set rest [string range $rest 1 end]
	}
	append ans $char
    }
    return [list $ans $rest]
}


#***********************************************************************
# %PROCEDURE: GenerateSecretsEntry
# %ARGUMENTS:
#  conn -- a connection key/value list
# %RETURNS:
#  Nothing
# %DESCRIPTION:
#  Adds entries to /etc/ppp/pap-secrets and /etc/ppp/chap-secrets.
#***********************************************************************
proc GenerateSecretsEntry { conn } {
    set user [value $conn UserName]
    set net [value $conn NetworkName]
    set password [value $conn Password]
    if {"$net" != ""} {
	set user "$user@$net"
    }
    GenerateSecretsEntryForFile $user $password "/etc/ppp/pap-secrets"
    GenerateSecretsEntryForFile $user $password "/etc/ppp/chap-secrets"
}

#***********************************************************************
# %PROCEDURE: GenerateSecretsEntryForFile
# %ARGUMENTS:
#  user -- user name
#  password -- password
#  fname -- file to add entry to.
# %RETURNS:
#  Nothing
# %DESCRIPTION:
#  Adds entries to /etc/ppp/pap-secrets or /etc/ppp/chap-secrets.
#***********************************************************************
proc GenerateSecretsEntryForFile { user password fname } {
    # Copy $fname to $fname.new
    set out [open "$fname.new" "w"]
    exec chmod go-rwx "$fname.new"
    if {[file exists $fname]} {
	set in [open $fname "r"]
	while {[gets $in line] >= 0} {
	    set trimmed [string trim $line]
	    if {"$trimmed" == ""} {
		puts $out $line
		continue
	    }
	    if {[string match "#*" $trimmed]} {
		puts $out $line
		continue
	    }

	    # Read the user name off the line; copy it unless it's our
	    # user name.
	    foreach {word dummy} [ReadShellEscapedWord $line] {break}
	    if {$word != $user} {
		puts $out $line
	    }
	}
	close $in
    }

    # Now add our line
    set user [ShellEscape $user]
    set password [ShellEscape $password]
    puts $out "$user\t*\t$password\t*"
    close $out
    file rename -force $fname.new $fname
}

#***********************************************************************
# %PROCEDURE: ShellEscape
# %ARGUMENTS:
#  str
# %RETURNS:
#  A version of $str with shell meta-characters escaped
#***********************************************************************
proc ShellEscape { str } {
    set ans ""
    foreach char [split $str ""] {
	if {[string first $char "01234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_+=-@./"] >= 0} {
	    append ans $char
	} else {
	    append ans "\\$char"
	}
    }
    return $ans
}


#***********************************************************************
# %PROCEDURE: GenerateConfigFile
# %ARGUMENTS:
#  conn -- a connection key/value list
# %RETURNS:
#  Nothing
# %DESCRIPTION:
#  Generates a configuration file for adsl-start and friends under
#  /etc/ppp/rp-pppoe-gui
#***********************************************************************
proc GenerateConfigFile { conn } {
    global ConfigDir
    set name [value $conn ConnectionName]
    set fname [file join $ConfigDir conf.$name]
    set fp [open "$fname.new" w]
    puts $fp "# Configuration file for connection `$name'."
    puts $fp "# Automatically generated.  Do not edit by hand."
    puts $fp ""
    foreach {var val} $conn {
	switch -exact $var {
	    UserName {
		set net [value $conn NetworkName]
		if {"$net" != ""} {
		    set user "$val@$net"
		} else {
		    set user "$val"
		}
		puts $fp [ShellEscape "USER=$user"]
	    }
	    Interface {
		puts $fp [ShellEscape "ETH=$val"]
	    }
	    DNSType {
		if {"$val" == "From Server"} {
		    puts $fp "DNSTYPE=SERVER"
		    puts $fp "USEPEERDNS=yes"
		} elseif {"$val" == "Specify"} {
		    puts $fp "DNSTYPE=SPECIFY"
		    puts $fp "USEPEERDNS=no"
		} else {
		    puts $fp "DNSTYPE=NOCHANGE"
		    puts $fp "USEPEERDNS=no"
		}
	    }
	    DNS1 {
		puts $fp [ShellEscape "DNS1=$val"]
	    }
	    DNS2 {
		puts $fp [ShellEscape "DNS2=$val"]
	    }
	    NonrootOK {
		if {$val} {
		    puts $fp "NONROOT=OK"
		}
	    }
	    ACName {
		puts $fp [ShellEscape "ACNAME=$val"]
	    }
	    ServiceName {
		puts $fp [ShellEscape "SERVICENAME=$val"]
	    }
	    FirewallType {
		if {"$val" == "None"} {
		    puts $fp "FIREWALL=NONE"
		} elseif {"$val" == "Masquerading"} {
		    puts $fp "FIREWALL=MASQUERADE"
		} else {
		    puts $fp "FIREWALL=STANDALONE"
		}
	    }
	    Sync {
		if {$val} {
		    puts $fp "SYNCHRONOUS=yes"
		} else {
		    puts $fp "SYNCHRONOUS=no"
		}
	    }
	}
    }
    puts $fp "CONNECT_TIMEOUT=30"
    puts $fp "CONNECT_POLL=1"
    puts $fp "FORCEPING=\".\""
    puts $fp "PIDFILE=/var/run/adsl-$name.pid"
    puts $fp "CLAMPMSS=1412"
    puts $fp "LCP_INTERVAL=20"
    puts $fp "LCP_FAILURE=3"
    puts $fp "PPPOE_TIMEOUT=80"
    puts $fp "LINUX_PLUGIN="
    puts $fp "DEMAND=no"
    close $fp
    file rename -force "$fname.new" "$fname"
}

#***********************************************************************
# %PROCEDURE: GetConnectionStatus
# %ARGUMENTS:
#  conn -- connection name
# %RETURNS:
#  A three-element list:
#  {started/stopped up/down if}
#  If first element is "started", then connection has been started.
#  If second element is "up", then connection is up.
#  If connection is up, third element is PPP interface.
#***********************************************************************
proc GetConnectionStatus { conn } {
    set pidfile "/var/run/adsl-$conn.pid"

    # Check for PID file
    if {![file readable $pidfile]} {
	return {stopped down ""}
    }
    set fp [open $pidfile "r"]
    gets $fp pid
    close $fp

    # Check if process is dead
    if {![file exists "/proc/$pid"]} {
	# The pppd might still be running... doh...
	if {![file readable "$pidfile.pppd"]} {
	    return {stopped down ""}
	}
	set fp [open "$pidfile.pppd" "r"]
	gets $fp pid
	close $fp
	if {![file exists "/proc/$pid"]} {
	    return {stopped down ""}
	}
    }

    # Now get PID of pppd
    if {![file readable "$pidfile.pppd"]} {
	return {started down ""}
    }
    set fp [open "$pidfile.pppd" "r"]
    gets $fp pid
    close $fp

    # Find interface to which it corresponds
    set pppdfiles [glob -nocomplain "/var/run/ppp*.pid"]
    set found {}
    foreach file $pppdfiles {
	set fp [open $file "r"]
	gets $fp ifpid
	close $fp
	if {$ifpid == $pid} {
	    set found [file rootname [file tail $file]]
	    break
	}
    }
    if {"$found" == ""} {
	return {started down ""}
    }
    return [list started up $found]
}

#***********************************************************************
# %PROCEDURE: UpdateConnectionState
# %ARGUMENTS:
#  fromAfter -- if 1, was called from an "after" callback.
# %RETURNS:
#  Nothing
# %DESCRIPTION:
#  Updates the "LED" displays; periodically reschedules itself to keep
#  updating display.
#***********************************************************************
proc UpdateConnectionState {{fromAfter 1}} {
    global UpdateToken
    global Packets
    global Bytes
    global UpdateInterval
    global MeasureTime
    if {$fromAfter} {
	set UpdateToken ""
    }

    set conn [GetCurrentConnection]
    if {"$conn" == ""} {
	ConnectionStateOff
	ResetGraph
	if {"$UpdateToken" != ""} {
	    after cancel $UpdateToken
	    set UpdateToken {}
	}
	return
    }

    foreach {startstop updown interface} [GetConnectionStatus $conn] {break}
    if {"$startstop" == "stopped"} {
	ConnectionStateOff
	ResetGraph
    } elseif {"$updown" == "down"} {
	ConnectionStateDown
	ResetGraph
    } else {
	# Get the packet counts
	set found 0
	set fp [open "/proc/net/dev" "r"]
	while {[gets $fp line] >= 0} {
	    if {![string match "*$interface:*" $line]} {
		continue
	    }
	    set colon [string first ":" $line]
	    if {$colon < 0} {
		continue
	    }
	    set line [string range $line [expr $colon+1] end]
	    set found 1
	    set MeasureTime [clock seconds]
	    break
	}
	close $fp
	if {$found} {
	    foreach {rbytes rpacks rerrs rdrop rfifo rframe rcomp rmulti tbytes tpacks} $line {break}
	    if {!$fromAfter} {
		set Packets(in) $rpacks
		set Packets(out) $tpacks
		set Bytes(in) $rbytes
		set Bytes(out) $tbytes
		ConnectionStateUp
		ResetGraph
	    } else {
		if {$rpacks != $Packets(in)} {
		    ConnectionReceiveActive
		} else {
		    ConnectionReceiveUp
		}
		if {$tpacks != $Packets(out)} {
		    ConnectionTransmitActive
		} else {
		    ConnectionTransmitUp
		}
		set Packets(in) $rpacks
		set Packets(out) $tpacks
		set Bytes(in) $rbytes
		set Bytes(out) $tbytes
		UpdateGraph
	    }
	} else {
	    ConnectionStateUp
	    ResetGraph
	}
    }
    if {"$UpdateToken" == ""} {
	set UpdateToken [after $UpdateInterval UpdateConnectionState]
    }
    if {$fromAfter} {
	SetButtonStates
    }
}

proc ConnectionStateOff {} {
    .c itemconfigure xmitrect -fill "#A0A0A0"
    .c itemconfigure recvrect -fill "#A0A0A0"
}

proc ConnectionStateDown {} {
    .c itemconfigure xmitrect -fill "#A00000"
    .c itemconfigure recvrect -fill "#A00000"
}

proc ConnectionStateUp {} {
    .c itemconfigure xmitrect -fill "#00D000"
    .c itemconfigure recvrect -fill "#00D000"
}

proc ConnectionTransmitActive {} {
    .c itemconfigure xmitrect -fill "#FFFF00"
}

proc ConnectionTransmitUp {} {
    .c itemconfigure xmitrect -fill "#00D000"
}

proc ConnectionReceiveActive {} {
    .c itemconfigure recvrect -fill "#FFFF00"
}

proc ConnectionReceiveUp {} {
    .c itemconfigure recvrect -fill "#00D000"
}

proc ResetGraph {} {
    global GraphPoints
    set GraphPoints(in) {}
    set GraphPoints(out) {}
    set GraphPoints(times) {}
    .graph delete all
    UpdateGraph
}

proc UpdateGraph {} {
    global GraphPoints Bytes UpdateInterval MeasureTime
    lappend GraphPoints(times) $MeasureTime
    lappend GraphPoints(in) $Bytes(in)
    lappend GraphPoints(out) $Bytes(out)

    set w [winfo width .graph]
    set w2 [expr $w/2]

    set h [winfo height .graph]
    set toChop [expr [llength $GraphPoints(in)] - $w2 - 1]
    if {$toChop > 0} {
	set GraphPoints(in) [lrange $GraphPoints(in) $toChop end]
    }
    set toChop [expr [llength $GraphPoints(out)] - $w2 - 1]
    if {$toChop > 0} {
	set GraphPoints(out) [lrange $GraphPoints(out) $toChop end]
    }
    set toChop [expr [llength $GraphPoints(times)] - $w2 - 1]
    if {$toChop > 0} {
	set GraphPoints(times) [lrange $GraphPoints(times) $toChop end]
    }

    set prev [lindex $GraphPoints(in) 0]
    set incoords {}
    set outcoords {}
    set inmax 0
    set outmax 0
    foreach thing [lrange $GraphPoints(in) 1 end] {
	set diff [expr $thing - $prev]
	set prev $thing
	lappend incoords $diff
	if {$diff > $inmax} {
	    set inmax $diff
	}
    }

    set prev [lindex $GraphPoints(out) 0]
    foreach thing [lrange $GraphPoints(out) 1 end] {
	set diff [expr $thing - $prev]
	set prev $thing
	lappend outcoords $diff
	if {$diff > $outmax} {
	    set outmax $diff
	}
    }

    if {$inmax == 0} { set inmax 1 }
    if {$outmax == 0} { set outmax 1 }
    # Draw the transmit line
    set x 0
    set hh [expr $h-4]
    set scaled {}
    foreach thing $outcoords {
	lappend scaled $x [expr double($h) - 2 - (double($hh) * double($thing) / double($outmax))]
	incr x
    }

    .graph delete all
    if {[llength $scaled] >= 4} {
	eval ".graph create line $scaled -fill #A00000"
	set bits [expr 8.0 * ([lindex $GraphPoints(out) end] - [lindex $GraphPoints(out) 0])]
	set timediff [expr [lindex $GraphPoints(times) end] - [lindex $GraphPoints(times) 0]]
	if {$timediff != 0} {
	    set bps [Pretty [expr double($bits) / $timediff]]
	    .graph create text 2 2 -anchor nw -font fixed -text "$bps"
	}
    }

    # Draw the receive line
    set x $w2
    set scaled {}
    foreach thing $incoords {
	lappend scaled $x [expr double($h) - 2 - (double($hh) * double($thing) / double($inmax))]
	incr x
    }

    if {[llength $scaled] >= 4} {
	eval ".graph create line $scaled -fill #00A000"
	set bits [expr 8.0 * ([lindex $GraphPoints(in) end] - [lindex $GraphPoints(in) 0])]
	set timediff [expr [lindex $GraphPoints(times) end] - [lindex $GraphPoints(times) 0]]
	if {$timediff != 0} {
	    set bps [Pretty [expr double($bits) / $timediff]]
	    .graph create text [expr $w2+2] 2 -anchor nw -font fixed -text "$bps"
	}
    }
}

proc Pretty { n } {
    if {$n < 0} {
	return "***"
    }
    if {$n < 1000} {
	return [format "%.1f" $n]
    }
    set n [expr $n/1000.0]
    if {$n < 1000} {
	return [format "%.1fk" $n]
    }
    set n [expr $n/1000.0]
    if {$n < 1000} {
	return [format "%.1fM" $n]
    }
    set n [expr $n/1000.0]
    return [format "%.1fG" $n]
}

#***********************************************************************
# %PROCEDURE: Help
# %ARGUMENTS:
#  None
# %RETURNS:
#  Nothing
# %DESCRIPTION:
#  Opens help page
#***********************************************************************
proc Help {} {
    if {![file readable /usr/share/rp-pppoe-gui/tkpppoe.html]} {
	    tk_dialog .err Error "Help file '/usr/share/rp-pppoe-gui/tkpppoe.html' is not installed" error 0 OK	
	return
    }
    catch { exec /bin/sh -c "netscape -remote 'openURL(/usr/share/rp-pppoe-gui/tkpppoe.html)' || netscape /usr/share/rp-pppoe-gui/tkpppoe.html" > /dev/null 2>/dev/null & }
}

	

#***********************************************************************
# %PROCEDURE: doLogo
# %ARGUMENTS:
#  None
# %RETURNS:
#  Nothing
# %DESCRIPTION:
#  Does the logo thing
#***********************************************************************
proc doLogo {} {
    global AlreadyRunFile ConfigDir
    if {[file exists $AlreadyRunFile]} {
	return
    }
    catch { file mkdir $ConfigDir }
    catch { close [open $AlreadyRunFile "w"] }
    canvas .c -width 374 -height 286 -bg #FFFFCC
    pack .c
    drawLogo .c #FFFFCC

    # Funky effect
    .c create text 4 4 -anchor nw -text "Welcome to RP-PPPoE" \
	    -fill red -font {-family times -size -24 -weight bold} -tags pppoe
    .c lower pppoe

    .c move logo -300 0

    update idletasks

    for {set i 0} {$i < 15} {incr i} {
	.c move logo 20 0
	update idletasks
	after 25
    }

    .c create text 4 28 -anchor nw -text "http://www.roaringpenguin.com" \
	    -fill red -font {-family courier -size -14 -weight bold}
    update idletasks
    after 2500
}

doLogo
catch { destroy .c }

# Try creating an empty config file if none exists
if {![file readable $ConnectionInfoFile]} {
    catch { file mkdir $ConfigDir }
    catch {
	set fp [open $ConnectionInfoFile "w"]
	close $fp
    }
}

CreateMainDialog