/** * send current config to the firewall and save under name $config_name * */ public function API_uploadConfig($config_name = 'panconfigurator-default.xml') { print "Uploadig config to device...."; $url = "&type=import&category=configuration&category=configuration"; $answer =& $this->connector->sendRequest($url, false, DH::dom_to_xml($this->xmlroot), $config_name); print "OK!\n"; }
} } print "Tagging object " . $o['sub'] . "/" . $o['name'] . "... "; //$connector->setShowApiCalls(true); $connector->sendSetRequest($xpath, $element); print "OK!\n"; } } /****************** * script starts here * */ $con = new PanAPIConnector($argv[1], ''); //$con->setShowApiCalls(true); print "Requesting API key..."; $res =& $con->sendRequest("type=keygen&user={$argv['2']}&password={$argv['3']}"); $res =& searchForName('name', 'result', $res); if ($res === null) { derr('error'); } $res =& searchForName('name', 'key', $res['children']); if ($res === null) { derr('error'); } if (strlen($res['content']) < 1) { derr('error'); } $con->apikey = $res['content']; print "OK, key is {$con->apikey}\n\n"; // end of API key extraction // PANOS or Panorama ?
/** * @param string $host * @param string $apiKey * @param bool $promptForKey * @param bool $checkConnectivity * @return PanAPIConnector */ public static function findOrCreateConnectorFromHost($host, $apiKey = null, $promptForKey = true, $checkConnectivity = true) { self::loadConnectorsFromUserHome(); $host = strtolower($host); foreach (self::$savedConnectors as $connector) { if ($connector->apihost == $host) { return $connector; } } if ($apiKey === null && $promptForKey === false) { derr('API host/key not found and apiKey is blank + promptForKey is disabled'); } if ($apiKey !== null) { $connection = new PanAPIConnector($host, $apiKey, 'panos'); } elseif ($promptForKey) { print "** Request API access to host '{$host}' but API was not found in cache.\n" . "** Please enter API key or username below and hit enter: "; $handle = fopen("php://stdin", "r"); $line = fgets($handle); $apiKey = trim($line); if (strlen($apiKey) < 19) { $user = $apiKey; print "* you input user '{$user}' , please enter password now: "; $line = fgets($handle); $password = trim($line); print "* Now generating an API key from '{$host}'..."; $con = new PanAPIConnector($host, ''); $url = "type=keygen&user={$user}&password={$password}"; $res = $con->sendRequest($url); $res = DH::findFirstElement('response', $res); if ($res === false) { derr('missing <response> from API answer'); } $res = DH::findFirstElement('result', $res); if ($res === false) { derr('missing <result> from API answer'); } $res = DH::findFirstElement('key', $res); if ($res === false) { derr('unsupported response from PANOS API'); } $apiKey = $res->textContent; print "OK, key is {$apiKey}\n\n"; } fclose($handle); $connection = new PanAPIConnector($host, $apiKey, 'panos'); } if ($checkConnectivity) { $connection->testConnectivity(); self::$savedConnectors[] = $connection; self::saveConnectorsToUserHome(); } return $connection; }