diff --git a/.dockerignore b/.dockerignore
new file mode 100644
index 00000000..583d90f4
--- /dev/null
+++ b/.dockerignore
@@ -0,0 +1,4 @@
+composer.lock
+config.cron
+config.php
+vendor/
diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 00000000..aa9a0470
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,15 @@
+# This file is for unifying the coding style for different editors and IDEs
+# editorconfig.org
+
+# PHP PSR-2 Coding Standards
+# http://www.php-fig.org/psr/psr-2/
+
+root = true
+
+[*.php]
+charset = utf-8
+end_of_line = lf
+insert_final_newline = true
+trim_trailing_whitespace = true
+indent_style = space
+indent_size = 4
diff --git a/.gitignore b/.gitignore
index b74decb0..807ac819 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,17 @@
+/composer.lock
/config.php
+/cards.xml
+/vendor/
+php-cs-fixer.config
+config.cron
+cache
+/carddav2fb.wiki
+/workbench/google.php
+/workbench/liz.php
+/workbench/request_b.php
+/workbench/request_m.php
+/workbench/t-online.php
+/workbench/test.php
+/workbench/test1.php
+/workbench/wolf_cfg.php
+/.vscode/launch.json
diff --git a/.php_cs.php b/.php_cs.php
new file mode 100644
index 00000000..60251103
--- /dev/null
+++ b/.php_cs.php
@@ -0,0 +1,14 @@
+in('src')
+;
+
+return PhpCsFixer\Config::create()
+ ->setRules([
+ '@PSR2' => true,
+ 'array_syntax' => ['syntax' => 'short'],
+ ])
+ ->setFinder($finder)
+ ->setUsingCache(false)
+;
\ No newline at end of file
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 00000000..50566a1e
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,56 @@
+sudo: false
+
+language: php
+
+php:
+ - "7.3"
+
+cache:
+ directories:
+ - $HOME/.composer/cache
+
+env:
+ global:
+ - secure: "Ef6Z9viGwbt8crRkwdjqfg3/xBwTvALrLBfTJJGsbYNbOq7g8amL6EMdlaUhjqLnQT+sHELtQIScpOp7XuVzt5t6yMbYh4zPBJ1MCjY1Fav859X44g42Ba8TzM3jlDSe95n2tq3kM9ExfIhBHIPwjn/Yfy32zhIFXmuDVbQKC4xW0/uD63kvnqA7H74/atNeyVTZu+ZrN05v9kRceLkb98QN2K/EOYZZcLikJDX98afVqI6IdQCjnpOlZ9DoSlODZ11xVPwdfo9wnlrf4RDhYR8MBOGGffQNigc2lIfHEwjOqh65+59TrL5YkdFtuti9dyKNXqvLK3SSUTjMsf1eQnpDoMuN1nS5kOTvPh0QpxrfotspuaUO5/hq2fmO/guvYFVVlShRrNYlMbVokzvk2NW5lohp8kENzntTyNRo+bmgP/GSM5a1Mg0uvpAMAirOUEWZUEatdJLsnokULv8Q8WlC5G59H5zdmzXeLNOh1LMWDUSFrn2M+JDkM8kmK34R6CRpSsxB1c+fJT711EDTl363TAqMvSrvlNgpyMXiNDmSjPIjfjD1sNsO7MkDrLjRj9nUxIaSRMmzW0MKr+Z/R/SCa2+ujY0o/pVZF8hr2UA0VWnji+b5RAiFwEKD5HM9RfeMe2O9rbdlas6I9pO38HOhli43bvvYVeqNq2evOoQ="
+ - secure: "ZN/wGrHvtcl01q6DUBlcvZZ49szNGgYbk8E4DZcc2T8dkNPITumnxhdYU+HoSFvvQm0w3KAIRTRj67EJxeHrKrxpnyJKtl03+iDcdVABP3rLFBy+9PHVgQ4oPEZ9qVqTdRP/z44CwjjR/NNXnSUTNtCIPjW5hnN4eM2YcugxQy8vTr8bwRoFkTrGDSgQhszg+bsjRan0PchJPnWmXnkqYR+lrHUIWcBr73/nwysdZQAX4BK9iUkETwJMNgw3Lgm4Q8QB8eNKoewZKnkjaJ+ykxudOtjXidRl7GxJpyUR6BzI2R6ba0Yf1B8lE+Fk/XuO9qFbZ/qu1Wv6F4AXuSiXcpmI/SVySj7+BN+Jha7Mbz9m2PRp4FXvRW4HxUNPJ168J+pWbzivpMSJ31Nt8MaxGtXedkVX1+j0g6p4hBueulRldJRKkifSFRqPq0z56KrFuSd9FHcpYEjile+wElutM2Fjw8+5QkP4kmaJd/zxHCE1P8tri3sljuWyl1yhKR2V87pY99hCtUp8H48pXBatUYK2pNOJho0f+rtwQIGjcQDAL96EVLXvNS4AW8tLZyUZC9hduSVrbPSxtHNdi8EDX/HJRifLI3sSMGW9ct3Tj5MfPo0MHc3okFh7nHCiCCQQGYEi8mWlLpm7DDgm6YXZo8h5UcOJcMbKAdh/IMm6oLQ="
+
+notifications:
+ email:
+ on_success: never
+ on_failure: change
+
+jobs:
+ include:
+ - stage: Test
+ install:
+ - composer install
+ script:
+ - vendor/bin/phpunit
+ - # parallel
+ install:
+ - rm -f ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini
+ - composer require --dev "phpstan/phpstan"
+ script:
+ - ./vendor/bin/phpstan analyze --level=5 --no-progress src
+ - # parallel
+ install:
+ - rm -f ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini
+ - composer require --dev "friendsofphp/php-cs-fixer:^2.8"
+ script:
+ - IFS=$'\n'; COMMIT_SCA_FILES=($(git diff --name-only --diff-filter=ACMRTUXB "${TRAVIS_COMMIT_RANGE}")); unset IFS
+ - ./vendor/bin/php-cs-fixer fix --config=.php_cs.php -v --dry-run --diff --stop-on-violation --using-cache=no --path-mode=intersection -- "${COMMIT_SCA_FILES[@]}"
+ - stage: Deploy
+ install: skip
+ script: skip
+ before_deploy:
+ - |
+ docker login -u $DOCKER_USER -p $DOCKER_PASS
+ docker pull ${TRAVIS_REPO_SLUG}:latest
+ deploy:
+ - provider: script
+ on:
+ branch: master
+ script: >
+ bash -c "set -xe &&
+ docker build --cache-from ${TRAVIS_REPO_SLUG}:latest -t ${TRAVIS_REPO_SLUG}:latest . &&
+ docker push ${TRAVIS_REPO_SLUG}:latest"
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 00000000..1731abe6
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,33 @@
+FROM alpine:3.12
+LABEL description="Download CardDAV VCards and upload as phonebook to AVM FRITZ!Box"
+
+VOLUME [ "/data" ]
+
+# Install dependencies for carddav2fb
+RUN set -xe && \
+ apk update && apk upgrade && \
+ apk add --no-cache --virtual=run-deps \
+ php7-cli \
+ php7-curl \
+ php7-dom \
+ php7-ftp \
+ php7-gd \
+ php7-mbstring \
+ php7-simplexml \
+ php7-tokenizer \
+ php7-xml \
+ php7-xmlreader \
+ php7-xmlwriter \
+ composer && \
+ apk del --progress --purge && \
+ rm -rf /var/cache/apk/*
+
+# Copy carddav2fb and install php dependencies
+COPY . /srv
+RUN mkdir -p /data && \
+ cd /srv && \
+ composer install --no-dev && \
+ chmod +x /srv/carddav2fb /srv/docker-entrypoint && \
+ ln -s /data/config.php .
+
+ENTRYPOINT [ "/srv/docker-entrypoint" ]
diff --git a/README.md b/README.md
index c428c610..8e5fc3fa 100644
--- a/README.md
+++ b/README.md
@@ -1,100 +1,124 @@
# CardDAV contacts import for AVM FRITZ!Box
-[](https://scrutinizer-ci.com/g/jens-maus/carddav2fb/build-status/master) [](https://scrutinizer-ci.com/g/jens-maus/carddav2fb/?branch=master)
+[](https://travis-ci.org/andig/carddav2fb) [](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=BB3W3WH7GVSNW)
-Features:
+This is a completely revised version of [https://github.com/jens-maus/carddav2fb][descent].
-* Allows to import CardDAV-based VCard contacts (e.g. from 'owncloud') to a phonebook in a AVM FRITZ!Box
-* CardDAV import includes photo images specified in VCards
-* No modification of FRITZ!Box firmware (aka FRITZ!OS) required
-* Definition of multiple CardDAV accounts and "folders" possible
-* Format of full name in FRITZ!Box phonebook can be designed
+## Features
-**CAUTION: This script will overwrite your current contacts in the FritzBox without any warning!**
+* download from any number of CardDAV servers
+* read from any local *.vcf files (optional)
+* selection (include/exclude) by categories or groups (e.g. iCloud)
+* upload of contact pictures to display them on the FRITZ!Fon (handling see below)
+* automatically preserves quickDial and vanity attributes of phone numbers set in FRITZ!Box Web GUI. Works without config.
+* automatically preserves internal numbers (e.g. if you use [Gruppenruf](https://avm.de/service/fritzbox/fritzbox-7590/wissensdatenbank/publication/show/1148_Interne-Rufgruppe-in-FRITZ-Box-einrichten-Gruppenruf/))
+* if more than nine phone numbers are included, the contact will be divided into a corresponding number of phonebook entries (any existing email addresses are assigned to the first set [there is no quantity limit!])
+* phone numbers are sorted by type. The order of the conversion values ('phoneTypes') determines the order in the phone book entry
+* the contact's UID of the CardDAV server is added to the phonebook entry (not visible in the FRITZ! Box GUI)
+* automatically preserves QuickDial and Vanity attributes of phone numbers set in FRITZ!Box Web GUI. Works without config. These data are saved separately in the internal FRITZ!Box memory under `../FRITZ/mediabox/Atrributes.csv` from loss.
+* generates an image with keypad and designated quickdial numbers (2-9), which can be uploaded to designated handhelds (see details below)
-## Information
+## Requirements
-This version of carddav2fb is a forked version from carlos22 (https://github.com/carlos22/carddav2fb) and adding support for convenient image upload, different FRITZ!Box base paths (for example for FRITZ!Box 7490 (UI) OS: 6.50) and full name design support.
+* PHP 8.2 or higher (`apt-get install php php-curl php-mbstring php-xml`)
+* [Composer][composer]
+
+## Installation
-## Requirements
+Install requirements
-* PHP-version 5.3.6 or higher
-* PHP-curl module
-* PHP-ftp module
-* PHP-mbstring module
+```console
+git clone https://github.com/andig/carddav2fb.git
+cd carddav2fb
+composer install --no-dev
+```
-## Installation
+edit `config.example.php` and save as `config.php`
- Checkout the carddav2fb sources including its related subprojects using the following command:
+## Usage
- git clone https://github.com/jens-maus/carddav2fb.git
+### List all commands
-Now you should have everything setup and checked out to a 'carddav2fb' directory.
+```console
+./carddav2fb list
+```
-### Configuration
-1. Make sure you have `System -> FRITZ!Box-Users -> Login via Username+Password` in your FRITZ!Box activated.
-2. Make sure you have a separate user created under `System -> FRITZ!Box-Users` for which the following access rights have been granted:
- * `FRITZ!Box settings` (required to upload telephone book data)
- * `Access to NAS content` (required to upload photos via ftp).
-3. Make sure the telephone book you are going to update via carddav2fb exists on the FRITZ!Box, otherwise the upload will fail.
-4. Copy `config.example.php` to `config.php` and adapt it to your needs including setting the FRITZ!Box user settings.
+### Complete processing
-## Usage
+```console
+./carddav2fb run
+```
+
+### Get help for a command
+
+```console
+./carddav2fb run -h
+```
+
+#### Preconditions
-### Ubuntu
+* memory (USB stick) is indexed [Heimnetz -> Speicher (NAS) -> Speicher an der FRITZ!Box]
+* ftp access is active [Heimnetz -> Speicher (NAS) -> Heimnetzfreigabe]
+* you use an standalone user (NOT! dslf-config) which has explicit permissions for FRITZ!Box settings, access to NAS content and read/write permission to all available memory [System -> FRITZ!Box-Benutzer -> [user] -> Berechtigungen]
-1. Install PHP, PHP-curl, PHP-ftp, PHP-mbstring and php-xml module:
+### Upload FRITZ!Fon background image
- sudo apt-get install php-cli php-curl php-ftp php-mbstring php-xml
+
-2. Open a Terminal and execute:
+Using the `background-image` command it is possible to upload the quickdial numbers as background image to FRITZ!Fon (nothing else!)
- php carddav2fb.php
+```console
+./carddav2fb background-image
+```
-### Windows
+Uploading can also be included in uploading phonebook:
-1. Download PHP from [php.net](http://windows.php.net/download/). Extract it to `C:\PHP`.
-2. Start -> cmd. Run `C:\PHP\php.exe C:\path\to\carddav2fb\carddav2fb.php`
+```console
+./carddav2fb run -i
+```
-## config.php Example (owncloud)
+#### Image upload preconditions
- $config['fritzbox_ip'] = 'fritz.box';
- $config['fritzbox_user'] = '';
- $config['fritzbox_pw'] = '';
- $config['phonebook_number'] = '0';
- $config['phonebook_name'] = 'Telefonbuch';
- $config['fritzbox_path'] = 'file:///var/media/ftp/';
+* requires FRITZ!Fon C4 or C5 handhelds
+* settings in FRITZ!Fon: Einstellungen -> Anzeige -> Startbildschirme -> Klassisch -> Optionen -> Hintergrundbild
+* assignment is made via the internal number(s) of the handheld(s) in the 'fritzfons'-array in config.php
+* internal number have to be between '610' and '615', no '**'-prefix
- // full name format options default 0
- // parts in '' will only added if existing and switched to true in config
- // 0 = 'Prefix' Lastname, Firstname, 'Additional Names', 'Suffix', 'orgname'
- // 1 = 'Prefix' Firstname Lastname 'AdditionalNames' 'Suffix' '(orgname)'
- // 2 = 'Prefix' Firstname 'AdditionalNames' Lastname 'Suffix' '(orgname)'
- $config['fullname_format'] = 0;
+## Debugging
- // fullname parts
- $config['prefix'] = false; // include prefix in fullname if existing
- $config['suffix'] = false; // include suffix in fullname if existing
- $config['addnames'] = false; // include additionalnames in fullname if existing
- $config['orgname'] = false; // include organisation (company) in fullname if existing
-
- $config['quickdial_keyword'] = 'Quickdial:'; // once activated you may add 'Quickdial:+49030123456:**709' to the contact note field and the number will be set as quickdialnumber in your FRITZ!Box. It is possible to add more quickdials for one contact each in a new line
+For debugging please set your config.php to
- // first
- $config['carddav'][0] = array(
- 'url' => 'https:///remote.php/carddav/addressbooks//contacts',
- 'user' => '',
- 'pw' => ''
- );
+```php
+'http' => 'debug' => true
+```
-## Note
-This script is using third-party libraries for downloading VCards from CardDAV servers based on the following packages
-* CardDAV-PHP (https://github.com/jens-maus/CardDAV-PHP.git)
-* FRITZ!Box-API-PHP (https://github.com/jens-maus/fritzbox_api_php.git)
-* VCard-Parser (https://github.com/jens-maus/vCard-parser.git)
+## Docker image
+
+The Docker image contains the tool and all its dependencies. A volume
+`/data` contains the configuration files. If the configuration is
+missing, the Docker entrypoint will abort with an error message and copy
+an example file to the volume.
+
+There are two ways to use the image:
+
+```console
+docker run --rm -v ./carddav2fb-config:/data andig/carddav2fb command...
+```
+
+will execute a single command (and remove the created container
+afterwards).
+
+Without a command, the container entrypoint will enter an endless loop,
+repeatedly executing `carddav2fb run` in given intervals. This allows
+automatic, regular updates of your FRITZ!Box's phonebook.
## License
-This script is released under Public Domain.
+
+This script is released under Public Domain, some parts under GNU AGPL or MIT license. Make sure you understand which parts are which.
## Authors
-Copyright (c) 2012-2016 Karl Glatz, Martin Rost, Jens Maus, Johannes Freiburger
+
+Copyright (c) 2012-2025 Andreas Götz, Volker Püschel, Karl Glatz, Christian Putzke, Martin Rost, Jens Maus, Johannes Freiburger
+
+[composer]: https://getcomposer.org/download/
+[descent]: https://github.com/jens-maus/carddav2fb
diff --git a/assets/fritzfon.png b/assets/fritzfon.png
new file mode 100644
index 00000000..a90a5ae4
Binary files /dev/null and b/assets/fritzfon.png differ
diff --git a/assets/impact.ttf b/assets/impact.ttf
new file mode 100644
index 00000000..114e6c19
Binary files /dev/null and b/assets/impact.ttf differ
diff --git a/assets/keypad.jpg b/assets/keypad.jpg
new file mode 100644
index 00000000..25381e1b
Binary files /dev/null and b/assets/keypad.jpg differ
diff --git a/carddav2fb b/carddav2fb
new file mode 100755
index 00000000..6472c72e
--- /dev/null
+++ b/carddav2fb
@@ -0,0 +1,20 @@
+#!/usr/bin/env php
+addCommands(array(
+ new RunCommand(),
+ new DownloadCommand(),
+ new ConvertCommand(),
+ new UploadCommand(),
+ new BackgroundCommand()
+));
+
+$app->run();
diff --git a/carddav2fb.php b/carddav2fb.php
deleted file mode 100755
index bd9a25fd..00000000
--- a/carddav2fb.php
+++ /dev/null
@@ -1,829 +0,0 @@
- (LICNECE: unknown)
- * * CardDAV-PHP (LICENCE: AGPLv3)
- * * fritzbox_api_php (LICENCE: CC-by-SA 3.0)
- *
- * LICENCE (of this file): MIT
- *
- * Autors: Karl Glatz (original author)
- * Martin Rost
- * Jens Maus
- * Johannes Freiburger
- *
- */
-error_reporting(E_ALL);
-setlocale(LC_ALL, 'de_DE.UTF8');
-
-// Version identifier for CardDAV2FB
-$carddav2fb_version = '1.11 (2016-05-12)';
-
-// check for the minimum php version
-$php_min_version = '5.3.6';
-if(version_compare(PHP_VERSION, $php_min_version) < 0)
-{
- print 'ERROR: PHP version ' . $php_min_version . ' is required. Found version: ' . PHP_VERSION . PHP_EOL;
- exit(1);
-}
-
-require_once('lib/CardDAV-PHP/carddav.php');
-require_once('lib/vCard-parser/vCard.php');
-require_once('lib/fritzbox_api_php/fritzbox_api.class.php');
-
-if($argc == 2)
- $config_file_name = $argv[1];
-else
- $config_file_name = __DIR__ . '/config.php';
-
-// default/fallback config options
-$config['tmp_dir'] = sys_get_temp_dir();
-$config['fritzbox_ip'] = 'fritz.box';
-$config['fritzbox_ip_ftp'] = $config['fritzbox_ip'];
-$config['fritzbox_force_local_login'] = false;
-$config['phonebook_number'] = '0';
-$config['phonebook_name'] = 'Telefonbuch';
-$config['usb_disk'] = '';
-$config['fritzbox_path'] = 'file:///var/media/ftp/';
-$config['fullname_format'] = 0; // see config.example.php for options
-$config['prefix'] = false;
-$config['suffix'] = false;
-$config['addnames'] = false;
-$config['orgname'] = false;
-$config['build_photos'] = true;
-$config['quickdial_keyword'] = 'Quickdial:';
-
-if(is_file($config_file_name))
- require($config_file_name);
-else
-{
- print 'ERROR: No ' . $config_file_name . ' found, please take a look at config.example.php and create a ' . $config_file_name . ' file!' . PHP_EOL;
- exit(1);
-}
-
-// ---------------------------------------------
-// MAIN
-print "carddav2fb.php " . $carddav2fb_version . " - CardDAV to FRITZ!Box phonebook conversion tool" . PHP_EOL;
-print "Copyright (c) 2012-2016 Karl Glatz, Martin Rost, Jens Maus, Johannes Freiburger" . PHP_EOL . PHP_EOL;
-
-$client = new CardDAV2FB($config);
-
-// read vcards from webdav
-print 'Retrieving VCards from all CardDAV server(s):' . PHP_EOL;
-$client->get_carddav_entries();
-print 'Done.' . PHP_EOL;
-
-flush(); // in case this script runs by php-cgi
-
-// transform them to a fritzbox compatible xml file
-print 'Converting VCards to FritzBox XML format:' . PHP_EOL;
-$client->build_fb_xml();
-print 'Done.' . PHP_EOL;
-
-flush(); // in case this script runs by php-cgi
-
-// upload the XML-file to the FRITZ!Box (CAUTION: this will overwrite all current entries in the phone book!!)
-print 'Upload data to FRITZ!Box @ ' . $config['fritzbox_ip'] . PHP_EOL;
-if($client->upload_to_fb())
- print 'Done.' . PHP_EOL;
-else
- exit(1);
-
-flush(); // in case this script runs by php-cgi
-
-// ---------------------------------------------
-// Class definition
-class CardDAV2FB
-{
- protected $entries = array();
- protected $fbxml = "";
- protected $config = null;
- protected $tmpdir = null;
-
- public function __construct($config)
- {
- $this->config = $config;
-
- // create a temp directory where we store photos
- $this->tmpdir = $this->mktemp($this->config['tmp_dir']);
- }
-
- public function __destruct()
- {
- // remote temp directory
- $this->rmtemp($this->tmpdir);
- }
-
- // Source: https://php.net/manual/de/function.tempnam.php#61436
- public function mktemp($dir, $prefix = '', $mode = 0700)
- {
- if(substr($dir, -1) != '/')
- $dir .= '/';
-
- do
- {
- $path = $dir . $prefix . mt_rand(0, 9999999);
- }
- while(!mkdir($path, $mode));
-
- return $path;
- }
-
- public function rmtemp($dir)
- {
- if(is_dir($dir))
- {
- $objects = scandir($dir);
- foreach($objects as $object)
- {
- if($object != "." && $object != "..")
- {
- if(filetype($dir . "/" . $object) == "dir")
- rrmdir($dir . "/" . $object); else unlink($dir . "/" . $object);
- }
- }
- reset($objects);
- rmdir($dir);
- }
- }
-
- public function is_base64($str)
- {
- try
- {
- // Check if there are valid base64 characters
- if(!preg_match('/^[a-zA-Z0-9\/\r\n+]*={0,2}$/', $str))
- return false;
-
- // Decode the string in strict mode and check the results
- $decoded = base64_decode($str, true);
- if($decoded === false)
- return false;
-
- // Encode the string again
- if(base64_encode($decoded) === $str)
- return true;
- else
- return false;
- }
- catch(Exception $e)
- {
- // If exception is caught, then it is not a base64 encoded string
- return false;
- }
- }
-
- public function base64_to_jpeg($inputfile, $outputfile)
- {
- // read data (binary)
- $ifp = fopen($inputfile, "rb");
- $imageData = fread($ifp, filesize($inputfile));
- fclose($ifp);
-
- // encode & write data (binary)
- $ifp = fopen($outputfile, "wb");
- fwrite($ifp, base64_decode($imageData));
- fclose($ifp);
-
- // return output filename
- return($outputfile);
- }
-
- public function get_carddav_entries()
- {
- $entries = array();
- $snum = 0;
-
- if(is_array($this->config['carddav']))
- {
- foreach($this->config['carddav'] as $conf)
- {
- print " [" . $snum . "]: " . $conf['url'] . " ";
- $carddav = new CardDavPHP\CardDavBackend($conf['url']);
- $carddav->setAuth($conf['user'], $conf['pw']);
-
- // set the vcard extension in case the user
- // defined it in the config
- if(isset($conf['extension']))
- $carddav->setVcardExtension($conf['extension']);
-
- // retrieve data from the CardDAV server now
- $xmldata = $carddav->get();
-
- // identify if we received UTF-8 encoded data from the
- // CardDAV server and if not reencode it since the FRITZ!Box
- // requires UTF-8 encoded data
- if(iconv('utf-8', 'utf-8//IGNORE', $xmldata) != $xmldata)
- $xmldata = utf8_encode($xmldata);
-
- // read raw_vcard data from xml response
- $raw_vcards = array();
- $xmlvcard = new SimpleXMLElement($xmldata);
-
- foreach($xmlvcard->element as $vcard_element)
- {
- $id = $vcard_element->id->__toString();
- $value = (string)$vcard_element->vcard->__toString();
- $raw_vcards[$id] = $value;
- }
-
- print " " . count($raw_vcards) . " VCards retrieved." . PHP_EOL;
-
- // parse raw_vcards
- $quick_dial_arr = array();
- foreach($raw_vcards as $v)
- {
- $vcard_obj = new vCard(false, $v);
- $name_arr = null;
- if(isset($vcard_obj->n[0]))
- $name_arr = $vcard_obj->n[0];
- $org_arr = null;
- if(isset($vcard_obj->org[0]))
- $org_arr = $vcard_obj->org[0];
- $addnames = '';
- $prefix = '';
- $suffix = '';
- $orgname = '';
- $formattedname = '';
-
- // Build name Parts if existing ans switch to true in config
- if(isset($name_arr['prefixes']) and $this->config['prefix'])
- $prefix = trim($name_arr['prefixes']);
-
- if(isset($name_arr['suffixes']) and $this->config['suffix'])
- $suffix = trim($name_arr['suffixes']);
-
- if(isset($name_arr['additionalnames']) and $this->config['addnames'])
- $addnames = trim($name_arr['additionalnames']);
-
- if(isset($org_arr['name']) and $this->config['orgname'])
- $orgname = trim($org_arr['name']);
-
- if (isset($vcard_obj->fn[0]))
- $formattedname = $vcard_obj->fn[0];
-
- $firstname = trim($name_arr['firstname']);
- $lastname = trim($name_arr['lastname']);
-
- // the following section implemented different ways of constructing the
- // final phonebook name entry depending on user preferred settings
- // selectable in the config file. Possible options are:
- //
- // $this->config['fullname_format']:
- //
- // 0: "Prefix Lastname, Firstname AdditionalNames Suffix (orgname)"
- // 1: "Prefix Firstname Lastname AdditionalNames Suffix (orgname)"
- // 2: "Prefix Firstname AdditionalNames Lastname Suffix (orgname)"
- //
- $name = '';
- $format = $this->config['fullname_format'];
-
- // Prefix
- if(!empty($prefix))
- $name .= $prefix;
-
- if($format == 0)
- {
- // Lastname
- if(!empty($name) and !empty($lastname))
- $name .= ' ' . $lastname;
- else
- $name .= $lastname;
- }
- else
- {
- // Firstname
- if(!empty($name) and !empty($firstname))
- $name .= ' ' . $firstname;
- else
- $name .= $firstname;
- }
-
- if($format == 2)
- {
- // AdditionalNames
- if(!empty($name) and !empty($addnames))
- $name .= ' ' . $addnames;
- else
- $name .= $addnames;
- }
-
- if($format == 0)
- {
- // Firstname
- if(!empty($name) and !empty($firstname))
- $name .= ', ' . $firstname;
- else
- $name .= $firstname;
- }
- else
- {
- // Lastname
- if(!empty($name) and !empty($lastname))
- $name .= ' ' . $lastname;
- else
- $name .= $lastname;
- }
-
- if($format != 2)
- {
- // AdditionalNames
- if(!empty($name) and !empty($addnames))
- $name .= ' ' . $addnames;
- else
- $name .= $addnames;
- }
-
- // Suffix
- if(!empty($name) and !empty($suffix))
- $name .= ' ' . $suffix;
- else
- $name .= $suffix;
-
- // OrgName
- if(!empty($name) and !empty($orgname))
- $name .= ' (' . $orgname . ')';
- else
- $name .= $orgname;
-
- // make sure to trim whitespaces and double spaces
- $name = trim(str_replace(' ', ' ', $name));
-
- // perform a fallback to formatted name, if we don't have any name and formatted name is available
- if(empty($name) and !empty($formattedname))
- $name = $formattedname;
-
- if(empty($name))
- {
- print ' WARNING: No fullname, lastname, orgname or formatted name found!' . PHP_EOL;
- $name = 'UNKNOWN';
- }
-
- // format filename of contact photo; remove special letters
- if($vcard_obj->photo)
- {
- $photo = str_replace(array(',', '&', ' ', '/', 'ä', 'ö', 'ü', 'Ä', 'Ö', 'Ü', 'ß', 'á', 'à', 'ó', 'ò', 'ú', 'ù', 'í', 'ø'),
- array('', '_', '_', '_', 'ae', 'oe', 'ue', 'Ae', 'Oe', 'Ue', 'ss', 'a', 'a', 'o', 'o', 'u', 'u', 'i', 'oe'), $name);
- }
- else
- $photo = '';
-
- // phone
- $phone_no = array();
- if($vcard_obj->categories)
- $categories = $vcard_obj->categories[0];
- else
- $categories = array();
-
- // check for quickdial entry
- if(isset($vcard_obj->note[0]))
- {
- $note = $vcard_obj->note[0];
- $notes = explode($this->config['quickdial_keyword'], $note);
- foreach($notes as $linenr => $linecontent)
- {
- $found = strrpos($linecontent, ":**7");
- if($found > 0)
- {
- $pos_qd_start = strrpos($linecontent, ":**7");
- $quick_dial_for_nr = preg_replace("/[^0-9+]/", "", substr($linecontent, 0, $pos_qd_start));
- $quick_dial_nr = intval(substr($linecontent, $pos_qd_start + 4, 3));
- $quick_dial_arr[$quick_dial_for_nr] = $quick_dial_nr;
- }
- }
- }
-
- // e-mail addresses
- $email_add = array();
- $vip = isset($this->config['group_vip']) && in_array((string)$this->config['group_vip'], $categories);
-
- if(array_key_exists('group_filter', $this->config) && is_array($this->config['group_filter']))
- {
- $add_entry = 0;
- foreach($this->config['group_filter'] as $group_filter)
- {
- if(in_array($group_filter, $categories))
- {
- $add_entry = 1;
- break;
- }
- }
- }
- else
- $add_entry = 1;
-
- if($add_entry == 1)
- {
- foreach($vcard_obj->tel as $t)
- {
- $prio = 0;
- $quickdial = null;
-
- if(!is_array($t) || empty($t['type']))
- {
- $type = "mobile";
- $phone_number = $t;
- }
- else
- {
- $phone_number = $t['value'];
-
- $phone_number_clean = preg_replace("/[^0-9+]/", "", $phone_number);
- foreach($quick_dial_arr as $qd_phone_nr => $value)
- {
- if($qd_phone_nr == $phone_number_clean)
- {
- //Set quickdial
- if($value == 1)
- print "\nWARNING: Quickdial value 1 (**701) is not possible but used! \n";
- elseif($value >= 100)
- print "\nWARNING: Quickdial value bigger than 99 (**799) is not possible but used! \n";
-
- $quickdial = $value;
- }
- }
-
- $typearr_lower = unserialize(strtolower(serialize($t['type'])));
-
- // find out priority
- if(in_array("pref", $typearr_lower))
- $prio = 1;
-
- // set the proper type
- if(in_array("cell", $typearr_lower))
- $type = "mobile";
- elseif(in_array("home", $typearr_lower))
- $type = "home";
- elseif(in_array("fax", $typearr_lower))
- $type = "fax_work";
- elseif(in_array("work", $typearr_lower))
- $type = "work";
- elseif(in_array("other", $typearr_lower))
- $type = "other";
- elseif(in_array("dom", $typearr_lower))
- $type = "other";
- else
- continue;
- }
- $phone_no[] = array("type"=>$type, "prio"=>$prio, "quickdial"=>$quickdial, "value" => $this->_clear_phone_number($phone_number));
- }
-
- // request email address and type
- if($vcard_obj->email)
- {
- foreach($vcard_obj->email as $e)
- {
- if(empty($e['type']))
- {
- $type_email = "work";
- $email = $e;
- }
- else
- {
- $email = $e['value'];
- $typearr_lower = unserialize(strtolower(serialize($e['type'])));
- if(in_array("work", $typearr_lower))
- $type_email = "work";
- elseif(in_array("home", $typearr_lower))
- $type_email = "home";
- elseif(in_array("other", $typearr_lower))
- $type_email = "other";
- else
- continue;
- }
-
- // DEBUG: print out the email address on the console
- //print $type_email.": ".$email."\n";
-
- $email_add[] = array("type"=>$type_email, "value" => $email);
- }
- }
- $entries[] = array("realName" => $name, "telephony" => $phone_no, "email" => $email_add, "vip" => $vip, "photo" => $photo, "photo_data" => $vcard_obj->photo);
- }
- }
-
- $snum++;
- }
- }
-
- $this->entries = $entries;
- }
-
- private function _clear_phone_number($number)
- {
- return preg_replace("/[^0-9+]/", "", $number);
- }
-
- public function build_fb_xml()
- {
- if(empty($this->entries))
- throw new Exception('No entries available! Call get_carddav_entries or set $this->entries manually!');
-
- // create FB XML in utf-8 format
- $root = new SimpleXMLElement('');
- $pb = $root->phonebook;
- $pb->addAttribute("name", $this->config['phonebook_name']);
-
- foreach($this->entries as $entry)
- {
- $contact = $pb->addChild("contact");
- $contact->addChild("category", $entry['vip']);
- $person = $contact->addChild("person");
- $person->addChild("realName", $this->_convert_text($entry['realName']));
-
- echo " VCard: '" . utf8_decode($entry['realName']) . "'" . PHP_EOL;
-
- // telephone: put the phonenumbers into the fritzbox xml file
- $telephony = $contact->addChild("telephony");
- $id = 0;
- foreach($entry['telephony'] as $tel)
- {
- $num = $telephony->addChild("number", $tel['value']);
- $num->addAttribute("type", $tel['type']);
- $num->addAttribute("vanity", "");
- $num->addAttribute("prio", $tel['prio']);
- $num->addAttribute("id", $id);
-
- if(isset($tel['quickdial']))
- {
- $num->addAttribute("quickdial", $tel['quickdial']);
- print " Added quickdial: " . $tel['quickdial'] . " for: " . $tel['value'] . " (" . $tel['type'] . ")" . PHP_EOL;
- }
-
- $id++;
- print " Added phone: " . $tel['value'] . " (" . $tel['type'] . ")" . PHP_EOL;
- }
-
- // output a warning if no telephone number was found
- if($id == 0)
- print " WARNING: no phone entry found. VCard will be ignored." . PHP_EOL;
-
- // email: put the email addresses into the fritzbox xml file
- $email = $contact->addChild("services");
- $id = 0;
- foreach($entry['email'] as $mail)
- {
- $mail_adr = $email->addChild("email", $mail['value']);
- $mail_adr->addAttribute("classifier", $mail['type']);
- $mail_adr->addAttribute("id", $id);
- $id++;
-
- print " Added email: " . $mail['value'] . " (" . $mail['type'] . ")" . PHP_EOL;
- }
-
- // check for a photo being part of the VCard
- if(($entry['photo']) and ($entry['photo_data']) and (is_array($entry['photo_data'])) and ($entry['photo_data'][0]))
- {
- // check if 'photo_data'[0] is an array as well because then
- // we have to extract ['value'] and friends.
- if(is_array($entry['photo_data'][0]) and (array_key_exists('value', $entry['photo_data'][0])))
- {
- // check if photo_data really contains JPEG data
- if((array_key_exists('type', $entry['photo_data'][0])) and (is_array($entry['photo_data'][0]['type'])) and
- ($entry['photo_data'][0]['type'][0] == 'jpeg' or $entry['photo_data'][0]['type'][0] == 'jpg' or $entry['photo_data'][0]['type'][0] == 'image/jpeg'))
- {
- // get photo, rename, base64 convert and save as jpg
- $photo_data = $entry['photo_data'][0]['value'];
- $photo_version = substr(sha1($photo_data), 0, 5);
- $photo_file = $this->tmpdir . '/' . "{$entry['photo']}_{$photo_version}.jpg";
-
- // check for base64 encoding of the photo data and convert it
- // accordingly.
- if(((array_key_exists('encoding', $entry['photo_data'][0])) and ($entry['photo_data'][0]['encoding'] == 'b')) or $this->is_base64($photo_data))
- {
- file_put_contents($photo_file . ".b64", $photo_data);
- $this->base64_to_jpeg($photo_file . ".b64", $photo_file);
- unlink($photo_file . ".b64");
- }
- else
- {
- print " WARNING: non-base64 encoded photo data found and used." . PHP_EOL;
- file_put_contents($photo_file, $photo_data);
- }
-
- // add contact photo to xml
- $person->addChild("imageURL", $this->config['fritzbox_path'] . $this->config['usb_disk'] . "FRITZ/fonpix/" . basename($photo_file));
-
- print " Added photo: " . basename($photo_file) . PHP_EOL;
- }
- else
- print " WARNING: Only jpg contact photos are currently supported." . PHP_EOL;
- }
- elseif(substr($entry['photo_data'][0], 0, 4) == 'http')
- {
- // add contact photo to xml
- $person->addChild("imageURL", $entry['photo_data'][0]);
-
- print " Added photo: " . $entry['photo_data'][0] . PHP_EOL;
- }
- else
- print " WARNING: Only VCard embedded photo data or a reference URL is currently supported." . PHP_EOL;
- }
-
- $contact->addChild("services");
- $contact->addChild("setup");
- $contact->addChild("mod_time", (string)time());
- }
-
- if($root->asXML() !== false)
- $this->fbxml = $root->asXML();
- else
- {
- print " ERROR: created XML data isn't well-formed." . PHP_EOL;
- exit(1);
- }
- }
-
- public function _convert_text($text)
- {
- $text = htmlspecialchars($text);
- return $text;
- }
-
- public function _concat($text1, $text2)
- {
- if($text1 == '')
- return $text2;
- elseif($text2 == '')
- return $text1;
- else
- return $text1 . ", " . $text2;
- }
-
- public function _parse_fb_result($text)
- {
- if(preg_match("/\
([^\<]+)\<\/h2\>/", $text, $matches) == 1 && !empty($matches))
- return $matches[1];
- else
- return "Error while uploading xml to fritzbox";
- }
-
- public function upload_to_fb()
- {
- // if the user wants to save the xml to a separate file, we do so now
- if(array_key_exists('output_file', $this->config))
- {
- // build md5 hash of previous stored xml without Elements
- $oldphonebhash = md5(preg_replace("/(\\d{10})/","",file_get_contents($this->config['output_file'],'r'),-1,$debugoldtsreplace));
- $output = fopen($this->config['output_file'], 'w');
- if($output)
- {
- fwrite($output, $this->fbxml);
- fclose($output);
- print " Saved to file " . $this->config['output_file'] . PHP_EOL;
- }
- if (array_key_exists('output_and_upload', $this->config) and $this->config['output_and_upload'])
- {
- $newphonebhash = md5(preg_replace("/(\\d{10})/","",file_get_contents($this->config['output_file'],'r'),-1,$debugnewtsreplace));
- print " INFO: Compare old and new phonebook file versions." . PHP_EOL . " INFO: old version: " . $oldphonebhash . PHP_EOL . " INFO: new version: " . $newphonebhash . PHP_EOL;
- if($oldphonebhash === $newphonebhash)
- {
- print " INFO: Same versions ==> No changes in phonebook or images" . PHP_EOL . " EXIT: No need to upload phonebook to the FRITZ!Box.". PHP_EOL;
- return 0;
- }
- else
- print " INFO: Different versions ==> Changes in phonebook." . PHP_EOL . " INFO: Changes dedected! Continue with upload." . PHP_EOL;
- }
- else
- return 0;
- }
- // now we upload the photo jpgs first being stored in the
- // temp directory.
-
- // perform an ftps-connection to copy over the photos to a specified directory
- $ftp_server = $this->config['fritzbox_ip_ftp'];
- $conn_id = ftp_ssl_connect($ftp_server);
- if($conn_id == false)
- {
- print " WARNING: Secure connection to FTP-server '" . $ftp_server . "' failed, retrying without SSL." . PHP_EOL;
- $conn_id = ftp_connect($ftp_server);
- }
-
- if($conn_id != false)
- {
- ftp_set_option($conn_id, FTP_TIMEOUT_SEC, 60);
- $login_result = ftp_login($conn_id, $this->config['fritzbox_user'], $this->config['fritzbox_pw']);
- if($login_result === true)
- {
- ftp_pasv($conn_id, true);
-
- // create remote photo path on FRITZ!Box if it doesn't exist
- $remote_path = $this->config['usb_disk'] . "/FRITZ/fonpix";
- $all_existing_files = ftp_nlist($conn_id, $remote_path);
- if($all_existing_files == false)
- {
- ftp_mkdir($conn_id, $remote_path);
- $all_existing_files = array();
- }
-
- // now iterate through all jpg files in tempdir and upload them if necessary
- $dir = new DirectoryIterator($this->tmpdir);
- foreach($dir as $fileinfo)
- {
- if(!$fileinfo->isDot())
- {
- if($fileinfo->getExtension() == "jpg")
- {
- $file = $fileinfo->getFilename();
-
- print " FTP-Upload '" . $file . "'...";
- if(!in_array($remote_path . "/" . $file, $all_existing_files))
- {
- if(!ftp_put($conn_id, $remote_path . "/" . $file, $fileinfo->getPathname(), FTP_BINARY))
- {
- // retry when a fault occurs.
- print " retrying... ";
- $conn_id = ftp_ssl_connect($ftp_server);
- if($conn_id == false)
- {
- print " WARNING: Secure re-connection to FTP-server '" . $ftp_server . "' failed, retrying without SSL." . PHP_EOL;
- $conn_id = ftp_connect($ftp_server);
- }
-
- if($conn_id == false)
- {
- print " ERROR: couldn't re-connect to FTP server '" . $ftp_server . "', abortіng." . PHP_EOL;
- break;
- }
-
- $login_result = ftp_login($conn_id, $this->config['fritzbox_user'], $this->config['fritzbox_pw']);
- if($login_result === false)
- {
- print " ERROR: couldn't re-login to FTP-server '" . $ftp_server . "' with provided username/password settings." . PHP_EOL;
- break;
- }
-
- ftp_pasv($conn_id, true);
- if(!ftp_put($conn_id, $remote_path . "/" . $file, $fileinfo->getPathname(), FTP_BINARY))
- print " ERROR: while uploading file " . $fileinfo->getFilename() . PHP_EOL;
- else
- print " ok." . PHP_EOL;
- }
- else
- print " ok." . PHP_EOL;
-
- // cleanup old files
- foreach($all_existing_files as $existing_file)
- {
- if(strpos($existing_file, $remote_path . "/" . substr($file, 0, -10)) !== false)
- {
- print " FTP-Delete: " . $existing_file . PHP_EOL;
- ftp_delete($conn_id, $remote_path . "/" . basename($existing_file));
- }
- }
- }
- else
- print " already exists." . PHP_EOL;
- }
- }
- }
- }
- else
- print " ERROR: couldn't login to FTP-server '" . $ftp_server . "' with provided username/password settings." . PHP_EOL;
-
- // close ftp connection
- ftp_close($conn_id);
- }
- else
- print " ERROR: couldn't connect to FTP server '" . $ftp_server . "'." . PHP_EOL;
-
- // lets post the phonebook xml to the FRITZ!Box
- print " Uploading Phonebook XML to " . $this->config['fritzbox_ip'] . PHP_EOL;
- try
- {
- $fritz = new fritzbox_api($this->config['fritzbox_pw'],
- $this->config['fritzbox_user'],
- $this->config['fritzbox_ip'],
- $this->config['fritzbox_force_local_login']);
-
- $formfields = array(
- 'PhonebookId' => $this->config['phonebook_number']
- );
-
- $filefileds = array('PhonebookImportFile' => array(
- 'type' => 'text/xml',
- 'filename' => 'updatepb.xml',
- 'content' => $this->fbxml,
- )
- );
-
- $raw_result = $fritz->doPostFile($formfields, $filefileds); // send the command
- $msg = $this->_parse_fb_result($raw_result);
- unset($fritz); // destroy the object to log out
-
- print " FRITZ!Box returned message: '" . $msg . "'" . PHP_EOL;
- }
- catch(Exception $e)
- {
- print " ERROR: " . $e->getMessage() . PHP_EOL; // show the error message in anything failed
- return false;
- }
- return true;
- }
-}
diff --git a/composer.json b/composer.json
new file mode 100644
index 00000000..e5f8694d
--- /dev/null
+++ b/composer.json
@@ -0,0 +1,29 @@
+{
+ "name": "andig/carddav2fb",
+ "description": "Download CardDAV VCards and upload as phonebook to AVM FRITZ!Box",
+ "type": "project",
+ "license": "MIT",
+ "authors": [
+ {
+ "name": "andig",
+ "email": "cpuidle@gmx.de"
+ }
+ ],
+ "require": {
+ "php": "^8.2",
+ "symfony/console": "^6.0",
+ "guzzlehttp/guzzle": "^7.9",
+ "ringcentral/psr7": "^1.3",
+ "sabre/vobject": "^4.5"
+ },
+ "autoload": {
+ "psr-4": {
+ "Andig\\": "src/",
+ "Test\\": "tests/"
+ },
+ "files": ["src/functions.php"]
+ },
+ "require-dev": {
+ "phpunit/phpunit": "^8|^9"
+ }
+}
diff --git a/config.example.cron b/config.example.cron
new file mode 100644
index 00000000..cde0ab9d
--- /dev/null
+++ b/config.example.cron
@@ -0,0 +1,2 @@
+INTERVAL=4h
+RUN_OPTIONS=
diff --git a/config.example.php b/config.example.php
index 44b47b65..86eeee33 100644
--- a/config.example.php
+++ b/config.example.php
@@ -1,75 +1,112 @@
[
+ 'id' => 0, // only "0" can store quickdial and vanity numbers
+ 'name' => 'Telefonbuch',
+ 'imagepath' => 'file:///var/InternerSpeicher/[YOURUSBSTICK]/FRITZ/fonpix/', // mandatory if you use the -i option
+ ],
-// hostname or IP address of Fritz!Box
-// Note: Some Boxes are configured to reject login via IP.
-// If that's the case with your box, then you have to specify the hostname.
-$config['fritzbox_ip'] = 'fritz.box';
-$config['fritzbox_ip_ftp'] = 'fritz.box';
+ // or server (is considered with the run and download command)
+ 'server' => [
+ [
+ 'url' => 'https://...',
+ 'user' => '',
+ 'password' => '',
+ 'http' => [ // http client options are directly passed to Guzzle http client
+ // 'verify' => false, // uncomment to disable certificate check
+ // 'auth' => 'digest', // uncomment for digest auth
+ ],
+ // 'method' => 'PROPFIND'; // uncomment if 'REPORT' (default) causes an error (e.g. t-online)
+ ],
+/* add as many as you need
+ [
+ 'url' => 'https://...',
+ 'user' => '',
+ 'password' => '',
+ ],
+*/
+ ],
-// user name/password to access Fritz!Box
-$config['fritzbox_user'] = 'fb_username';
-$config['fritzbox_pw'] = 'fb_password';
-//$config['fritzbox_force_local_login'] = true;
+ // or fritzbox
+ 'fritzbox' => [
+ 'url' => 'http://fritz.box',
+ 'user' => '',
+ 'password' => '',
+ 'fonpix' => '/[YOURUSBSTICK]/FRITZ/fonpix', // the storage on your usb stick for uploading images
+ 'fritzfons' => [ // uncomment to upload quickdial image as background to designated FRITZ!Fon
+ // '613', // internal number must be in the range '610' to '615' (maximum of DECT devices)
+ ],
+ 'quickdial_alias' => false, // if true, than vanity names ("JON") become quickdial aliases ("Jon") in the background image
+ 'http' => [ // http client options are directly passed to Guzzle http client
+ // 'verify' => false, // uncomment to disable certificate check
+ ],
+ 'ftp' => [
+ 'plain' => false, // set true to use FTP instead of FTPS e.g. on Windows
+ 'disabled' => false, // set true if your FRITZ!Box does not support ftp - e.g. 7412
+ ],
+ ],
-// number of the internal phone book and its name
-// 0 - main phone book
-// 1..n - additional phone books
-$config['phonebook_number'] = '0';
-$config['phonebook_name'] = 'Telefonbuch';
+ 'filters' => [
+ 'include' => [ // if empty include all by default
+ /*
+ 'categories' => [],
+ 'groups' => [],
+ */
+ ],
-// Fullname format options
-// 'only if exist and switched to true here in config'
-// 0: "Prefix Lastname, Firstname AdditionalNames Suffix (orgname)"
-// 1: "Prefix Firstname Lastname AdditionalNames Suffix (orgname)"
-// 2: "Prefix Firstname AdditionalNames Lastname Suffix (orgname)"
-$config['fullname_format'] = 0;
+ 'exclude' => [
+ /*
+ 'categories' => [],
+ 'groups' => [],
+ */
+ ],
+ ],
-// Fullname parts
-$config['prefix'] = false; // include prefix in fullname if existing
-$config['suffix'] = false; // include suffix in fullname if existing
-$config['addnames'] = false; // include additionalnames in fullname if existing
-$config['orgname'] = false; // include organisation (company) in fullname if existing
-
-// Quickdial starting keyword in notes
-//$config['quickdial_keyword'] = 'Quickdial:'; // once activated you may add 'Quickdial:+49030123456:**709' to the contact note field and the number will set as quickdialnumber. You may add more quickdials for a single contact each in a new line
-
-// optional: write output to file of sending it to the Fritz!Box
-//$config['output_file'] = '/media/usbdisk/share/phonebook.xml';
-// optional: once activated phonebook will also be upload to FRITZ!Box if changes are detectet (output_file must be set)
-//$config['output_and_upload'] = false;
-
-// optional: import only contacts of the given groups
-//$config['group_filter'] = array('Arzt','Familie','Freunde','Friseur','Geschäftlich','Hotline','Notruf','Restaurant','Shops');
-
-// group name of 'important' callers
-$config['group_vip'] = 'VIP';
-
-// base path of USB storage of Fritz!Box under which the path 'FRITZ\fonpix' could be found
-// '' -> use internal fritzbox storage
-//$config['usb_disk'] = 'Generic-FlashDisk-01';
-
-// many version Fritz!Box use 'file:///var/media/ftp/' others 'file:///var/InternerSpeicher/' to check just export an your current phonebook and have a look at any imageURL tag `file:///var/media/ftp/(HERE_config_from:usb_disk)/FRITZ/fonpix/9.jpg`.
-//$config['fritzbox_path'] = 'file:///var/media/ftp/';
-
-// multiple carddav adressbooks could be specified and will be merged together.
-
-// first
-$config['carddav'][0] = array(
- // URL of first CardDAV address book on cloud storage
- 'url' => 'https://raspserver/owncloud/remote.php/carddav/addressbooks/fritzbox/fb_contacts',
- // user name/password for CardDAV access
- 'user' => 'oc_username',
- 'pw' => 'oc_password',
- // vcf extension
- 'extension' => '.vcf'
-);
-
-// second
-//$config['carddav'][1] = array(
-// 'url' => 'https://raspserver/owncloud/remote.php/carddav/addressbooks/fritzbox/fb_contacts_second',
-// 'user' => 'oc_username',
-// 'pw' => 'oc_password',
-// 'extension' => '.vcf'
-//);
+ 'conversions' => [
+ 'vip' => [
+ 'categories' => [
+ 'VIP'
+ ],
+ 'groups' => [
+ 'PERS'
+ ],
+ ],
+ /**
+ * 'realName' conversions are processed consecutively. Order decides!
+ */
+ 'realName' => [
+ '{lastname}, {prefix} {nickname}',
+ '{lastname}, {prefix} {firstname}',
+ '{lastname}, {nickname}',
+ '{lastname}, {firstname}',
+ '{org}',
+ '{fullname}'
+ ],
+ /**
+ * 'phoneTypes':
+ * The order of the target values (first occurrence) determines the sorting of the telephone numbers
+ */
+ 'phoneTypes' => [
+ 'WORK' => 'work',
+ 'HOME' => 'home',
+ 'CELL' => 'mobile',
+ 'FAX' => 'fax_work' // NOTE: actual mapping is ignored but order counts, so fax is put last
+ ],
+ 'emailTypes' => [
+ 'WORK' => 'work',
+ 'HOME' => 'home'
+ ],
+ /**
+ * 'phoneReplaceCharacters' conversions are processed length descending!
+ */
+ 'phoneReplaceCharacters' => [
+ '+49' => '', // router is usually operated in 'DE; '0049' could also be part of a phone number
+ '(' => '',
+ ')' => '',
+ '/' => '',
+ '-' => ''
+ ]
+ ]
+];
diff --git a/docker-entrypoint b/docker-entrypoint
new file mode 100755
index 00000000..145bcae6
--- /dev/null
+++ b/docker-entrypoint
@@ -0,0 +1,27 @@
+#!/bin/sh
+set -e
+
+if [ ! -f "/data/config.php" ] ; then
+ echo "No carddav2fb config found!"
+ cp /srv/config.example.php /data/
+ echo "Copied config.example.php to /data volume. Please edit and rename to config.php"
+ exit 1
+fi
+if [ "$1" == "" ] ; then
+ if [ -f "/data/config.cron" ] ; then
+ . /data/config.cron
+ while true ; do
+ /srv/carddav2fb run $RUN_OPTIONS
+ sleep $INTERVAL
+ done
+ exit 0
+ else
+ echo "No cron config found!"
+ cp /srv/config.example.cron /data/
+ echo "Copied config.example.cron to /data volume. Please edit and rename to config.cron"
+ exit 1
+ fi
+else
+ cd /srv
+ ./carddav2fb $@
+fi
diff --git a/lib/CardDAV-PHP/CHANGELOG b/lib/CardDAV-PHP/CHANGELOG
deleted file mode 100644
index a443275c..00000000
--- a/lib/CardDAV-PHP/CHANGELOG
+++ /dev/null
@@ -1,115 +0,0 @@
-Changes from v0.5.2 to v0.6
-- Added Exception handling
-- Each method now analyzes the http status code on it's own
-- Minor comment, documentation and phpdoc changes
-
-Changes from v0.5.1 to v0.5.2
-- Added debug function
-- Some minor class structure changes
-- Some comment, documentation and phpdoc changes
-
-Changes from v0.5 to v0.5.1
-- Added SOGo to the CardDAV server list
-- Deleted the method get_last_vcard_id() -> the add method does now returns the vCard id
-- Added posibility to get a raw XML vCard response to the get_xml_vcard() method
-- Some comment, documentation and phpdoc changes
-
-Changes from v0.4.9 to v0.5
-- Added SOGo support
-- Special thanks to xbgmsharp for the great feedback!
-- Cache curl connection so that only one authentication process is needed
-- Added boolean return value for add-, edit- and delete-methods
-- Added addressbook handling
-
-Changes from v0.4.8 to v0.4.9
-- New method: clean_vcard
-- New method: get_last_vcard_id
-
-Changes from v0.4.7 to v0.4.8
-- Extended clean_response() method and added utf-encoding
-
-Changes from v0.4.6 to v0.4.7
-- Changed license from LGPLv2 to AGPLv3
-- Changed minor wordings in the changelog
-
-Changes from v0.4.5 to v0.4.6
-- Added "get XML vCard"-method to get a single vCard with more detailed information
-
-Changes from v0.4.4 to v0.4.5
-- Minor comment and class changes
-
-Changes from v0.4.3 to v0.4.4
-- Verified ownCloud support
-- Store username and password for class internal use
-- Cleaned the class
-- Automaticly adds a / at the end of an url if it's missing
-- Added a URL-Schema list
-
-Changes from v0.4.2 to v0.4.3
-- Added sabreDAV support
-
-Changes from v0.4.1 to v0.4.2
-- Standardized "get last modified" seems not to work with every server configuration -> no standardized date anymore!
-
-Changes from v0.4 to v0.4.1
-- Added memotoo support
-- Bugfix: mostly check_connection() returned "true" if the server connection failed
-- Removed unused code
-- Standardized "get last modified" to unix-timestamp
-- Changed version naming
-
-Changes from v0.3.3 to v0.4
-- Switched from "fopen" to curl for all server requests
-- get() uses now PROPFIND instead of REPORT
-- Simplified response additionally returns "get last modified"
-- Added Apple addressbook server support
-
-Changes from v0.3.3 to v0.3.4
-- vCard id returned by get() excludes now the file extension ".vcf"
-
-Changes from v0.3.2 to v0.3.3
-- Minor comment changes
-
-Changes from v0.3.1 to v0.3.2
-- Minor phpdoc changes / extensions
-
-Changes from v0.3 to v0.3.1
-- Get only entries if a vCard id exists
-- Get etag bugfix (PROFIND -> REPORT)
-- vCard id generator bugfix
-- Minor class-structure and comment changes
-
-Changes from v0.2.2 to v0.3
-- Deleted unused methods
-- Added server connection check
-- Added some more examples
-- get() can now return complete vCards
-
-Changes from v0.2.1 to v0.2.2
-- Added error handling
-- Added phpdoc support
-- Cleaned comments / variables
-
-Changes from v0.2 to v0.2.1
-- XML requests will be built by the XMLWriter
-- Added etag to simplified response
-
-Changes from v0.1.2 to v0.2
-- Added add functionality
-- Added update functionality
-- Added get vCard functionality
-- Added user-agent to http-requests
-- Added simplified response
-- Set vCard standard fields (Version, N, FN)
-
-Changes from v0.1.1 to v0.1.2
-- Added delete functionality
-
-Changes from v0.1 to v0.1.1
-- Added filter type (OR / AND)
-
-release v0.1
-- Query CardDAV server with XML response (only tested on davical)
-- Filter functionality for search implementations
-- Fieldsets for minimal vCards within the XML response
-- Authentification
diff --git a/lib/CardDAV-PHP/LICENSE b/lib/CardDAV-PHP/LICENSE
deleted file mode 100644
index 2def0e88..00000000
--- a/lib/CardDAV-PHP/LICENSE
+++ /dev/null
@@ -1,661 +0,0 @@
- GNU AFFERO GENERAL PUBLIC LICENSE
- Version 3, 19 November 2007
-
- Copyright (C) 2007 Free Software Foundation, Inc.
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
- Preamble
-
- The GNU Affero General Public License is a free, copyleft license for
-software and other kinds of works, specifically designed to ensure
-cooperation with the community in the case of network server software.
-
- The licenses for most software and other practical works are designed
-to take away your freedom to share and change the works. By contrast,
-our General Public Licenses are intended to guarantee your freedom to
-share and change all versions of a program--to make sure it remains free
-software for all its users.
-
- When we speak of free software, we are referring to freedom, not
-price. Our General Public Licenses are designed to make sure that you
-have the freedom to distribute copies of free software (and charge for
-them if you wish), that you receive source code or can get it if you
-want it, that you can change the software or use pieces of it in new
-free programs, and that you know you can do these things.
-
- Developers that use our General Public Licenses protect your rights
-with two steps: (1) assert copyright on the software, and (2) offer
-you this License which gives you legal permission to copy, distribute
-and/or modify the software.
-
- A secondary benefit of defending all users' freedom is that
-improvements made in alternate versions of the program, if they
-receive widespread use, become available for other developers to
-incorporate. Many developers of free software are heartened and
-encouraged by the resulting cooperation. However, in the case of
-software used on network servers, this result may fail to come about.
-The GNU General Public License permits making a modified version and
-letting the public access it on a server without ever releasing its
-source code to the public.
-
- The GNU Affero General Public License is designed specifically to
-ensure that, in such cases, the modified source code becomes available
-to the community. It requires the operator of a network server to
-provide the source code of the modified version running there to the
-users of that server. Therefore, public use of a modified version, on
-a publicly accessible server, gives the public access to the source
-code of the modified version.
-
- An older license, called the Affero General Public License and
-published by Affero, was designed to accomplish similar goals. This is
-a different license, not a version of the Affero GPL, but Affero has
-released a new version of the Affero GPL which permits relicensing under
-this license.
-
- The precise terms and conditions for copying, distribution and
-modification follow.
-
- TERMS AND CONDITIONS
-
- 0. Definitions.
-
- "This License" refers to version 3 of the GNU Affero General Public License.
-
- "Copyright" also means copyright-like laws that apply to other kinds of
-works, such as semiconductor masks.
-
- "The Program" refers to any copyrightable work licensed under this
-License. Each licensee is addressed as "you". "Licensees" and
-"recipients" may be individuals or organizations.
-
- To "modify" a work means to copy from or adapt all or part of the work
-in a fashion requiring copyright permission, other than the making of an
-exact copy. The resulting work is called a "modified version" of the
-earlier work or a work "based on" the earlier work.
-
- A "covered work" means either the unmodified Program or a work based
-on the Program.
-
- To "propagate" a work means to do anything with it that, without
-permission, would make you directly or secondarily liable for
-infringement under applicable copyright law, except executing it on a
-computer or modifying a private copy. Propagation includes copying,
-distribution (with or without modification), making available to the
-public, and in some countries other activities as well.
-
- To "convey" a work means any kind of propagation that enables other
-parties to make or receive copies. Mere interaction with a user through
-a computer network, with no transfer of a copy, is not conveying.
-
- An interactive user interface displays "Appropriate Legal Notices"
-to the extent that it includes a convenient and prominently visible
-feature that (1) displays an appropriate copyright notice, and (2)
-tells the user that there is no warranty for the work (except to the
-extent that warranties are provided), that licensees may convey the
-work under this License, and how to view a copy of this License. If
-the interface presents a list of user commands or options, such as a
-menu, a prominent item in the list meets this criterion.
-
- 1. Source Code.
-
- The "source code" for a work means the preferred form of the work
-for making modifications to it. "Object code" means any non-source
-form of a work.
-
- A "Standard Interface" means an interface that either is an official
-standard defined by a recognized standards body, or, in the case of
-interfaces specified for a particular programming language, one that
-is widely used among developers working in that language.
-
- The "System Libraries" of an executable work include anything, other
-than the work as a whole, that (a) is included in the normal form of
-packaging a Major Component, but which is not part of that Major
-Component, and (b) serves only to enable use of the work with that
-Major Component, or to implement a Standard Interface for which an
-implementation is available to the public in source code form. A
-"Major Component", in this context, means a major essential component
-(kernel, window system, and so on) of the specific operating system
-(if any) on which the executable work runs, or a compiler used to
-produce the work, or an object code interpreter used to run it.
-
- The "Corresponding Source" for a work in object code form means all
-the source code needed to generate, install, and (for an executable
-work) run the object code and to modify the work, including scripts to
-control those activities. However, it does not include the work's
-System Libraries, or general-purpose tools or generally available free
-programs which are used unmodified in performing those activities but
-which are not part of the work. For example, Corresponding Source
-includes interface definition files associated with source files for
-the work, and the source code for shared libraries and dynamically
-linked subprograms that the work is specifically designed to require,
-such as by intimate data communication or control flow between those
-subprograms and other parts of the work.
-
- The Corresponding Source need not include anything that users
-can regenerate automatically from other parts of the Corresponding
-Source.
-
- The Corresponding Source for a work in source code form is that
-same work.
-
- 2. Basic Permissions.
-
- All rights granted under this License are granted for the term of
-copyright on the Program, and are irrevocable provided the stated
-conditions are met. This License explicitly affirms your unlimited
-permission to run the unmodified Program. The output from running a
-covered work is covered by this License only if the output, given its
-content, constitutes a covered work. This License acknowledges your
-rights of fair use or other equivalent, as provided by copyright law.
-
- You may make, run and propagate covered works that you do not
-convey, without conditions so long as your license otherwise remains
-in force. You may convey covered works to others for the sole purpose
-of having them make modifications exclusively for you, or provide you
-with facilities for running those works, provided that you comply with
-the terms of this License in conveying all material for which you do
-not control copyright. Those thus making or running the covered works
-for you must do so exclusively on your behalf, under your direction
-and control, on terms that prohibit them from making any copies of
-your copyrighted material outside their relationship with you.
-
- Conveying under any other circumstances is permitted solely under
-the conditions stated below. Sublicensing is not allowed; section 10
-makes it unnecessary.
-
- 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
-
- No covered work shall be deemed part of an effective technological
-measure under any applicable law fulfilling obligations under article
-11 of the WIPO copyright treaty adopted on 20 December 1996, or
-similar laws prohibiting or restricting circumvention of such
-measures.
-
- When you convey a covered work, you waive any legal power to forbid
-circumvention of technological measures to the extent such circumvention
-is effected by exercising rights under this License with respect to
-the covered work, and you disclaim any intention to limit operation or
-modification of the work as a means of enforcing, against the work's
-users, your or third parties' legal rights to forbid circumvention of
-technological measures.
-
- 4. Conveying Verbatim Copies.
-
- You may convey verbatim copies of the Program's source code as you
-receive it, in any medium, provided that you conspicuously and
-appropriately publish on each copy an appropriate copyright notice;
-keep intact all notices stating that this License and any
-non-permissive terms added in accord with section 7 apply to the code;
-keep intact all notices of the absence of any warranty; and give all
-recipients a copy of this License along with the Program.
-
- You may charge any price or no price for each copy that you convey,
-and you may offer support or warranty protection for a fee.
-
- 5. Conveying Modified Source Versions.
-
- You may convey a work based on the Program, or the modifications to
-produce it from the Program, in the form of source code under the
-terms of section 4, provided that you also meet all of these conditions:
-
- a) The work must carry prominent notices stating that you modified
- it, and giving a relevant date.
-
- b) The work must carry prominent notices stating that it is
- released under this License and any conditions added under section
- 7. This requirement modifies the requirement in section 4 to
- "keep intact all notices".
-
- c) You must license the entire work, as a whole, under this
- License to anyone who comes into possession of a copy. This
- License will therefore apply, along with any applicable section 7
- additional terms, to the whole of the work, and all its parts,
- regardless of how they are packaged. This License gives no
- permission to license the work in any other way, but it does not
- invalidate such permission if you have separately received it.
-
- d) If the work has interactive user interfaces, each must display
- Appropriate Legal Notices; however, if the Program has interactive
- interfaces that do not display Appropriate Legal Notices, your
- work need not make them do so.
-
- A compilation of a covered work with other separate and independent
-works, which are not by their nature extensions of the covered work,
-and which are not combined with it such as to form a larger program,
-in or on a volume of a storage or distribution medium, is called an
-"aggregate" if the compilation and its resulting copyright are not
-used to limit the access or legal rights of the compilation's users
-beyond what the individual works permit. Inclusion of a covered work
-in an aggregate does not cause this License to apply to the other
-parts of the aggregate.
-
- 6. Conveying Non-Source Forms.
-
- You may convey a covered work in object code form under the terms
-of sections 4 and 5, provided that you also convey the
-machine-readable Corresponding Source under the terms of this License,
-in one of these ways:
-
- a) Convey the object code in, or embodied in, a physical product
- (including a physical distribution medium), accompanied by the
- Corresponding Source fixed on a durable physical medium
- customarily used for software interchange.
-
- b) Convey the object code in, or embodied in, a physical product
- (including a physical distribution medium), accompanied by a
- written offer, valid for at least three years and valid for as
- long as you offer spare parts or customer support for that product
- model, to give anyone who possesses the object code either (1) a
- copy of the Corresponding Source for all the software in the
- product that is covered by this License, on a durable physical
- medium customarily used for software interchange, for a price no
- more than your reasonable cost of physically performing this
- conveying of source, or (2) access to copy the
- Corresponding Source from a network server at no charge.
-
- c) Convey individual copies of the object code with a copy of the
- written offer to provide the Corresponding Source. This
- alternative is allowed only occasionally and noncommercially, and
- only if you received the object code with such an offer, in accord
- with subsection 6b.
-
- d) Convey the object code by offering access from a designated
- place (gratis or for a charge), and offer equivalent access to the
- Corresponding Source in the same way through the same place at no
- further charge. You need not require recipients to copy the
- Corresponding Source along with the object code. If the place to
- copy the object code is a network server, the Corresponding Source
- may be on a different server (operated by you or a third party)
- that supports equivalent copying facilities, provided you maintain
- clear directions next to the object code saying where to find the
- Corresponding Source. Regardless of what server hosts the
- Corresponding Source, you remain obligated to ensure that it is
- available for as long as needed to satisfy these requirements.
-
- e) Convey the object code using peer-to-peer transmission, provided
- you inform other peers where the object code and Corresponding
- Source of the work are being offered to the general public at no
- charge under subsection 6d.
-
- A separable portion of the object code, whose source code is excluded
-from the Corresponding Source as a System Library, need not be
-included in conveying the object code work.
-
- A "User Product" is either (1) a "consumer product", which means any
-tangible personal property which is normally used for personal, family,
-or household purposes, or (2) anything designed or sold for incorporation
-into a dwelling. In determining whether a product is a consumer product,
-doubtful cases shall be resolved in favor of coverage. For a particular
-product received by a particular user, "normally used" refers to a
-typical or common use of that class of product, regardless of the status
-of the particular user or of the way in which the particular user
-actually uses, or expects or is expected to use, the product. A product
-is a consumer product regardless of whether the product has substantial
-commercial, industrial or non-consumer uses, unless such uses represent
-the only significant mode of use of the product.
-
- "Installation Information" for a User Product means any methods,
-procedures, authorization keys, or other information required to install
-and execute modified versions of a covered work in that User Product from
-a modified version of its Corresponding Source. The information must
-suffice to ensure that the continued functioning of the modified object
-code is in no case prevented or interfered with solely because
-modification has been made.
-
- If you convey an object code work under this section in, or with, or
-specifically for use in, a User Product, and the conveying occurs as
-part of a transaction in which the right of possession and use of the
-User Product is transferred to the recipient in perpetuity or for a
-fixed term (regardless of how the transaction is characterized), the
-Corresponding Source conveyed under this section must be accompanied
-by the Installation Information. But this requirement does not apply
-if neither you nor any third party retains the ability to install
-modified object code on the User Product (for example, the work has
-been installed in ROM).
-
- The requirement to provide Installation Information does not include a
-requirement to continue to provide support service, warranty, or updates
-for a work that has been modified or installed by the recipient, or for
-the User Product in which it has been modified or installed. Access to a
-network may be denied when the modification itself materially and
-adversely affects the operation of the network or violates the rules and
-protocols for communication across the network.
-
- Corresponding Source conveyed, and Installation Information provided,
-in accord with this section must be in a format that is publicly
-documented (and with an implementation available to the public in
-source code form), and must require no special password or key for
-unpacking, reading or copying.
-
- 7. Additional Terms.
-
- "Additional permissions" are terms that supplement the terms of this
-License by making exceptions from one or more of its conditions.
-Additional permissions that are applicable to the entire Program shall
-be treated as though they were included in this License, to the extent
-that they are valid under applicable law. If additional permissions
-apply only to part of the Program, that part may be used separately
-under those permissions, but the entire Program remains governed by
-this License without regard to the additional permissions.
-
- When you convey a copy of a covered work, you may at your option
-remove any additional permissions from that copy, or from any part of
-it. (Additional permissions may be written to require their own
-removal in certain cases when you modify the work.) You may place
-additional permissions on material, added by you to a covered work,
-for which you have or can give appropriate copyright permission.
-
- Notwithstanding any other provision of this License, for material you
-add to a covered work, you may (if authorized by the copyright holders of
-that material) supplement the terms of this License with terms:
-
- a) Disclaiming warranty or limiting liability differently from the
- terms of sections 15 and 16 of this License; or
-
- b) Requiring preservation of specified reasonable legal notices or
- author attributions in that material or in the Appropriate Legal
- Notices displayed by works containing it; or
-
- c) Prohibiting misrepresentation of the origin of that material, or
- requiring that modified versions of such material be marked in
- reasonable ways as different from the original version; or
-
- d) Limiting the use for publicity purposes of names of licensors or
- authors of the material; or
-
- e) Declining to grant rights under trademark law for use of some
- trade names, trademarks, or service marks; or
-
- f) Requiring indemnification of licensors and authors of that
- material by anyone who conveys the material (or modified versions of
- it) with contractual assumptions of liability to the recipient, for
- any liability that these contractual assumptions directly impose on
- those licensors and authors.
-
- All other non-permissive additional terms are considered "further
-restrictions" within the meaning of section 10. If the Program as you
-received it, or any part of it, contains a notice stating that it is
-governed by this License along with a term that is a further
-restriction, you may remove that term. If a license document contains
-a further restriction but permits relicensing or conveying under this
-License, you may add to a covered work material governed by the terms
-of that license document, provided that the further restriction does
-not survive such relicensing or conveying.
-
- If you add terms to a covered work in accord with this section, you
-must place, in the relevant source files, a statement of the
-additional terms that apply to those files, or a notice indicating
-where to find the applicable terms.
-
- Additional terms, permissive or non-permissive, may be stated in the
-form of a separately written license, or stated as exceptions;
-the above requirements apply either way.
-
- 8. Termination.
-
- You may not propagate or modify a covered work except as expressly
-provided under this License. Any attempt otherwise to propagate or
-modify it is void, and will automatically terminate your rights under
-this License (including any patent licenses granted under the third
-paragraph of section 11).
-
- However, if you cease all violation of this License, then your
-license from a particular copyright holder is reinstated (a)
-provisionally, unless and until the copyright holder explicitly and
-finally terminates your license, and (b) permanently, if the copyright
-holder fails to notify you of the violation by some reasonable means
-prior to 60 days after the cessation.
-
- Moreover, your license from a particular copyright holder is
-reinstated permanently if the copyright holder notifies you of the
-violation by some reasonable means, this is the first time you have
-received notice of violation of this License (for any work) from that
-copyright holder, and you cure the violation prior to 30 days after
-your receipt of the notice.
-
- Termination of your rights under this section does not terminate the
-licenses of parties who have received copies or rights from you under
-this License. If your rights have been terminated and not permanently
-reinstated, you do not qualify to receive new licenses for the same
-material under section 10.
-
- 9. Acceptance Not Required for Having Copies.
-
- You are not required to accept this License in order to receive or
-run a copy of the Program. Ancillary propagation of a covered work
-occurring solely as a consequence of using peer-to-peer transmission
-to receive a copy likewise does not require acceptance. However,
-nothing other than this License grants you permission to propagate or
-modify any covered work. These actions infringe copyright if you do
-not accept this License. Therefore, by modifying or propagating a
-covered work, you indicate your acceptance of this License to do so.
-
- 10. Automatic Licensing of Downstream Recipients.
-
- Each time you convey a covered work, the recipient automatically
-receives a license from the original licensors, to run, modify and
-propagate that work, subject to this License. You are not responsible
-for enforcing compliance by third parties with this License.
-
- An "entity transaction" is a transaction transferring control of an
-organization, or substantially all assets of one, or subdividing an
-organization, or merging organizations. If propagation of a covered
-work results from an entity transaction, each party to that
-transaction who receives a copy of the work also receives whatever
-licenses to the work the party's predecessor in interest had or could
-give under the previous paragraph, plus a right to possession of the
-Corresponding Source of the work from the predecessor in interest, if
-the predecessor has it or can get it with reasonable efforts.
-
- You may not impose any further restrictions on the exercise of the
-rights granted or affirmed under this License. For example, you may
-not impose a license fee, royalty, or other charge for exercise of
-rights granted under this License, and you may not initiate litigation
-(including a cross-claim or counterclaim in a lawsuit) alleging that
-any patent claim is infringed by making, using, selling, offering for
-sale, or importing the Program or any portion of it.
-
- 11. Patents.
-
- A "contributor" is a copyright holder who authorizes use under this
-License of the Program or a work on which the Program is based. The
-work thus licensed is called the contributor's "contributor version".
-
- A contributor's "essential patent claims" are all patent claims
-owned or controlled by the contributor, whether already acquired or
-hereafter acquired, that would be infringed by some manner, permitted
-by this License, of making, using, or selling its contributor version,
-but do not include claims that would be infringed only as a
-consequence of further modification of the contributor version. For
-purposes of this definition, "control" includes the right to grant
-patent sublicenses in a manner consistent with the requirements of
-this License.
-
- Each contributor grants you a non-exclusive, worldwide, royalty-free
-patent license under the contributor's essential patent claims, to
-make, use, sell, offer for sale, import and otherwise run, modify and
-propagate the contents of its contributor version.
-
- In the following three paragraphs, a "patent license" is any express
-agreement or commitment, however denominated, not to enforce a patent
-(such as an express permission to practice a patent or covenant not to
-sue for patent infringement). To "grant" such a patent license to a
-party means to make such an agreement or commitment not to enforce a
-patent against the party.
-
- If you convey a covered work, knowingly relying on a patent license,
-and the Corresponding Source of the work is not available for anyone
-to copy, free of charge and under the terms of this License, through a
-publicly available network server or other readily accessible means,
-then you must either (1) cause the Corresponding Source to be so
-available, or (2) arrange to deprive yourself of the benefit of the
-patent license for this particular work, or (3) arrange, in a manner
-consistent with the requirements of this License, to extend the patent
-license to downstream recipients. "Knowingly relying" means you have
-actual knowledge that, but for the patent license, your conveying the
-covered work in a country, or your recipient's use of the covered work
-in a country, would infringe one or more identifiable patents in that
-country that you have reason to believe are valid.
-
- If, pursuant to or in connection with a single transaction or
-arrangement, you convey, or propagate by procuring conveyance of, a
-covered work, and grant a patent license to some of the parties
-receiving the covered work authorizing them to use, propagate, modify
-or convey a specific copy of the covered work, then the patent license
-you grant is automatically extended to all recipients of the covered
-work and works based on it.
-
- A patent license is "discriminatory" if it does not include within
-the scope of its coverage, prohibits the exercise of, or is
-conditioned on the non-exercise of one or more of the rights that are
-specifically granted under this License. You may not convey a covered
-work if you are a party to an arrangement with a third party that is
-in the business of distributing software, under which you make payment
-to the third party based on the extent of your activity of conveying
-the work, and under which the third party grants, to any of the
-parties who would receive the covered work from you, a discriminatory
-patent license (a) in connection with copies of the covered work
-conveyed by you (or copies made from those copies), or (b) primarily
-for and in connection with specific products or compilations that
-contain the covered work, unless you entered into that arrangement,
-or that patent license was granted, prior to 28 March 2007.
-
- Nothing in this License shall be construed as excluding or limiting
-any implied license or other defenses to infringement that may
-otherwise be available to you under applicable patent law.
-
- 12. No Surrender of Others' Freedom.
-
- If conditions are imposed on you (whether by court order, agreement or
-otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License. If you cannot convey a
-covered work so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you may
-not convey it at all. For example, if you agree to terms that obligate you
-to collect a royalty for further conveying from those to whom you convey
-the Program, the only way you could satisfy both those terms and this
-License would be to refrain entirely from conveying the Program.
-
- 13. Remote Network Interaction; Use with the GNU General Public License.
-
- Notwithstanding any other provision of this License, if you modify the
-Program, your modified version must prominently offer all users
-interacting with it remotely through a computer network (if your version
-supports such interaction) an opportunity to receive the Corresponding
-Source of your version by providing access to the Corresponding Source
-from a network server at no charge, through some standard or customary
-means of facilitating copying of software. This Corresponding Source
-shall include the Corresponding Source for any work covered by version 3
-of the GNU General Public License that is incorporated pursuant to the
-following paragraph.
-
- Notwithstanding any other provision of this License, you have
-permission to link or combine any covered work with a work licensed
-under version 3 of the GNU General Public License into a single
-combined work, and to convey the resulting work. The terms of this
-License will continue to apply to the part which is the covered work,
-but the work with which it is combined will remain governed by version
-3 of the GNU General Public License.
-
- 14. Revised Versions of this License.
-
- The Free Software Foundation may publish revised and/or new versions of
-the GNU Affero General Public License from time to time. Such new versions
-will be similar in spirit to the present version, but may differ in detail to
-address new problems or concerns.
-
- Each version is given a distinguishing version number. If the
-Program specifies that a certain numbered version of the GNU Affero General
-Public License "or any later version" applies to it, you have the
-option of following the terms and conditions either of that numbered
-version or of any later version published by the Free Software
-Foundation. If the Program does not specify a version number of the
-GNU Affero General Public License, you may choose any version ever published
-by the Free Software Foundation.
-
- If the Program specifies that a proxy can decide which future
-versions of the GNU Affero General Public License can be used, that proxy's
-public statement of acceptance of a version permanently authorizes you
-to choose that version for the Program.
-
- Later license versions may give you additional or different
-permissions. However, no additional obligations are imposed on any
-author or copyright holder as a result of your choosing to follow a
-later version.
-
- 15. Disclaimer of Warranty.
-
- THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
-APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
-HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
-OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
-THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
-IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
-ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
-
- 16. Limitation of Liability.
-
- IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
-THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
-GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
-USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
-DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
-PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
-EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
-SUCH DAMAGES.
-
- 17. Interpretation of Sections 15 and 16.
-
- If the disclaimer of warranty and limitation of liability provided
-above cannot be given local legal effect according to their terms,
-reviewing courts shall apply local law that most closely approximates
-an absolute waiver of all civil liability in connection with the
-Program, unless a warranty or assumption of liability accompanies a
-copy of the Program in return for a fee.
-
- END OF TERMS AND CONDITIONS
-
- How to Apply These Terms to Your New Programs
-
- If you develop a new program, and you want it to be of the greatest
-possible use to the public, the best way to achieve this is to make it
-free software which everyone can redistribute and change under these terms.
-
- To do so, attach the following notices to the program. It is safest
-to attach them to the start of each source file to most effectively
-state the exclusion of warranty; and each file should have at least
-the "copyright" line and a pointer to where the full notice is found.
-
-
- Copyright (C)
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program 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 Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see .
-
-Also add information on how to contact you by electronic and paper mail.
-
- If your software can interact with users remotely through a computer
-network, you should also make sure that it provides a way for users to
-get its source. For example, if your program is a web application, its
-interface could display a "Source" link that leads users to an archive
-of the code. There are many ways you could offer source, and different
-solutions will be better for different programs; see section 13 for the
-specific requirements.
-
- You should also get your employer (if you work as a programmer) or school,
-if any, to sign a "copyright disclaimer" for the program, if necessary.
-For more information on this, and how to apply and follow the GNU AGPL, see
-.
\ No newline at end of file
diff --git a/lib/CardDAV-PHP/README.md b/lib/CardDAV-PHP/README.md
deleted file mode 100644
index fbafef66..00000000
--- a/lib/CardDAV-PHP/README.md
+++ /dev/null
@@ -1,33 +0,0 @@
-Description
------------
-This is a simple CardDAV client written in PHP called "CardDAV PHP".
-
-
-Features
---------
-* Query your CardDAV server with XML response (simplified or raw)
-* Supports many authentication methods
-* You can add / update / delete vCards from your CardDAV server
-* Get single vCards (raw or extended XML) from your CardDAV server
-* Check CardDAV server connection
-* Tested CardDAV servers: DAViCal, Apple Addressbook Server, memotoo, SabreDAV, ownCloud, SOGo
-
-
-Installation
-------------
-* Nothing to install - it's standalone
-* Requires PHP 5.3 and CURL
-* The documentation can be found in the class itself
-
-
-Special thanks
---------------
-* xbgmsharp for the great feedback!
-
-
-Contact
--------
-* Author: Christian Putzke
-* Report feature requests and bugs here: https://github.com/graviox/CardDAV-PHP/issues
-* Visit my website: http://www.graviox.de/
-* Follow me on Twitter: https://twitter.com/cputzke/
\ No newline at end of file
diff --git a/lib/CardDAV-PHP/carddav.php b/lib/CardDAV-PHP/carddav.php
deleted file mode 100644
index 405a051e..00000000
--- a/lib/CardDAV-PHP/carddav.php
+++ /dev/null
@@ -1,769 +0,0 @@
-setAuth('username', 'password');
- * echo $carddav->get();
- *
- *
- * Simple vCard query
- * ------------------
- * $carddav = new CardDavBackend('https://davical.example.com/user/contacts/');
- * $carddav->setAuth('username', 'password');
- * echo $carddav->getVcard('0126FFB4-2EB74D0A-302EA17F');
- *
- *
- * XML vCard query
- * ------------------
- * $carddav = new CardDavBackend('https://davical.example.com/user/contacts/');
- * $carddav->setAuth('username', 'password');
- * echo $carddav->getXmlVcard('0126FFB4-2EB74D0A-302EA17F');
- *
- *
- * Check CardDAV server connection
- * -------------------------------
- * $carddav = new CardDavBackend('https://davical.example.com/user/contacts/');
- * $carddav->setAuth('username', 'password');
- * var_dump($carddav->checkConnection());
- *
- *
- * CardDAV delete query
- * --------------------
- * $carddav = new CardDavBackend('https://davical.example.com/user/contacts/');
- * $carddav->setAuth('username', 'password');
- * $carddav->delete('0126FFB4-2EB74D0A-302EA17F');
- *
- *
- * CardDAV add query
- * --------------------
- * $vcard = 'BEGIN:VCARD
- * VERSION:3.0
- * UID:1f5ea45f-b28a-4b96-25as-ed4f10edf57b
- * FN:Christian Putzke
- * N:Christian;Putzke;;;
- * EMAIL;TYPE=OTHER:christian.putzke@graviox.de
- * END:VCARD';
- *
- * $carddav = new CardDavBackend('https://davical.example.com/user/contacts/');
- * $carddav->setAuth('username', 'password');
- * $vcard_id = $carddav->add($vcard);
- *
- *
- * CardDAV update query
- * --------------------
- * $vcard = 'BEGIN:VCARD
- * VERSION:3.0
- * UID:1f5ea45f-b28a-4b96-25as-ed4f10edf57b
- * FN:Christian Putzke
- * N:Christian;Putzke;;;
- * EMAIL;TYPE=OTHER:christian.putzke@graviox.de
- * END:VCARD';
- *
- * $carddav = new CardDavBackend('https://davical.example.com/user/contacts/');
- * $carddav->setAuth('username', 'password');
- * $carddav->update($vcard, '0126FFB4-2EB74D0A-302EA17F');
- *
- *
- * CardDAV debug
- * -------------
- * $carddav = new CardDavBackend('https://davical.example.com/user/contacts/');
- * $carddav->enableDebug();
- * $carddav->setAuth('username', 'password');
- * $carddav->get();
- * var_dump($carddav->getDebug());
- *
- *
- * CardDAV server list
- * -------------------
- * DAViCal: https://example.com/{resource|principal|username}/{collection}/
- * Apple Addressbook Server: https://example.com/addressbooks/users/{resource|principal|username}/{collection}/
- * memotoo: https://sync.memotoo.com/cardDAV/
- * SabreDAV: https://example.com/addressbooks/{resource|principal|username}/{collection}/
- * ownCloud: https://example.com/apps/contacts/carddav.php/addressbooks/{resource|principal|username}/{collection}/
- * SOGo: https://example.com/SOGo/dav/{resource|principal|username}/Contacts/{collection}/
- * Google (direct): https://google.com/m8/carddav/principals/__uids__/{username}/lists/default/
- *
- *
- * @author Christian Putzke
- * @copyright Christian Putzke
- * @link http://www.graviox.de/
- * @link https://twitter.com/cputzke/
- * @since 24.05.2015
- * @version 0.7
- * @license http://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
- *
- */
-
-class CardDavBackend
-{
- /**
- * CardDAV PHP Version
- *
- * @constant string
- */
- const VERSION = '0.7';
-
- /**
- * User agent displayed in http requests
- *
- * @constant string
- */
- const USERAGENT = 'CardDAV PHP/';
-
- /**
- * CardDAV server url
- *
- * @var string
- */
- private $url = null;
-
- /**
- * CardDAV server url_parts
- *
- * @var array
- */
- private $url_parts = null;
-
- /**
- * VCard File URL Extension
- *
- * @var string
- */
- private $url_vcard_extension = '.vcf';
-
- /**
- * Authentication string
- *
- * @var string
- */
- private $auth = null;
-
- /**
- * Authentication: username
- *
- * @var string
- */
- private $username = null;
-
- /**
- * Authentication: password
- *
- * @var string
- */
- private $password = null;
-
- /**
- * Characters used for vCard id generation
- *
- * @var array
- */
- private $vcard_id_chars = array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'A', 'B', 'C', 'D', 'E', 'F');
-
- /**
- * CardDAV server connection (curl handle)
- *
- * @var resource
- */
- private $curl;
-
- /**
- * Follow redirects (Location Header)
- *
- * @var boolean
- */
- private $follow_redirects = true;
-
- /**
- * Maximum redirects to follow
- *
- * @var integer
- */
- private $follow_redirects_count = 3;
-
- /**
- * Debug on or off
- *
- * @var boolean
- */
- private $debug = false;
-
- /**
- * All available debug information
- *
- * @var array
- */
- private $debug_information = array();
-
- /**
- * Exception codes
- */
- const EXCEPTION_WRONG_HTTP_STATUS_CODE_GET = 1000;
- const EXCEPTION_WRONG_HTTP_STATUS_CODE_GET_VCARD = 1001;
- const EXCEPTION_WRONG_HTTP_STATUS_CODE_GET_XML_VCARD = 1002;
- const EXCEPTION_WRONG_HTTP_STATUS_CODE_DELETE = 1003;
- const EXCEPTION_WRONG_HTTP_STATUS_CODE_ADD = 1004;
- const EXCEPTION_WRONG_HTTP_STATUS_CODE_UPDATE = 1005;
- const EXCEPTION_MALFORMED_XML_RESPONSE = 1006;
- const EXCEPTION_COULD_NOT_GENERATE_NEW_VCARD_ID = 1007;
-
-
- /**
- * Constructor
- * Sets the CardDAV server url
- *
- * @param string $url CardDAV server url
- */
- public function __construct($url = null)
- {
- if ($url !== null) {
- $this->setUrl($url);
- }
- }
-
- /**
- * Sets debug information
- *
- * @param array $debug_information Debug information
- * @return void
- */
- public function setDebug(array $debug_information)
- {
- $this->debug_information[] = $debug_information;
- }
-
- /**
- * Sets the CardDAV server url
- *
- * @param string $url CardDAV server url
- * @return void
- */
- public function setUrl($url)
- {
- $this->url = $url;
-
- if (substr($this->url, -1, 1) !== '/') {
- $this->url = $this->url . '/';
- }
-
- $this->url_parts = parse_url($this->url);
-
- // workaround for providers that don't use the default .vcf extension
- if (strpos($this->url, "google.com"))
- {
- $this->setVcardExtension("");
- }
- }
-
- /**
- * Sets the CardDAV vcard url extension
- *
- * Most providers do requests handling Vcards with .vcf, however
- * this isn't always the case and some providers (such as Google)
- * returned a 404 if the .vcf extension is used - or the other
- * way around, returning 404 unless .vcf is used.
- *
- * Both approaches are technically correct, see rfc635
- * http://tools.ietf.org/html/rfc6352
- *
- *
- * @param string $extension File extension
- * @return void
- */
- public function setVcardExtension($extension)
- {
- $this->url_vcard_extension = $extension;
- }
-
- /**
- * Sets authentication information
- *
- * @param string $username CardDAV server username
- * @param string $password CardDAV server password
- * @return void
- */
- public function setAuth($username, $password)
- {
- $this->username = $username;
- $this->password = $password;
- $this->auth = $username . ':' . $password;
- }
-
- /**
- * Sets wether to follow redirects and if yes how often
- *
- * @param boolean $follow_redirects
- * @param integer $follow_redirects_count
- * @return void
- */
- public function setFollowRedirects($follow_redirects, $follow_redirects_count = 3)
- {
- $this->follow_redirects = $follow_redirects && $follow_redirects_count > 0;
- $this->follow_redirects_count = $follow_redirects_count > 0 ? $follow_redirects_count : 0;
- }
-
- /**
- * Gets all available debug information
- *
- * @return array $this->debug_information All available debug information
- */
- public function getDebug()
- {
- return $this->debug_information;
- }
-
- /**
- * Gets all vCards including additional information from the CardDAV server
- *
- * @param boolean $include_vcards Include vCards within the response (simplified only)
- * @param boolean $raw Get response raw or simplified
- * @return string Raw or simplified XML response
- */
- public function get($include_vcards = true, $raw = false)
- {
- // for owncloud&co. Doesn't work with OpenXchange/Appsuite
- $result = $this->query($this->url, 'PROPFIND');
-
- // for OpenXchange/Appsuite
- $content = '';
- $content_type = 'application/xml';
- //$result = $this->query($this->url, 'REPORT', $content, $content_type);
-
- // DEBUG: print the response of the carddav-server
- //print_r($result);
-
- switch ($result['http_code'])
- {
- case 200:
- case 207:
- if ($raw === true) {
- return $result['response'];
- } else {
- return $this->simplify($result['response'], $include_vcards);
- }
- }
-
- throw new \Exception(
- "Woops, something's gone wrong! The CardDAV server returned the http status code {$result['http_code']}.",
- self::EXCEPTION_WRONG_HTTP_STATUS_CODE_GET
- );
-
- }
-
- /**
- * Gets a clean vCard from the CardDAV server
- *
- * @param string $vcard_id vCard id on the CardDAV server
- * @return string vCard (text/vcard)
- */
- public function getVcard($vcard_id)
- {
- $vcard_id = str_replace($this->url_vcard_extension, null, $vcard_id);
- $result = $this->query($this->url . $vcard_id . $this->url_vcard_extension, 'GET');
-
- // DEBUG: print the response of the carddav-server
- // print_r($result);
-
- switch ($result['http_code'])
- {
- case 404:
- $altResult = $this->query($this->url . $vcard_id , 'GET');
- // DEBUG: print the response of the carddav-server
- // print_r($altResult);
- switch ($altResult['http_code'])
- {
- case 200:
- case 207:
- print "Ignoring given Vcard Extension (".$this->url_vcard_extension.")" . PHP_EOL. ".";
- $this->setVcardExtension("");
- return $altResult['response'];
- }
- throw new \Exception(
- "Woops, something's gone wrong! The CardDAV server returned the http status code {$result['http_code']}:{$result['response']}:{$vcard_id}.",
- self::EXCEPTION_WRONG_HTTP_STATUS_CODE_GET_VCARD
- );
-
- case 200:
- case 207:
- print ".";
- return $result['response'];
- }
-
- throw new \Exception(
- "Woops, something's gone wrong! The CardDAV server returned the http status code {$result['http_code']}:{$result['response']}:{$vcard_id}.",
- self::EXCEPTION_WRONG_HTTP_STATUS_CODE_GET_VCARD
- );
- }
-
- /**
- * Gets a vCard + XML from the CardDAV Server
- *
- * @param string $vcard_id vCard id on the CardDAV Server
- * @return string Raw or simplified vCard (text/xml)
- */
- public function getXmlVcard($vcard_id)
- {
- $vcard_id = str_replace($this->url_vcard_extension, null, $vcard_id);
-
- $xml = new XMLWriter();
- $xml->openMemory();
- $xml->setIndent(4);
- $xml->startDocument('1.0', 'utf-8');
- $xml->startElement('C:addressbook-multiget');
- $xml->writeAttribute('xmlns:D', 'DAV:');
- $xml->writeAttribute('xmlns:C', 'urn:ietf:params:xml:ns:carddav');
- $xml->startElement('D:prop');
- $xml->writeElement('D:getetag');
- $xml->writeElement('D:getlastmodified');
- $xml->endElement();
- $xml->writeElement('D:href', $this->url_parts['path'] . $vcard_id . $this->url_vcard_extension);
- $xml->endElement();
- $xml->endDocument();
-
- $result = $this->query($this->url, 'REPORT', $xml->outputMemory(), 'text/xml');
-
- switch ($result['http_code'])
- {
- case 200:
- case 207:
- return $this->simplify($result['response'], true);
-
- }
-
- throw new \Exception(
- "Woops, something's gone wrong! The CardDAV server returned the http status code {$result['http_code']}.",
- self::EXCEPTION_WRONG_HTTP_STATUS_CODE_GET_XML_VCARD
- );
- }
-
- /**
- * Enables the debug mode
- *
- * @return void
- */
- public function enableDebug()
- {
- $this->debug = true;
- }
-
- /**
- * Checks if the CardDAV server is reachable
- *
- * @return boolean
- */
- public function checkConnection()
- {
- $result = $this->query($this->url, 'OPTIONS');
-
- if ($result['http_code'] === 200) {
- return true;
- } else {
- return false;
- }
- }
-
- /**
- * Cleans the vCard
- *
- * @param string $vcard vCard
- * @return string $vcard vCard
- */
- private function cleanVcard($vcard)
- {
- $vcard = str_replace("\t", null, $vcard);
-
- return $vcard;
- }
-
- /**
- * Deletes an entry from the CardDAV server
- *
- * @param string $vcard_id vCard id on the CardDAV server
- * @return boolean
- */
- public function delete($vcard_id)
- {
- $result = $this->query($this->url . $vcard_id . $this->url_vcard_extension, 'DELETE');
-
- switch ($result['http_code'])
- {
- case 204:
- return true;
- }
-
- throw new \Exception(
- "Woops, something's gone wrong! The CardDAV server returned the http status code {$result['http_code']}.",
- self::EXCEPTION_WRONG_HTTP_STATUS_CODE_DELETE
- );
- }
-
- /**
- * Adds an entry to the CardDAV server
- *
- * @param string $vcard vCard
- * @param string $vcard_id vCard id on the CardDAV server
- * @return string The new vCard id
- */
- public function add($vcard, $vcard_id = null)
- {
- if ($vcard_id === null) {
- $vcard_id = $this->generateVcardId();
- }
- $vcard = $this->cleanVcard($vcard);
- $result = $this->query($this->url . $vcard_id . $this->url_vcard_extension, 'PUT', $vcard, 'text/vcard');
-
- switch($result['http_code'])
- {
- case 201:
- return $vcard_id;
- }
-
- throw new \Exception(
- "Woops, something's gone wrong! The CardDAV server returned the http status code {$result['http_code']}.",
- self::EXCEPTION_WRONG_HTTP_STATUS_CODE_ADD
- );
- }
-
- /**
- * Updates an entry to the CardDAV server
- *
- * @param string $vcard vCard
- * @param string $vcard_id vCard id on the CardDAV server
- * @return boolean
- */
- public function update($vcard, $vcard_id)
- {
- try {
- return $this->add($vcard, $vcard_id);
- } catch (Exception $e) {
- throw new \Exception($e->getMessage(), self::EXCEPTION_WRONG_HTTP_STATUS_CODE_UPDATE);
- }
- }
-
- /**
- * Simplify CardDAV XML response
- *
- * @param string $response CardDAV XML response
- * @param boolean $include_vcards Include vCards or not
- * @return string Simplified CardDAV XML response
- */
- private function simplify($response, $include_vcards = true)
- {
- $response = $this->cleanResponse($response);
-
- try {
- $xml = new \SimpleXMLElement($response);
- } catch (Exception $e) {
- throw new \Exception(
- "The XML response seems to be malformed and can't be simplified!",
- self::EXCEPTION_MALFORMED_XML_RESPONSE,
- $e
- );
- }
-
- $simplified_xml = new \XMLWriter();
- $simplified_xml->openMemory();
- $simplified_xml->setIndent(4);
-
- $simplified_xml->startDocument('1.0', 'utf-8');
- $simplified_xml->startElement('response');
-
- if (!empty($xml->response)) {
- foreach ($xml->response as $response) {
- if ((preg_match('/vcard/', $response->propstat->prop->getcontenttype) || preg_match('/vcf/', $response->href)) &&
- !$response->propstat->prop->resourcetype->collection) {
- $id = basename($response->href);
- $id = str_replace($this->url_vcard_extension, null, $id);
-
- try {
- $vcardData = $this->getVcard($id);
- if (!empty($id)) {
- $simplified_xml->startElement('element');
- $simplified_xml->writeElement('id', $id);
- $simplified_xml->writeElement('etag', str_replace('"', null, $response->propstat->prop->getetag));
- $simplified_xml->writeElement('last_modified', $response->propstat->prop->getlastmodified);
-
- if ($include_vcards === true) {
- $simplified_xml->writeElement('vcard', $vcardData);
- }
- $simplified_xml->endElement();
- }
- } catch (\Exception $e) {
- print("Error fetching vCard: {$id}: {$e->getMessage()}\n");
- }
- } elseif (preg_match('/unix-directory/', $response->propstat->prop->getcontenttype)) {
- if (isset($response->propstat->prop->href)) {
- $href = $response->propstat->prop->href;
- } elseif (isset($response->href)) {
- $href = $response->href;
- } else {
- $href = null;
- }
-
- $url = str_replace($this->url_parts['path'], null, $this->url) . $href;
- $simplified_xml->startElement('addressbook_element');
- $simplified_xml->writeElement('display_name', $response->propstat->prop->displayname);
- $simplified_xml->writeElement('url', $url);
- $simplified_xml->writeElement('last_modified', $response->propstat->prop->getlastmodified);
- $simplified_xml->endElement();
- }
- }
- }
-
- $simplified_xml->endElement();
- $simplified_xml->endDocument();
-
- return $simplified_xml->outputMemory();
- }
-
- /**
- * Cleans CardDAV XML response
- *
- * @param string $response CardDAV XML response
- * @return string $response Cleaned CardDAV XML response
- */
- private function cleanResponse($response)
- {
- $response = utf8_encode($response);
- $response = str_replace('D:', null, $response);
- $response = str_replace('d:', null, $response);
- $response = str_replace('C:', null, $response);
- $response = str_replace('c:', null, $response);
-
- return $response;
- }
-
- /**
- * Curl initialization
- *
- * @return void
- */
- public function curlInit()
- {
- if (empty($this->curl)) {
- $this->curl = curl_init();
- curl_setopt($this->curl, CURLOPT_HEADER, true);
- curl_setopt($this->curl, CURLOPT_SSL_VERIFYHOST, false);
- curl_setopt($this->curl, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($this->curl, CURLOPT_USERAGENT, self::USERAGENT.self::VERSION);
-
- if ($this->auth !== null) {
- curl_setopt($this->curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
- curl_setopt($this->curl, CURLOPT_USERPWD, $this->auth);
- }
-
- /* allow to follow redirects if activated */
- curl_setopt($this->curl, CURLOPT_FOLLOWLOCATION, $this->follow_redirects);
- if ($this->follow_redirects)
- {
- curl_setopt($this->curl, CURLOPT_MAXREDIRS, $this->follow_redirects_count);
- }
- }
- }
-
- /**
- * Query the CardDAV server via curl and returns the response
- *
- * @param string $url CardDAV server URL
- * @param string $method HTTP method like (OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, COPY, MOVE)
- * @param string $content Content for CardDAV queries
- * @param string $content_type Set content type
- * @return array Raw CardDAV Response and http status code
- */
- private function query($url, $method, $content = null, $content_type = null)
- {
- $this->curlInit();
-
- curl_setopt($this->curl, CURLOPT_URL, $url);
- curl_setopt($this->curl, CURLOPT_CUSTOMREQUEST, $method);
-
- if ($content !== null) {
- curl_setopt($this->curl, CURLOPT_POST, true);
- curl_setopt($this->curl, CURLOPT_POSTFIELDS, $content);
- } else {
- curl_setopt($this->curl, CURLOPT_POST, false);
- curl_setopt($this->curl, CURLOPT_POSTFIELDS, null);
- }
-
- if ($content_type !== null) {
- curl_setopt($this->curl, CURLOPT_HTTPHEADER, array('Content-type: '.$content_type, 'Depth: 1'));
- } else {
- curl_setopt($this->curl, CURLOPT_HTTPHEADER, array('Depth: 1'));
- }
-
- $complete_response = curl_exec($this->curl);
- $header_size = curl_getinfo($this->curl, CURLINFO_HEADER_SIZE);
- $http_code = curl_getinfo($this->curl, CURLINFO_HTTP_CODE);
- $header = trim(substr($complete_response, 0, $header_size));
- $response = substr($complete_response, $header_size);
-
- $return = array(
- 'response' => $response,
- 'http_code' => $http_code
- );
-
- if ($this->debug === true) {
- $debug = $return;
- $debug['url'] = $url;
- $debug['method'] = $method;
- $debug['content'] = $content;
- $debug['content_type'] = $content_type;
- $debug['header'] = $header;
- $this->setDebug($debug);
- }
-
- return $return;
- }
-
- /**
- * Returns a valid and unused vCard id
- *
- * @return string $vcard_id Valid vCard id
- */
- private function generateVcardId()
- {
- $vcard_id = null;
-
- for ($number = 0; $number <= 25; $number ++) {
- if ($number == 8 || $number == 17) {
- $vcard_id .= '-';
- } else {
- $vcard_id .= $this->vcard_id_chars[mt_rand(0, (count($this->vcard_id_chars) - 1))];
- }
- }
-
- try {
- $carddav = new CardDavBackend($this->url);
- $carddav->setAuth($this->username, $this->password);
-
- $result = $carddav->query($this->url . $vcard_id . $this->url_vcard_extension, 'GET');
-
- if ($result['http_code'] !== 404) {
- $vcard_id = $this->generateVcardId();
- }
-
- return $vcard_id;
- } catch (Exception $e) {
- throw new \Exception($e->getMessage(), self::EXCEPTION_COULD_NOT_GENERATE_NEW_VCARD_ID);
- }
- }
-
- /**
- * Destructor
- * Close curl connection if it's open
- *
- * @return void
- */
- public function __destruct()
- {
- if (!empty($this->curl)) {
- curl_close($this->curl);
- }
- }
-}
-
-?>
diff --git a/lib/fritzbox_api_php/CHANGELOG.txt b/lib/fritzbox_api_php/CHANGELOG.txt
deleted file mode 100644
index 95030d28..00000000
--- a/lib/fritzbox_api_php/CHANGELOG.txt
+++ /dev/null
@@ -1,79 +0,0 @@
-0.5.0b7 2013-01-02:
----
-
-* added a parameter to the constructor of the api to load a different config file (i.e. new frizbox_api('alt') loads fritzbox_user_alt.conf.php
-* fixed the logfile-logging in all bundled scripts
-
-
-0.5.0b6 2012-12-23:
----
-
-* added a username config item to login with a local user, when user-based login is enabled in the box config
-
-
-0.5.0b5 2012-12-18:
----
-
-* fixed the remoteconfig login code to work with new user system
-* fixed the logger calls to echo the message, when the logger is not initialized
-
-
-0.5.0b4 2012-12-16:
----
-
-* fixed a typo in the remoteconfig login code
-
-
-0.5.0b3 2012-12-09:
----
-
-* changed fritzbox_get_foncallslist.php to work with new firmwares, moved old method to fritzbox_get_foncallslist_xml.php
-
-
-0.5.0b3 2012-12-07:
----
-
-* fixed internal SID login/logut-handling
-
-
-0.5.0b1 2012-12-05:
----
-
-* added support for the new .lua-loginpage in newest Fritz Labor firmwares
-* refactored the whole codebase, introduced a new autoloaded config object, so check the new config file fritzbox_user.conf.php
-
-
-0.4.1 2012-03-15:
----
-
-* added a new script fritzbox_guestlan_on_off.php to switch the new Guest-LAN on and off
-* tested all builtin scripts with new FRITZ!OS 05.20
-
-
-0.4 2011-05-15:
----
-
-* added support for the new .lua forms like the WLAN guest access settings
-
-
-0.3 2010-05-19:
----
-
-* added a doGetRequest method in the API
-* some minor changes
-* a new module for downloading the foncalls list
-
-
-0.2 2010-04-07:
----
-
-* added a capability to use the Fritz!Box remote admin mode
- Important limitation: does not check the certificate, so the password is sent to any computer responding at the configured address.
- Feel free to hack the cURL calls to accept only a given certrificate
-
-
-0.1:
----
-
-* First release
-
diff --git a/lib/fritzbox_api_php/README.md b/lib/fritzbox_api_php/README.md
deleted file mode 100644
index cbecf8f2..00000000
--- a/lib/fritzbox_api_php/README.md
+++ /dev/null
@@ -1,80 +0,0 @@
-# FritzBox! PHP API
-
-Provides an interface to your FritzBox! using the webinterface. Thus, no modification the to firmware (aka FritzOS) is required!
-
-### Requirements
-* PHP 5 (tested with 5.3)
-* PHP-curl
-
-Install on Debian/Ubuntu: sudo apt-get install php5-cli php5-curl
-
-###Sample Scripts
-
-* Enable/Disable TAM
-* Download Phone call list
-* Enable/Disable Guest (W)LAN
-* Ring a Phone
-* Reboot
-* Export the Phonebook
-* **Import the Phonebook (only tested with FB 71xx) [not available in the original version]**
-
-**Newer Version available at**: [IPF discussion thread](http://www.ip-phone-forum.de/showthread.php?t=196309)
-
-AUTHORS: [Gregor Nathanael Meyer](http://spackmat.de/spackblog), Karl Glatz, (maybe others)
-
-----------
-
-### Important! ###
-Do not use Windows Notepad as it will break the files due to their UTF-8 coding and UNIX linebreaks. Download a serious editor like Notepad++ instead.
-Also do not use or modify this scripts, if you do not know, what you do. This script is itended for advanced users
-
-
-
-### Basic usage advisory ####
-
-The scripts are well documented, please take a look to understand them.
-This is also the right moment to check the config file "fritzbox.conf.php"!
-
-All files must be in the same directory. If this condition is fulfilled, you don't need to pay any more attention to "fritzbox_api.class.php".
-
-To use "fritzbox_tam_on_off.php", you have to call it in a terminal, it will then explain its usage. This script is a reference implementation of the PHP Fritz!Box API, use it as a base for your own implementations
-
-
-
-### Usage on a Windows system ###
-
-The script works fine on my Windows Vista machine and a simply extraced PHP 5.3.0 distribution (get it at http://windows.php.net/download/, PHP 5.4.0 works as well). The cURL extension and the mbstring extenstion must be enabled in the php.ini and the correct timezone must be set. To do this, copy the php.ini-production to php.ini and uncomment/change the following directives:
-
-extension_dir = "ext"
-extension=php_curl.dll
-extension=php_mbstring.dll
-date.timezone = Europe/Berlin
-
-After you have done that, you can call the script in a terminal:
-
- C:\>path\to\php.exe path\to\fritzbox_tam_on_off.php
-
-i.e. if you extracted PHP to c:\php and the Fritz!Box PHP API to a subfolder named fritz_api, you call it this way:
- C:\>cd php
- C:\php>php fritz_api\fritzbox_tam_on_off.php
-
-If you use the Windows taskplanner, configure the logger to a logfile or to silent mode and call via php-win.exe instead of php.exe. This will prevent the terminal from being opened.
-
-
-
-### Usage on a UNIX system ###
-
-If you use UNIX, you should be familiar with calling a PHP script via the PHP-CLI. If you don't have the PHP-CLI installed, you can edit the $argv part in "fritz_tam_on_off.php" to work with PHP-CGI and $_GET or you hardcode the necessary arguments.
-
-Ensure that the cURL and the mbstring extensions are available and a valid timezone is set. The script was tested on a Ubuntu Server machine with PHP 5.2.
-
-
-
-### Feedback, license, support ###
-You are welcome to send me feedback via email (Gregor [at] der-meyer.de) or visit my personal blog at http://spackmat.de/spackblog (in German)
-
-The whole work is licensed under a Creative Commons cc-by-sa license (http://creativecommons.org/licenses/by-sa/3.0/de/). You are free to use and modify it, even for commercial use. If you redistribute it, you have to ensure my name is kept in the code and you use the same conditions.
-
-Feel free to add (and contribute) other nice scripts. The API class should work with any config item, which is available in the Fritz!Box Web UI. Use Firebug or LiveHeaders to figure out the name of the proper POST-Field.
-
-I won't give any personal support for this script, unless you pay for it. :) I'm a freelance IT-consultant and webdeveloper, loocated in Düsseldorf, Germany.
diff --git a/lib/fritzbox_api_php/README.txt b/lib/fritzbox_api_php/README.txt
deleted file mode 100644
index 1e69fbdb..00000000
--- a/lib/fritzbox_api_php/README.txt
+++ /dev/null
@@ -1,58 +0,0 @@
-### Important! ###
-Do not use Windows Notepad as it will break the files due to their UTF-8 coding and UNIX linebreaks. Download a serious editor like Notepad++ instead.
-Also do not use or modify this scripts, if you do not know, what you do. This script is itended for advanced users
-
-
-### Upgrade advisory for version 0.5.0 and up ####
-
-Version 0.5.0 introduced a new config format with graceful default values, so check the new config file fritzbox_user.conf.php
-
-
-### Basic usage advisory ####
-
-The scripts are well documented, please take a look to understand them.
-This is also the right moment to check the config file "fritzbox.conf.php"!
-
-All files must be in the same directory. If this condition is fulfilled, you don't need to pay any more attention to "fritzbox_api.class.php".
-
-To use "fritzbox_tam_on_off.php", you have to call it in a terminal, it will then explain its usage. This script is a reference implementation of the PHP Fritz!Box API, use it as a base for your own implementations
-
-
-
-### Usage on a Windows system ###
-
-The script works fine on my Windows 7 machine and a simply extraced PHP 5.3 distribution (get it at http://windows.php.net/download/, PHP 5.4 works as well). The cURL extension and the mbstring extenstion must be enabled in the php.ini and the correct timezone must be set. To do this, copy the php.ini-production to php.ini and uncomment/change the following directives:
-
-extension_dir = "ext"
-extension=php_curl.dll
-extension=php_mbstring.dll
-date.timezone = Europe/Berlin
-
-After you have done that, you can call the script in a terminal:
-
- C:\>"path\to\php.exe" "path\to\fritzbox_tam_on_off.php"
-
-i.e. if you extracted PHP to c:\php and the Fritz!Box PHP API to a subfolder named fritz_api, you call it this way:
- C:\>cd php
- C:\php>"php.exe" "fritz_api\fritzbox_tam_on_off.php"
-
-If you use the Windows taskplanner, configure the logger to a logfile or to silent mode and call via php-win.exe instead of php.exe. This will prevent the terminal from being opened.
-
-
-
-### Usage on a UNIX system ###
-
-If you use UNIX, you should be familiar with calling a PHP script via the PHP-CLI. If you don't have the PHP-CLI installed, you can edit the $argv part in "fritz_tam_on_off.php" to work with PHP-CGI and $_GET or you hardcode the necessary arguments.
-
-Ensure that the cURL and the mbstring extensions are available and a valid timezone is set. The script was tested on a Ubuntu Server machine with PHP 5.3.
-
-
-
-### Feedback, license, support ###
-You are welcome to send me feedback via email (Gregor [at] der-meyer.de) or visit my personal blog at http://spackmat.de/spackblog (in German)
-
-The whole work is licensed under a Creative Commons cc-by-sa license (http://creativecommons.org/licenses/by-sa/3.0/de/). You are free to use and modify it, even for commercial use. If you redistribute it, you have to ensure my name is kept in the code and you use the same conditions.
-
-Feel free to add (and contribute) other nice scripts. The API class should work with any config item, which is available in the Fritz!Box Web UI. Use Firebug or LiveHeaders to figure out the name of the proper POST-Field.
-
-I won't give any personal support for this script, unless you pay for it. :) I'm a freelance IT-consultant and webdeveloper, loocated in Düsseldorf, Germany.
\ No newline at end of file
diff --git a/lib/fritzbox_api_php/fritzbox_api.class.php b/lib/fritzbox_api_php/fritzbox_api.class.php
deleted file mode 100644
index bf4296ee..00000000
--- a/lib/fritzbox_api_php/fritzbox_api.class.php
+++ /dev/null
@@ -1,539 +0,0 @@
-
- * @license http://creativecommons.org/licenses/by-sa/3.0/de/ Creative Commons cc-by-sa
- * @version 0.5.0b7 2013-01-02
- * @package Fritz!Box PHP tools
- */
-
-/* A simple usage example
- *
- * try
- * {
- * // load the fritzbox_api class
- * require_once('fritzbox_api.class.php');
- * $fritz = new fritzbox_api();
- *
- * // init the output message
- * $message = date('Y-m-d H:i') . ' ';
- *
- * // update the setting
- * $formfields = array(
- * 'telcfg:command/Dial' => '**610',
- * );
- * $fritz->doPostForm($formfields);
- * $message .= 'Phone ' . $dial . ' ringed.';
- * }
- * catch (Exception $e)
- * {
- * $message .= $e->getMessage();
- * }
- *
- * // log the result
- * $fritz->logMessage($message);
- * $fritz = null; // destroy the object to log out
- */
-
-/**
- * the main Fritz!Box API class
- *
- */
-class fritzbox_api {
- /**
- * @var object config object
- */
- public $config = array();
-
- /**
- * @var string the session ID, set by method initSID() after login
- */
- protected $sid = '0000000000000000';
-
-
- /**
- * the constructor, initializes the object and calls the login method
- *
- * @access public
- */
- public function __construct($password = false,$user_name = false,$fritzbox_ip = 'fritz.box',$force_local_login = false)
- {
- // init the config object
- $this->config = new fritzbox_api_config();
-
- // try autoloading the config
- if (file_exists(__DIR__ . '/fritzbox_user.conf.php') && is_readable(__DIR__ . '/fritzbox_user.conf.php') ) {
- require_once(__DIR__ . '/fritzbox_user.conf.php');
- }
-
- // set FRITZ!Box-IP and URL
- $this->config->setItem('fritzbox_ip',$fritzbox_ip);
-
- // check if login on local network (fritz.box) or via a dynamic DNS-host
- if ($fritzbox_ip != 'fritz.box' && !$force_local_login) {
- $this->config->setItem('enable_remote_config',true);
- $this->config->setItem('remote_config_user',$user_name);
- $this->config->setItem('remote_config_password',$password);
- $this->config->setItem('fritzbox_url', 'https://'.$this->config->getItem('fritzbox_ip'));
- } else {
- $this->config->setItem('enable_remote_config',false);
- if($user_name != false){
- $this->config->setItem('username',$user_name);
- }
- if($password != false){
- $this->config->setItem('password',$password);
- }
- $this->config->setItem('fritzbox_url', 'http://' . $this->config->getItem('fritzbox_ip'));
- }
-
- // make some config consistency checks
- if ( $this->config->getItem('enable_remote_config') === true ){
- if ( !$this->config->getItem('remote_config_user') || !$this->config->getItem('remote_config_password') ){
- $this->error('ERROR: Remote config mode enabled, but no username or no password provided');
- }
- }
- else {
- $this->config->setItem('old_remote_config_user', null);
- $this->config->setItem('old_remote_config_password', null);
- }
- $this->sid = $this->initSID();
- }
-
-
- /**
- * the destructor just calls the logout method
- *
- * @access public
- */
- public function __destruct()
- {
- $this->logout();
- }
-
-
- /**
- * do a POST request on the box
- * the main cURL wrapper handles the command
- *
- * @param array $formfields an associative array with the POST fields to pass
- * @return string the raw HTML code returned by the Fritz!Box
- */
- public function doPostForm($formfields = array())
- {
- $ch = curl_init();
-
- if ( isset($formfields['getpage']) && strpos($formfields['getpage'], '.lua') > 0 )
- {
- curl_setopt($ch, CURLOPT_URL, $this->config->getItem('fritzbox_url') . $formfields['getpage'] . '?sid=' . $this->sid);
- unset($formfields['getpage']);
- }
- else
- {
- // add the sid, if it is already set
- if ($this->sid != '0000000000000000')
- {
- $formfields['sid'] = $this->sid;
- }
- curl_setopt($ch, CURLOPT_URL, $this->config->getItem('fritzbox_url') . '/cgi-bin/webcm');
- }
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_POST, 1);
- if ( $this->config->getItem('enable_remote_config') == true )
- {
- // set name of SSL-certificate (must be same as remote-hostname (dynDNS) of FRITZ!Box) and remove port in address if alternate port is given
- if (strpos($this->config->getItem('fritzbox_ip'),":")){
- $ssl_cert_fritzbox = explode(":", $this->config->getItem('fritzbox_ip'));
- $ssl_cert_fritzbox = $ssl_cert_fritzbox[0];
- } else {
- $ssl_cert_fritzbox = $this->config->getItem('fritzbox_ip');
- }
-
- // set SSL-options and path to certificate
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 2);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
- curl_setopt($ch, CURLOPT_CAPATH, '/etc/ssl/certs');
-
- // support for pre FRITZ!OS 5.50 remote config
- if (!$this->config->getItem('use_lua_login_method')){
- curl_setopt($ch, CURLOPT_USERPWD, $this->config->getItem('remote_config_user') . ':' . $this->config->getItem('remote_config_password'));
- }
- }
- curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($formfields));
- $output = curl_exec($ch);
- curl_close($ch);
- return $output;
- }
-
- public function doPostFile($formfields = array(), $filefileds = array())
- {
- $ch = curl_init();
-
- // add the sid, if it is already set
- if ($this->sid != '0000000000000000')
- {
- // 'sid' MUST be the first POST variable!!! (otherwise it will not work!!)
- // therfore we use array_merge to ensuere the foreach outputs 'sid' fist
- $formfields = array_merge(array('sid' => $this->sid), $formfields);
- //$formfields['sid'] = $this->sid;
- }
- curl_setopt($ch, CURLOPT_URL, $this->config->getItem('fritzbox_url') . '/cgi-bin/firmwarecfg');
- curl_setopt($ch, CURLOPT_POST, 1);
-
- // enable for debugging:
- //curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
-
- // if filefileds not specified ('@/path/to/file.xml;type=text/xml' works fine)
- if(empty( $filefileds )) {
- curl_setopt($ch, CURLOPT_POSTFIELDS, $formfields); // http_build_query
- }
- // post calculated raw data
- else {
- $header = $this->_create_custom_file_post_header($formfields, $filefileds);
- curl_setopt($ch, CURLOPT_HTTPHEADER , array(
- 'Content-Type: multipart/form-data; boundary=' . $header['delimiter'], 'Content-Length: ' . strlen($header['data']) )
- );
-
- curl_setopt($ch, CURLOPT_POSTFIELDS, $header['data']);
- }
-
- $output = curl_exec($ch);
-
- // curl error
- if(curl_errno($ch)) {
- $this->error(curl_error($ch)." (".curl_errno($ch).")");
- }
-
- // finger out an error message, if given
- preg_match('@
(.*?)
@is', $output, $matches);
- if (isset($matches[1]))
- {
- $this->error(str_replace(' ', ' ', $matches[1]));
- }
-
- curl_close($ch);
- return $output;
- }
-
- private function _create_custom_file_post_header($postFields, $fileFields) {
- // form field separator
- $delimiter = '-------------' . uniqid();
-
- /*
- // file upload fields: name => array(type=>'mime/type',content=>'raw data')
- $fileFields = array(
- 'file1' => array(
- 'type' => 'text/xml',
- 'content' => '...your raw file content goes here...',
- 'filename' = 'filename.xml'
- ),
- );
- // all other fields (not file upload): name => value
- $postFields = array(
- 'otherformfield' => 'content of otherformfield is this text',
- );
- */
-
- $data = '';
-
- // populate normal fields first (simpler)
- foreach ($postFields as $name => $content) {
- $data .= "--" . $delimiter . "\r\n";
- $data .= 'Content-Disposition: form-data; name="' . urlencode($name) . '"';
- $data .= "\r\n\r\n";
- $data .= $content;
- $data .= "\r\n";
- }
- // populate file fields
- foreach ($fileFields as $name => $file) {
- $data .= "--" . $delimiter . "\r\n";
- // "filename" attribute is not essential; server-side scripts may use it
- $data .= 'Content-Disposition: form-data; name="' . urlencode($name) . '";' .
- ' filename="' . $file['filename'] . '"' . "\r\n";
-
- //$data .= 'Content-Transfer-Encoding: binary'."\r\n";
- // this is, again, informative only; good practice to include though
- $data .= 'Content-Type: ' . $file['type'] . "\r\n";
- // this endline must be here to indicate end of headers
- $data .= "\r\n";
- // the file itself (note: there's no encoding of any kind)
- $data .= $file['content'] . "\r\n";
- }
- // last delimiter
- $data .= "--" . $delimiter . "--\r\n";
-
- return array('delimiter' => $delimiter, 'data' => $data);
- }
-
- /**
- * do a GET request on the box
- * the main cURL wrapper handles the command
- *
- * @param array $params an associative array with the GET params to pass
- * @return string the raw HTML code returned by the Fritz!Box
- */
- public function doGetRequest($params = array())
- {
- // add the sid, if it is already set
- if ($this->sid != '0000000000000000')
- {
- $params['sid'] = $this->sid;
- }
-
- $ch = curl_init();
- if ( strpos($params['getpage'], '.lua') > 0 )
- {
- $getpage = $params['getpage'] . '?';
- unset($params['getpage']);
- }
- else
- {
- $getpage = '/cgi-bin/webcm?';
- }
- curl_setopt($ch, CURLOPT_URL, $this->config->getItem('fritzbox_url') . $getpage . http_build_query($params));
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_HTTPGET, 1);
- if ( $this->config->getItem('enable_remote_config') )
- {
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
-
- // support for pre FRITZ!OS 5.50 remote config
- if ( !$this->config->getItem('use_lua_login_method') )
- {
- curl_setopt($ch, CURLOPT_USERPWD, $this->config->getItem('remote_config_user') . ':' . $this->config->getItem('remote_config_password'));
- }
- }
- $output = curl_exec($ch);
- curl_close($ch);
- return $output;
- }
-
-
- /**
- * the login method, handles the secured login-process
- * newer firmwares (xx.04.74 and newer) need a challenge-response mechanism to prevent Cross-Site Request Forgery attacks
- * see http://www.avm.de/de/Extern/Technical_Note_Session_ID.pdf for details
- *
- * @return string a valid SID, if the login was successful, otherwise throws an Exception with an error message
- */
- protected function initSID()
- {
- // determine, wich login type we have to use
- if ( $this->config->getItem('use_lua_login_method') == true )
- {
- $loginpage = '/login_sid.lua';
- }
- else
- {
- $loginpage = '../html/login_sid.xml';
- }
-
- // read the current status
- $session_status_simplexml = simplexml_load_string($this->doGetRequest(array('getpage' => $loginpage)));
-
- if ( !is_object($session_status_simplexml) || get_class($session_status_simplexml) != 'SimpleXMLElement' )
- {
- $this->error('Response of initialization call ' . $loginpage . ' in ' . __FUNCTION__ . ' was not xml-formatted.');
- }
-
- // perhaps we already have a SID (i.e. when no password is set)
- if ( $session_status_simplexml->SID != '0000000000000000' )
- {
- return $session_status_simplexml->SID;
- }
- // we have to login and get a new SID
- else
- {
- // the challenge-response magic, pay attention to the mb_convert_encoding()
- $challenge = $session_status_simplexml->Challenge;
-
- // do the login
- $formfields = array(
- 'getpage' => $loginpage,
- );
- if ( $this->config->getItem('use_lua_login_method') )
- {
- if ( $this->config->getItem('enable_remote_config') )
- {
- $formfields['username'] = $this->config->getItem('remote_config_user');
- $response = $challenge . '-' . md5(mb_convert_encoding($challenge . '-' . $this->config->getItem('remote_config_password'), "UCS-2LE", "UTF-8"));
- }
- else
- {
- if ( $this->config->getItem('username') )
- {
- $formfields['username'] = $this->config->getItem('username');
- }
- $response = $challenge . '-' . md5(mb_convert_encoding($challenge . '-' . $this->config->getItem('password'), "UCS-2LE", "UTF-8"));
- }
- $formfields['response'] = $response;
- }
- else
- {
- $response = $challenge . '-' . md5(mb_convert_encoding($challenge . '-' . $this->config->getItem('password'), "UCS-2LE", "UTF-8"));
- $formfields['login:command/response'] = $response;
- }
- $output = $this->doPostForm($formfields);
-
- // finger out the SID from the response
- $session_status_simplexml = simplexml_load_string($output);
- if ( !is_object($session_status_simplexml) || get_class($session_status_simplexml) != 'SimpleXMLElement' )
- {
- $this->error('Response of login call to ' . $loginpage . ' in ' . __FUNCTION__ . ' was not xml-formatted.');
- }
-
- if ( $session_status_simplexml->SID != '0000000000000000' )
- {
- return (string)$session_status_simplexml->SID;
- }
- else
- {
- $this->error('ERROR: Login failed with an unknown response.');
- }
- }
- }
-
-
- /**
- * the logout method just sends a logout command to the Fritz!Box
- *
- */
- protected function logout()
- {
- if ( $this->config->getItem('use_lua_login_method') == true )
- {
- $this->doGetRequest(array('getpage' => '/home/home.lua', 'logout' => '1'));
- }
- else
- {
- $formfields = array(
- 'getpage' => '../html/de/menus/menu2.html',
- 'security:command/logout' => 'logout',
- );
- $this->doPostForm($formfields);
- }
- }
-
-
- /**
- * the error method just throws an Exception
- *
- * @param string $message an error message for the Exception
- */
- public function error($message = null)
- {
- throw new Exception($message);
- }
-
-
- /**
- * a getter for the session ID
- *
- * @return string $this->sid
- */
- public function getSID()
- {
- return $this->sid;
- }
-
- /**
- * log a message
- *
- * @param $message string the message to log
- */
- public function logMessage($message)
- {
- if ( $this->config->getItem('newline') == false )
- {
- $this->config->setItem('newline', (PHP_OS == 'WINNT') ? "\r\n" : "\n");
- }
-
- if ( $this->config->getItem('logging') == 'console' )
- {
- echo $message;
- }
- else if ( $this->config->getItem('logging') == 'silent' || $this->config->getItem('logging') == false )
- {
- // do nothing
- }
- else
- {
- if ( is_writable($this->config->getItem('logging')) || is_writable(dirname($this->config->getItem('logging'))) )
- {
- file_put_contents($this->config->getItem('logging'), $message . $this->config->getItem('newline'), FILE_APPEND);
- }
- else
- {
- echo('Error: Cannot log to non-writeable file or dir: ' . $this->config->getItem('logging'));
- }
- }
- }
-}
-
-class fritzbox_api_config {
- protected $config = array();
-
- public function __construct()
- {
- # use the new .lua login method in current (end 2012) labor and newer firmwares (Fritz!OS 5.50 and up)
- $this->setItem('use_lua_login_method', true);
-
- # set to your Fritz!Box IP address or DNS name (defaults to fritz.box), for remote config mode, use the dyndns-name like example.dyndns.org
- $this->setItem('fritzbox_ip', 'fritz.box');
-
- # if needed, enable remote config here
- #$this->setItem('enable_remote_config', true);
- #$this->setItem('remote_config_user', 'test');
- #$this->setItem('remote_config_password', 'test123');
-
- # set to your Fritz!Box username, if login with username is enabled (will be ignored, when remote config is enabled)
- $this->setItem('username', false);
-
- # set to your Fritz!Box password (defaults to no password)
- $this->setItem('password', false);
-
- # set the logging mechanism (defaults to console logging)
- $this->setItem('logging', 'console'); // output to the console
- #$this->setItem('logging', 'silent'); // do not output anything, be careful with this logging mode
- #$this->setItem('logging', 'tam.log'); // the path to a writeable logfile
-
- # the newline character for the logfile (does not need to be changed in most cases)
- $this->setItem('newline', (PHP_OS == 'WINNT') ? "\r\n" : "\n");
- }
-
- /* gets an item from the config
- *
- * @param $item string the item to get
- * @return mixed the value of the item
- */
- public function getItem($item = 'all')
- {
- if ( $item == 'all' )
- {
- return $this->config;
- }
- elseif ( isset($this->config[$item]) )
- {
- return $this->config[$item];
- }
- return false;
- }
-
- /* sets an item into the config
- *
- * @param $item string the item to set
- * @param $value mixed the value to store into the item
- */
- public function setItem($item, $value)
- {
- $this->config[$item] = $value;
- }
-}
diff --git a/lib/fritzbox_api_php/fritzbox_delete_foncallslist.php b/lib/fritzbox_api_php/fritzbox_delete_foncallslist.php
deleted file mode 100644
index 01cb055d..00000000
--- a/lib/fritzbox_api_php/fritzbox_delete_foncallslist.php
+++ /dev/null
@@ -1,50 +0,0 @@
-
- * @license http://creativecommons.org/licenses/by-sa/3.0/de/ Creative Commons cc-by-sa
- * @version 0.1 2015-06-11
- * @package Fritz!Box PHP tools
- */
-
-try
-{
- // load the fritzbox_api class
- require_once('fritzbox_api.class.php');
- $fritz = new fritzbox_api();
-
- // init the output message
- $message = date('Y-m-d H:i') . ' ';
-
- // delete calllist form fields
- $formfields = array(
- 'getpage' => '/fon_num/foncalls_list.lua',
- 'usejournal' => '1',
- 'callstab' => 'all',
- 'submit' => 'clear',
- 'clear' => '1',
- );
-
- $fritz->doPostForm($formfields);
- // set a log message
- $message .= 'Call list sucessfully deleted';
-}
-catch (Exception $e)
-{
- $message .= $e->getMessage();
-}
-
-// log the result
-if ( isset($fritz) && is_object($fritz) && get_class($fritz) == 'fritzbox_api' )
-{
- $fritz->logMessage($message);
-}
-else
-{
- echo($message);
-}
-$fritz = null; // destroy the object to log out
-?>
diff --git a/lib/fritzbox_api_php/fritzbox_diversity0on.php b/lib/fritzbox_api_php/fritzbox_diversity0on.php
deleted file mode 100644
index 21b6ad0d..00000000
--- a/lib/fritzbox_api_php/fritzbox_diversity0on.php
+++ /dev/null
@@ -1,37 +0,0 @@
- '../html/de/menus/menu2.html',
- 'telcfg:settings/Diversity' . $diversity . '/Active' => $mode,
- );
- $fritz->doPostForm($formfields);
-}
-catch (Exception $e)
-{
- $message .= $e->getMessage();
-}
-
-// log the result
-if ( isset($fritz) && is_object($fritz) && get_class($fritz) == 'fritzbox_api' )
-{
- $fritz->logMessage($message);
-}
-else
-{
- echo($message);
-}
-$fritz = null; // destroy the object to log out
-?>
\ No newline at end of file
diff --git a/lib/fritzbox_api_php/fritzbox_get_foncallslist.php b/lib/fritzbox_api_php/fritzbox_get_foncallslist.php
deleted file mode 100644
index b7232500..00000000
--- a/lib/fritzbox_api_php/fritzbox_get_foncallslist.php
+++ /dev/null
@@ -1,73 +0,0 @@
-
- * @license http://creativecommons.org/licenses/by-sa/3.0/de/ Creative Commons cc-by-sa
- * @version 0.4 2013-01-02
- * @package Fritz!Box PHP tools
- */
-
-try
-{
- // load the fritzbox_api class
- require_once('fritzbox_api.class.php');
- $fritz = new fritzbox_api();
-
- // init the output message
- $message = date('Y-m-d H:i') . ' ';
-
- if ( !$fritz->config->getItem('foncallslist_path') )
- {
- throw new Exception('Mandatory config Item foncallslist_path not set.');
- }
- if ( ( file_exists($fritz->config->getItem('foncallslist_path')) && !is_writable($fritz->config->getItem('foncallslist_path')) ) || ( !file_exists($fritz->config->getItem('foncallslist_path')) && !is_writable(dirname($fritz->config->getItem('foncallslist_path'))) ) )
- {
- throw new Exception('Config item foncallslist_path (' . $fritz->config->getItem('foncallslist_path') . ') is not writeable.');
- }
-
- // get the phone calls list
- $params = array(
- //'getpage' => '../html/de/home/foncallsdaten.xml',
- //'getpage' => '../html/de/FRITZ!Box_Anrufliste.csv',
- 'getpage' => '/fon_num/foncalls_list.lua',
- );
- $fritz->doGetRequest($params);
-
- // get the phone calls list
- $params = array(
- //'getpage' => '../html/de/home/foncallsdaten.xml',
- //'getpage' => '../html/de/FRITZ!Box_Anrufliste.csv',
- 'getpage' => '/fon_num/foncalls_list.lua',
- 'csv' => '',
- );
- $output = $fritz->doGetRequest($params);
-
- // write out the call list to the desired path
- file_put_contents($fritz->config->getItem('foncallslist_path'), $output);
-
- // set a log message
- $message .= 'Call list sucessfully downloaded';
-}
-catch (Exception $e)
-{
- $message .= $e->getMessage();
-}
-
-// log the result
-if ( isset($fritz) && is_object($fritz) && get_class($fritz) == 'fritzbox_api' )
-{
- $fritz->logMessage($message);
-}
-else
-{
- echo($message);
-}
-$fritz = null; // destroy the object to log out
-?>
\ No newline at end of file
diff --git a/lib/fritzbox_api_php/fritzbox_get_foncallslist_xml.php b/lib/fritzbox_api_php/fritzbox_get_foncallslist_xml.php
deleted file mode 100644
index 8d3ed3bf..00000000
--- a/lib/fritzbox_api_php/fritzbox_get_foncallslist_xml.php
+++ /dev/null
@@ -1,72 +0,0 @@
-
- * @license http://creativecommons.org/licenses/by-sa/3.0/de/ Creative Commons cc-by-sa
- * @version 0.3 2013-01-02
- * @package Fritz!Box PHP tools
- */
-
-try
-{
- // load the fritzbox_api class
- require_once('fritzbox_api.class.php');
- $fritz = new fritzbox_api();
-
- // init the output message
- $message = date('Y-m-d H:i') . ' ';
-
- if ( !$fritz->config->getItem('foncallslist_path') )
- {
- throw new Exception('Mandatory config Item foncallslist_path not set.');
- }
- if ( ( file_exists($fritz->config->getItem('foncallslist_path')) && !is_writable($fritz->config->getItem('foncallslist_path')) ) || ( !file_exists($fritz->config->getItem('foncallslist_path')) && !is_writable(dirname($fritz->config->getItem('foncallslist_path'))) ) )
- {
- throw new Exception('Config item foncallslist_path (' . $fritz->config->getItem('foncallslist_path') . ') is not writeable.');
- }
-
- // get the frontend-page to refresh the list
- $params = array(
- 'getpage' => '../html/de/menus/menu2.html',
- 'var:menu' => 'fon',
- 'var:pagename' => 'foncalls',
- 'var:errorpagename' => 'foncalls',
- 'var:type' => '0',
- );
- $fritz->doPostForm($params);
-
- // get the phone calls list
- $params = array(
- 'getpage' => '../html/de/home/foncallsdaten.xml',
- );
- $output = $fritz->doGetRequest($params);
-
- // write out the call list to the desired path
- file_put_contents($fritz->config->getItem('foncallslist_path'), $output);
-
- // set a log message
- $message .= 'Call list sucessfully downloaded';
-}
-catch (Exception $e)
-{
- $message .= $e->getMessage();
-}
-
-// log the result
-if ( isset($fritz) && is_object($fritz) && get_class($fritz) == 'fritzbox_api' )
-{
- $fritz->logMessage($message);
-}
-else
-{
- echo($message);
-}
-$fritz = null; // destroy the object to log out
-?>
\ No newline at end of file
diff --git a/lib/fritzbox_api_php/fritzbox_guestlan_on_off.php b/lib/fritzbox_api_php/fritzbox_guestlan_on_off.php
deleted file mode 100644
index 1f5e9bac..00000000
--- a/lib/fritzbox_api_php/fritzbox_guestlan_on_off.php
+++ /dev/null
@@ -1,127 +0,0 @@
-
- * @license http://creativecommons.org/licenses/by-sa/3.0/de/ Creative Commons cc-by-sa
- * @version 0.3 2013-01-02
- * @package Fritz!Box PHP tools
- */
-
-try
-{
- // load the fritzbox_api class
- require_once('fritzbox_api.class.php');
- $fritz = new fritzbox_api();
-
- // init the output message
- $message = date('Y-m-d H:i') . ' ';
-
- // handle the CLI arguments or give a help message
- if (isset($argv[1]) && ($argv[1] == 0 || $argv[1] == 1) )
- {
- $mode = (bool)$argv[1];
- }
- else
- {
- if ( $fritz->config->getItem('logging') == 'console' )
- {
- echo '
- Enables or disables the LAN4 guest access of a Fritz!Box
-
- Usage on UNIX systems:
- /path/to/php ' . $argv[0] . ' {0|1}
-
- Usage on Windows systems:
- "c:\path\to\php.exe" ' . $argv[0] . ' {0|1}
-
- 0 disables the guest access
- 1 enables the guest access
- ';
- }
- else
- {
- $fritz->logMessage($message . 'ERROR: Script was called without or with an invalid argument');
- }
- exit;
- }
-
-
- // read the current settings
- $formfields = array(
- 'getpage' => '/net/network_settings.lua',
- );
- $output = $fritz->doGetRequest($formfields);
-
-
- // read time_server_activ setting
- preg_match('@name="time_server_activ"[^>]+(checked)[^>]*@', $output, $matches);
- if ( isset($matches[1]) )
- {
- $formfields['time_server_activ'] = 'on';
- }
- // read time_server setting
- preg_match('@name="time_server"[^>]+value="([^"]*)"[^>]*@', $output, $matches);
- $formfields['time_server'] = isset($matches[1]) ? $matches[1] : '0.europe.pool.ntp.org';
- // read other_prefix_allowed setting
- preg_match('@name="other_prefix_allowed"[^>]+(checked)[^>]*@', $output, $matches);
- if ( isset($matches[1]) )
- {
- $formfields['other_prefix_allowed'] = 'on';
- }
- // read dnsv6_server_activ setting
- preg_match('@name="dnsv6_server_activ"[^>]+(checked)[^>]*@', $output, $matches);
- if ( isset($matches[1]) )
- {
- $formfields['dnsv6_server_activ'] = 'on';
- }
-
- // set new given setting
- if ( $mode == true )
- {
- $formfields['guest_enabled'] = 'on';
- }
-
- // do the update
- $formfields['btnSave'] = '';
- $output = $fritz->doPostForm($formfields);
-
- preg_match('@name="guest_enabled"[^>]+(checked)[^>]*@', $output, $matches);
- if ( isset($matches[1]) && $mode == true )
- {
- $message .= 'LAN4 guest access is now active.';
- }
- else if ( !isset($matches[1]) && $mode == false )
- {
- $message .= 'LAN4 guest access is now inactive.';
- }
- else if ( isset($matches[1]) && $mode == false )
- {
- $message .= 'ERROR: LAN4 guest access status change failed, should be inactive, but is still active.';
- }
- else if ( !isset($matches[1]) && $mode == true )
- {
- $message .= 'ERROR: LAN4 guest access status change failed, should be active, but is still inactive.';
- }
-}
-catch (Exception $e)
-{
- $message .= $e->getMessage();
-}
-
-// log the result
-if ( isset($fritz) && is_object($fritz) && get_class($fritz) == 'fritzbox_api' )
-{
- $fritz->logMessage($message);
-}
-else
-{
- echo($message);
-}
-$fritz = null; // destroy the object to log out
-?>
\ No newline at end of file
diff --git a/lib/fritzbox_api_php/fritzbox_guestwlan_on_off.php b/lib/fritzbox_api_php/fritzbox_guestwlan_on_off.php
deleted file mode 100644
index f009496f..00000000
--- a/lib/fritzbox_api_php/fritzbox_guestwlan_on_off.php
+++ /dev/null
@@ -1,143 +0,0 @@
-
- * @license http://creativecommons.org/licenses/by-sa/3.0/de/ Creative Commons cc-by-sa
- * @version 0.3 2013-01-02
- * @package Fritz!Box PHP tools
- */
-
-try
-{
- // load the fritzbox_api class
- require_once('fritzbox_api.class.php');
- $fritz = new fritzbox_api();
-
- // init the output message
- $message = date('Y-m-d H:i') . ' ';
-
- // handle the CLI arguments or give a help message
- if (isset($argv[1]) && ($argv[1] == 0 || $argv[1] == 1) )
- {
- $mode = (bool)$argv[1];
- }
- else
- {
- if ( $fritz->config->getItem('logging') == 'console' )
- {
- echo '
- Enables or disables the WLAN guest access of a Fritz!Box
-
- Usage on UNIX systems:
- /path/to/php ' . $argv[0] . ' {0|1} [optional: PASSWORD]
-
- Usage on Windows systems:
- c:\path\to\php.exe ' . $argv[0] . ' {0|1} [optional: PASSWORD]
-
- 0 disables the guest access
- 1 enables the guest access
-
- The optional argument PASSWORD sets a new guest access password (min 8 chars)
- Defaults to false, so the current password is kept.
- ';
- }
- else
- {
- $fritz->logMessage($message . 'ERROR: Script was called without or with an invalid argument');
- }
- exit;
- }
- $wpa_key = (isset($argv[2]) && strlen($argv[2]) >= 8 && strlen($argv[2]) <= 63) ? $argv[2] : false;
-
-
- // read the current settings
- $formfields = array(
- 'getpage' => '/wlan/guest_access.lua',
- );
- $output = $fritz->doGetRequest($formfields);
-
- // read down_time_activ setting
- preg_match('@name="down_time_activ"[^>]+(checked)[^>]*@', $output, $matches);
- if ( isset($matches[1]) )
- {
- $formfields['down_time_activ'] = 'on';
- }
- // read down_time_value setting
- preg_match('@name="down_time_value".*?
';
-
- if ($vCard -> PHOTO)
- {
- foreach ($vCard -> PHOTO as $Photo)
- {
- if ($Photo['encoding'] == 'b')
- {
- echo ' ';
- }
- else
- {
- echo ' ';
- }
-
- /*
- // It can also be saved to a file
- try
- {
- $vCard -> SaveFile('photo', 0, 'test_image.jpg');
- // The parameters are:
- // - name of the file we want to save (photo, logo or sound)
- // - index of the file in case of multiple files (defaults to 0)
- // - target path to save to, including the filenam
- }
- catch (Exception $E)
- {
- // Target path not writable
- }
- */
- }
- }
-
- foreach ($vCard -> N as $Name)
- {
- echo '