<commit_before>; vim:filetype=lisp

(defvar *rc-path*
 (or
  (uiop:getenv "USER_LISP_SHELL_RC")
  *compile-file-pathname*
  *load-pathname*))

(load (format nil
              "~a/src/nix/lang-os/user/user-shell.lisp"
              (uiop:getenv "HOME")))

(defun im-browsers ()
  (firefox (list "https://web.telegram.org/")
           :pass-stderr nil :pass-stdout nil :wait nil
           :no-close t :stumpwm-tags "cat/e-im im telegram no-auto-tags"
           :javascript t
           :socks-proxy 1080)
  )

(defun email-browsers ()
  (firefox (list "https://email.mccme.ru/")
           :pass-stderr nil :pass-stdout nil :wait nil
           :no-close t :stumpwm-tags "cat/em-email email mail mccme no-auto-tags"
           :data "/home/raskin/fallout/"
           :javascript t
           :socks-proxy 1080)
  (firefox (list "https://github.com/notifications/")
           :pass-stderr nil :pass-stdout nil :wait nil
           :no-close t :stumpwm-tags "cat/em-email email mail github no-auto-tags"
           :javascript t
           :socks-proxy 1080)
  )

(defun matrix-term ()
  (& urxvt 
     -name "weechat:matrix:dev" -title "Weechat: Matrix: dev.mccme.ru"
     -e sh -c "https_proxy= weechat -d ~/.weechat-dev"))

(defun vps-term ()
  (& sh -c "ssh-window \"$(cat ~/.vps-ssh)\""))

(defun subuser-signal ()
  (let* ((home (format nil "~a/.local/share/signal-home"
                       (uiop:getenv "HOME"))))
    (loop with stack := (list home)
          for next := (pop stack)
          while next
          do (ignore-errors
               (ask-with-auth 
                 ()
                 `(chown-subuser ,next "")))
          do (setf stack
                   (append
                     (mapcar 'namestring
                             (directory
                               (format nil "~a/*.*" next)))
                     stack)))
    (subuser-nsjail-x-application
      (list (true-executable "signal-desktop"))
      :environment `(("HOME" "/signal-home")
                     ("HTTPS_PROXY" "socks://127.0.0.1:1080")
                     ("HTTP_PROXY" "socks://127.0.0.1:1080")
                     ("https_proxy" "socks://127.0.0.1:1080")
                     ("http_proxy" "socks://127.0.0.1:1080")
                     )
      :name "signal-sandbox"
      :netns nil
      :mounts `(("-B" ,home "/signal-home"))
      :grant (list home)
      :hostname "signal-nsjail"
      :wait nil)))

(defun communication-windows ()
  (vps-term)
  (matrix-term)
  (im-browsers)
  (subuser-signal)
  (email-browsers))

(defun enter-labri (&rest args &key (brightness 400) (extra-ips `())
                          (location "LaBRI.fr")
                          &allow-other-keys)
  (apply
    'enter-location
    :brightness brightness
    :extra-ips extra-ips
    :location location
    args)
  (! x-options))

(defun enter-ratmino (&rest args &key (brightness 20) (extra-ips `())
                          (location "ratmino")
                          &allow-other-keys)
  (apply
    'enter-location
    :brightness brightness
    :extra-ips extra-ips
    :location location
    args)
  (! x-options))

(defun enter-mccme (&rest args &key (brightness 20) (extra-ips `())
                          (location "mccme")
                          &allow-other-keys)
  (apply
    'enter-location
    :brightness brightness
    :extra-ips extra-ips
    :location location
    args)
  (! x-options))

(defun enter-tum (&rest args &key (brightness 400) (extra-ips `())
                        (location "in.tum.de")
                        &allow-other-keys)
  (! x-options)
  (apply
    'enter-location
    :brightness brightness
    :extra-ips extra-ips
    :location location
    :extra-requests `((activate-interface "eth0")
                      (activate-interface "eth1")
                      (dhcp-resolv-conf))
    args)
  (! x-options)
  (when
    (or
      (ignore-errors (ethernet-attached "eth0"))
      (ignore-errors (ethernet-attached "eth1"))
      )
    (ask-with-auth
      (:presence t)
      `(progn
         (kill-wifi "wlan0")
         ,(if (ethernet-attached "eth0") `(dhclient "eth0" t) `(progn))
         ,(if (ethernet-attached "eth1") `(dhclient "eth1" t) `(progn))
         ))
    (! proxy-restart (format nil "~a/src/rc/squid/direct.squid" ($ :home))))
  (! x-options))

(defun enter-home-poing (&rest args)
  (apply 'enter-home
         (append args
                 (list :location "home@Poing"
                       :extra-requests `((local-resolv-conf))))))

(defun disconnect ()
  (alexandria:write-string-into-file
    "10" (format nil "~a/.watchperiod" (uiop:getenv "HOME"))
    :if-exists :supersede)
  (! web-stream-updater-starter quit)
  (ask-with-auth 
    (:presence t)
    `(list 
       (set-cpu-frequency "min")
       (set-brightness 1)))
  (! x-options)
  )

(defun xrandr-home-poing ()
  (! xrandr --output "VGA-1-2" --above "LVDS-1")
  (! xrandr --fb 4000x3000)
  (! pkill compton)
  (sleep 0.1)
  (! pkill -abrt compton)
  (sleep 0.1)
  (! pkill -kill compton)
  (sleep 0.5)
  (& compton --dbe))
<commit_msg>Syncing from Monotone at 20190323-024625. Last commit message was A more configurable disconnect<commit_after>; vim:filetype=lisp

(defvar *rc-path*
 (or
  (uiop:getenv "USER_LISP_SHELL_RC")
  *compile-file-pathname*
  *load-pathname*))

(load (format nil
              "~a/src/nix/lang-os/user/user-shell.lisp"
              (uiop:getenv "HOME")))

(defun im-browsers ()
  (firefox (list "https://web.telegram.org/")
           :pass-stderr nil :pass-stdout nil :wait nil
           :no-close t :stumpwm-tags "cat/e-im im telegram no-auto-tags"
           :javascript t
           :socks-proxy 1080)
  )

(defun email-browsers ()
  (firefox (list "https://email.mccme.ru/")
           :pass-stderr nil :pass-stdout nil :wait nil
           :no-close t :stumpwm-tags "cat/em-email email mail mccme no-auto-tags"
           :data "/home/raskin/fallout/"
           :javascript t
           :socks-proxy 1080)
  (firefox (list "https://github.com/notifications/")
           :pass-stderr nil :pass-stdout nil :wait nil
           :no-close t :stumpwm-tags "cat/em-email email mail github no-auto-tags"
           :javascript t
           :socks-proxy 1080)
  )

(defun matrix-term ()
  (& urxvt 
     -name "weechat:matrix:dev" -title "Weechat: Matrix: dev.mccme.ru"
     -e sh -c "https_proxy= weechat -d ~/.weechat-dev"))

(defun vps-term ()
  (& sh -c "ssh-window \"$(cat ~/.vps-ssh)\""))

(defun subuser-signal ()
  (let* ((home (format nil "~a/.local/share/signal-home"
                       (uiop:getenv "HOME"))))
    (loop with stack := (list home)
          for next := (pop stack)
          while next
          do (ignore-errors
               (ask-with-auth 
                 ()
                 `(chown-subuser ,next "")))
          do (setf stack
                   (append
                     (mapcar 'namestring
                             (directory
                               (format nil "~a/*.*" next)))
                     stack)))
    (subuser-nsjail-x-application
      (list (true-executable "signal-desktop"))
      :environment `(("HOME" "/signal-home")
                     ("HTTPS_PROXY" "socks://127.0.0.1:1080")
                     ("HTTP_PROXY" "socks://127.0.0.1:1080")
                     ("https_proxy" "socks://127.0.0.1:1080")
                     ("http_proxy" "socks://127.0.0.1:1080")
                     )
      :name "signal-sandbox"
      :netns nil
      :mounts `(("-B" ,home "/signal-home"))
      :grant (list home)
      :hostname "signal-nsjail"
      :wait nil)))

(defun communication-windows ()
  (vps-term)
  (matrix-term)
  (im-browsers)
  (subuser-signal)
  (email-browsers))

(defun enter-labri (&rest args &key (brightness 400) (extra-ips `())
                          (location "LaBRI.fr")
                          &allow-other-keys)
  (apply
    'enter-location
    :brightness brightness
    :extra-ips extra-ips
    :location location
    args)
  (! x-options))

(defun enter-ratmino (&rest args &key (brightness 20) (extra-ips `())
                          (location "ratmino")
                          &allow-other-keys)
  (apply
    'enter-location
    :brightness brightness
    :extra-ips extra-ips
    :location location
    args)
  (! x-options))

(defun enter-mccme (&rest args &key (brightness 20) (extra-ips `())
                          (location "mccme")
                          &allow-other-keys)
  (apply
    'enter-location
    :brightness brightness
    :extra-ips extra-ips
    :location location
    args)
  (! x-options))

(defun enter-tum (&rest args &key (brightness 400) (extra-ips `())
                        (location "in.tum.de")
                        &allow-other-keys)
  (! x-options)
  (apply
    'enter-location
    :brightness brightness
    :extra-ips extra-ips
    :location location
    :extra-requests `((activate-interface "eth0")
                      (activate-interface "eth1")
                      (dhcp-resolv-conf))
    args)
  (! x-options)
  (when
    (or
      (ignore-errors (ethernet-attached "eth0"))
      (ignore-errors (ethernet-attached "eth1"))
      )
    (ask-with-auth
      (:presence t)
      `(progn
         (kill-wifi "wlan0")
         ,(if (ethernet-attached "eth0") `(dhclient "eth0" t) `(progn))
         ,(if (ethernet-attached "eth1") `(dhclient "eth1" t) `(progn))
         ))
    (! proxy-restart (format nil "~a/src/rc/squid/direct.squid" ($ :home))))
  (! x-options))

(defun enter-home-poing (&rest args)
  (apply 'enter-home
         (append args
                 (list :location "home@Poing"
                       :extra-requests `((local-resolv-conf))))))

(defun disconnect (&key kill-ssh kill-wifi (brightness 1) (cpu-frequency "min"))
  (alexandria:write-string-into-file
    "10" (format nil "~a/.watchperiod" (uiop:getenv "HOME"))
    :if-exists :supersede)
  (! web-stream-updater-starter quit)
  (ask-with-auth 
    (:presence t)
    `(list 
       (set-cpu-frequency ,cpu-frequency)
       (set-brightness ,brightness)
       ,@(when kill-wifi `(kill-wifi))))
  (when kill-ssh (stumpwm-eval `(close-ssh-windows)))
  (! x-options)
  )

(defun xrandr-home-poing ()
  (! xrandr --output "VGA-1-2" --above "LVDS-1")
  (! xrandr --fb 4000x3000)
  (! pkill compton)
  (sleep 0.1)
  (! pkill -abrt compton)
  (sleep 0.1)
  (! pkill -kill compton)
  (sleep 0.5)
  (& compton --dbe))

{'fraction_non_alphanumeric': 0.15465105116636269, 'fraction_numerical': 0.018815397907266967, 'mean_word_length': 1.8581618655692729, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 8, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '508992', 'n_tokens_mistral': 3745, 'n_tokens_neox': 3520, 'n_words': 758}