xaizek / rocketgit (License: AGPLv3+) (since 2018-12-09)
Light and fast Git hosting solution suitable to serve both as a hub or as a personal code storage with its tickets, pull requests, API and much more.
Commit f50c94843c00656a453979591585c3d9d073469c

Update last_seen only at login/logout, not on every access
Author: Catalin(ux) M. BOIE
Author date (UTC): 2015-03-20 04:42
Committer name: Catalin(ux) M. BOIE
Committer date (UTC): 2015-03-20 04:42
Parent(s): 4c9eaa994fa1e2370812e49fe85742f00f51ee7b
Signing key:
Tree: 5c760a67ef9eede3b8ca6a02606a81bbf432722f
File Lines added Lines deleted
TODO 3 5
inc/dispatch/dispatch.php 2 0
inc/repo.inc.php 4 1
inc/user.inc.php 36 38
inc/user/repo-page.php 1 0
File TODO changed (mode: 100644) (index 72ffd6e..a123594)
12 12 proiectului, e nevoie. Dar intr-un form, in textarea, nu e nevoie. proiectului, e nevoie. Dar intr-un form, in textarea, nu e nevoie.
13 13 Apoi as putea elimina description_nice. Apoi as putea elimina description_nice.
14 14 [ ] Security: Link-uri + xss (Ionut) [ ] Security: Link-uri + xss (Ionut)
15 [ ] "UPDATE users SET last_seen" must be done only on logout?
16 What if the session expires?!
17 Bun, no way at every page accessed.
18 Maybe only at login/logout?
19 [ ] Spell check html files?
20 15 [ ] [ ]
21 16
22 17 == BEFORE NEXT RELEASE == == BEFORE NEXT RELEASE ==
18 [ ] Make the blob show nicer and remove rg_template_list (replace
19 it with rg_template*).
20 [ ] If there are a lot of tags/branches, remove oldest ones.
23 21 [ ] Add a "Stats" menu per repo: at least disk size. [ ] Add a "Stats" menu per repo: at least disk size.
24 22 [ ] Seems we are stuck processing events in events.php daemon because we are [ ] Seems we are stuck processing events in events.php daemon because we are
25 23 stuck in 'accept'. We should keep processing the events queue. stuck in 'accept'. We should keep processing the events queue.
File inc/dispatch/dispatch.php changed (mode: 100644) (index 67e71cf..fafacb2)
... ... case 'logout':
16 16 if (!rg_token_valid($db, $rg, TRUE)) if (!rg_token_valid($db, $rg, TRUE))
17 17 break; break;
18 18
19 rg_user_set_last_seen($db, $rg['login_ui']['uid']);
20
19 21 if (rg_sess_destroy($db, $rg['sid'], $rg['login_ui'])) { if (rg_sess_destroy($db, $rg['sid'], $rg['login_ui'])) {
20 22 $body .= rg_template("user/logout.html", $rg); $body .= rg_template("user/logout.html", $rg);
21 23 } else { } else {
File inc/repo.inc.php changed (mode: 100644) (index 45347f1..5078366)
... ... function rg_repo_history_load($db, $repo_id, $category, $number, $max_seconds)
521 521 while (($row = rg_sql_fetch_array($res))) { while (($row = rg_sql_fetch_array($res))) {
522 522 $row['username'] = 'n/a'; $row['username'] = 'n/a';
523 523 if ($row['uid'] > 0) { if ($row['uid'] > 0) {
524 $ui = rg_user_info($db, '', $row['uid'], '');
524 $ui = rg_user_info($db, $row['uid'], '', '');
525 525 if ($ui['exists'] == 1) if ($ui['exists'] == 1)
526 526 $row['username'] = $ui['username']; $row['username'] = $ui['username'];
527 527 } }
 
... ... function rg_repo_edit($db, $login_ui, &$new)
909 909
910 910 if ($new['repo_id'] == 0) { if ($new['repo_id'] == 0) {
911 911 $new['deleted'] = 0; $new['deleted'] = 0;
912 $new['disk_used_mb'] = 0;
913 $new['git_dir_done'] = 0;
914
912 915 $sql = "INSERT INTO repos (uid, master, name" $sql = "INSERT INTO repos (uid, master, name"
913 916 . ", itime, max_commit_size, description" . ", itime, max_commit_size, description"
914 917 . ", git_dir_done, public)" . ", git_dir_done, public)"
File inc/user.inc.php changed (mode: 100644) (index cd3fcc2..b001456)
... ... function rg_user_info($db, $uid, $user, $email)
646 646 return $ret; return $ret;
647 647 } }
648 648
649 /*
650 * Update last_seen field
651 */
652 function rg_user_set_last_seen($db, $uid)
653 {
654 rg_log_enter("user_set_last_seen: uid=$uid");
655
656 $ret = FALSE;
657 while (1) {
658 $now = time();
659
660 $IP = $_SERVER['REMOTE_ADDR'];
661
662 $params = array("last_seen" => $now,
663 "last_ip" => $IP,
664 "uid" => $uid);
665 $sql = "UPDATE users SET last_seen = @@last_seen@@"
666 . ", last_ip = @@last_ip@@"
667 . " WHERE uid = @@uid@@";
668 $res = rg_sql_query_params($db, $sql, $params);
669 if ($res === FALSE) {
670 rg_user_set_error("cannot update last seen (" . rg_sql_error() . ")");
671 break;
672 }
673 rg_sql_free_result($res);
674
675 rg_cache_merge("user::" . $uid, $params);
676
677 $ret = TRUE;
678 break;
679 }
680
681 rg_log_exit();
682 return $ret;
683 }
684
649 685 /* /*
650 686 * Loads ui based on sid, if possible * Loads ui based on sid, if possible
651 687 */ */
 
... ... function rg_user_login_by_sid($db, &$rg)
686 722
687 723 rg_sess_update($db, $sess); rg_sess_update($db, $sess);
688 724
689 rg_user_set_last_seen($db, $rg['login_ui']['uid']);
690
691 725 $ret = TRUE; $ret = TRUE;
692 726 break; break;
693 727 } }
 
... ... function rg_user_make_admin($db, $rg, $uid, $op)
920 954 return $ret; return $ret;
921 955 } }
922 956
923 /*
924 * Update last_seen field
925 */
926 function rg_user_set_last_seen($db, $uid)
927 {
928 rg_log_enter("user_set_last_seen: uid=$uid");
929
930 $ret = FALSE;
931 while (1) {
932 $now = time();
933
934 $IP = $_SERVER['REMOTE_ADDR'];
935
936 $params = array("last_seen" => $now,
937 "last_ip" => $IP,
938 "uid" => $uid);
939 $sql = "UPDATE users SET last_seen = @@last_seen@@"
940 . ", last_ip = @@last_ip@@"
941 . " WHERE uid = @@uid@@";
942 $res = rg_sql_query_params($db, $sql, $params);
943 if ($res === FALSE) {
944 rg_user_set_error("cannot update last seen (" . rg_sql_error() . ")");
945 break;
946 }
947 rg_sql_free_result($res);
948
949 rg_cache_merge("user::" . $uid, $params);
950
951 $ret = TRUE;
952 break;
953 }
954
955 rg_log_exit();
956 return $ret;
957 }
958
959 957 /* /*
960 958 * List users * List users
961 959 * TODO: switch to templates. * TODO: switch to templates.
File inc/user/repo-page.php changed (mode: 100644) (index 712a31e..7248de2)
... ... if (strcmp($_subop, "history") == 0) {
117 117 $blob = $_tree[0]; $blob = $_tree[0];
118 118 $_hash = $_tree[0]['ref']; $_hash = $_tree[0]['ref'];
119 119 $c = rg_git_content($_hash); $c = rg_git_content($_hash);
120 // TODO: error code check
120 121 $_content = array( $_content = array(
121 122 "hash" => $_hash, "hash" => $_hash,
122 123 "HTML:content" => rg_template_list($c) "HTML:content" => rg_template_list($c)
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://code.reversed.top/user/xaizek/rocketgit

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/rocketgit

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