Advertisement
Finnsk3

Awesome Miner Auto Stop

Jul 14th, 2018
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. <?php
  2. $gamingTasks = array();
  3. //Detect when these applications are running and stop mining
  4. $gamingTasks[] = 'Discord';
  5. $gamingTasks[] = 'SomeApp';
  6.  
  7. $amServer = 'amserver';
  8. $amPort = '9999';
  9. $checkEvery = 15; //Check every x seconds
  10.  
  11. $minerData = json_decode(fetch("http://$amServer:$amPort/api/miners"),true);
  12. $minerData = $minerData['groupList'];
  13. $minerToControl = array();
  14. //Miners to control
  15. $minerToControl[] = getminer('192.168.1.1'); //You can target an IP
  16. $minerToControl[] = getminer('Miner1'); //You can target the name of a miner in AM
  17.  
  18. unset($minerData);
  19.  
  20. while (true) {
  21. if (checkProcessors()) startMining();
  22. sleep($checkEvery);
  23. }
  24.  
  25. function checkProcessors() {
  26. global $gamingTasks;
  27. exec('tasklist',$tasklist);
  28. foreach ($tasklist as $task) {
  29. $task = preg_replace('/.exe.*/','',$task);
  30. if (in_array($task,$gamingTasks)) {
  31. stopMining();
  32. return;
  33. }
  34. }
  35. return true;
  36. }
  37.  
  38. function getMiner($nameOrIP) {
  39. global $amServer, $minerData;
  40. foreach ($minerData as $group) {
  41. foreach ($group['minerList'] as $miner) {
  42. if ($nameOrIP == $miner['name'] ||
  43. $nameOrIP == $miner['hostname'])
  44. return $miner['id'];
  45. }
  46. }
  47. }
  48.  
  49. function stopMining() {
  50. global $minerToControl, $amServer, $amPort;
  51. foreach ($minerToControl as $id) {
  52. if (!json_decode(fetch("http://$amServer:$amPort/api/miners/$id"),true)['canStop']) continue;
  53. echo "Stopping miner id($id)\n";
  54. fetch("http://$amServer:$amPort/api/miners/$id?action=stop",true);
  55. }
  56. }
  57.  
  58. function startMining() {
  59. global $minerToControl, $amServer, $amPort;
  60. foreach ($minerToControl as $id) {
  61. if (!json_decode(fetch("http://$amServer:$amPort/api/miners/$id"),true)['canStart']) continue;
  62. echo "Starting miner id($id)\n";
  63. fetch("http://$amServer:$amPort/api/miners/$id?action=start",true);
  64. }
  65. }
  66.  
  67. function fetch($url, $post=false) {
  68. $ch = curl_init();
  69.  
  70. curl_setopt($ch,CURLOPT_URL, $url);
  71. curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
  72. if ($post != false) {
  73. curl_setopt($ch, CURLOPT_POST, true);
  74. curl_setopt($ch, CURLOPT_POSTFIELDS, explode('?',$url)[1]);
  75. curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
  76. }
  77.  
  78. return curl_exec($ch);
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement