Skip to content

Instantly share code, notes, and snippets.

@jaapmarcus
Created September 11, 2020 07:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jaapmarcus/86c0e588a8ba69a6f521e3ea370708a4 to your computer and use it in GitHub Desktop.
Save jaapmarcus/86c0e588a8ba69a6f521e3ea370708a4 to your computer and use it in GitHub Desktop.
api_test.php
<html>
<head>
<title>API Demo</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
</head>
<body>
<?php
if($_POST){
echo '<pre>';
echo 'https://' . $_POST['hostname'] . ':' . $_POST['port'] . '/api/'."\r\n";
// Prepare POST query
$postvars = array(
'user' => $_POST['admin'],
'password' => $_POST['password'],
'returncode' => 'no',
'cmd' => 'v-list-users',
);
$postdata = http_build_query($postvars);
// Send POST query via cURL
$postdata = http_build_query($postvars);
$curl = curl_init();
curl_setopt($curl, CURLOPT_HEADER, true);
curl_setopt($curl, CURLOPT_URL, 'https://' . $_POST['hostname'] . ':' . $_POST['port'] . '/api/');
curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
$answer = curl_exec($curl);
var_dump($answer);
echo '</pre>';
}
?>
<div class="content">
<form method="post">
<div class="row">
<div class="col-md-3">
<label for="ip">Hostname</label>
</div>
<div class="col-md-9">
<input type="text" name="hostname" value="<?php if(!empty($_POST['hostname'])){ echo $_POST['hostname'];}?>" class=""/>
</div>
</div>
<div class="row">
<div class="col-md-3">
<label for="port">PORT</label>
</div>
<div class="col-md-9">
<input type="text" name="port" value="<?php if(!empty($_POST['port'])){ echo $_POST['port'];}?>" class=""/>
</div>
</div>
<div class="row">
<div class="col-md-3">
<label for="admin">User</label>
</div>
<div class="col-md-9">
<input type="text" name="admin" value="<?php if(!empty($_POST['admin'])){ echo $_POST['admin'];}?>" class=""/>
</div>
</div>
<div class="row">
<div class="col-md-3">
<label for="admin">Password</label>
</div>
<div class="col-md-9">
<input type="text" name="password" value="<?php if(!empty($_POST['password'])){ echo $_POST['password'];}?>" class=""/>
</div>
</div>
<input type="submit">
</form>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
<script src="./js.js"></script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment