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

Revision 190, 6.2 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
2require_once('common/includes/class.page.php');
3require_once('common/includes/class.contract.php');
4require_once('common/includes/class.http.php');
5
6$page = new Page();
7$page->setAdmin();
8$page->setTitle('Administration - Synchronization');
9
10if ($_REQUEST['do'] == 'sync')
11{
12    $http = new http_request(KB_SYNCURL);
13    $fp = $http->connect();
14    if (!$fp)
15    {
16        $html .= 'Could not connect to Server:<br/>'."\n";
17        $html .= $http->getError();
18
19        $page->addContext($menubox->generate());
20        $page->setContent($html);
21        $page->generate();
22        return;
23    }
24
25    $content_file = 'DATA_START';
26    $qry = new DBQuery();
27    $qry->execute("select plt_name, plt_externalid from kb3_pilots where plt_externalid != 0");
28    while ($data = $qry->getRow())
29    {
30        $content_file .= '!'.$data['plt_name'].'|'.$data['plt_externalid'].'-';
31    }
32
33    $content_file .= 'ITEMS_START';
34    $qry->execute("select itm_name, itm_externalid, itm_value from kb3_items where itm_value != 0");
35    while ($data = $qry->getRow())
36    {
37        $content_file .= '§'.$data['itm_name'].'|'.$data['itm_externalid'].'|'.$data['itm_value'].'-';
38    }
39
40    $content_file = gzdeflate($content_file);
41
42    $http->set_postdata('data', $content_file);
43    $http->set_useragent("EVE-KB SYNC (VER ".KB_VERSION.")");
44    $http->set_header('X-KBHost: '.base64_encode(KB_HOST));
45
46    // wait 90s for processed answer
47    $http->setSockettimeout(90);
48    $file = $http->get_content();
49    $header = $http->get_header();
50
51    preg_match("/X-KBVersion: (.*)/", $header, $match);
52    $version = explode('.', trim($match[1]));
53    $recv = $http->get_recv();
54    $sended = $http->get_sent();
55
56    // the response ($file) contains ids new to us
57    $data = @gzinflate($file);
58    if ($data == false)
59    {
60        if ($http->status['timed_out'] == 1)
61        {
62            $html .= "Socket request timed out<br/>\n";
63            $html .= 'This could mean that the server is not available or overloaded, please try again later<br/>';
64        }
65        else
66        {
67            $html .= "getting compressed data failed, server response was:<br><pre>\n";
68            $html .= $file."</pre>\n";
69            $html .= "Sent ".round($sended/1024, 2)." kB and received ".round($recv/1024, 2)." kB of data.<br>\n";
70        }
71    }
72    else
73    {
74        unset($file);
75
76        // get all names we'll find
77        preg_match_all("^!(.*?)\|(.*?)-^", $data, $matches);
78        $results = count($matches[1]);
79        $update = new DBQuery();
80        for ($i = 0; $i<$results; $i++)
81        {
82            $update->execute("update kb3_pilots set plt_externalid='".addslashes($matches[2][$i])."' where plt_name='".addslashes($matches[1][$i])."' limit 1");
83        }
84        $html .= "Synchronization complete, got $results new ids from server running version ".$version[0].'.'.$version[1].'.'.$version[2].'.<br/>';
85
86        if (isset($_REQUEST['itm_update']))
87        {
88            preg_match_all('^§(.*?)\|(.*?)\|(.*?)-^', $data, $matches);
89            unset($data);
90            $results = count($matches[1]);
91            if (isset($_REQUEST['itm_overwrite']))
92            {
93                $add_qrystr = '';
94            }
95            else
96            {
97                $add_qrystr = ' AND itm_value=0';
98            }
99
100            for ($i = 0; $i<$results; $i++)
101            {
102                $update->execute("update kb3_items set itm_externalid='".addslashes($matches[2][$i])."', itm_value='".addslashes($matches[3][$i])."' where itm_name='".addslashes($matches[1][$i])."'".$add_qrystr." limit 1");
103            }
104            if ($results == 0)
105            {
106                $html .= 'No items fetched, itm_sync_module may be offline.<br/>';
107            }
108            else
109            {
110                $html .= $results.' item prices have been fetched.<br/>';
111            }
112        }
113
114        $html .= "Sent ".round($sended/1024, 2)." kB and received ".round($recv/1024, 2)." kB of data.<br>\n";
115        $html .= '<a href="?a=admin_sync">Back</a>';
116
117        // check for updates here
118        // we might move this to a new/second point some time
119        $ownversion = explode('.', KB_VERSION);
120        if ($version[1] > $ownversion[1] && $version[1] % 2 == 1)
121        {
122            // test for new minor updates below the dev-version
123            if ($version[1]-1 > $ownversion[1])
124            {
125                $upgrade = true;
126            }
127        }
128        elseif ($version[1] > $ownversion[1] && $version[1] % 2 == 0)
129        {
130            // we get here in case there is a new minor version thats not a dev
131            $upgrade = true;
132        }
133        if ($version[0] > $ownversion[0] || $upgrade)
134        {
135            $html .= "Looks like your Killboard version is pretty old, perhaps you want to upgrade it ?<br/>\n";
136            $html .= "Check the <a href='http://www.eve-dev.net/forums/viewforum.php?f=2'>EVE-Dev Forums</a> for new releases and additional information<br>\n";
137        }
138    }
139}
140else
141{
142    $html .= 'You can synchronize your external characterids for the portrait generation with the EVE-Dev.org-Server here.<br>';
143    $html .= 'Your Server will try to contact <i>"'.KB_SYNCURL.'"</i> to exchange the data.<br>';
144    $html .= 'One synchronization every one or two weeks should be enough.<br>';
145    $html .= 'Please don\'t abuse this free service!<br>';
146    $html .= '<form id="options" name="options" method="post" action="?a=admin_sync">';
147    $html .= "<table class=kb-subtable>";
148    $html .= "<tr><td width=120><b>Update item values</b></td><td><input type=checkbox name=itm_update id=itm_update";
149    $html .= " checked=\"checked\"></td></tr>";
150    $html .= "<tr><td width=120><b>Overwrite local values</b></td><td><input type=checkbox name=itm_overwrite id=itm_overwrite";
151    $html .= " checked=\"checked\">(If disabled only values with 0 will be overwritten)</td></tr>";
152    $html .= '<input type="hidden" name="do" value="sync">';
153    $html .= '<tr><td width=120></td><td><input type=submit name=submit value="Synchronize now"></td></tr></table></form>';
154}
155$page->addContext($menubox->generate());
156$page->setContent($html);
157$page->generate();
158?>
Note: See TracBrowser for help on using the browser.