Skip to content

Commit

Permalink
initial progress
Browse files Browse the repository at this point in the history
php server works and ldap server is online with correct schema but not fully working
  • Loading branch information
Leone25 committed Oct 17, 2024
1 parent 6300601 commit 276fdda
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ resources/photos/
resources/pdftemplates/
tests/.phpunit.result.cache
resources/*/output/
dirsrv/
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,23 @@ Connects to an LDAP backend and possibly some day in the future to Keycloak via

## How

### Baremetal

```shell
composer install
# The defaults are good for development, change them for production
cp config/config-example.php config/config.php
php -S localhost:8777 -t public
```

### Docker
*NOT MEANT FOR PRODUCTION*
```shell
# Should have preconfigured connection to ldap and keycloak
cp config/config-example-docker.php config/config.php
docker-compose up
```

### SIR generation

To set up that functionality:
Expand Down
31 changes: 31 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
services:
ldap:
image: crauto/ldap
build:
context: ./
dockerfile: ./docker/ldap/Dockerfile
volumes:
- ./dirsrv:/data
ports:
- "8389:389"
- "8636:636"
app:
image: crauto/app
build:
context: ./
dockerfile: ./docker/app/Dockerfile
cache_from:
- crauto/app
volumes:
# Source directories
- ./public:/var/www/html/public
- ./resources:/var/www/html/resources
- ./src:/var/www/html/src
- ./templates:/var/www/html/templates
- ./tests:/var/www/html/tests
- ./config:/var/www/html/config
ports:
- "8082:80"
depends_on:
- ldap
stop_grace_period: 1s
30 changes: 30 additions & 0 deletions docker/app/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
FROM php:8.2.12-bookworm

RUN mkdir -p /var/www/html
WORKDIR /var/www/html

COPY ./composer.json ./composer.json
COPY ./composer.lock ./composer.lock

RUN apt-get update && apt-get install -y libldap2-dev libldb-dev unzip gettext \
&& ln -s /usr/lib/x86_64-linux-gnu/libldap.so /usr/lib/libldap.so \
&& ln -s /usr/lib/x86_64-linux-gnu/liblber.so /usr/lib/liblber.so
RUN docker-php-ext-install ldap

# install composer
RUN php -r "readfile('http://getcomposer.org/installer');" | php -- --install-dir=/usr/bin/ --filename=composer

# create mount points
RUN mkdir ./public ./resources ./src ./templates ./test ./config

COPY ./config ./config

RUN if [ ! -f config/config.php ]; then \
echo "Error: configuration not found." 1>&2; \
echo "run \"cp config/config-example-docker.php config/config.php\", edit it and restart the container" 1>&2; \
exit 1; \
fi

RUN composer install --no-dev --optimize-autoloader

CMD php -S 0.0.0.0:80 -t public/
4 changes: 4 additions & 0 deletions docker/keycloak/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM quay.io/keycloak/keycloak:25.0.1

ENV KEYCLOAK_ADMIN=admin
ENV KEYCLOAK_ADMIN_PASSWORD=admin
17 changes: 17 additions & 0 deletions docker/ldap/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM 389ds/dirsrv:3.0

ENV DS_DM_PASSWORD=asd
ENV DS_SUFFIX=dc=weeeopen,dc=net
ENV DS_ERRORLOG_LEVEL=16384

# Install git
RUN zypper install -y git

# Download schema files
RUN cd /tmp/ && git clone "https://github.com/WEEE-Open/schema.git"

# Add schema files to the server (ignore errors)
RUN cp /tmp/schema/* /etc/dirsrv/schema/ || :

# Remove schema files
RUN rm -rf /tmp/schema
2 changes: 1 addition & 1 deletion public/people.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
}
http_response_code(303);
// $_SERVER['REQUEST_URI'] is already url encoded
header("Location: ${_SERVER['REQUEST_URI']}");
header("Location: " . _SERVER['REQUEST_URI']);
exit;
}
} catch (LdapException | ValidationException | InvalidArgumentException $e) {
Expand Down
2 changes: 1 addition & 1 deletion src/Ldap.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ public function getUsers(array $attributes): array
]
],
];
$sr = ldap_search($this->ds, $this->usersDn, '(uid=*)', $attributes, null, null, null, null, $serverctrls);
$sr = ldap_search($this->ds, $this->usersDn, '(uid=*)', $attributes, 0, -1, -1, LDAP_DEREF_NEVER, $serverctrls);
} else {
$sr = ldap_search($this->ds, $this->usersDn, '(uid=*)', $attributes);
}
Expand Down

0 comments on commit 276fdda

Please sign in to comment.