Rev 12 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
12 | daniel-mar | 1 | <?php |
2 | |||
14 | daniel-mar | 3 | if (!defined('WBLEGAL')) die('Kann nicht ohne Personal WebBase ausgeführt werden.'); |
12 | 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 | |||
23 | if ($konfiguration['core_directftp']['ftp-server'] == '') { |
||
24 | $conn_id = null; |
||
25 | $login_result = false; |
||
26 | } else { |
||
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']); |
||
29 | } |
||
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='.urlencode($modul).'">Konfigurationswerte</a> einsehen.<br><br><a href="'.$_SERVER['PHP_SELF'].'?seite=inhalt&modul='.urlencode($modul).'">Zurück</a>'.$footer); |
||
41 | |||
42 | // Los gehts! |
||
43 | |||
44 | if ($aktion == 'delete') |
||
45 | { |
||
46 | // Nun Modul über FTP löschen! |
||
47 | @ftp_rmdir_rec($conn_id, $konfiguration['core_directftp']['ftp-verzeichnis'].'modules/'.wb_dir_escape($entfernen)); |
||
48 | if ($conn_id) @ftp_quit($conn_id); |
||
49 | |||
50 | // Info: MySQL-Daten löschen sich über Autostart automatisch |
||
51 | if (!headers_sent()) header('location: '.$_SERVER['PHP_SELF'].'?seite=inhalt&modul='.urlencode($modul)); |
||
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) |
||
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)) |
||
61 | { |
||
62 | if ($conn_id) @ftp_quit($conn_id); |
||
63 | 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='.urlencode($modul).'">Zurück</a>'.$footer); |
||
64 | } |
||
65 | @ftp_site($conn_id, 'CHMOD 0644 '.$konfiguration['core_directftp']['ftp-verzeichnis'].'modules/'.wb_dir_escape($modul).'/temp/'.wb_dir_escape($uid).'.zip'); |
||
66 | |||
67 | // Temporäres Verzeichnis für Extraktion erstellen |
||
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).'/'); |
||
71 | |||
72 | // Entpacken zum Personal WebBase-Temp-Verzeichnis |
||
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); |
||
77 | $zip->close(); |
||
78 | |||
79 | // Temporäre Daten löschen |
||
80 | @ftp_delete($conn_id, $konfiguration['core_directftp']['ftp-verzeichnis'].'modules/'.wb_dir_escape($modul).'/temp/'.wb_dir_escape($uid).'.zip'); |
||
81 | |||
82 | // Wenn Verzeichnis leer ist, lässt es sich löschen. -> Fehler |
||
83 | $verzinh = @ftp_nlist($conn_id, $konfiguration['core_directftp']['ftp-verzeichnis'].'modules/'.wb_dir_escape($modul).'/temp/'.wb_dir_escape($uid).'/'); |
||
84 | if (count($verzinh) == 0) |
||
85 | { |
||
86 | @ftp_rmdir_rec($conn_id, $konfiguration['core_directftp']['ftp-verzeichnis'].'modules/'.wb_dir_escape($modul).'/temp/'.wb_dir_escape($uid).'/'); |
||
87 | if ($conn_id) @ftp_quit($conn_id); |
||
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&modul='.urlencode($modul).'">Zurück</a>'.$footer); |
||
89 | } |
||
90 | |||
91 | // Verzeichnis verschieben |
||
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).'/')) |
||
93 | { |
||
94 | @ftp_rmdir_rec($conn_id, $konfiguration['core_directftp']['ftp-verzeichnis'].'modules/'.wb_dir_escape($modul).'/temp/'.wb_dir_escape($uid).'/'); |
||
95 | if ($conn_id) @ftp_quit($conn_id); |
||
96 | die($header.'<b>Fehler</b><br><br>Das Verschieben des Verzeichnisses ist misslungen!<br><br><a href="'.$_SERVER['PHP_SELF'].'?seite=inhalt&modul='.urlencode($modul).'">Zurück</a>'.$footer); |
||
97 | } |
||
98 | |||
99 | // Richtigen Dateinamen finden |
||
100 | $fn = 'modules/'.wb_dir_escape($uid).'/ordnername.txt'; |
||
101 | $fp = @fopen($fn, 'r'); |
||
102 | $inhalt = @fread($fp, @filesize($fn)); |
||
103 | @fclose($fp); |
||
104 | |||
105 | // Datei ordnername.txt im Zielmodul löschen |
||
106 | @ftp_delete ($conn_id, $konfiguration['core_directftp']['ftp-verzeichnis'].'modules/'.wb_dir_escape($uid).'/ordnername.txt'); |
||
107 | |||
108 | if ($inhalt != '') |
||
109 | { |
||
110 | // Schutzverletzung im Ordnernamen? |
||
111 | if (strpos($inhalt, '..')) |
||
112 | { |
||
113 | if ($conn_id) @ftp_quit($conn_id); |
||
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&modul='.urlencode($modul).'">Zurück</a>'.$footer); |
||
115 | } |
||
116 | |||
117 | // Gibt es schon ein Modul mit dem Titel? Dann Alternativenamen finden |
||
118 | if (@ftp_chdir($conn_id, $konfiguration['core_directftp']['ftp-verzeichnis'].'modules/'.wb_dir_escape($inhalt).'/')) |
||
119 | { |
||
120 | @ftp_cdup($conn_id); |
||
121 | $zusatz = 2; |
||
122 | $problem = true; |
||
123 | while (@ftp_chdir($conn_id, $konfiguration['core_directftp']['ftp-verzeichnis'].'modules/'.wb_dir_escape($inhalt).$zusatz.'/')) |
||
124 | { |
||
125 | @ftp_cdup($conn_id); |
||
126 | $zusatz++; |
||
127 | } |
||
128 | } |
||
129 | else |
||
130 | { |
||
131 | $problem = false; |
||
132 | $zusatz = ''; |
||
133 | } |
||
134 | |||
135 | // Ordner umbenennen |
||
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); |
||
137 | |||
138 | // FTP-Verbindung trennen |
||
139 | if ($conn_id) @ftp_quit($conn_id); |
||
140 | |||
141 | // Wurde der Ordner nicht umbenannt? (z.B. Wenn der Ordnertitel nicht für Dateisystem zulässig war) |
||
142 | if (!$erfolg) |
||
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&modul='.urlencode($modul).'">Zurück</a>'.$footer); |
||
144 | |||
145 | // Wurde nur der Ordner nicht korrekt umbenannt? (z.B. wenn es ein Modul mit dem selben Namen noch gibt) |
||
146 | if ($problem) |
||
147 | 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='.urlencode($modul).'">Zurück</a>'.$footer); |
||
148 | } |
||
149 | else |
||
150 | { |
||
151 | // Kein Dateiname angegeben? |
||
152 | if ($conn_id) @ftp_quit($conn_id); |
||
153 | 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='.urlencode($modul).'">Zurück</a>'.$footer); |
||
154 | } |
||
155 | |||
156 | // Alles OK? Dann zurück! |
||
157 | if (!headers_sent()) header('location: '.$_SERVER['PHP_SELF'].'?seite=inhalt&modul='.urlencode($modul)); |
||
158 | } |
||
159 | |||
160 | ?> |