beaglebone.txt 279KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656
  1. #+TITLE: FreedomBone
  2. #+AUTHOR: Bob Mottram
  3. #+EMAIL: bob@robotics.uk.to
  4. #+KEYWORDS: freedombox, debian, beaglebone, friendica, email, web server, home server, internet, censorship, surveillance, social network, irc, jabber
  5. #+DESCRIPTION: Turn the Beaglebone Black into a personal communications server
  6. #+OPTIONS: ^:nil
  7. #+STYLE: <link rel="stylesheet" type="text/css" href="index.css" />
  8. #+BEGIN_CENTER
  9. *How to turn the Beaglebone Black into a FreedomBox-like personal communications server*
  10. #+END_CENTER
  11. [[./images/freedombone_small.jpg]]
  12. #+BEGIN_CENTER
  13. Copyright (C) 2014 Bob Mottram
  14. Permission is granted to copy, distribute and/or modify this document under the terms of the [[https://gnu.org/licenses/fdl.html][GNU Free Documentation License]], Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
  15. Source for this web site in [[https://en.wikipedia.org/wiki/Org-mode][Emacs org-mode]] format is available [[/beaglebone.txt][here]]. Comments or patches may be submitted via [[https://github.com/bashrc/freedombone][Github]].
  16. #+END_CENTER
  17. * Introduction
  18. #+BEGIN_VERSE
  19. /The battle for liberty is never won, and is never lost. The battle for liberty always continues. It is never too late, and it is never soon enough, to defend freedom. No matter how enslaved we are, we always have hope. No matter how free we are we are never safe. Nothing ever limits the government, except the people. Any generation which fails to defend freedom will lose it, and the next generation will have to shed blood to gain it back./
  20. -- John Perna
  21. #+END_VERSE
  22. ** What is FreedomBone?
  23. Today many of us rely upon "free" services in the cloud, such as Gmail, Facebook, Google+ and so on. It might appear that these services are indispensible infrastructure of the modern internet, but actually they're not strictly needed and the amount of value which they deliver to the average internet user is very marginal. It is possible to be a citizen of the internet and yet not use those things - to disintermediate the most well known companies and cut out their prurient or merely cringeworthy business models.
  24. FreedomBone is a personal home communications server based upon the BeagleBone Black hardware. It's small and cheap and will allow you to use email, have your own web site and do social networking in a federated way without needing to rely upon any intermediary companies other than your ISP.
  25. ** Do I need any prior knowledge?
  26. In these instructions only a minimal level of familiarity with Linux is assumed. It's assumed that you know the basics of the /nano/ and /emacs/ editors, but it would be simple to also use other editors if you prefer.
  27. ** Why should I do this?
  28. You should consider doing this if you are a freedom-oriented sort of person and you want to maintain sovereignty over your information. Laws in many places in the world consider you to have relinquished any property rights over data which you put onto a server not owned by youself (i.e. owned by a third party, such as Google or Facebook). The frequently cited and often absurd mantra is that there is "/no reasonable expectation of privacy/".
  29. If you don't like the idea of having all your communications intercepted and investigated by the Surveillance State then you should consider running a FreedomBone. If your profession involves maintaining confidentiality as an essential feature, such as legal or medical services, counselling, teaching or any sort of activism then you should consider running a FreedomBone. Especially if your activities include [[https://firstlook.org/theintercept/article/2014/03/20/inside-nsa-secret-efforts-hunt-hack-system-administrators/][systems administration]] or [[http://www.spiegel.de/international/germany/gchq-and-nsa-targeted-private-german-companies-a-961444.html][software engineering for any communications-related systems]] then it is highly likely that you have already been targeted and "tasked" by the surveillance apparatus.
  30. As Eben Moglen noted in his now famous [[https://www.youtube.com/watch?v=QOEMv0S8AcA]["Freedom in The Cloud"]] talk the simple fact of you keeping your own internet logs (found in the /var/log directory) puts a certain amount of power in your hands and takes it away from parties who would otherwise sell that information without your knowledge or permission to advertisers or other shady outfits who may not have your best interests at heart.
  31. ** After it's installed will it need a lot of maintenance?
  32. So long as the hardware is ok the amount of maintenance needed should be very small. Unlike on Windows based systems you don't need to defragment drives or mess about with anti-virus programs. I ran a similar Sheevaplug system between 2010 and 2013 with only occasional software updates or reboots, and uptime was probably 99% or better.
  33. ** Is it secure?
  34. Nothing is totally secure or infallible. You could have the most secure technology and yet still use easy to guess passwords. In general any software described as "uncrackable" or "guaranteed secure" is likely to be bogus and should be treated with suspicion. No matter what the hype may claim, all software has bugs so it's really a question of whether your communications are more secure or less secure. Using something like Freedombone will be likely to increase your degree of communications security to a level which is above average.
  35. This system will not defend you from an attacker who is actively trying to block or corrupt your communications, but I assume that doesn't apply in the majority of cases. Another thing to be aware of is that running a FreedomBone could make you more vulnerable to traffic analysis, since the server is associated with your home address and isn't a giant aggregation of users somewhere in the cloud. You need to weigh this alongside the additional legal protection which owning the server and having it in your own home gives you.
  36. FreedomBone should be far more secure than using popular cloud-based services which have spying built into them as a core feature (although not one which is typically advertised), but it is not necessarily any kind of impenetrable information fortress.
  37. This project is not only about security. It's also about having independence and at least in the realm of information being able to have more control over your own life, without having gatekeepers, censors or companies in the middle. That's the way that the internet was designed to be in the first place.
  38. ** Will running a server all the time affect my electricity bill?
  39. Hardly at all. The BeagleBone Black consumes very little power - less than 5W. It would even be potentially possible to run it from a solar panel.
  40. ** Can I use a Raspberry Pi or Cubieboard instead?
  41. These instructions are not highly specific to the Beaglebone Black and so will likely also work on other single board computers (SBCs) such as the [[https://en.wikipedia.org/wiki/Raspberry_pi][Raspberry Pi]] or [[https://en.wikipedia.org/wiki/Cubieboard][Cubieboard]]. The original Raspberry Pi only had 256MB of RAM and so the performance of some services may be more limited. The Beaglebone Black was chosen mainly because of its low cost, relatively good CPU performance for the price (by the standards of 2013) and also low electricity consumption. The Cubieboard is also another good alternative, with the A20 version having similar specifications but twice as much RAM as the BeagleBone Black.
  42. ** Why should I trust the packages or source code downloaded from this site?
  43. If you're particularly security conscious then you shouldn't. Binary or source packages have only been included here for convenience and to avoid confusion. "/Go and find a Debian installation for the BeagleBone Black somewhere on the web/" is too vague an instruction for my liking, and I've attempted to keep things as concise and unambiguous as possible - particularly with an average or new Linux user in mind.
  44. However, for maximum security for those software systems which are not already packaged within the Debian repositories then seek out the original sources and verify the hashes independently.
  45. It's worth adopting an attitude of "/trust but verify/". Don't let fear of mass surveillance and [[https://www.techdirt.com/articles/20140207/08354426130/gchq-has-entire-program-dirty-tricks-including-honeypots-using-journalists-deleting-online-accounts.shtml]["dirty tricks"]] paralyse you into trusting nothing and consequently doing nothing. Doing nothing means that the surveillance apparatus has succeeded in keeping you under observation at all times.
  46. ** Do I need to have a static IP address?
  47. This is often a question which people ask about running a server from home. The answer is that you don't need a static IP address. In the vast majority of cases you will have a dynamic IP address issued by your ISP, which may change from time to time. How then does the DNS system know how to resolve your domain name correctly? To do this you need to use a dynamic IP address system, such as [[http://freedns.afraid.org/][freeDNS]]. The details of that are explained [[Getting onto the web][here]]. Other services are available, but they're not usually /free as in beer/. In this guide a static IP address of 192.168.1.60 is only used within your /local network/ (i.e. not the big bad internet of public IP addresses), so that your internet router can be set up to send incoming traffic to the right computer.
  48. * Inventory
  49. #+BEGIN_VERSE
  50. /You can’t help someone just by making a wish to do so, you have to take action./
  51. -- Dalai Lama
  52. #+END_VERSE
  53. These instructions assume that you have the following ingredients.
  54. ** A BeagleBone Black (BBB)
  55. It should come with a suitable USB cable for the initial setup. To make things look nicer you may also want to get a case for it.
  56. ** An internet connection
  57. It is assumed that the most common situation is via a router installed at home. The router should have ethernet sockets on it and a web interface which allows you to forward ports (sometimes under the "firewall" settings), so that you can forward ssh and web traffic to the BBB.
  58. ** microSD card
  59. To use as the main storage for the BBB. 16 or 32GB is fine, and can be obtained quite cheaply. Try to use Sandisk (class 10 or better) where possible and avoid cheaper cards which often have poor performance.
  60. You may also need an SD card adaptor or USB card reader in order to flash the operating image to the microSD card. For instance, many laptops have an SD card slot but not a microSD slot.
  61. ** 5V/2A power supply
  62. With a plug suitable for powering the BBB. If you have some device with a USB socket nearby you may also be able to just use that for electrical power. However, powering from the USB cable alone might result in crashes when the system is under load, depending upon how many milliamps can be supplied by the USB hub/socket. If the system crashes due to running out of power then you will see that the LEDs on the BBB are continuously on, rather than flashing. One way to test whether the board has enough power is to try compiling a Linux kernel on it, but any CPU and disk intensive program will also suffice as a test.
  63. [[http://beagleboard.org/Support/FAQ][beagleboard.org]] gives the following advice on power supplies:
  64. #+BEGIN_VERSE
  65. /Power over USB is sufficient as long as the software and system running perform some management to keep it under the USB current limit threshold. For simplicity and maximum capability, powering over the 5V barrel connector is typically recommended./
  66. /The power adapter is required to provide 5V over a 5.5mm outer diameter and 2.1mm inner diameter barrel connector (a barrel connector length of 9.5mm is more than sufficient). The recommended supply current is at least 1.2A (or 6W), but at least 2A (or 10W) is recommended if you are going to connect up anything over the USB./
  67. #+END_VERSE
  68. The plug should be /centre positive/, meaning that the centre/tip is positive and the outer part is negative.
  69. ** An ethernet patch cable
  70. Just an ordinary cat5 or cat6 cable that you can get from most electrical/computer stores.
  71. * Installing Debian onto the microSD card
  72. ** Beaglebone Black
  73. The Debian Linux OS will be installed onto a small flash drive. It's a good idea to do this rather than using the internal flash, because it will allow you to easily create backups of the entire system if necessary using the dd command.
  74. Download the image.
  75. #+BEGIN_SRC: bash
  76. cd ~/
  77. wget http://freedombone.uk.to/debian-jessie-console-armhf-2014-08-13.tar.xz
  78. #+END_SRC
  79. Verify it.
  80. #+BEGIN_SRC: bash
  81. sha256sum debian-jessie-console-armhf-2014-08-13.tar.xz
  82. fc225cfb3c2dfad92cccafa97e92c3cd3db9d94f4771af8da364ef59609f43de
  83. #+END_SRC
  84. Uncompress it.
  85. #+BEGIN_SRC: bash
  86. tar xJf debian-jessie-console-armhf-2014-08-13.tar.xz
  87. cd debian-jessie-console-armhf-2014-08-13
  88. #+END_SRC
  89. Create the disk image, where sdX is the name of the flash drive (probably it will be sdb or sdc). An easy way to find out the device name of the flash drive is to enter the command:
  90. #+BEGIN_SRC: bash
  91. ls /dev/sd*
  92. #+END_SRC
  93. then plug in the flash drive and type the same command again. You'll be able to see the difference. Once you know the device name then you can proceed to install the image onto the flash drive.
  94. #+BEGIN_SRC: bash
  95. sudo apt-get install u-boot-tools dosfstools git-core kpartx wget parted
  96. sudo ./setup_sdcard.sh --mmc /dev/sdX --dtb beaglebone
  97. #+END_SRC
  98. Once that is completed we need to copy a boot file to enable the system to boot correctly. An example /uEnv.txt/ file can also be [[Boot (uEnv.txt)][seen here]].
  99. #+BEGIN_SRC: bash
  100. sudo cp /media/$USER/BOOT/bbb-uEnv.txt /media/$USER/BOOT/uEnv.txt
  101. sync
  102. #+END_SRC
  103. Now the microSD card can be safely removed via your file manager (usually right click and "safely remove" or "eject").
  104. ** Cubieboard
  105. The Debian Linux OS will be installed onto a small flash drive. It's a good idea to do this rather than using the internal flash, because it will allow you to easily create backups of the entire system if necessary using the dd command.
  106. Download the Cubieboard image from http://cubian.org/downloads/
  107. #+BEGIN_SRC: bash
  108. sudo apt-get install p7zip-full
  109. 7z x CUBIAN_IMAGE.7z
  110. #+END_SRC
  111. Create the disk image, where sdX is the name of the flash drive (probably it will be sdb or sdc). An easy way to find out the device name of the flash drive is to enter the command:
  112. #+BEGIN_SRC: bash
  113. ls /dev/sd*
  114. #+END_SRC
  115. then plug in the flash drive and type the same command again. You'll be able to see the difference. Once you know the device name then you can proceed to install the image onto the flash drive.
  116. #+BEGIN_SRC: bash
  117. sudo dd if=EXTRACTED_CUBIAN_IMAGE of=/dev/sdX bs=4096; sync
  118. #+END_SRC
  119. * Setup
  120. #+BEGIN_VERSE
  121. /Build the tools for a future you would want to live in/
  122. -- Kurt Opsahl
  123. #+END_VERSE
  124. ** Things to be aware of
  125. *** A note on ssh
  126. When using ssh to log into the BBB if you get warnings of the type "/the ECDSA host key for domain differs from the key for the IP address/" then run the command:
  127. #+BEGIN_SRC: bash
  128. ssh-keygen -R <IP address>
  129. #+END_SRC
  130. *** Passwords
  131. It's highly recommended that you use a password manager, such as KeepassX, and make all your passwords long random strings. It's also a good idea to use different passwords for different pieces of software, instead of one or two passwords for the whole system. That compartmentalises the security such that even if an attacker gains access to one system they can't necessarily get access to others.
  132. *** HTTPS
  133. Throughout these instructions self signed SSL certificates are used to implement access to web pages via HTTPS. The whole HTTPS security model upon which much of the internet currently rests seems broken in that it usually depends upon "trusted certificate authorities" who are not really trusted, except perhaps by the maintainers of certain web browser software. So all that HTTPS really guarantees is that you have an encrypted connection, but an encrypted connection /to who/ can be subject to doubt. As was seen in 2013 with the [[https://www.schneier.com/essay-455.html][information coming from Edward Snowden]], and also the [[http://en.wikipedia.org/wiki/Lavabit][Lavabit email service]], it's possible for companies/organisations to be compromised or bribed and SSL private keys for all users can be demanded using gagging orders or secret laws without any individual user ever being able to know that their communications is no longer secure..
  134. Not knowing who you're really connecting to is especially true for self-signed certificates, so it is in principle possible that when logging into a site with a username and password a system such as [[http://arstechnica.com/tech-policy/2013/11/uk-spies-continue-quantum-insert-attack-via-linkedin-slashdot-pages/][Quantum Insert]], or a compromised [[http://en.wikipedia.org/wiki/Domain_Name_System][DNS service]], could be used to direct the user to a fake copy of the login screen for the purposes of obtaining their login details. While this doesn't seem to be a major problem at the time of writing it's something to keep in mind. So if you can't log in or if you log in and what you see doesn't look like your site then it's possible that such a compromise could have taken place. Using a password manager with different login details for each site is one way to ensure that if one system is compromised then the attacker can't necessarily get access to all your other stuff.
  135. ** Initial
  136. Eject the microSD card from your computer and plug it into the BBB, then connect the USB cable between the two. You may need to wait for a couple of minutes for the BBB to boot from the card, then you can then open a terminal and login via ssh.
  137. Note that if you're using a Cubieboard then the ssh login is different (see https://github.com/cubieplayer/Cubian/wiki/Get-started-with-Cubian) and it may be easier to directly edit the following files with the microSD card plugged into your laptop.
  138. #+BEGIN_SRC: bash
  139. ssh debian@192.168.7.2
  140. #+END_SRC
  141. The default password is /temppwd/
  142. Then log in as root:
  143. #+BEGIN_SRC: bash
  144. su
  145. #+END_SRC
  146. The default password is /root/
  147. The first thing to do is to change the passwords from their defaults.
  148. #+BEGIN_SRC: bash
  149. passwd
  150. #+END_SRC
  151. Then you will need to change the network interfaces. The main task here is to comment out the stuff related to usb0. That will enable you to plug the BBB into the back of a router and for it to be detectable on the network.
  152. #+BEGIN_SRC: bash
  153. nano /etc/network/interfaces
  154. #+END_SRC
  155. The resulting interfaces file should look like this:
  156. #+BEGIN_SRC: bash
  157. # This file describes the network interfaces available on your system
  158. # and how to activate them. For more information, see interfaces(5).
  159. # The loopback network interface
  160. auto lo
  161. iface lo inet loopback
  162. # The primary network interface
  163. allow-hotplug eth0
  164. iface eth0 inet static
  165. address 192.168.1.60
  166. netmask 255.255.255.0
  167. gateway 192.168.1.254
  168. dns-nameservers 213.73.91.35 85.214.20.141
  169. # Example to keep MAC address between reboots
  170. #hwaddress ether DA:AD:CE:EF:CA:FE
  171. # WiFi Example
  172. #auto wlan0
  173. #iface wlan0 inet dhcp
  174. # wpa-ssid "essid"
  175. # wpa-psk "password"
  176. # Ethernet/RNDIS gadget (g_ether)
  177. # ... or on host side, usbnet and random hwaddr
  178. # Note on some boards, usb0 is automaticly setup with an init script
  179. # in that case, to completely disable remove file [run_boot-scripts] from the boot partition
  180. #iface usb0 inet static
  181. # address 192.168.7.2
  182. # netmask 255.255.255.0
  183. # network 192.168.7.0
  184. # gateway 192.168.7.1
  185. #+END_SRC
  186. CTRL-o followed by ENTER to save, then CTRL-x to exit.
  187. In the above example "address 192.168.1.60" is a static IP address for the BBB, which will allow incoming network traffic to be directed from the router in a reliable manner. It should be outside of the DHCP range set up on the router.
  188. "gateway 192.168.1.254" should be the IP address of the router.
  189. Note that setting the DNS servers with dns-nameservers is important because some home routers do not allow you to change the DNS settings.
  190. Edit resolv.conf.
  191. #+BEGIN_SRC: bash
  192. nano /etc/resolv.conf
  193. #+END_SRC
  194. It should look something like the following:
  195. #+BEGIN_SRC: bash
  196. domain localdomain
  197. search localdomain
  198. nameserver 213.73.91.35
  199. nameserver 85.214.20.141
  200. #+END_SRC
  201. It's not a good idea to use the DNS servers provided by default by your ISP, since those are almost certainly subject to censorship and monitoring. Other possible IP addresses are:
  202. | DNS IP | Organisation | Location |
  203. |-----------------+--------------------------------+-------------|
  204. | 85.214.73.63 | Digitalcourage | Germany |
  205. | 87.118.100.175 | German Privacy Foundation e.V. | Germany |
  206. | 94.75.228.29 | German Privacy Foundation e.V. | Germany |
  207. | 85.25.251.254 | German Privacy Foundation e.V. | Germany |
  208. | 2.141.58.13 | German Privacy Foundation e.V. | Germany |
  209. | 213.73.91.35 | Chaos Computer Club Berlin | Germany |
  210. | 212.82.225.7 | ClaraNet | Germany |
  211. | 212.82.226.212 | ClaraNet | Germany |
  212. | 58.6.115.42 | OpenNIC | Australia |
  213. | 58.6.115.43 | OpenNIC | Australia |
  214. | 119.31.230.42 | OpenNIC | Australia |
  215. | 200.252.98.162 | OpenNIC | Brazil |
  216. | 217.79.186.148 | OpenNIC | Germany |
  217. | 81.89.98.6 | OpenNIC | Germany |
  218. | 78.159.101.37 | OpenNIC | Germany |
  219. | 203.167.220.153 | OpenNIC | New Zealand |
  220. | 82.229.244.191 | OpenNIC | France |
  221. | 82.229.244.191 | OpenNIC | Czechnya |
  222. | 216.87.84.211 | OpenNIC | USA |
  223. | 66.244.95.20 | OpenNIC | USA |
  224. | 207.192.69.155 | OpenNIC | USA |
  225. | 72.14.189.120 | OpenNIC | USA |
  226. | 194.145.226.26 | PowerNS | Germany |
  227. | 77.220.232.44 | PowerNS | Germany |
  228. | 78.46.89.147 | ValiDOM | Germany |
  229. | 88.198.75.145 | ValiDOM | Germany |
  230. | 85.25.149.144 | Freie Unzensierte Nameserver | Germany |
  231. | 87.106.37.196 | Freie Unzensierte Nameserver | Germany |
  232. | 209.59.210.167 | Christoph Hochstätter | USA |
  233. | 85.214.117.11 | Christoph Hochstätter | Germany |
  234. | 83.243.5.253 | private | Germany |
  235. | 88.198.130.211 | private | Germany |
  236. | 85.10.211.244 | private | Germany |
  237. CTRL-o followed by ENTER to save, then CTRL-x to exit.
  238. Now disconnect the BBB from your computer and plug it into the router. You'll need an ethernet patch cable and you may also need a 5V/1A power supply for the BBB.
  239. If you go to the web administration screen for your internet router (often it's on 192.168.2.1 or 192.168.1.254) then after a few minutes you should see the BBB appear on the network. It's name will be "arm".
  240. If you're using a Cubieboard:
  241. #+BEGIN_SRC: bash
  242. nano /etc/apt/sources.list
  243. #+END_SRC
  244. Delete the existing sources and replace them with the sources [[Example software sources][listed here]], then save and exit. If you use the default Cubian software sources then dependency problems will occur later on.
  245. ** Add a user
  246. Ssh back in to the BBB and login as root. In this example the BBB's IP address is 192.168.1.60.
  247. #+BEGIN_SRC: bash
  248. ssh-keygen -f "/home/myusername/.ssh/known_hosts" -R 192.168.1.60
  249. ssh debian@192.168.1.60
  250. su
  251. #+END_SRC
  252. Then make a new user. It's a bad idea to add users to the sudo group, because that then means that an attacker potentially only needs to know one password in order to get administrator access to the system. With no sudoers an attacker needs to know, or be able to obtain, two separate passwords to be able to really compromise the system.
  253. #+BEGIN_SRC: bash
  254. adduser myusername
  255. #+END_SRC
  256. Exit from the ssh login by typing "exit" a couple of times, then ssh back in as the new user. Make sure you use a difficult to guess password/phrase, or ideally a randomly generated password used together with a password manager such as KeepassX.
  257. Remove the default debian user.
  258. #+BEGIN_SRC: bash
  259. userdel -r debian
  260. #+END_SRC
  261. ** Text editor
  262. For an editor which is less erratic than vi when used within a remote console such as Terminator.
  263. #+BEGIN_SRC: bash
  264. apt-get update
  265. apt-get install emacs24
  266. update-alternatives --set editor /usr/bin/emacs24
  267. #+END_SRC
  268. Some basic Emacs keys which will be useful to new users are:
  269. | Load a file | CTRL-x CTRL-f |
  270. | Save | CTRL-x CTRL-s |
  271. | Exit | CTRL-x CTRL-c |
  272. If you need an example Emacs configuration file to get you going then one can be [[Emacs setup][found here]].
  273. ** Remove proprietary repositories
  274. By default the Debian operating system includes references to a repository which can be used to install some proprietary software. Because the source code of proprietary software cannot be independently audited or patched it could contain malicious backdoors or malware, or more likely because it's unmaintainable it could just be old and out of date and so may contain security vulnerabilities which the Surveillance State can make use of via its [[https://en.wikipedia.org/wiki/FOXACID][automated exploit delivery system]]. It's a good idea to remove those repositories as follows, so that the software from them can't be installed by accident:
  275. #+BEGIN_SRC: bash
  276. editor /etc/apt/sources.list
  277. #+END_SRC
  278. Then remove any references to *non-free*, save and exit. With that done you can be sure that all the software on your system is [[https://en.wikipedia.org/wiki/Free_and_open_source_software][FOSS]], and so can be checked, updated or customized as necessary.
  279. ** Enable backports
  280. To enable some newer packages add backports to the repositories.
  281. #+BEGIN_SRC: bash
  282. echo "deb http://ftp.us.debian.org/debian jessie-backports main" >> /etc/apt/sources.list
  283. apt-get update
  284. apt-get dist-upgrade
  285. apt-get install ca-certificates
  286. #+END_SRC
  287. ** Configure your location/language
  288. Not everybody lives in the US or Europe. You may want to change your location and language settings accordingly.
  289. #+BEGIN_SRC: bash
  290. dpkg-reconfigure locales
  291. apt-get install keyboard-configuration
  292. reboot
  293. #+END_SRC
  294. After reboot is complete ssh back in as the root user, then to verify the change.
  295. #+BEGIN_SRC: bash
  296. locale -a
  297. #+END_SRC
  298. Set your time zone with:
  299. #+BEGIN_SRC: bash
  300. tzselect
  301. #+END_SRC
  302. For example, for British time:
  303. #+BEGIN_SRC: bash
  304. export TZ='Europe/London'
  305. echo "export TZ='Europe/London'" >> ~/.bashrc
  306. echo "export TZ='Europe/London'" >> /home/myusername/.bashrc
  307. #+END_SRC
  308. ** Upgrade the kernel
  309. Using a more recent kernel should improve stability of the system and also allow it to make use of hardware random number generation, which improves the overall security. Please note that this kernel is specific to the BBB, so if you're using a Raspberry Pi, Cubieboard or other SBC then look elsewhere on the web for information about upgrading the kernel. Newer kernels are also available at http://rcn-ee.net/deb/jessie-armhf ("bone" in the name indicates kernels with BBB specific patches).
  310. #+BEGIN_SRC: bash
  311. cd /opt/scripts/tools
  312. ./update_kernel.sh --kernel v3.15.10-bone7
  313. reboot
  314. #+END_SRC
  315. After the system has rebooted you can ssh back unto it and log in as the root user. You can check that the kernel version has changed with the command:
  316. #+BEGIN_SRC: bash
  317. uname -mrs
  318. #+END_SRC
  319. Note: If you're upgrading to any other kernel version and the BBB fails to reboot, with lights continuously on, then remove power, take out the microSD, insert it into your laptop then do something like "*sudo emacs /media/$USER/rootfs/boot/uEnv.txt*" and change the kernel version to the previous one which you were using, then eject the microSD drive, re-insert it into the BBB and re-apply power.
  320. Now enable zram.
  321. #+BEGIN_SRC: bash
  322. editor /etc/modprobe.d/zram.conf
  323. #+END_SRC
  324. Add the following:
  325. #+BEGIN_SRC: bash
  326. options zram num_devices=1
  327. #+END_SRC
  328. Save and exit, then create an initialisation script.
  329. #+BEGIN_SRC: bash
  330. editor /etc/init.d/zram
  331. #+END_SRC
  332. Add the following:
  333. #+BEGIN_SRC: bash
  334. #!/bin/bash
  335. ### BEGIN INIT INFO
  336. # Provides: zram
  337. # Required-Start:
  338. # Required-Stop:
  339. # Default-Start: 2 3 4 5
  340. # Default-Stop: 0 1 6
  341. # Short-Description: Increased Performance In Linux With zRam (Virtual Swap Compressed in RAM)
  342. # Description: Adapted from systemd scripts at https://github.com/mystilleef/FedoraZram
  343. ### END INIT INFO
  344. start() {
  345. # get the number of CPUs
  346. num_cpus=$(grep -c processor /proc/cpuinfo)
  347. # if something goes wrong, assume we have 1
  348. [ "$num_cpus" != 0 ] || num_cpus=1
  349. # set decremented number of CPUs
  350. decr_num_cpus=$((num_cpus - 1))
  351. # get the amount of memory in the machine
  352. mem_total_kb=$(grep MemTotal /proc/meminfo | grep -E --only-matching '[[:digit:]]+')
  353. mem_total=$((mem_total_kb * 1024))
  354. # load dependency modules
  355. modprobe zram num_devices=$num_cpus
  356. # initialize the devices
  357. for i in $(seq 0 $decr_num_cpus); do
  358. echo $((mem_total / num_cpus)) > /sys/block/zram$i/disksize
  359. done
  360. # Creating swap filesystems
  361. for i in $(seq 0 $decr_num_cpus); do
  362. mkswap /dev/zram$i
  363. done
  364. # Switch the swaps on
  365. for i in $(seq 0 $decr_num_cpus); do
  366. swapon -p 100 /dev/zram$i
  367. done
  368. }
  369. stop() {
  370. # get the number of CPUs
  371. num_cpus=$(grep -c processor /proc/cpuinfo)
  372. # set decremented number of CPUs
  373. decr_num_cpus=$((num_cpus - 1))
  374. # Switching off swap
  375. for i in $(seq 0 $decr_num_cpus); do
  376. if [ "$(grep /dev/zram$i /proc/swaps)" != "" ]; then
  377. swapoff /dev/zram$i
  378. sleep 1
  379. fi
  380. done
  381. sleep 1
  382. rmmod zram
  383. }
  384. case "$1" in
  385. start)
  386. start
  387. ;;
  388. stop)
  389. stop
  390. ;;
  391. restart)
  392. stop
  393. sleep 3
  394. start
  395. ;;
  396. *)
  397. echo "Usage: $0 {start|stop|restart}"
  398. RETVAL=1
  399. esac
  400. exit $RETVAL
  401. #+END_SRC
  402. Save and exit.
  403. #+BEGIN_SRC: bash
  404. chmod +x /etc/init.d/zram
  405. update-rc.d zram defaults
  406. service zram start
  407. reboot
  408. #+END_SRC
  409. After the system has rebooted ssh back into it and become the root user, then to check that the changes were successful:
  410. #+BEGIN_SRC: bash
  411. dmesg | grep zram
  412. #+END_SRC
  413. Should show something like:
  414. #+BEGIN_SRC: bash
  415. [ 507.322337] zram: Created 1 device(s) ...
  416. [ 507.651151] Adding 505468k swap on /dev/zram0. Priority:100 extents:1 across:505468k SS
  417. #+END_SRC
  418. ** Random number generation
  419. #+BEGIN_VERSE
  420. /Near as I can tell, the answer on what has been requested is everything: deliberate weakenings of encryption algorithms, deliberate weakenings of random number generations, copies of master keys, encryption of the session key with an NSA-specific key … everything./
  421. -- Bruce Schneier, on the 2013 leaked NSA documents
  422. #+END_VERSE
  423. The security of encryption depends upon the randomness of the random source used on your system. If it isn't very random then it may be far more vulnerable to cryptanalysis, and it's known that in the past some dubious agencies have encouraged the use of flawed random number generators to assist with their prurient activities. Randomness - typically referred to as /entropy/ - is often gathered from factors such as the timing of key presses or mouse movements, but since the BBB won't have such devices plugged into it this reduces the amount of entropy available.
  424. *** On the Beaglebone Black
  425. Computers can't really generate truly random numbers by themselves, since they're deterministic and so operate in a highly predictable manner. Fortunately, the BBB has an onboard hardware random number generator, which is a physical process which behaves randomly and which can then be read into the computer and stored for later use in encryption algorithms.
  426. Information on exactly how the hardware random number generator on the Beaglebone AM335x CPU works [[http://e2e.ti.com/support/arm/sitara_arm/f/791/t/292794.aspx][seems hard to come by]], but we can later use some software to verify that it does indeed produce random numbers and hasn't been deliberately weakened.
  427. If you are using a Beaglebone and have updated the kernel then install:
  428. #+BEGIN_SRC: bash
  429. apt-get install rng-tools
  430. editor /etc/default/rng-tools
  431. #+END_SRC
  432. Uncomment *HRNGDEVICE=/dev/hwrng*, save and exit then restart the daemon.
  433. #+BEGIN_SRC: bash
  434. service rng-tools restart
  435. #+END_SRC
  436. Your BBB will now use hardware to generate random numbers.
  437. *** On other Single Board Computers
  438. If you are not using a Beaglebone (a Cubieboard for example), or if you didn't update the kernel, then you can still improve the random number generation by installing:
  439. #+BEGIN_SRC: bash
  440. apt-get install haveged
  441. #+END_SRC
  442. *** Verifying random number quality
  443. #+BEGIN_VERSE
  444. /Living in a surveillance state is exactly like being guilty until proven guilty./
  445. -- Mohammad Tarakiyee
  446. #+END_VERSE
  447. You can check how much randomness (entropy) is available with:
  448. #+BEGIN_SRC: bash
  449. cat /proc/sys/kernel/random/entropy_avail
  450. #+END_SRC
  451. Ideally it should be in the range 1000-4096. If it is persistently below 500 then there may be a problem with your system which could make it less secure.
  452. To verify that random number generation is good on the BBB run:
  453. #+BEGIN_SRC: bash
  454. cat /dev/hwrng | rngtest -c 1000
  455. #+END_SRC
  456. You should see something like this, with zero or a small number of failures:
  457. #+BEGIN_SRC: bash
  458. rngtest: starting FIPS tests...
  459. rngtest: bits received from input: 20000032
  460. rngtest: FIPS 140-2 successes: 1000
  461. rngtest: FIPS 140-2 failures: 0
  462. rngtest: FIPS 140-2(2001-10-10) Monobit: 0
  463. rngtest: FIPS 140-2(2001-10-10) Poker: 0
  464. rngtest: FIPS 140-2(2001-10-10) Runs: 0
  465. rngtest: FIPS 140-2(2001-10-10) Long run: 0
  466. rngtest: FIPS 140-2(2001-10-10) Continuous run: 0
  467. rngtest: input channel speed: (min=3.104; avg=26.015; max=18.626)Gibits/s
  468. rngtest: FIPS tests speed: (min=160.281; avg=165.696; max=168.792)Mibits/s
  469. rngtest: Program run time: 115987 microseconds
  470. #+END_SRC
  471. *** Cryptotronix Hashlet
  472. #+BEGIN_VERSE
  473. /One must acknowledge with cryptography no amount of violence will ever solve a math problem./
  474. -- Jacob Appelbaum
  475. #+END_VERSE
  476. An optional extra is the [[http://cryptotronix.com/products/hashlet/][Cryptotronix Hashlet]] which also has hardware random number generation capability via the [[./Atmel-8740-CryptoAuth-ATSHA204-Datasheet.pdf][Atmel ATSHA204]] chip.
  477. Install the hashlet [[./images/hashlet_installed.jpg][like this]] on the BBB, then install some dependencies.
  478. #+BEGIN_SRC: bash
  479. apt-get install git automake libtool bison flex build-essential libgcrypt11-dev texinfo
  480. #+END_SRC
  481. Download the source code.
  482. #+BEGIN_SRC: bash
  483. mkdir ~/build
  484. cd ~/build
  485. git clone https://github.com/cryptotronix/hashlet
  486. #+END_SRC
  487. Now install the driver.
  488. #+BEGIN_SRC: bash
  489. cd hashlet
  490. chmod o+rw /dev/i2c*
  491. ./autogen.sh
  492. make check
  493. make install
  494. #+END_SRC
  495. To check the initial state of the device:
  496. #+BEGIN_SRC: bash
  497. hashlet --bus=/dev/i2c-2 state
  498. #+END_SRC
  499. It should return the message "/Factory/". This is intended to provide an indication that the hardware hasn't been tampered with by [[https://en.wikipedia.org/wiki/Tailored_Access_Operations][TAO]] or other shady outfits in transit. If /i2c-2/ fails then try /i2c-1/ or /i2c-0/.
  500. #+BEGIN_SRC: bash
  501. hashlet --bus=/dev/i2c-2 personalize
  502. #+END_SRC
  503. Nothing should be returned by this command, but a file called ~/.hashlet will be generated which is the private key of the device. This personalization process is a one-time operation which physically alters the hardware, so it would not be trivial to reset the device back to "Factory" again. To make sure it's only accessible by the root user:
  504. #+BEGIN_SRC: bash
  505. chmod 400 ~/.hashlet
  506. #+END_SRC
  507. Now create a daemon which will create a random number generator device */dev/hashletrng*.
  508. #+BEGIN_SRC: bash
  509. editor /usr/bin/hashletd
  510. #+END_SRC
  511. #+BEGIN_SRC: bash
  512. #!/bin/sh
  513. PATH='/usr/local/sbin:/usr/local/bin:/usr/bin:/sbin:/usr/sbin:/bin'
  514. I2CBUS=2
  515. BYTES=32
  516. DEVICE=/dev/hashletrng
  517. # create a device
  518. if [ ! -e ${DEVICE} ]; then
  519. chmod o+rw /dev/i2c*
  520. mknod ${DEVICE} p
  521. fi
  522. while :
  523. do
  524. /usr/local/bin/hashlet --bus=/dev/i2c-${I2CBUS} random ${BYTES} > ${DEVICE}
  525. done
  526. #+END_SRC
  527. Save and exit. Now create an init script to run it.
  528. #+BEGIN_SRC: bash
  529. editor /etc/init.d/hashlet
  530. #+END_SRC
  531. Add the following:
  532. #+BEGIN_SRC: bash
  533. #!/bin/bash
  534. # /etc/init.d/hashlet
  535. ### BEGIN INIT INFO
  536. # Provides: hashlet
  537. # Required-Start: $remote_fs $syslog
  538. # Required-Stop: $remote_fs $syslog
  539. # Default-Start: 2 3 4 5
  540. # Default-Stop: 0 1 6
  541. # Short-Description: hashlet
  542. # Description: Creates a random number generator device
  543. ### END INIT INFO
  544. # Author: Bob Mottram <bob@robotics.uk.to>
  545. #Settings
  546. SERVICE='hashlet'
  547. LOGFILE='/dev/null'
  548. COMMAND="/usr/bin/hashletd"
  549. USERNAME='root'
  550. NICELEVEL=19
  551. HISTORY=1024
  552. INVOCATION="nice -n ${NICELEVEL} ${COMMAND}"
  553. PATH='/usr/local/sbin:/usr/local/bin:/usr/bin:/sbin:/usr/sbin:/bin'
  554. hashlet_start() {
  555. echo "Starting $SERVICE..."
  556. su --command "screen -h ${HISTORY} -dmS ${SERVICE} ${INVOCATION}" $USERNAME
  557. }
  558. hashlet_stop() {
  559. echo "Stopping $SERVICE"
  560. su --command "screen -p 0 -S ${SERVICE} -X stuff "'^C'"" $USERNAME
  561. }
  562. #Start-Stop here
  563. case "$1" in
  564. start)
  565. hashlet_start
  566. ;;
  567. stop)
  568. hashlet_stop
  569. ;;
  570. restart)
  571. hashlet_stop
  572. sleep 10s
  573. hashlet_start
  574. ;;
  575. *)
  576. echo "Usage: $0 {start|stop|restart}"
  577. exit 1
  578. ;;
  579. esac
  580. exit 0
  581. #+END_SRC
  582. Save and exit, then start the daemon.
  583. #+BEGIN_SRC: bash
  584. chmod +x /usr/bin/hashletd
  585. chmod +x /etc/init.d/hashlet
  586. update-rc.d hashlet defaults
  587. service hashlet start
  588. #+END_SRC
  589. Then to obtain some random bytes:
  590. #+BEGIN_SRC: bash
  591. cat /dev/hashletrng
  592. #+END_SRC
  593. The rate of entropy generation by the Hashlet seems very slow compared to */dev/hwrng*, and this is most likely because of the I2C interface. So it's probably a good idea to keep hwrng as the main random source and only use the Hashlet's random number generator for any ancillary stuff.
  594. ** Alter ssh configuration
  595. #+BEGIN_VERSE
  596. /The privacy rights of US persons in international communications are significantly diminished, if not completely eliminated, when those communications have been transmitted to or obtained from non-US persons located outside the United States./
  597. -- US Department Of Justice
  598. #+END_VERSE
  599. Altering the ssh configuration will make it a little more secure than the standard Debian settings.
  600. #+BEGIN_SRC: bash
  601. editor /etc/ssh/sshd_config
  602. #+END_SRC
  603. Check the following values:
  604. #+BEGIN_SRC: bash
  605. PermitRootLogin no
  606. X11Forwarding no
  607. ServerKeyBits 4096
  608. Protocol 2
  609. PermitEmptyPasswords no
  610. StrictModes yes
  611. TCPKeepAlive no
  612. #+END_SRC
  613. Comment out:
  614. #+BEGIN_SRC: bash
  615. #HostKey /etc/ssh/ssh_host_dsa_key
  616. #HostKey /etc/ssh/ssh_host_ecdsa_key
  617. #+END_SRC
  618. Append the following:
  619. #+BEGIN_SRC: bash
  620. ClientAliveInterval 60
  621. ClientAliveCountMax 3
  622. Ciphers aes256-ctr,aes128-ctr
  623. MACs hmac-sha2-512,hmac-sha2-256,hmac-ripemd160
  624. KexAlgorithms diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1
  625. #+END_SRC
  626. Save and exit. Now clear out any pre-existing host keys and reconfigure the ssh server.
  627. #+BEGIN_SRC: bash
  628. rm /etc/ssh/ssh_host_*
  629. dpkg-reconfigure openssh-server
  630. service ssh restart
  631. #+END_SRC
  632. To test the new settings log out by typing "exit" a couple of times, then log back in again with:
  633. #+BEGIN_SRC: bash
  634. ssh -vvv myusername@192.168.1.60
  635. #+END_SRC
  636. and check that some number of bits are set within a 4096 bit sized key:
  637. #+BEGIN_SRC: bash
  638. debug2: bits set: */4096
  639. #+END_SRC
  640. ** Install CPU limiter
  641. #+BEGIN_VERSE
  642. /On every side, and at every hour of the day, we came up against the relentless limitations of pioneer life./
  643. -- Anna Howard Shaw
  644. #+END_VERSE
  645. Some process may consume a lot of CPU power and cause the system to become unresponsive or to crash. To avoid that it's possible to limit the maximum percentage of the CPU which processes can use. We can whitelist some editors and tools that are commonly used and which have an initial CPU spike (such as Emacs loading its configuration files), with everything else being subject to a CPU limit if usage goes above a threshold percentage for more than one second.
  646. #+BEGIN_SRC: bash
  647. apt-get install cpulimit gawk
  648. #+END_SRC
  649. Create a script which can be run as a daemon.
  650. #+BEGIN_SRC: bash
  651. editor /usr/bin/cpulimit_daemon.sh
  652. #+END_SRC
  653. Add the following:
  654. #+BEGIN_SRC: bash
  655. #!/bin/bash
  656. # ==============================================================
  657. # CPU limit daemon - set PID's max. percentage CPU consumptions
  658. # ==============================================================
  659. # Variables
  660. CPU_LIMIT=50 # Maximum percentage CPU consumption by each PID
  661. DAEMON_INTERVAL=1 # Daemon check interval in seconds
  662. BLACK_PROCESSES_LIST= # Limit only processes defined in this variable. If variable is empty (default) all violating processes are limited.
  663. WHITE_PROCESSES_LIST="cron|top|emacs|vi|vim|nano" # Limit all processes except processes defined in this variable. If variable is empty (default) all violating processes are limited.
  664. # Check if one of the variables BLACK_PROCESSES_LIST or WHITE_PROCESSES_LIST is defined.
  665. if [[ -n "$BLACK_PROCESSES_LIST" && -n "$WHITE_PROCESSES_LIST" ]] ; then # If both variables are defined then error is produced.
  666. echo "At least one or both of the variables BLACK_PROCESSES_LIST or WHITE_PROCESSES_LIST must be empty."
  667. exit 1
  668. elif [[ -n "$BLACK_PROCESSES_LIST" ]] ; then # If this variable is non-empty then set NEW_PIDS_COMMAND variable to bellow command
  669. NEW_PIDS_COMMAND="top -b -n1 -c | grep -E '$BLACK_PROCESSES_LIST' | gawk '\$9>CPU_LIMIT {print \$1}' CPU_LIMIT=$CPU_LIMIT"
  670. elif [[ -n "$WHITE_PROCESSES_LIST" ]] ; then # If this variable is non-empty then set NEW_PIDS_COMMAND variable to bellow command
  671. NEW_PIDS_COMMAND="top -b -n1 -c | gawk 'NR>6' | grep -E -v '$WHITE_PROCESSES_LIST' | gawk '\$9>CPU_LIMIT {print \$1}' CPU_LIMIT=$CPU_LIMIT"
  672. else
  673. NEW_PIDS_COMMAND="top -b -n1 -c | gawk 'NR>6 && \$9>CPU_LIMIT {print \$1}' CPU_LIMIT=$CPU_LIMIT"
  674. fi
  675. # Search and limit violating PIDs
  676. while sleep $DAEMON_INTERVAL
  677. do
  678. NEW_PIDS=$(eval "$NEW_PIDS_COMMAND") # Violating PIDs
  679. LIMITED_PIDS=$(ps -eo args | gawk '$1=="cpulimit" {print $3}') # Already limited PIDs
  680. QUEUE_PIDS=$(comm -23 <(echo "$NEW_PIDS" | sort -u) <(echo "$LIMITED_PIDS" | sort -u) | grep -v '^$') # PIDs in queue
  681. # These can be uncommented for debugging purposes
  682. # echo "DAEMON_INTERVAL: " $DAEMON_INTERVAL
  683. # echo "CPU_LIMI: " $CPU_LIMIT
  684. # echo "NEW_PIDS: " $NEW_PIDS
  685. # echo "LIMITED_PIDS: " $LIMITED_PIDS
  686. # echo "QUEUE_PIDS: " $QUEUE_PIDS
  687. for i in $QUEUE_PIDS
  688. do
  689. cpulimit -p $i -l $CPU_LIMIT -z & # Limit new violating processes
  690. done
  691. done
  692. #+END_SRC
  693. Save and exit.
  694. #+BEGIN_SRC: bash
  695. chmod +x /usr/bin/cpulimit_daemon.sh
  696. editor /etc/init.d/cpulimit
  697. #+END_SRC
  698. Add the following:
  699. #+BEGIN_SRC: bash
  700. #!/bin/sh
  701. # /etc/init.d/cpulimit
  702. ### BEGIN INIT INFO
  703. # Provides: cpulimit
  704. # Required-Start: $remote_fs $syslog
  705. # Required-Stop: $remote_fs $syslog
  706. # Default-Start: 2 3 4 5
  707. # Default-Stop: 0 1 6
  708. # Short-Description: Limits CPU use by processes
  709. # Description: Limits CPU use by processes
  710. ### END INIT INFO
  711. # Author: Bob Mottram <bob@robotics.uk.to>
  712. set -e
  713. case "$1" in
  714. start)
  715. if [ $(ps -eo pid,args | gawk '$3=="/usr/bin/cpulimit_daemon.sh" {print $1}' | wc -l) -eq 0 ]; then
  716. nohup /usr/bin/cpulimit_daemon.sh >/dev/null 2>&1 &
  717. ps -eo pid,args | gawk '$3=="/usr/bin/cpulimit_daemon.sh" {print}' | wc -l | gawk '{ if ($1 == 1) print " * cpulimit daemon started successfully"; else print " * cpulimit daemon can not be started" }'
  718. else
  719. echo " * cpulimit daemon can't be started, because it is already running"
  720. fi
  721. ;;
  722. stop)
  723. CPULIMIT_DAEMON=$(ps -eo pid,args | gawk '$3=="/usr/bin/cpulimit_daemon.sh" {print $1}' | wc -l)
  724. CPULIMIT_INSTANCE=$(ps -eo pid,args | gawk '$2=="cpulimit" {print $1}' | wc -l)
  725. CPULIMIT_ALL=$((CPULIMIT_DAEMON + CPULIMIT_INSTANCE))
  726. if [ $CPULIMIT_ALL -gt 0 ]; then
  727. if [ $CPULIMIT_DAEMON -gt 0 ]; then
  728. ps -eo pid,args | gawk '$3=="/usr/bin/cpulimit_daemon.sh" {print $1}' | xargs kill -9 # kill cpulimit daemon
  729. fi
  730. if [ $CPULIMIT_INSTANCE -gt 0 ]; then
  731. ps -eo pid,args | gawk '$2=="cpulimit" {print $1}' | xargs kill -9 # release cpulimited process to normal priority
  732. fi
  733. ps -eo pid,args | gawk '$3=="/usr/bin/cpulimit_daemon.sh" {print}' | wc -l | gawk '{ if ($1 == 1) print " * cpulimit daemon can not be stopped"; else print " * cpulimit daemon stopped successfully" }'
  734. else
  735. echo " * cpulimit daemon can't be stopped, because it is not running"
  736. fi
  737. ;;
  738. restart)
  739. $0 stop
  740. sleep 3
  741. $0 start
  742. ;;
  743. status)
  744. ps -eo pid,args | gawk '$3=="/usr/bin/cpulimit_daemon.sh" {print}' | wc -l | gawk '{ if ($1 == 1) print " * cpulimit daemon is running"; else print " * cpulimit daemon is not running" }'
  745. ;;
  746. esac
  747. exit 0
  748. #+END_SRC
  749. Save and exit.
  750. #+BEGIN_SRC: bash
  751. chmod +x /etc/init.d/cpulimit
  752. update-rc.d cpulimit defaults
  753. service cpulimit start
  754. #+END_SRC
  755. ** Getting onto the web
  756. Create a subdomain on [[http://freedns.afraid.org][freeDNS]]. You may need to click on "/subdomains/" a couple of times. FreeDNS is preferred because it is one of the few domain name providers which supports genuinely free (as in beer) accounts. So if your budget is tiny or non-existent you can still participate as a first class citizen of the internet. If you do have money to spend there is also a premium option.
  757. Select "/dynamic DNS/" then click "/quick cron example/"
  758. An example would look like:
  759. #+BEGIN_SRC: bash
  760. 4,14,24,34,44,54 * * * * root sleep 29 ; /usr/bin/timeout 200 wget -O - https://free\ dns.afraid.org/dynamic/update.php?ABCKDNRCLFHENSLKNFEGSBFLFF== >> /dev/null 2>&1 &
  761. #+END_SRC
  762. It's important to make sure that you change the *http* to *https*, since this will help to prevent a potential attacker from hijacking your site and redirecting it to a fake version for the purposes of obtaining your login details.
  763. Edit */etc/crontab* and append that to the top of the file, underneath the heading line which looks like this:
  764. #+BEGIN_SRC: bash
  765. # m h dom mon dow user command
  766. #+END_SRC
  767. In general the most frequently run crontab entries should be at the top. Then save and exit.
  768. Via your router's firewall settings you should now open port 22 (secure shell). This will allow you to ssh into your BBB from any location - not just your own local network.
  769. The freeDNS subdomain which you just created will hereafter just be refered to as "/your domain name/".
  770. If you have multiple freedns subdomains then you may want to rationalise that a little within */etc/crontab*. Rather than listing them all individually create a script:
  771. #+BEGIN_SRC: bash
  772. editor /usr/bin/dynamicdns
  773. #+END_SRC
  774. Add however many freedns subdomains you have.
  775. #+BEGIN_SRC: bash
  776. #!/bin/bash
  777. # subdomain name 1
  778. wget -O - https://freedns.afraid.org/dynamic/update.php?<subdomain code 1>== >> /dev/null 2>&1
  779. # subdomain name 2
  780. wget -O - https://freedns.afraid.org/dynamic/update.php?<subdomain code 2>== >> /dev/null 2>&1
  781. ...
  782. #+END_SRC
  783. Save and exit, then make the script runnable and only readable by the root user.
  784. #+BEGIN_SRC: bash
  785. chmod 600 /usr/bin/dynamicdns
  786. chmod +x /usr/bin/dynamicdns
  787. #+END_SRC
  788. Then within */etc/crontab*
  789. #+BEGIN_SRC: bash
  790. editor /etc/crontab
  791. #+END_SRC
  792. You can replace the multiple freedns entries with a single line:
  793. #+BEGIN_SRC: bash
  794. */5 * * * * root /usr/bin/timeout 240 /usr/bin/dynamicdns
  795. #+END_SRC
  796. Then save and exit and restart the cron daemon.
  797. #+BEGIN_SRC: bash
  798. service cron restart
  799. #+END_SRC
  800. If you want to know what a typical /crontab/ file might look like then see the [[Example crontab file]]
  801. ** Set the host name
  802. #+BEGIN_SRC: bash
  803. editor /etc/hostname
  804. #+END_SRC
  805. Save and exit.
  806. Also issue the command, replacing /mydomainname.com/ with your domain name.
  807. #+BEGIN_SRC: bash
  808. hostname mydomainname.com
  809. #+END_SRC
  810. You may also need to assign the same hostname separately via your router's web interface.
  811. #+BEGIN_SRC: bash
  812. editor /etc/hosts
  813. #+END_SRC
  814. Append the following, replacing /mydomainname.com/ with your domain name.
  815. #+BEGIN_SRC: bash
  816. 127.0.1.1 mydomainname.com
  817. #+END_SRC
  818. If you then run the command:
  819. #+BEGIN_SRC: bash
  820. hostname -f
  821. #+END_SRC
  822. it should return your domain name.
  823. ** Install time synchronisation
  824. #+BEGIN_VERSE
  825. /You may delay, but time will not./
  826. -- Benjamin Franklin
  827. #+END_VERSE
  828. It's convenient to have the clock on your server automatically synchronised with other servers on the internet so that you don't need to set the clock manually. The usual way of doing this is via [[https://en.wikipedia.org/wiki/Network_Time_Protocol][NTP]], but that method uses unencrypted signals which could potentially be interfered with in order to mess up your system. /tlsdate/ provides a slightly more secure way of setting the date and time over a SSL/TLS connection to a known good time source.
  829. First install some prerequisites.
  830. #+BEGIN_SRC: bash
  831. apt-get install build-essential automake git pkg-config autoconf libtool libssl-dev
  832. apt-get remove ntpdate
  833. #+END_SRC
  834. Now download and install tlsdate.
  835. #+BEGIN_SRC: bash
  836. mkdir ~/build
  837. cd ~/build
  838. git clone https://github.com/ioerror/tlsdate.git
  839. cd ~/build/tlsdate
  840. ./autogen.sh
  841. ./configure
  842. make
  843. make install
  844. #+END_SRC
  845. If you get errors during the /configure/ stage then you may need to reboot so that some of the installed dependencies take effect.
  846. #+BEGIN_SRC: bash
  847. editor /usr/bin/updatedate
  848. #+END_SRC
  849. Add the following, changing /username@mydomainname.com/ to your email address:
  850. #+BEGIN_SRC: bash
  851. #!/bin/bash
  852. TIMESOURCE=google.com
  853. TIMESOURCE2=www.ptb.de
  854. LOGFILE=/var/log/tlsdate.log
  855. TIMEOUT=5
  856. EMAIL=username@mydomainname.com
  857. # File which contains the previous date as a number
  858. BEFORE_DATE_FILE=/var/log/tlsdateprevious.txt
  859. # File which contains the previous date as a string
  860. BEFORE_FULLDATE_FILE=/var/log/tlsdate.txt
  861. DATE_BEFORE=$(date)
  862. BEFORE=$(date -d "$Y-$M-$D" '+%s')
  863. BACKWARDS_BETWEEN=0
  864. # If the date was previously set
  865. if [[ -f "$BEFORE_DATE_FILE" ]]; then
  866. BEFORE_FILE=$(cat $BEFORE_DATE_FILE)
  867. BEFORE_FULLDATE=$(cat $BEFORE_FULLDATE_FILE)
  868. # is the date going backwards?
  869. if (( BEFORE_FILE > BEFORE )); then
  870. echo -n "Date went backwards between tlsdate updates. " \
  871. >> $LOGFILE
  872. echo -n "$BEFORE_FILE > $BEFORE, " >> $LOGFILE
  873. echo "$BEFORE_FULLDATE > $DATE_BEFORE" >> $LOGFILE
  874. # Send a warning email
  875. echo $(tail $LOGFILE -n 2) | mail -s "tlsdate anomaly" $EMAIL
  876. # Try another time source
  877. TIMESOURCE=$TIMESOURCE2
  878. # try running without any parameters
  879. tlsdate >> $LOGFILE
  880. BACKWARDS_BETWEEN=1
  881. fi
  882. fi
  883. # Set the date
  884. /usr/bin/timeout $TIMEOUT tlsdate -l -t -H $TIMESOURCE -p 443 >> $LOGFILE
  885. DATE_AFTER=$(date)
  886. AFTER=$(date -d "$Y-$M-$D" '+%s')
  887. # After setting the date did it go backwards?
  888. if (( AFTER < BEFORE )); then
  889. echo "Incorrect date: $DATE_BEFORE -> $DATE_AFTER" >> $LOGFILE
  890. # Send a warning email
  891. echo $(tail $LOGFILE -n 2) | mail -s "tlsdate anomaly" $EMAIL
  892. # Try resetting the date from another time source
  893. /usr/bin/timeout $TIMEOUT tlsdate -l -t -H $TIMESOURCE2 -p 443 >> $LOGFILE
  894. DATE_AFTER=$(date)
  895. AFTER=$(date -d "$Y-$M-$D" '+%s')
  896. else
  897. echo -n $TIMESOURCE >> $LOGFILE
  898. if [[ -f "$BEFORE_DATE_FILE" ]]; then
  899. echo -n " " >> $LOGFILE
  900. echo -n $BEFORE_FILE >> $LOGFILE
  901. fi
  902. echo -n " " >> $LOGFILE
  903. echo -n $BEFORE >> $LOGFILE
  904. echo -n " " >> $LOGFILE
  905. echo -n $AFTER >> $LOGFILE
  906. echo -n " " >> $LOGFILE
  907. echo $DATE_AFTER >> $LOGFILE
  908. fi
  909. # Log the last date
  910. if [ BACKWARDS_BETWEEN == 0 ]; then
  911. echo "$AFTER" > $BEFORE_DATE_FILE
  912. echo "$DATE_AFTER" > $BEFORE_FULLDATE_FILE
  913. exit 0
  914. else
  915. exit 1
  916. fi
  917. #+END_SRC
  918. Save and exit.
  919. #+BEGIN_SRC: bash
  920. chmod +x /usr/bin/updatedate
  921. editor /etc/crontab
  922. #+END_SRC
  923. Add the following near the top of the list of tasks.
  924. #+BEGIN_SRC: bash
  925. */15 * * * * root /usr/bin/updatedate
  926. #+END_SRC
  927. Save and exit.
  928. #+BEGIN_SRC: bash
  929. service cron restart
  930. #+END_SRC
  931. This obtains the date and time from www.ptb.de every 15 minutes. Obviously if you wish to use a different source for the date and time then the cron entry can be edited accordingly.
  932. To ensure that the system always gets the correct time on initial bootup create an init script.
  933. #+BEGIN_SRC: bash
  934. editor /etc/init.d/tlsdate
  935. #+END_SRC
  936. Add the following:
  937. #+BEGIN_SRC: bash
  938. #!/bin/bash
  939. # /etc/init.d/tlsdate
  940. ### BEGIN INIT INFO
  941. # Provides: tlsdate
  942. # Required-Start: $remote_fs $syslog
  943. # Required-Stop: $remote_fs $syslog
  944. # Default-Start: 2 3 4 5
  945. # Default-Stop: 0 1 6
  946. # Short-Description: Initially calls tlsdate with the timewarp option
  947. # Description: Initially calls tlsdate with the timewarp option
  948. ### END INIT INFO
  949. # Author: Bob Mottram <bob@robotics.uk.to>
  950. PATH='/usr/local/sbin:/usr/local/bin:/usr/bin:/sbin:/usr/sbin:/bin'
  951. LOGFILE="/var/log/tlsdate.log"
  952. TLSDATECOMMAND="tlsdate --timewarp -l -H www.ptb.de -p 443 >> $LOGFILE"
  953. #Start-Stop here
  954. case "$1" in
  955. start)
  956. echo "tlsdate started"
  957. $TLSDATECOMMAND
  958. ;;
  959. stop)
  960. echo "tlsdate stopped"
  961. ;;
  962. restart)
  963. echo "tlsdate restarted"
  964. $TLSDATECOMMAND
  965. ;;
  966. *)
  967. echo "Usage: $0 {start|stop|restart}"
  968. exit 1
  969. ;;
  970. esac
  971. exit 0
  972. #+END_SRC
  973. Save and exit, then start the daemon.
  974. #+BEGIN_SRC: bash
  975. chmod +x /etc/init.d/tlsdate
  976. update-rc.d tlsdate defaults
  977. service tlsdate start
  978. #+END_SRC
  979. ** Install fail2ban
  980. #+BEGIN_SRC: bash
  981. apt-get install fail2ban
  982. #+END_SRC
  983. ** Set up a firewall
  984. #+BEGIN_VERSE
  985. /The NSA also attacks network devices directly: routers, switches, firewalls, etc. Most of these devices have surveillance capabilities already built in; the trick is to surreptitiously turn them on. This is an especially fruitful avenue of attack; routers are updated less frequently, tend not to have security software installed on them, and are generally ignored as a vulnerability./
  986. -- Bruce Schneier
  987. #+END_VERSE
  988. A basic firewall limits the maximum rate at which connections can be made and closes any unused ports, and this helps to defend against various kinds of DDOS attack. Your internet router may contain a firewall, but chances are that it also contains proprietary software which can be remotely changed/updated by the ISP. Unless you're running free software, such as [[https://en.wikipedia.org/wiki/OpenWrt][OpenWrt]], on your internet router then it's reasonable to assume that the device is hostile and could be conducting surveillance, trying to do [[https://en.wikipedia.org/wiki/Man-in-the-middle_attack]["man in the middle"]] attacks or be pushing "implants" onto the computers and mobile devices on your local network. That means that your server needs its own firewall.
  989. #+BEGIN_SRC: bash
  990. apt-get install portsentry
  991. editor /etc/portsentry/portsentry.conf
  992. #+END_SRC
  993. Uncomment the entry for *iptables support for Linux*
  994. Set the following properties:
  995. #+BEGIN_SRC: bash
  996. TCP_PORTS="1,7,9,11,15,79,109,110,111,119,138,139,512,513,514,515,540,635,1080,1524,2000,2001,3000,4000,4001,5742,6000,6001,6667,12345,12346,20034,27665,30303,32771,32772,32773,32774,31337,40421,40425,49724,54320"
  997. UDP_PORTS="1,7,9,66,67,68,69,111,137,138,161,162,474,513,517,518,635,640,641,666,700,2049,3000,31335,27444,34555,32770,32771,32772,32773,32774,31337,54321"
  998. ADVANCED_EXCLUDE_TCP="113,139,70,80,443,587,143,6697,993,5060,5061,25,465,22,4040,5222,5223,5269,5280,5281,8444"
  999. ADVANCED_EXCLUDE_UDP="520,138,137,67,70,80,443,143,6697,993, 5060,5061,25,465,22,4040,5222,5223,5269,5280,5281,8444"
  1000. SCAN_TRIGGER="2"
  1001. BLOCK_UDP="2"
  1002. BLOCK_TCP="2"
  1003. #+END_SRC
  1004. Save and exit.
  1005. #+BEGIN_SRC: bash
  1006. service portsentry restart
  1007. editor /tmp/firewall.sh
  1008. #+END_SRC
  1009. Enter the following:
  1010. #+BEGIN_SRC: bash
  1011. #!/bin/bash
  1012. # First of all delete any existing rules.
  1013. # This means you're back to a known state:
  1014. iptables -P INPUT ACCEPT
  1015. ip6tables -P INPUT ACCEPT
  1016. iptables -F
  1017. ip6tables -F
  1018. iptables -X
  1019. ip6tables -X
  1020. # Drop any IPv6 traffic
  1021. ip6tables -A INPUT -p icmp -j DROP
  1022. ip6tables -A INPUT -p tcp -j DROP
  1023. ip6tables -A INPUT -p udp -j DROP
  1024. # Drop access to unused ports
  1025. iptables -A INPUT -p tcp --destination-port 1 -j DROP
  1026. iptables -A INPUT -p tcp --destination-port 7 -j DROP
  1027. iptables -A INPUT -p tcp --destination-port 109:111 -j DROP
  1028. iptables -A INPUT -p tcp --destination-port 995 -j DROP
  1029. iptables -A INPUT -p tcp --destination-port 139 -j DROP
  1030. iptables -A INPUT -p tcp --destination-port 6000:6001 -j DROP
  1031. iptables -A INPUT -p tcp --destination-port 9 -j DROP
  1032. iptables -A INPUT -p tcp --destination-port 79 -j DROP
  1033. iptables -A INPUT -p tcp --destination-port 515 -j DROP
  1034. iptables -A INPUT -p tcp --destination-port 4001 -j DROP
  1035. iptables -A INPUT -p tcp --destination-port 1524 -j DROP
  1036. iptables -A INPUT -p tcp --destination-port 1080 -j DROP
  1037. iptables -A INPUT -p tcp --destination-port 512:514 -j DROP
  1038. iptables -A INPUT -p tcp --destination-port 31337 -j DROP
  1039. iptables -A INPUT -p tcp --destination-port 2000:2001 -j DROP
  1040. iptables -A INPUT -p tcp --destination-port 12345 -j DROP
  1041. iptables -A INPUT -p tcp --destination-port 32771:32774 -j DROP
  1042. iptables -A INPUT -p tcp --destination-port 4000 -j DROP
  1043. iptables -A INPUT -p tcp --destination-port 119 -j DROP
  1044. iptables -A INPUT -p tcp --destination-port 137 -j DROP
  1045. iptables -A INPUT -p tcp --destination-port 4242 -j DROP
  1046. iptables -A INPUT -p tcp --destination-port 9050 -j DROP
  1047. iptables -A INPUT -p tcp --destination-port 3000 -j DROP
  1048. iptables -A INPUT -p tcp --destination-port 3306 -j DROP
  1049. iptables -A INPUT -p tcp --destination-port 8432 -j DROP
  1050. iptables -A INPUT -p tcp --destination-port 8433 -j DROP
  1051. iptables -A INPUT -p udp --destination-port 1 -j DROP
  1052. iptables -A INPUT -p udp --destination-port 7 -j DROP
  1053. iptables -A INPUT -p udp --destination-port 109:111 -j DROP
  1054. iptables -A INPUT -p udp --destination-port 995 -j DROP
  1055. iptables -A INPUT -p udp --destination-port 139 -j DROP
  1056. iptables -A INPUT -p udp --destination-port 6000:6001 -j DROP
  1057. iptables -A INPUT -p udp --destination-port 9 -j DROP
  1058. iptables -A INPUT -p udp --destination-port 79 -j DROP
  1059. iptables -A INPUT -p udp --destination-port 515 -j DROP
  1060. iptables -A INPUT -p udp --destination-port 4001 -j DROP
  1061. iptables -A INPUT -p udp --destination-port 1524 -j DROP
  1062. iptables -A INPUT -p udp --destination-port 1080 -j DROP
  1063. iptables -A INPUT -p udp --destination-port 512:514 -j DROP
  1064. iptables -A INPUT -p udp --destination-port 31337 -j DROP
  1065. iptables -A INPUT -p udp --destination-port 2000:2001 -j DROP
  1066. iptables -A INPUT -p udp --destination-port 12345 -j DROP
  1067. iptables -A INPUT -p udp --destination-port 32771:32774 -j DROP
  1068. iptables -A INPUT -p udp --destination-port 6665:6669 -j DROP
  1069. iptables -A INPUT -p udp --destination-port 4000 -j DROP
  1070. iptables -A INPUT -p udp --destination-port 119 -j DROP
  1071. iptables -A INPUT -p udp --destination-port 137 -j DROP
  1072. iptables -A INPUT -p udp --destination-port 8432 -j DROP
  1073. iptables -A INPUT -p udp --destination-port 8433 -j DROP
  1074. iptables -A INPUT -p udp --destination-port 3306 -j DROP
  1075. iptables -A INPUT -p udp --destination-port 4242 -j DROP
  1076. iptables -A INPUT -p udp --destination-port 9050 -j DROP
  1077. iptables -A INPUT -p udp --destination-port 3000 -j DROP
  1078. iptables -A INPUT -p udp --destination-port 8442 -j DROP
  1079. # Make sure NEW incoming tcp connections are SYN packets
  1080. iptables -A INPUT -p tcp ! --syn -m state --state NEW -j DROP
  1081. # Drop packets with incoming fragments
  1082. iptables -A INPUT -f -j DROP
  1083. # Incoming malformed XMAS packets drop them
  1084. iptables -A INPUT -p tcp --tcp-flags ALL ALL -j DROP
  1085. iptables -A INPUT -p tcp --tcp-flags ALL FIN,PSH,URG -j DROP
  1086. iptables -A INPUT -p tcp --tcp-flags ALL SYN,RST,ACK,FIN,URG -j DROP
  1087. # Incoming malformed NULL packets:
  1088. iptables -A INPUT -p tcp --tcp-flags ALL NONE -j DROP
  1089. # Drop UDP to used ports
  1090. iptables -A INPUT -p udp --match multiport --dports 70,80,443,143,6697,993,5060,5061,25 -j DROP
  1091. iptables -A INPUT -p udp --match multiport --dports 465,587,22,5222,5223,5269,5280,5281,8444 -j DROP
  1092. # Limit ssh logins
  1093. iptables -A INPUT -p tcp --dport 22 -m limit --limit 3/minute --limit-burst 1 -j ACCEPT
  1094. # Limit web connections
  1095. iptables -A INPUT -p tcp --dport 80 -m limit --limit 10/minute --limit-burst 1 -j ACCEPT
  1096. iptables -A INPUT -p tcp --dport 443 -m limit --limit 10/minute --limit-burst 1 -j ACCEPT
  1097. # Limit number of XMPP connections
  1098. iptables -A INPUT -p tcp --match multiport --dports 5222:5223,5269,5280:5281 -m limit --limit 3/minute --limit-burst 1 -j ACCEPT
  1099. # Limit IRC connections
  1100. iptables -A INPUT -p tcp --dport 6665:6669 -m limit --limit 3/minute --limit-burst 1 -j ACCEPT
  1101. iptables -A INPUT -p tcp --dport 6697 -m limit --limit 3/minute --limit-burst 1 -j ACCEPT
  1102. # Limit gopher connections
  1103. iptables -A INPUT -p tcp --dport 70 -m limit --limit 3/minute --limit-burst 1 -j ACCEPT
  1104. # Limit IMAP connections
  1105. iptables -A INPUT -p tcp --dport 143 -m limit --limit 3/minute --limit-burst 1 -j ACCEPT
  1106. iptables -A INPUT -p tcp --dport 993 -m limit --limit 3/minute --limit-burst 1 -j ACCEPT
  1107. # Limit Subsonic connections
  1108. iptables -A INPUT -p tcp --dport 4040 -m limit --limit 10/minute --limit-burst 1 -j ACCEPT
  1109. iptables -A INPUT -p udp --dport 4040 -m limit --limit 10/minute --limit-burst 1 -j ACCEPT
  1110. # Limit SIP connections
  1111. iptables -A INPUT -p tcp --dport 5060:5061 -m limit --limit 3/minute --limit-burst 1 -j ACCEPT
  1112. # Limit SMTP/SMTPS connections
  1113. iptables -A INPUT -p tcp --dport 25 -m limit --limit 3/minute --limit-burst 1 -j ACCEPT
  1114. iptables -A INPUT -p tcp --dport 465 -m limit --limit 3/minute --limit-burst 1 -j ACCEPT
  1115. iptables -A INPUT -p tcp --dport 587 -m limit --limit 3/minute --limit-burst 1 -j ACCEPT
  1116. # Limit Bitmessage connections
  1117. iptables -A INPUT -p tcp --dport 8444 -m limit --limit 3/minute --limit-burst 1 -j ACCEPT
  1118. # Limit the number of incoming tcp connections
  1119. # Interface 0 incoming syn-flood protection
  1120. iptables -N syn_flood
  1121. iptables -A INPUT -p tcp --syn -j syn_flood
  1122. iptables -A syn_flood -m limit --limit 1/s --limit-burst 3 -j RETURN
  1123. iptables -A syn_flood -j DROP
  1124. # Limiting the incoming icmp ping request:
  1125. #iptables -A INPUT -p icmp -m limit --limit 1/s --limit-burst 1 -j ACCEPT
  1126. #iptables -A INPUT -p icmp -m limit --limit 1/s --limit-burst 1 -j LOG --log-prefix PING-DROP:
  1127. iptables -A INPUT -p icmp -j DROP
  1128. #iptables -A OUTPUT -p icmp -j ACCEPT
  1129. # Block malware servers (See Der Spiegel Snowden files)
  1130. iptables -A INPUT -s 146.185.26.163 -j DROP
  1131. iptables -A INPUT -s 37.130.229.100 -j DROP
  1132. iptables -A INPUT -s 85.237.211.198 -j DROP
  1133. iptables -A INPUT -s 85.237.212.52 -j DROP
  1134. iptables -A INPUT -s 85.237.211.177 -j DROP
  1135. iptables -A INPUT -s 212.118.232.184 -j DROP
  1136. iptables -A INPUT -s 212.118.232.50 -j DROP
  1137. iptables -A INPUT -s 176.249.28.104 -j DROP
  1138. iptables -A INPUT -s 212.118.232.140 -j DROP
  1139. iptables -A INPUT -s 37.130.229.101 -j DROP
  1140. iptables -A INPUT -s 31.6.17.94 -j DROP
  1141. iptables -A INPUT -s 84.45.121.218 -j DROP
  1142. iptables -A INPUT -s 80.84.63.242 -j DROP
  1143. iptables -A INPUT -s 37.220.10.28 -j DROP
  1144. iptables -A INPUT -s 94.229.78.58 -j DROP
  1145. iptables -A OUTPUT -s 146.185.26.163 -j DROP
  1146. iptables -A OUTPUT -s 37.130.229.100 -j DROP
  1147. iptables -A OUTPUT -s 85.237.211.198 -j DROP
  1148. iptables -A OUTPUT -s 85.237.212.52 -j DROP
  1149. iptables -A OUTPUT -s 85.237.211.177 -j DROP
  1150. iptables -A OUTPUT -s 212.118.232.184 -j DROP
  1151. iptables -A OUTPUT -s 212.118.232.50 -j DROP
  1152. iptables -A OUTPUT -s 176.249.28.104 -j DROP
  1153. iptables -A OUTPUT -s 212.118.232.140 -j DROP
  1154. iptables -A OUTPUT -s 37.130.229.101 -j DROP
  1155. iptables -A OUTPUT -s 31.6.17.94 -j DROP
  1156. iptables -A OUTPUT -s 84.45.121.218 -j DROP
  1157. iptables -A OUTPUT -s 80.84.63.242 -j DROP
  1158. iptables -A OUTPUT -s 37.220.10.28 -j DROP
  1159. iptables -A OUTPUT -s 94.229.78.58 -j DROP
  1160. # Save the settings
  1161. iptables-save > /etc/firewall.conf
  1162. ip6tables-save > /etc/firewall6.conf
  1163. printf '#!/bin/sh\n' > /etc/network/if-up.d/iptables
  1164. printf 'iptables-restore < /etc/firewall.conf\n' >> /etc/network/if-up.d/iptables
  1165. printf 'ip6tables-restore < /etc/firewall6.conf\n' >> /etc/network/if-up.d/iptables
  1166. chmod +x /etc/network/if-up.d/iptables
  1167. #+END_SRC
  1168. Save and exit.
  1169. Note that this will disable IP version 6. At the time of writing it is expected that the average internet user is running on IP version 4.
  1170. #+BEGIN_SRC: bash
  1171. chmod +x /tmp/firewall.sh
  1172. . /tmp/firewall.sh
  1173. rm /tmp/firewall.sh
  1174. #+END_SRC
  1175. Also disable ping. This may be inconvenient to some extent, but it seems common for malicious systems, including but not limited to the [[http://www.nbcnews.com/news/investigations/snowden-docs-british-spies-used-sex-dirty-tricks-n23091][JTRIG "EFFECTS" team]], to try to disable the machine by flooding it with pings. These days there seems to be not much difference between "cybercrime" and nefarious state-sponsored internet activities.
  1176. #+BEGIN_SRC: bash
  1177. editor /etc/sysctl.conf
  1178. #+END_SRC
  1179. Uncomment or change the following:
  1180. #+BEGIN_SRC: bash
  1181. net.ipv4.tcp_syncookies = 1
  1182. net.ipv4.conf.all.accept_redirects = 0
  1183. net.ipv6.conf.all.accept_redirects = 0
  1184. net.ipv4.conf.all.send_redirects = 0
  1185. net.ipv4.conf.all.accept_source_route = 0
  1186. net.ipv6.conf.all.accept_source_route = 0
  1187. net.ipv4.conf.default.rp_filter=1
  1188. net.ipv4.conf.all.rp_filter=1
  1189. net.ipv4.ip_forward=0
  1190. net.ipv6.conf.all.forwarding=0
  1191. #+END_SRC
  1192. And append the following:
  1193. #+BEGIN_SRC: bash
  1194. # ignore pings
  1195. net.ipv4.icmp_echo_ignore_all = 1
  1196. net.ipv6.icmp_echo_ignore_all = 1
  1197. # disable ipv6
  1198. net.ipv6.conf.all.disable_ipv6 = 1
  1199. net.ipv4.tcp_synack_retries = 2
  1200. net.ipv4.tcp_syn_retries = 1
  1201. # keepalive
  1202. net.ipv4.tcp_keepalive_probes = 9
  1203. net.ipv4.tcp_keepalive_intvl = 75
  1204. net.ipv4.tcp_keepalive_time = 7200
  1205. #+END_SRC
  1206. Save and exit. It may be a good idea to reboot at this point and then log back into the BBB using ssh. You can do a safe reboot of the system by typing:
  1207. #+BEGIN_SRC: bash
  1208. reboot
  1209. #+END_SRC
  1210. After reboot and logging back in to the root account via /ssh/ you can verify that the firewall rules were restored correctly with:
  1211. #+BEGIN_SRC: bash
  1212. iptables -L
  1213. #+END_SRC
  1214. and
  1215. #+BEGIN_SRC: bash
  1216. ip6tables -L
  1217. #+END_SRC
  1218. ** Install Email
  1219. #+BEGIN_VERSE
  1220. /The government argued that, since the "inspection" of the data was to be carried out by a machine, they were exempt from the normal search-and-seizure protections of the Fourth Amendment...The prosecution also argued that my users had no expectation of privacy, even though the service I provided - encryption - is designed for users' privacy/
  1221. -- Ladar Levison
  1222. #+END_VERSE
  1223. Email is not very secure, but its usefulness and ubiquity mean that it's likely to continue as a primary communications method for many years to come. You can encrypt the contents of email using PGP/GPG, but very few people do that and even for those that do the metadata (the From/To/CC/BCC) is always transmitted in the clear as a fundamental aspect of the protocol, allowing an attacker to easily construct detailed models of people's social network and life patterns even without knowing the content.
  1224. Exim4 seems much easier to install and configure than Postfix.
  1225. #+BEGIN_SRC: bash
  1226. service postfix stop
  1227. apt-get remove postfix
  1228. aptitude install exim4 sasl2-bin swaks libnet-ssleay-perl procmail
  1229. #+END_SRC
  1230. You will be prompted to remove postfix. Say yes and yes again.
  1231. #+BEGIN_SRC: bash
  1232. dpkg-reconfigure exim4-config
  1233. #+END_SRC
  1234. Settings as follows:
  1235. #+BEGIN_SRC: bash
  1236. internet site
  1237. System mail name: mydomainname.com
  1238. IP addresses to listen on: blank
  1239. Destinations: mydomainname.com (and any other domains that you own)
  1240. Domains to relay mail: blank
  1241. Smarthost Relay: 192.168.1.0/24 (the range of addresses on your LAN)
  1242. Dial on demand = no
  1243. Maildir format in home directory
  1244. Split configuration = no
  1245. Root and postmaster: root email
  1246. #+END_SRC
  1247. To test the installation:
  1248. #+BEGIN_SRC: bash
  1249. telnet 192.168.1.60 25
  1250. ehlo xxx
  1251. quit
  1252. #+END_SRC
  1253. #+BEGIN_SRC: bash
  1254. editor /etc/default/saslauthd
  1255. #+END_SRC
  1256. set START=yes then save and exit.
  1257. #+BEGIN_SRC: bash
  1258. /etc/init.d/saslauthd start
  1259. editor /usr/bin/exim-gencert
  1260. #+END_SRC
  1261. Add the following:
  1262. #+BEGIN_SRC: bash
  1263. #!/bin/sh -e
  1264. if [ -n "$EX4DEBUG" ]; then
  1265. echo "now debugging $0 $@"
  1266. set -x
  1267. fi
  1268. DIR=/etc/exim4
  1269. CERT=$DIR/exim.crt
  1270. KEY=$DIR/exim.key
  1271. # This exim binary was built with GnuTLS which does not support dhparams
  1272. # from a file. See /usr/share/doc/exim4-base/README.Debian.gz
  1273. #DH=$DIR/exim.dhparam
  1274. if ! which openssl > /dev/null ;then
  1275. echo "$0: openssl is not installed, exiting" 1>&2
  1276. exit 1
  1277. fi
  1278. # valid for ten years
  1279. DAYS=3650
  1280. if [ "$1" != "--force" ] && [ -f $CERT ] && [ -f $KEY ]; then
  1281. echo "[*] $CERT and $KEY exists!"
  1282. echo " Use \"$0 --force\" to force generation!"
  1283. exit 0
  1284. fi
  1285. if [ "$1" = "--force" ]; then
  1286. shift
  1287. fi
  1288. #SSLEAY=/tmp/exim.ssleay.$$.cnf
  1289. SSLEAY="$(tempfile -m600 -pexi)"
  1290. cat > $SSLEAY <<EOM
  1291. RANDFILE = $HOME/.rnd
  1292. [ req ]
  1293. default_bits = 4096
  1294. default_keyfile = exim.key
  1295. distinguished_name = req_distinguished_name
  1296. [ req_distinguished_name ]
  1297. countryName = Country Code (2 letters)
  1298. countryName_default = GB
  1299. countryName_min = 2
  1300. countryName_max = 2
  1301. stateOrProvinceName = State or Province Name (full name)
  1302. localityName = Locality Name (eg, city)
  1303. organizationName = Organization Name (eg, company; recommended)
  1304. organizationName_max = 64
  1305. organizationalUnitName = Organizational Unit Name (eg, section)
  1306. organizationalUnitName_max = 64
  1307. commonName = Server name (eg. ssl.domain.tld; required!!!)
  1308. commonName_max = 64
  1309. emailAddress = Email Address
  1310. emailAddress_max = 40
  1311. EOM
  1312. echo "[*] Creating a self signed SSL certificate for Exim!"
  1313. echo " This may be sufficient to establish encrypted connections but for"
  1314. echo " secure identification you need to buy a real certificate!"
  1315. echo " "
  1316. echo " Please enter the hostname of your MTA at the Common Name (CN) prompt!"
  1317. echo " "
  1318. openssl req -config $SSLEAY -x509 -sha256 -newkey rsa:4096 -keyout $KEY -out $CERT -days $DAYS -nodes
  1319. #see README.Debian.gz*# openssl dhparam -check -text -5 512 -out $DH
  1320. rm -f $SSLEAY
  1321. chown root:Debian-exim $KEY $CERT $DH
  1322. chmod 640 $KEY $CERT $DH
  1323. echo "[*] Done generating self signed certificates for exim!"
  1324. echo " Refer to the documentation and example configuration files"
  1325. echo " over at /usr/share/doc/exim4-base/ for an idea on how to enable TLS"
  1326. echo " support in your mail transfer agent."
  1327. #+END_SRC
  1328. Save and exit
  1329. #+BEGIN_SRC: bash
  1330. chmod +x /usr/bin/exim-gencert
  1331. exim-gencert --force
  1332. #+END_SRC
  1333. This will generate the certificate used for email authentication. You will be asked for various details, the most important of which is the server name, which should be your domain name.
  1334. #+BEGIN_SRC: bash
  1335. editor /etc/exim4/exim4.conf.template
  1336. #+END_SRC
  1337. Uncomment the section which begins with *login_saslauthd_server*
  1338. Search for the line *.ifdef MAIN_HARDCODE_PRIMARY_HOSTNAME* and above it insert the lines:
  1339. #+BEGIN_SRC: bash
  1340. MAIN_HARDCODE_PRIMARY_HOSTNAME = mydomainname.com
  1341. MAIN_TLS_ENABLE = true
  1342. #+END_SRC
  1343. Save and exit.
  1344. #+BEGIN_SRC: bash
  1345. editor /etc/default/exim4
  1346. change SMTPLISTENEROPTIONS to:
  1347. SMTPLISTENEROPTIONS='-oX 465:25:587 -oP /var/run/exim4/exim.pid'
  1348. #+END_SRC
  1349. save and exit
  1350. #+BEGIN_SRC: bash
  1351. editor /etc/exim4/exim4.conf.template
  1352. #+END_SRC
  1353. Under the section *main/03_exim4-config_tlsoptions* add the following:
  1354. #+BEGIN_SRC: bash
  1355. tls_on_connect_ports=465
  1356. #+END_SRC
  1357. save and exit
  1358. #+BEGIN_SRC: bash
  1359. adduser myusername sasl
  1360. addgroup Debian-exim sasl
  1361. /etc/init.d/exim4 restart
  1362. mkdir -m 700 /etc/skel/Maildir
  1363. mkdir -m 700 /etc/skel/Maildir/Sent
  1364. mkdir -m 700 /etc/skel/Maildir/Sent/tmp
  1365. mkdir -m 700 /etc/skel/Maildir/Sent/cur
  1366. mkdir -m 700 /etc/skel/Maildir/Sent/new
  1367. mkdir -m 700 /etc/skel/Maildir/.learn-spam
  1368. mkdir -m 700 /etc/skel/Maildir/.learn-spam/cur
  1369. mkdir -m 700 /etc/skel/Maildir/.learn-spam/new
  1370. mkdir -m 700 /etc/skel/Maildir/.learn-spam/tmp
  1371. mkdir -m 700 /etc/skel/Maildir/.learn-ham
  1372. mkdir -m 700 /etc/skel/Maildir/.learn-ham/cur
  1373. mkdir -m 700 /etc/skel/Maildir/.learn-ham/new
  1374. mkdir -m 700 /etc/skel/Maildir/.learn-ham/tmp
  1375. ln -s /etc/skel/Maildir/.learn-spam /etc/skel/Maildir/spam
  1376. ln -s /etc/skel/Maildir/.learn-ham /etc/skel/Maildir/ham
  1377. #+END_SRC
  1378. If you're starting from scratch and don't already have a /Maildir/ directory in your home directory, then create one as follows:
  1379. #+BEGIN_SRC: bash
  1380. export MYUSERNAME=myusername
  1381. mkdir -m 700 /home/$MYUSERNAME/Maildir
  1382. mkdir -m 700 /home/$MYUSERNAME/Maildir/cur
  1383. mkdir -m 700 /home/$MYUSERNAME/Maildir/tmp
  1384. mkdir -m 700 /home/$MYUSERNAME/Maildir/new
  1385. mkdir -m 700 /home/$MYUSERNAME/Maildir/Sent
  1386. mkdir -m 700 /home/$MYUSERNAME/Maildir/Sent/cur
  1387. mkdir -m 700 /home/$MYUSERNAME/Maildir/Sent/tmp
  1388. mkdir -m 700 /home/$MYUSERNAME/Maildir/Sent/new
  1389. mkdir -m 700 /home/$MYUSERNAME/Maildir/.learn-spam
  1390. mkdir -m 700 /home/$MYUSERNAME/Maildir/.learn-spam/cur
  1391. mkdir -m 700 /home/$MYUSERNAME/Maildir/.learn-spam/new
  1392. mkdir -m 700 /home/$MYUSERNAME/Maildir/.learn-spam/tmp
  1393. mkdir -m 700 /home/$MYUSERNAME/Maildir/.learn-ham
  1394. mkdir -m 700 /home/$MYUSERNAME/Maildir/.learn-ham/cur
  1395. mkdir -m 700 /home/$MYUSERNAME/Maildir/.learn-ham/new
  1396. mkdir -m 700 /home/$MYUSERNAME/Maildir/.learn-ham/tmp
  1397. ln -s /home/$MYUSERNAME/Maildir/.learn-spam /home/$MYUSERNAME/Maildir/spam
  1398. ln -s /home/$MYUSERNAME/Maildir/.learn-ham /home/$MYUSERNAME/Maildir/ham
  1399. chown -R $MYUSERNAME:$MYUSERNAME /home/$MYUSERNAME/Maildir
  1400. #+END_SRC
  1401. ** Spam filtering
  1402. #+BEGIN_SRC: bash
  1403. aptitude install spamassassin exim4-daemon-heavy
  1404. #+END_SRC
  1405. If you encounter any problems with dependencies then select 'n' and then 'y' to whatever the suggestion for removals is. Repeat the aptitude install process until you don't get any more dependency errors.
  1406. #+BEGIN_SRC: bash
  1407. editor /etc/default/spamassassin
  1408. #+END_SRC
  1409. Set *ENABLED=1* then save and exit.
  1410. #+BEGIN_SRC: bash
  1411. editor /etc/exim4/exim4.conf.template
  1412. #+END_SRC
  1413. Uncomment or change according to your configuration
  1414. #+BEGIN_SRC: bash
  1415. # For spam scanning, there is a similar option that defines the interface to
  1416. # SpamAssassin. You do not need to set this if you are using the default, which
  1417. # is shown in this commented example. As for virus scanning, you must also
  1418. # modify the acl_check_data access control list to enable spam scanning.
  1419. spamd_address = 127.0.0.1 783
  1420. #+END_SRC
  1421. Add spam header in the /acl_check_data/ section:
  1422. #+BEGIN_SRC: bash
  1423. ### acl/40_exim4-config_check_data
  1424. #################################
  1425. # This ACL is used after the contents of a message have been received. This
  1426. # is the ACL in which you can test a message's headers or body, and in
  1427. # particular, this is where you can invoke external virus or spam scanners.
  1428. acl_check_data:
  1429. ...
  1430. ...
  1431. ...
  1432. # See the exim docs and the exim wiki for more suitable examples.
  1433. #
  1434. # warn
  1435. # spam = Debian-exim:true
  1436. # add_header = X-Spam_score: $spam_score\n\
  1437. # X-Spam_score_int: $spam_score_int\n\
  1438. # X-Spam_bar: $spam_bar\n\
  1439. # X-Spam_report: $spam_report
  1440. # put headers in all messages (no matter if spam or not)
  1441. warn spam = nobody:true
  1442. add_header = X-Spam-Score: $spam_score ($spam_bar)
  1443. add_header = X-Spam-Report: $spam_report
  1444. # add second subject line with *SPAM* marker when message
  1445. # is over threshold
  1446. warn spam = nobody
  1447. add_header = Subject: ***SPAM (score:$spam_score)*** $h_Subject:
  1448. #+END_SRC
  1449. Save and exit, then restart
  1450. #+BEGIN_SRC: bash
  1451. exit
  1452. editor ~/.procmailrc
  1453. #+END_SRC
  1454. The text should look like the following.
  1455. #+BEGIN_SRC: sh
  1456. MAILDIR=$HOME/Maildir
  1457. DEFAULT=$MAILDIR/
  1458. LOGFILE=$HOME/log/procmail.log
  1459. LOGABSTRACT=all
  1460. # get spamassassin to check emails
  1461. :0fw: .spamassassin.lock
  1462. * < 256000
  1463. | spamc
  1464. # strong spam are discarded
  1465. :0
  1466. * ^X-Spam-Level: \*\*\*\*\*\*
  1467. /dev/null
  1468. # weak spam are kept just in case - clear this out every now and then
  1469. :0
  1470. * ^X-Spam-Level: \*\*\*\*\*
  1471. .0-spam/
  1472. # otherwise, marginal spam goes here for revision
  1473. :0
  1474. * ^X-Spam-Level: \*\*
  1475. .spam/
  1476. #+END_SRC
  1477. Save and exit.
  1478. #+BEGIN_SRC: bash
  1479. su
  1480. editor /usr/bin/filterspam
  1481. #+END_SRC
  1482. Add the following contents:
  1483. #+BEGIN_SRC: bash
  1484. #!/bin/bash
  1485. USERNAME=$1
  1486. MAILDIR=/home/$USERNAME/Maildir/.learn-spam
  1487. if [ ! -d "$MAILDIR" ]; then
  1488. exit
  1489. fi
  1490. for f in `ls $MAILDIR/cur`
  1491. do
  1492. spamc -L spam < "$MAILDIR/cur/$f" > /dev/null
  1493. rm "$MAILDIR/cur/$f"
  1494. done
  1495. for f in `ls $MAILDIR/new`
  1496. do
  1497. spamc -L spam < "$MAILDIR/new/$f" > /dev/null
  1498. rm "$MAILDIR/new/$f"
  1499. done
  1500. #+END_SRC
  1501. Save and exit.
  1502. #+BEGIN_SRC: bash
  1503. editor /usr/bin/filterham
  1504. #+END_SRC
  1505. Add the following contents:
  1506. #+BEGIN_SRC: bash
  1507. #!/bin/bash
  1508. USERNAME=$1
  1509. MAILDIR=/home/$USERNAME/Maildir/.learn-ham
  1510. if [ ! -d "$MAILDIR" ]; then
  1511. exit
  1512. fi
  1513. for f in `ls $MAILDIR/cur`
  1514. do
  1515. spamc -L ham < "$MAILDIR/cur/$f" > /dev/null
  1516. rm "$MAILDIR/cur/$f"
  1517. done
  1518. for f in `ls $MAILDIR/new`
  1519. do
  1520. spamc -L ham < "$MAILDIR/new/$f" > /dev/null
  1521. rm "$MAILDIR/new/$f"
  1522. done
  1523. #+END_SRC
  1524. Save and exit.
  1525. #+BEGIN_SRC: bash
  1526. editor /etc/crontab
  1527. #+END_SRC
  1528. Append the following, replacing *myusername* with your username.
  1529. #+BEGIN_SRC: bash
  1530. */3 * * * * root /usr/bin/timeout 120 /usr/bin/filterspam myusername
  1531. */3 * * * * root /usr/bin/timeout 120 /usr/bin/filterham myusername
  1532. #+END_SRC
  1533. Save and exit.
  1534. #+BEGIN_SRC: bash
  1535. chmod 655 /usr/bin/filterspam /usr/bin/filterham
  1536. service spamassassin restart
  1537. service exim4 restart
  1538. service cron restart
  1539. #+END_SRC
  1540. ** Install Dovecot
  1541. #+BEGIN_VERSE
  1542. /I dreamt last night that I was living in a surveillance state. I woke up and… I’m still in a surveillance state./
  1543. -- Conrad Kramer
  1544. #+END_VERSE
  1545. Install the required packages.
  1546. #+BEGIN_SRC: bash
  1547. aptitude -y install dovecot-common dovecot-imapd
  1548. #+END_SRC
  1549. Edit the configuration file.
  1550. #+BEGIN_SRC: bash
  1551. editor /etc/dovecot/dovecot.conf
  1552. #+END_SRC
  1553. Line 26: change:
  1554. #+BEGIN_SRC: bash
  1555. listen = *
  1556. #+END_SRC
  1557. Save and exit.
  1558. #+BEGIN_SRC: bash
  1559. editor /etc/dovecot/conf.d/10-auth.conf
  1560. #+END_SRC
  1561. Line 9: uncomment and change (allow plain text auth)
  1562. #+BEGIN_SRC: bash
  1563. disable_plaintext_auth = no
  1564. #+END_SRC
  1565. Line 99: add:
  1566. #+BEGIN_SRC: bash
  1567. auth_mechanisms = plain login
  1568. #+END_SRC
  1569. Save and exit.
  1570. #+BEGIN_SRC: bash
  1571. editor /etc/dovecot/conf.d/10-mail.conf
  1572. #+END_SRC
  1573. Line 30: uncomment and add:
  1574. #+BEGIN_SRC: bash
  1575. mail_location = maildir:~/Maildir:LAYOUT=fs
  1576. #+END_SRC
  1577. Save and exit.
  1578. #+BEGIN_SRC: bash
  1579. editor /etc/dovecot/conf.d/10-ssl.conf
  1580. #+END_SRC
  1581. Append the following:
  1582. #+BEGIN_SRC: bash
  1583. ssl_cipher_list = 'EDH+CAMELLIA:EDH+aRSA:EECDH+aRSA+AESGCM:EECDH+aRSA+SHA384:EECDH+aRSA+SHA256:EECDH:+CAMELLIA256:+AES256:+CAMELLIA128:+AES128:+SSLv3:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EXP:!PSK:!DSS:!RC4:!SEED:!ECDSA:CAMELLIA256-SHA:AES256-SHA:CAMELLIA128-SHA:AES128-SHA'
  1584. #+END_SRC
  1585. Save and exit, then start the dovecot service.
  1586. #+BEGIN_SRC: bash
  1587. service dovecot restart
  1588. #+END_SRC
  1589. ** Create a GPG key
  1590. #+BEGIN_VERSE
  1591. /If privacy is outlawed, only outlaws will have privacy./
  1592. -- Philip Zimmermann
  1593. #+END_VERSE
  1594. *** Initial installation
  1595. Assuming that you are logged in as root, first ensure that GPG is installed and then exit to your user account.
  1596. #+BEGIN_SRC: bash
  1597. apt-get install gnupg
  1598. exit
  1599. #+END_SRC
  1600. Now we will add some settings:
  1601. #+BEGIN_SRC: bash
  1602. mkdir ~/.gnupg
  1603. editor ~/.gnupg/gpg.conf
  1604. #+END_SRC
  1605. The configuration should look like the following. Of particular importance are the default preferences at the end.
  1606. #+BEGIN_SRC: bash
  1607. # Options for GnuPG
  1608. # Copyright 1998, 1999, 2000, 2001, 2002, 2003,
  1609. # 2010 Free Software Foundation, Inc.
  1610. #
  1611. # This file is free software; as a special exception the author gives
  1612. # unlimited permission to copy and/or distribute it, with or without
  1613. # modifications, as long as this notice is preserved.
  1614. #
  1615. # This file is distributed in the hope that it will be useful, but
  1616. # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
  1617. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  1618. #
  1619. # Unless you specify which option file to use (with the command line
  1620. # option "--options filename"), GnuPG uses the file ~/.gnupg/gpg.conf
  1621. # by default.
  1622. #
  1623. # An options file can contain any long options which are available in
  1624. # GnuPG. If the first non white space character of a line is a '#',
  1625. # this line is ignored. Empty lines are also ignored.
  1626. #
  1627. # See the man page for a list of options.
  1628. # Uncomment the following option to get rid of the copyright notice
  1629. #no-greeting
  1630. # If you have more than 1 secret key in your keyring, you may want to
  1631. # uncomment the following option and set your preferred keyid.
  1632. #default-key 621CC013
  1633. # If you do not pass a recipient to gpg, it will ask for one. Using
  1634. # this option you can encrypt to a default key. Key validation will
  1635. # not be done in this case. The second form uses the default key as
  1636. # default recipient.
  1637. #default-recipient some-user-id
  1638. #default-recipient-self
  1639. # Use --encrypt-to to add the specified key as a recipient to all
  1640. # messages. This is useful, for example, when sending mail through a
  1641. # mail client that does not automatically encrypt mail to your key.
  1642. # In the example, this option allows you to read your local copy of
  1643. # encrypted mail that you've sent to others.
  1644. #encrypt-to some-key-id
  1645. # By default GnuPG creates version 4 signatures for data files as
  1646. # specified by OpenPGP. Some earlier (PGP 6, PGP 7) versions of PGP
  1647. # require the older version 3 signatures. Setting this option forces
  1648. # GnuPG to create version 3 signatures.
  1649. #force-v3-sigs
  1650. # Because some mailers change lines starting with "From " to ">From "
  1651. # it is good to handle such lines in a special way when creating
  1652. # cleartext signatures; all other PGP versions do it this way too.
  1653. #no-escape-from-lines
  1654. # If you do not use the Latin-1 (ISO-8859-1) charset, you should tell
  1655. # GnuPG which is the native character set. Please check the man page
  1656. # for supported character sets. This character set is only used for
  1657. # metadata and not for the actual message which does not undergo any
  1658. # translation. Note that future version of GnuPG will change to UTF-8
  1659. # as default character set. In most cases this option is not required
  1660. # as GnuPG is able to figure out the correct charset at runtime.
  1661. #charset utf-8
  1662. # Group names may be defined like this:
  1663. # group mynames = paige 0x12345678 joe patti
  1664. #
  1665. # Any time "mynames" is a recipient (-r or --recipient), it will be
  1666. # expanded to the names "paige", "joe", and "patti", and the key ID
  1667. # "0x12345678". Note there is only one level of expansion - you
  1668. # cannot make an group that points to another group. Note also that
  1669. # if there are spaces in the recipient name, this will appear as two
  1670. # recipients. In these cases it is better to use the key ID.
  1671. #group mynames = paige 0x12345678 joe patti
  1672. # Lock the file only once for the lifetime of a process. If you do
  1673. # not define this, the lock will be obtained and released every time
  1674. # it is needed, which is usually preferable.
  1675. #lock-once
  1676. # GnuPG can send and receive keys to and from a keyserver. These
  1677. # servers can be HKP, email, or LDAP (if GnuPG is built with LDAP
  1678. # support).
  1679. #
  1680. # Example HKP keyserver:
  1681. # hkp://keys.gnupg.net
  1682. # hkp://subkeys.pgp.net
  1683. #
  1684. # Example email keyserver:
  1685. # mailto:pgp-public-keys@keys.pgp.net
  1686. #
  1687. # Example LDAP keyservers:
  1688. # ldap://keyserver.pgp.com
  1689. #
  1690. # Regular URL syntax applies, and you can set an alternate port
  1691. # through the usual method:
  1692. # hkp://keyserver.example.net:22742
  1693. #
  1694. # Most users just set the name and type of their preferred keyserver.
  1695. # Note that most servers (with the notable exception of
  1696. # ldap://keyserver.pgp.com) synchronize changes with each other. Note
  1697. # also that a single server name may actually point to multiple
  1698. # servers via DNS round-robin. hkp://keys.gnupg.net is an example of
  1699. # such a "server", which spreads the load over a number of physical
  1700. # servers. To see the IP address of the server actually used, you may use
  1701. # the "--keyserver-options debug".
  1702. keyserver hkp://keys.gnupg.net
  1703. #keyserver mailto:pgp-public-keys@keys.nl.pgp.net
  1704. #keyserver ldap://keyserver.pgp.com
  1705. # Common options for keyserver functions:
  1706. #
  1707. # include-disabled : when searching, include keys marked as "disabled"
  1708. # on the keyserver (not all keyservers support this).
  1709. #
  1710. # no-include-revoked : when searching, do not include keys marked as
  1711. # "revoked" on the keyserver.
  1712. #
  1713. # verbose : show more information as the keys are fetched.
  1714. # Can be used more than once to increase the amount
  1715. # of information shown.
  1716. #
  1717. # use-temp-files : use temporary files instead of a pipe to talk to the
  1718. # keyserver. Some platforms (Win32 for one) always
  1719. # have this on.
  1720. #
  1721. # keep-temp-files : do not delete temporary files after using them
  1722. # (really only useful for debugging)
  1723. #
  1724. # http-proxy="proxy" : set the proxy to use for HTTP and HKP keyservers.
  1725. # This overrides the "http_proxy" environment variable,
  1726. # if any.
  1727. #
  1728. # auto-key-retrieve : automatically fetch keys as needed from the keyserver
  1729. # when verifying signatures or when importing keys that
  1730. # have been revoked by a revocation key that is not
  1731. # present on the keyring.
  1732. #
  1733. # no-include-attributes : do not include attribute IDs (aka "photo IDs")
  1734. # when sending keys to the keyserver.
  1735. keyserver-options auto-key-retrieve
  1736. # Display photo user IDs in key listings
  1737. # list-options show-photos
  1738. # Display photo user IDs when a signature from a key with a photo is
  1739. # verified
  1740. # verify-options show-photos
  1741. # Use this program to display photo user IDs
  1742. #
  1743. # %i is expanded to a temporary file that contains the photo.
  1744. # %I is the same as %i, but the file isn't deleted afterwards by GnuPG.
  1745. # %k is expanded to the key ID of the key.
  1746. # %K is expanded to the long OpenPGP key ID of the key.
  1747. # %t is expanded to the extension of the image (e.g. "jpg").
  1748. # %T is expanded to the MIME type of the image (e.g. "image/jpeg").
  1749. # %f is expanded to the fingerprint of the key.
  1750. # %% is %, of course.
  1751. #
  1752. # If %i or %I are not present, then the photo is supplied to the
  1753. # viewer on standard input. If your platform supports it, standard
  1754. # input is the best way to do this as it avoids the time and effort in
  1755. # generating and then cleaning up a secure temp file.
  1756. #
  1757. # If no photo-viewer is provided, GnuPG will look for xloadimage, eog,
  1758. # or display (ImageMagick). On Mac OS X and Windows, the default is
  1759. # to use your regular JPEG image viewer.
  1760. #
  1761. # Some other viewers:
  1762. # photo-viewer "qiv %i"
  1763. # photo-viewer "ee %i"
  1764. #
  1765. # This one saves a copy of the photo ID in your home directory:
  1766. # photo-viewer "cat > ~/photoid-for-key-%k.%t"
  1767. #
  1768. # Use your MIME handler to view photos:
  1769. # photo-viewer "metamail -q -d -b -c %T -s 'KeyID 0x%k' -f GnuPG"
  1770. # Passphrase agent
  1771. #
  1772. # We support the old experimental passphrase agent protocol as well as
  1773. # the new Assuan based one (currently available in the "newpg" package
  1774. # at ftp.gnupg.org/gcrypt/alpha/aegypten/). To make use of the agent,
  1775. # you have to run an agent as daemon and use the option
  1776. #
  1777. # use-agent
  1778. #
  1779. # which tries to use the agent but will fallback to the regular mode
  1780. # if there is a problem connecting to the agent. The normal way to
  1781. # locate the agent is by looking at the environment variable
  1782. # GPG_AGENT_INFO which should have been set during gpg-agent startup.
  1783. # In certain situations the use of this variable is not possible, thus
  1784. # the option
  1785. #
  1786. # --gpg-agent-info=<path>:<pid>:1
  1787. #
  1788. # may be used to override it.
  1789. # Automatic key location
  1790. #
  1791. # GnuPG can automatically locate and retrieve keys as needed using the
  1792. # auto-key-locate option. This happens when encrypting to an email
  1793. # address (in the "user@example.com" form), and there are no
  1794. # user@example.com keys on the local keyring. This option takes the
  1795. # following arguments, in the order they are to be tried:
  1796. #
  1797. # cert = locate a key using DNS CERT, as specified in RFC-4398.
  1798. # GnuPG can handle both the PGP (key) and IPGP (URL + fingerprint)
  1799. # CERT methods.
  1800. #
  1801. # pka = locate a key using DNS PKA.
  1802. #
  1803. # ldap = locate a key using the PGP Universal method of checking
  1804. # "ldap://keys.(thedomain)". For example, encrypting to
  1805. # user@example.com will check ldap://keys.example.com.
  1806. #
  1807. # keyserver = locate a key using whatever keyserver is defined using
  1808. # the keyserver option.
  1809. #
  1810. # You may also list arbitrary keyservers here by URL.
  1811. #
  1812. # Try CERT, then PKA, then LDAP, then hkp://subkeys.net:
  1813. #auto-key-locate cert pka ldap hkp://subkeys.pgp.net
  1814. # default preferences
  1815. personal-digest-preferences SHA256
  1816. cert-digest-algo SHA256
  1817. default-preference-list SHA512 SHA384 SHA256 SHA224 AES256 AES192 AES CAST5 ZLIB BZIP2 ZIP Uncompressed
  1818. #+END_SRC
  1819. Save and exit.
  1820. *** If you have an existing key
  1821. #+BEGIN_SRC: bash
  1822. gpg --import ~/public_key.txt
  1823. gpg --allow-secret-key-import --import ~/private_key.txt
  1824. shred -zu ~/private_key.txt
  1825. #+END_SRC
  1826. Now check the digest preferences, replacing /keyID/ with your GPG key ID. This applies especially if you have a key which was generated some time ago.
  1827. #+BEGIN_SRC: bash
  1828. export MYGPGKEYID=keyID
  1829. gpg --edit-key $MYGPGKEYID
  1830. setpref SHA512 SHA384 SHA256 SHA224 AES256 AES192 AES CAST5 ZLIB BZIP2 ZIP Uncompressed
  1831. save
  1832. gpg --send-keys $MYGPGKEYID
  1833. #+END_SRC
  1834. *** To create a new key
  1835. Generate a key with the following command:
  1836. #+BEGIN_SRC: bash
  1837. gpg --gen-key
  1838. #+END_SRC
  1839. You can find your GPG key ID by entering:
  1840. #+BEGIN_SRC: bash
  1841. gpg --list-keys
  1842. #+END_SRC
  1843. The key ID is the second part of the string of numbers and letters. So for example in:
  1844. #+BEGIN_SRC: bash
  1845. pub 4096R/EA982E38 2012-05-20
  1846. #+END_SRC
  1847. the key ID is EA982E38. Now send your public key to a server so that others can find it.
  1848. #+BEGIN_SRC: bash
  1849. gpg --send-keys $MYGPGKEYID
  1850. #+END_SRC
  1851. *** root settings
  1852. If you later create an encrypted mailing list then the root user will also need to have good GPG settings so that it can generate key pairs for the list. The easiest way to ensure this is to do the following, replacing /myusername/ with your username:
  1853. #+BEGIN_SRC: bash
  1854. su
  1855. cp -r /home/myusername/.gnupg ~/
  1856. chown -R root:root ~/.gnupg
  1857. #+END_SRC
  1858. ** Protect processes
  1859. Because the BBB has limited RAM some processes may occasionally be automatically killed if physical memory availability is getting too low. The way in which processes are chosen to be sacrificed is not particularly intelligent, and so can result in vital systems being stopped. To try to prevent that from ever happening the following script can be used, which should ensure that at a minimum ssh, email and mysql keep running.
  1860. #+BEGIN_SRC: bash
  1861. editor /usr/bin/protectprocesses
  1862. #+END_SRC
  1863. Add the following:
  1864. #+BEGIN_SRC: bash
  1865. #!/bin/bash
  1866. declare -a protect=('/usr/sbin/sshd' '/usr/sbin/mysqld --basedir=/usr' '/bin/sh /usr/bin/mysqld_safe' '/usr/sbin/exim4')
  1867. for p in "${protect[@]}"
  1868. do
  1869. OOM_PROC_ID=$(ps aux | grep '$p' | grep -v grep | head -n 1 | awk -F ' ' '{print $2}')
  1870. if [ ! -z "$OOM_PROC_ID" ]; then
  1871. echo -1000 >/proc/$OOM_PROC_ID/oom_score_adj
  1872. echo -17 >/proc/$OOM_PROC_ID/oom_adj
  1873. fi
  1874. done
  1875. #+END_SRC
  1876. Save and exit, then edit the cron jobs:
  1877. #+BEGIN_SRC: bash
  1878. editor /etc/crontab
  1879. #+END_SRC
  1880. And add the line:
  1881. #+BEGIN_SRC: bash
  1882. */1 * * * * root /usr/bin/timeout 30 /usr/bin/protectprocesses
  1883. #+END_SRC
  1884. Then save and exit and restart cron.
  1885. #+BEGIN_SRC: bash
  1886. chmod +x /usr/bin/protectprocesses
  1887. service cron restart
  1888. #+END_SRC
  1889. Here cron is used so that if we stop one of the relevant processes and then restart it then its oom priority will be reassigned again
  1890. .
  1891. ** Setting up a web site
  1892. #+BEGIN_VERSE
  1893. /It's important to have the geek community as a whole think about its responsibility and what it can do. We need various alternative voices pushing back on conventional government sometimes./
  1894. -- Tim Berners-Lee
  1895. #+END_VERSE
  1896. First install nginx and some scripts for easily enabling and disabling the web sites which we will create.
  1897. #+BEGIN_SRC: bash
  1898. apt-get install nginx php5-fpm git
  1899. cd ~/build
  1900. git clone https://github.com/perusio/nginx_ensite
  1901. cd ~/build/nginx_ensite
  1902. cp nginx_* /usr/sbin
  1903. #+END_VERSE
  1904. In the examples below replace /mydomainname.com/ with your own domain name.
  1905. #+BEGIN_SRC: bash
  1906. export HOSTNAME=mydomainname.com
  1907. mkdir /var/www/$HOSTNAME
  1908. mkdir /var/www/$HOSTNAME/htdocs
  1909. editor /etc/nginx/sites-available/$HOSTNAME
  1910. #+END_SRC
  1911. The configuration for the site should look something like the following. Replace /mydonainname.com/ with the site domain name.
  1912. #+BEGIN_SRC: bash
  1913. server {
  1914. listen 80;
  1915. server_name mydomainname.com;
  1916. root /var/www/mydomainname.com/htdocs;
  1917. error_log /var/www/mydomainname.com/error.log;
  1918. index index.html index.htm index.php;
  1919. # Uncomment this if you need to redirect HTTP to HTTPS
  1920. #rewrite ^ https://$server_name$request_uri? permanent;
  1921. location / {
  1922. try_files $uri $uri/ /index.html;
  1923. }
  1924. location ~ \.php$ {
  1925. fastcgi_split_path_info ^(.+\.php)(/.+)$;
  1926. fastcgi_pass unix:/var/run/php5-fpm.sock;
  1927. fastcgi_index index.php;
  1928. include fastcgi_params;
  1929. }
  1930. }
  1931. server {
  1932. listen 443 ssl;
  1933. root /var/www/mydomainname.com/htdocs;
  1934. server_name mydomainname.com;
  1935. error_log /var/www/mydomainname.com/error_ssl.log;
  1936. index index.html index.htm index.php;
  1937. charset utf-8;
  1938. client_max_body_size 20m;
  1939. client_body_buffer_size 128k;
  1940. ssl on;
  1941. ssl_certificate /etc/ssl/certs/mydomainname.com.crt;
  1942. ssl_certificate_key /etc/ssl/private/mydomainname.com.key;
  1943. ssl_session_timeout 5m;
  1944. ssl_prefer_server_ciphers on;
  1945. ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # not possible to do exclusive
  1946. ssl_ciphers 'EDH+CAMELLIA:EDH+aRSA:EECDH+aRSA+AESGCM:EECDH+aRSA+SHA384:EECDH+aRSA+SHA256:EECDH:+CAMELLIA256:+AES256:+CAMELLIA128:+AES128:+SSLv3:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EXP:!PSK:!DSS:!RC4:!SEED:!ECDSA:CAMELLIA256-SHA:AES256-SHA:CAMELLIA128-SHA:AES128-SHA';
  1947. add_header Strict-Transport-Security max-age=15768000; # six months
  1948. # use this only if all subdomains support HTTPS!
  1949. # add_header Strict-Transport-Security "max-age=15768000; includeSubDomains";
  1950. # rewrite to front controller as default rule
  1951. location / {
  1952. rewrite ^/(.*) /index.php?q=$uri&$args last;
  1953. }
  1954. # make sure webfinger and other well known services aren't blocked
  1955. # by denying dot files and rewrite request to the front controller
  1956. location ^~ /.well-known/ {
  1957. allow all;
  1958. rewrite ^/(.*) /index.php?q=$uri&$args last;
  1959. }
  1960. # statically serve these file types when possible
  1961. # otherwise fall back to front controller
  1962. # allow browser to cache them
  1963. # added .htm for advanced source code editor library
  1964. location ~* \.(jpg|jpeg|gif|png|ico|css|js|htm|html|ttf|woff|svg)$ {
  1965. expires 30d;
  1966. try_files $uri /index.php?q=$uri&$args;
  1967. }
  1968. # block these file types
  1969. location ~* \.(tpl|md|tgz|log|out)$ {
  1970. deny all;
  1971. }
  1972. # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  1973. # or a unix socket
  1974. location ~* \.php$ {
  1975. # Zero-day exploit defense.
  1976. # http://forum.nginx.org/read.php?2,88845,page=3
  1977. # Won't work properly (404 error) if the file is not stored on this
  1978. # server, which is entirely possible with php-fpm/php-fcgi.
  1979. # Comment the 'try_files' line out if you set up php-fpm/php-fcgi on
  1980. # another machine. And then cross your fingers that you won't get hacked.
  1981. try_files $uri =404;
  1982. # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
  1983. fastcgi_split_path_info ^(.+\.php)(/.+)$;
  1984. # With php5-cgi alone:
  1985. # fastcgi_pass 127.0.0.1:9000;
  1986. # With php5-fpm:
  1987. fastcgi_pass unix:/var/run/php5-fpm.sock;
  1988. include fastcgi_params;
  1989. fastcgi_index index.php;
  1990. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  1991. }
  1992. # deny access to all dot files
  1993. location ~ /\. {
  1994. deny all;
  1995. }
  1996. #deny access to store
  1997. location ~ /store {
  1998. deny all;
  1999. }
  2000. }
  2001. #+END_SRC
  2002. Save and exit. Then change the domain name.
  2003. #+BEGIN_SRC: bash
  2004. sed "s/mydomainname.com/$HOSTNAME/g" /etc/nginx/sites-available/$HOSTNAME > /tmp/website
  2005. cp -f /tmp/website /etc/nginx/sites-available/$HOSTNAME
  2006. #+END_SRC
  2007. Then to enable the site:
  2008. #+BEGIN_SRC: bash
  2009. nginx_dissite default
  2010. nginx_ensite $HOSTNAME
  2011. #+END_SRC
  2012. Create a self-signed certificate. The passphrase isn't important and will be removed, so make it easy (such as "password").
  2013. #+BEGIN_SRC: bash
  2014. editor /usr/bin/makecert
  2015. #+END_SRC
  2016. Enter the following, changing the country code and location as needed:
  2017. #+BEGIN_SRC: bash
  2018. #!/bin/bash
  2019. HOSTNAME=$1
  2020. COUNTRY_CODE="GB"
  2021. AREA="Greater Manchester"
  2022. LOCATION="Manchester"
  2023. ORGANISATION="Freedombone"
  2024. openssl req \
  2025. -x509 -nodes -days 3650 \
  2026. -subj "/O=$ORGANISATION/C=$COUNTRY_CODE/ST=$AREA/L=$LOCATION/CN=$HOSTNAME" \
  2027. -newkey rsa:1024 \
  2028. -keyout /etc/ssl/private/$HOSTNAME.key \
  2029. -out /etc/ssl/certs/$HOSTNAME.crt
  2030. chmod 400 /etc/ssl/private/$HOSTNAME.key
  2031. /etc/init.d/nginx reload
  2032. #+END_SRC
  2033. Save and exit.
  2034. #+BEGIN_SRC: bash
  2035. chmod +x /usr/bin/makecert
  2036. makecert $HOSTNAME
  2037. #+END_SRC
  2038. If all has gone well then there should be no warnings or errors after you run the service restart command. After that you should enable ports 80 (HTTP) and 443 (HTTPS) on your internet router/firewall, such that they are redirected to the BBB.
  2039. Also limit the amount of memory which any php scripts can use.
  2040. #+BEGIN_SRC: bash
  2041. editor /etc/php5/fpm/php.ini
  2042. #+END_SRC
  2043. Set the following:
  2044. #+BEGIN_SRC: bash
  2045. memory_limit = 32M
  2046. #+END_SRC
  2047. Also set:
  2048. #+BEGIN_SRC: bash
  2049. cgi.fix_pathinfo=0
  2050. #+END_SRC
  2051. Save and exit. Also edit */etc/php5/cli/php.ini* and set /memory_limit/ to the same value. This should prevent any rogue scripts from crashing the system.
  2052. #+BEGIN_SRC: bash
  2053. service php5-fpm restart
  2054. service nginx restart
  2055. #+END_SRC
  2056. ** Accessing your Email
  2057. #+BEGIN_VERSE
  2058. /The emails showed that Google...was among several other military/defense contractors vying for a piece of DAC’s $10.9-million surveillance contracting action./
  2059. -- Article on the "Google-Military-Surveillance Complex" by Yasha Levine
  2060. #+END_VERSE
  2061. *** Mutt email client
  2062. #+BEGIN_SRC: bash
  2063. apt-get install mutt-patched lynx abook
  2064. exit
  2065. mkdir ~/.mutt
  2066. echo "text/html; lynx -dump -width=78 -nolist %s | sed ‘s/^ //’; copiousoutput; needsterminal; nametemplate=%s.html" > ~/.mutt/mailcap
  2067. su
  2068. editor /etc/Muttrc
  2069. #+END_SRC
  2070. Append the following:
  2071. #+BEGIN_SRC: bash
  2072. set mbox_type=Maildir
  2073. set folder="~/Maildir"
  2074. set mask="!^\\.[^.]"
  2075. set mbox="~/Maildir"
  2076. set record="+Sent"
  2077. set postponed="+Drafts"
  2078. set trash="+Trash"
  2079. set spoolfile="~/Maildir"
  2080. auto_view text/x-vcard text/html text/enriched
  2081. set editor="emacs"
  2082. set header_cache="+.cache"
  2083. macro index S "<tag-prefix><save-message>=.learn-spam<enter>" "move to learn-spam"
  2084. macro pager S "<save-message>=.learn-spam<enter>" "move to learn-spam"
  2085. macro index H "<tag-prefix><copy-message>=.learn-ham<enter>" "copy to learn-ham"
  2086. macro pager H "<copy-message>=.learn-ham<enter>" "copy to learn-ham"
  2087. # set up the sidebar
  2088. set sidebar_width=12
  2089. set sidebar_visible=yes
  2090. set sidebar_delim='|'
  2091. set sidebar_sort=yes
  2092. set rfc2047_parameters
  2093. # Show inbox and sent items
  2094. mailboxes = =Sent
  2095. # Alter these colours as needed for maximum bling
  2096. color sidebar_new yellow default
  2097. color normal white default
  2098. color hdrdefault brightcyan default
  2099. color signature green default
  2100. color attachment brightyellow default
  2101. color quoted green default
  2102. color quoted1 white default
  2103. color tilde blue default
  2104. # ctrl-n, ctrl-p to select next, prev folder
  2105. # ctrl-o to open selected folder
  2106. bind index \Cp sidebar-prev
  2107. bind index \Cn sidebar-next
  2108. bind index \Co sidebar-open
  2109. bind pager \Cp sidebar-prev
  2110. bind pager \Cn sidebar-next
  2111. bind pager \Co sidebar-open
  2112. # ctrl-b toggles sidebar visibility
  2113. macro index,pager \Cb '<enter-command>toggle sidebar_visible<enter><redraw-screen>' "toggle sidebar"
  2114. # esc-m Mark new messages as read
  2115. macro index <esc>m "T~N<enter>;WNT~O<enter>;WO\CT~T<enter>" "mark all messages read"
  2116. # Collapsing threads
  2117. macro index [ "<collapse-thread>" "collapse/uncollapse thread"
  2118. macro index ] "<collapse-all>" "collapse/uncollapse all threads"
  2119. # threads containing new messages
  2120. uncolor index "~(~N)"
  2121. color index brightblue default "~(~N)"
  2122. # new messages themselves
  2123. uncolor index "~N"
  2124. color index brightyellow default "~N"
  2125. # GPG/PGP integration
  2126. # this set the number of seconds to keep in memory the passphrase used to encrypt/sign
  2127. set pgp_timeout=60
  2128. # automatically sign and encrypt with PGP/MIME
  2129. set pgp_autosign # autosign all outgoing mails
  2130. set pgp_replyencrypt # autocrypt replies to crypted
  2131. set pgp_replysign # autosign replies to signed
  2132. set pgp_auto_decode=yes # decode attachments
  2133. unset smime_is_default
  2134. set alias_file=~/.mutt-alias
  2135. source ~/.mutt-alias
  2136. set query_command= "abook --mutt-query '%s'"
  2137. macro index,pager A "<pipe-message>abook --add-email-quiet<return>" "add the sender address to abook"
  2138. #+END_SRC
  2139. Save and exit.
  2140. #+BEGIN_SRC: bash
  2141. editor /etc/mail/spamassassin/local.cf
  2142. #+END_SRC
  2143. Uncomment *use_bayes*, *bayes_auto_learn*
  2144. Save and exit, then run:
  2145. #+BEGIN_SRC: bash
  2146. service spamassassin restart
  2147. exit
  2148. cp /etc/Muttrc ~/.muttrc
  2149. touch ~/.mutt-alias
  2150. #+END_SRC
  2151. Finally you can then type *mutt* to get access to your email. Hence as a fallback, or if you prefer as the primary way of accessing email, you can ssh into the BBB and use the mutt command line email client. Ssh clients are available for all operating systems, and also you should be reasonably protected from passive surveillance between wherever you are and the BBB (although not between the BBB and the wider internet), which can be useful if you are for example using an Android tablet from a cafe or railway station.
  2152. To use the address book system open an email and then to add the sender to the address list press the A key. It will ask you for an alias which may be used the next time you want to send a mail. Alternatively you may just edit the *~/.mutt-alias* file directly to add email addresses.
  2153. Some useful keys to know are:
  2154. | ESC / | Search for text within message contents |
  2155. | "/" | Search for text within headers |
  2156. | * | Move to the last message |
  2157. | TAB | Move to the next unread message |
  2158. | d | Delete a message |
  2159. | u | Undelete a mail which is pending deletion |
  2160. | $ | Delete all messages selected and check for new messages |
  2161. | a | Add to the address book |
  2162. | m | Send a new mail |
  2163. | ESC-m | Mark all messages as having been read |
  2164. | S | Mark a message as spam |
  2165. | H | Mark a message as ham |
  2166. | CTRL-b | Toggle side bar on/off |
  2167. | CTRL-n | Next mailbox (on side bar) |
  2168. | CTRL-p | Previous mailbox (on side bar) |
  2169. | CTRL-o | Open mailbox (on side bar) |
  2170. | ] | Expand or collapse all threads |
  2171. | [ | Expand of collapse the current thread |
  2172. | CTRL-k | Import a PGP/GPG public key |
  2173. One of the most common things which you might wish to do is to send an email. To do this first press /m/ to create a new message. Enter the address to send to and the subject, then after a few seconds the Emacs editor will appear with a blank document. Type your email then press /CTRL-x CTRL-s/ to save it and /CTRL-x CTRL-c/ to exit. You will then see a summary of the email to be sent out. Press /y/ to send it and then enter your GPG key passphrase (the one you gave when creating a PGP/GPG key). The purpose of that is to add a signature which is a strong proof that the email was written by you and not by someone else.
  2174. *** K9 Android client
  2175. #+BEGIN_VERSE
  2176. /The surveillance state is robust. It is robust politically, legally, and technically./
  2177. -- Bruce Schneier
  2178. #+END_VERSE
  2179. **** Incoming server settings
  2180. * Select settings/account settings
  2181. * Select Fetching mail/incoming server
  2182. * Enter your username and password
  2183. * IMAP server should be your domain name
  2184. * Security: SSL/TLS (always)
  2185. * Authentication: Plain
  2186. * Port: 993
  2187. **** Outgoing (SMTP) server settings
  2188. * Select settings/account settings
  2189. * Select Sending mail/outgoing server
  2190. * Set SMTP server to your domain name
  2191. * Set Security to SSL/TLS (always)
  2192. * Set port to 465
  2193. * Set authentication to PLAIN
  2194. * Enter your username and password
  2195. * Accept the SSL certificate
  2196. **** Folders
  2197. To view any new folders which you may have created using the /mailinglistrule/ script from your inbox press the *K9 icon* at the top left to access folders, then press the *menu button* and select *refresh folder list*.
  2198. If your folder still doesn't show up then press the *menu button*, select *show folders* and select *all folders*.
  2199. *** Webmail
  2200. #+BEGIN_VERSE
  2201. /Most of the information extracted is "content", such as recordings of phone calls or the substance of email messages./
  2202. -- From a 2013 Guardian article on GCHQ/NSA bulk internet data interception.
  2203. #+END_VERSE
  2204. For maximum speed and efficiency the recommended email client is Mutt, accessed via ssh, but non-technical people who aren't using an Android app are unlikely to want to use email in that manner. So it's a good idea to also have a webmail system installed, both for accessibility and as a fallback should ssh not be available due to port blocking.
  2205. If you're not already logged in as root:
  2206. #+BEGIN_SRC: bash
  2207. su
  2208. #+END_SRC
  2209. Install dependencies.
  2210. #+BEGIN_SRC: bash
  2211. apt-get install mysql-server libapache2-mod-authz-unixgroup
  2212. #+END_SRC
  2213. Create a mysql database, specifying a password which should be a long random string generated with a password manager such as KeepassX.
  2214. #+BEGIN_SRC: bash
  2215. mysql -u root -p
  2216. create database roundcubemail;
  2217. CREATE USER 'roundcube'@'localhost' IDENTIFIED BY 'roundcubepassword';
  2218. GRANT ALL PRIVILEGES ON roundcubemail.* TO 'roundcube'@'localhost';
  2219. quit
  2220. #+END_SRC
  2221. Download roundcube.
  2222. #+BEGIN_SRC: bash
  2223. mkdir ~/build
  2224. cd ~/build
  2225. wget http://freedombone.uk.to/roundcubemail.tar.gz
  2226. #+END_SRC
  2227. Verify it.
  2228. #+BEGIN_SRC: bash
  2229. sha256sum roundcubemail.tar.gz
  2230. 1c1560a7a56e6884b45c49f52961dbbb3f6bacbc7e7c755440750a1ab027171c
  2231. #+END_SRC
  2232. Extract the files.
  2233. #+BEGIN_SRC: bash
  2234. tar -xzvf roundcubemail.tar.gz
  2235. export HOSTNAME=mydomainname.com
  2236. cp -r roundcubemail-* /var/www/$HOSTNAME/htdocs/mail
  2237. chown -R www-data:www-data /var/www/$HOSTNAME/htdocs/mail/temp
  2238. chown -R www-data:www-data /var/www/$HOSTNAME/htdocs/mail/logs
  2239. rm /var/www/$HOSTNAME/htdocs/mail/.htaccess
  2240. #+END_SRC
  2241. Edit your web site configuration.
  2242. #+BEGIN_SRC: bash
  2243. editor /etc/nginx/sites-available/$HOSTNAME
  2244. #+END_SRC
  2245. Within the 80 VirtualHost section add the following:
  2246. #+BEGIN_SRC: bash
  2247. location /mail/ {
  2248. deny all;
  2249. }
  2250. #+END_SRC
  2251. Within the 443 VirtualHost section add the following:
  2252. #+BEGIN_SRC: bash
  2253. location /mail/ {
  2254. autoindex on;
  2255. allow all;
  2256. }
  2257. #+END_SRC
  2258. Save and exit, then restart Apache.
  2259. #+BEGIN_SRC: bash
  2260. service nginx restart
  2261. #+END_SRC
  2262. Now with a browser visit https://mydomainname.com/mail/installer. Scroll down and click "next". Give your webmail site a product name.
  2263. Change *spellcheck_engine* to *ATD*.
  2264. Under database settings change the database type to SQlite and leave all other fields blank.
  2265. Unser IMAP set *default_host* to ssl://mydomainname.com, *default_port* to 993 and *username_domain* to your domain name.
  2266. Set *smtp_port* to 465.
  2267. Check "Use the current IMAP username and password for SMTP authentication"
  2268. Change the *database password* to the password you gave when creating the MySql database above.
  2269. Click *create config*
  2270. Click download to download the file.
  2271. The config file which you downloaded should contain the following:
  2272. #+BEGIN_SRC: bash
  2273. $config['default_host'] = 'localhost';
  2274. $config['smtp_port'] = 465;
  2275. $config['username_domain'] = '';
  2276. #+END_SRC
  2277. In a terminal on your local machine (not logged into the BBB):
  2278. #+BEGIN_SRC: bash
  2279. cd ~/Downloads
  2280. scp config.inc.php myusername@mydomainname.com:/home/myusername
  2281. #+END_SRC
  2282. Then in a terminal ssh'd into the BBB:
  2283. #+BEGIN_SRC: bash
  2284. mv /home/myusername/config.inc.php /var/www/$HOSTNAME/htdocs/mail/config
  2285. chmod 755 /var/www/$HOSTNAME/htdocs/mail/config/config.inc.php
  2286. #+END_SRC
  2287. Click *continue*.
  2288. Click *initialize database*.
  2289. Under *Test SMTP config* you can use a [[mailinator.com]] address to check that mail can be sent.
  2290. Now we can delete the installer.
  2291. #+BEGIN_SRC: bash
  2292. rm -rf /var/www/$HOSTNAME/htdocs/mail/installer
  2293. #+END_SRC
  2294. Now with a browser navigate to https://mydomainname.com/mail and log in.
  2295. You'll notice that you may not be able to see any mailing list folders which you may have created earlier using the /mailinglistrule/ script. To make folders visible click on the cog-like settings icon at the bottom left of the screen then select *manage folders*. You will then be able to select which folders you wish to become visible. Make sure that the *Sent*, *spam* and *ham* folders are selected.
  2296. Click on the *Mail* icon to go back to your main mail screen then click on the *Settings* icon at the top right of the screen and select *special folders*. Set *Junk* to *spam* then click the save button. Also select *identities* and make sure that your email address is correct.
  2297. *** Thunderbird
  2298. #+BEGIN_VERSE
  2299. /Towards the end of 2012, we heard from the National Technical Assistance Centre (NTAC), a division of GCHQ and a liaison with the Home Office, [that] they wanted the keys to decrypt the customer data./
  2300. -- Brian Spector, on the shutting down of the PrivateSky encrypted email service
  2301. #+END_VERSE
  2302. Another common way in which you may want to access email is via Thunderbird. This may be especially useful if you're trying to convert former Windows users who may previously have been using some version of Outlook.
  2303. The following instructions should be carried out on the client machines (laptop, etc), not on the BBB itself.
  2304. **** Initial setup
  2305. Install *Thunderbird* and *Enigmail*. How you do this just depends upon your distro and software manager or "app store".
  2306. Open Thinderbird
  2307. Select "*Skip this and use existing email*"
  2308. Enter your name, email address (myusername@mydomainname.com) and the password for your user (the one from [[Add a user]]).
  2309. You'll get a message saying "/Thunderbird failed to find the settings/"
  2310. The settings should be as follows, substituting /mydomainname.com/ for your domain name and /myusername/ for the username given previously in [[Add a user]].
  2311. * Incoming: IMAP, mydomainname.com, 993, SSL/TLS, Normal Password
  2312. * Outgoing: SMTP, mydomainname.com, 465, SSL/TLS, Normal Password
  2313. * Username: myusername
  2314. Click *Done*.
  2315. Click *Get Certificate* and make sure "*permanently store this exception*" is selected", then click *Store Security Exception*.
  2316. From OpenPGP setup select "*Yes, I would like the wizard to get me started*". If the wizard doesn't start automatically then "setup wizard" can be selected from OpenPGP on the menu bar.
  2317. Select "*Yes, I want to sign all of my email*"
  2318. Select "*No, I will create per-recipient rules*"
  2319. Select "*yes*" to change default settings.
  2320. **** If you have existing GPG key
  2321. Export your GPG public and private keys.
  2322. #+BEGIN_SRC: bash
  2323. gpg --output ~/public_key.txt --armor --export KEY_ID
  2324. gpg --output ~/private_key.txt --armor --export-secret-key KEY_ID
  2325. #+END_SRC
  2326. Select "*I have existing public and private keys*".
  2327. Select your public and private GPG exported key files.
  2328. Select the account which you want to use and click *Next*, *Next* and *Finish*.
  2329. Remove your exported key files.
  2330. #+BEGIN_SRC: bash
  2331. shred -zu ~/public_key.txt
  2332. shred -zu ~/private_key.txt
  2333. #+END_SRC
  2334. **** If you don't have any existing GPG or PGP key
  2335. Select "*I want to create a new key pair*"
  2336. Enter a passphrase and click *Next* a couple of times.
  2337. Click *Generate Certificate* to generate a revocation certificate.
  2338. Enter the passphrase which you gave previously.
  2339. Click *Finish*
  2340. From the menu select *OpenPGP* and then *Key Management*. Make sure that *Display all keys* is selected and then select your key. Select *Keyserver* on the menu and then *Upload Public Keys*. This will upload your public key to a key server so that others can find it.
  2341. Select *File* from the menu then *Export keys to file*. Click on *Export Secret keys* and select a location to save them to. It's a good idea to save them to a USB stick which can then be removed from the computer and carried around on a keyring together with your physical keys. If you need to set up GPG or Thunderbird/Enigmail on others then this file will be used to import your keys.
  2342. **** Using for the first time
  2343. Click on the Thunderbird menu, which looks like three horizontal bars on the right hand side.
  2344. Hover over *preferences* and then *Account settings*.
  2345. Select *OpenPGP Security* and make sure that *use PGP/MIME by default* is ticked. This will enable you to sign/encrypt attachments, HTML bodies and UTF-8 without any problems.
  2346. Select *Synchronization & Storage*.
  2347. Make sure that *Keep messages for this account on this computer* is unticked, then click *Ok*.
  2348. Click on *Inbox*. Depending upon how much email you have it may take a while to import the subject lines.
  2349. Note that when sending an email for the first time you will also need to accept the SSL certificate.
  2350. Get into the habit of using email encryption and encourage others to do so. Remember that you may not think that your emails are very interesting but the Surveillance State is highly interested in them and will be actively trying to data mine your private life looking for "suspicious" patterns, regardless of whether you are guilty of any crime or not.
  2351. **** Making folders visible
  2352. By default you won't be able to see any folders which you may have created earlier using the /mailinglistrule/ script. To make folders visible select:
  2353. *Menu*, hover over *Preferences*, select *Account Settings*, select *Server Settings* then click on the *Advanced* button.
  2354. Make sure that "*show only subscribed folders*" is not checked. Then click the *ok* buttons. Folders will be re-scanned, which may take some time depending upon how much email you have, but your folders will then appear.
  2355. ** Create Email folders and rules
  2356. #+BEGIN_VERSE
  2357. /Yes, the NSA set fire to the Internet but it’s the business models of Google, Facebook, etc, that provide the firewood. Trusting the companies supplying the firewood to be your fire fighters is naïve at best./
  2358. -- Aral Balkan
  2359. #+END_VERSE
  2360. *** Rules for mailing lists
  2361. A common situation with email is that you may be subscribed to various mailing lists and want incoming email from those to be automatically grouped into a separate folder for each list.
  2362. We can make a script to make adding mailing list rules easy:
  2363. #+BEGIN_SRC: bash
  2364. editor /usr/bin/mailinglistrule
  2365. #+END_SRC
  2366. Add the following:
  2367. #+BEGIN_SRC: bash
  2368. #!/bin/bash
  2369. MYUSERNAME=$1
  2370. MAILINGLIST=$2
  2371. SUBJECTTAG=$3
  2372. MUTTRC=/home/$MYUSERNAME/.muttrc
  2373. PM=/home/$MYUSERNAME/.procmailrc
  2374. LISTDIR=/home/$MYUSERNAME/Maildir/$MAILINGLIST
  2375. if [ ! -d "$LISTDIR" ]; then
  2376. mkdir -m 700 $LISTDIR
  2377. mkdir -m 700 $LISTDIR/tmp
  2378. mkdir -m 700 $LISTDIR/new
  2379. mkdir -m 700 $LISTDIR/cur
  2380. fi
  2381. chown -R $MYUSERNAME:$MYUSERNAME $LISTDIR
  2382. echo "" >> $PM
  2383. echo ":0" >> $PM
  2384. echo " * ^Subject:.*()\[$SUBJECTTAG\]" >> $PM
  2385. echo "$LISTDIR/new" >> $PM
  2386. chown $MYUSERNAME:$MYUSERNAME $PM
  2387. if [ ! -f "$MUTTRC" ]; then
  2388. cp /etc/Muttrc $MUTTRC
  2389. chown $MYUSERNAME:$MYUSERNAME $MUTTRC
  2390. fi
  2391. PROCMAILLOG=/home/$MYUSERNAME/log
  2392. if [ ! -d $PROCMAILLOG ]; then
  2393. mkdir $PROCMAILLOG
  2394. chown -R $MYUSERNAME:$MYUSERNAME $PROCMAILLOG
  2395. fi
  2396. #+END_SRC
  2397. Save and exit, then make the script executable.
  2398. #+BEGIN_SRC: bash
  2399. chmod +x /usr/bin/mailinglistrule
  2400. #+END_SRC
  2401. Now we can add a new mailing list rule with the following, where /myusername/ is your username, /mailinglistname/ is the name of the mailing list (with no spaces) and /subjecttag/ is the tag which usually appears within square brackets in the subject line of emails from the list.
  2402. #+BEGIN_SRC: bash
  2403. mailinglistrule [myusername] [mailinglistname] [subjecttag]
  2404. #+END_SRC
  2405. Repeat this command for as many mailing lists as you need. Then edit your local Mutt configuration.
  2406. #+BEGIN_SRC: bash
  2407. editor /home/myusername/.muttrc
  2408. #+END_SRC
  2409. Search for the *mailboxes* variable and add entries for the mailing lists you just created. For example:
  2410. #+BEGIN_SRC: bash
  2411. mailboxes = =Sent =mailinglistname
  2412. #+END_SRC
  2413. Then save and exit.
  2414. *** Rules for specific email addresses
  2415. You can also make a script which will allow you to move mail from specific email addresses to a folder.
  2416. #+BEGIN_SRC: bash
  2417. editor /usr/bin/emailrule
  2418. #+END_SRC
  2419. Add the following:
  2420. #+BEGIN_SRC: bash
  2421. #!/bin/bash
  2422. MYUSERNAME=$1
  2423. EMAILADDRESS=$2
  2424. MAILINGLIST=$3
  2425. MUTTRC=/home/$MYUSERNAME/.muttrc
  2426. PM=/home/$MYUSERNAME/.procmailrc
  2427. LISTDIR=/home/$MYUSERNAME/Maildir/$MAILINGLIST
  2428. if [ ! -d "$LISTDIR" ]; then
  2429. mkdir -m 700 $LISTDIR
  2430. mkdir -m 700 $LISTDIR/tmp
  2431. mkdir -m 700 $LISTDIR/new
  2432. mkdir -m 700 $LISTDIR/cur
  2433. fi
  2434. chown -R $MYUSERNAME:$MYUSERNAME $LISTDIR
  2435. echo "" >> $PM
  2436. echo ":0" >> $PM
  2437. echo " * ^From: $EMAILADDRESS" >> $PM
  2438. echo "$LISTDIR/new" >> $PM
  2439. chown $MYUSERNAME:$MYUSERNAME $PM
  2440. if [ ! -f "$MUTTRC" ]; then
  2441. cp /etc/Muttrc $MUTTRC
  2442. chown $MYUSERNAME:$MYUSERNAME $MUTTRC
  2443. fi
  2444. PROCMAILLOG=/home/$MYUSERNAME/log
  2445. if [ ! -d $PROCMAILLOG ]; then
  2446. mkdir $PROCMAILLOG
  2447. chown -R $MYUSERNAME:$MYUSERNAME $PROCMAILLOG
  2448. fi
  2449. #+END_SRC
  2450. Save and exit, then make the script executable.
  2451. #+BEGIN_SRC: bash
  2452. chmod +x /usr/bin/emailrule
  2453. #+END_SRC
  2454. Then to add a particular email address to a folder run the command:
  2455. #+BEGIN_SRC: bash
  2456. emailrule [myusername] [emailaddress] [foldername]
  2457. #+END_SRC
  2458. If you want any mail from the given email address to be deleted then set the /foldername/ to /Trash/.
  2459. To ensure that the folder appears within Mutt.
  2460. #+BEGIN_SRC: bash
  2461. editor /home/myusername/.muttrc
  2462. #+END_SRC
  2463. Search for the *mailboxes* variable and add entries for the mailing lists you just created. For example:
  2464. #+BEGIN_SRC: bash
  2465. mailboxes = =Sent =foldername
  2466. #+END_SRC
  2467. Then save and exit.
  2468. ** Install a Blog
  2469. #+BEGIN_VERSE
  2470. /When society gives censors wide and vague powers they never confine themselves to deserving targets. They are not snipers, but machine-gunners. Allow them to fire at will, and they will hit anything that moves./
  2471. -- Nick Cohen
  2472. #+END_VERSE
  2473. Wordpress is the most popular blogging platform, but in practice I found it to be high maintenance with frequent security updates and breakages. More practical for a home server is Flatpress. Flatpress doesn't use a MySql database, just text files, and so is easy to relocate or reinstall.
  2474. See the [[Setting up a web site]] section of this document for details of how to configure the web server for your blog's domain.
  2475. Download flatpress.
  2476. #+BEGIN_SRC: bash
  2477. mkdir ~/build
  2478. cd ~/build
  2479. wget http://freedombone.uk.to/flatpress.tar.gz
  2480. #+END_SRC
  2481. Verify the download:
  2482. #+BEGIN_SRC: bash
  2483. sha256sum flatpress.tar.gz
  2484. 6312a49aab5aabd6371518dcaf081f489dff04d001bc34b4fe3f2a81170bbd4e flatpress.tar.gz
  2485. #+END_SRC
  2486. Extract and install it.
  2487. #+BEGIN_SRC: bash
  2488. tar -xzvf flatpress.tar.gz
  2489. cd flatpress-*
  2490. cp -r * /var/www/$HOSTNAME/htdocs
  2491. chmod -R 755 /var/www/$HOSTNAME/htdocs/fp-content
  2492. chown -R www-data:www-data /var/www/$HOSTNAME/htdocs/fp-content
  2493. cd ..
  2494. rm -rf flatpress-*
  2495. rm -f flatpress.tar.gz
  2496. #+END_SRC
  2497. Now visit your blog and follow the setup instructions, which are quite minimal. Various themes and addons are available from the Flatpress web site, http://www.flatpress.org
  2498. ** Install an IRC server
  2499. #+BEGIN_VERSE
  2500. /Give me the liberty to know, to utter, and to argue freely according to conscience, above all liberties./
  2501. -- John Milton
  2502. #+END_VERSE
  2503. *** Base install
  2504. IRC is not an especially secure system. For instance, even with the best encryption it's easily possible to imagine IRC-specific cribs which could be used by cryptanalytic systems. However, we'll try to implement it in a manner which will at least give the surveillance aparatus something to ponder over.
  2505. #+BEGIN_SRC: bash
  2506. adduser ircserver
  2507. cd ~/build
  2508. wget http://freedombone.uk.to/ircd-hybrid-8.1.20.tgz
  2509. #+END_SRC
  2510. Verify the download.
  2511. #+BEGIN_SRC: bash
  2512. sha256sum ircd-hybrid-8.1.20.tgz
  2513. 5570be89fa76b2712d7f08d6c828d613d201daed8c1064be7245fe10bdffa228
  2514. #+END_SRC
  2515. Download Anope.
  2516. #+BEGIN_SRC: bash
  2517. wget http://freedombone.uk.to/anope-2.0.1-source.tar.gz
  2518. #+END_SRC
  2519. And verify it.
  2520. #+BEGIN_SRC: bash
  2521. sha256sum anope-2.0.1-source.tar.gz
  2522. 539f603adc4f982e3a5ffd175ecb007aadc619a692409b3e9e1f7f15fb1288e6
  2523. #+END_SRC
  2524. Then compile and install them.
  2525. #+BEGIN_SRC: bash
  2526. apt-get install libssl-dev cmake
  2527. tar -xvf ircd-hybrid-8.1.20.tgz
  2528. tar -xvf anope-2.0.1-source.tar.gz
  2529. cd ~/build/ircd-hybrid-8.1.20
  2530. ./configure -prefix="/home/ircserver/ircd"
  2531. make
  2532. make install
  2533. cd ~/build/anope-2.0.1-source
  2534. ./Config
  2535. #+END_SRC
  2536. Answer the questions as follows:
  2537. #+BEGIN_SRC: bash
  2538. In what directory do you want the binaries to be installed?
  2539. /home/ircserver/services
  2540. Create it?
  2541. y
  2542. Where do you want the data files to be installed?
  2543. /home/ircserver/services
  2544. Which group should all Services data files be owned by?
  2545. ircserver
  2546. What should the default umask for data files be (in octal)?
  2547. 007
  2548. Would you like to build a debug version of Anope?
  2549. n
  2550. Would you like to utilize run-cc.pl?
  2551. n
  2552. Do you want to build using precompiled headers?
  2553. n
  2554. If you need no extra include directories.
  2555. NONE
  2556. Are there any extra arguments you wish to pass to CMake?
  2557. NONE
  2558. #+END_SRC
  2559. Then build and install Anope.
  2560. #+BEGIN_SRC: bash
  2561. cd build
  2562. make
  2563. make install
  2564. cd /home/ircserver/ircd/etc
  2565. cp reference.conf ircd.conf
  2566. #+END_SRC
  2567. Create some ssl certificates:
  2568. #+BEGIN_SRC: bash
  2569. mkdir /home/ircserver/ircd/ssl
  2570. openssl genrsa -out /home/ircserver/ircd/ssl/ircd.key 4096
  2571. openssl req -new -x509 -key /home/ircserver/ircd/ssl/ircd.key -out /home/ircserver/ircd/ssl/ircd.pem -days 3650
  2572. #+END_SRC
  2573. You will be asked for some details. The next step will take a few minutes to gather entropy, so go and do something else.
  2574. #+BEGIN_SRC: bash
  2575. openssl dhparam -out /home/ircserver/ircd/ssl/dhparam.pem 1024
  2576. #+END_SRC
  2577. Now alter the permissions on the files so that they're accessible to the /ircserver/ user:
  2578. #+BEGIN_SRC: bash
  2579. chmod 600 /home/ircserver/ircd/ssl/ircd.key
  2580. chmod 600 /home/ircserver/ircd/ssl/ircd.pem
  2581. chmod 600 /home/ircserver/ircd/ssl/dhparam.pem
  2582. chown -R ircserver:ircserver /home/ircserver/ircd
  2583. chown -R ircserver:ircserver /home/ircserver/services
  2584. #+END_SRC
  2585. Now edit the configuration:
  2586. #+BEGIN_SRC: bash
  2587. editor /home/ircserver/ircd/etc/ircd.conf
  2588. #+END_SRC
  2589. Comment out:
  2590. #+BEGIN_SRC: bash
  2591. // havent_read_conf = 1;
  2592. // flags = need_ident;
  2593. #+END_SRC
  2594. Uncomment and change the following lines:
  2595. #+BEGIN_SRC: bash
  2596. rsa_private_key_file = "/home/ircserver/ircd/ssl/ircd.key";
  2597. ssl_certificate_file = "/home/ircserver/ircd/ssl/ircd.pem";
  2598. ssl_dh_param_file = "/home/ircserver/ircd/ssl/dhparam.pem";
  2599. #+END_SRC
  2600. Above the ssl parameters set *network_name* to your domain name.
  2601. Uncomment:
  2602. #+BEGIN_SRC: bash
  2603. ssl_server_method = tldv1, sslv3;
  2604. #+END_SRC
  2605. Within the *operator* section (line 424):
  2606. #+BEGIN_SRC: bash
  2607. name = "myusername";
  2608. user = "*@192.168.1.*";
  2609. password = "mypassword";
  2610. encrypted = no;
  2611. #+END_SRC
  2612. Within the *connect* section (line 555):
  2613. #+BEGIN_SRC: bash
  2614. name = "mydomainname.com";
  2615. host = "192.168.1.60";
  2616. vhost = "192.168.1.60";
  2617. send_password = "mysendacceptpassword";
  2618. accept_password = "mysendacceptpassword";
  2619. #+END_SRC
  2620. And within the *service* section:
  2621. #+BEGIN_SRC: bash
  2622. name = "mydomainname.com";
  2623. #+END_SRC
  2624. Within the serverinfo section change *name*, *network_name* and *network_desc* to a name and description for your IRC server. To avoid confusion you could make the name and network name the same as your domain name.
  2625. Change *max_clients* to 20, or a number which is sufficient for the number of simultaneous users you expect.
  2626. Save and exit.
  2627. #+BEGIN_SRC: bash
  2628. cd /home/ircserver/services/conf
  2629. cp example.conf services.conf
  2630. editor services.conf
  2631. #+END_SRC
  2632. Set the following, replacing /operatorpassword/ with a password which will be used to manage your IRC channels, /mydomainname.com/ with your domain name and /myusername/ with your username:
  2633. Within the *module* section set *name* to "hybrid".
  2634. Within the *uplink* section set *password* to the /sendacceptpassword/.
  2635. Uncomment *#oper* and *name* underneath it, and change the name to your username.
  2636. Save and exit, then create a daemon.
  2637. #+BEGIN_SRC: bash
  2638. editor /etc/init.d/ircd-hybrid
  2639. #+END_SRC
  2640. Add the following:
  2641. #+BEGIN_SRC: bash
  2642. #!/bin/bash
  2643. # /etc/init.d/ircd-hybrid
  2644. ### BEGIN INIT INFO
  2645. # Provides: ircd-hybrid
  2646. # Required-Start: $remote_fs $syslog
  2647. # Required-Stop: $remote_fs $syslog
  2648. # Default-Start: 2 3 4 5
  2649. # Default-Stop: 0 1 6
  2650. # Short-Description: starts irc server
  2651. # Description: starts irc server
  2652. ### END INIT INFO
  2653. # Author: Bob Mottram <bob@robotics.uk.to>
  2654. #Settings
  2655. SERVICE='ircd-hybrid'
  2656. COMMAND='ircd'
  2657. USER='ircserver'
  2658. NICELEVEL=19 # from 0-19 the bigger the number, the less the impact on system resources
  2659. HISTORY=1024
  2660. INVOCATION="nice -n ${NICELEVEL} ${COMMAND}"
  2661. PATH='/usr/local/sbin:/usr/local/bin:/usr/bin:/sbin:/usr/sbin:/bin:/home/ircserver/ircd/sbin:/home/ircserver/ircd/bin'
  2662. irc_start() {
  2663. echo "Starting $SERVICE..."
  2664. cd /home/$USER/ircd
  2665. su --command "bin/$COMMAND" $USER
  2666. su --command "/home/$USER/services/bin/services" $USER
  2667. }
  2668. irc_stop() {
  2669. echo "Stopping $SERVICE"
  2670. killall -15 $COMMAND
  2671. killall -15 $USER
  2672. }
  2673. #Start-Stop here
  2674. case "$1" in
  2675. start)
  2676. irc_start
  2677. ;;
  2678. stop)
  2679. irc_stop
  2680. ;;
  2681. restart)
  2682. irc_stop
  2683. sleep 10s
  2684. irc_start
  2685. ;;
  2686. *)
  2687. echo "Usage: $0 {start|stop|restart}"
  2688. exit 1
  2689. ;;
  2690. esac
  2691. exit 0
  2692. #+END_SRC
  2693. Save and exit, then start the daemon.
  2694. #+BEGIN_SRC: bash
  2695. chmod +x /etc/init.d/ircd-hybrid
  2696. update-rc.d ircd-hybrid defaults
  2697. service ircd-hybrid start
  2698. #+END_SRC
  2699. *** Channel management
  2700. To to install channel management tools.
  2701. #+BEGIN_SRC: bash
  2702. mkdir ~/build
  2703. cd ~/build
  2704. wget http://freedombone.uk.to/hybserv_1.9.4-1_armhf.deb
  2705. #+END_SRC
  2706. Verify it.
  2707. #+BEGIN_SRC: bash
  2708. sha256sum hybserv_1.9.4-1_armhf.deb
  2709. 41bf4eb6e24c87610a80bc14db1103a57484835510eea7e4ba9709c523318615 hybserv_1.9.4-1_armhf.deb
  2710. #+END_SRC
  2711. Install it.
  2712. #+BEGIN_SRC: bash
  2713. dpkg -i hybserv_1.9.4-1_armhf.deb
  2714. #+END_SRC
  2715. Make a md5 version of the password for the IRC server operator.
  2716. #+BEGIN_SRC: bash
  2717. /usr/bin/mkpasswd <myoperatorpassword>
  2718. #+END_SRC
  2719. Edit the ircd-hybrid configuration.
  2720. #+BEGIN_SRC: bash
  2721. editor /etc/ircd-hybrid/ircd.conf
  2722. #+END_SRC
  2723. Enter the md5 password which you previously created within the /operator/ section. Also change /user/ to:
  2724. #+BEGIN_SRC: bash
  2725. user = "*@*";
  2726. #+END_SRC
  2727. Then save and exit.
  2728. #+BEGIN_SRC: bash
  2729. editor /etc/hybserv/hybserv.conf
  2730. #+END_SRC
  2731. Change #MD5 PASSWORD HERE# to the md5 operator password created earlier, mydomainname.com to your domain name and mysendacceptpassword to the send/accept password specified within /ircd.conf/.
  2732. #+BEGIN_SRC: bash
  2733. A:mynickname <myemailaddress>
  2734. N:irc.mydomainname.com:Hybrid services
  2735. O:*@*:#MD5 PASSWORD HERE#:root:segj (comment out other Q: lines)
  2736. S:mysendacceptpassword:192.168.1.60:6697 (remove the other two services)
  2737. #+END_SRC
  2738. Also remove the line *#NOT-EDITED#*, then save and exit.
  2739. Now we need to restart the ircd and hybrid server to make things work:
  2740. #+BEGIN_SRC: bash
  2741. service ircd-hybrid restart
  2742. service hybserv start
  2743. #+END_SRC
  2744. *** Usage with Irssi
  2745. On another computer (not the BBB).
  2746. #+BEGIN_SRC: bash
  2747. sudo apt-get install irssi irssi-plugin-otr irssi-plugin-xmpp
  2748. irssi
  2749. #+END_SRC
  2750. Connect to the IRC and identify yourself as an operator. Here /mynetwork/ should be the same as *network_name* specified earlier within /ircd.conf/. The network name is something equivalent to "freenode".
  2751. #+BEGIN_SRC: bash
  2752. /network add -nick mynick mynetwork
  2753. /channel add -auto #mychannel mynetwork channelpassword
  2754. /server add -auto -network mynetwork -ssl mydonainname.com 6697 mysendacceptpassword
  2755. /connect mydomainname.com
  2756. /join #mychannel
  2757. /msg -servername chanserv REGISTER #mychannel channelpassword
  2758. /msg -servername chanserv set #mychannel mlock +k channelpassword
  2759. /set paste_join_multiline OFF
  2760. #+END_SRC
  2761. If you edit the irssi config file:
  2762. #+BEGIN_SRC: bash
  2763. editor ~/.irssi/config
  2764. #+END_SRC
  2765. It should look something like this:
  2766. #+BEGIN_SRC: bash
  2767. {
  2768. address = "mydomainname.com";
  2769. chatnet = "mynetwork";
  2770. port = "6697";
  2771. password = "mysendacceptpassword";
  2772. use_ssl = "yes";
  2773. ssl_verify = "no";
  2774. autoconnect = "yes";
  2775. },
  2776. #+END_SRC
  2777. If you're not using a self-signed certificate (self-signed is the default) then you can set *ssl_verify* to "yes".
  2778. By default irssi will use UTC time. An example of setting to some other time zone is as follows:
  2779. #+BEGIN_SRC: bash
  2780. echo "load perl" >> ~/.irssi/startup
  2781. echo "script exec $ENV{'TZ'}='Europe/London';" >> ~/.irssi/startup
  2782. #+END_SRC
  2783. Also enable /Off The Record/ (OTR) messaging.
  2784. #+BEGIN_SRC: bash
  2785. echo "load otr" >> ~/.irssi/startup
  2786. #+END_SRC
  2787. By default Irssi does not look especially attractive. To improve it's looks:
  2788. #+BEGIN_SRC: bash
  2789. cd ~/.irssi
  2790. wget http://freedombone.uk.to/irssi/xchat.theme
  2791. mkdir ~/.irssi/scripts
  2792. mkdir ~/.irssi/scripts/autorun
  2793. cd ~/.irssi/scripts/autorun
  2794. wget http://freedombone.uk.to/irssi/xchatnickcolor.pl
  2795. wget http://freedombone.uk.to/irssi/adv_windowlist.pl
  2796. #+END_SRC
  2797. Verify the files:
  2798. #+BEGIN_SRC: bash
  2799. sha256sum ~/.irssi/xchat.theme
  2800. 7a84130ad55aabd0b043a03b013628438e6c7f82a58e15267633bc7eb443e60b
  2801. sha256sum ~/.irssi/scripts/autorun/xchatnickcolor.pl
  2802. 8293e867a22d42ce5a28cd755237509b6f3587fd2b21d7d20af4a832081610ca
  2803. sha256sum ~/.irssi/scripts/autorun/adv_windowlist.pl
  2804. e4dd8f6d384bf4f2d0ab5ccf06df06e4a69d2647b08d37c8fc6cfd9326688395
  2805. #+END_SRC
  2806. Then run Irssi and enter the commands:
  2807. #+BEGIN_SRC: bash
  2808. /set theme xchat
  2809. /statusbar window remove act
  2810. /set awl
  2811. /set awl_block -14
  2812. /set awl_display_key $Q%K|$N%n $H$C$S
  2813. /set awl_display_key_active $Q%K|$N%n $H%U$C%n$S
  2814. /set awl_display_nokey [$N]$H$C$S
  2815. /run autorun/adv_windowlist.pl
  2816. /set awl_viewer off
  2817. /save
  2818. #+END_SRC
  2819. *** Using irssi with Off The Record messaging (OTR)
  2820. Once you're running irssi then you can enable OTR with:
  2821. #+BEGIN_SRC: bash
  2822. /statusbar window add otr
  2823. /otr genkey mynick@network (for example mynick@irc.freenode.net)
  2824. #+END_SRC
  2825. Then to see your OTR fingerprint:
  2826. #+BEGIN_SRC: bash
  2827. /otr info
  2828. #+END_SRC
  2829. And to trust or distrust someone else's fingerprint.
  2830. #+BEGIN_SRC: bash
  2831. /otr trust [fingerprint]
  2832. /otr distrust [fingerprint]
  2833. #+END_SRC
  2834. *** Usage with XChat
  2835. Within the network list click, *Add* and enter your domain name then click *Edit*.
  2836. Select the entry within the servers box, then enter *mydomainname.com/6697* and press *Enter*.
  2837. Uncheck *use global user information*.
  2838. Enter first and second nicknames and check *auto connect to this network on startup*.
  2839. Check *use SSL* and *accept invalid SSL certificate*.
  2840. Enter some favourite channels and within *server password* enter /mysendacceptpassword/ which you defined earlier when setting up the server.
  2841. Click *close* and then *connect*.
  2842. *** Install Irssi as a daemon
  2843. It may be useful to run a persistent Irssi session on the BBB. This will enable you to log in and see any entries which occurred previously so that you don't find yourself in an argument without knowledge of what was said in the last few minutes or hours. This feature only works for a single user on the BBB - typically the administrator.
  2844. First install some prerequisites.
  2845. #+BEGIN_SRC: bash
  2846. apt-get install irssi irssi-plugin-otr irssi-plugin-xmpp screen
  2847. #+END_SRC
  2848. Create an initialisation script.
  2849. #+BEGIN_SRC: bash
  2850. editor /etc/init.d/irssid
  2851. #+END_SRC
  2852. Add the following:
  2853. #+BEGIN_SRC: bash
  2854. #!/bin/bash
  2855. ### BEGIN INIT INFO
  2856. # Provides: irssid
  2857. # Required-Start: $network
  2858. # Required-Stop: $network
  2859. # Default-Start: 2 3 4 5
  2860. # Default-Stop: 0 1 6
  2861. # Short-Description: Start irssi daemon within screen session at boot time
  2862. # Description: This init script will start an irssi session under screen using the settings provided in /etc/irssid.conf
  2863. ### END INIT INFO
  2864. # Include the LSB library functions
  2865. . /lib/lsb/init-functions
  2866. # Setup static variables
  2867. configFile='/etc/irssid.conf'
  2868. daemonExec='/usr/bin/screen'
  2869. daemonArgs='-D -m'
  2870. daemonName="$(basename "$daemonExec")"
  2871. pidFile='/var/run/irssid.pid'
  2872. #
  2873. # Checks if the environment is capable of running the script (such as
  2874. # availability of programs etc).
  2875. #
  2876. # Return: 0 if the environmnt is properly setup for execution of init script, 1
  2877. # if not all conditions have been met.
  2878. #
  2879. function checkEnvironment() {
  2880. # Verify that the necessary binaries are available for execution.
  2881. local binaries=(irssi screen)
  2882. for bin in "${binaries[@]}"; do
  2883. if ! which "$bin" > /dev/null; then
  2884. log_failure_msg "Binary '$bin' is not available. Please install \
  2885. package containing it."
  2886. exit 5
  2887. fi
  2888. done
  2889. }
  2890. #
  2891. # Checks if the configuration files are available and properly setup.
  2892. #
  2893. # Return: 0 if irssid if properly configured, 1 otherwise.
  2894. #
  2895. function checkConfig() {
  2896. # Make sure the configuration file has been created
  2897. if ! [[ -f $configFile ]]; then
  2898. log_failure_msg "Please populate the configuration file '$configFile' \
  2899. before running."
  2900. exit 6
  2901. fi
  2902. # Make sure the required options have been set
  2903. local reqOptions=(user group session)
  2904. for option in "${reqOptions[@]}"; do
  2905. if ! grep -q -e "^[[:blank:]]*$option=" "$configFile"; then
  2906. log_failure_msg "Mandatory option '$option' was not specified in \
  2907. '$configFile'"
  2908. exit 6
  2909. fi
  2910. done
  2911. }
  2912. #
  2913. # Loads the configuration file and performs any additional configuration steps.
  2914. #
  2915. function configure() {
  2916. . "$configFile"
  2917. daemonArgs="$daemonArgs -S $session irssi"
  2918. [[ -n $args ]] && daemonArgs="$daemonArgs $args"
  2919. daemonCommand="$daemonExec $daemonArgs"
  2920. }
  2921. #
  2922. # Starts the daemon.
  2923. #
  2924. # Return: LSB-compliant code.
  2925. #
  2926. function start() {
  2927. start-stop-daemon --start -v -b -x /bin/su -p /tmp/irssi.screen.session -m --chdir /home/$user -- - $user -c "screen -D -m -S irssi -- irssi" 1>>/log.irssi
  2928. }
  2929. #
  2930. # Stops the daemon.
  2931. #
  2932. # Return: LSB-compliant code.
  2933. #
  2934. function stop() {
  2935. start-stop-daemon --stop -x /bin/su -p /tmp/irssi.screen.session -q
  2936. }
  2937. checkEnvironment
  2938. checkConfig
  2939. configure
  2940. case "$1" in
  2941. start)
  2942. log_daemon_msg "Starting daemon" "irssid"
  2943. start && log_end_msg 0 || log_end_msg $?
  2944. ;;
  2945. stop)
  2946. log_daemon_msg "Stopping daemon" "irssid"
  2947. stop && log_end_msg 0 || log_end_msg $?
  2948. ;;
  2949. restart)
  2950. log_daemon_msg "Restarting daemon" "irssid"
  2951. stop
  2952. start && log_end_msg 0 || log_end_msg $?
  2953. ;;
  2954. force-reload)
  2955. log_daemon_msg "Restarting daemon" "irssid"
  2956. stop
  2957. start && log_end_msg 0 || log_end_msg $?
  2958. ;;
  2959. status)
  2960. status_of_proc -p "$pidFile" "$daemonExec" screen && exit 0 || exit $?
  2961. ;;
  2962. *)
  2963. echo "irssid (start|stop|restart|force-reload|status|help)"
  2964. ;;
  2965. esac
  2966. #+END_SRC
  2967. Save and exit.
  2968. #+BEGIN_SRC: bash
  2969. chmod +x /etc/init.d/irssid
  2970. #+END_SRC
  2971. Create a configuration file, replacing /myusername/ with your username.
  2972. #+BEGIN_SRC: bash
  2973. editor /etc/irssid.conf
  2974. #+END_SRC
  2975. #+BEGIN_SRC: bash
  2976. #
  2977. # Configuration file for irssid init script
  2978. #
  2979. # Mandatory options:
  2980. #
  2981. # user - Specify user for running irssi.
  2982. # group - Specify group for running irssi.
  2983. # session - Specify screen session name to be used for irssi.
  2984. #
  2985. # Non-mandatory options:
  2986. #
  2987. # args - Pass additional arguments to irssi.
  2988. #
  2989. user='myusername'
  2990. group='irssi'
  2991. session='irssi'
  2992. args='--config /home/myusername/.irssi/config'
  2993. #+END_SRC
  2994. Save and exit. Then add your user to the irssi group and start the daemon.
  2995. #+BEGIN_SRC: bash
  2996. groupadd irssi
  2997. usermod -aG irssi myusername
  2998. update-rc.d irssid defaults
  2999. chown -R myusername:irssi /home/myusername/.irssi
  3000. service irssid start
  3001. #+END_SRC
  3002. Create a script to make running IRC on the server easier.
  3003. #+BEGIN_SRC: bash
  3004. editor /usr/bin/irc
  3005. #+END_SRC
  3006. Add the following:
  3007. #+BEGIN_SRC: bash
  3008. #!/bin/bash
  3009. screen -r irssi
  3010. #+END_SRC
  3011. Save and exit.
  3012. #+BEGIN_SRC: bash
  3013. chmod +x /usr/bin/irc
  3014. chown myusername:myusername /usr/bin/irc
  3015. #+END_SRC
  3016. Then to subsequently access irssi log into the BBB using ssh and type:
  3017. #+BEGIN_SRC: bash
  3018. irc
  3019. #+END_SRC
  3020. To set UK time within Irssi:
  3021. #+BEGIN_SRC: bash
  3022. /script exec $ENV{'TZ'}='Europe/London';
  3023. /save
  3024. #+END_SRC
  3025. ** Install a Jabber/XMPP server
  3026. #+BEGIN_VERSE
  3027. /Well heck, it isn’t that hard to write an instant messaging system./
  3028. --Jeremie Miller
  3029. #+END_VERSE
  3030. *** The Server
  3031. Generate a SSL certificate.
  3032. #+BEGIN_SRC: bash
  3033. openssl genrsa -out /etc/ssl/private/xmpp.key 4096
  3034. openssl req -new -x509 -key /etc/ssl/private/xmpp.key -out /etc/ssl/certs/xmpp.crt -days 3650
  3035. #+END_SRC
  3036. Change permissions.
  3037. #+BEGIN_SRC: bash
  3038. chmod 600 /etc/ssl/private/xmpp.key
  3039. chmod 600 /etc/ssl/certs/xmpp.crt
  3040. #+END_SRC
  3041. Install Prosody.
  3042. #+BEGIN_SRC: bash
  3043. apt-get install prosody
  3044. chown prosody:prosody /etc/ssl/private/xmpp.key
  3045. chown prosody:prosody /etc/ssl/certs/xmpp.crt
  3046. cp -a /etc/prosody/conf.avail/example.com.cfg.lua /etc/prosody/conf.avail/xmpp.cfg.lua
  3047. editor /etc/prosody/conf.avail/xmpp.cfg.lua
  3048. #+END_SRC
  3049. Change the *VirtualHost* name to your domain name and remove the line below it.
  3050. Set the ssl section to:
  3051. #+BEGIN_SRC: bash
  3052. ssl = {
  3053. key = "/etc/ssl/private/xmpp.key";
  3054. certificate = "/etc/ssl/certs/xmpp.crt";
  3055. }
  3056. #+END_SRC
  3057. And also append the following:
  3058. #+BEGIN_SRC: bash
  3059. modules_enabled = {
  3060. "bosh"; -- Enable mod_bosh
  3061. "tls"; -- Enable mod_tls
  3062. }
  3063. c2s_require_encryption = true
  3064. s2s_require_encryption = true
  3065. #+END_SRC
  3066. Save and exit. Create a symbolic link.
  3067. #+BEGIN_SRC: bash
  3068. ln -sf /etc/prosody/conf.avail/xmpp.cfg.lua /etc/prosody/conf.d/xmpp.cfg.lua
  3069. editor /etc/prosody/prosody.cfg.lua
  3070. #+END_SRC
  3071. Within the *ssl* section set:
  3072. #+BEGIN_SRC: bash
  3073. ssl = {
  3074. key = "/etc/ssl/private/xmpp.key";
  3075. certificate = "/etc/ssl/certs/xmpp.crt";
  3076. }
  3077. #+END_SRC
  3078. Uncomment and set the following to *true*
  3079. #+BEGIN_SRC: bash
  3080. c2s_require_encryption = true
  3081. s2s_require_encryption = true
  3082. #+END_SRC
  3083. Within the *modules_enabled* section uncomment *bosh*, then save and exit.
  3084. Add a user. You will be prompted to specify a password. You can repeat the process for as many users as needed. This will also be your Jabber ID (JID).
  3085. #+BEGIN_SRC: bash
  3086. prosodyctl adduser myusername@mydomainname.com
  3087. #+END_SRC
  3088. Restart the server
  3089. #+BEGIN_SRC: bash
  3090. service prosody restart
  3091. #+END_SRC
  3092. On your internet router/firewall open ports 5222, 5223, 5269, 5280 and 5281 and forward them to the BBB.
  3093. It's possible to test that your XMPP server is working at https://xmpp.net. It may take several minutes and you'll get a low score because of the self-signed certificate, but it will at least verify that your server is capable of communicating.
  3094. *** Managing users
  3095. To add a user:
  3096. #+BEGIN_SRC: bash
  3097. prosodyctl adduser myusername@mydomainname.com
  3098. #+END_SRC
  3099. To change a user password:
  3100. #+BEGIN_SRC: bash
  3101. prosodyctl passwd myusername@mydomainname.com
  3102. #+END_SRC
  3103. To remove a user:
  3104. #+BEGIN_SRC: bash
  3105. prosodyctl deluser myusername@mydomainname.com
  3106. #+END_SRC
  3107. Report the status of the XMPP server:
  3108. #+BEGIN_SRC: bash
  3109. prosodyctl status
  3110. #+END_SRC
  3111. *** Using with Jitsi
  3112. Jitsi is the recommended communications client for desktop or laptop systems, since it includes the /off the record/ (OTR) feature which provides some additional security beyond the usual SSL certificates.
  3113. Jitsi can be downloaded from https://jitsi.org/
  3114. On your desktop/laptop open Jitsi and select *Options* from the *Tools* menu.
  3115. Click *Add* to add a new user, then enter the Jabber ID which you previously specified with /prosodyctl/ when setting up the XMPP server. Close and then you should notice that your status is "Online" (or if not then you should be able to set it to online).
  3116. From the *File* menu you can add contacts, then select the chat icon to begin a chat. Click on the lock icon on the right hand side and this will initiate an authentication procedure in which you can specify a question and answer to verify the identity of the person you're communicating with. Once authentication is complete then you'll be chating using OTR, which provides an additional layer of security.
  3117. When opening Jitsi initially you will get a certificate warning for your domain name (assuming that you're using a self-signed certificate). If this happens then select *View Certificate* and enable the checkbox to trust the certificate, then select *Continue Anyway*. Once you've done this then the certificate warning will not appear again unless you reinstall Jitsi or use a different computer.
  3118. You can also [[https://www.youtube.com/watch?v=vgx7VSrDGjk][see this video]] as an example of using OTR.
  3119. *** Using with Ubuntu
  3120. The default XMPP client in Ubuntu is Empathy. Using Empathy isn't as secure as using Jitsi, since it doesn't include the /off the record/ feature, but since it's the default it's what many users will have easy access to.
  3121. Open *System Settings* and select *Online Accounts*, *Add account* and then *Jabber*.
  3122. Enter your username (myusername@mydomainname.com) and password.
  3123. Click on *Advanced* and make sure that *Encryption required* and *Ignore SSL certificate errors* are checked. Ignoring the certificate errors will allow you to use the self-signed certificate created earlier. Then click *Done* and set your Jabber account and Empathy to *On*.
  3124. *** Using with Android
  3125. There are a few XMPP clients available on Android. Ideally choose ones which support off-the-record messaging. Here are some examples.
  3126. **** Xabber
  3127. Install [[https://f-droid.org/][F-Droid]]
  3128. Search for and install Xabber.
  3129. Add an account and enter your Jabber/XMPP ID and password.
  3130. From the menu select *Settings* then *Security* then *OTR mode*. Set the mode to *Required*.
  3131. Make sure that *Check server certificate* is not checked.
  3132. Go back to the initial screen and then using the menu you can add contacts and begin chatting. Both parties will need to go through the off-the-record question and answer verification before the chat can begin, but that only needs to be done once for each person you're chatting with.
  3133. **** Gibberbot
  3134. Install [[https://f-droid.org/][F-Droid]]
  3135. Search for and install Gibberbot, otherwise known as ChatSecure.
  3136. From the menu open *Accounts*
  3137. Select *Add account*
  3138. Change the server port from 0 to 5222
  3139. Done
  3140. Accept unknown certificate? Select *Always*
  3141. Go back to the initial screen and then using the menu you can add contacts and begin chatting.
  3142. ** Social Networking
  3143. #+BEGIN_VERSE
  3144. /Facebook is not your friend, it is a surveillance engine./
  3145. -- Richard Stallman, Free Software Foundation
  3146. #+END_VERSE
  3147. *** Friendica
  3148. **** Installation
  3149. See [[Setting up a web site]] for details of how to update the Apache configuration for your Friendica site. You should have a separate domain name specifically to run Friendica on. It can't be installed in a subdirectory on a domain used for something else.
  3150. Edit your Apache configuration and disable the port 80 (HTTP) version of the site. We only want to log into Friendica via HTTPS, so to prevent anyone from accidentally logging in insecurely:
  3151. #+BEGIN_SRC: bash
  3152. editor /etc/apache2/sites-available/myfriendicadomainname.com
  3153. #+END_SRC
  3154. Replace the section which begins with *<VirtualHost *:80>* with the following, replacing /myusername@mydomainname.com/ with your email address and /myfriendicadomainname.com/ with your Friendica domain name:
  3155. #+BEGIN_SRC: bash
  3156. <VirtualHost *:80>
  3157. ServerAdmin myusername@mydomainname.com
  3158. ServerName myfriendicadomainname.com
  3159. RewriteEngine On
  3160. RewriteCond %{HTTPS} off
  3161. RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
  3162. </VirtualHost>
  3163. #+END_SRC
  3164. Save and exit, then restart the apache server.
  3165. #+BEGIN_SRC: bash
  3166. service apache2 restart
  3167. #+END_SRC
  3168. Now install some dependencies.
  3169. #+BEGIN_SRC: bash
  3170. apt-get install mysql-server php5-common php5-cli php5-curl php5-gd php5-mysql php5-mcrypt php5-fpm php5-cgi php-apc
  3171. #+END_SRC
  3172. Enter an admin password for MySQL.
  3173. Reduce the memory use of mysql by using the "small" configuration.
  3174. #+BEGIN_SRC: bash
  3175. cp /usr/share/doc/mysql-server-5.5/examples/my-small.cnf /etc/mysql/my.cnf
  3176. #+END_SRC
  3177. Create a mysql database, replacing /myfriendicapassword/ with a password used to administer the friendica database.
  3178. #+BEGIN_SRC: bash
  3179. mysql -u root -p
  3180. create database friendica;
  3181. CREATE USER 'friendicaadmin'@'localhost' IDENTIFIED BY 'myfriendicapassword';
  3182. GRANT ALL PRIVILEGES ON friendica.* TO 'friendicaadmin'@'localhost';
  3183. quit
  3184. #+END_SRC
  3185. You may need to fix Git SSL problems.
  3186. #+BEGIN_SRC: bash
  3187. git config --global http.sslVerify true
  3188. apt-get install ca-certificates
  3189. cd ~/
  3190. editor .gitconfig
  3191. #+END_SRC
  3192. The .gitconfig file should look something like this:
  3193. #+BEGIN_SRC: bash
  3194. [user]
  3195. name = yourname
  3196. email = myusername@mydomainname.com
  3197. [http]
  3198. sslVerify = true
  3199. sslCAinfo = /etc/ssl/certs/ca-certificates.crt
  3200. #+END_SRC
  3201. Get the source code.
  3202. #+BEGIN_SRC: bash
  3203. export HOSTNAME=myfriendicadomainname.com
  3204. cd /var/www/$HOSTNAME
  3205. rm -rf htdocs
  3206. git clone https://github.com/friendica/friendica.git htdocs
  3207. chmod -R 755 htdocs
  3208. chown -R www-data:www-data htdocs
  3209. chown -R www-data:www-data htdocs/view/smarty3
  3210. git clone https://github.com/friendica/friendica-addons.git htdocs/addon
  3211. #+END_SRC
  3212. Now visit the URL of your site and you should be taken through the rest of the installation procedure.
  3213. | Database Server Name | localhost |
  3214. | Database login name | friendicaadmin |
  3215. | Database Login Password | myfriendicapassword |
  3216. | Database Name | friendica |
  3217. When installation is complete if you already have an exported account which you wish to import then visit https://myfriendicadomain.com/uimport, rather than registering a new user. If you get an error when trying to import an account then try increasing the value of LimitRequestBody within your apache configuration and restart the apache2 service.
  3218. If you have trouble with "allow override" ensure that "AllowOverride" is set to "all" in your Apache settings for the site (within /etc/apache2/sites-available) and then restart the apache2 service.
  3219. Install the poller.
  3220. #+BEGIN_SRC: bash
  3221. editor /etc/crontab
  3222. #+END_SRC
  3223. and append the following, changing /myfriendicadomainname.com/ to whatever your Friendica domain is.
  3224. #+BEGIN_SRC: bash
  3225. */10 * * * * root cd /var/www/myfriendicadomainname.com/htdocs; /usr/bin/timeout 120 /usr/bin/php include/poller.php
  3226. #+END_SRC
  3227. Save and exit, then restart cron.
  3228. #+BEGIN_SRC: bash
  3229. service cron restart
  3230. #+END_SRC
  3231. You can improve the speed of Friendica database searches by adding the following indexes:
  3232. #+BEGIN_SRC: bash
  3233. mysql -u root -p
  3234. use friendica;
  3235. CREATE INDEX `uri_received` ON item(`uri`, `received`);
  3236. CREATE INDEX `received_uri` ON item(`received`, `uri`);
  3237. CREATE INDEX `contact-id_created` ON item(`contact-id`, created);
  3238. CREATE INDEX `uid_network_received` ON item(`uid`, `network`, `received`);
  3239. CREATE INDEX `uid_parent` ON item(`uid`, `parent`);
  3240. CREATE INDEX `uid_received` ON item(`uid`, `received`);
  3241. CREATE INDEX `uid_network_commented` ON item(`uid`, `network`, `commented`);
  3242. CREATE INDEX `uid_title` ON item(uid, `title`);
  3243. CREATE INDEX `created_contact-id` ON item(`created`, `contact-id`);
  3244. quit
  3245. #+END_SRC
  3246. Make sure that Friendica doesn't use too much memory.
  3247. #+BEGIN_SRC: bash
  3248. editor /var/www/$HOSTNAME/htdocs/.htaccess
  3249. #+END_SRC
  3250. Append the following:
  3251. #+BEGIN_SRC: bash
  3252. php_value memory_limit 32M
  3253. #+END_SRC
  3254. The save ane exit.
  3255. **** Backups
  3256. Make sure that the database gets backed up. By using cron if anything goes wrong then you should be able to recover the database either from the previous day or the previous week.
  3257. #+BEGIN_SRC: bash
  3258. editor /etc/cron.daily/backup
  3259. #+END_SRC
  3260. Enter the following, replacing /myusername@mydomainname.com/ with your email address and the mysql root password as appropriate.
  3261. #+BEGIN_SRC: bash
  3262. #!/bin/sh
  3263. EMAIL=myusername@mydomainname.com
  3264. MYSQL_PASSWORD=<mysql root password>
  3265. umask 0077
  3266. # stop the web server to avoid any changes to the databases during backup
  3267. service nginx stop
  3268. # Save to a temporary file first so that it can be checked for non-zero size
  3269. TEMPFILE=/tmp/friendicared.sql
  3270. # Backup the Friendica database
  3271. DAILYFILE=/var/backups/friendica_daily.sql
  3272. mysqldump --password=$MYSQL_PASSWORD friendica > $TEMPFILE
  3273. FILESIZE=$(stat -c%s $TEMPFILE)
  3274. if [ "$FILESIZE" -eq "0" ]; then
  3275. if [ -f $DAILYFILE ]; then
  3276. cp $DAILYFILE $TEMPFILE
  3277. # try to restore yesterday's database
  3278. mysql -u root --password=$MYSQL_PASSWORD friendica -o < $DAILYFILE
  3279. # Send a warning email
  3280. echo "Unable to create a backup of the Friendica database. Attempted to restore from yesterday's backup." | mail -s "Friendica backup" $EMAIL
  3281. else
  3282. # Send a warning email
  3283. echo "Unable to create a backup of the Friendica database." | mail -s "Friendica backup" $EMAIL
  3284. fi
  3285. else
  3286. chmod 600 $TEMPFILE
  3287. mv $TEMPFILE $DAILYFILE
  3288. # Make the backup readable only by root
  3289. chmod 600 $DAILYFILE
  3290. fi
  3291. # Backup the Roundcube database
  3292. DAILYFILE=/var/backups/roundcubemail_daily.sql
  3293. mysqldump --password=$MYSQL_PASSWORD roundcubemail > $TEMPFILE
  3294. FILESIZE=$(stat -c%s $TEMPFILE)
  3295. if [ "$FILESIZE" -eq "0" ]; then
  3296. if [ -f $DAILYFILE ]; then
  3297. cp $DAILYFILE $TEMPFILE
  3298. # try to restore yesterday's database
  3299. mysql -u root --password=$MYSQL_PASSWORD roundcubemail -o < $DAILYFILE
  3300. # Send a warning email
  3301. echo "Unable to create a backup of the Roundcube database. Attempted to restore from yesterday's backup" | mail -s "Roundcube backup" $EMAIL
  3302. else
  3303. # Send a warning email
  3304. echo "Unable to create a backup of the Roundcube database." | mail -s "Roundcube backup" $EMAIL
  3305. fi
  3306. else
  3307. chmod 600 $TEMPFILE
  3308. mv $TEMPFILE $DAILYFILE
  3309. # Make the backup readable only by root
  3310. chmod 600 $DAILYFILE
  3311. fi
  3312. # Backup the Red Matrix database
  3313. DAILYFILE=/var/backups/redmatrix_daily.sql
  3314. #mysqldump --password=$MYSQL_PASSWORD redmatrix > $TEMPFILE
  3315. #FILESIZE=$(stat -c%s $TEMPFILE)
  3316. #if [ "$FILESIZE" -eq "0" ]; then
  3317. # if [ -f $DAILYFILE ]; then
  3318. # cp $DAILYFILE $TEMPFILE
  3319. # # try to restore yesterday's database
  3320. # mysql -u root --password=$MYSQL_PASSWORD redmatrix -o < $DAILYFILE
  3321. # # Send a warning email
  3322. # echo "Unable to create a backup of the Red Matrix database. Attempted to restore from yesterday's backup" | mail -s "Red Matrix backup" $EMAIL
  3323. # else
  3324. # # Send a warning email
  3325. # echo "Unable to create a backup of the Red Matrix database." | mail -s "Red Matrix backup" $EMAIL
  3326. # fi
  3327. #else
  3328. # chmod 600 $TEMPFILE
  3329. # mv $TEMPFILE $DAILYFILE
  3330. # # Make the backup readable only by root
  3331. # chmod 600 $DAILYFILE
  3332. #fi
  3333. # restart the web server
  3334. service nginx start
  3335. exit 0
  3336. #+END_SRC
  3337. Save and exit.
  3338. #+BEGIN_SRC: bash
  3339. chmod 600 /etc/cron.daily/backup
  3340. chmod +x /etc/cron.daily/backup
  3341. editor /etc/cron.weekly/backup
  3342. #+END_SRC
  3343. Enter the following
  3344. #+BEGIN_SRC: bash
  3345. #!/bin/sh
  3346. umask 0077
  3347. # Friendica
  3348. cp -f /var/backups/friendica_weekly.sql /var/backups/friendica_2weekly.sql
  3349. cp -f /var/backups/friendica_daily.sql /var/backups/friendica_weekly.sql
  3350. # Roundcube
  3351. cp -f /var/backups/roundcubemail_weekly.sql /var/backups/roundcubemail_2weekly.sql
  3352. cp -f /var/backups/roundcubemail_daily.sql /var/backups/roundcubemail_weekly.sql
  3353. # Red Matrix
  3354. #cp -f /var/backups/redmatrix_weekly.sql /var/backups/redmatrix_2weekly.sql
  3355. #cp -f /var/backups/redmatrix_daily.sql /var/backups/redmatrix_weekly.sql
  3356. #+END_SRC
  3357. Save and exit.
  3358. #+BEGIN_SRC: bash
  3359. chmod 600 /etc/cron.weekly/backup
  3360. chmod +x /etc/cron.weekly/backup
  3361. editor /etc/cron.monthly/backup
  3362. #+END_SRC
  3363. Enter the following
  3364. #+BEGIN_SRC: bash
  3365. #!/bin/sh
  3366. # Friendica
  3367. cp -f /var/backups/friendica_monthly.sql /var/backups/friendica_2monthly.sql
  3368. cp -f /var/backups/friendica_weekly.sql /var/backups/friendica_monthly.sql
  3369. # Roundcube
  3370. cp -f /var/backups/roundcubemail_monthly.sql /var/backups/roundcubemail_2monthly.sql
  3371. cp -f /var/backups/roundcubemail_weekly.sql /var/backups/roundcubemail_monthly.sql
  3372. # Red Matrix
  3373. #cp -f /var/backups/redmatrix_monthly.sql /var/backups/redmatrix_2monthly.sql
  3374. #cp -f /var/backups/redmatrix_weekly.sql /var/backups/redmatrix_monthly.sql
  3375. #+END_SRC
  3376. Save and exit.
  3377. #+BEGIN_SRC: bash
  3378. chmod 600 /etc/cron.monthly/backup
  3379. chmod +x /etc/cron.monthly/backup
  3380. #+END_SRC
  3381. **** Recommended configuration
  3382. ***** Admin
  3383. To get to the admin settings you will need to be logged in with the admin email address which you specified at the beginning of the installation procedure. Depending upon the theme which you're using "/admin/" will be available either as an icon or on a drop down menu.
  3384. Under the *plugins* section the main one which you may wish to enable is the NSFW plugin. With that enabled if a post contans the #NSFW tag then it will appear minimised by default and you will need to click a button to open it.
  3385. Under the *themes* section select a few themes, including mobile themes which are suitable for phones or tablets.
  3386. Under the *site* section give your Friendica node a name other than "/my friend network/", you can change the icon and banner text and set the default mobile theme typically to /frost-mobile/. If you don't want your node to host a lot of accounts for people you don't know then you may want to set the register policy to "/requires approval/". For security it's probably a good idea only to host accounts for people who you actually know, rather than random strangers. Also be aware that the Beaglebone does not have a great deal of computational power or bandwidth and will not function well if there are hundreds of users using your node. If you're not federating with Diaspora or other sites then you may wish to select "/only allow Friendica contacts/". That improves the security of the system, since communication between Friendica nodes is always encrypted separately and in addition to the usual SSL encryption layer - which makes life interesting for the Surveillance State and at least keeps those cryptanalysts employed.
  3387. If you also wish to publish your public posts to a Diaspora node then within the *site* settings select *enable Diaspora support*.
  3388. It's probably a good idea to enable "/private posts by default for new users/" and also "/don't include post content in email notifications/". Since traditional email isn't a secure system and is easily vulnerable to attack by systems such as [[https://en.wikipedia.org/wiki/XKeyscore][Xkeyscore]].
  3389. ***** Settings
  3390. Each user has their own customisable settings, typically available either via an icon or by an entry on a drop down menu.
  3391. Under *additional features* enable "/richtext editor/", "/post preview/", "/group filter/", "/network filter/", "/edit sent posts/" and "/dislike posts/".
  3392. Under *display settings* select your desktop and mobile themes.
  3393. Once you have connected to enough friends it's also a good idea to use the "/export personal data/" option from here. This will save a file to your local system, which you can import into another friendica node if necessary.
  3394. **** To access from an Android device
  3395. ***** App
  3396. Open a browser on your device and go to https://f-droid.org/ then download and install the F-Droid apk. If you then open F-Droid you can search for and install the Friendica app.
  3397. If you are using a self-signed certificate then at the login screen scroll down to the bottom, select the SSL settings then scroll down and disable SSL certificate checks. You will then be able to log in using https, which at least gives you some protection via the encryption.
  3398. More information about the Friendica app can be found on http://friendica-for-android.wiki-lab.net/
  3399. ***** Mobile Theme
  3400. Another way to access Friendica from a mobile device is to just use the web browser. If you have selected a mobile theme within your settings then when viewing from an Android system the mobile theme will be displayed.
  3401. *** Movim
  3402. #+BEGIN_VERSE
  3403. /The way we communicate with others and with ourselves ultimately determines the quality of our lives/
  3404. -- Anthony Robbins
  3405. #+END_VERSE
  3406. Movim is another social networking system based around the XMPP protocol.
  3407. You will need to have previously [[Install a Jabber/XMPP server][installed the Jabber/XMPP server]].
  3408. Edit your Apache configuration and disable the port 80 (HTTP) version of the site. We only want to log into Movim via HTTPS, so to prevent anyone from accidentally logging in insecurely:
  3409. #+BEGIN_SRC: bash
  3410. editor /etc/apache2/sites-available/mydomainname.com
  3411. #+END_SRC
  3412. Within the section which begins with *<VirtualHost *:80>* add the following:
  3413. #+BEGIN_SRC: bash
  3414. <Directory /var/www/mydomainname.com/htdocs/movim>
  3415. deny from all
  3416. </Directory>
  3417. #+END_SRC
  3418. Within the section which begins with *<VirtualHost *:443>* add the following:
  3419. #+BEGIN_SRC: bash
  3420. <Directory /var/www/mydomainname.com/htdocs/movim>
  3421. Options Indexes FollowSymLinks MultiViews
  3422. AllowOverride All
  3423. Order allow,deny
  3424. allow from all
  3425. </Directory>
  3426. #+END_SRC
  3427. Save and exit, then restart the apache server.
  3428. #+BEGIN_SRC: bash
  3429. service apache2 restart
  3430. #+END_SRC
  3431. Download the source.
  3432. #+BEGIN_SRC: bash
  3433. mkdir ~/build
  3434. cd ~/build
  3435. wget http://freedombone.uk.to/movim.tar.gz
  3436. #+END_SRC
  3437. Verify it.
  3438. #+BEGIN_SRC: bash
  3439. sha256sum movim.tar.gz
  3440. 2740ddbedf6cefcc2934759374376643b6cdea4fb7f944ec25098a6868cb499e movim.tar.gz
  3441. #+END_SRC
  3442. Install it.
  3443. #+BEGIN_SRC: bash
  3444. tar -xzvf movim.tar.gz
  3445. export HOSTNAME=mydomainname.com
  3446. cp -r movim-* /var/www/$HOSTNAME/htdocs/movim
  3447. chmod 755 /var/www/$HOSTNAME/htdocs/movim
  3448. chown -R www-data:www-data /var/www/$HOSTNAME/htdocs/movim
  3449. #+END_SRC
  3450. Install some MySql prerequisites.
  3451. #+BEGIN_SRC: bash
  3452. apt-get install mysql-server php5-common php5-cli php5-curl php5-gd php5-mysql php5-mcrypt
  3453. #+END_SRC
  3454. If necessary, enter an admin password for MySQL.
  3455. Reduce the memory use of mysql by using the "small" configuration.
  3456. #+BEGIN_SRC: bash
  3457. cp /usr/share/doc/mysql-server-5.5/examples/my-small.cnf /etc/mysql/my.cnf
  3458. #+END_SRC
  3459. Create a mysql database.
  3460. #+BEGIN_SRC: bash
  3461. mysql -u root -p
  3462. create database movim;
  3463. CREATE USER 'movimadmin'@'localhost' IDENTIFIED BY 'movimadminpassword';
  3464. GRANT ALL PRIVILEGES ON movim.* TO 'movimadmin'@'localhost';
  3465. quit
  3466. #+END_SRC
  3467. With a web browser navigate to:
  3468. https://mydomainname.com/movim/admin
  3469. Enter /admin/ as the username and /password/ as the password.
  3470. Click on /General Settings/ and alter the administrator username to /movimadmin/ and password to some long random string (using a password manager such as KeepassX).
  3471. Change the /Environment/ from /Development/ to /Production/.
  3472. The /BOSH URL/ should be http://localhost:5280/http-bind (TODO: should this be https://localhost:5281/http-bind and if so do certificate warnings need to be disabled?)
  3473. Click /Submit/ followed by /Resend/.
  3474. Click on /Database Settings/ and alter the MySql movim database username to /movimadmin/ and password to the password you specified in the previous step.
  3475. Click /Submit/ followed by /Resend/. If you get a lot of orange warnings about database fields being created then hit /Submit/ again until you see "Movim database is up to date".
  3476. If everything on all three tabs looks green then you are ready to go. Click on the Movim logo at the top left and then log in with your Jabber ID (JID).
  3477. *** Red Matrix
  3478. **** Introduction
  3479. Red Matrix is the current version of the Friendica social networking system. It's more general than Friendica in that it's designed as a generic communication system based around a protocol called "zot". At the time of writing in early 2014 Red Matrix remains at an alpha stage of development and so it's not advised that you install it unless you're willing to put up with bugs and frustrations. In the large majority of cases it's better to stick with Friendica for now.
  3480. **** Prerequisites
  3481. The main problem with Red Matrix is that in order to install it you will need to have purchased a domain name (i.e. not a FreeDNS subdomain) and a SSL certificate for it.
  3482. You could join some other Red Matrix server, but this suffers from "/The Levison Problem/" in which some goons show up with a gagging order demanding coppies of the SSL private key. In that scenario unless the owner of the server is exceptionally brave users may never be informed that the site has been compromised or that there is interception hardware attached to the server. Joining another server defeats the object of being digitally self-sufficient and raises legal question marks about the ownership of data which you might upload to a server which doesn't belong to you.
  3483. **** Installation
  3484. See [[Setting up a web site]] for details of how to update the Apache configuration for your Red Matrix site. You should have a separate domain name specifically to run Red Matrix on. It can't be installed in a subdirectory on a domain used for something else.
  3485. Edit your Apache configuration and disable the port 80 (HTTP) version of the site. We only want to log into Red Matrix via HTTPS, so to prevent anyone from accidentally logging in insecurely:
  3486. #+BEGIN_SRC: bash
  3487. editor /etc/apache2/sites-available/mydomainname.com
  3488. #+END_SRC
  3489. Replace the section which begins with *<VirtualHost *:80>* with the following:
  3490. #+BEGIN_SRC: bash
  3491. <VirtualHost *:80>
  3492. ServerAdmin myusername@mydomainname.com
  3493. ServerName myredmatrixdomainname.com
  3494. RewriteEngine On
  3495. RewriteCond %{HTTPS} off
  3496. RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
  3497. </VirtualHost>
  3498. #+END_SRC
  3499. Save and exit, then restart the apache server.
  3500. #+BEGIN_SRC: bash
  3501. service apache2 restart
  3502. #+END_SRC
  3503. Now install some dependencies.
  3504. #+BEGIN_SRC: bash
  3505. apt-get install mysql-server php5-common php5-cli php5-curl php5-gd php5-mysql php5-mcrypt
  3506. #+END_SRC
  3507. Enter an admin password for MySQL.
  3508. Reduce the memory use of mysql by using the "small" configuration.
  3509. #+BEGIN_SRC: bash
  3510. cp /usr/share/doc/mysql-server-5.5/examples/my-small.cnf /etc/mysql/my.cnf
  3511. #+END_SRC
  3512. Create a mysql database.
  3513. #+BEGIN_SRC: bash
  3514. mysql -u root -p
  3515. create database redmatrix;
  3516. CREATE USER 'redmatrixadmin'@'localhost' IDENTIFIED BY 'password';
  3517. GRANT ALL PRIVILEGES ON redmatrix.* TO 'redmatrixadmin'@'localhost';
  3518. quit
  3519. #+END_SRC
  3520. You may need to fix Git SSL problems.
  3521. #+BEGIN_SRC: bash
  3522. git config --global http.sslVerify true
  3523. apt-get install ca-certificates
  3524. cd ~/
  3525. editor .gitconfig
  3526. #+END_SRC
  3527. The .gitconfig file should look something like this:
  3528. #+BEGIN_SRC: bash
  3529. [http]
  3530. sslVerify = true
  3531. sslCAinfo = /etc/ssl/certs/ca-certificates.crt
  3532. [user]
  3533. email = myusername@mydomainname.com
  3534. name = yourname
  3535. #+END_SRC
  3536. Get the source code.
  3537. #+BEGIN_SRC: bash
  3538. export HOSTNAME=mydomainname.com
  3539. mkdir /var/www/$HOSTNAME
  3540. cd /var/www/$HOSTNAME
  3541. rm -rf htdocs
  3542. git clone https://github.com/friendica/red.git htdocs
  3543. chmod -R 755 htdocs
  3544. chown -R www-data:www-data htdocs
  3545. mkdir htdocs/view/tpl/smarty3
  3546. mkdir htdocs/store/[data]
  3547. mkdir htdocs/store/[data]/smarty3
  3548. chmod 777 htdocs/view/tpl
  3549. chmod 777 htdocs/view/tpl/smarty3
  3550. chmod 777 htdocs/store/[data]/smarty3
  3551. git clone https://github.com/friendica/red-addons.git htdocs/addon
  3552. #+END_SRC
  3553. Now visit the URL of your site and you should be taken through the rest of the installation procedure. Note that this may take a few minutes so don't be concerned if it looks as if it has crashed - just leave it running. If you have trouble with "allow override" ensure that "AllowOverride" is set to "all" in your Apache settings for the site (within /etc/apache2/sites-available) and then restart the apache2 service.
  3554. Install the poller.
  3555. #+BEGIN_SRC
  3556. editor /etc/crontab
  3557. #+END_SRC
  3558. and append the following, changing /mydomainname.com/ to whatever your domain is.
  3559. #+BEGIN_SRC
  3560. 12,22,32,42,52 * * * * root cd /var/www/mydomainname.com/htdocs; /usr/bin/timeout 240 /usr/bin/php include/poller.php
  3561. #+END_SRC
  3562. Save and exit, then restart cron.
  3563. #+BEGIN_SRC: bash
  3564. service cron restart
  3565. #+END_SRC
  3566. **** Backups
  3567. Make sure that the database gets backed up. By using cron if anything goes wrong then you should be able to recover the database either from the previous day or the previous week.
  3568. #+BEGIN_SRC: bash
  3569. editor /etc/cron.daily/backup
  3570. #+END_SRC
  3571. Uncomment the lines for Red Matrix, then save and exit. If you didn't install Friendica earlier then see the backup section within the Friendica install instructions.
  3572. #+BEGIN_SRC: bash
  3573. chmod 600 /etc/cron.daily/backup
  3574. chmod +x /etc/cron.daily/backup
  3575. editor /etc/cron.weekly/backup
  3576. #+END_SRC
  3577. If you already have a backup script created for Friendica then just uncomment the lines for Red Matrix. The backup script should look something like the following:
  3578. #+BEGIN_SRC: bash
  3579. #!/bin/sh
  3580. umask 0077
  3581. # Friendica
  3582. cp -f /var/backups/friendica_weekly.sql /var/backups/friendica_2weekly.sql
  3583. cp -f /var/backups/friendica_daily.sql /var/backups/friendica_weekly.sql
  3584. # Red Matrix
  3585. cp -f /var/backups/redmatrix_weekly.sql /var/backups/redmatrix_2weekly.sql
  3586. cp -f /var/backups/redmatrix_daily.sql /var/backups/redmatrix_weekly.sql
  3587. #+END_SRC
  3588. Save and exit.
  3589. #+BEGIN_SRC: bash
  3590. chmod 600 /etc/cron.weekly/backup
  3591. chmod +x /etc/cron.weekly/backup
  3592. editor /etc/cron.monthly/backup
  3593. #+END_SRC
  3594. If you already have a backup script created for Friendica then just uncomment the lines for Red Matrix. The backup script should look something like the following:
  3595. #+BEGIN_SRC: bash
  3596. #!/bin/sh
  3597. # Friendica
  3598. cp -f /var/backups/friendica_monthly.sql /var/backups/friendica_2monthly.sql
  3599. cp -f /var/backups/friendica_weekly.sql /var/backups/friendica_monthly.sql
  3600. # Red Matrix
  3601. cp -f /var/backups/redmatrix_monthly.sql /var/backups/redmatrix_2monthly.sql
  3602. cp -f /var/backups/redmatrix_weekly.sql /var/backups/redmatrix_monthly.sql
  3603. #+END_SRC
  3604. Save and exit.
  3605. #+BEGIN_SRC: bash
  3606. chmod 600 /etc/cron.monthly/backup
  3607. chmod +x /etc/cron.monthly/backup
  3608. #+END_SRC
  3609. **** To access from an Android device
  3610. ***** App
  3611. Open a browser on your device and go to https://f-droid.org/ then download and install the F-Droid apk. If you then open F-Droid you can search for and install the Friendica app.
  3612. If you are using a self-signed certificate then at the login screen scroll down to the bottom, select the SSL settings then scroll down and disable SSL certificate checks. You will then be able to log in using https, which at least gives you some protection via the encryption.
  3613. More information about the Friendica app can be found on http://friendica-for-android.wiki-lab.net/
  3614. *** pump.io
  3615. :PROPERTIES:
  3616. :ORDERED: t
  3617. :END:
  3618. pump.io is the successor to StatusNet (which later became [[GNU Social]]) and is a communications system which can do things other than just microblogging. It takes fewer system resources to run and so is better suited to low power servers such as the BBB, but is more complicated to install. pump.io doesn't work well with self-signed SSL certificates so this may be something which you can only use if you have your own domain and an "authority" issued certificate. Using a self-signed certificate you can only use pump.io as a /data silo/ which won't federate with other servers.
  3619. For a pump.io site you will need a separate domain/subdomain, so see [[Setting up a web site]] for details of how to create an Apache configuration for your site. If you're using freedns then you will need to create a new subdomain.
  3620. #+BEGIN_SRC: bash
  3621. apt-get update
  3622. apt-get install build-essential openssl libssl-dev redis-server imagemagick graphicsmagick git-core screen
  3623. #+END_SRC
  3624. Download nodejs
  3625. #+BEGIN_SRC: bash
  3626. mkdir ~/build
  3627. cd ~/build
  3628. wget http://freedombone.uk.to/node_0.10.28-1_armhf.deb
  3629. #+END_SRC
  3630. Verify it.
  3631. #+BEGIN_SRC: bash
  3632. sha256sum node_0.10.28-1_armhf.deb
  3633. 42000a475d3397f295fe76998e79af999eebb8324ac9bb4981e931fabd9297aa
  3634. #+END_SRC
  3635. Install it.
  3636. #+BEGIN_SRC: bash
  3637. dpkg -i node_0.10.28-1_armhf.deb
  3638. #+END_SRC
  3639. Install pump.io
  3640. #+BEGIN_SRC: bash
  3641. cd /opt
  3642. git clone https://github.com/e14n/pump.io.git
  3643. cd /opt/pump.io
  3644. npm install
  3645. npm install databank-redis
  3646. echo "vm.overcommit_memory=1" >> /etc/sysctl.conf
  3647. sysctl vm.overcommit_memory=1
  3648. #+END_SRC
  3649. Now edit the configuration file.
  3650. #+BEGIN_SRC: bash
  3651. editor /etc/pump.io.json
  3652. #+END_SRC
  3653. Add the following, replacing /mypumpiodomainname.com/ with your domain name.
  3654. #+BEGIN_SRC: bash
  3655. {
  3656. "driver": "redis",
  3657. "params": {"host":"localhost","port":6379},
  3658. "secret": "A long random string",
  3659. "noweb": false,
  3660. "site": "Name of my pump.io site",
  3661. "owner": "My name or organisation",
  3662. "ownerURL": "https://mypumpiodomainname.com/",
  3663. "port": 7270,
  3664. "urlPort": 443,
  3665. "hostname": "mypumpiodomainname.com",
  3666. "address": "localhost",
  3667. "nologger": true,
  3668. "serverUser": "pumpio",
  3669. "rejectUnauthorized": false,
  3670. "key": "/var/local/pump.io/keys/mypumpiodomainname.com.key",
  3671. "cert": "/var/local/pump.io/keys/mypumpiodomainname.com.bundle.crt",
  3672. "uploaddir": "/var/local/pump.io/uploads",
  3673. "debugClient": false,
  3674. "firehose": "ofirehose.example",
  3675. "logfile": "/var/local/pump.io/pump.log",
  3676. "disableRegistration": false
  3677. }
  3678. #+END_SRC
  3679. Save and exit.
  3680. #+BEGIN_SRC: bash
  3681. export HOSTNAME=mypumpiodomainname.com
  3682. mkdir /var/local/pump.io
  3683. mkdir /var/local/pump.io/uploads
  3684. mkdir /var/local/pump.io/keys
  3685. cp /etc/ssl/private/$HOSTNAME.key /var/local/pump.io/keys
  3686. cp /etc/ssl/certs/$HOSTNAME.crt /var/local/pump.io/keys
  3687. cp /etc/ssl/certs/$HOSTNAME.bundle.crt /var/local/pump.io/keys
  3688. useradd -s /bin/bash -d /var/local/pump.io pumpio
  3689. chown -R pumpio:pumpio /var/local/pump.io
  3690. chmod 400 /var/local/pump.io/keys/*
  3691. chmod -R 777 /opt
  3692. #+END_SRC
  3693. Edit your web server configuration.
  3694. #+BEGIN_SRC: bash
  3695. editor /etc/nginx/sites-available/$HOSTNAME
  3696. #+END_SRC
  3697. Delete all existing contents then add the following:
  3698. #+BEGIN_SRC: bash
  3699. upstream pumpbackend {
  3700. server 127.0.0.1:7270 max_fails=3 fail_timeout=30s;
  3701. server 127.0.0.1:7270 max_fails=3 fail_timeout=60s;
  3702. server 127.0.0.1:7270 max_fails=3 fail_timeout=90s;
  3703. }
  3704. server {
  3705. listen 80;
  3706. server_name mypumpiodomainname.com;
  3707. rewrite ^ https://$server_name$request_uri? permanent;
  3708. }
  3709. map $http_upgrade $connection_upgrade {
  3710. default upgrade;
  3711. '' close;
  3712. }
  3713. server {
  3714. listen 443 ssl;
  3715. server_name mypumpiodomainname.com;
  3716. error_log /var/www/mypumpiodomainname.com/error.log debug;
  3717. ssl on;
  3718. ssl_certificate /etc/ssl/certs/mypumpiodomainname.com.bundle.crt;
  3719. ssl_certificate_key /etc/ssl/private/mypumpiodomainname.com.key;
  3720. ssl_session_timeout 5m;
  3721. ssl_prefer_server_ciphers on;
  3722. ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # not possible to do exclusive
  3723. ssl_ciphers 'EDH+CAMELLIA:EDH+aRSA:EECDH+aRSA+AESGCM:EECDH+aRSA+SHA384:EECDH+aRSA+SHA256:EECDH:+CAMELLIA256:+AES256:+CAMELLIA128:+AES128:+SSLv3:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EXP:!PSK:!DSS:!RC4:!SEED:!ECDSA:CAMELLIA256-SHA:AES256-SHA:CAMELLIA128-SHA:AES128-SHA';
  3724. #add_header Strict-Transport-Security max-age=15768000; # six months
  3725. # use this only if all subdomains support HTTPS!
  3726. add_header Strict-Transport-Security "max-age=15768000; includeSubDomains";
  3727. client_max_body_size 6m;
  3728. keepalive_timeout 75 75;
  3729. gzip_vary off;
  3730. location / {
  3731. proxy_pass https://pumpbackend;
  3732. proxy_http_version 1.1;
  3733. proxy_redirect off;
  3734. proxy_set_header Upgrade $http_upgrade;
  3735. proxy_set_header Connection $connection_upgrade;
  3736. proxy_set_header Host $http_host;
  3737. proxy_set_header X-Real-IP $remote_addr;
  3738. proxy_buffers 16 32k;
  3739. }
  3740. }
  3741. #+END_SRC
  3742. Save and exit.
  3743. #+BEGIN_SRC: bash
  3744. sed "s/mypumpiodomainname.com/$HOSTNAME/g" /etc/nginx/sites-available/$HOSTNAME > /tmp/website
  3745. cp -f /tmp/website /etc/nginx/sites-available/$HOSTNAME
  3746. service nginx restart
  3747. npm install forever -g
  3748. #+END_SRC
  3749. Now create the daemon.
  3750. #+BEGIN_SRC: bash
  3751. editor /etc/init.d/pumpio
  3752. #+END_SRC
  3753. Add the following text:
  3754. #+BEGIN_SRC: bash
  3755. #!/bin/bash
  3756. # /etc/init.d/pumpio
  3757. ### BEGIN INIT INFO
  3758. # Provides: pump.io
  3759. # Required-Start: $remote_fs $syslog
  3760. # Required-Stop: $remote_fs $syslog
  3761. # Default-Start: 2 3 4 5
  3762. # Default-Stop: 0 1 6
  3763. # Short-Description: starts pump.io as a background daemon
  3764. # Description: Starts pump.io on boot
  3765. ### END INIT INFO
  3766. # Author: Bob Mottram <bob@robotics.uk.to>
  3767. #Settings
  3768. SERVICE='pumpio'
  3769. COMMAND="forever /opt/pump.io/bin/pump > /var/local/pump.io/daemon.log"
  3770. USERNAME='pumpio'
  3771. NICELEVEL=19 # from 0-19 the bigger the number, the less the impact on system OAresources
  3772. HISTORY=1024
  3773. INVOCATION="nice -n ${NICELEVEL} ${COMMAND}"
  3774. PATH='/usr/local/sbin:/usr/local/bin:/usr/bin:/sbin:/usr/sbin:/bin:/var/local/pump.io'
  3775. pumpio_start() {
  3776. echo "Starting $SERVICE..."
  3777. su --command "screen -h ${HISTORY} -dmS ${SERVICE} ${INVOCATION}" $USERNAME
  3778. }
  3779. pumpio_stop() {
  3780. echo "Stopping $SERVICE"
  3781. su --command "screen -p 0 -S ${SERVICE} -X stuff "'^C'"" $USERNAME
  3782. }
  3783. #Start-Stop here
  3784. case "$1" in
  3785. start)
  3786. pumpio_start
  3787. ;;
  3788. stop)
  3789. pumpio_stop
  3790. ;;
  3791. restart)
  3792. pumpio_stop
  3793. sleep 10s
  3794. pumpio_start
  3795. ;;
  3796. *)
  3797. echo "Usage: $0 {start|stop|restart}"
  3798. exit 1
  3799. ;;
  3800. esac
  3801. exit 0
  3802. #+END_SRC
  3803. Save and exit. Then enable the daemon and run it.
  3804. #+BEGIN_SRC: bash
  3805. chmod +x /etc/init.d/pumpio
  3806. update-rc.d pumpio defaults
  3807. service pumpio start
  3808. #+END_SRC
  3809. Now visit your pump.io site by navigating to:
  3810. https://mypumpiodomainname.com
  3811. and add a new user. If you wish this to be a single user node not open to the general public (including spammers and sockpuppets) then edit */etc/pump.io.json* and set *disableRegistration* to *true*. After making that change restart with the command *service pumpio restart*.
  3812. Once you've set up your user account it's recommended that you don't use the web based user interface and instead use a native client such as [[http://jancoding.wordpress.com/dianara/][Dianara]] or Pumpa. On Ubuntu you can install these via the Software Center. On mobile devices you can install AndStatus via F-Droid.
  3813. A list of pump.io sites can be found at http://pumpstatus.jpope.org. At the time of writing there isn't any public directory and so finding people to follow is really a question of navigating through lists of /following/ or /followers/ (rather like the web before search engines were invented).
  3814. Ensure that data data gets backed up with:
  3815. #+BEGIN_SRC: bash
  3816. printf "\n\n# Redis backup" >> /etc/cron.daily/backup
  3817. printf "\ntar -czvf /var/backups/redis_daily.tar.gz /var/lib/redis/dump.rdb" >> /etc/cron.daily/backup
  3818. printf "\n\n# Redis backup" >> /etc/cron.weekly/backup
  3819. printf "\ncp -f /var/backups/redis_weekly.tar.gz /var/backups/redis_weekly2.tar.gz" >> /etc/cron.weekly/backup
  3820. printf "\ncp -f /var/backups/redis_daily.tar.gz /var/backups/redis_weekly.tar.gz" >> /etc/cron.weekly/backup
  3821. printf "\n\n# Redis backup" >> /etc/cron.monthly/backup
  3822. printf "\ncp -f /var/backups/redis_monthly.tar.gz /var/backups/redis_monthly2.tar.gz" >> /etc/cron.monthly/backup
  3823. printf "\ncp -f /var/backups/redis_weekly.tar.gz /var/backups/redis_monthly.tar.gz" >> /etc/cron.monthly/backup
  3824. printf "\n\n# Pump.io backup" >> /etc/cron.daily/backup
  3825. printf "\ntar -czvf /var/backups/pumpio_daily.tar.gz /var/local/pump.io --exclude /var/local/pump.io/.forever" >> /etc/cron.daily/backup
  3826. printf "\n\n# Pump.io backup" >> /etc/cron.weekly/backup
  3827. printf "\ncp -f /var/backups/pumpio_weekly.tar.gz /var/backups/pumpio_weekly2.tar.gz" >> /etc/cron.weekly/backup
  3828. printf "\ncp -f /var/backups/pumpio_daily.tar.gz /var/backups/pumpio_weekly.tar.gz" >> /etc/cron.weekly/backup
  3829. printf "\n\n# Pump.io backup" >> /etc/cron.monthly/backup
  3830. printf "\ncp -f /var/backups/pumpio_monthly.tar.gz /var/backups/pumpio_monthly2.tar.gz" >> /etc/cron.monthly/backup
  3831. printf "\ncp -f /var/backups/pumpio_weekly.tar.gz /var/backups/pumpio_monthly.tar.gz" >> /etc/cron.monthly/backup
  3832. #+END_SRC
  3833. At the time of writing creating backups of the pump.io database is critically important, because regenerating the database or moving to a different databank type causes you to be /permanently banned/ from the pump.io network unless you change your domain name (which may not always be an available option).
  3834. ** Install Gopher
  3835. *** Server setup
  3836. Gopher is an old internet protocol which originated a few years before the web and is purely text based. It can be quite fun to build a gopher site and browse the gopherverse. One thing to keep in mind is that there is no security with gopher, so any text transmitted is trivially interceptable by systems such as [[https://en.wikipedia.org/wiki/XKeyscore][Xkeyscore]] or deep packet inspection.
  3837. To set up a gopher server:
  3838. #+BEGIN_SRC: bash
  3839. apt-get install build-essential
  3840. mkdir ~/build
  3841. cd ~/build
  3842. wget http://freedombone.uk.to/geomyidae-current.tgz
  3843. #+END_SRC
  3844. Verify the download:
  3845. #+BEGIN_SRC: bash
  3846. sha256sum geomyidae-current.tgz
  3847. 162f55ab059ab0a9be8e840497795293bbd51c34b1f4564dcdf3f0ddd5c0db31 geomyidae-current.tgz
  3848. #+END_SRC
  3849. Then extract and install it.
  3850. #+BEGIN_SRC: bash
  3851. tar -xzvf geomyidae-current.tgz
  3852. cd geomyidae-*
  3853. make
  3854. make install
  3855. mkdir -p /var/gopher
  3856. #+END_SRC
  3857. Your content should be placed within /var/gopher with the index page being named index.gph. The Gopher format is very simple - simpler than HTML - so creating pages is not much more difficult than editing a text file.
  3858. #+BEGIN_SRC: bash
  3859. editor /etc/init.d/gopher
  3860. #+END_SRC
  3861. Enter the following:
  3862. #+BEGIN_SRC: bash
  3863. #! /bin/sh
  3864. ### BEGIN INIT INFO
  3865. # Provides: gopher
  3866. # Required-Start: $remote_fs $syslog
  3867. # Required-Stop: $remote_fs $syslog
  3868. # Default-Start: 2 3 4 5
  3869. # Default-Stop: 0 1 6
  3870. # Short-Description: Gopher daemon
  3871. # Description: Gopher daemon
  3872. ### END INIT INFO
  3873. # Do NOT "set -e"
  3874. # PATH should only include /usr/* if it runs after the mountnfs.sh script
  3875. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  3876. DESC="Gopher daemon"
  3877. NAME=geomyidae
  3878. DAEMON=/usr/bin/$NAME
  3879. DAEMON_ARGS="-l /var/log/geomyidae.log -b /var/gopher -p 70"
  3880. PIDFILE=/var/run/$NAME.pid
  3881. SCRIPTNAME=/etc/init.d/$NAME
  3882. # Exit if the package is not installed
  3883. [ -x "$DAEMON" ] || exit 0
  3884. # Read configuration variable file if it is present
  3885. [ -r /etc/default/$NAME ] && . /etc/default/$NAME
  3886. # Load the VERBOSE setting and other rcS variables
  3887. . /lib/init/vars.sh
  3888. # Define LSB log_* functions.
  3889. # Depend on lsb-base (>= 3.2-14) to ensure that this file is present
  3890. # and status_of_proc is working.
  3891. . /lib/lsb/init-functions
  3892. #
  3893. # Function that starts the daemon/service
  3894. #
  3895. do_start()
  3896. {
  3897. # Return
  3898. # 0 if daemon has been started
  3899. # 1 if daemon was already running
  3900. # 2 if daemon could not be started
  3901. start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
  3902. || return 1
  3903. start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
  3904. $DAEMON_ARGS \
  3905. || return 2
  3906. # Add code here, if necessary, that waits for the process to be ready
  3907. # to handle requests from services started subsequently which depend
  3908. # on this one. As a last resort, sleep for some time.
  3909. }
  3910. #
  3911. # Function that stops the daemon/service
  3912. #
  3913. do_stop()
  3914. {
  3915. # Return
  3916. # 0 if daemon has been stopped
  3917. # 1 if daemon was already stopped
  3918. # 2 if daemon could not be stopped
  3919. # other if a failure occurred
  3920. start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
  3921. RETVAL="$?"
  3922. [ "$RETVAL" = 2 ] && return 2
  3923. # Wait for children to finish too if this is a daemon that forks
  3924. # and if the daemon is only ever run from this initscript.
  3925. # If the above conditions are not satisfied then add some other code
  3926. # that waits for the process to drop all resources that could be
  3927. # needed by services started subsequently. A last resort is to
  3928. # sleep for some time.
  3929. start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
  3930. [ "$?" = 2 ] && return 2
  3931. # Many daemons don't delete their pidfiles when they exit.
  3932. rm -f $PIDFILE
  3933. return "$RETVAL"
  3934. }
  3935. #
  3936. # Function that sends a SIGHUP to the daemon/service
  3937. #
  3938. do_reload() {
  3939. #
  3940. # If the daemon can reload its configuration without
  3941. # restarting (for example, when it is sent a SIGHUP),
  3942. # then implement that here.
  3943. #
  3944. start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
  3945. return 0
  3946. }
  3947. case "$1" in
  3948. start)
  3949. [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
  3950. do_start
  3951. case "$?" in
  3952. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  3953. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  3954. esac
  3955. ;;
  3956. stop)
  3957. [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
  3958. do_stop
  3959. case "$?" in
  3960. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  3961. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  3962. esac
  3963. ;;
  3964. status)
  3965. status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
  3966. ;;
  3967. #reload|force-reload)
  3968. #
  3969. # If do_reload() is not implemented then leave this commented out
  3970. # and leave 'force-reload' as an alias for 'restart'.
  3971. #
  3972. #log_daemon_msg "Reloading $DESC" "$NAME"
  3973. #do_reload
  3974. #log_end_msg $?
  3975. #;;
  3976. restart|force-reload)
  3977. #
  3978. # If the "reload" option is implemented then remove the
  3979. # 'force-reload' alias
  3980. #
  3981. log_daemon_msg "Restarting $DESC" "$NAME"
  3982. do_stop
  3983. case "$?" in
  3984. 0|1)
  3985. do_start
  3986. case "$?" in
  3987. 0) log_end_msg 0 ;;
  3988. 1) log_end_msg 1 ;; # Old process is still running
  3989. *) log_end_msg 1 ;; # Failed to start
  3990. esac
  3991. ;;
  3992. *)
  3993. # Failed to stop
  3994. log_end_msg 1
  3995. ;;
  3996. esac
  3997. ;;
  3998. *)
  3999. #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
  4000. echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
  4001. exit 3
  4002. ;;
  4003. esac
  4004. :
  4005. #+END_SRC
  4006. Save and exit. Then start the gopher service.
  4007. #+BEGIN_SRC: bash
  4008. chmod +x /etc/init.d/gopher
  4009. update-rc.d gopher defaults
  4010. service gopher start
  4011. #+END_SRC
  4012. On your internet router change the firewall settings to route port 70 to the BBB, then provided that you have a gopher plugin installed within your browser then you should be able to navigate to your gopher site with:
  4013. #+BEGIN_SRC: bash
  4014. gopher://mydomainname.com
  4015. #+END_SRC
  4016. There is a browser addon for Gopher called "overbite". Installing that should enable you to view your site.
  4017. *** A phlogging script
  4018. A phlog is the gopher equivalent of a blog on the web. You can create a script which makes phlogging easy.
  4019. #+BEGIN_SRC: bash
  4020. editor /usr/bin/mkphlog
  4021. #+END_SRC
  4022. Add the following:
  4023. #+BEGIN_SRC: bash
  4024. #!/bin/sh
  4025. # mkphlog - a utility to ease the creation of phlogs.
  4026. # Organizes phlog posts in separate directories.
  4027. # Created by octotep; anyone can distribute, modify, and
  4028. # share this file however they please.
  4029. #
  4030. # Version 0.3
  4031. #
  4032. # Modified by Bob Mottram
  4033. #
  4034. # Please note, all date strings are in the form of mm/dd/yy(yy)
  4035. # The base of the entire gopher site.
  4036. gopherRoot="/var/gopher"
  4037. # The name of the phlog directory (contained in $gopherHome)
  4038. phlogDirName="phlog"
  4039. # Default editor, unless the user has one specified in env
  4040. editor=${EDITOR:-emacs}
  4041. # Default timezone, unless the user has one specified in env
  4042. TZ=${TZ:-UTC}
  4043. # Tells the script how many lines the title of the main page spans.
  4044. # Used to insert the newest post at the top.
  4045. # Titles created by mkphlog are 3 lines.
  4046. # Isn't used if $addTitleToMain is false
  4047. titleLineCount=3
  4048. entryDate=`date +%Y-%m-%d`
  4049. # Creates the phlog directory if it dosen't already exist.
  4050. CreatePhlogDir() {
  4051. mkdir $phlogDirName
  4052. chmod 755 $phlogDirName
  4053. cd $phlogDirName
  4054. echo "Phlog directory created."
  4055. }
  4056. # Updates the main phlog listing
  4057. UpdatePhlogListing() {
  4058. # Just in case the user didn't specify a title
  4059. if [ "$postTitleAns" = "" ] ; then
  4060. echo -n "Do you want to create a blank post? (y/n) "
  4061. read blankPostAns
  4062. case $blankPostAns in
  4063. y* | Y* ) $postTitleAns="New Post" ;;
  4064. n* | N* ) echo "Goodbye, then." ; exit 1 ;;
  4065. * ) exit 1 ;;
  4066. esac
  4067. fi
  4068. cd $gopherRoot/$phlogDirName/
  4069. title2=$(echo "${postTitleAns}" | tr " " _)
  4070. postfilename="${entryDate}_${title2}.txt"
  4071. touch ${postfilename}
  4072. echo $postTitleAns >> ${postfilename}
  4073. date "+%A %b %e %l:%M:%S %Y" >> ${postfilename}
  4074. echo "------------------------------" >> ${postfilename}
  4075. echo >> ${postfilename}
  4076. }
  4077. if [ -d $gopherRoot ] ; then
  4078. cd $gopherRoot
  4079. else
  4080. echo "You don't have a gopherspace set-up. Please run the gopher server setup instructions."
  4081. exit 1
  4082. fi
  4083. if [ -d $phlogDirName ] ; then
  4084. cd $phlogDirName
  4085. else
  4086. echo -n "Do you want to create a phlog directory? (y/n) "
  4087. read phlogDirAns
  4088. case $phlogDirAns in
  4089. y* | Y* ) CreatePhlogDir ;;
  4090. n* | N* ) exit 1 ;;
  4091. * ) exit 1 ;;
  4092. esac
  4093. fi
  4094. echo -n "Would you like to create a phlog entry for today? (y/n) "
  4095. read phlogAns
  4096. case $phlogAns in
  4097. y* | Y* ) echo "Creating today's phlog entry..." ;;
  4098. n* | N* ) exit 0 ;;
  4099. * ) exit 1 ;;
  4100. esac
  4101. # Make sure there isn't a post for that day, lest we overwrite it.
  4102. if [ ! -d $entryDate ]; then
  4103. echo -n "Title: "
  4104. read postTitleAns
  4105. title2=$(echo "${postTitleAns}" | tr " " _)
  4106. postfilename="${entryDate}_${title2}.txt"
  4107. touch ${postfilename}
  4108. chmod 644 ${postfilename}
  4109. UpdatePhlogListing
  4110. echo -n "Would you like to edit the post with $editor? (y/n) "
  4111. read editorAns
  4112. case $editorAns in
  4113. y* | Y* ) $editor $gopherRoot/$phlogDirName/${postfilename} ;;
  4114. n* | N* ) exit 0 ;;
  4115. * ) exit 0 ;;
  4116. esac
  4117. rm $gopherRoot/$phlogDirName/${postfilename}~
  4118. else
  4119. echo "There is already a post for today."
  4120. echo -n "Would you like to edit the post with $editor? (y/n) "
  4121. read editorAns
  4122. case $editorAns in
  4123. y* | Y* ) $editor $gopherRoot/$phlogDirName/$entryDate*.txt ;;
  4124. n* | N* ) exit 0 ;;
  4125. * ) exit 1 ;;
  4126. esac
  4127. rm $gopherRoot/$phlogDirName/${postfilename}.txt~
  4128. fi
  4129. exit 0
  4130. #+END_SRC
  4131. Save and exit.
  4132. #+BEGIN_SRC: bash
  4133. chmod +x /usr/bin/mkphlog
  4134. #+END_SRC
  4135. Now entering the command /mkphlog/ will allow you to create a phlog entry.
  4136. ** Install Owncloud
  4137. #+BEGIN_VERSE
  4138. /It's not water vapour/
  4139. -- Larry Ellison
  4140. #+END_VERSE
  4141. Owncloud will allow you to upload and download files, share photos, collaboratively edit documents, have a calendar and more. You should be warned that Owncloud runs quite slowly via an ordinary web browser, but it can be a convenient way to access and share your data from any location in a reasonably secure manner.
  4142. *** Server Installation
  4143. Install some dependencies:
  4144. #+BEGIN_SRC: bash
  4145. apt-get install php5 php5-gd php-xml-parser php5-intl
  4146. apt-get install php5-sqlite php5-mysql smbclient curl libcurl3 php5-curl
  4147. #+END_SRC
  4148. You will need to create a new subdomain, so see [[Setting up a web site]] for details of how to do that.
  4149. #+BEGIN_SRC: bash
  4150. export HOSTNAME=myowncloudcomainname.com
  4151. editor /etc/nginx/sites-available/$HOSTNAME
  4152. #+END_SRC
  4153. Delete all existing contents, then add the following:
  4154. #+BEGIN_SRC: bash
  4155. server {
  4156. listen 80;
  4157. server_name myownclouddomainname.com;
  4158. rewrite ^ https://$server_name$request_uri? permanent;
  4159. }
  4160. server {
  4161. listen 443 ssl;
  4162. root /var/www/myownclouddomainname.com/htdocs;
  4163. server_name myownclouddomainname.com;
  4164. ssl on;
  4165. ssl_certificate /etc/ssl/certs/myownclouddomainname.com.crt;
  4166. ssl_certificate_key /etc/ssl/private/myownclouddomainname.com.key;
  4167. ssl_session_timeout 5m;
  4168. ssl_prefer_server_ciphers on;
  4169. ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # not possible to do exclusive
  4170. ssl_ciphers 'EDH+CAMELLIA:EDH+aRSA:EECDH+aRSA+AESGCM:EECDH+aRSA+SHA384:EECDH+aRSA+SHA256:EECDH:+CAMELLIA256:+AES256:+CAMELLIA128:+AES128:+SSLv3:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EXP:!PSK:!DSS:!RC4:!SEED:!ECDSA:CAMELLIA256-SHA:AES256-SHA:CAMELLIA128-SHA:AES128-SHA';
  4171. add_header Strict-Transport-Security max-age=15768000; # six months
  4172. # use this only if all subdomains support HTTPS!
  4173. # add_header Strict-Transport-Security "max-age=15768000; includeSubDomains";
  4174. # make sure webfinger and other well known services aren't blocked
  4175. # by denying dot files and rewrite request to the front controller
  4176. location ^~ /.well-known/ {
  4177. allow all;
  4178. rewrite ^/(.*) /index.php?q=$uri&$args last;
  4179. }
  4180. client_max_body_size 10G; # set max upload size
  4181. client_body_buffer_size 128k;
  4182. fastcgi_buffers 64 4K;
  4183. rewrite ^/caldav(.*)$ /remote.php/caldav$1 redirect;
  4184. rewrite ^/carddav(.*)$ /remote.php/carddav$1 redirect;
  4185. rewrite ^/webdav(.*)$ /remote.php/webdav$1 redirect;
  4186. index index.php;
  4187. error_page 403 /core/templates/403.php;
  4188. error_page 404 /core/templates/404.php;
  4189. location = /robots.txt {
  4190. allow all;
  4191. log_not_found off;
  4192. access_log off;
  4193. }
  4194. location ~ ^/(data|config|\.ht|db_structure\.xml|README) {
  4195. deny all;
  4196. }
  4197. location / {
  4198. # The following 2 rules are only needed with webfinger
  4199. rewrite ^/.well-known/host-meta /public.php?service=host-meta last;
  4200. rewrite ^/.well-known/host-meta.json /public.php?service=host-meta-json last;
  4201. rewrite ^/.well-known/carddav /remote.php/carddav/ redirect;
  4202. rewrite ^/.well-known/caldav /remote.php/caldav/ redirect;
  4203. rewrite ^(/core/doc/[^\/]+/)$ $1/index.html;
  4204. try_files $uri $uri/ index.php;
  4205. }
  4206. location ~ ^(.+?\.php)(/.*)?$ {
  4207. try_files $1 =404;
  4208. fastcgi_split_path_info ^(.+\.php)(/.+)$;
  4209. fastcgi_pass unix:/var/run/php5-fpm.sock;
  4210. fastcgi_index index.php;
  4211. include fastcgi_params;
  4212. fastcgi_param SCRIPT_FILENAME $document_root$1;
  4213. fastcgi_param PATH_INFO $2;
  4214. fastcgi_param HTTPS on;
  4215. }
  4216. # Optional: set long EXPIRES header on static assets
  4217. location ~* ^.+\.(jpg|jpeg|gif|bmp|ico|png|css|js|swf)$ {
  4218. expires 30d;
  4219. # Optional: Don't log access to assets
  4220. access_log off;
  4221. }
  4222. }
  4223. #+END_SRC
  4224. Save and exit. Then change the domain name.
  4225. #+BEGIN_SRC: bash
  4226. sed "s/myownclouddomainname.com/$HOSTNAME/g" /etc/nginx/sites-available/$HOSTNAME > /tmp/website
  4227. cp -f /tmp/website /etc/nginx/sites-available/$HOSTNAME
  4228. #+END_SRC
  4229. Download owncloud.
  4230. #+BEGIN_SRC: bash
  4231. mkdir ~/build
  4232. cd ~/build
  4233. wget http://freedombone.uk.to/owncloud.tar.bz2
  4234. #+END_SRC
  4235. Verify the download:
  4236. #+BEGIN_SRC: bash
  4237. sha256sum owncloud.tar.bz2
  4238. 9aca2aa0a0cd7b052e881c30ad6de25d135ec3f88a3920274f1be223b4cabedf
  4239. #+END_SRC
  4240. Extract the archive. This may take a couple of minutes, so don't be alarmed that the system has crashed.
  4241. #+BEGIN_SRC: bash
  4242. tar -xjf owncloud.tar.bz2
  4243. #+END_SRC
  4244. The extraction will take a few minutes. Move the extracted files to your site and set file permissions.
  4245. #+BEGIN_SRC: bash
  4246. cp -r owncloud/* /var/www/$HOSTNAME/htdocs
  4247. #+END_SRC
  4248. The copying also takes a few minutes. Then change the file permissions.
  4249. #+BEGIN_SRC: bash
  4250. chown -R www-data:www-data /var/www/$HOSTNAME/htdocs/apps
  4251. chown -R www-data:www-data /var/www/$HOSTNAME/htdocs/config
  4252. chown www-data:www-data /var/www/$HOSTNAME/htdocs
  4253. #+END_SRC
  4254. Increase the maximum upload size:
  4255. #+BEGIN_SRC: bash
  4256. editor /etc/php5/fpm/php.ini
  4257. #+END_SRC
  4258. Set the following:
  4259. #+BEGIN_SRC: bash
  4260. upload_max_filesize = 50M
  4261. post_max_size = 50M
  4262. #+END_SRC
  4263. Save and exit.
  4264. #+BEGIN_SRC: bash
  4265. service php5-fpm restart
  4266. service nginx restart
  4267. #+END_SRC
  4268. With a web browser visit your domain (mydomainname.com/owncloud) and enter an administrator username and password.
  4269. For extra security you may also wish to create an ordinary owncloud user with limited privileges. To do that click on the *settings* dropdown menu (top right) then *users* then enter a *Login Name* and *password* and click on *create*. Under *quota* select a size which is suitable for the remaining space on your microSD card, then select the settings menu from the top right and select *log out*. You can now log back in as your new user.
  4270. *** Owncloud on Android
  4271. First install [[https://f-droid.org/][F-Droid]] and then search for the current Owncloud app. Once it's installed you'll then be able to log into the BBB with the URL https://mydomainname.com/opencloud, supplying your username and password.
  4272. ** Install a Wiki
  4273. #+BEGIN_VERSE
  4274. /I believe that technology can liberate, but you need to be a master rather than a user. You need to pull technology apart and master it rather than letting it control you./
  4275. -- Tom Barbalet
  4276. #+END_VERSE
  4277. Dokuwiki is based upon flat files, and so is easy to move from one server to another without a lot of database complications.
  4278. Download the wiki.
  4279. #+BEGIN_SRC: bash
  4280. mkdir ~/build
  4281. cd ~/build
  4282. wget http://freedombone.uk.to/dokuwiki.tgz
  4283. #+END_SRC
  4284. Verify it.
  4285. #+BEGIN_SRC: bash
  4286. sha256sum dokuwiki.tgz
  4287. 6b126f90979463d9ddaa74acc6f96aa230cfdc789946f241c3646086d9574be8 dokuwiki.tgz
  4288. #+END_SRC
  4289. Then extract and install it.
  4290. #+BEGIN_SRC: bash
  4291. export HOSTNAME=mywikidomainname.com
  4292. tar -xzvf dokuwiki.tgz
  4293. rm -rf /var/www/$HOSTNAME/htdocs
  4294. mv dokuwiki /var/www/$HOSTNAME/htdocs
  4295. #+END_SRC
  4296. and alter permissions:
  4297. #+BEGIN_SRC: bash
  4298. chmod -R 755 /var/www/$HOSTNAME/htdocs
  4299. chown -R www-data:www-data /var/www/$HOSTNAME/htdocs
  4300. #+END_SRC
  4301. Open a browser and visit http://$HOSTNAME/install.php, then fill out the details. Once everything has been accepted without errors:
  4302. #+BEGIN_SRC: bash
  4303. rm /var/www/$HOSTNAME/htdocs/install.php
  4304. #+END_SRC
  4305. Add a few extra mime types:
  4306. #+BEGIN_SRC: bash
  4307. editor /var/www/$HOSTNAME/htdocs/conf/mime.conf
  4308. #+END_SRC
  4309. Append the following:
  4310. #+BEGIN_SRC: bash
  4311. ogv video/ogg
  4312. mp4 video/mp4
  4313. webm video/webm
  4314. #+END_SRC
  4315. Save and exit.
  4316. If you need to be able to upload large files to the wiki then edit */etc/php5/fpm/php.ini* and set *upload_max_filesize* accordingly.
  4317. Now you can visit your wiki and begin editing.
  4318. ** Install Bitmessage
  4319. #+BEGIN_VERSE
  4320. /The weakness of mass surveillance is that it can very easily be made much more expensive through changes in technical standards: pervasive, end-to-end encryption can quickly make indiscriminate surveillance impossible on a cost-effective basis/
  4321. -- Edward J. Snowden, testimony to the EU parliament
  4322. #+END_VERSE
  4323. *** A new kind of Email
  4324. [[https://bitmessage.org][Bitmessage]] is a new type of messaging system intended to fulfill the same role as email, but without the security problems. In particular, Bitmessage attempts to not just encrypt the content but also the metadata. It's message broadcasting system makes it exceedingly difficult for an attacker to know which computer a message is destined for. The only way you know whether a message has been sent to you is whether you are able to decrypt it from the passing stream of messages.
  4325. Although similar to Bitcoin in some regards, such as "/proof of work/", Bitmessage has no block chain and messages are only buffered for approximately three days after which they are deleted from any given node.
  4326. Installing Bitmessage as a daemon will increase the size of the network, and therefore the level of security for all users.
  4327. *** The Daemon
  4328. Install from the current source code.
  4329. #+BEGIN_SRC: bash
  4330. apt-get install python screen
  4331. mkdir ~/build
  4332. cd ~/build
  4333. git clone https://github.com/bashrc/PyBitmessage.git
  4334. cd PyBitmessage
  4335. make install
  4336. #+END_SRC
  4337. Now create the daemon.
  4338. #+BEGIN_SRC: bash
  4339. editor /etc/init.d/pybitmessage
  4340. #+END_SRC
  4341. Add the following text:
  4342. #+BEGIN_SRC: bash
  4343. #!/bin/bash
  4344. # /etc/init.d/bitmessage
  4345. ### BEGIN INIT INFO
  4346. # Provides: pybitmessage
  4347. # Required-Start: $remote_fs $syslog
  4348. # Required-Stop: $remote_fs $syslog
  4349. # Default-Start: 2 3 4 5
  4350. # Default-Stop: 0 1 6
  4351. # Short-Description: starts bitmessage as a background daemon, suitable for servers
  4352. # Description: This file should be used to construct scripts to be
  4353. # placed in /etc/init.d.
  4354. ### END INIT INFO
  4355. # Author: Super-Nathan <BM-Gu2k3Wy2hpTMYBxSoM2937SPcuU6xzEj>
  4356. #Settings
  4357. SERVICE='pybitmessage'
  4358. LOGFILE='/dev/null' # this disables logging
  4359. # LOGFILE='/var/log/bitmessage.log' # comment out the above line and un-comment this line to save a log
  4360. COMMAND="python bitmessagemain.py > $LOGFILE"
  4361. USERNAME='bitmsg'
  4362. NICELEVEL=19 # from 0-19 the bigger the number, the less the impact on system resources
  4363. HISTORY=1024
  4364. PBM_LOCATION="/usr/local/share/pybitmessage"
  4365. INVOCATION="nice -n ${NICELEVEL} ${COMMAND}"
  4366. PATH='/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/core_perl:/sbin:/usr/sbin:/bin:/usr/local/share/pybitmessage'
  4367. bm_start() {
  4368. echo "Starting $SERVICE..."
  4369. cd ${PBM_LOCATION}
  4370. su --command "screen -h ${HISTORY} -dmS ${SERVICE} ${INVOCATION}" $USERNAME
  4371. }
  4372. bm_stop() {
  4373. echo "Stopping $SERVICE"
  4374. su --command "screen -p 0 -S ${SERVICE} -X stuff "'^C'"" $USERNAME
  4375. }
  4376. #Start-Stop here
  4377. case "$1" in
  4378. start)
  4379. bm_start
  4380. ;;
  4381. stop)
  4382. bm_stop
  4383. ;;
  4384. restart)
  4385. bm_stop
  4386. sleep 60s
  4387. bm_start
  4388. ;;
  4389. *)
  4390. echo "Usage: $0 {start|stop|restart}"
  4391. exit 1
  4392. ;;
  4393. esac
  4394. exit 0
  4395. #+END_SRC
  4396. Save and exit.
  4397. Add a user which will be specifically for Bitmessage. Since bitmessage is still a relatively young and experimental project, this adds further compartmentalisation such that if there are any bugs within PyBitmessage then an attacker can't neccessarily gain control of root or any other user account. Here we create a user called /bitmsg/ and give it a long random password.
  4398. #+BEGIN_SRC: bash
  4399. adduser bitmsg
  4400. #+END_SRC
  4401. Create a /keys.dat/ file which is used to configure Bitmessage.
  4402. #+BEGIN_SRC: bash
  4403. mkdir /home/bitmsg/.config
  4404. mkdir /home/bitmsg/.config/PyBitmessage
  4405. editor /home/bitmsg/.config/PyBitmessage/keys.dat
  4406. #+END_SRC
  4407. Add the following, changing /apipassword/ to some long random string:
  4408. #+BEGIN_SRC: bash
  4409. [bitmessagesettings]
  4410. settingsversion = 8
  4411. port = 8444
  4412. timeformat = %%a, %%d %%b %%Y %%I:%%M %%p
  4413. blackwhitelist = black
  4414. startonlogon = False
  4415. minimizetotray = False
  4416. showtraynotifications = True
  4417. startintray = False
  4418. socksproxytype = none
  4419. sockshostname = localhost
  4420. socksport = 9050
  4421. socksauthentication = False
  4422. sockslisten = False
  4423. socksusername =
  4424. sockspassword =
  4425. keysencrypted = false
  4426. messagesencrypted = false
  4427. defaultnoncetrialsperbyte = 640
  4428. defaultpayloadlengthextrabytes = 14000
  4429. minimizeonclose = false
  4430. maxacceptablenoncetrialsperbyte = 0
  4431. maxacceptablepayloadlengthextrabytes = 0
  4432. userlocale = system
  4433. useidenticons = True
  4434. identiconsuffix = re9E9UtSEaWD
  4435. replybelow = False
  4436. stopresendingafterxdays = 4
  4437. stopresendingafterxmonths =
  4438. namecoinrpctype = namecoind
  4439. namecoinrpchost = localhost
  4440. namecoinrpcuser =
  4441. namecoinrpcpassword =
  4442. namecoinrpcport = 8336
  4443. sendoutgoingconnections = True
  4444. willinglysendtomobile = False
  4445. maxpayloadlengthkb = 256
  4446. daemon = true
  4447. apienabled = true
  4448. apiport = 8442
  4449. apiinterface = 127.0.0.1
  4450. apiusername = bitmsg
  4451. maxpayloadlengthkb = 256
  4452. apipassword = change_this_password
  4453. #+END_SRC
  4454. Save and exit. Then enable the daemon and run it.
  4455. #+BEGIN_SRC: bash
  4456. rm -f /tmp/-usr-local-share-pybitmessage-*.lock
  4457. chown -R bitmsg:bitmsg /home/bitmsg
  4458. chmod +x /etc/init.d/pybitmessage
  4459. update-rc.d pybitmessage defaults
  4460. service pybitmessage start
  4461. #+END_SRC
  4462. Now open port 8444 on your internet router or firewall and direct it to the BBB.
  4463. *** Using Bitmessage
  4464. Although in principle it would be possible to send Bitmessages directly from the BBB, in practice the /proof of work/ requirement would mean that it would take an infeasibly long time to send messages, and the computational workload would likely greatly impair the performance of other services also running on the system. So to send and receive Bitmessages it's better to just install the client on a laptop or desktop machine.
  4465. The easiest way to install the client is either to download it from [[https://bitmessage.org][bitmessage.org]] or to get the latest build from Github as follows:
  4466. #+BEGIN_SRC: bash
  4467. mkdir ~/build
  4468. cd ~/build
  4469. git clone https://github.com/Bitmessage/PyBitmessage.git
  4470. cd PyBitmessage
  4471. make install
  4472. pybitmessage
  4473. #+END_SRC
  4474. *** Connect Bitmessage to Email
  4475. It may be convenient to have any Bitmessages addressed to you which arrive at the BBB to be transfered to your email, so that you can check for messages on mobile devices or on computers where installing a Bitmessage client isn't an available option. This transference will take place on the BBB itself, so will not involve transmitting any plaintext over the local network or internet. To do this first you'll need to set up a receiving Bitmessage address by editing:
  4476. #+BEGIN_SRC: bash
  4477. /home/bitmsg/.config/PyBitmessage/keys.dat
  4478. #+END_SRC
  4479. and adding the details for your address, which could be coppied from another machine (such as a laptop running a Bitmessage client).
  4480. It will look something like:
  4481. #+BEGIN_SRC: bash
  4482. [BM-address]
  4483. label = myusername@mydomainname.com
  4484. enabled = true
  4485. decoy = false
  4486. noncetrialsperbyte = 640
  4487. payloadlengthextrabytes = 14000
  4488. privsigningkey = ...
  4489. privencryptionkey = ...
  4490. lastpubkeysendtime = ...
  4491. #+END_SRC
  4492. Note that it's particularly important that /label/ be set to your email address. This is how the system will know that when a bitmessage arrives which account to transfer it to.
  4493. You should also make sure that /apipassword/ is set to some long random string.
  4494. Save and close /keys.dat/, then restart the Bitmessage daemon.
  4495. #+BEGIN_SRC: bash
  4496. service pybitmessage restart
  4497. #+END_SRC
  4498. The restart will take 30 seconds or so. Next install the Bitmessage to email gateway.
  4499. #+BEGIN_SRC: bash
  4500. cd /usr/share
  4501. git clone https://github.com/bashrc/bitmessage-email-gateway
  4502. chown -R bitmsg:bitmsg bitmessage-email-gateway
  4503. cd bitmessage-email-gateway
  4504. mkdir /home/bitmsg/Maildir
  4505. mkdir /home/bitmsg/Maildir/new
  4506. chown -R bitmsg:bitmsg /home/bitmsg
  4507. #+END_SRC
  4508. Substitute /your_domain_name/ for your domain name (the main one used for email).
  4509. #+BEGIN_SRC: bash
  4510. sed 's/mydomainname.com/your_domain_name/g' bitmessage-gateway.py > bitmessage-gateway.py
  4511. #+END_SRC
  4512. Find out what the API password is:
  4513. #+BEGIN_SRC: bash
  4514. grep "apipassword" /home/bitmsg/.config/PyBitmessage/keys.dat | awk -F ' ' '{print $3}'
  4515. #+END_SRC
  4516. Then change it with:
  4517. #+BEGIN_SRC: bash
  4518. sed "s/'password' : ''/'password' : 'bitmessage_api_password'/g" bitmessage-gateway.py > bitmessage-gateway.py
  4519. #+END_SRC
  4520. Now create the daemon.
  4521. #+BEGIN_SRC: bash
  4522. editor /etc/init.d/bitmessage-gateway
  4523. #+END_SRC
  4524. Add the following text:
  4525. #+BEGIN_SRC: bash
  4526. #!/bin/bash
  4527. # /etc/init.d/bitmessage-gateway
  4528. ### BEGIN INIT INFO
  4529. # Provides: bitmessage-gateway
  4530. # Required-Start: $remote_fs $syslog
  4531. # Required-Stop: $remote_fs $syslog
  4532. # Default-Start: 2 3 4 5
  4533. # Default-Stop: 0 1 6
  4534. # Short-Description: starts a gateway between bitmessage and email
  4535. # Description:
  4536. ### END INIT INFO
  4537. # Author: Bob Mottram <bob@robotics.uk.to>
  4538. #Settings
  4539. SERVICE='bitmessage-gateway'
  4540. LOGFILE='/dev/null'
  4541. COMMAND="python bitmessage-gateway.py > $LOGFILE"
  4542. USERNAME='bitmsg'
  4543. NICELEVEL=19 # from 0-19 the bigger the number, the less the impact on system resources
  4544. HISTORY=1024
  4545. BMG_LOCATION="/usr/share/bitmessage-email-gateway"
  4546. INVOCATION="nice -n ${NICELEVEL} ${COMMAND}"
  4547. PATH='/usr/local/sbin:/usr/local/bin:/usr/bin:/sbin:/usr/sbin:/bin:/usr/share/bitmessage-email-gateway'
  4548. bmg_start() {
  4549. echo "Starting $SERVICE..."
  4550. cd ${BMG_LOCATION}
  4551. su --command "screen -h ${HISTORY} -dmS ${SERVICE} ${INVOCATION}" $USERNAME
  4552. }
  4553. bmg_stop() {
  4554. echo "Stopping $SERVICE"
  4555. su --command "screen -p 0 -S ${SERVICE} -X stuff "'^C'"" $USERNAME
  4556. }
  4557. #Start-Stop here
  4558. case "$1" in
  4559. start)
  4560. bmg_start
  4561. ;;
  4562. stop)
  4563. bmg_stop
  4564. ;;
  4565. restart)
  4566. bmg_stop
  4567. sleep 5s
  4568. bmg_start
  4569. ;;
  4570. *)
  4571. echo "Usage: $0 {start|stop|restart}"
  4572. exit 1
  4573. ;;
  4574. esac
  4575. exit 0
  4576. #+END_SRC
  4577. Save and exit.
  4578. #+BEGIN_SRC: bash
  4579. chmod +x /etc/init.d/bitmessage-gateway
  4580. update-rc.d bitmessage-gateway defaults
  4581. service bitmessage-gateway start
  4582. #+END_SRC
  4583. From a Bitmessage client you should now be able to send a message to your Bitmessage address and have it eventually appear as an email in your inbox.
  4584. ** Overcome restrictive environments
  4585. #+BEGIN_VERSE
  4586. /Censorship reflects a society's lack of confidence in itself. It is a hallmark of an authoritarian regime./
  4587. -- Potter Stewart
  4588. #+END_VERSE
  4589. In some environments, such as behind corporate firewalls or under regimes hostile towards the idea of open access to knowledge and information you may find that you're not able to use tools such as /ssh/ to get access to the BBB. In the worst case all ports other than 80 and 443 may be blocked.
  4590. In that scenario you can use a tool called [[http://code.google.com/p/shellinabox/][shellinabox]] to log into your BBB via your web site rather than via a terminal. This means that you can administrate your system from any device which has a web browser and keyboard.
  4591. #+BEGIN_SRC: bash
  4592. apt-get install shellinabox libapache
  4593. 2-mod-proxy-html
  4594. #+END_SRC
  4595. Update your Apache configuration.
  4596. #+BEGIN_SRC: bash
  4597. export HOSTNAME=mydomainname.com
  4598. editor /etc/apache2/sites-available/$HOSTNAME
  4599. #+END_SRC
  4600. Within the section which begins with *<VirtualHost *:443>* add the following, replacing /mydomainname.com/ with your domain name and /myusername/ with your username.
  4601. #+BEGIN_SRC: bash
  4602. <Location /shell>
  4603. ProxyPass http://localhost:4200/
  4604. Order allow,deny
  4605. Allow from all
  4606. AuthName "Authentication for shellinabox"
  4607. AuthUserFile /home/mydomainname.com/public_html/.htpasswd
  4608. AuthGroupFile /home/mydomainname.com/public_html/.htgroup
  4609. AuthType Basic
  4610. Require group shellinabox
  4611. Require user myusername
  4612. </Location>
  4613. #+END_SRC
  4614. Save and exit, then create a login password. It's recommended that the password be a long random string and that you then access it using a password manager such as KeepassX.
  4615. #+BEGIN_SRC: bash
  4616. mkdir /home/$HOSTNAME
  4617. mkdir /home/$HOSTNAME/public_html
  4618. htpasswd -c /home/$HOSTNAME/public_html/.htpasswd myusername
  4619. #+END_SRC
  4620. Create a user group.
  4621. #+BEGIN_SRC: bash
  4622. editor /home/$HOSTNAME/public_html/.htgroup
  4623. #+END_SRC
  4624. Add the following:
  4625. #+BEGIN_SRC: bash
  4626. shellinabox: myusername
  4627. #+END_SRC
  4628. Save and exit, then restart Apache.
  4629. #+BEGIN_SRC: bash
  4630. a2enmod proxy_http
  4631. service apache2 restart
  4632. #+END_SRC
  4633. Now with a web browser navigate to https://mydomainname.com/shell and log in.
  4634. If you're in a very locked down environment where access to web sites is severely restricted then as a last resort you may be able to use a command line browser, such as [[https://en.wikipedia.org/wiki/Lynx_%28web_browser%29][lynx]] from within /shellinabox/.
  4635. ** Set up a mailing list
  4636. #+BEGIN_VERSE
  4637. /All over the world there are many people who are united in creating software, content, and culture that is freely available for others to share, enjoy and enrich their lives. Together we believe that freedom is good. We believe it helps people do good things, make better choices, and lead safer and more secure lives. Together we are a community united by this belief./
  4638. -- Jono Bacon
  4639. #+END_VERSE
  4640. *** Public mailing list
  4641. Email mailing lists are old skool but still remain as a common and easy way of communicating on the internet. If you're running a public organisation such as an open source project or community group then you may want to set one up.
  4642. **** Installation
  4643. #+BEGIN_SRC: bash
  4644. export HOSTNAME=mydomainname.com
  4645. apt-get install mailman
  4646. newlist mailman
  4647. #+END_SRC
  4648. Enter an email address for the list administrator and a password.
  4649. #+BEGIN_SRC: bash
  4650. editor /etc/mailman/mm_cfg.py
  4651. #+END_SRC
  4652. Set *MTA=None* and change *http:* to *https:*, then save and exit.
  4653. Add some settings.
  4654. #+BEGIN_SRC: bash
  4655. editor /etc/exim4/conf.d/main/04_mailman_options
  4656. #+END_SRC
  4657. Add the following, replacing /mydomainname.com/ with your domain name.
  4658. #+BEGIN_SRC: bash
  4659. # Mailman macro definitions
  4660. # Home dir for the Mailman installation
  4661. MM_HOME=/var/lib/mailman
  4662. # User and group for Mailman
  4663. MM_UID=list
  4664. MM_GID=list
  4665. #
  4666. # Domains that your lists are in - colon separated list
  4667. # you may wish to add these into local_domains as well
  4668. domainlist mm_domains=mydomainname.com
  4669. # The path of the Mailman mail wrapper script
  4670. MM_WRAP=MM_HOME/mail/mailman
  4671. #
  4672. # The path of the list config file (used as a required file when
  4673. # verifying list addresses)
  4674. MM_LISTCHK=MM_HOME/lists/${lc::$local_part}/config.pck
  4675. #+END_SRC
  4676. Save and exit.
  4677. #+BEGIN_SRC: bash
  4678. editor /etc/exim4/conf.d/main/000_localmacros
  4679. #+END_SRC
  4680. Append the following:
  4681. #+BEGIN_SRC: bash
  4682. SYSTEM_ALIASES_PIPE_TRANSPORT = address_pipe
  4683. SYSTEM_ALIASES_USER = list
  4684. SYSTEM_ALIASES_GROUP = list
  4685. #+END_SRC
  4686. Save and exit.
  4687. #+BEGIN_SRC: bash
  4688. editor /etc/exim4/conf.d/acl/30_exim4-config_check_rcpt
  4689. #+END_SRC
  4690. Append the following, before the final /accept/:
  4691. #+BEGIN_SRC: bash
  4692. # Do callback verification unless Mailman incoming bounce
  4693. deny !local_parts = *-bounces : *-bounces+*
  4694. !verify = sender/callout=30s,defer_ok
  4695. #+END_SRC
  4696. Save and exit.
  4697. #+BEGIN_SRC: bash
  4698. editor
  4699. /etc/exim4/conf.d/router/450_exim4-config_mailman_aliases
  4700. #+END_SRC
  4701. Add the following:
  4702. #+BEGIN_SRC: bash
  4703. mailman:
  4704. driver = accept
  4705. domains = +mm_domains
  4706. require_files = MM_LISTCHK
  4707. local_part_suffix_optional
  4708. local_part_suffix = -admin : \
  4709. -bounces : -bounces+* : \
  4710. -confirm : -confirm+* : \
  4711. -join : -leave : \
  4712. -owner : -request : \
  4713. -subscribe : -unsubscribe
  4714. transport = mailman_transport
  4715. #+END_SRC
  4716. Save and exit.
  4717. #+BEGIN_SRC: bash
  4718. editor /etc/exim4/conf.d/transport/40_exim4-config_mailman_pipe
  4719. #+END_SRC
  4720. Add the following:
  4721. #+BEGIN_SRC: bash
  4722. mailman_transport:
  4723. driver = pipe
  4724. command = MM_WRAP \
  4725. '${if def:local_part_suffix \
  4726. {${sg{$local_part_suffix}{-(\\w+)(\\+.*)?}{\$1}}} \
  4727. {post}}' \
  4728. $local_part
  4729. current_directory = MM_HOME
  4730. home_directory = MM_HOME
  4731. user = MM_UID
  4732. group = MM_GID
  4733. #+END_SRC
  4734. Save and exit.
  4735. #+BEGIN_SRC: bash
  4736. chown root:list /var/lib/mailman/mail/mailman
  4737. update-exim4.conf.template -r
  4738. update-exim4.conf
  4739. service exim4 restart
  4740. editor /etc/apache2/conf.d/mailman
  4741. #+END_SRC
  4742. Add the following:
  4743. #+BEGIN_SRC: bash
  4744. Alias /pipermail /var/lib/mailman/archives/public
  4745. Alias /images/mailman /usr/share/images/mailman
  4746. <directory /var/lib/mailman/archives/public>
  4747. DirectoryIndex index.html
  4748. </directory>
  4749. #+END_SRC
  4750. Save and exit.
  4751. #+BEGIN_SRC: bash
  4752. editor /etc/apache2/sites-available/$HOSTNAME
  4753. #+END_SRC
  4754. Add the following to the 443 section.
  4755. #+BEGIN_SRC: bash
  4756. <Location /mailman>
  4757. Options Indexes FollowSymLinks MultiViews
  4758. Order allow,deny
  4759. Allow from all
  4760. RedirectMatch ^/$ /cgi-bin/mailman/listinfo
  4761. </Location>
  4762. #+END_SRC
  4763. Save and exit.
  4764. #+BEGIN_SRC: bash
  4765. service apache2 restart
  4766. #+END_SRC
  4767. Now add your mailing list. The list name should not include any spaces.
  4768. #+BEGIN_SRC: bash
  4769. newlist mymailinglistname
  4770. #+END_SRC
  4771. With a browser visit https://$HOSTNAME/cgi-bin/mailman/admin/mymailinglistname to configure the mailing list.
  4772. Under *General Options* add an email address for a moderator (could be the same as the administrator) and click *Submit your changes*.
  4773. Under *Privacy Options* set steps required for subscription to *Confirm and approve* and click *Submit your changes*.
  4774. Also change these settings for the account within https://$HOSTNAME/cgi-bin/mailman/admin/mailman
  4775. Then to test that the mailing list works:
  4776. #+BEGIN_SRC: bash
  4777. exim -d+route -bt mymailinglistname@$HOSTNAME
  4778. #+END_SRC
  4779. If everything is working then this shouldn't show any problems.
  4780. **** Using the mailing list
  4781. Direct subscribers towards:
  4782. #+BEGIN_SRC: bash
  4783. https://mydomainname.com/cgi-bin/mailman/listinfo/mymailinglistname
  4784. #+END_SRC
  4785. To administrate the list visit:
  4786. #+BEGIN_SRC: bash
  4787. https://mydomainname.com/cgi-bin/mailman/admin/mymailinglistname
  4788. #+END_SRC
  4789. To add another mailing list:
  4790. #+BEGIN_SRC: bash
  4791. newlist mymailinglistname
  4792. #+END_SRC
  4793. To delete a mailing list:
  4794. #+BEGIN_SRC: bash
  4795. rmlist -a mymailinglistname
  4796. #+END_SRC
  4797. *** Private (encrypted) mailing list
  4798. In addition to conventional public email lists it's also possible to set up a private mailing list which is only readable by members. A private email list uses [[https://en.wikipedia.org/wiki/GNU_Privacy_Guard][GPG]] and a public/private key pair for the server which can then be used to send emails to the list in an encrypted form. The email addresses and public GPG keys of members may be added to the list so that any new messages can be distributed to them in a secure manner.
  4799. Private mailing lists are likely to be able to keep the contents of the discussion out of the clutches of warrantless mass surveillance but, as with all conventional email, it won't prevent such systems from generating social graphs of who is communicating with the list since the /from/ and /to/ attributes are always transmitted in the clear.
  4800. **** Installation
  4801. #+BEGIN_SRC: bash
  4802. apt-get install schleuder
  4803. #+END_SRC
  4804. Edit the configuration:
  4805. #+BEGIN_SRC: bash
  4806. editor /etc/schleuder/schleuder.conf
  4807. #+END_SRC
  4808. Set the following parameters, replacing /mydomainname.com/ with your domain name:
  4809. #+BEGIN_SRC: bash
  4810. smtp_port: 465
  4811. superadminaddr: root@mydomainname.com
  4812. #+END_SRC
  4813. Save and exit.
  4814. Get your GPG public key, replacing /myGPGkeyID/ with your GPG key ID:
  4815. #+BEGIN_SRC: bash
  4816. export MYKEYID=myGPGkeyID
  4817. gpg --search-keys $MYKEYID
  4818. gpg --output /tmp/mypublickey.txt --armor --export $MYKEYID
  4819. #+END_SRC
  4820. Then to create a mailing list, replacing /mydomainname.com/ with your domain name, /myusername/ with your username and /mailinglistname/ with the name of the mailing list. /mailinglistname/ should be all one word, with no spaces.
  4821. #+BEGIN_SRC: bash
  4822. export MAILINGLISTNAME=mailinglistname
  4823. export MYUSERNAME=myusername
  4824. export HOSTNAME=mydomainname.com
  4825. export EMAILADDRESS=$MYUSERNAME@$HOSTNAME
  4826. schleuder-newlist $MAILINGLISTNAME@$HOSTNAME -realname "mailing list name" -adminaddress $EMAILADDRESS -initmember $EMAILADDRESS -initmemberkey /tmp/mypublickey.txt -nointeractive
  4827. #+END_SRC
  4828. Now add a mailing list rule:
  4829. #+BEGIN_SRC: bash
  4830. emailrule $MYUSERNAME $MAILINGLISTNAME@$HOSTNAME $MAILINGLISTNAME
  4831. #+END_SRC
  4832. Edit your Mutt configuration.
  4833. #+BEGIN_SRC: bash
  4834. editor /home/$MYUSERNAME/.muttrc
  4835. #+END_SRC
  4836. Search for the /mailboxes/ parameter and add "=mailinglistname". For example:
  4837. #+BEGIN_SRC: bash
  4838. mailboxes = =Sent =Drafts =mailinglistname
  4839. #+END_SRC
  4840. Save and exit.
  4841. Update Exim routing.
  4842. #+BEGIN_SRC: bash
  4843. editor /etc/exim4/conf.d/router/550_exim4-config_schleuder
  4844. #+END_SRC
  4845. Add the following:
  4846. #+BEGIN_SRC: bash
  4847. schleuder:
  4848. debug_print = "R: schleuder for $local_part@$domain"
  4849. driver = accept
  4850. local_part_suffix_optional
  4851. local_part_suffix = +* : -bounce : -sendkey
  4852. domains = +local_domains
  4853. user = schleuder
  4854. group = schleuder
  4855. require_files = schleuder:+/var/lib/schleuder/$domain/${local_part}
  4856. transport = schleuder_transport
  4857. #+END_SRC
  4858. Save and exit.
  4859. #+BEGIN_SRC: bash
  4860. editor /etc/exim4/conf.d/transport/30_exim4-config_schleuder
  4861. #+END_SRC
  4862. Add the following.
  4863. #+BEGIN_SRC: bash
  4864. schleuder_transport:
  4865. debug_print = "T: schleuder_transport for $local_part@$domain"
  4866. driver = pipe
  4867. home_directory = "/var/lib/schleuder/$domain/$local_part"
  4868. command = "/usr/bin/schleuder $local_part@$domain"
  4869. #+END_SRC
  4870. Save and exit.
  4871. #+BEGIN_SRC: bash
  4872. chown -R schleuder:schleuder /var/lib/schleuder
  4873. update-exim4.conf.template -r
  4874. update-exim4.conf
  4875. service exim4 restart
  4876. useradd -d /var/schleuderlists -s /bin/false schleuder
  4877. adduser Debian-exim schleuder
  4878. usermod -a -G mail schleuder
  4879. #+END_SRC
  4880. Test the routing.
  4881. #+BEGIN_SRC: bash
  4882. exim -d -bt mailinglistname@mydomainname.com
  4883. #+END_SRC
  4884. **** Importing the public key of the mailing list
  4885. Before you can use the mailing list you will first need to import its public key. How you do this depends upon which email client you're using.
  4886. ***** Using Mutt
  4887. Send an email to /mailinglistname-sendkey@mydomainname.com/ to have the list public key emailed to you.
  4888. When you receive the email open it and press *CTRL-k* to import it.
  4889. ***** Using Thunderbird
  4890. Send an email to /mailinglistname-sendkey@mydomainname.com/ to have the list public key emailed to you.
  4891. When you receive the email open it, select all the text with *CTRL-a* then *CTRL-c*.
  4892. On the menu select *OpenPGP* followed by *Key Management*.
  4893. You will now see a new menu bar. Select *Edit* followed by *Import keys from clipboard*.
  4894. Click on *Import* followed by *Ok*.
  4895. **** Using the list
  4896. To obtain the public keys of list members send an email to /mailinglistname-request@mydomainname.com/ containing *X-LIST-KEYS* in the message body.
  4897. To add a member: *X-ADD-MEMBER: othermember@otherdomain.net*
  4898. An example of adding a public key to the list:
  4899. #+BEGIN_SRC: bash
  4900. X-ADD-KEY:
  4901. -----BEGIN PGP PUBLIC KEY BLOCK-----
  4902. Version: GnuPG v1.4.9 (GNU/Linux)
  4903. mQGiBEjVO7oRBADQvT6wtD2IzzIiK0NbrcilCKCp4MWb8cYXTXguwPQI6y0Nerz4
  4904. dsK6J0X1Vgeo02tqA4xd3EDK8rdqL2yZfl/2egH8+85R3gDk+kqkfEp4pwCgp6VO
  4905. [...]
  4906. pNlF/qkaWwRb048h+iMrW21EkouLKTDPFkdFbapV2X5KJZIcfhO1zEbwc1ZKF3Ju
  4907. Q9X5GRmY62hz9SCZnsC0jeYAni8OUQV9NXfXlS/vePBUnOL08NQB
  4908. =xTv3
  4909. -----END PGP PUBLIC KEY BLOCK-----
  4910. #+END_SRC
  4911. To get details for a member: *X-GET-MEMBER: othermember@otherdomain.net*
  4912. To delete a member: *X-DELETE-MEMBER: othermember@otherdomain.net*
  4913. To delete a public key: *X-DELETE-KEY: keyID*
  4914. You can unsubscribe from the list with *X-UNSUBSCRIBE* in the message body.
  4915. *** Decentralised mailing list
  4916. A disadvantage with encrypted mailing lists which use the conventional email system is that there is a single server on which the list resides, and this creates a single point of failure and a bandwidth bottleneck for more heavily subscribed lists. If the mailing list server goes down for whatever reason then that may cause a lot of disruption to its users.
  4917. An alternative is to use a decentralised mailing list, implemented using Bitmessage. On your local machine (not the BBB) you can make a private mailing list which is difficult to censor and where there is no single point of failure. This type of mailing list is known as a "/chan/".
  4918. With Bitmessage if any one computer goes offline then the conversation can still keep going since there is no central mailing list server. Bitmessages are also encrypted with public/private key pairs and the manner in which the system operates makes it very difficult for the surveillance apparatus to exfiltrate the social graph of list users.
  4919. On a Debian based system:
  4920. #+BEGIN_SRC: bash
  4921. sudo apt-get install makepasswd
  4922. #+END_SRC
  4923. or on an RPM based system:
  4924. #+BEGIN_SRC: bash
  4925. sudo yum install makepasswd
  4926. #+END_SRC
  4927. Create a name for your mailing list. This will be a random string.
  4928. #+BEGIN_SRC: bash
  4929. makepasswd -c 40
  4930. #+END_SRC
  4931. Keep a note of this.
  4932. Run the Bitmessage client and on the menu select *File/Join-Create Chan/Create new chan*
  4933. Enter the random string which you created as the name of the mailing list. Also take a note of the BM address which is created.
  4934. You can hand out the random string used to generate the mailing list and its corresponding BM address to fellow members, either within a bitmessage or on paper or via [[https://en.wikipedia.org/wiki/Sneakernet][sneakernet]] or in a GPG/PGP encrypted email or via an XMPP+OTR or Friendica private message. Once others have those two pieces of data then they will be able to join.
  4935. To make the list easier to identify, rather than just appearing as a random string, then under the *Your Identities* tab right click on it and select *Set Avatar* and assign a suitable icon.
  4936. The disadvantage of this type of mailing list is that it's not possible for any one participant to act as a list moderator, or in other words each participant must do their own moderation. That's ok if the size of the group is small, but if it's larger then anyone spamming or trolling the list can make things miserable for the others.
  4937. ** Install a microblog
  4938. #+BEGIN_VERSE
  4939. /If you want to have more control over how you interact on the web, and regain your freedom, privacy and autonomy from outside interference, you need to start moving towards using programs like GNU Social/
  4940. -- Jason Self
  4941. #+END_VERSE
  4942. For a microblog you will need a separate domain/subdomain, so see [[Setting up a web site]] for details of how to create an Apache configuration for your microblog. If you're using freedns then you will need to create a new subdomain.
  4943. Install some dependencies:
  4944. #+BEGIN_SRC: bash
  4945. apt-get install php5-xcache php-gettext php5-curl php5-gd php5-mysql
  4946. #+END_SRC
  4947. Download GNU Social
  4948. #+BEGIN_SRC: bash
  4949. mkdir ~/build
  4950. cd ~/build
  4951. wget http://freedombone.uk.to/gnu-social.tar.gz
  4952. #+END_SRC
  4953. Verify it.
  4954. #+BEGIN_SRC: bash
  4955. sha256sum gnu-social.tar.gz
  4956. 1f886241c7f1a175e7be3cccbcb944ab6c03617fb75aefa4d62d37abed87d2b4
  4957. #+END_SRC
  4958. Extract the files and set permissions on them, where /mydomainname.com/ is your domain name.
  4959. #+BEGIN_SRC: bash
  4960. export HOSTNAME=mydomainname.com
  4961. tar zxf gnu-social.tar.gz
  4962. rm -rf /var/www/$HOSTNAME/htdocs
  4963. mv statusnet-gnu-social /var/www/$HOSTNAME/htdocs
  4964. chmod a+w /var/www/$HOSTNAME/htdocs
  4965. chown www-data:www-data /var/www/$HOSTNAME/htdocs
  4966. chmod a+w /var/www/$HOSTNAME/htdocs/avatar
  4967. chmod a+w /var/www/$HOSTNAME/htdocs/background
  4968. chmod a+w /var/www/$HOSTNAME/htdocs/file
  4969. chmod +x /var/www/$HOSTNAME/htdocs/scripts/maildaemon.php
  4970. #+END_SRC
  4971. Edit the Apache access settings.
  4972. #+BEGIN_SRC: bash
  4973. editor /var/www/$HOSTNAME/htdocs/.htaccess
  4974. #+END_SRC
  4975. Add the following:
  4976. #+BEGIN_SRC: bash
  4977. <IfModule mod_rewrite.c>
  4978. RewriteEngine On
  4979. RewriteBase /
  4980. ## Uncomment these if having trouble with API authentication
  4981. ## when PHP is running in CGI or FastCGI mode.
  4982. #
  4983. #RewriteCond %{HTTP:Authorization} ^(.*)
  4984. #RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%1]
  4985. RewriteCond %{REQUEST_FILENAME} !-f
  4986. RewriteCond %{REQUEST_FILENAME} !-d
  4987. RewriteRule (.*) index.php?p=$1 [L,QSA]
  4988. </IfModule>
  4989. <FilesMatch "\.(ini)">
  4990. Order allow,deny
  4991. </FilesMatch>
  4992. #+END_SRC
  4993. Save and exit, then create a database.
  4994. #+BEGIN_SRC: bash
  4995. mysql -u root -p
  4996. create database gnusocial;
  4997. CREATE USER 'gnusocialadmin'@'localhost' IDENTIFIED BY 'gnusocialpassword';
  4998. GRANT ALL PRIVILEGES ON gnusocial.* TO 'gnusocialadmin'@'localhost';
  4999. quit
  5000. #+END_SRC
  5001. Add the mailer script to the aliases file:
  5002. #+BEGIN_SRC: bash
  5003. editor /etc/aliases
  5004. #+END_SRC
  5005. Add the following, replacing /mydomainname.com/ with your domain name.
  5006. #+BEGIN_SRC: bash
  5007. www-data: root
  5008. *: /var/www/mydomainname.com/htdocs/scripts/maildaemon.php
  5009. #+END_SRC
  5010. Save and exit. Update the aliases by typing:
  5011. #+BEGIN_SRC: bash
  5012. newaliases
  5013. #+END_SRC
  5014. Then with a web browser navigate to:
  5015. https://$HOSTNAME/install.php
  5016. Set a name for the site.
  5017. Server SSL: enable
  5018. Hostname: localhost
  5019. Type: MySql
  5020. Name: gnusocial
  5021. DB username: gnusocialadmin
  5022. DB Password; your gnu social admin password goes here
  5023. Administrator nickname: myusername
  5024. Administrator password: mylongrandompassword
  5025. Subscribe to announcements: ticked
  5026. Site profile: Community
  5027. Press the *Submit* button. It may take a few minutes, so don't be concerned that it has crashed. When the process completes you will see a lot of "Strict standards" warnings which you can ignore.
  5028. Navigate to http://$HOSTNAME/gnusocial and you can then complete the configuration via the *Admin* section on the header bar. Some recommended admin settings are:
  5029. Under the *Site* settings:
  5030. Text limit: 140
  5031. Dupe Limit: 60000
  5032. Under the *User* settings:
  5033. Bio limit: 1000
  5034. Under the *Access* settings:
  5035. /Invite only/ ticked
  5036. Under the License section select a license if you wish. Details for Creative Commons licenses [[https://creativecommons.org/licenses/][can be found here]]. If you only intend to do private microblogging then just leave these settings as they are.
  5037. If you want to invite more users then click on the big button *Invite more colleagues*, then enter their email addresses and hit the *send* button. The invite only configuration which you've just installed is useful because it prevents spammers, or other [[https://en.wikipedia.org/wiki/Joint_Threat_Research_Intelligence_Group]["bad actors"]], from clogging your system with nonsense.
  5038. Edit the config file.
  5039. #+BEGIN_SRC: bash
  5040. editor /var/www/$HOSTNAME/htdocs/config.php
  5041. #+END_SRC
  5042. Change the ssl setting from *always* to *sometimes*, hten save and exit.
  5043. So, you're now microblogging on the open web, with no companies in the middle. Congratulations! To find some other people to connect to you can try searching other nodes listed at http://gnu.io/try/
  5044. When following other GNU Social users enter the URL of your profile. For example, https://mygnusocialdomain/myusername
  5045. ** Install Mediagoblin
  5046. #+BEGIN_VERSE
  5047. /The silos that are the main current points of media sharing are not only vulnerable to attacks on free speech, but also hamper important grassroots economic activity by privileging the interests of a tiny minority over those of most of the world./
  5048. #+END_VERSE
  5049. Mediagoblin allows you to have a YouTube/Soundcloud/Flickr/Picasa type of site to share your pictures, videos or audio files. An advantage of not having any company in the middle is that you can't be arbitrarily censored without any explanation, as seems to frequently occur on YouTube. It is recommended that you use media formats which are not encumbered by patents, such as /ogg/ or /ogv/.
  5050. For a mediagoblin site it is recommended to use a separate domain/subdomain, so see [[Setting up a web site]] for details of how to create an Apache configuration for your microblog. If you're using freedns then you will need to create a new subdomain.
  5051. Install some dependencies.
  5052. #+BEGIN_SRC: bash
  5053. aptitude install git-core python python-dev python-lxml python-imaging python-virtualenv python-gst0.10 libjpeg8-dev sqlite3 libapache2-mod-fcgid gstreamer0.10-plugins-base gstreamer0.10-plugins-bad gstreamer0.10-plugins-good gstreamer0.10-plugins-ugly gstreamer0.10-ffmpeg python-numpy python-scipy libsndfile1-dev
  5054. #+END_SRC
  5055. Create a user, replacing /mymediagoblindomain/ with the domain name for your mediagoblin site.
  5056. #+BEGIN_SRC: bash
  5057. export HOSTNAME=mymediagoblindomain
  5058. adduser mediagoblin
  5059. #+END_SRC
  5060. Give the user a long random password.
  5061. #+BEGIN_SRC: bash
  5062. mkdir -p /srv/$HOSTNAME
  5063. chown -hR mediagoblin:mediagoblin /srv/$HOSTNAME
  5064. su - mediagoblin
  5065. export HOSTNAME=mymediagoblindomain
  5066. cd /srv/$HOSTNAME
  5067. git clone git://gitorious.org/mediagoblin/mediagoblin.git
  5068. cd mediagoblin
  5069. git submodule init
  5070. git submodule update
  5071. virtualenv --system-site-packages .
  5072. ./bin/python setup.py develop
  5073. ./bin/easy_install flup
  5074. cp mediagoblin.ini mediagoblin_local.ini
  5075. cp paste.ini paste_local.ini
  5076. editor mediagoblin_local.ini
  5077. #+END_SRC
  5078. Change *email_sender_address* to your email address and set *email_debug_mode* to false. Also append the following to the bottom of the file, under the *plugins* section.
  5079. #+BEGIN_SRC: bash
  5080. [[mediagoblin.media_types.audio]]
  5081. [[mediagoblin.media_types.video]]
  5082. [[mediagoblin.media_types.stl]]
  5083. #+END_SRC
  5084. Then save and exit.
  5085. #+BEGIN_SRC: bash
  5086. ./bin/pip install scikits.audiolab
  5087. ./bin/gmg dbupdate
  5088. exit # to go back to the root user
  5089. editor /etc/init.d/mediagoblin
  5090. #+END_SRC
  5091. Add the following, replacing /mymediagoblindomain/ with the domain name for your mediagoblin site.
  5092. #+BEGIN_SRC: bash
  5093. #!/bin/bash
  5094. # /etc/init.d/mediagoblin
  5095. ### BEGIN INIT INFO
  5096. # Provides: mediagoblin
  5097. # Required-Start: $remote_fs $syslog
  5098. # Required-Stop: $remote_fs $syslog
  5099. # Default-Start: 2 3 4 5
  5100. # Default-Stop: 0 1 6
  5101. # Short-Description: starts mediagoblin
  5102. # Description: Other methods may work, but I found this the easiest
  5103. ### END INIT INFO
  5104. # Author: Bob Mottram <bob@robotics.uk.to>
  5105. #Settings
  5106. SERVICE='mediagoblin'
  5107. LOGFILE='/srv/mymediagoblindomain/mediagoblin.log'
  5108. COMMAND="./lazyserver.sh > $LOGFILE"
  5109. USERNAME='mediagoblin'
  5110. NICELEVEL=15 # from 0-19 the bigger the number, the less the impact on system resources
  5111. HISTORY=1024
  5112. MG_LOCATION="/srv/mymediagoblindomain/mediagoblin"
  5113. INVOCATION="nice -n ${NICELEVEL} ${COMMAND}"
  5114. PATH='/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/core_perl:/sbin:/usr/sbin:/bin'
  5115. mg_start() {
  5116. echo "Starting $SERVICE..."
  5117. cd ${MG_LOCATION}
  5118. su --command "screen -h ${HISTORY} -dmS ${SERVICE} ${INVOCATION}" $USERNAME
  5119. }
  5120. mg_stop() {
  5121. echo "Stopping $SERVICE"
  5122. su --command "screen -p 0 -S ${SERVICE} -X stuff "'^C'"" $USERNAME
  5123. }
  5124. #Start-Stop here
  5125. case "$1" in
  5126. start)
  5127. mg_start
  5128. ;;
  5129. stop)
  5130. mg_stop
  5131. ;;
  5132. restart)
  5133. mg_stop
  5134. sleep 10s
  5135. mg_start
  5136. ;;
  5137. *)
  5138. echo "Usage: $0 {start|stop|restart}"
  5139. exit 1
  5140. ;;
  5141. esac
  5142. exit 0
  5143. #+END_SRC
  5144. Save and exit.
  5145. #+BEGIN_SRC: bash
  5146. chmod +x /etc/init.d/mediagoblin
  5147. update-rc.d mediagoblin defaults
  5148. service mediagoblin start
  5149. #+END_SRC
  5150. Edit the Apache configuration for your mediagoblin site.
  5151. #+BEGIN_SRC: bash
  5152. editor /etc/apache2/sites-available/mymediagoblindomain
  5153. #+END_SRC
  5154. Delete the existing configuration (in Emacs it's CTRL-x h then CTRL-w) and paste the following, replacing /mymediagoblindomain/ with your mediagoblin domain name and /myusername@mydomainname.com/ with your email address.
  5155. #+BEGIN_SRC: bash
  5156. <VirtualHost *:80>
  5157. ServerAdmin myusername@mydomainname.com
  5158. DocumentRoot /srv/mymediagoblindomain/mediagoblin
  5159. ServerName mymediagoblindomain
  5160. <Directory />
  5161. Options FollowSymLinks
  5162. AllowOverride None
  5163. </Directory>
  5164. <Directory /srv/mymediagoblindomain/mediagoblin/>
  5165. Options Indexes FollowSymLinks MultiViews
  5166. AllowOverride All
  5167. Order allow,deny
  5168. allow from all
  5169. LimitRequestBody 536870912
  5170. </Directory>
  5171. LogLevel warn
  5172. ProxyVia On
  5173. ProxyRequests off
  5174. ProxyPreserveHost on
  5175. ProxyPass / http://localhost:6543/
  5176. ErrorLog "/var/log/apache2/error.log"
  5177. CustomLog "/var/log/apache2/access.log" combined
  5178. RewriteEngine On
  5179. RewriteOptions Inherit
  5180. </VirtualHost>
  5181. #+END_SRC
  5182. Save and exit.
  5183. Now in a browser visit http://mymediagoblindomain and create a user. If you wish this to be a single user installation to prevent a lot of spammers signing up.
  5184. #+BEGIN_SRC: bash
  5185. editor /srv/mymediagoblindomain/mediagoblin/mediagoblin_local.ini
  5186. #+END_SRC
  5187. Then set:
  5188. #+BEGIN_SRC: bash
  5189. allow_registration = false
  5190. #+END_SRC
  5191. Save and exit.
  5192. ** Run a pastebin service
  5193. If you need to be able to share short text files or other kinds of files on a temporary basis (doing technical support or reporting a bug, for example) then it's useful to have a pastebin system running on your server.
  5194. For this you will need to set up a new subdomain and create a new Apache configuration. For details on how to do that see [[Getting onto the web]] and [[Setting up a web site]].
  5195. #+BEGIN_SRC: bash
  5196. adduser --disabled-login zerobin
  5197. mkdir ~/build
  5198. cd ~/build
  5199. git clone https://github.com/sametmax/0bin.git
  5200. cd 0bin
  5201. python setup.py install
  5202. chown -R zerobin:zerobin /usr/local/lib/python2.7/dist-packages/zerobin-0.4.1-py2.7.egg/zerobin/static
  5203. #+END_SRC
  5204. For the /chown/ command you may need to change the directory name within /dist-packages/, depending upon the version number of [[https://github.com/sametmax/0bin][0bin]].
  5205. Now create the daemon.
  5206. #+BEGIN_SRC: bash
  5207. editor /etc/init.d/zerobin
  5208. #+END_SRC
  5209. Add the following text:
  5210. #+BEGIN_SRC: bash
  5211. #!/bin/bash
  5212. # /etc/init.d/zerobin
  5213. ### BEGIN INIT INFO
  5214. # Provides: zerobin
  5215. # Required-Start: $remote_fs $syslog
  5216. # Required-Stop: $remote_fs $syslog
  5217. # Default-Start: 2 3 4 5
  5218. # Default-Stop: 0 1 6
  5219. # Short-Description: starts zerobin as a background daemon
  5220. # Description: starts zerobin as a background daemon
  5221. ### END INIT INFO
  5222. # Author: Bob Mottram <bob@robotics.uk.to>
  5223. #Settings
  5224. SERVICE='zerobin'
  5225. LOGFILE='/home/zerobin/zerobin.log'
  5226. COMMAND="zerobin > $LOGFILE"
  5227. USERNAME='zerobin'
  5228. NICELEVEL=19 # from 0-19 the bigger the number, the less the impact on system resources
  5229. HISTORY=1024
  5230. INVOCATION="nice -n ${NICELEVEL} ${COMMAND}"
  5231. PATH='/usr/local/sbin:/usr/local/bin:/usr/bin:/sbin:/usr/sbin:/bin'
  5232. zerobin_start() {
  5233. echo "Starting $SERVICE..."
  5234. su --command "screen -h ${HISTORY} -dmS ${SERVICE} ${INVOCATION}" $USERNAME
  5235. }
  5236. zerobin_stop() {
  5237. echo "Stopping $SERVICE"
  5238. su --command "screen -p 0 -S ${SERVICE} -X stuff "'^C'"" $USERNAME
  5239. }
  5240. #Start-Stop here
  5241. case "$1" in
  5242. start)
  5243. zerobin_start
  5244. ;;
  5245. stop)
  5246. zerobin_stop
  5247. ;;
  5248. restart)
  5249. zerobin_stop
  5250. sleep 2s
  5251. zerobin_start
  5252. ;;
  5253. *)
  5254. echo "Usage: $0 {start|stop|restart}"
  5255. exit 1
  5256. ;;
  5257. esac
  5258. exit 0
  5259. #+END_SRC
  5260. Save and exit.
  5261. #+BEGIN_SRC: bash
  5262. chmod +x /etc/init.d/zerobin
  5263. update-rc.d zerobin defaults
  5264. service zerobin start
  5265. #+END_SRC
  5266. Now edit the Apache configuration, delete anything which already exists and add the following, changing /mypastedomainname.com/ to your pastebin subdomain and /username@mydomainname.com/ to your email address:
  5267. #+BEGIN_SRC: bash
  5268. <VirtualHost *:80>
  5269. ServerAdmin username@mydomainname.com
  5270. ServerName mypastedomainname.com
  5271. <Location />
  5272. ProxyPass http://localhost:8000/
  5273. Order allow,deny
  5274. Allow from all
  5275. LimitRequestBody 256000
  5276. </Location>
  5277. ErrorLog ${APACHE_LOG_DIR}/paste_error.log
  5278. # Possible values include: debug, info, notice, warn, error, crit,
  5279. # alert, emerg.
  5280. LogLevel error
  5281. CustomLog ${APACHE_LOG_DIR}/paste.log combined
  5282. </VirtualHost>
  5283. #+END_SRC
  5284. Save and exit.
  5285. The encryption used here is really just intended to provide you with plausible deniability for content which other users may post to your server. Pastes aren't really intended to be totally private, so if your intention is to send private messages then Bitmessage, an XMPP chat session with OTR or a GPG encrypted email is a far better solution.
  5286. #+BEGIN_SRC: bash
  5287. service apache2 restart
  5288. #+END_SRC
  5289. You can now visit your new site and paste things for others to see, and vice versa. Uploads are limited to 256K in size to prevent your storage space from being used up. You can further limit the maximum amount of storage space by doing the following:
  5290. #+BEGIN_SRC: bash
  5291. editor /usr/bin/zerobinupdate
  5292. #+END_SRC
  5293. Add the following:
  5294. #+BEGIN_SRC: bash
  5295. #!/bin/bash
  5296. CONTENT=/usr/local/lib/python2.7/dist-packages/zerobin-0.4.1-py2.7.egg/zerobin/static/content
  5297. # Exit if there is no content directory
  5298. if [[ ! -d $CONTENT ]]; then
  5299. exit
  5300. fi
  5301. LOG=/home/zerobin/zerobin.log
  5302. CHECK=`du -hs $CONTENT`
  5303. regex="([0-9]+)G"
  5304. if [[ $CHECK =~ $regex && ${BASH_REMATCH[1]} -gt 1 ]]; then
  5305. echo "Directory size limit exceeded - removing zerobin content" >> $LOG
  5306. rm -rf $CONTENT/*
  5307. fi
  5308. #+END_SRC
  5309. Save and exit.
  5310. #+BEGIN_SRC: bash
  5311. chmod +x /usr/bin/zerobinupdate
  5312. echo "*/5 * * * * root /usr/bin/timeout 120 /usr/bin/zerobinupdate" >> /etc/crontab
  5313. #+END_SRC
  5314. Additionally to ensure that the service is being used as intended and not as a permanent data store:
  5315. #+BEGIN_SRC: bash
  5316. editor /usr/bin/zerobinclear
  5317. #+END_SRC
  5318. Add the following:
  5319. #+BEGIN_SRC: bash
  5320. #!/bin/bash
  5321. CONTENT=/usr/local/lib/python2.7/dist-packages/zerobin-0.4.1-py2.7.egg/zerobin/static/content
  5322. # Exit if there is no content directory
  5323. if [[ ! -d $CONTENT ]]; then
  5324. exit
  5325. fi
  5326. rm -rf $CONTENT
  5327. #+END_SRC
  5328. Save and exit.
  5329. #+BEGIN_SRC: bash
  5330. chmod +x /usr/bin/zerobinclear
  5331. echo "35 3 * * * root /usr/bin/zerobinclear" >> /etc/crontab
  5332. service cron restart
  5333. #+END_SRC
  5334. This will delete all pasted content once per day.
  5335. ** Subsonic music server
  5336. #+BEGIN_VERSE
  5337. /Where words fail, music speaks./
  5338. -- Hans Christian Andersen
  5339. #+END_VERSE
  5340. *** Introduction
  5341. Owncloud is probably the easiest way to handle your media, but Subsonic is another alternative and has a mobile app which can be used to conveniently play your music. Unless you particularly prefer Subsonic it's probably better to stick with Owncloud and skip this section.
  5342. The method of installing Subsonic described here is not ideal, but works. The main issue is that the Debian package supplied from sourceforge contains a licensing [[https://www.fsf.org/blogs/community/antifeatures][antifeature]], which needs to be removed in order to achieve a fully free system.
  5343. *** Installing the Server
  5344. For this you will need a new subdomain (or your own domain), so see [[Setting up a web site]] for details of how to do that.
  5345. #+BEGIN_SRC: bash
  5346. apt-get install openjdk-7-jre openjdk-7-jdk lintian maven libav-tools
  5347. adduser subsonic
  5348. mkdir ~/build
  5349. cd ~/build
  5350. wget http://freedombone.uk.to/subsonic-4.9.deb
  5351. sha256sum subsonic-4.9.deb
  5352. 064c2a7e69d47715ce230f3dfcacdc627c18f6466e0fe48952f133ce06be698d
  5353. dpkg -i subsonic-4.9.deb
  5354. #+END_SRC
  5355. Now we remove the antifeature by compiling from source and then overwriting the relevant files.
  5356. #+BEGIN_SRC: bash
  5357. git clone https://github.com/EugeneKay/subsonic.git
  5358. cd subsonic
  5359. git checkout release
  5360. mvn package
  5361. mvn -P full -pl subsonic-booter -am install
  5362. mvn -P full -pl subsonic-installer-debian/ -am install
  5363. cp ~/build/subsonic/subsonic-booter/target/subsonic-booter-jar-with-dependencies.jar /usr/share/subsonic/
  5364. cp ~/build/subsonic/subsonic-main/target/subsonic.war /usr/share/subsonic/subsonic.war
  5365. cp ~/build/subsonic/subsonic-booter/src/main/script/subsonic.sh /usr/share/subsonic/subsonic.sh
  5366. editor /etc/default/subsonic
  5367. #+END_SRC
  5368. Settings should look like the following.
  5369. #+BEGIN_SRC: bash
  5370. SUBSONIC_ARGS="--max-memory=100"
  5371. SUBSONIC_USER=subsonic
  5372. #+END_SRC
  5373. Save and exit.
  5374. #+BEGIN_SRC: bash
  5375. chown -R subsonic:subsonic /var/subsonic
  5376. mkdir /var/music
  5377. chown -R subsonic:subsonic /var/music
  5378. service subsonic restart
  5379. #+END_SRC
  5380. Edit your web server configuration.
  5381. #+BEGIN_SRC: bash
  5382. editor /etc/nginx/sites-available/$HOSTNAME
  5383. #+END_SRC
  5384. Delete all existing contents then add the following:
  5385. #+BEGIN_SRC: bash
  5386. upstream subsonicbackend {
  5387. server 127.0.0.1:4040 max_fails=3 fail_timeout=30s;
  5388. server 127.0.0.1:4040 max_fails=3 fail_timeout=60s;
  5389. server 127.0.0.1:4040 max_fails=3 fail_timeout=90s;
  5390. }
  5391. server {
  5392. listen 80;
  5393. server_name mysubsonicdomainname.com;
  5394. rewrite ^ https://$server_name$request_uri? permanent;
  5395. }
  5396. map $http_upgrade $connection_upgrade {
  5397. default upgrade;
  5398. '' close;
  5399. }
  5400. server {
  5401. listen 443 ssl;
  5402. server_name mysubsonicdomainname.com;
  5403. index index.php;
  5404. error_log /var/www/mysubsonicdomainname.com/error.log debug;
  5405. ssl on;
  5406. ssl_certificate /etc/ssl/certs/mysubsonicdomainname.com.crt;
  5407. ssl_certificate_key /etc/ssl/private/mysubsonicdomainname.com.key;
  5408. ssl_session_timeout 5m;
  5409. ssl_prefer_server_ciphers on;
  5410. ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # not possible to do exclusive
  5411. ssl_ciphers 'EDH+CAMELLIA:EDH+aRSA:EECDH+aRSA+AESGCM:EECDH+aRSA+SHA384:EECDH+aRSA+SHA256:EECDH:+CAMELLIA256:+AES256:+CAMELLIA128:+AES128:+SSLv3:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EXP:!PSK:!DSS:!RC4:!SEED:!ECDSA:CAMELLIA256-SHA:AES256-SHA:CAMELLIA128-SHA:AES128-SHA';
  5412. #add_header Strict-Transport-Security max-age=15768000; # six months
  5413. # use this only if all subdomains support HTTPS!
  5414. add_header Strict-Transport-Security "max-age=15768000; includeSubDomains";
  5415. client_max_body_size 6m;
  5416. keepalive_timeout 75 75;
  5417. gzip_vary off;
  5418. location / {
  5419. proxy_pass https://subsonicbackend;
  5420. proxy_http_version 1.1;
  5421. proxy_redirect off;
  5422. proxy_set_header Upgrade $http_upgrade;
  5423. proxy_set_header Connection $connection_upgrade;
  5424. proxy_set_header Host $http_host;
  5425. proxy_set_header X-Real-IP $remote_addr;
  5426. proxy_buffers 16 32k;
  5427. }
  5428. }
  5429. server {
  5430. listen 443 ssl;
  5431. server_name mysubsonicdomainname.com;
  5432. charset utf-8;
  5433. root /var/www/mysubsonicdomainname.com/htdocs;
  5434. index index.php;
  5435. if ( !-d $request_filename ) {
  5436. rewrite ^/rest/(.*).view$ /rest/index.php?action=$1 last;
  5437. }
  5438. if ( !-d $request_filename ) {
  5439. rewrite ^/plex/(.*)$ /plex/index.php?action=$1 last;
  5440. }
  5441. location /rest {
  5442. limit_except GET POST {
  5443. deny all;
  5444. }
  5445. }
  5446. location /plex {
  5447. limit_except GET POST {
  5448. deny all;
  5449. }
  5450. }
  5451. location ^~ /bin/ {
  5452. deny all;
  5453. return 403;
  5454. }
  5455. location ^~ /config/ {
  5456. deny all;
  5457. return 403;
  5458. }
  5459. location / {
  5460. limit_except GET POST HEAD{
  5461. deny all;
  5462. }
  5463. }
  5464. location ~ ^(.+\.php)(.*)$ {
  5465. try_files $fastcgi_script_name =404;
  5466. fastcgi_split_path_info ^(.+\.php)(.*)$;
  5467. fastcgi_pass unix:/var/run/php5-fpm.sock;
  5468. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  5469. fastcgi_param PATH_INFO $fastcgi_path_info;
  5470. include /etc/nginx/fastcgi_params;
  5471. }
  5472. }
  5473. #+END_SRC
  5474. Save and exit.
  5475. #+BEGIN_SRC: bash
  5476. sed "s/mysubsonicdomainname.com/$HOSTNAME/g" /etc/nginx/sites-available/$HOSTNAME > /tmp/website
  5477. cp -f /tmp/website /etc/nginx/sites-available/$HOSTNAME
  5478. /etc/init.d/nginx reload
  5479. #+END_SRC
  5480. #+BEGIN_SRC: bash
  5481. export HOSTNAME=mysubsonicdomainname.com
  5482. editor /etc/apache2/sites-available/$HOSTNAME
  5483. #+END_SRC
  5484. Add the following, replacing /mysubsonicdomainname.com/ with your subsonic domain name and /myusername@mydomainname.com/ with your email address.
  5485. #+BEGIN_SRC: bash
  5486. <VirtualHost *:80>
  5487. ServerName mysubsonicdomainname.com
  5488. Redirect permanent / https://mysubsonicdomainname.com/
  5489. </VirtualHost>
  5490. <IfModule mod_ssl.c>
  5491. <VirtualHost *:443>
  5492. ServerAdmin myusername@mydomainname.com
  5493. ServerName mysubsonicdomainname.com
  5494. ProxyRequests Off
  5495. ProxyPreserveHost Off
  5496. <Location />
  5497. ProxyPass http://localhost:4040/
  5498. ProxyPassReverse http://localhost:4040/
  5499. </Location>
  5500. RewriteEngine on
  5501. RewriteOptions inherit
  5502. DocumentRoot /var/www/mysubsonicdomainname.com/htdocs
  5503. <Directory />
  5504. Options FollowSymLinks
  5505. AllowOverride All
  5506. </Directory>
  5507. <Directory /var/www/mysubsonicdomainname.com/htdocs/>
  5508. Options All
  5509. AllowOverride All
  5510. Order allow,deny
  5511. allow from all
  5512. LimitRequestBody 5120000
  5513. </Directory>
  5514. # Don't serve .php~ or .php# files created by emacs
  5515. <Files ~ "(^#.*#|~|\.sw[op])$">
  5516. Order allow,deny
  5517. Deny from all
  5518. </Files>
  5519. <IfModule headers_module>
  5520. Header set X-Content-Type-Options nosniff
  5521. Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate, private"
  5522. Header set Pragma no-cache
  5523. </IfModule>
  5524. <Files .htaccess>
  5525. deny from all
  5526. </Files>
  5527. ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
  5528. <Directory "/usr/lib/cgi-bin">
  5529. AllowOverride All
  5530. Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
  5531. Order allow,deny
  5532. Allow from all
  5533. LimitRequestBody 512000
  5534. </Directory>
  5535. ErrorLog ${APACHE_LOG_DIR}/error.log
  5536. # Possible values include: debug, info, notice, warn, error, crit,
  5537. # alert, emerg.
  5538. LogLevel error
  5539. CustomLog ${APACHE_LOG_DIR}/ssl_access.log combined
  5540. # SSL Engine Switch:
  5541. # Enable/Disable SSL for this virtual host.
  5542. SSLEngine on
  5543. SSLCertificateFile /etc/ssl/certs/mysubsonicdomainname.com.crt
  5544. SSLCertificateKeyFile /etc/ssl/private/mysubsonicdomainname.com.key
  5545. # Options based on bettercrypto.org
  5546. SSLProtocol All -SSLv2 -SSLv3
  5547. SSLHonorCipherOrder On
  5548. SSLCompression off
  5549. SSLCipherSuite EDH+CAMELLIA:EDH+aRSA:EECDH+aRSA+AESGCM:EECDH+aRSA+SHA384:EECDH+aRSA+SHA256:EECDH:+CAMELLIA256:+AES256:+CAMELLIA128:+AES128:+SSLv3:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EXP:!PSK:!SRP:!DSS:!RC4:!SEED:!ECDSA:CAMELLIA256-SHA:AES256-SHA:CAMELLIA128-SHA:AES128-SHA
  5550. # Add six earth month HSTS header for all users ...
  5551. Header add Strict-Transport-Security "max-age=15768000"
  5552. # If you want to protect all subdomains , use the following header
  5553. # ALL subdomains HAVE TO support https if you use this !
  5554. # Strict-Transport-Security: max-age=15768000 ; includeSubDomains
  5555. # SSL Engine Options:
  5556. # Set various options for the SSL engine.
  5557. # o FakeBasicAuth:
  5558. # Translate the client X.509 into a Basic Authorisation. This means that
  5559. # the standard Auth/DBMAuth methods can be used for access control. The
  5560. # user name is the `one line' version of the client's X.509 certificate.
  5561. # Note that no password is obtained from the user. Every entry in the user
  5562. # file needs this password: `xxj31ZMTZzkVA'.
  5563. # o ExportCertData:
  5564. # This exports two additional environment variables: SSL_CLIENT_CERT and
  5565. # SSL_SERVER_CERT. These contain the PEM-encoded certificates of the
  5566. # server (always existing) and the client (only existing when client
  5567. # authentication is used). This can be used to import the certificates
  5568. # into CGI scripts.
  5569. # o StdEnvVars:
  5570. # This exports the standard SSL/TLS related `SSL_*' environment variables.
  5571. # Per default this exportation is switched off for performance reasons,
  5572. # because the extraction step is an expensive operation and is usually
  5573. # useless for serving static content. So one usually enables the
  5574. # exportation for CGI and SSI requests only.
  5575. # o StrictRequire:
  5576. # This denies access when "SSLRequireSSL" or "SSLRequire" applied even
  5577. # under a "Satisfy any" situation, i.e. when it applies access is denied
  5578. # and no other module can change it.
  5579. # o OptRenegotiate:
  5580. # This enables optimized SSL connection renegotiation handling when SSL
  5581. # directives are used in per-directory context.
  5582. #SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire
  5583. <FilesMatch "\.(cgi|shtml|phtml|php)$">
  5584. SSLOptions +StdEnvVars
  5585. </FilesMatch>
  5586. <Directory /usr/lib/cgi-bin>
  5587. SSLOptions +StdEnvVars
  5588. </Directory>
  5589. # SSL Protocol Adjustments:
  5590. # The safe and default but still SSL/TLS standard compliant shutdown
  5591. # approach is that mod_ssl sends the close notify alert but doesn't wait for
  5592. # the close notify alert from client. When you need a different shutdown
  5593. # approach you can use one of the following variables:
  5594. # o ssl-unclean-shutdown:
  5595. # This forces an unclean shutdown when the connection is closed, i.e. no
  5596. # SSL close notify alert is send or allowed to received. This violates
  5597. # the SSL/TLS standard but is needed for some brain-dead browsers. Use
  5598. # this when you receive I/O errors because of the standard approach where
  5599. # mod_ssl sends the close notify alert.
  5600. # o ssl-accurate-shutdown:
  5601. # This forces an accurate shutdown when the connection is closed, i.e. a
  5602. # SSL close notify alert is send and mod_ssl waits for the close notify
  5603. # alert of the client. This is 100% SSL/TLS standard compliant, but in
  5604. # practice often causes hanging connections with brain-dead browsers. Use
  5605. # this only for browsers where you know that their SSL implementation
  5606. # works correctly.
  5607. # Notice: Most problems of broken clients are also related to the HTTP
  5608. # keep-alive facility, so you usually additionally want to disable
  5609. # keep-alive for those clients, too. Use variable "nokeepalive" for this.
  5610. # Similarly, one has to force some clients to use HTTP/1.0 to workaround
  5611. # their broken HTTP/1.1 implementation. Use variables "downgrade-1.0" and
  5612. # "force-response-1.0" for this.
  5613. BrowserMatch "MSIE [2-6]" \
  5614. nokeepalive ssl-unclean-shutdown \
  5615. downgrade-1.0 force-response-1.0
  5616. # MSIE 7 and newer should be able to use keepalive
  5617. BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown
  5618. </VirtualHost>
  5619. </IfModule>
  5620. #+END_SRC
  5621. Save and exit.
  5622. #+BEGIN_SRC: bash
  5623. makecert mysubsonicdomainname.com
  5624. a2ensite mysubsonicdomainname.com
  5625. service apache2 restart
  5626. #+END_SRC
  5627. *** Configuration
  5628. Open a browser and go to your subsonic domain name. Log in with username /admin/ and password /admin/, then change your administrator password.
  5629. Within the settings click on /users/ and add a user. Give your user access to everything by ticking all the checkboxes. You can then log out and log back in as the user.
  5630. Click /settings/ and select /transcoding/. Change the transcoding settings to the following:
  5631. | Name | Convert from | Convert to | Step 1 |
  5632. |----------------+---------------------------------------------------+------------+------------------------------------------------------------------------------------------------------------------------------------------|
  5633. | mp3 audio | ogg oga aac m4a flac wav wma aif aiff ape mpc shn | mp3 | avconv -i %s -b %bk -q 0 -loglevel error -f mp3 - |
  5634. | flv/h264 video | avi mpg mpeg mp4 m4v mkv mov wmv ogv divx m2ts | flv | avconv -ss %o -i %s -async 1 -b %bk -s %wx%h -c:a libmp3lame -ar 44100 -ac 2 -v debug -f flv -c:v libx264 -preset superfast -threads 0 - |
  5635. | Downsample command | avconv -i %s -b %bk -v 0 -f mp3 - |
  5636. | HTTP Live Streaming command | avconv -ss %0 -t %d -i %s -async 1 -b %bk -s %wx%h -ar 44100 -ac 2 -v 0 -f mpegts -vcodec libx264 -preset superfast -acodec libmp3lame -threads 0 - |
  5637. Then save.
  5638. Open port 4040 on your internet router and forward it to the BBB.
  5639. *** Adding your music
  5640. The easiest way to add your music is to obtain a large capacity USB stick, copy your music onto it, plug it into the front of the BBB and then mount it as a drive.
  5641. So with the USB stick plugged in and logged into the BBB as root via ssh:
  5642. #+BEGIN_SRC: bash
  5643. mount /dev/sda /var/music
  5644. chown -R subsonic:subsonic /var/music
  5645. #+END_SRC
  5646. Then within a browser go to your Subsonic domain name, select *settings*, then *Media folders* then *Scan media folders now*. Depending upon how much music you have this could take a while, so don't be too impatient.
  5647. *** Android App
  5648. Within [[https://f-droid.org/][F-Droid]] search for *Dsub* and install it.
  5649. Open the app, then press on the Dsub icon (top left) and select *settings*, followed by *servers*. Select one of the unused servers then set the name to your domain name, the server address to https://mysubsonicdomainname.com (the domain name you used for subsonic) and your username and password for the Subsonic user which you created earlier. Press on *test server* to check the internet connection to the BBB.
  5650. Remove any other servers (including the demo) by pressing on them then selecting *remove server*.
  5651. You can then press *back* a few times to return to the main Dsub menu and press *recently added*. If your media library has been scanned (as in the earlier "adding your music" step) then you should see tracks appear. Press on one, then press the play button.
  5652. Other proprietary Subsonic mobile apps are available, but are not recommended. Anything proprietary could contain backdoors, malware or other nasties which merely assist the surveillance apparatus.
  5653. ** Database maintenance
  5654. #+BEGIN_VERSE
  5655. /To be ready to fail is to be prepared for success./
  5656. -- Jose Bergamin
  5657. #+END_VERSE
  5658. Ideally the system should be as close to "/install and forget/" as possible, but sometimes mysql databases can become corrupted. To handle that situation we can set up a script to monitor the databases and automatically try to repair them, and if the repair fails then to roll back to the previous day's backup, so that at most you may have lost one day of social media updates, rather than losing everything.
  5659. #+BEGIN_SRC: bash
  5660. editor /usr/bin/repairdatabase
  5661. #+END_SRC
  5662. Add the following, using your mysql root password and entering your email address.
  5663. #+BEGIN_SRC: bash
  5664. #!/bin/bash
  5665. DATABASE=$1
  5666. EMAIL=myusername@mydomainname.com
  5667. MYSQL_ROOT_PASSWORD=mysqlrootpassword
  5668. TEMPFILE=/tmp/repairdatabase_$DATABASE
  5669. umask 0077
  5670. # check the database
  5671. mysqlcheck -c -u root --password=$MYSQL_ROOT_PASSWORD $DATABASE > $TEMPFILE
  5672. # Attempt to repair the database if it contains errors
  5673. if grep -q "Error" "$TEMPFILE"; then
  5674. mysqlcheck -u root --password=$MYSQL_ROOT_PASSWORD --auto-repair $DATABASE
  5675. else
  5676. # No errors were found, so exit
  5677. rm -f $TEMPFILE
  5678. exit 0
  5679. fi
  5680. rm -f $TEMPFILE
  5681. # Check the database again
  5682. mysqlcheck -c -u root --password=$MYSQL_ROOT_PASSWORD $DATABASE > $TEMPFILE
  5683. # If it still contains errors then restore from backup
  5684. if grep -q "Error" "$TEMPFILE"; then
  5685. mysql -u root --password=$MYSQL_ROOT_PASSWORD $DATABASE -o < /var/backups/${DATABASE}_daily.sql
  5686. # Send a warning email
  5687. echo "$DATABASE database corruption could not be repaired. Restored from backup." | mail -s "Freedombone database maintenance" $EMAIL
  5688. rm -f $TEMPFILE
  5689. exit 1
  5690. fi
  5691. rm -f $TEMPFILE
  5692. exit 0
  5693. #+END_SRC
  5694. Save and exit.
  5695. #+BEGIN_SRC: bash
  5696. chmod 600 /usr/bin/repairdatabase
  5697. editor /etc/cron.hourly/repair
  5698. #+END_SRC
  5699. Add the following. If you're using Red Matrix then uncomment that line.
  5700. #+BEGIN_SRC: bash
  5701. #!/bin/bash
  5702. repairdatabase friendica
  5703. #repairdatabase redmatrix
  5704. repairdatabase roundcubemail
  5705. #+END_SRC
  5706. Save and exit.
  5707. #+BEGIN_SRC: bash
  5708. chmod +x /etc/cron.hourly/repair
  5709. #+END_SRC
  5710. Also to keep maintenance to the minimum we need to automatically repair the databases when the system initially boots after a power cycle. So if there's an electrical power outage and the session table gets corrupted then you don't need to be concerned with repairing it manually.
  5711. #+BEGIN_SRC: bash
  5712. editor /usr/bin/runinitialrepair
  5713. #+END_SRC
  5714. Add the following:
  5715. #+BEGIN_SRC: bash
  5716. #!/bin/bash
  5717. sleep 180
  5718. /etc/cron.hourly/repair > /var/log/initialrepair.log
  5719. exit 0
  5720. #+END_SRC
  5721. Save and exit.
  5722. #+BEGIN_SRC: bash
  5723. chmod +x /usr/bin/runinitialrepair
  5724. editor /etc/init.d/initialrepair
  5725. #+END_SRC
  5726. Add the following:
  5727. #+BEGIN_SRC: bash
  5728. #!/bin/bash
  5729. # /etc/init.d/initialrepair
  5730. ### BEGIN INIT INFO
  5731. # Provides: initialrepair
  5732. # Required-Start: $remote_fs $syslog
  5733. # Required-Stop: $remote_fs $syslog
  5734. # Default-Start: 2 3 4 5
  5735. # Default-Stop: 0 1 6
  5736. # Short-Description: mysql database repair on boot
  5737. # Description: Repairs mysql databases at startup
  5738. ### END INIT INFO
  5739. # Author: Bob Mottram <bob@robotics.uk.to>
  5740. #Settings
  5741. SERVICE='initialrepair'
  5742. INVOCATION='/usr/bin/runinitialrepair'
  5743. PATH='/usr/local/sbin:/usr/local/bin:/usr/bin:/sbin:/usr/sbin:/bin'
  5744. initialrepair_start() {
  5745. echo "Starting $SERVICE..."
  5746. su --command "screen -h 1024 -dmS ${SERVICE} ${INVOCATION}" root
  5747. }
  5748. initialrepair_stop() {
  5749. echo "Stopping $SERVICE"
  5750. su --command "screen -p 0 -S ${SERVICE} -X stuff "'^C'"" root
  5751. }
  5752. #Start-Stop here
  5753. case "$1" in
  5754. start)
  5755. initialrepair_start
  5756. ;;
  5757. stop)
  5758. initialrepair_stop
  5759. ;;
  5760. restart)
  5761. initialrepair_stop
  5762. initialrepair_start
  5763. ;;
  5764. *)
  5765. echo "Usage: $0 {start|stop|restart}"
  5766. exit 1
  5767. ;;
  5768. esac
  5769. exit 0
  5770. #+END_SRC
  5771. Save and exit.
  5772. #+BEGIN_SRC: bash
  5773. chmod +x /etc/init.d/initialrepair
  5774. update-rc.d initialrepair defaults
  5775. service initialrepair start
  5776. #+END_SRC
  5777. ** Install Tripwire
  5778. #+BEGIN_VERSE
  5779. /...by the time you get done with all of that, we have a freedom box/
  5780. -- Eben Moglen
  5781. #+END_VERSE
  5782. Tripwire will try to detect any intrusions into your system. It's a good idea to install it after you have installed all of the other programs which you intend to use.
  5783. #+BEGIN_SRC: bash
  5784. apt-get install tripwire
  5785. export HOSTNAME=mydomainname.com
  5786. cd /etc/tripwire
  5787. cp arm-local.key $HOSTNAME-local.key
  5788. cp site.key $HOSTNAME-site.key
  5789. tripwire --init
  5790. tripwire --update-policy --secure-mode low /etc/tripwire/twpol.txt
  5791. tripwire --check --interactive
  5792. #+END_SRC
  5793. you will be asked for two passphrases ("site" and "local"). Make a note of these.
  5794. Turn off reporting of changes to system logs.
  5795. #+BEGIN_SRC: bash
  5796. editor /etc/tripwire/twcfg.txt
  5797. #+END_SRC
  5798. Set *SYSLOGREPORTING* to false and comment out the line, then save and exit.
  5799. #+BEGIN_SRC: bash
  5800. editor /etc/tripwire/twpol.txt
  5801. #+END_SRC
  5802. Edit the "Root config files" section so that it looks like this:
  5803. #+BEGIN_SRC: bash
  5804. # These files change the behavior of the root account
  5805. (
  5806. rulename = "Root config files",
  5807. severity = 100
  5808. )
  5809. {
  5810. /root -> $(SEC_CRIT) ; # Catch all additions to /root
  5811. /root/.bashrc -> $(SEC_CONFIG) ;
  5812. /root/.bash_history -> $(SEC_CONFIG) ;
  5813. }
  5814. #+END_SRC
  5815. Then save and exit.
  5816. #+BEGIN_SRC: bash
  5817. editor /usr/bin/reset-tripwire
  5818. #+END_SRC
  5819. Add the following:
  5820. #+BEGIN_SRC: bash
  5821. #!/bin/sh
  5822. tripwire --update-policy --secure-mode low /etc/tripwire/twpol.txt
  5823. #+END_SRC
  5824. Save and exit.
  5825. #+BEGIN_SRC: bash
  5826. chmod +x /usr/bin/reset-tripwire
  5827. #+END_SRC
  5828. If you subsequently install any more packages or make configuration changes then update the policy again with:
  5829. #+BEGIN_SRC: bash
  5830. reset-tripwire
  5831. #+END_SRC
  5832. Also, to look for any rootkits.
  5833. #+BEGIN_SRC: bash
  5834. apt-get install rkhunter
  5835. #+END_SRC
  5836. * Router/Firewall ports
  5837. The following ports on your internet router/firewall should be forwarded to the BBB.
  5838. | Protocol | Port/s |
  5839. |---------------+------------|
  5840. | Gopher | 70 |
  5841. | HTTP | 80 |
  5842. | HTTPS | 443 |
  5843. | IMAP | 143 |
  5844. | IRC | 6665..6669 |
  5845. | IRC SSL | 6697 |
  5846. | SIP | 5060..5061 |
  5847. | SMTP | 25,587 |
  5848. | SMTPS | 465 |
  5849. | SSH | 22 |
  5850. | XMPP | 5222..5223 |
  5851. | XMPP (server) | 5269 |
  5852. | XMPP (BOSH) | 5280..5281 |
  5853. | Bitmessage | 8444 |
  5854. | Subsonic | 4040 |
  5855. * Hints and Tips
  5856. ** Example configurations
  5857. *** Software sources
  5858. If you get errors when running *apt-get update* then you may need to check your repositories list. Here are examples of repositories within */etc/apt/sources.list*
  5859. **** Beaglebone Black
  5860. #+BEGIN_SRC: bash
  5861. deb http://ftp.us.debian.org/debian/ jessie main contrib
  5862. deb-src http://ftp.us.debian.org/debian/ jessie main contrib
  5863. deb http://ftp.us.debian.org/debian/ jessie-updates main contrib
  5864. deb-src http://ftp.us.debian.org/debian/ jessie-updates main contrib
  5865. #Kernel source: https://github.com/RobertCNelson/linux-stable-rcn-ee
  5866. deb [arch=armhf] http://repos.rcn-ee.net/debian/ jessie main
  5867. deb http://ftp.us.debian.org/debian jessie-backports main
  5868. #+END_SRC
  5869. **** Cubieboard
  5870. #+BEGIN_SRC: bash
  5871. deb http://ftp.us.debian.org/debian/ wheezy main contrib
  5872. deb-src http://ftp.us.debian.org/debian/ wheezy main contrib
  5873. deb http://ftp.us.debian.org/debian/ wheezy-updates main contrib
  5874. deb-src http://ftp.us.debian.org/debian/ wheezy-updates main contrib
  5875. deb http://security.debian.org/ wheezy/updates main contrib
  5876. deb-src http://security.debian.org/ wheezy/updates main contrib
  5877. deb http://ftp.us.debian.org/debian wheezy-backports main contrib
  5878. deb http://mirrors.sohu.com/debian/ wheezy main contrib
  5879. deb-src http://mirrors.sohu.com/debian/ wheezy main contrib
  5880. deb http://packages.cubian.org/ wheezy main
  5881. deb http://repo.ajenti.org/debian main main debian
  5882. #+END_SRC
  5883. *** Emacs setup
  5884. An example Emacs configuration file. This should be saved to */home/myusername/.emacs* and */root/.emacs*
  5885. #+BEGIN_SRC: bash
  5886. (add-to-list 'load-path "~/.emacs.d/")
  5887. ;; ===== Remove trailing whitepace ======================================
  5888. (add-hook 'before-save-hook 'delete-trailing-whitespace)
  5889. ;; ===== Press CTRL-L to go to a line number ============================
  5890. (global-set-key "\C-l" 'goto-line)
  5891. ;; ===== Show line numbers ==============================================
  5892. (add-hook 'find-file-hook (lambda () (linum-mode 1)))
  5893. ;; ===== Enable line wrapping in org-mode ===============================
  5894. (add-hook 'org-mode-hook
  5895. '(lambda ()
  5896. (visual-line-mode 1)))
  5897. ;; ===== Enable shift select in org mode ================================
  5898. (setq org-support-shift-select t)
  5899. ;; ===== Set standard indent to 4 spaces ================================
  5900. (setq standard-indent 4)
  5901. (setq-default tab-width 4)
  5902. (setq c-basic-offset 4)
  5903. ;; ===== Support Wheel Mouse Scrolling =================================
  5904. (mouse-wheel-mode t)
  5905. ;; ===== Place Backup Files in Specific Directory ======================
  5906. (setq make-backup-files t)
  5907. (setq version-control t)
  5908. (setq backup-directory-alist (quote ((".*" . "~/.emacs_backups/"))))
  5909. ;; ===== Make Text mode the default mode for new buffers ===============
  5910. (setq default-major-mode 'text-mode)
  5911. ;; ===== Line length ===================================================
  5912. (setq-default fill-column 72)
  5913. ;; ===== Enable Line and Column Numbering ==============================
  5914. (line-number-mode 1)
  5915. (column-number-mode 1)
  5916. ;; ===== Turn on Auto Fill mode automatically in all modes =============
  5917. ;; Auto-fill-mode the the automatic wrapping of lines and insertion of
  5918. ;; newlines when the cursor goes over the column limit.
  5919. ;; This should actually turn on auto-fill-mode by default in all major
  5920. ;; modes. The other way to do this is to turn on the fill for specific
  5921. ;; modes via hooks.
  5922. (setq auto-fill-mode 1)
  5923. ;; ===== Enable GPG encryption ========================================
  5924. (require 'epa)
  5925. (epa-file-enable)
  5926. #+END_SRC
  5927. *** Boot (uEnv.txt)
  5928. An example of the uEnv.txt file within the BOOT partition on the microSD card of the BBB.
  5929. #+BEGIN_SRC: bash
  5930. ##These are needed to be compliant with Debian 2014-05-14 u-boot.
  5931. loadximage=load mmc 0:2 ${loadaddr} /boot/vmlinuz-${uname_r}
  5932. loadxfdt=load mmc 0:2 ${fdtaddr} /boot/dtbs/${uname_r}/${fdtfile}
  5933. loadxrd=load mmc 0:2 ${rdaddr} /boot/initrd.img-${uname_r}; setenv rdsize ${filesize}
  5934. loaduEnvtxt=load mmc 0:2 ${loadaddr} /boot/uEnv.txt ; env import -t ${loadaddr} ${filesize};
  5935. loadall=run loaduEnvtxt; run loadximage; run loadxrd; run loadxfdt;
  5936. mmcargs=setenv bootargs console=tty0 console=${console} ${optargs} ${cape_disable} ${cape_enable} root=${mmcroot} rootfstype=${mmcrootfstype} ${cmdline}
  5937. uenvcmd=run loadall; run mmcargs; bootz ${loadaddr} ${rdaddr}:${rdsize} ${fdtaddr};
  5938. #+END_SRC
  5939. ** Messaging security
  5940. If you're connected to other friends via Friendica then the preferred way to send private messages is via Friendica's built-in messaging system. This is a lot more convenient than using GPG with ordinary email and yet still provides a similar level of protection from unwarranted interception.
  5941. ** Moving Domains
  5942. If you're moving servers and using a different domain name or path then you can search and replace URLs within files in the following way:
  5943. #+BEGIN_SRC: bash
  5944. find /var/www/mynewdomain/htdocs -type f -exec sed -i 's@myolddomain@mynewdomain@g' {} \;
  5945. #+END_SRC
  5946. If you're moving the blog to a new domain then you will need to delete the lock file:
  5947. #+BEGIN_SRC: bash
  5948. rm /var/www/myblogdomainname.com/htdocs/fp-content/%%setup.lock
  5949. #+END_SRC
  5950. Then visit your blog and reinstall it. Your existing content will be unaffected but you will need to delete the welcome post which gets added and also re-select your chosen theme.
  5951. If you need to import blog posts from another blog then copy the *fp-content/content* directory from the old blog to the new blog, then within the admin panel select *maintain* and *rebuild index*.
  5952. ** MySql foo
  5953. *** Reset the root password
  5954. To reset the root password, or if mysql forgets its root password.
  5955. #+BEGIN_SRC: bash
  5956. /etc/init.d/mysql stop
  5957. mysqld_safe --skip-grant-tables &
  5958. mysql -u root
  5959. use mysql;
  5960. update user set password=PASSWORD("mynewpassword") where User='root';
  5961. flush privileges;
  5962. quit
  5963. /etc/init.d/mysql stop
  5964. /etc/init.d/mysql start
  5965. #+END_SRC
  5966. *** Repair and optimize databases
  5967. To check, repair and optimize the databases.
  5968. #+BEGIN_SRC: bash
  5969. mysqlcheck -c -u root -p --all-databases
  5970. mysqlcheck -u root -p --auto-repair --all-databases
  5971. mysqlcheck -u root -p -o --all-databases
  5972. #+END_SRC
  5973. *** Backup all databases
  5974. To back up all mysql databases:
  5975. #+BEGIN_SRC: bash
  5976. mysqldump -u root -p --all-databases --events > /var/backups/databasebackup.sql
  5977. #+END_SRC
  5978. *** Restoring a particular mysql database
  5979. To restore yesterday's friendica backup:
  5980. #+BEGIN_SRC: bash
  5981. mysql -u root -p friendica -o < /var/backups/friendica_daily.sql
  5982. #+END_SRC
  5983. To restore the webmail database:
  5984. #+BEGIN_SRC: bash
  5985. mysql -u root -p roundcubemail -o < /var/backups/roundcubemail_daily.sql
  5986. #+END_SRC
  5987. To restore yesterday's Red Matrix backup:
  5988. #+BEGIN_SRC: bash
  5989. mysql -u root -p redmatrix -o < /var/backups/redmatrix_daily.sql
  5990. #+END_SRC
  5991. *** Removing and reinstalling mysql server
  5992. Sometimes the mysql database may get completely messed up, and running /service mysql start/ may always fail with nothing reported in the logs. So if you manage to get into that unfortinate situation then you can fully remove mysql and reinstall it as follows:
  5993. #+BEGIN_SRC: bash
  5994. ps aux | grep mysql
  5995. #+END_SRC
  5996. and use /kill -9 <pid>/ to kill all mysql processes.
  5997. #+BEGIN_SRC: bash
  5998. apt-get remove --purge mysql\*
  5999. rm -rf /etc/mysql
  6000. rm -rf /var/lib/mysql
  6001. apt-get clean
  6002. updatedb
  6003. #+END_SRC
  6004. Reinstall mysql:
  6005. #+BEGIN_SRC: bash
  6006. apt-get install mysql-server php5-common php5-cli php5-curl php5-gd php5-mysql php5-mcrypt php5-fpm php5-cgi php-apc
  6007. #+END_SRC
  6008. Then to recreate the Friendica and webmail databases:
  6009. #+BEGIN_SRC: bash
  6010. mysql -p
  6011. create database friendica;
  6012. CREATE USER 'friendicaadmin'@'localhost' IDENTIFIED BY 'myfriendicapassword';
  6013. GRANT ALL PRIVILEGES ON friendica.* TO 'friendicaadmin'@'localhost';
  6014. create database roundcubemail;
  6015. CREATE USER 'roundcube'@'localhost' IDENTIFIED BY 'roundcubepassword';
  6016. GRANT ALL PRIVILEGES ON roundcubemail.* TO 'roundcube'@'localhost';
  6017. quit
  6018. mysql -u root -p friendica -o < /var/backups/friendica_daily.sql
  6019. mysql -u root -p roundcubemail -o < /var/backups/roundcubemail_daily.sql
  6020. #+END_SRC
  6021. And if you previously had Red Matrix installed:
  6022. #+BEGIN_SRC: bash
  6023. mysql -p
  6024. create database redmatrix;
  6025. CREATE USER 'redmatrixadmin'@'localhost' IDENTIFIED BY 'myredmatrixpassword';
  6026. GRANT ALL PRIVILEGES ON redmatrix.* TO 'redmatrixadmin'@'localhost';
  6027. quit
  6028. mysql -u root -p redmatrix -o < /var/backups/redmatrix_daily.sql
  6029. #+END_SRC
  6030. Since IMAP seems entangled with mysql it may also be necessary to reinstall Exim and Dovecot.
  6031. #+BEGIN_SRC: bash
  6032. apt-get remove --purge exim4\*
  6033. #+END_SRC
  6034. Then follow the instructions in [[Install Email]], [[Spam filtering]] and [[Install Dovecot]].
  6035. ** Regenerating SSL certificates
  6036. If a security vulnerability arrises which requires you to regenerate your SSL certificates, such as [[http://filippo.io/Heartbleed]["heartbleed"]], then this can be done as follows:
  6037. Obtain the latest updates:
  6038. #+BEGIN_SRC: bash
  6039. apt-get update
  6040. apt-get upgrade
  6041. #+END_SRC
  6042. Run *makecert <domain>* for each of your sites.
  6043. Recreate the XMPP certificate:
  6044. #+BEGIN_SRC: bash
  6045. openssl genrsa -out /etc/ssl/private/xmpp.key 4096
  6046. openssl req -new -x509 -key /etc/ssl/private/xmpp.key -out /etc/ssl/certs/xmpp.crt -days 3650
  6047. chmod 600 /etc/ssl/private/xmpp.key
  6048. chmod 600 /etc/ssl/certs/xmpp.crt
  6049. chown prosody:prosody /etc/ssl/private/xmpp.key
  6050. chown prosody:prosody /etc/ssl/certs/xmpp.crt
  6051. #+END_SRC
  6052. And regenerate the IRC server keys:
  6053. #+BEGIN_SRC: bash
  6054. openssl genrsa -out /home/ircserver/ircd/ssl/ircd.key 4096
  6055. openssl req -new -x509 -key /home/ircserver/ircd/ssl/ircd.key -out /home/ircserver/ircd/ssl/ircd.pem -days 3650
  6056. openssl dhparam -out /home/ircserver/ircd/ssl/dhparam.pem 1024
  6057. #+END_SRC
  6058. This will take a few minutes to gather entropy.
  6059. #+BEGIN_SRC: bash
  6060. chmod 600 /home/ircserver/ircd/ssl/ircd.key
  6061. chmod 600 /home/ircserver/ircd/ssl/ircd.pem
  6062. chmod 600 /home/ircserver/ircd/ssl/dhparam.pem
  6063. chown -R ircserver:ircserver /home/ircserver/ircd/ssl
  6064. #+END_SRC
  6065. Regenerate email certificate.
  6066. #+BEGIN_SRC: bash
  6067. exim-gencert --force
  6068. #+END_SRC
  6069. As an added precaution you may wish to regenerate your ssh host keys:
  6070. #+BEGIN_SRC: bash
  6071. rm /etc/ssh/ssh_host_*
  6072. dpkg-reconfigure openssh-server
  6073. #+END_SRC
  6074. Then reboot the server with:
  6075. #+BEGIN_SRC: bash
  6076. reboot
  6077. #+END_SRC
  6078. ** Example crontab file
  6079. This is an example of what your crontab file might look like, with the more frequently run tasks at the top. For the two most frequent tasks specific minutes within each hour are given and they're arranged to try to minimise the number of things running simultaneously.
  6080. #+BEGIN_SRC: bash
  6081. # /etc/crontab: system-wide crontab
  6082. # Unlike any other crontab you don't have to run the `crontab'
  6083. # command to install the new version when you edit this file
  6084. # and files in /etc/cron.d. These files also have username fields,
  6085. # that none of the other crontabs do.
  6086. SHELL=/bin/sh
  6087. PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
  6088. # m h dom mon dow user command
  6089. 10,20,30,40,50 * * * * root /usr/bin/timeout 120 /usr/bin/dynamicdns && /usr/bin/spamfilter myusername
  6090. 15,35,55 * * * * root cd /var/www/mydomainname/htdocs; /usr/bin/timeout 240 /usr/bin/php include/poller.php
  6091. 17 * * * * root cd / && run-parts --report /etc/cron.hourly
  6092. 25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
  6093. 47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
  6094. 52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
  6095. #+END_SRC
  6096. ** Using your own domain
  6097. Suppose that you have bought a domain name (rather than using a free subdomain on freedns) and you want to use that instead.
  6098. Remove any existing nameservers for your domain (or select "custom" nameservers), then add:
  6099. #+BEGIN_SRC: bash
  6100. NS1.AFRAID.ORG
  6101. NS2.AFRAID.ORG
  6102. NS3.AFRAID.ORG
  6103. NS4.AFRAID.ORG
  6104. #+END_SRC
  6105. It might take a few minutes for the above change to take effect. Within freedns click on "Domains" and add your domains (this might only be available to paid members). Make sure that they're marked as "private".
  6106. Select "Subdomains" from the menu on the left then select the MX entry for your domain and change the destination to *10:mydomainname* rather than *10:mail.mydomainname*.
  6107. To route email to one of your freedns domains:
  6108. #+BEGIN_SRC: bash
  6109. editor /etc/mailname
  6110. #+END_SRC
  6111. Add any extra domains which you own, then save and exit.
  6112. #+BEGIN_SRC: bash
  6113. editor /etc/exim4/update-exim4.conf.conf
  6114. #+END_SRC
  6115. Within dc_other_hostnames add your extra domain names, separated by a colon ':' character.
  6116. Save and exit, then restart exim.
  6117. #+BEGIN_SRC: bash
  6118. update-exim4.conf.template -r
  6119. update-exim4.conf
  6120. service exim4 restart
  6121. #+END_SRC
  6122. You should now be able to send an email from /postmaster@mynewdomainname/ and it should arrive in your inbox.
  6123. ** Obtaining an "official" SSL certificate
  6124. You can obtain a free "official" (as in recognised by default by web browsers) SSL certificate from [[https://www.startssl.com/][StartSSL]]. You will first need to have bought a domain name, since it's not possible to obtain one for a freedns subdomain, so see [[Using your own domain]] for details of how to do that. You should also have tested that you can send email to the domain and receive it on the BBB (via Mutt or any other email client).
  6125. When creating a SSL certificate it's important that the private key (the private component of the public/private pair in [[https://en.wikipedia.org/wiki/Public-key_cryptography][public key cryptography]]) be generated on the BBB /and remain there/. Don't generate the private key via the StartSSL certificate wizard because this means that potentially they may retain a copy of it which could then be exfiltrated either via [[https://en.wikipedia.org/wiki/Lavabit][Lavabit]] style methodology, "implants", compromised sysadmins or other "side channel" methods. So that the private key isn't broadcast on the internet we can instead generate a certificate request, which is really just a request for authorisation of a public key.
  6126. Firstly you should have an Apache web site configutaion ready to go. See [[Setting up a web site]] for details.
  6127. Within StartSSL under the validations wizard validate your domain, which means sending an email to it and confirming a code.
  6128. Now we can generate the certificate request as follows.
  6129. #+BEGIN_SRC: bash
  6130. export HOSTNAME=mydomainname.com
  6131. openssl genrsa -out /etc/ssl/private/$HOSTNAME.key 2048
  6132. chown root:ssl-cert /etc/ssl/private/$HOSTNAME.key
  6133. chmod 440 /etc/ssl/private/$HOSTNAME.key
  6134. mkdir /etc/ssl/requests
  6135. #+END_SRC
  6136. Now make a certificate request as follows. You should copy and paste the whole of this, not just line by line.
  6137. #+BEGIN_SRC: bash
  6138. openssl req -new -key /etc/ssl/private/$HOSTNAME.key -out /etc/ssl/requests/$HOSTNAME.csr
  6139. #+END_SRC
  6140. For the email address it's a good idea to use postmaster@mydomainname.
  6141. Use a random 20 character password, and keep a note of it. We'll remove this later.
  6142. View the request with:
  6143. #+BEGIN_SRC: bash
  6144. cat /etc/ssl/requests/$HOSTNAME.csr
  6145. #+END_SRC
  6146. You can then click on "skip" within the StartSSL certificates wizard and copy and paste the encrypted request into the text entry box. A confirmation will be emailed back to you normally within a few hours.
  6147. Log into your StartSSL account and select *Retrieve Certificate* from the *Tool Box* tab. Copy the text.
  6148. #+BEGIN_SRC: bash
  6149. editor /etc/ssl/certs/$HOSTNAME.crt
  6150. #+END_SRC
  6151. Paste the public key, then save and exit. Then on the BBB.
  6152. #+BEGIN_SRC: bash
  6153. mkdir /etc/ssl/roots
  6154. mkdir /etc/ssl/chains
  6155. wget "http://www.startssl.com/certs/ca.pem" --output-document="/etc/ssl/roots/startssl-root.ca"
  6156. wget "http://www.startssl.com/certs/sub.class1.server.ca.pem" --output-document="/etc/ssl/chains/startssl-sub.class1.server.ca.pem"
  6157. wget "http://www.startssl.com/certs/sub.class2.server.ca.pem" --output-document="/etc/ssl/chains/startssl-sub.class2.server.ca.pem"
  6158. wget "http://www.startssl.com/certs/sub.class3.server.ca.pem" --output-document="/etc/ssl/chains/startssl-sub.class3.server.ca.pem"
  6159. ln -s "/etc/ssl/roots/startssl-root.ca" "/etc/ssl/roots/$HOSTNAME-root.ca"
  6160. ln -s "/etc/ssl/chains/startssl-sub.class1.server.ca.pem" "/etc/ssl/chains/$HOSTNAME.ca"
  6161. cp "/etc/ssl/certs/$HOSTNAME.crt" "/etc/ssl/certs/$HOSTNAME.crt+chain+root"
  6162. test -e "/etc/ssl/chains/$HOSTNAME.ca" && cat "/etc/ssl/chains/$HOSTNAME.ca" >> "/etc/ssl/certs/$HOSTNAME.crt+chain+root"
  6163. test -e "/etc/ssl/roots/$HOSTNAME-root.ca" && cat "/etc/ssl/roots/$HOSTNAME-root.ca" >> "/etc/ssl/certs/$HOSTNAME.crt+chain+root"
  6164. #+END_SRC
  6165. To avoid any possibility of the certificates being accidentally overwritten by self-signed ones at a later date you can create backups.
  6166. #+BEGIN_SRC: bash
  6167. mkdir /etc/ssl/backups
  6168. mkdir /etc/ssl/backups/certs
  6169. mkdir /etc/ssl/backups/private
  6170. cp /etc/ssl/certs/$HOSTNAME* /etc/ssl/backups/certs/
  6171. cp /etc/ssl/private/$HOSTNAME* /etc/ssl/backups/private/
  6172. chmod -R 400 /etc/ssl/backups/certs/*
  6173. chmod -R 400 /etc/ssl/backups/private/*
  6174. #+END_SRC
  6175. Remove the certificate password, so if the server is rebooted then it won't wait indefinitely for a non-existant keyboard user to type in a password.
  6176. #+BEGIN_SRC: bash
  6177. openssl rsa -in /etc/ssl/private/$HOSTNAME.key -out /etc/ssl/private/$HOSTNAME.new.key
  6178. cp /etc/ssl/private/$HOSTNAME.new.key /etc/ssl/private/$HOSTNAME.key
  6179. shred -zu /etc/ssl/private/$HOSTNAME.new.key
  6180. #+END_SRC
  6181. Create a bundled certificate which joins the certificate and chain file together.
  6182. #+BEGIN_SRC: bash
  6183. cat /etc/ssl/certs/$HOSTNAME.crt /etc/ssl/chains/startssl-sub.class1.server.ca.pem > /etc/ssl/certs/$HOSTNAME.bundle.crt
  6184. #+END_SRC
  6185. Edit your configuration file.
  6186. #+BEGIN_SRC: bash
  6187. editor /etc/nginx/sites-available/$HOSTNAME
  6188. #+END_SRC
  6189. Add the following to the section which starts with *listen 443*
  6190. #+BEGIN_SRC: bash
  6191. ssl_certificate /etc/ssl/certs/mydomainname.com_bundle.crt;
  6192. #+END_SRC
  6193. Save and exit, then restart the web server.
  6194. #+BEGIN_SRC: bash
  6195. service nginx restart
  6196. #+END_SRC
  6197. Now visit your web site at https://mydomainname.com and you should notice that there is no certificate warning displayed. You will now be able to install systems which don't allow the use of self-signed certificates, such as [[https://redmatrix.me/&JS=1][Red Matrix]].
  6198. * Deprecated
  6199. The following items have been deprecated until such time as a successful installation is achieved.
  6200. ** Gitlab
  6201. Install some dependencies:
  6202. #+BEGIN_SRC: bash
  6203. apt-get update -y
  6204. apt-get upgrade -y
  6205. apt-get install sudo -y
  6206. apt-get install -y build-essential zlib1g-dev libyaml-dev libssl-dev libgdbm-dev libreadline-dev libncurses5-dev libffi-dev curl openssh-server redis-server checkinstall libxml2-dev libxslt-dev libcurl4-openssl-dev libicu-dev logrotate git-core
  6207. #+END_SRC
  6208. Install bundler
  6209. #+BEGIN_SRC: bash
  6210. gem install bundler --no-ri --no-rdoc
  6211. #+END_SRC
  6212. Create a user for running Gitlab.
  6213. #+BEGIN_SRC: bash
  6214. adduser --disabled-login --gecos 'GitLab' git
  6215. #+END_SRC
  6216. Install mysql (it may already be installed).
  6217. #+BEGIN_SRC: bash
  6218. apt-get install -y mysql-server mysql-client libmysqlclient-dev
  6219. mysql_secure_installation
  6220. mysql -u root -p
  6221. #+END_SRC
  6222. Enter the following commands, substituting /gitlabpassword/ with a password to be used for the Gitlab installation.
  6223. #+BEGIN_SRC: bash
  6224. CREATE USER 'git'@'localhost' IDENTIFIED BY 'gitlabpassword';
  6225. SET storage_engine=INNODB;
  6226. CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
  6227. GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'git'@'localhost';
  6228. quit
  6229. #+END_SRC
  6230. Obtain the code and install it.
  6231. #+BEGIN_SRC: bash
  6232. cd /home/git
  6233. sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 6-8-stable gitlab
  6234. cd /home/git/gitlab
  6235. sudo -u git -H cp /home/git/gitlab/config/gitlab.yml.example /home/git/gitlab/config/gitlab.yml
  6236. sudo -u git -H editor /home/git/gitlab/config/gitlab.yml
  6237. #+END_SRC
  6238. Set /host/ to your gitlab domain name, /port/ to 443 and /https/ to true, then save and exit.
  6239. #+BEGIN_SRC: bash
  6240. chown -R git /home/git/gitlab/log/
  6241. chown -R git /home/git/gitlab/tmp/
  6242. chmod -R u+rwX /home/git/gitlab/log/
  6243. chmod -R u+rwX /home/git/gitlab/tmp/
  6244. sudo -u git -H mkdir /home/git/gitlab-satellites
  6245. chmod u+rwx,g+rx,o-rwx /home/git/gitlab-satellites
  6246. chmod -R u+rwX /home/git/gitlab/tmp/pids/
  6247. chmod -R u+rwX /home/git/gitlab/tmp/sockets/
  6248. chmod -R u+rwX /home/git/gitlab/public/uploads
  6249. sudo -u git -H cp /home/git/gitlab/config/unicorn.rb.example /home/git/gitlab/config/unicorn.rb
  6250. #sudo -u git -H editor /home/git/gitlab/config/unicorn.rb
  6251. sudo -u git -H cp /home/git/gitlab/config/initializers/rack_attack.rb.example /home/git/gitlab/config/initializers/rack_attack.rb
  6252. sudo -u git -H git config --global user.name "GitLab"
  6253. sudo -u git -H git config --global user.email "gitlab@localhost"
  6254. sudo -u git -H git config --global core.autocrlf input
  6255. sudo -u git cp /home/git/gitlab/config/database.yml.mysql /home/git/gitlab/config/database.yml
  6256. sudo -u git -H chmod o-rwx /home/git/gitlab/config/database.yml
  6257. sudo -u git -H bundle install --deployment --without development test postgres aws
  6258. #+END_SRC
  6259. Fails here with:
  6260. /Could not find libv8-3.16.14.3 in any of the sources/
  6261. /Run `bundle install` to install missing gems./
  6262. #+BEGIN_SRC: bash
  6263. sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production
  6264. sudo -u git -H bundle exec rake gitlab:shell:install[v1.9.3] REDIS_URL=redis://localhost:6379
  6265. sudo -u git -H editor /home/git/gitlab-shell/config.yml
  6266. cp lib/support/init.d/gitlab /etc/init.d/gitlab
  6267. update-rc.d gitlab defaults 21
  6268. cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab
  6269. sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production
  6270. sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production
  6271. service gitlab start
  6272. #+END_SRC
  6273. Set up the Apache configuration.
  6274. #+BEGIN_SRC: bash
  6275. cp lib/support/apache/gitlab /etc/apache2/sites-available/mygitlabdomain
  6276. editor /etc/apache2/sites-available/mygitlabdomain
  6277. #+END_SRC
  6278. Set your domain name and email accordingly.
  6279. #+BEGIN_SRC: bash
  6280. a2ensite mygitlabdomain
  6281. #+END_SRC
  6282. ** Monkeysphere
  6283. #+BEGIN_SRC: bash
  6284. aptitude install monkeysphere
  6285. aptitude install msva-perl
  6286. aptitude install xul-ext-monkeysphere
  6287. export HOSTNAME=mydomainname.com
  6288. monkeysphere-host import-key /etc/ssh/ssh_host_rsa_key ssh://$HOSTNAME
  6289. monkeysphere-host publish-key
  6290. #+END_SRC
  6291. ** Diaspora
  6292. First install some dependencies:
  6293. #+BEGIN_SRC: bash
  6294. aptitude install build-essential libssl-dev libcurl4-openssl-dev libxml2-dev libxslt-dev imagemagick git-core redis-server curl libmysqlclient-dev libmagickwand-dev librtmp-dev libgnutls-dev libp11-kit-dev libp11-kit0 curl gawk libreadline6-dev libyaml-dev sqlite3 libgdbm-dev libffi-dev
  6295. #+END_SRC
  6296. If there is trouble with dependencies select 'n' then 'y' to the solution.
  6297. Create a diaspora user.
  6298. #+BEGIN_SRC: bash
  6299. adduser --disabled-login diaspora
  6300. su diaspora
  6301. cd ~/
  6302. curl -L dspr.tk/1t | bash
  6303. echo "[[ -s \"$HOME/.rvm/scripts/rvm\" ]] && source \"$HOME/.rvm/scripts/rvm\"" >> ~/.bashrc
  6304. . ~/.bashrc
  6305. rvm autolibs read-only
  6306. rvm install ruby-2.0.0-p481
  6307. git clone https://github.com/diaspora/diaspora.git
  6308. cd diaspora
  6309. #+END_SRC
  6310. Select 'y' to trust /home/diaspora/diaspora/.rvmrc
  6311. #+BEGIN_SRC: bash
  6312. cp config/diaspora.yml.example config/diaspora.yml
  6313. editor config/diaspora.yml
  6314. #+END_SRC
  6315. Set *url* to https://mydiasporadomainname.com/
  6316. Set *certificate_authorities* to */etc/ssl/certs/ca-certificates.crt*
  6317. Set *require_ssl* to *true*
  6318. Set *single_process_mode* to *false*
  6319. Set *port* to 3001
  6320. Set *rails_environment* to 'production'.
  6321. Set *pod_name* to the name of your pod.
  6322. Set *enable_registrations* to *true*.
  6323. Set *autofollow_on_join* to *false*
  6324. Under *captcha* set *enable* to *false*
  6325. Under *invitations* set *open* to *true*
  6326. Set *bitcoin_address* if you wish to accept donations.
  6327. Under *mail* set *enable* to *true*
  6328. Set *sender_address* to no-reply@mydiasporadomainname.com
  6329. Set *method* to *sendmail*
  6330. Set *exim_fix* to true.
  6331. Under *admins* set *account* to your username
  6332. Under *admins* set *podmin_email* to your email address
  6333. Save and exit.
  6334. #+BEGIN_SRC: bash
  6335. RAILS_ENV=production bundle install --without test development
  6336. #+END_SRC
  6337. This will take quite a while to install.
  6338. #+BEGIN_SRC: bash
  6339. RAILS_ENV=production bundle exec rake db:create db:schema:load
  6340. bundle exec rake assets:precompile
  6341. #+END_SRC
  6342. Alter the Apache configuration.
  6343. #+BEGIN_SRC: bash
  6344. exit
  6345. export HOSTNAME=mydiasporadomainname.com
  6346. editor /etc/apache2/sites-available/$HOSTNAME
  6347. #+END_SRC
  6348. Delete anything which already exists and add the following:
  6349. #+BEGIN_SRC: bash
  6350. <VirtualHost *:80>
  6351. ServerName mydiasporadomainname.com
  6352. ServerAlias www.mydiasporadomainname.com
  6353. RedirectPermanent / https://mydiasporadomainname.com/
  6354. </VirtualHost>
  6355. <VirtualHost *:443>
  6356. ServerName mydiasporadomainname.com
  6357. ServerAlias www.mydiasporadomainname.com
  6358. DocumentRoot /home/diaspora/diaspora/public
  6359. RewriteEngine On
  6360. RewriteCond %{HTTP_HOST} !^mydiasporadomainname\.com [NC]
  6361. RewriteRule ^/(.*)$ https://mydiasporadomainname\.com/$1 [L,R,QSA]
  6362. RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
  6363. RewriteRule ^/(.*)$ balancer://upstream%{REQUEST_URI} [P,QSA,L]
  6364. <Proxy balancer://upstream>
  6365. BalancerMember http://127.0.0.1:3001
  6366. </Proxy>
  6367. ProxyRequests Off
  6368. ProxyVia On
  6369. ProxyPreserveHost On
  6370. RequestHeader set X_FORWARDED_PROTO https
  6371. <Proxy *>
  6372. # Apache < 2.4
  6373. Order allow,deny
  6374. Allow from all
  6375. # Apache >= 2.4
  6376. #Require all granted
  6377. </Proxy>
  6378. <Directory /home/diaspora/diaspora/public>
  6379. Options -MultiViews
  6380. # Apache < 2.4
  6381. Allow from all
  6382. AllowOverride all
  6383. # Apache >= 2.4
  6384. #Require all granted
  6385. </Directory>
  6386. SSLEngine On
  6387. SSLCertificateFile /etc/ssl/certs/mydiasporadomainname.com.crt
  6388. SSLCertificateKeyFile /etc/ssl/private/mydiasporadomainname.com.key
  6389. # maybe not needed, need for example for startssl to point to a local
  6390. # copy of http://www.startssl.com/certs/sub.class1.server.ca.pem
  6391. SSLCertificateChainFile /etc/ssl/chains/startssl-sub.class1.server.ca.pem
  6392. # Based on https://wiki.mozilla.org/Security/Server_Side_TLS - consider as global configuration
  6393. SSLProtocol all -SSLv2
  6394. SSLCipherSuite ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:ECDHE-RSA-RC4-SHA:ECDHE-ECDSA-RC4-SHA:AES128:AES256:RC4-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!3DES:!MD5:!PSK
  6395. SSLHonorCipherOrder on
  6396. SSLCompression off
  6397. </VirtualHost>
  6398. #+END_SRC
  6399. Save and exit.
  6400. #+BEGIN_SRC: bash
  6401. editor /usr/bin/rundiaspora
  6402. #+END_SRC
  6403. Add the following.
  6404. #+BEGIN_SRC: bash
  6405. #!/bin/sh
  6406. USERNAME=diaspora
  6407. COMMAND="cd /home/$USERNAME/diaspora; /bin/sh /home/$USERNAME/diaspora/script/server > /home/$USERNAME/diaspora.log"
  6408. su -l $USERNAME -c '$COMMAND'
  6409. #+END_SRC
  6410. Save and exit.
  6411. Create an init script:
  6412. #+BEGIN_SRC: bash
  6413. chmod +x /usr/bin/rundiaspora
  6414. editor /etc/init.d/diaspora
  6415. #+END_SRC
  6416. Add the following.
  6417. #+BEGIN_SRC: bash
  6418. #!/bin/bash
  6419. # /etc/init.d/diaspora
  6420. ### BEGIN INIT INFO
  6421. # Provides: diaspora
  6422. # Required-Start: $remote_fs $syslog
  6423. # Required-Stop: $remote_fs $syslog
  6424. # Default-Start: 2 3 4 5
  6425. # Default-Stop: 0 1 6
  6426. # Short-Description: starts diaspora
  6427. # Description: Starts Diaspora.
  6428. ### END INIT INFO
  6429. # Author: Bob Mottram <bob@robotics.uk.to>
  6430. #Settings
  6431. SERVICE='diaspora'
  6432. HISTORY=1024
  6433. USERNAME='diaspora'
  6434. COMMAND="rundiaspora"
  6435. NICELEVEL=19 # from 0-19
  6436. INVOCATION="nice -n ${NICELEVEL} ${COMMAND}"
  6437. PATH='/usr/local/sbin:/usr/local/bin:/usr/bin:/sbin:/usr/sbin:/bin'
  6438. diaspora_start() {
  6439. echo -n $"Starting $SERVICE service"
  6440. screen -h ${HISTORY} -dmS ${SERVICE} ${INVOCATION}
  6441. # su --command "screen -h ${HISTORY} -dmS ${SERVICE} ${INVOCATION}" $USERNAME
  6442. # su -l $USERNAME -c "$COMMAND"
  6443. # RETVAL=$?
  6444. echo
  6445. }
  6446. diaspora_stop() {
  6447. echo -n $"Stopping $SERVICE service"
  6448. screen -p 0 -S ${SERVICE} -X stuff "'^C'"
  6449. # su --command "screen -p 0 -S ${SERVICE} -X stuff "'^C'"" $USERNAME
  6450. # su -l $USERNAME -c "/home/$USERNAME/diaspora/script/server"
  6451. # RETVAL=$?
  6452. echo
  6453. }
  6454. #Start-Stop here
  6455. case "$1" in
  6456. start)
  6457. diaspora_start
  6458. ;;
  6459. stop)
  6460. diaspora_stop
  6461. ;;
  6462. restart)
  6463. diaspora_stop
  6464. diaspora_start
  6465. ;;
  6466. *)
  6467. echo "Usage: $0 {start|stop|restart}"
  6468. exit 1
  6469. ;;
  6470. esac
  6471. exit 0
  6472. #+END_SRC
  6473. Save and exit.
  6474. #+BEGIN_SRC: bash
  6475. chmod +x /etc/init.d/diaspora
  6476. update-rc.d diaspora defaults
  6477. service diaspora start
  6478. #+END_SRC
  6479. Now enable the site:
  6480. #+BEGIN_SRC: bash
  6481. a2enmod ssl
  6482. a2enmod rewrite
  6483. a2enmod headers
  6484. a2enmod proxy
  6485. a2enmod proxy_connect
  6486. a2enmod proxy_http
  6487. a2enmod proxy_balancer
  6488. a2ensite $HOSTNAME
  6489. service apache2 restart
  6490. #+END_SRC
  6491. * Related projects
  6492. * [[https://arkos.io/][ArkOS]]
  6493. * [[https://freedomboxfoundation.org/][Freedombox]]
  6494. * [[https://github.com/JoshData/mailinabox][Mail-in-a-Box]]
  6495. * [[https://github.com/sandstorm-io/sandstorm][Sandstorm]]
  6496. * [[https://github.com/al3x/sovereign][Sovereign]]