Deprecated: Use of "parent" in callables is deprecated in /var/www/html/forum/src/vendor/league/flysystem-eventable-filesystem/src/EventableFilesystem.php on line 431
  • If you need help or want to discuss things, you now can also join us on our Discord Server!
  • A first preview of the unlimited version of SinusBot can be found in the Upcoming Changes thread. A version for Windows will follow, but we don't have a release date, yet.

PhP "Method Not Allowed" trotz POST

Status
Not open for further replies.
<?php
Code:
[CODE]
class Bot {
    public $botHost = '127.0.0.1';
    public $botPort = 8087;
    public $botId = NULL;
    public $token = NULL;
    public $uuid = NULL;
    public function __construct($botHost = '127.0.0.1', $botPort = 8087, $botId = NULL) {
        $this->botHost = $botHost;
        $this->botPort = $botPort;
        if ($botId == NULL) {
            $botId = $this->DefaultBot();
        }
        $this->botId = $botId;
    }
    public function DefaultBot() {
        $ch = curl_init();
        curl_setopt_array($ch, array(
            CURLOPT_URL => 'http://'.$this->botHost.':'.$this->botPort.'/api/v1/botId',
            CURLOPT_RETURNTRANSFER => 1
        ));
        $data = curl_exec($ch);
        curl_close($ch);
        $json = json_decode($data, TRUE);
        return $json['defaultBotId'];
    }
    public function Login($username, $password) {
        $ch = curl_init();
        curl_setopt_array($ch, array(
            CURLOPT_URL => 'http://'.$this->botHost.':'.$this->botPort.'/api/v1/bot/login',
            CURLOPT_RETURNTRANSFER => 1,
            CURLOPT_POSTFIELDS => json_encode(array('username' => $username, 'password' => $password, 'botId' => $this->botId)),
            CURLOPT_HTTPHEADER => array('Content-Type: application/json')
        ));
        $data = curl_exec($ch);
        $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        #echo "data: ".$data."<br>Code: ".$code."<br>";
        curl_close($ch);
        if ($code != 200) return NULL;
        $token=json_decode($data, TRUE);
        $this -> token =$token["token"];
    }
    public function GetInstances() {
        $ch = curl_init();
        curl_setopt_array($ch, array(
            CURLOPT_URL => 'http://'.$this->botHost.':'.$this->botPort.'/api/v1/bot/instances',
            CURLOPT_RETURNTRANSFER => 1,
            CURLOPT_HTTPHEADER => array('Authorization: bearer '.$this->token)
        ));
        $data = curl_exec($ch);
        $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        #echo $data;
        #echo $code;
        curl_close($ch);
        if ($code != 200) return NULL;
        $json = json_decode($data, TRUE);
        return $json;
    }
    public function GetInstanceStatus($instanceId) {
        $ch = curl_init();
        curl_setopt_array($ch, array(
            CURLOPT_URL => 'http://'.$this->botHost.':'.$this->botPort.'/api/v1/bot/i/'.$instanceId.'/status',
            CURLOPT_RETURNTRANSFER => 1,
            CURLOPT_HTTPHEADER => array('Authorization: bearer '.$this->token)
        ));
        $data = curl_exec($ch);
        $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);
        if ($code != 200) return NULL;
        $json = json_decode($data, TRUE);
	return $json;
    }
    public function KillInstance($uid) {
        $ch = curl_init();
        curl_setopt_array($ch, array(
            CURLOPT_URL => 'http://'.$this->botHost.':'.$this->botPort.'/api/v1/bot/i/'.$uid.'/kill',
            CURLOPT_RETURNTRANSFER => 1,
            CURLOPT_HTTPHEADER => array('Authorization: bearer '.$this->token)
        ));
        $data = curl_exec($ch);
        $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
	echo $data."->".$code;
        curl_close($ch);
        if ($code != 200) return NULL;
        $json = json_decode($data, TRUE);
	return $json;
    }
    public function SpawnInstance($instanceId) {
        echo $instanceId;
        $ch = curl_init();
        curl_setopt_array($ch, array(
            CURLOPT_URL => 'http://'.$this->botHost.':'.$this->botPort.'/api/v1/bot/i/'.$instanceId.'/spawn',
            CURLOPT_RETURNTRANSFER => 1,
            CURLOPT_HTTPHEADER => array('Authorization: bearer '.$this->token)
        ));
        #printr($ch);
        $data = curl_exec($ch);
        $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);
        if ($code != 200) return NULL;
        $json = json_decode($data, TRUE);
	return $json;
    }

}

$bot = new Bot('127.0.0.1', 8087);
$bot->Login('admin', 'foobar');

if (isset($_POST['submit']))
{
    echo"Post da<br>";
  $uuid=$_POST['uid'];
  $value1=$_POST['submit'];
  $bot->KillInstance($uuid);
  #echo $bot;
  echo $uuid."->".$value1;
    unset($_POST['submit']);
    #header('Loacatio


}
else
{
echo "Kei Post";
}

$instances = $bot->GetInstances();
#printf($instances);
#echo '<link href="css location" rel="stylesheet" type="text/css" />';
#echo "Wassustfalsch";
echo "<table border=1 width=100%>";
echo "<tr><td colspan=4>Musikbot Control</td></tr>";
echo "<tr><td>Botname</td><td>Sender</td><td>Titel</td><td>Actio</td></tr>";
#echo "</table>";
for ($i = 0; $i < count($instances); $i++) {

    $info = $bot->GetInstanceStatus($instances[$i]['uuid']);
    if ($info['currentTrack'] != NULL && $info['playing']) {

        echo '';
  #printf("%s is playing %s by %s\n", $instances[$i]['nick'], $info['currentTrack']['title'], $info['currentTrack']['artist']);
  echo "<tr><td>".$instances[$i]['nick']."</td><td>".$info['currentTrack']['title']."</td><td>".$info['currentTrack']['artist'];
  echo '</td><td>';

  # actioplacedhere</td></tr>
 
    echo'<form action="botctl.php" method="post"><input type="hidden" name="uid" value="'.$instances[$i]['uuid'].'"><button type="submit" name="submit" value="kill">Kill</button></form>';
    echo"</td></tr>";

    } else {

        echo '<div class="output'.$i.'">';
  printf("%s is not playing anything right now\n", $instances[$i]['nick']);
  echo '
'; 
    }
}
echo "</table>";
[/CODE]
?>

Jemand eine Idee weshalb das nicht geht? Wusste nicht genau wo ich das posten sollte, darum einfach mal in Installation reingepackt.
 

flyth

is reticulating splines
Staff member
Developer
Contributor
Du machst da kein POST. Du musst die entsprechenden CURLOPT-Felder setzen. Lies dir am besten mal die Doku zu curl in PHP durch.
 
Status
Not open for further replies.
Top