{"id":23819816,"url":"https://github.com/kth/kursstatistik-api","last_synced_at":"2025-09-07T02:30:50.410Z","repository":{"id":35704038,"uuid":"198176900","full_name":"KTH/kursstatistik-api","owner":"KTH","description":"Håller tjänster för att hämta statistik om en specifik kurs eller kursomgång, exempelvis antal registrerade studenter.","archived":false,"fork":false,"pushed_at":"2024-11-22T14:52:02.000Z","size":4774,"stargazers_count":3,"open_issues_count":4,"forks_count":0,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-11-22T15:38:33.218Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/KTH.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-07-22T08:07:26.000Z","updated_at":"2024-11-22T14:40:48.000Z","dependencies_parsed_at":"2024-01-04T12:26:17.863Z","dependency_job_id":"a20dd6fa-6418-4207-8506-5672fa5b5e4d","html_url":"https://github.com/KTH/kursstatistik-api","commit_stats":null,"previous_names":[],"tags_count":2119,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KTH%2Fkursstatistik-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KTH%2Fkursstatistik-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KTH%2Fkursstatistik-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KTH%2Fkursstatistik-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KTH","download_url":"https://codeload.github.com/KTH/kursstatistik-api/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":232163091,"owners_count":18481581,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-01-02T07:15:50.601Z","updated_at":"2025-09-07T02:30:50.399Z","avatar_url":"https://github.com/KTH.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Welcome to Kursstatistik-api 👋\n\n![Version](https://img.shields.io/badge/version-2.0.0-blue.svg?cacheSeconds=2592000)\n![Prerequisite](https://img.shields.io/badge/node-18-blue.svg)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](#)\n\nMicro service for course statistics from _Ladok Uppföljningsdatabas_ using _[Stunnel](https://www.stunnel.org)_.\n\n## Setup in Azure\n\n### Stunnel\n\n#### Add or Change Certificate from Ladok\n\nSee document _Certifikat för uppföljningsdatabasen i kursstatistik-api_ in Confluence.\n\n## Development Setup on macOS\n\n### Stunnel\n\n#### Add Certificate from Ladok\n\nAfter ordering a certificate from Ladok, you will receive an email with instructions. Follow these instructions and download certficate (PFX file) and password files. The email might also include instructions on how to extract key and client certificate. Below is a modified set of instructions (based in [this post](http://sharepointoscar.com/2017-03-16-extract-key-from-pfx/)). The modification is necessary so that the password to the key can be removed later (this modification might not be necessary with an improved Stunnel configuration.) Extract key and certificate in a suitable folder.\n\nHere we assume that the certificate name we received is `kursstatistik-api@KTH.pfx`.\nIf you get errors when running the below `openssl`-commands, it will probably be fixed by passing the flag `--legacy`\n\n```sh\n# Extract private key from PFX file\n$ openssl pkcs12 -in kursstatistik-api@KTH.pfx -nocerts -out kursstatistik-api@KTH.pem -nodes\n\n# Set secure file permissions on private key file\n$ chmod 400 kursstatistik-api@KTH.pem\n\n# Extract client certificate from PFX file\n$ openssl pkcs12 -in kursstatistik-api@KTH.pfx -out kursstatistik-api@KTH.crt -clcerts -nokeys\n```\n\nAfterwards, make sure to remove anything before the initial `-----BEGIN PRIVATE KEY-----` from the kursstatistik-api@KTH.pem file before running the following commands.\n\n```sh\n# Convert private key to base64 and copy to clipboard\n$ cat kursstatistik-api@KTH.pem | base64 | pbcopy\n\n# Convert client certificate to base64 and copy to clipboard\n$ cat kursstatistik-api@KTH.crt | base64 | pbcopy\n```\n\nSet the resulting strings as `LADOK3_CERT_KEY` and `LADOK3_CERT` respectively\n\nRemove all the certificate and password files from your machine\n\n#### Install Stunnel\n\nThis assumes that you have _Homebrew_ installed. If not, follow the instructions on [brew.sh](https://brew.sh/).\n\n```sh\n$ brew install stunnel\n```\n\n#### Configure Stunnel\n\nAfter ordering a certificate from Ladok, you will also receive an email with instructions on how to configure _Stunnel_. Below is a modified set of instructions and suggested configuration. During the last couple of updates, we have not received an updated certificate chain file.\n\nYou may, or may not, choose to use a _config_ folder. These instructions assume that all files are in `/usr/local/etc/stunnel`, simply called the _stunnel folder_,\n\n1. Save the certificate chain file, e.g. `UF-prod-ca-bundle.txt`, to the stunnel folder.\n2. Move the private key file and the client certificate file to the stunnel folder.\n3. Change the _stunnel config file_, `stunnel.conf` to:\n\n```sh\ndebug = 7\nforeground = yes\n[db2_ufhsk_ENVIRONMENT]\nclient = yes\naccept = localhost:11000\nconnect = [url received in email from ladok]\nkey = kursstatistik-api@KTH.pem\nverify = 2\ncert = kursstatistik-api@KTH.crt\nCAfile = [certificate chain file]\n```\n\n#### Start Stunnel\n\n```sh\n# In /usr/local/etc/stunnel\n$ stunnel\n```\n\n_TODO: Add instructions to run Stunnel in any folder._\n\n#### Troubleshooting\n\nIf localhost port 11000 is already in use:\n\n```sh\n# Find out which service that uses port 11000\n$ lsof -nP -i4TCP:11000 | grep LISTEN\n\n# stunnel 6850 [account name]   12u  IPv4 0x9fb72bfe23991e4b      0t0  TCP 127.0.0.1:11000 (LISTEN)\n\n# Kill process\n$ kill 6850\n```\n\n## Database Connection String Using ibm_db\n\nDatabase connection details will also be included in the emails sent from Ladok. Set the following variables in .env for the database connection string:\n\n```sh\nLADOK3_USERNAME=xxxxx\nLADOK3_PASSWORD=xxxxx\nLADOK3_DATABASE=xxxxx\nSTUNNEL_HOST=localhost\nSTUNNEL_PORT=11000\nSTUNNEL_CONFIGURATION_NAME=db2_ufhsk_ENVIRONMENT\nSTUNNEL_CONFIGURATION_CONNECT_URL=xxxxx\n```\n\nThe connection string looks like this:\n\n```sh\nDATABASE=${process.env.LADOK3_DATABASE};HOSTNAME=${process.env.STUNNEL_HOST};UID=${process.env.LADOK3_USERNAME};PWD=${process.env.LADOK3_PASSWORD};PORT=11000;PROTOCOL=TCPIP\n```\n\n## Test\n\nTest data is available in document _KIP - Testdata - Förstagångsregistrerade och examinationsgrad.xlsx_.\n\n## Developing on a Macbook with M1 or M2 chip\n\nThe `ibm_db` package does not run on newer macs with M1/M2 chipset. If you are using VSCode and want to develop/test locally, you can use the supplied devcontainer-configuration to start the project in a devcontainer.\n\nTip: npm install (sometimes?) does not work in devcontainer because postinstall-script for ibm_db fails. A workaround is to ignore scripts: `npm install --ignore-scripts`\n\n### Docker\n\nIf you want to run the docker image, you have to replace line 1 in the [Dockerfile](./Dockerfile) with the following:\n\n```Docker\n# FROM ubuntu:22.04 # Replace this\nFROM --platform=linux/amd64 ubuntu:22.04 # with this\n```\n\nMake sure that only the line `NODE_ENV: 'development'` is uncommented\nThen run `docker-compose -f docker-compose.yml up`\n\nRunning the Docker we do not have to put any secrets into config/secrets and you do not have to configure stunnel locally.\nMake sure you have all the needed variables in your `.env`-file, then they are read everytime you run `docker-compose up`\n\nThe needed variables seem to be:\n\n```\nLADOK3_CERT\nLADOK3_CERT_KEY\nLADOK3_USERNAME\nLADOK3_PASSWORD\nTUNNEL_CONFIGURATION_NAME\nTUNNEL_CONFIGURATION_CONNECT_URL\nLADOK3_DATABASE\nSTUNNEL_HOST\nSTUNNEL_PORT\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkth%2Fkursstatistik-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkth%2Fkursstatistik-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkth%2Fkursstatistik-api/lists"}