source: trunk/Modules/NetworkShare/SharePage.php

Last change on this file was 929, checked in by chronos, 2 years ago
  • Modified: Removed commended out print_r and echo commands used only for debugging.
File size: 13.6 KB
Line 
1<?php
2
3class SharePage extends Page
4{
5 public array $Dependencies = array('Log');
6 public int $MaxNesting = 20; // Maximální vnoření
7 public array $Promene = array( // Automatické zapamatování proměnných
8 'keyword' => '',
9 'file_type' => 0,
10 'size' => '',
11 'size_method' => 1,
12 'size_units' => 2,
13 'online' => 'on',
14 'order' => 'size DESC',
15 'page' => '0',
16 'view' => 1,
17 );
18
19 function __construct(System $System)
20 {
21 parent::__construct($System);
22 $this->Title = 'Sdílené soubory';
23 $this->Description = 'Prohledávání sdílených souborů';
24 $this->ParentClass = 'PagePortal';
25 }
26
27 function ShowTime(): string
28 {
29 return date("H:i:s")."<br />\n";
30 }
31
32 // Inicializace Logu
33 //$LogFile = fopen('info.log','w');
34 function Loguj($Info)
35 {
36 //global $LogFile;
37 //fputs($LogFile,$Info."\n");
38 }
39 //Show_Array($GLOBALS);
40
41 // Najde cestu ke keřenu
42 function PlnaCesta($Row): string
43 {
44 // Vyhledání cesty
45 $Otec = $Row['Parent'];
46 $Cesta = ''; //$Row['name'];
47 $i = 0;
48 while (($Otec > 1) && ($i < $this->MaxNesting))
49 {
50 $DbResult = $this->Database->query('SELECT Id,Name,Parent FROM NetworkShareItem WHERE Id='.$Otec);
51 $Row = $DbResult->fetch_array();
52 $this->Loguj('Name: '.$Row['Name'].' ID:'.$Row['Id'].' Parent:'.$Row['Parent']);
53 $Cesta = $Row['Name'].'\\'.$Cesta;
54 $Otec = $Row['Parent'];
55 $i++;
56 }
57 if ($i >= $this->MaxNesting) $Cesta = '?'.'\\'.$Cesta;
58 return '\\\\'.$Cesta;
59 }
60
61 // Převede velikost v bajtech na odpovídající jednotky
62 function PrevedVelikost($Velikost): string
63 {
64 $Jednotky = array('B','kB','MB','GB','TB','PB','EB');
65 while ($Velikost >= 1024)
66 {
67 $Velikost = round($Velikost / 1024 * 10) / 10;
68 array_shift($Jednotky);
69 }
70 return $Velikost.'&nbsp;'.$Jednotky[0];
71 }
72
73 function Show(): string
74 {
75 if (!ModuleUser::Cast($this->System->GetModule('User'))->User->CheckPermission('NetworkShare', 'Display')) return 'Nemáte oprávnění';
76
77 // If not only online checkbox checked
78 if (array_key_exists('view', $_POST) and !array_key_exists('online', $_POST)) $_POST['online'] = 'off';
79
80 // Default host list view
81 if ((count($_POST) == 0) and (count($_GET) == 0))
82 {
83 $_POST['view'] = 1;
84 $_POST['page'] = 0;
85 }
86
87 // Toggle order direction
88 if (array_key_exists('order', $_GET) and ($_SESSION['order'] == $_GET['order'])) $_GET['order'] .= ' DESC';
89
90 foreach ($this->Promene as $Index => $Prvek)
91 {
92 if (!array_key_exists($Index, $_SESSION)) $_SESSION[$Index] = $this->Promene[$Index];
93 if (array_key_exists($Index, $_GET)) $_SESSION[$Index] = $_GET[$Index];
94 if (array_key_exists($Index, $_POST)) $_SESSION[$Index] = $_POST[$Index];
95 if (($Index == 'keyword') and (array_key_exists('view', $_GET))) $_SESSION[$Index] = $this->Promene[$Index];
96 if (($Index == 'view') and ((array_key_exists('keyword', $_POST)) or (array_key_exists('keyword', $_GET)))) $_SESSION[$Index] = '';
97 $$Index = $_SESSION[$Index];
98 //echo('$'.$Index.' = '.$_SESSION[$Index].'<br>');
99 }
100 //echo($keyword);
101 //if ($keyword)
102 //if ($keyword != '') $view = '';
103
104 //$this->Database->select_db('share');
105
106 // Log search
107 if (array_key_exists('keyword', $_POST) or array_key_exists('keyword', $_GET))
108 ModuleLog::Cast($this->System->GetModule('Log'))->NewRecord('Share', 'Hledaný výraz', $_SESSION['keyword']);
109
110 // Zobrazení formuláře
111 $Output = '<form action="?" method="post">
112 <input type="hidden" name="view" value="">
113 <input type="hidden" name="page" value="0">
114 Hledat: <input type="text" name="keyword" value="'.$keyword.'">';
115 $Output .= '<input type="submit" value="Hledat">&nbsp;Typ: <select name="file_type" id="file_type">';
116 $Selected = array('', '', '', '', '', '', '', '');
117 $Selected[$file_type] = 'selected ';
118 $Output .= '<option '.$Selected[0].'value="0">Vše
119 <option '.$Selected[1].'value="1">Audio(mp3,wav,ogg,mid)
120 <option '.$Selected[2].'value="2">Dokument(doc,txt,pdf)
121 <option '.$Selected[3].'value="3">Komprimovaný(zip,rar,ace,tar)
122 <option '.$Selected[4].'value="4">Video(mpeg,avi,ogm,mkv,asf)
123 <option '.$Selected[5].'value="5">Obrázek(jpg,bmp,gif,png)
124 <option '.$Selected[6].'value="6">Složka
125 <option '.$Selected[7].'value="7">Spustitelný(exe,com)
126 <option '.$Selected[7].'value="8">Obraz disku(iso,nrg,ccd,bin)
127 </select>
128 &nbsp;Velikost: <select name="size_method">';
129 $Selected = array('', '', '');
130 $Selected[$size_method] = 'selected ';
131 $Output .= '<option '.$Selected[0].'value="0">Rovno
132 <option '.$Selected[1].'value="1">Nejméně
133 <option '.$Selected[2].'value="2">Nejvíce
134 </select>
135 <input type="edit" size="5" name="size" value="'.$size.'">
136 <select name="size_units">';
137 $Selected = array('', '', '', '');
138 $Selected[$size_units] = 'selected ';
139 $Output .= '<option '.$Selected[0].'value="0">B
140 <option '.$Selected[1].'value="1">kB
141 <option '.$Selected[2].'value="2">MB
142 <option '.$Selected[3].'value="3">GB
143 </select>&nbsp;';
144
145 if ($online == 'on') $Selected = 'checked '; else $Selected = '';
146 $Output .= '<input type="checkbox" '.$Selected.'name="online">Pouze aktivní uživatele<br>
147 </form>';
148
149 //$Output .= $view;
150 if ($view != '')
151 {
152 // Zobrazení obsahu vybrané složky
153 $DbResult = $this->Database->query('SELECT * FROM NetworkShareItem WHERE id='.$view);
154 $Row = $DbResult->fetch_array();
155 $Cesta = $this->PlnaCesta($Row);
156 $Output .= '<strong>Obsah složky: '.$Cesta.$Row['name'].'</strong><br />';
157 $Podminka = '(Parent='.$view.')';
158 $Nahoru = $Row['Parent'];
159 } else
160 {
161 // Zobrazení výsledku vyhledávání
162 $Output .= '<strong>Výsledek hledání:</strong><br />';
163 $Podminka = "(Name LIKE '%".strtr($keyword, '*', '%')."%')";
164
165 // Hledání podle typů
166 $Pripony = array('',
167 "(ext LIKE 'mp3') OR (ext LIKE 'wav') OR (ext LIKE 'ogg') OR (ext LIKE 'mid')",
168 "(ext LIKE 'doc') OR (ext LIKE 'txt') OR (ext LIKE 'pdf')",
169 "(ext LIKE 'zip') OR (ext LIKE 'rar') OR (ext LIKE 'ace') OR (ext LIKE 'tar')",
170 "(ext LIKE 'mpeg') OR (ext LIKE 'mpg') OR (ext LIKE 'avi') OR (ext LIKE 'ogm') OR (ext LIKE 'mkv') OR (ext LIKE 'asf')",
171 "(ext LIKE 'jpg') OR (ext LIKE 'gif') OR (ext LIKE 'bmp') OR (ext LIKE 'ico') OR (ext LIKE 'png')",
172 "(type='2')",
173 "(ext LIKE 'exe') OR (ext LIKE 'com')",
174 "(ext LIKE 'iso') OR (ext LIKE 'nrg') OR (ext LIKE 'ccd') OR (ext LIKE 'bin') OR (ext LIKE 'mds')",
175 );
176 if ($file_type > 0) $Podminka .= ' AND ('.$Pripony[$file_type].')';
177
178 //Hledání podle velikosti
179 $Jednotky = array(1, 1024, 1048576, 1073741824);
180 if (is_numeric($size))
181 {
182 $Metoda = array('=', '>', '<');
183 $Velikost = $size * $Jednotky[$size_units];
184 $Podminka .= ' AND (Size'.$Metoda[$size_method].$Velikost.')';
185 }
186 }
187
188 // Omezení na online/offline uživatele
189 //$this->Database->select_db('is');
190 if ($online == 'on') $DbResult = $this->Database->query('SELECT Id FROM NetworkDevice WHERE Online=1 AND Member IS NOT NULL');
191 else $DbResult = $this->Database->query('SELECT Id FROM NetworkDevice');
192 $Vyber = '';
193 while ($Row = $DbResult->fetch_array()) $Vyber .= $Row['Id'].',';
194 $Podminka .= ' AND (Host IN ('.substr($Vyber, 0, -1).'))';
195 //echo($Podminka.'<br>');
196 //$this->Database->select_db('share');
197
198 //ShowTime();
199
200 // Zjištění počtu výskytů
201 //DB_Query("SELECT COUNT(*) FROM NetworkShareItem WHERE ($Podminka)");
202 //$Row = DB_Row();
203 //$Pocet = $Row[0];
204
205 // Zobrazení [..]
206 if (($view != '') && ($page == 0) && ($Nahoru > 0))
207 {
208 $DbResult = $this->Database->query('SELECT * FROM NetworkShareItem WHERE Id='.$view);
209 $Row = $DbResult->fetch_array();
210 //ShowArray($Row);
211 $Datum = explode(' ', $Row['date']);
212 $upstr = '<tr><td bgcolor="#F0F0FF"><a href="index.php?view='.$Nahoru.'">[..]</a></td><td bgcolor="#F0F0FF" width="1%"></td><td align="right" bgcolor="#F0F0FF" width="1%">'.$this->PrevedVelikost($Row['size']).'</td><td bgcolor="#F0F0FF" width="90">'.$Datum[0].'</td><td bgcolor="#F0F0FF" width="50%">'.$Cesta.'</td></tr>';
213 } else $upstr = '';
214
215 // Nacteni vysledku z databaze
216 $PerPage = 30;
217 $Dotaz = "SELECT COUNT(*) FROM NetworkShareItem WHERE (".$Podminka.")";
218 if ($order != '') $Dotaz .= ' ORDER BY '.$order;
219 $Dotaz .= " LIMIT ".($page * $PerPage).",".$PerPage;
220 $DbResult = $this->Database->query($Dotaz);
221 $Row = $DbResult->fetch_array();
222 $Pocet = $Row[0];
223
224 if ($Pocet > 0)
225 {
226 $Output .= 'Nalezeno celkem: '.$Pocet.' položek<br />';
227 } else
228 $Output .= 'Podle zadaných podmínek nic nenalezeno';
229 if (($Pocet > 0) || ($upstr))
230 {
231 $Output .= '<table width="100%" style="font-size: 8pt;" border="0" cellpadding="2" cellspacing="2">
232 <tr><th bgcolor="#E0E0FF"><a href="index.php?order=name">Soubor</a></th><th bgcolor="#E0E0FF"><a href="index.php?order=ext">Přípona</a></th><th bgcolor="#E0E0FF"><a href="index.php?order=size">Velikost</a></th><th bgcolor="#E0E0FF"><a href="index.php?order=date">Datum</a></th><th bgcolor="#E0E0FF">Umístění</th></tr>';
233 $Output .= $upstr;
234 if ($Pocet > 0)
235 {
236 // Zobrazení tabulky s výsledky
237 $Pages = floor($Pocet / $PerPage);
238 // echo($Dotaz);
239
240 // Zobrazení poloľek
241 while ($Row = $DbResult->fetch_array())
242 {
243 // Loguj('Radek '.$Row['name']);
244 $Radek = $Row;
245 $Cesta = $this->PlnaCesta($Row);
246 $Datum = explode(' ', $Radek['Date']);
247
248 // Zobrazení řádku
249 $Cesta2 = strtr($Cesta.$Radek['Name'], '\\', '/');
250 if ($Radek['Ext'] != '') $Cesta2 .= '.'.$Radek['Ext'];
251 if ($Radek['Type'] != 0) $Adresa = 'index.php?view='.$Radek['Id'].'">['.$Radek['Name'].']';
252 else
253 {
254 if (strstr($_SERVER['HTTP_USER_AGENT'], 'Linux')) $Adresa = 'smb:'.$Cesta2.'">'.$Radek['Name'];
255 else $Adresa = 'file:///'.$Cesta2.'">'.$Radek['Name'];
256 }
257 $Output .= '<tr><td bgcolor="#F0F0FF"><a href="'.$Adresa.'</a></td>'.
258 '<td bgcolor="#F0F0FF" width="1%">'.$Radek['Ext'].'</td>'.
259 '<td align="right" bgcolor="#F0F0FF" width="1%">'.$this->PrevedVelikost($Radek['Size']).'</td>'.
260 '<td bgcolor="#F0F0FF" width="90">'.$Datum[0].'</td>'.
261 '<td bgcolor="#F0F0FF" width="50%" >'.$Cesta.'</td></tr>';
262 }
263 $Output .= '</table>';
264 }
265 }
266 if ($Pocet > 0)
267 {
268 // Celkový přehled
269 if ($view == 1)
270 {
271 $DbResult = $this->Database->query('SELECT SUM(Size) FROM NetworkShareItem WHERE (Parent=1) AND (Host IN ('.substr($Vyber,0,-1).'))');
272 $Row = $DbResult->fetch_array();
273 $SizeOnline = $this->PrevedVelikost($Row[0]);
274 $DbResult = $this->Database->query('SELECT Size FROM NetworkShareItem WHERE Id=1');
275 $Row = $DbResult->fetch_array();
276 $Size = $this->PrevedVelikost($Row['size']);
277 $DbResult = $this->Database->query('SELECT COUNT(*) FROM NetworkShareItem');
278 $Row = $DbResult->fetch_array();
279 $Output .= '<br />Celková velikost online sdílených dat: '.$SizeOnline;
280 $Output .= '<br />Celkem v databázi '.$Row[0].' položek o celkové velikosti '.$Size.'<br />';
281 $Output .= '<br /><strong>Popis služby:</strong><br />
282 Tento vyhledávač slouží k prohledávání obsahu samba sdílení všech uživatelů. Je postaven na filosofii, čím více lidí bude sdílet data, tím větší bude pravděpodobnost, že najdete to co hledáte. Každý počítač je jednou za den oskenován a informace o jeho sdílení jsou zaneseny do databáze. Každou hodinu probíhá kontrola zapnutých počítačů a jejich případné oskenování. Při hledání použíjte znak * podobně jako při vyhledávání souborů na disku.<br><br>
283 <a href="firefox.php">Vyhledávání přes internetový prohlížeč Firefox</a><br />';
284 $Output .= '<a href="playlist.php">WinAMP playlist mp3 souborů online počítačů</a><br /><br />';
285
286 // Zobrazení chyb sdílení
287 $Host = gethostbyaddr(GetRemoteAddress());
288 //echo($Host);
289 $Host = strtoupper(substr($Host, 0, strpos($Host, '.')));
290 $DbResult = $this->Database->select('NetworkShareError', '*', 'Host="'.$Host.'"');
291 if ($DbResult->num_rows > 0) $Output .= '<strong>Výpis chybových hlášení pro počítač '.$Host.':</strong><br />';
292 //echo('host="'.$Host.'"');
293 while ($Row = $DbResult->fetch_array())
294 {
295 $Row['Message'] = str_replace('/', '\\', $Row['Message']);
296 $Output .= $Row['Message'].'<br />';
297 }
298 }
299
300 // Zobrazení seznamu stránek
301 if ($Pages > 1)
302 {
303 if ($page > 0) $Output .= '<a href="index.php?page=0">&lt;&lt;</a> ';
304 if ($page > 0) $Output .= '<a href="index.php?page='.($page-1).'">&lt;</a> ';
305 $PagesMax = $Pages;
306 $PagesMin = 0;
307 if ($PagesMax > ($page + 10)) $PagesMax = $page + 10;
308 if ($PagesMin < ($page - 10))
309 {
310 $Output .= ' .. ';
311 $PagesMin = $page - 10;
312 }
313 for ($i = $PagesMin; $i <= $PagesMax; $i++)
314 {
315 if ($i == $page) $Output .= '<strong>';
316 $Output .= '<a href="index.php?page='.$i.'">'.($i + 1).'</a> ';
317 if ($i == $page) $Output .= '</strong>';
318 }
319 if ($PagesMax < $Pages) $Output .= ' .. ';
320 if ($page < $Pages) $Output .= '<a href="index.php?page='.($page + 1).'">&gt;</a> ';
321 if ($page < $Pages) $Output .= '<a href="index.php?page='.$Pages.'">&gt;&gt;</a>';
322 }
323 }
324 return $Output;
325 }
326}
Note: See TracBrowser for help on using the repository browser.