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?
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.
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 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;
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()
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 =]
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 (not only for me)