root/dev/common/admin/admin_kill_import.php @ 190

Revision 190, 6.8 KB (checked in by exi, 15 years ago)

This is a big update...
Moved all admin scripts to common/admin.
Moved all includes and classes to common/includes.
Edited all include-paths to reflect the movement.
Fixed a bug with the session system allowing every registered user to access admin pages.
Replaced calls to date() to use a wrapper so gmdate can be used.
Replaced some calls to $config with calls to the static object.
Fixed a big which caused the portrait_grab to not download a new picute.
Added a classified-state to kills.
Removed the sync_server server script in this tree.
Added code to help modules find the includes to index.php.

Line 
1<?php
2@set_time_limit(0);
3require_once('common/includes/class.parser.php');
4require_once('common/includes/class.kill.php');
5
6$page = new Page();
7$page->setAdmin();
8$page->setTitle('Administration - Killmail Importer');
9
10if (!$_POST['dir'])
11{
12    $dir = getcwd();
13}
14if (!$_POST['ext'])
15{
16    $ext = '.txt';
17}
18else
19{
20    $ext = $_POST['ext'];
21}
22if ($_REQUEST['submit'] == 'Reset')
23{
24    unset($_SESSION['kill_import']);
25    unset($_POST);
26}
27
28$html .= "<form id=\"options\" name=\"options\" method=\"post\" action=\"?a=admin_kill_import\">";
29
30if ($_POST)
31{
32    $dir = $_POST['dir'];
33    if (!$dir && $_SESSION['kill_import'])
34    {
35        $dir = $_SESSION['kill_import']['dir'];
36        $ext = $_SESSION['kill_import']['ext'];
37    }
38    if (!strstr($dir, getcwd()))
39    {
40        $dir = getcwd().$dir;
41    }
42
43    if (substr($dir, -1, 1) != '/')
44    {
45        $dir .= '/';
46    }
47    if (is_dir($dir))
48    {
49        $dirh = opendir($dir);
50        $i = 0;
51        while ($file = readdir($dirh))
52        {
53            if (strstr($file, $ext))
54            {
55                $i++;
56            }
57        }
58        if (!$num)
59        {
60            $num = 200;
61        }
62        if ($_POST['submit'] != 'Import')
63        {
64            $html .= "<div class=block-header2>Import Options</div>";
65            $html .= "<table class=kb-subtable>";
66            $html .= "<tr><td width=120></td><td>'$dir' contains $i files matching '$ext'</td></tr>";
67            $html .= "<tr><td width=120><b>Read # mails at once:</b></td><td><input type=text name=num id=num size=3 maxlength=10 value=\"".$num."\"></td></tr>";
68            $html .= "<tr><td width=120><b>Start with mail #:</b></td><td><input type=text name=startnum id=startnum size=3 maxlength=10 value=\"0\"></td></tr>";
69            $html .= "<tr><td width=120></td><td><input type=submit name=submit value=\"Import\">&nbsp;<input type=submit name=submit value=\"Reset\"></td></tr>";
70            $html .= "</table>";
71            $_SESSION['kill_import'] = array();
72            $_SESSION['kill_import']['dir'] = $dir;
73            $_SESSION['kill_import']['count'] = $i;
74            $_SESSION['kill_import']['ext'] = $ext;
75        }
76        else
77        {
78            $_SESSION['kill_import']['do'] = 1;
79            $_SESSION['kill_import']['num'] = $_POST['num'];
80            $_SESSION['kill_import']['startnum'] = $_POST['startnum'];
81        }
82    }
83    else
84    {
85        $html .= "'$dir' is not a valid directory<br>\n";
86    }
87}
88elseif (!isset($_SESSION['kill_import']['do']))
89{
90    $html .= "<div class=block-header2>Scan for Killmails</div>";
91    $html .= "<table class=kb-subtable>";
92    $html .= "<tr><td width=120><b>Directory:</b></td><td><input type=text name=dir id=dir size=60 maxlength=80 value=\"".$dir."\"></td></tr>";
93    $html .= "<tr><td width=120><b>Extension:</b></td><td><input type=text name=ext id=ext size=3 maxlength=10 value=\"".$ext."\"></td></tr>";
94    $html .= "<tr><td width=120><b>Attention:</b></td><td>For security reasons only directorys below the main EVE-KB-directory will be read.</td></tr>";
95    $html .= "<tr><td width=120></td><td><input type=submit name=submit value=\"Check\"></td></tr>";
96    $html .= "</table>";
97}
98$html .= "</form>";
99
100if (isset($_SESSION['kill_import']['do']))
101{
102    $i = 0;
103    $p = 0;
104    $p_all = 0;
105    $posted = 0;
106    $posted_all = 0;
107    $invalid = 0;
108    $inv = 0;
109    $num = 0;
110
111    $dirh = opendir($_SESSION['kill_import']['dir']);
112    while ($file = readdir($dirh))
113    {
114        if (strstr($file, $_SESSION['kill_import']['ext']))
115        {
116            $i++;
117            if ($i <= $_SESSION['kill_import']['startnum'])
118            {
119                continue;
120            }
121            if ($i <= $_SESSION['kill_import']['numcount'])
122            {
123                continue;
124            }
125            $num++;
126            $read++;
127            $mail = file_get_contents($_SESSION['kill_import']['dir'].$file);
128            $mail = stripslashes($mail);
129            $parser = new Parser($mail);
130
131            $killid = $parser->parse(false);
132            if ($killid == 0)
133            {
134                $inv++;
135                $invalid++;
136                $html .= "Killmail is malformed: $file.<br>\n";
137                //unlink($dir.$file);
138            }
139            elseif ($killid == -1)
140            {
141                $posted++;
142                $posted_all++;
143                #echo "That $file killmail has already been posted <a href=\"?a=kill_detail&kll_id=" . $parser->dupeid_ . "\">here</a>.<br>\n";
144            }
145            else
146            {
147                $p++;
148                $p_all++;
149            }
150
151            if ($i % 10 == 0)
152            {
153                $html .= "$i/".$_SESSION['kill_import']['count']." - $num files read, $p new, $posted old, $inv invalid<br>\n";
154                $inv = 0;
155                $p = 0;
156                $posted = 0;
157            }
158            if ($i >= $_SESSION['kill_import']['count'])
159            {
160                $html .= "$i/".$_SESSION['kill_import']['count']." - $num files read, $p new, $posted old, $inv invalid<br>\n";
161                $_SESSION['kill_import']['numcount'] = $i;
162//                $_SESSION['kill_import']['postall'] = $posted_all;
163//                $_SESSION['kill_import']['p_all'] = $p_all;
164                break;
165            }
166            if ($num >= $_SESSION['kill_import']['num'])
167            {
168                $html .= "$i/".$_SESSION['kill_import']['count']." - $num files read, $p new, $posted old, $inv invalid<br>\n";
169                $_SESSION['kill_import']['numcount'] = $i;
170                break;
171            }
172        }
173    }
174
175    if ($_SESSION['kill_import']['count'] - $_SESSION['kill_import']['numcount'] > 0)
176    {
177        $html .= '<meta http-equiv="refresh" content="5; URL=?a=kill_import" />';
178        $html .= 'Automatic refresh in 5s<br/>';
179        $html .= '<a href="?a=kill_import">Read next '.$_SESSION['kill_import']['num'].'</a>&nbsp;<a href="?a=kill_import&submit=Reset">Reset</a>';
180        $_SESSION['kill_import']['read'] += $read;
181        $_SESSION['kill_import']['p_all'] += $p_all;
182        $_SESSION['kill_import']['posted_all'] += $posted_all;
183        $_SESSION['kill_import']['invalid'] += $invalid;
184    }
185    else
186    {
187        $html .= 'Import complete, '.$_SESSION['kill_import']['read'].' files read, '
188                 .$_SESSION['kill_import']['p_all'].' kills added, '
189                 .$_SESSION['kill_import']['posted_all'].' already posted, '
190                 .$_SESSION['kill_import']['invalid'].' malformed<br>';
191        $html .= '<a href="?a=kill_import">Ok</a>';
192        unset($_SESSION['kill_import']);
193    }
194}
195$page->addContext($menubox->generate());
196$page->setContent($html);
197$page->generate();
198?>
Note: See TracBrowser for help on using the browser.