-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmulticoin.php
1567 lines (1428 loc) · 49.8 KB
/
multicoin.php
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
<?php
$version="4.19";
function RandomString($length = 20) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}
#**************************************************************************#
function dialog_menu ($args) {
$pipes = array (NULL, NULL, NULL);
# Allow user to interact with dialog
$in = fopen ('php://stdin', 'r');
$out = fopen ('php://stdout', 'w');
# But tell PHP to redirect stderr so we can read it
$p = proc_open ('dialog '.$args, array (
0 => $in,
1 => $out,
2 => array ('pipe', 'w')
), $pipes);
# Wait for and read result
$result = stream_get_contents ($pipes[2]); #inhalt
// Close all handles
fclose ($pipes[2]);
fclose ($out);
fclose ($in);
proc_close ($p); #exit code
return $result;
}
#****************************************************************#
function dialog ($args) {
$pipes = array (NULL, NULL, NULL);
# Allow user to interact with dialog
$in = fopen ('php://stdin', 'r');
$out = fopen ('php://stdout', 'w');
# But tell PHP to redirect stderr so we can read it
$p = proc_open ('dialog '.$args, array (
0 => $in,
1 => $out,
2 => array ('pipe', 'w')
), $pipes);
# Wait for and read result
$result1 = stream_get_contents ($pipes[2]); #inhalt
// Close all handles
fclose ($pipes[2]);
fclose ($out);
fclose ($in);
$result2=proc_close ($p); #exit code
$result=$result2."|".$result1;
return $result;
}
#****************************************************************#
function dialog_input ($args) {
$pipes = array (NULL, NULL, NULL);
# Allow user to interact with dialog
$in = fopen ('php://stdin', 'r');
$out = fopen ('php://stdout', 'w');
# But tell PHP to redirect stderr so we can read it
$p = proc_open ('dialog '.$args, array (
0 => $in,
1 => $out,
2 => array ('pipe', 'w')
), $pipes);
# Wait for and read result
$result = stream_get_contents ($pipes[2]);
// Close all handles
fclose ($pipes[2]);
fclose ($out);
fclose ($in);
proc_close ($p);
return $result;
}
#****************************************************************#
function scan_nodes($db,$coin)
{
$db->exec("DELETE FROM nodes where coin='$coin'");
$results = $db->query("SELECT * from coin where coin_name='$coin'");
$row = $results->fetchArray();
$daemon=$row['daemon'];
$cli=$row['cli'];
$home=$row['home_dir'];
$prefix=$row['datadir'];
$conf=$row['confname'];
$prefix_len=strlen($prefix);
if ( $handle = opendir($home) )
{
// einlesen der Verzeichnisses
while (($file = readdir($handle)) !== false)
{
$pos = strpos($file, substr($prefix,1));
if ($pos)
{
$z=substr($file,$prefix_len);
#dialog("--msgbox '$z' 5 40");
$alias=$z;
$status="";
$block=0;
$aktiv=0;
$ip="";
#exec("$cli -conf=$conf -datadir=$home/$prefix$alias masternode status >mnstatus.txt 2>&1",$lines,$result);
exec("$cli -conf=$conf -datadir=$home/$prefix$alias masternodedebug >mnstatus.txt 2>&1",$lines,$result);
#dialog("--title 'Masternodedebug: $coin -> $alias' --textbox 'mnstatus.txt' 0 0");
$status_file = file("mnstatus.txt");
$status="";
$status=$status_file[0];
$status=str_replace("'", '', $status);
$status=trim($status);
$sync="no";
exec("$cli -conf=$conf -datadir=$home/$prefix$alias mnsync status >mnstatus.txt 2>&1",$lines,$result);
#dialog("--title 'Sync: Masternode: $mn' --textbox 'mnstatus.txt' 0 0");
$resp = file_get_contents("mnstatus.txt");
$obj = json_decode($resp);
$sync=$obj->IsBlockchainSynced;
#dialog("--msgbox '$alias Sync status: $sync' 15 40");
# $status_file = file("mnstatus.txt");
# $z=$status_file[0];
# $pos=strpos($z,"true");
# if ($pos > 0)
# {
# $sync="yes";
# #dialog("--msgbox 'status: $status' 15 40");
# }
$db->exec("INSERT INTO nodes(coin,alias,status,block,ip,aktiv,sync) VALUES ('$coin', '$alias', '$status', $block, '$ip', $aktiv, '$sync')");
$errno=$db->lastErrorCode();
if ($errno > 0) {
$err=$db->lastErrorMsg();
dialog("--msgbox 'SQL-Error Scan Nodes: $errno -> $err' 90 90");
}
}
}
closedir($handle);
} #ende -> if ( $handle = opendir($home) )
}
#****************************************************************#
function stop_all_nodes($db)
{
$coin=$GLOBALS['coin'];
$results = $db->query("SELECT * from coin where coin_name='$coin'");
$row = $results->fetchArray();
$home=$row['home_dir'];
$prefix=$row['datadir'];
scan_nodes($db,$coin);
$results = $db->query("SELECT * from nodes where coin='$coin'");
while ($row = $results->fetchArray())
{
$alias=$row['alias'];
dialog ("--title 'Stop all $coin Nodes' --infobox 'Please wait..stopping $alias' 5 50");
exec("systemctl stop $prefix$alias.service");
sleep(3);
}
}
#****************************************************************#
function start_all_nodes($db)
{
$coin=$GLOBALS['coin'];
$results = $db->query("SELECT * from coin where coin_name='$coin'");
$row = $results->fetchArray();
$home=$row['home_dir'];
$prefix=$row['datadir'];
scan_nodes($db,$coin);
$results = $db->query("SELECT * from nodes where coin='$coin'");
while ($row = $results->fetchArray())
{
$alias=$row['alias'];
dialog ("--title 'Start all $coin Nodes' --infobox 'Please wait..starting $alias' 5 50");
exec("systemctl start $prefix$alias.service");
sleep(3);
}
}
#****************************************************************#
function scan_conf($db)
{
$db->exec("DELETE FROM conf");
$coin=$GLOBALS['coin'];
$results = $db->query("SELECT * from coin where coin_name='$coin'");
$row = $results->fetchArray();
$home=$row['home_dir'];
$prefix=$row['datadir'];
$conf=$row['confname'];
if ( $handle = opendir($home) )
{
$mn_array=array();
$i=0;
while (($file = readdir($handle)) !== false)
{
$pos = strpos($file, substr($prefix,1));
if ($pos)
{
$mn_array[$i]=$file;
$i++;
}
}
closedir($handle);
$c=count($mn_array);
for($i=0; $i < $c; $i++)
{
$z=$home."/".$mn_array[$i]."/$conf";
#dialog("--msgbox '$z' 5 40");
$conf_file = file("$z");
for($j=0;$j < count($conf_file); $j++)
{
$z=$conf_file[$j];
#dialog("--msgbox '$z' 5 40");
#....................................
if (substr($z,0,7) == "rpcport" )
{
$t = explode("=", $z);
$rpcport=$t[1];
#dialog("--msgbox '--> rpcport: $rpcport' 5 40");
}
#..................................#
if (substr($z,0,4) == "port" )
{
$t = explode("=", $z);
$port=$t[1];
#dialog("--msgbox '--> port: $port' 5 40");
}
#..................................#
if (substr($z,0,4) == "bind" )
{
$t = explode("=", $z);
$bind=$t[1];
$bind=trim($bind);
}
} #end of for($j=0;$j < count($conf_file); $j++)
$sql="INSERT INTO conf (coin, alias, port, rpcport, ip) ";
$mna=$mn_array[$i];
$sql.="VALUES ('$coin', '$mna', $port, $rpcport, '$bind')";
$db->exec($sql);
}
} #end of if ( $handle = opendir($home) )
}
#****************************************************************#
function get_privkey($db,$alias,$ip)
{
$coin=$GLOBALS['coin'];
$results = $db->query("SELECT * from coin where coin_name='$coin'");
$row = $results->fetchArray();
$daemon=$row['daemon'];
$cli=$row['cli'];
$home=$row['home_dir'];
$prefix=$row['datadir'];
$conf=$row['confname'];
$port=$row["port"];
$hoch_rpcport=$port;
$lowport=$port;
#get port
$c = $db->querySingle("SELECT COUNT(*) as c FROM conf WHERE coin='$coin'");
#dialog("--msgbox 'c von conf=$c' 5 40");
if ($c > 0)
{
$port=$lowport-1; #ipv4 only
$results = $db->query("SELECT *from conf where coin='$coin' ORDER BY port DESC");
while ($row = $results->fetchArray())
{
$lowport=$row['port'];
}
#dialog("--msgbox 'c=$c ->lowport: $lowport' 5 40");
}
$c = $db->querySingle("SELECT COUNT(*) as c FROM ipv6");
if ($c == 0)
{
$port=$lowport-1; #ipv4 only
#dialog("--msgbox 'ipv4 only c=$c ->port: $port' 5 40");
}
# get rpcport
$results = $db->query("SELECT * from conf where coin='$coin' ORDER BY rpcport ASC");
while ($row = $results->fetchArray())
{
$hoch_rpcport=$row['rpcport'];
}
$rpcuser=RandomString();
$rpcpassword=RandomString();
$rpcallowip="127.0.0.1";
$rpcport=$hoch_rpcport+1;
$pos=strpos($ip,":");
if ($pos > 0)
{
$ip="[".$ip."]";
}
$z="rpcuser=$rpcuser\n";
$z.="rpcpassword=$rpcpassword\n";
$z.="rpcallowip=127.0.0.1\n";
$z.="rpcport=$rpcport\n";
$z.="listen=1\n";
$z.="server=1\n";
$z.="daemon=1\n";
$z.="logintimestamps=1\n";
$z.="maxconnections=32\n";
$z.="masternode=0\n";
$z.="port=$port\n";
$z.="bind=$ip\n";
$z.="externalip=$ip\n";
#$z.="masternodeprivkey=$privkey\n";
if (!file_exists($home)) mkdir($home);
$folder="$home/$prefix$alias";
$file=$folder."/".$conf;
file_put_contents($file, $z);
#dialog("--title 'Privkey' --textbox '$file' 0 0");
dialog ("--title 'Generating Privkey' --infobox 'Please wait..' 5 50");
$punkte="..";
#dialog("--title 'Privkey' --msgbox 'Starte $daemon: -conf=$conf -datadir=$home/$prefix$alias ' 25 40");
exec("systemctl start $prefix$alias");
sleep(5);
dialog ("--title 'Generating Privkey' --infobox 'Please wait$punkte' 5 50");
#dialog("--title 'Privkey' --msgbox 'Starte $cli: -conf=$conf -datadir=$home/$prefix$alias ' 25 40");
do
{
exec("$cli -conf=$conf -datadir=$home/$prefix$alias createmasternodekey >mnstatus.txt 2>&1");
#dialog("--title 'Privkey' --textbox 'mnstatus.txt' 0 0");
$z = file("mnstatus.txt");
$p=$z[0];
$err=substr($p,0,5);
#dialog("--title 'Privkey' --msgbox 'err: $p' 25 40");
$punkte.="..";
dialog ("--title 'Generating Privkey' --infobox 'Please wait$punkte' 5 50");
sleep(3);
} while ($err=="error");
#dialog("--msgbox 'First PrivKey: $p ' 5 40");
$punkte.="..";
dialog ("--title 'Generating Privkey' --infobox 'Please wait$punkte' 5 50");
exec("systemctl stop $prefix$alias");
sleep(5);
return $p;
}
#-----------------------------------------------------------------#
function make_systemservice($db,$alias)
{
$coin=$GLOBALS['coin'];
$results = $db->query("SELECT * from coin where coin_name='$coin'");
$row = $results->fetchArray();
$daemon=$row['daemon'];
$cli=$row['cli'];
$repo=$row['repo'];
$port=$row['port'];
$home=$row['home_dir'];
$prefix=$row['datadir'];
$conf=$row['confname'];
$coin_user="root";
$z="[Unit]\n";
$z.="Description=$prefix$alias service\n";
$z.="After=network.target\n";
$z.="[Service]\n";
$z.="User=$coin_user\n";
$z.="Group=$coin_user\n";
$z.="Type=forking\n";
$z.="ExecStart=/usr/local/bin/$daemon -conf=/$coin_user/$home/${prefix}$alias/$conf -datadir=/$coin_user/$home/${prefix}$alias\n";
$z.="ExecStop=-/usr/local/bin/$cli -conf=/$coin_user/$home/${prefix}$alias/$conf -datadir=/$coin_user/$home/${prefix}$alias stop\n";
$z.="Restart=always\n";
$z.="PrivateTmp=true\n";
$z.="TimeoutStopSec=60s\n";
$z.="TimeoutStartSec=10s\n";
$z.="StartLimitInterval=120s\n";
$z.="StartLimitBurst=5\n";
$z.="[Install]\n";
$z.="WantedBy=multi-user.target\n";
$file="/etc/systemd/system/${prefix}$alias.service";
file_put_contents($file, $z);
exec("systemctl enable ${prefix}$alias.service");
} # end of make_systemservice($db,$alias)
#-----------------------------------------------------------------#
function make_conf($db,$alias,$privkey,$ip)
{
$coin=$GLOBALS['coin'];
$results = $db->query("SELECT * from coin where coin_name='$coin'");
$row = $results->fetchArray();
$daemon=$row['daemon'];
$cli=$row['cli'];
$repo=$row['repo'];
$port=$row['port'];
$home=$row['home_dir'];
$prefix=$row['datadir'];
$conf=$row['confname'];
$hoch_rpcport=$port;
$lowport=$port;
#get port
#$c = $db->querySingle("SELECT COUNT(*) as c FROM conf WHERE coin='$coin'");
#dialog("--msgbox 'c von conf=$c' 5 40");
#if ($c > 0)
#{
# $port=$lowport-1; #ipv4 only
# $results = $db->query("SELECT *from conf where coin='$coin' ORDER BY port DESC");
# while ($row = $results->fetchArray())
# {
# $lowport=$row['port'];
# }
# #dialog("--msgbox 'c=$c ->lowport: $lowport' 5 40");
#}
$c = $db->querySingle("SELECT COUNT(*) as c FROM ipv6");
if ($c == 0)
{
$results = $db->query("SELECT coin,port from conf where coin='$coin' ORDER BY port ASC");
while ($row = $results->fetchArray())
{
$lowport=$row['port'];
}
$port=$lowport-1; #ipv4 only
#dialog("--msgbox 'ipv4 only c=$c ->port: $port' 5 40");
}
# get rpcport
$results = $db->query("SELECT * from conf where coin='$coin' ORDER BY rpcport ASC");
while ($row = $results->fetchArray())
{
$hoch_rpcport=$row['rpcport'];
}
$rpcuser=RandomString();
$rpcpassword=RandomString();
$rpcallowip="127.0.0.1";
$rpcport=$hoch_rpcport +1;
$pos=strpos($ip,":");
if ($pos > 0) $ip="[".$ip."]";
$z="rpcuser=$rpcuser\n";
$z.="rpcpassword=$rpcpassword\n";
$z.="rpcallowip=127.0.0.1\n";
$z.="rpcport=$rpcport\n";
$z.="listen=1\n";
$z.="server=1\n";
$z.="daemon=1\n";
$z.="logintimestamps=1\n";
$z.="maxconnections=32\n";
$z.="masternode=1\n";
$z.="port=$port\n";
$z.="bind=$ip\n";
$z.="externalip=$ip\n";
$z.="masternodeprivkey=$privkey\n";
if (!file_exists($home)) mkdir($home);
$folder="$home/$prefix$alias";
$file=$folder."/".$conf;
file_put_contents($file, $z);
return($ip);
} # end of m;ake_conf
#-----------------------------------------------------------------#
function fastsync($db,$alias)
{
$coin=$GLOBALS['coin'];
$results = $db->query("SELECT * from coin where coin_name='$coin'");
$row = $results->fetchArray();
$home=$row['home_dir'];
$prefix=$row['datadir'];
#dialog("--msgbox 'Fastsync-Check' 10 90");
$coin=$GLOBALS['coin'];
$c = $db->querySingle("SELECT COUNT(*) as c FROM nodes WHERE coin='$coin' and sync='1'");
if ($c == 0)
{
dialog("--msgbox 'No masternode available for Fastsync !' 10 90");
}
else
{
$results = $db->query("SELECT * from nodes where coin='$coin' and sync='1'");
$row = $results->fetchArray();
$sync_alias=$row['alias'];
#dialog("--msgbox 'Fastsync-alias: $sync_alias' 10 90");
dialog ("--infobox 'Please wait for Fastsync...' 5 50");
exec("systemctl stop $prefix$sync_alias");
sleep(10);
$active_node="$home/$prefix$sync_alias";
# exec("ls -l -R >fs.log");
dialog ("--infobox 'Copying blocks...$active_node/blocks -> $home/$prefix$alias/blocks' 5 50");
exec("cp -r $active_node/blocks $home/$prefix$alias/ 2>>fs.log");
dialog ("--infobox 'Copying chainstate...$active_node/chainstate -> $home/$prefix$alias/chainstate' 5 50");
exec("cp -r -v $active_node/chainstate $home/$prefix$alias/ 2>>fs.log");
dialog ("--infobox 'Copying sporks...$active_node/sporks $home/$prefix$alias/sporks' 5 50");
exec("cp -r -v $active_node/sporks $home/$prefix$alias/ 2>>fs.log");
dialog ("--infobox 'Copying peers.dat...$active_node/peers.dat $home/$prefix$alias/peers.dat' 5 50");
exec("cp -v $active_node/peers.dat $home/$prefix$alias/peers.dat 2>>fs.log");
exec("systemctl start $prefix$sync_alias");
}
}
#-----------------------------------------------------------------#
function masternode_menu ($coin,$mn,$db)
{
$coin=$GLOBALS['coin'];
if ($coin == "NONE")
{
dialog("--msgbox 'Please select a coin first !' 5 40");
return;
}
$results = $db->query("SELECT * from coin where coin_name='$coin'");
$row = $results->fetchArray();
$coin_name=$row['coin_name'];
$daemon=$row['daemon'];
$cli=$row['cli'];
$repo=$row['repo'];
$port=$row['port'];
$home=$row['home_dir'];
$prefix=$row['datadir'];
$conf=$row['confname'];
do {
$alias=$GLOBALS['alias'];
exec("systemctl status ${prefix}$alias.service >mnstatus.txt");
$t= file("mnstatus.txt");
$z=$t[2];
$pos=strpos($z,"running");
if($pos > 0)
{
$status="running";
}
else
{
$status="inactive";
}
$args=" --clear --title 'Submenu: Masternode [Coin: $coin - Masternode: $alias ]' --menu '' 30 80 30 ";
$args.="1 'Getinfo' ";
$args.="- '------------------' ";
$args.="2 'Status' ";
$args.="- '------------------' ";
$args.="3 'Start/Stop Systemctl ($status)' ";
$args.="- '------------------' ";
$args.="4 'Edit $conf' ";
$args.="- '------------------' ";
$args.="5 'Select Masternode' ";
$args.="- '------------------' ";
$args.="6 'Install Masternode' ";
$args.="- '--------------' ";
$args.="7 'Delete Masternode' ";
$args.="- '--------------' ";
$args.="8 'Stop all $coin Nodes' ";
$args.="- '--------------' ";
$args.="9 'Start all $coin Nodes' ";
$args.="- '--------------' ";
$args.="A 'Systemctl status' ";
$args.="- '--------------' ";
$args.="B 'Debug Command' ";
$args.="- '--------------' ";
$args.="0 'Back to Main-Menu'";
$menu_item=dialog_menu($args);
echo "$menu_item\n";
if ($menu_item == "1")
{
exec("$cli -conf=$conf -datadir=$home/$prefix$alias getinfo >mnstatus.txt 2>&1",$lines,$result);
dialog("--title 'Masternode: $coin_name - $alias' --textbox 'mnstatus.txt' 0 0");
}
#........................................................................#
if ($menu_item == "2")
{
exec("$cli -conf=$conf -datadir=$home/$prefix$alias masternode status >mnstatus.txt 2>&1",$lines,$result);
$t= file("mnstatus.txt");
$z=$t[0];
# $z.="\n".$t[1];
# $z.="\n".$t[2];
# $z.="\n".$t[3];
# $z.="\n".$t[4];
# $z.="\n".$t[5];
# $z.="\n".$t[6];
# $z.="\n".$t[7];
$z.=$t[1];
$z.=$t[2];
$z.=$t[3];
$z.=$t[4];
$z.=$t[5];
$z.=$t[6];
$z.=$t[7];
dialog("--title 'Masternode: $coin_name - $mn' --msgbox '$z' 15 90");
}
#........................................................................#
if ($menu_item == "3")
{
exec("systemctl status ${prefix}$alias.service >mnstatus.txt");
$t= file("mnstatus.txt");
$z=$t[2];
$pos=strpos($z,"running");
dialog ("--infobox 'Please wait.....' 5 50");
if($pos > 0)
{
exec("systemctl stop ${prefix}$alias.service");
$status="inactive";
}
else
{
exec("systemctl start ${prefix}$alias.service");
$status="running";
}
}
#........................................................................#
if ($menu_item == "4")
{
$file="$home/$prefix$alias/$conf";
#dialog("--title 'Masternode: $mn' --textbox '$file' 0 0");
$res=dialog_input("--title 'Masternode: $mn' --editbox '$file' 0 0");
$t = explode("|", $res); #0=exitcode 1=inhalt
#dialog("--title 'Debug editbox' --msgbox 'Exitcode: $t[0] * Inhalt: $t[1]' 5 40");
if ($t[0] =="") return; #erfassung ganz beenden
file_put_contents($file, $t[0]);
}
#........................................................................#
if ($menu_item == "5") #select masternode
{
$db->exec("DELETE FROM tempsort");
$z="";
$prefix_len=strlen($prefix);
if ( $handle = opendir($home) )
{
// einlesen der Verzeichnisses
$mn_array=array();
$i=1;
$args=" --clear --title 'Select a Masternode' --menu '' 30 80 30 ";
while (($file = readdir($handle)) !== false)
{
$pos = strpos($file, substr($prefix,1));
if ($pos)
{
$z=substr($file,$prefix_len);
$db->exec("INSERT INTO tempsort(feld) VALUES ('$z')");
}
}
closedir($handle);
$args=" --clear --title 'Select a Masternode' --menu '' 30 80 30 ";
$mn_array=array();
$i=1;
$results = $db->query("SELECT * from tempsort ORDER BY feld");
while ($row = $results->fetchArray())
{
$z=$row["feld"];
$mn_array[$i]=$z;
$i_str=strval($i);
$args.="$i_str '$z' ";
$i++;
}
do
{
$menu=dialog_menu($args);
$index=intval($menu);
$mn=$mn_array[$index];
} while ($menu = "0");
} #ende -> if ( $handle = opendir($home) )
$GLOBALS['alias']=$mn;
}
#..............Install Masternode.........................................#
if ($menu_item == "6")
{
scan_conf($db);
scan_nodes($db,$coin);
$ipv4only=0;
$c = $db->querySingle("SELECT COUNT(*) as c FROM ipv6");
if ($c == 0)
{
$ipv4only=1;
dialog("--msgbox 'You are using ipv4only (Several Nodes with same IPV4 IP). Working is not guaranteed.' 5 40");
}
$args=" --clear --title 'Select IP' --menu '' 30 80 30 ";
$ip_array=array();
$i=1;
$results = $db->query("SELECT ip from ipv4");
while ($row = $results->fetchArray())
{
$ip=$row['ip'];
$ip_array[$i]=$ip;
$i_str=strval($i);
$c = $db->querySingle("SELECT COUNT(*) as count FROM conf WHERE coin='$coin' and ip LIKE '%$ip%'");
$t=" in use";
if (($c == 0) or ($ipv4only == 1))
{
$t="free";
$args.="$i_str '$ip $t' ";
$i++;
}
}
$results = $db->query("SELECT ip from ipv6");
while ($row = $results->fetchArray())
{
$ip=$row['ip'];
$ip_array[$i]=$ip;
$i_str=strval($i);
$c = $db->querySingle("SELECT COUNT(*) as count FROM conf WHERE coin='$coin' and ip LIKE '%$ip%'");
$t=" in use";
if ($c == 0)
{
$t="free";
$args.="$i_str '$ip $t' ";
$i++;
}
}
do
{
$menu=dialog_menu($args);
$index=intval($menu);
$ip=$ip_array[$index];
} while ($menu = "0");
#dialog("--msgbox 'Selected IP: $ip' 5 40");
if ($ip =="")
{
dialog("--msgbox 'No IP selected or no IP free - Install aborted' 15 40");
return;
}
do {
$res=dialog("--inputbox 'New alias ?' 0 0");
$t = explode("|", $res); #0=exitcode 1=inhalt
if ($t[0] > 0) return; #erfassung ganz beenden
$alias=$t[1];
} while ($t[1] == "");
$folder="$home/$prefix$alias";
mkdir($folder);
make_systemservice($db,$alias);
$privkey=get_privkey($db,$alias,$ip);
if ($privkey == "abort")
{
dialog("--msgbox 'Installation aborted' 5 40");
}
else
{
$externalip=make_conf($db,$alias,$privkey,$ip);
}
fastsync($db,$alias);
$GLOBALS['alias']=$alias;
exec("systemctl start $prefix$alias");
$ok=0;
do
{
dialog ("--infobox 'New masternode is starting...' 5 50");
sleep(5);
exec("$cli -conf=$conf -datadir=$home/$prefix$alias getinfo >mnstatus.txt 2>&1",$lines,$result);
#dialog("--title 'Masternode: $coin_name - $mn' --textbox 'mnstatus.txt' 0 0");
$t= file("mnstatus.txt");
$z=$t[0];
$z=trim($z);
if ($z=="{") $ok=1;
} while ($ok==0);
system('clear');
echo "\n";
echo "Copy and paste the line below in your masternode.conf on your PC\n";
echo "\n";
echo "$alias $externalip:$port $privkey\n";
echo "<alias> <ip:port> <privkey>\n";
echo "\n";
echo "Then goto your PC wallet, make a new address and send your collateral payment.\n";
echo "Add the txid and outputindex to the line\n";
$line = readline("<Press Enter if done>");
} # end of 6 - Install Masternode
#.................delete masternode......................................#
if ($menu_item == "7") #delete masternode
{
$args="--title 'Delete Masternode $mn' --defaultno --yesno 'Do you really want to delete $coin Masternode $mn ?' 7 60";
$res=dialog($args);
#dialog("--msgbox 'Antwort: $res' 5 40");
if ($res == 0)
{
exec("systemctl stop ${prefix}$alias.service");
sleep(5);
exec("systemctl diable ${prefix}$alias.service");
exec("rm -R $home/${prefix}$alias");
$file="/etc/systemd/system/${prefix}$alias.service";
unlink($file);
dialog("--title '' --msgbox 'Masternode: $alias deleted !' 5 40");
$GLOBALS['alias']="NONE";
}
}
#.........................................................................#
if ($menu_item == "8") #stop all nodes
{
$args="--title 'Stop all $coin Masternodes' --defaultno --yesno 'Do you really want to stop ALL $coin Masternode ?' 7 60";
$res=dialog($args);
#dialog("--msgbox 'Antwort: $res' 5 40");
if ($res == 0)
{
stop_all_nodes($db);
$GLOBALS['alias']="NONE";
}
}
#.........................................................................#
if ($menu_item == "9") #start all nodes
{
$args="--title 'Stop all $coin Masternodes' --defaultno --yesno 'Do you really want to start ALL $coin Masternode ?' 7 60";
$res=dialog($args);
#dialog("--msgbox 'Antwort: $res' 5 40");
if ($res == 0)
{
start_all_nodes($db);
$GLOBALS['alias']="NONE";
}
}
if ($menu_item == "A")
{
exec("systemctl -l status ${prefix}$alias.service >mnstatus.txt");
dialog("--title 'Ststus: $coin_name - $alias' --textbox 'mnstatus.txt' 0 0");
}
if ($menu_item == "B")
{
echo "$daemon -conf=$conf -datadir=$home/$prefix$alias \n";
echo "$cli -conf=$conf -datadir=$home/$prefix$alias getinfo \n";
$line = readline("<Press Enter to return>");
}
} while ($menu_item != "0");
}
#****************************************************************#
function get_ipv6 ($db)
{
$db->exec("DELETE FROM ipv6");
exec('/sbin/ifconfig' ,$lines, $result);
$c=count($lines);
for($i=1; $i < $c; $i++)
{
$z=$lines[$i];
$t=explode(" ",$z);
$t10=$t[10];
$t12=$t[12];
$pos=strpos($t12,"/");
if (($t10 == "inet6") and ($pos > 0))
{
$v=explode("/",$t12);
$ipv6=$v[0];
$db->exec("INSERT INTO ipv6(ip) VALUES ('$ipv6')");
}
}
$db->exec("DELETE FROM ipv6 where ip LIKE 'fe80%'");
}
#****************************************************************#
function get_ip_neu($db)
{
$db->exec("DELETE FROM ipv6");
exec('/sbin/ifconfig >ip.txt');
$lines=file("ip.txt");
$z=$lines[0];
$t=explode(" ",$z);
$network_interfacename=$t[0];
#dialog("--msgbox 'Interfacename: $network_interfacename' 5 40");
exec('ip addr show $network_interfacename | grep -vw "inet" | grep "global" | grep -w "inet6" | cut -d/ -f1 >ipv6_addresses.txt');
$lines=file('ipv6_addresses.txt');
$c=count($lines);
for($i=0; $i < $c; $i++)
{
$z=$lines[$i];
$ipv6=str_replace("inet6", "",$z );
$ipv6=trim($ipv6);
#dialog("--msgbox '$ipv6' 5 40");
$db->exec("INSERT INTO ipv6(ip) VALUES ('$ipv6')");
}
$db->exec("DELETE FROM ipv6 where ip LIKE 'fe80%'");
$db->exec("DELETE FROM ipv4");
exec('ip addr show $network_interfacename | grep -vw "inet6" | grep "global" | grep -w "inet" | cut -d/ -f1 >ipv4_addresses.txt');
$lines=file('ipv4_addresses.txt');
$c=count($lines);
for($i=0; $i < $c; $i++)
{
$z=$lines[$i];
$ipv4=str_replace("inet", "",$z );
$ipv4=trim($ipv4);
#dialog("--msgbox '$ipv4' 5 40");
$db->exec("INSERT INTO ipv4(ip) VALUES ('$ipv4')");
}
#$db->exec("DELETE FROM ipv6 where ip LIKE 'fe80%'");
}
#***************************************************************#
function wallet_menu ($coin,$mn)
{
do {
$args=" --clear --title 'Submenu: Masternode [Coin: $coin_name - Masternode: $A ]' --menu '' 30 80 30 ";
$args.="1 'Getinfo' ";
$args.="2 'Status' ";
$args.="3 'Edit Conf-File' ";
$args.="4 '--------------' ";
$args.="5 'Select Masternode' ";
$args.="0 'Back to Main-Menu'";
$menu_item=dialog($args);
echo "$menu_item\n";
if ($menu_item == "1")
{
}
} while ($menu_item != "0");
}
#****************************************************************#
function insert_coin($db)
{
#Coin Name
do {
$res=dialog("--help-button --hfile 'temp.hlp' --help-label 'F1-Help' --hline 'Shift-Insert for copy/paste' --inputbox 'Coin Name ?' 0 0");
$t = explode("|", $res); #0=exitcode 1=inhalt
#dialog("--msgbox 'Exitcode: $t[0] * Inhalt: $t[1]' 5 40");
if ($t[0] > 0) return; #erfassung ganz beenden
$coin_name=$t[1];
} while ($t[1] == "");
#Coin Daemon
do {
$res=dialog("--help-button --hfile 'temp.hlp' --help-label 'F1-Help' --hline 'Shift-Insert for copy/paste' --inputbox 'Coin Daemon ?' 0 0");
$t = explode("|", $res); #0=exitcode 1=inhalt
#dialog("--msgbox 'Exitcode: $t[0] * Inhalt: $t[1]' 5 40");
if ($t[0] > 0) return; #erfassung ganz beenden
$coin_daemon=$t[1];
} while ($t[1] == "");
#dialog("--msgbox 'Coin Daemon: $coin_daemon' 5 40");
#Coin Cli
do {
$res=dialog("--help-button --hfile 'temp.hlp' --help-label 'F1-Help' --hline 'Shift-Insert for copy/paste' --inputbox 'Coin Cli ?' 0 0");
$t = explode("|", $res); #0=exitcode 1=inhalt
#dialog("--msgbox 'Exitcode: $t[0] * Inhalt: $t[1]' 5 40");
if ($t[0] > 0) return; #erfassung ganz beenden
$coin_cli=$t[1];
} while ($t[1] == "");
#dialog("--msgbox 'Coin Cli: $coin_cli' 5 40");
#Coin Repo
do {
$res=dialog("--help-button --hfile 'temp.hlp' --help-label 'F1-Help' --hline 'Shift-Insert for copy/paste' --inputbox 'Coin Repo/Url ?' 6 60");
$t = explode("|", $res); #0=exitcode 1=inhalt
#dialog("--msgbox 'Exitcode: $t[0] * Inhalt: $t[1]' 5 40");
if ($t[0] == 1) return; #erfassung ganz beenden
if ($t[0] == 255) return; #erfassung ganz beenden
$coin_repo=$t[1];
} while ($t[1] == "");
#Coin port
do {
$res=dialog("--help-button --hfile 'temp.hlp' --help-label 'F1-Help' --hline 'Shift-Insert for copy/paste' --inputbox 'Coin Port ?' 0 0");
$t = explode("|", $res); #0=exitcode 1=inhalt
#dialog("--msgbox 'Exitcode: $t[0] * Inhalt: $t[1]' 5 40");
if ($t[0] > 0) return; #erfassung ganz beenden
$coin_port=$t[1];
} while ($t[1] == "");
#Home-Dir
#do {
# $res=dialog("--help-button --hfile 'temp.hlp' --help-label 'F1-Help' --hline 'Shift-Insert for copy/paste' --inputbox 'Muco Home Folder ?' 0 0 'muco'");
# $t = explode("|", $res); #0=exitcode 1=inhalt
# #dialog("--msgbox 'Exitcode: $t[0] * Inhalt: $t[1]' 5 40");
# if ($t[0] > 0) return; #erfassung ganz beenden
# $coin_home_dir=$t[1];
#} while ($t[1] == "");
$coin_home_dir="muco";