<?php
require('routeros_api.class.php');

// MikroTik Router Credentials
$routerIP = '192.168.88.1';
$routerUsername = 'admin';
$routerPassword = 'password';

// New User Details
$newUsername = $_POST['username'];
$newPassword = $_POST['password'];
$profile = 'default'; // Profile to assign

$API = new RouterosAPI();

if ($API->connect($routerIP, $routerUsername, $routerPassword)) {
    $API->write('/ip/hotspot/user/add', false);
    $API->write('=name=' . $newUsername, false);
    $API->write('=password=' . $newPassword, false);
    $API->write('=profile=' . $profile);

    $READ = $API->read(true);
    $API->disconnect();
    echo 'User added successfully';
} else {
    echo 'Unable to connect to RouterOS';
}
?>
