Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $gamingTasks = array();
- //Detect when these applications are running and stop mining
- $gamingTasks[] = 'Discord';
- $gamingTasks[] = 'SomeApp';
- $amServer = 'amserver';
- $amPort = '9999';
- $checkEvery = 15; //Check every x seconds
- $minerData = json_decode(fetch("http://$amServer:$amPort/api/miners"),true);
- $minerData = $minerData['groupList'];
- $minerToControl = array();
- //Miners to control
- $minerToControl[] = getminer('192.168.1.1'); //You can target an IP
- $minerToControl[] = getminer('Miner1'); //You can target the name of a miner in AM
- unset($minerData);
- while (true) {
- if (checkProcessors()) startMining();
- sleep($checkEvery);
- }
- function checkProcessors() {
- global $gamingTasks;
- exec('tasklist',$tasklist);
- foreach ($tasklist as $task) {
- $task = preg_replace('/.exe.*/','',$task);
- if (in_array($task,$gamingTasks)) {
- stopMining();
- return;
- }
- }
- return true;
- }
- function getMiner($nameOrIP) {
- global $amServer, $minerData;
- foreach ($minerData as $group) {
- foreach ($group['minerList'] as $miner) {
- if ($nameOrIP == $miner['name'] ||
- $nameOrIP == $miner['hostname'])
- return $miner['id'];
- }
- }
- }
- function stopMining() {
- global $minerToControl, $amServer, $amPort;
- foreach ($minerToControl as $id) {
- if (!json_decode(fetch("http://$amServer:$amPort/api/miners/$id"),true)['canStop']) continue;
- echo "Stopping miner id($id)\n";
- fetch("http://$amServer:$amPort/api/miners/$id?action=stop",true);
- }
- }
- function startMining() {
- global $minerToControl, $amServer, $amPort;
- foreach ($minerToControl as $id) {
- if (!json_decode(fetch("http://$amServer:$amPort/api/miners/$id"),true)['canStart']) continue;
- echo "Starting miner id($id)\n";
- fetch("http://$amServer:$amPort/api/miners/$id?action=start",true);
- }
- }
- function fetch($url, $post=false) {
- $ch = curl_init();
- curl_setopt($ch,CURLOPT_URL, $url);
- curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
- if ($post != false) {
- curl_setopt($ch, CURLOPT_POST, true);
- curl_setopt($ch, CURLOPT_POSTFIELDS, explode('?',$url)[1]);
- curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
- }
- return curl_exec($ch);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement