A user has given this how to get wwwauth to work on PHP as CGI on Apache - it is CMSimple version 2.4 - and "Copy of cms.php" is original cms.php:
Code:
Compare: (<)C:\Documents and Settings\Administrator\Skrivebord\Copy of cms.php (41459 bytes)
with: (>)C:\Documents and Settings\Administrator\Skrivebord\cms.php (42379 bytes)
81,111c81,128
< $adm=(gc('status')=='adm'&&logincheck());
<
< if($login&&!$adm)
< {
< if($cf['security']['wwwaut']!='true')
< {
< if($passwd==$cf['security']['password'])
< {
< setcookie('status','adm');
< setcookie('passwd',$passwd);
< $adm=true;
< $edit=true;
< writelog(date("Y-m-d H:i:s")." from ".sv('REMOTE_ADDR')." logged_in\n");
< }
< else getlost();
< }
< else
< {
< if(sv('PHP_AUTH_USER')==''||sv('PHP_AUTH_PW')==''||gc('status')=='')
< {
< // In a future version of CMSimple this new Server API check will replace the setting of a variable
< if($cf['security']['wwwaut']=='true'&&(php_sapi_name()=='cgi'||php_sapi_name()=='cgi-fcgi'))
< {
< $e.='<li>security_wwwaut should only be set true, when Server API is apache - your is '.php_sapi_name().' - please see <a href="http://www.cmsimple.dk/?Requirements">http://www.cmsimple.dk/?Requirements</a>';
< }
< else
< {
< setcookie('status','login');
< header('WWW-Authenticate: Basic realm="'.$tx['login']['warning'].'"');
< getlost();
< }
---
> //$headers = getallheaders();
> //$auth=$headers['authorization'];
> //if ($auth=='') { $auth=$headers['Authorization']; }
>
> if(preg_match('/Basic+(.*)$/i', $_SERVER['REMOTE_USER'], $matches)) {
> list($name, $password) = explode(':', base64_decode($matches[1]));
> $_SERVER['PHP_AUTH_USER'] = strip_tags($name);
> $_SERVER['PHP_AUTH_PW'] = strip_tags($password);
> }
>
> //if((!$_SERVER['PHP_AUTH_USER'] || !$_SERVER['PHP_AUTH_USER']) && ($cf['security']['wwwaut']=='true')
> // && preg_match('/Basics+(.*)$/i', $_SERVER['REMOTE_USER'], $matches)) {
> // list($name, $password) = explode(':', base64_decode($matches[1]));
> // $_SERVER['PHP_AUTH_USER'] = strip_tags($name);
> // $_SERVER['PHP_AUTH_PW'] = strip_tags($password);
> // }
> //print "-->" . $_SERVER['PHP_AUTH_USER'] . "<--\n";
> //print "-->" . $_SERVER['PHP_AUTH_PW'] . "<--\n";
>
>
>
> $adm=(gc('status')=='adm'&&logincheck());
> if($login&&!$adm)
> {
> if($cf['security']['wwwaut']!='true')
> {
> if($passwd==$cf['security']['password'])
> {
> setcookie('status','adm');
> setcookie('passwd',$passwd);
> $adm=true;
> $edit=true;
> writelog(date("Y-m-d H:i:s")." from ".sv('REMOTE_ADDR')." logged_in\n");
> }
> else getlost();
> }
> else
> {
> if(sv('PHP_AUTH_USER')==''||sv('PHP_AUTH_PW')==''||gc('status')=='')
> {
> // In a future version of CMSimple this new Server API check will replace the setting of a variable
> if($cf['security']['wwwaut']=='true'&&(php_sapi_name()=='cgis'||php_sapi_name()=='cgi-fcgi'))
> {
> //$e.='<li>security_wwwaut should only be set true, when Server API is apache - your is '.php_sapi_name().' - please see <a href="http://www.cmsimple.dk/?Requirements">http://www.cmsimple.dk/?Requirements</a>';
> setcookie('status','login');
> //phpinfo();
> header('WWW-Authenticate: Basic realm="'.$tx['login']['warning'].'"');
> getlost();
115,155c132,168
< if(logincheck())
< {
< setcookie('status','adm');
< $adm=true;
< $edit=true;
< writelog(date($tx['log']['dateformat']).' '.sv('REMOTE_ADDR').' '.$tx['log']['loggedin']."\n");
< }
< else
< {
< getlost();
< }
< }
< }
< }
< else if($logout&&$adm)
< {
< $fn=date("YmdHis").'.htm';
< if(@copy($pth['file']['content'],$pth['folder']['content'].$fn))
< {
< $o.='<p>'.ucfirst($tx['filetype']['backup']).' '.$fn.' '.$tx['result']['created'].'</p>';
< $fl=array();
< $fd=@opendir($pth['folder']['content']);
< while(($p=@readdir($fd))==true)
< {
< if(preg_match("/\d{3}\.htm/",$p))$fl[]=$p;
< }
< if($fd==true)closedir($fd);
< @sort($fl,SORT_STRING);
< $v=count($fl)-$cf['backup']['numberoffiles'];
< for($i=0;$i<$v;$i++)
< {
< if(@unlink($pth['folder']['content'].'/'.$fl[$i]))$o.='<p>'.ucfirst($tx['filetype']['backup']).' '.$fl[$i].' '.$tx['result']['deleted'].'</p>';
< else e('cntdelete','backup',$fl[$i]);
< }
< }
< else e('cntsave','backup',$fn);
< $adm=false;
< setcookie('status','');
< setcookie('passwd','');
< $o.='<p><font color="red">'.$tx['login']['loggedout'].'</font></p>';
< }
---
> setcookie('status','login');
> header('WWW-Authenticate: Basic realm="'.$tx['login']['warning'].'"');
> getlost();
> }
> }
> else
> {
> if(logincheck())
> {
> setcookie('status','adm');
> $adm=true;
> $edit=true;
> writelog(date($tx['log']['dateformat']).' '.sv('REMOTE_ADDR').' '.$tx['log']['loggedin']."\n");
> }
> else
> {
> getlost();
> }
> }
> }
> }else
> if($logout&&$adm){$fn=date("YmdHis").'.htm';
> if(@copy($pth['file']['content'],$pth['folder']['content'].$fn)){$o.='<p>'.ucfirst($tx['filetype']['backup']).' '.$fn.' '.$tx['result']['created'].'</p>';
> $fl=array();
> $fd=@opendir($pth['folder']['content']);
> while(($p=@readdir($fd))==true){if(preg_match("/\d{3}\.htm/",$p))$fl[]=$p;}
> if($fd==true)closedir($fd);
> @sort($fl,SORT_STRING);
> $v=count($fl)-$cf['backup']['numberoffiles'];
> for($i=0;$i<$v;$i++){
> if(@unlink($pth['folder']['content'].'/'.$fl[$i]))$o.='<p>'.ucfirst($tx['filetype']['backup']).' '.$fl[$i].' '.$tx['result']['deleted'].'</p>';else e('cntdelete','backup',$fl[$i]);
> }}else e('cntsave','backup',$fn);
> $adm=false;
> setcookie('status','');
> setcookie('passwd','');
> $o.='<p><font color="red">'.$tx['login']['loggedout'].'</font></p>';
> }
261,262c274,277
< function sv($s){global $HTTP_SERVER_VARS; // if phpversion() above 4.1 you might want to use $_SERVER
< if(isset($HTTP_SERVER_VARS[$s]))return $HTTP_SERVER_VARS[$s];else return'';}
---
> //function sv($s){global $HTTP_SERVER_VARS; // if phpversion() above 4.1 you might want to use $_SERVER
> //if(isset($HTTP_SERVER_VARS[$s]))return $HTTP_SERVER_VARS[$s];else return'';}
> function sv($s){global $_SERVER; // if phpversion() above 4.1 you might want to use $_SERVER
> if(isset($_SERVER[$s]))return $_SERVER[$s];else return'';}
269c284,290
< function logincheck(){global $cf;if($cf['security']['wwwaut']=='true')return (sv('PHP_AUTH_USER')==$cf['security']['username']&&sv('PHP_AUTH_PW')==$cf['security']['password']);else return (gc('passwd')==$cf['security']['password']);}
---
> function logincheck(){
> global $cf;
> if($cf['security']['wwwaut']=='true')
> return (sv('PHP_AUTH_USER')==$cf['security']['username']&&sv('PHP_AUTH_PW')==$cf['security']['password']);
>
> else return (gc('passwd')==$cf['security']['password']);
> }