public function __construct() { parent::__construct(); $this->load->library("CiSmarty"); $this->load->library('CiPage'); //定义后台模版路径 //$this->cismarty->assign("THEMEPATH", "/application/themes/admin/default"); }
public function __construct() { parent::__construct(); $this->load->library("CiSmarty"); $this->load->library('CiPage'); //定义后台模版路径 $this->cismarty->assign("THEMEPATH", "/application/" . THEME_ADMIN); //取得当前按钮 $this->load->helper("admin_menu"); $this->cismarty->assign("admin_menu", admin_menu()); $this->load->helper("common"); }
public function Parse($filename) { $root = new CNode(CNode::K_ROOT, $filename, CNode::T_ROOT); $filename = $root->Get(CNode::FLD_VAL); $xmlstring = file_get_contents($filename); if ($xmlstring === FALSE) { $root->SetErr("failed to read file {$filename}", CNode::E_FATAL); return $root; } $parser = xml_parser_create(); xml_set_object($parser, $this); xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, false); xml_set_element_handler($parser, 'startElement', 'endElement'); xml_set_character_data_handler($parser, 'characterData'); // Build a Root node and initialize the node_stack... $this->node_stack = array(); $this->cur_node = $root; // parse the data and free the parser... $result = xml_parse($parser, $xmlstring); if (!$result) { $err = 'XML error: ' . xml_error_string(xml_get_error_code($parser)) . ' at line ' . xml_get_current_line_number($parser); $root->SetErr("failed to parse file {$filename}, {$err}", CNode::E_FATAL); } xml_parser_free($parser); return $root; }
/** * Edit a connection * after the update need to update the nodes so they're in the same groups as the connection * @param string $fromnodeid * @param string $fromroleid * @param string $linktypeid * @param string $tonodeid * @param string $toroleid * @param string $private * @param string $description * @return Connection object (this) (or Error object) */ function edit($fromnodeid, $fromroleid, $linktypeid, $tonodeid, $toroleid, $private, $description = "") { global $DB, $CFG, $USER, $HUB_SQL; $dt = time(); //check user can edit connection try { $this->canedit(); } catch (Exception $e) { return access_denied_error(); } $currentuser = ''; if (isset($USER->userid)) { $currentuser = $USER->userid; } try { $fromnode = new CNode($fromnodeid); $fromnode = $fromnode->load(); //$fromnode->canedit(); } catch (Exception $e) { //return access_denied_error(); } try { $tonode = new CNode($tonodeid); $tonode = $tonode->load(); //$tonode->canedit(); } catch (Exception $e) { //return access_denied_error(); } $params = array(); $params[0] = $dt; $params[1] = $fromnode->name; $params[2] = $tonode->name; $params[3] = $linktypeid; $params[4] = $fromnodeid; $params[5] = $tonodeid; $params[6] = $fromroleid; $params[7] = $toroleid; $params[8] = $private; $params[9] = $description; $params[10] = $this->connid; $params[11] = $currentuser; $res = $DB->insert($HUB_SQL->DATAMODEL_CONNECTION_UPDATE_ALL, $params); if (!$res) { return database_error(); } // now also add groups to the from and to nodes $params = array(); $params[0] = $this->connid; $resArray = $DB->select($HUB_SQL->DATAMODEL_CONNECTION_SELECT_GROUP, $params); if (!$resArray) { return database_error(); } else { $count = count($resArray); for ($i = 0; $i < $count; $i++) { $array = $resArray[$i]; $groupid = $array['GroupID']; $fromnode = new CNode($fromnodeid); $fromnode->addGroup($groupid); $tonode = new CNode($tonodeid); $tonode->addGroup($groupid); } } $temp = $this->load(); if (!auditConnection($USER->userid, $temp->connid, "", $fromnodeid, $tonodeid, $linktypeid, $fromroleid, $toroleid, $CFG->actionEdit, format_object('xml', $temp))) { return database_error(); } return $temp; }
/** * Add a node to a view. Requires login * * @param string $viewid * @param string $nodeid * @param string $xpos. * @param string $ypos. * @param string $groupid (optional) the id of the group to add the node to. * * @return ViewNode or Error */ function addNodeToView($viewid, $nodeid, $xpos, $ypos, $groupid = "") { global $USER; $v = new View($viewid); $viewnode = $v->addNode($nodeid, $xpos, $ypos); if (!$viewnode instanceof Error) { if (isset($groupid) && $groupid != "") { $group = new Group($groupid); if (!$group instanceof Error) { if ($group->ismember($USER->userid)) { $node = new CNode($nodeid); $node->addGroup($groupid); } } } else { // if not given get groups for map node and add it to those. Should only be one at present. $mapnode = new CNode($viewid); $mapnode = $mapnode->load(); if (isset($mapnode->groups)) { $groups = $mapnode->groups; $count = count($groups); for ($i = 0; $i < $count; $i++) { $nextgroup = $groups[$i]; if (isset($nextgroup)) { if ($nextgroup->ismember($USER->userid)) { $node = new CNode($nodeid); $node->addGroup($nextgroup->groupid); } } } } } } return $viewnode; }
/** * Check whether the current user can delete the map * * @throws Exception */ function candelete() { global $USER, $USER; // need to be allowed to delete the associated view node. try { $node = new CNode($this->nodeid); $node->candelete(); } catch (Exception $e) { return access_denied_error(); } }
private function init_special() { $lines = file($this->_path); if ($lines === FALSE) { return FALSE; } $this->_root = new CNode(CNode::K_ROOT, $this->_id, CNode::T_ROOT); $items = array(); if ($this->_id == 'MIME') { foreach ($lines as $line) { if (($c = strpos($line, '=')) > 0) { $suffix = trim(substr($line, 0, $c)); $type = trim(substr($line, $c + 1)); $m = new CNode('index', $suffix); $m->AddChild(new CNode('suffix', $suffix)); $m->AddChild(new CNode('type', $type)); $items[$suffix] = $m; } } } elseif ($this->_id == 'ADMUSR' || $this->_id == 'V_UDB') { foreach ($lines as $line) { $parsed = explode(':', trim($line)); $size = count($parsed); if ($size == 2 || $size == 3) { $name = trim($parsed[0]); $pass = trim($parsed[1]); if ($name != '' && $pass != '') { $u = new CNode('index', $name); $u->AddChild(new CNode('name', $name)); $u->AddChild(new CNode('passwd', $pass)); if ($size == 3 && ($group = trim($parsed[2])) != '') { $u->AddChild(new CNode('group', $group)); } $items[$name] = $u; } } } } elseif ($this->_id == 'V_GDB') { foreach ($lines as $line) { $parsed = explode(':', trim($line)); if (count($parsed) == 2) { $group = trim($parsed[0]); $users = trim($parsed[1]); if ($group != '') { $g = new CNode('index', $group); $g->AddChild(new CNode('name', $group)); $g->AddChild(new CNode('users', $users)); $items[$group] = $g; } } } } ksort($items, SORT_STRING); reset($items); foreach ($items as $item) { $this->_root->AddChild($item); } return TRUE; }
/** * Add a node. Requires login * * @param string $name * @param string $desc * @param string $nodetypename, the name of the nodetype this node is. * @param string $focalnodeid, the id of the node to connect this new node to. * @param string $direction optional, whether the new node is a 'from' or 'to' in the connection. The focalnode then becomes the other end. Defaults to 'from'; * @param string $private optional, can be Y or N, defaults to users preferred setting * @param string $groupid optional, the id of any group to add the new node and the new connection to. * @param string $imageurlid optional, the urlid of the url for the image that is being used as this node's icon * @param string $imagethumbnail optional, the local server path to the thumbnail of the image used for this node * @param string $resources optional, an array of urls to add to this new node * * @return Node or Error */ function addNodeAndConnect($name, $desc, $nodetypename, $focalnodeid, $linktypename, $direction = "from", $groupid = "", $private = "N", $imageurlid = "", $imagethumbnail = "", $resources = "") { global $USER, $CFG; if ($private == "") { $private = $USER->privatedata; } $conndesc = ""; // if groupid given, check current user in group before going any further. if ($groupid != "") { $group = new Group($groupid); if (!$group instanceof Error) { if (!$group->ismember($USER->userid)) { $error = new Error(); return $error->createNotInGroup($group->name); } } else { return $group; } } $r = getRoleByName($nodetypename); if (!$r instanceof Error) { $nodetypeid = $r->roleid; $n = new CNode(); $node = $n->add($name, $desc, $private, $nodetypeid, $imageurlid, $imagethumbnail); if (!$node instanceof Error) { // Add to group if (isset($groupid) && $groupid != "") { addGroupToNode($node->nodeid, $groupid); } if ($resources != "") { foreach ($resources as $url) { $url = trim($url); if ($url != "") { $title = $url; $urlobj = new URL(); $urlobj->add($url, $title, "", $private, "", ""); if (!$urlobj instanceof Error) { $node->addURL($urlobj->urlid, ""); } else { return $urlobj; } } } } // Connect to focal node $focalnode = new CNode($focalnodeid); $focalnode = $focalnode->load(); if (!$focalnode instanceof Error) { $focalrole = getRoleByName($focalnode->role->name); $focalroleid = $focalrole->roleid; $lt = getLinkTypeByLabel($linktypename); $linkType = $lt->linktypeid; if ($direction == 'from') { $connection = addConnection($node->nodeid, $nodetypeid, $linkType, $focalnodeid, $focalroleid, $private, $conndesc); } else { $connection = addConnection($focalnodeid, $focalroleid, $linkType, $node->nodeid, $nodetypeid, $private, $conndesc); } if (!$connection instanceof Error) { // add to group if (isset($groupid) && $groupid != "") { addGroupToConnection($connection->connid, $groupid); } } return $connection; } else { return $focalnode; } } else { return $node; } } else { return $r; } }
/** * load in the nodes for the given SQL statement * * @param string $sql * @param array $params the parameters that go into the sql statement * @param int $start starting from record item * @param int $max for a record limit of this given count * @param string $orderby the name of the field to sort by * @param string $sort 'ASC' or 'DESC' (ascending or descending ordering) * @param string the style of each record in the collection (defaults to 'short' , can be 'long'); * @return NodeSet (this) */ function load($sql, $params, $start, $max, $orderby, $sort, $style = 'short') { global $DB, $HUB_SQL; if (!isset($params)) { $params = array(); } // GET TOTAL RECORD COUTN BEFORE LIMITING $csql = $HUB_SQL->DATAMODEL_NODE_LOAD_PART1; $csql .= $sql; $csql .= $HUB_SQL->DATAMODEL_NODE_LOAD_PART2; $carray = $DB->select($csql, $params); $totalconns = $carray[0]["totalnodes"]; // ADD SORTING $sql = $DB->nodeOrderString($sql, $orderby, $sort); // ADD LIMITING $sql = $DB->addLimitingResults($sql, $start, $max); //error_log("Search1=".$sql); $resArray = $DB->select($sql, $params); //create new nodeset and loop to add each node to the set $count = count($resArray); $this->totalno = $totalconns; $this->start = $start; $this->count = $count; for ($i = 0; $i < $count; $i++) { $array = $resArray[$i]; $node = new CNode($array["NodeID"]); $this->add($node->load($style)); } return $this; }
protected function instantiateTemplate() { $tpname = $this->_disp->Get(DInfo::FLD_ViewName); $vhname = $this->_disp->GetLast(DInfo::FLD_REF); $s_tpnode = $this->_serv->GetChildNodeById('vhTemplate', $tpname); if ($s_tpnode == NULL) { return false; } $s_vhnode = $s_tpnode->GetChildNodeById('member', $vhname); if ($s_vhnode == NULL) { return false; } $confpath = $this->getConfFilePath(DInfo::CT_TP, $tpname); $tp = new CData(DInfo::CT_TP, $confpath); if (($conferr = $tp->GetConfErr()) != NULL) { $this->_disp->Set(DInfo::FLD_TopMsg, $conferr); return false; } $tproot = $tp->GetRootNode(); $configfile = $tproot->GetChildVal('configFile'); if ($configfile == NULL) { return false; } $vhRoot_path = ''; if (strncasecmp('$VH_ROOT', $configfile, 8) == 0) { $vhRoot_path = $s_vhnode->GetChildVal('vhRoot'); // customized if ($vhRoot_path == NULL) { //default $vhRoot_path = $tproot->GetChildVal('vhRoot'); if ($vhRoot_path == NULL) { return false; } } } $configfile = PathTool::GetAbsFile($configfile, 'VR', $vhname, $vhRoot_path); $vh = new CData(DInfo::CT_VH, $configfile, "`{$vhname}"); if (($conferr = $vh->GetConfErr()) != NULL) { $this->_disp->Set(DInfo::FLD_TopMsg, $conferr); return false; } $vhroot = $tproot->GetChildren('virtualHostConfig'); if ($vhroot == false) { return false; } $vh->SetRootNode($vhroot); $vh->SaveFile(); // save serv file $basemap = new DTblMap(array('', '*virtualhost$name'), 'V_TOPD'); $tproot->AddChild(new CNode('name', $vhname)); $tproot->AddChild(new CNode('note', "Instantiated from template {$tpname}")); $basemap->Convert(0, $tproot, 1, $this->_serv->GetRootNode()); $s_vhnode->RemoveFromParent(); $domains = $s_vhnode->GetChildVal('vhDomain'); if ($domains == NULL) { $domains = $vhname; } // default if (($domainalias = $s_vhnode->GetChildVal('vhAliases')) != NULL) { $domains .= ", {$domainalias}"; } $listeners = $s_tpnode->GetChildVal('listeners'); $lns = preg_split("/, /", $listeners, -1, PREG_SPLIT_NO_EMPTY); foreach ($lns as $ln) { $listener = $this->_serv->GetChildNodeById('listener', $ln); if ($listener != NULL) { $vhmap = new CNode('vhmap', $vhname); $vhmap->AddChild(new CNode('domain', $domains)); $listener->AddChild($vhmap); } else { error_log("cannot find listener {$ln} \n"); } } $this->_serv->SaveFile(); return true; }
/** * Check whether the current user can add a node * * @throws Exception */ function canadd($viewid, $nodeid) { global $DB, $USER, $HUB_SQL, $LNG; // needs to be logged in api_check_login(); //You need to be able to view the node you are adding to the map //and you need permission to edit the map try { $node = new CNode($nodeid); $node->canview(); $view = new View($viewid); $view->canedit(); } catch (Exception $e) { return access_denied_error(); } }
die; } $errors = array(); if (isset($_POST["deletenode"])) { $nodeid = optional_param("nodeid", "", PARAM_ALPHANUMEXT); if ($nodeid != "") { $node = new CNode($nodeid); $node->delete(); } else { array_push($errors, $LNG->SPAM_ADMIN_ID_ERROR); } } else { if (isset($_POST["restorenode"])) { $nodeid = optional_param("nodeid", "", PARAM_ALPHANUMEXT); if ($nodeid != "") { $node = new CNode($nodeid); $node->updateStatus($CFG->STATUS_ACTIVE); } else { array_push($errors, $LNG->SPAM_ADMIN_ID_ERROR); } } } $ns = getNodesByStatus($CFG->STATUS_SPAM, 0, -1, 'name', 'ASC', 'long'); $nodes = $ns->nodes; $count = count($nodes); for ($i = 0; $i < $count; $i++) { $node = $nodes[$i]; $reporterid = getSpamReporter($node->nodeid); if ($reporterid != false) { $reporter = new User($reporterid); $reporter = $reporter->load();
private function parse_raw($rawfiles, $root) { $fid = $rawfiles->AddRawFile($root); $filename = $root->Get(CNode::FLD_VAL); $rawlines = file($filename); if ($rawlines == NULL) { $errlevel = $root->Get(CNode::FLD_KEY) == CNode::K_ROOT ? CNode::E_FATAL : CNode::E_WARN; $errmsg = "Failed to read file {$filename}"; $rawfiles->MarkError($root, $errlevel, $errmsg); return; } $root->SetRawMap($fid, 1, count($rawlines), ''); $stack = array(); $cur_node = $root; $prev_node = NULL; $cur_val = ''; $cur_comment = ''; $from_line = 0; $to_line = 0; $sticky = FALSE; $multiline_tag = ''; foreach ($rawlines as $line_num => $data) { $line_num++; if ($sticky || $multiline_tag != '') { $d = rtrim($data, "\r\n"); } else { $d = trim($data); } if ($d == '') { $cur_comment .= "\n"; continue; // ignore empty lines } if ($d[0] == '#') { $cur_comment .= $d . "\n"; continue; // comments } if (!$sticky && $multiline_tag == '') { $from_line = $line_num; } $end_char = $d[strlen($d) - 1]; $cur_val .= $d; if ($end_char == '\\') { $sticky = TRUE; $cur_val .= "\n"; //make the line end with \n\ continue; } else { $sticky = FALSE; } if ($multiline_tag != '') { if (trim($d) == $multiline_tag) { // stop $multiline_tag = ''; } else { $cur_val .= "\n"; continue; } } elseif (($pos = strpos($d, '<<<')) > 0) { $multiline_tag = trim(substr($d, $pos + 3)); $cur_val .= "\n"; continue; } $to_line = $line_num; if ($d[0] == '}') { // end of block if ($cur_comment != '') { $cur_node->AddEndComment($cur_comment); } if (strlen($cur_val) > 1) { $rawfiles->MarkError($cur_node, CNode::E_WARN, 'No other characters allowed at the end of closing }'); } if (count($stack) > 0) { $prev_node = $cur_node; $prev_node->Set(CNode::FLD_FLTO, $line_num); $cur_node = array_pop($stack); } else { $rawfiles->MarkError($prev_node == NULL ? $cur_node : $prev_node, CNode::E_FATAL, 'Mismatched blocks, may due to extra closing }'); } } else { $is_block = FALSE; if ($end_char == '{') { $cur_val = rtrim(substr($cur_val, 0, strlen($cur_val) - 1)); $is_block = TRUE; } if (preg_match('/^([\\S]+)\\s/', $cur_val, $m)) { $key = $m[1]; $val = trim(substr($cur_val, strlen($m[0]))); if (substr($val, 0, 3) == '<<<') { $posv0 = strpos($val, "\n"); $posv1 = strrpos($val, "\n"); $val = trim(substr($val, $posv0 + 1, $posv1 - $posv0)); } } else { $key = $cur_val; $val = NULL; } $type = CNode::T_KV; if ($is_block) { $type = $val == NULL ? CNode::T_KB : CNode::T_KVB; } elseif (strcasecmp($key, 'include') == 0) { $type = CNode::T_INC; } $newnode = new CNode($key, $val, $type); $newnode->SetRawMap($fid, $from_line, $to_line, $cur_comment); // validate key if (!preg_match('/^([a-zA-Z_0-9:])+$/', $key)) { $rawfiles->MarkError($newnode, CNode::E_WARN, "Invalid char in keyword {$key}"); } $cur_node->AddChild($newnode); if ($newnode->HasFlag(CNode::BM_BLK)) { $stack[] = $cur_node; $prev_node = $cur_node; $cur_node = $newnode; } elseif ($newnode->HasFlag(CNode::BM_INC)) { $this->parse_raw($rawfiles, $newnode); } } $cur_val = ''; $cur_comment = ''; } if ($cur_comment != '') { $cur_node->AddEndComment($cur_comment); $cur_comment = ''; } while (count($stack) > 0) { $rawfiles->MarkError($cur_node, CNode::E_FATAL, 'Mismatched blocks at end of the file, may due to extra openning { or missing closing }.'); $prev_node = $cur_node; $cur_node = array_pop($stack); } }
$maptitle = $node->name; $desc = $node->description; $private = $node->private; $background = $node->getNodeProperty('background'); } else { echo "<script type='text/javascript'>"; echo "alert('" . $LNG->FORM_MAP_NOT_FOUND . "');"; echo "window.close();"; echo "</script>"; die; } } include_once $HUB_FLM->getCodeDirPath("ui/popuplib.php"); /**********************************************************************************/ if (!empty($errors)) { $node = new CNode($nodeid); $background = $node->getNodeProperty('background'); echo "<div class='errors'>" . $LNG->FORM_ERROR_MESSAGE . ":<ul>"; foreach ($errors as $error) { echo "<li>" . $error . "</li>"; } echo "</ul></div>"; } ?> <script type="text/javascript"> function init() { $('dialogheader').insert('<?php echo $LNG->FORM_MAP_TITLE_EDIT; ?>
/** * Check whether the current user can view the current ViewConnection record * * @throws Exception */ function canview() { global $DB, $CFG, $USER, $HUB_SQL, $LNG; //check if you can view the map node and you can view this node in the map try { $view = new CNode($this->viewid); $view->canview(); $con = new Connection($this->connid); $con->canview(); } catch (Exception $e) { return access_denied_error(); } }