protected function doAction()
 {
     $script = [];
     $this->getInputs($script, ['scriptid', 'name', 'type', 'execute_on', 'command', 'description', 'usrgrpid', 'groupid', 'host_access']);
     $script['confirmation'] = $this->getInput('confirmation', '');
     if ($this->getInput('type', ZBX_SCRIPT_TYPE_CUSTOM_SCRIPT) == ZBX_SCRIPT_TYPE_IPMI && $this->hasInput('commandipmi')) {
         $script['command'] = $this->getInput('commandipmi');
     }
     if ($this->getInput('hgstype', 1) == 0) {
         $script['groupid'] = 0;
     }
     DBstart();
     $result = API::Script()->update($script);
     if ($result) {
         $scriptId = reset($result['scriptids']);
         add_audit(AUDIT_ACTION_UPDATE, AUDIT_RESOURCE_SCRIPT, 'Name [' . $this->getInput('name', '') . '] id [' . $scriptId . ']');
     }
     $result = DBend($result);
     if ($result) {
         $response = new CControllerResponseRedirect('zabbix.php?action=script.list&uncheck=1');
         $response->setMessageOk(_('Script updated'));
     } else {
         $response = new CControllerResponseRedirect('zabbix.php?action=script.edit&scriptid=' . $this->getInput('scriptid'));
         $response->setFormData($this->getInputAll());
         $response->setMessageError(_('Cannot update script'));
     }
     $this->setResponse($response);
 }
Exemplo n.º 2
0
 private static function transactionEnd($result)
 {
     if (self::$transactionStarted) {
         self::$transactionStarted = false;
         DBend($result);
     }
 }
 protected function doAction()
 {
     $proxy = [];
     $this->getInputs($proxy, ['host', 'status', 'description', 'tls_connect', 'tls_accept', 'tls_issuer', 'tls_subject', 'tls_psk_identity', 'tls_psk']);
     if ($this->getInput('status', HOST_STATUS_PROXY_ACTIVE) == HOST_STATUS_PROXY_PASSIVE) {
         $proxy['interface'] = [];
         $this->getInputs($proxy['interface'], ['dns', 'ip', 'useip', 'port']);
     }
     DBstart();
     if ($this->hasInput('proxy_hostids')) {
         // skip discovered hosts
         $proxy['hosts'] = API::Host()->get(['output' => ['hostid'], 'hostids' => $this->getInput('proxy_hostids'), 'filter' => ['flags' => ZBX_FLAG_DISCOVERY_NORMAL]]);
     }
     $result = API::Proxy()->create([$proxy]);
     if ($result) {
         add_audit(AUDIT_ACTION_ADD, AUDIT_RESOURCE_PROXY, '[' . $this->getInput('host', '') . '] [' . reset($result['proxyids']) . ']');
     }
     $result = DBend($result);
     if ($result) {
         $response = new CControllerResponseRedirect('zabbix.php?action=proxy.list&uncheck=1');
         $response->setMessageOk(_('Proxy added'));
     } else {
         $response = new CControllerResponseRedirect('zabbix.php?action=proxy.edit');
         $response->setFormData($this->getInputAll());
         $response->setMessageError(_('Cannot add proxy'));
     }
     $this->setResponse($response);
 }
Exemplo n.º 4
0
 public static function flush()
 {
     // if not initialised, no changes were made
     if (is_null(self::$profiles)) {
         return true;
     }
     if (self::$userDetails['userid'] <= 0) {
         return null;
     }
     if (!empty(self::$insert) || !empty(self::$update)) {
         DBstart();
         foreach (self::$insert as $idx => $profile) {
             foreach ($profile as $idx2 => $data) {
                 self::insertDB($idx, $data['value'], $data['type'], $idx2);
             }
         }
         ksort(self::$update);
         foreach (self::$update as $idx => $profile) {
             ksort($profile);
             foreach ($profile as $idx2 => $data) {
                 self::updateDB($idx, $data['value'], $data['type'], $idx2);
             }
         }
         DBend();
     }
 }
Exemplo n.º 5
0
 protected static function endAPITransactions($result)
 {
     if (self::$transaction['counter'] > 0 && self::$transaction['owner'] != 'DB_CLASS') {
         unset(self::$transaction['owner']);
         self::$transaction['counter'] = 0;
         $result = DBend($result);
     }
 }
function update_node_profile($nodeids)
{
    DBstart();
    DBexecute('DELETE FROM profiles WHERE userid=' . CWebUser::$data['userid'] . ' AND idx=' . zbx_dbstr('web.nodes.selected'));
    foreach ($nodeids as $nodeid) {
        DBexecute('INSERT INTO profiles (profileid,userid,idx,value_id,type)' . ' VALUES (' . get_dbid('profiles', 'profileid') . ',' . CWebUser::$data['userid'] . ',' . zbx_dbstr('web.nodes.selected') . ',' . $nodeid . ',4)');
    }
    DBend();
}
Exemplo n.º 7
0
function update_node_profile($nodeids)
{
    global $USER_DETAILS;
    DBstart();
    $sql = 'DELETE FROM profiles WHERE userid=' . $USER_DETAILS['userid'] . ' AND idx=' . zbx_dbstr('web.nodes.selected');
    DBexecute($sql);
    foreach ($nodeids as $nodeid) {
        $profileid = get_dbid('profiles', 'profileid');
        $sql = 'INSERT INTO profiles (profileid, userid, idx, value_id, type)' . ' VALUES (' . $profileid . ',' . $USER_DETAILS['userid'] . ', ' . zbx_dbstr('web.nodes.selected') . ',' . $nodeid . ', 4)';
        DBexecute($sql);
    }
    DBend();
}
Exemplo n.º 8
0
 /**
  * Adds favorite value to DB.
  *
  * @param string $idx    identifier of favorite value group
  * @param int    $favid  value id
  * @param string $favobj source object
  *
  * @return bool did SQL INSERT succeeded
  */
 public static function add($idx, $favid, $favobj = null)
 {
     if (self::exists($idx, $favid, $favobj)) {
         return true;
     }
     // add to cache only if cache is created
     if (isset(self::$cache[$idx])) {
         self::$cache[$idx][] = array('value' => $favid, 'source' => $favobj);
     }
     DBstart();
     $values = array('profileid' => get_dbid('profiles', 'profileid'), 'userid' => CWebUser::$data['userid'], 'idx' => zbx_dbstr($idx), 'value_id' => zbx_dbstr($favid), 'type' => PROFILE_TYPE_ID);
     if (!is_null($favobj)) {
         $values['source'] = zbx_dbstr($favobj);
     }
     return DBend(DBexecute('INSERT INTO profiles (' . implode(', ', array_keys($values)) . ') VALUES (' . implode(', ', $values) . ')'));
 }
 protected function doAction()
 {
     $profile = ['graphid' => 'web.favorite.graphids', 'itemid' => 'web.favorite.graphids', 'screenid' => 'web.favorite.screenids', 'slideshowid' => 'web.favorite.screenids', 'sysmapid' => 'web.favorite.sysmapids'];
     $object = $this->getInput('object');
     $objectid = $this->getInput('objectid');
     $data = [];
     DBstart();
     $result = CFavorite::remove($profile[$object], $objectid, $object);
     $result = DBend($result);
     if ($result) {
         $data['main_block'] = '$("addrm_fav").title = "' . _('Add to favourites') . '";' . "\n" . '$("addrm_fav").onclick = function() { add2favorites("' . $object . '", "' . $objectid . '"); }' . "\n" . 'switchElementClass("addrm_fav", "btn-remove-fav", "btn-add-fav");';
     } else {
         $data['main_block'] = '';
     }
     $this->setResponse(new CControllerResponseData($data));
 }
Exemplo n.º 10
0
 public static function flush()
 {
     if (!empty(self::$insert) || !empty(self::$update)) {
         DBstart();
         foreach (self::$insert as $idx => $profile) {
             foreach ($profile as $idx2 => $data) {
                 $result = self::insertDB($idx, $data['value'], $data['type'], $idx2);
             }
         }
         ksort(self::$update);
         foreach (self::$update as $idx => $profile) {
             ksort($profile);
             foreach ($profile as $idx2 => $data) {
                 self::updateDB($idx, $data['value'], $data['type'], $idx2);
             }
         }
         DBend();
     }
 }
 protected function doAction()
 {
     $scriptids = $this->getInput('scriptids');
     DBstart();
     $result = API::Script()->delete($scriptids);
     if ($result) {
         foreach ($scriptids as $scriptid) {
             add_audit(AUDIT_ACTION_DELETE, AUDIT_RESOURCE_SCRIPT, _('Script') . ' [' . $scriptid . ']');
         }
     }
     $result = DBend($result);
     $deleted = count($scriptids);
     $response = new CControllerResponseRedirect('zabbix.php?action=script.list&uncheck=1');
     if ($result) {
         $response->setMessageOk(_n('Script deleted', 'Scripts deleted', $deleted));
     } else {
         $response->setMessageError(_n('Cannot delete script', 'Cannot delete scripts', $deleted));
     }
     $this->setResponse($response);
 }
Exemplo n.º 12
0
            if (!$newMacrosIds) {
                throw new Exception(_('Cannot add macro.'));
            }
            $newMacrosCreated = API::UserMacro()->get(array('globalmacroids' => $newMacrosIds['globalmacroids'], 'globalmacro' => 1, 'output' => API_OUTPUT_EXTEND));
            foreach ($newMacrosCreated as $macro) {
                add_audit_ext(AUDIT_ACTION_ADD, AUDIT_RESOURCE_MACRO, $macro['globalmacroid'], $macro['macro'] . SPACE . RARR . SPACE . $macro['value'], null, null, null);
            }
        }
        // reload macros after updating to properly display them in the form
        $_REQUEST['macros'] = API::UserMacro()->get(array('globalmacro' => true, 'output' => API_OUTPUT_EXTEND, 'preservekeys' => true));
        $result = true;
        DBend(true);
        show_message(_('Macros updated'));
    } catch (Exception $e) {
        $result = false;
        DBend(false);
        error($e->getMessage());
        show_error_message(_('Cannot update macros'));
    }
}
/*
 * Display
 */
$form = new CForm();
$form->cleanItems();
$cmbConf = new CComboBox('configDropDown', 'adm.macros.php', 'redirect(this.options[this.selectedIndex].value);');
$cmbConf->addItems(array('adm.gui.php' => _('GUI'), 'adm.housekeeper.php' => _('Housekeeping'), 'adm.images.php' => _('Images'), 'adm.iconmapping.php' => _('Icon mapping'), 'adm.regexps.php' => _('Regular expressions'), 'adm.macros.php' => _('Macros'), 'adm.valuemapping.php' => _('Value mapping'), 'adm.workingtime.php' => _('Working time'), 'adm.triggerseverities.php' => _('Trigger severities'), 'adm.triggerdisplayoptions.php' => _('Trigger displaying options'), 'adm.other.php' => _('Other')));
$form->addItem($cmbConf);
$cnf_wdgt = new CWidget();
$cnf_wdgt->addPageHeader(_('CONFIGURATION OF MACROS'), $form);
$data = array();
Exemplo n.º 13
0
 /**
  * Delete Users
  *
  * @static
  * @param array $userids
  * @return boolean
  */
 public static function delete($userids)
 {
     $result = false;
     DBstart(false);
     foreach ($userids as $userid) {
         $result = delete_user($userid);
         if (!$resukt) {
             break;
         }
     }
     DBend($result);
     if ($result) {
         return true;
     } else {
         self::$error = array('error' => ZBX_API_ERROR_INTERNAL, 'data' => 'Internal zabbix error');
         return false;
     }
 }
Exemplo n.º 14
0
        add_audit(AUDIT_ACTION_UPDATE, AUDIT_RESOURCE_ITEM, _('Item') . ' [' . $item['key_'] . '] [' . $id . '] ' . _('Host') . ' [' . $host['host'] . '] ' . _('History cleared'));
    }
    $go_result = DBend($go_result);
    show_messages($go_result, _('History cleared'), $go_result);
} elseif ($_REQUEST['go'] == 'delete' && isset($_REQUEST['group_itemid'])) {
    DBstart();
    $group_itemid = $_REQUEST['group_itemid'];
    $itemsToDelete = API::Item()->get(array('output' => array('key_', 'itemid'), 'selectHosts' => array('name'), 'itemids' => $group_itemid, 'preservekeys' => true));
    $go_result = API::Item()->delete($group_itemid);
    if ($go_result) {
        foreach ($itemsToDelete as $item) {
            $host = reset($item['hosts']);
            add_audit(AUDIT_ACTION_DELETE, AUDIT_RESOURCE_ITEM, _('Item') . ' [' . $item['key_'] . '] [' . $item['itemid'] . '] ' . _('Host') . ' [' . $host['name'] . ']');
        }
    }
    show_messages(DBend($go_result), _('Items deleted'), _('Cannot delete items'));
}
if ($_REQUEST['go'] != 'none' && !empty($go_result)) {
    $url = new CUrl();
    $path = $url->getPath();
    insert_js('cookie.eraseArray("' . $path . '")');
}
/*
 * Display
 */
if (isset($_REQUEST['form']) && str_in_array($_REQUEST['form'], array(_('Create item'), 'update', 'clone'))) {
    $data = getItemFormData();
    $data['page_header'] = _('CONFIGURATION OF ITEMS');
    // render view
    $itemView = new CView('configuration.item.edit', $data);
    $itemView->render();
Exemplo n.º 15
0
        show_messages($result, _('Item updated'), _('Cannot update item'));
    } else {
        $screenItem['x'] = get_request('x');
        $screenItem['y'] = get_request('y');
        $result = API::ScreenItem()->create($screenItem);
        show_messages($result, _('Item added'), _('Cannot add item'));
    }
    DBend($result);
    if ($result) {
        add_audit_details(AUDIT_ACTION_UPDATE, AUDIT_RESOURCE_SCREEN, $screen['screenid'], $screen['name'], 'Cell changed ' . (isset($_REQUEST['screenitemid']) ? 'screen itemid "' . $_REQUEST['screenitemid'] . '"' : '') . (isset($_REQUEST['x']) && isset($_REQUEST['y']) ? ' coordinates "' . $_REQUEST['x'] . ',' . $_REQUEST['y'] . '"' : '') . (isset($_REQUEST['resourcetype']) ? ' resource type "' . $_REQUEST['resourcetype'] . '"' : ''));
        unset($_REQUEST['form']);
    }
} elseif (isset($_REQUEST['delete'])) {
    DBstart();
    $screenitemid = API::ScreenItem()->delete($_REQUEST['screenitemid']);
    $result = DBend($screenitemid);
    show_messages($result, _('Item deleted'), _('Cannot delete item'));
    if ($result && !empty($screenitemid)) {
        $screenitemid = reset($screenitemid);
        $screenitemid = reset($screenitemid);
        add_audit_details(AUDIT_ACTION_DELETE, AUDIT_RESOURCE_SCREEN, $screen['screenid'], $screen['name'], 'Screen itemid "' . $screenitemid . '"');
    }
    unset($_REQUEST['x']);
} elseif (isset($_REQUEST['add_row'])) {
    DBexecute('UPDATE screens SET vsize=(vsize+1) WHERE screenid=' . zbx_dbstr($screen['screenid']));
    $add_row = get_request('add_row', 0);
    if ($screen['vsize'] > $add_row) {
        DBexecute('UPDATE screens_items SET y=(y+1) WHERE screenid=' . zbx_dbstr($screen['screenid']) . ' AND y>=' . zbx_dbstr($add_row));
    }
    add_audit_details(AUDIT_ACTION_UPDATE, AUDIT_RESOURCE_SCREEN, $screen['screenid'], $screen['name'], 'Row added');
} elseif (isset($_REQUEST['add_col'])) {
Exemplo n.º 16
0
    /**
     * Add items to graph
     *
     * <code>
     * $items = array(
     * 	*string 'graphid'		=> null,
     * 	array 'items' 			=> (
     *		'item1' => array(
     * 			*int 'itemid'			=> null,
     * 			int 'color'			=> '000000',
     * 			int 'drawtype'			=> 0,
     * 			int 'sortorder'			=> 0,
     * 			int 'yaxisside'			=> 1,
     * 			int 'calc_fnc'			=> 2,
     * 			int 'type'			=> 0,
     * 			int 'periods_cnt'		=> 5,
     *		), ... )
     * );
     * </code>
     *
     * @static
     * @param array $items multidimensional array with items data
     * @return boolean
     */
    public static function addItems($items)
    {
        $error = 'Unknown ZABBIX internal error';
        $result_ids = array();
        $result = false;
        $tpl_graph = false;
        $graphid = $items['graphid'];
        $items_tmp = $items['items'];
        $items = array();
        $itemids = array();
        foreach ($items_tmp as $item) {
            $graph_db_fields = array('itemid' => null, 'color' => '000000', 'drawtype' => 0, 'sortorder' => 0, 'yaxisside' => 1, 'calc_fnc' => 2, 'type' => 0, 'periods_cnt' => 5);
            if (!check_db_fields($graph_db_fields, $item)) {
                self::$error = array('error' => ZBX_API_ERROR_INTERNAL, 'data' => 'Wrong fields for item [ ' . $item['itemid'] . ' ]');
                return false;
            }
            $items[$item['itemid']] = $item;
            $itemids[$item['itemid']] = $item['itemid'];
        }
        // check if graph is templated graph, then items cannot be added
        $graph = CGraph::getById(array('graphid' => $graphid));
        if ($graph['templateid'] != 0) {
            self::$error = array('error' => ZBX_API_ERROR_INTERNAL, 'data' => 'Cannot edit templated graph : ' . $graph['name']);
            return false;
        }
        // check if graph belongs to template, if so, only items from same template can be added
        $tmp_hosts = get_hosts_by_graphid($graphid);
        $host = DBfetch($tmp_hosts);
        // if graph belongs to template, only one host is possible
        if ($host["status"] == HOST_STATUS_TEMPLATE) {
            $sql = 'SELECT DISTINCT count(i.hostid) as count
					FROM items i
					WHERE i.hostid<>' . $host['hostid'] . ' AND ' . DBcondition('i.itemid', $itemids);
            $host_count = DBfetch(DBselect($sql));
            if ($host_count['count']) {
                self::$error = array('error' => ZBX_API_ERROR_INTERNAL, 'data' => 'You must use items only from host : ' . $host['host'] . ' for template graph : ' . $graph['name']);
                return false;
            }
            $tpl_graph = true;
        }
        DBstart(false);
        $result = self::addItems_rec($graphid, $items, $tpl_graph);
        $result = DBend($result);
        if ($result) {
            return $result;
        } else {
            self::$error = array('error' => ZBX_API_ERROR_INTERNAL, 'data' => $error);
            //'Internal zabbix error');
            return false;
        }
    }
    }
    $result = DBend($result);
    if ($result) {
        unset($_REQUEST['itemid'], $_REQUEST['form']);
    }
} elseif (($_REQUEST['go'] == 'activate' || $_REQUEST['go'] == 'disable') && isset($_REQUEST['group_itemid'])) {
    $group_itemid = $_REQUEST['group_itemid'];
    DBstart();
    $go_result = $_REQUEST['go'] == 'activate' ? activate_item($group_itemid) : disable_item($group_itemid);
    $go_result = DBend($go_result);
    show_messages($go_result, $_REQUEST['go'] == 'activate' ? _('Items activated') : _('Items disabled'), null);
} elseif ($_REQUEST['go'] == 'delete' && isset($_REQUEST['group_itemid'])) {
    $group_itemid = $_REQUEST['group_itemid'];
    DBstart();
    $go_result = API::Itemprototype()->delete($group_itemid);
    $go_result = DBend($go_result);
    show_messages($go_result, _('Items deleted'), _('Cannot delete items'));
}
if ($_REQUEST['go'] != 'none' && isset($go_result) && $go_result) {
    $url = new CUrl();
    $path = $url->getPath();
    insert_js('cookie.eraseArray("' . $path . '")');
}
/*
 * Display
 */
if (isset($_REQUEST['form'])) {
    $data = getItemFormData();
    $data['page_header'] = _('CONFIGURATION OF ITEM PROTOTYPES');
    $data['is_item_prototype'] = true;
    // render view
Exemplo n.º 18
0
        $maintenanceids = $_REQUEST['maintenanceids'];
    }
    zbx_value2array($maintenanceids);
    DBstart();
    $maintenances = array();
    foreach ($maintenanceids as $id => $maintenanceid) {
        $maintenances[$maintenanceid] = get_maintenance_by_maintenanceid($maintenanceid);
    }
    $goResult = API::Maintenance()->delete($maintenanceids);
    if ($goResult) {
        foreach ($maintenances as $maintenanceid => $maintenance) {
            add_audit(AUDIT_ACTION_DELETE, AUDIT_RESOURCE_MAINTENANCE, 'Id [' . $maintenanceid . '] ' . _('Name') . ' [' . $maintenance['name'] . ']');
        }
        unset($_REQUEST['form'], $_REQUEST['maintenanceid']);
    }
    $goResult = DBend($goResult);
    show_messages($goResult, _('Maintenance deleted'), _('Cannot delete maintenance'));
    clearCookies($goResult);
} elseif (isset($_REQUEST['add_timeperiod']) && isset($_REQUEST['new_timeperiod'])) {
    $new_timeperiod = $_REQUEST['new_timeperiod'];
    if ($new_timeperiod['timeperiod_type'] == TIMEPERIOD_TYPE_ONETIME) {
        $new_timeperiod['start_date'] = mktime($_REQUEST['new_timeperiod_start_date_hour'], $_REQUEST['new_timeperiod_start_date_minute'], 0, $_REQUEST['new_timeperiod_start_date_month'], $_REQUEST['new_timeperiod_start_date_day'], $_REQUEST['new_timeperiod_start_date_year']);
    }
    // start time
    $new_timeperiod['start_time'] = $new_timeperiod['hour'] * SEC_PER_HOUR + $new_timeperiod['minute'] * SEC_PER_MIN;
    // period
    $new_timeperiod['period'] = $new_timeperiod['period_days'] * SEC_PER_DAY + $new_timeperiod['period_hours'] * SEC_PER_HOUR + $new_timeperiod['period_minutes'] * SEC_PER_MIN;
    // days of week
    if (!isset($new_timeperiod['dayofweek'])) {
        $dayofweek = !isset($new_timeperiod['dayofweek_su']) ? '0' : '1';
        $dayofweek .= !isset($new_timeperiod['dayofweek_sa']) ? '0' : '1';
Exemplo n.º 19
0
        uncheckTableRows($pageFilter->hostid);
    }
    show_messages($result, _n('Application deleted', 'Applications deleted', $deleted), _n('Cannot delete application', 'Cannot delete applications', $deleted));
} elseif (hasRequest('applications') && str_in_array(getRequest('action'), array('application.massenable', 'application.massdisable'))) {
    $enableApplicationItems = getRequest('action') === 'application.massenable';
    $applications = API::Application()->get(array('output' => array(), 'applicationids' => getRequest('applications', array()), 'selectItems' => array('itemid'), 'hostids' => $pageFilter->hostid > 0 ? $pageFilter->hostid : null));
    $actionSuccessful = true;
    $updatedItemCount = 0;
    DBstart();
    foreach ($applications as $application) {
        foreach ($application['items'] as $item) {
            $actionSuccessful &= $enableApplicationItems ? activate_item($item['itemid']) : disable_item($item['itemid']);
            $updatedItemCount++;
        }
    }
    $actionSuccessful = DBend($actionSuccessful);
    if ($actionSuccessful) {
        uncheckTableRows($pageFilter->hostid);
    }
    $messageSuccess = $enableApplicationItems ? _n('Item enabled', 'Items enabled', $updatedItemCount) : _n('Item disabled', 'Items disabled', $updatedItemCount);
    $messageFailed = $enableApplicationItems ? _n('Cannot enable item', 'Cannot enable items', $updatedItemCount) : _n('Cannot disable item', 'Cannot disable items', $updatedItemCount);
    show_messages($actionSuccessful, $messageSuccess, $messageFailed);
}
/*
 * Display
 */
if (isset($_REQUEST['form'])) {
    $data = array('applicationid' => getRequest('applicationid'), 'form' => getRequest('form'), 'form_refresh' => getRequest('form_refresh', 0));
    if (isset($data['applicationid']) && !isset($_REQUEST['form_refresh'])) {
        $dbApplication = reset($dbApplication);
        $data['appname'] = $dbApplication['name'];
Exemplo n.º 20
0
                                     } else {
                                         if ($_REQUEST['go'] == 'delete' && isset($_REQUEST['g_actionid'])) {
                                             if (!count($nodes = get_accessible_nodes_by_user($USER_DETAILS, PERM_READ_WRITE, PERM_RES_IDS_ARRAY))) {
                                                 access_deny();
                                             }
                                             DBstart();
                                             $actionids = array();
                                             $sql = 'SELECT DISTINCT a.actionid ' . ' FROM actions a ' . ' WHERE ' . DBin_node('a.actionid', $nodes) . ' AND ' . DBcondition('a.actionid', $_REQUEST['g_actionid']);
                                             $result = DBselect($sql);
                                             while ($row = DBfetch($result)) {
                                                 $del_res = delete_action($row['actionid']);
                                                 if ($del_res) {
                                                     $actionids[] = $row['actionid'];
                                                 }
                                             }
                                             $result = DBend();
                                             if ($result && isset($del_res)) {
                                                 show_messages(TRUE, S_ACTIONS_DELETED, S_CANNOT_DELETE_ACTIONS);
                                                 add_audit(AUDIT_ACTION_DELETE, AUDIT_RESOURCE_ACTION, ' Actions [' . implode(',', $actionids) . '] deleted');
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 21
0
 /**
  * Update item
  *
  * {@source}
  * @access public
  * @static
  * @since 1.8
  * @version 1
  *
  * @static
  * @param array $items multidimensional array with items data
  * @return boolean
  */
 public static function update($items)
 {
     $result = false;
     $itemids = array();
     DBstart(false);
     foreach ($items as $item) {
         $result = update_item($item['itemid'], $item);
         if (!$result) {
             break;
         }
         $itemids[$result] = $result;
     }
     $result = DBend($result);
     if ($result) {
         return $itemids;
     } else {
         self::$error = array('error' => ZBX_API_ERROR_INTERNAL, 'data' => 'Internal zabbix error');
         return false;
     }
 }
Exemplo n.º 22
0
function update_image($imageid, $name, $imagetype, $file)
{
    if (is_null($file)) {
        /* only update parameters */
        return DBexecute("update images set name=" . zbx_dbstr($name) . ",imagetype=" . zbx_dbstr($imagetype) . " where imageid={$imageid}");
    } else {
        global $DB;
        if ($file["error"] != 0 || $file["size"] == 0) {
            error("Incorrect Image");
            return FALSE;
        }
        if ($file["size"] < 1024 * 1024) {
            $image = fread(fopen($file["tmp_name"], "r"), filesize($file["tmp_name"]));
            if ($DB['TYPE'] == "ORACLE") {
                $result = DBexecute('UPDATE images SET name=' . zbx_dbstr($name) . ',imagetype=' . zbx_dbstr($imagetype) . ' WHERE imageid=' . $imageid);
                if (!$result) {
                    return $result;
                }
                DBstart();
                if (!($stid = DBselect('SELECT image FROM images WHERE imageid=' . $imageid . ' FOR UPDATE'))) {
                    DBend();
                    return false;
                }
                $row = DBfetch($stid);
                $lobimage = $row['image'];
                DBend($lobimage->save($image));
                $lobimage->free();
                return $stid;
            } else {
                if ($DB['TYPE'] == "POSTGRESQL") {
                    $image = pg_escape_bytea($image);
                    $sql = 'UPDATE images SET name=' . zbx_dbstr($name) . ',imagetype=' . zbx_dbstr($imagetype) . ",image='" . $image . "'" . ' WHERE imageid=' . $imageid;
                    return DBexecute($sql);
                } else {
                    if ($DB['TYPE'] == "SQLITE3") {
                        $image = bin2hex($image);
                    }
                }
            }
            $sql = 'UPDATE images SET name=' . zbx_dbstr($name) . ',imagetype=' . zbx_dbstr($imagetype) . ',image=' . zbx_dbstr($image) . ' WHERE imageid=' . $imageid;
            return DBexecute($sql);
        } else {
            error("Image size must be less than 1Mb");
            return FALSE;
        }
    }
}
Exemplo n.º 23
0
 /**
  * Import configuration data.
  *
  * @todo   for 1.8 version import old class CXmlImport18 is used
  *
  * @throws Exception
  * @throws UnexpectedValueException
  * @return bool
  */
 public function import()
 {
     if (empty($this->reader)) {
         throw new UnexpectedValueException('Reader is not set.');
     }
     try {
         // hack to make api throw exceptions
         // this made to not check all api calls results for false return
         czbxrpc::$useExceptions = true;
         DBstart();
         $this->data = $this->reader->read($this->source);
         $version = $this->getImportVersion();
         // if import version is 1.8 we use old class that support it.
         // old import class process hosts, maps and screens separately.
         if ($version == '1.8') {
             CXmlImport18::import($this->source);
             if ($this->options['maps']['updateExisting'] || $this->options['maps']['createMissing']) {
                 CXmlImport18::parseMap($this->options);
             }
             if ($this->options['screens']['updateExisting'] || $this->options['screens']['createMissing']) {
                 CXmlImport18::parseScreen($this->options);
             }
             if ($this->options['hosts']['updateExisting'] || $this->options['hosts']['createMissing'] || $this->options['templates']['updateExisting'] || $this->options['templates']['createMissing']) {
                 CXmlImport18::parseMain($this->options);
             }
         } else {
             $this->formatter = $this->getFormatter($version);
             // pass data to formatter
             // export has root key "zabbix_export" which is not passed
             $this->formatter->setData($this->data['zabbix_export']);
             $this->referencer = new CImportReferencer();
             // parse all import for references to resolve them all together with less sql count
             $this->gatherReferences();
             $this->processGroups();
             $this->processTemplates();
             $this->processHosts();
             $this->processApplications();
             $this->processItems();
             $this->processDiscoveryRules();
             $this->processTriggers();
             $this->processGraphs();
             $this->processImages();
             $this->processMaps();
             // screens should be created after all other elements
             $this->processTemplateScreens();
             $this->processScreens();
         }
         // prevent api from throwing exception
         czbxrpc::$useExceptions = false;
         return DBend(true);
     } catch (Exception $e) {
         czbxrpc::$useExceptions = false;
         DBend(false);
         throw new Exception($e->getMessage(), $e->getCode());
     }
 }
Exemplo n.º 24
0
$trigger = API::Trigger()->get(['triggerids' => $_REQUEST['triggerid'], 'output' => API_OUTPUT_EXTEND, 'expandDescription' => true]);
if (!$trigger) {
    access_deny();
}
$trigger = reset($trigger);
/*
 * Actions
 */
if (hasRequest('update')) {
    DBstart();
    $result = DBexecute('UPDATE triggers' . ' SET comments=' . zbx_dbstr(getRequest('comments')) . ' WHERE triggerid=' . zbx_dbstr(getRequest('triggerid')));
    $trigger['comments'] = $_REQUEST['comments'];
    if ($result) {
        add_audit(AUDIT_ACTION_UPDATE, AUDIT_RESOURCE_TRIGGER, _('Trigger') . ' [' . $_REQUEST['triggerid'] . '] [' . $trigger['description'] . '] ' . _('Comments') . ' [' . $_REQUEST['comments'] . ']');
    }
    $result = DBend($result);
    show_messages($result, _('Description updated'), _('Cannot update description'));
} elseif (isset($_REQUEST['cancel'])) {
    jsRedirect('tr_status.php');
    exit;
}
/*
 * Display
 */
$triggerEditable = API::Trigger()->get(['triggerids' => $_REQUEST['triggerid'], 'output' => ['triggerid'], 'editable' => true]);
$data = ['triggerid' => getRequest('triggerid'), 'trigger' => $trigger, 'isTriggerEditable' => !empty($triggerEditable), 'isCommentExist' => !empty($trigger['comments'])];
// render view
$triggerCommentView = new CView('monitoring.triggerComment', $data);
$triggerCommentView->render();
$triggerCommentView->show();
require_once dirname(__FILE__) . '/include/page_footer.php';
Exemplo n.º 25
0
            $messages['triggers.severities'] = array();
        }
        DBstart();
        updateMessageSettings($messages);
        $result = API::User()->updateProfile($user);
        if ($result && CwebUser::$data['type'] > USER_TYPE_ZABBIX_USER) {
            $result = API::User()->updateMedia(array('users' => $user, 'medias' => $user['user_medias']));
        }
        $result = DBend($result);
        if (!$result) {
            error(API::User()->resetErrors());
        }
        if ($result) {
            DBstart();
            add_audit(AUDIT_ACTION_UPDATE, AUDIT_RESOURCE_USER, 'User alias [' . CWebUser::$data['alias'] . '] Name [' . CWebUser::$data['name'] . ']' . ' Surname [' . CWebUser::$data['surname'] . '] profile id [' . CWebUser::$data['userid'] . ']');
            DBend(true);
            ob_end_clean();
            redirect(CWebUser::$data['last_page']['url']);
        } else {
            show_messages($result, _('User updated'), _('Cannot update user'));
        }
    }
}
ob_end_flush();
/*
 * Display
 */
$data = getUserFormData(CWebUser::$data['userid'], true);
$data['userid'] = CWebUser::$data['userid'];
$data['form'] = getRequest('form');
$data['form_refresh'] = getRequest('form_refresh', 0);
Exemplo n.º 26
0
                        }
                        /*				add_audit(AUDIT_ACTION_UPDATE,AUDIT_RESOURCE_HOST,'Old status ['.$old_status.'] '.'New status ['.$status.'] ['.$db_host['hostid'].']');*/
                    }
                }
                $go_result = DBend($go_result && !empty($hosts));
                show_messages($go_result, S_HOST_STATUS_UPDATED, NULL);
            } else {
                if ($_REQUEST['go'] == 'delete' && isset($_REQUEST['hosts'])) {
                    $hosts = get_request('hosts', array());
                    DBstart();
                    foreach ($hosts as $hostid) {
                        $proxy = get_host_by_hostid($hostid);
                        $go_result = delete_proxy($hostid);
                        add_audit(AUDIT_ACTION_DELETE, AUDIT_RESOURCE_PROXY, '[' . $proxy['host'] . ' ] [' . $proxy['hostid'] . ']');
                    }
                    $go_result = DBend();
                    show_messages($go_result, S_PROXY_DELETED, S_CANNOT_DELETE_PROXY);
                }
            }
        }
    }
}
if ($_REQUEST['go'] != 'none' && isset($go_result) && $go_result) {
    $url = new CUrl();
    $path = $url->getPath();
    insert_js('cookie.eraseArray("' . $path . '")');
}
$proxies_wdgt = new CWidget();
$frmForm = new CForm();
$cmbConf = new CComboBox('config', 'proxies.php', 'javascript: redirect(this.options[this.selectedIndex].value);');
$cmbConf->addItem('nodes.php', S_NODES);
Exemplo n.º 27
0
function update_profile($idx, $value, $type = PROFILE_TYPE_UNKNOWN, $idx2 = null, $source = null)
{
    global $USER_DETAILS;
    if ($USER_DETAILS['alias'] == ZBX_GUEST_USER) {
        return false;
    }
    if (profile_type($type, 'unknown')) {
        $type = profile_type_by_value($value);
    } else {
        $value = profile_value_by_type($value, $type);
    }
    //if($idx == 'web.audit.filter.action') SDI('PROF: v='.$value.'  t='.$type);
    if ($value === false) {
        return false;
    }
    $sql_cond = '';
    if (zbx_numeric($idx2)) {
        $sql_cond = ' AND idx2=' . $idx2 . ' AND ' . DBin_node('idx2');
    }
    if (profile_type($type, 'array')) {
        $sql = 'DELETE FROM profiles ' . ' WHERE userid=' . $USER_DETAILS["userid"] . ' AND idx=' . zbx_dbstr($idx) . $sql_cond;
        DBstart();
        DBexecute($sql);
        foreach ($value as $id => $val) {
            insert_profile($idx, $val, $type, $idx2, $source);
        }
        $result = DBend();
    } else {
        $sql = 'SELECT profileid ' . ' FROM profiles ' . ' WHERE userid=' . $USER_DETAILS['userid'] . ' AND idx=' . zbx_dbstr($idx) . $sql_cond;
        $row = DBfetch(DBselect($sql));
        if (!$row) {
            $result = insert_profile($idx, $value, $type, $idx2, $source);
        } else {
            $val = array();
            $value_type = profile_field_by_type($type);
            $val['value_id'] = 0;
            $val['value_int'] = 0;
            $val['value_str'] = '';
            $val[$value_type] = $value;
            $idx2 = zbx_numeric($idx2) ? $idx2 : 0;
            $src = is_null($source) ? '' : $source;
            if (is_array($value)) {
                $val[$value_type] = isset($value['value']) ? $value['value'] : '';
                $src = isset($value['source']) ? $value['source'] : $src;
            }
            if (is_null($val[$value_type])) {
                return false;
            }
            $sql = 'UPDATE profiles ' . ' SET value_id=' . $val['value_id'] . ',' . ' value_int=' . $val['value_int'] . ',' . ' value_str=' . zbx_dbstr($val['value_str']) . ',' . ' type=' . $type . ',' . ' source=' . zbx_dbstr($src) . ' WHERE userid=' . $USER_DETAILS["userid"] . ' AND idx=' . zbx_dbstr($idx) . $sql_cond;
            //if($idx == 'web.audit.filter.action') SDI($sql);
            $result = DBexecute($sql);
        }
    }
    return $result;
}
Exemplo n.º 28
0
 /**
  * Call the given API service method and return the response.
  *
  * @param string 	$requestApi			API name
  * @param string 	$requestMethod		API method
  * @param mixed 	$params				API parameters
  * @param string	$auth				Authentication token
  *
  * @return CApiClientResponse
  */
 public function callMethod($requestApi, $requestMethod, $params, $auth)
 {
     global $DB;
     $api = strtolower($requestApi);
     $method = strtolower($requestMethod);
     $response = new CApiClientResponse();
     // check API
     if (!$this->isValidApi($api)) {
         $response->errorCode = ZBX_API_ERROR_PARAMETERS;
         $response->errorMessage = _s('Incorrect API "%1$s".', $requestApi);
         return $response;
     }
     // check method
     if (!$this->isValidMethod($api, $method)) {
         $response->errorCode = ZBX_API_ERROR_PARAMETERS;
         $response->errorMessage = _s('Incorrect method "%1$s.%2$s".', $requestApi, $requestMethod);
         return $response;
     }
     // check params
     if (!is_array($params)) {
         $response->errorCode = ZBX_API_ERROR_PARAMETERS;
         $response->errorMessage = _s('Cannot call method "%1$s.%2$s" without parameters.', $requestApi, $requestMethod);
         return $response;
     }
     $requiresAuthentication = $this->requiresAuthentication($api, $method);
     // check that no authentication token is passed to methods that don't require it
     if (!$requiresAuthentication && $auth !== null) {
         $response->errorCode = ZBX_API_ERROR_PARAMETERS;
         $response->errorMessage = _s('The "%1$s.%2$s" method must be called without the "auth" parameter.', $requestApi, $requestMethod);
         return $response;
     }
     $newTransaction = false;
     try {
         // authenticate
         if ($requiresAuthentication) {
             $this->authenticate($auth);
         }
         // the nopermission parameter must not be available for external API calls.
         unset($params['nopermissions']);
         // if no transaction has been started yet - start one
         if ($DB['TRANSACTIONS'] == 0) {
             DBstart();
             $newTransaction = true;
         }
         // call API method
         $result = call_user_func_array([$this->serviceFactory->getObject($api), $method], [$params]);
         // if the method was called successfully - commit the transaction
         if ($newTransaction) {
             DBend(true);
         }
         $response->data = $result;
     } catch (Exception $e) {
         if ($newTransaction) {
             // if we're calling user.login and authentication failed - commit the transaction to save the
             // failed attempt data
             if ($api === 'user' && $method === 'login') {
                 DBend(true);
             } else {
                 DBend(false);
             }
         }
         $response->errorCode = $e instanceof APIException ? $e->getCode() : ZBX_API_ERROR_INTERNAL;
         $response->errorMessage = $e->getMessage();
         // add debug data
         if ($this->debug) {
             $response->debug = $e->getTrace();
         }
     }
     return $response;
 }
Exemplo n.º 29
0
        }
        $result = DBend($result);
        if ($page['type'] == PAGE_TYPE_JS && $result) {
            echo 'switchElementClass("addrm_fav", "iconminus", "iconplus");';
        }
    }
}
if (!empty($_REQUEST['period']) || !empty($_REQUEST['stime'])) {
    CScreenBase::calculateTime(array('profileIdx' => 'web.screens', 'profileIdx2' => $pageFilter->graphid, 'updateProfile' => true, 'period' => getRequest('period'), 'stime' => getRequest('stime')));
    $curl = new CUrl();
    $curl->removeArgument('period');
    $curl->removeArgument('stime');
    ob_end_clean();
    DBstart();
    CProfile::flush();
    DBend();
    redirect($curl->getUrl());
}
ob_end_flush();
if ($page['type'] == PAGE_TYPE_JS || $page['type'] == PAGE_TYPE_HTML_BLOCK) {
    require_once dirname(__FILE__) . '/include/page_footer.php';
    exit;
}
/*
 * Display
 */
$data = array('pageFilter' => $pageFilter, 'graphid' => $pageFilter->graphid, 'fullscreen' => $_REQUEST['fullscreen']);
// render view
$chartsView = new CView('monitoring.charts', $data);
$chartsView->render();
$chartsView->show();
 protected function doAction()
 {
     $mediatype = [];
     $this->getInputs($mediatype, ['type', 'description', 'status']);
     switch ($mediatype['type']) {
         case MEDIA_TYPE_EMAIL:
             $this->getInputs($mediatype, ['smtp_server', 'smtp_port', 'smtp_helo', 'smtp_email', 'smtp_security', 'smtp_verify_peer', 'smtp_verify_host', 'smtp_authentication', 'passwd']);
             if ($this->hasInput('smtp_username')) {
                 $mediatype['username'] = $this->getInput('smtp_username');
             }
             break;
         case MEDIA_TYPE_EXEC:
             $this->getInputs($mediatype, ['exec_path']);
             $mediatype['exec_params'] = '';
             if ($this->hasInput('exec_params')) {
                 $exec_params = zbx_objectValues($this->getInput('exec_params'), 'exec_param');
                 foreach ($exec_params as $exec_param) {
                     $mediatype['exec_params'] .= $exec_param . "\n";
                 }
             }
             break;
         case MEDIA_TYPE_SMS:
             $this->getInputs($mediatype, ['gsm_modem']);
             break;
         case MEDIA_TYPE_JABBER:
             $this->getInputs($mediatype, ['passwd']);
             if ($this->hasInput('jabber_username')) {
                 $mediatype['username'] = $this->getInput('jabber_username');
             }
             break;
         case MEDIA_TYPE_EZ_TEXTING:
             $this->getInputs($mediatype, ['passwd']);
             if ($this->hasInput('eztext_username')) {
                 $mediatype['username'] = $this->getInput('eztext_username');
             }
             if ($this->hasInput('eztext_limit')) {
                 $mediatype['exec_path'] = $this->getInput('eztext_limit');
             }
             break;
     }
     DBstart();
     $result = API::Mediatype()->create($mediatype);
     if ($result) {
         add_audit(AUDIT_ACTION_ADD, AUDIT_RESOURCE_MEDIA_TYPE, 'Media type [' . $mediatype['description'] . ']');
     }
     $result = DBend($result);
     if ($result) {
         $response = new CControllerResponseRedirect('zabbix.php?action=mediatype.list&uncheck=1');
         $response->setMessageOk(_('Media type added'));
     } else {
         $response = new CControllerResponseRedirect('zabbix.php?action=mediatype.edit');
         $response->setFormData($this->getInputAll());
         $response->setMessageError(_('Cannot add media type'));
     }
     $this->setResponse($response);
 }