2
0

upgrade.php 150 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513
  1. <?php
  2. /**
  3. * Simple Machines Forum (SMF)
  4. *
  5. * @package SMF
  6. * @author Simple Machines http://www.simplemachines.org
  7. * @copyright 2011 Simple Machines
  8. * @license http://www.simplemachines.org/about/smf/license.php BSD
  9. *
  10. * @version 2.1 Alpha 1
  11. */
  12. // Version information...
  13. define('SMF_VERSION', '2.1 Alpha 1');
  14. define('SMF_LANG_VERSION', '2.0');
  15. $GLOBALS['required_php_version'] = '5.1.0';
  16. $GLOBALS['required_mysql_version'] = '4.0.18';
  17. $databases = array(
  18. 'mysql' => array(
  19. 'name' => 'MySQL',
  20. 'version' => '4.0.18',
  21. 'version_check' => 'return min(mysql_get_server_info(), mysql_get_client_info());',
  22. 'utf8_support' => true,
  23. 'utf8_version' => '4.1.0',
  24. 'utf8_version_check' => 'return mysql_get_server_info();',
  25. 'alter_support' => true,
  26. ),
  27. 'postgresql' => array(
  28. 'name' => 'PostgreSQL',
  29. 'version' => '8.0',
  30. 'version_check' => '$version = pg_version(); return $version[\'client\'];',
  31. 'always_has_db' => true,
  32. ),
  33. 'sqlite' => array(
  34. 'name' => 'SQLite',
  35. 'version' => '1',
  36. 'version_check' => 'return 1;',
  37. 'always_has_db' => true,
  38. ),
  39. );
  40. // General options for the script.
  41. $timeLimitThreshold = 3;
  42. $upgrade_path = dirname(__FILE__);
  43. $upgradeurl = $_SERVER['PHP_SELF'];
  44. // Where the SMF images etc are kept.
  45. $smfsite = 'http://www.simplemachines.org/smf';
  46. // Disable the need for admins to login?
  47. $disable_security = false;
  48. // How long, in seconds, must admin be inactive to allow someone else to run?
  49. $upcontext['inactive_timeout'] = 10;
  50. // All the steps in detail.
  51. // Number,Name,Function,Progress Weight.
  52. $upcontext['steps'] = array(
  53. 0 => array(1, 'Login', 'WelcomeLogin', 2),
  54. 1 => array(2, 'Upgrade Options', 'UpgradeOptions', 2),
  55. 2 => array(3, 'Backup', 'BackupDatabase', 10),
  56. 3 => array(4, 'Database Changes', 'DatabaseChanges', 70),
  57. // This is removed as it doesn't really work right at the moment.
  58. //4 => array(5, 'Cleanup Mods', 'CleanupMods', 10),
  59. 4 => array(5, 'Delete Upgrade', 'DeleteUpgrade', 1),
  60. );
  61. // Just to remember which one has files in it.
  62. $upcontext['database_step'] = 3;
  63. @set_time_limit(600);
  64. if (!ini_get('safe_mode'))
  65. {
  66. ini_set('mysql.connect_timeout', -1);
  67. ini_set('default_socket_timeout', 900);
  68. }
  69. // Clean the upgrade path if this is from the client.
  70. if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR']))
  71. for ($i = 1; $i < $_SERVER['argc']; $i++)
  72. {
  73. if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0)
  74. $upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1];
  75. }
  76. // Are we from the client?
  77. if (php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR']))
  78. {
  79. $command_line = true;
  80. $disable_security = 1;
  81. }
  82. else
  83. $command_line = false;
  84. // Load this now just because we can.
  85. require_once($upgrade_path . '/Settings.php');
  86. // Are we logged in?
  87. if (isset($upgradeData))
  88. {
  89. $upcontext['user'] = unserialize(base64_decode($upgradeData));
  90. // Check for sensible values.
  91. if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400)
  92. $upcontext['user']['started'] = time();
  93. if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400)
  94. $upcontext['user']['updated'] = 0;
  95. $upcontext['started'] = $upcontext['user']['started'];
  96. $upcontext['updated'] = $upcontext['user']['updated'];
  97. }
  98. // Nothing sensible?
  99. if (empty($upcontext['updated']))
  100. {
  101. $upcontext['started'] = time();
  102. $upcontext['updated'] = 0;
  103. $upcontext['user'] = array(
  104. 'id' => 0,
  105. 'name' => 'Guest',
  106. 'pass' => 0,
  107. 'started' => $upcontext['started'],
  108. 'updated' => $upcontext['updated'],
  109. );
  110. }
  111. // Load up some essential data...
  112. loadEssentialData();
  113. // Are we going to be mimic'ing SSI at this point?
  114. if (isset($_GET['ssi']))
  115. {
  116. require_once($sourcedir . '/Subs.php');
  117. require_once($sourcedir . '/Errors.php');
  118. require_once($sourcedir . '/Logging.php');
  119. require_once($sourcedir . '/Load.php');
  120. require_once($sourcedir . '/Security.php');
  121. require_once($sourcedir . '/Subs-Package.php');
  122. loadUserSettings();
  123. loadPermissions();
  124. }
  125. // All the non-SSI stuff.
  126. if (!function_exists('ip2range'))
  127. require_once($sourcedir . '/Subs.php');
  128. if (!function_exists('un_htmlspecialchars'))
  129. {
  130. function un_htmlspecialchars($string)
  131. {
  132. return strtr($string, array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES)) + array('&#039;' => '\'', '&nbsp;' => ' '));
  133. }
  134. }
  135. if (!function_exists('text2words'))
  136. {
  137. function text2words($text)
  138. {
  139. global $smcFunc;
  140. // Step 1: Remove entities/things we don't consider words:
  141. $words = preg_replace('~(?:[\x0B\0\xA0\t\r\s\n(){}\\[\\]<>!@$%^*.,:+=`\~\?/\\\\]+|&(?:amp|lt|gt|quot);)+~', ' ', $text);
  142. // Step 2: Entities we left to letters, where applicable, lowercase.
  143. $words = preg_replace('~([^&\d]|^)[#;]~', '$1 ', un_htmlspecialchars(strtolower($words)));
  144. // Step 3: Ready to split apart and index!
  145. $words = explode(' ', $words);
  146. $returned_words = array();
  147. foreach ($words as $word)
  148. {
  149. $word = trim($word, '-_\'');
  150. if ($word != '')
  151. $returned_words[] = substr($word, 0, 20);
  152. }
  153. return array_unique($returned_words);
  154. }
  155. }
  156. if (!function_exists('clean_cache'))
  157. {
  158. // Empty out the cache folder.
  159. function clean_cache($type = '')
  160. {
  161. global $cachedir, $sourcedir;
  162. // No directory = no game.
  163. if (!is_dir($cachedir))
  164. return;
  165. // Remove the files in SMF's own disk cache, if any
  166. $dh = opendir($cachedir);
  167. while ($file = readdir($dh))
  168. {
  169. if ($file != '.' && $file != '..' && $file != 'index.php' && $file != '.htaccess' && (!$type || substr($file, 0, strlen($type)) == $type))
  170. @unlink($cachedir . '/' . $file);
  171. }
  172. closedir($dh);
  173. // Invalidate cache, to be sure!
  174. // ... as long as Load.php can be modified, anyway.
  175. @touch($sourcedir . '/' . 'Load.php');
  176. clearstatcache();
  177. }
  178. }
  179. // MD5 Encryption.
  180. if (!function_exists('md5_hmac'))
  181. {
  182. function md5_hmac($data, $key)
  183. {
  184. if (strlen($key) > 64)
  185. $key = pack('H*', md5($key));
  186. $key = str_pad($key, 64, chr(0x00));
  187. $k_ipad = $key ^ str_repeat(chr(0x36), 64);
  188. $k_opad = $key ^ str_repeat(chr(0x5c), 64);
  189. return md5($k_opad . pack('H*', md5($k_ipad . $data)));
  190. }
  191. }
  192. // http://www.faqs.org/rfcs/rfc959.html
  193. if (!class_exists('ftp_connection'))
  194. {
  195. class ftp_connection
  196. {
  197. var $connection = 'no_connection', $error = false, $last_message, $pasv = array();
  198. // Create a new FTP connection...
  199. function ftp_connection($ftp_server, $ftp_port = 21, $ftp_user = 'anonymous', $ftp_pass = '[email protected]')
  200. {
  201. if ($ftp_server !== null)
  202. $this->connect($ftp_server, $ftp_port, $ftp_user, $ftp_pass);
  203. }
  204. function connect($ftp_server, $ftp_port = 21, $ftp_user = 'anonymous', $ftp_pass = '[email protected]')
  205. {
  206. if (substr($ftp_server, 0, 6) == 'ftp://')
  207. $ftp_server = substr($ftp_server, 6);
  208. elseif (substr($ftp_server, 0, 7) == 'ftps://')
  209. $ftp_server = 'ssl://' . substr($ftp_server, 7);
  210. if (substr($ftp_server, 0, 7) == 'http://')
  211. $ftp_server = substr($ftp_server, 7);
  212. $ftp_server = strtr($ftp_server, array('/' => '', ':' => '', '@' => ''));
  213. // Connect to the FTP server.
  214. $this->connection = @fsockopen($ftp_server, $ftp_port, $err, $err, 5);
  215. if (!$this->connection)
  216. {
  217. $this->error = 'bad_server';
  218. return;
  219. }
  220. // Get the welcome message...
  221. if (!$this->check_response(220))
  222. {
  223. $this->error = 'bad_response';
  224. return;
  225. }
  226. // Send the username, it should ask for a password.
  227. fwrite($this->connection, 'USER ' . $ftp_user . "\r\n");
  228. if (!$this->check_response(331))
  229. {
  230. $this->error = 'bad_username';
  231. return;
  232. }
  233. // Now send the password... and hope it goes okay.
  234. fwrite($this->connection, 'PASS ' . $ftp_pass . "\r\n");
  235. if (!$this->check_response(230))
  236. {
  237. $this->error = 'bad_password';
  238. return;
  239. }
  240. }
  241. function chdir($ftp_path)
  242. {
  243. if (!is_resource($this->connection))
  244. return false;
  245. // No slash on the end, please...
  246. if (substr($ftp_path, -1) == '/' && $ftp_path !== '/')
  247. $ftp_path = substr($ftp_path, 0, -1);
  248. fwrite($this->connection, 'CWD ' . $ftp_path . "\r\n");
  249. if (!$this->check_response(250))
  250. {
  251. $this->error = 'bad_path';
  252. return false;
  253. }
  254. return true;
  255. }
  256. function chmod($ftp_file, $chmod)
  257. {
  258. if (!is_resource($this->connection))
  259. return false;
  260. // Convert the chmod value from octal (0777) to text ("777").
  261. fwrite($this->connection, 'SITE CHMOD ' . decoct($chmod) . ' ' . $ftp_file . "\r\n");
  262. if (!$this->check_response(200))
  263. {
  264. $this->error = 'bad_file';
  265. return false;
  266. }
  267. return true;
  268. }
  269. function unlink($ftp_file)
  270. {
  271. // We are actually connected, right?
  272. if (!is_resource($this->connection))
  273. return false;
  274. // Delete file X.
  275. fwrite($this->connection, 'DELE ' . $ftp_file . "\r\n");
  276. if (!$this->check_response(250))
  277. {
  278. fwrite($this->connection, 'RMD ' . $ftp_file . "\r\n");
  279. // Still no love?
  280. if (!$this->check_response(250))
  281. {
  282. $this->error = 'bad_file';
  283. return false;
  284. }
  285. }
  286. return true;
  287. }
  288. function check_response($desired)
  289. {
  290. // Wait for a response that isn't continued with -, but don't wait too long.
  291. $time = time();
  292. do
  293. $this->last_message = fgets($this->connection, 1024);
  294. while (substr($this->last_message, 3, 1) != ' ' && time() - $time < 5);
  295. // Was the desired response returned?
  296. return is_array($desired) ? in_array(substr($this->last_message, 0, 3), $desired) : substr($this->last_message, 0, 3) == $desired;
  297. }
  298. function passive()
  299. {
  300. // We can't create a passive data connection without a primary one first being there.
  301. if (!is_resource($this->connection))
  302. return false;
  303. // Request a passive connection - this means, we'll talk to you, you don't talk to us.
  304. @fwrite($this->connection, 'PASV' . "\r\n");
  305. $time = time();
  306. do
  307. $response = fgets($this->connection, 1024);
  308. while (substr($response, 3, 1) != ' ' && time() - $time < 5);
  309. // If it's not 227, we weren't given an IP and port, which means it failed.
  310. if (substr($response, 0, 4) != '227 ')
  311. {
  312. $this->error = 'bad_response';
  313. return false;
  314. }
  315. // Snatch the IP and port information, or die horribly trying...
  316. if (preg_match('~\((\d+),\s*(\d+),\s*(\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+))\)~', $response, $match) == 0)
  317. {
  318. $this->error = 'bad_response';
  319. return false;
  320. }
  321. // This is pretty simple - store it for later use ;).
  322. $this->pasv = array('ip' => $match[1] . '.' . $match[2] . '.' . $match[3] . '.' . $match[4], 'port' => $match[5] * 256 + $match[6]);
  323. return true;
  324. }
  325. function create_file($ftp_file)
  326. {
  327. // First, we have to be connected... very important.
  328. if (!is_resource($this->connection))
  329. return false;
  330. // I'd like one passive mode, please!
  331. if (!$this->passive())
  332. return false;
  333. // Seems logical enough, so far...
  334. fwrite($this->connection, 'STOR ' . $ftp_file . "\r\n");
  335. // Okay, now we connect to the data port. If it doesn't work out, it's probably "file already exists", etc.
  336. $fp = @fsockopen($this->pasv['ip'], $this->pasv['port'], $err, $err, 5);
  337. if (!$fp || !$this->check_response(150))
  338. {
  339. $this->error = 'bad_file';
  340. @fclose($fp);
  341. return false;
  342. }
  343. // This may look strange, but we're just closing it to indicate a zero-byte upload.
  344. fclose($fp);
  345. if (!$this->check_response(226))
  346. {
  347. $this->error = 'bad_response';
  348. return false;
  349. }
  350. return true;
  351. }
  352. function list_dir($ftp_path = '', $search = false)
  353. {
  354. // Are we even connected...?
  355. if (!is_resource($this->connection))
  356. return false;
  357. // Passive... non-agressive...
  358. if (!$this->passive())
  359. return false;
  360. // Get the listing!
  361. fwrite($this->connection, 'LIST -1' . ($search ? 'R' : '') . ($ftp_path == '' ? '' : ' ' . $ftp_path) . "\r\n");
  362. // Connect, assuming we've got a connection.
  363. $fp = @fsockopen($this->pasv['ip'], $this->pasv['port'], $err, $err, 5);
  364. if (!$fp || !$this->check_response(array(150, 125)))
  365. {
  366. $this->error = 'bad_response';
  367. @fclose($fp);
  368. return false;
  369. }
  370. // Read in the file listing.
  371. $data = '';
  372. while (!feof($fp))
  373. $data .= fread($fp, 4096);
  374. fclose($fp);
  375. // Everything go okay?
  376. if (!$this->check_response(226))
  377. {
  378. $this->error = 'bad_response';
  379. return false;
  380. }
  381. return $data;
  382. }
  383. function locate($file, $listing = null)
  384. {
  385. if ($listing === null)
  386. $listing = $this->list_dir('', true);
  387. $listing = explode("\n", $listing);
  388. @fwrite($this->connection, 'PWD' . "\r\n");
  389. $time = time();
  390. do
  391. $response = fgets($this->connection, 1024);
  392. while (substr($response, 3, 1) != ' ' && time() - $time < 5);
  393. // Check for 257!
  394. if (preg_match('~^257 "(.+?)" ~', $response, $match) != 0)
  395. $current_dir = strtr($match[1], array('""' => '"'));
  396. else
  397. $current_dir = '';
  398. for ($i = 0, $n = count($listing); $i < $n; $i++)
  399. {
  400. if (trim($listing[$i]) == '' && isset($listing[$i + 1]))
  401. {
  402. $current_dir = substr(trim($listing[++$i]), 0, -1);
  403. $i++;
  404. }
  405. // Okay, this file's name is:
  406. $listing[$i] = $current_dir . '/' . trim(strlen($listing[$i]) > 30 ? strrchr($listing[$i], ' ') : $listing[$i]);
  407. if (substr($file, 0, 1) == '*' && substr($listing[$i], -(strlen($file) - 1)) == substr($file, 1))
  408. return $listing[$i];
  409. if (substr($file, -1) == '*' && substr($listing[$i], 0, strlen($file) - 1) == substr($file, 0, -1))
  410. return $listing[$i];
  411. if (basename($listing[$i]) == $file || $listing[$i] == $file)
  412. return $listing[$i];
  413. }
  414. return false;
  415. }
  416. function create_dir($ftp_dir)
  417. {
  418. // We must be connected to the server to do something.
  419. if (!is_resource($this->connection))
  420. return false;
  421. // Make this new beautiful directory!
  422. fwrite($this->connection, 'MKD ' . $ftp_dir . "\r\n");
  423. if (!$this->check_response(257))
  424. {
  425. $this->error = 'bad_file';
  426. return false;
  427. }
  428. return true;
  429. }
  430. function detect_path($filesystem_path, $lookup_file = null)
  431. {
  432. $username = '';
  433. if (isset($_SERVER['DOCUMENT_ROOT']))
  434. {
  435. if (preg_match('~^/home[2]?/([^/]+?)/public_html~', $_SERVER['DOCUMENT_ROOT'], $match))
  436. {
  437. $username = $match[1];
  438. $path = strtr($_SERVER['DOCUMENT_ROOT'], array('/home/' . $match[1] . '/' => '', '/home2/' . $match[1] . '/' => ''));
  439. if (substr($path, -1) == '/')
  440. $path = substr($path, 0, -1);
  441. if (strlen(dirname($_SERVER['PHP_SELF'])) > 1)
  442. $path .= dirname($_SERVER['PHP_SELF']);
  443. }
  444. elseif (substr($filesystem_path, 0, 9) == '/var/www/')
  445. $path = substr($filesystem_path, 8);
  446. else
  447. $path = strtr(strtr($filesystem_path, array('\\' => '/')), array($_SERVER['DOCUMENT_ROOT'] => ''));
  448. }
  449. else
  450. $path = '';
  451. if (is_resource($this->connection) && $this->list_dir($path) == '')
  452. {
  453. $data = $this->list_dir('', true);
  454. if ($lookup_file === null)
  455. $lookup_file = $_SERVER['PHP_SELF'];
  456. $found_path = dirname($this->locate('*' . basename(dirname($lookup_file)) . '/' . basename($lookup_file), $data));
  457. if ($found_path == false)
  458. $found_path = dirname($this->locate(basename($lookup_file)));
  459. if ($found_path != false)
  460. $path = $found_path;
  461. }
  462. elseif (is_resource($this->connection))
  463. $found_path = true;
  464. return array($username, $path, isset($found_path));
  465. }
  466. function close()
  467. {
  468. // Goodbye!
  469. fwrite($this->connection, 'QUIT' . "\r\n");
  470. fclose($this->connection);
  471. return true;
  472. }
  473. }
  474. }
  475. // Have we got tracking data - if so use it (It will be clean!)
  476. if (isset($_GET['data']))
  477. {
  478. $upcontext['upgrade_status'] = unserialize(base64_decode($_GET['data']));
  479. $upcontext['current_step'] = $upcontext['upgrade_status']['curstep'];
  480. $upcontext['language'] = $upcontext['upgrade_status']['lang'];
  481. $upcontext['rid'] = $upcontext['upgrade_status']['rid'];
  482. $is_debug = $upcontext['upgrade_status']['debug'];
  483. $support_js = $upcontext['upgrade_status']['js'];
  484. // Load the language.
  485. if (file_exists($boarddir . '/Themes/default/languages/Install.' . $upcontext['language'] . '.php'))
  486. require_once($boarddir . '/Themes/default/languages/Install.' . $upcontext['language'] . '.php');
  487. }
  488. // Set the defaults.
  489. else
  490. {
  491. $upcontext['current_step'] = 0;
  492. $upcontext['rid'] = mt_rand(0, 5000);
  493. $upcontext['upgrade_status'] = array(
  494. 'curstep' => 0,
  495. 'lang' => isset($_GET['lang']) ? $_GET['lang'] : basename($language, '.lng'),
  496. 'rid' => $upcontext['rid'],
  497. 'pass' => 0,
  498. 'debug' => 0,
  499. 'js' => 0,
  500. );
  501. $upcontext['language'] = $upcontext['upgrade_status']['lang'];
  502. }
  503. // Don't do security check if on Yabbse
  504. if (!isset($modSettings['smfVersion']))
  505. $disable_security = true;
  506. // If this isn't the first stage see whether they are logging in and resuming.
  507. if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step']))
  508. checkLogin();
  509. // This only exists if we're on SMF ;)
  510. if (isset($modSettings['smfVersion']))
  511. {
  512. $request = $smcFunc['db_query']('', '
  513. SELECT variable, value
  514. FROM {db_prefix}themes
  515. WHERE id_theme = {int:id_theme}
  516. AND variable IN ({string:theme_url}, {string:theme_dir}, {string:images_url})',
  517. array(
  518. 'id_theme' => 1,
  519. 'theme_url' => 'theme_url',
  520. 'theme_dir' => 'theme_dir',
  521. 'images_url' => 'images_url',
  522. 'db_error_skip' => true,
  523. )
  524. );
  525. while ($row = $smcFunc['db_fetch_assoc']($request))
  526. $modSettings[$row['variable']] = $row['value'];
  527. $smcFunc['db_free_result']($request);
  528. }
  529. if (!isset($modSettings['theme_url']))
  530. {
  531. $modSettings['theme_dir'] = $boarddir . '/Themes/default';
  532. $modSettings['theme_url'] = 'Themes/default';
  533. $modSettings['images_url'] = 'Themes/default/images';
  534. }
  535. if (!isset($settings['default_theme_url']))
  536. $settings['default_theme_url'] = $modSettings['theme_url'];
  537. if (!isset($settings['default_theme_dir']))
  538. $settings['default_theme_dir'] = $modSettings['theme_dir'];
  539. $upcontext['is_large_forum'] = (empty($modSettings['smfVersion']) || $modSettings['smfVersion'] <= '1.1 RC1') && !empty($modSettings['totalMessages']) && $modSettings['totalMessages'] > 75000;
  540. // Default title...
  541. $upcontext['page_title'] = isset($modSettings['smfVersion']) ? 'Updating Your SMF Install!' : 'Upgrading from YaBB SE!';
  542. $upcontext['right_to_left'] = isset($txt['lang_rtl']) ? $txt['lang_rtl'] : false;
  543. if ($command_line)
  544. cmdStep0();
  545. // Don't error if we're using xml.
  546. if (isset($_GET['xml']))
  547. $upcontext['return_error'] = true;
  548. // Loop through all the steps doing each one as required.
  549. $upcontext['overall_percent'] = 0;
  550. foreach ($upcontext['steps'] as $num => $step)
  551. {
  552. if ($num >= $upcontext['current_step'])
  553. {
  554. // The current weight of this step in terms of overall progress.
  555. $upcontext['step_weight'] = $step[3];
  556. // Make sure we reset the skip button.
  557. $upcontext['skip'] = false;
  558. // We cannot proceed if we're not logged in.
  559. if ($num != 0 && !$disable_security && $upcontext['user']['pass'] != $upcontext['upgrade_status']['pass'])
  560. {
  561. $upcontext['steps'][0][2]();
  562. break;
  563. }
  564. // Call the step and if it returns false that means pause!
  565. if (function_exists($step[2]) && $step[2]() === false)
  566. break;
  567. elseif (function_exists($step[2]))
  568. $upcontext['current_step']++;
  569. }
  570. $upcontext['overall_percent'] += $step[3];
  571. }
  572. upgradeExit();
  573. // Exit the upgrade script.
  574. function upgradeExit($fallThrough = false)
  575. {
  576. global $upcontext, $upgradeurl, $boarddir, $command_line;
  577. // Save where we are...
  578. if (!empty($upcontext['current_step']) && !empty($upcontext['user']['id']))
  579. {
  580. $upcontext['user']['step'] = $upcontext['current_step'];
  581. $upcontext['user']['substep'] = $_GET['substep'];
  582. $upcontext['user']['updated'] = time();
  583. $upgradeData = base64_encode(serialize($upcontext['user']));
  584. copy($boarddir . '/Settings.php', $boarddir . '/Settings_bak.php');
  585. changeSettings(array('upgradeData' => '"' . $upgradeData . '"'));
  586. }
  587. // Handle the progress of the step, if any.
  588. if (!empty($upcontext['step_progress']) && isset($upcontext['steps'][$upcontext['current_step']]))
  589. {
  590. $upcontext['step_progress'] = round($upcontext['step_progress'], 1);
  591. $upcontext['overall_percent'] += $upcontext['step_progress'] * ($upcontext['steps'][$upcontext['current_step']][3] / 100);
  592. }
  593. $upcontext['overall_percent'] = (int) $upcontext['overall_percent'];
  594. // We usually dump our templates out.
  595. if (!$fallThrough)
  596. {
  597. // This should not happen my dear... HELP ME DEVELOPERS!!
  598. if (!empty($command_line))
  599. {
  600. if (function_exists('debug_print_backtrace'))
  601. debug_print_backtrace();
  602. echo "\n" . 'Error: Unexpected call to use the ' . (isset($upcontext['sub_template']) ? $upcontext['sub_template'] : '') . ' template. Please copy and paste all the text above and visit the SMF support forum to tell the Developers that they\'ve made a boo boo; they\'ll get you up and running again.';
  603. flush();
  604. die();
  605. }
  606. if (!isset($_GET['xml']))
  607. template_upgrade_above();
  608. else
  609. {
  610. header('Content-Type: text/xml; charset=ISO-8859-1');
  611. // Sadly we need to retain the $_GET data thanks to the old upgrade scripts.
  612. $upcontext['get_data'] = array();
  613. foreach ($_GET as $k => $v)
  614. {
  615. if (substr($k, 0, 3) != 'amp' && !in_array($k, array('xml', 'substep', 'lang', 'data', 'step', 'filecount')))
  616. {
  617. $upcontext['get_data'][$k] = $v;
  618. }
  619. }
  620. template_xml_above();
  621. }
  622. // Call the template.
  623. if (isset($upcontext['sub_template']))
  624. {
  625. $upcontext['upgrade_status']['curstep'] = $upcontext['current_step'];
  626. $upcontext['form_url'] = $upgradeurl . '?step=' . $upcontext['current_step'] . '&amp;substep=' . $_GET['substep'] . '&amp;data=' . base64_encode(serialize($upcontext['upgrade_status']));
  627. // Custom stuff to pass back?
  628. if (!empty($upcontext['query_string']))
  629. $upcontext['form_url'] .= $upcontext['query_string'];
  630. call_user_func('template_' . $upcontext['sub_template']);
  631. }
  632. // Was there an error?
  633. if (!empty($upcontext['forced_error_message']))
  634. echo $upcontext['forced_error_message'];
  635. // Show the footer.
  636. if (!isset($_GET['xml']))
  637. template_upgrade_below();
  638. else
  639. template_xml_below();
  640. }
  641. // Bang - gone!
  642. die();
  643. }
  644. // Used to direct the user to another location.
  645. function redirectLocation($location, $addForm = true)
  646. {
  647. global $upgradeurl, $upcontext, $command_line;
  648. // Command line users can't be redirected.
  649. if ($command_line)
  650. upgradeExit(true);
  651. // Are we providing the core info?
  652. if ($addForm)
  653. {
  654. $upcontext['upgrade_status']['curstep'] = $upcontext['current_step'];
  655. $location = $upgradeurl . '?step=' . $upcontext['current_step'] . '&substep=' . $_GET['substep'] . '&data=' . base64_encode(serialize($upcontext['upgrade_status'])) . $location;
  656. }
  657. while (@ob_end_clean());
  658. header('Location: ' . strtr($location, array('&amp;' => '&')));
  659. // Exit - saving status as we go.
  660. upgradeExit(true);
  661. }
  662. // Load all essential data and connect to the DB as this is pre SSI.php
  663. function loadEssentialData()
  664. {
  665. global $db_server, $db_user, $db_passwd, $db_name, $db_connection, $db_prefix, $db_character_set, $db_type;
  666. global $modSettings, $sourcedir, $smcFunc, $upcontext;
  667. // Do the non-SSI stuff...
  668. @set_magic_quotes_runtime(0);
  669. error_reporting(E_ALL);
  670. define('SMF', 1);
  671. // Start the session.
  672. if (@ini_get('session.save_handler') == 'user')
  673. @ini_set('session.save_handler', 'files');
  674. @session_start();
  675. if (empty($smcFunc))
  676. $smcFunc = array();
  677. // Check we don't need some compatibility.
  678. if (@version_compare(PHP_VERSION, '5.1', '<='))
  679. require_once($sourcedir . '/Subs-Compat.php');
  680. // Initialize everything...
  681. initialize_inputs();
  682. // Get the database going!
  683. if (empty($db_type))
  684. $db_type = 'mysql';
  685. if (file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
  686. {
  687. require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
  688. // Make the connection...
  689. $db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, array('non_fatal' => true));
  690. // Oh dear god!!
  691. if ($db_connection === null)
  692. die('Unable to connect to database - please check username and password are correct in Settings.php');
  693. if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1)
  694. $smcFunc['db_query']('', '
  695. SET NAMES ' . $db_character_set,
  696. array(
  697. 'db_error_skip' => true,
  698. )
  699. );
  700. // Load the modSettings data...
  701. $request = $smcFunc['db_query']('', '
  702. SELECT variable, value
  703. FROM {db_prefix}settings',
  704. array(
  705. 'db_error_skip' => true,
  706. )
  707. );
  708. $modSettings = array();
  709. while ($row = $smcFunc['db_fetch_assoc']($request))
  710. $modSettings[$row['variable']] = $row['value'];
  711. $smcFunc['db_free_result']($request);
  712. }
  713. else
  714. {
  715. return throw_error('Cannot find ' . $sourcedir . '/Subs-Db-' . $db_type . '.php' . '. Please check you have uploaded all source files and have the correct paths set.');
  716. }
  717. // If they don't have the file, they're going to get a warning anyway so we won't need to clean request vars.
  718. if (file_exists($sourcedir . '/QueryString.php'))
  719. {
  720. require_once($sourcedir . '/QueryString.php');
  721. cleanRequest();
  722. }
  723. if (!isset($_GET['substep']))
  724. $_GET['substep'] = 0;
  725. }
  726. function initialize_inputs()
  727. {
  728. global $sourcedir, $start_time, $upcontext, $db_type;
  729. $start_time = time();
  730. umask(0);
  731. // Fun. Low PHP version...
  732. if (!isset($_GET))
  733. {
  734. $GLOBALS['_GET']['step'] = 0;
  735. return;
  736. }
  737. ob_start();
  738. // Better to upgrade cleanly and fall apart than to screw everything up if things take too long.
  739. ignore_user_abort(true);
  740. // This is really quite simple; if ?delete is on the URL, delete the upgrader...
  741. if (isset($_GET['delete']))
  742. {
  743. @unlink(__FILE__);
  744. // And the extra little files ;).
  745. @unlink(dirname(__FILE__) . '/upgrade_1-0.sql');
  746. @unlink(dirname(__FILE__) . '/upgrade_1-1.sql');
  747. @unlink(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql');
  748. @unlink(dirname(__FILE__) . '/upgrade_2-1_' . $db_type . '.sql');
  749. @unlink(dirname(__FILE__) . '/webinstall.php');
  750. $dh = opendir(dirname(__FILE__));
  751. while ($file = readdir($dh))
  752. {
  753. if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1]))
  754. @unlink(dirname(__FILE__) . '/' . $file);
  755. }
  756. closedir($dh);
  757. header('Location: http://' . (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT']) . dirname($_SERVER['PHP_SELF']) . '/Themes/default/images/blank.png');
  758. exit;
  759. }
  760. // Are we calling the backup css file?
  761. if (isset($_GET['infile_css']))
  762. {
  763. header('Content-Type: text/css');
  764. template_css();
  765. exit;
  766. }
  767. // Anybody home?
  768. if (!isset($_GET['xml']))
  769. {
  770. $upcontext['remote_files_available'] = false;
  771. $test = @fsockopen('www.simplemachines.org', 80, $errno, $errstr, 1);
  772. if ($test)
  773. $upcontext['remote_files_available'] = true;
  774. @fclose($test);
  775. }
  776. // Something is causing this to happen, and it's annoying. Stop it.
  777. $temp = 'upgrade_php?step';
  778. while (strlen($temp) > 4)
  779. {
  780. if (isset($_GET[$temp]))
  781. unset($_GET[$temp]);
  782. $temp = substr($temp, 1);
  783. }
  784. // Force a step, defaulting to 0.
  785. $_GET['step'] = (int) @$_GET['step'];
  786. $_GET['substep'] = (int) @$_GET['substep'];
  787. }
  788. // Step 0 - Let's welcome them in and ask them to login!
  789. function WelcomeLogin()
  790. {
  791. global $boarddir, $sourcedir, $db_prefix, $language, $modSettings, $cachedir, $upgradeurl, $upcontext, $disable_security;
  792. global $smcFunc, $db_type, $databases, $txt;
  793. $upcontext['sub_template'] = 'welcome_message';
  794. // Check for some key files - one template, one language, and a new and an old source file.
  795. $check = @file_exists($boarddir . '/Themes/default/index.template.php')
  796. && @file_exists($sourcedir . '/QueryString.php')
  797. && @file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')
  798. && @file_exists(dirname(__FILE__) . '/upgrade_2-1_' . $db_type . '.sql');
  799. // Need legacy scripts?
  800. if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1)
  801. $check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql');
  802. if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0)
  803. $check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
  804. if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1)
  805. $check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
  806. if (!$check)
  807. // Don't tell them what files exactly because it's a spot check - just like teachers don't tell which problems they are spot checking, that's dumb.
  808. return throw_error('The upgrader was unable to find some crucial files.<br /><br />Please make sure you uploaded all of the files included in the package, including the Themes, Sources, and other directories.');
  809. // Do they meet the install requirements?
  810. if (!php_version_check())
  811. return throw_error('Warning! You do not appear to have a version of PHP installed on your webserver that meets SMF\'s minimum installations requirements.<br /><br />Please ask your host to upgrade.');
  812. if (!db_version_check())
  813. return throw_error('Your ' . $databases[$db_type]['name'] . ' version does not meet the minimum requirements of SMF.<br /><br />Please ask your host to upgrade.');
  814. // Do they have ALTER privileges?
  815. if (!empty($databases[$db_type]['alter_support']) && $smcFunc['db_query']('alter_boards', 'ALTER TABLE {db_prefix}boards ORDER BY id_board', array()) === false)
  816. return throw_error('The ' . $databases[$db_type]['name'] . ' user you have set in Settings.php does not have proper privileges.<br /><br />Please ask your host to give this user the ALTER, CREATE, and DROP privileges.');
  817. // Do a quick version spot check.
  818. $temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
  819. preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
  820. if (empty($match[1]) || $match[1] != SMF_VERSION)
  821. return throw_error('The upgrader found some old or outdated files.<br /><br />Please make certain you uploaded the new versions of all the files included in the package.');
  822. // What absolutely needs to be writable?
  823. $writable_files = array(
  824. $boarddir . '/Settings.php',
  825. $boarddir . '/Settings_bak.php',
  826. );
  827. // Check the cache directory.
  828. $cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
  829. if (!file_exists($cachedir_temp))
  830. @mkdir($cachedir_temp);
  831. if (!file_exists($cachedir_temp))
  832. return throw_error('The cache directory could not be found.<br /><br />Please make sure you have a directory called &quot;cache&quot; in your forum directory before continuing.');
  833. if (!file_exists($boarddir . '/Themes/default/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
  834. return throw_error('The upgrader was unable to find language files for the language specified in Settings.php.<br />SMF will not work without the primary language files installed.<br /><br />Please either install them, or <a href="' . $upgradeurl . '?step=0;lang=english">use english instead</a>.');
  835. elseif (!isset($_GET['skiplang']))
  836. {
  837. $temp = substr(@implode('', @file($boarddir . '/Themes/default/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
  838. preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
  839. if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
  840. return throw_error('The upgrader found some old or outdated language files, for the forum default language, ' . $upcontext['language'] . '.<br /><br />Please make certain you uploaded the new versions of all the files included in the package, even the theme and language files for the default theme.<br />&nbsp;&nbsp;&nbsp;[<a href="' . $upgradeurl . '?skiplang">SKIP</a>] [<a href="' . $upgradeurl . '?lang=english">Try English</a>]');
  841. }
  842. // This needs to exist!
  843. if (!file_exists($boarddir . '/Themes/default/languages/Install.' . $upcontext['language'] . '.php'))
  844. return throw_error('The upgrader could not find the &quot;Install&quot; language file for the forum default language, ' . $upcontext['language'] . '.<br /><br />Please make certain you uploaded all the files included in the package, even the theme and language files for the default theme.<br />&nbsp;&nbsp;&nbsp;[<a href="' . $upgradeurl . '?lang=english">Try English</a>]');
  845. else
  846. require_once($boarddir . '/Themes/default/languages/Install.' . $upcontext['language'] . '.php');
  847. if (!makeFilesWritable($writable_files))
  848. return false;
  849. // Check agreement.txt. (it may not exist, in which case $boarddir must be writable.)
  850. if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
  851. return throw_error('The upgrader was unable to obtain write access to agreement.txt.<br /><br />If you are using a linux or unix based server, please ensure that the file is chmod\'d to 777, or if it does not exist that the directory this upgrader is in is 777.<br />If your server is running Windows, please ensure that the internet guest account has the proper permissions on it or its folder.');
  852. // Upgrade the agreement.
  853. elseif (isset($modSettings['agreement']))
  854. {
  855. $fp = fopen($boarddir . '/agreement.txt', 'w');
  856. fwrite($fp, $modSettings['agreement']);
  857. fclose($fp);
  858. }
  859. // We're going to check that their board dir setting is right incase they've been moving stuff around.
  860. if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => '')))
  861. $upcontext['warning'] = '
  862. It looks as if your board directory settings <em>might</em> be incorrect. Your board directory is currently set to &quot;' . $boarddir . '&quot; but should probably be &quot;' . dirname(__FILE__) . '&quot;. Settings.php currently lists your paths as:<br />
  863. <ul>
  864. <li>Board Directory: ' . $boarddir . '</li>
  865. <li>Source Directory: ' . $boarddir . '</li>
  866. <li>Cache Directory: ' . $cachedir_temp . '</li>
  867. </ul>
  868. If these seem incorrect please open Settings.php in a text editor before proceeding with this upgrade. If they are incorrect due to you moving your forum to a new location please download and execute the <a href="http://download.simplemachines.org/?tools">Repair Settings</a> tool from the Simple Machines website before continuing.';
  869. // Either we're logged in or we're going to present the login.
  870. if (checkLogin())
  871. return true;
  872. return false;
  873. }
  874. // Step 0.5: Does the login work?
  875. function checkLogin()
  876. {
  877. global $boarddir, $sourcedir, $db_prefix, $language, $modSettings, $cachedir, $upgradeurl, $upcontext, $disable_security;
  878. global $smcFunc, $db_type, $databases, $support_js, $txt;
  879. // Are we trying to login?
  880. if (isset($_POST['contbutt']) && (!empty($_POST['user']) || $disable_security))
  881. {
  882. // If we've disabled security pick a suitable name!
  883. if (empty($_POST['user']))
  884. $_POST['user'] = 'Administrator';
  885. // Before 2.0 these column names were different!
  886. $oldDB = false;
  887. if (empty($db_type) || $db_type == 'mysql')
  888. {
  889. $request = $smcFunc['db_query']('', '
  890. SHOW COLUMNS
  891. FROM {db_prefix}members
  892. LIKE {string:member_name}',
  893. array(
  894. 'member_name' => 'memberName',
  895. 'db_error_skip' => true,
  896. )
  897. );
  898. if ($smcFunc['db_num_rows']($request) != 0)
  899. $oldDB = true;
  900. $smcFunc['db_free_result']($request);
  901. }
  902. // Get what we believe to be their details.
  903. if (!$disable_security)
  904. {
  905. if ($oldDB)
  906. $request = $smcFunc['db_query']('', '
  907. SELECT id_member, memberName AS member_name, passwd, id_group,
  908. additionalGroups AS additional_groups, lngfile
  909. FROM {db_prefix}members
  910. WHERE memberName = {string:member_name}',
  911. array(
  912. 'member_name' => $_POST['user'],
  913. 'db_error_skip' => true,
  914. )
  915. );
  916. else
  917. $request = $smcFunc['db_query']('', '
  918. SELECT id_member, member_name, passwd, id_group, additional_groups, lngfile
  919. FROM {db_prefix}members
  920. WHERE member_name = {string:member_name}',
  921. array(
  922. 'member_name' => $_POST['user'],
  923. 'db_error_skip' => true,
  924. )
  925. );
  926. if ($smcFunc['db_num_rows']($request) != 0)
  927. {
  928. list ($id_member, $name, $password, $id_group, $addGroups, $user_language) = $smcFunc['db_fetch_row']($request);
  929. $groups = explode(',', $addGroups);
  930. $groups[] = $id_group;
  931. foreach ($groups as $k => $v)
  932. $groups[$k] = (int) $v;
  933. // Figure out the password using SMF's encryption - if what they typed is right.
  934. if (isset($_REQUEST['hash_passwrd']) && strlen($_REQUEST['hash_passwrd']) == 40)
  935. {
  936. // Challenge passed.
  937. if ($_REQUEST['hash_passwrd'] == sha1($password . $upcontext['rid']))
  938. $sha_passwd = $password;
  939. }
  940. else
  941. $sha_passwd = sha1(strtolower($name) . un_htmlspecialchars($_REQUEST['passwrd']));
  942. }
  943. else
  944. $upcontext['username_incorrect'] = true;
  945. $smcFunc['db_free_result']($request);
  946. }
  947. $upcontext['username'] = $_POST['user'];
  948. // Track whether javascript works!
  949. if (!empty($_POST['js_works']))
  950. {
  951. $upcontext['upgrade_status']['js'] = 1;
  952. $support_js = 1;
  953. }
  954. else
  955. $support_js = 0;
  956. // Note down the version we are coming from.
  957. if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version']))
  958. $upcontext['user']['version'] = $modSettings['smfVersion'];
  959. // Didn't get anywhere?
  960. if ((empty($sha_passwd) || $password != $sha_passwd) && empty($upcontext['username_incorrect']) && !$disable_security)
  961. {
  962. // MD5?
  963. $md5pass = md5_hmac($_REQUEST['passwrd'], strtolower($_POST['user']));
  964. if ($md5pass != $password)
  965. {
  966. $upcontext['password_failed'] = true;
  967. // Disable the hashing this time.
  968. $upcontext['disable_login_hashing'] = true;
  969. }
  970. }
  971. if ((empty($upcontext['password_failed']) && !empty($name)) || $disable_security)
  972. {
  973. // Set the password.
  974. if (!$disable_security)
  975. {
  976. // Do we actually have permission?
  977. if (!in_array(1, $groups))
  978. {
  979. $request = $smcFunc['db_query']('', '
  980. SELECT permission
  981. FROM {db_prefix}permissions
  982. WHERE id_group IN ({array_int:groups})
  983. AND permission = {string:admin_forum}',
  984. array(
  985. 'groups' => $groups,
  986. 'admin_forum' => 'admin_forum',
  987. 'db_error_skip' => true,
  988. )
  989. );
  990. if ($smcFunc['db_num_rows']($request) == 0)
  991. return throw_error('You need to be an admin to perform an upgrade!');
  992. $smcFunc['db_free_result']($request);
  993. }
  994. $upcontext['user']['id'] = $id_member;
  995. $upcontext['user']['name'] = $name;
  996. }
  997. else
  998. {
  999. $upcontext['user']['id'] = 1;
  1000. $upcontext['user']['name'] = 'Administrator';
  1001. }
  1002. $upcontext['user']['pass'] = mt_rand(0,60000);
  1003. // This basically is used to match the GET variables to Settings.php.
  1004. $upcontext['upgrade_status']['pass'] = $upcontext['user']['pass'];
  1005. // Set the language to that of the user?
  1006. if (isset($user_language) && $user_language != $upcontext['language'] && file_exists($boarddir . '/Themes/default/languages/index.' . basename($user_language, '.lng') . '.php'))
  1007. {
  1008. $user_language = basename($user_language, '.lng');
  1009. $temp = substr(@implode('', @file($boarddir . '/Themes/default/languages/index.' . $user_language . '.php')), 0, 4096);
  1010. preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
  1011. if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
  1012. $upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been updated to the latest version. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.';
  1013. elseif (!file_exists($boarddir . '/Themes/default/languages/Install.' . basename($user_language, '.lng') . '.php'))
  1014. $upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been uploaded/updated as the &quot;Install&quot; language file is missing. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.';
  1015. else
  1016. {
  1017. // Set this as the new language.
  1018. $upcontext['language'] = $user_language;
  1019. $upcontext['upgrade_status']['lang'] = $upcontext['language'];
  1020. // Include the file.
  1021. require_once($boarddir . '/Themes/default/languages/Install.' . $user_language . '.php');
  1022. }
  1023. }
  1024. // If we're resuming set the step and substep to be correct.
  1025. if (isset($_POST['cont']))
  1026. {
  1027. $upcontext['current_step'] = $upcontext['user']['step'];
  1028. $_GET['substep'] = $upcontext['user']['substep'];
  1029. }
  1030. return true;
  1031. }
  1032. }
  1033. return false;
  1034. }
  1035. // Step 1: Do the maintenance and backup.
  1036. function UpgradeOptions()
  1037. {
  1038. global $db_prefix, $command_line, $modSettings, $is_debug, $smcFunc;
  1039. global $boarddir, $boardurl, $sourcedir, $maintenance, $mmessage, $cachedir, $upcontext, $db_type;
  1040. $upcontext['sub_template'] = 'upgrade_options';
  1041. $upcontext['page_title'] = 'Upgrade Options';
  1042. // If we've not submitted then we're done.
  1043. if (empty($_POST['upcont']))
  1044. return false;
  1045. // Firstly, if they're enabling SM stat collection just do it.
  1046. if (!empty($_POST['stats']) && substr($boardurl, 0, 16) != 'http://localhost' && empty($modSettings['allow_sm_stats']))
  1047. {
  1048. // Attempt to register the site etc.
  1049. $fp = @fsockopen('www.simplemachines.org', 80, $errno, $errstr);
  1050. if ($fp)
  1051. {
  1052. $out = 'GET /smf/stats/register_stats.php?site=' . base64_encode($boardurl) . ' HTTP/1.1' . "\r\n";
  1053. $out .= 'Host: www.simplemachines.org' . "\r\n";
  1054. $out .= 'Connection: Close' . "\r\n\r\n";
  1055. fwrite($fp, $out);
  1056. $return_data = '';
  1057. while (!feof($fp))
  1058. $return_data .= fgets($fp, 128);
  1059. fclose($fp);
  1060. // Get the unique site ID.
  1061. preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID);
  1062. if (!empty($ID[1]))
  1063. $smcFunc['db_insert']('replace',
  1064. $db_prefix . 'settings',
  1065. array('variable' => 'string', 'value' => 'string'),
  1066. array('allow_sm_stats', $ID[1]),
  1067. array('variable')
  1068. );
  1069. }
  1070. }
  1071. else
  1072. $smcFunc['db_query']('', '
  1073. DELETE FROM {db_prefix}settings
  1074. WHERE variable = {string:allow_sm_stats}',
  1075. array(
  1076. 'allow_sm_stats' => 'allow_sm_stats',
  1077. 'db_error_skip' => true,
  1078. )
  1079. );
  1080. // Emptying the error log?
  1081. if (!empty($_POST['empty_error']))
  1082. $smcFunc['db_query']('truncate_table', '
  1083. TRUNCATE {db_prefix}log_errors',
  1084. array(
  1085. )
  1086. );
  1087. $changes = array();
  1088. // If we're overriding the language follow it through.
  1089. if (isset($_GET['lang']) && file_exists($boarddir . '/Themes/default/languages/index.' . $_GET['lang'] . '.php'))
  1090. $changes['language'] = '\'' . $_GET['lang'] . '\'';
  1091. if (!empty($_POST['maint']))
  1092. {
  1093. $changes['maintenance'] = '2';
  1094. // Remember what it was...
  1095. $upcontext['user']['main'] = $maintenance;
  1096. if (!empty($_POST['maintitle']))
  1097. {
  1098. $changes['mtitle'] = '\'' . addslashes($_POST['maintitle']) . '\'';
  1099. $changes['mmessage'] = '\'' . addslashes($_POST['mainmessage']) . '\'';
  1100. }
  1101. else
  1102. {
  1103. $changes['mtitle'] = '\'Upgrading the forum...\'';
  1104. $changes['mmessage'] = '\'Don\\\'t worry, we will be back shortly with an updated forum. It will only be a minute ;).\'';
  1105. }
  1106. }
  1107. if ($command_line)
  1108. echo ' * Updating Settings.php...';
  1109. // Backup the current one first.
  1110. copy($boarddir . '/Settings.php', $boarddir . '/Settings_bak.php');
  1111. // Fix some old paths.
  1112. if (substr($boarddir, 0, 1) == '.')
  1113. $changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
  1114. if (substr($sourcedir, 0, 1) == '.')
  1115. $changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
  1116. if (empty($cachedir) || substr($cachedir, 0, 1) == '.')
  1117. $changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
  1118. // Not had the database type added before?
  1119. if (empty($db_type))
  1120. $changes['db_type'] = 'mysql';
  1121. // @todo Maybe change the cookie name if going to 1.1, too?
  1122. // Update Settings.php with the new settings.
  1123. changeSettings($changes);
  1124. if ($command_line)
  1125. echo ' Successful.' . "\n";
  1126. // Are we doing debug?
  1127. if (isset($_POST['debug']))
  1128. {
  1129. $upcontext['upgrade_status']['debug'] = true;
  1130. $is_debug = true;
  1131. }
  1132. // If we're not backing up then jump one.
  1133. if (empty($_POST['backup']))
  1134. $upcontext['current_step']++;
  1135. // If we've got here then let's proceed to the next step!
  1136. return true;
  1137. }
  1138. // Backup the database - why not...
  1139. function BackupDatabase()
  1140. {
  1141. global $upcontext, $db_prefix, $command_line, $is_debug, $support_js, $file_steps, $smcFunc;
  1142. $upcontext['sub_template'] = isset($_GET['xml']) ? 'backup_xml' : 'backup_database';
  1143. $upcontext['page_title'] = 'Backup Database';
  1144. // Done it already - js wise?
  1145. if (!empty($_POST['backup_done']))
  1146. return true;
  1147. // Some useful stuff here.
  1148. db_extend();
  1149. // Get all the table names.
  1150. $filter = str_replace('_', '\_', preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) != 0 ? $match[2] : $db_prefix) . '%';
  1151. $db = preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) != 0 ? strtr($match[1], array('`' => '')) : false;
  1152. $tables = $smcFunc['db_list_tables']($db, $filter);
  1153. $table_names = array();
  1154. foreach ($tables as $table)
  1155. if (substr($table, 0, 7) !== 'backup_')
  1156. $table_names[] = $table;
  1157. $upcontext['table_count'] = count($table_names);
  1158. $upcontext['cur_table_num'] = $_GET['substep'];
  1159. $upcontext['cur_table_name'] = str_replace($db_prefix, '', isset($table_names[$_GET['substep']]) ? $table_names[$_GET['substep']] : $table_names[0]);
  1160. $upcontext['step_progress'] = (int) (($upcontext['cur_table_num'] / $upcontext['table_count']) * 100);
  1161. // For non-java auto submit...
  1162. $file_steps = $upcontext['table_count'];
  1163. // What ones have we already done?
  1164. foreach ($table_names as $id => $table)
  1165. if ($id < $_GET['substep'])
  1166. $upcontext['previous_tables'][] = $table;
  1167. if ($command_line)
  1168. echo 'Backing Up Tables.';
  1169. // If we don't support javascript we backup here.
  1170. if (!$support_js || isset($_GET['xml']))
  1171. {
  1172. // Backup each table!
  1173. for ($substep = $_GET['substep'], $n = count($table_names); $substep < $n; $substep++)
  1174. {
  1175. $upcontext['cur_table_name'] = str_replace($db_prefix, '', (isset($table_names[$substep + 1]) ? $table_names[$substep + 1] : $table_names[$substep]));
  1176. $upcontext['cur_table_num'] = $substep + 1;
  1177. $upcontext['step_progress'] = (int) (($upcontext['cur_table_num'] / $upcontext['table_count']) * 100);
  1178. // Do we need to pause?
  1179. nextSubstep($substep);
  1180. backupTable($table_names[$substep]);
  1181. // If this is XML to keep it nice for the user do one table at a time anyway!
  1182. if (isset($_GET['xml']))
  1183. return upgradeExit();
  1184. }
  1185. if ($is_debug && $command_line)
  1186. {
  1187. echo "\n" . ' Successful.\'' . "\n";
  1188. flush();
  1189. }
  1190. $upcontext['step_progress'] = 100;
  1191. $_GET['substep'] = 0;
  1192. // Make sure we move on!
  1193. return true;
  1194. }
  1195. // Either way next place to post will be database changes!
  1196. $_GET['substep'] = 0;
  1197. return false;
  1198. }
  1199. // Backup one table...
  1200. function backupTable($table)
  1201. {
  1202. global $is_debug, $command_line, $db_prefix, $smcFunc;
  1203. if ($is_debug && $command_line)
  1204. {
  1205. echo "\n" . ' +++ Backing up \"' . str_replace($db_prefix, '', $table) . '"...';
  1206. flush();
  1207. }
  1208. $smcFunc['db_backup_table']($table, 'backup_' . $table);
  1209. if ($is_debug && $command_line)
  1210. echo ' done.';
  1211. }
  1212. // Step 2: Everything.
  1213. function DatabaseChanges()
  1214. {
  1215. global $db_prefix, $modSettings, $command_line, $smcFunc;
  1216. global $language, $boardurl, $sourcedir, $boarddir, $upcontext, $support_js, $db_type;
  1217. // Have we just completed this?
  1218. if (!empty($_POST['database_done']))
  1219. return true;
  1220. $upcontext['sub_template'] = isset($_GET['xml']) ? 'database_xml' : 'database_changes';
  1221. $upcontext['page_title'] = 'Database Changes';
  1222. // All possible files.
  1223. // Name, <version, insert_on_complete
  1224. $files = array(
  1225. array('upgrade_1-0.sql', '1.1', '1.1 RC0'),
  1226. array('upgrade_1-1.sql', '2.0', '2.0 a'),
  1227. array('upgrade_2-0_' . $db_type . '.sql', '2.1', '2.1 dev0'),
  1228. array('upgrade_2-1_' . $db_type . '.sql', '3.0', SMF_VERSION),
  1229. );
  1230. // How many files are there in total?
  1231. if (isset($_GET['filecount']))
  1232. $upcontext['file_count'] = (int) $_GET['filecount'];
  1233. else
  1234. {
  1235. $upcontext['file_count'] = 0;
  1236. foreach ($files as $file)
  1237. {
  1238. if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1])
  1239. $upcontext['file_count']++;
  1240. }
  1241. }
  1242. // Do each file!
  1243. $did_not_do = count($files) - $upcontext['file_count'];
  1244. $upcontext['step_progress'] = 0;
  1245. $upcontext['cur_file_num'] = 0;
  1246. foreach ($files as $file)
  1247. {
  1248. if ($did_not_do)
  1249. $did_not_do--;
  1250. else
  1251. {
  1252. $upcontext['cur_file_num']++;
  1253. $upcontext['cur_file_name'] = $file[0];
  1254. // Do we actually need to do this still?
  1255. if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1])
  1256. {
  1257. $nextFile = parse_sql(dirname(__FILE__) . '/' . $file[0]);
  1258. if ($nextFile)
  1259. {
  1260. // Only update the version of this if complete.
  1261. $smcFunc['db_insert']('replace',
  1262. $db_prefix . 'settings',
  1263. array('variable' => 'string', 'value' => 'string'),
  1264. array('smfVersion', $file[2]),
  1265. array('variable')
  1266. );
  1267. $modSettings['smfVersion'] = $file[2];
  1268. }
  1269. // If this is XML we only do this stuff once.
  1270. if (isset($_GET['xml']))
  1271. {
  1272. // Flag to move on to the next.
  1273. $upcontext['completed_step'] = true;
  1274. // Did we complete the whole file?
  1275. if ($nextFile)
  1276. $upcontext['current_debug_item_num'] = -1;
  1277. return upgradeExit();
  1278. }
  1279. elseif ($support_js)
  1280. break;
  1281. }
  1282. // Set the progress bar to be right as if we had - even if we hadn't...
  1283. $upcontext['step_progress'] = ($upcontext['cur_file_num'] / $upcontext['file_count']) * 100;
  1284. }
  1285. }
  1286. $_GET['substep'] = 0;
  1287. // So the template knows we're done.
  1288. if (!$support_js)
  1289. {
  1290. $upcontext['changes_complete'] = true;
  1291. // If this is the command line we can't do any more.
  1292. if ($command_line)
  1293. return DeleteUpgrade();
  1294. return true;
  1295. }
  1296. return false;
  1297. }
  1298. // Clean up any mods installed...
  1299. function CleanupMods()
  1300. {
  1301. global $db_prefix, $modSettings, $upcontext, $boarddir, $sourcedir, $settings, $smcFunc, $command_line;
  1302. // Sorry. Not supported for command line users.
  1303. if ($command_line)
  1304. return true;
  1305. // Skipping first?
  1306. if (!empty($_POST['skip']))
  1307. {
  1308. unset($_POST['skip']);
  1309. return true;
  1310. }
  1311. // If we get here withOUT SSI we need to redirect to ensure we get it!
  1312. if (!isset($_GET['ssi']) || !function_exists('mktree'))
  1313. redirectLocation('&ssi=1');
  1314. $upcontext['sub_template'] = 'clean_mods';
  1315. $upcontext['page_title'] = 'Cleanup Modifications';
  1316. // This can be skipped.
  1317. $upcontext['skip'] = true;
  1318. // If we're on the second redirect continue...
  1319. if (isset($_POST['cleandone2']))
  1320. return true;
  1321. // Do we already know about some writable files?
  1322. if (isset($_POST['writable_files']))
  1323. {
  1324. $writable_files = unserialize(base64_decode($_POST['writable_files']));
  1325. if (!makeFilesWritable($writable_files))
  1326. {
  1327. // What have we left?
  1328. $upcontext['writable_files'] = $writable_files;
  1329. return false;
  1330. }
  1331. }
  1332. // Load all theme paths....
  1333. $request = $smcFunc['db_query']('', '
  1334. SELECT id_theme, variable, value
  1335. FROM {db_prefix}themes
  1336. WHERE id_member = {int:id_member}
  1337. AND variable IN ({string:theme_dir}, {string:images_url})',
  1338. array(
  1339. 'id_member' => 0,
  1340. 'theme_dir' => 'theme_dir',
  1341. 'images_url' => 'images_url',
  1342. 'db_error_skip' => true,
  1343. )
  1344. );
  1345. $theme_paths = array();
  1346. while ($row = $smcFunc['db_fetch_assoc']($request))
  1347. {
  1348. if ($row['id_theme'] == 1)
  1349. $settings['default_' . $row['variable']] = $row['value'];
  1350. elseif ($row['variable'] == 'theme_dir')
  1351. $theme_paths[$row['id_theme']][$row['variable']] = $row['value'];
  1352. }
  1353. $smcFunc['db_free_result']($request);
  1354. // Are there are mods installed that may need uninstalling?
  1355. $request = $smcFunc['db_query']('', '
  1356. SELECT id_install, filename, name, themes_installed, version
  1357. FROM {db_prefix}log_packages
  1358. WHERE install_state = {int:installed}
  1359. ORDER BY time_installed DESC',
  1360. array(
  1361. 'installed' => 1,
  1362. 'db_error_skip' => true,
  1363. )
  1364. );
  1365. $upcontext['packages'] = array();
  1366. while ($row = $smcFunc['db_fetch_assoc']($request))
  1367. {
  1368. // Work out the status.
  1369. if (!file_exists($boarddir . '/Packages/' . $row['filename']))
  1370. {
  1371. $status = 'Missing';
  1372. $status_color = 'red';
  1373. $result = 'Removed';
  1374. }
  1375. else
  1376. {
  1377. $status = 'Installed';
  1378. $status_color = 'green';
  1379. $result = 'No Action Needed';
  1380. }
  1381. $upcontext['packages'][$row['id_install']] = array(
  1382. 'id' => $row['id_install'],
  1383. 'themes' => explode(',', $row['themes_installed']),
  1384. 'name' => $row['name'],
  1385. 'filename' => $row['filename'],
  1386. 'missing_file' => file_exists($boarddir . '/Packages/' . $row['filename']) ? 0 : 1,
  1387. 'files' => array(),
  1388. 'file_count' => 0,
  1389. 'status' => $status,
  1390. 'result' => $result,
  1391. 'color' => $status_color,
  1392. 'version' => $row['version'],
  1393. 'needs_removing' => false,
  1394. );
  1395. }
  1396. $smcFunc['db_free_result']($request);
  1397. // Don't carry on if there are none.
  1398. if (empty($upcontext['packages']))
  1399. return true;
  1400. // Setup some basics.
  1401. if (!empty($upcontext['user']['version']))
  1402. $_SESSION['version_emulate'] = $upcontext['user']['version'];
  1403. // Before we get started, don't report notice errors.
  1404. $oldErrorReporting = error_reporting(E_ALL ^ E_NOTICE);
  1405. if (!mktree($boarddir . '/Packages/temp', 0755))
  1406. {
  1407. deltree($boarddir . '/Packages/temp', false);
  1408. if (!mktree($boarddir . '/Packages/temp', 0777))
  1409. {
  1410. deltree($boarddir . '/Packages/temp', false);
  1411. // @todo Error here - plus chmod!
  1412. }
  1413. }
  1414. // Anything which reinstalled should not have its entry removed.
  1415. $reinstall_worked = array();
  1416. // We're gonna be doing some removin'
  1417. $test = isset($_POST['cleandone']) ? false : true;
  1418. foreach ($upcontext['packages'] as $id => $package)
  1419. {
  1420. // Can't do anything about this....
  1421. if ($package['missing_file'])
  1422. continue;
  1423. // Not testing *and* this wasn't checked?
  1424. if (!$test && (!isset($_POST['remove']) || !isset($_POST['remove'][$id])))
  1425. continue;
  1426. // What are the themes this was installed into?
  1427. $cur_theme_paths = array();
  1428. foreach ($theme_paths as $tid => $data)
  1429. if ($tid != 1 && in_array($tid, $package['themes']))
  1430. $cur_theme_paths[$tid] = $data;
  1431. // Get the modifications data if applicable.
  1432. $filename = $package['filename'];
  1433. $packageInfo = getPackageInfo($filename);
  1434. if (!is_array($packageInfo))
  1435. continue;
  1436. $info = parsePackageInfo($packageInfo['xml'], $test, 'uninstall');
  1437. // Also get the reinstall details...
  1438. if (isset($_POST['remove']))
  1439. $infoInstall = parsePackageInfo($packageInfo['xml'], true);
  1440. if (is_file($boarddir . '/Packages/' . $filename))
  1441. read_tgz_file($boarddir . '/Packages/' . $filename, $boarddir . '/Packages/temp');
  1442. else
  1443. copytree($boarddir . '/Packages/' . $filename, $boarddir . '/Packages/temp');
  1444. // Work out how we uninstall...
  1445. $files = array();
  1446. foreach ($info as $change)
  1447. {
  1448. // Work out two things:
  1449. // 1) Whether it's installed at the moment - and if so whether its fully installed, and:
  1450. // 2) Whether it could be installed on the new version.
  1451. if ($change['type'] == 'modification')
  1452. {
  1453. $contents = @file_get_contents($boarddir . '/Packages/temp/' . $upcontext['base_path'] . $change['filename']);
  1454. if ($change['boardmod'])
  1455. $results = parseBoardMod($contents, $test, $change['reverse'], $cur_theme_paths);
  1456. else
  1457. $results = parseModification($contents, $test, $change['reverse'], $cur_theme_paths);
  1458. foreach ($results as $action)
  1459. {
  1460. // Something we can remove? Probably means it existed!
  1461. if (($action['type'] == 'replace' || $action['type'] == 'append' || (!empty($action['filename']) && $action['type'] == 'failure')) && !in_array($action['filename'], $files))
  1462. $files[] = $action['filename'];
  1463. if ($action['type'] == 'failure')
  1464. {
  1465. $upcontext['packages'][$id]['needs_removing'] = true;
  1466. $upcontext['packages'][$id]['status'] = 'Reinstall Required';
  1467. $upcontext['packages'][$id]['color'] = '#FD6435';
  1468. }
  1469. }
  1470. }
  1471. }
  1472. // Store this info for the template as appropriate.
  1473. $upcontext['packages'][$id]['files'] = $files;
  1474. $upcontext['packages'][$id]['file_count'] = count($files);
  1475. // If we've done something save the changes!
  1476. if (!$test)
  1477. package_flush_cache();
  1478. // Are we attempting to reinstall this thing?
  1479. if (isset($_POST['remove']) && !$test && isset($infoInstall))
  1480. {
  1481. // Need to extract again I'm afraid.
  1482. if (is_file($boarddir . '/Packages/' . $filename))
  1483. read_tgz_file($boarddir . '/Packages/' . $filename, $boarddir . '/Packages/temp');
  1484. else
  1485. copytree($boarddir . '/Packages/' . $filename, $boarddir . '/Packages/temp');
  1486. $errors = false;
  1487. $upcontext['packages'][$id]['result'] = 'Removed';
  1488. foreach ($infoInstall as $change)
  1489. {
  1490. if ($change['type'] == 'modification')
  1491. {
  1492. $contents = @file_get_contents($boarddir . '/Packages/temp/' . $upcontext['base_path'] . $change['filename']);
  1493. if ($change['boardmod'])
  1494. $results = parseBoardMod($contents, true, $change['reverse'], $cur_theme_paths);
  1495. else
  1496. $results = parseModification($contents, true, $change['reverse'], $cur_theme_paths);
  1497. // Are there any errors?
  1498. foreach ($results as $action)
  1499. if ($action['type'] == 'failure')
  1500. $errors = true;
  1501. }
  1502. }
  1503. if (!$errors)
  1504. {
  1505. $reinstall_worked[] = $id;
  1506. $upcontext['packages'][$id]['result'] = 'Reinstalled';
  1507. $upcontext['packages'][$id]['color'] = 'green';
  1508. foreach ($infoInstall as $change)
  1509. {
  1510. if ($change['type'] == 'modification')
  1511. {
  1512. $contents = @file_get_contents($boarddir . '/Packages/temp/' . $upcontext['base_path'] . $change['filename']);
  1513. if ($change['boardmod'])
  1514. $results = parseBoardMod($contents, false, $change['reverse'], $cur_theme_paths);
  1515. else
  1516. $results = parseModification($contents, false, $change['reverse'], $cur_theme_paths);
  1517. }
  1518. }
  1519. // Save the changes.
  1520. package_flush_cache();
  1521. }
  1522. }
  1523. }
  1524. // Put errors back on a sec.
  1525. error_reporting($oldErrorReporting);
  1526. // Check everything is writable.
  1527. if ($test && !empty($upcontext['packages']))
  1528. {
  1529. $writable_files = array();
  1530. foreach ($upcontext['packages'] as $package)
  1531. {
  1532. if (!empty($package['files']))
  1533. foreach ($package['files'] as $file)
  1534. $writable_files[] = $file;
  1535. }
  1536. if (!empty($writable_files))
  1537. {
  1538. $writable_files = array_unique($writable_files);
  1539. $upcontext['writable_files'] = $writable_files;
  1540. if (!makeFilesWritable($writable_files))
  1541. return false;
  1542. }
  1543. }
  1544. if (file_exists($boarddir . '/Packages/temp'))
  1545. deltree($boarddir . '/Packages/temp');
  1546. // Removing/Reinstalling any packages?
  1547. if (isset($_POST['remove']))
  1548. {
  1549. $deletes = array();
  1550. foreach ($_POST['remove'] as $id => $dummy)
  1551. {
  1552. if (!in_array((int) $id, $reinstall_worked))
  1553. $deletes[] = (int) $id;
  1554. }
  1555. if (!empty($deletes))
  1556. upgrade_query( '
  1557. UPDATE ' . $db_prefix . 'log_packages
  1558. SET install_state = 0
  1559. WHERE id_install IN (' . implode(',', $deletes) . ')');
  1560. // Ensure we don't lose our changes!
  1561. package_put_contents($boarddir . '/Packages/installed.list', time());
  1562. $upcontext['sub_template'] = 'cleanup_done';
  1563. return false;
  1564. }
  1565. else
  1566. {
  1567. $allgood = true;
  1568. // Is there actually anything that needs our attention?
  1569. foreach ($upcontext['packages'] as $package)
  1570. if ($package['color'] != 'green')
  1571. $allgood = false;
  1572. if ($allgood)
  1573. return true;
  1574. }
  1575. $_GET['substep'] = 0;
  1576. return isset($_POST['cleandone']) ? true : false;
  1577. }
  1578. // Delete the damn thing!
  1579. function DeleteUpgrade()
  1580. {
  1581. global $command_line, $language, $upcontext, $boarddir, $sourcedir, $forum_version, $user_info, $maintenance, $smcFunc, $db_type;
  1582. // Now it's nice to have some of the basic SMF source files.
  1583. if (!isset($_GET['ssi']) && !$command_line)
  1584. redirectLocation('&ssi=1');
  1585. $upcontext['sub_template'] = 'upgrade_complete';
  1586. $upcontext['page_title'] = 'Upgrade Complete';
  1587. $endl = $command_line ? "\n" : '<br />' . "\n";
  1588. $changes = array(
  1589. 'language' => '\'' . (substr($language, -4) == '.lng' ? substr($language, 0, -4) : $language) . '\'',
  1590. 'db_error_send' => '1',
  1591. 'upgradeData' => '#remove#',
  1592. );
  1593. // Are we in maintenance mode?
  1594. if (isset($upcontext['user']['main']))
  1595. {
  1596. if ($command_line)
  1597. echo ' * ';
  1598. $upcontext['removed_maintenance'] = true;
  1599. $changes['maintenance'] = $upcontext['user']['main'];
  1600. }
  1601. // Otherwise if somehow we are in 2 let's go to 1.
  1602. elseif (!empty($maintenance) && $maintenance == 2)
  1603. $changes['maintenance'] = 1;
  1604. // Wipe this out...
  1605. $upcontext['user'] = array();
  1606. // Make a backup of Settings.php first as otherwise earlier changes are lost.
  1607. copy($boarddir . '/Settings.php', $boarddir . '/Settings_bak.php');
  1608. changeSettings($changes);
  1609. // Clean any old cache files away.
  1610. clean_cache();
  1611. // Can we delete the file?
  1612. $upcontext['can_delete_script'] = is_writable(dirname(__FILE__)) || is_writable(__FILE__);
  1613. // Now is the perfect time to fetch the SM files.
  1614. if ($command_line)
  1615. cli_scheduled_fetchSMfiles();
  1616. else
  1617. {
  1618. require_once($sourcedir . '/ScheduledTasks.php');
  1619. $forum_version = SMF_VERSION; // The variable is usually defined in index.php so lets just use the constant to do it for us.
  1620. scheduled_fetchSMfiles(); // Now go get those files!
  1621. }
  1622. // Log what we've done.
  1623. if (empty($user_info['id']))
  1624. $user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
  1625. // Log the action manually, so CLI still works.
  1626. $smcFunc['db_insert']('',
  1627. '{db_prefix}log_actions',
  1628. array(
  1629. 'log_time' => 'int', 'id_log' => 'int', 'id_member' => 'int', 'ip' => 'string-16', 'action' => 'string',
  1630. 'id_board' => 'int', 'id_topic' => 'int', 'id_msg' => 'int', 'extra' => 'string-65534',
  1631. ),
  1632. array(
  1633. time(), 3, $user_info['id'], $command_line ? '127.0.0.1' : $user_info['ip'], 'upgrade',
  1634. 0, 0, 0, serialize(array('version' => $forum_version, 'member' => $user_info['id'])),
  1635. ),
  1636. array('id_action')
  1637. );
  1638. $user_info['id'] = 0;
  1639. // Save the current database version.
  1640. $server_version = $smcFunc['db_server_info']();
  1641. if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
  1642. updateSettings(array('db_mysql_group_by_fix' => '1'));
  1643. if ($command_line)
  1644. {
  1645. echo $endl;
  1646. echo 'Upgrade Complete!', $endl;
  1647. echo 'Please delete this file as soon as possible for security reasons.', $endl;
  1648. exit;
  1649. }
  1650. // Make sure it says we're done.
  1651. $upcontext['overall_percent'] = 100;
  1652. if (isset($upcontext['step_progress']))
  1653. unset($upcontext['step_progress']);
  1654. $_GET['substep'] = 0;
  1655. return false;
  1656. }
  1657. // Just like the built in one, but setup for CLI to not use themes.
  1658. function cli_scheduled_fetchSMfiles()
  1659. {
  1660. global $sourcedir, $txt, $language, $settings, $forum_version, $modSettings, $smcFunc;
  1661. if (empty($modSettings['time_format']))
  1662. $modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
  1663. // What files do we want to get
  1664. $request = $smcFunc['db_query']('', '
  1665. SELECT id_file, filename, path, parameters
  1666. FROM {db_prefix}admin_info_files',
  1667. array(
  1668. )
  1669. );
  1670. $js_files = array();
  1671. while ($row = $smcFunc['db_fetch_assoc']($request))
  1672. {
  1673. $js_files[$row['id_file']] = array(
  1674. 'filename' => $row['filename'],
  1675. 'path' => $row['path'],
  1676. 'parameters' => sprintf($row['parameters'], $language, urlencode($modSettings['time_format']), urlencode($forum_version)),
  1677. );
  1678. }
  1679. $smcFunc['db_free_result']($request);
  1680. // We're gonna need fetch_web_data() to pull this off.
  1681. require_once($sourcedir . '/Subs-Package.php');
  1682. foreach ($js_files as $ID_FILE => $file)
  1683. {
  1684. // Create the url
  1685. $server = empty($file['path']) || substr($file['path'], 0, 7) != 'http://' ? 'http://www.simplemachines.org' : '';
  1686. $url = $server . (!empty($file['path']) ? $file['path'] : $file['path']) . $file['filename'] . (!empty($file['parameters']) ? '?' . $file['parameters'] : '');
  1687. // Get the file
  1688. $file_data = fetch_web_data($url);
  1689. // If we got an error - give up - the site might be down.
  1690. if ($file_data === false)
  1691. return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
  1692. // Save the file to the database.
  1693. $smcFunc['db_query']('substring', '
  1694. UPDATE {db_prefix}admin_info_files
  1695. SET data = SUBSTRING({string:file_data}, 1, 65534)
  1696. WHERE id_file = {int:id_file}',
  1697. array(
  1698. 'id_file' => $ID_FILE,
  1699. 'file_data' => $file_data,
  1700. )
  1701. );
  1702. }
  1703. return true;
  1704. }
  1705. function convertSettingsToTheme()
  1706. {
  1707. global $db_prefix, $modSettings, $smcFunc;
  1708. $values = array(
  1709. 'show_latest_member' => @$GLOBALS['showlatestmember'],
  1710. 'show_bbc' => isset($GLOBALS['showyabbcbutt']) ? $GLOBALS['showyabbcbutt'] : @$GLOBALS['showbbcbutt'],
  1711. 'show_modify' => @$GLOBALS['showmodify'],
  1712. 'show_user_images' => @$GLOBALS['showuserpic'],
  1713. 'show_blurb' => @$GLOBALS['showusertext'],
  1714. 'show_gender' => @$GLOBALS['showgenderimage'],
  1715. 'show_newsfader' => @$GLOBALS['shownewsfader'],
  1716. 'display_recent_bar' => @$GLOBALS['Show_RecentBar'],
  1717. 'show_member_bar' => @$GLOBALS['Show_MemberBar'],
  1718. 'linktree_link' => @$GLOBALS['curposlinks'],
  1719. 'show_profile_buttons' => @$GLOBALS['profilebutton'],
  1720. 'show_mark_read' => @$GLOBALS['showmarkread'],
  1721. 'show_board_desc' => @$GLOBALS['ShowBDescrip'],
  1722. 'newsfader_time' => @$GLOBALS['fadertime'],
  1723. 'use_image_buttons' => empty($GLOBALS['MenuType']) ? 1 : 0,
  1724. 'enable_news' => @$GLOBALS['enable_news'],
  1725. 'return_to_post' => @$modSettings['returnToPost'],
  1726. );
  1727. $themeData = array();
  1728. foreach ($values as $variable => $value)
  1729. {
  1730. if (!isset($value) || $value === null)
  1731. $value = 0;
  1732. $themeData[] = array(0, 1, $variable, $value);
  1733. }
  1734. if (!empty($themeData))
  1735. {
  1736. $smcFunc['db_insert']('ignore',
  1737. $db_prefix . 'themes',
  1738. array('id_member' => 'int', 'id_theme' => 'int', 'variable' => 'string', 'value' => 'string'),
  1739. $themeData,
  1740. array('id_member', 'id_theme', 'variable')
  1741. );
  1742. }
  1743. }
  1744. // This function only works with MySQL but that's fine as it is only used for v1.0.
  1745. function convertSettingstoOptions()
  1746. {
  1747. global $db_prefix, $modSettings, $smcFunc;
  1748. // Format: new_setting -> old_setting_name.
  1749. $values = array(
  1750. 'calendar_start_day' => 'cal_startmonday',
  1751. 'view_newest_first' => 'viewNewestFirst',
  1752. 'view_newest_pm_first' => 'viewNewestFirst',
  1753. );
  1754. foreach ($values as $variable => $value)
  1755. {
  1756. if (empty($modSettings[$value[0]]))
  1757. continue;
  1758. $smcFunc['db_query']('', '
  1759. INSERT IGNORE INTO {db_prefix}themes
  1760. (id_member, id_theme, variable, value)
  1761. SELECT id_member, 1, {string:variable}, {string:value}
  1762. FROM {db_prefix}members',
  1763. array(
  1764. 'variable' => $variable,
  1765. 'value' => $modSettings[$value[0]],
  1766. 'db_error_skip' => true,
  1767. )
  1768. );
  1769. $smcFunc['db_query']('', '
  1770. INSERT IGNORE INTO {db_prefix}themes
  1771. (id_member, id_theme, variable, value)
  1772. VALUES (-1, 1, {string:variable}, {string:value})',
  1773. array(
  1774. 'variable' => $variable,
  1775. 'value' => $modSettings[$value[0]],
  1776. 'db_error_skip' => true,
  1777. )
  1778. );
  1779. }
  1780. }
  1781. function changeSettings($config_vars)
  1782. {
  1783. global $boarddir;
  1784. $settingsArray = file($boarddir . '/Settings_bak.php');
  1785. if (count($settingsArray) == 1)
  1786. $settingsArray = preg_split('~[\r\n]~', $settingsArray[0]);
  1787. for ($i = 0, $n = count($settingsArray); $i < $n; $i++)
  1788. {
  1789. // Don't trim or bother with it if it's not a variable.
  1790. if (substr($settingsArray[$i], 0, 1) == '$')
  1791. {
  1792. $settingsArray[$i] = trim($settingsArray[$i]) . "\n";
  1793. foreach ($config_vars as $var => $val)
  1794. {
  1795. if (isset($settingsArray[$i]) && strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
  1796. {
  1797. if ($val == '#remove#')
  1798. unset($settingsArray[$i]);
  1799. else
  1800. {
  1801. $comment = strstr(substr($settingsArray[$i], strpos($settingsArray[$i], ';')), '#');
  1802. $settingsArray[$i] = '$' . $var . ' = ' . $val . ';' . ($comment != '' ? "\t\t" . $comment : "\n");
  1803. }
  1804. unset($config_vars[$var]);
  1805. }
  1806. }
  1807. }
  1808. if (isset($settingsArray[$i]))
  1809. {
  1810. if (trim(substr($settingsArray[$i], 0, 2)) == '?' . '>')
  1811. $end = $i;
  1812. }
  1813. }
  1814. // Assume end-of-file if the end wasn't found.
  1815. if (empty($end) || $end < 10)
  1816. $end = count($settingsArray);
  1817. if (!empty($config_vars))
  1818. {
  1819. $settingsArray[$end++] = '';
  1820. foreach ($config_vars as $var => $val)
  1821. {
  1822. if ($val != '#remove#')
  1823. $settingsArray[$end++] = '$' . $var . ' = ' . $val . ';' . "\n";
  1824. }
  1825. }
  1826. // This should be the last line and even last bytes of the file.
  1827. $settingsArray[$end] = '?' . '>';
  1828. // Blank out the file - done to fix a oddity with some servers.
  1829. $fp = fopen($boarddir . '/Settings.php', 'w');
  1830. fclose($fp);
  1831. $fp = fopen($boarddir . '/Settings.php', 'r+');
  1832. for ($i = 0; $i < $end; $i++)
  1833. {
  1834. if (isset($settingsArray[$i]))
  1835. fwrite($fp, strtr($settingsArray[$i], "\r", ''));
  1836. }
  1837. fwrite($fp, rtrim($settingsArray[$i]));
  1838. fclose($fp);
  1839. }
  1840. function php_version_check()
  1841. {
  1842. $minver = explode('.', $GLOBALS['required_php_version']);
  1843. $curver = explode('.', PHP_VERSION);
  1844. return !(($curver[0] <= $minver[0]) && ($curver[1] <= $minver[1]) && ($curver[1] <= $minver[1]) && ($curver[2][0] < $minver[2][0]));
  1845. }
  1846. function db_version_check()
  1847. {
  1848. global $db_type, $databases;
  1849. $curver = eval($databases[$db_type]['version_check']);
  1850. $curver = preg_replace('~\-.+?$~', '', $curver);
  1851. return version_compare($databases[$db_type]['version'], $curver, '<=');
  1852. }
  1853. function getMemberGroups()
  1854. {
  1855. global $db_prefix, $smcFunc;
  1856. static $member_groups = array();
  1857. if (!empty($member_groups))
  1858. return $member_groups;
  1859. $request = $smcFunc['db_query']('', '
  1860. SELECT group_name, id_group
  1861. FROM {db_prefix}membergroups
  1862. WHERE id_group = {int:admin_group} OR id_group > {int:old_group}',
  1863. array(
  1864. 'admin_group' => 1,
  1865. 'old_group' => 7,
  1866. 'db_error_skip' => true,
  1867. )
  1868. );
  1869. if ($request === false)
  1870. {
  1871. $request = $smcFunc['db_query']('', '
  1872. SELECT membergroup, id_group
  1873. FROM {db_prefix}membergroups
  1874. WHERE id_group = {int:admin_group} OR id_group > {int:old_group}',
  1875. array(
  1876. 'admin_group' => 1,
  1877. 'old_group' => 7,
  1878. 'db_error_skip' => true,
  1879. )
  1880. );
  1881. }
  1882. while ($row = $smcFunc['db_fetch_row']($request))
  1883. $member_groups[trim($row[0])] = $row[1];
  1884. $smcFunc['db_free_result']($request);
  1885. return $member_groups;
  1886. }
  1887. function fixRelativePath($path)
  1888. {
  1889. global $install_path;
  1890. // Fix the . at the start, clear any duplicate slashes, and fix any trailing slash...
  1891. return addslashes(preg_replace(array('~^\.([/\\\]|$)~', '~[/]+~', '~[\\\]+~', '~[/\\\]$~'), array($install_path . '$1', '/', '\\', ''), $path));
  1892. }
  1893. function parse_sql($filename)
  1894. {
  1895. global $db_prefix, $db_collation, $boarddir, $boardurl, $command_line, $file_steps, $step_progress, $custom_warning;
  1896. global $upcontext, $support_js, $is_debug, $smcFunc, $db_connection, $databases, $db_type, $db_character_set;
  1897. /*
  1898. Failure allowed on:
  1899. - INSERT INTO but not INSERT IGNORE INTO.
  1900. - UPDATE IGNORE but not UPDATE.
  1901. - ALTER TABLE and ALTER IGNORE TABLE.
  1902. - DROP TABLE.
  1903. Yes, I realize that this is a bit confusing... maybe it should be done differently?
  1904. If a comment...
  1905. - begins with --- it is to be output, with a break only in debug mode. (and say successful\n\n if there was one before.)
  1906. - begins with ---# it is a debugging statement, no break - only shown at all in debug.
  1907. - is only ---#, it is "done." and then a break - only shown in debug.
  1908. - begins with ---{ it is a code block terminating at ---}.
  1909. Every block of between "--- ..."s is a step. Every "---#" section represents a substep.
  1910. Replaces the following variables:
  1911. - {$boarddir}
  1912. - {$boardurl}
  1913. - {$db_prefix}
  1914. - {$db_collation}
  1915. */
  1916. // May want to use extended functionality.
  1917. db_extend();
  1918. db_extend('packages');
  1919. // Our custom error handler - does nothing but does stop public errors from XML!
  1920. if (!function_exists('sql_error_handler'))
  1921. {
  1922. function sql_error_handler($errno, $errstr, $errfile, $errline)
  1923. {
  1924. global $support_js;
  1925. if ($support_js)
  1926. return true;
  1927. else
  1928. echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
  1929. }
  1930. }
  1931. // Make our own error handler.
  1932. set_error_handler('sql_error_handler');
  1933. // If we're on MySQL supporting collations then let's find out what the members table uses and put it in a global var - to allow upgrade script to match collations!
  1934. if (!empty($databases[$db_type]['utf8_support']) && version_compare($databases[$db_type]['utf8_version'], eval($databases[$db_type]['utf8_version_check']), '>'))
  1935. {
  1936. $request = $smcFunc['db_query']('', '
  1937. SHOW TABLE STATUS
  1938. LIKE {string:table_name}',
  1939. array(
  1940. 'table_name' => "{$db_prefix}members",
  1941. 'db_error_skip' => true,
  1942. )
  1943. );
  1944. if ($smcFunc['db_num_rows']($request) === 0)
  1945. die('Unable to find members table!');
  1946. $table_status = $smcFunc['db_fetch_assoc']($request);
  1947. $smcFunc['db_free_result']($request);
  1948. if (!empty($table_status['Collation']))
  1949. {
  1950. $request = $smcFunc['db_query']('', '
  1951. SHOW COLLATION
  1952. LIKE {string:collation}',
  1953. array(
  1954. 'collation' => $table_status['Collation'],
  1955. 'db_error_skip' => true,
  1956. )
  1957. );
  1958. // Got something?
  1959. if ($smcFunc['db_num_rows']($request) !== 0)
  1960. $collation_info = $smcFunc['db_fetch_assoc']($request);
  1961. $smcFunc['db_free_result']($request);
  1962. // Excellent!
  1963. if (!empty($collation_info['Collation']) && !empty($collation_info['Charset']))
  1964. $db_collation = ' CHARACTER SET ' . $collation_info['Charset'] . ' COLLATE ' . $collation_info['Collation'];
  1965. }
  1966. }
  1967. if (empty($db_collation))
  1968. $db_collation = '';
  1969. $endl = $command_line ? "\n" : '<br />' . "\n";
  1970. $lines = file($filename);
  1971. $current_type = 'sql';
  1972. $current_data = '';
  1973. $substep = 0;
  1974. $last_step = '';
  1975. // Make sure all newly created tables will have the proper characters set.
  1976. if (isset($db_character_set) && $db_character_set === 'utf8')
  1977. $lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
  1978. // Count the total number of steps within this file - for progress.
  1979. $file_steps = substr_count(implode('', $lines), '---#');
  1980. $upcontext['total_items'] = substr_count(implode('', $lines), '--- ');
  1981. $upcontext['debug_items'] = $file_steps;
  1982. $upcontext['current_item_num'] = 0;
  1983. $upcontext['current_item_name'] = '';
  1984. $upcontext['current_debug_item_num'] = 0;
  1985. $upcontext['current_debug_item_name'] = '';
  1986. // This array keeps a record of what we've done in case java is dead...
  1987. $upcontext['actioned_items'] = array();
  1988. $done_something = false;
  1989. foreach ($lines as $line_number => $line)
  1990. {
  1991. $do_current = $substep >= $_GET['substep'];
  1992. // Get rid of any comments in the beginning of the line...
  1993. if (substr(trim($line), 0, 2) === '/*')
  1994. $line = preg_replace('~/\*.+?\*/~', '', $line);
  1995. // Always flush. Flush, flush, flush. Flush, flush, flush, flush! FLUSH!
  1996. if ($is_debug && !$support_js && $command_line)
  1997. flush();
  1998. if (trim($line) === '')
  1999. continue;
  2000. if (trim(substr($line, 0, 3)) === '---')
  2001. {
  2002. $type = substr($line, 3, 1);
  2003. // An error??
  2004. if (trim($current_data) != '' && $type !== '}')
  2005. {
  2006. $upcontext['error_message'] = 'Error in upgrade script - line ' . $line_number . '!' . $endl;
  2007. if ($command_line)
  2008. echo $upcontext['error_message'];
  2009. }
  2010. if ($type == ' ')
  2011. {
  2012. if (!$support_js && $do_current && $_GET['substep'] != 0 && $command_line)
  2013. {
  2014. echo ' Successful.', $endl;
  2015. flush();
  2016. }
  2017. $last_step = htmlspecialchars(rtrim(substr($line, 4)));
  2018. $upcontext['current_item_num']++;
  2019. $upcontext['current_item_name'] = $last_step;
  2020. if ($do_current)
  2021. {
  2022. $upcontext['actioned_items'][] = $last_step;
  2023. if ($command_line)
  2024. echo ' * ';
  2025. }
  2026. }
  2027. elseif ($type == '#')
  2028. {
  2029. $upcontext['step_progress'] += (100 / $upcontext['file_count']) / $file_steps;
  2030. $upcontext['current_debug_item_num']++;
  2031. if (trim($line) != '---#')
  2032. $upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
  2033. // Have we already done something?
  2034. if (isset($_GET['xml']) && $done_something)
  2035. {
  2036. restore_error_handler();
  2037. return $upcontext['current_debug_item_num'] >= $upcontext['debug_items'] ? true : false;
  2038. }
  2039. if ($do_current)
  2040. {
  2041. if (trim($line) == '---#' && $command_line)
  2042. echo ' done.', $endl;
  2043. elseif ($command_line)
  2044. echo ' +++ ', rtrim(substr($line, 4));
  2045. elseif (trim($line) != '---#')
  2046. {
  2047. if ($is_debug)
  2048. $upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
  2049. }
  2050. }
  2051. if ($substep < $_GET['substep'] && $substep + 1 >= $_GET['substep'])
  2052. {
  2053. if ($command_line)
  2054. echo ' * ';
  2055. else
  2056. $upcontext['actioned_items'][] = $last_step;
  2057. }
  2058. // Small step - only if we're actually doing stuff.
  2059. if ($do_current)
  2060. nextSubstep(++$substep);
  2061. else
  2062. $substep++;
  2063. }
  2064. elseif ($type == '{')
  2065. $current_type = 'code';
  2066. elseif ($type == '}')
  2067. {
  2068. $current_type = 'sql';
  2069. if (!$do_current)
  2070. {
  2071. $current_data = '';
  2072. continue;
  2073. }
  2074. if (eval('global $db_prefix, $modSettings, $smcFunc; ' . $current_data) === false)
  2075. {
  2076. $upcontext['error_message'] = 'Error in upgrade script ' . basename($filename) . ' on line ' . $line_number . '!' . $endl;
  2077. if ($command_line)
  2078. echo $upcontext['error_message'];
  2079. }
  2080. // Done with code!
  2081. $current_data = '';
  2082. $done_something = true;
  2083. }
  2084. continue;
  2085. }
  2086. $current_data .= $line;
  2087. if (substr(rtrim($current_data), -1) === ';' && $current_type === 'sql')
  2088. {
  2089. if ((!$support_js || isset($_GET['xml'])))
  2090. {
  2091. if (!$do_current)
  2092. {
  2093. $current_data = '';
  2094. continue;
  2095. }
  2096. $current_data = strtr(substr(rtrim($current_data), 0, -1), array('{$db_prefix}' => $db_prefix, '{$boarddir}' => $boarddir, '{$sboarddir}' => addslashes($boarddir), '{$boardurl}' => $boardurl, '{$db_collation}' => $db_collation));
  2097. upgrade_query($current_data);
  2098. // @todo This will be how it kinda does it once mysql all stripped out - needed for postgre (etc).
  2099. /*
  2100. $result = $smcFunc['db_query']('', $current_data, false, false);
  2101. // Went wrong?
  2102. if (!$result)
  2103. {
  2104. // Bit of a bodge - do we want the error?
  2105. if (!empty($upcontext['return_error']))
  2106. {
  2107. $upcontext['error_message'] = $smcFunc['db_error']($db_connection);
  2108. return false;
  2109. }
  2110. }*/
  2111. $done_something = true;
  2112. }
  2113. $current_data = '';
  2114. }
  2115. // If this is xml based and we're just getting the item name then that's grand.
  2116. elseif ($support_js && !isset($_GET['xml']) && $upcontext['current_debug_item_name'] != '' && $do_current)
  2117. {
  2118. restore_error_handler();
  2119. return false;
  2120. }
  2121. // Clean up by cleaning any step info.
  2122. $step_progress = array();
  2123. $custom_warning = '';
  2124. }
  2125. // Put back the error handler.
  2126. restore_error_handler();
  2127. if ($command_line)
  2128. {
  2129. echo ' Successful.' . "\n";
  2130. flush();
  2131. }
  2132. $_GET['substep'] = 0;
  2133. return true;
  2134. }
  2135. function upgrade_query($string, $unbuffered = false)
  2136. {
  2137. global $db_connection, $db_server, $db_user, $db_passwd, $db_type, $command_line, $upcontext, $upgradeurl, $modSettings;
  2138. global $db_name, $db_unbuffered, $smcFunc;
  2139. // Get the query result - working around some SMF specific security - just this once!
  2140. $modSettings['disableQueryCheck'] = true;
  2141. $db_unbuffered = $unbuffered;
  2142. $result = $smcFunc['db_query']('', $string, 'security_override');
  2143. $db_unbuffered = false;
  2144. // Failure?!
  2145. if ($result !== false)
  2146. return $result;
  2147. $db_error_message = $smcFunc['db_error']($db_connection);
  2148. // If MySQL we do something more clever.
  2149. if ($db_type == 'mysql')
  2150. {
  2151. $mysql_errno = mysql_errno($db_connection);
  2152. $error_query = in_array(substr(trim($string), 0, 11), array('INSERT INTO', 'UPDATE IGNO', 'ALTER TABLE', 'DROP TABLE ', 'ALTER IGNOR'));
  2153. // Error numbers:
  2154. // 1016: Can't open file '....MYI'
  2155. // 1050: Table already exists.
  2156. // 1054: Unknown column name.
  2157. // 1060: Duplicate column name.
  2158. // 1061: Duplicate key name.
  2159. // 1062: Duplicate entry for unique key.
  2160. // 1068: Multiple primary keys.
  2161. // 1072: Key column '%s' doesn't exist in table.
  2162. // 1091: Can't drop key, doesn't exist.
  2163. // 1146: Table doesn't exist.
  2164. // 2013: Lost connection to server during query.
  2165. if ($mysql_errno == 1016)
  2166. {
  2167. if (preg_match('~\'([^\.\']+)~', $db_error_message, $match) != 0 && !empty($match[1]))
  2168. mysql_query( '
  2169. REPAIR TABLE `' . $match[1] . '`');
  2170. $result = mysql_query($string);
  2171. if ($result !== false)
  2172. return $result;
  2173. }
  2174. elseif ($mysql_errno == 2013)
  2175. {
  2176. $db_connection = mysql_connect($db_server, $db_user, $db_passwd);
  2177. mysql_select_db($db_name, $db_connection);
  2178. if ($db_connection)
  2179. {
  2180. $result = mysql_query($string);
  2181. if ($result !== false)
  2182. return $result;
  2183. }
  2184. }
  2185. // Duplicate column name... should be okay ;).
  2186. elseif (in_array($mysql_errno, array(1060, 1061, 1068, 1091)))
  2187. return false;
  2188. // Duplicate insert... make sure it's the proper type of query ;).
  2189. elseif (in_array($mysql_errno, array(1054, 1062, 1146)) && $error_query)
  2190. return false;
  2191. // Creating an index on a non-existent column.
  2192. elseif ($mysql_errno == 1072)
  2193. return false;
  2194. elseif ($mysql_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE')
  2195. return false;
  2196. }
  2197. // If a table already exists don't go potty.
  2198. else
  2199. {
  2200. if (in_array(substr(trim($string), 0, 8), array('CREATE T', 'CREATE S', 'DROP TABL', 'ALTER TA', 'CREATE I')))
  2201. {
  2202. if (strpos($db_error_message, 'exist') !== false)
  2203. return true;
  2204. // SQLite
  2205. if (strpos($db_error_message, 'missing') !== false)
  2206. return true;
  2207. }
  2208. elseif (strpos(trim($string), 'INSERT ') !== false)
  2209. {
  2210. if (strpos($db_error_message, 'duplicate') !== false)
  2211. return true;
  2212. }
  2213. }
  2214. // Get the query string so we pass everything.
  2215. $query_string = '';
  2216. foreach ($_GET as $k => $v)
  2217. $query_string .= ';' . $k . '=' . $v;
  2218. if (strlen($query_string) != 0)
  2219. $query_string = '?' . substr($query_string, 1);
  2220. if ($command_line)
  2221. {
  2222. echo 'Unsuccessful! Database error message:', "\n", $db_error_message, "\n";
  2223. die;
  2224. }
  2225. // Bit of a bodge - do we want the error?
  2226. if (!empty($upcontext['return_error']))
  2227. {
  2228. $upcontext['error_message'] = $db_error_message;
  2229. return false;
  2230. }
  2231. // Otherwise we have to display this somewhere appropriate if possible.
  2232. $upcontext['forced_error_message'] = '
  2233. <strong>Unsuccessful!</strong><br />
  2234. <div style="margin: 2ex;">
  2235. This query:
  2236. <blockquote><tt>' . nl2br(htmlspecialchars(trim($string))) . ';</tt></blockquote>
  2237. Caused the error:
  2238. <blockquote>' . nl2br(htmlspecialchars($db_error_message)) . '</blockquote>
  2239. </div>
  2240. <form action="' . $upgradeurl . $query_string . '" method="post">
  2241. <input type="submit" value="Try again" class="button_submit" />
  2242. </form>
  2243. </div>';
  2244. upgradeExit();
  2245. }
  2246. // This performs a table alter, but does it unbuffered so the script can time out professionally.
  2247. function protected_alter($change, $substep, $is_test = false)
  2248. {
  2249. global $db_prefix, $smcFunc;
  2250. db_extend('packages');
  2251. // Firstly, check whether the current index/column exists.
  2252. $found = false;
  2253. if ($change['type'] === 'column')
  2254. {
  2255. $columns = $smcFunc['db_list_columns']('{db_prefix}' . $change['table'], true);
  2256. foreach ($columns as $column)
  2257. {
  2258. // Found it?
  2259. if ($column['name'] === $change['name'])
  2260. {
  2261. $found |= 1;
  2262. // Do some checks on the data if we have it set.
  2263. if (isset($change['col_type']))
  2264. $found &= $change['col_type'] === $column['type'];
  2265. if (isset($change['null_allowed']))
  2266. $found &= $column['null'] == $change['null_allowed'];
  2267. if (isset($change['default']))
  2268. $found &= $change['default'] === $column['default'];
  2269. }
  2270. }
  2271. }
  2272. elseif ($change['type'] === 'index')
  2273. {
  2274. $request = upgrade_query( '
  2275. SHOW INDEX
  2276. FROM ' . $db_prefix . $change['table']);
  2277. if ($request !== false)
  2278. {
  2279. $cur_index = array();
  2280. while ($row = $smcFunc['db_fetch_assoc']($request))
  2281. if ($row['Key_name'] === $change['name'])
  2282. $cur_index[(int) $row['Seq_in_index']] = $row['Column_name'];
  2283. ksort($cur_index, SORT_NUMERIC);
  2284. $found = array_values($cur_index) === $change['target_columns'];
  2285. $smcFunc['db_free_result']($request);
  2286. }
  2287. }
  2288. // If we're trying to add and it's added, we're done.
  2289. if ($found && in_array($change['method'], array('add', 'change')))
  2290. return true;
  2291. // Otherwise if we're removing and it wasn't found we're also done.
  2292. elseif (!$found && in_array($change['method'], array('remove', 'change_remove')))
  2293. return true;
  2294. // Otherwise is it just a test?
  2295. elseif ($is_test)
  2296. return false;
  2297. // Not found it yet? Bummer! How about we see if we're currently doing it?
  2298. $running = false;
  2299. $found = false;
  2300. while (1 == 1)
  2301. {
  2302. $request = upgrade_query('
  2303. SHOW FULL PROCESSLIST');
  2304. while ($row = $smcFunc['db_fetch_assoc']($request))
  2305. {
  2306. if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false)
  2307. $found = true;
  2308. }
  2309. // Can't find it? Then we need to run it fools!
  2310. if (!$found && !$running)
  2311. {
  2312. $smcFunc['db_free_result']($request);
  2313. $success = upgrade_query('
  2314. ALTER TABLE ' . $db_prefix . $change['table'] . '
  2315. ' . $change['text'], true) !== false;
  2316. if (!$success)
  2317. return false;
  2318. // Return
  2319. $running = true;
  2320. }
  2321. // What if we've not found it, but we'd ran it already? Must of completed.
  2322. elseif (!$found)
  2323. {
  2324. $smcFunc['db_free_result']($request);
  2325. return true;
  2326. }
  2327. // Pause execution for a sec or three.
  2328. sleep(3);
  2329. // Can never be too well protected.
  2330. nextSubstep($substep);
  2331. }
  2332. // Protect it.
  2333. nextSubstep($substep);
  2334. }
  2335. // Alter a text column definition preserving its character set.
  2336. function textfield_alter($change, $substep)
  2337. {
  2338. global $db_prefix, $databases, $db_type, $smcFunc;
  2339. // Versions of MySQL < 4.1 wouldn't benefit from character set detection.
  2340. if (empty($databases[$db_type]['utf8_support']) || version_compare($databases[$db_type]['utf8_version'], eval($databases[$db_type]['utf8_version_check']), '>'))
  2341. {
  2342. $column_fix = true;
  2343. $null_fix = !$change['null_allowed'];
  2344. }
  2345. else
  2346. {
  2347. $request = $smcFunc['db_query']('', '
  2348. SHOW FULL COLUMNS
  2349. FROM {db_prefix}' . $change['table'] . '
  2350. LIKE {string:column}',
  2351. array(
  2352. 'column' => $change['column'],
  2353. 'db_error_skip' => true,
  2354. )
  2355. );
  2356. if ($smcFunc['db_num_rows']($request) === 0)
  2357. die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
  2358. $table_row = $smcFunc['db_fetch_assoc']($request);
  2359. $smcFunc['db_free_result']($request);
  2360. // If something of the current column definition is different, fix it.
  2361. $column_fix = $table_row['Type'] !== $change['type'] || (strtolower($table_row['Null']) === 'yes') !== $change['null_allowed'] || ($table_row['Default'] === null) !== !isset($change['default']) || (isset($change['default']) && $change['default'] !== $table_row['Default']);
  2362. // Columns that previously allowed null, need to be converted first.
  2363. $null_fix = strtolower($table_row['Null']) === 'yes' && !$change['null_allowed'];
  2364. // Get the character set that goes with the collation of the column.
  2365. if ($column_fix && !empty($table_row['Collation']))
  2366. {
  2367. $request = $smcFunc['db_query']('', '
  2368. SHOW COLLATION
  2369. LIKE {string:collation}',
  2370. array(
  2371. 'collation' => $table_row['Collation'],
  2372. 'db_error_skip' => true,
  2373. )
  2374. );
  2375. // No results? Just forget it all together.
  2376. if ($smcFunc['db_num_rows']($request) === 0)
  2377. unset($table_row['Collation']);
  2378. else
  2379. $collation_info = $smcFunc['db_fetch_assoc']($request);
  2380. $smcFunc['db_free_result']($request);
  2381. }
  2382. }
  2383. if ($column_fix)
  2384. {
  2385. // Make sure there are no NULL's left.
  2386. if ($null_fix)
  2387. $smcFunc['db_query']('', '
  2388. UPDATE {db_prefix}' . $change['table'] . '
  2389. SET ' . $change['column'] . ' = {string:default}
  2390. WHERE ' . $change['column'] . ' IS NULL',
  2391. array(
  2392. 'default' => isset($change['default']) ? $change['default'] : '',
  2393. 'db_error_skip' => true,
  2394. )
  2395. );
  2396. // Do the actual alteration.
  2397. $smcFunc['db_query']('', '
  2398. ALTER TABLE {db_prefix}' . $change['table'] . '
  2399. CHANGE COLUMN ' . $change['column'] . ' ' . $change['column'] . ' ' . $change['type'] . (isset($collation_info['Charset']) ? ' CHARACTER SET ' . $collation_info['Charset'] . ' COLLATE ' . $collation_info['Collation'] : '') . ($change['null_allowed'] ? '' : ' NOT NULL') . (isset($change['default']) ? ' default {string:default}' : ''),
  2400. array(
  2401. 'default' => isset($change['default']) ? $change['default'] : '',
  2402. 'db_error_skip' => true,
  2403. )
  2404. );
  2405. }
  2406. nextSubstep($substep);
  2407. }
  2408. // Check if we need to alter this query.
  2409. function checkChange(&$change)
  2410. {
  2411. global $smcFunc, $db_type, $databases;
  2412. static $database_version, $where_field_support;
  2413. // Attempt to find a database_version.
  2414. if (empty($database_version))
  2415. {
  2416. $database_version = $databases[$db_type]['version_check'];
  2417. $where_field_support = $db_type == 'mysql' && version_compare('5.0', $database_version, '<=');
  2418. }
  2419. // Not a column we need to check on?
  2420. if (!in_array($change['name'], array('memberGroups', 'passwordSalt')))
  2421. return;
  2422. // Break it up you (six|seven).
  2423. $temp = explode(' ', str_replace('NOT NULL', 'NOT_NULL', $change['text']));
  2424. // Can we support a shortcut method?
  2425. if ($where_field_support)
  2426. {
  2427. // Get the details about this change.
  2428. $request = $smcFunc['db_query']('', '
  2429. SHOW FIELDS
  2430. FROM {db_prefix}{raw:table}
  2431. WHERE Field = {string:old_name} OR Field = {string:new_name}',
  2432. array(
  2433. 'table' => $change['table'],
  2434. 'old_name' => $temp[1],
  2435. 'new_name' => $temp[2],
  2436. ));
  2437. if ($smcFunc['db_num_rows'] != 1)
  2438. return;
  2439. list (, $current_type) = $smcFunc['db_fetch_assoc']($request);
  2440. $smcFunc['db_free_result']($request);
  2441. }
  2442. else
  2443. {
  2444. // Do this the old fashion, sure method way.
  2445. $request = $smcFunc['db_query']('', '
  2446. SHOW FIELDS
  2447. FROM {db_prefix}{raw:table}',
  2448. array(
  2449. 'table' => $change['table'],
  2450. ));
  2451. // Mayday!
  2452. if ($smcFunc['db_num_rows'] == 0)
  2453. return;
  2454. // Oh where, oh where has my little field gone. Oh where can it be...
  2455. while ($row = $smcFunc['db_query']($request))
  2456. if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
  2457. {
  2458. $current_type = $row['Type'];
  2459. break;
  2460. }
  2461. }
  2462. // If this doesn't match, the column may of been altered for a reason.
  2463. if (trim($current_type) != trim($temp[3]))
  2464. $temp[3] = $current_type;
  2465. // Piece this back together.
  2466. $change['text'] = str_replace('NOT_NULL', 'NOT NULL', implode(' ', $temp));
  2467. }
  2468. // The next substep.
  2469. function nextSubstep($substep)
  2470. {
  2471. global $start_time, $timeLimitThreshold, $command_line, $file_steps, $modSettings, $custom_warning;
  2472. global $step_progress, $is_debug, $upcontext;
  2473. if ($_GET['substep'] < $substep)
  2474. $_GET['substep'] = $substep;
  2475. if ($command_line)
  2476. {
  2477. if (time() - $start_time > 1 && empty($is_debug))
  2478. {
  2479. echo '.';
  2480. $start_time = time();
  2481. }
  2482. return;
  2483. }
  2484. @set_time_limit(300);
  2485. if (function_exists('apache_reset_timeout'))
  2486. @apache_reset_timeout();
  2487. if (time() - $start_time <= $timeLimitThreshold)
  2488. return;
  2489. // Do we have some custom step progress stuff?
  2490. if (!empty($step_progress))
  2491. {
  2492. $upcontext['substep_progress'] = 0;
  2493. $upcontext['substep_progress_name'] = $step_progress['name'];
  2494. if ($step_progress['current'] > $step_progress['total'])
  2495. $upcontext['substep_progress'] = 99.9;
  2496. else
  2497. $upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
  2498. // Make it nicely rounded.
  2499. $upcontext['substep_progress'] = round($upcontext['substep_progress'], 1);
  2500. }
  2501. // If this is XML we just exit right away!
  2502. if (isset($_GET['xml']))
  2503. return upgradeExit();
  2504. // We're going to pause after this!
  2505. $upcontext['pause'] = true;
  2506. $upcontext['query_string'] = '';
  2507. foreach ($_GET as $k => $v)
  2508. {
  2509. if ($k != 'data' && $k != 'substep' && $k != 'step')
  2510. $upcontext['query_string'] .= ';' . $k . '=' . $v;
  2511. }
  2512. // Custom warning?
  2513. if (!empty($custom_warning))
  2514. $upcontext['custom_warning'] = $custom_warning;
  2515. upgradeExit();
  2516. }
  2517. function cmdStep0()
  2518. {
  2519. global $boarddir, $sourcedir, $db_prefix, $language, $modSettings, $start_time, $cachedir, $databases, $db_type, $smcFunc, $upcontext;
  2520. global $language, $is_debug, $txt;
  2521. $start_time = time();
  2522. ob_end_clean();
  2523. ob_implicit_flush(true);
  2524. @set_time_limit(600);
  2525. if (!isset($_SERVER['argv']))
  2526. $_SERVER['argv'] = array();
  2527. $_GET['maint'] = 1;
  2528. foreach ($_SERVER['argv'] as $i => $arg)
  2529. {
  2530. if (preg_match('~^--language=(.+)$~', $arg, $match) != 0)
  2531. $_GET['lang'] = $match[1];
  2532. elseif (preg_match('~^--path=(.+)$~', $arg) != 0)
  2533. continue;
  2534. elseif ($arg == '--no-maintenance')
  2535. $_GET['maint'] = 0;
  2536. elseif ($arg == '--debug')
  2537. $is_debug = true;
  2538. elseif ($arg == '--backup')
  2539. $_POST['backup'] = 1;
  2540. elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($boarddir . '/Themes/converted')))
  2541. $_GET['conv'] = 1;
  2542. elseif ($i != 0)
  2543. {
  2544. echo 'SMF Command-line Upgrader
  2545. Usage: /path/to/php -f ' . basename(__FILE__) . ' -- [OPTION]...
  2546. --language=LANG Reset the forum\'s language to LANG.
  2547. --no-maintenance Don\'t put the forum into maintenance mode.
  2548. --debug Output debugging information.
  2549. --backup Create backups of tables with "backup_" prefix.';
  2550. echo "\n";
  2551. exit;
  2552. }
  2553. }
  2554. if (!php_version_check())
  2555. print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
  2556. if (!db_version_check())
  2557. print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
  2558. if (!empty($databases[$db_type]['alter_support']) && $smcFunc['db_query']('alter_boards', 'ALTER TABLE {db_prefix}boards ORDER BY id_board', array()) === false)
  2559. print_error('Error: The ' . $databases[$db_type]['name'] . ' account in Settings.php does not have sufficient privileges.', true);
  2560. $check = @file_exists($boarddir . '/Themes/default/index.template.php')
  2561. && @file_exists($sourcedir . '/QueryString.php')
  2562. && @file_exists($sourcedir . '/ManageBoards.php');
  2563. if (!$check && !isset($modSettings['smfVersion']))
  2564. print_error('Error: Some files are missing or out-of-date.', true);
  2565. // Do a quick version spot check.
  2566. $temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
  2567. preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
  2568. if (empty($match[1]) || $match[1] != SMF_VERSION)
  2569. print_error('Error: Some files have not yet been updated properly.');
  2570. // Make sure Settings.php is writable.
  2571. if (!is_writable($boarddir . '/Settings.php'))
  2572. @chmod($boarddir . '/Settings.php', 0777);
  2573. if (!is_writable($boarddir . '/Settings.php'))
  2574. print_error('Error: Unable to obtain write access to "Settings.php".', true);
  2575. // Make sure Settings.php is writable.
  2576. if (!is_writable($boarddir . '/Settings_bak.php'))
  2577. @chmod($boarddir . '/Settings_bak.php', 0777);
  2578. if (!is_writable($boarddir . '/Settings_bak.php'))
  2579. print_error('Error: Unable to obtain write access to "Settings_bak.php".');
  2580. if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
  2581. print_error('Error: Unable to obtain write access to "agreement.txt".');
  2582. elseif (isset($modSettings['agreement']))
  2583. {
  2584. $fp = fopen($boarddir . '/agreement.txt', 'w');
  2585. fwrite($fp, $modSettings['agreement']);
  2586. fclose($fp);
  2587. }
  2588. // Make sure Themes is writable.
  2589. if (!is_writable($boarddir . '/Themes'))
  2590. @chmod($boarddir . '/Themes', 0777);
  2591. if (!is_writable($boarddir . '/Themes') && !isset($modSettings['smfVersion']))
  2592. print_error('Error: Unable to obtain write access to "Themes".');
  2593. // Make sure cache directory exists and is writable!
  2594. $cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
  2595. if (!file_exists($cachedir_temp))
  2596. @mkdir($cachedir_temp);
  2597. if (!is_writable($cachedir_temp))
  2598. @chmod($cachedir_temp, 0777);
  2599. if (!is_writable($cachedir_temp))
  2600. print_error('Error: Unable to obtain write access to "cache".', true);
  2601. if (!file_exists($boarddir . '/Themes/default/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
  2602. print_error('Error: Unable to find language files!', true);
  2603. else
  2604. {
  2605. $temp = substr(@implode('', @file($boarddir . '/Themes/default/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
  2606. preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
  2607. if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
  2608. print_error('Error: Language files out of date.', true);
  2609. if (!file_exists($boarddir . '/Themes/default/languages/Install.' . $upcontext['language'] . '.php'))
  2610. print_error('Error: Install language is missing for selected language.', true);
  2611. // Otherwise include it!
  2612. require_once($boarddir . '/Themes/default/languages/Install.' . $upcontext['language'] . '.php');
  2613. }
  2614. // Make sure we skip the HTML for login.
  2615. $_POST['upcont'] = true;
  2616. $upcontext['current_step'] = 1;
  2617. }
  2618. function print_error($message, $fatal = false)
  2619. {
  2620. static $fp = null;
  2621. if ($fp === null)
  2622. $fp = fopen('php://stderr', 'wb');
  2623. fwrite($fp, $message . "\n");
  2624. if ($fatal)
  2625. exit;
  2626. }
  2627. function throw_error($message)
  2628. {
  2629. global $upcontext;
  2630. $upcontext['error_msg'] = $message;
  2631. $upcontext['sub_template'] = 'error_message';
  2632. return false;
  2633. }
  2634. // Check files are writable - make them writable if necessary...
  2635. function makeFilesWritable(&$files)
  2636. {
  2637. global $upcontext, $boarddir;
  2638. if (empty($files))
  2639. return true;
  2640. $failure = false;
  2641. // On linux, it's easy - just use is_writable!
  2642. if (substr(__FILE__, 1, 2) != ':\\')
  2643. {
  2644. foreach ($files as $k => $file)
  2645. {
  2646. if (!is_writable($file))
  2647. {
  2648. @chmod($file, 0755);
  2649. // Well, 755 hopefully worked... if not, try 777.
  2650. if (!is_writable($file) && !@chmod($file, 0777))
  2651. $failure = true;
  2652. // Otherwise remove it as it's good!
  2653. else
  2654. unset($files[$k]);
  2655. }
  2656. else
  2657. unset($files[$k]);
  2658. }
  2659. }
  2660. // Windows is trickier. Let's try opening for r+...
  2661. else
  2662. {
  2663. foreach ($files as $k => $file)
  2664. {
  2665. // Folders can't be opened for write... but the index.php in them can ;).
  2666. if (is_dir($file))
  2667. $file .= '/index.php';
  2668. // Funny enough, chmod actually does do something on windows - it removes the read only attribute.
  2669. @chmod($file, 0777);
  2670. $fp = @fopen($file, 'r+');
  2671. // Hmm, okay, try just for write in that case...
  2672. if (!$fp)
  2673. $fp = @fopen($file, 'w');
  2674. if (!$fp)
  2675. $failure = true;
  2676. else
  2677. unset($files[$k]);
  2678. @fclose($fp);
  2679. }
  2680. }
  2681. if (empty($files))
  2682. return true;
  2683. if (!isset($_SERVER))
  2684. return !$failure;
  2685. // What still needs to be done?
  2686. $upcontext['chmod']['files'] = $files;
  2687. // If it's windows it's a mess...
  2688. if ($failure && substr(__FILE__, 1, 2) == ':\\')
  2689. {
  2690. $upcontext['chmod']['ftp_error'] = 'total_mess';
  2691. return false;
  2692. }
  2693. // We're going to have to use... FTP!
  2694. elseif ($failure)
  2695. {
  2696. // Load any session data we might have...
  2697. if (!isset($_POST['ftp_username']) && isset($_SESSION['installer_temp_ftp']))
  2698. {
  2699. $upcontext['chmod']['server'] = $_SESSION['installer_temp_ftp']['server'];
  2700. $upcontext['chmod']['port'] = $_SESSION['installer_temp_ftp']['port'];
  2701. $upcontext['chmod']['username'] = $_SESSION['installer_temp_ftp']['username'];
  2702. $upcontext['chmod']['password'] = $_SESSION['installer_temp_ftp']['password'];
  2703. $upcontext['chmod']['path'] = $_SESSION['installer_temp_ftp']['path'];
  2704. }
  2705. // Or have we submitted?
  2706. elseif (isset($_POST['ftp_username']))
  2707. {
  2708. $upcontext['chmod']['server'] = $_POST['ftp_server'];
  2709. $upcontext['chmod']['port'] = $_POST['ftp_port'];
  2710. $upcontext['chmod']['username'] = $_POST['ftp_username'];
  2711. $upcontext['chmod']['password'] = $_POST['ftp_password'];
  2712. $upcontext['chmod']['path'] = $_POST['ftp_path'];
  2713. }
  2714. if (isset($upcontext['chmod']['username']))
  2715. {
  2716. $ftp = new ftp_connection($upcontext['chmod']['server'], $upcontext['chmod']['port'], $upcontext['chmod']['username'], $upcontext['chmod']['password']);
  2717. if ($ftp->error === false)
  2718. {
  2719. // Try it without /home/abc just in case they messed up.
  2720. if (!$ftp->chdir($upcontext['chmod']['path']))
  2721. {
  2722. $upcontext['chmod']['ftp_error'] = $ftp->last_message;
  2723. $ftp->chdir(preg_replace('~^/home[2]?/[^/]+?~', '', $upcontext['chmod']['path']));
  2724. }
  2725. }
  2726. }
  2727. if (!isset($ftp) || $ftp->error !== false)
  2728. {
  2729. if (!isset($ftp))
  2730. $ftp = new ftp_connection(null);
  2731. // Save the error so we can mess with listing...
  2732. elseif ($ftp->error !== false && !isset($upcontext['chmod']['ftp_error']))
  2733. $upcontext['chmod']['ftp_error'] = $ftp->last_message === null ? '' : $ftp->last_message;
  2734. list ($username, $detect_path, $found_path) = $ftp->detect_path(dirname(__FILE__));
  2735. if ($found_path || !isset($upcontext['chmod']['path']))
  2736. $upcontext['chmod']['path'] = $detect_path;
  2737. if (!isset($upcontext['chmod']['username']))
  2738. $upcontext['chmod']['username'] = $username;
  2739. return false;
  2740. }
  2741. else
  2742. {
  2743. // We want to do a relative path for FTP.
  2744. if (!in_array($upcontext['chmod']['path'], array('', '/')))
  2745. {
  2746. $ftp_root = strtr($boarddir, array($upcontext['chmod']['path'] => ''));
  2747. if (substr($ftp_root, -1) == '/' && ($upcontext['chmod']['path'] == '' || $upcontext['chmod']['path'][0] === '/'))
  2748. $ftp_root = substr($ftp_root, 0, -1);
  2749. }
  2750. else
  2751. $ftp_root = $boarddir;
  2752. // Save the info for next time!
  2753. $_SESSION['installer_temp_ftp'] = array(
  2754. 'server' => $upcontext['chmod']['server'],
  2755. 'port' => $upcontext['chmod']['port'],
  2756. 'username' => $upcontext['chmod']['username'],
  2757. 'password' => $upcontext['chmod']['password'],
  2758. 'path' => $upcontext['chmod']['path'],
  2759. 'root' => $ftp_root,
  2760. );
  2761. foreach ($files as $k => $file)
  2762. {
  2763. if (!is_writable($file))
  2764. $ftp->chmod($file, 0755);
  2765. if (!is_writable($file))
  2766. $ftp->chmod($file, 0777);
  2767. // Assuming that didn't work calculate the path without the boarddir.
  2768. if (!is_writable($file))
  2769. {
  2770. if (strpos($file, $boarddir) === 0)
  2771. {
  2772. $ftp_file = strtr($file, array($_SESSION['installer_temp_ftp']['root'] => ''));
  2773. $ftp->chmod($ftp_file, 0755);
  2774. if (!is_writable($file))
  2775. $ftp->chmod($ftp_file, 0777);
  2776. // Sometimes an extra slash can help...
  2777. $ftp_file = '/' . $ftp_file;
  2778. if (!is_writable($file))
  2779. $ftp->chmod($ftp_file, 0755);
  2780. if (!is_writable($file))
  2781. $ftp->chmod($ftp_file, 0777);
  2782. }
  2783. }
  2784. if (is_writable($file))
  2785. unset($files[$k]);
  2786. }
  2787. $ftp->close();
  2788. }
  2789. }
  2790. // What remains?
  2791. $upcontext['chmod']['files'] = $files;
  2792. if (empty($files))
  2793. return true;
  2794. return false;
  2795. }
  2796. /******************************************************************************
  2797. ******************* Templates are below this point ****************************
  2798. ******************************************************************************/
  2799. // This is what is displayed if there's any chmod to be done. If not it returns nothing...
  2800. function template_chmod()
  2801. {
  2802. global $upcontext, $upgradeurl, $settings;
  2803. // Don't call me twice!
  2804. if (!empty($upcontext['chmod_called']))
  2805. return;
  2806. $upcontext['chmod_called'] = true;
  2807. // Nothing?
  2808. if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error']))
  2809. return;
  2810. // @todo Temporary!
  2811. $txt['error_ftp_no_connect'] = 'Unable to connect to FTP server with this combination of details.';
  2812. $txt['ftp_login'] = 'Your FTP connection information';
  2813. $txt['ftp_login_info'] = 'This web installer needs your FTP information in order to automate the installation for you. Please note that none of this information is saved in your installation, it is just used to setup SMF.';
  2814. $txt['ftp_server'] = 'Server';
  2815. $txt['ftp_server_info'] = 'The address (often localhost) and port for your FTP server.';
  2816. $txt['ftp_port'] = 'Port';
  2817. $txt['ftp_username'] = 'Username';
  2818. $txt['ftp_username_info'] = 'The username to login with. <em>This will not be saved anywhere.</em>';
  2819. $txt['ftp_password'] = 'Password';
  2820. $txt['ftp_password_info'] = 'The password to login with. <em>This will not be saved anywhere.</em>';
  2821. $txt['ftp_path'] = 'Install Path';
  2822. $txt['ftp_path_info'] = 'This is the <em>relative</em> path you use in your FTP client <a href="' . $_SERVER['PHP_SELF'] . '?ftphelp" onclick="window.open(this.href, \'\', \'width=450,height=250\');return false;" target="_blank">(more help)</a>.';
  2823. $txt['ftp_path_found_info'] = 'The path in the box above was automatically detected.';
  2824. $txt['ftp_path_help'] = 'Your FTP path is the path you see when you log in to your FTP client. It commonly starts with &quot;<tt>www</tt>&quot;, &quot;<tt>public_html</tt>&quot;, or &quot;<tt>httpdocs</tt>&quot; - but it should include the directory SMF is in too, such as &quot;/public_html/forum&quot;. It is different from your URL and full path.<br /><br />Files in this path may be overwritten, so make sure it\'s correct.';
  2825. $txt['ftp_path_help_close'] = 'Close';
  2826. $txt['ftp_connect'] = 'Connect';
  2827. // Was it a problem with Windows?
  2828. if (!empty($upcontext['chmod']['ftp_error']) && $upcontext['chmod']['ftp_error'] == 'total_mess')
  2829. {
  2830. echo '
  2831. <div class="error_message">
  2832. <div style="color: red;">The following files need to be writable to continue the upgrade. Please ensure the Windows permissions are correctly set to allow this:</div>
  2833. <ul style="margin: 2.5ex; font-family: monospace;">
  2834. <li>' . implode('</li>
  2835. <li>', $upcontext['chmod']['files']). '</li>
  2836. </ul>
  2837. </div>';
  2838. return false;
  2839. }
  2840. echo '
  2841. <div class="panel">
  2842. <h2>Your FTP connection information</h2>
  2843. <h3>The upgrader can fix any issues with file permissions to make upgrading as simple as possible. Simply enter your connection information below or alternatively click <a href="#" onclick="warning_popup();">here</a> for a list of files which need to be changed.</h3>
  2844. <script type="text/javascript"><!-- // --><![CDATA[
  2845. function warning_popup()
  2846. {
  2847. popup = window.open(\'\',\'popup\',\'height=150,width=400,scrollbars=yes\');
  2848. var content = popup.document;
  2849. content.write(\'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n\');
  2850. content.write(\'<html xmlns="http://www.w3.org/1999/xhtml"', $upcontext['right_to_left'] ? ' dir="rtl"' : '', '>\n\t<head>\n\t\t<meta name="robots" content="noindex" />\n\t\t\');
  2851. content.write(\'<title>Warning</title>\n\t\t<link rel="stylesheet" type="text/css" href="', $settings['default_theme_url'], '/css/index.css" />\n\t</head>\n\t<body id="popup">\n\t\t\');
  2852. content.write(\'<div class="windowbg description">\n\t\t\t<h4>The following files needs to be made writable to continue:</h4>\n\t\t\t\');
  2853. content.write(\'<p>', implode('<br />\n\t\t\t', $upcontext['chmod']['files']), '</p>\n\t\t\t\');
  2854. content.write(\'<a href="javascript:self.close();">close</a>\n\t\t</div>\n\t</body>\n</html>\');
  2855. content.close();
  2856. }
  2857. // ]]></script>';
  2858. if (!empty($upcontext['chmod']['ftp_error']))
  2859. echo '
  2860. <div class="error_message">
  2861. <div style="color: red;">
  2862. The following error was encountered when trying to connect:<br />
  2863. <br />
  2864. <code>', $upcontext['chmod']['ftp_error'], '</code>
  2865. </div>
  2866. </div>
  2867. <br />';
  2868. if (empty($upcontext['chmod_in_form']))
  2869. echo '
  2870. <form action="', $upcontext['form_url'], '" method="post">';
  2871. echo '
  2872. <table width="520" cellspacing="0" cellpadding="0" border="0" align="center" style="margin-bottom: 1ex;">
  2873. <tr>
  2874. <td width="26%" valign="top" class="textbox"><label for="ftp_server">', $txt['ftp_server'], ':</label></td>
  2875. <td>
  2876. <div style="float: right; margin-right: 1px;"><label for="ftp_port" class="textbox"><strong>', $txt['ftp_port'], ':&nbsp;</strong></label> <input type="text" size="3" name="ftp_port" id="ftp_port" value="', isset($upcontext['chmod']['port']) ? $upcontext['chmod']['port'] : '21', '" class="input_text" /></div>
  2877. <input type="text" size="30" name="ftp_server" id="ftp_server" value="', isset($upcontext['chmod']['server']) ? $upcontext['chmod']['server'] : 'localhost', '" style="width: 70%;" class="input_text" />
  2878. <div style="font-size: smaller; margin-bottom: 2ex;">', $txt['ftp_server_info'], '</div>
  2879. </td>
  2880. </tr><tr>
  2881. <td width="26%" valign="top" class="textbox"><label for="ftp_username">', $txt['ftp_username'], ':</label></td>
  2882. <td>
  2883. <input type="text" size="50" name="ftp_username" id="ftp_username" value="', isset($upcontext['chmod']['username']) ? $upcontext['chmod']['username'] : '', '" style="width: 99%;" class="input_text" />
  2884. <div style="font-size: smaller; margin-bottom: 2ex;">', $txt['ftp_username_info'], '</div>
  2885. </td>
  2886. </tr><tr>
  2887. <td width="26%" valign="top" class="textbox"><label for="ftp_password">', $txt['ftp_password'], ':</label></td>
  2888. <td>
  2889. <input type="password" size="50" name="ftp_password" id="ftp_password" style="width: 99%;" class="input_password" />
  2890. <div style="font-size: smaller; margin-bottom: 3ex;">', $txt['ftp_password_info'], '</div>
  2891. </td>
  2892. </tr><tr>
  2893. <td width="26%" valign="top" class="textbox"><label for="ftp_path">', $txt['ftp_path'], ':</label></td>
  2894. <td style="padding-bottom: 1ex;">
  2895. <input type="text" size="50" name="ftp_path" id="ftp_path" value="', isset($upcontext['chmod']['path']) ? $upcontext['chmod']['path'] : '', '" style="width: 99%;" class="input_text" />
  2896. <div style="font-size: smaller; margin-bottom: 2ex;">', !empty($upcontext['chmod']['path']) ? $txt['ftp_path_found_info'] : $txt['ftp_path_info'], '</div>
  2897. </td>
  2898. </tr>
  2899. </table>
  2900. <div class="righttext" style="margin: 1ex;"><input type="submit" value="', $txt['ftp_connect'], '" class="button_submit" /></div>
  2901. </div>';
  2902. if (empty($upcontext['chmod_in_form']))
  2903. echo '
  2904. </form>';
  2905. }
  2906. function template_upgrade_above()
  2907. {
  2908. global $modSettings, $txt, $smfsite, $settings, $upcontext, $upgradeurl;
  2909. echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2910. <html xmlns="http://www.w3.org/1999/xhtml"', $upcontext['right_to_left'] ? ' dir="rtl"' : '', '>
  2911. <head>
  2912. <meta http-equiv="Content-Type" content="text/html; charset=', isset($txt['lang_character_set']) ? $txt['lang_character_set'] : 'ISO-8859-1', '" />
  2913. <meta name="robots" content="noindex" />
  2914. <title>', $txt['upgrade_upgrade_utility'], '</title>
  2915. <link rel="stylesheet" type="text/css" href="', $settings['default_theme_url'], '/css/index.css?fin20" />
  2916. <link rel="stylesheet" type="text/css" href="', $settings['default_theme_url'], '/css/install.css?fin20" />
  2917. <script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/script.js"></script>
  2918. <script type="text/javascript"><!-- // --><![CDATA[
  2919. var smf_scripturl = \'', $upgradeurl, '\';
  2920. var smf_charset = \'', (empty($modSettings['global_character_set']) ? (empty($txt['lang_character_set']) ? 'ISO-8859-1' : $txt['lang_character_set']) : $modSettings['global_character_set']), '\';
  2921. var startPercent = ', $upcontext['overall_percent'], ';
  2922. // This function dynamically updates the step progress bar - and overall one as required.
  2923. function updateStepProgress(current, max, overall_weight)
  2924. {
  2925. // What out the actual percent.
  2926. var width = parseInt((current / max) * 100);
  2927. if (document.getElementById(\'step_progress\'))
  2928. {
  2929. document.getElementById(\'step_progress\').style.width = width + "%";
  2930. setInnerHTML(document.getElementById(\'step_text\'), width + "%");
  2931. }
  2932. if (overall_weight && document.getElementById(\'overall_progress\'))
  2933. {
  2934. overall_width = parseInt(startPercent + width * (overall_weight / 100));
  2935. document.getElementById(\'overall_progress\').style.width = overall_width + "%";
  2936. setInnerHTML(document.getElementById(\'overall_text\'), overall_width + "%");
  2937. }
  2938. }
  2939. // ]]></script>
  2940. </head>
  2941. <body>
  2942. <div id="header"><div class="frame">
  2943. <div id="top_section">
  2944. <h1 class="forumtitle">', $txt['upgrade_upgrade_utility'], '</h1>
  2945. <img id="smflogo" src="Themes/default/images/smflogo.png" alt="Simple Machines Forum" title="Simple Machines Forum" />
  2946. </div>
  2947. <div id="upper_section" class="middletext flow_hidden">
  2948. <div class="user"></div>
  2949. <div class="news normaltext">
  2950. </div>
  2951. </div>
  2952. </div></div>
  2953. <div id="content_section"><div class="frame">
  2954. <div id="main_content_section">
  2955. <div id="main-steps">
  2956. <h2>', $txt['upgrade_progress'], '</h2>
  2957. <ul>';
  2958. foreach ($upcontext['steps'] as $num => $step)
  2959. echo '
  2960. <li class="', $num < $upcontext['current_step'] ? 'stepdone' : ($num == $upcontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>';
  2961. echo '
  2962. </ul>
  2963. </div>
  2964. <div style="float: left; width: 40%;">
  2965. <div style="font-size: 8pt; height: 12pt; border: 1px solid black; background-color: white; width: 50%; margin: auto;">
  2966. <div id="overall_text" style="color: #000; position: absolute; margin-left: -5em;">', $upcontext['overall_percent'], '%</div>
  2967. <div id="overall_progress" style="width: ', $upcontext['overall_percent'], '%; height: 12pt; z-index: 1; background-color: lime;">&nbsp;</div>
  2968. <div class="progress">', $txt['upgrade_overall_progress'], '</div>
  2969. </div>
  2970. ';
  2971. if (isset($upcontext['step_progress']))
  2972. echo '
  2973. <div style="font-size: 8pt; height: 12pt; border: 1px solid black; background-color: white; width: 50%; margin: 5px auto; ">
  2974. <div id="step_text" style="color: #000; position: absolute; margin-left: -5em;">', $upcontext['step_progress'], '%</div>
  2975. <div id="step_progress" style="width: ', $upcontext['step_progress'], '%; height: 12pt; z-index: 1; background-color: #ffd000;">&nbsp;</div>
  2976. <div class="progress">', $txt['upgrade_step_progress'], '</div>
  2977. </div>
  2978. ';
  2979. echo '
  2980. <div id="substep_bar_div" class="smalltext" style="display: ', isset($upcontext['substep_progress']) ? '' : 'none', ';">', isset($upcontext['substep_progress_name']) ? trim(strtr($upcontext['substep_progress_name'], array('.' => ''))) : '', ':</div>
  2981. <div id="substep_bar_div2" style="font-size: 8pt; height: 12pt; border: 1px solid black; background-color: white; width: 50%; margin: 5px auto; display: ', isset($upcontext['substep_progress']) ? '' : 'none', ';">
  2982. <div id="substep_text" style="color: #000; position: absolute; margin-left: -5em;">', isset($upcontext['substep_progress']) ? $upcontext['substep_progress'] : '', '%</div>
  2983. <div id="substep_progress" style="width: ', isset($upcontext['substep_progress']) ? $upcontext['substep_progress'] : 0, '%; height: 12pt; z-index: 1; background-color: #eebaf4;">&nbsp;</div>
  2984. </div>';
  2985. // How long have we been running this?
  2986. $elapsed = time() - $upcontext['started'];
  2987. $mins = (int) ($elapsed / 60);
  2988. $seconds = $elapsed - $mins * 60;
  2989. echo '
  2990. <div class="smalltext" style="padding: 5px; text-align: center;">', $txt['upgrade_time_elapsed'], ':
  2991. <span id="mins_elapsed">', $mins, '</span> ', $txt['upgrade_time_mins'], ', <span id="secs_elapsed">', $seconds, '</span> ', $txt['upgrade_time_secs'], '.
  2992. </div>';
  2993. echo '
  2994. </div>
  2995. <div id="main_screen" class="clear">
  2996. <h2>', $upcontext['page_title'], '</h2>
  2997. <div class="panel">
  2998. <div style="max-height: 360px; overflow: auto;">';
  2999. }
  3000. function template_upgrade_below()
  3001. {
  3002. global $upcontext, $txt;
  3003. if (!empty($upcontext['pause']))
  3004. echo '
  3005. <em>', $txt['upgrade_incomplete'], '.</em><br />
  3006. <h2 style="margin-top: 2ex;">', $txt['upgrade_not_quite_done'], '</h2>
  3007. <h3>
  3008. ', $txt['upgrade_paused_overload'], '
  3009. </h3>';
  3010. if (!empty($upcontext['custom_warning']))
  3011. echo '
  3012. <div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
  3013. <div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
  3014. <strong style="text-decoration: underline;">', $txt['upgrade_note'], '</strong><br />
  3015. <div style="padding-left: 6ex;">', $upcontext['custom_warning'], '</div>
  3016. </div>';
  3017. echo '
  3018. <div class="righttext" style="margin: 1ex;">';
  3019. if (!empty($upcontext['continue']))
  3020. echo '
  3021. <input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '"', $upcontext['continue'] == 2 ? ' disabled="disabled"' : '', ' class="button_submit" />';
  3022. if (!empty($upcontext['skip']))
  3023. echo '
  3024. <input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="dontSubmit = true; document.getElementById(\'contbutt\').disabled = \'disabled\'; return true;" class="button_submit" />';
  3025. echo '
  3026. </div>
  3027. </form>
  3028. </div>
  3029. </div>
  3030. </div>
  3031. </div>
  3032. </div></div>
  3033. <div id="footer_section"><div class="frame" style="height: 40px;">
  3034. <div class="smalltext"><a href="http://www.simplemachines.org/" title="Simple Machines Forum" target="_blank" class="new_win">SMF &copy;2011, Simple Machines</a></div>
  3035. </div></div>
  3036. </body>
  3037. </html>';
  3038. // Are we on a pause?
  3039. if (!empty($upcontext['pause']))
  3040. {
  3041. echo '
  3042. <script type="text/javascript"><!-- // --><![CDATA[
  3043. window.onload = doAutoSubmit;
  3044. var countdown = 3;
  3045. var dontSubmit = false;
  3046. function doAutoSubmit()
  3047. {
  3048. if (countdown == 0 && !dontSubmit)
  3049. document.upform.submit();
  3050. else if (countdown == -1)
  3051. return;
  3052. document.getElementById(\'contbutt\').value = "', $txt['upgrade_continue'], ' (" + countdown + ")";
  3053. countdown--;
  3054. setTimeout("doAutoSubmit();", 1000);
  3055. }
  3056. // ]]></script>';
  3057. }
  3058. }
  3059. function template_xml_above()
  3060. {
  3061. global $upcontext;
  3062. echo '<', '?xml version="1.0" encoding="ISO-8859-1"?', '>
  3063. <smf>';
  3064. if (!empty($upcontext['get_data']))
  3065. foreach ($upcontext['get_data'] as $k => $v)
  3066. echo '
  3067. <get key="', $k, '">', $v, '</get>';
  3068. }
  3069. function template_xml_below()
  3070. {
  3071. global $upcontext;
  3072. echo '
  3073. </smf>';
  3074. }
  3075. function template_error_message()
  3076. {
  3077. global $upcontext;
  3078. echo '
  3079. <div class="error_message">
  3080. <div style="color: red;">
  3081. ', $upcontext['error_msg'], '
  3082. </div>
  3083. <br />
  3084. <a href="', $_SERVER['PHP_SELF'], '">Click here to try again.</a>
  3085. </div>';
  3086. }
  3087. function template_welcome_message()
  3088. {
  3089. global $upcontext, $modSettings, $upgradeurl, $disable_security, $settings, $txt;
  3090. echo '
  3091. <script type="text/javascript" src="http://www.simplemachines.org/smf/current-version.js?version=' . SMF_VERSION . '"></script>
  3092. <script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/sha1.js"></script>
  3093. <h3>', sprintf($txt['upgrade_ready_proceed'], SMF_VERSION), '</h3>
  3094. <form action="', $upcontext['form_url'], '" method="post" name="upform" id="upform" ', empty($upcontext['disable_login_hashing']) ? ' onsubmit="hashLoginPassword(this, \'' . $upcontext['rid'] . '\');"' : '', '>
  3095. <div id="version_warning" style="margin: 2ex; padding: 2ex; border: 2px dashed #a92174; color: black; background-color: #fbbbe2; display: none;">
  3096. <div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
  3097. <strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br />
  3098. <div style="padding-left: 6ex;">
  3099. ', sprintf($txt['upgrade_warning_out_of_date'], SMF_VERSION), '
  3100. </div>
  3101. </div>';
  3102. $upcontext['chmod_in_form'] = true;
  3103. template_chmod();
  3104. // For large, pre 1.1 RC2 forums give them a warning about the possible impact of this upgrade!
  3105. if ($upcontext['is_large_forum'])
  3106. echo '
  3107. <div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
  3108. <div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
  3109. <strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br />
  3110. <div style="padding-left: 6ex;">
  3111. ', $txt['upgrade_warning_lots_data'], '
  3112. </div>
  3113. </div>';
  3114. // A warning message?
  3115. if (!empty($upcontext['warning']))
  3116. echo '
  3117. <div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
  3118. <div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
  3119. <strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br />
  3120. <div style="padding-left: 6ex;">
  3121. ', $upcontext['warning'], '
  3122. </div>
  3123. </div>';
  3124. // Paths are incorrect?
  3125. echo '
  3126. <div style="margin: 2ex; padding: 2ex; border: 2px dashed #804840; color: black; background-color: #fe5a44; ', (file_exists($settings['default_theme_dir'] . '/scripts/script.js') ? 'display: none;' : ''), '" id="js_script_missing_error">
  3127. <div style="float: left; width: 2ex; font-size: 2em; color: black;">!!</div>
  3128. <strong style="text-decoration: underline;">', $txt['upgrade_critical_error'], '</strong><br />
  3129. <div style="padding-left: 6ex;">
  3130. ', $txt['upgrade_error_script_js'], '
  3131. </div>
  3132. </div>';
  3133. // Is there someone already doing this?
  3134. if (!empty($upcontext['user']['id']) && (time() - $upcontext['started'] < 72600 || time() - $upcontext['updated'] < 3600))
  3135. {
  3136. $ago = time() - $upcontext['started'];
  3137. if ($ago < 60)
  3138. $ago = $ago . ' seconds';
  3139. elseif ($ago < 3600)
  3140. $ago = (int) ($ago / 60) . ' minutes';
  3141. else
  3142. $ago = (int) ($ago / 3600) . ' hours';
  3143. $active = time() - $upcontext['updated'];
  3144. if ($active < 60)
  3145. $updated = $active . ' seconds';
  3146. elseif ($active < 3600)
  3147. $updated = (int) ($active / 60) . ' minutes';
  3148. else
  3149. $updated = (int) ($active / 3600) . ' hours';
  3150. echo '
  3151. <div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
  3152. <div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
  3153. <strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br />
  3154. <div style="padding-left: 6ex;">
  3155. &quot;', $upcontext['user']['name'], '&quot; has been running the upgrade script for the last ', $ago, ' - and was last active ', $updated, ' ago.';
  3156. if ($active < 600)
  3157. echo '
  3158. We recommend that you do not run this script unless you are sure that ', $upcontext['user']['name'], ' has completed their upgrade.';
  3159. if ($active > $upcontext['inactive_timeout'])
  3160. echo '
  3161. <br /><br />You can choose to either run the upgrade again from the beginning - or alternatively continue from the last step reached during the last upgrade.';
  3162. else
  3163. echo '
  3164. <br /><br />This upgrade script cannot be run until ', $upcontext['user']['name'], ' has been inactive for at least ', ($upcontext['inactive_timeout'] > 120 ? round($upcontext['inactive_timeout'] / 60, 1) . ' minutes!' : $upcontext['inactive_timeout'] . ' seconds!');
  3165. echo '
  3166. </div>
  3167. </div>';
  3168. }
  3169. echo '
  3170. <strong>Admin Login: ', $disable_security ? '(DISABLED)' : '', '</strong>
  3171. <h3>For security purposes please login with your admin account to proceed with the upgrade.</h3>
  3172. <table>
  3173. <tr valign="top">
  3174. <td><strong ', $disable_security ? 'style="color: gray;"' : '', '>Username:</strong></td>
  3175. <td>
  3176. <input type="text" name="user" value="', !empty($upcontext['username']) ? $upcontext['username'] : '', '" ', $disable_security ? 'disabled="disabled"' : '', ' class="input_text" />';
  3177. if (!empty($upcontext['username_incorrect']))
  3178. echo '
  3179. <div class="smalltext" style="color: red;">Username Incorrect</div>';
  3180. echo '
  3181. </td>
  3182. </tr>
  3183. <tr valign="top">
  3184. <td><strong ', $disable_security ? 'style="color: gray;"' : '', '>Password:</strong></td>
  3185. <td>
  3186. <input type="password" name="passwrd" value=""', $disable_security ? ' disabled="disabled"' : '', ' class="input_password" />
  3187. <input type="hidden" name="hash_passwrd" value="" />';
  3188. if (!empty($upcontext['password_failed']))
  3189. echo '
  3190. <div class="smalltext" style="color: red;">Password Incorrect</div>';
  3191. echo '
  3192. </td>
  3193. </tr>';
  3194. // Can they continue?
  3195. if (!empty($upcontext['user']['id']) && time() - $upcontext['user']['updated'] >= $upcontext['inactive_timeout'] && $upcontext['user']['step'] > 1)
  3196. {
  3197. echo '
  3198. <tr>
  3199. <td colspan="2">
  3200. <label for="cont"><input type="checkbox" id="cont" name="cont" checked="checked" class="input_check" />Continue from step reached during last execution of upgrade script.</label>
  3201. </td>
  3202. </tr>';
  3203. }
  3204. echo '
  3205. </table><br />
  3206. <span class="smalltext">
  3207. <strong>Note:</strong> If necessary the above security check can be bypassed for users who may administrate a server but not have admin rights on the forum. In order to bypass the above check simply open &quot;upgrade.php&quot; in a text editor and replace &quot;$disable_security = 0;&quot; with &quot;$disable_security = 1;&quot; and refresh this page.
  3208. </span>
  3209. <input type="hidden" name="login_attempt" id="login_attempt" value="1" />
  3210. <input type="hidden" name="js_works" id="js_works" value="0" />';
  3211. // Say we want the continue button!
  3212. $upcontext['continue'] = !empty($upcontext['user']['id']) && time() - $upcontext['user']['updated'] < $upcontext['inactive_timeout'] ? 2 : 1;
  3213. // This defines whether javascript is going to work elsewhere :D
  3214. echo '
  3215. <script type="text/javascript"><!-- // --><![CDATA[
  3216. if (\'XMLHttpRequest\' in window && document.getElementById(\'js_works\'))
  3217. document.getElementById(\'js_works\').value = 1;
  3218. // Latest version?
  3219. function smfCurrentVersion()
  3220. {
  3221. var smfVer, yourVer;
  3222. if (!(\'smfVersion\' in window))
  3223. return;
  3224. window.smfVersion = window.smfVersion.replace(/SMF\s?/g, \'\');
  3225. smfVer = document.getElementById(\'smfVersion\');
  3226. yourVer = document.getElementById(\'yourVersion\');
  3227. setInnerHTML(smfVer, window.smfVersion);
  3228. var currentVersion = getInnerHTML(yourVer);
  3229. if (currentVersion < window.smfVersion)
  3230. document.getElementById(\'version_warning\').style.display = \'\';
  3231. }
  3232. addLoadEvent(smfCurrentVersion);
  3233. // This checks that the script file even exists!
  3234. if (typeof(smfSelectText) == \'undefined\')
  3235. document.getElementById(\'js_script_missing_error\').style.display = \'\';
  3236. // ]]></script>';
  3237. }
  3238. function template_upgrade_options()
  3239. {
  3240. global $upcontext, $modSettings, $upgradeurl, $disable_security, $settings, $boarddir, $db_prefix, $mmessage, $mtitle, $db_type;
  3241. echo '
  3242. <h3>Before the upgrade gets underway please review the options below - and hit continue when you\'re ready to begin.</h3>
  3243. <form action="', $upcontext['form_url'], '" method="post" name="upform" id="upform">';
  3244. // Warning message?
  3245. if (!empty($upcontext['upgrade_options_warning']))
  3246. echo '
  3247. <div style="margin: 1ex; padding: 1ex; border: 1px dashed #cc3344; color: black; background-color: #ffe4e9;">
  3248. <div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
  3249. <strong style="text-decoration: underline;">Warning!</strong><br />
  3250. <div style="padding-left: 4ex;">
  3251. ', $upcontext['upgrade_options_warning'], '
  3252. </div>
  3253. </div>';
  3254. echo '
  3255. <table cellpadding="1" cellspacing="0">
  3256. <tr valign="top">
  3257. <td width="2%">
  3258. <input type="checkbox" name="backup" id="backup" value="1"', $db_type != 'mysql' && $db_type != 'postgresql' ? ' disabled="disabled"' : '', ' class="input_check" />
  3259. </td>
  3260. <td width="100%">
  3261. <label for="backup">Backup tables in your database with the prefix &quot;backup_' . $db_prefix . '&quot;.</label>', isset($modSettings['smfVersion']) ? '' : ' (recommended!)', '
  3262. </td>
  3263. </tr>
  3264. <tr valign="top">
  3265. <td width="2%">
  3266. <input type="checkbox" name="maint" id="maint" value="1" checked="checked" class="input_check" />
  3267. </td>
  3268. <td width="100%">
  3269. <label for="maint">Put the forum into maintenance mode during upgrade.</label> <span class="smalltext">(<a href="#" onclick="document.getElementById(\'mainmess\').style.display = document.getElementById(\'mainmess\').style.display == \'\' ? \'none\' : \'\'">Customize</a>)</span>
  3270. <div id="mainmess" style="display: none;">
  3271. <strong class="smalltext">Maintenance Title: </strong><br />
  3272. <input type="text" name="maintitle" size="30" value="', htmlspecialchars($mtitle), '" class="input_text" /><br />
  3273. <strong class="smalltext">Maintenance Message: </strong><br />
  3274. <textarea name="mainmessage" rows="3" cols="50">', htmlspecialchars($mmessage), '</textarea>
  3275. </div>
  3276. </td>
  3277. </tr>
  3278. <tr valign="top">
  3279. <td width="2%">
  3280. <input type="checkbox" name="debug" id="debug" value="1" class="input_check" />
  3281. </td>
  3282. <td width="100%">
  3283. <label for="debug">Output extra debugging information</label>
  3284. </td>
  3285. </tr>
  3286. <tr valign="top">
  3287. <td width="2%">
  3288. <input type="checkbox" name="empty_error" id="empty_error" value="1" class="input_check" />
  3289. </td>
  3290. <td width="100%">
  3291. <label for="empty_error">Empty error log before upgrading</label>
  3292. </td>
  3293. </tr>
  3294. <tr valign="top">
  3295. <td width="2%">
  3296. <input type="checkbox" name="stats" id="stats" value="1"', empty($modSettings['allow_sm_stats']) ? '' : ' checked="checked"', ' class="input_check" />
  3297. </td>
  3298. <td width="100%">
  3299. <label for="stats">
  3300. Allow Simple Machines to Collect Basic Stats Monthly.<br />
  3301. <span class="smalltext">If enabled, this will allow Simple Machines to visit your site once a month to collect basic statistics. This will help us make decisions as to which configurations to optimise the software for. For more information please visit our <a href="http://www.simplemachines.org/about/stats.php" target="_blank">info page</a>.</span>
  3302. </label>
  3303. </td>
  3304. </tr>
  3305. </table>
  3306. <input type="hidden" name="upcont" value="1" />';
  3307. // We need a normal continue button here!
  3308. $upcontext['continue'] = 1;
  3309. }
  3310. // Template for the database backup tool/
  3311. function template_backup_database()
  3312. {
  3313. global $upcontext, $modSettings, $upgradeurl, $disable_security, $settings, $support_js, $is_debug;
  3314. echo '
  3315. <h3>Please wait while a backup is created. For large forums this may take some time!</h3>';
  3316. echo '
  3317. <form action="', $upcontext['form_url'], '" name="upform" id="upform" method="post">
  3318. <input type="hidden" name="backup_done" id="backup_done" value="0" />
  3319. <strong>Completed <span id="tab_done">', $upcontext['cur_table_num'], '</span> out of ', $upcontext['table_count'], ' tables.</strong>
  3320. <span id="debuginfo"></span>';
  3321. // Dont any tables so far?
  3322. if (!empty($upcontext['previous_tables']))
  3323. foreach ($upcontext['previous_tables'] as $table)
  3324. echo '
  3325. <br />Completed Table: &quot;', $table, '&quot;.';
  3326. echo '
  3327. <h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>
  3328. <br /><span id="commess" style="font-weight: bold; display: ', $upcontext['cur_table_num'] == $upcontext['table_count'] ? 'inline' : 'none', ';">Backup Complete! Click Continue to Proceed.</span>';
  3329. // Continue please!
  3330. $upcontext['continue'] = $support_js ? 2 : 1;
  3331. // If javascript allows we want to do this using XML.
  3332. if ($support_js)
  3333. {
  3334. echo '
  3335. <script type="text/javascript"><!-- // --><![CDATA[
  3336. var lastTable = ', $upcontext['cur_table_num'], ';
  3337. function getNextTables()
  3338. {
  3339. getXMLDocument(\'', $upcontext['form_url'], '&xml&substep=\' + lastTable, onBackupUpdate);
  3340. }
  3341. // Got an update!
  3342. function onBackupUpdate(oXMLDoc)
  3343. {
  3344. var sCurrentTableName = "";
  3345. var iTableNum = 0;
  3346. var sCompletedTableName = getInnerHTML(document.getElementById(\'current_table\'));
  3347. for (var i = 0; i < oXMLDoc.getElementsByTagName("table")[0].childNodes.length; i++)
  3348. sCurrentTableName += oXMLDoc.getElementsByTagName("table")[0].childNodes[i].nodeValue;
  3349. iTableNum = oXMLDoc.getElementsByTagName("table")[0].getAttribute("num");
  3350. // Update the page.
  3351. setInnerHTML(document.getElementById(\'tab_done\'), iTableNum);
  3352. setInnerHTML(document.getElementById(\'current_table\'), sCurrentTableName);
  3353. lastTable = iTableNum;
  3354. updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
  3355. // If debug flood the screen.
  3356. if ($is_debug)
  3357. echo '
  3358. setOuterHTML(document.getElementById(\'debuginfo\'), \'<br />Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');';
  3359. echo '
  3360. // Get the next update...
  3361. if (iTableNum == ', $upcontext['table_count'], ')
  3362. {
  3363. document.getElementById(\'commess\').style.display = "";
  3364. document.getElementById(\'current_tab_div\').style.display = "none";
  3365. document.getElementById(\'contbutt\').disabled = 0;
  3366. document.getElementById(\'backup_done\').value = 1;
  3367. }
  3368. else
  3369. getNextTables();
  3370. }
  3371. getNextTables();
  3372. // ]]></script>';
  3373. }
  3374. }
  3375. function template_backup_xml()
  3376. {
  3377. global $upcontext, $settings, $options, $txt;
  3378. echo '
  3379. <table num="', $upcontext['cur_table_num'], '">', $upcontext['cur_table_name'], '</table>';
  3380. }
  3381. // Here is the actual "make the changes" template!
  3382. function template_database_changes()
  3383. {
  3384. global $upcontext, $modSettings, $upgradeurl, $disable_security, $settings, $support_js, $is_debug, $timeLimitThreshold;
  3385. echo '
  3386. <h3>Executing database changes</h3>
  3387. <h4 style="font-style: italic;">Please be patient - this may take some time on large forums. The time elapsed increments from the server to show progress is being made!</h4>';
  3388. echo '
  3389. <form action="', $upcontext['form_url'], '&amp;filecount=', $upcontext['file_count'], '" name="upform" id="upform" method="post">
  3390. <input type="hidden" name="database_done" id="database_done" value="0" />';
  3391. // No javascript looks rubbish!
  3392. if (!$support_js)
  3393. {
  3394. foreach ($upcontext['actioned_items'] as $num => $item)
  3395. {
  3396. if ($num != 0)
  3397. echo ' Successful!';
  3398. echo '<br />' . $item;
  3399. }
  3400. if (!empty($upcontext['changes_complete']))
  3401. echo ' Successful!<br /><br /><span id="commess" style="font-weight: bold;">Database Updates Complete! Click Continue to Proceed.</span><br />';
  3402. }
  3403. else
  3404. {
  3405. // Tell them how many files we have in total.
  3406. if ($upcontext['file_count'] > 1)
  3407. echo '
  3408. <strong id="info1">Executing upgrade script <span id="file_done">', $upcontext['cur_file_num'], '</span> of ', $upcontext['file_count'], '.</strong>';
  3409. echo '
  3410. <h3 id="info2"><strong>Executing:</strong> &quot;<span id="cur_item_name">', $upcontext['current_item_name'], '</span>&quot; (<span id="item_num">', $upcontext['current_item_num'], '</span> of <span id="total_items"><span id="item_count">', $upcontext['total_items'], '</span>', $upcontext['file_count'] > 1 ? ' - of this script' : '', ')</span></h3>
  3411. <br /><span id="commess" style="font-weight: bold; display: ', !empty($upcontext['changes_complete']) || $upcontext['current_debug_item_num'] == $upcontext['debug_items'] ? 'inline' : 'none', ';">Database Updates Complete! Click Continue to Proceed.</span>';
  3412. if ($is_debug)
  3413. {
  3414. echo '
  3415. <div id="debug_section" style="height: 200px; overflow: auto;">
  3416. <span id="debuginfo"></span>
  3417. </div>';
  3418. }
  3419. }
  3420. // Place for the XML error message.
  3421. echo '
  3422. <div id="error_block" style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9; display: ', empty($upcontext['error_message']) ? 'none' : '', ';">
  3423. <div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
  3424. <strong style="text-decoration: underline;">Error!</strong><br />
  3425. <div style="padding-left: 6ex;" id="error_message">', isset($upcontext['error_message']) ? $upcontext['error_message'] : 'Unknown Error!', '</div>
  3426. </div>';
  3427. // We want to continue at some point!
  3428. $upcontext['continue'] = $support_js ? 2 : 1;
  3429. // If javascript allows we want to do this using XML.
  3430. if ($support_js)
  3431. {
  3432. echo '
  3433. <script type="text/javascript"><!-- // --><![CDATA[
  3434. var lastItem = ', $upcontext['current_debug_item_num'], ';
  3435. var sLastString = "', strtr($upcontext['current_debug_item_name'], array('"' => '&quot;')), '";
  3436. var iLastSubStepProgress = -1;
  3437. var curFile = ', $upcontext['cur_file_num'], ';
  3438. var totalItems = 0;
  3439. var prevFile = 0;
  3440. var retryCount = 0;
  3441. var testvar = 0;
  3442. var timeOutID = 0;
  3443. var getData = "";
  3444. var debugItems = ', $upcontext['debug_items'], ';
  3445. function getNextItem()
  3446. {
  3447. // We want to track this...
  3448. if (timeOutID)
  3449. clearTimeout(timeOutID);
  3450. timeOutID = window.setTimeout("retTimeout()", ', (10 * $timeLimitThreshold), '000);
  3451. getXMLDocument(\'', $upcontext['form_url'], '&xml&filecount=', $upcontext['file_count'], '&substep=\' + lastItem + getData, onItemUpdate);
  3452. }
  3453. // Got an update!
  3454. function onItemUpdate(oXMLDoc)
  3455. {
  3456. var sItemName = "";
  3457. var sDebugName = "";
  3458. var iItemNum = 0;
  3459. var iSubStepProgress = -1;
  3460. var iDebugNum = 0;
  3461. var bIsComplete = 0;
  3462. getData = "";
  3463. // We\'ve got something - so reset the timeout!
  3464. if (timeOutID)
  3465. clearTimeout(timeOutID);
  3466. // Assume no error at this time...
  3467. document.getElementById("error_block").style.display = "none";
  3468. // Are we getting some duff info?
  3469. if (!oXMLDoc.getElementsByTagName("item")[0])
  3470. {
  3471. // Too many errors?
  3472. if (retryCount > 15)
  3473. {
  3474. document.getElementById("error_block").style.display = "";
  3475. setInnerHTML(document.getElementById("error_message"), "Error retrieving information on step: " + (sDebugName == "" ? sLastString : sDebugName));';
  3476. if ($is_debug)
  3477. echo '
  3478. setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
  3479. echo '
  3480. }
  3481. else
  3482. {
  3483. retryCount++;
  3484. getNextItem();
  3485. }
  3486. return false;
  3487. }
  3488. // Never allow loops.
  3489. if (curFile == prevFile)
  3490. {
  3491. retryCount++;
  3492. if (retryCount > 10)
  3493. {
  3494. document.getElementById("error_block").style.display = "";
  3495. setInnerHTML(document.getElementById("error_message"), "Upgrade script appears to be going into a loop - step: " + sDebugName);';
  3496. if ($is_debug)
  3497. echo '
  3498. setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
  3499. echo '
  3500. }
  3501. }
  3502. retryCount = 0;
  3503. for (var i = 0; i < oXMLDoc.getElementsByTagName("item")[0].childNodes.length; i++)
  3504. sItemName += oXMLDoc.getElementsByTagName("item")[0].childNodes[i].nodeValue;
  3505. for (var i = 0; i < oXMLDoc.getElementsByTagName("debug")[0].childNodes.length; i++)
  3506. sDebugName += oXMLDoc.getElementsByTagName("debug")[0].childNodes[i].nodeValue;
  3507. for (var i = 0; i < oXMLDoc.getElementsByTagName("get").length; i++)
  3508. {
  3509. getData += "&" + oXMLDoc.getElementsByTagName("get")[i].getAttribute("key") + "=";
  3510. for (var j = 0; j < oXMLDoc.getElementsByTagName("get")[i].childNodes.length; j++)
  3511. {
  3512. getData += oXMLDoc.getElementsByTagName("get")[i].childNodes[j].nodeValue;
  3513. }
  3514. }
  3515. iItemNum = oXMLDoc.getElementsByTagName("item")[0].getAttribute("num");
  3516. iDebugNum = parseInt(oXMLDoc.getElementsByTagName("debug")[0].getAttribute("num"));
  3517. bIsComplete = parseInt(oXMLDoc.getElementsByTagName("debug")[0].getAttribute("complete"));
  3518. iSubStepProgress = parseFloat(oXMLDoc.getElementsByTagName("debug")[0].getAttribute("percent"));
  3519. sLastString = sDebugName + " (Item: " + iDebugNum + ")";
  3520. curFile = parseInt(oXMLDoc.getElementsByTagName("file")[0].getAttribute("num"));
  3521. debugItems = parseInt(oXMLDoc.getElementsByTagName("file")[0].getAttribute("debug_items"));
  3522. totalItems = parseInt(oXMLDoc.getElementsByTagName("file")[0].getAttribute("items"));
  3523. // If we have an error we haven\'t completed!
  3524. if (oXMLDoc.getElementsByTagName("error")[0] && bIsComplete)
  3525. iDebugNum = lastItem;
  3526. // Do we have the additional progress bar?
  3527. if (iSubStepProgress != -1)
  3528. {
  3529. document.getElementById("substep_bar_div").style.display = "";
  3530. document.getElementById("substep_bar_div2").style.display = "";
  3531. document.getElementById("substep_progress").style.width = iSubStepProgress + "%";
  3532. setInnerHTML(document.getElementById("substep_text"), iSubStepProgress + "%");
  3533. setInnerHTML(document.getElementById("substep_bar_div"), sDebugName.replace(/\./g, "") + ":");
  3534. }
  3535. else
  3536. {
  3537. document.getElementById("substep_bar_div").style.display = "none";
  3538. document.getElementById("substep_bar_div2").style.display = "none";
  3539. }
  3540. // Move onto the next item?
  3541. if (bIsComplete)
  3542. lastItem = iDebugNum;
  3543. else
  3544. lastItem = iDebugNum - 1;
  3545. // Are we finished?
  3546. if (bIsComplete && iDebugNum == -1 && curFile >= ', $upcontext['file_count'], ')
  3547. {';
  3548. if ($is_debug)
  3549. echo '
  3550. document.getElementById(\'debug_section\').style.display = "none";';
  3551. echo '
  3552. document.getElementById(\'commess\').style.display = "";
  3553. document.getElementById(\'contbutt\').disabled = 0;
  3554. document.getElementById(\'database_done\').value = 1;';
  3555. if ($upcontext['file_count'] > 1)
  3556. echo '
  3557. document.getElementById(\'info1\').style.display = "none";';
  3558. echo '
  3559. document.getElementById(\'info2\').style.display = "none";
  3560. updateStepProgress(100, 100, ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');
  3561. return true;
  3562. }
  3563. // Was it the last step in the file?
  3564. else if (bIsComplete && iDebugNum == -1)
  3565. {
  3566. lastItem = 0;
  3567. prevFile = curFile;';
  3568. if ($is_debug)
  3569. echo '
  3570. setOuterHTML(document.getElementById(\'debuginfo\'), \'Moving to next script file...done<br /><span id="debuginfo"><\' + \'/span>\');';
  3571. echo '
  3572. getNextItem();
  3573. return true;
  3574. }';
  3575. // If debug scroll the screen.
  3576. if ($is_debug)
  3577. echo '
  3578. if (iLastSubStepProgress == -1)
  3579. {
  3580. // Give it consistent dots.
  3581. dots = sDebugName.match(/\./g);
  3582. numDots = dots ? dots.length : 0;
  3583. for (var i = numDots; i < 3; i++)
  3584. sDebugName += ".";
  3585. setOuterHTML(document.getElementById(\'debuginfo\'), sDebugName + \'<span id="debuginfo"><\' + \'/span>\');
  3586. }
  3587. iLastSubStepProgress = iSubStepProgress;
  3588. if (bIsComplete)
  3589. setOuterHTML(document.getElementById(\'debuginfo\'), \'done<br /><span id="debuginfo"><\' + \'/span>\');
  3590. else
  3591. setOuterHTML(document.getElementById(\'debuginfo\'), \'...<span id="debuginfo"><\' + \'/span>\');
  3592. if (document.getElementById(\'debug_section\').scrollHeight)
  3593. document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
  3594. echo '
  3595. // Update the page.
  3596. setInnerHTML(document.getElementById(\'item_num\'), iItemNum);
  3597. setInnerHTML(document.getElementById(\'cur_item_name\'), sItemName);';
  3598. if ($upcontext['file_count'] > 1)
  3599. {
  3600. echo '
  3601. setInnerHTML(document.getElementById(\'file_done\'), curFile);
  3602. setInnerHTML(document.getElementById(\'item_count\'), totalItems);';
  3603. }
  3604. echo '
  3605. // Is there an error?
  3606. if (oXMLDoc.getElementsByTagName("error")[0])
  3607. {
  3608. var sErrorMsg = "";
  3609. for (var i = 0; i < oXMLDoc.getElementsByTagName("error")[0].childNodes.length; i++)
  3610. sErrorMsg += oXMLDoc.getElementsByTagName("error")[0].childNodes[i].nodeValue;
  3611. document.getElementById("error_block").style.display = "";
  3612. setInnerHTML(document.getElementById("error_message"), sErrorMsg);
  3613. return false;
  3614. }
  3615. // Get the progress bar right.
  3616. barTotal = debugItems * ', $upcontext['file_count'], ';
  3617. barDone = (debugItems * (curFile - 1)) + lastItem;
  3618. updateStepProgress(barDone, barTotal, ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');
  3619. // Finally - update the time here as it shows the server is responding!
  3620. curTime = new Date();
  3621. iElapsed = (curTime.getTime() / 1000 - ', $upcontext['started'], ');
  3622. mins = parseInt(iElapsed / 60);
  3623. secs = parseInt(iElapsed - mins * 60);
  3624. setInnerHTML(document.getElementById("mins_elapsed"), mins);
  3625. setInnerHTML(document.getElementById("secs_elapsed"), secs);
  3626. getNextItem();
  3627. return true;
  3628. }
  3629. // What if we timeout?!
  3630. function retTimeout(attemptAgain)
  3631. {
  3632. // Oh noes...
  3633. if (!attemptAgain)
  3634. {
  3635. document.getElementById("error_block").style.display = "";
  3636. setInnerHTML(document.getElementById("error_message"), "Server has not responded for ', ($timeLimitThreshold * 10), ' seconds. It may be worth waiting a little longer or otherwise please click <a href=\"#\" onclick=\"retTimeout(true); return false;\">here<" + "/a> to try this step again");
  3637. }
  3638. else
  3639. {
  3640. document.getElementById("error_block").style.display = "none";
  3641. getNextItem();
  3642. }
  3643. }';
  3644. // Start things off assuming we've not errored.
  3645. if (empty($upcontext['error_message']))
  3646. echo '
  3647. getNextItem();';
  3648. echo '
  3649. // ]]></script>';
  3650. }
  3651. return;
  3652. }
  3653. function template_database_xml()
  3654. {
  3655. global $upcontext, $settings, $options, $txt;
  3656. echo '
  3657. <file num="', $upcontext['cur_file_num'], '" items="', $upcontext['total_items'], '" debug_items="', $upcontext['debug_items'], '">', $upcontext['cur_file_name'], '</file>
  3658. <item num="', $upcontext['current_item_num'], '">', $upcontext['current_item_name'], '</item>
  3659. <debug num="', $upcontext['current_debug_item_num'], '" percent="', isset($upcontext['substep_progress']) ? $upcontext['substep_progress'] : '-1', '" complete="', empty($upcontext['completed_step']) ? 0 : 1, '">', $upcontext['current_debug_item_name'], '</debug>';
  3660. if (!empty($upcontext['error_message']))
  3661. echo '
  3662. <error>', $upcontext['error_message'], '</error>';
  3663. }
  3664. function template_clean_mods()
  3665. {
  3666. global $upcontext, $modSettings, $upgradeurl, $disable_security, $settings, $boarddir, $db_prefix, $boardurl;
  3667. $upcontext['chmod_in_form'] = true;
  3668. echo '
  3669. <h3>SMF has detected some packages which were installed but not fully removed prior to upgrade. We recommend you remove the following mods and reinstall upon completion of the upgrade.</h3>
  3670. <form action="', $upcontext['form_url'], '&amp;ssi=1" name="upform" id="upform" method="post">';
  3671. // In case it's required.
  3672. template_chmod();
  3673. echo '
  3674. <table width="90%" align="center" cellspacing="1" cellpadding="2" style="background-color: black;">
  3675. <tr style="background-color: #eeeeee;">
  3676. <td width="40%"><strong>Modification Name</strong></td>
  3677. <td width="10%" align="center"><strong>Version</strong></td>
  3678. <td width="15%"><strong>Files Affected</strong></td>
  3679. <td width="20%"><strong>Status</strong></td>
  3680. <td width="5%" align="center"><strong>Fix?</strong></td>
  3681. </tr>';
  3682. foreach ($upcontext['packages'] as $package)
  3683. {
  3684. echo '
  3685. <tr style="background-color: #cccccc;">
  3686. <td width="40%">', $package['name'], '</td>
  3687. <td width="10%">', $package['version'], '</td>
  3688. <td width="15%">', $package['file_count'], ' <span class="smalltext">[<a href="#" onclick="alert(\'The following files are affected by this modification:\\n\\n', strtr(implode('<br />', $package['files']), array('\\' => '\\\\', '<br />' => '\\n')), '\'); return false;">details</a>]</td>
  3689. <td width="20%"><span style="font-weight: bold; color: ', $package['color'], '">', $package['status'], '</span></td>
  3690. <td width="5%" align="center">
  3691. <input type="hidden" name="remove[', $package['id'], ']" value="0" />
  3692. <input type="checkbox" name="remove[', $package['id'], ']"', $package['color'] == 'green' ? ' disabled="disabled"' : '', ' class="input_check" />
  3693. </td>
  3694. </tr>';
  3695. }
  3696. echo '
  3697. </table>
  3698. <input type="hidden" name="cleandone" value="1" />';
  3699. // Files to make writable?
  3700. if (!empty($upcontext['writable_files']))
  3701. echo '
  3702. <input type="hidden" name="writable_files" value="', base64_encode(serialize($upcontext['writable_files'])), '" />';
  3703. // We'll want a continue button...
  3704. if (empty($upcontext['chmod']['files']))
  3705. $upcontext['continue'] = 1;
  3706. }
  3707. // Finished with the mods - let them know what we've done.
  3708. function template_cleanup_done()
  3709. {
  3710. global $upcontext, $modSettings, $upgradeurl, $disable_security, $settings, $boarddir, $db_prefix, $boardurl;
  3711. echo '
  3712. <h3>SMF has attempted to fix and reinstall mods as required. We recommend you visit the package manager upon completing upgrade to check the status of your modifications.</h3>
  3713. <form action="', $upcontext['form_url'], '&amp;ssi=1" name="upform" id="upform" method="post">
  3714. <table width="90%" align="center" cellspacing="1" cellpadding="2" style="background-color: black;">
  3715. <tr style="background-color: #eeeeee;">
  3716. <td width="100%"><strong>Actions Completed:</strong></td>
  3717. </tr>';
  3718. foreach ($upcontext['packages'] as $package)
  3719. {
  3720. echo '
  3721. <tr style="background-color: #cccccc;">
  3722. <td>', $package['name'], '... <span style="font-weight: bold; color: ', $package['color'], ';">', $package['result'], '</span></td>
  3723. </tr>';
  3724. }
  3725. echo '
  3726. </table>
  3727. <input type="hidden" name="cleandone2" value="1" />';
  3728. // We'll want a continue button...
  3729. $upcontext['continue'] = 1;
  3730. }
  3731. // Do they want to upgrade their templates?
  3732. function template_upgrade_templates()
  3733. {
  3734. global $upcontext, $modSettings, $upgradeurl, $disable_security, $settings, $boarddir, $db_prefix, $boardurl;
  3735. echo '
  3736. <h3>There have been numerous language and template changes since the previous version of SMF. On this step the upgrader can attempt to automatically make these changes in your templates to save you from doing so manually.</h3>
  3737. <form action="', $upcontext['form_url'], '&amp;ssi=1', $upcontext['is_test'] ? '' : ';forreal=1', '" name="upform" id="upform" method="post">';
  3738. // Any files need to be writable?
  3739. $upcontext['chmod_in_form'] = true;
  3740. template_chmod();
  3741. // Language/Template files need an update?
  3742. if ($upcontext['temp_progress'] == 0 && !$upcontext['is_test'] && (!empty($upcontext['languages']) || !empty($upcontext['themes'])))
  3743. {
  3744. echo '
  3745. The following template files will be updated to ensure they are compatible with this version of SMF. Note that this can only fix a limited number of compatibility issues and in general you should seek out the latest version of these themes/language files.
  3746. <table width="90%" align="center" cellspacing="1" cellpadding="2" style="background-color: black;">
  3747. <tr style="background-color: #eeeeee;">
  3748. <td width="80%"><strong>Area</strong></td>
  3749. <td width="20%" align="center"><strong>Changes Required</strong></td>
  3750. </tr>';
  3751. foreach ($upcontext['languages'] as $language)
  3752. {
  3753. echo '
  3754. <tr style="background-color: #cccccc;">
  3755. <td width="80%">
  3756. &quot;', $language['name'], '&quot; Language Pack
  3757. <div class="smalltext">(';
  3758. foreach ($language['files'] as $k => $file)
  3759. echo $file['name'], $k + 1 != count($language['files']) ? ', ' : ')';
  3760. echo '
  3761. </div>
  3762. </td>
  3763. <td width="20%" align="center">', $language['edit_count'] == 0 ? 1 : $language['edit_count'], '</td>
  3764. </tr>';
  3765. }
  3766. foreach ($upcontext['themes'] as $theme)
  3767. {
  3768. echo '
  3769. <tr style="background-color: #CCCCCC;">
  3770. <td width="80%">
  3771. &quot;', $theme['name'], '&quot; Theme
  3772. <div class="smalltext">(';
  3773. foreach ($theme['files'] as $k => $file)
  3774. echo $file['name'], $k + 1 != count($theme['files']) ? ', ' : ')';
  3775. echo '
  3776. </div>
  3777. </td>
  3778. <td width="20%" align="center">', $theme['edit_count'] == 0 ? 1 : $theme['edit_count'], '</td>
  3779. </tr>';
  3780. }
  3781. echo '
  3782. </table>';
  3783. }
  3784. else
  3785. {
  3786. $langFiles = 0;
  3787. $themeFiles = 0;
  3788. if (!empty($upcontext['languages']))
  3789. foreach ($upcontext['languages'] as $lang)
  3790. $langFiles += count($lang['files']);
  3791. if (!empty($upcontext['themes']))
  3792. foreach ($upcontext['themes'] as $theme)
  3793. $themeFiles += count($theme['files']);
  3794. echo sprintf('Found <strong>%d</strong> language files and <strong>%d</strong> templates requiring an update so far.', $langFiles, $themeFiles) . '<br />';
  3795. // What we're currently doing?
  3796. if (!empty($upcontext['current_message']))
  3797. echo '
  3798. ', $upcontext['current_message'];
  3799. }
  3800. echo '
  3801. <input type="hidden" name="uptempdone" value="1" />';
  3802. if (!empty($upcontext['languages']))
  3803. echo '
  3804. <input type="hidden" name="languages" value="', base64_encode(serialize($upcontext['languages'])), '" />';
  3805. if (!empty($upcontext['themes']))
  3806. echo '
  3807. <input type="hidden" name="themes" value="', base64_encode(serialize($upcontext['themes'])), '" />';
  3808. if (!empty($upcontext['writable_files']))
  3809. echo '
  3810. <input type="hidden" name="writable_files" value="', base64_encode(serialize($upcontext['writable_files'])), '" />';
  3811. // Offer them the option to upgrade from YaBB SE?
  3812. if (!empty($upcontext['can_upgrade_yabbse']))
  3813. echo '
  3814. <br /><label for="conv"><input type="checkbox" name="conv" id="conv" value="1" class="input_check" /> Convert the existing YaBB SE template and set it as default.</label><br />';
  3815. // We'll want a continue button... assuming chmod is OK (Otherwise let them use connect!)
  3816. if (empty($upcontext['chmod']['files']) || $upcontext['is_test'])
  3817. $upcontext['continue'] = 1;
  3818. }
  3819. function template_upgrade_complete()
  3820. {
  3821. global $upcontext, $modSettings, $upgradeurl, $disable_security, $settings, $boarddir, $db_prefix, $boardurl;
  3822. echo '
  3823. <h3>That wasn\'t so hard, was it? Now you are ready to use <a href="', $boardurl, '/index.php">your installation of SMF</a>. Hope you like it!</h3>
  3824. <form action="', $boardurl, '/index.php">';
  3825. if (!empty($upcontext['can_delete_script']))
  3826. echo '
  3827. <label for="delete_self"><input type="checkbox" id="delete_self" onclick="doTheDelete(this);" class="input_check" /> Delete this upgrade.php and its data files now.</label> <em>(doesn\'t work on all servers.)</em>
  3828. <script type="text/javascript"><!-- // --><![CDATA[
  3829. function doTheDelete(theCheck)
  3830. {
  3831. var theImage = document.getElementById ? document.getElementById("delete_upgrader") : document.all.delete_upgrader;
  3832. theImage.src = "', $upgradeurl, '?delete=1&ts_" + (new Date().getTime());
  3833. theCheck.disabled = true;
  3834. }
  3835. // ]]></script>
  3836. <img src="', $boardurl, '/Themes/default/images/blank.png" alt="" id="delete_upgrader" /><br />';
  3837. echo '<br />
  3838. If you had any problems with this upgrade, or have any problems using SMF, please don\'t hesitate to <a href="http://www.simplemachines.org/community/index.php">look to us for assistance</a>.<br />
  3839. <br />
  3840. Best of luck,<br />
  3841. Simple Machines';
  3842. }
  3843. ?>