This repository was archived by the owner on Mar 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathmcontrol
More file actions
executable file
·156 lines (135 loc) · 4.84 KB
/
mcontrol
File metadata and controls
executable file
·156 lines (135 loc) · 4.84 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/usr/bin/perl
### BEGIN INIT INFO
# Provides: mine
# Required-Start: $local_fs $network
# Required-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: mine
# Description: mine script for Pimp
### END INIT INFO
# This file is part of IFMI PoolManager.
#
# PoolManager is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
use warnings;
use strict;
use File::Copy;
use YAML qw( DumpFile );
my $login = (getpwuid $>);
die "must run as root" if ($login ne 'root');
if (!defined $ARGV[0] || $ARGV[0] eq "") {
print "Usage: start, stop, restart, switch, installht, cleargraphs, delbins, boot (Restarts the machine)\n";
exit;
}
require '/opt/ifmi/pm-common.pl';
my $conf = &getConfig;
my %conf = %{$conf};
my $conffile = "/opt/ifmi/poolmanager.conf";
my $currentm = $conf{settings}{current_mconf};
my $minerpath = $conf{miners}{$currentm}{mpath};
$minerpath = 0 if (!defined $minerpath);
if ($ARGV[0] eq "switch") {
my $swopt = $ARGV[1];
&switchProfile($swopt);
}
if ($ARGV[0] eq "start") {
&startMining;
}
if ($ARGV[0] eq "stop") {
print "Stopping mining.....\n";
&stopCGMiner();
print "Mining stopped.\n";
&blog("stopping miner") if (defined(${$conf}{settings}{verbose}));
}
if ($ARGV[0] eq "restart") {
&stopCGMiner();
&blog("stopping miner") if (defined(${$conf}{settings}{verbose}));
sleep 10;
my $mcheck = `ps -eo command | grep -Ec ^$minerpath`;
if ($mcheck > 0) {
die "another mining process is running."
}
print "Starting mining...";
print "\nCurrent Profile: " . $conf{miners}{$currentm}{mconfig} . "\n";
&startCGMiner();
print "Mining started... Waiting 10 seconds and setting super priority.\n";
&blog("starting miner") if (defined(${$conf}{settings}{verbose}));
sleep 10;
&resetPoolSuperPri;
print "Super priority set.\n";
}
if ($ARGV[0] eq "boot") {
my $bootcmd;
if (-e "/sbin/coldreboot") {
$bootcmd = "/sbin/coldreboot"
} else {
$bootcmd = "/sbin/reboot"
}
`$bootcmd`;
&blog("booting miner with $bootcmd") if (defined(${$conf}{settings}{verbose}));
}
if ($ARGV[0] eq "cleargraphs") {
system('/bin/rm /opt/ifmi/rrdtool/*.rrd');
system('/bin/rm /var/www/IFMI/graphs/*.png');
`/opt/ifmi/pmgraph.pl`;
}
if ($ARGV[0] eq "delbins") {
`rm /opt/ifmi/*.bin`;
}
if ($ARGV[0] eq "installht") {
if (-e "/var/htpasswd") {
`/usr/bin/htpasswd -b /var/htpasswd poolmanager live`;
} else {
`/usr/bin/htpasswd -bc /var/htpasswd poolmanager live`;
}
`chown www-data /var/htpasswd`;
if (-d "/etc/lighttpd") {
copy "/etc/lighttpd/conf-available/05-auth.conf", "/etc/lighttpd/conf-available/05-auth.conf.pre-ifmi" if (!-f "/etc/lighttpd/conf-available/05-auth.conf.pre-ifmi");
if ((-f "/etc/lighttpd/conf-available/05-auth.conf.pre-ifmi") && (! `grep htpasswd /etc/lighttpd/conf-available/05-auth.conf`)) {
open my $lin, '>>', "/etc/lighttpd/conf-available/05-auth.conf";
print $lin "auth.backend = \"htpasswd\" \n";
print $lin "auth.backend.htpasswd.userfile = \"/var/htpasswd\"\n";
print $lin "auth.require = ( \"/\" => ( \"method\" => \"basic\", \"realm\" => \"Restricted access\", \"require\" => \"user=valid-user\" ) ) \n";
close $lin;
`lighty-enable-mod auth`;
`/usr/sbin/service lighttpd restart`;
}
} else {
if (! `grep AuthUserFile /etc/apache2/sites-available/default-ssl`) {
copy "/etc/apache2/sites-available/default-ssl", "/etc/apache2/sites-available/default-ssl.pre-ifmi"
if (!-f "/etc/apache2/sites-available/default-ssl.pre-ifmi");
open my $din, '<', "/etc/apache2/sites-available/default-ssl";
open my $dout, '>', "/etc/apache2/sites-available/default-ssl.out";
while (<$din>) {
print $dout $_;
last if /Directory \/>/;
}
print $dout "\n AuthType Basic\n AuthName \"Authentication Required\"\n";
print $dout " AuthUserFile /var/htpasswd\n";
print $dout "# Comment out the line below to disable password protection\n";
print $dout " Require valid-user\n\n";
while (<$din>) {
print $dout $_;
}
close $dout;
move "/etc/apache2/sites-available/default-ssl.out", "/etc/apache2/sites-available/default-ssl";
`/usr/sbin/service apache2 graceful`;
}
}
if (! `grep -E /usr/bin/htpasswd /etc/sudoers`) {
my $fin = "/etc/sudoers";
open my $sin, '<', $fin;
open my $sout, '>', "$fin.out";
while (<$sin>) {
s/\/opt\/ifmi\/mcontrol/\/opt\/ifmi\/mcontrol,\/usr\/bin\/htpasswd/;
print $sout $_;
}
close $sin; close $sout;
rename $fin, "$fin.back";
rename "$fin.out", $fin;
`chmod 0440 /etc/sudoers`;
}
}