Another RouterOS API Delphi Client

hello. excuse my English.
how do I run this command because I have tried various ways and does not serve me.

ip hotspot active remove [/ip hotspot active find]

and tried and not working

ip/hotspot/active/remove 
=[=
=ip=
=hotspot=
=active=
=find=
=]=

or can give me a help to disconnect all active users in hotspot

first,

/ip/hotspot/active/print
=.proplist=.id

then,

/ip/hotspot/active/remove
=.id=comma-separated-list-of-ids-from-prevoius-command-result



hmmm… maybe just disable HotSpot?..

hello how i can connect api via alternative api port?
best regards Gladio peace

function Connect(const Hostname, Username, Password: AnsiString; const Port: AnsiString = '8728'): Boolean;

so, add a string parameter with port number after the password

Chupaka you’re amazing, i love your beautiful mind:)

how i can set timeout for “ROS.Query”
kind regards Gladio Peace.

I wonder how do I include the following eating via api, this command works fine in terminal via mikrotik wimbox


/ queue / simple / add name = “Leonardo Xavier” target-addresses = “192.168.2.34”
max-limit = “256K/256K” burst-limit = “512K/512K” burst-threshold = “256K/256K” burst-time = "60/6
0 "

API and CLI (Terminal) are different things. in API, command should look like this:

/queue/simple/add
=name=Leonardo Xavier
=target-addresses=192.168.2.34
=max-limit=256000/256000
=burst-limit=512000/512000
=burst-threshold=256000/256000
=burst-time=60/60

thank Chupaka
but solved this problem a few days ago, now I want to see if I can remove a client’s specific mikrotik via its api, I’m having trouble with the command to locate the customer, and isolates it from the other, because the print command and not find me retronam via WinBox values ​​which can not hold a charge for this type of association as I did with the other commands, testing them in wimbox first.
Another thing about the backup could generate the file with the following command:

/ system / files / backup / save

the file appears in the files wimbox perfect as backup, but how to make a print this file in a memo field? even how to get this file?

Hey Chupaka
I have this component running great for a long time, since before Delphi 2009.
But there is a problem with multi-threading.
I put whole component inside a thread and sometimes, with few instances in different threads, connecting to different routers, all threads (or just 1) would just hang.
Almost like a lockup in critical section or something.
I could not pinpoint where it hang yet, but I thought maybe you could give me some pointer what I could look for, or maybe is it a limitation/bug in Syapse libs?

Thanks
Ekkas

as far as I know, Synapse is being written with multi-threading in mind, so there should not be any problems in it…

Excellent work.
It’s working fine for some purposes.
But it has a very serious bug (or maybe I’m not using correctly)

  • if you are connected on mikrotik and
  • if the mikrotik is unavailable(this can happen easily) and
  • if you send a command for the router, the application will crash completely and not come back anymore. :frowning:
    To do a test like this is simple, connect in the RouterOS, disconnect the network cable or just a reboot in RouterOS and then send a command. The result will be disastrous =/
    Any way to fix this problem?
    ty.

I recorded a video for more detail, maybe my explanation was confusing.
I’m using the demo application to report. :slight_smile:

[youtube]http://www.youtube.com/watch?v=jaiuJyeg0SA&f[/youtube]

I do not believe to be the best solution, but that works fine for me.
I made a new function to send commands based on the former, with the difference that she always checks if the remote port is available before to send the query. If you can fix this another way is rly better, thanks!


Function Tfrm_ApiConect.SendAndGetAll(ComandoCmd: TStrings): String;
var
  Res: TRosApiResult;

  pa: array of AnsiString;
  i: Integer;
  i2: Integer;
  s: String;
begin
s := 'ERROR: Host unreachable.';
if TestServer(##### IP VALUE #####, ##### PORT VALUE #####)) then
 begin
  s := '';
  SetLength(pa, 0);
  for i := 0 to ComandoCmd.Count - 1 do
  begin
    s := Trim(ComandoCmd[i]);
    if s <> '' then
    begin
      SetLength(pa, High(pa) + 2);
      pa[High(pa)] := s;
    end;
  end;
  if High(pa) >= 0 then
  begin

   Res := ROS.Query(pa, True)
    end
  else
  begin
    ShowMessage('Type a command!');
    Exit;
  end;

  if ROS.LastError <> '' then
  begin
   s := ('ERROR: ' + ROS.LastError);
  end;

  while not Res.Eof do
  begin
    for i := 0 to High(Res.Values) do
      s := s + Res.Values[i].Name + '=' + Res.Values[i].Value + #13#10;
    s := s + '<END_INFO>'#13#10;
    Res.Next;
  end;

  s := s + '================'#13#10;
  s := Replace(s, #0, '#0');
  Res.Free;
 end;
    Result := (s);

 end;

Function TestServ(Host, Port: String): Boolean;
var
  bCon: Boolean;
begin
  bcon := False;
    with TTcpClient.Create(nil) do
    try
      try
        RemoteHost := Host;
        RemotePort := Port;
        Connect;
        bCon := Connected;
      except
      end;
    finally
      if  bCon then
      begin
        Disconnect;
        Result := True;
      end
      else
      begin
      	Connect;
	bCon := Connected;
	 if  bCon then
    	  begin
       	   Disconnect;
           Result := True;
       	  end
          else
      	  begin
          Result := False;
         end;
      end;
      Free;
    end;

end;

v1.2: Added basic support for API over TLS

Only TLS without certificate is currently supported.
Add ‘ssl_openssl’ to your project uses (http://synapse.ararat.cz/doku.php/public:howto:sslplugin) and then call TRosApiClient.SSLConnect() instead of TRosApiClient.Connect()

links in first post, and here is a patch for RouterOSAPI.pas
RouterOSAPI-1.1-to-1.2.zip (1.31 KB)

Hello,

/tool/user-manager/user/add
=customer=admin
=username=123
=password=123
=copy-from=*88

This works but the idea is simple hotspot POS for user who will add username and password random generated in Edit1.Text but…

How to add this script into delphi without using memo. If cant add into delphi how to add dynamic field to read Edit1.Text in memo every time.

Thanks

memo is just for ease of handling from user side. look at any button’s code, you may do something like
var
pa: array of AnsiString;
i: Integer;
begin
SetLength(pa, 5);
pa[0] := ‘/tool/user-manager/user/add’;
pa[1] := ‘=customer=admin’;
pa[4] := ‘=copy-from=*88’;

for i := 100 to 199 do
begin
pa[2] := ‘=username=’ + IntToStr(i);
pa[3] := ‘=password=’ + GetMyRandomPasswordFor(i);

ROS.Query(pa, True).Free; // don't even try to check for errors - bad practice =]

end;

Thanks for advice. I’m still using memo because thats really easy way to see whats happen, but i have one more question.

How to check for existing user in user-manager?

I’m using

Randomize;
I := Random(9999999999);
Memcmd.Lines.Strings[0] := ‘/tool/user-manager/user/add’;
Memcmd.Lines.Strings[1] := ‘=customer=admin’;
Memcmd.Lines.Strings[2] := ‘=username=’ + IntToStr(I) + End7;
Memcmd.Lines.Strings[3] := ‘=password=’ + IntToStr(I) + End7;
Memcmd.Lines.Strings[4] := ‘=copy-from=’ + CopyFrom7;

PS. - end7, copyfrom7 is readstring from ini file


With this i found username and all info for him, but how to check for existing when press button and generate new “unique” string?
/tool/user-manager/user/print
?name=115053253411

All of this will be useless if i’m 100% sure Randomize generate unique values.

Do you know method for unique values?

many many questions, but this may be interest and for other users :slight_smile: (not only for me)

Thanks :slight_smile:

your way

/tool/user-manager/user/print
?name=115053253411

is the right one. if the user exists - just generate one more random value :slight_smile:

well, if you’re not generating more than 1 user per second, you may use DateTimeToUnix(Now) for username :smiley:

It works with delphi 7
but it can’t conncet in delphi 2013 XE4
this error appears:
“Host not found”

could you help me please?
thanks