Signed-off-by: Callan Barrett <wizzomafizzo@gmail.com> --- web/html/pkgsubmit.php | 2 ++ web/lib/acctfuncs.inc | 2 ++ web/lib/aur.inc | 36 ++++++++++++++++++++++++++++++++++++ web/lib/config.inc.proto | 2 ++ web/lib/pkgfuncs.inc | 8 ++++++++ web/template/pkg_comment_form.php | 2 ++ 6 files changed, 52 insertions(+), 0 deletions(-) diff --git a/web/html/pkgsubmit.php b/web/html/pkgsubmit.php index a3394af..04c1542 100644 --- a/web/html/pkgsubmit.php +++ b/web/html/pkgsubmit.php @@ -369,6 +369,7 @@ if ($_COOKIE["AURSID"]): } } + if (LOGGING) { logit(2, username_from_sid($_COOKIE['AURSID']), pkgname_from_id($pdata['ID'])); } header('Location: packages.php?ID=' . $pdata['ID']); } else { @@ -419,6 +420,7 @@ if ($_COOKIE["AURSID"]): } pkg_notify(account_from_sid($_COOKIE["AURSID"]), array($packageID)); + if (LOGGING) { logit(1, username_from_sid($_COOKIE['AURSID']), pkgname_from_id($packageID)); } header('Location: packages.php?ID=' . $packageID); diff --git a/web/lib/acctfuncs.inc b/web/lib/acctfuncs.inc index 9ed4f22..661b081 100644 --- a/web/lib/acctfuncs.inc +++ b/web/lib/acctfuncs.inc @@ -290,6 +290,8 @@ function process_account_form($UTYPE,$TYPE,$A,$U="",$T="",$S="",$E="", } else { # account created/modified, tell them so. # + if (LOGGING) { logit(4, username_from_sid($U)); } + print __("The account, %h%s%h, has been successfully created.", "<b>", $U, "</b>"); print "<p>\n"; diff --git a/web/lib/aur.inc b/web/lib/aur.inc index 517abe3..6a07d69 100644 --- a/web/lib/aur.inc +++ b/web/lib/aur.inc @@ -437,3 +437,39 @@ function mkurl($append) { return substr($out, 5); } + +/** + * Log whatever you like to a table + * + * Basic function so we can get some stats about stuff, we'll just dump + * everything into a table and make up some numbers for different actions + * + * Some NumbersĀ®: + * 1 = upload new package + * 2 = update package + * 3 = delete package + * 4 = register account + * 5 = comment somewhere + * 6 = I dunno lol (I had search here for some reason) + * (maybe we don't need to log this much, I'll make some numbers up anyway) + * 7 = vote/unvote + * 8 = flag/unflag + * 9 = adopt/disown + * + * @param int $action Put your magic number here that represents whatever + * action you're logging + * @param string $who Optional string to log who did the action, normal username + * not the ID + * @param string $pkg Optional string of what package an action happened to, + * actual package names not IDs + */ +function logit($action, $who='', $pkg='') +{ + $dbh = db_connect(); + $q = sprintf("INSERT INTO Log (`action`, `when`, `who`, `pkg`) VALUES (%d, UNIX_TIMESTAMP(), '%s', '%s')", + $action, + mysql_real_escape_string($who), + mysql_real_escape_string($pkg) + ); + db_query($q, $dbh); +} diff --git a/web/lib/config.inc.proto b/web/lib/config.inc.proto index 89b4fe5..6b2b73a 100644 --- a/web/lib/config.inc.proto +++ b/web/lib/config.inc.proto @@ -39,3 +39,5 @@ $SUPPORTED_LANGS = array( # Idle seconds before timeout $LOGIN_TIMEOUT = 7200; +# Shall we log everything? +define("LOGGING", FALSE); diff --git a/web/lib/pkgfuncs.inc b/web/lib/pkgfuncs.inc index 80775a2..699d6e3 100644 --- a/web/lib/pkgfuncs.inc +++ b/web/lib/pkgfuncs.inc @@ -599,6 +599,8 @@ function pkg_flag ($atype, $ids, $action = True) { } else { $flag .= ", " . $pid; } + + if (LOGGING) { logit(8, username_from_sid($_COOKIE['AURSID']), pkgname_from_id($pid)); } } $ood = $action ? 1 : 0; @@ -699,6 +701,8 @@ function pkg_delete ($atype, $ids) { # These are the packages that are safe to delete foreach ($ids_to_delete as $id) { + if (LOGGING) { logit(3, username_from_sid($_COOKIE['AURSID']), pkgname_from_id($id)); } + $q = "DELETE FROM PackageVotes WHERE PackageID = " . $id; $result = db_query($q, $dbh); @@ -757,6 +761,8 @@ function pkg_adopt ($atype, $ids, $action = True) { } else { $pkg .= ", ".$pid; } + + if (LOGGING) { logit(9, username_from_sid($_COOKIE['AURSID']), pkgname_from_id($pid)); } } $field = "MaintainerUID"; @@ -840,6 +846,8 @@ function pkg_vote ($atype, $ids, $action = True) { } } } + + if (LOGGING) { logit(7, username_from_sid($_COOKIE['AURSID']), pkgname_from_id($pid)); } } # only vote for packages the user hasn't already voted for diff --git a/web/template/pkg_comment_form.php b/web/template/pkg_comment_form.php index 70570da..213cc81 100644 --- a/web/template/pkg_comment_form.php +++ b/web/template/pkg_comment_form.php @@ -11,6 +11,8 @@ if (isset($_REQUEST['comment'])) { $q.= 'UNIX_TIMESTAMP())'; db_query($q, $dbh); + if (LOGGING) { logit(5, username_from_sid($_COOKIE['AURSID']), pkgname_from_id(intval($_REQUEST['ID']))); } + # Send email notifications $q = 'SELECT CommentNotify.*, Users.Email '; $q.= 'FROM CommentNotify, Users '; -- 1.6.0.4