aboutsummaryrefslogtreecommitdiff
path: root/emacs/.emacs.d/lisp/my/tor.el
diff options
context:
space:
mode:
Diffstat (limited to 'emacs/.emacs.d/lisp/my/tor.el')
-rw-r--r--emacs/.emacs.d/lisp/my/tor.el57
1 files changed, 57 insertions, 0 deletions
diff --git a/emacs/.emacs.d/lisp/my/tor.el b/emacs/.emacs.d/lisp/my/tor.el
new file mode 100644
index 0000000..9ed7d5f
--- /dev/null
+++ b/emacs/.emacs.d/lisp/my/tor.el
@@ -0,0 +1,57 @@
+;;; tor.el -- tor utilities -*- lexical-binding: t -*-
+
+;; Copyright (C) 2025 Free Software Foundation, Inc.
+
+;; Author: Yuchen Pei <id@ypei.org>
+;; Package-Requires: ((emacs "30.1"))
+
+;; This file is part of dotted.
+
+;; dotted is free software: you can redistribute it and/or modify it under
+;; the terms of the GNU Affero General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; dotted is distributed in the hope that it will be useful, but WITHOUT
+;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General
+;; Public License for more details.
+
+;; You should have received a copy of the GNU Affero General Public
+;; License along with dotted. If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; tor utilities.
+
+;;; Code:
+
+
+(defun my-call-process-with-torsocks (no-tor program
+ &optional infile destination display
+ &rest args)
+ (if no-tor
+ (apply 'call-process
+ (append (list program infile destination display) args))
+ (apply 'call-process
+ (append (list "torsocks" infile destination display program) args))))
+
+(defun my-start-process-with-torsocks (no-tor name buffer program
+ &rest program-args)
+ (if no-tor
+ (apply 'start-process (append (list name buffer program) program-args))
+ (apply 'start-process
+ (append (list name buffer "torsocks" program) program-args))))
+
+(defun tor-parse-check-dom (dom)
+ (let ((content (dom-by-class dom "content")))
+ (format "%s\n%s"
+ (string-trim (dom-text (dom-by-tag content 'h1)))
+ (string-trim (dom-texts (car (dom-by-tag content 'p)))))))
+
+(defun tor-check (&optional no-tor)
+ (require 'my-wget)
+ (tor-parse-check-dom (my-wget-dom "https://check.torproject.org/" no-tor)))
+
+(provide 'tor)
+;;; tor.el ends here