0

APIを介してmikrotikユーザーマネージャーでユーザーを作成するアプリを開発しようとしています。また、次のコマンドを使用してターミナルで JavaScript も試しました。

$node script name.js

それは機能しており、ユーザーが作成されました。次に、HTMLボタンをクリックしてそのJavaScriptを実行しようとしました。その後、JavaScript は実行されず、ユーザーは作成しません。コードは次のとおりです。

<html>
<head>

 </head>
<body>
<button type = "button" onclick="conn();">Try it</button>
<script type="text/javascript">
var api = require('mikronode');
 var connection = new api('192.168.5.1','admin','xxxxxx');
 connection.connect(function conn() {

    conn.closeOnDone(true); // All channels need to complete before the connection will close.

    var actionChannel=conn.openChannel();
    // These will run synchronsously
    actionChannel.write(['/tool/user-manager/user/add','=username=tiran','=password=123456','=customer=admin']); // don't care to do anything after it's done.
    actionChannel.write(['/tool/user-manager/user/create-and-activate-profile','=customer=admin','=numbers=tiran','=profile=general']); // don't care to do anything after it's done.
    //actionChannel.write('/tool/user-manager/user/print',function(chan) {

       //chan.on('done',function(data) {
          //packets=api.parseItems(data);
          //packets.forEach(function(packet) {
              //alert('done');
             //alert('user: '+JSON.stringify(packet));
              //console.log('user: '+JSON.stringify(packet));
          //});
          //listenChannel.close(); // This should call the /cancel command to stop the listen.
       //});
    //});
    actionChannel.close(); // The above commands will complete before this is closed.
 });
</script>
 </body>
 </html>
4

1 に答える 1