• R/O
  • SSH
  • HTTPS

svardos: Commit


Commit MetaInfo

Revision345 (tree)
Time2021-09-06 18:36:13
Authormateuszviste

Log Message

implementation of checkup actions

Change Summary

Incremental Difference

--- website/repo/index.php (revision 344)
+++ website/repo/index.php (revision 345)
@@ -7,7 +7,7 @@
77 === API ===
88 ?a=pull&p=PACKAGE downloads the zip archive containing PACKAGE
99 ?a=search&p=PHRASE list packages that match PHRASE
10- ?a=checkup&p=PACKAGE&v=ver check if package available in version > v
10+ ?a=checkup list of packages+versions in $_POST
1111 */
1212
1313
@@ -18,6 +18,44 @@
1818 }
1919
2020
21+function csv_to_array($filename = '', $delimiter = "\t") {
22+ //if (! file_exists($filename) || ! is_readable($filename)) return FALSE;
23+ $handle = fopen($filename, 'r');
24+ if ($handle === false) return(false);
25+
26+ $rez = array();
27+
28+ while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE) {
29+ $rez[] = $row;
30+ }
31+ fclose($handle);
32+
33+ return $rez;
34+}
35+
36+
37+function tabulprint($ar_data, $ar_width, $margin = true) {
38+ $count = 0;
39+ foreach ($ar_data as $item) {
40+ if ($count == 0) {
41+ echo '|';
42+ if ($margin) echo ' ';
43+ }
44+ echo substr(str_pad($item, $ar_width[$count]), 0, $ar_width[$count]);
45+ if ($margin) {
46+ echo ' | ';
47+ } else {
48+ echo '|';
49+ }
50+ $count++;
51+ }
52+ echo "\r\n";
53+}
54+
55+
56+// *** MAIN START ************************************************************
57+
58+
2159 if (empty($_GET['a'])) {
2260 http_response_code(404);
2361 echo "ERROR: no action specified\r\n";
@@ -24,15 +62,18 @@
2462 exit(0);
2563 }
2664
27-if (empty($_GET['p'])) {
28- http_response_code(404);
29- echo "ERROR: no package specified\r\n";
30- exit(0);
65+$a = strtolower($_GET['a']);
66+
67+$p = '';
68+if ($a != 'checkup') {
69+ if (empty($_GET['p'])) {
70+ http_response_code(404);
71+ echo "ERROR: no package specified\r\n";
72+ exit(0);
73+ }
74+ $p = strtolower($_GET['p']);
3175 }
3276
33-$a = strtolower($_GET['a']);
34-$p = strtolower($_GET['p']);
35-
3677 $v = '';
3778 if (!empty($_GET['v'])) $v = $_GET['v'];
3879
@@ -79,12 +120,29 @@
79120 }
80121
81122 if ($a === 'checkup') {
123+ $found = 0;
124+ $remote_pkgs = csv_to_array("php://input", "\t"); // [0] = pkgname ; [1] = version
82125 while (($pkg = fgetcsv($handle, 1024, "\t")) !== FALSE) {
83- if (strcasecmp($pkg[0], $p)) {
84- echo "found package {$pkg[0]} ver {$pkg[1]} -> is it newer than '{$v}' ?\r\n";
126+ // is $pkg part of remote packages?
127+ foreach ($remote_pkgs as $rpkg) {
128+ if (strcasecmp($pkg[0], $rpkg[0]) != 0) continue;
129+ if ($pkg[1] === $rpkg[1]) continue; // skip same version
130+ if ($found == 0) {
131+ echo str_pad('', 58, '-') . "\r\n";
132+ tabulprint(array('PACKAGE', 'INSTALLED (LOCAL)', 'AVAILABLE (REMOTE)'), array(8, 20, 20));
133+ tabulprint(array('----------', '----------------------', '----------------------'), array(10, 22, 22), false);
134+ }
135+ $found++;
136+ tabulprint(array('' . $pkg[0], $rpkg[1], $pkg[1]), array(8, 20, 20));
85137 break;
86138 }
87139 }
140+ if ($found == 0) {
141+ echo "no available updates\r\n";
142+ } else {
143+ echo str_pad('', 58, '-') . "\r\n";
144+ echo "found {$found} differing packages\r\n";
145+ }
88146 }
89147 fclose($handle);
90148
Show on old repository browser