Commits

Alexandre Macabies committed 945d312 Merge

Merged prologin/sadm into master

Comments (0)

Files changed (6)

config/udb-server.yml

 db:
     default:
         ENGINE: django.db.backends.sqlite3
-        NAME: udb.db
+        NAME: /var/prologin/udb/udb.db
         USER:
         PASSWORD:
         HOST:
     auth-nxdomain yes;
     datasize default;
 
-    // Swap comments on these two lines to enable DNS recursion for users.
-    allow-recursion { 127.0.0.1; };
-    // allow-recursion { 127.0.0.1; 192.168.0.0/16; };
+    allow-recursion { 127.0.0.1; 192.168.0.0/16; };
 
     allow-transfer { none; };
     allow-update { none; };

docs/source/setup.rst

 Install a few packages we will need::
 
   pacman -S git dhcp bind python python-pip python-virtualenv libyaml nginx \
-            sqlite dnsutils rsync postgresql-libs tcpdump base-devel
+            sqlite dnsutils rsync postgresql-libs tcpdump base-devel pwgen
 
 Create the main Python ``virtualenv`` we'll use for all our Prologin apps::
 
   python3 install.py mdbsync
 
   systemctl enable mdbsync && systemctl start mdbsync
-  systemctl restart nginx
+  systemctl reload nginx
   echo '127.0.0.1 mdbsync' >> /etc/hosts
 
 To check if ``mdbsync`` is working, try to register for updates::
 
   python3 install.py netboot
   systemctl enable netboot && systemctl start netboot
-  systemctl restart nginx
+  systemctl reload nginx
 
 TFTP
 ~~~~
 
 The TFTP server will serve files from ``/srv/tftp``.
 
+iPXE bootrom
+~~~~~~~~~~~~
+
+The iPXE bootrom is an integral part of the boot chain for user machines. It is
+loaded by the machine BIOS via PXE and is responsible for booting the Linux
+kernel using the nearest RFS. It also handles registering the machine in the
+MDB if needed. These instructions need to be run on ``gw``.
+
+iPXE is an external open source project, clone it first::
+
+  git clone git://git.ipxe.org/ipxe.git
+
+Then compile time settings need to be modified. Uncomment the following lines::
+
+  // in src/config/general.h
+  #define REBOOT_CMD
+
+You can now build iPXE: go to ``src/`` and build the bootrom using our script
+provided in ``sadm/netboot``::
+
+  make bin/undionly.kpxe EMBED=/root/sadm/netboot/script.ipxe
+  cp bin/undionly.kpxe /srv/tftp/prologin.kpxe
+
 udb
 ~~~
 
-TODO
+Install ``udb`` using the ``install.py`` recipe::
+
+  python install.py udb
+  systemctl enable udb && systemctl start udb
+  systemctl reload nginx
+
+You can then import all contestants information to ``udb`` using the
+``batchimport`` command::
+
+  cd /var/prologin/udb
+  python manage.py batchimport --file=/root/finalistes.txt
+
+The password sheet data can then be generated with this command, then printed
+by someone else::
+
+  python manage.py pwdsheetdata --type=user > /root/user_pwdsheet_data
+
+Then do the same for organizers::
+
+  python manage.py batchimport --logins --type=orga --pwdlen=10 \
+      --uidbase=11000 --file=/root/orgas.txt
+  python manage.py pwdsheetdata --type=orga > /root/orga_pwdsheet_data
 
 udbsync
 ~~~~~~~
 TODO: How to install new package, sync, hook to generate /var... and more
 documentation to the above commands.
 
-iPXE bootrom
-~~~~~~~~~~~~
-
-The iPXE bootrom is an integral part of the boot chain for user machines. It is
-loaded by the machine BIOS via PXE and is responsible for booting the Linux
-kernel using the nearest RFS. It also handles registering the machine in the
-MDB if needed. These instructions need to be run on ``gw``.
-
-iPXE is an external open source project, clone it first::
-
-  git clone git://git.ipxe.org/ipxe.git
-
-Then compile time settings need to be modified. Uncomment the following lines::
-
-  // in config/general.h
-  #define REBOOT_CMD
-
-You can now build iPXE: go to ``src/`` and build the bootrom using our script
-provided in ``prologin-sadm/netboot``::
-
-  make bin/undionly.kpxe EMBED=/path/to/prologin-sadm/netboot/script.ipxe
-  cp bin/undionly.kpxe /srv/tftp/prologin.kpxe
-
 Copying the kernel and initramfs
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
     install_cfg_profile('mdbsync-pub', group='mdbsync')
     install_cfg_profile('mdbsync-sub', group='mdbsync_public')
     install_cfg_profile('udb-client', group='udb_public')
+    install_cfg_profile('udb-client-auth', group='udb')
     install_cfg_profile('udbsync-pub', group='udbsync')
     install_cfg_profile('udbsync-sub', group='udbsync_public')
     install_cfg_profile('presencesync-pub', group='presencesync')
 
     mkdir('/var/prologin/netboot', mode=0o700, owner='netboot:netboot')
     copy('netboot/netboot.py', '/var/prologin/netboot/netboot.py', mode=0o750,
-         owner='mdbdns:mdbdns')
+         owner='netboot:netboot')
     install_nginx_service('netboot')
     install_systemd_unit('netboot')
+    install_cfg_profile('netboot', group='netboot')
 
 
 def install_udb():

python-lib/prologin/mdb.py

 
         Raise a RegistrationError on failure. Return None if successful.
         """
-        r = requests.get(CFG.get['mdb'] + 'register?' + qs)
+        r = requests.get(self.url + 'register?' + qs)
         if r.status_code != 200:
             raise RegistrationError(r.text)
 

udb/udbapi/management/commands/batchimport.py

     proc = subprocess.Popen(['pwgen', '-cnB', str(length)],
                             stdout=subprocess.PIPE)
     out, err = proc.communicate()
-    return out.strip()
+    return out.strip().decode('utf-8')
 
 
 def create_users(names, options):
     uid = options['uidbase']
     logins = set()  # To check for duplicates
-    for (firstname, lastname) in names:
-        fn, ln = make_ascii(firstname), make_ascii(lastname)
+    for t in names:
+        if options['logins']:
+            login = make_ascii(t)
+            realname = t
+        else:
+            firstname, lastname = t
+            fn, ln = make_ascii(firstname), make_ascii(lastname)
+
+            parts = re.split('[^a-z]', fn)
+            login = ''.join(p.strip()[0] for p in parts if p.strip())
+
+            ln = ''.join(c for c in ln if c in string.ascii_lowercase)
+            ln = ln[:10]
+            login += ln
+
+            base_login = login
+            i = 1
+            while login in logins:
+                login = base_login + str(i)
+                i += 1
+            realname = firstname + ' ' + lastname
 
-        parts = re.split('[^a-z]', fn)
-        login = ''.join(p.strip()[0] for p in parts if p.strip())
-
-        ln = ''.join(c for c in ln if c in string.ascii_lowercase)
-        ln = ln[:10]
-        login += ln
-
-        base_login = login
-        i = 1
-        while login in logins:
-            login = base_login + str(i)
-            i += 1
         logins.add(login)
 
         u = User()
         u.login = login
-        u.realname = firstname + ' ' + lastname
+        u.realname = realname
         u.uid = uid
         u.group = options['type']
         u.password = generate_password(options['pwdlen'])
         make_option('--type', default='user', help='User type (user/orga/root)'),
         make_option('--pwdlen', type='int', default=8, help='Password length'),
         make_option('--uidbase', type='int', default=10000, help='Base UID'),
+        make_option('--logins', action='store_true', default=False, help='File contains logins, not real names')
     )
 
     def handle(self, *args, **options):
         with open(options['file']) as fp:
             lines = [l for l in fp.read().split('\n') if l]
             for l in lines:
-                firstname, lastname = [f.strip() for f in l.split('\t')]
-                names.append((firstname, lastname))
+                if options['logins']:
+                    names.append(l.strip())
+                else:
+                    firstname, lastname = [f.strip() for f in l.split('\t')]
+                    names.append((firstname, lastname))
 
         create_users(names, options)