Subversion Repositories personal-webbase

Rev

Rev 4 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 daniel-mar 1
<?php
2
 
3 daniel-mar 3
if (!defined('IBLEGAL')) die('Kann nicht ohne Personal WebBase ausgef&uuml;hrt werden.');
2 daniel-mar 4
 
5
function ftp_rmdir_rec($handle, $path)
6
{
7
   if (!@ftp_delete($handle, $path))
8
   {
9
       $list = @ftp_nlist($handle, $path);
10
       if(!empty($list))
11
           foreach($list as $value)
12
               ftp_rmdir_rec($handle, $value);
13
   }
14
 
15
   if(@ftp_rmdir($handle, $path))
16
       return true;
17
   else
18
       return false;
19
}
20
 
21
  // Funktioniert FTP-Zugang?
22
 
3 daniel-mar 23
if ($konfiguration['core_directftp']['ftp-server'] == '') {
24
        $conn_id = null;
25
        $login_result = false;
26
} else {
2 daniel-mar 27
  $conn_id = @ftp_connect($konfiguration['core_directftp']['ftp-server'], $konfiguration['core_directftp']['ftp-port']);
28
  $login_result = @ftp_login ($conn_id, $konfiguration['core_directftp']['ftp-username'], $konfiguration['core_directftp']['ftp-passwort']);
3 daniel-mar 29
}
2 daniel-mar 30
 
31
  $fehler = 0;
32
 
33
  if ((!$conn_id) || (!$login_result))
34
    $fehler = 1;
35
 
36
  if ((@ftp_size($conn_id, $konfiguration['core_directftp']['ftp-verzeichnis'].'modules/moddir.txt') == -1) || (substr($konfiguration['core_directftp']['ftp-verzeichnis'], 0, 1) != '/') || (substr($konfiguration['core_directftp']['ftp-verzeichnis'], strlen($konfiguration['core_directftp']['ftp-verzeichnis'])-1, 1) != '/'))
37
    $fehler = 1;
38
 
39
  if ($fehler)
8 daniel-mar 40
    die($header.'<b>Fehler</b><br><br>Fehlkonfiguration im FTP-Direktzugriff-Kernmodul! FTP-Zugangsdaten oder -Verzeichnis fehlerhaft bzw. zu geringe Zugriffsrechte! Bitte <a href="'.$_SERVER['PHP_SELF'].'?modul=core_directftp&amp;seite=konfig&amp;vonmodul='.urlencode($modul).'">Konfigurationswerte</a> einsehen.<br><br><a href="'.$_SERVER['PHP_SELF'].'?seite=inhalt&amp;modul='.urlencode($modul).'">Zur&uuml;ck</a>'.$footer);
2 daniel-mar 41
 
42
  // Los gehts!
43
 
44
  if ($aktion == 'delete')
45
  {
46
    // Nun Modul über FTP löschen!
8 daniel-mar 47
    @ftp_rmdir_rec($conn_id, $konfiguration['core_directftp']['ftp-verzeichnis'].'modules/'.wb_dir_escape($entfernen));
3 daniel-mar 48
    if ($conn_id) @ftp_quit($conn_id);
2 daniel-mar 49
 
50
    // Info: MySQL-Daten löschen sich über Autostart automatisch
8 daniel-mar 51
    if (!headers_sent()) header('location: '.$_SERVER['PHP_SELF'].'?seite=inhalt&modul='.urlencode($modul));
2 daniel-mar 52
  }
53
 
54
  if ($aktion == 'install')
55
  {
56
          // Temp-Verzeichnisnamen finden
57
      $uid = 'temp_'.zufall(10);
58
 
59
      // Datei in unser Verzeichnis kopieren, sodass wir darauf zugreifen können (für Safe-Mode)
8 daniel-mar 60
      if (!@ftp_put($conn_id, $konfiguration['core_directftp']['ftp-verzeichnis'].'modules/'.wb_dir_escape($modul).'/temp/'.wb_dir_escape($uid).'.zip', $_FILES['dfile']['tmp_name'], FTP_BINARY))
2 daniel-mar 61
      {
3 daniel-mar 62
        if ($conn_id) @ftp_quit($conn_id);
8 daniel-mar 63
        die($header.'<b>Fehler</b><br><br>Konnte ZIP-Datei nicht in tempor&auml;res Verzeichnis des Modules hineinkopieren (FTP)!.<br><br><a href="'.$_SERVER['PHP_SELF'].'?seite=inhalt&amp;modul='.urlencode($modul).'">Zur&uuml;ck</a>'.$footer);
2 daniel-mar 64
      }
8 daniel-mar 65
      @ftp_site($conn_id, 'CHMOD 0644 '.$konfiguration['core_directftp']['ftp-verzeichnis'].'modules/'.wb_dir_escape($modul).'/temp/'.wb_dir_escape($uid).'.zip');
2 daniel-mar 66
 
67
      // Temporäres Verzeichnis für Extraktion erstellen
8 daniel-mar 68
      @ftp_rmdir_rec($conn_id, $konfiguration['core_directftp']['ftp-verzeichnis'].'modules/'.wb_dir_escape($modul).'/temp/'.wb_dir_escape($uid).'/');
69
      @ftp_mkdir($conn_id, $konfiguration['core_directftp']['ftp-verzeichnis'].'modules/'.wb_dir_escape($modul).'/temp/'.wb_dir_escape($uid).'/');
70
      @ftp_site($conn_id, 'CHMOD 0755 '.$konfiguration['core_directftp']['ftp-verzeichnis'].'modules/'.wb_dir_escape($modul).'/temp/'.wb_dir_escape($uid).'/');
2 daniel-mar 71
 
3 daniel-mar 72
      // Entpacken zum Personal WebBase-Temp-Verzeichnis
8 daniel-mar 73
      if (file_exists('modules/'.wb_dir_escape($modul).'/dUnzip2.inc.php'))
74
        include('modules/'.wb_dir_escape($modul).'/dUnzip2.inc.php');
75
          $zip = new dUnzip2('modules/'.wb_dir_escape($modul).'/temp/'.wb_dir_escape($uid).'.zip');
76
      $zip->unzipAll('modules/'.wb_dir_escape($modul).'/temp/'.wb_dir_escape($uid).'/', '', true);
2 daniel-mar 77
      $zip->close();
78
 
79
          // Temporäre Daten löschen
8 daniel-mar 80
          @ftp_delete($conn_id, $konfiguration['core_directftp']['ftp-verzeichnis'].'modules/'.wb_dir_escape($modul).'/temp/'.wb_dir_escape($uid).'.zip');
2 daniel-mar 81
 
82
      // Wenn Verzeichnis leer ist, lässt es sich löschen. -> Fehler
8 daniel-mar 83
      $verzinh = @ftp_nlist($conn_id, $konfiguration['core_directftp']['ftp-verzeichnis'].'modules/'.wb_dir_escape($modul).'/temp/'.wb_dir_escape($uid).'/');
2 daniel-mar 84
      if (count($verzinh) == 0)
85
      {
8 daniel-mar 86
        @ftp_rmdir_rec($conn_id, $konfiguration['core_directftp']['ftp-verzeichnis'].'modules/'.wb_dir_escape($modul).'/temp/'.wb_dir_escape($uid).'/');
3 daniel-mar 87
        if ($conn_id) @ftp_quit($conn_id);
8 daniel-mar 88
        die($header.'<b>Fehler</b><br><br>Dekompression entweder komplett misslungen oder ZIP-Datei war leer.<br><br><a href="'.$_SERVER['PHP_SELF'].'?seite=inhalt&amp;modul='.urlencode($modul).'">Zur&uuml;ck</a>'.$footer);
2 daniel-mar 89
      }
90
 
91
          // Verzeichnis verschieben
8 daniel-mar 92
          if (!@ftp_rename($conn_id, $konfiguration['core_directftp']['ftp-verzeichnis'].'modules/'.wb_dir_escape($modul).'/temp/'.wb_dir_escape($uid).'/', $konfiguration['core_directftp']['ftp-verzeichnis'].'modules/'.wb_dir_escape($uid).'/'))
2 daniel-mar 93
          {
8 daniel-mar 94
        @ftp_rmdir_rec($conn_id, $konfiguration['core_directftp']['ftp-verzeichnis'].'modules/'.wb_dir_escape($modul).'/temp/'.wb_dir_escape($uid).'/');
3 daniel-mar 95
        if ($conn_id) @ftp_quit($conn_id);
8 daniel-mar 96
        die($header.'<b>Fehler</b><br><br>Das Verschieben des Verzeichnisses ist misslungen!<br><br><a href="'.$_SERVER['PHP_SELF'].'?seite=inhalt&amp;modul='.urlencode($modul).'">Zur&uuml;ck</a>'.$footer);
2 daniel-mar 97
          }
98
 
99
          // Richtigen Dateinamen finden
8 daniel-mar 100
          $fn = 'modules/'.wb_dir_escape($uid).'/ordnername.txt';
2 daniel-mar 101
          $fp = @fopen($fn, 'r');
102
          $inhalt = @fread($fp, @filesize($fn));
103
      @fclose($fp);
104
 
105
      // Datei ordnername.txt im Zielmodul löschen
8 daniel-mar 106
      @ftp_delete ($conn_id, $konfiguration['core_directftp']['ftp-verzeichnis'].'modules/'.wb_dir_escape($uid).'/ordnername.txt');
2 daniel-mar 107
 
108
      if ($inhalt != '')
109
      {
110
        // Schutzverletzung im Ordnernamen?
111
        if (strpos($inhalt, '..'))
112
        {
3 daniel-mar 113
          if ($conn_id) @ftp_quit($conn_id);
8 daniel-mar 114
          die($header.'<b>Fehler</b><br><br>Das Modul konnte zwar installiert werden, jedoch gab es bei der Umbenennung des Ordners eine Schutzverletzung!<br><br><a href="'.$_SERVER['PHP_SELF'].'?seite=inhalt&amp;modul='.urlencode($modul).'">Zur&uuml;ck</a>'.$footer);
2 daniel-mar 115
        }
116
 
117
        // Gibt es schon ein Modul mit dem Titel? Dann Alternativenamen finden
8 daniel-mar 118
        if (@ftp_chdir($conn_id, $konfiguration['core_directftp']['ftp-verzeichnis'].'modules/'.wb_dir_escape($inhalt).'/'))
2 daniel-mar 119
        {
120
          @ftp_cdup($conn_id);
121
          $zusatz = 2;
122
          $problem = true;
8 daniel-mar 123
          while (@ftp_chdir($conn_id, $konfiguration['core_directftp']['ftp-verzeichnis'].'modules/'.wb_dir_escape($inhalt).$zusatz.'/'))
2 daniel-mar 124
          {
125
            @ftp_cdup($conn_id);
126
            $zusatz++;
127
          }
128
        }
129
        else
130
        {
131
          $problem = false;
132
          $zusatz = '';
133
        }
134
 
135
        // Ordner umbenennen
8 daniel-mar 136
        $erfolg = @ftp_rename ($conn_id, $konfiguration['core_directftp']['ftp-verzeichnis'].'modules/'.wb_dir_escape($uid), $konfiguration['core_directftp']['ftp-verzeichnis'].'modules/'.wb_dir_escape($inhalt).$zusatz);
2 daniel-mar 137
 
138
        // FTP-Verbindung trennen
3 daniel-mar 139
        if ($conn_id) @ftp_quit($conn_id);
2 daniel-mar 140
 
141
        // Wurde der Ordner nicht umbenannt? (z.B. Wenn der Ordnertitel nicht für Dateisystem zulässig war)
142
        if (!$erfolg)
8 daniel-mar 143
          die($header.'<b>Information</b><br><br>Das Modul konnte zwar installiert werden, jedoch gab es bei der Umbenennung des Ordners einen Fehler!<br><br><a href="'.$_SERVER['PHP_SELF'].'?seite=inhalt&amp;modul='.urlencode($modul).'">Zur&uuml;ck</a>'.$footer);
2 daniel-mar 144
 
145
        // Wurde nur der Ordner nicht korrekt umbenannt? (z.B. wenn es ein Modul mit dem selben Namen noch gibt)
146
        if ($problem)
8 daniel-mar 147
          die($header.'<b>Information</b><br><br>Es existiert bereits ein Modul mit dem Namen &quot;'.$inhalt.'&quot;. Das Modul wurde trotzdem unter dem alternativen Namen &quot;'.$inhalt.$zusatz.'&quot; installiert.<br><br><a href="'.$_SERVER['PHP_SELF'].'?seite=inhalt&amp;modul='.urlencode($modul).'">Zur&uuml;ck</a>'.$footer);
2 daniel-mar 148
      }
149
      else
150
      {
151
        // Kein Dateiname angegeben?
3 daniel-mar 152
        if ($conn_id) @ftp_quit($conn_id);
8 daniel-mar 153
        die($header.'<b>Information</b><br><br>Das Modul wurde unter dem Namen &quot;'.$uid.'&quot; angelegt, da in der Moduldatei keine Namensangabe vorhanden war.<br><br><a href="'.$_SERVER['PHP_SELF'].'?seite=inhalt&amp;modul='.urlencode($modul).'">Zur&uuml;ck</a>'.$footer);
2 daniel-mar 154
      }
155
 
156
      // Alles OK? Dann zurück!
8 daniel-mar 157
      if (!headers_sent()) header('location: '.$_SERVER['PHP_SELF'].'?seite=inhalt&modul='.urlencode($modul));
2 daniel-mar 158
  }
159
 
3 daniel-mar 160
?>