var db = sql_connect("mysql", config_db); var userid = undef; var isadmin = 0; function encode_smtext(text) { text = xml::text; text =~ s,\[([0-9]+)\],[$1],g; text =~ s,(http|https|ftp)://(\S+[a-zA-Z0-9\/]),$0,g; return text; } function check_crypt(clear_pass, crypted_pass) { if (crypt(clear_pass, crypted_pass) ~== crypted_pass) return 1; // compatibility hack for old sumbaster crypt clear_pass =~ e/([^a-zA-Z0-9%])/g fmt("%02X", ord($1)); if (crypt(clear_pass, crypted_pass) ~== crypted_pass) return 1; return 0; } function patch_fixup(patch_id) { var text = config_patchfixup(sql_value(db, "SELECT patch_origtext FROM patch WHERE patch_id = ${mysql::patch_id}")); var teaser = text =~ s/^--- .*//Rsm; sql(db, "UPDATE patch SET patch_text = ${mysql::text}, patch_teaser = ${mysql::teaser} WHERE patch_id = ${mysql::patch_id}"); sql(db, "DELETE FROM patch_file WHERE patch_id = ${mysql::patch_id}"); var files; foreach[] f (text =~ /^(---|\+\+\+)\s+(\S+)/ANgm) files[f[2]] = 1; delete files["/dev/null"]; foreach f (files) sql(db, "INSERT INTO patch_file SET patch_id = ${mysql::patch_id}, patch_file = ${mysql::f}"); votepattern_check(patch_id, 0); } function patch_add(text) { var uid = system('date "+%Y%m%d%H%M%S\$\$00000"'); uid =~ s/(.{19}).*/$1/; sql(db, <:SQL> : INSERT INTO : patch : SET : patch_uid = '$uid', : patch_status = 'O', : patch_origtext = ${mysql::text}, : user_id_owner = $userid ); var patch_id = sql_value(db, "SELECT last_insert_id()"); sql(db, <:SQL> : INSERT INTO : vote : SET : vote_type = '+', : user_id = $userid, : patch_id = $patch_id ); patch_fixup(patch_id); mail(patch: uid, newthread: 1, "Added by @@@"); return uid; } function votepattern_import(text) { var lines = text =~ /[^\n]+/Ag; var current; var data; foreach[] line (lines) { line =~ s/^\s*//; line =~ s/\s*$//; if (line ~== "") continue; if (line =~ /^\[\s*(\S*)\s*\]$/) { if (declared data[$1]) goto error; data[current = $1] = [ title: $1, regex: undef, users: undef, votes: 1 ]; continue; } if (line =~ /^regex\s*=\s*(.*)/) { data[current].regex[$1] = undef; continue; } if (line =~ /^users\s*=\s*(.*)/) { foreach[] u ($1 =~ /\S+/Ag) { var id = sql_value(db, "SELECT user_id FROM user WHERE user_name = ${mysql::u}"); if (not defined id) goto error; data[current].users[id] = undef; } continue; } if (line =~ /^votes\s*=\s*([0-9]+)/) { data[current].votes = $1; continue; } error: panic "Error in votepattern import: '$line'"; } sql(db, "DELETE FROM votepattern"); sql(db, "DELETE FROM votepattern_regex"); sql(db, "DELETE FROM votepattern_user"); foreach[] d (data) { sql(db, "INSERT INTO votepattern SET votepattern_title = ${mysql::d.title}, votepattern_minvotes = ${mysql::d.votes}"); var id = sql_value(db, "SELECT last_insert_id()"); foreach r (d.regex) sql(db, "INSERT INTO votepattern_regex SET votepattern_id = $id, votepattern_regex = ${mysql::r}"); foreach u (d.users) sql(db, "INSERT INTO votepattern_user SET votepattern_id = $id, user_id = ${mysql::u}"); } } function votepattern_export() { var text; var vplist = sql(db, "SELECT votepattern_id AS id, votepattern_title AS title, votepattern_minvotes AS votes FROM votepattern ORDER BY votepattern_title"); foreach[] v (vplist) { text ~= "\n"; text ~= "[ $v.title ]\n"; var relist = sql(db, "SELECT votepattern_regex AS regex FROM votepattern_regex WHERE votepattern_id = $v.id ORDER BY votepattern_regex"); var ulist = sql(db, "SELECT user_name AS user FROM votepattern_user LEFT JOIN user USING (user_id) WHERE votepattern_id = $v.id ORDER BY user_name"); foreach[] r (relist) text ~= "regex = $r.regex\n"; if (elementsof ulist > 0) { text ~= "users ="; foreach[] u (ulist) text ~= " $u.user"; text ~= "\n"; } if (v.votes != 1) text ~= "votes = $v.votes\n"; } return text; } function votepattern_check(patch_id, showdetails) { var votecheckok = 1; var result, data; var temp = sql(db, <:SQL> : SELECT : votepattern.votepattern_id AS id, : votepattern.votepattern_title AS title, : votepattern.votepattern_minvotes AS votes, : patch_file.patch_file AS file : FROM : patch_file, : votepattern_regex, : votepattern : WHERE : patch_file.patch_id = ${mysql::patch_id} : AND : patch_file.patch_file REGEXP votepattern_regex.votepattern_regex : AND : votepattern_regex.votepattern_id = votepattern.votepattern_id ); foreach[] t (temp) { if (not declared data[t.id]) data[t.id] = [ id: t.id, title: t.title, votes: t.votes, files: undef ]; data[t.id].files[t.file] = undef; } var unmatched_id = sql_value(db, "SELECT votepattern_id FROM votepattern WHERE votepattern_title = 'unmatched'"); var unmatched_votes = sql_value(db, "SELECT votepattern_minvotes FROM votepattern WHERE votepattern_title = 'unmatched'"); if (defined unmatched_id) { temp = sql_array(db, <:SQL> : SELECT : patch_file.patch_file AS value : FROM : patch_file : WHERE : patch_file.patch_id = ${mysql::patch_id} : AND : (SELECT count(*) FROM votepattern_regex WHERE patch_file REGEXP votepattern_regex) = 0 ); if (elementsof temp > 0) { if (not declared data[unmatched_id]) data[unmatched_id] = [ id: unmatched_id, title: 'unmatched', votes: unmatched_votes, files: undef ]; foreach[] t (temp) data[unmatched_id].files[t] = undef; } } foreach[] d (data) { var vdata; foreach[] type ([ "+", "-" ]) { vdata[type] = sql_array(db, <:SQL> : SELECT : user_name AS value : FROM : vote LEFT JOIN user USING (user_id) : WHERE : patch_id = ${mysql::patch_id} : AND : vote_type = '$type' : AND : vote.user_id IN ( SELECT user_id FROM votepattern_user WHERE votepattern_id = $d.id ) ); } vdata["*"] = sql_array(db, <:SQL> : SELECT : user_name AS value : FROM : votepattern_user LEFT JOIN user USING (user_id) : WHERE : votepattern_id = $d.id : AND : (SELECT count(*) FROM vote WHERE vote.patch_id = ${mysql::patch_id} AND vote.user_id = votepattern_user.user_id) = 0 ); d.votes -= elementsof vdata["+"]; result ~= '
\nVotecheck \'${xml::d.title}\':\n'; switch { case elementsof vdata["-"] > 0: votecheckok = 0; patch_status_dump ~= "- pattern:$d.title\n"; result ~= <:> : Got qualified contra votes : (${array_join(vdata["-"], ", ")}) ; case d.votes > 0: votecheckok = 0; patch_status_dump ~= "- pattern:$d.title\n"; result ~= <:> : Missing $d.votes qualified vote(s) : (${array_join(vdata["*"], ", ")}) ; default: patch_status_dump ~= "+ pattern:$d.title\n"; result ~= <:> : OK : (${array_join(vdata["+"], ", ")}) ; } if (showdetails) { foreach f (d.files) result ~= '
${xml::f}
\n'; } result ~= '
\n'; } if (votecheckok != sql_value(db, "SELECT patch_votecheckok FROM patch WHERE patch_id = ${mysql::patch_id}")) sql(db, "UPDATE patch SET patch_votecheckok = $votecheckok WHERE patch_id = ${mysql::patch_id}"); return result; }