Skip to content

Commit

Permalink
Fix phonebook csv upload (#204)
Browse files Browse the repository at this point in the history
* fix csv upload path

* Add a volume for uploaded phonebook CSV

* fix custom phonebook source delete

* Fix environment variables name

#203
  • Loading branch information
Stell0 authored May 21, 2024
1 parent d0b8ee1 commit eea8569
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 19 deletions.
5 changes: 3 additions & 2 deletions freepbx/Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -534,8 +534,9 @@ RUN a2enmod rewrite proxy*
# Clean apt files
RUN apt-get clean autoclean && apt-get autoremove --yes && rm -rf /var/lib/{apt,dpkg,cache,log}/* && touch /var/lib/dpkg/status

# Install centralized phonebook update script
RUN mkdir -p /usr/share/phonebooks/ && \
# Install centralized phonebook update script and CSV upload path
RUN mkdir -p /usr/share/phonebooks/ /var/lib/nethvoice/phonebook/uploads && \
chown asterisk:asterisk /var/lib/nethvoice/phonebook/uploads && \
curl -L https://github.com/nethesis/nethserver-phonebook-mysql/archive/refs/heads/ns8.tar.gz -o - | tar xzp --strip-component=5 -C /usr/share/phonebooks/ nethserver-phonebook-mysql-ns8/root/usr/share/phonebooks

# Overwrite Debian default vim mouse policy
Expand Down
4 changes: 4 additions & 0 deletions freepbx/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ php /configure_users.php
# Make sure config dir is writable from nethcti and freepbx containers
chown -R asterisk:asterisk /etc/nethcti

# make sure CSV uopload path exists if /var/lib/nethvoice isn't a volume or already initialized
mkdir -p /var/lib/nethvoice/phonebook/uploads
chown -R asterisk:asterisk /var/lib/nethvoice/phonebook/uploads

# Change Apache httpd port
sed -i "s/<VirtualHost \*:80>/<VirtualHost \*:${APACHE_PORT}>/" /etc/apache2/sites-enabled/000-default.conf
sed -i "s/Listen 80/Listen ${APACHE_PORT}/" /etc/apache2/ports.conf
Expand Down
4 changes: 2 additions & 2 deletions freepbx/var/www/html/freepbx/rest/lib/libUsers.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ function getToken() {

function getUser($username) {
# add domain part if needed
if (strpos($username, '@') === false && !empty($ENV['NETHVOICE_LDAP_HOST'])) {
return "$username@{$ENV['NETHVOICE_LDAP_HOST']}";
if (strpos($username, '@') === false && !empty($_ENV['NETHVOICE_LDAP_HOST'])) {
return "$username@{$_ENV['NETHVOICE_LDAP_HOST']}";
}
return $username;
}
Expand Down
4 changes: 2 additions & 2 deletions freepbx/var/www/html/freepbx/rest/modules/configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ function setLegacyMode($value) {
# GET /configuration/networks return green ip address and netmasks
#
$app->get('/configuration/networks', function (Request $request, Response $response, $args) {
if (!empty($ENV['NETHVOICE_HOST_LOCAL_NETWORKS'])) {
if (!empty($_ENV['NETHVOICE_HOST_LOCAL_NETWORKS'])) {
// Here a json object like this is expected [{"network":"192.168.5.0","ip":"192.168.5.14","netmask":"255.255.255.0","gateway":"192.168.5.1"},...]
$networks = json_decode($ENV['NETHVOICE_HOST_LOCAL_NETWORKS']);
$networks = json_decode($_ENV['NETHVOICE_HOST_LOCAL_NETWORKS']);
} else {
$networks = [];
}
Expand Down
20 changes: 8 additions & 12 deletions freepbx/var/www/html/freepbx/rest/modules/phonebook.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,12 @@
$route = $request->getAttribute('route');
$id = $route->getArgument('id');
$file = '/etc/phonebook/sources.d/' . $id . '.json';
$res = delete_import_from_cron($id);
if (!$res) {
throw new Exception("Error deleting $file from crontab!");
}

// Delete from phonebook db contacts imported from this source
$phonebookdb = new PDO(
'mysql:host='.$ENV['PHONEBOOK_DB_HOST'].';port='.$ENV['PHONEBOOK_DB_PORT'].';dbname='.$ENV['PHONEBOOK_DB_NAME'],
$ENV['PHONEBOOK_DB_USER'],
$ENV['PHONEBOOK_DB_PASS']);
'mysql:host='.$_ENV['PHONEBOOK_DB_HOST'].';port='.$_ENV['PHONEBOOK_DB_PORT'].';dbname='.$_ENV['PHONEBOOK_DB_NAME'],
$_ENV['PHONEBOOK_DB_USER'],
$_ENV['PHONEBOOK_DB_PASS']);

$sth = $phonebookdb->prepare('DELETE FROM phonebook WHERE sid_imported = ?');
$sth->execute([$id]);
Expand Down Expand Up @@ -230,7 +226,7 @@

/* Upload a local CSV file source */
$app->post('/phonebook/uploadfile', function (Request $request, Response $response, $args) {
$upload_dest = sprintf('/var/lib/nethserver/nethvoice/phonebook/uploads/%s.csv', uniqid());
$upload_dest = sprintf('/var/lib/nethvoice/phonebook/uploads/%s.csv', uniqid());
try {
$file = array_pop($request->getUploadedFiles());
if ($file->getError() != UPLOAD_ERR_OK) {
Expand All @@ -257,9 +253,9 @@
$configuration = array();
$configuration['ldaps'] = array();
$configuration['ldaps']['enabled'] = true;
$configuration['ldaps']['port'] = $ENV['PHONEBOOK_LDAP_PORT'];
$configuration['ldaps']['user'] = 'cn='.$ENV['PHONEBOOK_LDAP_USER'].',dc=phonebook,dc=nh';
$configuration['ldaps']['password'] = $ENV['PHONEBOOK_LDAP_PASS'];
$configuration['ldaps']['port'] = $_ENV['PHONEBOOK_LDAP_PORT'];
$configuration['ldaps']['user'] = 'cn='.$_ENV['PHONEBOOK_LDAP_USER'].',dc=phonebook,dc=nh';
$configuration['ldaps']['password'] = $_ENV['PHONEBOOK_LDAP_PASS'];
$configuration['ldaps']['tls'] = 'ldaps';
$configuration['ldaps']['base'] = 'dc=phonebook,dc=nh';
$configuration['ldaps']['name_display'] = '%cn %o';
Expand Down Expand Up @@ -309,7 +305,7 @@ function unlink_local_csv($config)
{
if(isset($config['dbtype'], $config['url'])
&& $config['dbtype'] == 'csv'
&& substr($config['url'], 0, 55) == 'file:///var/lib/nethserver/nethvoice/phonebook/uploads/'
&& substr($config['url'], 0, 55) == 'file:///var/lib/nethvoice/phonebook/uploads/'
) {
unlink(substr($config['url'], 7));
}
Expand Down
2 changes: 1 addition & 1 deletion freepbx/var/www/html/freepbx/rest/modules/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,6 @@
* GET /settings/conferenceurl return the conference JitsiUrl
*/
$app->get('/settings/conferenceurl', function (Request $request, Response $response, $args) {
return $response->withJson($ENV['NETHVOICE_CONFERENCEURL'], 200);
return $response->withJson($_ENV['NETHVOICE_CONFERENCEURL'], 200);
});

1 change: 1 addition & 0 deletions imageroot/systemd/user/freepbx.service
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ ExecStart=/usr/bin/podman run \
--volume=reports_config:/opt/nethvoice-report:z \
--volume=tancredi:/var/lib/tancredi:z \
--volume=astdb:/var/lib/asterisk/db:z \
--volume=phonebookcsv:/var/lib/nethvoice/phonebook/uploads:z \
--volume=/dev/log:/dev/log \
--env=NETHVOICE* \
--env=ASTERISK_* \
Expand Down

0 comments on commit eea8569

Please sign in to comment.