-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcoinds.add-do.step2.php
More file actions
130 lines (107 loc) · 4.8 KB
/
coinds.add-do.step2.php
File metadata and controls
130 lines (107 loc) · 4.8 KB
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
<?php
require_once(".config.php");
require_once(".auth.php");
if(strlen($_POST['serverid'])<=0 || strlen($_POST['templateid'])<=0){
die("Please go back and select a Server AND a Template to use!");
}
$con=mysqli_connect($db['host'],$db['user'],$db['pass'],$db['name']);
if (mysqli_connect_errno()) {
$debug[] = "Failed to connect to MySQL";
$debug['mysql_error'] = mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT name,coind,gitsrc,cd_gitsrc,port_p2p,port_rpc FROM coind_templates WHERE id='".$_POST['templateid']."'");
$coindinfo = mysqli_fetch_row($result);
$coindinfo['name'] = $coindinfo[0];
$coindinfo['coind'] = $coindinfo[1];
$coindinfo['gitsrc'] = $coindinfo[2];
$coindinfo['cd_gitsrc'] = $coindinfo[3];
$coindinfo['port_p2p'] = $coindinfo[4];
$coindinfo['port_rpc'] = $coindinfo[5];
$result2 = mysqli_query($con,"SELECT ip FROM servers WHERE id='".$_POST['serverid']."'");
$serverinfo = mysqli_fetch_row($result2);
$serverinfo['ip'] = $serverinfo[0];
//log into server.,
$ssh = new Net_SSH2($serverinfo['ip']);
$key = new Crypt_RSA();
$key->loadKey(file_get_contents($sshkey_location));
if (!$ssh->login('root', $key)) {
$debug[] = "SSH Login Failed!";
} else {
//check if ports are in used
//yes? randomly choose ports and check those yes?...repeat
$port = $coindinfo['port_p2p'];
$valid_port = false;
while(!$valid_port){
$debug['port_check'] = $ssh->exec('netstat -ln | grep \':'.$port.' \' | grep \'LISTEN\'');
if(strlen($debug['port_check'])>0){
$port = rand(1025,65535);
} else {
$valid_port = true;
$port_p2p = $port;
}
}
$port = $coindinfo['port_rpc'];
$valid_port = false;
while(!$valid_port){
$debug['port_check'] = $ssh->exec('netstat -ln | grep \':'.$port.' \' | grep \'LISTEN\'');
if(strlen($debug['port_check'])>0){
$port = rand(1025,65535);
} else {
$valid_port = true;
$port_rpc = $port;
}
}
$debug['adduser'] = $ssh->exec('adduser '.$_POST['username'].' --disabled-password --gecos "First Last,RoomNumber,WorkPhone,HomePhone"');
$debug['step'][] = "user created...";
$coinfix = substr($coindinfo['coind'], 0, -1);
$debug['mkdir_coinname'] = $ssh->exec('mkdir /home/'.$_POST['username'].'/.'.$coinfix);
$debug['step'][] = "created coind config directory...";
//build the config
$coinconfig = "server=1\n";
$coinconfig .= "daemon=1\n";
$coinconfig .= "port=".$port_p2p."\n";
$coinconfig .= "rpcport=".$port_rpc."\n";
$coinconfig .= "rpcuser=".$_POST['rpc_user']."\n";
$coinconfig .= "rpcpassword=".$_POST['rpc_password']."\n";
$coinconfig .= "rpcthreads=".$_POST['rpc_threads']."\n";
$aips = explode(",",$_POST['allowedips']);
foreach($aips as $ip){
$coinconfig .= "rpcallowip=".$ip."\n";
}
//latter check if we have other coinds running, if so...add those as nodes
//now submit it
$debug['mkdir_coinname'] = $ssh->exec('printf "'.$coinconfig.'" >> /home/'.$_POST['username'].'/.'.$coinfix.'/'.$coinfix.'.conf');
$debug['step'][] = "created & saved config file...";
$debug['chown_coinddir'] = $ssh->exec('chown -R '.$_POST['username'].' /home/'.$_POST['username'].'/.'.$coinfix);
$debug['step'][] = "chown'ed directory & .conf file...";
}
echo "<strong>Compile (High Resources, Long Time)</strong> ";
echo '
<form action=coinds.add-do.step3.php method=post>
<input type=hidden name=templateid value="'.$_POST['templateid'].'" />
<input type=hidden name=serverid value="'.$_POST['serverid'].'" />
<input type=hidden name=username value="'.$_POST['username'].'" />
<input type=hidden name=rpc_user value="'.$_POST['rpc_user'].'" />
<input type=hidden name=rpc_password value="'.$_POST['rpc_password'].'" />
<input type=hidden name=rpc_threads value="'.$_POST['rpc_threads'].'" />
<input type=hidden name=allowedips value="'.$_POST['allowedips'].'" />
<input type=hidden name=port_rpc value="'.$port_rpc.'" />
<input type=hidden name=port_p2p value="'.$port_p2p.'" />
<input type=submit value="Do Compile" />
</form>';
//check if we have a pre-compiled daemond file
echo "<strong>Pre-Compiled ([RECOMMENDED]Low Resources, Short Time)</strong> ";
echo '
<form action=coinds.add-do.step3-1.php method=post>
<input type=hidden name=templateid value="'.$_POST['templateid'].'" />
<input type=hidden name=serverid value="'.$_POST['serverid'].'" />
<input type=hidden name=username value="'.$_POST['username'].'" />
<input type=hidden name=rpc_user value="'.$_POST['rpc_user'].'" />
<input type=hidden name=rpc_password value="'.$_POST['rpc_password'].'" />
<input type=hidden name=rpc_threads value="'.$_POST['rpc_threads'].'" />
<input type=hidden name=allowedips value="'.$_POST['allowedips'].'" />
<input type=hidden name=port_rpc value="'.$port_rpc.'" />
<input type=hidden name=port_p2p value="'.$port_p2p.'" />
<input type=submit value="Copy Daemon File" />
</form>';
mysqli_close($con);