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