/** * 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()); } }
/** * 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; }
} } if (!empty($reciever_mail)) { $smtp['from'] = $config->get_value('notify_email_smtp_from', $notify_cfg_key); $smtp['from_name'] = $config->get_value('notify_email_smtp_from_name', $notify_cfg_key); $email_enabled = true; } } $rigs_to_reboot = array(); // Holds all notifications which will be send. $notifications = array(); if (!empty($rig_notifications)) { foreach ($rig_notifications as $rig => $notification_data) { $rig_cfg = $config->get_rig($rig); $rpc = new PHPMinerRPC($rig_cfg['http_ip'], $rig_cfg['http_port'], $rig_cfg['rpc_key'], 10); if (!$rpc->ping()) { continue; } // Rig disabled. if (!empty($rig_cfg['disabled'])) { continue; } $is_cgminer_running = $rpc->is_cgminer_running(); $has_defunc = $rpc->is_cgminer_defunc(); $notify_cgminer_restart = $notification_data['notify_cgminer_restart']; $notify_reboot = $notification_data['notify_reboot']; // If PHPMiner should check for defunc. if (!empty($notification_data['reboot_defunc'])) { // Check if there is a defunced cgminer process. $rigs_to_reboot[$rig] = $has_defunc; if (!empty($rigs_to_reboot[$rig]) && $notify_reboot) {