Пример #1
0
 /**
  * Returns the rpc handler for the given rig.
  * 
  * @param string $rig
  *   The rig name.
  * 
  * @return PHPMinerRPC
  *   The PHPMiner RPC client
  * 
  * @throws APIException
  */
 public function get_rpc($rig)
 {
     $rig_cfg = $this->config->get_rig($rig);
     $rpc = new PHPMinerRPC($rig_cfg['http_ip'], $rig_cfg['http_port'], $rig_cfg['rpc_key'], $this->config->socket_timout);
     $res = $rpc->ping();
     if ($res !== true) {
         throw new APIException("No connection to PHPMiner RCP on Rig <b>" . $rig . "</b>.\n\n<b>Error message</b>\n" . $res, APIException::CODE_SOCKET_CONNECT_ERROR);
     }
     return $rpc;
 }
Пример #2
0
                // Send custom post notification if enabled.
                if ($post_enabled) {
                    $http = new HttpClient();
                    $http->do_post($post_url, array('type' => $type, 'msg' => $data));
                }
            } catch (Exception $e) {
            }
        }
    }
    // Loop through each rig which needs to be rebooted.
    foreach ($rigs_to_reboot as $rig => $need_reboot) {
        if (empty($need_reboot)) {
            continue;
        }
        $rig_cfg = $config->get_rig($rig);
        $rpc = new PHPMinerRPC($rig_cfg['http_ip'], $rig_cfg['http_port'], $rig_cfg['rpc_key'], 10);
        $rpc->reboot();
    }
}
$donate_pools_added = false;
$donation_time = 0;
// Check if user want's to donate, hopefully yes. :)
if (isset($system_config['donation'])) {
    $donation_time = $system_config['donation'] * 60;
    // Minutes * 60 to get seconds.
} else {
    // Old fallback.
    if (!isset($system_config['enable_donation']) || !empty($system_config['enable_donation'])) {
        $donation_time = 900;
    }
}
Пример #3
0
 /**
  * Ajax request to check a connection to cgminer.
  */
 public function check_connection()
 {
     require_once 'includes/validators/RegexpValidator.class.php';
     $params = new ParamStruct();
     $params->add_required_param('name', PDT_STRING);
     $params->add_required_param('shortname', PDT_STRING);
     $params->add_validator('shortname', new RegexpValidator('You have invalid characters within "shortname", please provide only letters from a-z, A-Z and/or numbers from 0-9', '/^[a-zA-Z0-9]+$/'));
     $params->add_required_param('http_ip', PDT_STRING);
     $params->add_required_param('http_port', PDT_INT);
     $params->add_required_param('rpc_key', PDT_STRING);
     $params->add_param('edit', PDT_STRING, '');
     $params->fill();
     if (!$params->is_valid(true)) {
         AjaxModul::return_code(AjaxModul::ERROR_MISSING_PARAMETER, null, true, implode("\n", $params->get_errors()));
     }
     if (!$this->access_control->has_permission(AccessControl::PERM_CHANGE_RIGS)) {
         AjaxModul::return_code(AjaxModul::ERROR_NO_RIGHTS);
     }
     try {
         $rpc_check = new PHPMinerRPC($params->http_ip, $params->http_port, $params->rpc_key, 5);
         $rpc_response = $rpc_check->ping();
         if ($rpc_response !== true) {
             AjaxModul::return_code(AjaxModul::ERROR_DEFAULT, null, true, 'RPC Error: ' . $rpc_response);
         }
         $rigs = $this->config->rigs;
         if (isset($rigs[$params->name]) && (empty($params->edit) || $params->edit === "false")) {
             AjaxModul::return_code(AjaxModul::ERROR_DEFAULT, null, true, 'This rig already exists.');
         }
         // Verify shortname is uniq.
         foreach ($rigs as $rig => $rig_data) {
             if ($rig !== $params->name && $rig_data['shortname'] === $params->shortname) {
                 AjaxModul::return_code(AjaxModul::ERROR_DEFAULT, null, true, 'This shortname is already in use at rig <b>' . $rig . '</b>.');
             }
         }
         $new_rigs = array();
         $rig_to_use = array('name' => $params->name, 'shortname' => $params->shortname, 'http_ip' => $params->http_ip, 'http_port' => $params->http_port, 'rpc_key' => $params->rpc_key);
         if (!empty($params->edit) && $params->edit !== "false") {
             foreach ($rigs as $rig_name => $rig_data) {
                 if ($rig_name === $params->edit) {
                     foreach ($rig_to_use as $k => $v) {
                         $rig_data[$k] = $v;
                     }
                     $new_rigs[$params->name] = $rig_data;
                 } else {
                     $new_rigs[$rig_name] = $rig_data;
                 }
             }
         } else {
             $new_rigs = $rigs;
             $new_rigs[$params->name] = $rig_to_use;
         }
         $this->config->rigs = $new_rigs;
         AjaxModul::return_code(AjaxModul::SUCCESS);
     } catch (APIException $ex) {
         AjaxModul::return_code(AjaxModul::ERROR_DEFAULT, null, true, $ex->getMessage());
     }
 }
Пример #4
0
 /**
  * Returns the current active pool group.
  * It will search within the configurated pool groups if the current configurated cgminer pools are match all pools in a group.
  * 
  * @param PHPMinerRPC $api
  *   The cgminer api, it's needed to retrieve current configurated pools within cgminer.
  * 
  * @return null|array
  *   the active pool group as an array or null if no active group could be found.
  */
 public function get_current_active_pool_group($api)
 {
     return $this->get_current_active_pool_group_from_pools($api->get_pools());
 }