beaglebone.txt 270KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349
  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", "guaranteed secure" or "NSA-proof" 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. ** Make SSL/TLS certificates
  1219. For email, web server and other services we will be using SSL/TLS certificates, so create a script which makes this easy to do with a single command.
  1220. #+BEGIN_SRC: bash
  1221. editor /usr/bin/makecert
  1222. #+END_SRC
  1223. Enter the following. You can change the country code and location if you wish, but that's not essential.
  1224. #+BEGIN_SRC: bash
  1225. #!/bin/bash
  1226. HOSTNAME=$1
  1227. COUNTRY_CODE="US"
  1228. AREA="Free Speech Zone"
  1229. LOCATION="Freedomville"
  1230. ORGANISATION="Freedombone"
  1231. UNIT="Freedombone Unit"
  1232. if ! which openssl > /dev/null ;then
  1233. echo "$0: openssl is not installed, exiting" 1>&2
  1234. exit 1
  1235. fi
  1236. openssl req \
  1237. -x509 -nodes -days 3650 \
  1238. -sha256 \
  1239. -subj "/O=$ORGANISATION/OU=$UNIT/C=$COUNTRY_CODE/ST=$AREA/L=$LOCATION/CN=$HOSTNAME" \
  1240. -newkey rsa:2048 \
  1241. -keyout /etc/ssl/private/$HOSTNAME.key \
  1242. -out /etc/ssl/certs/$HOSTNAME.crt
  1243. openssl dhparam -check -text -5 1024 -out /etc/ssl/certs/$HOSTNAME.dhparam
  1244. chmod 400 /etc/ssl/private/$HOSTNAME.key
  1245. chmod 640 /etc/ssl/certs/$HOSTNAME.crt
  1246. chmod 640 /etc/ssl/certs/$HOSTNAME.dhparam
  1247. /etc/init.d/nginx reload
  1248. # add the public certificate to a separate directory
  1249. # so that we can redistribute it easily
  1250. if [ ! -d /etc/ssl/mycerts ]; then
  1251. mkdir /etc/ssl/mycerts
  1252. fi
  1253. cp /etc/ssl/certs/$HOSTNAME.crt /etc/ssl/mycerts
  1254. # Create a bundle of your certificates
  1255. cat /etc/ssl/mycerts/*.crt > /etc/ssl/freedombone-bundle.crt
  1256. tar -czvf /etc/ssl/freedombone-certs.tar.gz /etc/ssl/mycerts/*.crt
  1257. #+END_SRC
  1258. Save and exit.
  1259. #+BEGIN_SRC: bash
  1260. chmod +x /usr/bin/makecert
  1261. #+END_SRC
  1262. ** Install Email
  1263. #+BEGIN_VERSE
  1264. /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/
  1265. -- Ladar Levison
  1266. #+END_VERSE
  1267. 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.
  1268. Exim4 seems much easier to install and configure than Postfix.
  1269. #+BEGIN_SRC: bash
  1270. service postfix stop
  1271. apt-get remove postfix
  1272. aptitude install exim4 sasl2-bin swaks libnet-ssleay-perl procmail
  1273. #+END_SRC
  1274. You will be prompted to remove postfix. Say yes and yes again.
  1275. #+BEGIN_SRC: bash
  1276. dpkg-reconfigure exim4-config
  1277. #+END_SRC
  1278. Settings as follows:
  1279. #+BEGIN_SRC: bash
  1280. internet site
  1281. System mail name: mydomainname.com
  1282. IP addresses to listen on: blank
  1283. Destinations: mydomainname.com (and any other domains that you own)
  1284. Domains to relay mail: blank
  1285. Smarthost Relay: 192.168.1.0/24 (the range of addresses on your LAN)
  1286. Dial on demand = no
  1287. Maildir format in home directory
  1288. Split configuration = no
  1289. Root and postmaster: root email
  1290. #+END_SRC
  1291. To test the installation:
  1292. #+BEGIN_SRC: bash
  1293. telnet 192.168.1.60 25
  1294. ehlo xxx
  1295. quit
  1296. #+END_SRC
  1297. #+BEGIN_SRC: bash
  1298. editor /etc/default/saslauthd
  1299. #+END_SRC
  1300. set START=yes then save and exit.
  1301. #+BEGIN_SRC: bash
  1302. /etc/init.d/saslauthd start
  1303. makecert exim
  1304. mv /etc/ssl/private/exim.key /etc/exim4
  1305. mv /etc/ssl/certs/exim.crt /etc/exim4
  1306. mv /etc/ssl/certs/exim.dhparam /etc/exim4
  1307. chown root:Debian-exim /etc/exim4/exim.key /etc/exim4/exim.crt /etc/exim4/exim.dhparam
  1308. chmod 640 /etc/exim4/exim.key /etc/exim4/exim.crt /etc/exim4/exim.dhparam
  1309. editor /etc/exim4/exim4.conf.template
  1310. #+END_SRC
  1311. Uncomment the section which begins with *login_saslauthd_server*
  1312. Search for the line *.ifdef MAIN_HARDCODE_PRIMARY_HOSTNAME* and above it insert the lines:
  1313. #+BEGIN_SRC: bash
  1314. MAIN_HARDCODE_PRIMARY_HOSTNAME = mydomainname.com
  1315. MAIN_TLS_ENABLE = true
  1316. #+END_SRC
  1317. Save and exit.
  1318. #+BEGIN_SRC: bash
  1319. editor /etc/default/exim4
  1320. change SMTPLISTENEROPTIONS to:
  1321. SMTPLISTENEROPTIONS='-oX 465:25:587 -oP /var/run/exim4/exim.pid'
  1322. #+END_SRC
  1323. save and exit
  1324. #+BEGIN_SRC: bash
  1325. editor /etc/exim4/exim4.conf.template
  1326. #+END_SRC
  1327. Under the section *main/03_exim4-config_tlsoptions* add the following:
  1328. #+BEGIN_SRC: bash
  1329. tls_on_connect_ports=465
  1330. #+END_SRC
  1331. save and exit
  1332. #+BEGIN_SRC: bash
  1333. adduser myusername sasl
  1334. addgroup Debian-exim sasl
  1335. /etc/init.d/exim4 restart
  1336. mkdir -m 700 /etc/skel/Maildir
  1337. mkdir -m 700 /etc/skel/Maildir/Sent
  1338. mkdir -m 700 /etc/skel/Maildir/Sent/tmp
  1339. mkdir -m 700 /etc/skel/Maildir/Sent/cur
  1340. mkdir -m 700 /etc/skel/Maildir/Sent/new
  1341. mkdir -m 700 /etc/skel/Maildir/.learn-spam
  1342. mkdir -m 700 /etc/skel/Maildir/.learn-spam/cur
  1343. mkdir -m 700 /etc/skel/Maildir/.learn-spam/new
  1344. mkdir -m 700 /etc/skel/Maildir/.learn-spam/tmp
  1345. mkdir -m 700 /etc/skel/Maildir/.learn-ham
  1346. mkdir -m 700 /etc/skel/Maildir/.learn-ham/cur
  1347. mkdir -m 700 /etc/skel/Maildir/.learn-ham/new
  1348. mkdir -m 700 /etc/skel/Maildir/.learn-ham/tmp
  1349. ln -s /etc/skel/Maildir/.learn-spam /etc/skel/Maildir/spam
  1350. ln -s /etc/skel/Maildir/.learn-ham /etc/skel/Maildir/ham
  1351. #+END_SRC
  1352. If you're starting from scratch and don't already have a /Maildir/ directory in your home directory, then create one as follows:
  1353. #+BEGIN_SRC: bash
  1354. export MYUSERNAME=myusername
  1355. mkdir -m 700 /home/$MYUSERNAME/Maildir
  1356. mkdir -m 700 /home/$MYUSERNAME/Maildir/cur
  1357. mkdir -m 700 /home/$MYUSERNAME/Maildir/tmp
  1358. mkdir -m 700 /home/$MYUSERNAME/Maildir/new
  1359. mkdir -m 700 /home/$MYUSERNAME/Maildir/Sent
  1360. mkdir -m 700 /home/$MYUSERNAME/Maildir/Sent/cur
  1361. mkdir -m 700 /home/$MYUSERNAME/Maildir/Sent/tmp
  1362. mkdir -m 700 /home/$MYUSERNAME/Maildir/Sent/new
  1363. mkdir -m 700 /home/$MYUSERNAME/Maildir/.learn-spam
  1364. mkdir -m 700 /home/$MYUSERNAME/Maildir/.learn-spam/cur
  1365. mkdir -m 700 /home/$MYUSERNAME/Maildir/.learn-spam/new
  1366. mkdir -m 700 /home/$MYUSERNAME/Maildir/.learn-spam/tmp
  1367. mkdir -m 700 /home/$MYUSERNAME/Maildir/.learn-ham
  1368. mkdir -m 700 /home/$MYUSERNAME/Maildir/.learn-ham/cur
  1369. mkdir -m 700 /home/$MYUSERNAME/Maildir/.learn-ham/new
  1370. mkdir -m 700 /home/$MYUSERNAME/Maildir/.learn-ham/tmp
  1371. ln -s /home/$MYUSERNAME/Maildir/.learn-spam /home/$MYUSERNAME/Maildir/spam
  1372. ln -s /home/$MYUSERNAME/Maildir/.learn-ham /home/$MYUSERNAME/Maildir/ham
  1373. chown -R $MYUSERNAME:$MYUSERNAME /home/$MYUSERNAME/Maildir
  1374. #+END_SRC
  1375. ** Spam filtering
  1376. #+BEGIN_SRC: bash
  1377. aptitude install spamassassin exim4-daemon-heavy
  1378. #+END_SRC
  1379. 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.
  1380. #+BEGIN_SRC: bash
  1381. editor /etc/default/spamassassin
  1382. #+END_SRC
  1383. Set *ENABLED=1* then save and exit.
  1384. #+BEGIN_SRC: bash
  1385. editor /etc/exim4/exim4.conf.template
  1386. #+END_SRC
  1387. Uncomment or change according to your configuration
  1388. #+BEGIN_SRC: bash
  1389. # For spam scanning, there is a similar option that defines the interface to
  1390. # SpamAssassin. You do not need to set this if you are using the default, which
  1391. # is shown in this commented example. As for virus scanning, you must also
  1392. # modify the acl_check_data access control list to enable spam scanning.
  1393. spamd_address = 127.0.0.1 783
  1394. #+END_SRC
  1395. Add spam header in the /acl_check_data/ section:
  1396. #+BEGIN_SRC: bash
  1397. ### acl/40_exim4-config_check_data
  1398. #################################
  1399. # This ACL is used after the contents of a message have been received. This
  1400. # is the ACL in which you can test a message's headers or body, and in
  1401. # particular, this is where you can invoke external virus or spam scanners.
  1402. acl_check_data:
  1403. ...
  1404. ...
  1405. ...
  1406. # See the exim docs and the exim wiki for more suitable examples.
  1407. #
  1408. # warn
  1409. # spam = Debian-exim:true
  1410. # add_header = X-Spam_score: $spam_score\n\
  1411. # X-Spam_score_int: $spam_score_int\n\
  1412. # X-Spam_bar: $spam_bar\n\
  1413. # X-Spam_report: $spam_report
  1414. # put headers in all messages (no matter if spam or not)
  1415. warn spam = nobody:true
  1416. add_header = X-Spam-Score: $spam_score ($spam_bar)
  1417. add_header = X-Spam-Report: $spam_report
  1418. # add second subject line with *SPAM* marker when message
  1419. # is over threshold
  1420. warn spam = nobody
  1421. add_header = Subject: ***SPAM (score:$spam_score)*** $h_Subject:
  1422. #+END_SRC
  1423. Save and exit, then restart
  1424. #+BEGIN_SRC: bash
  1425. exit
  1426. editor ~/.procmailrc
  1427. #+END_SRC
  1428. The text should look like the following.
  1429. #+BEGIN_SRC: sh
  1430. MAILDIR=$HOME/Maildir
  1431. DEFAULT=$MAILDIR/
  1432. LOGFILE=$HOME/log/procmail.log
  1433. LOGABSTRACT=all
  1434. # get spamassassin to check emails
  1435. :0fw: .spamassassin.lock
  1436. * < 256000
  1437. | spamc
  1438. # strong spam are discarded
  1439. :0
  1440. * ^X-Spam-Level: \*\*\*\*\*\*
  1441. /dev/null
  1442. # weak spam are kept just in case - clear this out every now and then
  1443. :0
  1444. * ^X-Spam-Level: \*\*\*\*\*
  1445. .0-spam/
  1446. # otherwise, marginal spam goes here for revision
  1447. :0
  1448. * ^X-Spam-Level: \*\*
  1449. .spam/
  1450. #+END_SRC
  1451. Save and exit.
  1452. #+BEGIN_SRC: bash
  1453. su
  1454. editor /usr/bin/filterspam
  1455. #+END_SRC
  1456. Add the following contents:
  1457. #+BEGIN_SRC: bash
  1458. #!/bin/bash
  1459. USERNAME=$1
  1460. MAILDIR=/home/$USERNAME/Maildir/.learn-spam
  1461. if [ ! -d "$MAILDIR" ]; then
  1462. exit
  1463. fi
  1464. for f in `ls $MAILDIR/cur`
  1465. do
  1466. spamc -L spam < "$MAILDIR/cur/$f" > /dev/null
  1467. rm "$MAILDIR/cur/$f"
  1468. done
  1469. for f in `ls $MAILDIR/new`
  1470. do
  1471. spamc -L spam < "$MAILDIR/new/$f" > /dev/null
  1472. rm "$MAILDIR/new/$f"
  1473. done
  1474. #+END_SRC
  1475. Save and exit.
  1476. #+BEGIN_SRC: bash
  1477. editor /usr/bin/filterham
  1478. #+END_SRC
  1479. Add the following contents:
  1480. #+BEGIN_SRC: bash
  1481. #!/bin/bash
  1482. USERNAME=$1
  1483. MAILDIR=/home/$USERNAME/Maildir/.learn-ham
  1484. if [ ! -d "$MAILDIR" ]; then
  1485. exit
  1486. fi
  1487. for f in `ls $MAILDIR/cur`
  1488. do
  1489. spamc -L ham < "$MAILDIR/cur/$f" > /dev/null
  1490. rm "$MAILDIR/cur/$f"
  1491. done
  1492. for f in `ls $MAILDIR/new`
  1493. do
  1494. spamc -L ham < "$MAILDIR/new/$f" > /dev/null
  1495. rm "$MAILDIR/new/$f"
  1496. done
  1497. #+END_SRC
  1498. Save and exit.
  1499. #+BEGIN_SRC: bash
  1500. editor /etc/crontab
  1501. #+END_SRC
  1502. Append the following, replacing *myusername* with your username.
  1503. #+BEGIN_SRC: bash
  1504. */3 * * * * root /usr/bin/timeout 120 /usr/bin/filterspam myusername
  1505. */3 * * * * root /usr/bin/timeout 120 /usr/bin/filterham myusername
  1506. #+END_SRC
  1507. Save and exit.
  1508. #+BEGIN_SRC: bash
  1509. chmod 655 /usr/bin/filterspam /usr/bin/filterham
  1510. service spamassassin restart
  1511. service exim4 restart
  1512. service cron restart
  1513. #+END_SRC
  1514. ** Install Dovecot
  1515. #+BEGIN_VERSE
  1516. /I dreamt last night that I was living in a surveillance state. I woke up and… I’m still in a surveillance state./
  1517. -- Conrad Kramer
  1518. #+END_VERSE
  1519. Install the required packages.
  1520. #+BEGIN_SRC: bash
  1521. aptitude -y install dovecot-common dovecot-imapd
  1522. #+END_SRC
  1523. Edit the configuration file.
  1524. #+BEGIN_SRC: bash
  1525. editor /etc/dovecot/dovecot.conf
  1526. #+END_SRC
  1527. Line 26: change:
  1528. #+BEGIN_SRC: bash
  1529. listen = *
  1530. #+END_SRC
  1531. Save and exit.
  1532. #+BEGIN_SRC: bash
  1533. editor /etc/dovecot/conf.d/10-auth.conf
  1534. #+END_SRC
  1535. Line 9: uncomment and change (allow plain text auth)
  1536. #+BEGIN_SRC: bash
  1537. disable_plaintext_auth = no
  1538. #+END_SRC
  1539. Line 99: add:
  1540. #+BEGIN_SRC: bash
  1541. auth_mechanisms = plain login
  1542. #+END_SRC
  1543. Save and exit.
  1544. #+BEGIN_SRC: bash
  1545. editor /etc/dovecot/conf.d/10-mail.conf
  1546. #+END_SRC
  1547. Line 30: uncomment and add:
  1548. #+BEGIN_SRC: bash
  1549. mail_location = maildir:~/Maildir:LAYOUT=fs
  1550. #+END_SRC
  1551. Save and exit.
  1552. #+BEGIN_SRC: bash
  1553. editor /etc/dovecot/conf.d/10-ssl.conf
  1554. #+END_SRC
  1555. Append the following:
  1556. #+BEGIN_SRC: bash
  1557. 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'
  1558. #+END_SRC
  1559. Save and exit, then start the dovecot service.
  1560. #+BEGIN_SRC: bash
  1561. service dovecot restart
  1562. #+END_SRC
  1563. ** Create a GPG key
  1564. #+BEGIN_VERSE
  1565. /If privacy is outlawed, only outlaws will have privacy./
  1566. -- Philip Zimmermann
  1567. #+END_VERSE
  1568. *** Initial installation
  1569. Assuming that you are logged in as root, first ensure that GPG is installed and then exit to your user account.
  1570. #+BEGIN_SRC: bash
  1571. apt-get install gnupg
  1572. exit
  1573. #+END_SRC
  1574. Now we will add some settings:
  1575. #+BEGIN_SRC: bash
  1576. mkdir ~/.gnupg
  1577. editor ~/.gnupg/gpg.conf
  1578. #+END_SRC
  1579. The configuration should look like the following. Of particular importance are the default preferences at the end.
  1580. #+BEGIN_SRC: bash
  1581. # Options for GnuPG
  1582. # Copyright 1998, 1999, 2000, 2001, 2002, 2003,
  1583. # 2010 Free Software Foundation, Inc.
  1584. #
  1585. # This file is free software; as a special exception the author gives
  1586. # unlimited permission to copy and/or distribute it, with or without
  1587. # modifications, as long as this notice is preserved.
  1588. #
  1589. # This file is distributed in the hope that it will be useful, but
  1590. # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
  1591. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  1592. #
  1593. # Unless you specify which option file to use (with the command line
  1594. # option "--options filename"), GnuPG uses the file ~/.gnupg/gpg.conf
  1595. # by default.
  1596. #
  1597. # An options file can contain any long options which are available in
  1598. # GnuPG. If the first non white space character of a line is a '#',
  1599. # this line is ignored. Empty lines are also ignored.
  1600. #
  1601. # See the man page for a list of options.
  1602. # Uncomment the following option to get rid of the copyright notice
  1603. #no-greeting
  1604. # If you have more than 1 secret key in your keyring, you may want to
  1605. # uncomment the following option and set your preferred keyid.
  1606. #default-key 621CC013
  1607. # If you do not pass a recipient to gpg, it will ask for one. Using
  1608. # this option you can encrypt to a default key. Key validation will
  1609. # not be done in this case. The second form uses the default key as
  1610. # default recipient.
  1611. #default-recipient some-user-id
  1612. #default-recipient-self
  1613. # Use --encrypt-to to add the specified key as a recipient to all
  1614. # messages. This is useful, for example, when sending mail through a
  1615. # mail client that does not automatically encrypt mail to your key.
  1616. # In the example, this option allows you to read your local copy of
  1617. # encrypted mail that you've sent to others.
  1618. #encrypt-to some-key-id
  1619. # By default GnuPG creates version 4 signatures for data files as
  1620. # specified by OpenPGP. Some earlier (PGP 6, PGP 7) versions of PGP
  1621. # require the older version 3 signatures. Setting this option forces
  1622. # GnuPG to create version 3 signatures.
  1623. #force-v3-sigs
  1624. # Because some mailers change lines starting with "From " to ">From "
  1625. # it is good to handle such lines in a special way when creating
  1626. # cleartext signatures; all other PGP versions do it this way too.
  1627. #no-escape-from-lines
  1628. # If you do not use the Latin-1 (ISO-8859-1) charset, you should tell
  1629. # GnuPG which is the native character set. Please check the man page
  1630. # for supported character sets. This character set is only used for
  1631. # metadata and not for the actual message which does not undergo any
  1632. # translation. Note that future version of GnuPG will change to UTF-8
  1633. # as default character set. In most cases this option is not required
  1634. # as GnuPG is able to figure out the correct charset at runtime.
  1635. #charset utf-8
  1636. # Group names may be defined like this:
  1637. # group mynames = paige 0x12345678 joe patti
  1638. #
  1639. # Any time "mynames" is a recipient (-r or --recipient), it will be
  1640. # expanded to the names "paige", "joe", and "patti", and the key ID
  1641. # "0x12345678". Note there is only one level of expansion - you
  1642. # cannot make an group that points to another group. Note also that
  1643. # if there are spaces in the recipient name, this will appear as two
  1644. # recipients. In these cases it is better to use the key ID.
  1645. #group mynames = paige 0x12345678 joe patti
  1646. # Lock the file only once for the lifetime of a process. If you do
  1647. # not define this, the lock will be obtained and released every time
  1648. # it is needed, which is usually preferable.
  1649. #lock-once
  1650. # GnuPG can send and receive keys to and from a keyserver. These
  1651. # servers can be HKP, email, or LDAP (if GnuPG is built with LDAP
  1652. # support).
  1653. #
  1654. # Example HKP keyserver:
  1655. # hkp://keys.gnupg.net
  1656. # hkp://subkeys.pgp.net
  1657. #
  1658. # Example email keyserver:
  1659. # mailto:pgp-public-keys@keys.pgp.net
  1660. #
  1661. # Example LDAP keyservers:
  1662. # ldap://keyserver.pgp.com
  1663. #
  1664. # Regular URL syntax applies, and you can set an alternate port
  1665. # through the usual method:
  1666. # hkp://keyserver.example.net:22742
  1667. #
  1668. # Most users just set the name and type of their preferred keyserver.
  1669. # Note that most servers (with the notable exception of
  1670. # ldap://keyserver.pgp.com) synchronize changes with each other. Note
  1671. # also that a single server name may actually point to multiple
  1672. # servers via DNS round-robin. hkp://keys.gnupg.net is an example of
  1673. # such a "server", which spreads the load over a number of physical
  1674. # servers. To see the IP address of the server actually used, you may use
  1675. # the "--keyserver-options debug".
  1676. keyserver hkp://keys.gnupg.net
  1677. #keyserver mailto:pgp-public-keys@keys.nl.pgp.net
  1678. #keyserver ldap://keyserver.pgp.com
  1679. # Common options for keyserver functions:
  1680. #
  1681. # include-disabled : when searching, include keys marked as "disabled"
  1682. # on the keyserver (not all keyservers support this).
  1683. #
  1684. # no-include-revoked : when searching, do not include keys marked as
  1685. # "revoked" on the keyserver.
  1686. #
  1687. # verbose : show more information as the keys are fetched.
  1688. # Can be used more than once to increase the amount
  1689. # of information shown.
  1690. #
  1691. # use-temp-files : use temporary files instead of a pipe to talk to the
  1692. # keyserver. Some platforms (Win32 for one) always
  1693. # have this on.
  1694. #
  1695. # keep-temp-files : do not delete temporary files after using them
  1696. # (really only useful for debugging)
  1697. #
  1698. # http-proxy="proxy" : set the proxy to use for HTTP and HKP keyservers.
  1699. # This overrides the "http_proxy" environment variable,
  1700. # if any.
  1701. #
  1702. # auto-key-retrieve : automatically fetch keys as needed from the keyserver
  1703. # when verifying signatures or when importing keys that
  1704. # have been revoked by a revocation key that is not
  1705. # present on the keyring.
  1706. #
  1707. # no-include-attributes : do not include attribute IDs (aka "photo IDs")
  1708. # when sending keys to the keyserver.
  1709. keyserver-options auto-key-retrieve
  1710. # Display photo user IDs in key listings
  1711. # list-options show-photos
  1712. # Display photo user IDs when a signature from a key with a photo is
  1713. # verified
  1714. # verify-options show-photos
  1715. # Use this program to display photo user IDs
  1716. #
  1717. # %i is expanded to a temporary file that contains the photo.
  1718. # %I is the same as %i, but the file isn't deleted afterwards by GnuPG.
  1719. # %k is expanded to the key ID of the key.
  1720. # %K is expanded to the long OpenPGP key ID of the key.
  1721. # %t is expanded to the extension of the image (e.g. "jpg").
  1722. # %T is expanded to the MIME type of the image (e.g. "image/jpeg").
  1723. # %f is expanded to the fingerprint of the key.
  1724. # %% is %, of course.
  1725. #
  1726. # If %i or %I are not present, then the photo is supplied to the
  1727. # viewer on standard input. If your platform supports it, standard
  1728. # input is the best way to do this as it avoids the time and effort in
  1729. # generating and then cleaning up a secure temp file.
  1730. #
  1731. # If no photo-viewer is provided, GnuPG will look for xloadimage, eog,
  1732. # or display (ImageMagick). On Mac OS X and Windows, the default is
  1733. # to use your regular JPEG image viewer.
  1734. #
  1735. # Some other viewers:
  1736. # photo-viewer "qiv %i"
  1737. # photo-viewer "ee %i"
  1738. #
  1739. # This one saves a copy of the photo ID in your home directory:
  1740. # photo-viewer "cat > ~/photoid-for-key-%k.%t"
  1741. #
  1742. # Use your MIME handler to view photos:
  1743. # photo-viewer "metamail -q -d -b -c %T -s 'KeyID 0x%k' -f GnuPG"
  1744. # Passphrase agent
  1745. #
  1746. # We support the old experimental passphrase agent protocol as well as
  1747. # the new Assuan based one (currently available in the "newpg" package
  1748. # at ftp.gnupg.org/gcrypt/alpha/aegypten/). To make use of the agent,
  1749. # you have to run an agent as daemon and use the option
  1750. #
  1751. # use-agent
  1752. #
  1753. # which tries to use the agent but will fallback to the regular mode
  1754. # if there is a problem connecting to the agent. The normal way to
  1755. # locate the agent is by looking at the environment variable
  1756. # GPG_AGENT_INFO which should have been set during gpg-agent startup.
  1757. # In certain situations the use of this variable is not possible, thus
  1758. # the option
  1759. #
  1760. # --gpg-agent-info=<path>:<pid>:1
  1761. #
  1762. # may be used to override it.
  1763. # Automatic key location
  1764. #
  1765. # GnuPG can automatically locate and retrieve keys as needed using the
  1766. # auto-key-locate option. This happens when encrypting to an email
  1767. # address (in the "user@example.com" form), and there are no
  1768. # user@example.com keys on the local keyring. This option takes the
  1769. # following arguments, in the order they are to be tried:
  1770. #
  1771. # cert = locate a key using DNS CERT, as specified in RFC-4398.
  1772. # GnuPG can handle both the PGP (key) and IPGP (URL + fingerprint)
  1773. # CERT methods.
  1774. #
  1775. # pka = locate a key using DNS PKA.
  1776. #
  1777. # ldap = locate a key using the PGP Universal method of checking
  1778. # "ldap://keys.(thedomain)". For example, encrypting to
  1779. # user@example.com will check ldap://keys.example.com.
  1780. #
  1781. # keyserver = locate a key using whatever keyserver is defined using
  1782. # the keyserver option.
  1783. #
  1784. # You may also list arbitrary keyservers here by URL.
  1785. #
  1786. # Try CERT, then PKA, then LDAP, then hkp://subkeys.net:
  1787. #auto-key-locate cert pka ldap hkp://subkeys.pgp.net
  1788. # default preferences
  1789. personal-digest-preferences SHA256
  1790. cert-digest-algo SHA256
  1791. default-preference-list SHA512 SHA384 SHA256 SHA224 AES256 AES192 AES CAST5 ZLIB BZIP2 ZIP Uncompressed
  1792. #+END_SRC
  1793. Save and exit.
  1794. *** If you have an existing key
  1795. #+BEGIN_SRC: bash
  1796. gpg --import ~/public_key.txt
  1797. gpg --allow-secret-key-import --import ~/private_key.txt
  1798. shred -zu ~/private_key.txt
  1799. #+END_SRC
  1800. 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.
  1801. #+BEGIN_SRC: bash
  1802. export MYGPGKEYID=keyID
  1803. gpg --edit-key $MYGPGKEYID
  1804. setpref SHA512 SHA384 SHA256 SHA224 AES256 AES192 AES CAST5 ZLIB BZIP2 ZIP Uncompressed
  1805. save
  1806. gpg --send-keys $MYGPGKEYID
  1807. #+END_SRC
  1808. *** To create a new key
  1809. Generate a key with the following command:
  1810. #+BEGIN_SRC: bash
  1811. gpg --gen-key
  1812. #+END_SRC
  1813. You can find your GPG key ID by entering:
  1814. #+BEGIN_SRC: bash
  1815. gpg --list-keys
  1816. #+END_SRC
  1817. The key ID is the second part of the string of numbers and letters. So for example in:
  1818. #+BEGIN_SRC: bash
  1819. pub 4096R/EA982E38 2012-05-20
  1820. #+END_SRC
  1821. the key ID is EA982E38. Now send your public key to a server so that others can find it.
  1822. #+BEGIN_SRC: bash
  1823. gpg --send-keys $MYGPGKEYID
  1824. #+END_SRC
  1825. *** root settings
  1826. 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:
  1827. #+BEGIN_SRC: bash
  1828. su
  1829. cp -r /home/myusername/.gnupg ~/
  1830. chown -R root:root ~/.gnupg
  1831. #+END_SRC
  1832. ** Protect processes
  1833. 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.
  1834. #+BEGIN_SRC: bash
  1835. editor /usr/bin/protectprocesses
  1836. #+END_SRC
  1837. Add the following:
  1838. #+BEGIN_SRC: bash
  1839. #!/bin/bash
  1840. declare -a protect=('/usr/sbin/sshd' '/usr/sbin/mysqld --basedir=/usr' '/bin/sh /usr/bin/mysqld_safe' '/usr/sbin/exim4')
  1841. for p in "${protect[@]}"
  1842. do
  1843. OOM_PROC_ID=$(ps aux | grep '$p' | grep -v grep | head -n 1 | awk -F ' ' '{print $2}')
  1844. if [ ! -z "$OOM_PROC_ID" ]; then
  1845. echo -1000 >/proc/$OOM_PROC_ID/oom_score_adj
  1846. echo -17 >/proc/$OOM_PROC_ID/oom_adj
  1847. fi
  1848. done
  1849. #+END_SRC
  1850. Save and exit, then edit the cron jobs:
  1851. #+BEGIN_SRC: bash
  1852. editor /etc/crontab
  1853. #+END_SRC
  1854. And add the line:
  1855. #+BEGIN_SRC: bash
  1856. */1 * * * * root /usr/bin/timeout 30 /usr/bin/protectprocesses
  1857. #+END_SRC
  1858. Then save and exit and restart cron.
  1859. #+BEGIN_SRC: bash
  1860. chmod +x /usr/bin/protectprocesses
  1861. service cron restart
  1862. #+END_SRC
  1863. 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
  1864. .
  1865. ** Setting up a web site
  1866. #+BEGIN_VERSE
  1867. /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./
  1868. -- Tim Berners-Lee
  1869. #+END_VERSE
  1870. First remove any existing web server installation and then install nginx together with some scripts for easily enabling and disabling the web sites which we will create.
  1871. #+BEGIN_SRC: bash
  1872. apt-get remove --purge apache2
  1873. apt-get install nginx php5-fpm git
  1874. cd ~/build
  1875. git clone https://github.com/perusio/nginx_ensite
  1876. cd ~/build/nginx_ensite
  1877. cp nginx_* /usr/sbin
  1878. #+END_SRC
  1879. In the examples below replace /mydomainname.com/ with your own domain name.
  1880. #+BEGIN_SRC: bash
  1881. export HOSTNAME=mydomainname.com
  1882. mkdir /var/www/$HOSTNAME
  1883. mkdir /var/www/$HOSTNAME/htdocs
  1884. editor /etc/nginx/sites-available/$HOSTNAME
  1885. #+END_SRC
  1886. The configuration for the site should look something like the following. Replace /mydonainname.com/ with the site domain name.
  1887. #+BEGIN_SRC: bash
  1888. server {
  1889. listen 80;
  1890. server_name mydomainname.com;
  1891. root /var/www/mydomainname.com/htdocs;
  1892. error_log /var/www/mydomainname.com/error.log;
  1893. index index.html index.htm index.php;
  1894. # Uncomment this if you need to redirect HTTP to HTTPS
  1895. #rewrite ^ https://$server_name$request_uri? permanent;
  1896. location / {
  1897. try_files $uri $uri/ /index.html;
  1898. }
  1899. location ~ \.php$ {
  1900. fastcgi_split_path_info ^(.+\.php)(/.+)$;
  1901. fastcgi_pass unix:/var/run/php5-fpm.sock;
  1902. fastcgi_index index.php;
  1903. include fastcgi_params;
  1904. }
  1905. }
  1906. server {
  1907. listen 443 ssl;
  1908. root /var/www/mydomainname.com/htdocs;
  1909. server_name mydomainname.com;
  1910. error_log /var/www/mydomainname.com/error_ssl.log;
  1911. index index.html index.htm index.php;
  1912. charset utf-8;
  1913. client_max_body_size 20m;
  1914. client_body_buffer_size 128k;
  1915. ssl on;
  1916. ssl_certificate /etc/ssl/certs/mydomainname.com.crt;
  1917. ssl_certificate_key /etc/ssl/private/mydomainname.com.key;
  1918. ssl_dhparam /etc/ssl/certs/mydomainname.com.dhparam;
  1919. ssl_session_timeout 5m;
  1920. ssl_prefer_server_ciphers on;
  1921. ssl_session_cache builtin:1000 shared:SSL:10m;
  1922. ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # not possible to do exclusive
  1923. 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';
  1924. add_header X-Frame-Options DENY;
  1925. add_header X-Content-Type-Options nosniff;
  1926. add_header Strict-Transport-Security max-age=15768000;
  1927. # if you want to be able to access the site via HTTP
  1928. # then replace the above with the following:
  1929. # add_header Strict-Transport-Security "max-age=0;";
  1930. # rewrite to front controller as default rule
  1931. location / {
  1932. rewrite ^/(.*) /index.php?q=$uri&$args last;
  1933. }
  1934. # make sure webfinger and other well known services aren't blocked
  1935. # by denying dot files and rewrite request to the front controller
  1936. location ^~ /.well-known/ {
  1937. allow all;
  1938. rewrite ^/(.*) /index.php?q=$uri&$args last;
  1939. }
  1940. # statically serve these file types when possible
  1941. # otherwise fall back to front controller
  1942. # allow browser to cache them
  1943. # added .htm for advanced source code editor library
  1944. location ~* \.(jpg|jpeg|gif|png|ico|css|js|htm|html|ttf|woff|svg)$ {
  1945. expires 30d;
  1946. try_files $uri /index.php?q=$uri&$args;
  1947. }
  1948. # block these file types
  1949. location ~* \.(tpl|md|tgz|log|out)$ {
  1950. deny all;
  1951. }
  1952. # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  1953. # or a unix socket
  1954. location ~* \.php$ {
  1955. # Zero-day exploit defense.
  1956. # http://forum.nginx.org/read.php?2,88845,page=3
  1957. # Won't work properly (404 error) if the file is not stored on this
  1958. # server, which is entirely possible with php-fpm/php-fcgi.
  1959. # Comment the 'try_files' line out if you set up php-fpm/php-fcgi on
  1960. # another machine. And then cross your fingers that you won't get hacked.
  1961. try_files $uri =404;
  1962. # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
  1963. fastcgi_split_path_info ^(.+\.php)(/.+)$;
  1964. # With php5-cgi alone:
  1965. # fastcgi_pass 127.0.0.1:9000;
  1966. # With php5-fpm:
  1967. fastcgi_pass unix:/var/run/php5-fpm.sock;
  1968. include fastcgi_params;
  1969. fastcgi_index index.php;
  1970. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  1971. }
  1972. # deny access to all dot files
  1973. location ~ /\. {
  1974. deny all;
  1975. }
  1976. #deny access to store
  1977. location ~ /store {
  1978. deny all;
  1979. }
  1980. }
  1981. #+END_SRC
  1982. Save and exit. Then change the domain name.
  1983. #+BEGIN_SRC: bash
  1984. sed "s/mydomainname.com/$HOSTNAME/g" /etc/nginx/sites-available/$HOSTNAME > /tmp/website
  1985. cp -f /tmp/website /etc/nginx/sites-available/$HOSTNAME
  1986. #+END_SRC
  1987. Then to enable the site:
  1988. #+BEGIN_SRC: bash
  1989. nginx_dissite default
  1990. nginx_ensite $HOSTNAME
  1991. makecert $HOSTNAME
  1992. #+END_SRC
  1993. 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.
  1994. Also limit the amount of memory which any php scripts can use.
  1995. #+BEGIN_SRC: bash
  1996. editor /etc/php5/fpm/php.ini
  1997. #+END_SRC
  1998. Set the following:
  1999. #+BEGIN_SRC: bash
  2000. memory_limit = 32M
  2001. #+END_SRC
  2002. Also set:
  2003. #+BEGIN_SRC: bash
  2004. cgi.fix_pathinfo=0
  2005. #+END_SRC
  2006. 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.
  2007. #+BEGIN_SRC: bash
  2008. editor /etc/php5/fpm/pool.d/www.conf
  2009. #+END_SRC
  2010. Set the following:
  2011. #+BEGIN_SRC: bash
  2012. pm.max_children = 20
  2013. #+END_SRC
  2014. Save and exit.
  2015. #+BEGIN_SRC: bash
  2016. service php5-fpm restart
  2017. service nginx restart
  2018. #+END_SRC
  2019. ** Accessing your Email
  2020. #+BEGIN_VERSE
  2021. /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./
  2022. -- Article on the "Google-Military-Surveillance Complex" by Yasha Levine
  2023. #+END_VERSE
  2024. *** Mutt email client
  2025. #+BEGIN_SRC: bash
  2026. apt-get install mutt-patched lynx abook
  2027. exit
  2028. mkdir ~/.mutt
  2029. echo "text/html; lynx -dump -width=78 -nolist %s | sed ‘s/^ //’; copiousoutput; needsterminal; nametemplate=%s.html" > ~/.mutt/mailcap
  2030. su
  2031. editor /etc/Muttrc
  2032. #+END_SRC
  2033. Append the following:
  2034. #+BEGIN_SRC: bash
  2035. set mbox_type=Maildir
  2036. set folder="~/Maildir"
  2037. set mask="!^\\.[^.]"
  2038. set mbox="~/Maildir"
  2039. set record="+Sent"
  2040. set postponed="+Drafts"
  2041. set trash="+Trash"
  2042. set spoolfile="~/Maildir"
  2043. auto_view text/x-vcard text/html text/enriched
  2044. set editor="emacs"
  2045. set header_cache="+.cache"
  2046. macro index S "<tag-prefix><save-message>=.learn-spam<enter>" "move to learn-spam"
  2047. macro pager S "<save-message>=.learn-spam<enter>" "move to learn-spam"
  2048. macro index H "<tag-prefix><copy-message>=.learn-ham<enter>" "copy to learn-ham"
  2049. macro pager H "<copy-message>=.learn-ham<enter>" "copy to learn-ham"
  2050. # set up the sidebar
  2051. set sidebar_width=12
  2052. set sidebar_visible=yes
  2053. set sidebar_delim='|'
  2054. set sidebar_sort=yes
  2055. set rfc2047_parameters
  2056. # Show inbox and sent items
  2057. mailboxes = =Sent
  2058. # Alter these colours as needed for maximum bling
  2059. color sidebar_new yellow default
  2060. color normal white default
  2061. color hdrdefault brightcyan default
  2062. color signature green default
  2063. color attachment brightyellow default
  2064. color quoted green default
  2065. color quoted1 white default
  2066. color tilde blue default
  2067. # ctrl-n, ctrl-p to select next, prev folder
  2068. # ctrl-o to open selected folder
  2069. bind index \Cp sidebar-prev
  2070. bind index \Cn sidebar-next
  2071. bind index \Co sidebar-open
  2072. bind pager \Cp sidebar-prev
  2073. bind pager \Cn sidebar-next
  2074. bind pager \Co sidebar-open
  2075. # ctrl-b toggles sidebar visibility
  2076. macro index,pager \Cb '<enter-command>toggle sidebar_visible<enter><redraw-screen>' "toggle sidebar"
  2077. # esc-m Mark new messages as read
  2078. macro index <esc>m "T~N<enter>;WNT~O<enter>;WO\CT~T<enter>" "mark all messages read"
  2079. # Collapsing threads
  2080. macro index [ "<collapse-thread>" "collapse/uncollapse thread"
  2081. macro index ] "<collapse-all>" "collapse/uncollapse all threads"
  2082. # threads containing new messages
  2083. uncolor index "~(~N)"
  2084. color index brightblue default "~(~N)"
  2085. # new messages themselves
  2086. uncolor index "~N"
  2087. color index brightyellow default "~N"
  2088. # GPG/PGP integration
  2089. # this set the number of seconds to keep in memory the passphrase used to encrypt/sign
  2090. set pgp_timeout=60
  2091. # automatically sign and encrypt with PGP/MIME
  2092. set pgp_autosign # autosign all outgoing mails
  2093. set pgp_replyencrypt # autocrypt replies to crypted
  2094. set pgp_replysign # autosign replies to signed
  2095. set pgp_auto_decode=yes # decode attachments
  2096. unset smime_is_default
  2097. set alias_file=~/.mutt-alias
  2098. source ~/.mutt-alias
  2099. set query_command= "abook --mutt-query '%s'"
  2100. macro index,pager A "<pipe-message>abook --add-email-quiet<return>" "add the sender address to abook"
  2101. #+END_SRC
  2102. Save and exit.
  2103. #+BEGIN_SRC: bash
  2104. editor /etc/mail/spamassassin/local.cf
  2105. #+END_SRC
  2106. Uncomment *use_bayes*, *bayes_auto_learn*
  2107. Save and exit, then run:
  2108. #+BEGIN_SRC: bash
  2109. service spamassassin restart
  2110. exit
  2111. cp /etc/Muttrc ~/.muttrc
  2112. touch ~/.mutt-alias
  2113. #+END_SRC
  2114. 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.
  2115. 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.
  2116. Some useful keys to know are:
  2117. | ESC / | Search for text within message contents |
  2118. | "/" | Search for text within headers |
  2119. | * | Move to the last message |
  2120. | TAB | Move to the next unread message |
  2121. | d | Delete a message |
  2122. | u | Undelete a mail which is pending deletion |
  2123. | $ | Delete all messages selected and check for new messages |
  2124. | a | Add to the address book |
  2125. | m | Send a new mail |
  2126. | ESC-m | Mark all messages as having been read |
  2127. | S | Mark a message as spam |
  2128. | H | Mark a message as ham |
  2129. | CTRL-b | Toggle side bar on/off |
  2130. | CTRL-n | Next mailbox (on side bar) |
  2131. | CTRL-p | Previous mailbox (on side bar) |
  2132. | CTRL-o | Open mailbox (on side bar) |
  2133. | ] | Expand or collapse all threads |
  2134. | [ | Expand of collapse the current thread |
  2135. | CTRL-k | Import a PGP/GPG public key |
  2136. 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.
  2137. *** K9 Android client
  2138. #+BEGIN_VERSE
  2139. /The surveillance state is robust. It is robust politically, legally, and technically./
  2140. -- Bruce Schneier
  2141. #+END_VERSE
  2142. **** Incoming server settings
  2143. * Select settings/account settings
  2144. * Select Fetching mail/incoming server
  2145. * Enter your username and password
  2146. * IMAP server should be your domain name
  2147. * Security: SSL/TLS (always)
  2148. * Authentication: Plain
  2149. * Port: 993
  2150. **** Outgoing (SMTP) server settings
  2151. * Select settings/account settings
  2152. * Select Sending mail/outgoing server
  2153. * Set SMTP server to your domain name
  2154. * Set Security to SSL/TLS (always)
  2155. * Set port to 465
  2156. * Set authentication to PLAIN
  2157. * Enter your username and password
  2158. * Accept the SSL certificate
  2159. **** Folders
  2160. 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*.
  2161. If your folder still doesn't show up then press the *menu button*, select *show folders* and select *all folders*.
  2162. *** Webmail
  2163. #+BEGIN_VERSE
  2164. /Most of the information extracted is "content", such as recordings of phone calls or the substance of email messages./
  2165. -- From a 2013 Guardian article on GCHQ/NSA bulk internet data interception.
  2166. #+END_VERSE
  2167. 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.
  2168. If you're not already logged in as root:
  2169. #+BEGIN_SRC: bash
  2170. su
  2171. #+END_SRC
  2172. Install dependencies.
  2173. #+BEGIN_SRC: bash
  2174. apt-get install mysql-server
  2175. #+END_SRC
  2176. Create a mysql database, specifying a password which should be a long random string generated with a password manager such as KeepassX.
  2177. #+BEGIN_SRC: bash
  2178. mysql -u root -p
  2179. create database roundcubemail;
  2180. CREATE USER 'roundcube'@'localhost' IDENTIFIED BY 'roundcubepassword';
  2181. GRANT ALL PRIVILEGES ON roundcubemail.* TO 'roundcube'@'localhost';
  2182. quit
  2183. #+END_SRC
  2184. Download roundcube.
  2185. #+BEGIN_SRC: bash
  2186. mkdir ~/build
  2187. cd ~/build
  2188. wget http://freedombone.uk.to/roundcubemail.tar.gz
  2189. #+END_SRC
  2190. Verify it.
  2191. #+BEGIN_SRC: bash
  2192. sha256sum roundcubemail.tar.gz
  2193. 1c1560a7a56e6884b45c49f52961dbbb3f6bacbc7e7c755440750a1ab027171c
  2194. #+END_SRC
  2195. Extract the files.
  2196. #+BEGIN_SRC: bash
  2197. tar -xzvf roundcubemail.tar.gz
  2198. export HOSTNAME=mydomainname.com
  2199. cp -r roundcubemail-* /var/www/$HOSTNAME/htdocs/mail
  2200. chown -R www-data:www-data /var/www/$HOSTNAME/htdocs/mail/temp
  2201. chown -R www-data:www-data /var/www/$HOSTNAME/htdocs/mail/logs
  2202. rm /var/www/$HOSTNAME/htdocs/mail/.htaccess
  2203. #+END_SRC
  2204. Edit your web site configuration.
  2205. #+BEGIN_SRC: bash
  2206. editor /etc/nginx/sites-available/$HOSTNAME
  2207. #+END_SRC
  2208. Within the 80 VirtualHost section add the following:
  2209. #+BEGIN_SRC: bash
  2210. location /mail/ {
  2211. deny all;
  2212. }
  2213. #+END_SRC
  2214. Within the 443 VirtualHost section add the following:
  2215. #+BEGIN_SRC: bash
  2216. location /mail/ {
  2217. autoindex on;
  2218. allow all;
  2219. }
  2220. #+END_SRC
  2221. Save and exit, then restart the web server.
  2222. #+BEGIN_SRC: bash
  2223. service nginx restart
  2224. #+END_SRC
  2225. Now with a browser visit https://mydomainname.com/mail/installer. Scroll down and click "next". Give your webmail site a product name.
  2226. Change *spellcheck_engine* to *ATD*.
  2227. Under database settings change the database type to SQlite and leave all other fields blank.
  2228. Unser IMAP set *default_host* to ssl://mydomainname.com, *default_port* to 993 and *username_domain* to your domain name.
  2229. Set *smtp_port* to 465.
  2230. Check "Use the current IMAP username and password for SMTP authentication"
  2231. Change the *database password* to the password you gave when creating the MySql database above.
  2232. Click *create config*
  2233. Click download to download the file.
  2234. The config file which you downloaded should contain the following:
  2235. #+BEGIN_SRC: bash
  2236. $config['default_host'] = 'localhost';
  2237. $config['smtp_port'] = 465;
  2238. $config['username_domain'] = '';
  2239. #+END_SRC
  2240. In a terminal on your local machine (not logged into the BBB):
  2241. #+BEGIN_SRC: bash
  2242. cd ~/Downloads
  2243. scp config.inc.php myusername@mydomainname.com:/home/myusername
  2244. #+END_SRC
  2245. Then in a terminal ssh'd into the BBB:
  2246. #+BEGIN_SRC: bash
  2247. mv /home/myusername/config.inc.php /var/www/$HOSTNAME/htdocs/mail/config
  2248. chmod 755 /var/www/$HOSTNAME/htdocs/mail/config/config.inc.php
  2249. #+END_SRC
  2250. Click *continue*.
  2251. Click *initialize database*.
  2252. Under *Test SMTP config* you can use a [[mailinator.com]] address to check that mail can be sent.
  2253. Now we can delete the installer.
  2254. #+BEGIN_SRC: bash
  2255. rm -rf /var/www/$HOSTNAME/htdocs/mail/installer
  2256. #+END_SRC
  2257. Now with a browser navigate to https://mydomainname.com/mail and log in.
  2258. 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.
  2259. 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.
  2260. *** Thunderbird
  2261. #+BEGIN_VERSE
  2262. /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./
  2263. -- Brian Spector, on the shutting down of the PrivateSky encrypted email service
  2264. #+END_VERSE
  2265. 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.
  2266. The following instructions should be carried out on the client machines (laptop, etc), not on the BBB itself.
  2267. **** Initial setup
  2268. Install *Thunderbird* and *Enigmail*. How you do this just depends upon your distro and software manager or "app store".
  2269. Open Thinderbird
  2270. Select "*Skip this and use existing email*"
  2271. Enter your name, email address (myusername@mydomainname.com) and the password for your user (the one from [[Add a user]]).
  2272. You'll get a message saying "/Thunderbird failed to find the settings/"
  2273. The settings should be as follows, substituting /mydomainname.com/ for your domain name and /myusername/ for the username given previously in [[Add a user]].
  2274. * Incoming: IMAP, mydomainname.com, 993, SSL/TLS, Normal Password
  2275. * Outgoing: SMTP, mydomainname.com, 465, SSL/TLS, Normal Password
  2276. * Username: myusername
  2277. Click *Done*.
  2278. Click *Get Certificate* and make sure "*permanently store this exception*" is selected", then click *Store Security Exception*.
  2279. 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.
  2280. Select "*Yes, I want to sign all of my email*"
  2281. Select "*No, I will create per-recipient rules*"
  2282. Select "*yes*" to change default settings.
  2283. **** If you have existing GPG key
  2284. Export your GPG public and private keys.
  2285. #+BEGIN_SRC: bash
  2286. gpg --output ~/public_key.txt --armor --export KEY_ID
  2287. gpg --output ~/private_key.txt --armor --export-secret-key KEY_ID
  2288. #+END_SRC
  2289. Select "*I have existing public and private keys*".
  2290. Select your public and private GPG exported key files.
  2291. Select the account which you want to use and click *Next*, *Next* and *Finish*.
  2292. Remove your exported key files.
  2293. #+BEGIN_SRC: bash
  2294. shred -zu ~/public_key.txt
  2295. shred -zu ~/private_key.txt
  2296. #+END_SRC
  2297. **** If you don't have any existing GPG or PGP key
  2298. Select "*I want to create a new key pair*"
  2299. Enter a passphrase and click *Next* a couple of times.
  2300. Click *Generate Certificate* to generate a revocation certificate.
  2301. Enter the passphrase which you gave previously.
  2302. Click *Finish*
  2303. 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.
  2304. 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.
  2305. **** Using for the first time
  2306. Click on the Thunderbird menu, which looks like three horizontal bars on the right hand side.
  2307. Hover over *preferences* and then *Account settings*.
  2308. 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.
  2309. Select *Synchronization & Storage*.
  2310. Make sure that *Keep messages for this account on this computer* is unticked, then click *Ok*.
  2311. Click on *Inbox*. Depending upon how much email you have it may take a while to import the subject lines.
  2312. Note that when sending an email for the first time you will also need to accept the SSL certificate.
  2313. 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.
  2314. **** Making folders visible
  2315. 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:
  2316. *Menu*, hover over *Preferences*, select *Account Settings*, select *Server Settings* then click on the *Advanced* button.
  2317. 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.
  2318. ** Create Email folders and rules
  2319. #+BEGIN_VERSE
  2320. /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./
  2321. -- Aral Balkan
  2322. #+END_VERSE
  2323. *** Rules for mailing lists
  2324. 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.
  2325. We can make a script to make adding mailing list rules easy:
  2326. #+BEGIN_SRC: bash
  2327. editor /usr/bin/mailinglistrule
  2328. #+END_SRC
  2329. Add the following:
  2330. #+BEGIN_SRC: bash
  2331. #!/bin/bash
  2332. MYUSERNAME=$1
  2333. MAILINGLIST=$2
  2334. SUBJECTTAG=$3
  2335. MUTTRC=/home/$MYUSERNAME/.muttrc
  2336. PM=/home/$MYUSERNAME/.procmailrc
  2337. LISTDIR=/home/$MYUSERNAME/Maildir/$MAILINGLIST
  2338. if [ ! -d "$LISTDIR" ]; then
  2339. mkdir -m 700 $LISTDIR
  2340. mkdir -m 700 $LISTDIR/tmp
  2341. mkdir -m 700 $LISTDIR/new
  2342. mkdir -m 700 $LISTDIR/cur
  2343. fi
  2344. chown -R $MYUSERNAME:$MYUSERNAME $LISTDIR
  2345. echo "" >> $PM
  2346. echo ":0" >> $PM
  2347. echo " * ^Subject:.*()\[$SUBJECTTAG\]" >> $PM
  2348. echo "$LISTDIR/new" >> $PM
  2349. chown $MYUSERNAME:$MYUSERNAME $PM
  2350. if [ ! -f "$MUTTRC" ]; then
  2351. cp /etc/Muttrc $MUTTRC
  2352. chown $MYUSERNAME:$MYUSERNAME $MUTTRC
  2353. fi
  2354. PROCMAILLOG=/home/$MYUSERNAME/log
  2355. if [ ! -d $PROCMAILLOG ]; then
  2356. mkdir $PROCMAILLOG
  2357. chown -R $MYUSERNAME:$MYUSERNAME $PROCMAILLOG
  2358. fi
  2359. #+END_SRC
  2360. Save and exit, then make the script executable.
  2361. #+BEGIN_SRC: bash
  2362. chmod +x /usr/bin/mailinglistrule
  2363. #+END_SRC
  2364. 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.
  2365. #+BEGIN_SRC: bash
  2366. mailinglistrule [myusername] [mailinglistname] [subjecttag]
  2367. #+END_SRC
  2368. Repeat this command for as many mailing lists as you need. Then edit your local Mutt configuration.
  2369. #+BEGIN_SRC: bash
  2370. editor /home/myusername/.muttrc
  2371. #+END_SRC
  2372. Search for the *mailboxes* variable and add entries for the mailing lists you just created. For example:
  2373. #+BEGIN_SRC: bash
  2374. mailboxes = =Sent =mailinglistname
  2375. #+END_SRC
  2376. Then save and exit.
  2377. *** Rules for specific email addresses
  2378. You can also make a script which will allow you to move mail from specific email addresses to a folder.
  2379. #+BEGIN_SRC: bash
  2380. editor /usr/bin/emailrule
  2381. #+END_SRC
  2382. Add the following:
  2383. #+BEGIN_SRC: bash
  2384. #!/bin/bash
  2385. MYUSERNAME=$1
  2386. EMAILADDRESS=$2
  2387. MAILINGLIST=$3
  2388. MUTTRC=/home/$MYUSERNAME/.muttrc
  2389. PM=/home/$MYUSERNAME/.procmailrc
  2390. LISTDIR=/home/$MYUSERNAME/Maildir/$MAILINGLIST
  2391. if [ ! -d "$LISTDIR" ]; then
  2392. mkdir -m 700 $LISTDIR
  2393. mkdir -m 700 $LISTDIR/tmp
  2394. mkdir -m 700 $LISTDIR/new
  2395. mkdir -m 700 $LISTDIR/cur
  2396. fi
  2397. chown -R $MYUSERNAME:$MYUSERNAME $LISTDIR
  2398. echo "" >> $PM
  2399. echo ":0" >> $PM
  2400. echo " * ^From: $EMAILADDRESS" >> $PM
  2401. echo "$LISTDIR/new" >> $PM
  2402. chown $MYUSERNAME:$MYUSERNAME $PM
  2403. if [ ! -f "$MUTTRC" ]; then
  2404. cp /etc/Muttrc $MUTTRC
  2405. chown $MYUSERNAME:$MYUSERNAME $MUTTRC
  2406. fi
  2407. PROCMAILLOG=/home/$MYUSERNAME/log
  2408. if [ ! -d $PROCMAILLOG ]; then
  2409. mkdir $PROCMAILLOG
  2410. chown -R $MYUSERNAME:$MYUSERNAME $PROCMAILLOG
  2411. fi
  2412. #+END_SRC
  2413. Save and exit, then make the script executable.
  2414. #+BEGIN_SRC: bash
  2415. chmod +x /usr/bin/emailrule
  2416. #+END_SRC
  2417. Then to add a particular email address to a folder run the command:
  2418. #+BEGIN_SRC: bash
  2419. emailrule [myusername] [emailaddress] [foldername]
  2420. #+END_SRC
  2421. If you want any mail from the given email address to be deleted then set the /foldername/ to /Trash/.
  2422. To ensure that the folder appears within Mutt.
  2423. #+BEGIN_SRC: bash
  2424. editor /home/myusername/.muttrc
  2425. #+END_SRC
  2426. Search for the *mailboxes* variable and add entries for the mailing lists you just created. For example:
  2427. #+BEGIN_SRC: bash
  2428. mailboxes = =Sent =foldername
  2429. #+END_SRC
  2430. Then save and exit.
  2431. ** Install a Blog
  2432. #+BEGIN_VERSE
  2433. /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./
  2434. -- Nick Cohen
  2435. #+END_VERSE
  2436. 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.
  2437. 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.
  2438. Download flatpress.
  2439. #+BEGIN_SRC: bash
  2440. mkdir ~/build
  2441. cd ~/build
  2442. wget http://freedombone.uk.to/flatpress.tar.gz
  2443. #+END_SRC
  2444. Verify the download:
  2445. #+BEGIN_SRC: bash
  2446. sha256sum flatpress.tar.gz
  2447. 6312a49aab5aabd6371518dcaf081f489dff04d001bc34b4fe3f2a81170bbd4e flatpress.tar.gz
  2448. #+END_SRC
  2449. Extract and install it.
  2450. #+BEGIN_SRC: bash
  2451. tar -xzvf flatpress.tar.gz
  2452. cd flatpress-*
  2453. cp -r * /var/www/$HOSTNAME/htdocs
  2454. chmod -R 755 /var/www/$HOSTNAME/htdocs/fp-content
  2455. chown -R www-data:www-data /var/www/$HOSTNAME/htdocs/fp-content
  2456. cd ..
  2457. rm -rf flatpress-*
  2458. rm -f flatpress.tar.gz
  2459. #+END_SRC
  2460. 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
  2461. ** Install an IRC server
  2462. #+BEGIN_VERSE
  2463. /Give me the liberty to know, to utter, and to argue freely according to conscience, above all liberties./
  2464. -- John Milton
  2465. #+END_VERSE
  2466. *** Base install
  2467. 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.
  2468. #+BEGIN_SRC: bash
  2469. adduser ircserver
  2470. cd ~/build
  2471. wget http://freedombone.uk.to/ircd-hybrid-8.1.20.tgz
  2472. #+END_SRC
  2473. Verify the download.
  2474. #+BEGIN_SRC: bash
  2475. sha256sum ircd-hybrid-8.1.20.tgz
  2476. 5570be89fa76b2712d7f08d6c828d613d201daed8c1064be7245fe10bdffa228
  2477. #+END_SRC
  2478. Download Anope.
  2479. #+BEGIN_SRC: bash
  2480. wget http://freedombone.uk.to/anope-2.0.1-source.tar.gz
  2481. #+END_SRC
  2482. And verify it.
  2483. #+BEGIN_SRC: bash
  2484. sha256sum anope-2.0.1-source.tar.gz
  2485. 539f603adc4f982e3a5ffd175ecb007aadc619a692409b3e9e1f7f15fb1288e6
  2486. #+END_SRC
  2487. Then compile and install them.
  2488. #+BEGIN_SRC: bash
  2489. apt-get install libssl-dev cmake
  2490. tar -xvf ircd-hybrid-8.1.20.tgz
  2491. tar -xvf anope-2.0.1-source.tar.gz
  2492. cd ~/build/ircd-hybrid-8.1.20
  2493. ./configure -prefix="/home/ircserver/ircd"
  2494. make
  2495. make install
  2496. cd ~/build/anope-2.0.1-source
  2497. ./Config
  2498. #+END_SRC
  2499. Answer the questions as follows:
  2500. #+BEGIN_SRC: bash
  2501. In what directory do you want the binaries to be installed?
  2502. /home/ircserver/services
  2503. Create it?
  2504. y
  2505. Where do you want the data files to be installed?
  2506. /home/ircserver/services
  2507. Which group should all Services data files be owned by?
  2508. ircserver
  2509. What should the default umask for data files be (in octal)?
  2510. 007
  2511. Would you like to build a debug version of Anope?
  2512. n
  2513. Would you like to utilize run-cc.pl?
  2514. n
  2515. Do you want to build using precompiled headers?
  2516. n
  2517. If you need no extra include directories.
  2518. NONE
  2519. Are there any extra arguments you wish to pass to CMake?
  2520. NONE
  2521. #+END_SRC
  2522. Then build and install Anope.
  2523. #+BEGIN_SRC: bash
  2524. cd build
  2525. make
  2526. make install
  2527. cd /home/ircserver/ircd/etc
  2528. cp reference.conf ircd.conf
  2529. #+END_SRC
  2530. Create some ssl certificates:
  2531. #+BEGIN_SRC: bash
  2532. mkdir /home/ircserver/ircd/ssl
  2533. makecert ircd
  2534. mv /etc/ssl/private/ircd.key /home/ircserver/ircd/ssl/
  2535. mv /etc/ssl/certs/ircd.crt /home/ircserver/ircd/ssl/ircd.pem
  2536. mv /etc/ssl/certs/ircd.dhparam /home/ircserver/ircd/ssl/dhparam.pem
  2537. chmod 640 /home/ircserver/ircd/ssl/*
  2538. chown -R ircserver:ircserver /home/ircserver/ircd
  2539. chown -R ircserver:ircserver /home/ircserver/services
  2540. chown -R ircserver:ircserver /home/ircserver/ircd/ssl
  2541. #+END_SRC
  2542. Now edit the configuration:
  2543. #+BEGIN_SRC: bash
  2544. editor /home/ircserver/ircd/etc/ircd.conf
  2545. #+END_SRC
  2546. Comment out:
  2547. #+BEGIN_SRC: bash
  2548. // havent_read_conf = 1;
  2549. // flags = need_ident;
  2550. #+END_SRC
  2551. Uncomment and change the following lines:
  2552. #+BEGIN_SRC: bash
  2553. rsa_private_key_file = "/home/ircserver/ircd/ssl/ircd.key";
  2554. ssl_certificate_file = "/home/ircserver/ircd/ssl/ircd.pem";
  2555. ssl_dh_param_file = "/home/ircserver/ircd/ssl/dhparam.pem";
  2556. #+END_SRC
  2557. Above the ssl parameters set *network_name* to your domain name.
  2558. Uncomment:
  2559. #+BEGIN_SRC: bash
  2560. ssl_server_method = tldv1, sslv3;
  2561. #+END_SRC
  2562. Within the *operator* section (line 424):
  2563. #+BEGIN_SRC: bash
  2564. name = "myusername";
  2565. user = "*@192.168.1.*";
  2566. password = "mypassword";
  2567. encrypted = no;
  2568. #+END_SRC
  2569. Within the *connect* section (line 555):
  2570. #+BEGIN_SRC: bash
  2571. name = "mydomainname.com";
  2572. host = "192.168.1.60";
  2573. vhost = "192.168.1.60";
  2574. send_password = "mysendacceptpassword";
  2575. accept_password = "mysendacceptpassword";
  2576. #+END_SRC
  2577. And within the *service* section:
  2578. #+BEGIN_SRC: bash
  2579. name = "mydomainname.com";
  2580. #+END_SRC
  2581. 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.
  2582. Change *max_clients* to 20, or a number which is sufficient for the number of simultaneous users you expect.
  2583. Save and exit.
  2584. #+BEGIN_SRC: bash
  2585. cd /home/ircserver/services/conf
  2586. cp example.conf services.conf
  2587. editor services.conf
  2588. #+END_SRC
  2589. 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:
  2590. Within the *module* section set *name* to "hybrid".
  2591. Within the *uplink* section set *password* to the /sendacceptpassword/.
  2592. Uncomment *#oper* and *name* underneath it, and change the name to your username.
  2593. Save and exit, then create a daemon.
  2594. #+BEGIN_SRC: bash
  2595. editor /etc/init.d/ircd-hybrid
  2596. #+END_SRC
  2597. Add the following:
  2598. #+BEGIN_SRC: bash
  2599. #!/bin/bash
  2600. # /etc/init.d/ircd-hybrid
  2601. ### BEGIN INIT INFO
  2602. # Provides: ircd-hybrid
  2603. # Required-Start: $remote_fs $syslog
  2604. # Required-Stop: $remote_fs $syslog
  2605. # Default-Start: 2 3 4 5
  2606. # Default-Stop: 0 1 6
  2607. # Short-Description: starts irc server
  2608. # Description: starts irc server
  2609. ### END INIT INFO
  2610. # Author: Bob Mottram <bob@robotics.uk.to>
  2611. #Settings
  2612. SERVICE='ircd-hybrid'
  2613. COMMAND='ircd'
  2614. USER='ircserver'
  2615. NICELEVEL=19 # from 0-19 the bigger the number, the less the impact on system resources
  2616. HISTORY=1024
  2617. INVOCATION="nice -n ${NICELEVEL} ${COMMAND}"
  2618. PATH='/usr/local/sbin:/usr/local/bin:/usr/bin:/sbin:/usr/sbin:/bin:/home/ircserver/ircd/sbin:/home/ircserver/ircd/bin'
  2619. irc_start() {
  2620. echo "Starting $SERVICE..."
  2621. cd /home/$USER/ircd
  2622. su --command "bin/$COMMAND" $USER
  2623. su --command "/home/$USER/services/bin/services" $USER
  2624. }
  2625. irc_stop() {
  2626. echo "Stopping $SERVICE"
  2627. killall -15 $COMMAND
  2628. killall -15 $USER
  2629. }
  2630. #Start-Stop here
  2631. case "$1" in
  2632. start)
  2633. irc_start
  2634. ;;
  2635. stop)
  2636. irc_stop
  2637. ;;
  2638. restart)
  2639. irc_stop
  2640. sleep 10s
  2641. irc_start
  2642. ;;
  2643. *)
  2644. echo "Usage: $0 {start|stop|restart}"
  2645. exit 1
  2646. ;;
  2647. esac
  2648. exit 0
  2649. #+END_SRC
  2650. Save and exit, then start the daemon.
  2651. #+BEGIN_SRC: bash
  2652. chmod +x /etc/init.d/ircd-hybrid
  2653. update-rc.d ircd-hybrid defaults
  2654. service ircd-hybrid start
  2655. #+END_SRC
  2656. *** Channel management
  2657. To to install channel management tools.
  2658. #+BEGIN_SRC: bash
  2659. mkdir ~/build
  2660. cd ~/build
  2661. wget http://freedombone.uk.to/hybserv_1.9.4-1_armhf.deb
  2662. #+END_SRC
  2663. Verify it.
  2664. #+BEGIN_SRC: bash
  2665. sha256sum hybserv_1.9.4-1_armhf.deb
  2666. 41bf4eb6e24c87610a80bc14db1103a57484835510eea7e4ba9709c523318615 hybserv_1.9.4-1_armhf.deb
  2667. #+END_SRC
  2668. Install it.
  2669. #+BEGIN_SRC: bash
  2670. dpkg -i hybserv_1.9.4-1_armhf.deb
  2671. #+END_SRC
  2672. Make a md5 version of the password for the IRC server operator.
  2673. #+BEGIN_SRC: bash
  2674. /usr/bin/mkpasswd <myoperatorpassword>
  2675. #+END_SRC
  2676. Edit the ircd-hybrid configuration.
  2677. #+BEGIN_SRC: bash
  2678. editor /etc/ircd-hybrid/ircd.conf
  2679. #+END_SRC
  2680. Enter the md5 password which you previously created within the /operator/ section. Also change /user/ to:
  2681. #+BEGIN_SRC: bash
  2682. user = "*@*";
  2683. #+END_SRC
  2684. Then save and exit.
  2685. #+BEGIN_SRC: bash
  2686. editor /etc/hybserv/hybserv.conf
  2687. #+END_SRC
  2688. 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/.
  2689. #+BEGIN_SRC: bash
  2690. A:mynickname <myemailaddress>
  2691. N:irc.mydomainname.com:Hybrid services
  2692. O:*@*:#MD5 PASSWORD HERE#:root:segj (comment out other Q: lines)
  2693. S:mysendacceptpassword:192.168.1.60:6697 (remove the other two services)
  2694. #+END_SRC
  2695. Also remove the line *#NOT-EDITED#*, then save and exit.
  2696. Now we need to restart the ircd and hybrid server to make things work:
  2697. #+BEGIN_SRC: bash
  2698. service ircd-hybrid restart
  2699. service hybserv start
  2700. #+END_SRC
  2701. *** Usage with Irssi
  2702. On another computer (not the BBB).
  2703. #+BEGIN_SRC: bash
  2704. sudo apt-get install irssi irssi-plugin-otr irssi-plugin-xmpp
  2705. irssi
  2706. #+END_SRC
  2707. 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".
  2708. #+BEGIN_SRC: bash
  2709. /network add -nick mynick mynetwork
  2710. /channel add -auto #mychannel mynetwork channelpassword
  2711. /server add -auto -network mynetwork -ssl mydonainname.com 6697 mysendacceptpassword
  2712. /connect mydomainname.com
  2713. /join #mychannel
  2714. /msg -servername chanserv REGISTER #mychannel channelpassword
  2715. /msg -servername chanserv set #mychannel mlock +k channelpassword
  2716. /set paste_join_multiline OFF
  2717. #+END_SRC
  2718. If you edit the irssi config file:
  2719. #+BEGIN_SRC: bash
  2720. editor ~/.irssi/config
  2721. #+END_SRC
  2722. It should look something like this:
  2723. #+BEGIN_SRC: bash
  2724. {
  2725. address = "mydomainname.com";
  2726. chatnet = "mynetwork";
  2727. port = "6697";
  2728. password = "mysendacceptpassword";
  2729. use_ssl = "yes";
  2730. ssl_verify = "no";
  2731. autoconnect = "yes";
  2732. },
  2733. #+END_SRC
  2734. If you're not using a self-signed certificate (self-signed is the default) then you can set *ssl_verify* to "yes".
  2735. By default irssi will use UTC time. An example of setting to some other time zone is as follows:
  2736. #+BEGIN_SRC: bash
  2737. echo "load perl" >> ~/.irssi/startup
  2738. echo "script exec $ENV{'TZ'}='Europe/London';" >> ~/.irssi/startup
  2739. #+END_SRC
  2740. Also enable /Off The Record/ (OTR) messaging.
  2741. #+BEGIN_SRC: bash
  2742. echo "load otr" >> ~/.irssi/startup
  2743. #+END_SRC
  2744. By default Irssi does not look especially attractive. To improve it's looks:
  2745. #+BEGIN_SRC: bash
  2746. cd ~/.irssi
  2747. wget http://freedombone.uk.to/irssi/xchat.theme
  2748. mkdir ~/.irssi/scripts
  2749. mkdir ~/.irssi/scripts/autorun
  2750. cd ~/.irssi/scripts/autorun
  2751. wget http://freedombone.uk.to/irssi/xchatnickcolor.pl
  2752. wget http://freedombone.uk.to/irssi/adv_windowlist.pl
  2753. #+END_SRC
  2754. Verify the files:
  2755. #+BEGIN_SRC: bash
  2756. sha256sum ~/.irssi/xchat.theme
  2757. 7a84130ad55aabd0b043a03b013628438e6c7f82a58e15267633bc7eb443e60b
  2758. sha256sum ~/.irssi/scripts/autorun/xchatnickcolor.pl
  2759. 8293e867a22d42ce5a28cd755237509b6f3587fd2b21d7d20af4a832081610ca
  2760. sha256sum ~/.irssi/scripts/autorun/adv_windowlist.pl
  2761. e4dd8f6d384bf4f2d0ab5ccf06df06e4a69d2647b08d37c8fc6cfd9326688395
  2762. #+END_SRC
  2763. Then run Irssi and enter the commands:
  2764. #+BEGIN_SRC: bash
  2765. /set theme xchat
  2766. /statusbar window remove act
  2767. /set awl
  2768. /set awl_block -14
  2769. /set awl_display_key $Q%K|$N%n $H$C$S
  2770. /set awl_display_key_active $Q%K|$N%n $H%U$C%n$S
  2771. /set awl_display_nokey [$N]$H$C$S
  2772. /run autorun/adv_windowlist.pl
  2773. /set awl_viewer off
  2774. /save
  2775. #+END_SRC
  2776. *** Using irssi with Off The Record messaging (OTR)
  2777. Once you're running irssi then you can enable OTR with:
  2778. #+BEGIN_SRC: bash
  2779. /statusbar window add otr
  2780. /otr genkey mynick@network (for example mynick@irc.freenode.net)
  2781. #+END_SRC
  2782. Then to see your OTR fingerprint:
  2783. #+BEGIN_SRC: bash
  2784. /otr info
  2785. #+END_SRC
  2786. And to trust or distrust someone else's fingerprint.
  2787. #+BEGIN_SRC: bash
  2788. /otr trust [fingerprint]
  2789. /otr distrust [fingerprint]
  2790. #+END_SRC
  2791. *** Usage with XChat
  2792. Within the network list click, *Add* and enter your domain name then click *Edit*.
  2793. Select the entry within the servers box, then enter *mydomainname.com/6697* and press *Enter*.
  2794. Uncheck *use global user information*.
  2795. Enter first and second nicknames and check *auto connect to this network on startup*.
  2796. Check *use SSL* and *accept invalid SSL certificate*.
  2797. Enter some favourite channels and within *server password* enter /mysendacceptpassword/ which you defined earlier when setting up the server.
  2798. Click *close* and then *connect*.
  2799. *** Install Irssi as a daemon
  2800. 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.
  2801. First install some prerequisites.
  2802. #+BEGIN_SRC: bash
  2803. apt-get install irssi irssi-plugin-otr irssi-plugin-xmpp screen
  2804. #+END_SRC
  2805. Create an initialisation script.
  2806. #+BEGIN_SRC: bash
  2807. editor /etc/init.d/irssid
  2808. #+END_SRC
  2809. Add the following:
  2810. #+BEGIN_SRC: bash
  2811. #!/bin/bash
  2812. ### BEGIN INIT INFO
  2813. # Provides: irssid
  2814. # Required-Start: $network
  2815. # Required-Stop: $network
  2816. # Default-Start: 2 3 4 5
  2817. # Default-Stop: 0 1 6
  2818. # Short-Description: Start irssi daemon within screen session at boot time
  2819. # Description: This init script will start an irssi session under screen using the settings provided in /etc/irssid.conf
  2820. ### END INIT INFO
  2821. # Include the LSB library functions
  2822. . /lib/lsb/init-functions
  2823. # Setup static variables
  2824. configFile='/etc/irssid.conf'
  2825. daemonExec='/usr/bin/screen'
  2826. daemonArgs='-D -m'
  2827. daemonName="$(basename "$daemonExec")"
  2828. pidFile='/var/run/irssid.pid'
  2829. #
  2830. # Checks if the environment is capable of running the script (such as
  2831. # availability of programs etc).
  2832. #
  2833. # Return: 0 if the environmnt is properly setup for execution of init script, 1
  2834. # if not all conditions have been met.
  2835. #
  2836. function checkEnvironment() {
  2837. # Verify that the necessary binaries are available for execution.
  2838. local binaries=(irssi screen)
  2839. for bin in "${binaries[@]}"; do
  2840. if ! which "$bin" > /dev/null; then
  2841. log_failure_msg "Binary '$bin' is not available. Please install \
  2842. package containing it."
  2843. exit 5
  2844. fi
  2845. done
  2846. }
  2847. #
  2848. # Checks if the configuration files are available and properly setup.
  2849. #
  2850. # Return: 0 if irssid if properly configured, 1 otherwise.
  2851. #
  2852. function checkConfig() {
  2853. # Make sure the configuration file has been created
  2854. if ! [[ -f $configFile ]]; then
  2855. log_failure_msg "Please populate the configuration file '$configFile' \
  2856. before running."
  2857. exit 6
  2858. fi
  2859. # Make sure the required options have been set
  2860. local reqOptions=(user group session)
  2861. for option in "${reqOptions[@]}"; do
  2862. if ! grep -q -e "^[[:blank:]]*$option=" "$configFile"; then
  2863. log_failure_msg "Mandatory option '$option' was not specified in \
  2864. '$configFile'"
  2865. exit 6
  2866. fi
  2867. done
  2868. }
  2869. #
  2870. # Loads the configuration file and performs any additional configuration steps.
  2871. #
  2872. function configure() {
  2873. . "$configFile"
  2874. daemonArgs="$daemonArgs -S $session irssi"
  2875. [[ -n $args ]] && daemonArgs="$daemonArgs $args"
  2876. daemonCommand="$daemonExec $daemonArgs"
  2877. }
  2878. #
  2879. # Starts the daemon.
  2880. #
  2881. # Return: LSB-compliant code.
  2882. #
  2883. function start() {
  2884. 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
  2885. }
  2886. #
  2887. # Stops the daemon.
  2888. #
  2889. # Return: LSB-compliant code.
  2890. #
  2891. function stop() {
  2892. start-stop-daemon --stop -x /bin/su -p /tmp/irssi.screen.session -q
  2893. }
  2894. checkEnvironment
  2895. checkConfig
  2896. configure
  2897. case "$1" in
  2898. start)
  2899. log_daemon_msg "Starting daemon" "irssid"
  2900. start && log_end_msg 0 || log_end_msg $?
  2901. ;;
  2902. stop)
  2903. log_daemon_msg "Stopping daemon" "irssid"
  2904. stop && log_end_msg 0 || log_end_msg $?
  2905. ;;
  2906. restart)
  2907. log_daemon_msg "Restarting daemon" "irssid"
  2908. stop
  2909. start && log_end_msg 0 || log_end_msg $?
  2910. ;;
  2911. force-reload)
  2912. log_daemon_msg "Restarting daemon" "irssid"
  2913. stop
  2914. start && log_end_msg 0 || log_end_msg $?
  2915. ;;
  2916. status)
  2917. status_of_proc -p "$pidFile" "$daemonExec" screen && exit 0 || exit $?
  2918. ;;
  2919. *)
  2920. echo "irssid (start|stop|restart|force-reload|status|help)"
  2921. ;;
  2922. esac
  2923. #+END_SRC
  2924. Save and exit.
  2925. #+BEGIN_SRC: bash
  2926. chmod +x /etc/init.d/irssid
  2927. #+END_SRC
  2928. Create a configuration file, replacing /myusername/ with your username.
  2929. #+BEGIN_SRC: bash
  2930. editor /etc/irssid.conf
  2931. #+END_SRC
  2932. #+BEGIN_SRC: bash
  2933. #
  2934. # Configuration file for irssid init script
  2935. #
  2936. # Mandatory options:
  2937. #
  2938. # user - Specify user for running irssi.
  2939. # group - Specify group for running irssi.
  2940. # session - Specify screen session name to be used for irssi.
  2941. #
  2942. # Non-mandatory options:
  2943. #
  2944. # args - Pass additional arguments to irssi.
  2945. #
  2946. user='myusername'
  2947. group='irssi'
  2948. session='irssi'
  2949. args='--config /home/myusername/.irssi/config'
  2950. #+END_SRC
  2951. Save and exit. Then add your user to the irssi group and start the daemon.
  2952. #+BEGIN_SRC: bash
  2953. groupadd irssi
  2954. usermod -aG irssi myusername
  2955. update-rc.d irssid defaults
  2956. chown -R myusername:irssi /home/myusername/.irssi
  2957. service irssid start
  2958. #+END_SRC
  2959. Create a script to make running IRC on the server easier.
  2960. #+BEGIN_SRC: bash
  2961. editor /usr/bin/irc
  2962. #+END_SRC
  2963. Add the following:
  2964. #+BEGIN_SRC: bash
  2965. #!/bin/bash
  2966. screen -r irssi
  2967. #+END_SRC
  2968. Save and exit.
  2969. #+BEGIN_SRC: bash
  2970. chmod +x /usr/bin/irc
  2971. chown myusername:myusername /usr/bin/irc
  2972. #+END_SRC
  2973. Then to subsequently access irssi log into the BBB using ssh and type:
  2974. #+BEGIN_SRC: bash
  2975. irc
  2976. #+END_SRC
  2977. To set UK time within Irssi:
  2978. #+BEGIN_SRC: bash
  2979. /script exec $ENV{'TZ'}='Europe/London';
  2980. /save
  2981. #+END_SRC
  2982. ** Install a Jabber/XMPP server
  2983. #+BEGIN_VERSE
  2984. /Well heck, it isn’t that hard to write an instant messaging system./
  2985. --Jeremie Miller
  2986. #+END_VERSE
  2987. *** The Server
  2988. Generate a SSL certificate.
  2989. #+BEGIN_SRC: bash
  2990. makecert xmpp
  2991. chown prosody:prosody /etc/ssl/private/xmpp.key
  2992. chown prosody:prosody /etc/ssl/certs/xmpp.*
  2993. #+END_SRC
  2994. Install Prosody.
  2995. #+BEGIN_SRC: bash
  2996. apt-get install prosody
  2997. chown prosody:prosody /etc/ssl/private/xmpp.key
  2998. chown prosody:prosody /etc/ssl/certs/xmpp.crt
  2999. cp -a /etc/prosody/conf.avail/example.com.cfg.lua /etc/prosody/conf.avail/xmpp.cfg.lua
  3000. editor /etc/prosody/conf.avail/xmpp.cfg.lua
  3001. #+END_SRC
  3002. Change the *VirtualHost* name to your domain name and remove the line below it.
  3003. Set the ssl section to:
  3004. #+BEGIN_SRC: bash
  3005. ssl = {
  3006. key = "/etc/ssl/private/xmpp.key";
  3007. certificate = "/etc/ssl/certs/xmpp.crt";
  3008. dhparam = "/etc/ssl/certs/xmpp.dhparam";
  3009. }
  3010. #+END_SRC
  3011. And also append the following:
  3012. #+BEGIN_SRC: bash
  3013. modules_enabled = {
  3014. "bosh"; -- Enable mod_bosh
  3015. "tls"; -- Enable mod_tls
  3016. }
  3017. c2s_require_encryption = true
  3018. s2s_require_encryption = true
  3019. #+END_SRC
  3020. Save and exit. Create a symbolic link.
  3021. #+BEGIN_SRC: bash
  3022. ln -sf /etc/prosody/conf.avail/xmpp.cfg.lua /etc/prosody/conf.d/xmpp.cfg.lua
  3023. editor /etc/prosody/prosody.cfg.lua
  3024. #+END_SRC
  3025. Within the *ssl* section set:
  3026. #+BEGIN_SRC: bash
  3027. ssl = {
  3028. key = "/etc/ssl/private/xmpp.key";
  3029. certificate = "/etc/ssl/certs/xmpp.crt";
  3030. }
  3031. #+END_SRC
  3032. Uncomment and set the following to *true*
  3033. #+BEGIN_SRC: bash
  3034. c2s_require_encryption = true
  3035. s2s_require_encryption = true
  3036. #+END_SRC
  3037. Within the *modules_enabled* section uncomment *bosh*, then save and exit.
  3038. 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).
  3039. #+BEGIN_SRC: bash
  3040. prosodyctl adduser myusername@mydomainname.com
  3041. #+END_SRC
  3042. Restart the server
  3043. #+BEGIN_SRC: bash
  3044. service prosody restart
  3045. #+END_SRC
  3046. On your internet router/firewall open ports 5222, 5223, 5269, 5280 and 5281 and forward them to the BBB.
  3047. 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.
  3048. *** Managing users
  3049. To add a user:
  3050. #+BEGIN_SRC: bash
  3051. prosodyctl adduser myusername@mydomainname.com
  3052. #+END_SRC
  3053. To change a user password:
  3054. #+BEGIN_SRC: bash
  3055. prosodyctl passwd myusername@mydomainname.com
  3056. #+END_SRC
  3057. To remove a user:
  3058. #+BEGIN_SRC: bash
  3059. prosodyctl deluser myusername@mydomainname.com
  3060. #+END_SRC
  3061. Report the status of the XMPP server:
  3062. #+BEGIN_SRC: bash
  3063. prosodyctl status
  3064. #+END_SRC
  3065. *** Using with Jitsi
  3066. 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.
  3067. Jitsi can be downloaded from https://jitsi.org/
  3068. On your desktop/laptop open Jitsi and select *Options* from the *Tools* menu.
  3069. 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).
  3070. 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.
  3071. 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.
  3072. You can also [[https://www.youtube.com/watch?v=vgx7VSrDGjk][see this video]] as an example of using OTR.
  3073. *** Using with Ubuntu
  3074. 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.
  3075. Open *System Settings* and select *Online Accounts*, *Add account* and then *Jabber*.
  3076. Enter your username (myusername@mydomainname.com) and password.
  3077. 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*.
  3078. *** Using with Android
  3079. There are a few XMPP clients available on Android. Ideally choose ones which support off-the-record messaging. Here are some examples.
  3080. **** Xabber
  3081. Install [[https://f-droid.org/][F-Droid]]
  3082. Search for and install Xabber.
  3083. Add an account and enter your Jabber/XMPP ID and password.
  3084. From the menu select *Settings* then *Security* then *OTR mode*. Set the mode to *Required*.
  3085. Make sure that *Check server certificate* is not checked.
  3086. 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.
  3087. **** Gibberbot
  3088. Install [[https://f-droid.org/][F-Droid]]
  3089. Search for and install Gibberbot, otherwise known as ChatSecure.
  3090. From the menu open *Accounts*
  3091. Select *Add account*
  3092. Change the server port from 0 to 5222
  3093. Done
  3094. Accept unknown certificate? Select *Always*
  3095. Go back to the initial screen and then using the menu you can add contacts and begin chatting.
  3096. ** Social Networking
  3097. #+BEGIN_VERSE
  3098. /Facebook is not your friend, it is a surveillance engine./
  3099. -- Richard Stallman, Free Software Foundation
  3100. #+END_VERSE
  3101. *** Friendica
  3102. **** Installation
  3103. See [[Setting up a web site]] for details of how to update a web server 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.
  3104. Edit your web server configuration:
  3105. #+BEGIN_SRC: bash
  3106. editor /etc/nginx/sites-available/myfriendicadomainname.com
  3107. #+END_SRC
  3108. Replace the section which begins with "listen 80" with the following:
  3109. #+BEGIN_SRC: bash
  3110. server {
  3111. listen 80;
  3112. rewrite ^ https://$server_name$request_uri? permanent;
  3113. }
  3114. #+END_SRC
  3115. Save and exit, then restart the web server.
  3116. #+BEGIN_SRC: bash
  3117. service nginx restart
  3118. #+END_SRC
  3119. Now install some dependencies.
  3120. #+BEGIN_SRC: bash
  3121. apt-get install mysql-server php5-common php5-cli php5-curl php5-gd php5-mysql php5-mcrypt php5-fpm php5-cgi php-apc
  3122. #+END_SRC
  3123. If you are installing /mysql-server/ for the first time then enter an admin password.
  3124. Reduce the memory use of mysql by using the "small" configuration.
  3125. #+BEGIN_SRC: bash
  3126. cp /usr/share/doc/mysql-server-5.5/examples/my-small.cnf /etc/mysql/my.cnf
  3127. #+END_SRC
  3128. Create a mysql database, replacing /myfriendicapassword/ with a password used to administer the friendica database.
  3129. #+BEGIN_SRC: bash
  3130. mysql -u root -p
  3131. create database friendica;
  3132. CREATE USER 'friendicaadmin'@'localhost' IDENTIFIED BY 'myfriendicapassword';
  3133. GRANT ALL PRIVILEGES ON friendica.* TO 'friendicaadmin'@'localhost';
  3134. quit
  3135. #+END_SRC
  3136. You may need to fix Git SSL problems.
  3137. #+BEGIN_SRC: bash
  3138. git config --global http.sslVerify true
  3139. apt-get install ca-certificates
  3140. cd ~/
  3141. editor .gitconfig
  3142. #+END_SRC
  3143. The .gitconfig file should look something like this:
  3144. #+BEGIN_SRC: bash
  3145. [user]
  3146. name = yourname
  3147. email = myusername@mydomainname.com
  3148. [http]
  3149. sslVerify = true
  3150. sslCAinfo = /etc/ssl/certs/ca-certificates.crt
  3151. #+END_SRC
  3152. Get the source code.
  3153. #+BEGIN_SRC: bash
  3154. export HOSTNAME=myfriendicadomainname.com
  3155. cd /var/www/$HOSTNAME
  3156. rm -rf htdocs
  3157. git clone https://github.com/friendica/friendica.git htdocs
  3158. chmod -R 755 htdocs
  3159. chown -R www-data:www-data htdocs
  3160. chown -R www-data:www-data htdocs/view/smarty3
  3161. git clone https://github.com/friendica/friendica-addons.git htdocs/addon
  3162. #+END_SRC
  3163. Now visit the URL of your site and you should be taken through the rest of the installation procedure.
  3164. | Database Server Name | localhost |
  3165. | Database login name | friendicaadmin |
  3166. | Database Login Password | myfriendicapassword |
  3167. | Database Name | friendica |
  3168. 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.
  3169. Install the poller.
  3170. #+BEGIN_SRC: bash
  3171. editor /etc/crontab
  3172. #+END_SRC
  3173. and append the following, changing /myfriendicadomainname.com/ to whatever your Friendica domain is.
  3174. #+BEGIN_SRC: bash
  3175. */10 * * * * root cd /var/www/myfriendicadomainname.com/htdocs; /usr/bin/timeout 120 /usr/bin/php include/poller.php
  3176. #+END_SRC
  3177. Save and exit, then restart cron.
  3178. #+BEGIN_SRC: bash
  3179. service cron restart
  3180. #+END_SRC
  3181. You can improve the speed of Friendica database searches by adding the following indexes:
  3182. #+BEGIN_SRC: bash
  3183. mysql -u root -p
  3184. use friendica;
  3185. CREATE INDEX `uri_received` ON item(`uri`, `received`);
  3186. CREATE INDEX `received_uri` ON item(`received`, `uri`);
  3187. CREATE INDEX `contact-id_created` ON item(`contact-id`, created);
  3188. CREATE INDEX `uid_network_received` ON item(`uid`, `network`, `received`);
  3189. CREATE INDEX `uid_parent` ON item(`uid`, `parent`);
  3190. CREATE INDEX `uid_received` ON item(`uid`, `received`);
  3191. CREATE INDEX `uid_network_commented` ON item(`uid`, `network`, `commented`);
  3192. CREATE INDEX `uid_title` ON item(uid, `title`);
  3193. CREATE INDEX `created_contact-id` ON item(`created`, `contact-id`);
  3194. quit
  3195. #+END_SRC
  3196. Make sure that Friendica doesn't use too much memory.
  3197. #+BEGIN_SRC: bash
  3198. editor /var/www/$HOSTNAME/htdocs/.htaccess
  3199. #+END_SRC
  3200. Append the following:
  3201. #+BEGIN_SRC: bash
  3202. php_value memory_limit 32M
  3203. #+END_SRC
  3204. The save ane exit.
  3205. **** Backups
  3206. 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.
  3207. #+BEGIN_SRC: bash
  3208. editor /etc/cron.daily/backup
  3209. #+END_SRC
  3210. Enter the following, replacing /myusername@mydomainname.com/ with your email address and the mysql root password as appropriate.
  3211. #+BEGIN_SRC: bash
  3212. #!/bin/sh
  3213. EMAIL=myusername@mydomainname.com
  3214. MYSQL_PASSWORD=<mysql root password>
  3215. umask 0077
  3216. # stop the web server to avoid any changes to the databases during backup
  3217. service nginx stop
  3218. # Save to a temporary file first so that it can be checked for non-zero size
  3219. TEMPFILE=/tmp/friendicared.sql
  3220. # Backup the Friendica database
  3221. DAILYFILE=/var/backups/friendica_daily.sql
  3222. mysqldump --password=$MYSQL_PASSWORD friendica > $TEMPFILE
  3223. FILESIZE=$(stat -c%s $TEMPFILE)
  3224. if [ "$FILESIZE" -eq "0" ]; then
  3225. if [ -f $DAILYFILE ]; then
  3226. cp $DAILYFILE $TEMPFILE
  3227. # try to restore yesterday's database
  3228. mysql -u root --password=$MYSQL_PASSWORD friendica -o < $DAILYFILE
  3229. # Send a warning email
  3230. echo "Unable to create a backup of the Friendica database. Attempted to restore from yesterday's backup." | mail -s "Friendica backup" $EMAIL
  3231. else
  3232. # Send a warning email
  3233. echo "Unable to create a backup of the Friendica database." | mail -s "Friendica backup" $EMAIL
  3234. fi
  3235. else
  3236. chmod 600 $TEMPFILE
  3237. mv $TEMPFILE $DAILYFILE
  3238. # Make the backup readable only by root
  3239. chmod 600 $DAILYFILE
  3240. fi
  3241. # Backup the Roundcube database
  3242. DAILYFILE=/var/backups/roundcubemail_daily.sql
  3243. mysqldump --password=$MYSQL_PASSWORD roundcubemail > $TEMPFILE
  3244. FILESIZE=$(stat -c%s $TEMPFILE)
  3245. if [ "$FILESIZE" -eq "0" ]; then
  3246. if [ -f $DAILYFILE ]; then
  3247. cp $DAILYFILE $TEMPFILE
  3248. # try to restore yesterday's database
  3249. mysql -u root --password=$MYSQL_PASSWORD roundcubemail -o < $DAILYFILE
  3250. # Send a warning email
  3251. echo "Unable to create a backup of the Roundcube database. Attempted to restore from yesterday's backup" | mail -s "Roundcube backup" $EMAIL
  3252. else
  3253. # Send a warning email
  3254. echo "Unable to create a backup of the Roundcube database." | mail -s "Roundcube backup" $EMAIL
  3255. fi
  3256. else
  3257. chmod 600 $TEMPFILE
  3258. mv $TEMPFILE $DAILYFILE
  3259. # Make the backup readable only by root
  3260. chmod 600 $DAILYFILE
  3261. fi
  3262. # Backup the Red Matrix database
  3263. DAILYFILE=/var/backups/redmatrix_daily.sql
  3264. #mysqldump --password=$MYSQL_PASSWORD redmatrix > $TEMPFILE
  3265. #FILESIZE=$(stat -c%s $TEMPFILE)
  3266. #if [ "$FILESIZE" -eq "0" ]; then
  3267. # if [ -f $DAILYFILE ]; then
  3268. # cp $DAILYFILE $TEMPFILE
  3269. # # try to restore yesterday's database
  3270. # mysql -u root --password=$MYSQL_PASSWORD redmatrix -o < $DAILYFILE
  3271. # # Send a warning email
  3272. # echo "Unable to create a backup of the Red Matrix database. Attempted to restore from yesterday's backup" | mail -s "Red Matrix backup" $EMAIL
  3273. # else
  3274. # # Send a warning email
  3275. # echo "Unable to create a backup of the Red Matrix database." | mail -s "Red Matrix backup" $EMAIL
  3276. # fi
  3277. #else
  3278. # chmod 600 $TEMPFILE
  3279. # mv $TEMPFILE $DAILYFILE
  3280. # # Make the backup readable only by root
  3281. # chmod 600 $DAILYFILE
  3282. #fi
  3283. # restart the web server
  3284. service nginx start
  3285. exit 0
  3286. #+END_SRC
  3287. Save and exit.
  3288. #+BEGIN_SRC: bash
  3289. chmod 600 /etc/cron.daily/backup
  3290. chmod +x /etc/cron.daily/backup
  3291. editor /etc/cron.weekly/backup
  3292. #+END_SRC
  3293. Enter the following
  3294. #+BEGIN_SRC: bash
  3295. #!/bin/sh
  3296. umask 0077
  3297. # Friendica
  3298. cp -f /var/backups/friendica_weekly.sql /var/backups/friendica_2weekly.sql
  3299. cp -f /var/backups/friendica_daily.sql /var/backups/friendica_weekly.sql
  3300. # Roundcube
  3301. cp -f /var/backups/roundcubemail_weekly.sql /var/backups/roundcubemail_2weekly.sql
  3302. cp -f /var/backups/roundcubemail_daily.sql /var/backups/roundcubemail_weekly.sql
  3303. # Red Matrix
  3304. #cp -f /var/backups/redmatrix_weekly.sql /var/backups/redmatrix_2weekly.sql
  3305. #cp -f /var/backups/redmatrix_daily.sql /var/backups/redmatrix_weekly.sql
  3306. #+END_SRC
  3307. Save and exit.
  3308. #+BEGIN_SRC: bash
  3309. chmod 600 /etc/cron.weekly/backup
  3310. chmod +x /etc/cron.weekly/backup
  3311. editor /etc/cron.monthly/backup
  3312. #+END_SRC
  3313. Enter the following
  3314. #+BEGIN_SRC: bash
  3315. #!/bin/sh
  3316. # Friendica
  3317. cp -f /var/backups/friendica_monthly.sql /var/backups/friendica_2monthly.sql
  3318. cp -f /var/backups/friendica_weekly.sql /var/backups/friendica_monthly.sql
  3319. # Roundcube
  3320. cp -f /var/backups/roundcubemail_monthly.sql /var/backups/roundcubemail_2monthly.sql
  3321. cp -f /var/backups/roundcubemail_weekly.sql /var/backups/roundcubemail_monthly.sql
  3322. # Red Matrix
  3323. #cp -f /var/backups/redmatrix_monthly.sql /var/backups/redmatrix_2monthly.sql
  3324. #cp -f /var/backups/redmatrix_weekly.sql /var/backups/redmatrix_monthly.sql
  3325. #+END_SRC
  3326. Save and exit.
  3327. #+BEGIN_SRC: bash
  3328. chmod 600 /etc/cron.monthly/backup
  3329. chmod +x /etc/cron.monthly/backup
  3330. #+END_SRC
  3331. **** Recommended configuration
  3332. ***** Admin
  3333. 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.
  3334. 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.
  3335. Under the *themes* section select a few themes, including mobile themes which are suitable for phones or tablets.
  3336. 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.
  3337. If you also wish to publish your public posts to a Diaspora node then within the *site* settings select *enable Diaspora support*.
  3338. 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]].
  3339. ***** Settings
  3340. Each user has their own customisable settings, typically available either via an icon or by an entry on a drop down menu.
  3341. Under *additional features* enable "/richtext editor/", "/post preview/", "/group filter/", "/network filter/", "/edit sent posts/" and "/dislike posts/".
  3342. Under *display settings* select your desktop and mobile themes.
  3343. 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.
  3344. **** To access from an Android device
  3345. ***** App
  3346. 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.
  3347. 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.
  3348. More information about the Friendica app can be found on http://friendica-for-android.wiki-lab.net/
  3349. ***** Mobile Theme
  3350. 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.
  3351. *** Movim
  3352. #+BEGIN_VERSE
  3353. /The way we communicate with others and with ourselves ultimately determines the quality of our lives/
  3354. -- Anthony Robbins
  3355. #+END_VERSE
  3356. Movim is another social networking system based around the XMPP protocol.
  3357. You will need to have previously [[Install a Jabber/XMPP server][installed the Jabber/XMPP server]].
  3358. 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:
  3359. #+BEGIN_SRC: bash
  3360. editor /etc/apache2/sites-available/mydomainname.com
  3361. #+END_SRC
  3362. Within the section which begins with *<VirtualHost *:80>* add the following:
  3363. #+BEGIN_SRC: bash
  3364. <Directory /var/www/mydomainname.com/htdocs/movim>
  3365. deny from all
  3366. </Directory>
  3367. #+END_SRC
  3368. Within the section which begins with *<VirtualHost *:443>* add the following:
  3369. #+BEGIN_SRC: bash
  3370. <Directory /var/www/mydomainname.com/htdocs/movim>
  3371. Options Indexes FollowSymLinks MultiViews
  3372. AllowOverride All
  3373. Order allow,deny
  3374. allow from all
  3375. </Directory>
  3376. #+END_SRC
  3377. Save and exit, then restart the apache server.
  3378. #+BEGIN_SRC: bash
  3379. service apache2 restart
  3380. #+END_SRC
  3381. Download the source.
  3382. #+BEGIN_SRC: bash
  3383. mkdir ~/build
  3384. cd ~/build
  3385. wget http://freedombone.uk.to/movim.tar.gz
  3386. #+END_SRC
  3387. Verify it.
  3388. #+BEGIN_SRC: bash
  3389. sha256sum movim.tar.gz
  3390. 2740ddbedf6cefcc2934759374376643b6cdea4fb7f944ec25098a6868cb499e movim.tar.gz
  3391. #+END_SRC
  3392. Install it.
  3393. #+BEGIN_SRC: bash
  3394. tar -xzvf movim.tar.gz
  3395. export HOSTNAME=mydomainname.com
  3396. cp -r movim-* /var/www/$HOSTNAME/htdocs/movim
  3397. chmod 755 /var/www/$HOSTNAME/htdocs/movim
  3398. chown -R www-data:www-data /var/www/$HOSTNAME/htdocs/movim
  3399. #+END_SRC
  3400. Install some MySql prerequisites.
  3401. #+BEGIN_SRC: bash
  3402. apt-get install mysql-server php5-common php5-cli php5-curl php5-gd php5-mysql php5-mcrypt
  3403. #+END_SRC
  3404. If necessary, enter an admin password for MySQL.
  3405. Reduce the memory use of mysql by using the "small" configuration.
  3406. #+BEGIN_SRC: bash
  3407. cp /usr/share/doc/mysql-server-5.5/examples/my-small.cnf /etc/mysql/my.cnf
  3408. #+END_SRC
  3409. Create a mysql database.
  3410. #+BEGIN_SRC: bash
  3411. mysql -u root -p
  3412. create database movim;
  3413. CREATE USER 'movimadmin'@'localhost' IDENTIFIED BY 'movimadminpassword';
  3414. GRANT ALL PRIVILEGES ON movim.* TO 'movimadmin'@'localhost';
  3415. quit
  3416. #+END_SRC
  3417. With a web browser navigate to:
  3418. https://mydomainname.com/movim/admin
  3419. Enter /admin/ as the username and /password/ as the password.
  3420. 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).
  3421. Change the /Environment/ from /Development/ to /Production/.
  3422. 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?)
  3423. Click /Submit/ followed by /Resend/.
  3424. Click on /Database Settings/ and alter the MySql movim database username to /movimadmin/ and password to the password you specified in the previous step.
  3425. 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".
  3426. 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).
  3427. *** Red Matrix
  3428. **** Introduction
  3429. 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.
  3430. **** Prerequisites
  3431. 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.
  3432. 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.
  3433. **** Installation
  3434. 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.
  3435. 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:
  3436. #+BEGIN_SRC: bash
  3437. editor /etc/apache2/sites-available/mydomainname.com
  3438. #+END_SRC
  3439. Replace the section which begins with *<VirtualHost *:80>* with the following:
  3440. #+BEGIN_SRC: bash
  3441. <VirtualHost *:80>
  3442. ServerAdmin myusername@mydomainname.com
  3443. ServerName myredmatrixdomainname.com
  3444. RewriteEngine On
  3445. RewriteCond %{HTTPS} off
  3446. RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
  3447. </VirtualHost>
  3448. #+END_SRC
  3449. Save and exit, then restart the apache server.
  3450. #+BEGIN_SRC: bash
  3451. service apache2 restart
  3452. #+END_SRC
  3453. Now install some dependencies.
  3454. #+BEGIN_SRC: bash
  3455. apt-get install mysql-server php5-common php5-cli php5-curl php5-gd php5-mysql php5-mcrypt
  3456. #+END_SRC
  3457. Enter an admin password for MySQL.
  3458. Reduce the memory use of mysql by using the "small" configuration.
  3459. #+BEGIN_SRC: bash
  3460. cp /usr/share/doc/mysql-server-5.5/examples/my-small.cnf /etc/mysql/my.cnf
  3461. #+END_SRC
  3462. Create a mysql database.
  3463. #+BEGIN_SRC: bash
  3464. mysql -u root -p
  3465. create database redmatrix;
  3466. CREATE USER 'redmatrixadmin'@'localhost' IDENTIFIED BY 'password';
  3467. GRANT ALL PRIVILEGES ON redmatrix.* TO 'redmatrixadmin'@'localhost';
  3468. quit
  3469. #+END_SRC
  3470. You may need to fix Git SSL problems.
  3471. #+BEGIN_SRC: bash
  3472. git config --global http.sslVerify true
  3473. apt-get install ca-certificates
  3474. cd ~/
  3475. editor .gitconfig
  3476. #+END_SRC
  3477. The .gitconfig file should look something like this:
  3478. #+BEGIN_SRC: bash
  3479. [http]
  3480. sslVerify = true
  3481. sslCAinfo = /etc/ssl/certs/ca-certificates.crt
  3482. [user]
  3483. email = myusername@mydomainname.com
  3484. name = yourname
  3485. #+END_SRC
  3486. Get the source code.
  3487. #+BEGIN_SRC: bash
  3488. export HOSTNAME=mydomainname.com
  3489. mkdir /var/www/$HOSTNAME
  3490. cd /var/www/$HOSTNAME
  3491. rm -rf htdocs
  3492. git clone https://github.com/friendica/red.git htdocs
  3493. chmod -R 755 htdocs
  3494. chown -R www-data:www-data htdocs
  3495. mkdir htdocs/view/tpl/smarty3
  3496. mkdir htdocs/store/[data]
  3497. mkdir htdocs/store/[data]/smarty3
  3498. chmod 777 htdocs/view/tpl
  3499. chmod 777 htdocs/view/tpl/smarty3
  3500. chmod 777 htdocs/store/[data]/smarty3
  3501. git clone https://github.com/friendica/red-addons.git htdocs/addon
  3502. #+END_SRC
  3503. 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.
  3504. Install the poller.
  3505. #+BEGIN_SRC
  3506. editor /etc/crontab
  3507. #+END_SRC
  3508. and append the following, changing /mydomainname.com/ to whatever your domain is.
  3509. #+BEGIN_SRC
  3510. 12,22,32,42,52 * * * * root cd /var/www/mydomainname.com/htdocs; /usr/bin/timeout 240 /usr/bin/php include/poller.php
  3511. #+END_SRC
  3512. Save and exit, then restart cron.
  3513. #+BEGIN_SRC: bash
  3514. service cron restart
  3515. #+END_SRC
  3516. **** Backups
  3517. 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.
  3518. #+BEGIN_SRC: bash
  3519. editor /etc/cron.daily/backup
  3520. #+END_SRC
  3521. 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.
  3522. #+BEGIN_SRC: bash
  3523. chmod 600 /etc/cron.daily/backup
  3524. chmod +x /etc/cron.daily/backup
  3525. editor /etc/cron.weekly/backup
  3526. #+END_SRC
  3527. 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:
  3528. #+BEGIN_SRC: bash
  3529. #!/bin/sh
  3530. umask 0077
  3531. # Friendica
  3532. cp -f /var/backups/friendica_weekly.sql /var/backups/friendica_2weekly.sql
  3533. cp -f /var/backups/friendica_daily.sql /var/backups/friendica_weekly.sql
  3534. # Red Matrix
  3535. cp -f /var/backups/redmatrix_weekly.sql /var/backups/redmatrix_2weekly.sql
  3536. cp -f /var/backups/redmatrix_daily.sql /var/backups/redmatrix_weekly.sql
  3537. #+END_SRC
  3538. Save and exit.
  3539. #+BEGIN_SRC: bash
  3540. chmod 600 /etc/cron.weekly/backup
  3541. chmod +x /etc/cron.weekly/backup
  3542. editor /etc/cron.monthly/backup
  3543. #+END_SRC
  3544. 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:
  3545. #+BEGIN_SRC: bash
  3546. #!/bin/sh
  3547. # Friendica
  3548. cp -f /var/backups/friendica_monthly.sql /var/backups/friendica_2monthly.sql
  3549. cp -f /var/backups/friendica_weekly.sql /var/backups/friendica_monthly.sql
  3550. # Red Matrix
  3551. cp -f /var/backups/redmatrix_monthly.sql /var/backups/redmatrix_2monthly.sql
  3552. cp -f /var/backups/redmatrix_weekly.sql /var/backups/redmatrix_monthly.sql
  3553. #+END_SRC
  3554. Save and exit.
  3555. #+BEGIN_SRC: bash
  3556. chmod 600 /etc/cron.monthly/backup
  3557. chmod +x /etc/cron.monthly/backup
  3558. #+END_SRC
  3559. **** To access from an Android device
  3560. ***** App
  3561. 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.
  3562. 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.
  3563. More information about the Friendica app can be found on http://friendica-for-android.wiki-lab.net/
  3564. *** pump.io
  3565. :PROPERTIES:
  3566. :ORDERED: t
  3567. :END:
  3568. 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.
  3569. 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.
  3570. #+BEGIN_SRC: bash
  3571. apt-get update
  3572. apt-get install build-essential openssl libssl-dev redis-server imagemagick graphicsmagick git-core screen
  3573. #+END_SRC
  3574. Download nodejs
  3575. #+BEGIN_SRC: bash
  3576. mkdir ~/build
  3577. cd ~/build
  3578. wget http://freedombone.uk.to/node_0.10.28-1_armhf.deb
  3579. #+END_SRC
  3580. Verify it.
  3581. #+BEGIN_SRC: bash
  3582. sha256sum node_0.10.28-1_armhf.deb
  3583. 42000a475d3397f295fe76998e79af999eebb8324ac9bb4981e931fabd9297aa
  3584. #+END_SRC
  3585. Install it.
  3586. #+BEGIN_SRC: bash
  3587. dpkg -i node_0.10.28-1_armhf.deb
  3588. #+END_SRC
  3589. Install pump.io
  3590. #+BEGIN_SRC: bash
  3591. cd /opt
  3592. git clone https://github.com/e14n/pump.io.git
  3593. cd /opt/pump.io
  3594. npm install
  3595. npm install databank-redis
  3596. echo "vm.overcommit_memory=1" >> /etc/sysctl.conf
  3597. sysctl vm.overcommit_memory=1
  3598. #+END_SRC
  3599. Now edit the configuration file.
  3600. #+BEGIN_SRC: bash
  3601. editor /etc/pump.io.json
  3602. #+END_SRC
  3603. Add the following, replacing /mypumpiodomainname.com/ with your domain name.
  3604. #+BEGIN_SRC: bash
  3605. {
  3606. "driver": "redis",
  3607. "params": {"host":"localhost","port":6379},
  3608. "secret": "A long random string",
  3609. "noweb": false,
  3610. "site": "Name of my pump.io site",
  3611. "owner": "My name or organisation",
  3612. "ownerURL": "https://mypumpiodomainname.com/",
  3613. "port": 7270,
  3614. "urlPort": 443,
  3615. "hostname": "mypumpiodomainname.com",
  3616. "address": "localhost",
  3617. "nologger": true,
  3618. "serverUser": "pumpio",
  3619. "rejectUnauthorized": false,
  3620. "key": "/var/local/pump.io/keys/mypumpiodomainname.com.key",
  3621. "cert": "/var/local/pump.io/keys/mypumpiodomainname.com.bundle.crt",
  3622. "uploaddir": "/var/local/pump.io/uploads",
  3623. "debugClient": false,
  3624. "firehose": "ofirehose.example",
  3625. "logfile": "/var/local/pump.io/pump.log",
  3626. "disableRegistration": false
  3627. }
  3628. #+END_SRC
  3629. Save and exit.
  3630. #+BEGIN_SRC: bash
  3631. export HOSTNAME=mypumpiodomainname.com
  3632. mkdir /var/local/pump.io
  3633. mkdir /var/local/pump.io/uploads
  3634. mkdir /var/local/pump.io/keys
  3635. cp /etc/ssl/private/$HOSTNAME.key /var/local/pump.io/keys
  3636. cp /etc/ssl/certs/$HOSTNAME.crt /var/local/pump.io/keys
  3637. cp /etc/ssl/certs/$HOSTNAME.bundle.crt /var/local/pump.io/keys
  3638. useradd -s /bin/bash -d /var/local/pump.io pumpio
  3639. chown -R pumpio:pumpio /var/local/pump.io
  3640. chmod 400 /var/local/pump.io/keys/*
  3641. chmod -R 777 /opt
  3642. #+END_SRC
  3643. Edit your web server configuration.
  3644. #+BEGIN_SRC: bash
  3645. editor /etc/nginx/sites-available/$HOSTNAME
  3646. #+END_SRC
  3647. Delete all existing contents then add the following:
  3648. #+BEGIN_SRC: bash
  3649. upstream pumpbackend {
  3650. server 127.0.0.1:7270 max_fails=3 fail_timeout=30s;
  3651. server 127.0.0.1:7270 max_fails=3 fail_timeout=60s;
  3652. server 127.0.0.1:7270 max_fails=3 fail_timeout=90s;
  3653. }
  3654. server {
  3655. listen 80;
  3656. server_name mypumpiodomainname.com;
  3657. rewrite ^ https://$server_name$request_uri? permanent;
  3658. }
  3659. map $http_upgrade $connection_upgrade {
  3660. default upgrade;
  3661. '' close;
  3662. }
  3663. server {
  3664. listen 443 ssl;
  3665. server_name mypumpiodomainname.com;
  3666. error_log /var/www/mypumpiodomainname.com/error.log debug;
  3667. ssl on;
  3668. ssl_certificate /etc/ssl/certs/mypumpiodomainname.com.bundle.crt;
  3669. ssl_certificate_key /etc/ssl/private/mypumpiodomainname.com.key;
  3670. ssl_dhparam /etc/ssl/certs/mypumpiodomainname.com.dhparam;
  3671. ssl_session_timeout 5m;
  3672. ssl_prefer_server_ciphers on;
  3673. ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # not possible to do exclusive
  3674. 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';
  3675. add_header X-Frame-Options DENY;
  3676. add_header X-Content-Type-Options nosniff;
  3677. add_header Strict-Transport-Security max-age=15768000;
  3678. # if you want to be able to access the site via HTTP
  3679. # then replace the above with the following:
  3680. # add_header Strict-Transport-Security "max-age=0;";
  3681. client_max_body_size 6m;
  3682. keepalive_timeout 75 75;
  3683. gzip_vary off;
  3684. location / {
  3685. proxy_pass https://pumpbackend;
  3686. proxy_http_version 1.1;
  3687. proxy_redirect off;
  3688. proxy_set_header Upgrade $http_upgrade;
  3689. proxy_set_header Connection $connection_upgrade;
  3690. proxy_set_header Host $http_host;
  3691. proxy_set_header X-Real-IP $remote_addr;
  3692. proxy_buffers 16 32k;
  3693. }
  3694. }
  3695. #+END_SRC
  3696. Save and exit.
  3697. #+BEGIN_SRC: bash
  3698. sed "s/mypumpiodomainname.com/$HOSTNAME/g" /etc/nginx/sites-available/$HOSTNAME > /tmp/website
  3699. cp -f /tmp/website /etc/nginx/sites-available/$HOSTNAME
  3700. service nginx restart
  3701. npm install forever -g
  3702. #+END_SRC
  3703. Now create the daemon.
  3704. #+BEGIN_SRC: bash
  3705. editor /etc/init.d/pumpio
  3706. #+END_SRC
  3707. Add the following text:
  3708. #+BEGIN_SRC: bash
  3709. #!/bin/bash
  3710. # /etc/init.d/pumpio
  3711. ### BEGIN INIT INFO
  3712. # Provides: pump.io
  3713. # Required-Start: $remote_fs $syslog
  3714. # Required-Stop: $remote_fs $syslog
  3715. # Default-Start: 2 3 4 5
  3716. # Default-Stop: 0 1 6
  3717. # Short-Description: starts pump.io as a background daemon
  3718. # Description: Starts pump.io on boot
  3719. ### END INIT INFO
  3720. # Author: Bob Mottram <bob@robotics.uk.to>
  3721. #Settings
  3722. SERVICE='pumpio'
  3723. COMMAND="forever /opt/pump.io/bin/pump > /var/local/pump.io/daemon.log"
  3724. USERNAME='pumpio'
  3725. NICELEVEL=19 # from 0-19 the bigger the number, the less the impact on system OAresources
  3726. HISTORY=1024
  3727. INVOCATION="nice -n ${NICELEVEL} ${COMMAND}"
  3728. PATH='/usr/local/sbin:/usr/local/bin:/usr/bin:/sbin:/usr/sbin:/bin:/var/local/pump.io'
  3729. pumpio_start() {
  3730. echo "Starting $SERVICE..."
  3731. su --command "screen -h ${HISTORY} -dmS ${SERVICE} ${INVOCATION}" $USERNAME
  3732. }
  3733. pumpio_stop() {
  3734. echo "Stopping $SERVICE"
  3735. su --command "screen -p 0 -S ${SERVICE} -X stuff "'^C'"" $USERNAME
  3736. }
  3737. #Start-Stop here
  3738. case "$1" in
  3739. start)
  3740. pumpio_start
  3741. ;;
  3742. stop)
  3743. pumpio_stop
  3744. ;;
  3745. restart)
  3746. pumpio_stop
  3747. sleep 10s
  3748. pumpio_start
  3749. ;;
  3750. *)
  3751. echo "Usage: $0 {start|stop|restart}"
  3752. exit 1
  3753. ;;
  3754. esac
  3755. exit 0
  3756. #+END_SRC
  3757. Save and exit. Then enable the daemon and run it.
  3758. #+BEGIN_SRC: bash
  3759. chmod +x /etc/init.d/pumpio
  3760. update-rc.d pumpio defaults
  3761. service pumpio start
  3762. #+END_SRC
  3763. Now visit your pump.io site by navigating to:
  3764. https://mypumpiodomainname.com
  3765. 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*.
  3766. 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.
  3767. 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).
  3768. Ensure that data data gets backed up with:
  3769. #+BEGIN_SRC: bash
  3770. printf "\n\n# Redis backup" >> /etc/cron.daily/backup
  3771. printf "\ntar -czvf /var/backups/redis_daily.tar.gz /var/lib/redis/dump.rdb" >> /etc/cron.daily/backup
  3772. printf "\n\n# Redis backup" >> /etc/cron.weekly/backup
  3773. printf "\ncp -f /var/backups/redis_weekly.tar.gz /var/backups/redis_weekly2.tar.gz" >> /etc/cron.weekly/backup
  3774. printf "\ncp -f /var/backups/redis_daily.tar.gz /var/backups/redis_weekly.tar.gz" >> /etc/cron.weekly/backup
  3775. printf "\n\n# Redis backup" >> /etc/cron.monthly/backup
  3776. printf "\ncp -f /var/backups/redis_monthly.tar.gz /var/backups/redis_monthly2.tar.gz" >> /etc/cron.monthly/backup
  3777. printf "\ncp -f /var/backups/redis_weekly.tar.gz /var/backups/redis_monthly.tar.gz" >> /etc/cron.monthly/backup
  3778. printf "\n\n# Pump.io backup" >> /etc/cron.daily/backup
  3779. printf "\ntar -czvf /var/backups/pumpio_daily.tar.gz /var/local/pump.io --exclude /var/local/pump.io/.forever" >> /etc/cron.daily/backup
  3780. printf "\n\n# Pump.io backup" >> /etc/cron.weekly/backup
  3781. printf "\ncp -f /var/backups/pumpio_weekly.tar.gz /var/backups/pumpio_weekly2.tar.gz" >> /etc/cron.weekly/backup
  3782. printf "\ncp -f /var/backups/pumpio_daily.tar.gz /var/backups/pumpio_weekly.tar.gz" >> /etc/cron.weekly/backup
  3783. printf "\n\n# Pump.io backup" >> /etc/cron.monthly/backup
  3784. printf "\ncp -f /var/backups/pumpio_monthly.tar.gz /var/backups/pumpio_monthly2.tar.gz" >> /etc/cron.monthly/backup
  3785. printf "\ncp -f /var/backups/pumpio_weekly.tar.gz /var/backups/pumpio_monthly.tar.gz" >> /etc/cron.monthly/backup
  3786. #+END_SRC
  3787. 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).
  3788. ** Install Gopher
  3789. *** Server setup
  3790. 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.
  3791. To set up a gopher server:
  3792. #+BEGIN_SRC: bash
  3793. apt-get install build-essential
  3794. mkdir ~/build
  3795. cd ~/build
  3796. wget http://freedombone.uk.to/geomyidae-current.tgz
  3797. #+END_SRC
  3798. Verify the download:
  3799. #+BEGIN_SRC: bash
  3800. sha256sum geomyidae-current.tgz
  3801. 162f55ab059ab0a9be8e840497795293bbd51c34b1f4564dcdf3f0ddd5c0db31 geomyidae-current.tgz
  3802. #+END_SRC
  3803. Then extract and install it.
  3804. #+BEGIN_SRC: bash
  3805. tar -xzvf geomyidae-current.tgz
  3806. cd geomyidae-*
  3807. make
  3808. make install
  3809. mkdir -p /var/gopher
  3810. #+END_SRC
  3811. 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.
  3812. #+BEGIN_SRC: bash
  3813. editor /etc/init.d/gopher
  3814. #+END_SRC
  3815. Enter the following:
  3816. #+BEGIN_SRC: bash
  3817. #! /bin/sh
  3818. ### BEGIN INIT INFO
  3819. # Provides: gopher
  3820. # Required-Start: $remote_fs $syslog
  3821. # Required-Stop: $remote_fs $syslog
  3822. # Default-Start: 2 3 4 5
  3823. # Default-Stop: 0 1 6
  3824. # Short-Description: Gopher daemon
  3825. # Description: Gopher daemon
  3826. ### END INIT INFO
  3827. # Do NOT "set -e"
  3828. # PATH should only include /usr/* if it runs after the mountnfs.sh script
  3829. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  3830. DESC="Gopher daemon"
  3831. NAME=geomyidae
  3832. DAEMON=/usr/bin/$NAME
  3833. DAEMON_ARGS="-l /var/log/geomyidae.log -b /var/gopher -p 70"
  3834. PIDFILE=/var/run/$NAME.pid
  3835. SCRIPTNAME=/etc/init.d/$NAME
  3836. # Exit if the package is not installed
  3837. [ -x "$DAEMON" ] || exit 0
  3838. # Read configuration variable file if it is present
  3839. [ -r /etc/default/$NAME ] && . /etc/default/$NAME
  3840. # Load the VERBOSE setting and other rcS variables
  3841. . /lib/init/vars.sh
  3842. # Define LSB log_* functions.
  3843. # Depend on lsb-base (>= 3.2-14) to ensure that this file is present
  3844. # and status_of_proc is working.
  3845. . /lib/lsb/init-functions
  3846. #
  3847. # Function that starts the daemon/service
  3848. #
  3849. do_start()
  3850. {
  3851. # Return
  3852. # 0 if daemon has been started
  3853. # 1 if daemon was already running
  3854. # 2 if daemon could not be started
  3855. start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
  3856. || return 1
  3857. start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
  3858. $DAEMON_ARGS \
  3859. || return 2
  3860. # Add code here, if necessary, that waits for the process to be ready
  3861. # to handle requests from services started subsequently which depend
  3862. # on this one. As a last resort, sleep for some time.
  3863. }
  3864. #
  3865. # Function that stops the daemon/service
  3866. #
  3867. do_stop()
  3868. {
  3869. # Return
  3870. # 0 if daemon has been stopped
  3871. # 1 if daemon was already stopped
  3872. # 2 if daemon could not be stopped
  3873. # other if a failure occurred
  3874. start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
  3875. RETVAL="$?"
  3876. [ "$RETVAL" = 2 ] && return 2
  3877. # Wait for children to finish too if this is a daemon that forks
  3878. # and if the daemon is only ever run from this initscript.
  3879. # If the above conditions are not satisfied then add some other code
  3880. # that waits for the process to drop all resources that could be
  3881. # needed by services started subsequently. A last resort is to
  3882. # sleep for some time.
  3883. start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
  3884. [ "$?" = 2 ] && return 2
  3885. # Many daemons don't delete their pidfiles when they exit.
  3886. rm -f $PIDFILE
  3887. return "$RETVAL"
  3888. }
  3889. #
  3890. # Function that sends a SIGHUP to the daemon/service
  3891. #
  3892. do_reload() {
  3893. #
  3894. # If the daemon can reload its configuration without
  3895. # restarting (for example, when it is sent a SIGHUP),
  3896. # then implement that here.
  3897. #
  3898. start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
  3899. return 0
  3900. }
  3901. case "$1" in
  3902. start)
  3903. [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
  3904. do_start
  3905. case "$?" in
  3906. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  3907. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  3908. esac
  3909. ;;
  3910. stop)
  3911. [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
  3912. do_stop
  3913. case "$?" in
  3914. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  3915. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  3916. esac
  3917. ;;
  3918. status)
  3919. status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
  3920. ;;
  3921. #reload|force-reload)
  3922. #
  3923. # If do_reload() is not implemented then leave this commented out
  3924. # and leave 'force-reload' as an alias for 'restart'.
  3925. #
  3926. #log_daemon_msg "Reloading $DESC" "$NAME"
  3927. #do_reload
  3928. #log_end_msg $?
  3929. #;;
  3930. restart|force-reload)
  3931. #
  3932. # If the "reload" option is implemented then remove the
  3933. # 'force-reload' alias
  3934. #
  3935. log_daemon_msg "Restarting $DESC" "$NAME"
  3936. do_stop
  3937. case "$?" in
  3938. 0|1)
  3939. do_start
  3940. case "$?" in
  3941. 0) log_end_msg 0 ;;
  3942. 1) log_end_msg 1 ;; # Old process is still running
  3943. *) log_end_msg 1 ;; # Failed to start
  3944. esac
  3945. ;;
  3946. *)
  3947. # Failed to stop
  3948. log_end_msg 1
  3949. ;;
  3950. esac
  3951. ;;
  3952. *)
  3953. #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
  3954. echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
  3955. exit 3
  3956. ;;
  3957. esac
  3958. :
  3959. #+END_SRC
  3960. Save and exit. Then start the gopher service.
  3961. #+BEGIN_SRC: bash
  3962. chmod +x /etc/init.d/gopher
  3963. update-rc.d gopher defaults
  3964. service gopher start
  3965. #+END_SRC
  3966. 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:
  3967. #+BEGIN_SRC: bash
  3968. gopher://mydomainname.com
  3969. #+END_SRC
  3970. There is a browser addon for Gopher called "overbite". Installing that should enable you to view your site.
  3971. *** A phlogging script
  3972. A phlog is the gopher equivalent of a blog on the web. You can create a script which makes phlogging easy.
  3973. #+BEGIN_SRC: bash
  3974. editor /usr/bin/mkphlog
  3975. #+END_SRC
  3976. Add the following:
  3977. #+BEGIN_SRC: bash
  3978. #!/bin/sh
  3979. # mkphlog - a utility to ease the creation of phlogs.
  3980. # Organizes phlog posts in separate directories.
  3981. # Created by octotep; anyone can distribute, modify, and
  3982. # share this file however they please.
  3983. #
  3984. # Version 0.3
  3985. #
  3986. # Modified by Bob Mottram
  3987. #
  3988. # Please note, all date strings are in the form of mm/dd/yy(yy)
  3989. # The base of the entire gopher site.
  3990. gopherRoot="/var/gopher"
  3991. # The name of the phlog directory (contained in $gopherHome)
  3992. phlogDirName="phlog"
  3993. # Default editor, unless the user has one specified in env
  3994. editor=${EDITOR:-emacs}
  3995. # Default timezone, unless the user has one specified in env
  3996. TZ=${TZ:-UTC}
  3997. # Tells the script how many lines the title of the main page spans.
  3998. # Used to insert the newest post at the top.
  3999. # Titles created by mkphlog are 3 lines.
  4000. # Isn't used if $addTitleToMain is false
  4001. titleLineCount=3
  4002. entryDate=`date +%Y-%m-%d`
  4003. # Creates the phlog directory if it dosen't already exist.
  4004. CreatePhlogDir() {
  4005. mkdir $phlogDirName
  4006. chmod 755 $phlogDirName
  4007. cd $phlogDirName
  4008. echo "Phlog directory created."
  4009. }
  4010. # Updates the main phlog listing
  4011. UpdatePhlogListing() {
  4012. # Just in case the user didn't specify a title
  4013. if [ "$postTitleAns" = "" ] ; then
  4014. echo -n "Do you want to create a blank post? (y/n) "
  4015. read blankPostAns
  4016. case $blankPostAns in
  4017. y* | Y* ) $postTitleAns="New Post" ;;
  4018. n* | N* ) echo "Goodbye, then." ; exit 1 ;;
  4019. * ) exit 1 ;;
  4020. esac
  4021. fi
  4022. cd $gopherRoot/$phlogDirName/
  4023. title2=$(echo "${postTitleAns}" | tr " " _)
  4024. postfilename="${entryDate}_${title2}.txt"
  4025. touch ${postfilename}
  4026. echo $postTitleAns >> ${postfilename}
  4027. date "+%A %b %e %l:%M:%S %Y" >> ${postfilename}
  4028. echo "------------------------------" >> ${postfilename}
  4029. echo >> ${postfilename}
  4030. }
  4031. if [ -d $gopherRoot ] ; then
  4032. cd $gopherRoot
  4033. else
  4034. echo "You don't have a gopherspace set-up. Please run the gopher server setup instructions."
  4035. exit 1
  4036. fi
  4037. if [ -d $phlogDirName ] ; then
  4038. cd $phlogDirName
  4039. else
  4040. echo -n "Do you want to create a phlog directory? (y/n) "
  4041. read phlogDirAns
  4042. case $phlogDirAns in
  4043. y* | Y* ) CreatePhlogDir ;;
  4044. n* | N* ) exit 1 ;;
  4045. * ) exit 1 ;;
  4046. esac
  4047. fi
  4048. echo -n "Would you like to create a phlog entry for today? (y/n) "
  4049. read phlogAns
  4050. case $phlogAns in
  4051. y* | Y* ) echo "Creating today's phlog entry..." ;;
  4052. n* | N* ) exit 0 ;;
  4053. * ) exit 1 ;;
  4054. esac
  4055. # Make sure there isn't a post for that day, lest we overwrite it.
  4056. if [ ! -d $entryDate ]; then
  4057. echo -n "Title: "
  4058. read postTitleAns
  4059. title2=$(echo "${postTitleAns}" | tr " " _)
  4060. postfilename="${entryDate}_${title2}.txt"
  4061. touch ${postfilename}
  4062. chmod 644 ${postfilename}
  4063. UpdatePhlogListing
  4064. echo -n "Would you like to edit the post with $editor? (y/n) "
  4065. read editorAns
  4066. case $editorAns in
  4067. y* | Y* ) $editor $gopherRoot/$phlogDirName/${postfilename} ;;
  4068. n* | N* ) exit 0 ;;
  4069. * ) exit 0 ;;
  4070. esac
  4071. rm $gopherRoot/$phlogDirName/${postfilename}~
  4072. else
  4073. echo "There is already a post for today."
  4074. echo -n "Would you like to edit the post with $editor? (y/n) "
  4075. read editorAns
  4076. case $editorAns in
  4077. y* | Y* ) $editor $gopherRoot/$phlogDirName/$entryDate*.txt ;;
  4078. n* | N* ) exit 0 ;;
  4079. * ) exit 1 ;;
  4080. esac
  4081. rm $gopherRoot/$phlogDirName/${postfilename}.txt~
  4082. fi
  4083. exit 0
  4084. #+END_SRC
  4085. Save and exit.
  4086. #+BEGIN_SRC: bash
  4087. chmod +x /usr/bin/mkphlog
  4088. #+END_SRC
  4089. Now entering the command /mkphlog/ will allow you to create a phlog entry.
  4090. ** Install Owncloud
  4091. #+BEGIN_VERSE
  4092. /It's not water vapour/
  4093. -- Larry Ellison
  4094. #+END_VERSE
  4095. 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.
  4096. *** Server Installation
  4097. Install some dependencies:
  4098. #+BEGIN_SRC: bash
  4099. apt-get install php5 php5-gd php-xml-parser php5-intl
  4100. apt-get install php5-sqlite php5-mysql smbclient curl libcurl3 php5-curl
  4101. #+END_SRC
  4102. You will need to create a new subdomain, so see [[Setting up a web site]] for details of how to do that.
  4103. #+BEGIN_SRC: bash
  4104. export HOSTNAME=myowncloudcomainname.com
  4105. editor /etc/nginx/sites-available/$HOSTNAME
  4106. #+END_SRC
  4107. Delete all existing contents, then add the following:
  4108. #+BEGIN_SRC: bash
  4109. server {
  4110. listen 80;
  4111. server_name myownclouddomainname.com;
  4112. rewrite ^ https://$server_name$request_uri? permanent;
  4113. }
  4114. server {
  4115. listen 443 ssl;
  4116. root /var/www/myownclouddomainname.com/htdocs;
  4117. server_name myownclouddomainname.com;
  4118. ssl on;
  4119. ssl_certificate /etc/ssl/certs/myownclouddomainname.com.crt;
  4120. ssl_certificate_key /etc/ssl/private/myownclouddomainname.com.key;
  4121. ssl_dhparam /etc/ssl/certs/myownclouddomainname.com.dhparam;
  4122. ssl_session_timeout 5m;
  4123. ssl_prefer_server_ciphers on;
  4124. ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # not possible to do exclusive
  4125. 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';
  4126. add_header X-Frame-Options DENY;
  4127. add_header X-Content-Type-Options nosniff;
  4128. add_header Strict-Transport-Security max-age=15768000;
  4129. # if you want to be able to access the site via HTTP
  4130. # then replace the above with the following:
  4131. # add_header Strict-Transport-Security "max-age=0;";
  4132. # make sure webfinger and other well known services aren't blocked
  4133. # by denying dot files and rewrite request to the front controller
  4134. location ^~ /.well-known/ {
  4135. allow all;
  4136. rewrite ^/(.*) /index.php?q=$uri&$args last;
  4137. }
  4138. client_max_body_size 10G; # set max upload size
  4139. client_body_buffer_size 128k;
  4140. fastcgi_buffers 64 4K;
  4141. rewrite ^/caldav(.*)$ /remote.php/caldav$1 redirect;
  4142. rewrite ^/carddav(.*)$ /remote.php/carddav$1 redirect;
  4143. rewrite ^/webdav(.*)$ /remote.php/webdav$1 redirect;
  4144. index index.php;
  4145. error_page 403 /core/templates/403.php;
  4146. error_page 404 /core/templates/404.php;
  4147. location = /robots.txt {
  4148. allow all;
  4149. log_not_found off;
  4150. access_log off;
  4151. }
  4152. location ~ ^/(data|config|\.ht|db_structure\.xml|README) {
  4153. deny all;
  4154. }
  4155. location / {
  4156. # The following 2 rules are only needed with webfinger
  4157. rewrite ^/.well-known/host-meta /public.php?service=host-meta last;
  4158. rewrite ^/.well-known/host-meta.json /public.php?service=host-meta-json last;
  4159. rewrite ^/.well-known/carddav /remote.php/carddav/ redirect;
  4160. rewrite ^/.well-known/caldav /remote.php/caldav/ redirect;
  4161. rewrite ^(/core/doc/[^\/]+/)$ $1/index.html;
  4162. try_files $uri $uri/ index.php;
  4163. }
  4164. location ~ ^(.+?\.php)(/.*)?$ {
  4165. try_files $1 =404;
  4166. fastcgi_split_path_info ^(.+\.php)(/.+)$;
  4167. fastcgi_pass unix:/var/run/php5-fpm.sock;
  4168. fastcgi_index index.php;
  4169. include fastcgi_params;
  4170. fastcgi_param SCRIPT_FILENAME $document_root$1;
  4171. fastcgi_param PATH_INFO $2;
  4172. fastcgi_param HTTPS on;
  4173. }
  4174. # Optional: set long EXPIRES header on static assets
  4175. location ~* ^.+\.(jpg|jpeg|gif|bmp|ico|png|css|js|swf)$ {
  4176. expires 30d;
  4177. # Optional: Don't log access to assets
  4178. access_log off;
  4179. }
  4180. }
  4181. #+END_SRC
  4182. Save and exit. Then change the domain name.
  4183. #+BEGIN_SRC: bash
  4184. sed "s/myownclouddomainname.com/$HOSTNAME/g" /etc/nginx/sites-available/$HOSTNAME > /tmp/website
  4185. cp -f /tmp/website /etc/nginx/sites-available/$HOSTNAME
  4186. #+END_SRC
  4187. Download owncloud.
  4188. #+BEGIN_SRC: bash
  4189. mkdir ~/build
  4190. cd ~/build
  4191. wget http://freedombone.uk.to/owncloud.tar.bz2
  4192. #+END_SRC
  4193. Verify the download:
  4194. #+BEGIN_SRC: bash
  4195. sha256sum owncloud.tar.bz2
  4196. 9aca2aa0a0cd7b052e881c30ad6de25d135ec3f88a3920274f1be223b4cabedf
  4197. #+END_SRC
  4198. Extract the archive. This may take a couple of minutes, so don't be alarmed that the system has crashed.
  4199. #+BEGIN_SRC: bash
  4200. tar -xjf owncloud.tar.bz2
  4201. #+END_SRC
  4202. The extraction will take a few minutes. Move the extracted files to your site and set file permissions.
  4203. #+BEGIN_SRC: bash
  4204. cp -r owncloud/* /var/www/$HOSTNAME/htdocs
  4205. #+END_SRC
  4206. The copying also takes a few minutes. Then change the file permissions.
  4207. #+BEGIN_SRC: bash
  4208. chown -R www-data:www-data /var/www/$HOSTNAME/htdocs/apps
  4209. chown -R www-data:www-data /var/www/$HOSTNAME/htdocs/config
  4210. chown www-data:www-data /var/www/$HOSTNAME/htdocs
  4211. #+END_SRC
  4212. Increase the maximum upload size:
  4213. #+BEGIN_SRC: bash
  4214. editor /etc/php5/fpm/php.ini
  4215. #+END_SRC
  4216. Set the following:
  4217. #+BEGIN_SRC: bash
  4218. upload_max_filesize = 50M
  4219. post_max_size = 50M
  4220. #+END_SRC
  4221. Save and exit.
  4222. #+BEGIN_SRC: bash
  4223. service php5-fpm restart
  4224. service nginx restart
  4225. #+END_SRC
  4226. With a web browser visit your domain (mydomainname.com/owncloud) and enter an administrator username and password.
  4227. 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.
  4228. *** Owncloud on Android
  4229. 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.
  4230. ** Install a Wiki
  4231. #+BEGIN_VERSE
  4232. /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./
  4233. -- Tom Barbalet
  4234. #+END_VERSE
  4235. Dokuwiki is based upon flat files, and so is easy to move from one server to another without a lot of database complications.
  4236. Download the wiki.
  4237. #+BEGIN_SRC: bash
  4238. mkdir ~/build
  4239. cd ~/build
  4240. wget http://freedombone.uk.to/dokuwiki.tgz
  4241. #+END_SRC
  4242. Verify it.
  4243. #+BEGIN_SRC: bash
  4244. sha256sum dokuwiki.tgz
  4245. 6b126f90979463d9ddaa74acc6f96aa230cfdc789946f241c3646086d9574be8 dokuwiki.tgz
  4246. #+END_SRC
  4247. Then extract and install it.
  4248. #+BEGIN_SRC: bash
  4249. export HOSTNAME=mywikidomainname.com
  4250. tar -xzvf dokuwiki.tgz
  4251. rm -rf /var/www/$HOSTNAME/htdocs
  4252. mv dokuwiki /var/www/$HOSTNAME/htdocs
  4253. #+END_SRC
  4254. and alter permissions:
  4255. #+BEGIN_SRC: bash
  4256. chmod -R 755 /var/www/$HOSTNAME/htdocs
  4257. chown -R www-data:www-data /var/www/$HOSTNAME/htdocs
  4258. #+END_SRC
  4259. Open a browser and visit http://$HOSTNAME/install.php, then fill out the details. Once everything has been accepted without errors:
  4260. #+BEGIN_SRC: bash
  4261. rm /var/www/$HOSTNAME/htdocs/install.php
  4262. #+END_SRC
  4263. Add a few extra mime types:
  4264. #+BEGIN_SRC: bash
  4265. editor /var/www/$HOSTNAME/htdocs/conf/mime.conf
  4266. #+END_SRC
  4267. Append the following:
  4268. #+BEGIN_SRC: bash
  4269. ogv video/ogg
  4270. mp4 video/mp4
  4271. webm video/webm
  4272. #+END_SRC
  4273. Save and exit.
  4274. 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.
  4275. Now you can visit your wiki and begin editing.
  4276. ** Install Bitmessage
  4277. #+BEGIN_VERSE
  4278. /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/
  4279. -- Edward J. Snowden, testimony to the EU parliament
  4280. #+END_VERSE
  4281. *** A new kind of Email
  4282. [[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.
  4283. 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.
  4284. Installing Bitmessage as a daemon will increase the size of the network, and therefore the level of security for all users.
  4285. *** The Daemon
  4286. Install from the current source code.
  4287. #+BEGIN_SRC: bash
  4288. apt-get install python screen
  4289. mkdir ~/build
  4290. cd ~/build
  4291. git clone https://github.com/bashrc/PyBitmessage.git
  4292. cd PyBitmessage
  4293. make install
  4294. #+END_SRC
  4295. Now create the daemon.
  4296. #+BEGIN_SRC: bash
  4297. editor /etc/init.d/pybitmessage
  4298. #+END_SRC
  4299. Add the following text:
  4300. #+BEGIN_SRC: bash
  4301. #!/bin/bash
  4302. # /etc/init.d/bitmessage
  4303. ### BEGIN INIT INFO
  4304. # Provides: pybitmessage
  4305. # Required-Start: $remote_fs $syslog
  4306. # Required-Stop: $remote_fs $syslog
  4307. # Default-Start: 2 3 4 5
  4308. # Default-Stop: 0 1 6
  4309. # Short-Description: starts bitmessage as a background daemon, suitable for servers
  4310. # Description: This file should be used to construct scripts to be
  4311. # placed in /etc/init.d.
  4312. ### END INIT INFO
  4313. # Author: Super-Nathan <BM-Gu2k3Wy2hpTMYBxSoM2937SPcuU6xzEj>
  4314. #Settings
  4315. SERVICE='pybitmessage'
  4316. LOGFILE='/dev/null' # this disables logging
  4317. # LOGFILE='/var/log/bitmessage.log' # comment out the above line and un-comment this line to save a log
  4318. COMMAND="python bitmessagemain.py > $LOGFILE"
  4319. USERNAME='bitmsg'
  4320. NICELEVEL=19 # from 0-19 the bigger the number, the less the impact on system resources
  4321. HISTORY=1024
  4322. PBM_LOCATION="/usr/local/share/pybitmessage"
  4323. INVOCATION="nice -n ${NICELEVEL} ${COMMAND}"
  4324. PATH='/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/core_perl:/sbin:/usr/sbin:/bin:/usr/local/share/pybitmessage'
  4325. bm_start() {
  4326. echo "Starting $SERVICE..."
  4327. cd ${PBM_LOCATION}
  4328. su --command "screen -h ${HISTORY} -dmS ${SERVICE} ${INVOCATION}" $USERNAME
  4329. }
  4330. bm_stop() {
  4331. echo "Stopping $SERVICE"
  4332. su --command "screen -p 0 -S ${SERVICE} -X stuff "'^C'"" $USERNAME
  4333. }
  4334. #Start-Stop here
  4335. case "$1" in
  4336. start)
  4337. bm_start
  4338. ;;
  4339. stop)
  4340. bm_stop
  4341. ;;
  4342. restart)
  4343. bm_stop
  4344. sleep 60s
  4345. bm_start
  4346. ;;
  4347. *)
  4348. echo "Usage: $0 {start|stop|restart}"
  4349. exit 1
  4350. ;;
  4351. esac
  4352. exit 0
  4353. #+END_SRC
  4354. Save and exit.
  4355. 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.
  4356. #+BEGIN_SRC: bash
  4357. adduser bitmsg
  4358. #+END_SRC
  4359. Create a /keys.dat/ file which is used to configure Bitmessage.
  4360. #+BEGIN_SRC: bash
  4361. mkdir /home/bitmsg/.config
  4362. mkdir /home/bitmsg/.config/PyBitmessage
  4363. editor /home/bitmsg/.config/PyBitmessage/keys.dat
  4364. #+END_SRC
  4365. Add the following, changing /apipassword/ to some long random string:
  4366. #+BEGIN_SRC: bash
  4367. [bitmessagesettings]
  4368. settingsversion = 8
  4369. port = 8444
  4370. timeformat = %%a, %%d %%b %%Y %%I:%%M %%p
  4371. blackwhitelist = black
  4372. startonlogon = False
  4373. minimizetotray = False
  4374. showtraynotifications = True
  4375. startintray = False
  4376. socksproxytype = none
  4377. sockshostname = localhost
  4378. socksport = 9050
  4379. socksauthentication = False
  4380. sockslisten = False
  4381. socksusername =
  4382. sockspassword =
  4383. keysencrypted = false
  4384. messagesencrypted = false
  4385. defaultnoncetrialsperbyte = 640
  4386. defaultpayloadlengthextrabytes = 14000
  4387. minimizeonclose = false
  4388. maxacceptablenoncetrialsperbyte = 0
  4389. maxacceptablepayloadlengthextrabytes = 0
  4390. userlocale = system
  4391. useidenticons = True
  4392. identiconsuffix = re9E9UtSEaWD
  4393. replybelow = False
  4394. stopresendingafterxdays = 4
  4395. stopresendingafterxmonths =
  4396. namecoinrpctype = namecoind
  4397. namecoinrpchost = localhost
  4398. namecoinrpcuser =
  4399. namecoinrpcpassword =
  4400. namecoinrpcport = 8336
  4401. sendoutgoingconnections = True
  4402. willinglysendtomobile = False
  4403. maxpayloadlengthkb = 256
  4404. daemon = true
  4405. apienabled = true
  4406. apiport = 8442
  4407. apiinterface = 127.0.0.1
  4408. apiusername = bitmsg
  4409. maxpayloadlengthkb = 256
  4410. apipassword = change_this_password
  4411. #+END_SRC
  4412. Save and exit. Then enable the daemon and run it.
  4413. #+BEGIN_SRC: bash
  4414. rm -f /tmp/-usr-local-share-pybitmessage-*.lock
  4415. chown -R bitmsg:bitmsg /home/bitmsg
  4416. chmod +x /etc/init.d/pybitmessage
  4417. update-rc.d pybitmessage defaults
  4418. service pybitmessage start
  4419. #+END_SRC
  4420. Now open port 8444 on your internet router or firewall and direct it to the BBB.
  4421. *** Using Bitmessage
  4422. 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.
  4423. 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:
  4424. #+BEGIN_SRC: bash
  4425. mkdir ~/build
  4426. cd ~/build
  4427. git clone https://github.com/Bitmessage/PyBitmessage.git
  4428. cd PyBitmessage
  4429. make install
  4430. pybitmessage
  4431. #+END_SRC
  4432. *** Connect Bitmessage to Email
  4433. 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:
  4434. #+BEGIN_SRC: bash
  4435. /home/bitmsg/.config/PyBitmessage/keys.dat
  4436. #+END_SRC
  4437. and adding the details for your address, which could be coppied from another machine (such as a laptop running a Bitmessage client).
  4438. It will look something like:
  4439. #+BEGIN_SRC: bash
  4440. [BM-address]
  4441. label = myusername@mydomainname.com
  4442. enabled = true
  4443. decoy = false
  4444. noncetrialsperbyte = 640
  4445. payloadlengthextrabytes = 14000
  4446. privsigningkey = ...
  4447. privencryptionkey = ...
  4448. lastpubkeysendtime = ...
  4449. #+END_SRC
  4450. 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.
  4451. You should also make sure that /apipassword/ is set to some long random string.
  4452. Save and close /keys.dat/, then restart the Bitmessage daemon.
  4453. #+BEGIN_SRC: bash
  4454. service pybitmessage restart
  4455. #+END_SRC
  4456. The restart will take 30 seconds or so. Next install the Bitmessage to email gateway.
  4457. #+BEGIN_SRC: bash
  4458. cd /usr/share
  4459. git clone https://github.com/bashrc/bitmessage-email-gateway
  4460. chown -R bitmsg:bitmsg bitmessage-email-gateway
  4461. cd bitmessage-email-gateway
  4462. mkdir /home/bitmsg/Maildir
  4463. mkdir /home/bitmsg/Maildir/new
  4464. chown -R bitmsg:bitmsg /home/bitmsg
  4465. #+END_SRC
  4466. Substitute /your_domain_name/ for your domain name (the main one used for email).
  4467. #+BEGIN_SRC: bash
  4468. sed 's/mydomainname.com/your_domain_name/g' bitmessage-gateway.py > bitmessage-gateway.py
  4469. #+END_SRC
  4470. Find out what the API password is:
  4471. #+BEGIN_SRC: bash
  4472. grep "apipassword" /home/bitmsg/.config/PyBitmessage/keys.dat | awk -F ' ' '{print $3}'
  4473. #+END_SRC
  4474. Then change it with:
  4475. #+BEGIN_SRC: bash
  4476. sed "s/'password' : ''/'password' : 'bitmessage_api_password'/g" bitmessage-gateway.py > bitmessage-gateway.py
  4477. #+END_SRC
  4478. Now create the daemon.
  4479. #+BEGIN_SRC: bash
  4480. editor /etc/init.d/bitmessage-gateway
  4481. #+END_SRC
  4482. Add the following text:
  4483. #+BEGIN_SRC: bash
  4484. #!/bin/bash
  4485. # /etc/init.d/bitmessage-gateway
  4486. ### BEGIN INIT INFO
  4487. # Provides: bitmessage-gateway
  4488. # Required-Start: $remote_fs $syslog
  4489. # Required-Stop: $remote_fs $syslog
  4490. # Default-Start: 2 3 4 5
  4491. # Default-Stop: 0 1 6
  4492. # Short-Description: starts a gateway between bitmessage and email
  4493. # Description:
  4494. ### END INIT INFO
  4495. # Author: Bob Mottram <bob@robotics.uk.to>
  4496. #Settings
  4497. SERVICE='bitmessage-gateway'
  4498. LOGFILE='/dev/null'
  4499. COMMAND="python bitmessage-gateway.py > $LOGFILE"
  4500. USERNAME='bitmsg'
  4501. NICELEVEL=19 # from 0-19 the bigger the number, the less the impact on system resources
  4502. HISTORY=1024
  4503. BMG_LOCATION="/usr/share/bitmessage-email-gateway"
  4504. INVOCATION="nice -n ${NICELEVEL} ${COMMAND}"
  4505. PATH='/usr/local/sbin:/usr/local/bin:/usr/bin:/sbin:/usr/sbin:/bin:/usr/share/bitmessage-email-gateway'
  4506. bmg_start() {
  4507. echo "Starting $SERVICE..."
  4508. cd ${BMG_LOCATION}
  4509. su --command "screen -h ${HISTORY} -dmS ${SERVICE} ${INVOCATION}" $USERNAME
  4510. }
  4511. bmg_stop() {
  4512. echo "Stopping $SERVICE"
  4513. su --command "screen -p 0 -S ${SERVICE} -X stuff "'^C'"" $USERNAME
  4514. }
  4515. #Start-Stop here
  4516. case "$1" in
  4517. start)
  4518. bmg_start
  4519. ;;
  4520. stop)
  4521. bmg_stop
  4522. ;;
  4523. restart)
  4524. bmg_stop
  4525. sleep 5s
  4526. bmg_start
  4527. ;;
  4528. *)
  4529. echo "Usage: $0 {start|stop|restart}"
  4530. exit 1
  4531. ;;
  4532. esac
  4533. exit 0
  4534. #+END_SRC
  4535. Save and exit.
  4536. #+BEGIN_SRC: bash
  4537. chmod +x /etc/init.d/bitmessage-gateway
  4538. update-rc.d bitmessage-gateway defaults
  4539. service bitmessage-gateway start
  4540. #+END_SRC
  4541. 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.
  4542. ** Overcome restrictive environments
  4543. #+BEGIN_VERSE
  4544. /Censorship reflects a society's lack of confidence in itself. It is a hallmark of an authoritarian regime./
  4545. -- Potter Stewart
  4546. #+END_VERSE
  4547. 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.
  4548. 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.
  4549. #+BEGIN_SRC: bash
  4550. apt-get install shellinabox libapache
  4551. 2-mod-proxy-html
  4552. #+END_SRC
  4553. Update your Apache configuration.
  4554. #+BEGIN_SRC: bash
  4555. export HOSTNAME=mydomainname.com
  4556. editor /etc/apache2/sites-available/$HOSTNAME
  4557. #+END_SRC
  4558. Within the section which begins with *<VirtualHost *:443>* add the following, replacing /mydomainname.com/ with your domain name and /myusername/ with your username.
  4559. #+BEGIN_SRC: bash
  4560. <Location /shell>
  4561. ProxyPass http://localhost:4200/
  4562. Order allow,deny
  4563. Allow from all
  4564. AuthName "Authentication for shellinabox"
  4565. AuthUserFile /home/mydomainname.com/public_html/.htpasswd
  4566. AuthGroupFile /home/mydomainname.com/public_html/.htgroup
  4567. AuthType Basic
  4568. Require group shellinabox
  4569. Require user myusername
  4570. </Location>
  4571. #+END_SRC
  4572. 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.
  4573. #+BEGIN_SRC: bash
  4574. mkdir /home/$HOSTNAME
  4575. mkdir /home/$HOSTNAME/public_html
  4576. htpasswd -c /home/$HOSTNAME/public_html/.htpasswd myusername
  4577. #+END_SRC
  4578. Create a user group.
  4579. #+BEGIN_SRC: bash
  4580. editor /home/$HOSTNAME/public_html/.htgroup
  4581. #+END_SRC
  4582. Add the following:
  4583. #+BEGIN_SRC: bash
  4584. shellinabox: myusername
  4585. #+END_SRC
  4586. Save and exit, then restart Apache.
  4587. #+BEGIN_SRC: bash
  4588. a2enmod proxy_http
  4589. service apache2 restart
  4590. #+END_SRC
  4591. Now with a web browser navigate to https://mydomainname.com/shell and log in.
  4592. 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/.
  4593. ** Set up a mailing list
  4594. #+BEGIN_VERSE
  4595. /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./
  4596. -- Jono Bacon
  4597. #+END_VERSE
  4598. *** Public mailing list
  4599. 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.
  4600. **** Installation
  4601. #+BEGIN_SRC: bash
  4602. export HOSTNAME=mydomainname.com
  4603. apt-get install mailman
  4604. newlist mailman
  4605. #+END_SRC
  4606. Enter an email address for the list administrator and a password.
  4607. #+BEGIN_SRC: bash
  4608. editor /etc/mailman/mm_cfg.py
  4609. #+END_SRC
  4610. Set *MTA=None* and change *http:* to *https:*, then save and exit.
  4611. Add some settings.
  4612. #+BEGIN_SRC: bash
  4613. editor /etc/exim4/conf.d/main/04_mailman_options
  4614. #+END_SRC
  4615. Add the following, replacing /mydomainname.com/ with your domain name.
  4616. #+BEGIN_SRC: bash
  4617. # Mailman macro definitions
  4618. # Home dir for the Mailman installation
  4619. MM_HOME=/var/lib/mailman
  4620. # User and group for Mailman
  4621. MM_UID=list
  4622. MM_GID=list
  4623. #
  4624. # Domains that your lists are in - colon separated list
  4625. # you may wish to add these into local_domains as well
  4626. domainlist mm_domains=mydomainname.com
  4627. # The path of the Mailman mail wrapper script
  4628. MM_WRAP=MM_HOME/mail/mailman
  4629. #
  4630. # The path of the list config file (used as a required file when
  4631. # verifying list addresses)
  4632. MM_LISTCHK=MM_HOME/lists/${lc::$local_part}/config.pck
  4633. #+END_SRC
  4634. Save and exit.
  4635. #+BEGIN_SRC: bash
  4636. editor /etc/exim4/conf.d/main/000_localmacros
  4637. #+END_SRC
  4638. Append the following:
  4639. #+BEGIN_SRC: bash
  4640. SYSTEM_ALIASES_PIPE_TRANSPORT = address_pipe
  4641. SYSTEM_ALIASES_USER = list
  4642. SYSTEM_ALIASES_GROUP = list
  4643. #+END_SRC
  4644. Save and exit.
  4645. #+BEGIN_SRC: bash
  4646. editor /etc/exim4/conf.d/acl/30_exim4-config_check_rcpt
  4647. #+END_SRC
  4648. Append the following, before the final /accept/:
  4649. #+BEGIN_SRC: bash
  4650. # Do callback verification unless Mailman incoming bounce
  4651. deny !local_parts = *-bounces : *-bounces+*
  4652. !verify = sender/callout=30s,defer_ok
  4653. #+END_SRC
  4654. Save and exit.
  4655. #+BEGIN_SRC: bash
  4656. editor
  4657. /etc/exim4/conf.d/router/450_exim4-config_mailman_aliases
  4658. #+END_SRC
  4659. Add the following:
  4660. #+BEGIN_SRC: bash
  4661. mailman:
  4662. driver = accept
  4663. domains = +mm_domains
  4664. require_files = MM_LISTCHK
  4665. local_part_suffix_optional
  4666. local_part_suffix = -admin : \
  4667. -bounces : -bounces+* : \
  4668. -confirm : -confirm+* : \
  4669. -join : -leave : \
  4670. -owner : -request : \
  4671. -subscribe : -unsubscribe
  4672. transport = mailman_transport
  4673. #+END_SRC
  4674. Save and exit.
  4675. #+BEGIN_SRC: bash
  4676. editor /etc/exim4/conf.d/transport/40_exim4-config_mailman_pipe
  4677. #+END_SRC
  4678. Add the following:
  4679. #+BEGIN_SRC: bash
  4680. mailman_transport:
  4681. driver = pipe
  4682. command = MM_WRAP \
  4683. '${if def:local_part_suffix \
  4684. {${sg{$local_part_suffix}{-(\\w+)(\\+.*)?}{\$1}}} \
  4685. {post}}' \
  4686. $local_part
  4687. current_directory = MM_HOME
  4688. home_directory = MM_HOME
  4689. user = MM_UID
  4690. group = MM_GID
  4691. #+END_SRC
  4692. Save and exit.
  4693. #+BEGIN_SRC: bash
  4694. chown root:list /var/lib/mailman/mail/mailman
  4695. update-exim4.conf.template -r
  4696. update-exim4.conf
  4697. service exim4 restart
  4698. editor /etc/apache2/conf.d/mailman
  4699. #+END_SRC
  4700. Add the following:
  4701. #+BEGIN_SRC: bash
  4702. Alias /pipermail /var/lib/mailman/archives/public
  4703. Alias /images/mailman /usr/share/images/mailman
  4704. <directory /var/lib/mailman/archives/public>
  4705. DirectoryIndex index.html
  4706. </directory>
  4707. #+END_SRC
  4708. Save and exit.
  4709. #+BEGIN_SRC: bash
  4710. editor /etc/apache2/sites-available/$HOSTNAME
  4711. #+END_SRC
  4712. Add the following to the 443 section.
  4713. #+BEGIN_SRC: bash
  4714. <Location /mailman>
  4715. Options Indexes FollowSymLinks MultiViews
  4716. Order allow,deny
  4717. Allow from all
  4718. RedirectMatch ^/$ /cgi-bin/mailman/listinfo
  4719. </Location>
  4720. #+END_SRC
  4721. Save and exit.
  4722. #+BEGIN_SRC: bash
  4723. service apache2 restart
  4724. #+END_SRC
  4725. Now add your mailing list. The list name should not include any spaces.
  4726. #+BEGIN_SRC: bash
  4727. newlist mymailinglistname
  4728. #+END_SRC
  4729. With a browser visit https://$HOSTNAME/cgi-bin/mailman/admin/mymailinglistname to configure the mailing list.
  4730. Under *General Options* add an email address for a moderator (could be the same as the administrator) and click *Submit your changes*.
  4731. Under *Privacy Options* set steps required for subscription to *Confirm and approve* and click *Submit your changes*.
  4732. Also change these settings for the account within https://$HOSTNAME/cgi-bin/mailman/admin/mailman
  4733. Then to test that the mailing list works:
  4734. #+BEGIN_SRC: bash
  4735. exim -d+route -bt mymailinglistname@$HOSTNAME
  4736. #+END_SRC
  4737. If everything is working then this shouldn't show any problems.
  4738. **** Using the mailing list
  4739. Direct subscribers towards:
  4740. #+BEGIN_SRC: bash
  4741. https://mydomainname.com/cgi-bin/mailman/listinfo/mymailinglistname
  4742. #+END_SRC
  4743. To administrate the list visit:
  4744. #+BEGIN_SRC: bash
  4745. https://mydomainname.com/cgi-bin/mailman/admin/mymailinglistname
  4746. #+END_SRC
  4747. To add another mailing list:
  4748. #+BEGIN_SRC: bash
  4749. newlist mymailinglistname
  4750. #+END_SRC
  4751. To delete a mailing list:
  4752. #+BEGIN_SRC: bash
  4753. rmlist -a mymailinglistname
  4754. #+END_SRC
  4755. *** Private (encrypted) mailing list
  4756. 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.
  4757. 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.
  4758. **** Installation
  4759. #+BEGIN_SRC: bash
  4760. apt-get install schleuder
  4761. #+END_SRC
  4762. Edit the configuration:
  4763. #+BEGIN_SRC: bash
  4764. editor /etc/schleuder/schleuder.conf
  4765. #+END_SRC
  4766. Set the following parameters, replacing /mydomainname.com/ with your domain name:
  4767. #+BEGIN_SRC: bash
  4768. smtp_port: 465
  4769. superadminaddr: root@mydomainname.com
  4770. #+END_SRC
  4771. Save and exit.
  4772. Get your GPG public key, replacing /myGPGkeyID/ with your GPG key ID:
  4773. #+BEGIN_SRC: bash
  4774. export MYKEYID=myGPGkeyID
  4775. gpg --search-keys $MYKEYID
  4776. gpg --output /tmp/mypublickey.txt --armor --export $MYKEYID
  4777. #+END_SRC
  4778. 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.
  4779. #+BEGIN_SRC: bash
  4780. export MAILINGLISTNAME=mailinglistname
  4781. export MYUSERNAME=myusername
  4782. export HOSTNAME=mydomainname.com
  4783. export EMAILADDRESS=$MYUSERNAME@$HOSTNAME
  4784. schleuder-newlist $MAILINGLISTNAME@$HOSTNAME -realname "mailing list name" -adminaddress $EMAILADDRESS -initmember $EMAILADDRESS -initmemberkey /tmp/mypublickey.txt -nointeractive
  4785. #+END_SRC
  4786. Now add a mailing list rule:
  4787. #+BEGIN_SRC: bash
  4788. emailrule $MYUSERNAME $MAILINGLISTNAME@$HOSTNAME $MAILINGLISTNAME
  4789. #+END_SRC
  4790. Edit your Mutt configuration.
  4791. #+BEGIN_SRC: bash
  4792. editor /home/$MYUSERNAME/.muttrc
  4793. #+END_SRC
  4794. Search for the /mailboxes/ parameter and add "=mailinglistname". For example:
  4795. #+BEGIN_SRC: bash
  4796. mailboxes = =Sent =Drafts =mailinglistname
  4797. #+END_SRC
  4798. Save and exit.
  4799. Update Exim routing.
  4800. #+BEGIN_SRC: bash
  4801. editor /etc/exim4/conf.d/router/550_exim4-config_schleuder
  4802. #+END_SRC
  4803. Add the following:
  4804. #+BEGIN_SRC: bash
  4805. schleuder:
  4806. debug_print = "R: schleuder for $local_part@$domain"
  4807. driver = accept
  4808. local_part_suffix_optional
  4809. local_part_suffix = +* : -bounce : -sendkey
  4810. domains = +local_domains
  4811. user = schleuder
  4812. group = schleuder
  4813. require_files = schleuder:+/var/lib/schleuder/$domain/${local_part}
  4814. transport = schleuder_transport
  4815. #+END_SRC
  4816. Save and exit.
  4817. #+BEGIN_SRC: bash
  4818. editor /etc/exim4/conf.d/transport/30_exim4-config_schleuder
  4819. #+END_SRC
  4820. Add the following.
  4821. #+BEGIN_SRC: bash
  4822. schleuder_transport:
  4823. debug_print = "T: schleuder_transport for $local_part@$domain"
  4824. driver = pipe
  4825. home_directory = "/var/lib/schleuder/$domain/$local_part"
  4826. command = "/usr/bin/schleuder $local_part@$domain"
  4827. #+END_SRC
  4828. Save and exit.
  4829. #+BEGIN_SRC: bash
  4830. chown -R schleuder:schleuder /var/lib/schleuder
  4831. update-exim4.conf.template -r
  4832. update-exim4.conf
  4833. service exim4 restart
  4834. useradd -d /var/schleuderlists -s /bin/false schleuder
  4835. adduser Debian-exim schleuder
  4836. usermod -a -G mail schleuder
  4837. #+END_SRC
  4838. Test the routing.
  4839. #+BEGIN_SRC: bash
  4840. exim -d -bt mailinglistname@mydomainname.com
  4841. #+END_SRC
  4842. **** Importing the public key of the mailing list
  4843. 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.
  4844. ***** Using Mutt
  4845. Send an email to /mailinglistname-sendkey@mydomainname.com/ to have the list public key emailed to you.
  4846. When you receive the email open it and press *CTRL-k* to import it.
  4847. ***** Using Thunderbird
  4848. Send an email to /mailinglistname-sendkey@mydomainname.com/ to have the list public key emailed to you.
  4849. When you receive the email open it, select all the text with *CTRL-a* then *CTRL-c*.
  4850. On the menu select *OpenPGP* followed by *Key Management*.
  4851. You will now see a new menu bar. Select *Edit* followed by *Import keys from clipboard*.
  4852. Click on *Import* followed by *Ok*.
  4853. **** Using the list
  4854. To obtain the public keys of list members send an email to /mailinglistname-request@mydomainname.com/ containing *X-LIST-KEYS* in the message body.
  4855. To add a member: *X-ADD-MEMBER: othermember@otherdomain.net*
  4856. An example of adding a public key to the list:
  4857. #+BEGIN_SRC: bash
  4858. X-ADD-KEY:
  4859. -----BEGIN PGP PUBLIC KEY BLOCK-----
  4860. Version: GnuPG v1.4.9 (GNU/Linux)
  4861. mQGiBEjVO7oRBADQvT6wtD2IzzIiK0NbrcilCKCp4MWb8cYXTXguwPQI6y0Nerz4
  4862. dsK6J0X1Vgeo02tqA4xd3EDK8rdqL2yZfl/2egH8+85R3gDk+kqkfEp4pwCgp6VO
  4863. [...]
  4864. pNlF/qkaWwRb048h+iMrW21EkouLKTDPFkdFbapV2X5KJZIcfhO1zEbwc1ZKF3Ju
  4865. Q9X5GRmY62hz9SCZnsC0jeYAni8OUQV9NXfXlS/vePBUnOL08NQB
  4866. =xTv3
  4867. -----END PGP PUBLIC KEY BLOCK-----
  4868. #+END_SRC
  4869. To get details for a member: *X-GET-MEMBER: othermember@otherdomain.net*
  4870. To delete a member: *X-DELETE-MEMBER: othermember@otherdomain.net*
  4871. To delete a public key: *X-DELETE-KEY: keyID*
  4872. You can unsubscribe from the list with *X-UNSUBSCRIBE* in the message body.
  4873. *** Decentralised mailing list
  4874. 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.
  4875. 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/".
  4876. 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.
  4877. On a Debian based system:
  4878. #+BEGIN_SRC: bash
  4879. sudo apt-get install makepasswd
  4880. #+END_SRC
  4881. or on an RPM based system:
  4882. #+BEGIN_SRC: bash
  4883. sudo yum install makepasswd
  4884. #+END_SRC
  4885. Create a name for your mailing list. This will be a random string.
  4886. #+BEGIN_SRC: bash
  4887. makepasswd -c 40
  4888. #+END_SRC
  4889. Keep a note of this.
  4890. Run the Bitmessage client and on the menu select *File/Join-Create Chan/Create new chan*
  4891. 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.
  4892. 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.
  4893. 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.
  4894. 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.
  4895. ** Install a microblog
  4896. #+BEGIN_VERSE
  4897. /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/
  4898. -- Jason Self
  4899. #+END_VERSE
  4900. 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.
  4901. Install some dependencies:
  4902. #+BEGIN_SRC: bash
  4903. apt-get install php5-xcache php-gettext php5-curl php5-gd php5-mysql
  4904. #+END_SRC
  4905. Download GNU Social
  4906. #+BEGIN_SRC: bash
  4907. mkdir ~/build
  4908. cd ~/build
  4909. wget http://freedombone.uk.to/gnu-social.tar.gz
  4910. #+END_SRC
  4911. Verify it.
  4912. #+BEGIN_SRC: bash
  4913. sha256sum gnu-social.tar.gz
  4914. 1f886241c7f1a175e7be3cccbcb944ab6c03617fb75aefa4d62d37abed87d2b4
  4915. #+END_SRC
  4916. Extract the files and set permissions on them, where /mydomainname.com/ is your domain name.
  4917. #+BEGIN_SRC: bash
  4918. export HOSTNAME=mydomainname.com
  4919. tar zxf gnu-social.tar.gz
  4920. rm -rf /var/www/$HOSTNAME/htdocs
  4921. mv statusnet-gnu-social /var/www/$HOSTNAME/htdocs
  4922. chmod a+w /var/www/$HOSTNAME/htdocs
  4923. chown www-data:www-data /var/www/$HOSTNAME/htdocs
  4924. chmod a+w /var/www/$HOSTNAME/htdocs/avatar
  4925. chmod a+w /var/www/$HOSTNAME/htdocs/background
  4926. chmod a+w /var/www/$HOSTNAME/htdocs/file
  4927. chmod +x /var/www/$HOSTNAME/htdocs/scripts/maildaemon.php
  4928. #+END_SRC
  4929. Edit the Apache access settings.
  4930. #+BEGIN_SRC: bash
  4931. editor /var/www/$HOSTNAME/htdocs/.htaccess
  4932. #+END_SRC
  4933. Add the following:
  4934. #+BEGIN_SRC: bash
  4935. <IfModule mod_rewrite.c>
  4936. RewriteEngine On
  4937. RewriteBase /
  4938. ## Uncomment these if having trouble with API authentication
  4939. ## when PHP is running in CGI or FastCGI mode.
  4940. #
  4941. #RewriteCond %{HTTP:Authorization} ^(.*)
  4942. #RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%1]
  4943. RewriteCond %{REQUEST_FILENAME} !-f
  4944. RewriteCond %{REQUEST_FILENAME} !-d
  4945. RewriteRule (.*) index.php?p=$1 [L,QSA]
  4946. </IfModule>
  4947. <FilesMatch "\.(ini)">
  4948. Order allow,deny
  4949. </FilesMatch>
  4950. #+END_SRC
  4951. Save and exit, then create a database.
  4952. #+BEGIN_SRC: bash
  4953. mysql -u root -p
  4954. create database gnusocial;
  4955. CREATE USER 'gnusocialadmin'@'localhost' IDENTIFIED BY 'gnusocialpassword';
  4956. GRANT ALL PRIVILEGES ON gnusocial.* TO 'gnusocialadmin'@'localhost';
  4957. quit
  4958. #+END_SRC
  4959. Add the mailer script to the aliases file:
  4960. #+BEGIN_SRC: bash
  4961. editor /etc/aliases
  4962. #+END_SRC
  4963. Add the following, replacing /mydomainname.com/ with your domain name.
  4964. #+BEGIN_SRC: bash
  4965. www-data: root
  4966. *: /var/www/mydomainname.com/htdocs/scripts/maildaemon.php
  4967. #+END_SRC
  4968. Save and exit. Update the aliases by typing:
  4969. #+BEGIN_SRC: bash
  4970. newaliases
  4971. #+END_SRC
  4972. Then with a web browser navigate to:
  4973. https://$HOSTNAME/install.php
  4974. Set a name for the site.
  4975. Server SSL: enable
  4976. Hostname: localhost
  4977. Type: MySql
  4978. Name: gnusocial
  4979. DB username: gnusocialadmin
  4980. DB Password; your gnu social admin password goes here
  4981. Administrator nickname: myusername
  4982. Administrator password: mylongrandompassword
  4983. Subscribe to announcements: ticked
  4984. Site profile: Community
  4985. 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.
  4986. 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:
  4987. Under the *Site* settings:
  4988. Text limit: 140
  4989. Dupe Limit: 60000
  4990. Under the *User* settings:
  4991. Bio limit: 1000
  4992. Under the *Access* settings:
  4993. /Invite only/ ticked
  4994. 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.
  4995. 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.
  4996. Edit the config file.
  4997. #+BEGIN_SRC: bash
  4998. editor /var/www/$HOSTNAME/htdocs/config.php
  4999. #+END_SRC
  5000. Change the ssl setting from *always* to *sometimes*, hten save and exit.
  5001. 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/
  5002. When following other GNU Social users enter the URL of your profile. For example, https://mygnusocialdomain/myusername
  5003. ** Install Mediagoblin
  5004. #+BEGIN_VERSE
  5005. /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./
  5006. #+END_VERSE
  5007. 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/.
  5008. 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.
  5009. Install some dependencies.
  5010. #+BEGIN_SRC: bash
  5011. 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
  5012. #+END_SRC
  5013. Create a user, replacing /mymediagoblindomain/ with the domain name for your mediagoblin site.
  5014. #+BEGIN_SRC: bash
  5015. export HOSTNAME=mymediagoblindomain
  5016. adduser mediagoblin
  5017. #+END_SRC
  5018. Give the user a long random password.
  5019. #+BEGIN_SRC: bash
  5020. mkdir -p /srv/$HOSTNAME
  5021. chown -hR mediagoblin:mediagoblin /srv/$HOSTNAME
  5022. su - mediagoblin
  5023. export HOSTNAME=mymediagoblindomain
  5024. cd /srv/$HOSTNAME
  5025. git clone git://gitorious.org/mediagoblin/mediagoblin.git
  5026. cd mediagoblin
  5027. git submodule init
  5028. git submodule update
  5029. virtualenv --system-site-packages .
  5030. ./bin/python setup.py develop
  5031. ./bin/easy_install flup
  5032. cp mediagoblin.ini mediagoblin_local.ini
  5033. cp paste.ini paste_local.ini
  5034. editor mediagoblin_local.ini
  5035. #+END_SRC
  5036. 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.
  5037. #+BEGIN_SRC: bash
  5038. [[mediagoblin.media_types.audio]]
  5039. [[mediagoblin.media_types.video]]
  5040. [[mediagoblin.media_types.stl]]
  5041. #+END_SRC
  5042. Then save and exit.
  5043. #+BEGIN_SRC: bash
  5044. ./bin/pip install scikits.audiolab
  5045. ./bin/gmg dbupdate
  5046. exit # to go back to the root user
  5047. editor /etc/init.d/mediagoblin
  5048. #+END_SRC
  5049. Add the following, replacing /mymediagoblindomain/ with the domain name for your mediagoblin site.
  5050. #+BEGIN_SRC: bash
  5051. #!/bin/bash
  5052. # /etc/init.d/mediagoblin
  5053. ### BEGIN INIT INFO
  5054. # Provides: mediagoblin
  5055. # Required-Start: $remote_fs $syslog
  5056. # Required-Stop: $remote_fs $syslog
  5057. # Default-Start: 2 3 4 5
  5058. # Default-Stop: 0 1 6
  5059. # Short-Description: starts mediagoblin
  5060. # Description: Other methods may work, but I found this the easiest
  5061. ### END INIT INFO
  5062. # Author: Bob Mottram <bob@robotics.uk.to>
  5063. #Settings
  5064. SERVICE='mediagoblin'
  5065. LOGFILE='/srv/mymediagoblindomain/mediagoblin.log'
  5066. COMMAND="./lazyserver.sh > $LOGFILE"
  5067. USERNAME='mediagoblin'
  5068. NICELEVEL=15 # from 0-19 the bigger the number, the less the impact on system resources
  5069. HISTORY=1024
  5070. MG_LOCATION="/srv/mymediagoblindomain/mediagoblin"
  5071. INVOCATION="nice -n ${NICELEVEL} ${COMMAND}"
  5072. PATH='/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/core_perl:/sbin:/usr/sbin:/bin'
  5073. mg_start() {
  5074. echo "Starting $SERVICE..."
  5075. cd ${MG_LOCATION}
  5076. su --command "screen -h ${HISTORY} -dmS ${SERVICE} ${INVOCATION}" $USERNAME
  5077. }
  5078. mg_stop() {
  5079. echo "Stopping $SERVICE"
  5080. su --command "screen -p 0 -S ${SERVICE} -X stuff "'^C'"" $USERNAME
  5081. }
  5082. #Start-Stop here
  5083. case "$1" in
  5084. start)
  5085. mg_start
  5086. ;;
  5087. stop)
  5088. mg_stop
  5089. ;;
  5090. restart)
  5091. mg_stop
  5092. sleep 10s
  5093. mg_start
  5094. ;;
  5095. *)
  5096. echo "Usage: $0 {start|stop|restart}"
  5097. exit 1
  5098. ;;
  5099. esac
  5100. exit 0
  5101. #+END_SRC
  5102. Save and exit.
  5103. #+BEGIN_SRC: bash
  5104. chmod +x /etc/init.d/mediagoblin
  5105. update-rc.d mediagoblin defaults
  5106. service mediagoblin start
  5107. #+END_SRC
  5108. Edit the Apache configuration for your mediagoblin site.
  5109. #+BEGIN_SRC: bash
  5110. editor /etc/apache2/sites-available/mymediagoblindomain
  5111. #+END_SRC
  5112. 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.
  5113. #+BEGIN_SRC: bash
  5114. <VirtualHost *:80>
  5115. ServerAdmin myusername@mydomainname.com
  5116. DocumentRoot /srv/mymediagoblindomain/mediagoblin
  5117. ServerName mymediagoblindomain
  5118. <Directory />
  5119. Options FollowSymLinks
  5120. AllowOverride None
  5121. </Directory>
  5122. <Directory /srv/mymediagoblindomain/mediagoblin/>
  5123. Options Indexes FollowSymLinks MultiViews
  5124. AllowOverride All
  5125. Order allow,deny
  5126. allow from all
  5127. LimitRequestBody 536870912
  5128. </Directory>
  5129. LogLevel warn
  5130. ProxyVia On
  5131. ProxyRequests off
  5132. ProxyPreserveHost on
  5133. ProxyPass / http://localhost:6543/
  5134. ErrorLog "/var/log/apache2/error.log"
  5135. CustomLog "/var/log/apache2/access.log" combined
  5136. RewriteEngine On
  5137. RewriteOptions Inherit
  5138. </VirtualHost>
  5139. #+END_SRC
  5140. Save and exit.
  5141. 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.
  5142. #+BEGIN_SRC: bash
  5143. editor /srv/mymediagoblindomain/mediagoblin/mediagoblin_local.ini
  5144. #+END_SRC
  5145. Then set:
  5146. #+BEGIN_SRC: bash
  5147. allow_registration = false
  5148. #+END_SRC
  5149. Save and exit.
  5150. ** Run a pastebin service
  5151. 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.
  5152. 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]].
  5153. #+BEGIN_SRC: bash
  5154. adduser --disabled-login zerobin
  5155. mkdir ~/build
  5156. cd ~/build
  5157. git clone https://github.com/sametmax/0bin.git
  5158. cd 0bin
  5159. python setup.py install
  5160. chown -R zerobin:zerobin /usr/local/lib/python2.7/dist-packages/zerobin-0.4.1-py2.7.egg/zerobin/static
  5161. #+END_SRC
  5162. 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]].
  5163. Now create the daemon.
  5164. #+BEGIN_SRC: bash
  5165. editor /etc/init.d/zerobin
  5166. #+END_SRC
  5167. Add the following text:
  5168. #+BEGIN_SRC: bash
  5169. #!/bin/bash
  5170. # /etc/init.d/zerobin
  5171. ### BEGIN INIT INFO
  5172. # Provides: zerobin
  5173. # Required-Start: $remote_fs $syslog
  5174. # Required-Stop: $remote_fs $syslog
  5175. # Default-Start: 2 3 4 5
  5176. # Default-Stop: 0 1 6
  5177. # Short-Description: starts zerobin as a background daemon
  5178. # Description: starts zerobin as a background daemon
  5179. ### END INIT INFO
  5180. # Author: Bob Mottram <bob@robotics.uk.to>
  5181. #Settings
  5182. SERVICE='zerobin'
  5183. LOGFILE='/home/zerobin/zerobin.log'
  5184. COMMAND="zerobin > $LOGFILE"
  5185. USERNAME='zerobin'
  5186. NICELEVEL=19 # from 0-19 the bigger the number, the less the impact on system resources
  5187. HISTORY=1024
  5188. INVOCATION="nice -n ${NICELEVEL} ${COMMAND}"
  5189. PATH='/usr/local/sbin:/usr/local/bin:/usr/bin:/sbin:/usr/sbin:/bin'
  5190. zerobin_start() {
  5191. echo "Starting $SERVICE..."
  5192. su --command "screen -h ${HISTORY} -dmS ${SERVICE} ${INVOCATION}" $USERNAME
  5193. }
  5194. zerobin_stop() {
  5195. echo "Stopping $SERVICE"
  5196. su --command "screen -p 0 -S ${SERVICE} -X stuff "'^C'"" $USERNAME
  5197. }
  5198. #Start-Stop here
  5199. case "$1" in
  5200. start)
  5201. zerobin_start
  5202. ;;
  5203. stop)
  5204. zerobin_stop
  5205. ;;
  5206. restart)
  5207. zerobin_stop
  5208. sleep 2s
  5209. zerobin_start
  5210. ;;
  5211. *)
  5212. echo "Usage: $0 {start|stop|restart}"
  5213. exit 1
  5214. ;;
  5215. esac
  5216. exit 0
  5217. #+END_SRC
  5218. Save and exit.
  5219. #+BEGIN_SRC: bash
  5220. chmod +x /etc/init.d/zerobin
  5221. update-rc.d zerobin defaults
  5222. service zerobin start
  5223. #+END_SRC
  5224. 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:
  5225. #+BEGIN_SRC: bash
  5226. <VirtualHost *:80>
  5227. ServerAdmin username@mydomainname.com
  5228. ServerName mypastedomainname.com
  5229. <Location />
  5230. ProxyPass http://localhost:8000/
  5231. Order allow,deny
  5232. Allow from all
  5233. LimitRequestBody 256000
  5234. </Location>
  5235. ErrorLog ${APACHE_LOG_DIR}/paste_error.log
  5236. # Possible values include: debug, info, notice, warn, error, crit,
  5237. # alert, emerg.
  5238. LogLevel error
  5239. CustomLog ${APACHE_LOG_DIR}/paste.log combined
  5240. </VirtualHost>
  5241. #+END_SRC
  5242. Save and exit.
  5243. 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.
  5244. #+BEGIN_SRC: bash
  5245. service apache2 restart
  5246. #+END_SRC
  5247. 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:
  5248. #+BEGIN_SRC: bash
  5249. editor /usr/bin/zerobinupdate
  5250. #+END_SRC
  5251. Add the following:
  5252. #+BEGIN_SRC: bash
  5253. #!/bin/bash
  5254. CONTENT=/usr/local/lib/python2.7/dist-packages/zerobin-0.4.1-py2.7.egg/zerobin/static/content
  5255. # Exit if there is no content directory
  5256. if [[ ! -d $CONTENT ]]; then
  5257. exit
  5258. fi
  5259. LOG=/home/zerobin/zerobin.log
  5260. CHECK=`du -hs $CONTENT`
  5261. regex="([0-9]+)G"
  5262. if [[ $CHECK =~ $regex && ${BASH_REMATCH[1]} -gt 1 ]]; then
  5263. echo "Directory size limit exceeded - removing zerobin content" >> $LOG
  5264. rm -rf $CONTENT/*
  5265. fi
  5266. #+END_SRC
  5267. Save and exit.
  5268. #+BEGIN_SRC: bash
  5269. chmod +x /usr/bin/zerobinupdate
  5270. echo "*/5 * * * * root /usr/bin/timeout 120 /usr/bin/zerobinupdate" >> /etc/crontab
  5271. #+END_SRC
  5272. Additionally to ensure that the service is being used as intended and not as a permanent data store:
  5273. #+BEGIN_SRC: bash
  5274. editor /usr/bin/zerobinclear
  5275. #+END_SRC
  5276. Add the following:
  5277. #+BEGIN_SRC: bash
  5278. #!/bin/bash
  5279. CONTENT=/usr/local/lib/python2.7/dist-packages/zerobin-0.4.1-py2.7.egg/zerobin/static/content
  5280. # Exit if there is no content directory
  5281. if [[ ! -d $CONTENT ]]; then
  5282. exit
  5283. fi
  5284. rm -rf $CONTENT
  5285. #+END_SRC
  5286. Save and exit.
  5287. #+BEGIN_SRC: bash
  5288. chmod +x /usr/bin/zerobinclear
  5289. echo "35 3 * * * root /usr/bin/zerobinclear" >> /etc/crontab
  5290. service cron restart
  5291. #+END_SRC
  5292. This will delete all pasted content once per day.
  5293. ** Subsonic music server
  5294. #+BEGIN_VERSE
  5295. /Where words fail, music speaks./
  5296. -- Hans Christian Andersen
  5297. #+END_VERSE
  5298. *** Introduction
  5299. 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. Another limitation of Subsonic is that it requires Java, which uses a lot of RAM, so it may be better to only install it on systems with 1GB or more of memory and also increases the [[https://en.wikipedia.org/wiki/Attack_surface]["attack surface"]].
  5300. 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.
  5301. *** Installing the Server
  5302. 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.
  5303. #+BEGIN_SRC: bash
  5304. apt-get install openjdk-7-jre openjdk-7-jdk lintian maven libav-tools
  5305. adduser subsonic
  5306. mkdir ~/build
  5307. cd ~/build
  5308. wget http://freedombone.uk.to/subsonic-4.9.deb
  5309. sha256sum subsonic-4.9.deb
  5310. 064c2a7e69d47715ce230f3dfcacdc627c18f6466e0fe48952f133ce06be698d
  5311. dpkg -i subsonic-4.9.deb
  5312. #+END_SRC
  5313. Now we remove the antifeature by compiling from source and then overwriting the relevant files.
  5314. #+BEGIN_SRC: bash
  5315. git clone https://github.com/EugeneKay/subsonic.git
  5316. cd subsonic
  5317. git checkout release
  5318. mvn package
  5319. mvn -P full -pl subsonic-booter -am install
  5320. mvn -P full -pl subsonic-installer-debian/ -am install
  5321. cp ~/build/subsonic/subsonic-booter/target/subsonic-booter-jar-with-dependencies.jar /usr/share/subsonic/
  5322. cp ~/build/subsonic/subsonic-main/target/subsonic.war /usr/share/subsonic/subsonic.war
  5323. cp ~/build/subsonic/subsonic-booter/src/main/script/subsonic.sh /usr/share/subsonic/subsonic.sh
  5324. editor /etc/default/subsonic
  5325. #+END_SRC
  5326. Settings should look like the following.
  5327. #+BEGIN_SRC: bash
  5328. SUBSONIC_ARGS="--max-memory=100"
  5329. SUBSONIC_USER=subsonic
  5330. #+END_SRC
  5331. Save and exit.
  5332. #+BEGIN_SRC: bash
  5333. chown -R subsonic:subsonic /var/subsonic
  5334. mkdir /var/music
  5335. chown -R subsonic:subsonic /var/music
  5336. service subsonic restart
  5337. #+END_SRC
  5338. Edit your web server configuration.
  5339. #+BEGIN_SRC: bash
  5340. editor /etc/nginx/sites-available/$HOSTNAME
  5341. #+END_SRC
  5342. Delete all existing contents then add the following:
  5343. #+BEGIN_SRC: bash
  5344. server {
  5345. listen 80;
  5346. server_name mysubsonicdomainname.com;
  5347. rewrite ^ https://$server_name$request_uri? permanent;
  5348. }
  5349. server {
  5350. listen 443;
  5351. server_name mysubsonicdomainname.com;
  5352. index index.html index.htm;
  5353. error_log /var/www/mysubsonicdomainname.com/error.log debug;
  5354. ssl on;
  5355. ssl_certificate /etc/ssl/certs/mysubsonicdomainname.com.crt;
  5356. ssl_certificate_key /etc/ssl/private/mysubsonicdomainname.com.key;
  5357. ssl_dhparam /etc/ssl/certs/mysubsonicdomainname.com.dhparam;
  5358. ssl_session_timeout 5m;
  5359. ssl_prefer_server_ciphers on;
  5360. ssl_session_cache builtin:1000 shared:SSL:10m;
  5361. ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # not possible to do exclusive
  5362. 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';
  5363. add_header Strict-Transport-Security "max-age=0;";
  5364. client_max_body_size 20M;
  5365. location / {
  5366. proxy_pass http://localhost:4040/;
  5367. proxy_redirect http:// https://;
  5368. proxy_set_header Host $host;
  5369. proxy_set_header X-Real-IP $remote_addr;
  5370. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  5371. }
  5372. }
  5373. #+END_SRC
  5374. Save and exit.
  5375. #+BEGIN_SRC: bash
  5376. export HOSTNAME=mysubsonicdomainname.com
  5377. sed "s/mysubsonicdomainname.com/$HOSTNAME/g" /etc/nginx/sites-available/$HOSTNAME > /tmp/website
  5378. cp -f /tmp/website /etc/nginx/sites-available/$HOSTNAME
  5379. /etc/init.d/nginx reload
  5380. #+END_SRC
  5381. *** Configuration
  5382. Open a browser and go to your subsonic domain name. Log in with username /admin/ and password /admin/, then change your administrator password.
  5383. Still logged in as the administrator, click /settings/ and select /transcoding/. Change the transcoding settings to the following:
  5384. | Name | Convert from | Convert to | Step 1 |
  5385. |----------------+---------------------------------------------------+------------+------------------------------------------------------------------------------------------------------------------------------------------|
  5386. | 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 - |
  5387. | 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 - |
  5388. | Downsample command | avconv -i %s -b %bk -v 0 -f mp3 - |
  5389. | 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 - |
  5390. Then save.
  5391. 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.
  5392. Open port 4040 on your internet router and forward it to the BBB.
  5393. *** Adding your music
  5394. 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.
  5395. So with the USB stick plugged in and logged into the BBB as root via ssh:
  5396. #+BEGIN_SRC: bash
  5397. mount /dev/sda1 /var/music
  5398. chown -R subsonic:subsonic /var/music
  5399. #+END_SRC
  5400. Then within a browser go to your Subsonic domain name, log in as the administrator, 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. WHen It's complete you can log out and log back in as a user.
  5401. *** Android App
  5402. Within [[https://f-droid.org/][F-Droid]] search for *Dsub* and install it.
  5403. 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.
  5404. Remove any other servers (including the demo) by pressing on them then selecting *remove server*.
  5405. 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.
  5406. 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.
  5407. ** Database maintenance
  5408. #+BEGIN_VERSE
  5409. /To be ready to fail is to be prepared for success./
  5410. -- Jose Bergamin
  5411. #+END_VERSE
  5412. 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.
  5413. #+BEGIN_SRC: bash
  5414. editor /usr/bin/repairdatabase
  5415. #+END_SRC
  5416. Add the following, using your mysql root password and entering your email address.
  5417. #+BEGIN_SRC: bash
  5418. #!/bin/bash
  5419. DATABASE=$1
  5420. EMAIL=myusername@mydomainname.com
  5421. MYSQL_ROOT_PASSWORD=mysqlrootpassword
  5422. TEMPFILE=/tmp/repairdatabase_$DATABASE
  5423. umask 0077
  5424. # check the database
  5425. mysqlcheck -c -u root --password=$MYSQL_ROOT_PASSWORD $DATABASE > $TEMPFILE
  5426. # Attempt to repair the database if it contains errors
  5427. if grep -q "Error" "$TEMPFILE"; then
  5428. mysqlcheck -u root --password=$MYSQL_ROOT_PASSWORD --auto-repair $DATABASE
  5429. else
  5430. # No errors were found, so exit
  5431. rm -f $TEMPFILE
  5432. exit 0
  5433. fi
  5434. rm -f $TEMPFILE
  5435. # Check the database again
  5436. mysqlcheck -c -u root --password=$MYSQL_ROOT_PASSWORD $DATABASE > $TEMPFILE
  5437. # If it still contains errors then restore from backup
  5438. if grep -q "Error" "$TEMPFILE"; then
  5439. mysql -u root --password=$MYSQL_ROOT_PASSWORD $DATABASE -o < /var/backups/${DATABASE}_daily.sql
  5440. # Send a warning email
  5441. echo "$DATABASE database corruption could not be repaired. Restored from backup." | mail -s "Freedombone database maintenance" $EMAIL
  5442. rm -f $TEMPFILE
  5443. exit 1
  5444. fi
  5445. rm -f $TEMPFILE
  5446. exit 0
  5447. #+END_SRC
  5448. Save and exit.
  5449. #+BEGIN_SRC: bash
  5450. chmod 600 /usr/bin/repairdatabase
  5451. editor /etc/cron.hourly/repair
  5452. #+END_SRC
  5453. Add the following. If you're using Red Matrix then uncomment that line.
  5454. #+BEGIN_SRC: bash
  5455. #!/bin/bash
  5456. repairdatabase friendica
  5457. #repairdatabase redmatrix
  5458. repairdatabase roundcubemail
  5459. #+END_SRC
  5460. Save and exit.
  5461. #+BEGIN_SRC: bash
  5462. chmod +x /etc/cron.hourly/repair
  5463. #+END_SRC
  5464. 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.
  5465. #+BEGIN_SRC: bash
  5466. editor /usr/bin/runinitialrepair
  5467. #+END_SRC
  5468. Add the following:
  5469. #+BEGIN_SRC: bash
  5470. #!/bin/bash
  5471. sleep 180
  5472. /etc/cron.hourly/repair > /var/log/initialrepair.log
  5473. exit 0
  5474. #+END_SRC
  5475. Save and exit.
  5476. #+BEGIN_SRC: bash
  5477. chmod +x /usr/bin/runinitialrepair
  5478. editor /etc/init.d/initialrepair
  5479. #+END_SRC
  5480. Add the following:
  5481. #+BEGIN_SRC: bash
  5482. #!/bin/bash
  5483. # /etc/init.d/initialrepair
  5484. ### BEGIN INIT INFO
  5485. # Provides: initialrepair
  5486. # Required-Start: $remote_fs $syslog
  5487. # Required-Stop: $remote_fs $syslog
  5488. # Default-Start: 2 3 4 5
  5489. # Default-Stop: 0 1 6
  5490. # Short-Description: mysql database repair on boot
  5491. # Description: Repairs mysql databases at startup
  5492. ### END INIT INFO
  5493. # Author: Bob Mottram <bob@robotics.uk.to>
  5494. #Settings
  5495. SERVICE='initialrepair'
  5496. INVOCATION='/usr/bin/runinitialrepair'
  5497. PATH='/usr/local/sbin:/usr/local/bin:/usr/bin:/sbin:/usr/sbin:/bin'
  5498. initialrepair_start() {
  5499. echo "Starting $SERVICE..."
  5500. su --command "screen -h 1024 -dmS ${SERVICE} ${INVOCATION}" root
  5501. }
  5502. initialrepair_stop() {
  5503. echo "Stopping $SERVICE"
  5504. su --command "screen -p 0 -S ${SERVICE} -X stuff "'^C'"" root
  5505. }
  5506. #Start-Stop here
  5507. case "$1" in
  5508. start)
  5509. initialrepair_start
  5510. ;;
  5511. stop)
  5512. initialrepair_stop
  5513. ;;
  5514. restart)
  5515. initialrepair_stop
  5516. initialrepair_start
  5517. ;;
  5518. *)
  5519. echo "Usage: $0 {start|stop|restart}"
  5520. exit 1
  5521. ;;
  5522. esac
  5523. exit 0
  5524. #+END_SRC
  5525. Save and exit.
  5526. #+BEGIN_SRC: bash
  5527. chmod +x /etc/init.d/initialrepair
  5528. update-rc.d initialrepair defaults
  5529. service initialrepair start
  5530. #+END_SRC
  5531. ** Install Tripwire
  5532. #+BEGIN_VERSE
  5533. /...by the time you get done with all of that, we have a freedom box/
  5534. -- Eben Moglen
  5535. #+END_VERSE
  5536. 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.
  5537. #+BEGIN_SRC: bash
  5538. apt-get install tripwire
  5539. export HOSTNAME=mydomainname.com
  5540. cd /etc/tripwire
  5541. cp arm-local.key $HOSTNAME-local.key
  5542. cp site.key $HOSTNAME-site.key
  5543. tripwire --init
  5544. tripwire --update-policy --secure-mode low /etc/tripwire/twpol.txt
  5545. tripwire --check --interactive
  5546. #+END_SRC
  5547. you will be asked for two passphrases ("site" and "local"). Make a note of these.
  5548. Turn off reporting of changes to system logs.
  5549. #+BEGIN_SRC: bash
  5550. editor /etc/tripwire/twcfg.txt
  5551. #+END_SRC
  5552. Set *SYSLOGREPORTING* to false and comment out the line, then save and exit.
  5553. #+BEGIN_SRC: bash
  5554. editor /etc/tripwire/twpol.txt
  5555. #+END_SRC
  5556. Edit the "Root config files" section so that it looks like this:
  5557. #+BEGIN_SRC: bash
  5558. # These files change the behavior of the root account
  5559. (
  5560. rulename = "Root config files",
  5561. severity = 100
  5562. )
  5563. {
  5564. /root -> $(SEC_CRIT) ; # Catch all additions to /root
  5565. /root/.bashrc -> $(SEC_CONFIG) ;
  5566. /root/.bash_history -> $(SEC_CONFIG) ;
  5567. }
  5568. #+END_SRC
  5569. Then save and exit.
  5570. #+BEGIN_SRC: bash
  5571. editor /usr/bin/reset-tripwire
  5572. #+END_SRC
  5573. Add the following:
  5574. #+BEGIN_SRC: bash
  5575. #!/bin/sh
  5576. tripwire --update-policy --secure-mode low /etc/tripwire/twpol.txt
  5577. #+END_SRC
  5578. Save and exit.
  5579. #+BEGIN_SRC: bash
  5580. chmod +x /usr/bin/reset-tripwire
  5581. #+END_SRC
  5582. If you subsequently install any more packages or make configuration changes then update the policy again with:
  5583. #+BEGIN_SRC: bash
  5584. reset-tripwire
  5585. #+END_SRC
  5586. Also, to look for any rootkits.
  5587. #+BEGIN_SRC: bash
  5588. apt-get install rkhunter
  5589. #+END_SRC
  5590. * Router/Firewall ports
  5591. The following ports on your internet router/firewall should be forwarded to the BBB.
  5592. | Protocol | Port/s |
  5593. |---------------+------------|
  5594. | Gopher | 70 |
  5595. | HTTP | 80 |
  5596. | HTTPS | 443 |
  5597. | IMAP | 143 |
  5598. | IRC | 6665..6669 |
  5599. | IRC SSL | 6697 |
  5600. | SIP | 5060..5061 |
  5601. | SMTP | 25,587 |
  5602. | SMTPS | 465 |
  5603. | SSH | 22 |
  5604. | XMPP | 5222..5223 |
  5605. | XMPP (server) | 5269 |
  5606. | XMPP (BOSH) | 5280..5281 |
  5607. | Bitmessage | 8444 |
  5608. | Subsonic | 4040 |
  5609. * Hints and Tips
  5610. ** Example configurations
  5611. *** Software sources
  5612. 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*
  5613. **** Beaglebone Black
  5614. #+BEGIN_SRC: bash
  5615. deb http://ftp.us.debian.org/debian/ jessie main contrib
  5616. deb-src http://ftp.us.debian.org/debian/ jessie main contrib
  5617. deb http://ftp.us.debian.org/debian/ jessie-updates main contrib
  5618. deb-src http://ftp.us.debian.org/debian/ jessie-updates main contrib
  5619. #Kernel source: https://github.com/RobertCNelson/linux-stable-rcn-ee
  5620. deb [arch=armhf] http://repos.rcn-ee.net/debian/ jessie main
  5621. deb http://ftp.us.debian.org/debian jessie-backports main
  5622. #+END_SRC
  5623. **** Cubieboard
  5624. #+BEGIN_SRC: bash
  5625. deb http://ftp.us.debian.org/debian/ wheezy main contrib
  5626. deb-src http://ftp.us.debian.org/debian/ wheezy main contrib
  5627. deb http://ftp.us.debian.org/debian/ wheezy-updates main contrib
  5628. deb-src http://ftp.us.debian.org/debian/ wheezy-updates main contrib
  5629. deb http://security.debian.org/ wheezy/updates main contrib
  5630. deb-src http://security.debian.org/ wheezy/updates main contrib
  5631. deb http://ftp.us.debian.org/debian wheezy-backports main contrib
  5632. deb http://mirrors.sohu.com/debian/ wheezy main contrib
  5633. deb-src http://mirrors.sohu.com/debian/ wheezy main contrib
  5634. deb http://packages.cubian.org/ wheezy main
  5635. deb http://repo.ajenti.org/debian main main debian
  5636. #+END_SRC
  5637. *** Emacs setup
  5638. An example Emacs configuration file. This should be saved to */home/myusername/.emacs* and */root/.emacs*
  5639. #+BEGIN_SRC: bash
  5640. (add-to-list 'load-path "~/.emacs.d/")
  5641. ;; ===== Remove trailing whitepace ======================================
  5642. (add-hook 'before-save-hook 'delete-trailing-whitespace)
  5643. ;; ===== Press CTRL-L to go to a line number ============================
  5644. (global-set-key "\C-l" 'goto-line)
  5645. ;; ===== Show line numbers ==============================================
  5646. (add-hook 'find-file-hook (lambda () (linum-mode 1)))
  5647. ;; ===== Enable line wrapping in org-mode ===============================
  5648. (add-hook 'org-mode-hook
  5649. '(lambda ()
  5650. (visual-line-mode 1)))
  5651. ;; ===== Enable shift select in org mode ================================
  5652. (setq org-support-shift-select t)
  5653. ;; ===== Set standard indent to 4 spaces ================================
  5654. (setq standard-indent 4)
  5655. (setq-default tab-width 4)
  5656. (setq c-basic-offset 4)
  5657. ;; ===== Support Wheel Mouse Scrolling =================================
  5658. (mouse-wheel-mode t)
  5659. ;; ===== Place Backup Files in Specific Directory ======================
  5660. (setq make-backup-files t)
  5661. (setq version-control t)
  5662. (setq backup-directory-alist (quote ((".*" . "~/.emacs_backups/"))))
  5663. ;; ===== Make Text mode the default mode for new buffers ===============
  5664. (setq default-major-mode 'text-mode)
  5665. ;; ===== Line length ===================================================
  5666. (setq-default fill-column 72)
  5667. ;; ===== Enable Line and Column Numbering ==============================
  5668. (line-number-mode 1)
  5669. (column-number-mode 1)
  5670. ;; ===== Turn on Auto Fill mode automatically in all modes =============
  5671. ;; Auto-fill-mode the the automatic wrapping of lines and insertion of
  5672. ;; newlines when the cursor goes over the column limit.
  5673. ;; This should actually turn on auto-fill-mode by default in all major
  5674. ;; modes. The other way to do this is to turn on the fill for specific
  5675. ;; modes via hooks.
  5676. (setq auto-fill-mode 1)
  5677. ;; ===== Enable GPG encryption ========================================
  5678. (require 'epa)
  5679. (epa-file-enable)
  5680. #+END_SRC
  5681. *** Boot (uEnv.txt)
  5682. An example of the uEnv.txt file within the BOOT partition on the microSD card of the BBB.
  5683. #+BEGIN_SRC: bash
  5684. ##These are needed to be compliant with Debian 2014-05-14 u-boot.
  5685. loadximage=load mmc 0:2 ${loadaddr} /boot/vmlinuz-${uname_r}
  5686. loadxfdt=load mmc 0:2 ${fdtaddr} /boot/dtbs/${uname_r}/${fdtfile}
  5687. loadxrd=load mmc 0:2 ${rdaddr} /boot/initrd.img-${uname_r}; setenv rdsize ${filesize}
  5688. loaduEnvtxt=load mmc 0:2 ${loadaddr} /boot/uEnv.txt ; env import -t ${loadaddr} ${filesize};
  5689. loadall=run loaduEnvtxt; run loadximage; run loadxrd; run loadxfdt;
  5690. mmcargs=setenv bootargs console=tty0 console=${console} ${optargs} ${cape_disable} ${cape_enable} root=${mmcroot} rootfstype=${mmcrootfstype} ${cmdline}
  5691. uenvcmd=run loadall; run mmcargs; bootz ${loadaddr} ${rdaddr}:${rdsize} ${fdtaddr};
  5692. #+END_SRC
  5693. ** Messaging security
  5694. 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.
  5695. ** Moving Domains
  5696. 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:
  5697. #+BEGIN_SRC: bash
  5698. find /var/www/mynewdomain/htdocs -type f -exec sed -i 's@myolddomain@mynewdomain@g' {} \;
  5699. #+END_SRC
  5700. If you're moving the blog to a new domain then you will need to delete the lock file:
  5701. #+BEGIN_SRC: bash
  5702. rm /var/www/myblogdomainname.com/htdocs/fp-content/%%setup.lock
  5703. #+END_SRC
  5704. 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.
  5705. 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*.
  5706. ** MySql foo
  5707. *** Reset the root password
  5708. To reset the root password, or if mysql forgets its root password.
  5709. #+BEGIN_SRC: bash
  5710. /etc/init.d/mysql stop
  5711. mysqld_safe --skip-grant-tables &
  5712. mysql -u root
  5713. use mysql;
  5714. update user set password=PASSWORD("mynewpassword") where User='root';
  5715. flush privileges;
  5716. quit
  5717. /etc/init.d/mysql stop
  5718. /etc/init.d/mysql start
  5719. #+END_SRC
  5720. *** Repair and optimize databases
  5721. To check, repair and optimize the databases.
  5722. #+BEGIN_SRC: bash
  5723. mysqlcheck -c -u root -p --all-databases
  5724. mysqlcheck -u root -p --auto-repair --all-databases
  5725. mysqlcheck -u root -p -o --all-databases
  5726. #+END_SRC
  5727. *** Backup all databases
  5728. To back up all mysql databases:
  5729. #+BEGIN_SRC: bash
  5730. mysqldump -u root -p --all-databases --events > /var/backups/databasebackup.sql
  5731. #+END_SRC
  5732. *** Restoring a particular mysql database
  5733. To restore yesterday's friendica backup:
  5734. #+BEGIN_SRC: bash
  5735. mysql -u root -p friendica -o < /var/backups/friendica_daily.sql
  5736. #+END_SRC
  5737. To restore the webmail database:
  5738. #+BEGIN_SRC: bash
  5739. mysql -u root -p roundcubemail -o < /var/backups/roundcubemail_daily.sql
  5740. #+END_SRC
  5741. To restore yesterday's Red Matrix backup:
  5742. #+BEGIN_SRC: bash
  5743. mysql -u root -p redmatrix -o < /var/backups/redmatrix_daily.sql
  5744. #+END_SRC
  5745. *** Removing and reinstalling mysql server
  5746. 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:
  5747. #+BEGIN_SRC: bash
  5748. ps aux | grep mysql
  5749. #+END_SRC
  5750. and use /kill -9 <pid>/ to kill all mysql processes.
  5751. #+BEGIN_SRC: bash
  5752. apt-get remove --purge mysql\*
  5753. rm -rf /etc/mysql
  5754. rm -rf /var/lib/mysql
  5755. apt-get clean
  5756. updatedb
  5757. #+END_SRC
  5758. Reinstall mysql:
  5759. #+BEGIN_SRC: bash
  5760. apt-get install mysql-server php5-common php5-cli php5-curl php5-gd php5-mysql php5-mcrypt php5-fpm php5-cgi php-apc
  5761. #+END_SRC
  5762. Then to recreate the Friendica and webmail databases:
  5763. #+BEGIN_SRC: bash
  5764. mysql -p
  5765. create database friendica;
  5766. CREATE USER 'friendicaadmin'@'localhost' IDENTIFIED BY 'myfriendicapassword';
  5767. GRANT ALL PRIVILEGES ON friendica.* TO 'friendicaadmin'@'localhost';
  5768. create database roundcubemail;
  5769. CREATE USER 'roundcube'@'localhost' IDENTIFIED BY 'roundcubepassword';
  5770. GRANT ALL PRIVILEGES ON roundcubemail.* TO 'roundcube'@'localhost';
  5771. quit
  5772. mysql -u root -p friendica -o < /var/backups/friendica_daily.sql
  5773. mysql -u root -p roundcubemail -o < /var/backups/roundcubemail_daily.sql
  5774. #+END_SRC
  5775. And if you previously had Red Matrix installed:
  5776. #+BEGIN_SRC: bash
  5777. mysql -p
  5778. create database redmatrix;
  5779. CREATE USER 'redmatrixadmin'@'localhost' IDENTIFIED BY 'myredmatrixpassword';
  5780. GRANT ALL PRIVILEGES ON redmatrix.* TO 'redmatrixadmin'@'localhost';
  5781. quit
  5782. mysql -u root -p redmatrix -o < /var/backups/redmatrix_daily.sql
  5783. #+END_SRC
  5784. Since IMAP seems entangled with mysql it may also be necessary to reinstall Exim and Dovecot.
  5785. #+BEGIN_SRC: bash
  5786. apt-get remove --purge exim4\*
  5787. #+END_SRC
  5788. Then follow the instructions in [[Install Email]], [[Spam filtering]] and [[Install Dovecot]].
  5789. ** Regenerating SSL certificates
  5790. 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:
  5791. Obtain the latest updates:
  5792. #+BEGIN_SRC: bash
  5793. apt-get update
  5794. apt-get upgrade
  5795. #+END_SRC
  5796. Run *makecert <domain>* for each of your sites.
  5797. Recreate the XMPP certificate:
  5798. #+BEGIN_SRC: bash
  5799. makecert xmpp
  5800. chown prosody:prosody /etc/ssl/private/xmpp.key
  5801. chown prosody:prosody /etc/ssl/certs/xmpp.*
  5802. #+END_SRC
  5803. And regenerate the IRC server keys:
  5804. #+BEGIN_SRC: bash
  5805. makecert ircd
  5806. mv /etc/ssl/private/ircd.key /home/ircserver/ircd/ssl/
  5807. mv /etc/ssl/certs/ircd.crt /home/ircserver/ircd/ssl/ircd.pem
  5808. mv /etc/ssl/certs/ircd.dhparam /home/ircserver/ircd/ssl/dhparam.pem
  5809. chmod 640 /home/ircserver/ircd/ssl/*
  5810. chown -R ircserver:ircserver /home/ircserver/ircd
  5811. chown -R ircserver:ircserver /home/ircserver/services
  5812. chown -R ircserver:ircserver /home/ircserver/ircd/ssl
  5813. #+END_SRC
  5814. Regenerate email certificate.
  5815. #+BEGIN_SRC: bash
  5816. makecert exim
  5817. mv /etc/ssl/private/exim.key /etc/exim4
  5818. mv /etc/ssl/certs/exim.crt /etc/exim4
  5819. mv /etc/ssl/certs/exim.dhparam /etc/exim4
  5820. chown root:Debian-exim /etc/exim4/exim.key /etc/exim4/exim.crt /etc/exim4/exim.dhparam
  5821. chmod 640 /etc/exim4/exim.key /etc/exim4/exim.crt /etc/exim4/exim.dhparam
  5822. #+END_SRC
  5823. As an added precaution you may wish to regenerate your ssh host keys:
  5824. #+BEGIN_SRC: bash
  5825. rm /etc/ssh/ssh_host_*
  5826. dpkg-reconfigure openssh-server
  5827. #+END_SRC
  5828. Then reboot the server with:
  5829. #+BEGIN_SRC: bash
  5830. reboot
  5831. #+END_SRC
  5832. ** Example crontab file
  5833. 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.
  5834. #+BEGIN_SRC: bash
  5835. # /etc/crontab: system-wide crontab
  5836. # Unlike any other crontab you don't have to run the `crontab'
  5837. # command to install the new version when you edit this file
  5838. # and files in /etc/cron.d. These files also have username fields,
  5839. # that none of the other crontabs do.
  5840. SHELL=/bin/sh
  5841. PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
  5842. # m h dom mon dow user command
  5843. 10,20,30,40,50 * * * * root /usr/bin/timeout 120 /usr/bin/dynamicdns && /usr/bin/spamfilter myusername
  5844. 15,35,55 * * * * root cd /var/www/mydomainname/htdocs; /usr/bin/timeout 240 /usr/bin/php include/poller.php
  5845. 17 * * * * root cd / && run-parts --report /etc/cron.hourly
  5846. 25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
  5847. 47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
  5848. 52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
  5849. #+END_SRC
  5850. ** Using your own domain
  5851. Suppose that you have bought a domain name (rather than using a free subdomain on freedns) and you want to use that instead.
  5852. Remove any existing nameservers for your domain (or select "custom" nameservers), then add:
  5853. #+BEGIN_SRC: bash
  5854. NS1.AFRAID.ORG
  5855. NS2.AFRAID.ORG
  5856. NS3.AFRAID.ORG
  5857. NS4.AFRAID.ORG
  5858. #+END_SRC
  5859. 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".
  5860. 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*.
  5861. To route email to one of your freedns domains:
  5862. #+BEGIN_SRC: bash
  5863. editor /etc/mailname
  5864. #+END_SRC
  5865. Add any extra domains which you own, then save and exit.
  5866. #+BEGIN_SRC: bash
  5867. editor /etc/exim4/update-exim4.conf.conf
  5868. #+END_SRC
  5869. Within dc_other_hostnames add your extra domain names, separated by a colon ':' character.
  5870. Save and exit, then restart exim.
  5871. #+BEGIN_SRC: bash
  5872. update-exim4.conf.template -r
  5873. update-exim4.conf
  5874. service exim4 restart
  5875. #+END_SRC
  5876. You should now be able to send an email from /postmaster@mynewdomainname/ and it should arrive in your inbox.
  5877. ** Obtaining an "official" SSL certificate
  5878. 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).
  5879. 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.
  5880. Firstly you should have a web server site configuration ready to go. See [[Setting up a web site]] for details.
  5881. Within StartSSL under the validations wizard validate your domain, which means sending an email to it and confirming a code.
  5882. Now we can generate the certificate request as follows.
  5883. #+BEGIN_SRC: bash
  5884. export HOSTNAME=mydomainname.com
  5885. openssl genrsa -out /etc/ssl/private/$HOSTNAME.key 2048
  5886. chown root:ssl-cert /etc/ssl/private/$HOSTNAME.key
  5887. chmod 440 /etc/ssl/private/$HOSTNAME.key
  5888. mkdir /etc/ssl/requests
  5889. #+END_SRC
  5890. Now make a certificate request as follows. You should copy and paste the whole of this, not just line by line.
  5891. #+BEGIN_SRC: bash
  5892. openssl req -new -sha256 -key /etc/ssl/private/$HOSTNAME.key -out /etc/ssl/requests/$HOSTNAME.csr
  5893. #+END_SRC
  5894. For the email address it's a good idea to use postmaster@mydomainname.
  5895. Use a random 20 character password, and keep a note of it. We'll remove this later.
  5896. View the request with:
  5897. #+BEGIN_SRC: bash
  5898. cat /etc/ssl/requests/$HOSTNAME.csr
  5899. #+END_SRC
  5900. 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.
  5901. Log into your StartSSL account and select *Retrieve Certificate* from the *Tool Box* tab. Copy the text.
  5902. #+BEGIN_SRC: bash
  5903. editor /etc/ssl/certs/$HOSTNAME.crt
  5904. #+END_SRC
  5905. Paste the public key, then save and exit. Then on the BBB.
  5906. #+BEGIN_SRC: bash
  5907. mkdir /etc/ssl/roots
  5908. mkdir /etc/ssl/chains
  5909. wget "http://www.startssl.com/certs/ca.pem" --output-document="/etc/ssl/roots/startssl-root.ca"
  5910. wget "http://www.startssl.com/certs/sub.class1.server.ca.pem" --output-document="/etc/ssl/chains/startssl-sub.class1.server.ca.pem"
  5911. wget "http://www.startssl.com/certs/sub.class2.server.ca.pem" --output-document="/etc/ssl/chains/startssl-sub.class2.server.ca.pem"
  5912. wget "http://www.startssl.com/certs/sub.class3.server.ca.pem" --output-document="/etc/ssl/chains/startssl-sub.class3.server.ca.pem"
  5913. ln -s "/etc/ssl/roots/startssl-root.ca" "/etc/ssl/roots/$HOSTNAME-root.ca"
  5914. ln -s "/etc/ssl/chains/startssl-sub.class1.server.ca.pem" "/etc/ssl/chains/$HOSTNAME.ca"
  5915. cp "/etc/ssl/certs/$HOSTNAME.crt" "/etc/ssl/certs/$HOSTNAME.crt+chain+root"
  5916. test -e "/etc/ssl/chains/$HOSTNAME.ca" && cat "/etc/ssl/chains/$HOSTNAME.ca" >> "/etc/ssl/certs/$HOSTNAME.crt+chain+root"
  5917. test -e "/etc/ssl/roots/$HOSTNAME-root.ca" && cat "/etc/ssl/roots/$HOSTNAME-root.ca" >> "/etc/ssl/certs/$HOSTNAME.crt+chain+root"
  5918. #+END_SRC
  5919. To avoid any possibility of the certificates being accidentally overwritten by self-signed ones at a later date you can create backups.
  5920. #+BEGIN_SRC: bash
  5921. mkdir /etc/ssl/backups
  5922. mkdir /etc/ssl/backups/certs
  5923. mkdir /etc/ssl/backups/private
  5924. cp /etc/ssl/certs/$HOSTNAME* /etc/ssl/backups/certs/
  5925. cp /etc/ssl/private/$HOSTNAME* /etc/ssl/backups/private/
  5926. chmod -R 400 /etc/ssl/backups/certs/*
  5927. chmod -R 400 /etc/ssl/backups/private/*
  5928. #+END_SRC
  5929. 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.
  5930. #+BEGIN_SRC: bash
  5931. openssl rsa -in /etc/ssl/private/$HOSTNAME.key -out /etc/ssl/private/$HOSTNAME.new.key
  5932. cp /etc/ssl/private/$HOSTNAME.new.key /etc/ssl/private/$HOSTNAME.key
  5933. shred -zu /etc/ssl/private/$HOSTNAME.new.key
  5934. #+END_SRC
  5935. Create a bundled certificate which joins the certificate and chain file together.
  5936. #+BEGIN_SRC: bash
  5937. cat /etc/ssl/certs/$HOSTNAME.crt /etc/ssl/chains/startssl-sub.class1.server.ca.pem > /etc/ssl/certs/$HOSTNAME.bundle.crt
  5938. #+END_SRC
  5939. And also add it to the overall bundle of certificates for the BBB. This will allow you to easily install the certificates onto other systems.
  5940. #+BEGIN_SRC: bash
  5941. mkdir /etc/ssl/mycerts
  5942. cp /etc/ssl/certs/$HOSTNAME.bundle.crt /etc/ssl/mycerts
  5943. cat /etc/ssl/mycerts/*.crt > /etc/ssl/freedombone-bundle.crt
  5944. tar -czvf /etc/ssl/freedombone-certs.tar.gz /etc/ssl/mycerts/*.crt
  5945. #+END_SRC
  5946. Edit your configuration file.
  5947. #+BEGIN_SRC: bash
  5948. editor /etc/nginx/sites-available/$HOSTNAME
  5949. #+END_SRC
  5950. Add the following to the section which starts with *listen 443*
  5951. #+BEGIN_SRC: bash
  5952. ssl_certificate /etc/ssl/certs/mydomainname.com.bundle.crt;
  5953. #+END_SRC
  5954. Save and exit, then restart the web server.
  5955. #+BEGIN_SRC: bash
  5956. service nginx restart
  5957. #+END_SRC
  5958. 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]].
  5959. * Deprecated
  5960. The following items have been deprecated until such time as a successful installation is achieved.
  5961. ** Gitlab
  5962. Install some dependencies:
  5963. #+BEGIN_SRC: bash
  5964. apt-get update -y
  5965. apt-get upgrade -y
  5966. apt-get install sudo -y
  5967. 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
  5968. #+END_SRC
  5969. Install bundler
  5970. #+BEGIN_SRC: bash
  5971. gem install bundler --no-ri --no-rdoc
  5972. #+END_SRC
  5973. Create a user for running Gitlab.
  5974. #+BEGIN_SRC: bash
  5975. adduser --disabled-login --gecos 'GitLab' git
  5976. #+END_SRC
  5977. Install mysql (it may already be installed).
  5978. #+BEGIN_SRC: bash
  5979. apt-get install -y mysql-server mysql-client libmysqlclient-dev
  5980. mysql_secure_installation
  5981. mysql -u root -p
  5982. #+END_SRC
  5983. Enter the following commands, substituting /gitlabpassword/ with a password to be used for the Gitlab installation.
  5984. #+BEGIN_SRC: bash
  5985. CREATE USER 'git'@'localhost' IDENTIFIED BY 'gitlabpassword';
  5986. SET storage_engine=INNODB;
  5987. CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
  5988. GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'git'@'localhost';
  5989. quit
  5990. #+END_SRC
  5991. Obtain the code and install it.
  5992. #+BEGIN_SRC: bash
  5993. cd /home/git
  5994. sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 6-8-stable gitlab
  5995. cd /home/git/gitlab
  5996. sudo -u git -H cp /home/git/gitlab/config/gitlab.yml.example /home/git/gitlab/config/gitlab.yml
  5997. sudo -u git -H editor /home/git/gitlab/config/gitlab.yml
  5998. #+END_SRC
  5999. Set /host/ to your gitlab domain name, /port/ to 443 and /https/ to true, then save and exit.
  6000. #+BEGIN_SRC: bash
  6001. chown -R git /home/git/gitlab/log/
  6002. chown -R git /home/git/gitlab/tmp/
  6003. chmod -R u+rwX /home/git/gitlab/log/
  6004. chmod -R u+rwX /home/git/gitlab/tmp/
  6005. sudo -u git -H mkdir /home/git/gitlab-satellites
  6006. chmod u+rwx,g+rx,o-rwx /home/git/gitlab-satellites
  6007. chmod -R u+rwX /home/git/gitlab/tmp/pids/
  6008. chmod -R u+rwX /home/git/gitlab/tmp/sockets/
  6009. chmod -R u+rwX /home/git/gitlab/public/uploads
  6010. sudo -u git -H cp /home/git/gitlab/config/unicorn.rb.example /home/git/gitlab/config/unicorn.rb
  6011. #sudo -u git -H editor /home/git/gitlab/config/unicorn.rb
  6012. sudo -u git -H cp /home/git/gitlab/config/initializers/rack_attack.rb.example /home/git/gitlab/config/initializers/rack_attack.rb
  6013. sudo -u git -H git config --global user.name "GitLab"
  6014. sudo -u git -H git config --global user.email "gitlab@localhost"
  6015. sudo -u git -H git config --global core.autocrlf input
  6016. sudo -u git cp /home/git/gitlab/config/database.yml.mysql /home/git/gitlab/config/database.yml
  6017. sudo -u git -H chmod o-rwx /home/git/gitlab/config/database.yml
  6018. sudo -u git -H bundle install --deployment --without development test postgres aws
  6019. #+END_SRC
  6020. Fails here with:
  6021. /Could not find libv8-3.16.14.3 in any of the sources/
  6022. /Run `bundle install` to install missing gems./
  6023. #+BEGIN_SRC: bash
  6024. sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production
  6025. sudo -u git -H bundle exec rake gitlab:shell:install[v1.9.3] REDIS_URL=redis://localhost:6379
  6026. sudo -u git -H editor /home/git/gitlab-shell/config.yml
  6027. cp lib/support/init.d/gitlab /etc/init.d/gitlab
  6028. update-rc.d gitlab defaults 21
  6029. cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab
  6030. sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production
  6031. sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production
  6032. service gitlab start
  6033. #+END_SRC
  6034. Set up the Apache configuration.
  6035. #+BEGIN_SRC: bash
  6036. cp lib/support/apache/gitlab /etc/apache2/sites-available/mygitlabdomain
  6037. editor /etc/apache2/sites-available/mygitlabdomain
  6038. #+END_SRC
  6039. Set your domain name and email accordingly.
  6040. #+BEGIN_SRC: bash
  6041. a2ensite mygitlabdomain
  6042. #+END_SRC
  6043. ** Monkeysphere
  6044. #+BEGIN_SRC: bash
  6045. aptitude install monkeysphere
  6046. aptitude install msva-perl
  6047. aptitude install xul-ext-monkeysphere
  6048. export HOSTNAME=mydomainname.com
  6049. monkeysphere-host import-key /etc/ssh/ssh_host_rsa_key ssh://$HOSTNAME
  6050. monkeysphere-host publish-key
  6051. #+END_SRC
  6052. ** Diaspora
  6053. First install some dependencies:
  6054. #+BEGIN_SRC: bash
  6055. 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
  6056. #+END_SRC
  6057. If there is trouble with dependencies select 'n' then 'y' to the solution.
  6058. Create a diaspora user.
  6059. #+BEGIN_SRC: bash
  6060. adduser --disabled-login diaspora
  6061. su diaspora
  6062. cd ~/
  6063. curl -L dspr.tk/1t | bash
  6064. echo "[[ -s \"$HOME/.rvm/scripts/rvm\" ]] && source \"$HOME/.rvm/scripts/rvm\"" >> ~/.bashrc
  6065. . ~/.bashrc
  6066. rvm autolibs read-only
  6067. rvm install ruby-2.0.0-p481
  6068. git clone https://github.com/diaspora/diaspora.git
  6069. cd diaspora
  6070. #+END_SRC
  6071. Select 'y' to trust /home/diaspora/diaspora/.rvmrc
  6072. #+BEGIN_SRC: bash
  6073. cp config/diaspora.yml.example config/diaspora.yml
  6074. editor config/diaspora.yml
  6075. #+END_SRC
  6076. Set *url* to https://mydiasporadomainname.com/
  6077. Set *certificate_authorities* to */etc/ssl/certs/ca-certificates.crt*
  6078. Set *require_ssl* to *true*
  6079. Set *single_process_mode* to *false*
  6080. Set *port* to 3001
  6081. Set *rails_environment* to 'production'.
  6082. Set *pod_name* to the name of your pod.
  6083. Set *enable_registrations* to *true*.
  6084. Set *autofollow_on_join* to *false*
  6085. Under *captcha* set *enable* to *false*
  6086. Under *invitations* set *open* to *true*
  6087. Set *bitcoin_address* if you wish to accept donations.
  6088. Under *mail* set *enable* to *true*
  6089. Set *sender_address* to no-reply@mydiasporadomainname.com
  6090. Set *method* to *sendmail*
  6091. Set *exim_fix* to true.
  6092. Under *admins* set *account* to your username
  6093. Under *admins* set *podmin_email* to your email address
  6094. Save and exit.
  6095. #+BEGIN_SRC: bash
  6096. RAILS_ENV=production bundle install --without test development
  6097. #+END_SRC
  6098. This will take quite a while to install.
  6099. #+BEGIN_SRC: bash
  6100. RAILS_ENV=production bundle exec rake db:create db:schema:load
  6101. bundle exec rake assets:precompile
  6102. #+END_SRC
  6103. Alter the Apache configuration.
  6104. #+BEGIN_SRC: bash
  6105. exit
  6106. export HOSTNAME=mydiasporadomainname.com
  6107. editor /etc/apache2/sites-available/$HOSTNAME
  6108. #+END_SRC
  6109. Delete anything which already exists and add the following:
  6110. #+BEGIN_SRC: bash
  6111. <VirtualHost *:80>
  6112. ServerName mydiasporadomainname.com
  6113. ServerAlias www.mydiasporadomainname.com
  6114. RedirectPermanent / https://mydiasporadomainname.com/
  6115. </VirtualHost>
  6116. <VirtualHost *:443>
  6117. ServerName mydiasporadomainname.com
  6118. ServerAlias www.mydiasporadomainname.com
  6119. DocumentRoot /home/diaspora/diaspora/public
  6120. RewriteEngine On
  6121. RewriteCond %{HTTP_HOST} !^mydiasporadomainname\.com [NC]
  6122. RewriteRule ^/(.*)$ https://mydiasporadomainname\.com/$1 [L,R,QSA]
  6123. RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
  6124. RewriteRule ^/(.*)$ balancer://upstream%{REQUEST_URI} [P,QSA,L]
  6125. <Proxy balancer://upstream>
  6126. BalancerMember http://127.0.0.1:3001
  6127. </Proxy>
  6128. ProxyRequests Off
  6129. ProxyVia On
  6130. ProxyPreserveHost On
  6131. RequestHeader set X_FORWARDED_PROTO https
  6132. <Proxy *>
  6133. # Apache < 2.4
  6134. Order allow,deny
  6135. Allow from all
  6136. # Apache >= 2.4
  6137. #Require all granted
  6138. </Proxy>
  6139. <Directory /home/diaspora/diaspora/public>
  6140. Options -MultiViews
  6141. # Apache < 2.4
  6142. Allow from all
  6143. AllowOverride all
  6144. # Apache >= 2.4
  6145. #Require all granted
  6146. </Directory>
  6147. SSLEngine On
  6148. SSLCertificateFile /etc/ssl/certs/mydiasporadomainname.com.crt
  6149. SSLCertificateKeyFile /etc/ssl/private/mydiasporadomainname.com.key
  6150. # maybe not needed, need for example for startssl to point to a local
  6151. # copy of http://www.startssl.com/certs/sub.class1.server.ca.pem
  6152. SSLCertificateChainFile /etc/ssl/chains/startssl-sub.class1.server.ca.pem
  6153. # Based on https://wiki.mozilla.org/Security/Server_Side_TLS - consider as global configuration
  6154. SSLProtocol all -SSLv2
  6155. 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
  6156. SSLHonorCipherOrder on
  6157. SSLCompression off
  6158. </VirtualHost>
  6159. #+END_SRC
  6160. Save and exit.
  6161. #+BEGIN_SRC: bash
  6162. editor /usr/bin/rundiaspora
  6163. #+END_SRC
  6164. Add the following.
  6165. #+BEGIN_SRC: bash
  6166. #!/bin/sh
  6167. USERNAME=diaspora
  6168. COMMAND="cd /home/$USERNAME/diaspora; /bin/sh /home/$USERNAME/diaspora/script/server > /home/$USERNAME/diaspora.log"
  6169. su -l $USERNAME -c '$COMMAND'
  6170. #+END_SRC
  6171. Save and exit.
  6172. Create an init script:
  6173. #+BEGIN_SRC: bash
  6174. chmod +x /usr/bin/rundiaspora
  6175. editor /etc/init.d/diaspora
  6176. #+END_SRC
  6177. Add the following.
  6178. #+BEGIN_SRC: bash
  6179. #!/bin/bash
  6180. # /etc/init.d/diaspora
  6181. ### BEGIN INIT INFO
  6182. # Provides: diaspora
  6183. # Required-Start: $remote_fs $syslog
  6184. # Required-Stop: $remote_fs $syslog
  6185. # Default-Start: 2 3 4 5
  6186. # Default-Stop: 0 1 6
  6187. # Short-Description: starts diaspora
  6188. # Description: Starts Diaspora.
  6189. ### END INIT INFO
  6190. # Author: Bob Mottram <bob@robotics.uk.to>
  6191. #Settings
  6192. SERVICE='diaspora'
  6193. HISTORY=1024
  6194. USERNAME='diaspora'
  6195. COMMAND="rundiaspora"
  6196. NICELEVEL=19 # from 0-19
  6197. INVOCATION="nice -n ${NICELEVEL} ${COMMAND}"
  6198. PATH='/usr/local/sbin:/usr/local/bin:/usr/bin:/sbin:/usr/sbin:/bin'
  6199. diaspora_start() {
  6200. echo -n $"Starting $SERVICE service"
  6201. screen -h ${HISTORY} -dmS ${SERVICE} ${INVOCATION}
  6202. # su --command "screen -h ${HISTORY} -dmS ${SERVICE} ${INVOCATION}" $USERNAME
  6203. # su -l $USERNAME -c "$COMMAND"
  6204. # RETVAL=$?
  6205. echo
  6206. }
  6207. diaspora_stop() {
  6208. echo -n $"Stopping $SERVICE service"
  6209. screen -p 0 -S ${SERVICE} -X stuff "'^C'"
  6210. # su --command "screen -p 0 -S ${SERVICE} -X stuff "'^C'"" $USERNAME
  6211. # su -l $USERNAME -c "/home/$USERNAME/diaspora/script/server"
  6212. # RETVAL=$?
  6213. echo
  6214. }
  6215. #Start-Stop here
  6216. case "$1" in
  6217. start)
  6218. diaspora_start
  6219. ;;
  6220. stop)
  6221. diaspora_stop
  6222. ;;
  6223. restart)
  6224. diaspora_stop
  6225. diaspora_start
  6226. ;;
  6227. *)
  6228. echo "Usage: $0 {start|stop|restart}"
  6229. exit 1
  6230. ;;
  6231. esac
  6232. exit 0
  6233. #+END_SRC
  6234. Save and exit.
  6235. #+BEGIN_SRC: bash
  6236. chmod +x /etc/init.d/diaspora
  6237. update-rc.d diaspora defaults
  6238. service diaspora start
  6239. #+END_SRC
  6240. Now enable the site:
  6241. #+BEGIN_SRC: bash
  6242. a2enmod ssl
  6243. a2enmod rewrite
  6244. a2enmod headers
  6245. a2enmod proxy
  6246. a2enmod proxy_connect
  6247. a2enmod proxy_http
  6248. a2enmod proxy_balancer
  6249. a2ensite $HOSTNAME
  6250. service apache2 restart
  6251. #+END_SRC
  6252. * Related projects
  6253. * [[https://arkos.io/][ArkOS]]
  6254. * [[https://freedomboxfoundation.org/][Freedombox]]
  6255. * [[https://github.com/JoshData/mailinabox][Mail-in-a-Box]]
  6256. * [[https://github.com/sandstorm-io/sandstorm][Sandstorm]]
  6257. * [[https://github.com/al3x/sovereign][Sovereign]]