iSchedule administration helper.
[davical.git] / htdocs / iSchedule.php
blob7bb61e92a46f5d7c8ffbb091a4c41f6dd4311d8d
1 <?php
3 include("./always.php");
4 include("DAViCalSession.php");
5 $session->LoginRequired('Admin');
7 include("interactive-page.php");
8 require_once("AwlQuery.php");
9 require_once('iSchedule.php');
11 $page_elements = array();
12 $page_elements[] = <<<EOBODY
13 <h1>iSchedule Configuration</h1>
14 <p>iSchedule allows caldav servers to communicate directly with each other, bypassing the need to send invitations via email, for scheduled events where attendees are using different servers or providers. Additionally it enables freebusy lookups for remote attendees. Events and ToDos received via iSchedule will show up in the users scheduling inbox.
15 <br>&nbsp;
16 </p>
17 <p>The <a href="http://wiki.davical.org/w/iSchedule_configuration">iSchedule configuration</a> requires a few DNS entries. DNS SRV record(s) will need to be created for all domains you wish to accept requests for, these are the domain portion of email address on Principal records in DAViCal examples are listed below for domains found in your database. At least 1 public key must also be published if you wish to send requests from this server.</p>
18 EOBODY;
20 $status = '<h2>Status</h2>';
21 if (!isset($c->scheduling_dkim_domain)) {
22 $status .= <<<EOBODY
23 <div class='error'>ERROR</div>
24 <p>scheduling_dkim_domain not set</p>
25 EOBODY;
27 elseif ( $c->scheduling_dkim_domain != $_SERVER['SERVER_NAME'] ) {
28 $status .= <<<EOBODY
29 <div class='error'>WARNING</div>
30 <p>scheduling_dkim_domain does not match server name</p></h3>
31 EOBODY;
33 else {
34 $status .= '<div >' . checkiSchedule() . '</div>';
36 $page_elements[] = $status;
38 function checkiSchedule () {
39 global $c;
40 $ret = '';
42 $s = new iSchedule ();
43 $s->domain = $c->scheduling_dkim_domain;
44 if (!$s->getServer())
45 $ret .= '<p>SRV record missing for '. $s->domain .' or DNS failure, the domain you are going to send events from should have an SRV record</p>' ;
46 if ($s->remote_server != $c->scheduling_dkim_domain)
47 $ret .= '<p>SRV record for '.$s->domain . ' points to wrong domain: ' . $s->remote_server . ' instead of ' . $c->scheduling_dkim_domain .'</p>';
48 $s->remote_server = $c->scheduling_dkim_domain;
49 $s->remote_selector = $c->scheduling_dkim_selector;
50 if (!$s->getTxt()) {
51 if (isset($c->schedule_private_key))
52 $ret .= '<p>TXT record missing for '.$s->remote_selector . '._domainkey.' . $s->domain .' or DNS failure, Private RSA key is configured</p>' ;
53 else {
54 $keys = generateKeys();
55 $config = '<p>please add the following section to your DAViCal configuration file<pre>$c->schedule_private_key = &lt;&lt;&lt;ENDOFKEY' ."\n";
56 $config .= $keys['private']; //implode ("\n", str_split ( base64_encode ( $keys['private'] ), 64 ));
57 $config .= "ENDOFKEY\n</pre>";
58 $config .= "<br/> and create a DNS TXT record for <b>" . $c->scheduling_dkim_selector . "._domainkey." . $c->scheduling_dkim_domain ;
59 $config .= "</b> that contains:<pre>";
60 $config .= "k=rsa; t=s; p=" . preg_replace('/-----(BEGIN|END) PUBLIC KEY-----\n/','',$keys['public']);
61 $config .= '</pre></p>';
62 $ret .= $config;
65 if ( ! $s->parseTxt() )
66 $ret .= '<p>TXT record corrupt for '. $s->remote_selector .'._domainkey.'. $s->domain .' or DNS failure</p>' ;
67 else if ( $ret == '' )
68 $ret = '<p>iSchedule OK</p>';
69 return $ret;
72 function generateKeys () {
73 $config = array('private_key_bits' => 512, 'private_key_type' => OPENSSL_KEYTYPE_RSA);
74 $newKey = openssl_pkey_new($config);
75 if ( $newKey !== false ) {
76 openssl_pkey_export($newKey,$privateKey);
77 $publicKey=openssl_pkey_get_details($newKey);
78 $publicKey=$publicKey['key'];
79 return Array('private' => $privateKey, 'public' => $publicKey);
81 return false;
84 include("classEditor.php");
85 include("classBrowser.php");
87 function SRVOk ( $value, $name, $row ) {
88 global $BrowserCurrentRow;
89 $s = new iSchedule();
90 $s->domain = $BrowserCurrentRow->domain;
91 return translate( ( $s->getServer()?'OK': SRVFormat ( $s->domain ) ) );
94 function SRVFormat ( $domain ) {
95 global $c;
96 switch ( $_REQUEST['srv_format'] )
98 case 'dnsmasq':
99 return 'srv_host=_ischedules._tcp.' . $domain .','. ($c->scheduling_dkim_domain?$c->scheduling_dkim_domain:$_SERVER['SERVER_NAME']) .','. $_SERVER['SERVER_PORT'] ;
100 case 'bind': //_http._tcp.example.com. IN SRV 0 5 80 www.example.com.
101 return '_ischedules._tcp.' . $domain .'. IN SRV 0 5 ' . $_SERVER['SERVER_PORT'] .' '. ($c->scheduling_dkim_domain?$c->scheduling_dkim_domain:$_SERVER['SERVER_NAME']) ;
102 default:
103 return '_ischedules._tcp.' . $domain .' '. ($c->scheduling_dkim_domain?$c->scheduling_dkim_domain:$_SERVER['SERVER_NAME']) .' '. $_SERVER['SERVER_PORT'] ;
107 $browser = new Browser(translate('iSchedule Domains'));
108 $browser->AddColumn( "domain", translate('Domain'),'left','' );
109 // function AddColumn( $field, $header="", $align="", $format="", $sql="", $class="", $datatype="", $hook=null ) {
110 $browser->AddColumn( "srvok", translate('SRV Record'),'right','',"''",'','','SRVOk' );
111 $browser->SetJoins( "usr " );
112 $browser->SetWhere( " email is not null and email <> ''" );
114 $browser->SetDistinct( " split_part(email,'@',2) as " );
116 $sql = "select distinct split_part(email,'@',2) as domain from usr where email is not null and email <> ''";
119 $page_elements[] = $browser;
121 $c->stylesheets[] = 'css/edit.css';
123 include("page-header.php");
126 * Page elements could be an array of viewers, browsers or something else
127 * that supports the Render() method... or a non-object which we assume is
128 * just a string of text that we echo.
130 $heading_level = null;
131 foreach( $page_elements AS $k => $page_element ) {
132 if ( is_object($page_element) ) {
133 echo $page_element->Render($heading_level);
134 $heading_level = 'h2';
136 else {
137 echo $page_element;
141 if (function_exists("post_render_function")) {
142 post_render_function();
145 include("page-footer.php");