This repository has been archived by the owner on Mar 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 5914114
Showing
9 changed files
with
305 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.idea/ | ||
*.pyc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Copyright (c) 2018 Marius Hein | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# StarfaceCallWorkflow | ||
|
||
This workflow places a call on the starface for a dedicated SIP device | ||
|
||
![Screenshot Of Alfred With Device](doc/alfred1.png) | ||
|
||
![Screenshot Of Alfred Without Device](doc/alfred2.png) | ||
|
||
## Prerequisites | ||
|
||
This workflow uses python 2.7 and xmlrpclib >= 1.0.1 | ||
|
||
## Configuration | ||
|
||
Place a credentials file in your HOME directory ```~/.starface_credentials``` and add the following content to it: | ||
|
||
1. Line: URL of the starface appliance | ||
2. Line: Login | ||
3. Line: Password | ||
4. Line: Preferred device (optional) | ||
|
||
Finally the file looks like this: | ||
|
||
```bash | ||
$ cat /Users/mhein/.starface_credentials | ||
https://mystarface.foo.bar | ||
0123 | ||
PASSWORD | ||
SIP/16 | ||
``` | ||
|
||
## Appendix | ||
|
||
### call.py | ||
|
||
The workflow contains a python script to place the call: | ||
|
||
```bash | ||
$ python call.py --help | ||
usage: call.py -n +49911777-777 [ -d SIP/dev ] [ -h ] | ||
|
||
optional arguments: | ||
-h, --help show this help message and exit | ||
-n NUMBER, --number NUMBER | ||
Call number | ||
-d DEVICE, --device DEVICE | ||
Place call on device, e.g. SIP/mydevice | ||
-c CREDENTIAL, --credential CREDENTIAL | ||
Credential file | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
import hashlib | ||
import os | ||
import logging | ||
import sys | ||
import xmlrpclib | ||
import ssl | ||
|
||
|
||
class StarfaceConfig(): | ||
def __init__(self, file): | ||
self.file = file | ||
|
||
self.__items = ['url', 'user', 'password', 'preferred_device'] | ||
self.url = None | ||
self.user = None | ||
self.password = None | ||
self.preferred_device = None | ||
|
||
self.__load(self.file) | ||
|
||
def __load(self, file): | ||
with open(file, 'r') as f: | ||
for item in self.__items: | ||
setattr(self, item, f.readline().rstrip()) | ||
|
||
index = 0 | ||
for item in self.__items[:-1]: | ||
index+=1 | ||
if not getattr(self, item): | ||
raise RuntimeError('Config item "{0}" missing (line number {1})'.format(item, index)) | ||
|
||
|
||
class StarfaceCaller(): | ||
def __init__(self, url, user, password): | ||
self.url = url | ||
self.user = user | ||
self.password = password | ||
|
||
self.proxy = xmlrpclib.ServerProxy(self.uri, verbose=False, use_datetime=True, | ||
context=ssl._create_unverified_context()) | ||
|
||
@property | ||
def uri(self): | ||
return '{0}/xml-rpc?de.vertico.starface.auth={1}'.format(self.url, self.auth) | ||
|
||
@property | ||
def auth(self): | ||
password = hashlib.sha512() | ||
password.update(self.password) | ||
|
||
auth = hashlib.sha512() | ||
auth.update(self.user) | ||
auth.update('*') | ||
auth.update(password.hexdigest().lower()) | ||
|
||
return '{0}:{1}'.format(self.user, auth.hexdigest()) | ||
|
||
def get_version(self): | ||
return self.proxy.ucp.v30.requests.system.getServerVersion() | ||
|
||
def place_call(self, number, preferred_device=''): | ||
login = self.proxy.ucp.v20.server.connection.login() | ||
if login: | ||
self.proxy.ucp.v20.server.communication.call.placeCall(number, preferred_device, '') | ||
self.proxy.ucp.v20.server.connection.logout() | ||
else: | ||
raise RuntimeError('Could not call login on starface') | ||
|
||
|
||
def main(): | ||
logging.basicConfig(level=logging.DEBUG) | ||
logger = logging.getLogger(__name__) | ||
|
||
import argparse | ||
|
||
name = os.path.basename(sys.argv[0]) | ||
|
||
parser = argparse.ArgumentParser(prog=name, | ||
usage='%(prog)s -n +49911777-777 [ -d SIP/dev ] [ -h ]') | ||
|
||
parser.add_argument('-n', '--number', dest='number', help='Call number') | ||
parser.add_argument('-d', '--device', dest='device', help='Place call on device, e.g. SIP/mydevice') | ||
parser.add_argument('-c', '--credential', dest='credential', help='Credential file', | ||
default='~/.starface_credentials') | ||
|
||
args = parser.parse_args() | ||
|
||
if not args.number: | ||
print('{0}: No argument "number" given'.format(name)) | ||
parser.print_usage() | ||
return 1 | ||
|
||
credential = os.path.expanduser(args.credential) | ||
logger.debug('Using credential file %s', credential) | ||
|
||
config = StarfaceConfig(credential) | ||
caller = StarfaceCaller(url=config.url, user=config.user, password=config.password) | ||
|
||
logger.debug('Starface Version: %s', caller.get_version()) | ||
|
||
preferred_device = '' | ||
if args.device: | ||
preferred_device = args.device | ||
elif config.preferred_device: | ||
preferred_device = config.preferred_device | ||
|
||
caller.place_call(args.number, preferred_device) | ||
|
||
return 0; | ||
|
||
|
||
if __name__ == '__main__': | ||
sys.exit(main()) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>bundleid</key> | ||
<string>mxhash.starfacecaller</string> | ||
<key>category</key> | ||
<string>Productivity</string> | ||
<key>connections</key> | ||
<dict> | ||
<key>16039760-F173-4AB8-9C73-DA7401D5DE23</key> | ||
<array/> | ||
<key>2C99F6F1-EF16-4CF1-9762-5D05A1FFAA4D</key> | ||
<array> | ||
<dict> | ||
<key>destinationuid</key> | ||
<string>16039760-F173-4AB8-9C73-DA7401D5DE23</string> | ||
<key>modifiers</key> | ||
<integer>0</integer> | ||
<key>modifiersubtext</key> | ||
<string></string> | ||
<key>vitoclose</key> | ||
<false/> | ||
</dict> | ||
</array> | ||
</dict> | ||
<key>createdby</key> | ||
<string>Marius Hein</string> | ||
<key>description</key> | ||
<string></string> | ||
<key>disabled</key> | ||
<true/> | ||
<key>name</key> | ||
<string>StarfaceCallWorkflow</string> | ||
<key>objects</key> | ||
<array> | ||
<dict> | ||
<key>config</key> | ||
<dict> | ||
<key>concurrently</key> | ||
<false/> | ||
<key>escaping</key> | ||
<integer>0</integer> | ||
<key>script</key> | ||
<string></string> | ||
<key>scriptargtype</key> | ||
<integer>1</integer> | ||
<key>scriptfile</key> | ||
<string>run.sh</string> | ||
<key>type</key> | ||
<integer>8</integer> | ||
</dict> | ||
<key>type</key> | ||
<string>alfred.workflow.action.script</string> | ||
<key>uid</key> | ||
<string>16039760-F173-4AB8-9C73-DA7401D5DE23</string> | ||
<key>version</key> | ||
<integer>2</integer> | ||
</dict> | ||
<dict> | ||
<key>config</key> | ||
<dict> | ||
<key>argumenttype</key> | ||
<integer>0</integer> | ||
<key>keyword</key> | ||
<string>call</string> | ||
<key>subtext</key> | ||
<string></string> | ||
<key>text</key> | ||
<string>Call number</string> | ||
<key>withspace</key> | ||
<true/> | ||
</dict> | ||
<key>type</key> | ||
<string>alfred.workflow.input.keyword</string> | ||
<key>uid</key> | ||
<string>2C99F6F1-EF16-4CF1-9762-5D05A1FFAA4D</string> | ||
<key>version</key> | ||
<integer>1</integer> | ||
</dict> | ||
</array> | ||
<key>readme</key> | ||
<string></string> | ||
<key>uidata</key> | ||
<dict> | ||
<key>16039760-F173-4AB8-9C73-DA7401D5DE23</key> | ||
<dict> | ||
<key>xpos</key> | ||
<integer>360</integer> | ||
<key>ypos</key> | ||
<integer>50</integer> | ||
</dict> | ||
<key>2C99F6F1-EF16-4CF1-9762-5D05A1FFAA4D</key> | ||
<dict> | ||
<key>xpos</key> | ||
<integer>50</integer> | ||
<key>ypos</key> | ||
<integer>50</integer> | ||
</dict> | ||
</dict> | ||
<key>webaddress</key> | ||
<string>https://github.com/mxhash/StarfaceCallerWorkflow</string> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/bin/bash | ||
|
||
dir=$(pwd -P) | ||
query="$1" | ||
preferred_device="" | ||
regex=" SIP/(.+)$" | ||
|
||
cd $dir | ||
|
||
if [[ $query =~ $regex ]]; then | ||
preferred_device="SIP/${BASH_REMATCH[1]}" | ||
fi | ||
|
||
query=${query// SIP\/[A-Za-z0-9]*/} | ||
|
||
exec python call.py -n "$query" -d "$preferred_device" |