[PHP] gulli:börse backup-spider

Dieses Thema im Forum "Webentwicklung" wurde erstellt von Murdoc, 10. August 2008 .

Status des Themas:
Es sind keine weiteren Antworten möglich.
  1. 10. August 2008
    Zuletzt von einem Moderator bearbeitet: 13. April 2017
    gulli:börse backup-spider

    folgendes php-script erstellt ein backup der gulli:börse
    es wird kein mirror erstellt, grafiken und andere ressourcen werden nicht runtergeladen,
    lediglich alle threads und deren seiten.

    -> noch nicht ganz fertig, aber funktionstüchtig <-
    vielleicht will mir jemand helfen?

    f: warum php?
    a: gedacht war das ganze für server da schnellere anbindung.
    das script soll anschließend das ganze zippen und einem zum download anbieten.
    sollte wesentlich schneller sein als der lokale download.

    *todo:
    - board-index blättern
    - testen (man beachte das b [=beta] in der version)

    PHP:
    <? php
        

        
        //all errors
        
    error_reporting ( E_ALL | E_STRICT );
        @
    set_time_limit ( 0 );
        
        
    define ( 'DIR_SEP' DIRECTORY_SEPARATOR );  //einfacher zu merken :-)
        
    define ( 'AUTOSTART' , ( __FILE__  == ( str_replace (array( '/' '\\' ),  DIR_SEP getEnv ( 'SCRIPT_FILENAME' )))));
        
        
    //document-root
        
    $f  dirname ( __FILE__ );
        
    define ( 'BASE_DIR' $f  . (( substr ( $f , - 1 ) !=  DIR_SEP ) ?  DIR_SEP  '' ));
        unset(
    $f );
        
        class 
    GulliBackup  {
            const 
    INVALID_DIR_PATTERN  '(^\.?|[^a-zA-Z0-9_\.-]+)' ;
            const 
    INVALID_FILE_PATTERN  '[^a-zA-Z0-9_\.-]' ;
            const 
    THANDLE_BOARD  100 ;
            const 
    THANDLE_THREAD  200 ;
            private 
    $_curlHandle  null $_handle $_threadPages  0 ;
            protected static 
    $currentFolder $currentFile ;
            protected static 
    $outputType  '.html' $i  0 ;
            protected 
    $options  = array(
                
    'gb:userid'  =>  0 //bbuserid
                
    'gb:password'  =>  0 //bbpassword
                
    'output_format'  =>  '.html' ,
                
    'compress'  =>  'gz' ,
                
    'idle_between'  =>  //flodding verhindern! (sekunden)
            
    );
            
            

            
    public function  __construct ( $options  = array()) {
                
    date_default_timezone_set ( 'Europe/Berlin' );
                
    $this -> options  array_merge ( $this -> options $options );            
                
                

                
                
    $this -> _init ( 'http://board.gulli.com/forum/44-brse/' );
                
    //$this->_init('http://board.gulli.com/forum/202-wichtige-ankndigungen-zur-brse/');
                
    $this -> _parse ( BASE_DIR  'result/' );
            }
            
            

            
    private function  _init ( $url ) {            
                if(
    $this -> _curlHandle  !==  null )
                    
    $this -> _closeCurl ();
                    
                
    $this -> _curlHandle  curl_init ( $url );
                
    $this -> _setDefaultOptions ();
            }
            
            

            
    private function  _parse ( $parentBoard ) {
                
    $contents  curl_exec ( $this -> _curlHandle );
                
    $boards  = array();
                
    $threads  = array();
                
                
    //die aktuelle threadliste
                
    preg_match_all ( '~\<a href="http://board.gulli.com/thread/(.+)/?" id="thread_title_\d+" class="threadtitle"\>.+\</a\>~Uim' $contents $threads );
                if(
    $threads  && isset( $threads [ 1 ])) {
                    foreach(
    $threads [ 1 ] as  $thread ) {
                        
    $this -> _init ( 'http://board.gulli.com/thread/'  $thread  '/' );
                        
    $t  curl_exec ( $this -> _curlHandle );
                        
                        
    //thread-seiten
                        
    $pages  = array();
                        if(
    false  &&  preg_match ( '~\<td.*class="vbmenu_control".*\>Seite 1 von (\d+)\</td\>~Uim' $t $pages )) {
                            
    $pages  intval ( $pages [ 1 ]);
                            for(
    $i  2 $i  <=  $pages $i ++) {
                                
    $this -> _init ( 'http://board.gulli.com/thread/'  $thread  '/'  $i  '/' );
                                
    $sub  curl_exec ( $this -> _curlHandle );
                                
    $sub  preg_replace ( '~http://board.gulli.com/thread/'  $thread  '/(\d+)/~Uim' 'file://'  $parentBoard  $thread  '_$1.html' $sub );
                                
    $sub  preg_replace ( '~http://board.gulli.com/thread/'  $thread  '/~Uim' 'file://'  $parentBoard  $thread  '_1.html' $sub );
                                
    file_put_contents ( $parentBoard  $thread  '_'  $i  '.html' $sub );
                            }
                            
                            
    $t  preg_replace ( '~http://board.gulli.com/thread/'  $thread  '/(\d+)/~Uim' 'file://'  $parentBoard  $thread  '_$1.html' $t );
                        }
                        
                        
    file_put_contents ( $parentBoard  $thread  '_1.html' $t );
                    }
                }
                
                
    //alle subforen
                
    preg_match_all ( '~\<a href="http://board.gulli.com/forum/(.+)/"\>\<strong\>.+\</strong\>\</a\>~Uim' $contents $boards );
                if(
    $boards  && isset( $boards [ 1 ])) {
                    foreach(
    $boards [ 1 ] as  $board ) {
                        
    $this -> _init ( 'http://board.gulli.com/forum/'  $board  '/' );
                        
    mkdir ( $parentBoard  $board  '/' 0777 );
                        
    $this -> _parse ( $parentBoard  $board  '/' );
                    }
                }
                
                
    //thread-index als index.html speichern
                
    $contents  preg_replace ( '~http://board.gulli.com/thread/(.+)/~Uim' 'file://'  $parentBoard  '/$1_1.html' $contents );
                
    $contents  preg_replace ( '~http://board.gulli.com/forum/(.+)/~Uim' 'file://'  $parentBoard  '$1' $contents );
                
    file_put_contents ( $parentBoard  'index.html' $contents );
            }
            
            private function 
    _prepairThread ( $c $getPageOffset  true ) {
                if(
    $getPageOffset  ===  true ) {
                    
    $pages  = array();
                    
    preg_match ( '~<a class="smallfont" href="http://board.gulli.com/.*/(\d+)/" title="Letzte Seite~U' $c $pages );
                    
    $this -> _threadPages  $pages [ 1 ];
                }
                
                
    $cf  substr_replace ( self :: $currentFile 'file:///c:' 0 2 );
                
    $cf  preg_replace ( '~_\d+\.html$~' '' $cf );
                return 
    preg_replace (
                    
    '~<td class="alt1"><a(.*)href=".*/(\d+)/"(.*)>~U'
                    
    '<td class="alt1"><a$1href="'  $cf  '_$2.html"$3>' ,
                    
    $c
                
    );
            }
            
            

            
    private function  _closeCurl () {
                @
    curl_close ( $this -> _curlHandle );
                
    $this -> _curlHandle  null ;
            }
            
            

            
    private function  _setDefaultOptions () {
                
    curl_setOpt ( $this -> _curlHandle CURLOPT_RETURNTRANSFER true );
                
    curl_setOpt ( $this -> _curlHandle CURLOPT_REFERER 'http://board.gulli.com/' );
                
    //curl_setOpt($this->_curlHandle, CURLOPT_STDERR, fopen(BASE_DIR . 'curl.log', 'a'));
                
    curl_setOpt ( $this -> _curlHandle CURLOPT_USERAGENT ,
                    
    'Mozilla/5.0 (Windows; U; Windows NT 5.1; de-AT; '  .
                    
    'rv:1.8.1.15) Gecko/20080621 SeaMonkey/1.1.10'
                
    );
                
    curl_setOpt ( $this -> _curlHandle CURLOPT_COOKIE ,
                    
    'bbuserid='  $this -> options [ 'gb:userid' ] . 
                    
    ';bbpassword='  md5 ( $this -> options [ 'gb:password' ])
                );
            }
            
            

        
    }
        
        if(
    AUTOSTART ) {
            if(empty(
    $_GET [ 'userid' ]) || empty( $_GET [ 'password' ])):
                print <<<EOFORM
    <html><head><title>gulli:board &raquo; B&ouml;rse backup</title></head>
    <body><form action="
    { $_SERVER [ 'PHP_SELF' ]} " method="get">
            <strong>gb:userid</strong><br />
            <input type="text" name="userid" /><br />
            <br />
            <strong>gb:passwort</strong><br />
            <input type="text" name="password" /><br />
            <p style="color:red;font-weight: bold;">info: das backup kann mehrere minuten (mitunter sogar 30min oder mehr) dauern</p>
            <p><input type="submit" value="backup starten" /></p>
    </form></body>
    EOFORM;
            else: 
                print 
    'backup gestartet' ;
                print 
    '<br />bitte warten!' ;
                
    flush ();
                new 
    GulliBackup (array(
                    
    'gb:password'  =>  $_GET [ 'password' ],
                    
    'gb:userid'  =>  $_GET [ 'userid' ]
                ));
                print 
    '<br />backup beended' ;
            endif;
        }
    ?>
     
  2. 10. August 2008
    AW: gulli:börse backup-spider

    Danke, aber ich denke wenn das jetzt auch nur 50 leute starten (sei es Lokal oder per Root/FTP)
    dann ist das board wieder down udn das script nutzlos.

    Da wart ich lieber, dass einer mal n Backup macht und es uppt.
     
  3. 10. August 2008
    AW: gulli:börse backup-spider

    meinen respekt für diese arbeit hast du auf jeden fall!
     
  4. 10. August 2008
    AW: gulli:börse backup-spider

    Joa, darüber würd ich mich auch freuen.
    Ansonsten: Respect für das Skript.
     
  5. 10. August 2008
    AW: gulli:börse backup-spider

    In dem neuen "Open:Gully" Board machen bereits einige Leute mit einigen Root Servern ein Backup der Börse. ^^
    Es heißt außerdem "flooding", nicht "flodding"
    Und ja, son Flood-Protector ist schon sinnvoll, da Gulli ja alle leute die durch "sehr hohe Aktivität" auffallen sperrt. Aber ich denk mal wenn du 5 Sekunden für jeden Thread wartest... gehen wir mal von 300.000 Threads aus dann wären das 17.3 Tage Wenn man die ganze Börse sichern will. Da die Montag aber gelöscht wird.. Dazu kommen natürlich noch die Zeiten fürs Verbinden etc... also ist 'n bisschen spät meiner Meinung nach.
    Aber trotzdem nette Klasse.
    Hatte mir selber auch bereits so 'n Teil geschrieben.. das war zwar noch nicht auf Rekursivität ausgelegt, hat aber schön Header + Footer abgeschnitten und lediglich den Content erstmal in .html Dateien gesichert. Meine Klasse war jedoch sicher langsamer da ich sie sich "manuell" einloggen hab ^^ und nicht einfach die Cookies gesetzt habe.

    Aber ich musste, da Gulli ja den lighttpd benutzt, die Headerinformation "Expect:" leer setzen, sonst habe ich immer 'n Fehler vom HTTPd bekommen - hast du das nicht gemacht? Oder überseh ich das nur...
     
  6. 10. August 2008
    AW: gulli:börse backup-spider

    Die Börse wird nicht gelöscht sondern nur Software Deleted. Wird sicher dann irgendwann mal einen komplettes Backup geben.
     
  7. 10. August 2008
    AW: gulli:börse backup-spider

    woher hast du das ?
     
  8. 10. August 2008
    AW: gulli:börse backup-spider

    Weil sandler der admin selber behauptet hat dass die Postingcounter von der Löschung nicht betroffen werden.
    Wie wollen sie die beibehalten? Geht ja nur wenn die Foren und Threads nicht aus der DB gelöscht werden.
     
  9. 10. August 2008
    AW: gulli:börse backup-spider

    oder man ein winziges workaround einbaut um die post-zahl zu erhalten
     
  10. 10. August 2008
    AW: gulli:börse backup-spider

    was ich auch für wahrscheinlicher halte, alleine schon von der Speicherkapazität. die börse ist ja "nicht gerade klein"
     
  11. 10. August 2008
    AW: gulli:börse backup-spider

    joa, also ich hab selber mal probiert nur alle threads der jeweiligen ersten seite zu speichern... leider war ich gestern abend wohl nicht alleine^^ (db war überlastet).
    komm bei diesem sammelthread auf 10mb

    mein account is aber noch nicht gespeert und die flood-protection is nicht mal eingebaut^^

    wie dem auch sei, gulli sperrt zz bots aus mit der nachricht "too many spiders..." und ich hab ehrlich gesagt kein großes interesse an der börse, von daher...

    mal schauen was sich aus dem script noch ergibt.
     
  12. 8. Oktober 2008
    AW: gulli:börse backup-spider

    gibts mittlerweile ein backup? bräuchte noch ein password...
    das ist leider vergessen habe... und da wär das schon nice...
    danke
     
  13. Video Script

    Videos zum Themenbereich

    * gefundene Videos auf YouTube, anhand der Überschrift.