Skip to content
This repository was archived by the owner on Feb 25, 2021. It is now read-only.

Commit f94ab10

Browse files
author
Antoni Orfin
committed
Initial commit
0 parents  commit f94ab10

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+3579
-0
lines changed

.gitignore

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
vendor
2+
app/properties.json
3+
composer.lock
4+
box.phar
5+
composer.phar
6+
nbproject
7+
*~
8+
.project
9+
.settings
10+
.idea
11+
build/
12+
web/pb

LICENSE

+674
Large diffs are not rendered by default.

README.md

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
Octivi - Yealink PhoneBook Manager
2+
=============================================
3+
4+
Simple PHP application to manage your Yealink Remote phone book.
5+
6+
Installation
7+
---------------------------------------------
8+
9+
### Using a release file (prefered way)
10+
11+
1. Download the latest release of YealinkPhoneBookManager
12+
2. Unpack archive file under your web directory
13+
3. Modify .htaccess to allow access to your phone book manager - as described in a .htaccess password protection
14+
15+
### Using Composer (for development)
16+
17+
Under your host directory clone this Git repository.
18+
19+
1. In project folder execute commands:
20+
21+
curl -sS https://getcomposer.org/installer | php
22+
php composer.phar install
23+
24+
2. Copy `app/properties.json.dist` to `app/properties.json`
25+
3. In `app/properties.json` you can set default path and file name of your phone book
26+
4. Set the server's document root to the web/ folder
27+
28+
Configuration
29+
---------------------------------------------
30+
31+
Location of the configuration file depends on the way of the installation:
32+
33+
* From a release file - `index.php`
34+
* Composer - `app/properties.json`
35+
36+
In that files you will find configuration properties:
37+
38+
* `directory` - default directory of the phone book XML files
39+
* `defaultFileName` - name of the default file, which manager will use as a primary phone book
40+
41+
42+
.htaccess password protection
43+
---------------------------------------------
44+
45+
It's possible to configure a .htaccess file to ensure Basic access authentication protection. All you have to do is to uncomment
46+
last comment block in the .htaccess file, and set the right path of your .htpasswd file.
47+
48+
AuthUserFile /path/to/your/directory/.htpasswd
49+
50+
Yealink phones still can't get access through basic auth, so to allow them to read your phone book files, you must edit line:
51+
52+
Allow from 127.0.0.1
53+
54+
where 127.0.0.1 has to be your phone IP address.
55+
56+
57+
Phonebook backup
58+
---------------------------------------------
59+
60+
In the same directory as your orginal phonebook file is, the script will create backup files of your phonebook when clicking on the "Create Backup" button.
61+
62+
63+
Copyright
64+
---------------------------------------------
65+
66+
Copyright 2014 IMAGIN Sp. z o.o.
67+
Octivi - www.octivi.com

app/app.php

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?php
2+
/*
3+
* Copyright 2014 IMAGIN Sp. z o.o. - imagin.pl
4+
*
5+
* For the full copyright and license information, please view the LICENSE
6+
* file that was distributed with this source code.
7+
*/
8+
9+
require_once __DIR__ . '/bootstrap.php';
10+
11+
use Octivi\Controller\SourceController;
12+
use Octivi\Controller\ContactController;
13+
use Octivi\Controller\DefaultController;
14+
15+
$propertiesFile = __DIR__ . '/properties.json';
16+
17+
// $properties can come from the index.php (Phar distribution)
18+
if (isset($properties)) {
19+
$directoryPath = $properties['directory'];
20+
$directoryName = $properties['directory'];
21+
} else {
22+
$propertiesJson = file_get_contents($propertiesFile);
23+
$properties = json_decode($propertiesJson, true);
24+
25+
$directoryPath = __DIR__ . '/../web/' . $properties['directory'];
26+
$directoryName = $properties['directory'];
27+
}
28+
29+
if (!isset($properties['rootDirectory'])) {
30+
$properties['rootDirectory'] = __DIR__;
31+
}
32+
33+
$properties['rootDirectory'] = rtrim($properties['rootDirectory'], '/'). '/';
34+
35+
if (substr($directoryName, 0, strlen($properties['rootDirectory'])) == $properties['rootDirectory']) {
36+
$directoryName = substr($directoryName, strlen($properties['rootDirectory']));
37+
}
38+
39+
$defaultFileName = $properties['defaultFileName'];
40+
41+
$app['sourceDirectory'] = $directoryPath;
42+
$app['defaultFileName'] = $defaultFileName;
43+
$app['directoryName'] = $directoryName;
44+
45+
if (isset($properties['debug']) && $properties['debug']) {
46+
error_reporting(E_ALL);
47+
$app['debug'] = true;
48+
}
49+
50+
$app['controller.source'] = $app->share(
51+
function () use ($app) {
52+
return new SourceController($app);
53+
}
54+
);
55+
56+
$app['controller.contact'] = $app->share(
57+
function () use ($app) {
58+
return new ContactController($app);
59+
}
60+
);
61+
62+
$app['controller.default'] = $app->share(
63+
function () use ($app) {
64+
return new DefaultController($app);
65+
}
66+
);
67+
68+
$app->get('/', "controller.default:indexAction")->bind('homepage');
69+
70+
$app->get('/source', "controller.source:indexAction")->bind('source');
71+
$app->match('/source/new', "controller.source:newAction")->bind('source_new');
72+
$app->get('/source/list', "controller.source:listAction")->bind('source_list');
73+
$app->match('/source/upload', "controller.source:uploadAction")->bind('source_upload');
74+
75+
$name_pregmatch = '[A-Za-z.0-9-_ ]+';
76+
77+
$app->get('/contact/{name}', "controller.contact:indexAction")
78+
->assert('name', $name_pregmatch)
79+
->bind('contact');
80+
81+
$app->match('/contact/{name}/list', "controller.contact:listAction")
82+
->assert('name', $name_pregmatch)
83+
->bind('contact_list');
84+
85+
$app->get('/contact/{name}/edit', "controller.contact:editAction")
86+
->assert('name', $name_pregmatch)
87+
->bind('contact_edit');
88+
89+
$app->get('/contact/{name}/url', "controller.contact:urlAction")
90+
->assert('name', $name_pregmatch)
91+
->bind('contact_url');
92+
93+
$app->post('/contact/{name}/backup', "controller.contact:backupAction")
94+
->assert('name', $name_pregmatch)
95+
->bind('contact_backup');
96+
97+
$app->post('/contact/{name}/save', "controller.contact:saveAction")
98+
->assert('name', $name_pregmatch)
99+
->bind('contact_save');
100+
101+
return $app;

app/bootstrap.php

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
/*
3+
* Copyright 2014 IMAGIN Sp. z o.o. - imagin.pl
4+
*
5+
* For the full copyright and license information, please view the LICENSE
6+
* file that was distributed with this source code.
7+
*/
8+
9+
require_once __DIR__.'/../vendor/autoload.php';
10+
11+
$app = new Silex\Application();
12+
13+
$app->register(new Silex\Provider\ServiceControllerServiceProvider());
14+
$app->register(new Silex\Provider\TranslationServiceProvider(), array(
15+
'translator.messages' => array(),
16+
));
17+
$app->register(new Silex\Provider\SessionServiceProvider());
18+
$app->register(new Silex\Provider\FormServiceProvider());
19+
$app->register(new Silex\Provider\TwigServiceProvider(), array(
20+
'twig.path' => __DIR__ . '/../src/Octivi/views',
21+
));
22+
$app->register(new Silex\Provider\UrlGeneratorServiceProvider());
23+
$app->register(new Silex\Provider\ValidatorServiceProvider());
24+

app/properties.json.dist

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"directory": "pb",
3+
"defaultFileName": "contacts.xml",
4+
"debug": false
5+
}

box.json

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"main": "web/index.php",
3+
"output": "build/yealink-phonebook.phar",
4+
"web": true,
5+
"files": ["index.php"],
6+
"compactors": [
7+
"Herrera\\Box\\Compactor\\Php"
8+
],
9+
"finder": [
10+
{
11+
"exclude": ["Tests", "tests", "*.MD", "*.md", "properties.json", "*.dist"],
12+
"in": ["app", "vendor", "src", "web"]
13+
}
14+
]
15+
}

composer.json

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"name": "octivi/yealink-phonebook",
3+
"type": "application",
4+
"description": "Yealink PhoneBook Manager",
5+
"license": "GPL-3.0",
6+
"authors": [
7+
{
8+
"name": "Antoni Orfin",
9+
"email": "[email protected]"
10+
},
11+
{
12+
"name": "Piotr Cytera",
13+
"email": "[email protected]"
14+
}
15+
],
16+
"autoload": {
17+
"psr-0": {
18+
"": "src/"
19+
}
20+
},
21+
"require": {
22+
"silex/silex": "~1.1",
23+
"symfony/form": "~2.0",
24+
"symfony/config": "~2.0",
25+
"symfony/locale": "~2.2",
26+
"symfony/twig-bridge": "~2.2",
27+
"twig/twig": ">=1.8,<2.0-dev",
28+
"symfony/validator": "~2.3"
29+
},
30+
"require-dev": {
31+
"kherge/box": "~2.0"
32+
}
33+
}

dist/.htaccess

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
DirectoryIndex index.php
2+
3+
<IfModule mod_rewrite.c>
4+
RewriteEngine On
5+
6+
7+
# Redirect to URI without front controller to prevent duplicate content
8+
# (with and without `/app.php`). Only do this redirect on the initial
9+
# rewrite by Apache and not on subsequent cycles. Otherwise we would get an
10+
# endless redirect loop (request -> rewrite to front controller ->
11+
# redirect -> request -> ...).
12+
# So in case you get a "too many redirects" error or you always get redirected
13+
# to the startpage because your Apache does not expose the REDIRECT_STATUS
14+
# environment variable, you have 2 choices:
15+
# - disable this feature by commenting the following 2 lines or
16+
# - use Apache >= 2.3.9 and replace all git cheL flags by END flags and remove the
17+
# following RewriteCond (best solution)
18+
RewriteCond %{ENV:REDIRECT_STATUS} ^$
19+
RewriteRule ^index\.php(/(.*)|$) %{CONTEXT_PREFIX}/$2 [R=301,L]
20+
21+
# If the requested filename exists, simply serve it.
22+
# We only want to let Apache serve files and not directories.
23+
RewriteCond %{REQUEST_FILENAME} -f
24+
RewriteRule .? - [L]
25+
26+
# The following rewrites all other queries to the front controller. The
27+
# condition ensures that if you are using Apache aliases to do mass virtual
28+
# hosting, the base path will be prepended to allow proper resolution of the
29+
# app.php file; it will work in non-aliased environments as well, providing
30+
# a safe, one-size fits all solution.
31+
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
32+
RewriteRule ^(.*) - [E=BASE:%1]
33+
RewriteRule .? %{ENV:BASE}index.php [L]
34+
35+
# Order deny,allow
36+
# Deny from all
37+
# AuthName "Password protected"
38+
# AuthType Basic
39+
# AuthUserFile /path/to/.htpasswd
40+
# Require valid-user
41+
# Allow from 127.0.0.1 # your yealink phone IP.
42+
# Satisfy Any
43+
</IfModule>
44+

dist/index.php

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
/*
3+
* Copyright 2014 IMAGIN Sp. z o.o. - imagin.pl
4+
*
5+
* For the full copyright and license information, please view the LICENSE
6+
* file that was distributed with this source code.
7+
*/
8+
9+
$properties = array(
10+
'directory' => __DIR__ . '/pb', // default directory of the XML files
11+
'defaultFileName' => 'contacts.xml', // default phonebook file
12+
'debug' => true, // debug mode
13+
);
14+
15+
// Don't edit below this line
16+
$properties['rootDirectory'] = __DIR__;
17+
require_once 'yealink-phonebook.phar';

dist/pb/.gitkeep

Whitespace-only changes.

dist/pb/contacts.xml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<YealinkIPPhoneDirectory>
2+
<DirectoryEntry>
3+
<Name>Octivi HQ &lt;a href="http://octivi.com"&gt;&lt;b&gt;octivi.com&lt;/b&gt;&lt;/a&gt;</Name>
4+
<Telephone>0048717230120</Telephone>
5+
</DirectoryEntry>
6+
</YealinkIPPhoneDirectory>

index.php

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
3+
require_once __DIR__. '/web/index.php';
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
/*
3+
* Copyright 2014 IMAGIN Sp. z o.o. - imagin.pl
4+
*
5+
* For the full copyright and license information, please view the LICENSE
6+
* file that was distributed with this source code.
7+
*/
8+
9+
10+
namespace Octivi\Controller;
11+
12+
use Silex\Application;
13+
14+
abstract class BaseController
15+
{
16+
/**
17+
* @var \Silex\Application
18+
*/
19+
protected $app;
20+
21+
/**
22+
* @var \Twig_Environment
23+
*/
24+
protected $twig;
25+
26+
/**
27+
* @param Application $app
28+
*/
29+
public function __construct(Application $app)
30+
{
31+
$this->app = $app;
32+
$this->twig = $app['twig'];
33+
}
34+
}

0 commit comments

Comments
 (0)