List of commits:
Subject Hash Author Date (UTC)
keys: add some caching and prevent updating first_use if not necessary 35a152bc27fb1791f3f9d8ad1287c3847ed334a1 Catalin(ux) M. BOIE 2015-12-05 17:21:19
Deal correctly with cache regarding last_bug_id 705351cdea6af55f9dd61de0d85d41b8ac33fc88 Catalin(ux) M. BOIE 2015-12-03 21:01:08
Settle to Affero GPLv3+ 679d4032059256a01610e65cbff5496d32d9fc7d Catalin(ux) M. BOIE 2015-12-03 19:40:12
Missing Affero dee2c08fc8a0371ac37f6f00bf7f3e2e01f92e92 Catalin(ux) M. BOIE 2015-12-03 19:36:10
DO not show 2fa hint for a visiting user 4ff8837ef0f45572592f1d81724737b3732a046a Catalin(ux) M. BOIE 2015-12-03 17:25:24
Let the user choose the e-mail, no defaults should be suggested 09450741613a407c09bb465bff8a3c19c565df9a Catalin(ux) M. BOIE 2015-12-02 18:12:08
Pass uid for all events; more fixes for unit tests 866e43baf739ae7072949559d1c7e089c086af76 Catalin(ux) M. BOIE 2015-11-19 19:28:26
404 http error was receive for showing blobs ending in .php or .html ff87d956360a86e88a751d4c391585c84bb1e132 Catalin(ux) M. BOIE 2015-11-18 20:32:50
When creating an array, last_bug_id is set now correctly f679840c7ac3879aae69f488c561a5bd73ce71f1 Catalin(ux) M. BOIE 2015-11-18 19:14:48
We allow empty description for bugs c5a1b4057963eac575cc3d0d4872c4519fea80b0 Catalin(ux) M. BOIE 2015-11-18 18:26:39
Show the repo # on main repo page c72f4d8627ab577a92c5531ed7afb9e55a6bfd1b Catalin(ux) M. BOIE 2015-11-18 18:25:00
Bumped version to 0.42 8e9fab68ff08040402c0aa25539d1e8b29258f7d Catalin(ux) M. BOIE 2015-11-18 18:14:40
Renamed the virtual machines files 040c9f3a87826a52713b3b5f48d19c83236f8aa8 Catalin(ux) M. BOIE 2015-11-18 18:13:57
Admin user must not confirm the account by e-mail 0a81a2824087d9dcd2d1981c860946fd49cc8bf7 Catalin(ux) M. BOIE 2015-11-18 18:04:26
Bump the version to 0.41 363368555480d4c79c13867805c59541fd59e37c Catalin(ux) M. BOIE 2015-11-18 16:37:16
Mostly debug signaling by cache 2cd13a1f01403ebe733ef64ff2446b93e2cd46af Catalin(ux) M. BOIE 2015-11-18 16:36:40
Only texts changes. 37b6e035a5027c99a8b21672cef5431673320892 Catalin(ux) M. BOIE 2015-11-17 17:58:52
webhooks fixes 422d74f1cd4133e73ceb3edbb7a7da6d48c102f2 Catalin(ux) M. BOIE 2015-11-17 15:53:10
Checkpoint: ip/user fixes for remote connections, some pull request fixes and unit test start c8ac332f2ffda6149048dd17eaef8ff2f2920650 Catalin(ux) M. BOIE 2015-11-07 05:30:04
Added webhooks c2b73a8e494c4c61ce2d3f0d4101f0836a5a0df6 Catalin(ux) M. BOIE 2015-10-29 03:55:44
Commit 35a152bc27fb1791f3f9d8ad1287c3847ed334a1 - keys: add some caching and prevent updating first_use if not necessary
Author: Catalin(ux) M. BOIE
Author date (UTC): 2015-12-05 17:21
Committer name: Catalin(ux) M. BOIE
Committer date (UTC): 2015-12-05 17:21
Parent(s): 705351cdea6af55f9dd61de0d85d41b8ac33fc88
Signer:
Signing key:
Signing status: N
Tree: 138071dfa22d39b8048d9203b5e11a3d16a629da
File Lines added Lines deleted
inc/keys.inc.php 88 28
inc/struct.inc.php 7 0
root/themes/default/user/keys/list/header.html 1 0
root/themes/default/user/keys/list/line.html 1 0
scripts/remote.php 1 1
techdocs/cache.txt 0 0
File inc/keys.inc.php changed (mode: 100644) (index c146b8b..5fa6c69)
... ... require_once($INC . "/state.inc.php");
4 4 require_once($INC . "/prof.inc.php"); require_once($INC . "/prof.inc.php");
5 5 require_once($INC . "/mail.inc.php"); require_once($INC . "/mail.inc.php");
6 6 require_once($INC . "/events.inc.php"); require_once($INC . "/events.inc.php");
7 require_once($INC . "/cache.inc.php");
7 8
8 9 $rg_keys_error = ""; $rg_keys_error = "";
9 10
 
... ... function rg_keys_event_new($db, $event)
39 40 $ret = array(); $ret = array();
40 41
41 42 $event['op'] = "new"; $event['op'] = "new";
43
42 44 // mark keys dirty // mark keys dirty
43 45 $ret[] = array_merge($event, array("category" => 1002, "prio" => 10)); $ret[] = array_merge($event, array("category" => 1002, "prio" => 10));
46
44 47 // notify user // notify user
45 48 $ret[] = array_merge($event, array("category" => 1003, "prio" => 100)); $ret[] = array_merge($event, array("category" => 1003, "prio" => 100));
46 49
 
... ... function rg_keys_event_del($db, $event)
55 58 $ret = array(); $ret = array();
56 59 $event['type'] = 1; $event['type'] = 1;
57 60 $event['op'] = "del"; $event['op'] = "del";
61
58 62 // mark keys dirty // mark keys dirty
59 63 $ret[] = array_merge($event, array("category" => 1002, "prio" => 10)); $ret[] = array_merge($event, array("category" => 1002, "prio" => 10));
64
60 65 // notify user // notify user
61 66 $ret[] = array_merge($event, array("category" => 1003, "prio" => 100)); $ret[] = array_merge($event, array("category" => 1003, "prio" => 100));
67
62 68 return $ret; return $ret;
63 69 } }
64 70
 
... ... function rg_keys_event_del($db, $event)
67 73 * We ignore requests that were inserted in queue after we already * We ignore requests that were inserted in queue after we already
68 74 * regenerated the keys. * regenerated the keys.
69 75 * We must regenerate now to not let the user wait too much. * We must regenerate now to not let the user wait too much.
70 * TODO: When we will have support in sshd for key lookup, we will not need to regenerate.
76 * TODO: When we will have support in sshd for key lookup, we will not need
77 * to regenerate.
71 78 */ */
72 79 function rg_keys_event_regen($db, $event) function rg_keys_event_regen($db, $event)
73 80 { {
 
... ... function rg_keys_remove($db, $ui, $list)
308 315 . " (" . rg_event_error() . ")"); . " (" . rg_event_error() . ")");
309 316 break; break;
310 317 } }
311 rg_event_signal_daemon('', 0);
312 318
319 $key = 'user' . '::' . $ui['uid'] . '::' . 'keys';
320 foreach ($my_list as $_key_id)
321 rg_cache_unset($key . '::' . $_key_id,
322 RG_SOCKET_NO_WAIT);
323
324 rg_event_signal_daemon('', 0);
313 325 $ret = TRUE; $ret = TRUE;
314 326 break; break;
315 327 } }
 
... ... function rg_keys_add($db, $ui, $key)
389 401 } }
390 402 $do_rollback = 1; $do_rollback = 1;
391 403
392 $params = array("itime" => $itime,
393 "uid" => $ui['uid'],
394 "key" => $key);
404 $params = array(
405 'itime' => $itime,
406 'uid' => $ui['uid'],
407 'key' => $key,
408 'count' => 0,
409 'first_use' => 0);
395 410 $sql = "INSERT INTO keys (itime, uid, key)" $sql = "INSERT INTO keys (itime, uid, key)"
396 411 . " VALUES (@@itime@@, @@uid@@, @@key@@)" . " VALUES (@@itime@@, @@uid@@, @@key@@)"
397 412 . " RETURNING key_id"; . " RETURNING key_id";
 
... ... function rg_keys_add($db, $ui, $key)
427 442 } }
428 443 $do_rollback = 0; $do_rollback = 0;
429 444
445 $_key = 'user' . '::' . $ui['uid'] . '::'
446 . 'keys' . '::' . $key_id;
447 rg_cache_merge($_key, $params, RG_SOCKET_NO_WAIT);
448
430 449 rg_event_signal_daemon('', 0); rg_event_signal_daemon('', 0);
431 450
432 451 $ret = $key_id; $ret = $key_id;
 
... ... function rg_keys_add($db, $ui, $key)
444 463 /* /*
445 464 * Update first_use, last_use, last_ip and count * Update first_use, last_use, last_ip and count
446 465 */ */
447 function rg_keys_update_use($db, $key_id, $ip)
466 function rg_keys_update_use($db, $uid, $key_id, $ip, $cmd)
448 467 { {
449 468 rg_prof_start("keys_update_use"); rg_prof_start("keys_update_use");
450 rg_log_enter("keys_update_use: key_id=$key_id, ip=$ip");
469 rg_log_enter("keys_update_use: uid=$uid key_id=$key_id"
470 . ", ip=$ip, cmd=$cmd");
451 471
452 472 $ret = FALSE; $ret = FALSE;
453 473 while (1) { while (1) {
454 474 $now = time(); $now = time();
455 475
456 $params = array("now" => $now,
457 "key_id" => $key_id,
458 "ip" => $ip);
459 $sql = "UPDATE keys SET first_use = @@now@@"
460 . " WHERE first_use = 0"
461 . " AND key_id = @@key_id@@";
462 $res = rg_sql_query_params($db, $sql, $params);
463 if ($res === FALSE) {
464 rg_keys_set_error("cannot update key's first use"
465 . " (" . rg_sql_error() . ")");
466 break;
476 $update_first_use = TRUE;
477 $update_last_use = TRUE;
478
479 $key = 'user' . '::' . $uid . '::' . 'keys' . '::' . $key_id;
480 $c = rg_cache_get($key);
481 if ($c !== FALSE) {
482 if (isset($c['first_use']) && ($c['first_use'] > 0))
483 $update_first_use = FALSE;
484
485 // We will not update the field if is too soon
486 if (isset($c['last_use'])
487 && (strcmp($ip, $c['last_ip']) == 0)
488 && (strcmp($cmd, $c['last_cmd']) == 0)
489 && ($now - $c['last_use'] < 60))
490 $update_last_use = FALSE;
467 491 } }
468 492
469 $sql = "UPDATE keys SET last_use = @@now@@"
470 . ", last_ip = @@ip@@"
471 . ", count = count + 1"
472 . " WHERE key_id = @@key_id@@";
473 $res = rg_sql_query_params($db, $sql, $params);
474 if ($res === FALSE) {
475 rg_keys_set_error("cannot update key"
476 . " (" . rg_sql_error() . ")");
477 break;
493 $params = array(
494 'now' => $now,
495 'key_id' => $key_id,
496 'ip' => $ip,
497 'last_cmd' => $cmd);
498
499 if ($update_first_use) {
500 $sql = "UPDATE keys SET first_use = @@now@@"
501 . " WHERE first_use = 0"
502 . " AND key_id = @@key_id@@";
503 $res = rg_sql_query_params($db, $sql, $params);
504 if ($res === FALSE) {
505 rg_keys_set_error("cannot update key's first use");
506 break;
507 }
508 rg_sql_free_result($res);
509
510 rg_cache_set($key . '::' . 'first_use', $now,
511 RG_SOCKET_NO_WAIT);
478 512 } }
479 rg_sql_free_result($res);
513
514 if ($update_last_use) {
515 $sql = "UPDATE keys SET last_use = @@now@@"
516 . ", last_ip = @@ip@@"
517 . ", last_cmd = @@last_cmd@@"
518 . ", count = count + 1"
519 . " WHERE key_id = @@key_id@@";
520 $res = rg_sql_query_params($db, $sql, $params);
521 if ($res === FALSE) {
522 rg_keys_set_error("cannot update key"
523 . " (" . rg_sql_error() . ")");
524 break;
525 }
526 rg_sql_free_result($res);
527
528 $a = array(
529 'last_use' => $now,
530 'last_ip' => $ip,
531 'last_cmd' => $cmd);
532 rg_cache_merge($key, $a, RG_SOCKET_NO_WAIT);
533 }
534
480 535 $ret = TRUE; $ret = TRUE;
481 536 break; break;
482 537 } }
 
... ... function rg_keys_list($db, $ui)
621 676 else else
622 677 $t['last_use'] = gmdate("Y-m-d H:i", $row['last_use']); $t['last_use'] = gmdate("Y-m-d H:i", $row['last_use']);
623 678
679 if (empty($t['last_cmd']))
680 $t['last_cmd'] = "N/A";
681 else
682 $t['last_cmd'] = $row['last_cmd'];
683
624 684 $t['count'] = $row['count']; $t['count'] = $row['count'];
625 685
626 686 $ret[] = $t; $ret[] = $t;
File inc/struct.inc.php changed (mode: 100644) (index 6b201cd..f567bb2)
... ... $rg_sql_struct[35]['other'] = array(
482 482 "ALTER TABLE webhooks ADD opaque TEXT NOT NULL DEFAULT ''" "ALTER TABLE webhooks ADD opaque TEXT NOT NULL DEFAULT ''"
483 483 ); );
484 484
485 $rg_sql_struct[36]['tables'] = array();
486 $rg_sql_struct[36]['other'] = array(
487 'users drop double unique constriaint' =>
488 "ALTER TABLE users DROP CONSTRAINT users_username_key",
489 'last_cmd' => "ALTER TABLE keys ADD last_cmd TEXT NOT NULL DEFAULT ''"
490 );
491
485 492 // This must be the last line // This must be the last line
486 493 $rg_sql_schema_ver = count($rg_sql_struct); $rg_sql_schema_ver = count($rg_sql_struct);
487 494
File root/themes/default/user/keys/list/header.html changed (mode: 100644) (index 4287641..094d54e)
15 15 <th>First use (UTC)</th> <th>First use (UTC)</th>
16 16 <th>Last use (UTC)</th> <th>Last use (UTC)</th>
17 17 <th>Last IP</th> <th>Last IP</th>
18 <th>Last command</th>
18 19 <th>Count</th> <th>Count</th>
19 20 </tr> </tr>
20 21
File root/themes/default/user/keys/list/line.html changed (mode: 100644) (index 1cd93b8..102f5cd)
6 6 <td>@@first_use@@</td> <td>@@first_use@@</td>
7 7 <td>@@last_use@@</td> <td>@@last_use@@</td>
8 8 <td>@@last_ip@@</td> <td>@@last_ip@@</td>
9 <td><small>@@last_cmd@@</small></td>
9 10 <td>@@count@@</td> <td>@@count@@</td>
10 11 </tr> </tr>
11 12
File scripts/remote.php changed (mode: 100644) (index 7820736..f86204f)
... ... if (isset($_SERVER['SSH_CONNECTION'])) {
110 110 // We do this operation after dispatch to not impact the latency. // We do this operation after dispatch to not impact the latency.
111 111 // TODO: This should be put in a queue for performance reasons // TODO: This should be put in a queue for performance reasons
112 112 // At the same time, update stats? events? // At the same time, update stats? events?
113 $_r = rg_keys_update_use($db, $key_id, $ip);
113 $_r = rg_keys_update_use($db, $conn_ui['uid'], $key_id, $ip, $cmd_repo);
114 114 if ($_r !== TRUE) if ($_r !== TRUE)
115 115 rg_internal_error("Cannot update key last_use!"); rg_internal_error("Cannot update key last_use!");
116 116
File techdocs/cache.txt copied from file root/themes/default/errmsg/nodata.html (similarity 100%)
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/catalinux/rocketgit

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/catalinux/rocketgit

Clone this repository using git:
git clone git://git.rocketgit.com/user/catalinux/rocketgit

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main