#!/usr/bin/php -q This script is only meant to run at the command line."); } $no_http_headers = true; include(dirname(__FILE__)."/../include/global.php"); if ($_SERVER["argc"] == 1) { usage(); return 1; }else{ $groupName = ''; $userId = 0; $itemTypes = array('graph' => 1, 'tree' => 2, 'host' => 3, 'graph_template' => 4); $itemType = 0; $itemId = 0; for ($i = 1; $i < $_SERVER["argc"]; $i++) { switch ($_SERVER["argv"][$i]) { case "--user-id": $i++; $userId = $_SERVER["argv"][$i]; break; case "--group-name": $i++; $groupName = $_SERVER["argv"][$i]; break; case "--item-type": $i++; $itemType = $itemTypes[$_SERVER["argv"][$i]]; break; case "--item-id": $i++; $itemId = $_SERVER["argv"][$i]; break; default: usage(); return 1; } } if ($itemType == 0 || $itemId == 0) { usage(); return 1; } $userIds = array(); if (isset($groupName) && $groupName != '') { $users = db_fetch_assoc("select id from user_auth where oss_group = \"$groupName\""); foreach ($users as $u) { array_push($userIds, $u["id"]); } }elseif(isset($userId) && $userId > 0) { array_push($userIds, $userId); } foreach ($userIds as $id) { db_execute("replace into user_auth_perms (user_id, item_id, type) values ($id, $itemId, $itemType)"); } } function usage() { echo "Usage:\n"; echo "add_perms.php [ --group-name [Group Name] | --user-id [ID] ] --item-type --item-id\n\n"; echo "Where item-type is one of: graph, tree, host or graph_template\n"; } ?>