Rev 3 | 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ü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) |
||
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&seite=konfig&vonmodul='.$modul.'">Konfigurationswerte</a> einsehen.<br><br><a href="'.$_SERVER['PHP_SELF'].'?seite=inhalt&modul='.$modul.'">Zurück</a>'.$footer); |
||
41 | |||
42 | // Los gehts! |
||
43 | |||
44 | if ($aktion == 'delete') |
||
45 | { |
||
46 | // Achtung! Ein Hacker könnte ../ als Modul angeben und somit das komplette Modulverzeichnis oder mehr rekursiv löschen! |
||
47 | if (strpos($modul, '..')) |
||
48 | die($header.'<b>Fehler</b><br><br>Der Löschvorgang wurde aufgrund einer Schutzverletzung abgebrochen!<br><br><a href="'.$_SERVER['PHP_SELF'].'?seite=inhalt&modul='.$modul.'">Zurück</a>'.$footer); |
||
49 | |||
50 | // Nun Modul über FTP löschen! |
||
51 | @ftp_rmdir_rec($conn_id, $konfiguration['core_directftp']['ftp-verzeichnis'].'modules/'.$entfernen); |
||
3 | daniel-mar | 52 | if ($conn_id) @ftp_quit($conn_id); |
2 | daniel-mar | 53 | |
54 | // Info: MySQL-Daten löschen sich über Autostart automatisch |
||
55 | if (!headers_sent()) header('location: '.$_SERVER['PHP_SELF'].'?seite=inhalt&modul='.$modul); |
||
56 | } |
||
57 | |||
58 | if ($aktion == 'install') |
||
59 | { |
||
60 | // Temp-Verzeichnisnamen finden |
||
61 | $uid = 'temp_'.zufall(10); |
||
62 | |||
63 | // Datei in unser Verzeichnis kopieren, sodass wir darauf zugreifen können (für Safe-Mode) |
||
64 | if (!@ftp_put($conn_id, $konfiguration['core_directftp']['ftp-verzeichnis'].'modules/'.$modul.'/temp/'.$uid.'.zip', $_FILES['dfile']['tmp_name'], FTP_BINARY)) |
||
65 | { |
||
3 | daniel-mar | 66 | if ($conn_id) @ftp_quit($conn_id); |
2 | daniel-mar | 67 | die($header.'<b>Fehler</b><br><br>Konnte ZIP-Datei nicht in temporäres Verzeichnis des Modules hineinkopieren (FTP)!.<br><br><a href="'.$_SERVER['PHP_SELF'].'?seite=inhalt&modul='.$modul.'">Zurück</a>'.$footer); |
68 | } |
||
69 | @ftp_site($conn_id, 'CHMOD 0644 '.$konfiguration['core_directftp']['ftp-verzeichnis'].'modules/'.$modul.'/temp/'.$uid.'.zip'); |
||
70 | |||
71 | // Temporäres Verzeichnis für Extraktion erstellen |
||
72 | @ftp_rmdir_rec($conn_id, $konfiguration['core_directftp']['ftp-verzeichnis'].'modules/'.$modul.'/temp/'.$uid.'/'); |
||
73 | @ftp_mkdir($conn_id, $konfiguration['core_directftp']['ftp-verzeichnis'].'modules/'.$modul.'/temp/'.$uid.'/'); |
||
74 | @ftp_site($conn_id, 'CHMOD 0755 '.$konfiguration['core_directftp']['ftp-verzeichnis'].'modules/'.$modul.'/temp/'.$uid.'/'); |
||
75 | |||
3 | daniel-mar | 76 | // Entpacken zum Personal WebBase-Temp-Verzeichnis |
2 | daniel-mar | 77 | if (file_exists('modules/'.$modul.'/dUnzip2.inc.php')) |
78 | include('modules/'.$modul.'/dUnzip2.inc.php'); |
||
79 | $zip = new dUnzip2('modules/'.$modul.'/temp/'.$uid.'.zip'); |
||
80 | $zip->unzipAll('modules/'.$modul.'/temp/'.$uid.'/', '', true); |
||
81 | $zip->close(); |
||
82 | |||
83 | // Temporäre Daten löschen |
||
84 | @ftp_delete($conn_id, $konfiguration['core_directftp']['ftp-verzeichnis'].'modules/'.$modul.'/temp/'.$uid.'.zip'); |
||
85 | |||
86 | // Wenn Verzeichnis leer ist, lässt es sich löschen. -> Fehler |
||
87 | $verzinh = @ftp_nlist($conn_id, $konfiguration['core_directftp']['ftp-verzeichnis'].'modules/'.$modul.'/temp/'.$uid.'/'); |
||
88 | if (count($verzinh) == 0) |
||
89 | { |
||
90 | @ftp_rmdir_rec($conn_id, $konfiguration['core_directftp']['ftp-verzeichnis'].'modules/'.$modul.'/temp/'.$uid.'/'); |
||
3 | daniel-mar | 91 | if ($conn_id) @ftp_quit($conn_id); |
2 | daniel-mar | 92 | 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&modul='.$modul.'">Zurück</a>'.$footer); |
93 | } |
||
94 | |||
95 | // Verzeichnis verschieben |
||
96 | if (!@ftp_rename($conn_id, $konfiguration['core_directftp']['ftp-verzeichnis'].'modules/'.$modul.'/temp/'.$uid.'/', $konfiguration['core_directftp']['ftp-verzeichnis'].'modules/'.$uid.'/')) |
||
97 | { |
||
98 | @ftp_rmdir_rec($conn_id, $konfiguration['core_directftp']['ftp-verzeichnis'].'modules/'.$modul.'/temp/'.$uid.'/'); |
||
3 | daniel-mar | 99 | if ($conn_id) @ftp_quit($conn_id); |
2 | daniel-mar | 100 | die($header.'<b>Fehler</b><br><br>Das Verschieben des Verzeichnisses ist misslungen!<br><br><a href="'.$_SERVER['PHP_SELF'].'?seite=inhalt&modul='.$modul.'">Zurück</a>'.$footer); |
101 | } |
||
102 | |||
103 | // Richtigen Dateinamen finden |
||
104 | $fn = 'modules/'.$uid.'/ordnername.txt'; |
||
105 | $fp = @fopen($fn, 'r'); |
||
106 | $inhalt = @fread($fp, @filesize($fn)); |
||
107 | @fclose($fp); |
||
108 | |||
109 | // Datei ordnername.txt im Zielmodul löschen |
||
110 | @ftp_delete ($conn_id, $konfiguration['core_directftp']['ftp-verzeichnis'].'modules/'.$uid.'/ordnername.txt'); |
||
111 | |||
112 | if ($inhalt != '') |
||
113 | { |
||
114 | // Schutzverletzung im Ordnernamen? |
||
115 | if (strpos($inhalt, '..')) |
||
116 | { |
||
3 | daniel-mar | 117 | if ($conn_id) @ftp_quit($conn_id); |
2 | daniel-mar | 118 | 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&modul='.$modul.'">Zurück</a>'.$footer); |
119 | } |
||
120 | |||
121 | // Gibt es schon ein Modul mit dem Titel? Dann Alternativenamen finden |
||
122 | if (@ftp_chdir($conn_id, $konfiguration['core_directftp']['ftp-verzeichnis'].'modules/'.$inhalt.'/')) |
||
123 | { |
||
124 | @ftp_cdup($conn_id); |
||
125 | $zusatz = 2; |
||
126 | $problem = true; |
||
127 | while (@ftp_chdir($conn_id, $konfiguration['core_directftp']['ftp-verzeichnis'].'modules/'.$inhalt.$zusatz.'/')) |
||
128 | { |
||
129 | @ftp_cdup($conn_id); |
||
130 | $zusatz++; |
||
131 | } |
||
132 | } |
||
133 | else |
||
134 | { |
||
135 | $problem = false; |
||
136 | $zusatz = ''; |
||
137 | } |
||
138 | |||
139 | // Ordner umbenennen |
||
140 | $erfolg = @ftp_rename ($conn_id, $konfiguration['core_directftp']['ftp-verzeichnis'].'modules/'.$uid, $konfiguration['core_directftp']['ftp-verzeichnis'].'modules/'.$inhalt.$zusatz); |
||
141 | |||
142 | // FTP-Verbindung trennen |
||
3 | daniel-mar | 143 | if ($conn_id) @ftp_quit($conn_id); |
2 | daniel-mar | 144 | |
145 | // Wurde der Ordner nicht umbenannt? (z.B. Wenn der Ordnertitel nicht für Dateisystem zulässig war) |
||
146 | if (!$erfolg) |
||
147 | 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&modul='.$modul.'">Zurück</a>'.$footer); |
||
148 | |||
149 | // Wurde nur der Ordner nicht korrekt umbenannt? (z.B. wenn es ein Modul mit dem selben Namen noch gibt) |
||
150 | if ($problem) |
||
151 | die($header.'<b>Information</b><br><br>Es existiert bereits ein Modul mit dem Namen "'.$inhalt.'". Das Modul wurde trotzdem unter dem alternativen Namen "'.$inhalt.$zusatz.'" installiert.<br><br><a href="'.$_SERVER['PHP_SELF'].'?seite=inhalt&modul='.$modul.'">Zurück</a>'.$footer); |
||
152 | } |
||
153 | else |
||
154 | { |
||
155 | // Kein Dateiname angegeben? |
||
3 | daniel-mar | 156 | if ($conn_id) @ftp_quit($conn_id); |
2 | daniel-mar | 157 | die($header.'<b>Information</b><br><br>Das Modul wurde unter dem Namen "'.$uid.'" angelegt, da in der Moduldatei keine Namensangabe vorhanden war.<br><br><a href="'.$_SERVER['PHP_SELF'].'?seite=inhalt&modul='.$modul.'">Zurück</a>'.$footer); |
158 | } |
||
159 | |||
160 | // Alles OK? Dann zurück! |
||
161 | if (!headers_sent()) header('location: '.$_SERVER['PHP_SELF'].'?seite=inhalt&modul='.$modul); |
||
162 | } |
||
163 | |||
3 | daniel-mar | 164 | ?> |