Skip to content
This repository was archived by the owner on Mar 3, 2023. It is now read-only.

Commit 5914114

Browse files
committed
Big bang: Initial commit
0 parents  commit 5914114

File tree

9 files changed

+305
-0
lines changed

9 files changed

+305
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.idea/
2+
*.pyc

COPYING

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Copyright (c) 2018 Marius Hein
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
SOFTWARE.
20+

README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# StarfaceCallWorkflow
2+
3+
This workflow places a call on the starface for a dedicated SIP device
4+
5+
![Screenshot Of Alfred With Device](doc/alfred1.png)
6+
7+
![Screenshot Of Alfred Without Device](doc/alfred2.png)
8+
9+
## Prerequisites
10+
11+
This workflow uses python 2.7 and xmlrpclib >= 1.0.1
12+
13+
## Configuration
14+
15+
Place a credentials file in your HOME directory ```~/.starface_credentials``` and add the following content to it:
16+
17+
1. Line: URL of the starface appliance
18+
2. Line: Login
19+
3. Line: Password
20+
4. Line: Preferred device (optional)
21+
22+
Finally the file looks like this:
23+
24+
```bash
25+
$ cat /Users/mhein/.starface_credentials
26+
https://mystarface.foo.bar
27+
0123
28+
PASSWORD
29+
SIP/16
30+
```
31+
32+
## Appendix
33+
34+
### call.py
35+
36+
The workflow contains a python script to place the call:
37+
38+
```bash
39+
$ python call.py --help
40+
usage: call.py -n +49911777-777 [ -d SIP/dev ] [ -h ]
41+
42+
optional arguments:
43+
-h, --help show this help message and exit
44+
-n NUMBER, --number NUMBER
45+
Call number
46+
-d DEVICE, --device DEVICE
47+
Place call on device, e.g. SIP/mydevice
48+
-c CREDENTIAL, --credential CREDENTIAL
49+
Credential file
50+
```

call.py

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
import hashlib
2+
import os
3+
import logging
4+
import sys
5+
import xmlrpclib
6+
import ssl
7+
8+
9+
class StarfaceConfig():
10+
def __init__(self, file):
11+
self.file = file
12+
13+
self.__items = ['url', 'user', 'password', 'preferred_device']
14+
self.url = None
15+
self.user = None
16+
self.password = None
17+
self.preferred_device = None
18+
19+
self.__load(self.file)
20+
21+
def __load(self, file):
22+
with open(file, 'r') as f:
23+
for item in self.__items:
24+
setattr(self, item, f.readline().rstrip())
25+
26+
index = 0
27+
for item in self.__items[:-1]:
28+
index+=1
29+
if not getattr(self, item):
30+
raise RuntimeError('Config item "{0}" missing (line number {1})'.format(item, index))
31+
32+
33+
class StarfaceCaller():
34+
def __init__(self, url, user, password):
35+
self.url = url
36+
self.user = user
37+
self.password = password
38+
39+
self.proxy = xmlrpclib.ServerProxy(self.uri, verbose=False, use_datetime=True,
40+
context=ssl._create_unverified_context())
41+
42+
@property
43+
def uri(self):
44+
return '{0}/xml-rpc?de.vertico.starface.auth={1}'.format(self.url, self.auth)
45+
46+
@property
47+
def auth(self):
48+
password = hashlib.sha512()
49+
password.update(self.password)
50+
51+
auth = hashlib.sha512()
52+
auth.update(self.user)
53+
auth.update('*')
54+
auth.update(password.hexdigest().lower())
55+
56+
return '{0}:{1}'.format(self.user, auth.hexdigest())
57+
58+
def get_version(self):
59+
return self.proxy.ucp.v30.requests.system.getServerVersion()
60+
61+
def place_call(self, number, preferred_device=''):
62+
login = self.proxy.ucp.v20.server.connection.login()
63+
if login:
64+
self.proxy.ucp.v20.server.communication.call.placeCall(number, preferred_device, '')
65+
self.proxy.ucp.v20.server.connection.logout()
66+
else:
67+
raise RuntimeError('Could not call login on starface')
68+
69+
70+
def main():
71+
logging.basicConfig(level=logging.DEBUG)
72+
logger = logging.getLogger(__name__)
73+
74+
import argparse
75+
76+
name = os.path.basename(sys.argv[0])
77+
78+
parser = argparse.ArgumentParser(prog=name,
79+
usage='%(prog)s -n +49911777-777 [ -d SIP/dev ] [ -h ]')
80+
81+
parser.add_argument('-n', '--number', dest='number', help='Call number')
82+
parser.add_argument('-d', '--device', dest='device', help='Place call on device, e.g. SIP/mydevice')
83+
parser.add_argument('-c', '--credential', dest='credential', help='Credential file',
84+
default='~/.starface_credentials')
85+
86+
args = parser.parse_args()
87+
88+
if not args.number:
89+
print('{0}: No argument "number" given'.format(name))
90+
parser.print_usage()
91+
return 1
92+
93+
credential = os.path.expanduser(args.credential)
94+
logger.debug('Using credential file %s', credential)
95+
96+
config = StarfaceConfig(credential)
97+
caller = StarfaceCaller(url=config.url, user=config.user, password=config.password)
98+
99+
logger.debug('Starface Version: %s', caller.get_version())
100+
101+
preferred_device = ''
102+
if args.device:
103+
preferred_device = args.device
104+
elif config.preferred_device:
105+
preferred_device = config.preferred_device
106+
107+
caller.place_call(args.number, preferred_device)
108+
109+
return 0;
110+
111+
112+
if __name__ == '__main__':
113+
sys.exit(main())

doc/alfred1.png

22.9 KB
Loading

doc/alfred2.png

17.8 KB
Loading

icon.png

38 KB
Loading

info.plist

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>bundleid</key>
6+
<string>mxhash.starfacecaller</string>
7+
<key>category</key>
8+
<string>Productivity</string>
9+
<key>connections</key>
10+
<dict>
11+
<key>16039760-F173-4AB8-9C73-DA7401D5DE23</key>
12+
<array/>
13+
<key>2C99F6F1-EF16-4CF1-9762-5D05A1FFAA4D</key>
14+
<array>
15+
<dict>
16+
<key>destinationuid</key>
17+
<string>16039760-F173-4AB8-9C73-DA7401D5DE23</string>
18+
<key>modifiers</key>
19+
<integer>0</integer>
20+
<key>modifiersubtext</key>
21+
<string></string>
22+
<key>vitoclose</key>
23+
<false/>
24+
</dict>
25+
</array>
26+
</dict>
27+
<key>createdby</key>
28+
<string>Marius Hein</string>
29+
<key>description</key>
30+
<string></string>
31+
<key>disabled</key>
32+
<true/>
33+
<key>name</key>
34+
<string>StarfaceCallWorkflow</string>
35+
<key>objects</key>
36+
<array>
37+
<dict>
38+
<key>config</key>
39+
<dict>
40+
<key>concurrently</key>
41+
<false/>
42+
<key>escaping</key>
43+
<integer>0</integer>
44+
<key>script</key>
45+
<string></string>
46+
<key>scriptargtype</key>
47+
<integer>1</integer>
48+
<key>scriptfile</key>
49+
<string>run.sh</string>
50+
<key>type</key>
51+
<integer>8</integer>
52+
</dict>
53+
<key>type</key>
54+
<string>alfred.workflow.action.script</string>
55+
<key>uid</key>
56+
<string>16039760-F173-4AB8-9C73-DA7401D5DE23</string>
57+
<key>version</key>
58+
<integer>2</integer>
59+
</dict>
60+
<dict>
61+
<key>config</key>
62+
<dict>
63+
<key>argumenttype</key>
64+
<integer>0</integer>
65+
<key>keyword</key>
66+
<string>call</string>
67+
<key>subtext</key>
68+
<string></string>
69+
<key>text</key>
70+
<string>Call number</string>
71+
<key>withspace</key>
72+
<true/>
73+
</dict>
74+
<key>type</key>
75+
<string>alfred.workflow.input.keyword</string>
76+
<key>uid</key>
77+
<string>2C99F6F1-EF16-4CF1-9762-5D05A1FFAA4D</string>
78+
<key>version</key>
79+
<integer>1</integer>
80+
</dict>
81+
</array>
82+
<key>readme</key>
83+
<string></string>
84+
<key>uidata</key>
85+
<dict>
86+
<key>16039760-F173-4AB8-9C73-DA7401D5DE23</key>
87+
<dict>
88+
<key>xpos</key>
89+
<integer>360</integer>
90+
<key>ypos</key>
91+
<integer>50</integer>
92+
</dict>
93+
<key>2C99F6F1-EF16-4CF1-9762-5D05A1FFAA4D</key>
94+
<dict>
95+
<key>xpos</key>
96+
<integer>50</integer>
97+
<key>ypos</key>
98+
<integer>50</integer>
99+
</dict>
100+
</dict>
101+
<key>webaddress</key>
102+
<string>https://github.com/mxhash/StarfaceCallerWorkflow</string>
103+
</dict>
104+
</plist>

run.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
dir=$(pwd -P)
4+
query="$1"
5+
preferred_device=""
6+
regex=" SIP/(.+)$"
7+
8+
cd $dir
9+
10+
if [[ $query =~ $regex ]]; then
11+
preferred_device="SIP/${BASH_REMATCH[1]}"
12+
fi
13+
14+
query=${query// SIP\/[A-Za-z0-9]*/}
15+
16+
exec python call.py -n "$query" -d "$preferred_device"

0 commit comments

Comments
 (0)