Pages

Σάββατο 11 Μαΐου 2013

Ubiquity UniFi Controller Software στο openSUSEUbiquity UniFi Controller Software in openSUSE

Το ξεκίνημα της ιστορίας

The Beginning Of The Story

Κάποια στιγμή μου ζητήθηκε από ένα φίλο να τον βοηθήσω να στήσει ένα δίκτυο σε ένα ξενοδοχείο. Μετά από λίγο ψάξιμο βρέθηκαν τα κατάλληλα εργαλεία για αυτή τη δουλειά: τα Access Points της Ubiquity. Συγκεκριμένα η απόφαση πήγε στη σειρά UniFi που έχουν καταπληκτικά χαρακτηριστικά. Δίνουν τη δυνατότητα για custom guest portal για την είσοδο των πελατών, δημιουργία VPNs, μέχρι τέσσερα διαφορετικά SSIDs με το καθένα από αυτά να έχει τα δικά του χαρακτηριστικά, ορισμό μέγιστου bandwidth για κάθε client που συνδέεται επάνω, ορισμό μέγιστου ποσού δεδομένων που θα διακινήσει και πολλά άλλα. Όλα αυτά τα δίνουν σε αρκετά προσιτή τιμή.

Once, a friend of mine asked me to help him set up a wireless network of a hotel. After short searching in the internet and around the necessary tools for this job were found: The Access Points of Ubiquity. More precisely the decision end up to the UniFi line that have great specifications. They have the ability to use custom guest portals for the authorisation to the network usage, VPNs, ability to handle up to four wireless SSIDs, each having its own characteristics, bandwidth limit per client, user data quota and many many more; and all these in a very good price.

Το μειονέκτημα που υπάρχει στην όλη ιστορία είναι πως για να έχει custom guest portal, ή δημιουργία voucher για τους πελάτες, θα πρέπει ένας υπολογιστής να τρέχει συνεχώς το software της μαμάς εταιρίας (Ubiquity). Για να λυθεί αυτό, αρχικά υπήρχε η ιδέα να χρησιμοποιηθεί το μηχάνημα της reception του ξενοδοχείου για αυτή τη δουλειά. Όμως το μηχάνημα αυτό θα πρέπει να σβήνει κάποιες φορές... Άλλο ένα μειονέκτημα είναι ότι το συγκεκριμένο μηχάνημα τρέχει το ακατονόμαστο λειτουργικό.

The only drawback in the whole system is the necessity to have one computer running the mother company's (Ubiquity's) software 24/7 to give the ability of serving the custom guest portal and client voucher creation. The first idea was to use the reception's computer for that purpose. But this computer is switched off some hours in the night... Another minus in this idea was that this specific machine must run the unnamed operating system (may God make it "operating").

Μετά από μια επίδειξη του Ubuntu και του openSUSE, παρότι έχει κάποια ιδέα αυτός ο φίλος από Linux, προτίμησε (τι αναπάντεχο...) να χρησιμοποιήσει το προσωπικό του μηχάνημα με openSUSE και το software της Ubiquity να τρέχει σε αυτό το μηχάνημα. Αυτό το μηχάνημα δεν σβήνει ποτέ, οπότε είναι η καλύτερη ιδέα!

After a small demonstration of Ubuntu and openSUSE, though my friend already knew some things about Linux, he prefered (hmmm, how unexpected...) to use openSUSE and Ubiquity's software in his personal computer. That computer could stay alive 24/7, so this was the best idea!

Τι θα δούμε

What's in this article

Τα κομμάτια που θα δούμε σε αυτό το άρθρο είναι τα ακόλουθα:

We are going to discuss the following topics:

Προεργασία

Groundwork

Η προεργασία για το στήσιμο του συστήματος έχει το κλασικό backup αρχείων, εγκατάσταση του openSUSE στον υπολογιστή και επαναφορά των αρχείων από το backup του προηγούμενου λειτουργικού

The groundwork we have to do is to backup the system, install openSUSE in the computer and restore the necessary user files form the backup of the previous (ehmmm... non) operating system.

Στη συνέχεια θα πρέπει να εγκατασταθούν οι εξαρτήσεις που χρειάζεται το UniFi Controller Software. Αυτές δεν είναι πολλές:

Next, follows the step of dependecies installation of UniFi Controller Software. They are not that many:

  • Java
  • MongoDB

Η Java είναι από την αρχή εγκαταστημένη στο openSUSE (όπως και σε κάθε διανομή Linux), οπότε το μόνο που υπήρχε σαν εγκατάσταση είναι η database MongoDB. Δεν υπάρχει ευκολότερο πράγμα από αυτό. Απλώς ανοίγουμε το YaST (από το κεντρικό μενού επιλέγουμε το tab "Computer" και από τη λίστα που εμφανίζεται επιλέγουμε το "Install/Remove Software"

Java should be already installed in openSUSE (as in every Linux distribution), so the only one left to be installed is MongoDB database. There is no easier thing than that. Just open YaST (from the main menu select the "Computer" tab and in the appeared list select "Install/Remove Software"

Μετά την εισαγωγή του συνθηματικού του root, ανοίγει το κεντρικό παράθυρο του "YaST - Software Management". Στο πεδίο εύρεσης γράφουμε το "mongodb" και πατάμε το "Search". Στο δεξί τμήμα του παραθύρου εμφανίζεται και το πακέτο που μας ενδιαφέρει. Κάνουμε διπλό κλικ επάνω του και αμέσως μαρκάρεται για εγκατάσταση. Πατώντας το "Accept" ξεκινάμε την εγκατάσταση του πακέτου μας:

After typing the root password, "YaST - Software Management" main window opens. In the search field type "mongodb" and press "Search". At the right part of this window the needed package appears. Double clicking marks the package for installation. By pressing "Accept" the installation begins:

Εγκατάσταση του UniFi Controller

UniFi Controller Installation

Η εγκατάσταση του συστήματος είναι εύκολη. Δεν έχει κάτι το περίπλοκο. Το πρόγραμμα διατίθεται σε μορφή συμπιεσμένου αρχείου .zip σε δύο εκδόσεις:

The installation of the program in question is very simple. It does not contain anything complicated. It is available as a .zip file in two versions (at the time of this writing):

Όποια έκδοση και αν προτιμήσετε η εγκατάσταση γίνεται με τον ίδιο τρόπο. Σε γενικές γραμμές, για να είναι κάπως clean το σύστημα, προτείνεται εγκαταστάσεις τέτοιου είδους (που δεν είναι δηλαδή από αποθετήρια του λειτουργικού) να γίνονται στον κατάλογο /opt/, ή στον κατάλογο /usr/local/. Εδώ η εγκατάσταση θα γίνει στον κατάλογο /opt/. Απλά αποσυμπιέστε ως root τα περιεχόμενα του αρχείου .zip που κατεβάσατε, στον κατάλογο /opt/.

Whichever version you prefer to use, the installation walkthrough is the same. In general, for our system to be cleaner, such installations (meaning, installation of programs not included in the repositories of the system) is better to be either in /opt/ directory, or /usr/local/ one. In this article the installation will be in /opt/. Just unzip as root the .zip file you downloaded, at /opt/ directory.

eliaschr@orion:~> su
Password: 
orion:/home/eliaschr # cd /opt/
orion:/opt # unzip /home/eliaschr/Downloads/UniFi.unix.zip
.
.
.
orion:/opt # 

Δημιουργία group unifi - Προαιρετικό Βήμα

unifi Group Creation - Optional Step

Επειδή λογικά θα χρειάζεστε κατά καιρούς να κάνετε κάποιες αλλαγές, όπως δημιουργία guest portal κ.λ.π. που έχουν να κάνουν με απ' ευθείας αλλαγές στα αρχεία του δίσκου, καλό είναι να δημιουργήσετε ένα group με ονομασία unifi και να κάνετε τα αρχεία του καταλόγου UniFi/data να ανήκουν σε αυτό το group. Αν ενεργοποιήσετε και το SGID bit του εν λόγω υποκαταλόγου, τότε κάθε καινούργιο αρχείο ή κατάλογο που θα δημιουργείτε μέσα στον data θα ανήκει στο group unifi. Είναι προαιρετικό βήμα, αλλά ας δούμε πως γίνεται. Γενικά, οι επεξηγήσεις που υπάρχουν γίνονται όσο το δυνατόν με λιγότερη χρήση κονσόλας για να είναι λίγο πιο κατανοητά σε καινούργιους χρήστες του λειτουργικού:

Since from time to time you may need to make some alterations of the system, like the alteration of the guest portal etc., on the disc files, it is a very good way to create a user group named unifi and make the files in UniFi/data directory belong to it. If you also set the SGID bit of the directory in question, then every new file created in data will belong to the unifi group, also. It is an optional step, but lets see how it is done. In general, the explanations given in here use the command line interface as less as possible, for the new users of the operating system to be able to understand them easier:

Η δημιουργία του group γίνεται από το YaST. Αφού γίνει η επιλογή του YaST από το μενού και δωθεί ο κωδικός του root, εμφανίζεται το κεντρικό παράθυρο. Για τη δημιουργία ένός group γίνεται επιλογή της ομάδας "Security and Users" και στη δεξιά πλευρά του "User and Group Management"

The group creatin is done in YaST. By selecting YaST from the main menu and the root password is given, the main window of the program appears. To create o user group select "Security and Users" at the left side of the window and "User and Group Management" from its right part.

Το παράθυρο που ανοίγει δείχνει τους χρήστες που υπάρχουν αυτή τη στιγμή στο σύστημα. Στο επάνω μέρος υπάρχουν τέσσερις καρτέλες. Η δεύτερη ονομάζεται "Groups" και μιας και μας ενδιαφέρει να προσθέσουμε ομάδα στο σύστημα, την επιλέγουμε. Με την επιλογή της καρτέλας των ομάδων, εμφανίζονται στην οθόνη οι διαθέσιμες ομάδες ενώ στο κάτω τμήμα της οθόνης υπάρχει το πλήκτρο προσθήκης "Add". Με την επιλογή αυτού του πλήκτρου εμφανίζεται το παράθυρο της προσθήκης ομάδας.

The window that opens presents the users that exist in the system. At the upper part there are four tabs. The second one is named "Groups" and since we need to add a user group in our system, we select it. After our tab selection, the available groups appear on screen while at the bottom of the screen there is a button named "Add". Selecting this button a new window opens for the new group creation.

Στη θέση ονόματος της καινούργιας ομάδας μπαίνει το όνομα "unifi". Το νούμερο του group δεν χρειάζεται να αλλάξει μιας κι επιλέγεται αυτόματα από το σύστημα. Στο δικό σας σύστημα μπορεί να είναι διαφορετικό. Από τη δεξιά στήλη γίνεται επιλογή των χρηστών που θα έχουν τα δικαιώματα να αλλάζουν τις ρυθμίσεις του guest portal χωρίς να χρειάζεται να γίνονται root. Στο παραπάνω στιγμιότυπο φαίνονται οι ρυθμίσεις στο δικό μου μηχάνημα, όπου έχει προστεθεί και ο δικός μου χρήστης στο εν λόγω group.

In the name field of the new group "unifi" is placed. The number of the new group does not need to be changed as it is automatically placed by the system. In your system it may be different as it is in the snapshot. From the list at the right of the window the users that will have the access rights to change the guest portal files are selected. After that they will not have to be root to do all the job. In the above snapshot there are the settings made in my system, were only my user is added in this group.

Φυσικά, με το πάτημα του πλήκτρου "ΟΚ" εμφανίζεται και πάλι η αρχική εικόνα. Εκεί πρέπει να φαίνεται και η καινούργια ομάδα που μόλις δημιουργήθηκε. Πατώντας και πάλι το "ΟΚ" εφαρμόζονται οι καινούργιες ρυθμίσεις.

After pressing "ΟΚ" you return to the previous screen. The new group just created is there. By pressing "ΟΚ" again the new settings are applied to the system.

Το τελευταίο βήμα είναι να ανήκει ο κατάλογος που μπαίνουν τα δεδομένα στο καινούργιο group. Παράλληλα πρέπει το σύστημα, όταν δημιουργείται ένα καινούργιο αρχείο, να το κάνει να ανήκει και αυτό στο group unifi, αυτόματα. Αυτό χρειάζεται για να μπορεί να το διαβάζει και ο server του UniFi Controller Software. Δυστυχώς, εδώ δε μπορούμε να αποφύγουμε την κονσόλα, αλλά γίνεται με απλές εντολές.

The last step is to make the directory, with the data we need to be able to alter, a part of the new group. At the same time the newly created files must be automatically belong to the same group. This must be done for the UniFi Controller server to be able to read it. Unfortunately this cannot be done without the help of the console, but the commands are simple.

Ανοίγουμε μια κονσόλα και μπαίνουμε ως root εκτελώντας την εντολή su. Μετά την εισαγωγή του password του υπερχρήστη εκτελούνται οι εντολές που φαίνονται εδώ:

Open a console and become root by executing su. After entering the superuser's password enter the following commands:

eliaschr@orion:~> su
Password: 
orion:/home/eliaschr # cd /opt/UniFi/
orion:/opt/UniFi # mkdir data
orion:/opt/UniFi # chgrp unifi data
orion:/opt/UniFi # chmod g+w data
orion:/opt/UniFi # chmod g+s data

Αυτό που κάνουν οι εντολές είναι να δημιουργήσουν ένα κατάλογο με το όνομα data (εντολή mkdir), να κάνουν τον κατάλογο αυτό να ανήκει στο group unifi που δημιουργήθηκε πριν (εντολή chgrp), να δοθούν δικαιώματα ανάγνωσης κι εγγραφής στο group (πρώτη εντολή chmod) κι επιπλέον, ό,τι αρχείο ή κατάλογος δημιουργείται εκεί μέσα να ανήκει στο group που ανήκει και ο κατάλογος, δηλαδή το unifi (η τελευταία εντολή chmod). Η επόμενη εντολή, χρησιμοποιεί ένα σύστημα που ονομάζεται File Access Control List που προσθέτει επιπλέον δικαιώματα. Αυτό που μας ενδιαφέρει είναι τα αρχεία που δημιουργούνται να έχουν διακαιώματα read/write για τον χρήστη και το group, ενώ για τους υπόλοιπους να έχουν μόνο διακαιώματα διαβάσματος:

What these commands do, is to create a directory with the name data (mkdir command), make this directory belong to unifi group created earlier (chgrp command), give read and write access rights to that group (first chmod command) and whatever whatever file or directory is created in there is made automatically to belong to the group of its parent, meaning unifi (The last chmod command). The next command that shall be presented, uses an extended system that is called File Access Control List that extends the access rights of the files. What we need here, is the files that created to have read/write access for both the user and the group, but only read access rights for the rest of the users:

orion:/opt/UniFi # setfacl -d -m u::rwX,g::rwX,o::r data

Τέλος, για να είναι ολοκληρωμένη η εγκατάσταση του συστήματος, θα πρέπει να δημιουργήσουμε ένα link προς το εκτελέσιμο της βάσης δεδομένων. Το link βρίσκεται ήδη στον κατάλογο /opt/UniFi/bin/ κι έχει το όνομα mongod. Δυστυχώς δείχνει σε λάθος τοποθεσία, οπότε πρέπει να το διορθώσουμε:

Last but not least, for the installation to be complete we must create a link to the executable of the database. There is already a link in /opt/UniFi/bin/ directory named mongod. Unfortunately it points to a wrong place, so we must correct it:

orion:/opt/UniFi # cd bin
orion:/opt/UniFi/bin # rm mongod
orion:/opt/UniFi/bin # ln -s /usr/sbin/mongod mongod

Τώρα το εν λόγω link δείχνει στο σωστό σημείο.

Now the link in question points to the correct file.

Μέχρι εδώ έχουμε κάνει μισή δουλειά... Βασικά μας δίνεται η δυνατότητα να μπορούμε να αλλάζουμε τα δεδομένα των αρχείων που θα δημιουργεί ο server μέσα στον κατάλογο data και τους υποκαταλόγους του, ως απλοί χρήστες. Η διαφορά είναι πως αν δημιουργήσουμε κάτι δικό μας, τότε για να το διαβάσει σωστά ο server θα πρέπει να του αλλάξουμε τα δικαιώματα, αλλά αυτό πλέον μπορεί να γίνεται εύκολα από το γραφικό περιβάλλον, χωρίς τη χρήση της κονσόλας...

Well, up to now we have done half of the job... Actually, we have the access to alter files that the server creates in data directory and its siblings as simple users (without being root). The difference is that when we create something of our own, for the server to be able to read and manipulate it correctly we will have to change its access rights by hand; but this is not that simple through the graphical environment without the terminal usage...

Έλεγχος του UniFi Controller Software

UniFi Controller Software Test

Σε αυτό το σημείο είμαστε έτοιμοι να δούμε αν το πρόγραμμα που μόλις εγκαταστήσαμε τρέχει σωστά. Το πρόγραμμα είναι γραμμένο σε Java άρα για να τρέξει αρκεί να μπούμε σε μια κονσόλα, ως υπερχρήστες και να εκτελέσουμε την εντολή:

At that point we are ready to test if the program we've just installed is functional. The program is written in Java so to execute it we need to enter a console and, as superusers run the command:

orion:/whateverpath # java -jar /opt/UniFi/lib/ace.jar start &

Με την εκτέλεση της εντολής αυτής θα παρατηρήσουμε ότι ο επεξεργαστής αρχίζει και λειτουργεί αρκετά. Μετά από μερικά δευτερόλεπτα, αν δεν έχει εμφανιστεί κανένα μήνυμα λάθους, ο server του UniFi θα έχει ξεκινήσει και ο επεξεργαστής θα έχει πέσει πάλι για ύπνο! Για να τον ελέγξουμε ότι λειτουργεί σωστά αρκεί σε ένα browser να δωθεί η διεύθυνση http://localhost:8080/

By executing this command we observe the processor working hard for a while. After some seconds, if there is no error message, UniFi server must be up and running and the processor must have fallen to sleep, again! To test that the server is well functioning the address http://localhost:8080/ must be entered in a browser.

Το πρώτο πράγμα που θα εμφανιστεί είναι το προειδοποιητικό μήνυμα για το άγνωστο ssl certificate. Φυσικά και θα πρέπει να γίνει αποδεχτή του και ο browser θα συνεχίσει στην τελική σελίδα που φαίνεται στο στιγμιότυπο:

The first thing appears on screen is a warning message for an unknown ssl certificate. Of course we must accept it and the browser will continue to the following snapshot:

Το configuration του συστήματος συνεχίζει με το πάτημα του "Next" κ.λ.π. Στο τέλος θα εμφανιστεί το τελικό login screen.

The system configuration goes on by pressing the "Next" button etc. In the end there will be the login screen.

Τώρα ο server έχει δημιουργήσει κάποια αρχεία ρυθμίσεων. Μπορούμε να τα δούμε στον κατάλογο /opt/UniFi/data παρατηρώντας ότι όλα τα αρχεία ανήκουν όντως στην ομάδα unifi όπως ακριβώς ήταν επιθυμητό:

The server has now created some settings files. We can find then in the /opt/UniFi/data directory, noticing that these files really belong to unifi group as we needed:

eliaschr@orion:/whateverpath # ls -l /opt/UniFi/data/
total 16
drwxrwsr--+ 2 root unifi 4096 May 10 22:29 backup
drwxrwsr--+ 4 root unifi 4096 May 10 22:30 db
-rw-rw-r--  1 root unifi 2184 May 10 22:29 keystore
-rw-rw-r--  1 root unifi  620 May 10 22:51 system.properties

Αν δεν έχετε ακόμα ενεργοποιημένο κάποιο UniFi Access Point στο δίκτυο δε θα καταλάβετε ένα "πρόβλημα" που υπάρχει. Αν όμως έχετε κάποιο Access Point στο δίκτυο, τότε ας δούμε και πάλι το μήνυμα που υπήρξε στο δεύτερο βήμα της παραμετροποίησης:

If you have not connected any UniFi Access Point in the network, yet, you will not have noticed a "problem". But if you have then, lets see the message we saw at the second step of the configuration wizard, again:

Το σύστημα μας λέει πολύ απλά ότι δεν βρίσκει κανένα Access Point...

Well, no devices have been discovered, says the system...

Κάποιος μπλοκάρει την επικοινωνία... (Firewall)

Someone Blocks The Communication... (Firewall)

Ο λόγος που δε μπορούμε να δούμε κανένα από τα Access Points που έχουμε συνδεδεμένα στο δίκτυό μας είναι ότι το Firewall του openSUSE μπλοκάρει την επικοινωνία. Αν γνωρίζουμε λίγα πράγματα από το firewall, τότε μπορούμε να ενεργοποιήσουμε το logging και να δούμε τι προσπαθεί να κάνει ο UniFi Controller το οποίο σταματάει εξ αιτίας του firewall. Θα δούμε μια επικοινωνία broadcast στην πόρτα 10001. Αν επιθυμούμε να έχουμε πρόσβαση στο πρόγραμμα και από άλλο υπολογιστή τότε χρειαζόμαστε και τις πόρτες 8080 και 8443. Αν χρειάζεστε και το shutdown θα πρέπει να ανοιχτεί και η πόρτα 8081. Αυτές είναι οι πόρτες που πρέπει να ανοίξουμε στο τείχος προστασίας για να μπορέσει να λειτουργήσει το σύστημα σωστά.

The reason we cannot see any of our Access Points through the UniFi Controller is the openSUSE Firewall, blocking the communication. If we are familiar with this firewall, then we can enable its logging and find out what UniFi Controller tries to do that is blocked by openSUSE Firewall. Then, we will notice a broadcast packet using port 10001. If we wish access to the program by another computer, also, we also need access to ports 8080 and 8443. If we also need shutdown access to the Access Point another port must be included in the list; port 8081. These ate the ports we have to unblock in the firewall settings in order for the system to function properly.

Επειδή μπορεί να θέλετε να αλλάξετε τις πόρτες που χρησιμοποιεί το σύστημα, τότε για να δείτε το πλήρες σετ που χρησιμοποιούνται από τις ρυθμίσεις, αρκεί να ανοίξετε το αρχείο data/system.properties. Απλά, στις πόρτες που θα ρυθμίσετε το firewall θα πρέπει να θυμηθείτε και την πόρτα 10001.

Because you may need to change the ports that the UniFi system uses, to find out the complete set (and alter them) you can open the data/system.properties file. Don't forget that together with these ports you also have to unblock 10001 in the firewall settings.

portal.http.port=8880
portal.https.port=8843
unifi.db.port=27117
unifi.http.port=8080
unifi.https.port=8443
unifi.shutdown.port=8081

Ας δούμε πως θα ανοίξουμε τις πόρτες που θέλουμε στο τείχος προστασίας. Αρχικά ανοίγουμε το YaST (αν δεν το έχουμε ήδη ανοικτό) και από την αριστερή στήλη επιλέγουμε την ομάδα "Security and Users", ενώ από τη δεξιά πλευρά ανοίγουμε το "Firewall"

Lets see how we can open the necessary ports. First, we open YaST (if we don't have it already), from its left side we choose "Security and Users", and from its right side we select "Firewall"

Στο παράθυρο που θα ανοίξει έχουμε και πάλι κατηγορίες ρυθμίσεων από την αριστερή μεριά και η δεξιά αλλάζει ανάλογα με την κατηγορία που θα επιλέξουμε. Η κατηγορία που ας ενδιαφέρει είναι η "Allowed Services"

In the window that appears there are some settings categories at its left side, while the right one changes according to the selected category. The needed one is "Allowed Services"

Επειδή οι πόρτες που θα ανοίξουμε στο τείχος προστασίας δεν ανήκουν σε κάποια γνωστή υπηρεσία θα πρέπει να τις ορίσουμε χειροκίνητα. Για να γίνει αυτό πατάμε το κάτω δεξιά πλήκτρο που ονομάζεται "Advanced...". Θα ανοίξει ένα καινούργιο παράθυρο στο οποίο θα βάλουμε τα νούμερα από τις πόρτες που μας ενδιαφέρουν. Η ρύθμιση φαίνεται στο ακόλουθο στιγμιότυπο:

Since the ports we want to open do not belong to a known service, we have to specify them by hand. To do that we just use the "Advanced..." button, at the down right side of the window. Another window appears in which we specify the number of the ports we want unblocked. They appear in the following snapshot:

Αν υπάρχουν και άλλες πόρτες ρυθμισμένες, απλά προσθέτετε αυτές που φαίνονται στο στιγμιότυπο και δεν σβήνετε τις παλιές. Πατώντας το "ΟΚ" επανερχόμαστε στην προηγούμενη οθόνη.

If there are also other ports set before, then just add the shown ones in the list, without removing the older. By pressing "ΟΚ" the system transfers us to the previous screen.

Αν ρυθμίζετε για πρώτη φορά το τείχος προστασίας, τότε πολύ πιθανό να χρειαστεί να ορίσετε και τη ζώνη προστασίας για την κάρτα δικτύου σας. Για να γίνει αυτό από την αριστερή μεριά του παραθύρου επιλέξτε την κατηγορία "Interfaces". Στη δεξιά μεριά εμφανίζονται όλες οι διαθέσιμες κάρτες δικτύου.

If this is the first time you edit the firewall settings then chances are you'll have to also set the interface zone for your network card. You can do that by selecting the "Interfaces" category to the left side of the window. Then, at the right one appear all the existed network cards.

Κάνοντας διπλό κλικ στην κάρτα δικτύου που μας ενδιαφέρει εμφανίζεται ένα παράθυρο για τον ορισμό ζώνης. Εκεί ορίσουμε τη ζώνη που μας ενδιαφέρει και πατάμε το "ΟΚ" επανερχόμενοι στο αρχικό παράθυρο.

By double clicking on the network interface we want to setup another dialogue box appears for its zone setting. Choose the zone you are interested in and press "ΟΚ", returning again to the previous screen.

Τελειώνουμε τις ρυθμίσεις του firewall πατώντας "Next" και στη συνέχεια "Finish". Μόλις τελειώσει το σύστημα την εφαρμογή των ρυθμίσεων, το τείχος προστασίας πλέον θα αφήνει την επικοινωνία να γίνει κανονικά.

We end the firewall settings by pressing "Next", followed by "Finish". After tyhe system finishes the application of the new settings, the firewall will be open for the communication of UniFi to the Access Point.

Χρήση του UniFi Controller ως service

Usage Of UniFi Controller As A Service

Το τελευταίο στάδιο είναι να οριστεί το UniFi Controller ως service, δηλαδή να ανοίγει και να κλείνει ανάλογα με το runlevel του υπολογιστή, χωρίς να χρειάζεται την επέμβαση του χρήστη.

The last step is to make UniFi Controller to run as service, meaning to start and stop according to which runlevel our computer uses, without the need of user intervention.

Για να γίνει αυτό θα πρέπει να δημιουργηθεί ένα script που να μπει μέσα στον κατάλογο /etc/init.d/. Αυτό το script θα πρέπει να έχει την ιδιότητα να ξεκινάει και να σταματάει τον server του UniFi, όπως ακριβώς γίνεται και στα υπόλοιπα services του συστήματος. Η βασική βοήθεια για τη συγγραφή αυτού του script είναι το /etc/init.d/skeleton. Με λίγο editing αυτού μπορούμε να φτιάξουμε το ακόλουθο:

For this to happen there must be a script in /etc/init.d/ directory, with the functionality of starting and stopping the UniFi server, in the same way as all the other services of the system do. /etc/init.d/skeleton is what will help up create the script in question. A little bit of editing and we create the following:

#!/bin/sh
#
#     Template SUSE system startup script for service unifid
#     Copyright (C) 1995--2005  Kurt Garloff, SUSE / Novell Inc.
#          
#     This library is free software; you can redistribute it and/or modify it
#     under the terms of the GNU Lesser General Public License as published by
#     the Free Software Foundation; either version 2.1 of the License, or (at
#     your option) any later version.
#
#     This library is distributed in the hope that it will be useful, but
#     WITHOUT ANY WARRANTY; without even the implied warranty of
#     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#     Lesser General Public License for more details.
# 
#     You should have received a copy of the GNU Lesser General Public
#     License along with this library; if not, write to the Free Software
#     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA     
#
# /etc/init.d/unifid
#   and its symbolic link
# /usr/sbin/rcunifid
#
# System startup script for the UniFi Controller Server software of Ubiquity. See
# http://www.ubnt.com/
#
# LSB compatible service control script; see http://www.linuxbase.org/spec/
# 
# Note: This script uses functions rc_XXX defined in /etc/rc.status on
# UnitedLinux/SUSE/Novell based Linux distributions and is based on /etc/init.d/skeleton
# script provided by the openSUSE Community.
#
### BEGIN INIT INFO
# Provides:          unifid
# Required-Start:    $syslog $local_fs $network
# Should-Start:      $time ypbind smtp
# Required-Stop:     $syslog $local_fs $network
# Should-Stop:       ypbind smtp
# Default-Start:     3 5
# Default-Stop:      0 1 2 6
# Short-Description: unifid daemon providing Controller server for UniFi Access Points
# Description:       Start unifid to allow the UniFi Controller Software to be able to
#       control the UniFi Access Points of Ubiquity in the network. The softare runs in Java
#       and is installed in /opt/ directory.
### END INIT INFO
# 
# Any extensions to the keywords given above should be preceeded by 
# X-VendorTag- (X-UnitedLinux- X-SuSE- for us) according to LSB.
# 
# Notes on Required-Start/Should-Start:
# * There are two different issues that are solved by Required-Start
#    and Should-Start
# (a) Hard dependencies: This is used by the runlevel editor to determine
#     which services absolutely need to be started to make the start of
#     this service make sense. Example: nfsserver should have
#     Required-Start: $portmap
#     Also, required services are started before the dependent ones.
#     The runlevel editor will warn about such missing hard dependencies
#     and suggest enabling. During system startup, you may expect an error,
#     if the dependency is not fulfilled.
# (b) Specifying the init script ordering, not real (hard) dependencies.
#     This is needed by insserv to determine which service should be
#     started first (and at a later stage what services can be started
#     in parallel). The tag Should-Start: is used for this.
#     It tells, that if a service is available, it should be started
#     before. If not, never mind.
# * When specifying hard dependencies or ordering requirements, you can 
#   use names of services (contents of their Provides: section)
#   or pseudo names starting with a $. The following ones are available
#   according to LSB (1.1):
#       $local_fs               all local file systems are mounted
#                               (most services should need this!)
#       $remote_fs              all remote file systems are mounted
#                               (note that /usr may be remote, so
#                                many services should Require this!)
#       $syslog                 system logging facility up
#       $network                low level networking (eth card, ...)
#       $named                  hostname resolution available
#       $netdaemons             all network daemons are running
#   The $netdaemons pseudo service has been removed in LSB 1.2.
#   For now, we still offer it for backward compatibility.
#   These are new (LSB 1.2):
#       $time                   the system time has been set correctly
#       $portmap                SunRPC portmapping service available
#   UnitedLinux extensions:
#       $ALL                    indicates that a script should be inserted
#                               at the end
# * The services specified in the stop tags 
#   (Required-Stop/Should-Stop)
#   specify which services need to be still running when this service
#   is shut down. Often the entries there are just copies or a subset 
#   from the respective start tag.
# * Should-Start/Stop are now part of LSB as of 2.0,
#   formerly SUSE/Unitedlinux used X-UnitedLinux-Should-Start/-Stop.
#   insserv does support both variants.
# * X-UnitedLinux-Default-Enabled: yes/no is used at installation time
#   (%fillup_and_insserv macro in %post of many RPMs) to specify whether
#   a startup script should default to be enabled after installation.
#   It's not used by insserv.
#
# Note on runlevels:
# 0 - halt/poweroff                     6 - reboot
# 1 - single user                       2 - multiuser without network exported
# 3 - multiuser w/ network (text mode)  5 - multiuser w/ network and X11 (xdm)
# 
# Note on script names:
# http://www.linuxbase.org/spec/refspecs/LSB_1.3.0/gLSB/gLSB/scrptnames.html
# A registry has been set up to manage the init script namespace.
# http://www.lanana.org/
# Please use the names already registered or register one or use a
# vendor prefix.

# First define a small helper function that converts the number of lines produced by ps
# shell command to a number of LSB status. Needed by the "status" parameter
function ConvertOut() {
        if (( $1 < 2 ))
        then
                CNVOUT=3
        else
                CNVOUT=0
        fi
        return $CNVOUT
}

# Check for missing binaries (stale symlinks should not happen)
# Note: Special treatment of stop for LSB conformance
# java executable must be installed...
JAVA_BIN=/usr/bin/java
test -x $JAVA_BIN || { echo "Cannot find java executable in $JAVA_BIN, or java is not installed..."; 
        if [ "$1" = "stop" ]; then exit 0;
        else exit 5; fi; }
# Also, mongoDB must be installed. The extra step here is that there must be a valid link in
# /opt/UniFi/bin/mongod that points to the mongod executable
MONGOD_BIN=/opt/UniFi/bin/mongod
if [ ! \( -e $MONGOD_BIN \) ]
then
        echo "Cannot find mongod executable in $MONGOD_BIN, or mongoDB is not installed..."; 
        if [ "$1" = "stop" ]; then exit 0;
        else exit 5; fi;
fi
# Last but not least, the java jar file should be present. No need to be executable, because
# it is executed via java -jar ...
UNIFID_BIN=/opt/UniFi/lib/ace.jar
test -e $UNIFID_BIN || { echo "Cannot find UniFi Controller executable in $UNIFID_BIN, or the controller software is not installed..."; 
        if [ "$1" = "stop" ]; then exit 0;
        else exit 5; fi; }
# Source LSB init functions
# providing start_daemon, killproc, pidofproc, 
# log_success_msg, log_failure_msg and log_warning_msg.
# This is currently not used by UnitedLinux based distributions and
# not needed for init scripts for UnitedLinux only. If it is used,
# the functions from rc.status should not be sourced or used.
#. /lib/lsb/init-functions

# Shell functions sourced from /etc/rc.status:
#      rc_check         check and set local and overall rc status
#      rc_status        check and set local and overall rc status
#      rc_status -v     be verbose in local rc status and clear it afterwards
#      rc_status -v -r  ditto and clear both the local and overall rc status
#      rc_status -s     display "skipped" and exit with status 3
#      rc_status -u     display "unused" and exit with status 3
#      rc_failed        set local and overall rc status to failed
#      rc_failed   set local and overall rc status to 
#      rc_reset         clear both the local and overall rc status
#      rc_exit          exit appropriate to overall rc status
#      rc_active        checks whether a service is activated by symlinks
. /etc/rc.status

# Reset status of this service
rc_reset

# Return values acc. to LSB for all commands but status:
# 0       - success
# 1       - generic or unspecified error
# 2       - invalid or excess argument(s)
# 3       - unimplemented feature (e.g. "reload")
# 4       - user had insufficient privileges
# 5       - program is not installed
# 6       - program is not configured
# 7       - program is not running
# 8--199  - reserved (8--99 LSB, 100--149 distrib, 150--199 appl)
# 
# Note that starting an already running service, stopping
# or restarting a not-running service as well as the restart
# with force-reload (in case signaling is not supported) are
# considered a success.

case "$1" in
    start)
        echo -n "Starting unifid "
        ## Start daemon with startproc(8). If this fails
        ## the return value is set appropriately by startproc.
        /sbin/startproc $JAVA_BIN  -jar $UNIFID_BIN start

        # Remember status and be verbose
        rc_status -v
        ;;
    stop)
        echo -n "Shutting down unifid "
        ## Stop daemon with killproc(8) and if this fails
        ## killproc sets the return value according to LSB.

        #/sbin/killproc $FOO_BIN
        $JAVA_BIN -jar $UNIFID_BIN stop

        # Remember status and be verbose
        rc_status -v
        ;;
    try-restart|condrestart)
        ## Do a restart only if the service was active before.
        ## Note: try-restart is now part of LSB (as of 1.9).
        ## RH has a similar command named condrestart.
        if test "$1" = "condrestart"; then
                echo "${attn} Use try-restart ${done}(LSB)${attn} rather than condrestart ${warn}(RH)${norm}"
        fi
        $0 status
        if test $? = 0; then
                $0 restart
        else
                rc_reset        # Not running is not a failure.
        fi
        # Remember status and be quiet
        rc_status
        ;;
    restart)
        ## Stop the service and regardless of whether it was
        ## running or not, start it again.
        $0 stop
        $0 start

        # Remember status and be quiet
        rc_status
        ;;
    force-reload)
        ## Signal the daemon to reload its config. Most daemons
        ## do this on signal 1 (SIGHUP).
        ## If it does not support it, restart the service if it
        ## is running.

        echo -n "Reload service unifid "
        ## if it supports it:
        #/sbin/killproc -HUP $FOO_BIN
        #touch /var/run/FOO.pid
        #rc_status -v

        ## Otherwise:
        $0 try-restart
        rc_status
        ;;
    reload)
        ## Like force-reload, but if daemon does not support
        ## signaling, do nothing (!)

        # If it supports signaling:
        echo -n "Reload service unifid "
        #/sbin/killproc -HUP $FOO_BIN
        #touch /var/run/FOO.pid
        #rc_status -v

        ## Otherwise if it does not support reload:
        $0 try-restart
        rc_status
        #rc_failed 3
        #rc_status -v
        ;;
    status)
        echo -n "Checking for service unifid "
        ## Check status with checkproc(8), if process is running
        ## checkproc will return with exit status 0.

        # Return value is slightly different for the status command:
        # 0 - service up and running
        # 1 - service dead, but /var/run/  pid  file exists
        # 2 - service dead, but /var/lock/ lock file exists
        # 3 - service not running (unused)
        # 4 - service status unknown :-(
        # 5--199 reserved (5--99 LSB, 100--149 distro, 150--199 appl.)

        # NOTE: checkproc returns LSB compliant status values.
        # /sbin/checkproc $FOO_BIN
        # NOTE: rc_status knows that we called this init script with
        # "status" option and adapts its messages accordingly.
        # The only way to test if the java program runs is to check it through ps:
        JAVA_COUNT=$(ps aux |grep $UNIFID_BIN | wc -l)
        # The ps aux shell command if used with the grep shell command, returns one line for grep
        # and another line for the real $UNIFID_BIN file. So the result of the executed command is
        # 1 if the server is stopped, 2 if the server is started. We need to convert these values
        # into valid LSB compliant ones, meaning 3 and 0 respectively. The easiest way to do this
        # is to use a function that returns the correct status
        ConvertOut $JAVA_COUNT
        rc_status -v
        ;;
    #probe)
        ## Optional: Probe for the necessity of a reload, print out the
        ## argument to this init script which is required for a reload.
        ## Note: probe is not (yet) part of LSB (as of 1.9)

        #test /etc/FOO/FOO.conf -nt /var/run/FOO.pid && echo reload
        #;;
    *)
        echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload}"
        exit 1
        ;;
esac
rc_exit

Αυτό το script μπορείτε να το κάνετε copy/paste από εδώ και να το σώσετε μέσα στον κατάλογο του χρήστη με την ονομασία unifid. Οι ακόλουθες εντολές πρέπει να εκτελεστούν σε μια κονσόλα από τον υπερχρήστη για να δημιουργηθεί όλη η υποδομή του service:

You can copy/paste the script from here and save it with name unifid in the user's home directory (or werever you wish). The following commands must be executed in a console with superuser priviledges, for the service infrastructure to be created:

orion:/home/eliaschr # cp unifid /etc/init.d/
orion:/home/eliaschr # chmod 0755 /etc/init.d/unifid
orion:/home/eliaschr # ln -s /etc/init.d/unifid /sbin/rcunifid
orion:/home/eliaschr # ln -s /etc/init.d/unifid /usr/sbin/rcunifid

Τώρα θα τεστάρουμε το script και όσα έγιναν για τη χρήση του UniFi ως service. Για να γίνει αυτό θα πρέπει μέσα από το YaST να δούμε τα διαθέσιμα services και να προσπαθήσουμε να ανοίξουμε και να κλείσουμε αυτό που μας ενδιαφέρει, το unifid. Αφού ανοίξουμε το YaST (αν δεν το έχουμε ακόμα ανοικτό) και δώσουμε το password του root θα πρέπει να κάνουμε τα ακόλουθα:

We can test this script and everything done to make UniFi run as service by using YaST. Through it we will see all the available services and we will try to start and stop the one we created, unifid. After running YaST (again, if it is not still running) and enter the root password we must do the following:

Ανοίγουμε το "System Services (Runlevel)" από την ομάδα επιλογών "System".

Select the "System Services (Runlevel)" from the "System" group.

Στο παράθυρο που ανοίγει θα πρέπει να περιμένουμε λίγο για να αναγνωρίσει το σύστημα όλα τα services που υπάρχουν και να τα ρωτήσει αν είναι ενεργοποιημένα ή όχι. Μετά από λίγο που θα ολοκληρωθεί η λίστα, μπορούμε να βρούμε το service που μόλις δημιουργήσαμε, με την ονομασία unifid.

In the window that opens we have to wait some seconds for the system to finish service scanning and find out wether they are running or not. In a while, the list will be complete and there we can search for the service we created with the name unifid.

Ακόμα πιο ενδιαφέρον είναι αν γυρίσουμε σε Expert Mode, με επιλογή του από το επάνω μέρος της οθόνης. Τότε το παράθυρο μετασχηματίζεται, δίνοντας ακόμα περισσότερες πληροφορίες κι επιλογές:

It becomes more interesting if we select the Expert Mode at the top of the window. The window changes, giving more information and options:

Μπορούμε να δοκιμάσουμε την ενεργοποίηση και απενεργοποίηση του service από το κουμπί "Start/Stop/Refresh". Μπορούμε να δούμε την κατάσταση του service αν από το πλήκτρο αυτό επιλέξουμε το "Refresh status...". Αρχικά είναι απενεργοποιημένο. Το αναδυόμενο παράθυρο μας ενημερώνει για αυτή την κατάσταση.

We can test the activation and deactivation by using the "Start/Stop/Refresh" button. We can also observe the status of the service if, from the same button, in its dropdown list we select "Refresh status..." option. In the beginning it is stopped. The pop-up window informs us for this.

Αν δοκιμάσουμε να ενεργοποιήσουμε το unifid από το πλήκτρο με την επιλογή "Start...". Θα ενημερωθούμε ανάλογα:

Lets try to activate unifid from the button in question, by choosing "Start...". We will be informed:

Φυσικά το αποτέλεσμα θα το δούμε και στη λίστα του κεντρικού παραθύρου. Μπορούμε να ξαναδοκιμάσουμε την κατάσταση που επιστρέφει το script όταν το service είναι ενεργοποιημένο, ξανά με την επιλογή "Refresh status...".

Of course, we will also notice the result in the list of the main window. We can try again to see what is the status that the script returns, now that the service is up and running, again using the "Refresh status..." option.

Ας το απενεργοποιήσουμε πάλι να δούμε την αντίδραση του συστήματος. Επιλέγουμε το "Stop...". Το παράθυρο που θα μας εμφανιστεί είναι το ακόλουθο:

OK. Now, lets deactivate the service again to see the system's reaction. Choose "Stop...". The following window must appear:

Φυσικά, κάθε φορά που κάνουμε start το service ο επεξεργαστής εργάζεται αρκετά για ένα χρονικό διάστημα. Όταν τελειώσει, ο server μας είναι ενεργοποιημένος.

Naturally, each time we start the service, the processor starts working hard for a small period of time. When it finishes then our server is up.

Τέλος, όταν ενεργοποιήσουμε την υπηρεσία στο σύστημα από το κάτω δεξιά κουμπί "Set/Reset", θα δούμε ότι το service θα ενεργοποιηθεί στα runlevels 3 και 5, όπως ακριβώς τα ρυθμίσαμε στο script που γράψαμε.

Finaly, after we activate permanently the service using the "Set/Reset" button that lies at the bottom right of the window, we can see that the service is marked for starting at runlevels 3 and 5. This is described in the script we created earlier.

Όταν το ρυθμίσετε όπως θέλετε μπορείτε να αποθηκεύσετε τις ρυθμίσεις πατώντας το πλήκτρο "ΟΚ".

After you choose the settings at your will, you can store them by pressing "ΟΚ".

Από τώρα και στο εξής δεν είναι ανάγκη να ανοίγετε την κονσόλα για να ξεκινάτε το UniFi Controller Software. Εκτός του ότι μπορείτε να το έχετε να ανοίγει με τον υπολογιστή σας, μπορείτε να το ενεργοποιείτε ή απενεργοποιείτε από το YaST.

From now on, there is no need to open a terminal and start UniFi Controller Software by hand. And besides having it starting automatically while your operating system boots, you can activate and deactivate it at will through YaST.

Όταν το unifid είναι ενεργοποιημένο τότε μπορείτε να κάνετε login σε αυτό από τον browser σας, στη διεύθυνση http://localhost:8080

When unifid is activated, you can login to it through your browser, at the address http://localhost:8080

Συμπεράσματα

Conclusions

Παρότι το πρόγραμμα της εταιρίας Ubiquity έχει γραφτεί σε java και στην αρχή υπήρχαν αμφοβολίες πως θα μπορούσε να λειτουργήσει σωστά ως service, τελικά με λίγο κόπο ακόμα κι αυτό μπόρεσε να λειτουργήσει. Τώρα το σύστημα του ασύρματου δικτύου, μπορεί να παραμετροποιηθεί για τις ανάγκες ενός ξενοδοχείου, ενώ θα μπορούσε να λειτουργήσει ακόμα και σε ένα σύστημα small computer όπως π.χ. το Raspberry Pi, το Cubieboard, το Beagleboard ή ότι άλλο έχετε υπόψη σας :)

Even though Ubiquity's program is written in Java language and in the beginning there was doubt that it could work as a system service, finaly, with a small effort we managed to make it work. No the UniFi Wireless System can be used for covering the needs of a hotel, and it may even run in a small computer system as ie. a Raspberry Pi, Cubieboard, Beagleboard or anyother alike you have in your mind :)

Γενικά το UniFi είναι πολύ ενδιαφέρον και αν και ασχολήθηκα κάμποσο μαζί του ξέρω πολύ καλά πως έχει κρυφά σημεία που δεν τα έχω δει ακόμα!

In general, UniFi is very interesting and, even though I've used it a lot, I know well that there are so many "hidden" things that I haven't seen, yet!

Μια ακόμα επισήμανση που έχω να κάνω είναι πως όλη η διαδικασία ξεκίνησε αρκετό καιρό πριν κι έγινε σε σύστημα openSUSE 12.2

One more note is that all the job is done a while ago and that all the described process is done in openSUSE 12.2

Ηλίας Χρυσοχέρης

Elias Chrysocheris

Δεν υπάρχουν σχόλια:

Δημοσίευση σχολίου