Advertisement
Guest User

Fix GNUsocial When Instance Goes HTTP --> HTTPS

a guest
Jul 15th, 2017
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TCL 3.63 KB | None | 0 0
  1.  
  2.  
  3.     #!/usr/bin/env tclsh
  4.     package require Tcl 8.6
  5.     package require tdbc::mysql
  6.      
  7.     # Set up db connectivity
  8.     set dbname "your_database_name"
  9.     set dbuser "your_database_user"
  10.     set dbpwd  "your_dbuser_password"
  11.     set dbhost "127.0.0.1"
  12.     set remotehost "the_other_instance"
  13.      
  14.     tdbc::mysql::connection create db -user $dbuser -passwd $dbpwd -host $dbhost -database $dbname
  15.      
  16.      
  17.     ## Table: profile
  18.     #puts "\nConverting $remotehost URLs in profile table to HTTPS."
  19.     #db foreach row "SELECT profileurl, nickname FROM profile WHERE profileurl LIKE '%$remotehost%'" {
  20.     #   set url [dict get $row profileurl]
  21.     #   set nick [dict get $row nickname]
  22.     #   set temp [string index $url 4]
  23.     #   if {$temp == ":""} {
  24.     #      puts URL for $nick (\"$url\") is HTTP. Changing to HTTPS"
  25.     #      # change it
  26.     #      set newurl [string replace $url 4 4 s[string index $url 4]]
  27.     #      set stmt [$db prepare "UPDATE `profile` set profileurl $newurl where nickname=$nick"]
  28.     #      set res [$stmt execute]
  29.     #      stmt close
  30.     #   } else {
  31.     #      puts "URL for $nick (\"$url\") is already HTTPS"
  32.     #   }
  33.     #}
  34.     ## Commented because fl0wn points out that changing profile table can cause breakage.
  35.      
  36.     ## Table: ostatus_profile
  37.     db foreach row "SELECT uri, profile_id FROM ostatus_profile WHERE uri LIKE '%$remotehost%'" {
  38.        set url [dict get $row uri]
  39.        set id [dict get $row profile_id]
  40.        set temp [string index $uri 4]
  41.        if {$temp == ":""} {
  42.          puts "URL for $id (\"$url\") is HTTP. Changing to HTTPS"
  43.           # change it
  44.           set newurl [string replace $url 4 4 s[string index $url 4]]
  45.           set stmt [$db prepare "UPDATE `ostatus_profile` set uri $newurl where profile_id=$id"]
  46.           set res [$stmt execute]
  47.           stmt close
  48.        } else {
  49.           puts "URL for $id (\"$url\") is already HTTPS"
  50.        }
  51.     }
  52.      
  53.     ## Table: feedsub
  54.     db foreach row "SELECT id, uri, huburi FROM feedsub WHERE uri LIKE '%$remotehost%'" {
  55.        set id [dict get $row id]
  56.        set url [dict get $row uri]
  57.        set hub [dict get $row huburi]
  58.        set temp [string index $uri 4]
  59.        if {$temp == ":""} {
  60.          puts "Profile URL for $id (\"$uri\") is HTTP. Changing to HTTPS"
  61.           # change it
  62.           set newurl [string replace $uri 4 4 s[string index $uri 4]]
  63.           set stmt [$db prepare "UPDATE `feedsub` set uri $newurl where id=$id"]
  64.           set res [$stmt execute]
  65.           stmt close
  66.        } else {
  67.           puts "URL for $id (\"$url\") is already HTTPS"
  68.        }
  69.        set temp [string index $hub 4]
  70.        if {$temp == ":""} {
  71.          puts "Hub URL for $id (\"$hub\") is HTTP. Changing to HTTPS"
  72.           # change it
  73.           set newurl [string replace $hub 4 4 s[string index $hub 4]]
  74.           set stmt [$db prepare "UPDATE `feedsub` set huburi $newurl where id=$id"]
  75.           set res [$stmt execute]
  76.           stmt close
  77.        } else {
  78.           puts "URL for $id (\"$url\") is already HTTPS"
  79.        }
  80.     }
  81.      
  82.     ### Sources
  83.     ## String insertion: http://wiki.tcl.tk/44pagetoc706ab8bb
  84.     ## Return the nth character of a string: http://wiki.tcl.tk/10165
  85.     ## tdbc and tdbc::mysql: http://wiki.tcl.tk/20343
  86.     ## GNU Social tables which may need tweaking: https://git.gnu.io/gnu/gnu-social/issues/208 and https://nu.federati.net/conversation/51983 and https://sealion.club/notice/2344583 and http://whird.jpope.org/statusnet-subscription-hacking/
  87.      
  88.     ### Comment
  89.     ## Purpose: convert the db version of a GS instance's URLs from HTTP to HTTPS
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement