FIXME: appel curl ou fopen d'une methode http depuis une action ou un controlleur.
TODO: sécuriser les accès HTTP1.1 par un fichier config similaire a l'applet Discourse faite pour Tinternet
TODO: ajouter un plug-in symfony permettant de charger un utilisateur dans les apps a partir de l'authentification multiple
TODO: lire les documentation officielles provenant des 4 plate-formes tranquillement afin de comprendre commet doit on tester ces type d'auth quitte a créé un sous domaine particulier directement hebergé sur gittea
-->Sécuriser le serveur de dev
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,93 @@ |
1 |
+<?php |
|
2 |
+ |
|
3 |
+ |
|
4 |
+namespace MVC\Classe; |
|
5 |
+ |
|
6 |
+ |
|
7 |
+class Browser |
|
8 |
+{ |
|
9 |
+ |
|
10 |
+ public $user; |
|
11 |
+ public $userAgent; |
|
12 |
+ |
|
13 |
+ public function __construct() |
|
14 |
+ { |
|
15 |
+ |
|
16 |
+ $this->userAgent = $_SERVER['HTTP_USER_AGENT']; |
|
17 |
+ $this->user = $this->get_browser_name(); |
|
18 |
+ } |
|
19 |
+ |
|
20 |
+ protected function get_browser_name() |
|
21 |
+ { |
|
22 |
+ |
|
23 |
+ // Make case insensitive. |
|
24 |
+ $t = strtolower($this->userAgent); |
|
25 |
+ |
|
26 |
+ // If the string *starts* with the string, strpos returns 0 (i.e., FALSE). Do a ghetto hack and start with a space. |
|
27 |
+ // "[strpos()] may return Boolean FALSE, but may also return a non-Boolean value which evaluates to FALSE." |
|
28 |
+ // http://php.net/manual/en/function.strpos.php |
|
29 |
+ $t = " " . $t; |
|
30 |
+ |
|
31 |
+ // Humans / Regular Users |
|
32 |
+ if (strpos($t, 'opera') || strpos($t, 'opr/')) return 'Opera'; |
|
33 |
+ elseif (strpos($t, 'edge')) return 'Edge'; |
|
34 |
+ elseif (strpos($t, 'chrome')) return 'Chrome'; |
|
35 |
+ elseif (strpos($t, 'safari')) return 'Safari'; |
|
36 |
+ elseif (strpos($t, 'firefox')) return 'Firefox'; |
|
37 |
+ elseif (strpos($t, 'msie') || strpos($t, 'trident/7')) return 'Internet Explorer'; |
|
38 |
+ |
|
39 |
+ // Application Users |
|
40 |
+ elseif (strpos($t, 'curl')) return '[App] Curl'; |
|
41 |
+ |
|
42 |
+ // Search Engines |
|
43 |
+ elseif (strpos($t, 'google')) return '[Bot] Googlebot'; |
|
44 |
+ elseif (strpos($t, 'bing')) return '[Bot] Bingbot'; |
|
45 |
+ elseif (strpos($t, 'slurp')) return '[Bot] Yahoo! Slurp'; |
|
46 |
+ elseif (strpos($t, 'duckduckgo')) return '[Bot] DuckDuckBot'; |
|
47 |
+ elseif (strpos($t, 'baidu')) return '[Bot] Baidu'; |
|
48 |
+ elseif (strpos($t, 'yandex')) return '[Bot] Yandex'; |
|
49 |
+ elseif (strpos($t, 'sogou')) return '[Bot] Sogou'; |
|
50 |
+ elseif (strpos($t, 'exabot')) return '[Bot] Exabot'; |
|
51 |
+ elseif (strpos($t, 'msn')) return '[Bot] MSN'; |
|
52 |
+ |
|
53 |
+ // Common Tools and Bots |
|
54 |
+ elseif (strpos($t, 'mj12bot')) return '[Bot] Majestic'; |
|
55 |
+ elseif (strpos($t, 'ahrefs')) return '[Bot] Ahrefs'; |
|
56 |
+ elseif (strpos($t, 'semrush')) return '[Bot] SEMRush'; |
|
57 |
+ elseif (strpos($t, 'rogerbot') || strpos($t, 'dotbot')) return '[Bot] Moz or OpenSiteExplorer'; |
|
58 |
+ elseif (strpos($t, 'frog') || strpos($t, 'screaming')) return '[Bot] Screaming Frog'; |
|
59 |
+ |
|
60 |
+ // Miscellaneous |
|
61 |
+ elseif (strpos($t, 'facebook')) return '[Bot] Facebook'; |
|
62 |
+ elseif (strpos($t, 'pinterest')) return '[Bot] Pinterest'; |
|
63 |
+ |
|
64 |
+ // Check for strings commonly used in bot user agents |
|
65 |
+ elseif (strpos($t, 'crawler') || strpos($t, 'api') || |
|
66 |
+ strpos($t, 'spider') || strpos($t, 'http') || |
|
67 |
+ strpos($t, 'bot') || strpos($t, 'archive') || |
|
68 |
+ strpos($t, 'info') || strpos($t, 'data')) return '[Bot] Other'; |
|
69 |
+ |
|
70 |
+ return 'Other (Unknown)'; |
|
71 |
+ } |
|
72 |
+ |
|
73 |
+ public function isBot() |
|
74 |
+ { |
|
75 |
+ if (preg_match('#Bot#', $this->user)) { |
|
76 |
+ return true; |
|
77 |
+ } else { |
|
78 |
+ return false; |
|
79 |
+ } |
|
80 |
+ } |
|
81 |
+ |
|
82 |
+ // Alternative TO https://www.php.net/manual/fr/function.get-browser.php |
|
83 |
+ // Function written and tested December, 2018 |
|
84 |
+ |
|
85 |
+ public function isAppRequest() |
|
86 |
+ { |
|
87 |
+ if (preg_match('#App#', $this->user)) { |
|
88 |
+ return true; |
|
89 |
+ } else { |
|
90 |
+ return false; |
|
91 |
+ } |
|
92 |
+ } |
|
93 |
+} |
|
0 | 94 |
\ No newline at end of file |