|
1 | 1 | <?php
|
2 | 2 |
|
3 |
| -if (isset($_POST['username'])) { |
4 |
| - $_POST['path'] = '/'.$_POST['username'].'#'; |
5 |
| - $_SERVER['SERVER_NAME'] = 'id.'.ROOT_DOMAIN; |
6 |
| -} |
7 |
| - |
8 |
| -// Prepare the request |
9 |
| -$name = (isset($_POST['name']))?$_POST['name']:'Anonymous'; |
10 |
| -if (isset($_POST['path'])) { |
11 |
| - $path = (substr($_POST['path'], 0, 1) == '/')?substr($_POST['path'], 1):$_POST['path']; |
| 3 | +// create a WebID certificate + profile data |
| 4 | +if (isset($_POST['SPKAC']) && isset($_POST['username'])) { |
| 5 | + // Prepare the request |
| 6 | + $name = (isset($_POST['name']))?$_POST['name']:'Anonymous'; |
| 7 | + |
| 8 | + if (isset($_POST['path'])) { |
| 9 | + $_POST['path'] = (substr($_POST['path'], 0, 1) == '/')?substr($_POST['path'], 1):$_POST['path']; |
| 10 | + $path = $_POST['path']; |
| 11 | + } else { |
| 12 | + $path = 'profile/card#me'; |
| 13 | + } |
12 | 14 | // Exit if we don't have a #
|
13 | 15 | if (strpos($path, '#') === false) // missing #
|
14 | 16 | die("You must at least provide a # fragment. For example: #me or #public.");
|
|
17 | 19 | $path_frag = explode('#', $path);
|
18 | 20 | $profile = $path_frag[0];
|
19 | 21 | $hash = $path_frag[1];
|
20 |
| - |
| 22 | + $_root = $_ENV['CLOUD_DATA'].'/'.$_POST['username'].'.'.ROOT_DOMAIN; |
| 23 | + |
21 | 24 | // rebuild path for the profile document
|
22 | 25 | $webid_file = $_root.'/'.$profile;
|
23 | 26 |
|
24 |
| - // do not overwrite existing profile document |
| 27 | + // create but do not overwrite existing profile document |
25 | 28 | if (file_exists($webid_file) === true) {
|
26 | 29 | die('Error: <strong>'. $path.'</strong> already exists!');
|
27 | 30 | } else {
|
28 |
| - // check if the root dir exists and create it (recursively) if it doesn't |
29 |
| - if (strstr($webid_file,'/id.')===FALSE) |
| 31 | + // check if the root dir exists and create it (recursively) if it doesn't |
30 | 32 | if (!mkdir(dirname($webid_file), 0755, true))
|
31 |
| - die('Cannot create directory, please check permissions.'); |
| 33 | + die('Cannot create directory at '.dirname($webid_file).', please check permissions.'); |
32 | 34 | }
|
33 |
| -} else { |
34 |
| - die('You need to provide a preferred identifier.'); |
35 |
| -} |
36 |
| - |
37 |
| -$BASE = 'https://'.$_SERVER['SERVER_NAME']; // force https |
38 |
| -$email = $_POST['email']; |
39 |
| -$spkac = str_replace(str_split("\n\r"), '', $_POST['SPKAC']); |
40 |
| -$webid = 'https://'.$_SERVER['SERVER_NAME'].'/'.$path; |
41 | 35 |
|
42 |
| -$cert_cmd = 'python '.$_ENV['CLOUD_HOME'].'/py/pki.py '. |
43 |
| - " -s '$spkac'" . |
44 |
| - " -n '$name'" . |
45 |
| - " -w '$webid'"; |
46 |
| - |
47 |
| -// Send the certificate back to the user |
48 |
| -header('Content-Type: application/x-x509-user-cert'); |
49 |
| -$cert = trim(shell_exec($cert_cmd)); |
50 |
| -$ret_cmd = "echo '$cert' | openssl x509 -in /dev/stdin -outform der"; |
51 |
| -echo trim(shell_exec($ret_cmd)); |
52 |
| - |
53 |
| -$mod_cmd = "echo '$cert' | openssl x509 -in /dev/stdin -modulus -noout"; |
54 |
| -// remove the Modulus= part |
55 |
| -$output = explode('=', trim(shell_exec($mod_cmd))); |
56 |
| -$modulus = $output[1]; |
57 |
| - |
58 |
| -/* --- Profile --- */ |
59 |
| - |
60 |
| -// Write the new profile to disk |
61 |
| -$document = new Graph('', $webid_file, '', $BASE.'/'.$profile); |
62 |
| -if (!$document) { |
63 |
| - echo "Cannot create a new graph!"; |
64 |
| - exit; |
65 |
| -} |
| 36 | + $BASE = 'https://'.$_POST['username'].'.'.$_SERVER['SERVER_NAME']; // force https |
| 37 | + $email = isset($_POST['email'])?$_POST['email']:null; |
| 38 | + $spkac = str_replace(str_split("\n\r"), '', $_POST['SPKAC']); |
| 39 | + $webid = $BASE.'/'.$path; |
| 40 | + |
| 41 | + // --- Cert --- |
| 42 | + $cert_cmd = 'python '.$_ENV['CLOUD_HOME'].'/py/pki.py '. |
| 43 | + " -s '$spkac'" . |
| 44 | + " -n '$name'" . |
| 45 | + " -w '$webid'"; |
| 46 | + |
| 47 | + // Send the certificate back to the user |
| 48 | + header('Content-Type: application/x-x509-user-cert'); |
| 49 | + |
| 50 | + $cert = trim(shell_exec($cert_cmd)); |
| 51 | + $ret_cmd = "echo '$cert' | openssl x509 -in /dev/stdin -outform der"; |
| 52 | + echo trim(shell_exec($ret_cmd)); |
| 53 | + |
| 54 | + $mod_cmd = "echo '$cert' | openssl x509 -in /dev/stdin -modulus -noout"; |
| 55 | + // remove the Modulus= part |
| 56 | + $output = explode('=', trim(shell_exec($mod_cmd))); |
| 57 | + $modulus = $output[1]; |
| 58 | + |
| 59 | + // --- Workspaces --- |
| 60 | + // create shared storage space |
| 61 | + $storage_uri = $BASE.'/storage/'; |
| 62 | + $storage_file = $_root.'/storage/'; |
| 63 | + if (!mkdir($storage_file, 0755, true)) |
|
6D3F
64 | + die('Cannot create storage space "'.$storage_file.'", please check permissions'); |
| 65 | + // end workspaces |
| 66 | + |
| 67 | + // --- Profile --- |
| 68 | + // Write the new profile to disk |
| 69 | + $document = new Graph('', $webid_file, '', $BASE.'/'.$profile); |
| 70 | + if (!$document) { |
| 71 | + echo "Cannot create a new graph!"; |
| 72 | + exit; |
| 73 | + } |
| 74 | + |
| 75 | + // add a PrimaryTopic |
| 76 | + $document->append_objects($BASE.'/'.$profile, |
| 77 | + 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', |
| 78 | + array(array('type'=>'uri', 'value'=>'http://xmlns.com/foaf/0.1/PersonalProfileDocument'))); |
| 79 | + $document->append_objects($BASE.'/'.$profile, |
| 80 | + 'http://xmlns.com/foaf/0.1/primaryTopic', |
| 81 | + array(array('type'=>'uri', 'value'=>$webid))); |
| 82 | + |
| 83 | + // add a foaf:Person |
| 84 | + $document->append_objects($webid, |
| 85 | + 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', |
| 86 | + array(array('type'=>'uri', 'value'=>'http://xmlns.com/foaf/0.1/Person'))); |
| 87 | + // add name |
| 88 | + $document->append_objects($webid, |
| 89 | + 'http://xmlns.com/foaf/0.1/name', |
| 90 | + array(array('type'=>'literal', 'value'=>$name))); |
| 91 | + // add mbox if we have one |
| 92 | + if (strlen($email) > 0) { |
| 93 | + $document->append_objects($webid, |
| 94 | + 'http://xmlns.com/foaf/0.1/mbox', |
| 95 | + array(array('type'=>'uri', 'value'=>'mailto:'.$email))); |
| 96 | + } |
66 | 97 |
|
67 |
| -// add a PrimaryTopic |
68 |
| -$document->append_objects($BASE.'/'.$profile, |
69 |
| - 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', |
70 |
| - array(array('type'=>'uri', 'value'=>'http://xmlns.com/foaf/0.1/PersonalProfileDocument'))); |
71 |
| -$document->append_objects($BASE.'/'.$profile, |
72 |
| - 'http://xmlns.com/foaf/0.1/primaryTopic', |
73 |
| - array(array('type'=>'uri', 'value'=>$_base.$path))); |
74 |
| - |
75 |
| -// add a foaf:Person |
76 |
| -$document->append_objects($webid, |
77 |
| - 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', |
78 |
| - array(array('type'=>'uri', 'value'=>'http://xmlns.com/foaf/0.1/Person'))); |
79 |
| -// add name |
80 |
| -$document->append_objects($webid, |
81 |
| - 'http://xmlns.com/foaf/0.1/name', |
82 |
| - array(array('type'=>'literal', 'value'=>$name))); |
83 |
| -// add mbox if we have one |
84 |
| -if (strlen($email) > 0) { |
| 98 | + // ---- Add workspaces ---- |
| 99 | + // add shared storage space |
| 100 | + $document->append_objects($webid, |
| 101 | + 'http://www.w3.org/ns/pim/space#storage', |
| 102 | + array(array('type'=>'uri', 'value'=>$storage_uri))); |
| 103 | + |
| 104 | + // ---- Certificate ---- |
| 105 | + // add modulus and exponent as bnode |
85 | 106 | $document->append_objects($webid,
|
86 |
| - 'http://xmlns.com/foaf/0.1/mbox', |
87 |
| - array(array('type'=>'uri', 'value'=>'mailto:'.$email))); |
| 107 | + 'http://www.w3.org/ns/auth/cert#key', |
| 108 | + array(array('type'=>'bnode', 'value'=>'_:bnode1'))); |
| 109 | + $document->append_objects('_:bnode1', |
| 110 | + 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', |
| 111 | + array(array('type'=>'uri', 'value'=>'http://www.w3.org/ns/auth/cert#RSAPublicKey'))); |
| 112 | + |
| 113 | + if (isset($modulus)) |
| 114 | + $document->append_objects('_:bnode1', |
| 115 | + 'http://www.w3.org/ns/auth/cert#modulus', |
| 116 | + array(array('type'=>'literal', 'value'=>$modulus, 'datatype'=>'http://www.w3.org/2001/XMLSchema#hexBinary'))); |
| 117 | + |
| 118 | + $document->append_objects('_:bnode1', |
| 119 | + 'http://www.w3.org/ns/auth/cert#exponent', |
| 120 | + array(array('type'=>'literal', 'value'=>'65537', 'datatype'=>'http://www.w3.org/2001/XMLSchema#int'))); |
| 121 | + |
| 122 | + $document->save(); |
| 123 | + |
| 124 | + // ------ DONE WITH PROFILE ------- |
| 125 | + |
| 126 | + // ------ ACLs ------ |
| 127 | + // TODO: check if this is something we should do on the server side |
| 128 | + /* |
| 129 | + // master workspace |
| 130 | + $mw_acl = new Graph('', $mw_file, '', $mw_uri); |
| 131 | + $ap_acl = new Graph('', $ap_file, '', $ap_uri); |
| 132 | + $sh_acl = new Graph('', $sh_file, '', $sh_uri); |
| 133 | + $pu_acl = new Graph('', $pu_file, '', $pu_uri); |
| 134 | + $pr_acl = new Graph('', $pr_file, '', $pr_uri); |
| 135 | + |
| 136 | + if (!$mw_acl || !$ap_acl || $sh_acl || !pu_acl || !pr_acl) { |
| 137 | + echo "Cannot create ACL graphs!"; |
| 138 | + exit; |
| 139 | + } |
| 140 | + |
| 141 | + <> |
| 142 | + <http://www.w3.org/ns/auth/acl#accessTo> <> ; |
| 143 | + <http://www.w3.org/ns/auth/acl#agent> <https://my-profile.eu/people/deiu/card#me> ; |
| 144 | + <http://www.w3.org/ns/auth/acl#mode> <http://www.w3.org/ns/auth/acl#Read>, <http://www.w3.org/ns/auth/acl#Write> . |
| 145 | +
|
| 146 | +<#private/> |
| 147 | + <http://www.w3.org/ns/auth/acl#accessTo> <private/> ; |
| 148 | + <http://www.w3.org/ns/auth/acl#agent> <https://my-profile.eu/people/deiu/card#me> ; |
| 149 | + <http://www.w3.org/ns/auth/acl#mode> <http://www.w3.org/ns/auth/acl#Read>, <http://www.w3.org/ns/auth/acl#Write> . |
| 150 | + */ |
88 | 151 | }
|
89 |
| - |
90 |
| -// add modulus and exponent as bnode |
91 |
| -$document->append_objects($webid, |
92 |
| - 'http://www.w3.org/ns/auth/cert#key', |
93 |
| - array(array('type'=>'bnode', 'value'=>'_:bnode1'))); |
94 |
| -$document->append_objects('_:bnode1', |
95 |
| - 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', |
96 |
| - array(array('type'=>'uri', 'value'=>'http://www.w3.org/ns/auth/cert#RSAPublicKey'))); |
97 |
| - |
98 |
| -if (isset($modulus)) |
99 |
| -$document->append_objects('_:bnode1', |
100 |
| - 'http://www.w3.org/ns/auth/cert#modulus', |
101 |
| - array(array('type'=>'literal', 'value'=>$modulus, 'datatype'=>'http://www.w3.org/2001/XMLSchema#hexBinary'))); |
102 |
| - |
103 |
| -$document->append_objects('_:bnode1', |
104 |
| - 'http://www.w3.org/ns/auth/cert#exponent', |
105 |
| - array(array('type'=>'literal', 'value'=>'65537', 'datatype'=>'http://www.w3.org/2001/XMLSchema#int'))); |
106 |
| - |
107 |
| -$document->save(); |
108 |
| - |
|
0 commit comments