Subversion Repositories personal-webbase

Rev

Rev 2 | 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
if ($ib_user_type < 2) die('Keine Zugriffsberechtigung');
6
 
7
function ftp_rmdir_rec($handle, $path)
8
{
9
   if (!@ftp_delete($handle, $path))
10
   {
11
       $list = @ftp_nlist($handle, $path);
12
       if(!empty($list))
13
           foreach($list as $value)
14
               ftp_rmdir_rec($handle, $value);
15
   }
16
 
17
   if(@ftp_rmdir($handle, $path))
18
       return true;
19
   else
20
       return false;
21
}
22
 
23
  if (($aktion == 'delete') || ($aktion == 'install'))
24
  {
25
    // Funktioniert FTP-Zugang?
26
 
3 daniel-mar 27
        if ($konfiguration['core_directftp']['ftp-server'] == '') {
28
                $conn_id = null;
29
                $login_result = false;
30
        } else {
31
            $conn_id = @ftp_connect($konfiguration['core_directftp']['ftp-server'], $konfiguration['core_directftp']['ftp-port']);
32
            $login_result = @ftp_login ($conn_id, $konfiguration['core_directftp']['ftp-username'], $konfiguration['core_directftp']['ftp-passwort']);
33
        }
2 daniel-mar 34
 
35
    $fehler = 0;
36
 
37
    if ((!$conn_id) || (!$login_result))
38
      $fehler = 1;
39
 
40
    if ((@ftp_size($conn_id, $konfiguration['core_directftp']['ftp-verzeichnis'].'design/'.'desdir.txt') == -1) || (@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) != '/'))
41
      $fehler = 1;
42
 
43
    if ($fehler)
44
      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='.$modul.'">Konfigurationswerte</a> einsehen.<br><br><a href="'.$_SERVER['PHP_SELF'].'?seite=inhalt&amp;modul='.$modul.'">Zur&uuml;ck</a>'.$footer);
45
  }
46
 
47
  // Los gehts!
48
 
49
  if ($aktion == 'delete')
50
  {
51
    // Achtung! Ein Hacker könnte ../ als Design angeben und somit das komplette Designverzeichnis oder mehr rekursiv löschen!
52
    if (strpos($modul, '..'))
53
      die($header.'<b>Fehler</b><br><br>Der L&ouml;schvorgang wurde aufgrund einer Schutzverletzung abgebrochen!<br><br><a href="'.$_SERVER['PHP_SELF'].'?seite=inhalt&amp;modul='.$modul.'">Zur&uuml;ck</a>'.$footer);
54
 
55
    // Nun Design über FTP löschen!
56
    @ftp_rmdir_rec($conn_id, $konfiguration['core_directftp']['ftp-verzeichnis'].'design/'.$entfernen);
3 daniel-mar 57
    if ($conn_id) @ftp_quit($conn_id);
2 daniel-mar 58
 
59
    // Info: MySQL-Daten löschen sich über Autostart automatisch
60
    if (!headers_sent()) header('location: '.$_SERVER['PHP_SELF'].'?seite=inhalt&modul='.$modul);
61
  }
62
 
63
  if ($aktion == 'install')
64
  {
65
          // Temp-Verzeichnisnamen finden
66
      $uid = 'temp_'.zufall(10);
67
 
68
      // Datei in unser Verzeichnis kopieren, sodass wir darauf zugreifen können (für Safe-Mode)
69
      if (!@ftp_put($conn_id, $konfiguration['core_directftp']['ftp-verzeichnis'].'modules/'.$modul.'/temp/'.$uid.'.zip', $_FILES['dfile']['tmp_name'], FTP_BINARY))
70
      {
3 daniel-mar 71
        if ($conn_id) @ftp_quit($conn_id);
2 daniel-mar 72
        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='.$modul.'">Zur&uuml;ck</a>'.$footer);
73
      }
74
      @ftp_site($conn_id, 'CHMOD 0644 '.$konfiguration['core_directftp']['ftp-verzeichnis'].'modules/'.$modul.'/temp/'.$uid.'.zip');
75
 
76
      // Temporäres Verzeichnis für Extraktion erstellen
77
      @ftp_rmdir_rec($conn_id, $konfiguration['core_directftp']['ftp-verzeichnis'].'modules/'.$modul.'/temp/'.$uid.'/');
78
      @ftp_mkdir($conn_id, $konfiguration['core_directftp']['ftp-verzeichnis'].'modules/'.$modul.'/temp/'.$uid.'/');
79
      @ftp_site($conn_id, 'CHMOD 0755 '.$konfiguration['core_directftp']['ftp-verzeichnis'].'modules/'.$modul.'/temp/'.$uid.'/');
80
 
3 daniel-mar 81
      // Entpacken zum Personal WebBase-Temp-Verzeichnis
2 daniel-mar 82
      if (file_exists('modules/'.$modul.'/dUnzip2.inc.php'))
83
        include('modules/'.$modul.'/dUnzip2.inc.php');
84
          $zip = new dUnzip2('modules/'.$modul.'/temp/'.$uid.'.zip');
85
      $zip->unzipAll('modules/'.$modul.'/temp/'.$uid.'/', '', true);
86
      $zip->close();
87
 
88
          // Temporäre Daten löschen
89
          @ftp_delete($conn_id, $konfiguration['core_directftp']['ftp-verzeichnis'].'modules/'.$modul.'/temp/'.$uid.'.zip');
90
 
91
      // Wenn Verzeichnis leer ist, lässt es sich löschen. -> Fehler
92
      $verzinh = @ftp_nlist($conn_id, $konfiguration['core_directftp']['ftp-verzeichnis'].'modules/'.$modul.'/temp/'.$uid.'/');
93
      if (count($verzinh) == 0)
94
      {
95
        @ftp_rmdir_rec($conn_id, $konfiguration['core_directftp']['ftp-verzeichnis'].'modules/'.$modul.'/temp/'.$uid.'/');
3 daniel-mar 96
        if ($conn_id) @ftp_quit($conn_id);
2 daniel-mar 97
        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='.$modul.'">Zur&uuml;ck</a>'.$footer);
98
      }
99
 
100
          // Verzeichnis verschieben
101
          if (!@ftp_rename($conn_id, $konfiguration['core_directftp']['ftp-verzeichnis'].'modules/'.$modul.'/temp/'.$uid.'/', $konfiguration['core_directftp']['ftp-verzeichnis'].'design/'.$uid.'/'))
102
          {
103
        @ftp_rmdir_rec($conn_id, $konfiguration['core_directftp']['ftp-verzeichnis'].'modules/'.$modul.'/temp/'.$uid.'/');
3 daniel-mar 104
        if ($conn_id) @ftp_quit($conn_id);
2 daniel-mar 105
        die($header.'<b>Fehler</b><br><br>Das Verschieben des Verzeichnisses ist misslungen!<br><br><a href="'.$_SERVER['PHP_SELF'].'?seite=inhalt&amp;modul='.$modul.'">Zur&uuml;ck</a>'.$footer);
106
          }
107
 
108
          // Richtigen Dateinamen finden
109
          $fn = 'design/'.$uid.'/ordnername.txt';
110
          $fp = @fopen($fn, 'r');
111
          $inhalt = @fread($fp, @filesize($fn));
112
      @fclose($fp);
113
 
114
      // Datei ordnername.txt im Zielmodul löschen
115
      @ftp_delete ($conn_id, $konfiguration['core_directftp']['ftp-verzeichnis'].'design/'.$uid.'/ordnername.txt');
116
 
117
      if ($inhalt != '')
118
      {
119
        // Schutzverletzung im Ordnernamen?
120
        if (strpos($inhalt, '..'))
121
        {
3 daniel-mar 122
          if ($conn_id) @ftp_quit($conn_id);
2 daniel-mar 123
          die($header.'<b>Fehler</b><br><br>Das Design konnte zwar installiert werden, jedoch gab es bei der Umbenennung des Ordners eine Schutzverletzung!'.$footer);
124
        }
125
 
126
        // Gibt es schon ein Design mit dem Titel? Dann Alternativenamen finden
127
        if (@ftp_chdir($conn_id, $konfiguration['core_directftp']['ftp-verzeichnis'].'design/'.$inhalt.'/'))
128
        {
129
          @ftp_cdup($conn_id);
130
          $zusatz = 2;
131
          $problem = true;
132
          while (@ftp_chdir($conn_id, $konfiguration['core_directftp']['ftp-verzeichnis'].'design/'.$inhalt.$zusatz.'/'))
133
          {
134
            @ftp_cdup($conn_id);
135
            $zusatz++;
136
          }
137
        }
138
        else
139
        {
140
          $problem = false;
141
          $zusatz = '';
142
        }
143
 
144
        // Ordner umbenennen
145
        $erfolg = @ftp_rename ($conn_id, $konfiguration['core_directftp']['ftp-verzeichnis'].'design/'.$uid, $konfiguration['core_directftp']['ftp-verzeichnis'].'design/'.$inhalt.$zusatz);
146
 
147
        // FTP-Verbindung trennen
3 daniel-mar 148
        if ($conn_id) @ftp_quit($conn_id);
2 daniel-mar 149
 
150
        // Wurde der Ordner nicht umbenannt? (z.B. Wenn der Ordnertitel nicht für Dateisystem zulässig war)
151
        if (!$erfolg)
152
          die($header.'<b>Information</b><br><br>Das Design 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='.$modul.'">Zur&uuml;ck</a>'.$footer);
153
 
154
        // Wurde nur der Ordner nicht korrekt umbenannt? (z.B. wenn es ein Design mit dem selben Namen noch gibt)
155
        if ($problem)
156
          die($header.'<b>Information</b><br><br>Es existiert bereits ein Design mit dem Namen &quot;'.$inhalt.'&quot;. Das Design wurde trotzdem unter dem alternativen Namen &quot;'.$inhalt.$zusatz.'&quot; installiert.<br><br><a href="'.$_SERVER['PHP_SELF'].'?seite=inhalt&amp;modul='.$modul.'">Zur&uuml;ck</a>'.$footer);
157
      }
158
      else
159
      {
160
        // Kein Dateiname angegeben?
3 daniel-mar 161
        if ($conn_id) @ftp_quit($conn_id);
2 daniel-mar 162
        die($header.'<b>Information</b><br><br>Das Design wurde unter dem Namen &quot;'.$uid.'&quot; angelegt, da in der Designdatei keine Namensangabe vorhanden war.<br><br><a href="'.$_SERVER['PHP_SELF'].'?seite=inhalt&amp;modul='.$modul.'">Zur&uuml;ck</a>'.$footer);
163
      }
164
 
165
      // Alles OK? Dann zurück!
166
      if (!headers_sent()) header('location: '.$_SERVER['PHP_SELF'].'?seite=inhalt&modul='.$modul);
167
  }
168
 
169
  if ($aktion == 'changekonfig')
170
  {
171
    ib_change_config('design', $newdesign, $modul);
172
    echo '<script language="JavaScript" type="text/javascript">
173
          <!--
174
 
175
          parent.location.href = \'index.php?prv_modul='.$vonmodul.'&prv_seite='.$vonseite.'\';
176
 
177
          // -->
178
  </script>';
179
 
180
    // Funktioniert nicht für eine Designänderung: if (!headers_sent()) header('location: '.$_SERVER['PHP_SELF'].'?seite=inhalt&modul=admin_konfig');
181
  }
182
 
3 daniel-mar 183
?>