Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | daniel-mar | 1 | <?php |
2 | |||
3 | if (!defined('WBLEGAL')) die('Kann nicht ohne Personal WebBase ausgeführt werden.'); |
||
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 | { |
||
12 | foreach($list as $value) |
||
13 | { |
||
14 | ftp_rmdir_rec($handle, $value); |
||
15 | } |
||
16 | } |
||
17 | } |
||
18 | |||
19 | if(@ftp_rmdir($handle, $path)) |
||
20 | return true; |
||
21 | else |
||
22 | return false; |
||
23 | } |
||
24 | |||
25 | // Funktioniert FTP-Zugang? |
||
26 | |||
27 | $conn_id = @ftp_connect($configuration['common_directftp']['ftp-server'], $configuration['common_directftp']['ftp-port']); |
||
28 | $login_result = @ftp_login ($conn_id, $configuration['common_directftp']['ftp-username'], $configuration['common_directftp']['ftp-password']); |
||
29 | |||
30 | $fehler = 0; |
||
31 | |||
32 | if ((!$conn_id) || (!$login_result)) |
||
33 | $fehler = 1; |
||
34 | |||
35 | if ((@ftp_size($conn_id, $configuration['common_directftp']['ftp-verzeichnis'].'modules/moddir.txt') == -1) || (substr($configuration['common_directftp']['ftp-verzeichnis'], 0, 1) != '/') || (substr($configuration['common_directftp']['ftp-verzeichnis'], strlen($configuration['common_directftp']['ftp-verzeichnis'])-1, 1) != '/')) |
||
36 | $fehler = 1; |
||
37 | |||
38 | if ($fehler) |
||
39 | 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=common_directftp&seite=config&vonmodul='.$modul.'">Konfigurationswerte</a> einsehen.<br><br><a href="'.$_SERVER['PHP_SELF'].'?seite=main&modul='.$modul.'">Zurück</a>'.$footer); |
||
40 | |||
41 | // Los gehts! |
||
42 | |||
43 | if ($aktion == 'delete') |
||
44 | { |
||
45 | // Achtung! Ein Hacker könnte ../ als Modul angeben und somit das komplette Modulverzeichnis oder mehr rekursiv löschen! |
||
46 | if (strpos($modul, '..')) |
||
47 | die($header.'<b>Fehler</b><br><br>Der Löschvorgang wurde aufgrund einer Schutzverletzung abgebrochen!<br><br><a href="'.$_SERVER['PHP_SELF'].'?seite=main&modul='.$modul.'">Zurück</a>'.$footer); |
||
48 | |||
49 | // Nun Modul über FTP löschen! |
||
50 | @ftp_rmdir_rec($conn_id, $configuration['common_directftp']['ftp-verzeichnis'].'modules/'.$entfernen); |
||
51 | @ftp_quit($conn_id); |
||
52 | |||
53 | // Info: MySQL-Daten löschen sich über Autostart automatisch |
||
54 | wb_redirect_now($_SERVER['PHP_SELF'].'?seite=main&modul='.$modul); |
||
55 | } |
||
56 | |||
57 | if ($aktion == 'install') |
||
58 | { |
||
59 | // Temp-Verzeichnisnamen finden |
||
60 | $uid = 'temp_'.zufall(10); |
||
61 | |||
62 | // Datei in unser Verzeichnis kopieren, sodass wir darauf zugreifen können (für Safe-Mode) |
||
63 | if (!@ftp_put($conn_id, $configuration['common_directftp']['ftp-verzeichnis'].'modules/'.$modul.'/temp/'.$uid.'.zip', $_FILES['dfile']['tmp_name'], FTP_BINARY)) |
||
64 | { |
||
65 | @ftp_quit($conn_id); |
||
66 | 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=main&modul='.$modul.'">Zurück</a>'.$footer); |
||
67 | } |
||
68 | @ftp_site($conn_id, 'CHMOD 0644 '.$configuration['common_directftp']['ftp-verzeichnis'].'modules/'.$modul.'/temp/'.$uid.'.zip'); |
||
69 | |||
70 | // Temporäres Verzeichnis für Extraktion erstellen |
||
71 | @ftp_rmdir_rec($conn_id, $configuration['common_directftp']['ftp-verzeichnis'].'modules/'.$modul.'/temp/'.$uid.'/'); |
||
72 | @ftp_mkdir($conn_id, $configuration['common_directftp']['ftp-verzeichnis'].'modules/'.$modul.'/temp/'.$uid.'/'); |
||
73 | @ftp_site($conn_id, 'CHMOD 0755 '.$configuration['common_directftp']['ftp-verzeichnis'].'modules/'.$modul.'/temp/'.$uid.'/'); |
||
74 | |||
75 | // Entpacken zum Personal WebBase-Temp-Verzeichnis |
||
76 | if (file_exists('modules/'.$modul.'/includes/dunzip2.inc.php')) |
||
77 | include('modules/'.$modul.'/includes/dunzip2.inc.php'); |
||
78 | $zip = new dUnzip2('modules/'.$modul.'/temp/'.$uid.'.zip'); |
||
79 | $zip->unzipAll('modules/'.$modul.'/temp/'.$uid.'/', '', true); |
||
80 | $zip->close(); |
||
81 | |||
82 | // Temporäre Daten löschen |
||
83 | @ftp_delete($conn_id, $configuration['common_directftp']['ftp-verzeichnis'].'modules/'.$modul.'/temp/'.$uid.'.zip'); |
||
84 | |||
85 | // Wenn Verzeichnis leer ist, lässt es sich löschen. -> Fehler |
||
86 | $verzinh = @ftp_nlist($conn_id, $configuration['common_directftp']['ftp-verzeichnis'].'modules/'.$modul.'/temp/'.$uid.'/'); |
||
87 | if (count($verzinh) == 0) |
||
88 | { |
||
89 | @ftp_rmdir_rec($conn_id, $configuration['common_directftp']['ftp-verzeichnis'].'modules/'.$modul.'/temp/'.$uid.'/'); |
||
90 | @ftp_quit($conn_id); |
||
91 | die($header.'<b>Fehler</b><br><br>Dekompression entweder komplett misslungen oder ZIP-Datei war leer.<br><br><a href="'.$_SERVER['PHP_SELF'].'?seite=main&modul='.$modul.'">Zurück</a>'.$footer); |
||
92 | } |
||
93 | |||
94 | // Verzeichnis verschieben |
||
95 | if (!@ftp_rename($conn_id, $configuration['common_directftp']['ftp-verzeichnis'].'modules/'.$modul.'/temp/'.$uid.'/', $configuration['common_directftp']['ftp-verzeichnis'].'modules/'.$uid.'/')) |
||
96 | { |
||
97 | @ftp_rmdir_rec($conn_id, $configuration['common_directftp']['ftp-verzeichnis'].'modules/'.$modul.'/temp/'.$uid.'/'); |
||
98 | @ftp_quit($conn_id); |
||
99 | die($header.'<b>Fehler</b><br><br>Das Verschieben des Verzeichnisses ist misslungen!<br><br><a href="'.$_SERVER['PHP_SELF'].'?seite=main&modul='.$modul.'">Zurück</a>'.$footer); |
||
100 | } |
||
101 | |||
102 | // Richtigen Dateinamen finden |
||
103 | $fn = 'modules/'.$uid.'/folder_name.txt'; |
||
104 | $fp = @fopen($fn, 'r'); |
||
105 | $inhalt = @fread($fp, @filesize($fn)); |
||
106 | @fclose($fp); |
||
107 | |||
108 | // Datei folder_name.txt im Zielmodul löschen |
||
109 | @ftp_delete ($conn_id, $configuration['common_directftp']['ftp-verzeichnis'].'modules/'.$uid.'/folder_name.txt'); |
||
110 | |||
111 | if ($inhalt != '') |
||
112 | { |
||
113 | // Schutzverletzung im folder_namen? |
||
114 | if (strpos($inhalt, '..')) |
||
115 | { |
||
116 | @ftp_quit($conn_id); |
||
117 | 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=main&modul='.$modul.'">Zurück</a>'.$footer); |
||
118 | } |
||
119 | |||
120 | // Gibt es schon ein Modul mit dem Titel? Dann Alternativenamen finden |
||
121 | if (@ftp_chdir($conn_id, $configuration['common_directftp']['ftp-verzeichnis'].'modules/'.$inhalt.'/')) |
||
122 | { |
||
123 | @ftp_cdup($conn_id); |
||
124 | $zusatz = 2; |
||
125 | $problem = true; |
||
126 | while (@ftp_chdir($conn_id, $configuration['common_directftp']['ftp-verzeichnis'].'modules/'.$inhalt.$zusatz.'/')) |
||
127 | { |
||
128 | @ftp_cdup($conn_id); |
||
129 | $zusatz++; |
||
130 | } |
||
131 | } |
||
132 | else |
||
133 | { |
||
134 | $problem = false; |
||
135 | $zusatz = ''; |
||
136 | } |
||
137 | |||
138 | // Ordner umbenennen |
||
139 | $erfolg = @ftp_rename ($conn_id, $configuration['common_directftp']['ftp-verzeichnis'].'modules/'.$uid, $configuration['common_directftp']['ftp-verzeichnis'].'modules/'.$inhalt.$zusatz); |
||
140 | |||
141 | // FTP-Verbindung trennen |
||
142 | @ftp_quit($conn_id); |
||
143 | |||
144 | // Wurde der Ordner nicht umbenannt? (z.B. Wenn der Ordnertitel nicht für Dateisystem zulässig war) |
||
145 | if (!$erfolg) |
||
146 | 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=main&modul='.$modul.'">Zurück</a>'.$footer); |
||
147 | |||
148 | // Wurde nur der Ordner nicht korrekt umbenannt? (z.B. wenn es ein Modul mit dem selben Namen noch gibt) |
||
149 | if ($problem) |
||
150 | 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=main&modul='.$modul.'">Zurück</a>'.$footer); |
||
151 | } |
||
152 | else |
||
153 | { |
||
154 | // Kein Dateiname angegeben? |
||
155 | @ftp_quit($conn_id); |
||
156 | 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=main&modul='.$modul.'">Zurück</a>'.$footer); |
||
157 | } |
||
158 | |||
159 | // Alles OK? Dann zurück! |
||
160 | wb_redirect_now($_SERVER['PHP_SELF'].'?seite=main&modul='.$modul); |
||
161 | } |
||
162 | |||
163 | ?> |