<?php /** * --------------------------------------------------------------------- * GLPI - Gestionnaire Libre de Parc Informatique * Copyright (C) 2015-2018 Teclib' and contributors. * * http://glpi-project.org * * based on GLPI - Gestionnaire Libre de Parc Informatique * Copyright (C) 2003-2014 by the INDEPNET Development Team. * * --------------------------------------------------------------------- * * LICENSE * * This file is part of GLPI. * * GLPI is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * GLPI is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GLPI. If not, see <http://www.gnu.org/licenses/>. * --------------------------------------------------------------------- */
// Ensure current directory when run from crontab chdir(__DIR__);
useGlpi\Event;
include ('../inc/includes.php');
if (isset($_SERVER['argv'])) { for ($i=1; $i<$_SERVER['argc']; $i++) { $it = explode("=", $_SERVER['argv'][$i], 2); $it[0] = preg_replace('/^--/', '', $it[0]);
foreach ($DB->request($query) as $task) { if (!empty($only_tasks) && !in_array($task['name'], $only_tasks)) { echo $task['name']." is still running but not in the whitelist\n"; continue; }
que = queue.Queue() vis_nodes = [] que.put(Node) while que.qsize() != 0: top_node = que.get() if top_node notin vis_nodes: vis_nodes.append(top_node) if top_node['code'] == 'DB'or top_node['code'] == 'request': returnTrue child_node_list = get_Child_Nodes(top_node) for child_node in child_node_list: if child_node in vis_nodes: continue que.put(child_node) vis_nodes.append(child_node) returnFalse
defget_Target_Child_Node(Node): """ 根据提供的根节点(即foreach结点),确定$DB->request($query)函数的根结点 :param Node: :return: """ child_node_list = get_Child_Nodes(Node) for child_node in child_node_list: flag = traverse_Child_Node_DFS(child_node) # flag = traverse_Child_Node_BFS(child_node) if flag == True: return child_node returnNone
但这里我还有一个疑惑,为什么是node: { id = '188' }在CFG图上,而不是node: { id = '187' }?
flag = True# 判断是否经过了循环路径 final_PathList = list(set(PathList)) if len(final_PathList) == len(PathList): flag = False final_PathList.sort(key=PathList.index) for key in sorted(CycleDict.keys()): if key in final_PathList: idx = PathList.index(key) # 确定后一个重复的lineno的位置,进行替换 final_PathList[idx + 1:idx + 1] = iter(CycleDict[key]) if flag == True: # 如果没有经过循环,那么不用输出final_PathList,已经输出过PathList了 print(final_PathList)
defget_CFG_Path_DFS(StartNode, EndNode, PathList=[], CycleDict={}): """ 通过深搜来寻找CFG路径,当遍历到结束结点的时候就进行一次路径输出 :param StartNode: 遍历的起始Node结点 :param EndNode: 遍历的结束Node结点 :param PathList: 存储CFG路径 :param CycleDict: CFG图中存在的循环路径,需要特殊处理 :return: """ PathList.append(StartNode['lineno']) if StartNode == EndNode: print_CFG_PathList(PathList, CycleDict) else: CFG_Child_Node_List = get_CFG_Child_Nodes_List(StartNode) for CFG_Child_Node in CFG_Child_Node_List: # 情况1:绝大多数情况下,CFG的当前结点lineno都不会小于其后续结点的lineno if CFG_Child_Node['lineno'] >= StartNode['lineno']: get_CFG_Path_DFS(CFG_Child_Node, EndNode, PathList, CycleDict) # 情况2:在出现循环的情况下,当结点对应循环中的最后一行语句时,其后续子结点会回到循环体的初始行,所以会出现lineno变小的情况 else: # CFG_Child_Node['lineno'] < StartNode['lineno'] # 举例:41 -> 42 -> 43 -> 45(child_lineno) -> 41 child_lineno = CFG_Child_Node['lineno'] # 相当于上面的41 i = 0 while PathList[i] != child_lineno: i = i + 1 i = i + 1 CycleDict[child_lineno] = PathList[i + 1:] PathList.pop()
defget_CFG_FUNC_ENTRY_node(Node): """ 寻找CFG的入口结点,只有一个 :param Node: :return: """ entry_relationship = get_CFG_FUNC_ENTRY_relationships(Node) for rel in entry_relationship: if rel in entry_relationship: if rel.start_node == Node: return rel.end_node returnNone
que = queue.Queue() vis_nodes = [] que.put(Node) while que.qsize() != 0: top_node = que.get() if top_node notin vis_nodes: vis_nodes.append(top_node) if top_node['code'] == 'DB'or top_node['code'] == 'request': returnTrue child_node_list = get_Child_Nodes(top_node) for child_node in child_node_list: if child_node in vis_nodes: continue que.put(child_node) vis_nodes.append(child_node) returnFalse
defget_Target_Child_Node(Node): """ 根据提供的根节点(即foreach结点),确定$DB->request($query)函数的根结点 :param Node: :return: """ child_node_list = get_Child_Nodes(Node) for child_node in child_node_list: flag = traverse_Child_Node_BFS(child_node) if flag == True: return child_node returnNone
flag = True# 判断是否经过了循环路径 final_PathList = list(set(PathList)) if len(final_PathList) == len(PathList): flag = False final_PathList.sort(key=PathList.index) for key in sorted(CycleDict.keys()): if key in final_PathList: idx = PathList.index(key) # 确定后一个重复的lineno的位置,进行替换 final_PathList[idx + 1:idx + 1] = iter(CycleDict[key]) if flag == True: # 如果没有经过循环,那么不用输出final_PathList,已经输出过PathList了 print(final_PathList)
defget_CFG_Path_DFS(StartNode, EndNode, PathList=[], CycleDict={}): """ 通过深搜来寻找CFG路径,当遍历到结束结点的时候就进行一次路径输出 :param StartNode: 遍历的起始Node结点 :param EndNode: 遍历的结束Node结点 :param PathList: 存储CFG路径 :param CycleDict: CFG图中存在的循环路径,需要特殊处理 :return: """ PathList.append(StartNode['lineno']) if StartNode == EndNode: print_CFG_PathList(PathList, CycleDict) else: CFG_Child_Node_List = get_CFG_Child_Nodes_List(StartNode) for CFG_Child_Node in CFG_Child_Node_List: # 情况1:绝大多数情况下,CFG的当前结点lineno都不会小于其后续结点的lineno if CFG_Child_Node['lineno'] >= StartNode['lineno']: get_CFG_Path_DFS(CFG_Child_Node, EndNode, PathList, CycleDict) # 情况2:在出现循环的情况下,当结点对应循环中的最后一行语句时,其后续子结点会回到循环体的初始行,所以会出现lineno变小的情况 else: # CFG_Child_Node['lineno'] < StartNode['lineno'] # 举例:41 -> 42 -> 43 -> 45(child_lineno) -> 41 child_lineno = CFG_Child_Node['lineno'] # 相当于上面的41 i = 0 while PathList[i] != child_lineno: i = i + 1 i = i + 1 CycleDict[child_lineno] = PathList[i + 1:] PathList.pop()
if __name__ == "__main__": start_lineno = 1 end_lineno = 72