Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

atom.php

Go to the documentation of this file.
00001 <?php 00002 $ROOTURL = "http://atom.dosimple.ch/atom/"; 00003 $ROOTPATH = "atomServer"; 00004 $SALT = 'paprika'; 00005 $NONCE = sha1(md5($SALT.time())); 00006 00007 include_once($ROOTPATH."/inc/fct.inc.php"); 00008 include_once($ROOTPATH."/atomServer.class.php"); 00009 00010 // récupération des données HTTP 00011 $info = captureInfo(); 00012 $get = captureGet(); 00013 00014 $atom = new AtomServer($ROOTPATH, $ROOTURL); 00015 00016 if(isset($info['x-atom-authentication']) && isset($get['login'])) 00017 { 00018 $user = $info['x-atom-authentication']['user']; 00019 00020 $userdata = $atom->getUserData($user); 00021 $password = $userdata['password']; 00022 00023 $password = pwdDecode($user,$password,$SALT); 00024 00025 //A1 = username + ":" + realm + ":" + password 00026 $a1 = $user.":".$info['x-atom-authentication']['realm'].":".$password; 00027 //A2 = verb + ":" + uri 00028 $a2 = $info['method'].":".$info['url']; 00029 //response = sha(sha(A1) + ":" + nonce + ":" + "00000001" + ":" + cnonce + ":" + qop + ":" + sha(A2)) 00030 $response = sha1( 00031 sha1($a1).":" 00032 .$info['x-atom-authentication']['nonce'].":" 00033 .$info['x-atom-authentication']['nc'].":" 00034 .$info['x-atom-authentication']['cnonce'].":" 00035 .$info['x-atom-authentication']['qop'].":".sha1($a2)); 00036 00037 if($response == $info['x-atom-authentication']['response'] && $info['x-atom-authentication']['user'] == $get['login']) 00038 { 00039 $info['validated'] = true; 00040 unset($info['x-atom-authentification']); 00041 } 00042 else 00043 { 00044 header('WWW-Authenticate: Atom realm="a(tom)Blog", qop="atom-auth", algorithm="SHA", nonce="'.$NONCE.'"'); 00045 header('Content-Type: text/xml; charset; charset=utf-8'); 00046 echo '<?xml version="1.0" encoding="utf-8"?>'; 00047 echo '<error><msg>Error, need help ?</msg><link>/docs/authentication.html</link></error>'; 00048 exit(0); 00049 } 00050 /*đđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđ 00051 P U T 00052 __________________________________________________________________________________________________________________*/ 00053 $method = strtoupper($info['method']); 00054 if($method == 'PUT') 00055 { 00056 if(!$atom->setEntry($get['login'],$get['date'].'_'.$get['entry'],$info['data'])) 00057 { 00058 header('HTTP/1.1 500 Internal server error'); 00059 } 00060 else 00061 { 00062 header('HTTP/1.1 205 Reset Content'); 00063 } 00064 exit(0); 00065 } 00066 /*đđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđ 00067 P O S T 00068 __________________________________________________________________________________________________________________*/ 00069 else if($method == 'POST') 00070 { 00071 if(!$atom->addEntry($get['login'],$info['data'])) 00072 { 00073 header('HTTP/1.1 500 Internal server error'); 00074 } 00075 else 00076 { 00077 header('HTTP/1.1 201 Created'); 00078 //header('Location : ??'); 00079 } 00080 exit(0); 00081 } 00082 /*đđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđ 00083 D E L E T E 00084 __________________________________________________________________________________________________________________*/ 00085 else if($method == 'DELETE') 00086 { 00087 if(!$atom->delEntry($get['login'],$get['date'].'_'.$get['entry'],$info['data'])) 00088 { 00089 header('HTTP/1.1 500 Internal server error'); 00090 } 00091 else 00092 { 00093 header('HTTP/1.1 200 OK'); 00094 } 00095 exit(0); 00096 } 00097 header('X-Atom-Authentication-Info: nextnonce="'.$nonce.'"'); 00098 //exit(0); 00099 } 00100 /*đđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđđ 00101 G E T 00102 __________________________________________________________________________________________________________________*/ 00103 if(strtoupper($info['method']) == 'GET') 00104 { 00105 if(isset($get['mode'])) 00106 { 00107 switch($get['mode']) 00108 { 00109 case 'introspection': 00110 $header = 'Content-Type: application/x.atom+xml; charset=utf-8'; 00111 $data = $atom->getIntrospection($get['login']); 00112 break; 00113 case 'year': 00114 case 'month': 00115 case 'day': 00116 $header = 'Content-Type: text/html; charset=utf-8'; 00117 $data = $atom->getXhtmlArchives($get['login'], $get['date']); 00118 break; 00119 case 'entry': 00120 switch ($get['method']) 00121 { 00122 case 'atom': 00123 $header = 'Content-Type: application/x.atom+xml; charset=utf-8'; 00124 $data = $atom->getEntry($get['login'],$get['date'].'_'.$get['entry']); 00125 break; 00126 case 'html': 00127 default: 00128 $header = 'Content-Type: text/html; charset=utf-8'; 00129 $data .= $atom->getXhtmlEntry($get['login'],$get['date'].'_'.$get['entry']); 00130 break; 00131 } 00132 break; 00133 case 'feed': 00134 switch ($get['method']) 00135 { 00136 case 'rss091': 00137 $header = 'Content-Type: text/xml; charset=utf-8'; 00138 $data = $atom->getRss091Feed($get['login']); 00139 break; 00140 case 'atom': 00141 default: 00142 $header = 'Content-Type: application/x.atom+xml; charset=utf-8'; 00143 $data = $atom->getFeed($get['login']); 00144 break; 00145 } 00146 break; 00147 case 'user': 00148 $header = 'Content-Type: text/html; charset=utf-8'; 00149 $data .= $atom->getXhtmlFeed($get['login']); 00150 break; 00151 case 'help': 00152 default: 00153 $header = 'Content-Type: text/xml; charset=utf-8'; 00154 $data .= '<error><msg>Error, need help ?</msg><link>http://atom.dosimple.ch/docs/</link></error>'; 00155 break; 00156 } 00157 00158 header($header); 00159 echo $data; 00160 } 00161 else 00162 { 00163 echo "<error><msg>empty query</msg></error>"; 00164 } 00165 exit(0); 00166 } 00167 else 00168 { 00169 //header('WWW-Authenticate: WSSE realm="a(tom)Blog", profile="UsernameToken"'); 00170 header('WWW-Authenticate: Atom realm="a(tom)Blog", qop="atom-auth", algorithm="SHA", nonce="'.$NONCE.'"'); 00171 header("Content-Type: text/xml; charset=utf-8"); 00172 echo '<?xml version="1.0" encoding="utf-8"?>'; 00173 echo '<error> 00174 <msg>Error, need help ?</msg> 00175 <link>/docs/authentication.html</link> 00176 </error>'; 00177 } 00178 ?>

Generated on Fri Jun 25 00:00:22 2004 for a(tom)Blog by doxygen 1.3.7