Пример #1
0
 /**
  * Ajax request to save new configuration settings.
  */
 public function save_settings()
 {
     AccessControl::check_permission(AccessControl::PERM_CHANGE_NOTIFICATION_SETTINGS);
     $params = new ParamStruct();
     $params->add_required_param('settings', PDT_ARR);
     $params->fill();
     if (!$params->is_valid()) {
         AjaxModul::return_code(AjaxModul::ERROR_INVALID_PARAMETER);
     }
     db::getInstance()->begin();
     foreach ($params->settings as $key => $val) {
         $this->config->set_value($key, $val, 'notify');
     }
     db::getInstance()->commit();
     AjaxModul::return_code(AjaxModul::SUCCESS);
 }
Пример #2
0
 /**
  * Add/Change a group.
  */
 public function group_add()
 {
     AccessControl::check_permission(AccessControl::PERM_MANAGE_USERS);
     $params = new ParamStruct();
     $params->add_param('old_name', PDT_STRING, '');
     $params->add_required_param('name', PDT_STRING);
     $params->add_param('permissions', PDT_ARR, array());
     $params->fill();
     if (!$params->is_valid()) {
         AjaxModul::return_code(AjaxModul::ERROR_INVALID_PARAMETER);
     }
     $old = $params->old_name;
     if ($params->name !== $old && AccessControl::getInstance()->get_config()->group_exists($params->name)) {
         AjaxModul::return_code(AjaxModul::ERROR_INVALID_PARAMETER, null, true, 'This group already exists.');
     }
     if (empty($old)) {
         $result = $this->access_control->get_config()->group_add($params->name);
     } else {
         $this->access_control->get_config()->group_revoke_all_permission($old);
         $result = $this->access_control->get_config()->group_change($old, $params->name);
     }
     foreach ($params->permissions as $permission) {
         $this->access_control->get_config()->group_grant_permission($params->name, $permission);
     }
     if ($result) {
         AjaxModul::return_code(AjaxModul::SUCCESS);
     }
     AjaxModul::return_code(AjaxModul::ERROR_DEFAULT, null, true, 'Could not add or update the user');
 }
Пример #3
0
 public function add_group()
 {
     $params = new ParamStruct();
     $params->add_required_param('group', PDT_STRING);
     $params->add_param('strategy', PDT_INT, 0);
     $params->add_param('rotate_period', PDT_INT, 0);
     $params->add_param('miner', PDT_STRING, '');
     $params->add_validator('group', new FunctionValidator('This group already exists.', function ($value) {
         $pool_config = new PoolConfig();
         return !$pool_config->group_exists($value);
     }));
     $params->fill();
     if (!$this->access_control->has_permission(AccessControl::PERM_CHANGE_POOL_GROUP)) {
         AjaxModul::return_code(AjaxModul::ERROR_NO_RIGHTS);
     }
     if (!$params->is_valid(true)) {
         AjaxModul::return_code(AjaxModul::ERROR_MISSING_PARAMETER, null, true, implode("\n", $params->get_errors()));
     }
     if ($params->group === 'donate') {
         AjaxModul::return_code(AjaxModul::ERROR_DEFAULT, null, true, 'donate group is a special one, you can not add it.');
     }
     $this->load_pool_config();
     $result = $this->pool_config->add_group($params->group, $params->strategy, $params->rotate_period, $params->miner);
     if ($result !== true) {
         AjaxModul::return_code(AjaxModul::ERROR_INVALID_PARAMETER, null, true, $result);
     }
     AjaxModul::return_code(AjaxModul::SUCCESS);
 }
Пример #4
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());
     }
 }
Пример #5
0
 public function set_engine_clock()
 {
     $params = new ParamStruct();
     $params->add_required_param('rig', PDT_STRING);
     $params->add_required_param('gpu', PDT_INT);
     $params->add_required_param('value', PDT_INT);
     $params->add_validator('value', new FunctionValidator('Speed out of range, can only between 0 and 9999', function ($value) {
         return $value >= 0 && $value <= 9999;
     }));
     $params->fill();
     if (!$params->is_valid()) {
         AjaxModul::return_code(AjaxModul::ERROR_MISSING_PARAMETER);
     }
     if (!$this->access_control->has_permission(AccessControl::PERM_DEVICE_OVERCLOCK)) {
         AjaxModul::return_code(AjaxModul::ERROR_NO_RIGHTS);
     }
     try {
         // Just get the api to first check if all connections are fine.
         $this->get_rpc($params->rig);
         $gpus = array();
         // Check for avg change
         if ($params->gpu === -1) {
             foreach ($this->get_rpc($params->rig)->get_devices() as $gpu) {
                 if (!isset($gpu['GPU'])) {
                     continue;
                 }
                 $gpus[] = $gpu['GPU'];
             }
         } else {
             $gpus[] = $params->gpu;
         }
         foreach ($gpus as $gpu_id) {
             $this->get_rpc($params->rig)->set_gpuengine($gpu_id, $params->value);
             $this->get_rpc($params->rig)->set_config('gpu-engine', $params->value, $gpu_id);
         }
         AjaxModul::return_code(AjaxModul::SUCCESS);
     } catch (APIRequestException $ex) {
         AjaxModul::return_code(AjaxModul::ERROR_DEFAULT, null, true, $ex->getMessage());
     } catch (APIException $ex) {
         AjaxModul::return_code(AjaxModul::ERROR_DEFAULT, null, true, $ex->getMessage());
     }
 }