octo / librouteros

C library to communicate with network devices by MikroTik running their Linux-based operating system RouterOS.
ISC License
19 stars 6 forks source link

How to install on raspbian? #15

Closed SummerSeaSun closed 4 years ago

SummerSeaSun commented 4 years ago

Readme is missing the steps needed to install, this is what I've done:

git clone https://github.com/octo/librouteros.git
cd librouteros/
automake

result in errors:

configure.ac: error: no proper invocation of AM_INIT_AUTOMAKE was found. configure.ac: You should verify that configure.ac invokes AM_INIT_AUTOMAKE, configure.ac: that aclocal.m4 is present in the top-level directory, configure.ac: and that aclocal.m4 was recently regenerated (using aclocal) configure.ac:30: error: required file './install-sh' not found configure.ac:30: 'automake --add-missing' can install 'install-sh' Makefile.am: error: required file './INSTALL' not found Makefile.am: 'automake --add-missing' can install 'INSTALL' src/Makefile.am:3: error: COMPILER_IS_GCC does not appear in AM_CONDITIONAL src/Makefile.am:5: error: BUILD_WITH_DEBUG does not appear in AM_CONDITIONAL src/Makefile.am:15: error: BUILD_WITH_LIBSOCKET does not appear in AM_CONDITIONAL configure.ac:3: error: required file 'src/config.h.in' not found src/Makefile.am:11: error: Libtool library used but 'LIBTOOL' is undefined src/Makefile.am:11: The usual way to define 'LIBTOOL' is to add 'LT_INIT' src/Makefile.am:11: to 'configure.ac' and run 'aclocal' and 'autoconf' again. src/Makefile.am:11: If 'LT_INIT' is in 'configure.ac', make sure src/Makefile.am:11: its definition is in aclocal's search path. src/Makefile.am:18: warning: source file 'md5/md5.c' is in a subdirectory, src/Makefile.am:18: but option 'subdir-objects' is disabled automake: warning: possible forward-incompatibility. automake: At least a source file is in a subdirectory, but the 'subdir-objects' automake: automake option hasn't been enabled. For now, the corresponding output automake: object file(s) will be placed in the top-level directory. However, automake: this behaviour will change in future Automake versions: they will automake: unconditionally cause object files to be placed in the same subdirectory automake: of the corresponding sources. automake: You are advised to start using 'subdir-objects' option throughout your automake: project, to avoid future incompatibilities.

Instead this way for install success, but there are missing "*.h" at runtime:

1 ) ---- download librouteros-1.1.2.tar.bz2 from https://github.com/octo/librouteros/releases/download/librouteros-1.1.2/librouteros-1.1.2.tar.bz2 to a file /home/pi/librouteros-1.1.2.tar.bz2 ( home page: https://octo.github.io/librouteros/ examples: https://wiki.mikrotik.com/wiki/Librouteros ) 2 ) ---- extract from /home/pi/librouteros-1.1.2.tar.bz2 to /home/pi/librouteros-1.1.2 3 ) ---- cd /home/pi/librouteros-1.1.2 4 ) ---- apt install libgcrypt-dev 5 ) ---- modify the file: /home/pi/librouteros-1.1.2/src/ros.c ( example file ) --- comment out line 296: const char *host; --- comment out line 320: host = argv[optind];

5 ) ---- ./configure 6 ) ---- make 7 ) ---- make install 8 ) ---- create a symlink /usr/share/man/man1/ros.1 to /opt/librouteros/share/man/man1/ros.1 9 ) ---- create a symlink /usr/share/man/man3/librouteros.3 to /opt/librouteros/share/man/man3/librouteros.3 10 ) ---- create a symlink /usr/lib/librouteros.so.0 to /opt/librouteros/lib/librouteros.so.0

To build and run the test program: 1 ) ---- cd /home/pi/ 2 ) ---- make wifirssitest 3 ) ---- ./wifirssitest

The test program would output:

Temporary breakpoint 1, main (argc=1, argv=0x7effdf14) at wifirssitest.c:77
77 c = ros_connect ("192.168.1.1", ROUTEROS_API_PORT, "WHO", "AMI");
(gdb) n
78 if (c == NULL)
(gdb)
80 fprintf (stderr, "ros_connect failed: %s\n", strerror (errno));
(gdb)
ros_connect failed: Permission denied
81 exit (EXIT_FAILURE);
(gdb) n
[Inferior 1 (process 627) exited with code 01]

Getting down in step by step:

__GI_getaddrinfo (name=0x10d88 "192.168.1.1", service=0x10d80 "8728", hints=hints@entry=0x7effdd68, pai=0x7effdd64, pai@entry=0x7effdd5c)
at ../sysdeps/posix/getaddrinfo.c:2175
2175 ../sysdeps/posix/getaddrinfo.c: No such file or directory.
SummerSeaSun commented 4 years ago

Even with admin user I still get: ros_connect failed: Permission denied

manio commented 4 years ago

@Summer88 You are compiling it wrong. Take a look how I am doing it under debian:

git clone https://github.com/octo/librouteros.git
cd librouteros
autoreconf -ivf
./configure
make -j4

The permission denied error you have indicating a problem on the mikrotik or its configuration I suppose...

SummerSeaSun commented 4 years ago

Thank for your reply I've tried to reinstall with:

git clone https://github.com/octo/librouteros.git 
cd librouteros
root@gigi:/home/pi/librouteros# autoreconf -ivf
autoreconf: Entering directory `.'
autoreconf: configure.ac: not using Gettext
autoreconf: running: aclocal --force 
autoreconf: configure.ac: tracing
autoreconf: configure.ac: not using Libtool
autoreconf: running: /usr/bin/autoconf --force
configure.ac:36: error: possibly undefined macro: AC_LIBTOOL_DLOPEN
      If this token and others are legitimate, please use m4_pattern_allow.
      See the Autoconf documentation.
configure.ac:37: error: possibly undefined macro: AC_PROG_LIBTOOL
autoreconf: /usr/bin/autoconf failed with exit status: 1

However with this python library I can connect so the router is configured correctly. https://github.com/socialwifi/RouterOS-api

There's only a difference from python script to C, theres a plain_login option?

manio commented 4 years ago

What version of libtool you have installed?

I don't know the difference - never used a python script. If you compile librouteros there is a test tool which you can use for connecting to mikrotiks. You sure you are passing proper credentials and you have enabled the api in the routeros? Also make sure that you are not using SSL which is currently not enabled in the library....

SummerSeaSun commented 4 years ago

Actually libtool wasn't installed at all.

libtool/stable,now 2.4.6-9 all [installed]
  Generic library support script

Now autoreconf -ivf and install succeded. Recompiled the script but output is the same.

I've checked on the router API port 8728 is open. Thank you

manio commented 4 years ago

Hmmm ... no idea what is wrong in your case. I was testing it and it is working for me without any problem (I am constantly using the library for collecting statistics into collectd). Maybe they changed something in the newer RouterOS versions? No idea :(

SummerSeaSun commented 4 years ago

@cirolandolfi found the issue

Please take a look at you should update your code to work with latest RouterOS.

https://wiki.mikrotik.com/wiki/Manual:API

image

manio commented 4 years ago

@Summer88 This was done two years ago! :) https://github.com/octo/librouteros/commit/348e107aa5023c520604a0f67c68ce53794eb606

SummerSeaSun commented 4 years ago

Well looking at Release page "Latest release" appear to be 1.1.2 and that was the starting point of the issue.