Seite 1 von 2

OScam Info in PHP

Verfasst: Di 23. Aug 2011, 00:36
von pixbox
v1.7.4 - letzte aktualisierung: 26.05.2012
==============================================================================================

Wäre das nicht auch etwas für das IPC, glaub schon das es viel interesse für das OSCam Info bestehen würde

http://streamboard.gmc.to/wbb2/thread.p ... adid=32717
Danke an alle Tester! Die erste Stable 1.0 ist fertig.

Benötigt wird:
  • Webserver mit PHP5
  • CURL und mod_curl
  • OScam ab Version 1.xx
Features:
  • Auflisting der Clients mit aktuellem Status
  • Auflistung der Reader mit aktuellem Status
  • Auflisting von Paaren
  • Anzeige des Logs
  • Autorefresh
  • Statistische Auswertung der letzten 20 ECM's
  • Mehrsprachenfähig (deutsch und englisch bereits dabei)
  • Reader ECM-Historie
  • Client ECM/EMM Historie
  • Mehrinstanzenfähig (es können mehrere OSCam Server definiert werden)
  • Zugriffsberechtigungen der angelegten User. Inkl. welche OSCam's
    beauskunftet werden dürfen.
Installation:
Archiv entpacken und auf den Webserver laden. Im Anschluss die
Configuration vornehmen in den folgenden Dateien vornehmen:
  • config.global.php
  • config.oscam.php
  • config.user.php
um CURL noch zu installieren das ausführen
apt-get install php5-curl

anschliessend noch um Apache2 zu restarten
/etc/init.d/apache2 restart

EDIT: Anhang Update bzw Bugs behoben, trotzdem noch V1.0

Re: OScam Info in PHP 1.0 Stable

Verfasst: Di 23. Aug 2011, 10:35
von feissmaik
Was vllt nicht für jeden ersichtlich ist, OScamInfoPHP funktioniert nur wenn das jeweilge OScam, was abgefragt werden soll, ein funktionsfähiges WebIf konfiguriert hat worauf sich dann das OScamInfoPHP verbindet (quasi so wie bei CCcamInfoPHP)
dh wenn man httpallowed benutzt, muss man dort die IP des Servers wo OScamInfo drauf läuft, mit eintragen - also zb habt ihr einen vServer auf dem OScamInfo läuft und zuhause ein OScam und beim Kollegen noch ein OScam, dann muss in den OScam's die IP des vServers in httpallowed eingefügt werden....

======================================================================================================

Um es in IPC zu intregieren kann man folgendes machen:

1) in /var/www/ ein Verzeichniss anlegen:
mkdir /var/www/oscaminfo

2) die oscaminfo.rar in den neu erstellten Ordner /var/www/oscaminfo/ ablegen und entpacken:
(apt-get install unrar unzip)
unrar x oscaminfo.rar
oder: unzip oscaminfo.zip

3) eine Angepasste index.php für IPC mit der vorhandenen ersetzen:
wget -O/var/www/ipc/index.php ipc.pebkac.at/ipc/ipc_index_oscaminfo.php_

Konfiguiert man meherere OScamInfo Benutzer so brauch man denjenigen nicht das IPC User/Password zu geben!

======================================================================================================

die oscaminfo.rar direkt in /var/www/ zu entpacken kann ich nicht empfehlen weil dann entweder das IPC WebIf nicht automatisch angesurft, oder OScamInfo nicht angezeigt werden würde weil in /var/www/ eine index.html für IPC liegt und wenn dann da auchnoch ne index.php liegt kommt es auf die apache2 Konfiguration an welche der beiden index.* Dateien zuerst angesprochen wird...

Re: OScam Info in PHP 1.0 Stable

Verfasst: Mi 31. Aug 2011, 06:29
von blacky
Hi,

Das OScam Info PHP funktioniert mit PHP 5.3 leider nicht, nach einem Downgrade auf PHP 5.2 läuft es wie geschmiert.

Re: OScam Info in PHP 1.0 Stable

Verfasst: Sa 17. Sep 2011, 09:42
von GianniBlaze
Wie bekomme ich das wieder Gelöscht/deinstallierte???

Wollte es mal testen.

Habe es über oscam-infophp.sh installiert.

und will es wieder löschen...

Re: OScam Info in PHP 1.0 Stable

Verfasst: Sa 17. Sep 2011, 09:54
von feissmaik
rm -rf /var/www/oscaminfo

Re: OScam Info in PHP 1.0 Stable

Verfasst: Sa 12. Nov 2011, 10:18
von feissmaik
kann das sonst vllt mal bitte jmd hier hochladen und anhängen wenn eine neue Version rauskommt?

Re: OScam Info in PHP

Verfasst: Mo 24. Sep 2012, 22:35
von feissmaik
Hier eine Modifikation für v1.7.4 um fehlerhafte Logins in ein Logfile zu schreiben um es dann mit fail2ban auszuwerten und die IP zu sperren..
Spoiler
Show
oscaminfo/class.auth.php mit der folgenden ersetzen:

Code: Alles auswählen

<?php
session_start();

class auth{

    private $authData;
    public $errortext = "Login";
    public $sizeFaktor;
    
    function __construct(){
    
            if(isset($_GET["logoff"])){
               session_destroy();
               session_start();
               setcookie("aktReader", "");
               }
    
            if(!empty($_POST["user"]) && !empty($_POST["pass"])) $this->doAuth();
    
            if(isset($_SESSION["oscaminfo_auth"])) $this->authData = $_SESSION["oscaminfo_auth"];
            $this->calcSizes(SCREEN_SIZE);
            
            }
             
    function isAuth(){
             return (is_array($this->authData))?true:false;
             }
             
    function isTab($tab){
             return (in_array($tab,$this->authData["tabs"]))?true:false;
             }
             
    function doAuth(){
             require("config.user.php");
             require("config.oscam.php");
             if (file_exists("authfailedlog.php")) { require("authfailedlog.php"); }

             $array = @$user[$_POST["user"]];
             if(!is_array($array)){
                unset($_SESSION["oscaminfo_auth"]);
                if (isset($LOGDIR)) { LogAuthFailed("$LOGDIR/$LOGFILE",$_POST['user'],$_SERVER['REMOTE_ADDR']); }
                $this->errortext = LOGIN_FAILED;
                return;
                }

             if($array["password"] != $_POST["pass"]){
                unset($_SESSION["oscaminfo_auth"]);
                if (isset($LOGDIR)) { LogAuthFailed("$LOGDIR/$LOGFILE",$_POST['user'],$_SERVER['REMOTE_ADDR']); }
                $this->errortext = LOGIN_FAILED;
                return;             
                }
                
             $oscams = explode(",",$array["oscam"]);
             $array["tabs"] = explode(",",$array["tabs"]);
             $array["onlyclients"] = isset($array["onlyclients"])?explode(",",$array["onlyclients"]):array();
             $array["onlyreaders"] = isset($array["onlyreaders"])?explode(",",$array["onlyreaders"]):array();
             for($i=0;$i<count($oscams);$i++){
                 $o[$oscams[$i]] = $server[$oscams[$i]];
                 }
             
             $array["oscam"] = $o;
             
             $_SESSION["oscaminfo_auth"] = $array;
             }

    function getOscams($einer=true){
             $oscams = $this->authData["oscam"];
             if(!is_array($oscams))return;
             while(list($key,$val)=each($oscams)){

                   $icon = ($val["ssl"])?'<img border="0" title="SSL WebIF" alt="SSL WebIF" align="absmiddle" src="themes/icons/lock.gif">':'';

                   if($einer){
                      echo $key.' ('.$icon.trim($val["url"]).')';
                      break;
                      }
                   else{
                      echo '<a href="#" onClick="changeServer(\''.$key.'\',\''.$val["url"].'\',\''.str_replace('"','\\\'',$icon).'\')">'.$key.' ('.$icon.trim($val["url"]).')</a><br>';
                    }
                   }

             }
    function calcSizes($size=775){
             $size = ($size=="full")?$_POST["fullscreen"]:$size;
             if(is_NaN($size) || $size==0)$size = 755;
             $erg = floor($size / (775 / 100));
             $this->sizeFaktor = $erg/100;
             }
             
    function sortable($withLastActivity=true){
             
             if(empty($_SESSION["oscaminfo_auth"]["sort"]))return;
    
             $sorts = explode("_",$_SESSION["oscaminfo_auth"]["sort"]);
             
             if($sorts[0] == "lastactivity" && !$withLastActivity) return;
             
             echo "sortName=\"".$sorts[0]."\" ";
             echo "sortOrder=\"".$sorts[1]."\"";
             
             }
    
}
oscaminfo/admin/class.admin.php mit der folgenden ersetzen:

Code: Alles auswählen

<?php
require("../config.global.php");
require("../lang/".LANGUAGE.".inc.php");
require("../class.auth.php");
@session_start();

class admin extends auth{
	
	  public $delimiter;

    public $errortext = "Admin Login";
    
    private $oscamApi;
    
    private $server_tpl = "\n  \$server[\"#SERVERNAME#\"] = array(
                        \"url\"		=> \"#SERVERURL#\",
                        \"port\"		=> \"#SERVERPORT#\",
                        \"user\"		=> \"#SERVERUSER#\",
                        \"pass\"		=> \"#SERVERPASS#\",
                        \"ssl\"		=> #SERVERSSL#
                        );\n";
                        
    private $user_tpl = "\$user[\"#LOGINNAME#\"] = array(
                 \"password\"	=> \"#LOGINPASS#\", 
                 \"tabs\"		=> \"#LOGINTABS#\", 
                 \"onlyclients\" 	=> \"#ONLYCLIENTS#\",
                 \"onlyreaders\" 	=> \"#ONLYREADERS#\",
                 \"oscam\"	=> \"#OSCAM#\",
                 \"sort\"	=> \"#SORT#\"
                 );\n";     
                 

    private $global_tpl = "<?php
/* Autorefresh in seconds for OSCam Info */
DEFINE('REFRESH_SECS',#REFRESH_SECS#);

/* Language de=german / en=english */
DEFINE('LANGUAGE','#LANGUAGE#');

/* A custom notice in the header (empty if no message should be displayed)*/
DEFINE('CUSTOM_NOTICE','#CUSTOM_NOTICE#');

/* A custom stlye for the main grid, available are 'blue' and 'gray' */
DEFINE('OSCAM_STYLE','#OSCAM_STYLE#');

/* The width (in px) of the mainwindow(s), full screen size can be set with 'full' */
DEFINE('SCREEN_SIZE','#SCREEN_SIZE#');

/* The Adminuser */
DEFINE('ADM_USER','#ADM_USER#');

/* The Adminpassword */
DEFINE('ADM_PASS','#ADM_PASS#');

/* Connect through proxyserver, if no proxy is needed just leave blank */
DEFINE('PROXY_URL','#PROXY_URL#'); 
DEFINE('PROXY_PORT','#PROXY_PORT#');
DEFINE('PROXY_USER','#PROXY_USER#');
DEFINE('PROXY_PASS','#PROXY_PASS#');

/* Lower than this percent the values will cumulated */
DEFINE('LOWER_THAN','#LOWER_THAN#');

/* Available entries per page */
DEFINE('ENTRIES_PER_PAGE','#ENTRIES_PER_PAGE#');

/* Default entries per page */
DEFINE('ENTRIES_PER_PAGE_DEFAULT','#ENTRIES_PER_PAGE_DEFAULT#');

/* Channel picons update every XX days */
DEFINE('CHANNEL_PICONS','#CHANNEL_PICONS#');
?>";                 
                 
    
    function __construct(){
    
            if(isset($_GET["logoff"])){
               session_destroy();
               session_start();
               unset($_COOKIE["aktReader"]);
               }
    
            if(!empty($_POST["user"]) && !empty($_POST["pass"])) $this->doAuthAdm();
    
            $this->calcSizes(SCREEN_SIZE);
           
            $this->delimiter = (LANGUAGE=="de")?",":"."; 
            }
            
    function getLanguagesSelects(){
    	     $handle=opendir("../lang");
             while ($datei = readdir ($handle)) {
                    if(stristr($datei,".inc.") && !stristr($datei,"tld")){
                    	
                    	$checkLang = file_get_contents("../lang/".$datei);
                    	preg_match('#DEFINE\("_LANGUAGE_","(.*)"\);#',$checkLang,$erg);
                    	$sel = (LANGUAGE == substr($datei,0,2))?" selected":"";
                    	echo '<option value="'.substr($datei,0,2).'"'.$sel.'>'.$erg[1].'</option>';
                       }
                    }

             closedir($handle);
    	
    	     }

    function getPerPageSelects(){
             $entries = explode(",",ENTRIES_PER_PAGE);
             foreach($entries as $entry) {
                     $sel = ($entry==ENTRIES_PER_PAGE_DEFAULT)?" selected":"";
                     echo '<option value="'.$entry.'"'.$sel.'>'.$entry.'</option>';
                    }
    	     }
    	     
    function saveGlobal(){
    	     while(list($k,$v) = each($_POST)){
    	           $this->global_tpl = str_replace("#".strtoupper($k)."#",$v,$this->global_tpl);
    	           }
             if(@file_put_contents("../config.global.php",$this->global_tpl)){
             	echo "info|".ADM_SAVE_GLOBAL_OK_TITLE."|".ADM_SAVE_GLOBAL_OK_BODY;
             	exit;
                }
             
             echo "error|".ADM_SAVE_GLOBAL_ERR_TITLE."|".ADM_SAVE_GLOBAL_ERR_BODY;
             }
             
    function isAuthAdm(){
             return (isset($_SESSION["oscaminfo_adm_auth"]))?true:false;
             }

             
    function doAuthAdm(){
             if(ADM_USER == $_POST["user"] && ADM_PASS == $_POST["pass"]){
             	$_SESSION["oscaminfo_adm_auth"] = "adm";
                }
             else{
                if (file_exists("../authfailedlog.php")) { require("../authfailedlog.php"); }
                session_destroy();
                session_start();
                unset($_SESSION["oscaminfo_adm_auth"]);
                if (isset($LOGDIR)) { LogAuthFailed("$LOGDIR/$LOGFILE",$_POST['user'],$_SERVER['REMOTE_ADDR']); }
                $this->errortext = LOGIN_FAILED;
                }
             }
             
    function printServerProtocols(){
    	     $data = array();
    	     $count = 0;
    	     foreach($_SESSION["OIP_ADM_PROTOCOLS"][$_GET["types"]]["protocol"] as $p){
    	     	     $data[$count]["id"] = $p;
    	     	     $data[$count]["text"] = LNG_PROTOCOL.': '.$p;
    	     	
    	     	     $count++;
    	     	     }
    	     foreach($_SESSION["OIP_ADM_PROTOCOLS"][$_GET["types"]]["name"] as $p){
    	     	     $data[$count]["id"] = $p;
    	     	     $txt = ($_GET["types"]=="server")?LNG_READER:LNG_CLIENT;
    	     	     $data[$count]["text"] = $txt.': '.$p;
    	     	
    	     	     $count++;
    	     	     }    	     	     
    	     echo json_encode($data);
    	     }
    	     
    function restartServer(){
    	     include("../config.oscam.php");
    	
    	     $prot = ($server[$_GET["data"]]["ssl"])?"https":"http";
    	     print_r($server[$_GET["data"]]);
    	     $ch = curl_init($prot."://".$server[$_GET["data"]]["url"].":".$server[$_GET["data"]]["port"]."/oscamapi.html?part=shutdown&action=restart");
    	     if(((boolean) PROXY_URL) && ((boolean) PROXY_PORT)){
                curl_setopt($ch, CURLOPT_PROXY, "http://".PROXY_URL.":".PROXY_PORT);
                curl_setopt($ch, CURLOPT_PROXYPORT, PROXY_PORT);
                if(((boolean) PROXY_USER) && ((boolean) PROXY_PASS)) curl_setopt($ch, CURLOPT_PROXYUSERPWD, PROXY_USER.":".PROXY_PASS);
                }
    	     curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);
             curl_setopt($ch,CURLOPT_TIMEOUT,10);
             curl_setopt($ch,CURLOPT_FAILONERROR,1);
             curl_setopt($ch,CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
             curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
             curl_setopt($ch,CURLOPT_USERPWD,$server[$_GET["data"]]["user"].':'.$server[$_GET["data"]]["pass"]);
             if($server[$_GET["data"]]["ssl"]){
                 curl_setopt($ch,CURLOPT_SSL_VERIFYHOST, 0);
                 curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, 0);
                 }
             curl_exec($ch);       
             }
             
    function getServerProtocols(){
    	
    	     if(isset($_SESSION["OIP_ADM_PROTOCOLS"])){
    	     	$this->printServerProtocols();
    	     	return;
    	        }
    	
    	     include("../config.oscam.php");
    	     
    	     $servers = explode(",",$_GET["servers"]);
    	     $typeArrayAll['user']['protocol'] = array(); 
    	     $typeArrayAll['server']['protocol'] = array(); 
    	     $typeArrayAll['user']['name'] = array(); 
    	     $typeArrayAll['server']['name'] = array(); 
    	     foreach($servers as $s){
    	     	     $prot = ($server[$s]["ssl"])?"https":"http";
    	    	     $ch = curl_init($prot."://".$server[$s]["url"].":".$server[$s]["port"]."/oscamapi.html?part=status");
    	    	     if(((boolean) PROXY_URL) && ((boolean) PROXY_PORT)){
                        curl_setopt($ch, CURLOPT_PROXY, "http://".PROXY_URL.":".PROXY_PORT);
                        curl_setopt($ch, CURLOPT_PROXYPORT, PROXY_PORT);
                        if(((boolean) PROXY_USER) && ((boolean) PROXY_PASS)) curl_setopt($ch, CURLOPT_PROXYUSERPWD, PROXY_USER.":".PROXY_PASS);
                        }
    	             curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);
                     curl_setopt($ch,CURLOPT_TIMEOUT,10);
                     curl_setopt($ch,CURLOPT_FAILONERROR,1);
                     curl_setopt($ch,CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
                     curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
                     curl_setopt($ch,CURLOPT_USERPWD,$server[$s]["user"].':'.$server[$s]["pass"]);
                     if($server[$s]["ssl"]){
                        curl_setopt($ch,CURLOPT_SSL_VERIFYHOST, 0);
                        curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, 0);
                        }
                    
                     $typeArray = array();                     
                     $obj = (simplexml_load_string(curl_exec($ch),'SimpleXMLElement', LIBXML_NOCDATA));
                     foreach($obj->status->client as $c) {
                     	     if(!empty($c['type']) && ($c['type'] == "r" || $c['type'] == "p")){
                     	     	$typeArray['server']['protocol'][] = preg_replace("#\s(.*)#","",(String)$c['protocol']);
                     	     	$typeArray['server']['name'][] = (String)$c['name'];
                     	        }
                     	     if(!empty($c['type']) && ($c['type'] == "c")){
                     	     	$typeArray['user']['protocol'][] = preg_replace("#\s(.*)#","",(String)$c['protocol']);
                     	     	$typeArray['user']['name'][] = (String)$c['name'];
                     	        }
                     	     }
                     $typeArrayAll['user']['protocol'] = array_merge($typeArrayAll['user']['protocol'], $typeArray['user']['protocol']);
                     $typeArrayAll['server']['protocol'] = array_merge($typeArrayAll['server']['protocol'], $typeArray['server']['protocol']);
                     $typeArrayAll['user']['name'] = array_merge($typeArrayAll['user']['name'], $typeArray['user']['name']);
                     $typeArrayAll['server']['name'] = array_merge($typeArrayAll['server']['name'], $typeArray['server']['name']);
                     $typeArrayAll['user']['protocol'] = array_unique($typeArrayAll['user']['protocol']);
                     $typeArrayAll['server']['protocol'] = array_unique($typeArrayAll['server']['protocol']);
                     $typeArrayAll['user']['name'] = array_unique($typeArrayAll['user']['name']);
                     $typeArrayAll['server']['name'] = array_unique($typeArrayAll['server']['name']);
              }
      
             
             $_SESSION["OIP_ADM_PROTOCOLS"] = $typeArrayAll;
             
             $this->printServerProtocols();
    	
    	     }

    function getOscamServer($onlyNames=false){
             require("../config.oscam.php");
    	     $data = array();
    	     $count = 0;
    	     while(list($k,$v) = each($server)){
    	     	     $data[$count]["servername"] = $k;
    	     	     if(!$onlyNames)$data[$count]["serverurl"] = $v["url"];
    	     	     if(!$onlyNames)$data[$count]["serverport"] = $v["port"];
    	     	     if(!$onlyNames)$data[$count]["serveruser"] = $v["user"];
    	     	     if(!$onlyNames)$data[$count]["serverpass"] = $v["pass"];
    	     	     if(!$onlyNames)$data[$count]["serverssl"] = $v["ssl"];
    	     	     $count++;
    	     	     }
    	     echo json_encode($data);
             }
             
    function getOscamUser(){
             require("../config.user.php");
    	     $data = array();
    	     $count = 0;
    	     while(list($k,$v) = each($user)){
    	     	     $data[$count]["loginname"] = $k;
    	     	     $data[$count]["loginpass"] = $v["password"];
    	     	     $data[$count]["logintabs"] = $v["tabs"];
    	     	     if (array_key_exists('onlyclients', $v)) $data[$count]["onlyclients"] = $v["onlyclients"];
    	     	     if (array_key_exists('onlyreaders', $v)) $data[$count]["onlyreaders"] = $v["onlyreaders"];
    	     	     $data[$count]["oscam"] = $v["oscam"];
    	     	     $data[$count]["sort"] = $v["sort"];
    	     	     $count++;
    	     	     }
    	     echo json_encode($data);
             }
             
     function setOscamUser(){
     	      $ret["success"] = false;
     	      unset($_SESSION["OIP_ADM_PROTOCOLS"]);

     	      if(!isset($_GET["delete"])){
     	         $user_tpl = str_replace("#LOGINNAME#",$_POST["loginname"],$this->user_tpl);
        	 $user_tpl = str_replace("#LOGINPASS#",$_POST["loginpass"],$user_tpl);
        	 $user_tpl = str_replace("#LOGINTABS#",implode(",",$_POST["logintabs"]),$user_tpl);
        	 if(!isset($_POST["onlyclients"]))$_POST["onlyclients"]=array();
        	 if(!isset($_POST["onlyreaders"]))$_POST["onlyreaders"]=array();
        	 $user_tpl = str_replace("#ONLYCLIENTS#",implode(",",$_POST["onlyclients"]),$user_tpl);
        	 $user_tpl = str_replace("#ONLYREADERS#",implode(",",$_POST["onlyreaders"]),$user_tpl);
        	 if(count($_POST["onlyclients"])==0 || empty($_POST["onlyclients"]) || empty($_POST["onlyclients"][0]))$user_tpl = str_replace('"onlyclients"','//"onlyclients"',$user_tpl);
        	 if(count($_POST["onlyreaders"])==0 || empty($_POST["onlyreaders"]) || empty($_POST["onlyreaders"][0]))$user_tpl = str_replace('"onlyreaders"','//"onlyreaders"',$user_tpl);
        	 $osCams = explode(",",implode(",",array_unique($_POST["oscam"])));
        	 $user_tpl = str_replace("#OSCAM#",implode(",",array_unique($osCams)),$user_tpl);   
        	 if($_POST["sortable"] == "NONE_asc")$_POST["sortable"] = "identname_asc";
        	 if($_POST["sortable"] == "NONE_desc")$_POST["sortable"] = "identname_desc";        	 
        	 $user_tpl = str_replace("#SORT#",$_POST["sortable"],$user_tpl);   
        	 include("../config.user.php");
        	 if(array_key_exists($_POST["loginname"],$user) && !isset($_GET["server"])){
        	    $ret["success"] = false;
        	    $ret["msg"] = LNG_ADM_LOGINNAME_EXISTS;
        	    echo json_encode($ret);
        	    exit();
        	    }  	           	         
        	 }
        	
  	      $cfg = file_get_contents("../config.user.php");
     	                    
     	      if(!isset($_GET["server"])){
     	         $cfg = str_replace("?>",$user_tpl."\n?>",$cfg);	 
     	         }
     	      else{
     	        $cfgData = file("../config.user.php");
     	        $replaceData = "";
     	        $writeRepData = false;
     	        foreach($cfgData as $zeile){
     	        	if(stristr($zeile,'$user["'.$_GET["server"].'"]'))$writeRepData = true;
     	        	if($writeRepData)$replaceData.=$zeile;
     	        	if(stristr($zeile,');'))$writeRepData = false;
     	               }
     	        
     	         $user_tpl = (isset($_GET["delete"]))?"":$user_tpl;
     	         $replace_usr = (isset($_GET["delete"]))?"":$_POST["loginname"];
     	        
                 $cfg = str_replace($replaceData,$user_tpl,$cfg);
              }

     	      if(file_put_contents("../config.user.php",$cfg)){
     	      	 $ret["success"] = true;
     	      	 }
     	      else{
     	         $ret["msg"] = "Error writing config.user.php";
     	        }   
        	      
     	      echo json_encode($ret);
     	      
     	      }                          
             
     function setOscamServer(){
     	      $ret["success"] = false;
     	      unset($_SESSION["OIP_ADM_PROTOCOLS"]);     	      
     	      
     	      if(!isset($_GET["delete"])){
     	         $server_tpl = str_replace("#SERVERNAME#",$_POST["servername"],$this->server_tpl);
        	 $server_tpl = str_replace("#SERVERURL#",$_POST["serverurl"],$server_tpl);
        	 $server_tpl = str_replace("#SERVERPORT#",$_POST["serverport"],$server_tpl);
        	 $server_tpl = str_replace("#SERVERUSER#",$_POST["serveruser"],$server_tpl);
        	 $server_tpl = str_replace("#SERVERPASS#",$_POST["serverpass"],$server_tpl);
        	 $server_tpl = str_replace("#SERVERSSL#",($_POST["serverssl"]=="true")?"true":"false",$server_tpl);
        	 include("../config.oscam.php");
        	 if(array_key_exists($_POST["servername"],$server) && !isset($_GET["server"])){
        	    $ret["success"] = false;
        	    $ret["msg"] = LNG_ADM_SERVERNAME_EXISTS;
        	    echo json_encode($ret);
        	    exit();
        	    }
        	      	           	         
        	 }  	 
     	      
  	      $cfg = file_get_contents("../config.oscam.php");
     	                    
     	      if(!isset($_GET["server"])){
     	         $cfg = str_replace("?>",$server_tpl."\n?>",$cfg);	 
     	         }
     	      else{
     	        $cfgData = file("../config.oscam.php");
     	        $replaceData = "";
     	        $writeRepData = false;
     	        foreach($cfgData as $zeile){
     	        	if(stristr($zeile,'$server["'.$_GET["server"].'"]'))$writeRepData = true;
     	        	if($writeRepData)$replaceData.=$zeile;
     	        	if(stristr($zeile,');'))$writeRepData = false;
     	               }
     	        
     	        $server_tpl = (isset($_GET["delete"]))?"":$server_tpl;
     	        $replace_usr = (isset($_GET["delete"]))?"":$_POST["servername"];
     	        
              $cfg = str_replace($replaceData,$server_tpl,$cfg);
              
              
              
              $users = file("../config.user.php");
              $userData='';
              foreach($users as $usr){
              	      if(stristr($usr,'"oscam"')){
              	      	 $usr = str_replace('"'.$_GET["server"].'"','"'.$replace_usr.'"',$usr);
              	      	 $usr = str_replace(','.$_GET["server"].'"',','.$replace_usr.'"',$usr);
              	      	 $usr = str_replace('"'.$_GET["server"].',','"'.$replace_usr.',',$usr);
              	      	 $usr = str_replace(','.$_GET["server"].',',','.$replace_usr.',',$usr);
              	      	 $usr = str_replace(',,',',',$usr);
              	      	 $usr = str_replace('> ",','> "',$usr);
              	      	 $usr = str_replace(',"','"',$usr);
              	      	 }
              	      $userData.=$usr;
              	      }
              file_put_contents("../config.user.php",$userData);
     	      }
     	       
     	      
     	      if(file_put_contents("../config.oscam.php",$cfg)){
     	      	 $ret["success"] = true;
     	      	 }
     	      else{
     	         $ret["msg"] = "Error writing config.oscam.php";
     	        }    
     	        
     	      echo json_encode($ret); 
     	       
     	      }

function getSortable(){
         $ordner = array(LNG_ADM_SORTABLE_ASC,LNG_ADM_SORTABLE_DESC);
         $ordnerIcon = array("icon-asc","icon-desc");
         $ordnerVal = array("asc","desc");
         $data = array("identname"=>LNG_CLIENT.'/'.LNG_READER,
		       "country"=>LNG_CTY,
        	       "protocol"=>LNG_PROTOCOL,
        	       "request"=>LNG_LAST_USED_SHARE,
		       "ecmtime"=>LNG_ECM,
	               "loggedin"=>LNG_LOGGED_IN,
	               "lastactivity"=>LNG_LAST_ACTIVITY,
	               "connection"=>LNG_CONNECTION);
         $ajax = array();
         $ajax[0]["id"] = "";
	 $ajax[0]["text"] = ADM_NONE;
	 $ajax[0]["iconCls"] = "icon-cancel";

	 for($i=0;$i<count($ordner);$i++){
	     $ajax[$i+1]["id"] = "NONE_".$ordnerVal[$i];
	     $ajax[$i+1]["text"] = $ordner[$i];
	     $ajax[$i+1]["iconCls"] = $ordnerIcon[$i];
	     $tmpData = $data;
	     $tmpCount = 0;
	     $ajaxKids = array();
	     while(list($key,$value) = each ($tmpData)){
	          $ajaxKids[$tmpCount]["id"] = $key.'_'.$ordnerVal[$i];
	          $ajaxKids[$tmpCount]["text"] = $value;
	          $tmpCount++;
	          }
	     $ajax[$i+1]["children"] = $ajaxKids;
	     $ajax[$i+1]["state"] = "open";
	 
	     
	     
	     }
	 
	 
	 echo json_encode($ajax);

         }
}


ausserdem folgende datei neu erstellen -> oscaminfo/authfailedlog.php

Code: Alles auswählen

<?php

$LOGDIR = "logs";
$LOGFILE = "auth.failed.log";

if (preg_match("/admin/",$_SERVER['PHP_SELF'])) { $LOGDIR = "../$LOGDIR"; }

if (!is_dir($LOGDIR)) { CreateLogDir($LOGDIR); }
if (!file_exists("$LOGDIR/.htaccess")) { CreateLogDir($LOGDIR); }

function LogAuthFailed($TOFILE,$USER="",$IP) {
	if (!empty($USER)) {
		$logline = "[".date('d/m/Y H:i:s')."] $USER LOGIN FAILED: $IP";
	} else {
		$logline = "[".date('d/m/Y H:i:s')."] LOGIN FAILED: $IP";
	}
	$handle = fopen("$TOFILE","a");
	fwrite($handle,"$logline\n");
	fclose($handle);
}

function CreateLogDir($DIR) {
	if (!is_dir($DIR)) { $MKDIR = mkdir($DIR,0777,true); }
	if (!file_exists("$DIR/.htaccess")) {
		$handle = fopen("$DIR/.htaccess","w");
		if ($handle) {
			fwrite($handle,"Order deny,allow\n");
			fwrite($handle,"Deny from all\n");
			fclose($handle);
			exec("chmod 600 $DIR/.htaccess");
		}
	}
}

?>
wenn sich dann jemand fehlerhaft anmeldet wird das in die datei oscaminfo/logs/auth.failed.log geschrieben:

Code: Alles auswählen

24.09.2012 22:52:00: LOGIN FAILED: 10.0.2.2
dafür kann man sich dann in fail2ban einen filter erstellen..
Die Einstellung für fail2ban sähen dann so aus:

-> /etc/fail2ban/jail.conf

Code: Alles auswählen

[oscaminfo_login]
enabled = true
port = 80,443
filter = oscaminfo-login
logpath = /var/www/oscaminfo/logs/auth.failed.log
bantime = 3600
maxretry = 3
Zum testen die bantime zum beispiel auf 60 stellen..
Alternativ kann man da auch " port = http,https " eintragen.

-> /etc/fail2ban/filter.d/oscaminfo-login.conf

Code: Alles auswählen

[Definition]
failregex = .*LOGIN FAILED: <HOST>
ignoreregex =
Mit dem Befehl fail2ban-regex kann man regular expressions testen also ob die Filter Regeln funktionieren würden. Das würde in diesem Fall dann so aussehen:

Code: Alles auswählen

fail2ban-regex /var/www/oscaminfo/logs/auth.failed.log "LOGIN FAILED: <HOST>"
Natürlich Vorrausgesetzt man hat vorher schon fehlerhafte Loginversuche in dem Log stehen..

Dann anweisen das fail2ban die configs neu einliest: /etc/init.d/fail2ban force-reload
Und dann zum testen fehlerhafte Logins provozieren und gleichzeitig das fail2ban.log überwachen:
tail -f /var/log/fail2ban.log

Optional kann das Logfile dann auch noch ins IPC WebIf hinzugefügt werden, indem man unter Editor -> SYSTEM -> config.php im abschnitt Logs folgendes einfügt:

Code: Alles auswählen

$LOGS['System']['oscaminfoauth'] = "/var/www/oscaminfo/logs/auth.failed.log";

Re: OScam Info in PHP

Verfasst: Do 9. Mai 2013, 10:28
von vöslauer
version 1.8.3 ist jetzt aktuell

Re: OScam Info in PHP

Verfasst: Fr 31. Mai 2013, 08:37
von jensebub
Changelog:
Spoiler
Show

Code: Alles auswählen

//UPDATE: Version 1.7.4 - 11.05.2012
 
•Verwendung der Channel-Picons von OSCam. Nachladen von neuen Channel Picons aus dem OSCam-WebIF ist nur möglich wenn OSCam 1.20 ab Build #6645 installiert ist und dort die aktuellen Picons installiert sind.

 ----------------------------------------------------------
 
//UPDATE: Version 1.7.5 - 18.06.2012
 
•Schliessen aller Fenster mit [ESC] möglich
 
•Anpassung der Positionierung der Fenster bei zu kleinen Monitoren.

 ----------------------------------------------------------
 
//UPDATE: Version 1.7.6 - 22.06.2012
 
•Bugfix damit auch auf keinen Bildschirmen gescrollt werden kann
 
•Bugfix das die Readerdetails bei CCcam-Reader wieder vernünftig dargestellt werden.

 ----------------------------------------------------------
 
//UPDATE: Version 1.8 - 08.10.2012
 
•Logging der Nutzeraktivitäten
 
•Erweiterung der Administration um die Logging-Funktionen

----------------------------------------------------------
 
//UPDATE: Version 1.8.1 - 24.01.2013
 
•Erkennung und Ausgabe der OSCam-Version.

----------------------------------------------------------
 
//UPDATE: Version 1.8.2 - 15.02.2013
 
•Diverse Bugfixes bei der Ausgabe.
----------------------------------------------------------
 
//UPDATE: Version 1.8.3 - 08.05.2013
 
•Korrektur der Picons Ausgabe beim Mouseover
Gruß
jensebub

Re: OScam Info in PHP

Verfasst: So 1. Sep 2013, 19:27
von vöslauer
//UPDATE: Version 1.8.4 - 30.08.2013

Bessere Verwaltung von Offline-Readern/Clients