Release changes for version 1.1.2
[davical.git] / htdocs / iSchedule.php
blobd6273f16e60d9c9ce7005563ad2086ec3e2ce135
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 if ( empty($BrowserCurrentRow->domain) ) return ''; // skip empty rows
90 $s = new iSchedule();
91 $s->domain = $BrowserCurrentRow->domain;
92 return translate( ( $s->getServer()?'OK': SRVFormat ( $s->domain ) ) );
95 function SRVFormat ( $domain ) {
96 global $c;
97 switch ( @$_REQUEST['srv_format'] )
99 case 'dnsmasq':
100 return 'srv_host=_ischedules._tcp.' . $domain .','. ($c->scheduling_dkim_domain?$c->scheduling_dkim_domain:$_SERVER['SERVER_NAME']) .','. $_SERVER['SERVER_PORT'] ;
101 case 'bind': //_http._tcp.example.com. IN SRV 0 5 80 www.example.com.
102 return '_ischedules._tcp.' . $domain .'. IN SRV 0 5 ' . $_SERVER['SERVER_PORT'] .' '. ($c->scheduling_dkim_domain?$c->scheduling_dkim_domain:$_SERVER['SERVER_NAME']) ;
103 default:
104 return '_ischedules._tcp.' . $domain .' '. ($c->scheduling_dkim_domain?$c->scheduling_dkim_domain:$_SERVER['SERVER_NAME']) .' '. $_SERVER['SERVER_PORT'] ;
108 $browser = new Browser(translate('iSchedule Domains'));
109 $browser->AddColumn( "domain", translate('Domain'),'left','' );
110 // function AddColumn( $field, $header="", $align="", $format="", $sql="", $class="", $datatype="", $hook=null ) {
111 $browser->AddColumn( "srvok", translate('SRV Record'),'right','',"''",'','','SRVOk' );
112 $browser->SetJoins( "usr " );
113 $browser->SetWhere( " email is not null and email <> ''" );
115 $browser->SetDistinct( " split_part(email,'@',2) as " );
117 $sql = "select distinct split_part(email,'@',2) as domain from usr where email is not null and email <> ''";
120 $page_elements[] = $browser;
122 $c->stylesheets[] = 'css/edit.css';
124 include("page-header.php");
127 * Page elements could be an array of viewers, browsers or something else
128 * that supports the Render() method... or a non-object which we assume is
129 * just a string of text that we echo.
131 $heading_level = null;
132 foreach( $page_elements AS $k => $page_element ) {
133 if ( is_object($page_element) ) {
134 echo $page_element->Render($heading_level);
135 $heading_level = 'h2';
137 else {
138 echo $page_element;
142 if (function_exists("post_render_function")) {
143 post_render_function();
146 include("page-footer.php");