12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523 |
- <?php
- define('SMF_VERSION', '2.1 Alpha 1');
- define('SMF_LANG_VERSION', '2.1');
- $GLOBALS['required_php_version'] = '5.1.0';
- $GLOBALS['required_mysql_version'] = '4.0.18';
- $databases = array(
- 'mysql' => array(
- 'name' => 'MySQL',
- 'version' => '4.0.18',
- 'version_check' => 'return min(mysql_get_server_info(), mysql_get_client_info());',
- 'utf8_support' => true,
- 'utf8_version' => '4.1.0',
- 'utf8_version_check' => 'return mysql_get_server_info();',
- 'alter_support' => true,
- ),
- 'postgresql' => array(
- 'name' => 'PostgreSQL',
- 'version' => '8.0',
- 'version_check' => '$version = pg_version(); return $version[\'client\'];',
- 'always_has_db' => true,
- ),
- 'sqlite' => array(
- 'name' => 'SQLite',
- 'version' => '1',
- 'version_check' => 'return 1;',
- 'always_has_db' => true,
- ),
- );
- $timeLimitThreshold = 3;
- $upgrade_path = dirname(__FILE__);
- $upgradeurl = $_SERVER['PHP_SELF'];
- $smfsite = 'http://www.simplemachines.org/smf';
- $disable_security = false;
- $upcontext['inactive_timeout'] = 10;
- $upcontext['steps'] = array(
- 0 => array(1, 'Login', 'WelcomeLogin', 2),
- 1 => array(2, 'Upgrade Options', 'UpgradeOptions', 2),
- 2 => array(3, 'Backup', 'BackupDatabase', 10),
- 3 => array(4, 'Database Changes', 'DatabaseChanges', 70),
-
-
- 4 => array(5, 'Delete Upgrade', 'DeleteUpgrade', 1),
- );
- $upcontext['database_step'] = 3;
- @set_time_limit(600);
- if (!ini_get('safe_mode'))
- {
- ini_set('mysql.connect_timeout', -1);
- ini_set('default_socket_timeout', 900);
- }
- if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR']))
- for ($i = 1; $i < $_SERVER['argc']; $i++)
- {
- if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0)
- $upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1];
- }
- if (php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR']))
- {
- $command_line = true;
- $disable_security = 1;
- }
- else
- $command_line = false;
- require_once($upgrade_path . '/Settings.php');
- if (isset($upgradeData))
- {
- $upcontext['user'] = unserialize(base64_decode($upgradeData));
-
- if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400)
- $upcontext['user']['started'] = time();
- if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400)
- $upcontext['user']['updated'] = 0;
- $upcontext['started'] = $upcontext['user']['started'];
- $upcontext['updated'] = $upcontext['user']['updated'];
- }
- if (empty($upcontext['updated']))
- {
- $upcontext['started'] = time();
- $upcontext['updated'] = 0;
- $upcontext['user'] = array(
- 'id' => 0,
- 'name' => 'Guest',
- 'pass' => 0,
- 'started' => $upcontext['started'],
- 'updated' => $upcontext['updated'],
- );
- }
- loadEssentialData();
- if (isset($_GET['ssi']))
- {
- require_once($sourcedir . '/Subs.php');
- require_once($sourcedir . '/Errors.php');
- require_once($sourcedir . '/Logging.php');
- require_once($sourcedir . '/Load.php');
- require_once($sourcedir . '/Security.php');
- require_once($sourcedir . '/Subs-Package.php');
- loadUserSettings();
- loadPermissions();
- }
- if (!function_exists('ip2range'))
- require_once($sourcedir . '/Subs.php');
- if (!function_exists('un_htmlspecialchars'))
- {
- function un_htmlspecialchars($string)
- {
- return strtr($string, array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES)) + array(''' => '\'', ' ' => ' '));
- }
- }
- if (!function_exists('text2words'))
- {
- function text2words($text)
- {
- global $smcFunc;
-
- $words = preg_replace('~(?:[\x0B\0\xA0\t\r\s\n(){}\\[\\]<>!@$%^*.,:+=`\~\?/\\\\]+|&(?:amp|lt|gt|quot);)+~', ' ', $text);
-
- $words = preg_replace('~([^&\d]|^)[#;]~', '$1 ', un_htmlspecialchars(strtolower($words)));
-
- $words = explode(' ', $words);
- $returned_words = array();
- foreach ($words as $word)
- {
- $word = trim($word, '-_\'');
- if ($word != '')
- $returned_words[] = substr($word, 0, 20);
- }
- return array_unique($returned_words);
- }
- }
- if (!function_exists('clean_cache'))
- {
-
- function clean_cache($type = '')
- {
- global $cachedir, $sourcedir;
-
- if (!is_dir($cachedir))
- return;
-
- $dh = opendir($cachedir);
- while ($file = readdir($dh))
- {
- if ($file != '.' && $file != '..' && $file != 'index.php' && $file != '.htaccess' && (!$type || substr($file, 0, strlen($type)) == $type))
- @unlink($cachedir . '/' . $file);
- }
- closedir($dh);
-
-
- @touch($sourcedir . '/' . 'Load.php');
- clearstatcache();
- }
- }
- if (!function_exists('md5_hmac'))
- {
- function md5_hmac($data, $key)
- {
- if (strlen($key) > 64)
- $key = pack('H*', md5($key));
- $key = str_pad($key, 64, chr(0x00));
- $k_ipad = $key ^ str_repeat(chr(0x36), 64);
- $k_opad = $key ^ str_repeat(chr(0x5c), 64);
- return md5($k_opad . pack('H*', md5($k_ipad . $data)));
- }
- }
- if (!class_exists('ftp_connection'))
- {
- class ftp_connection
- {
- var $connection = 'no_connection', $error = false, $last_message, $pasv = array();
-
- function ftp_connection($ftp_server, $ftp_port = 21, $ftp_user = 'anonymous', $ftp_pass = 'ftpclient@simplemachines.org')
- {
- if ($ftp_server !== null)
- $this->connect($ftp_server, $ftp_port, $ftp_user, $ftp_pass);
- }
- function connect($ftp_server, $ftp_port = 21, $ftp_user = 'anonymous', $ftp_pass = 'ftpclient@simplemachines.org')
- {
- if (substr($ftp_server, 0, 6) == 'ftp://')
- $ftp_server = substr($ftp_server, 6);
- elseif (substr($ftp_server, 0, 7) == 'ftps://')
- $ftp_server = 'ssl://' . substr($ftp_server, 7);
- if (substr($ftp_server, 0, 7) == 'http://')
- $ftp_server = substr($ftp_server, 7);
- $ftp_server = strtr($ftp_server, array('/' => '', ':' => '', '@' => ''));
-
- $this->connection = @fsockopen($ftp_server, $ftp_port, $err, $err, 5);
- if (!$this->connection)
- {
- $this->error = 'bad_server';
- return;
- }
-
- if (!$this->check_response(220))
- {
- $this->error = 'bad_response';
- return;
- }
-
- fwrite($this->connection, 'USER ' . $ftp_user . "\r\n");
- if (!$this->check_response(331))
- {
- $this->error = 'bad_username';
- return;
- }
-
- fwrite($this->connection, 'PASS ' . $ftp_pass . "\r\n");
- if (!$this->check_response(230))
- {
- $this->error = 'bad_password';
- return;
- }
- }
- function chdir($ftp_path)
- {
- if (!is_resource($this->connection))
- return false;
-
- if (substr($ftp_path, -1) == '/' && $ftp_path !== '/')
- $ftp_path = substr($ftp_path, 0, -1);
- fwrite($this->connection, 'CWD ' . $ftp_path . "\r\n");
- if (!$this->check_response(250))
- {
- $this->error = 'bad_path';
- return false;
- }
- return true;
- }
- function chmod($ftp_file, $chmod)
- {
- if (!is_resource($this->connection))
- return false;
-
- fwrite($this->connection, 'SITE CHMOD ' . decoct($chmod) . ' ' . $ftp_file . "\r\n");
- if (!$this->check_response(200))
- {
- $this->error = 'bad_file';
- return false;
- }
- return true;
- }
- function unlink($ftp_file)
- {
-
- if (!is_resource($this->connection))
- return false;
-
- fwrite($this->connection, 'DELE ' . $ftp_file . "\r\n");
- if (!$this->check_response(250))
- {
- fwrite($this->connection, 'RMD ' . $ftp_file . "\r\n");
-
- if (!$this->check_response(250))
- {
- $this->error = 'bad_file';
- return false;
- }
- }
- return true;
- }
- function check_response($desired)
- {
-
- $time = time();
- do
- $this->last_message = fgets($this->connection, 1024);
- while (substr($this->last_message, 3, 1) != ' ' && time() - $time < 5);
-
- return is_array($desired) ? in_array(substr($this->last_message, 0, 3), $desired) : substr($this->last_message, 0, 3) == $desired;
- }
- function passive()
- {
-
- if (!is_resource($this->connection))
- return false;
-
- @fwrite($this->connection, 'PASV' . "\r\n");
- $time = time();
- do
- $response = fgets($this->connection, 1024);
- while (substr($response, 3, 1) != ' ' && time() - $time < 5);
-
- if (substr($response, 0, 4) != '227 ')
- {
- $this->error = 'bad_response';
- return false;
- }
-
- if (preg_match('~\((\d+),\s*(\d+),\s*(\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+))\)~', $response, $match) == 0)
- {
- $this->error = 'bad_response';
- return false;
- }
-
- $this->pasv = array('ip' => $match[1] . '.' . $match[2] . '.' . $match[3] . '.' . $match[4], 'port' => $match[5] * 256 + $match[6]);
- return true;
- }
- function create_file($ftp_file)
- {
-
- if (!is_resource($this->connection))
- return false;
-
- if (!$this->passive())
- return false;
-
- fwrite($this->connection, 'STOR ' . $ftp_file . "\r\n");
-
- $fp = @fsockopen($this->pasv['ip'], $this->pasv['port'], $err, $err, 5);
- if (!$fp || !$this->check_response(150))
- {
- $this->error = 'bad_file';
- @fclose($fp);
- return false;
- }
-
- fclose($fp);
- if (!$this->check_response(226))
- {
- $this->error = 'bad_response';
- return false;
- }
- return true;
- }
- function list_dir($ftp_path = '', $search = false)
- {
-
- if (!is_resource($this->connection))
- return false;
-
- if (!$this->passive())
- return false;
-
- fwrite($this->connection, 'LIST -1' . ($search ? 'R' : '') . ($ftp_path == '' ? '' : ' ' . $ftp_path) . "\r\n");
-
- $fp = @fsockopen($this->pasv['ip'], $this->pasv['port'], $err, $err, 5);
- if (!$fp || !$this->check_response(array(150, 125)))
- {
- $this->error = 'bad_response';
- @fclose($fp);
- return false;
- }
-
- $data = '';
- while (!feof($fp))
- $data .= fread($fp, 4096);
- fclose($fp);
-
- if (!$this->check_response(226))
- {
- $this->error = 'bad_response';
- return false;
- }
- return $data;
- }
- function locate($file, $listing = null)
- {
- if ($listing === null)
- $listing = $this->list_dir('', true);
- $listing = explode("\n", $listing);
- @fwrite($this->connection, 'PWD' . "\r\n");
- $time = time();
- do
- $response = fgets($this->connection, 1024);
- while (substr($response, 3, 1) != ' ' && time() - $time < 5);
-
- if (preg_match('~^257 "(.+?)" ~', $response, $match) != 0)
- $current_dir = strtr($match[1], array('""' => '"'));
- else
- $current_dir = '';
- for ($i = 0, $n = count($listing); $i < $n; $i++)
- {
- if (trim($listing[$i]) == '' && isset($listing[$i + 1]))
- {
- $current_dir = substr(trim($listing[++$i]), 0, -1);
- $i++;
- }
-
- $listing[$i] = $current_dir . '/' . trim(strlen($listing[$i]) > 30 ? strrchr($listing[$i], ' ') : $listing[$i]);
- if (substr($file, 0, 1) == '*' && substr($listing[$i], -(strlen($file) - 1)) == substr($file, 1))
- return $listing[$i];
- if (substr($file, -1) == '*' && substr($listing[$i], 0, strlen($file) - 1) == substr($file, 0, -1))
- return $listing[$i];
- if (basename($listing[$i]) == $file || $listing[$i] == $file)
- return $listing[$i];
- }
- return false;
- }
- function create_dir($ftp_dir)
- {
-
- if (!is_resource($this->connection))
- return false;
-
- fwrite($this->connection, 'MKD ' . $ftp_dir . "\r\n");
- if (!$this->check_response(257))
- {
- $this->error = 'bad_file';
- return false;
- }
- return true;
- }
- function detect_path($filesystem_path, $lookup_file = null)
- {
- $username = '';
- if (isset($_SERVER['DOCUMENT_ROOT']))
- {
- if (preg_match('~^/home[2]?/([^/]+?)/public_html~', $_SERVER['DOCUMENT_ROOT'], $match))
- {
- $username = $match[1];
- $path = strtr($_SERVER['DOCUMENT_ROOT'], array('/home/' . $match[1] . '/' => '', '/home2/' . $match[1] . '/' => ''));
- if (substr($path, -1) == '/')
- $path = substr($path, 0, -1);
- if (strlen(dirname($_SERVER['PHP_SELF'])) > 1)
- $path .= dirname($_SERVER['PHP_SELF']);
- }
- elseif (substr($filesystem_path, 0, 9) == '/var/www/')
- $path = substr($filesystem_path, 8);
- else
- $path = strtr(strtr($filesystem_path, array('\\' => '/')), array($_SERVER['DOCUMENT_ROOT'] => ''));
- }
- else
- $path = '';
- if (is_resource($this->connection) && $this->list_dir($path) == '')
- {
- $data = $this->list_dir('', true);
- if ($lookup_file === null)
- $lookup_file = $_SERVER['PHP_SELF'];
- $found_path = dirname($this->locate('*' . basename(dirname($lookup_file)) . '/' . basename($lookup_file), $data));
- if ($found_path == false)
- $found_path = dirname($this->locate(basename($lookup_file)));
- if ($found_path != false)
- $path = $found_path;
- }
- elseif (is_resource($this->connection))
- $found_path = true;
- return array($username, $path, isset($found_path));
- }
- function close()
- {
-
- fwrite($this->connection, 'QUIT' . "\r\n");
- fclose($this->connection);
- return true;
- }
- }
- }
- if (isset($_GET['data']))
- {
- $upcontext['upgrade_status'] = unserialize(base64_decode($_GET['data']));
- $upcontext['current_step'] = $upcontext['upgrade_status']['curstep'];
- $upcontext['language'] = $upcontext['upgrade_status']['lang'];
- $upcontext['rid'] = $upcontext['upgrade_status']['rid'];
- $is_debug = $upcontext['upgrade_status']['debug'];
- $support_js = $upcontext['upgrade_status']['js'];
-
- if (file_exists($boarddir . '/Themes/default/languages/Install.' . $upcontext['language'] . '.php'))
- require_once($boarddir . '/Themes/default/languages/Install.' . $upcontext['language'] . '.php');
- }
- else
- {
- $upcontext['current_step'] = 0;
- $upcontext['rid'] = mt_rand(0, 5000);
- $upcontext['upgrade_status'] = array(
- 'curstep' => 0,
- 'lang' => isset($_GET['lang']) ? $_GET['lang'] : basename($language, '.lng'),
- 'rid' => $upcontext['rid'],
- 'pass' => 0,
- 'debug' => 0,
- 'js' => 0,
- );
- $upcontext['language'] = $upcontext['upgrade_status']['lang'];
- }
- if (!isset($modSettings['smfVersion']))
- $disable_security = true;
- if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step']))
- checkLogin();
- if (isset($modSettings['smfVersion']))
- {
- $request = $smcFunc['db_query']('', '
- SELECT variable, value
- FROM {db_prefix}themes
- WHERE id_theme = {int:id_theme}
- AND variable IN ({string:theme_url}, {string:theme_dir}, {string:images_url})',
- array(
- 'id_theme' => 1,
- 'theme_url' => 'theme_url',
- 'theme_dir' => 'theme_dir',
- 'images_url' => 'images_url',
- 'db_error_skip' => true,
- )
- );
- while ($row = $smcFunc['db_fetch_assoc']($request))
- $modSettings[$row['variable']] = $row['value'];
- $smcFunc['db_free_result']($request);
- }
- if (!isset($modSettings['theme_url']))
- {
- $modSettings['theme_dir'] = $boarddir . '/Themes/default';
- $modSettings['theme_url'] = 'Themes/default';
- $modSettings['images_url'] = 'Themes/default/images';
- }
- if (!isset($settings['default_theme_url']))
- $settings['default_theme_url'] = $modSettings['theme_url'];
- if (!isset($settings['default_theme_dir']))
- $settings['default_theme_dir'] = $modSettings['theme_dir'];
- $upcontext['is_large_forum'] = (empty($modSettings['smfVersion']) || $modSettings['smfVersion'] <= '1.1 RC1') && !empty($modSettings['totalMessages']) && $modSettings['totalMessages'] > 75000;
- $upcontext['page_title'] = isset($modSettings['smfVersion']) ? 'Updating Your SMF Install!' : 'Upgrading from YaBB SE!';
- $upcontext['right_to_left'] = isset($txt['lang_rtl']) ? $txt['lang_rtl'] : false;
- if ($command_line)
- cmdStep0();
- if (isset($_GET['xml']))
- $upcontext['return_error'] = true;
- $upcontext['overall_percent'] = 0;
- foreach ($upcontext['steps'] as $num => $step)
- {
- if ($num >= $upcontext['current_step'])
- {
-
- $upcontext['step_weight'] = $step[3];
-
- $upcontext['skip'] = false;
-
- if ($num != 0 && !$disable_security && $upcontext['user']['pass'] != $upcontext['upgrade_status']['pass'])
- {
- $upcontext['steps'][0][2]();
- break;
- }
-
- if (function_exists($step[2]) && $step[2]() === false)
- break;
- elseif (function_exists($step[2]))
- $upcontext['current_step']++;
- }
- $upcontext['overall_percent'] += $step[3];
- }
- upgradeExit();
- function upgradeExit($fallThrough = false)
- {
- global $upcontext, $upgradeurl, $boarddir, $command_line;
-
- if (!empty($upcontext['current_step']) && !empty($upcontext['user']['id']))
- {
- $upcontext['user']['step'] = $upcontext['current_step'];
- $upcontext['user']['substep'] = $_GET['substep'];
- $upcontext['user']['updated'] = time();
- $upgradeData = base64_encode(serialize($upcontext['user']));
- copy($boarddir . '/Settings.php', $boarddir . '/Settings_bak.php');
- changeSettings(array('upgradeData' => '"' . $upgradeData . '"'));
- updateLastError();
- }
-
- if (!empty($upcontext['step_progress']) && isset($upcontext['steps'][$upcontext['current_step']]))
- {
- $upcontext['step_progress'] = round($upcontext['step_progress'], 1);
- $upcontext['overall_percent'] += $upcontext['step_progress'] * ($upcontext['steps'][$upcontext['current_step']][3] / 100);
- }
- $upcontext['overall_percent'] = (int) $upcontext['overall_percent'];
-
- if (!$fallThrough)
- {
-
- if (!empty($command_line))
- {
- if (function_exists('debug_print_backtrace'))
- debug_print_backtrace();
- 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.';
- flush();
- die();
- }
- if (!isset($_GET['xml']))
- template_upgrade_above();
- else
- {
- header('Content-Type: text/xml; charset=ISO-8859-1');
-
- $upcontext['get_data'] = array();
- foreach ($_GET as $k => $v)
- {
- if (substr($k, 0, 3) != 'amp' && !in_array($k, array('xml', 'substep', 'lang', 'data', 'step', 'filecount')))
- {
- $upcontext['get_data'][$k] = $v;
- }
- }
- template_xml_above();
- }
-
- if (isset($upcontext['sub_template']))
- {
- $upcontext['upgrade_status']['curstep'] = $upcontext['current_step'];
- $upcontext['form_url'] = $upgradeurl . '?step=' . $upcontext['current_step'] . '&substep=' . $_GET['substep'] . '&data=' . base64_encode(serialize($upcontext['upgrade_status']));
-
- if (!empty($upcontext['query_string']))
- $upcontext['form_url'] .= $upcontext['query_string'];
- call_user_func('template_' . $upcontext['sub_template']);
- }
-
- if (!empty($upcontext['forced_error_message']))
- echo $upcontext['forced_error_message'];
-
- if (!isset($_GET['xml']))
- template_upgrade_below();
- else
- template_xml_below();
- }
-
- die();
- }
- function redirectLocation($location, $addForm = true)
- {
- global $upgradeurl, $upcontext, $command_line;
-
- if ($command_line)
- upgradeExit(true);
-
- if ($addForm)
- {
- $upcontext['upgrade_status']['curstep'] = $upcontext['current_step'];
- $location = $upgradeurl . '?step=' . $upcontext['current_step'] . '&substep=' . $_GET['substep'] . '&data=' . base64_encode(serialize($upcontext['upgrade_status'])) . $location;
- }
- while (@ob_end_clean());
- header('Location: ' . strtr($location, array('&' => '&')));
-
- upgradeExit(true);
- }
- function loadEssentialData()
- {
- global $db_server, $db_user, $db_passwd, $db_name, $db_connection, $db_prefix, $db_character_set, $db_type;
- global $modSettings, $sourcedir, $smcFunc, $upcontext;
-
- @set_magic_quotes_runtime(0);
- error_reporting(E_ALL);
- define('SMF', 1);
-
- if (@ini_get('session.save_handler') == 'user')
- @ini_set('session.save_handler', 'files');
- @session_start();
- if (empty($smcFunc))
- $smcFunc = array();
-
- if (@version_compare(PHP_VERSION, '5.1', '<='))
- require_once($sourcedir . '/Subs-Compat.php');
-
- initialize_inputs();
-
- if (empty($db_type))
- $db_type = 'mysql';
- if (file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
- {
- require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
-
- $db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, array('non_fatal' => true));
-
- if ($db_connection === null)
- die('Unable to connect to database - please check username and password are correct in Settings.php');
- if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1)
- $smcFunc['db_query']('', '
- SET NAMES ' . $db_character_set,
- array(
- 'db_error_skip' => true,
- )
- );
-
- $request = $smcFunc['db_query']('', '
- SELECT variable, value
- FROM {db_prefix}settings',
- array(
- 'db_error_skip' => true,
- )
- );
- $modSettings = array();
- while ($row = $smcFunc['db_fetch_assoc']($request))
- $modSettings[$row['variable']] = $row['value'];
- $smcFunc['db_free_result']($request);
- }
- else
- {
- 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.');
- }
-
- if (file_exists($sourcedir . '/QueryString.php'))
- {
- require_once($sourcedir . '/QueryString.php');
- cleanRequest();
- }
- if (!isset($_GET['substep']))
- $_GET['substep'] = 0;
- }
- function initialize_inputs()
- {
- global $sourcedir, $start_time, $upcontext, $db_type;
- $start_time = time();
- umask(0);
-
- if (!isset($_GET))
- {
- $GLOBALS['_GET']['step'] = 0;
- return;
- }
- ob_start();
-
- ignore_user_abort(true);
-
- if (isset($_GET['delete']))
- {
- @unlink(__FILE__);
-
- @unlink(dirname(__FILE__) . '/upgrade_1-0.sql');
- @unlink(dirname(__FILE__) . '/upgrade_1-1.sql');
- @unlink(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql');
- @unlink(dirname(__FILE__) . '/upgrade_2-1_' . $db_type . '.sql');
- @unlink(dirname(__FILE__) . '/webinstall.php');
- $dh = opendir(dirname(__FILE__));
- while ($file = readdir($dh))
- {
- if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1]))
- @unlink(dirname(__FILE__) . '/' . $file);
- }
- closedir($dh);
- 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');
- exit;
- }
-
- if (isset($_GET['infile_css']))
- {
- header('Content-Type: text/css');
- template_css();
- exit;
- }
-
- if (!isset($_GET['xml']))
- {
- $upcontext['remote_files_available'] = false;
- $test = @fsockopen('www.simplemachines.org', 80, $errno, $errstr, 1);
- if ($test)
- $upcontext['remote_files_available'] = true;
- @fclose($test);
- }
-
- $temp = 'upgrade_php?step';
- while (strlen($temp) > 4)
- {
- if (isset($_GET[$temp]))
- unset($_GET[$temp]);
- $temp = substr($temp, 1);
- }
-
- $_GET['step'] = (int) @$_GET['step'];
- $_GET['substep'] = (int) @$_GET['substep'];
- }
- function WelcomeLogin()
- {
- global $boarddir, $sourcedir, $db_prefix, $language, $modSettings, $cachedir, $upgradeurl, $upcontext, $disable_security;
- global $smcFunc, $db_type, $databases, $txt;
- $upcontext['sub_template'] = 'welcome_message';
-
- $check = @file_exists($boarddir . '/Themes/default/index.template.php')
- && @file_exists($sourcedir . '/QueryString.php')
- && @file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')
- && @file_exists(dirname(__FILE__) . '/upgrade_2-1_' . $db_type . '.sql');
-
- if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1)
- $check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql');
- if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0)
- $check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
- if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1)
- $check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
- if (!$check)
-
- 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.');
-
- if (!php_version_check())
- 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.');
- if (!db_version_check())
- 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.');
-
- if (!empty($databases[$db_type]['alter_support']) && $smcFunc['db_query']('alter_boards', 'ALTER TABLE {db_prefix}boards ORDER BY id_board', array()) === false)
- 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.');
-
- $temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
- preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
- if (empty($match[1]) || $match[1] != SMF_VERSION)
- 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.');
-
- $writable_files = array(
- $boarddir . '/Settings.php',
- $boarddir . '/Settings_bak.php',
- );
- require_once($sourcedir . '/Security.php');
- createToken('login');
-
- $cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
- if (!file_exists($cachedir_temp))
- @mkdir($cachedir_temp);
- if (!file_exists($cachedir_temp))
- return throw_error('The cache directory could not be found.<br /><br />Please make sure you have a directory called "cache" in your forum directory before continuing.');
- if (!file_exists($boarddir . '/Themes/default/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
- 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>.');
- elseif (!isset($_GET['skiplang']))
- {
- $temp = substr(@implode('', @file($boarddir . '/Themes/default/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
- preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
- if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
- 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 /> [<a href="' . $upgradeurl . '?skiplang">SKIP</a>] [<a href="' . $upgradeurl . '?lang=english">Try English</a>]');
- }
-
- if (!file_exists($boarddir . '/Themes/default/languages/Install.' . $upcontext['language'] . '.php'))
- return throw_error('The upgrader could not find the "Install" 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 /> [<a href="' . $upgradeurl . '?lang=english">Try English</a>]');
- else
- require_once($boarddir . '/Themes/default/languages/Install.' . $upcontext['language'] . '.php');
- if (!makeFilesWritable($writable_files))
- return false;
-
- if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
- 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.');
-
- elseif (isset($modSettings['agreement']))
- {
- $fp = fopen($boarddir . '/agreement.txt', 'w');
- fwrite($fp, $modSettings['agreement']);
- fclose($fp);
- }
-
- if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => '')))
- $upcontext['warning'] = '
- It looks as if your board directory settings <em>might</em> be incorrect. Your board directory is currently set to "' . $boarddir . '" but should probably be "' . dirname(__FILE__) . '". Settings.php currently lists your paths as:<br />
- <ul>
- <li>Board Directory: ' . $boarddir . '</li>
- <li>Source Directory: ' . $boarddir . '</li>
- <li>Cache Directory: ' . $cachedir_temp . '</li>
- </ul>
- 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.';
-
- if (checkLogin())
- return true;
- return false;
- }
- function checkLogin()
- {
- global $boarddir, $sourcedir, $db_prefix, $language, $modSettings, $cachedir, $upgradeurl, $upcontext, $disable_security;
- global $smcFunc, $db_type, $databases, $support_js, $txt;
-
- if (isset($_POST['contbutt']) && (!empty($_POST['user']) || $disable_security))
- {
-
- if (empty($_POST['user']))
- $_POST['user'] = 'Administrator';
-
- $oldDB = false;
- if (empty($db_type) || $db_type == 'mysql')
- {
- $request = $smcFunc['db_query']('', '
- SHOW COLUMNS
- FROM {db_prefix}members
- LIKE {string:member_name}',
- array(
- 'member_name' => 'memberName',
- 'db_error_skip' => true,
- )
- );
- if ($smcFunc['db_num_rows']($request) != 0)
- $oldDB = true;
- $smcFunc['db_free_result']($request);
- }
-
- if (!$disable_security)
- {
- if ($oldDB)
- $request = $smcFunc['db_query']('', '
- SELECT id_member, memberName AS member_name, passwd, id_group,
- additionalGroups AS additional_groups, lngfile
- FROM {db_prefix}members
- WHERE memberName = {string:member_name}',
- array(
- 'member_name' => $_POST['user'],
- 'db_error_skip' => true,
- )
- );
- else
- $request = $smcFunc['db_query']('', '
- SELECT id_member, member_name, passwd, id_group, additional_groups, lngfile
- FROM {db_prefix}members
- WHERE member_name = {string:member_name}',
- array(
- 'member_name' => $_POST['user'],
- 'db_error_skip' => true,
- )
- );
- if ($smcFunc['db_num_rows']($request) != 0)
- {
- list ($id_member, $name, $password, $id_group, $addGroups, $user_language) = $smcFunc['db_fetch_row']($request);
- $groups = explode(',', $addGroups);
- $groups[] = $id_group;
- foreach ($groups as $k => $v)
- $groups[$k] = (int) $v;
-
- if (isset($_REQUEST['hash_passwrd']) && strlen($_REQUEST['hash_passwrd']) == 40)
- {
-
- if ($_REQUEST['hash_passwrd'] == sha1($password . $upcontext['rid']))
- $sha_passwd = $password;
- }
- else
- $sha_passwd = sha1(strtolower($name) . un_htmlspecialchars($_REQUEST['passwrd']));
- }
- else
- $upcontext['username_incorrect'] = true;
- $smcFunc['db_free_result']($request);
- }
- $upcontext['username'] = $_POST['user'];
-
- if (!empty($_POST['js_works']))
- {
- $upcontext['upgrade_status']['js'] = 1;
- $support_js = 1;
- }
- else
- $support_js = 0;
-
- if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version']))
- $upcontext['user']['version'] = $modSettings['smfVersion'];
-
- if ((empty($sha_passwd) || $password != $sha_passwd) && empty($upcontext['username_incorrect']) && !$disable_security)
- {
-
- $md5pass = md5_hmac($_REQUEST['passwrd'], strtolower($_POST['user']));
- if ($md5pass != $password)
- {
- $upcontext['password_failed'] = true;
-
- $upcontext['disable_login_hashing'] = true;
- }
- }
- if ((empty($upcontext['password_failed']) && !empty($name)) || $disable_security)
- {
-
- if (!$disable_security)
- {
-
- if (!in_array(1, $groups))
- {
- $request = $smcFunc['db_query']('', '
- SELECT permission
- FROM {db_prefix}permissions
- WHERE id_group IN ({array_int:groups})
- AND permission = {string:admin_forum}',
- array(
- 'groups' => $groups,
- 'admin_forum' => 'admin_forum',
- 'db_error_skip' => true,
- )
- );
- if ($smcFunc['db_num_rows']($request) == 0)
- return throw_error('You need to be an admin to perform an upgrade!');
- $smcFunc['db_free_result']($request);
- }
- $upcontext['user']['id'] = $id_member;
- $upcontext['user']['name'] = $name;
- }
- else
- {
- $upcontext['user']['id'] = 1;
- $upcontext['user']['name'] = 'Administrator';
- }
- $upcontext['user']['pass'] = mt_rand(0,60000);
-
- $upcontext['upgrade_status']['pass'] = $upcontext['user']['pass'];
-
- if (isset($user_language) && $user_language != $upcontext['language'] && file_exists($boarddir . '/Themes/default/languages/index.' . basename($user_language, '.lng') . '.php'))
- {
- $user_language = basename($user_language, '.lng');
- $temp = substr(@implode('', @file($boarddir . '/Themes/default/languages/index.' . $user_language . '.php')), 0, 4096);
- preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
- if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
- $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'] . '.';
- elseif (!file_exists($boarddir . '/Themes/default/languages/Install.' . basename($user_language, '.lng') . '.php'))
- $upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been uploaded/updated as the "Install" language file is missing. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.';
- else
- {
-
- $upcontext['language'] = $user_language;
- $upcontext['upgrade_status']['lang'] = $upcontext['language'];
-
- require_once($boarddir . '/Themes/default/languages/Install.' . $user_language . '.php');
- }
- }
-
- if (isset($_POST['cont']))
- {
- $upcontext['current_step'] = $upcontext['user']['step'];
- $_GET['substep'] = $upcontext['user']['substep'];
- }
- return true;
- }
- }
- return false;
- }
- function UpgradeOptions()
- {
- global $db_prefix, $command_line, $modSettings, $is_debug, $smcFunc;
- global $boarddir, $boardurl, $sourcedir, $maintenance, $mmessage, $cachedir, $upcontext, $db_type;
- $upcontext['sub_template'] = 'upgrade_options';
- $upcontext['page_title'] = 'Upgrade Options';
-
- if (empty($_POST['upcont']))
- return false;
-
- if (!empty($_POST['stats']) && substr($boardurl, 0, 16) != 'http://localhost' && empty($modSettings['allow_sm_stats']))
- {
-
- $fp = @fsockopen('www.simplemachines.org', 80, $errno, $errstr);
- if ($fp)
- {
- $out = 'GET /smf/stats/register_stats.php?site=' . base64_encode($boardurl) . ' HTTP/1.1' . "\r\n";
- $out .= 'Host: www.simplemachines.org' . "\r\n";
- $out .= 'Connection: Close' . "\r\n\r\n";
- fwrite($fp, $out);
- $return_data = '';
- while (!feof($fp))
- $return_data .= fgets($fp, 128);
- fclose($fp);
-
- preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID);
- if (!empty($ID[1]))
- $smcFunc['db_insert']('replace',
- $db_prefix . 'settings',
- array('variable' => 'string', 'value' => 'string'),
- array('allow_sm_stats', $ID[1]),
- array('variable')
- );
- }
- }
- else
- $smcFunc['db_query']('', '
- DELETE FROM {db_prefix}settings
- WHERE variable = {string:allow_sm_stats}',
- array(
- 'allow_sm_stats' => 'allow_sm_stats',
- 'db_error_skip' => true,
- )
- );
-
- if (!empty($_POST['empty_error']))
- $smcFunc['db_query']('truncate_table', '
- TRUNCATE {db_prefix}log_errors',
- array(
- )
- );
- $changes = array();
-
- if (isset($_GET['lang']) && file_exists($boarddir . '/Themes/default/languages/index.' . $_GET['lang'] . '.php'))
- $changes['language'] = '\'' . $_GET['lang'] . '\'';
- if (!empty($_POST['maint']))
- {
- $changes['maintenance'] = '2';
-
- $upcontext['user']['main'] = $maintenance;
- if (!empty($_POST['maintitle']))
- {
- $changes['mtitle'] = '\'' . addslashes($_POST['maintitle']) . '\'';
- $changes['mmessage'] = '\'' . addslashes($_POST['mainmessage']) . '\'';
- }
- else
- {
- $changes['mtitle'] = '\'Upgrading the forum...\'';
- $changes['mmessage'] = '\'Don\\\'t worry, we will be back shortly with an updated forum. It will only be a minute ;).\'';
- }
- }
- if ($command_line)
- echo ' * Updating Settings.php...';
-
- copy($boarddir . '/Settings.php', $boarddir . '/Settings_bak.php');
-
- if (substr($boarddir, 0, 1) == '.')
- $changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
- if (substr($sourcedir, 0, 1) == '.')
- $changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
- if (empty($cachedir) || substr($cachedir, 0, 1) == '.')
- $changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
-
- if (empty($db_type))
- $changes['db_type'] = 'mysql';
-
-
- changeSettings($changes);
- if ($command_line)
- echo ' Successful.' . "\n";
-
- if (isset($_POST['debug']))
- {
- $upcontext['upgrade_status']['debug'] = true;
- $is_debug = true;
- }
-
- if (empty($_POST['backup']))
- $upcontext['current_step']++;
-
- return true;
- }
- function BackupDatabase()
- {
- global $upcontext, $db_prefix, $command_line, $is_debug, $support_js, $file_steps, $smcFunc;
- $upcontext['sub_template'] = isset($_GET['xml']) ? 'backup_xml' : 'backup_database';
- $upcontext['page_title'] = 'Backup Database';
-
- if (!empty($_POST['backup_done']))
- return true;
-
- db_extend();
-
- $filter = str_replace('_', '\_', preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) != 0 ? $match[2] : $db_prefix) . '%';
- $db = preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) != 0 ? strtr($match[1], array('`' => '')) : false;
- $tables = $smcFunc['db_list_tables']($db, $filter);
- $table_names = array();
- foreach ($tables as $table)
- if (substr($table, 0, 7) !== 'backup_')
- $table_names[] = $table;
- $upcontext['table_count'] = count($table_names);
- $upcontext['cur_table_num'] = $_GET['substep'];
- $upcontext['cur_table_name'] = str_replace($db_prefix, '', isset($table_names[$_GET['substep']]) ? $table_names[$_GET['substep']] : $table_names[0]);
- $upcontext['step_progress'] = (int) (($upcontext['cur_table_num'] / $upcontext['table_count']) * 100);
-
- $file_steps = $upcontext['table_count'];
-
- foreach ($table_names as $id => $table)
- if ($id < $_GET['substep'])
- $upcontext['previous_tables'][] = $table;
- if ($command_line)
- echo 'Backing Up Tables.';
-
- if (!$support_js || isset($_GET['xml']))
- {
-
- for ($substep = $_GET['substep'], $n = count($table_names); $substep < $n; $substep++)
- {
- $upcontext['cur_table_name'] = str_replace($db_prefix, '', (isset($table_names[$substep + 1]) ? $table_names[$substep + 1] : $table_names[$substep]));
- $upcontext['cur_table_num'] = $substep + 1;
- $upcontext['step_progress'] = (int) (($upcontext['cur_table_num'] / $upcontext['table_count']) * 100);
-
- nextSubstep($substep);
- backupTable($table_names[$substep]);
-
- if (isset($_GET['xml']))
- return upgradeExit();
- }
- if ($is_debug && $command_line)
- {
- echo "\n" . ' Successful.\'' . "\n";
- flush();
- }
- $upcontext['step_progress'] = 100;
- $_GET['substep'] = 0;
-
- return true;
- }
-
- $_GET['substep'] = 0;
- return false;
- }
- function backupTable($table)
- {
- global $is_debug, $command_line, $db_prefix, $smcFunc;
- if ($is_debug && $command_line)
- {
- echo "\n" . ' +++ Backing up \"' . str_replace($db_prefix, '', $table) . '"...';
- flush();
- }
- $smcFunc['db_backup_table']($table, 'backup_' . $table);
- if ($is_debug && $command_line)
- echo ' done.';
- }
- function DatabaseChanges()
- {
- global $db_prefix, $modSettings, $command_line, $smcFunc;
- global $language, $boardurl, $sourcedir, $boarddir, $upcontext, $support_js, $db_type;
-
- if (!empty($_POST['database_done']))
- return true;
- $upcontext['sub_template'] = isset($_GET['xml']) ? 'database_xml' : 'database_changes';
- $upcontext['page_title'] = 'Database Changes';
-
-
- $files = array(
- array('upgrade_1-0.sql', '1.1', '1.1 RC0'),
- array('upgrade_1-1.sql', '2.0', '2.0 a'),
- array('upgrade_2-0_' . $db_type . '.sql', '2.1', '2.1 dev0'),
- array('upgrade_2-1_' . $db_type . '.sql', '3.0', SMF_VERSION),
- );
-
- if (isset($_GET['filecount']))
- $upcontext['file_count'] = (int) $_GET['filecount'];
- else
- {
- $upcontext['file_count'] = 0;
- foreach ($files as $file)
- {
- if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1])
- $upcontext['file_count']++;
- }
- }
-
- $did_not_do = count($files) - $upcontext['file_count'];
- $upcontext['step_progress'] = 0;
- $upcontext['cur_file_num'] = 0;
- foreach ($files as $file)
- {
- if ($did_not_do)
- $did_not_do--;
- else
- {
- $upcontext['cur_file_num']++;
- $upcontext['cur_file_name'] = $file[0];
-
- if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1])
- {
- $nextFile = parse_sql(dirname(__FILE__) . '/' . $file[0]);
- if ($nextFile)
- {
-
- $smcFunc['db_insert']('replace',
- $db_prefix . 'settings',
- array('variable' => 'string', 'value' => 'string'),
- array('smfVersion', $file[2]),
- array('variable')
- );
- $modSettings['smfVersion'] = $file[2];
- }
-
- if (isset($_GET['xml']))
- {
-
- $upcontext['completed_step'] = true;
-
- if ($nextFile)
- $upcontext['current_debug_item_num'] = -1;
- return upgradeExit();
- }
- elseif ($support_js)
- break;
- }
-
- $upcontext['step_progress'] = ($upcontext['cur_file_num'] / $upcontext['file_count']) * 100;
- }
- }
- $_GET['substep'] = 0;
-
- if (!$support_js)
- {
- $upcontext['changes_complete'] = true;
-
- if ($command_line)
- return DeleteUpgrade();
- return true;
- }
- return false;
- }
- function CleanupMods()
- {
- global $db_prefix, $modSettings, $upcontext, $boarddir, $sourcedir, $settings, $smcFunc, $command_line;
-
- if ($command_line)
- return true;
-
- if (!empty($_POST['skip']))
- {
- unset($_POST['skip']);
- return true;
- }
-
- if (!isset($_GET['ssi']) || !function_exists('mktree'))
- redirectLocation('&ssi=1');
- $upcontext['sub_template'] = 'clean_mods';
- $upcontext['page_title'] = 'Cleanup Modifications';
-
- $upcontext['skip'] = true;
-
- if (isset($_POST['cleandone2']))
- return true;
-
- if (isset($_POST['writable_files']))
- {
- $writable_files = unserialize(base64_decode($_POST['writable_files']));
- if (!makeFilesWritable($writable_files))
- {
-
- $upcontext['writable_files'] = $writable_files;
- return false;
- }
- }
-
- $request = $smcFunc['db_query']('', '
- SELECT id_theme, variable, value
- FROM {db_prefix}themes
- WHERE id_member = {int:id_member}
- AND variable IN ({string:theme_dir}, {string:images_url})',
- array(
- 'id_member' => 0,
- 'theme_dir' => 'theme_dir',
- 'images_url' => 'images_url',
- 'db_error_skip' => true,
- )
- );
- $theme_paths = array();
- while ($row = $smcFunc['db_fetch_assoc']($request))
- {
- if ($row['id_theme'] == 1)
- $settings['default_' . $row['variable']] = $row['value'];
- elseif ($row['variable'] == 'theme_dir')
- $theme_paths[$row['id_theme']][$row['variable']] = $row['value'];
- }
- $smcFunc['db_free_result']($request);
-
- $request = $smcFunc['db_query']('', '
- SELECT id_install, filename, name, themes_installed, version
- FROM {db_prefix}log_packages
- WHERE install_state = {int:installed}
- ORDER BY time_installed DESC',
- array(
- 'installed' => 1,
- 'db_error_skip' => true,
- )
- );
- $upcontext['packages'] = array();
- while ($row = $smcFunc['db_fetch_assoc']($request))
- {
-
- if (!file_exists($boarddir . '/Packages/' . $row['filename']))
- {
- $status = 'Missing';
- $status_color = 'red';
- $result = 'Removed';
- }
- else
- {
- $status = 'Installed';
- $status_color = 'green';
- $result = 'No Action Needed';
- }
- $upcontext['packages'][$row['id_install']] = array(
- 'id' => $row['id_install'],
- 'themes' => explode(',', $row['themes_installed']),
- 'name' => $row['name'],
- 'filename' => $row['filename'],
- 'missing_file' => file_exists($boarddir . '/Packages/' . $row['filename']) ? 0 : 1,
- 'files' => array(),
- 'file_count' => 0,
- 'status' => $status,
- 'result' => $result,
- 'color' => $status_color,
- 'version' => $row['version'],
- 'needs_removing' => false,
- );
- }
- $smcFunc['db_free_result']($request);
-
- if (empty($upcontext['packages']))
- return true;
-
- if (!empty($upcontext['user']['version']))
- $_SESSION['version_emulate'] = $upcontext['user']['version'];
-
- $oldErrorReporting = error_reporting(E_ALL ^ E_NOTICE);
- if (!mktree($boarddir . '/Packages/temp', 0755))
- {
- deltree($boarddir . '/Packages/temp', false);
- if (!mktree($boarddir . '/Packages/temp', 0777))
- {
- deltree($boarddir . '/Packages/temp', false);
-
- }
- }
-
- $reinstall_worked = array();
-
- $test = isset($_POST['cleandone']) ? false : true;
- foreach ($upcontext['packages'] as $id => $package)
- {
-
- if ($package['missing_file'])
- continue;
-
- if (!$test && (!isset($_POST['remove']) || !isset($_POST['remove'][$id])))
- continue;
-
- $cur_theme_paths = array();
- foreach ($theme_paths as $tid => $data)
- if ($tid != 1 && in_array($tid, $package['themes']))
- $cur_theme_paths[$tid] = $data;
-
- $filename = $package['filename'];
- $packageInfo = getPackageInfo($filename);
- if (!is_array($packageInfo))
- continue;
- $info = parsePackageInfo($packageInfo['xml'], $test, 'uninstall');
-
- if (isset($_POST['remove']))
- $infoInstall = parsePackageInfo($packageInfo['xml'], true);
- if (is_file($boarddir . '/Packages/' . $filename))
- read_tgz_file($boarddir . '/Packages/' . $filename, $boarddir . '/Packages/temp');
- else
- copytree($boarddir . '/Packages/' . $filename, $boarddir . '/Packages/temp');
-
- $files = array();
- foreach ($info as $change)
- {
-
-
-
- if ($change['type'] == 'modification')
- {
- $contents = @file_get_contents($boarddir . '/Packages/temp/' . $upcontext['base_path'] . $change['filename']);
- if ($change['boardmod'])
- $results = parseBoardMod($contents, $test, $change['reverse'], $cur_theme_paths);
- else
- $results = parseModification($contents, $test, $change['reverse'], $cur_theme_paths);
- foreach ($results as $action)
- {
-
- if (($action['type'] == 'replace' || $action['type'] == 'append' || (!empty($action['filename']) && $action['type'] == 'failure')) && !in_array($action['filename'], $files))
- $files[] = $action['filename'];
- if ($action['type'] == 'failure')
- {
- $upcontext['packages'][$id]['needs_removing'] = true;
- $upcontext['packages'][$id]['status'] = 'Reinstall Required';
- $upcontext['packages'][$id]['color'] = '#FD6435';
- }
- }
- }
- }
-
- $upcontext['packages'][$id]['files'] = $files;
- $upcontext['packages'][$id]['file_count'] = count($files);
-
- if (!$test)
- package_flush_cache();
-
- if (isset($_POST['remove']) && !$test && isset($infoInstall))
- {
-
- if (is_file($boarddir . '/Packages/' . $filename))
- read_tgz_file($boarddir . '/Packages/' . $filename, $boarddir . '/Packages/temp');
- else
- copytree($boarddir . '/Packages/' . $filename, $boarddir . '/Packages/temp');
- $errors = false;
- $upcontext['packages'][$id]['result'] = 'Removed';
- foreach ($infoInstall as $change)
- {
- if ($change['type'] == 'modification')
- {
- $contents = @file_get_contents($boarddir . '/Packages/temp/' . $upcontext['base_path'] . $change['filename']);
- if ($change['boardmod'])
- $results = parseBoardMod($contents, true, $change['reverse'], $cur_theme_paths);
- else
- $results = parseModification($contents, true, $change['reverse'], $cur_theme_paths);
-
- foreach ($results as $action)
- if ($action['type'] == 'failure')
- $errors = true;
- }
- }
- if (!$errors)
- {
- $reinstall_worked[] = $id;
- $upcontext['packages'][$id]['result'] = 'Reinstalled';
- $upcontext['packages'][$id]['color'] = 'green';
- foreach ($infoInstall as $change)
- {
- if ($change['type'] == 'modification')
- {
- $contents = @file_get_contents($boarddir . '/Packages/temp/' . $upcontext['base_path'] . $change['filename']);
- if ($change['boardmod'])
- $results = parseBoardMod($contents, false, $change['reverse'], $cur_theme_paths);
- else
- $results = parseModification($contents, false, $change['reverse'], $cur_theme_paths);
- }
- }
-
- package_flush_cache();
- }
- }
- }
-
- error_reporting($oldErrorReporting);
-
- if ($test && !empty($upcontext['packages']))
- {
- $writable_files = array();
- foreach ($upcontext['packages'] as $package)
- {
- if (!empty($package['files']))
- foreach ($package['files'] as $file)
- $writable_files[] = $file;
- }
- if (!empty($writable_files))
- {
- $writable_files = array_unique($writable_files);
- $upcontext['writable_files'] = $writable_files;
- if (!makeFilesWritable($writable_files))
- return false;
- }
- }
- if (file_exists($boarddir . '/Packages/temp'))
- deltree($boarddir . '/Packages/temp');
-
- if (isset($_POST['remove']))
- {
- $deletes = array();
- foreach ($_POST['remove'] as $id => $dummy)
- {
- if (!in_array((int) $id, $reinstall_worked))
- $deletes[] = (int) $id;
- }
- if (!empty($deletes))
- upgrade_query( '
- UPDATE ' . $db_prefix . 'log_packages
- SET install_state = 0
- WHERE id_install IN (' . implode(',', $deletes) . ')');
-
- package_put_contents($boarddir . '/Packages/installed.list', time());
- $upcontext['sub_template'] = 'cleanup_done';
- return false;
- }
- else
- {
- $allgood = true;
-
- foreach ($upcontext['packages'] as $package)
- if ($package['color'] != 'green')
- $allgood = false;
- if ($allgood)
- return true;
- }
- $_GET['substep'] = 0;
- return isset($_POST['cleandone']) ? true : false;
- }
- function DeleteUpgrade()
- {
- global $command_line, $language, $upcontext, $boarddir, $sourcedir, $forum_version, $user_info, $maintenance, $smcFunc, $db_type;
-
- if (!isset($_GET['ssi']) && !$command_line)
- redirectLocation('&ssi=1');
- $upcontext['sub_template'] = 'upgrade_complete';
- $upcontext['page_title'] = 'Upgrade Complete';
- $endl = $command_line ? "\n" : '<br />' . "\n";
- $changes = array(
- 'language' => '\'' . (substr($language, -4) == '.lng' ? substr($language, 0, -4) : $language) . '\'',
- 'db_error_send' => '1',
- 'upgradeData' => '#remove#',
- );
-
- if (isset($upcontext['user']['main']))
- {
- if ($command_line)
- echo ' * ';
- $upcontext['removed_maintenance'] = true;
- $changes['maintenance'] = $upcontext['user']['main'];
- }
-
- elseif (!empty($maintenance) && $maintenance == 2)
- $changes['maintenance'] = 1;
-
- $upcontext['user'] = array();
-
- copy($boarddir . '/Settings.php', $boarddir . '/Settings_bak.php');
- changeSettings($changes);
-
- clean_cache();
-
- $upcontext['can_delete_script'] = is_writable(dirname(__FILE__)) || is_writable(__FILE__);
-
- if ($command_line)
- cli_scheduled_fetchSMfiles();
- else
- {
- require_once($sourcedir . '/ScheduledTasks.php');
- $forum_version = SMF_VERSION;
- scheduled_fetchSMfiles();
- }
-
- if (empty($user_info['id']))
- $user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
-
- $smcFunc['db_insert']('',
- '{db_prefix}log_actions',
- array(
- 'log_time' => 'int', 'id_log' => 'int', 'id_member' => 'int', 'ip' => 'string-16', 'action' => 'string',
- 'id_board' => 'int', 'id_topic' => 'int', 'id_msg' => 'int', 'extra' => 'string-65534',
- ),
- array(
- time(), 3, $user_info['id'], $command_line ? '127.0.0.1' : $user_info['ip'], 'upgrade',
- 0, 0, 0, serialize(array('version' => $forum_version, 'member' => $user_info['id'])),
- ),
- array('id_action')
- );
- $user_info['id'] = 0;
-
- $server_version = $smcFunc['db_server_info']();
- if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
- updateSettings(array('db_mysql_group_by_fix' => '1'));
- if ($command_line)
- {
- echo $endl;
- echo 'Upgrade Complete!', $endl;
- echo 'Please delete this file as soon as possible for security reasons.', $endl;
- exit;
- }
-
- $upcontext['overall_percent'] = 100;
- if (isset($upcontext['step_progress']))
- unset($upcontext['step_progress']);
- $_GET['substep'] = 0;
- return false;
- }
- function cli_scheduled_fetchSMfiles()
- {
- global $sourcedir, $txt, $language, $settings, $forum_version, $modSettings, $smcFunc;
- if (empty($modSettings['time_format']))
- $modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
-
- $request = $smcFunc['db_query']('', '
- SELECT id_file, filename, path, parameters
- FROM {db_prefix}admin_info_files',
- array(
- )
- );
- $js_files = array();
- while ($row = $smcFunc['db_fetch_assoc']($request))
- {
- $js_files[$row['id_file']] = array(
- 'filename' => $row['filename'],
- 'path' => $row['path'],
- 'parameters' => sprintf($row['parameters'], $language, urlencode($modSettings['time_format']), urlencode($forum_version)),
- );
- }
- $smcFunc['db_free_result']($request);
-
- require_once($sourcedir . '/Subs-Package.php');
- foreach ($js_files as $ID_FILE => $file)
- {
-
- $server = empty($file['path']) || substr($file['path'], 0, 7) != 'http://' ? 'http://www.simplemachines.org' : '';
- $url = $server . (!empty($file['path']) ? $file['path'] : $file['path']) . $file['filename'] . (!empty($file['parameters']) ? '?' . $file['parameters'] : '');
-
- $file_data = fetch_web_data($url);
-
- if ($file_data === false)
- return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
-
- $smcFunc['db_query']('substring', '
- UPDATE {db_prefix}admin_info_files
- SET data = SUBSTRING({string:file_data}, 1, 65534)
- WHERE id_file = {int:id_file}',
- array(
- 'id_file' => $ID_FILE,
- 'file_data' => $file_data,
- )
- );
- }
- return true;
- }
- function convertSettingsToTheme()
- {
- global $db_prefix, $modSettings, $smcFunc;
- $values = array(
- 'show_latest_member' => @$GLOBALS['showlatestmember'],
- 'show_bbc' => isset($GLOBALS['showyabbcbutt']) ? $GLOBALS['showyabbcbutt'] : @$GLOBALS['showbbcbutt'],
- 'show_modify' => @$GLOBALS['showmodify'],
- 'show_user_images' => @$GLOBALS['showuserpic'],
- 'show_blurb' => @$GLOBALS['showusertext'],
- 'show_gender' => @$GLOBALS['showgenderimage'],
- 'show_newsfader' => @$GLOBALS['shownewsfader'],
- 'display_recent_bar' => @$GLOBALS['Show_RecentBar'],
- 'show_member_bar' => @$GLOBALS['Show_MemberBar'],
- 'linktree_link' => @$GLOBALS['curposlinks'],
- 'show_profile_buttons' => @$GLOBALS['profilebutton'],
- 'show_mark_read' => @$GLOBALS['showmarkread'],
- 'show_board_desc' => @$GLOBALS['ShowBDescrip'],
- 'newsfader_time' => @$GLOBALS['fadertime'],
- 'use_image_buttons' => empty($GLOBALS['MenuType']) ? 1 : 0,
- 'enable_news' => @$GLOBALS['enable_news'],
- 'return_to_post' => @$modSettings['returnToPost'],
- );
- $themeData = array();
- foreach ($values as $variable => $value)
- {
- if (!isset($value) || $value === null)
- $value = 0;
- $themeData[] = array(0, 1, $variable, $value);
- }
- if (!empty($themeData))
- {
- $smcFunc['db_insert']('ignore',
- $db_prefix . 'themes',
- array('id_member' => 'int', 'id_theme' => 'int', 'variable' => 'string', 'value' => 'string'),
- $themeData,
- array('id_member', 'id_theme', 'variable')
- );
- }
- }
- function convertSettingstoOptions()
- {
- global $db_prefix, $modSettings, $smcFunc;
-
- $values = array(
- 'calendar_start_day' => 'cal_startmonday',
- 'view_newest_first' => 'viewNewestFirst',
- 'view_newest_pm_first' => 'viewNewestFirst',
- );
- foreach ($values as $variable => $value)
- {
- if (empty($modSettings[$value[0]]))
- continue;
- $smcFunc['db_query']('', '
- INSERT IGNORE INTO {db_prefix}themes
- (id_member, id_theme, variable, value)
- SELECT id_member, 1, {string:variable}, {string:value}
- FROM {db_prefix}members',
- array(
- 'variable' => $variable,
- 'value' => $modSettings[$value[0]],
- 'db_error_skip' => true,
- )
- );
- $smcFunc['db_query']('', '
- INSERT IGNORE INTO {db_prefix}themes
- (id_member, id_theme, variable, value)
- VALUES (-1, 1, {string:variable}, {string:value})',
- array(
- 'variable' => $variable,
- 'value' => $modSettings[$value[0]],
- 'db_error_skip' => true,
- )
- );
- }
- }
- function changeSettings($config_vars)
- {
- global $boarddir;
- $settingsArray = file($boarddir . '/Settings_bak.php');
- if (count($settingsArray) == 1)
- $settingsArray = preg_split('~[\r\n]~', $settingsArray[0]);
- for ($i = 0, $n = count($settingsArray); $i < $n; $i++)
- {
-
- if (substr($settingsArray[$i], 0, 1) == '$')
- {
- $settingsArray[$i] = trim($settingsArray[$i]) . "\n";
- foreach ($config_vars as $var => $val)
- {
- if (isset($settingsArray[$i]) && strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
- {
- if ($val == '#remove#')
- unset($settingsArray[$i]);
- else
- {
- $comment = strstr(substr($settingsArray[$i], strpos($settingsArray[$i], ';')), '#');
- $settingsArray[$i] = '$' . $var . ' = ' . $val . ';' . ($comment != '' ? "\t\t" . $comment : "\n");
- }
- unset($config_vars[$var]);
- }
- }
- }
- if (isset($settingsArray[$i]))
- {
- if (trim(substr($settingsArray[$i], 0, 2)) == '?' . '>')
- $end = $i;
- }
- }
-
- if (empty($end) || $end < 10)
- $end = count($settingsArray);
- if (!empty($config_vars))
- {
- $settingsArray[$end++] = '';
- foreach ($config_vars as $var => $val)
- {
- if ($val != '#remove#')
- $settingsArray[$end++] = '$' . $var . ' = ' . $val . ';' . "\n";
- }
- }
-
- $settingsArray[$end] = '?' . '>';
-
- $fp = fopen($boarddir . '/Settings.php', 'w');
- fclose($fp);
- $fp = fopen($boarddir . '/Settings.php', 'r+');
- for ($i = 0; $i < $end; $i++)
- {
- if (isset($settingsArray[$i]))
- fwrite($fp, strtr($settingsArray[$i], "\r", ''));
- }
- fwrite($fp, rtrim($settingsArray[$i]));
- fclose($fp);
- }
- function updateLastError()
- {
-
- file_put_contents(dirname(__FILE__) . '/db_last_error.php', '<' . '?' . "php\n" . '$db_last_error = 0;' . "\n" . '?' . '>');
- }
- function php_version_check()
- {
- $minver = explode('.', $GLOBALS['required_php_version']);
- $curver = explode('.', PHP_VERSION);
- return !(($curver[0] <= $minver[0]) && ($curver[1] <= $minver[1]) && ($curver[1] <= $minver[1]) && ($curver[2][0] < $minver[2][0]));
- }
- function db_version_check()
- {
- global $db_type, $databases;
- $curver = eval($databases[$db_type]['version_check']);
- $curver = preg_replace('~\-.+?$~', '', $curver);
- return version_compare($databases[$db_type]['version'], $curver, '<=');
- }
- function getMemberGroups()
- {
- global $db_prefix, $smcFunc;
- static $member_groups = array();
- if (!empty($member_groups))
- return $member_groups;
- $request = $smcFunc['db_query']('', '
- SELECT group_name, id_group
- FROM {db_prefix}membergroups
- WHERE id_group = {int:admin_group} OR id_group > {int:old_group}',
- array(
- 'admin_group' => 1,
- 'old_group' => 7,
- 'db_error_skip' => true,
- )
- );
- if ($request === false)
- {
- $request = $smcFunc['db_query']('', '
- SELECT membergroup, id_group
- FROM {db_prefix}membergroups
- WHERE id_group = {int:admin_group} OR id_group > {int:old_group}',
- array(
- 'admin_group' => 1,
- 'old_group' => 7,
- 'db_error_skip' => true,
- )
- );
- }
- while ($row = $smcFunc['db_fetch_row']($request))
- $member_groups[trim($row[0])] = $row[1];
- $smcFunc['db_free_result']($request);
- return $member_groups;
- }
- function fixRelativePath($path)
- {
- global $install_path;
-
- return addslashes(preg_replace(array('~^\.([/\\\]|$)~', '~[/]+~', '~[\\\]+~', '~[/\\\]$~'), array($install_path . '$1', '/', '\\', ''), $path));
- }
- function parse_sql($filename)
- {
- global $db_prefix, $db_collation, $boarddir, $boardurl, $command_line, $file_steps, $step_progress, $custom_warning;
- global $upcontext, $support_js, $is_debug, $smcFunc, $db_connection, $databases, $db_type, $db_character_set;
-
- db_extend();
- db_extend('packages');
-
- if (!function_exists('sql_error_handler'))
- {
- function sql_error_handler($errno, $errstr, $errfile, $errline)
- {
- global $support_js;
- if ($support_js)
- return true;
- else
- echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
- }
- }
-
- set_error_handler('sql_error_handler');
-
- if (!empty($databases[$db_type]['utf8_support']) && version_compare($databases[$db_type]['utf8_version'], eval($databases[$db_type]['utf8_version_check']), '>'))
- {
- $request = $smcFunc['db_query']('', '
- SHOW TABLE STATUS
- LIKE {string:table_name}',
- array(
- 'table_name' => "{$db_prefix}members",
- 'db_error_skip' => true,
- )
- );
- if ($smcFunc['db_num_rows']($request) === 0)
- die('Unable to find members table!');
- $table_status = $smcFunc['db_fetch_assoc']($request);
- $smcFunc['db_free_result']($request);
- if (!empty($table_status['Collation']))
- {
- $request = $smcFunc['db_query']('', '
- SHOW COLLATION
- LIKE {string:collation}',
- array(
- 'collation' => $table_status['Collation'],
- 'db_error_skip' => true,
- )
- );
-
- if ($smcFunc['db_num_rows']($request) !== 0)
- $collation_info = $smcFunc['db_fetch_assoc']($request);
- $smcFunc['db_free_result']($request);
-
- if (!empty($collation_info['Collation']) && !empty($collation_info['Charset']))
- $db_collation = ' CHARACTER SET ' . $collation_info['Charset'] . ' COLLATE ' . $collation_info['Collation'];
- }
- }
- if (empty($db_collation))
- $db_collation = '';
- $endl = $command_line ? "\n" : '<br />' . "\n";
- $lines = file($filename);
- $current_type = 'sql';
- $current_data = '';
- $substep = 0;
- $last_step = '';
-
- if (isset($db_character_set) && $db_character_set === 'utf8')
- $lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
-
- $file_steps = substr_count(implode('', $lines), '---#');
- $upcontext['total_items'] = substr_count(implode('', $lines), '--- ');
- $upcontext['debug_items'] = $file_steps;
- $upcontext['current_item_num'] = 0;
- $upcontext['current_item_name'] = '';
- $upcontext['current_debug_item_num'] = 0;
- $upcontext['current_debug_item_name'] = '';
-
- $upcontext['actioned_items'] = array();
- $done_something = false;
- foreach ($lines as $line_number => $line)
- {
- $do_current = $substep >= $_GET['substep'];
-
- if (substr(trim($line), 0, 2) === '/*')
- $line = preg_replace('~/\*.+?\*/~', '', $line);
-
- if ($is_debug && !$support_js && $command_line)
- flush();
- if (trim($line) === '')
- continue;
- if (trim(substr($line, 0, 3)) === '---')
- {
- $type = substr($line, 3, 1);
-
- if (trim($current_data) != '' && $type !== '}')
- {
- $upcontext['error_message'] = 'Error in upgrade script - line ' . $line_number . '!' . $endl;
- if ($command_line)
- echo $upcontext['error_message'];
- }
- if ($type == ' ')
- {
- if (!$support_js && $do_current && $_GET['substep'] != 0 && $command_line)
- {
- echo ' Successful.', $endl;
- flush();
- }
- $last_step = htmlspecialchars(rtrim(substr($line, 4)));
- $upcontext['current_item_num']++;
- $upcontext['current_item_name'] = $last_step;
- if ($do_current)
- {
- $upcontext['actioned_items'][] = $last_step;
- if ($command_line)
- echo ' * ';
- }
- }
- elseif ($type == '#')
- {
- $upcontext['step_progress'] += (100 / $upcontext['file_count']) / $file_steps;
- $upcontext['current_debug_item_num']++;
- if (trim($line) != '---#')
- $upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
-
- if (isset($_GET['xml']) && $done_something)
- {
- restore_error_handler();
- return $upcontext['current_debug_item_num'] >= $upcontext['debug_items'] ? true : false;
- }
- if ($do_current)
- {
- if (trim($line) == '---#' && $command_line)
- echo ' done.', $endl;
- elseif ($command_line)
- echo ' +++ ', rtrim(substr($line, 4));
- elseif (trim($line) != '---#')
- {
- if ($is_debug)
- $upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
- }
- }
- if ($substep < $_GET['substep'] && $substep + 1 >= $_GET['substep'])
- {
- if ($command_line)
- echo ' * ';
- else
- $upcontext['actioned_items'][] = $last_step;
- }
-
- if ($do_current)
- nextSubstep(++$substep);
- else
- $substep++;
- }
- elseif ($type == '{')
- $current_type = 'code';
- elseif ($type == '}')
- {
- $current_type = 'sql';
- if (!$do_current)
- {
- $current_data = '';
- continue;
- }
- if (eval('global $db_prefix, $modSettings, $smcFunc; ' . $current_data) === false)
- {
- $upcontext['error_message'] = 'Error in upgrade script ' . basename($filename) . ' on line ' . $line_number . '!' . $endl;
- if ($command_line)
- echo $upcontext['error_message'];
- }
-
- $current_data = '';
- $done_something = true;
- }
- continue;
- }
- $current_data .= $line;
- if (substr(rtrim($current_data), -1) === ';' && $current_type === 'sql')
- {
- if ((!$support_js || isset($_GET['xml'])))
- {
- if (!$do_current)
- {
- $current_data = '';
- continue;
- }
- $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));
- upgrade_query($current_data);
-
-
- $done_something = true;
- }
- $current_data = '';
- }
-
- elseif ($support_js && !isset($_GET['xml']) && $upcontext['current_debug_item_name'] != '' && $do_current)
- {
- restore_error_handler();
- return false;
- }
-
- $step_progress = array();
- $custom_warning = '';
- }
-
- restore_error_handler();
- if ($command_line)
- {
- echo ' Successful.' . "\n";
- flush();
- }
- $_GET['substep'] = 0;
- return true;
- }
- function upgrade_query($string, $unbuffered = false)
- {
- global $db_connection, $db_server, $db_user, $db_passwd, $db_type, $command_line, $upcontext, $upgradeurl, $modSettings;
- global $db_name, $db_unbuffered, $smcFunc;
-
- $modSettings['disableQueryCheck'] = true;
- $db_unbuffered = $unbuffered;
- $result = $smcFunc['db_query']('', $string, 'security_override');
- $db_unbuffered = false;
-
- if ($result !== false)
- return $result;
- $db_error_message = $smcFunc['db_error']($db_connection);
-
- if ($db_type == 'mysql')
- {
- $mysql_errno = mysql_errno($db_connection);
- $error_query = in_array(substr(trim($string), 0, 11), array('INSERT INTO', 'UPDATE IGNO', 'ALTER TABLE', 'DROP TABLE ', 'ALTER IGNOR'));
-
-
-
-
-
-
-
-
-
-
-
-
- if ($mysql_errno == 1016)
- {
- if (preg_match('~\'([^\.\']+)~', $db_error_message, $match) != 0 && !empty($match[1]))
- mysql_query( '
- REPAIR TABLE `' . $match[1] . '`');
- $result = mysql_query($string);
- if ($result !== false)
- return $result;
- }
- elseif ($mysql_errno == 2013)
- {
- $db_connection = mysql_connect($db_server, $db_user, $db_passwd);
- mysql_select_db($db_name, $db_connection);
- if ($db_connection)
- {
- $result = mysql_query($string);
- if ($result !== false)
- return $result;
- }
- }
-
- elseif (in_array($mysql_errno, array(1060, 1061, 1068, 1091)))
- return false;
-
- elseif (in_array($mysql_errno, array(1054, 1062, 1146)) && $error_query)
- return false;
-
- elseif ($mysql_errno == 1072)
- return false;
- elseif ($mysql_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE')
- return false;
- }
-
- else
- {
- if (in_array(substr(trim($string), 0, 8), array('CREATE T', 'CREATE S', 'DROP TABL', 'ALTER TA', 'CREATE I')))
- {
- if (strpos($db_error_message, 'exist') !== false)
- return true;
-
- if (strpos($db_error_message, 'missing') !== false)
- return true;
- }
- elseif (strpos(trim($string), 'INSERT ') !== false)
- {
- if (strpos($db_error_message, 'duplicate') !== false)
- return true;
- }
- }
-
- $query_string = '';
- foreach ($_GET as $k => $v)
- $query_string .= ';' . $k . '=' . $v;
- if (strlen($query_string) != 0)
- $query_string = '?' . substr($query_string, 1);
- if ($command_line)
- {
- echo 'Unsuccessful! Database error message:', "\n", $db_error_message, "\n";
- die;
- }
-
- if (!empty($upcontext['return_error']))
- {
- $upcontext['error_message'] = $db_error_message;
- return false;
- }
-
- $upcontext['forced_error_message'] = '
- <strong>Unsuccessful!</strong><br />
- <div style="margin: 2ex;">
- This query:
- <blockquote><tt>' . nl2br(htmlspecialchars(trim($string))) . ';</tt></blockquote>
- Caused the error:
- <blockquote>' . nl2br(htmlspecialchars($db_error_message)) . '</blockquote>
- </div>
- <form action="' . $upgradeurl . $query_string . '" method="post">
- <input type="submit" value="Try again" class="button_submit" />
- </form>
- </div>';
- upgradeExit();
- }
- function protected_alter($change, $substep, $is_test = false)
- {
- global $db_prefix, $smcFunc;
- db_extend('packages');
-
- $found = false;
- if ($change['type'] === 'column')
- {
- $columns = $smcFunc['db_list_columns']('{db_prefix}' . $change['table'], true);
- foreach ($columns as $column)
- {
-
- if ($column['name'] === $change['name'])
- {
- $found |= 1;
-
- if (isset($change['col_type']))
- $found &= $change['col_type'] === $column['type'];
- if (isset($change['null_allowed']))
- $found &= $column['null'] == $change['null_allowed'];
- if (isset($change['default']))
- $found &= $change['default'] === $column['default'];
- }
- }
- }
- elseif ($change['type'] === 'index')
- {
- $request = upgrade_query( '
- SHOW INDEX
- FROM ' . $db_prefix . $change['table']);
- if ($request !== false)
- {
- $cur_index = array();
- while ($row = $smcFunc['db_fetch_assoc']($request))
- if ($row['Key_name'] === $change['name'])
- $cur_index[(int) $row['Seq_in_index']] = $row['Column_name'];
- ksort($cur_index, SORT_NUMERIC);
- $found = array_values($cur_index) === $change['target_columns'];
- $smcFunc['db_free_result']($request);
- }
- }
-
- if ($found && in_array($change['method'], array('add', 'change')))
- return true;
-
- elseif (!$found && in_array($change['method'], array('remove', 'change_remove')))
- return true;
-
- elseif ($is_test)
- return false;
-
- $running = false;
- $found = false;
- while (1 == 1)
- {
- $request = upgrade_query('
- SHOW FULL PROCESSLIST');
- while ($row = $smcFunc['db_fetch_assoc']($request))
- {
- if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false)
- $found = true;
- }
-
- if (!$found && !$running)
- {
- $smcFunc['db_free_result']($request);
- $success = upgrade_query('
- ALTER TABLE ' . $db_prefix . $change['table'] . '
- ' . $change['text'], true) !== false;
- if (!$success)
- return false;
-
- $running = true;
- }
-
- elseif (!$found)
- {
- $smcFunc['db_free_result']($request);
- return true;
- }
-
- sleep(3);
-
- nextSubstep($substep);
- }
-
- nextSubstep($substep);
- }
- function textfield_alter($change, $substep)
- {
- global $db_prefix, $databases, $db_type, $smcFunc;
-
- if (empty($databases[$db_type]['utf8_support']) || version_compare($databases[$db_type]['utf8_version'], eval($databases[$db_type]['utf8_version_check']), '>'))
- {
- $column_fix = true;
- $null_fix = !$change['null_allowed'];
- }
- else
- {
- $request = $smcFunc['db_query']('', '
- SHOW FULL COLUMNS
- FROM {db_prefix}' . $change['table'] . '
- LIKE {string:column}',
- array(
- 'column' => $change['column'],
- 'db_error_skip' => true,
- )
- );
- if ($smcFunc['db_num_rows']($request) === 0)
- die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
- $table_row = $smcFunc['db_fetch_assoc']($request);
- $smcFunc['db_free_result']($request);
-
- $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']);
-
- $null_fix = strtolower($table_row['Null']) === 'yes' && !$change['null_allowed'];
-
- if ($column_fix && !empty($table_row['Collation']))
- {
- $request = $smcFunc['db_query']('', '
- SHOW COLLATION
- LIKE {string:collation}',
- array(
- 'collation' => $table_row['Collation'],
- 'db_error_skip' => true,
- )
- );
-
- if ($smcFunc['db_num_rows']($request) === 0)
- unset($table_row['Collation']);
- else
- $collation_info = $smcFunc['db_fetch_assoc']($request);
- $smcFunc['db_free_result']($request);
- }
- }
- if ($column_fix)
- {
-
- if ($null_fix)
- $smcFunc['db_query']('', '
- UPDATE {db_prefix}' . $change['table'] . '
- SET ' . $change['column'] . ' = {string:default}
- WHERE ' . $change['column'] . ' IS NULL',
- array(
- 'default' => isset($change['default']) ? $change['default'] : '',
- 'db_error_skip' => true,
- )
- );
-
- $smcFunc['db_query']('', '
- ALTER TABLE {db_prefix}' . $change['table'] . '
- 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}' : ''),
- array(
- 'default' => isset($change['default']) ? $change['default'] : '',
- 'db_error_skip' => true,
- )
- );
- }
- nextSubstep($substep);
- }
- function checkChange(&$change)
- {
- global $smcFunc, $db_type, $databases;
- static $database_version, $where_field_support;
-
- if (empty($database_version))
- {
- $database_version = $databases[$db_type]['version_check'];
- $where_field_support = $db_type == 'mysql' && version_compare('5.0', $database_version, '<=');
- }
-
- if (!in_array($change['name'], array('memberGroups', 'passwordSalt')))
- return;
-
- $temp = explode(' ', str_replace('NOT NULL', 'NOT_NULL', $change['text']));
-
- if ($where_field_support)
- {
-
- $request = $smcFunc['db_query']('', '
- SHOW FIELDS
- FROM {db_prefix}{raw:table}
- WHERE Field = {string:old_name} OR Field = {string:new_name}',
- array(
- 'table' => $change['table'],
- 'old_name' => $temp[1],
- 'new_name' => $temp[2],
- ));
- if ($smcFunc['db_num_rows'] != 1)
- return;
- list (, $current_type) = $smcFunc['db_fetch_assoc']($request);
- $smcFunc['db_free_result']($request);
- }
- else
- {
-
- $request = $smcFunc['db_query']('', '
- SHOW FIELDS
- FROM {db_prefix}{raw:table}',
- array(
- 'table' => $change['table'],
- ));
-
- if ($smcFunc['db_num_rows'] == 0)
- return;
-
- while ($row = $smcFunc['db_query']($request))
- if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
- {
- $current_type = $row['Type'];
- break;
- }
- }
-
- if (trim($current_type) != trim($temp[3]))
- $temp[3] = $current_type;
-
- $change['text'] = str_replace('NOT_NULL', 'NOT NULL', implode(' ', $temp));
- }
- function nextSubstep($substep)
- {
- global $start_time, $timeLimitThreshold, $command_line, $file_steps, $modSettings, $custom_warning;
- global $step_progress, $is_debug, $upcontext;
- if ($_GET['substep'] < $substep)
- $_GET['substep'] = $substep;
- if ($command_line)
- {
- if (time() - $start_time > 1 && empty($is_debug))
- {
- echo '.';
- $start_time = time();
- }
- return;
- }
- @set_time_limit(300);
- if (function_exists('apache_reset_timeout'))
- @apache_reset_timeout();
- if (time() - $start_time <= $timeLimitThreshold)
- return;
-
- if (!empty($step_progress))
- {
- $upcontext['substep_progress'] = 0;
- $upcontext['substep_progress_name'] = $step_progress['name'];
- if ($step_progress['current'] > $step_progress['total'])
- $upcontext['substep_progress'] = 99.9;
- else
- $upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
-
- $upcontext['substep_progress'] = round($upcontext['substep_progress'], 1);
- }
-
- if (isset($_GET['xml']))
- return upgradeExit();
-
- $upcontext['pause'] = true;
- $upcontext['query_string'] = '';
- foreach ($_GET as $k => $v)
- {
- if ($k != 'data' && $k != 'substep' && $k != 'step')
- $upcontext['query_string'] .= ';' . $k . '=' . $v;
- }
-
- if (!empty($custom_warning))
- $upcontext['custom_warning'] = $custom_warning;
- upgradeExit();
- }
- function cmdStep0()
- {
- global $boarddir, $sourcedir, $db_prefix, $language, $modSettings, $start_time, $cachedir, $databases, $db_type, $smcFunc, $upcontext;
- global $language, $is_debug, $txt;
- $start_time = time();
- ob_end_clean();
- ob_implicit_flush(true);
- @set_time_limit(600);
- if (!isset($_SERVER['argv']))
- $_SERVER['argv'] = array();
- $_GET['maint'] = 1;
- foreach ($_SERVER['argv'] as $i => $arg)
- {
- if (preg_match('~^--language=(.+)$~', $arg, $match) != 0)
- $_GET['lang'] = $match[1];
- elseif (preg_match('~^--path=(.+)$~', $arg) != 0)
- continue;
- elseif ($arg == '--no-maintenance')
- $_GET['maint'] = 0;
- elseif ($arg == '--debug')
- $is_debug = true;
- elseif ($arg == '--backup')
- $_POST['backup'] = 1;
- elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($boarddir . '/Themes/converted')))
- $_GET['conv'] = 1;
- elseif ($i != 0)
- {
- echo 'SMF Command-line Upgrader
- Usage: /path/to/php -f ' . basename(__FILE__) . ' -- [OPTION]...
- --language=LANG Reset the forum\'s language to LANG.
- --no-maintenance Don\'t put the forum into maintenance mode.
- --debug Output debugging information.
- --backup Create backups of tables with "backup_" prefix.';
- echo "\n";
- exit;
- }
- }
- if (!php_version_check())
- print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
- if (!db_version_check())
- print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
- if (!empty($databases[$db_type]['alter_support']) && $smcFunc['db_query']('alter_boards', 'ALTER TABLE {db_prefix}boards ORDER BY id_board', array()) === false)
- print_error('Error: The ' . $databases[$db_type]['name'] . ' account in Settings.php does not have sufficient privileges.', true);
- $check = @file_exists($boarddir . '/Themes/default/index.template.php')
- && @file_exists($sourcedir . '/QueryString.php')
- && @file_exists($sourcedir . '/ManageBoards.php');
- if (!$check && !isset($modSettings['smfVersion']))
- print_error('Error: Some files are missing or out-of-date.', true);
-
- $temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
- preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
- if (empty($match[1]) || $match[1] != SMF_VERSION)
- print_error('Error: Some files have not yet been updated properly.');
-
- if (!is_writable($boarddir . '/Settings.php'))
- @chmod($boarddir . '/Settings.php', 0777);
- if (!is_writable($boarddir . '/Settings.php'))
- print_error('Error: Unable to obtain write access to "Settings.php".', true);
-
- if (!is_writable($boarddir . '/Settings_bak.php'))
- @chmod($boarddir . '/Settings_bak.php', 0777);
- if (!is_writable($boarddir . '/Settings_bak.php'))
- print_error('Error: Unable to obtain write access to "Settings_bak.php".');
- if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
- print_error('Error: Unable to obtain write access to "agreement.txt".');
- elseif (isset($modSettings['agreement']))
- {
- $fp = fopen($boarddir . '/agreement.txt', 'w');
- fwrite($fp, $modSettings['agreement']);
- fclose($fp);
- }
-
- if (!is_writable($boarddir . '/Themes'))
- @chmod($boarddir . '/Themes', 0777);
- if (!is_writable($boarddir . '/Themes') && !isset($modSettings['smfVersion']))
- print_error('Error: Unable to obtain write access to "Themes".');
-
- $cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
- if (!file_exists($cachedir_temp))
- @mkdir($cachedir_temp);
- if (!is_writable($cachedir_temp))
- @chmod($cachedir_temp, 0777);
- if (!is_writable($cachedir_temp))
- print_error('Error: Unable to obtain write access to "cache".', true);
- if (!file_exists($boarddir . '/Themes/default/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
- print_error('Error: Unable to find language files!', true);
- else
- {
- $temp = substr(@implode('', @file($boarddir . '/Themes/default/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
- preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
- if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
- print_error('Error: Language files out of date.', true);
- if (!file_exists($boarddir . '/Themes/default/languages/Install.' . $upcontext['language'] . '.php'))
- print_error('Error: Install language is missing for selected language.', true);
-
- require_once($boarddir . '/Themes/default/languages/Install.' . $upcontext['language'] . '.php');
- }
-
- $_POST['upcont'] = true;
- $upcontext['current_step'] = 1;
- }
- function print_error($message, $fatal = false)
- {
- static $fp = null;
- if ($fp === null)
- $fp = fopen('php://stderr', 'wb');
- fwrite($fp, $message . "\n");
- if ($fatal)
- exit;
- }
- function throw_error($message)
- {
- global $upcontext;
- $upcontext['error_msg'] = $message;
- $upcontext['sub_template'] = 'error_message';
- return false;
- }
- function makeFilesWritable(&$files)
- {
- global $upcontext, $boarddir;
- if (empty($files))
- return true;
- $failure = false;
-
- if (substr(__FILE__, 1, 2) != ':\\')
- {
- foreach ($files as $k => $file)
- {
- if (!is_writable($file))
- {
- @chmod($file, 0755);
-
- if (!is_writable($file) && !@chmod($file, 0777))
- $failure = true;
-
- else
- unset($files[$k]);
- }
- else
- unset($files[$k]);
- }
- }
-
- else
- {
- foreach ($files as $k => $file)
- {
-
- if (is_dir($file))
- $file .= '/index.php';
-
- @chmod($file, 0777);
- $fp = @fopen($file, 'r+');
-
- if (!$fp)
- $fp = @fopen($file, 'w');
- if (!$fp)
- $failure = true;
- else
- unset($files[$k]);
- @fclose($fp);
- }
- }
- if (empty($files))
- return true;
- if (!isset($_SERVER))
- return !$failure;
-
- $upcontext['chmod']['files'] = $files;
-
- if ($failure && substr(__FILE__, 1, 2) == ':\\')
- {
- $upcontext['chmod']['ftp_error'] = 'total_mess';
- return false;
- }
-
- elseif ($failure)
- {
-
- if (!isset($_POST['ftp_username']) && isset($_SESSION['installer_temp_ftp']))
- {
- $upcontext['chmod']['server'] = $_SESSION['installer_temp_ftp']['server'];
- $upcontext['chmod']['port'] = $_SESSION['installer_temp_ftp']['port'];
- $upcontext['chmod']['username'] = $_SESSION['installer_temp_ftp']['username'];
- $upcontext['chmod']['password'] = $_SESSION['installer_temp_ftp']['password'];
- $upcontext['chmod']['path'] = $_SESSION['installer_temp_ftp']['path'];
- }
-
- elseif (isset($_POST['ftp_username']))
- {
- $upcontext['chmod']['server'] = $_POST['ftp_server'];
- $upcontext['chmod']['port'] = $_POST['ftp_port'];
- $upcontext['chmod']['username'] = $_POST['ftp_username'];
- $upcontext['chmod']['password'] = $_POST['ftp_password'];
- $upcontext['chmod']['path'] = $_POST['ftp_path'];
- }
- if (isset($upcontext['chmod']['username']))
- {
- $ftp = new ftp_connection($upcontext['chmod']['server'], $upcontext['chmod']['port'], $upcontext['chmod']['username'], $upcontext['chmod']['password']);
- if ($ftp->error === false)
- {
-
- if (!$ftp->chdir($upcontext['chmod']['path']))
- {
- $upcontext['chmod']['ftp_error'] = $ftp->last_message;
- $ftp->chdir(preg_replace('~^/home[2]?/[^/]+?~', '', $upcontext['chmod']['path']));
- }
- }
- }
- if (!isset($ftp) || $ftp->error !== false)
- {
- if (!isset($ftp))
- $ftp = new ftp_connection(null);
-
- elseif ($ftp->error !== false && !isset($upcontext['chmod']['ftp_error']))
- $upcontext['chmod']['ftp_error'] = $ftp->last_message === null ? '' : $ftp->last_message;
- list ($username, $detect_path, $found_path) = $ftp->detect_path(dirname(__FILE__));
- if ($found_path || !isset($upcontext['chmod']['path']))
- $upcontext['chmod']['path'] = $detect_path;
- if (!isset($upcontext['chmod']['username']))
- $upcontext['chmod']['username'] = $username;
- return false;
- }
- else
- {
-
- if (!in_array($upcontext['chmod']['path'], array('', '/')))
- {
- $ftp_root = strtr($boarddir, array($upcontext['chmod']['path'] => ''));
- if (substr($ftp_root, -1) == '/' && ($upcontext['chmod']['path'] == '' || $upcontext['chmod']['path'][0] === '/'))
- $ftp_root = substr($ftp_root, 0, -1);
- }
- else
- $ftp_root = $boarddir;
-
- $_SESSION['installer_temp_ftp'] = array(
- 'server' => $upcontext['chmod']['server'],
- 'port' => $upcontext['chmod']['port'],
- 'username' => $upcontext['chmod']['username'],
- 'password' => $upcontext['chmod']['password'],
- 'path' => $upcontext['chmod']['path'],
- 'root' => $ftp_root,
- );
- foreach ($files as $k => $file)
- {
- if (!is_writable($file))
- $ftp->chmod($file, 0755);
- if (!is_writable($file))
- $ftp->chmod($file, 0777);
-
- if (!is_writable($file))
- {
- if (strpos($file, $boarddir) === 0)
- {
- $ftp_file = strtr($file, array($_SESSION['installer_temp_ftp']['root'] => ''));
- $ftp->chmod($ftp_file, 0755);
- if (!is_writable($file))
- $ftp->chmod($ftp_file, 0777);
-
- $ftp_file = '/' . $ftp_file;
- if (!is_writable($file))
- $ftp->chmod($ftp_file, 0755);
- if (!is_writable($file))
- $ftp->chmod($ftp_file, 0777);
- }
- }
- if (is_writable($file))
- unset($files[$k]);
- }
- $ftp->close();
- }
- }
-
- $upcontext['chmod']['files'] = $files;
- if (empty($files))
- return true;
- return false;
- }
- function template_chmod()
- {
- global $upcontext, $upgradeurl, $settings;
-
- if (!empty($upcontext['chmod_called']))
- return;
- $upcontext['chmod_called'] = true;
-
- if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error']))
- return;
-
- $txt['error_ftp_no_connect'] = 'Unable to connect to FTP server with this combination of details.';
- $txt['ftp_login'] = 'Your FTP connection information';
- $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.';
- $txt['ftp_server'] = 'Server';
- $txt['ftp_server_info'] = 'The address (often localhost) and port for your FTP server.';
- $txt['ftp_port'] = 'Port';
- $txt['ftp_username'] = 'Username';
- $txt['ftp_username_info'] = 'The username to login with. <em>This will not be saved anywhere.</em>';
- $txt['ftp_password'] = 'Password';
- $txt['ftp_password_info'] = 'The password to login with. <em>This will not be saved anywhere.</em>';
- $txt['ftp_path'] = 'Install Path';
- $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>.';
- $txt['ftp_path_found_info'] = 'The path in the box above was automatically detected.';
- $txt['ftp_path_help'] = 'Your FTP path is the path you see when you log in to your FTP client. It commonly starts with "<tt>www</tt>", "<tt>public_html</tt>", or "<tt>httpdocs</tt>" - but it should include the directory SMF is in too, such as "/public_html/forum". It is different from your URL and full path.<br /><br />Files in this path may be overwritten, so make sure it\'s correct.';
- $txt['ftp_path_help_close'] = 'Close';
- $txt['ftp_connect'] = 'Connect';
-
- if (!empty($upcontext['chmod']['ftp_error']) && $upcontext['chmod']['ftp_error'] == 'total_mess')
- {
- echo '
- <div class="error_message">
- <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>
- <ul style="margin: 2.5ex; font-family: monospace;">
- <li>' . implode('</li>
- <li>', $upcontext['chmod']['files']). '</li>
- </ul>
- </div>';
- return false;
- }
- echo '
- <div class="panel">
- <h2>Your FTP connection information</h2>
- <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>
- <script type="text/javascript"><!-- // --><![CDATA[
- function warning_popup()
- {
- popup = window.open(\'\',\'popup\',\'height=150,width=400,scrollbars=yes\');
- var content = popup.document;
- content.write(\'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n\');
- 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\');
- 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\');
- 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\');
- content.write(\'<p>', implode('<br />\n\t\t\t', $upcontext['chmod']['files']), '</p>\n\t\t\t\');
- content.write(\'<a href="javascript:self.close();">close</a>\n\t\t</div>\n\t</body>\n</html>\');
- content.close();
- }
- // ]]></script>';
- if (!empty($upcontext['chmod']['ftp_error']))
- echo '
- <div class="error_message">
- <div style="color: red;">
- The following error was encountered when trying to connect:<br />
- <br />
- <code>', $upcontext['chmod']['ftp_error'], '</code>
- </div>
- </div>
- <br />';
- if (empty($upcontext['chmod_in_form']))
- echo '
- <form action="', $upcontext['form_url'], '" method="post">';
- echo '
- <table width="520" cellspacing="0" cellpadding="0" border="0" align="center" style="margin-bottom: 1ex;">
- <tr>
- <td width="26%" valign="top" class="textbox"><label for="ftp_server">', $txt['ftp_server'], ':</label></td>
- <td>
- <div style="float: right; margin-right: 1px;"><label for="ftp_port" class="textbox"><strong>', $txt['ftp_port'], ': </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>
- <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" />
- <div style="font-size: smaller; margin-bottom: 2ex;">', $txt['ftp_server_info'], '</div>
- </td>
- </tr><tr>
- <td width="26%" valign="top" class="textbox"><label for="ftp_username">', $txt['ftp_username'], ':</label></td>
- <td>
- <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" />
- <div style="font-size: smaller; margin-bottom: 2ex;">', $txt['ftp_username_info'], '</div>
- </td>
- </tr><tr>
- <td width="26%" valign="top" class="textbox"><label for="ftp_password">', $txt['ftp_password'], ':</label></td>
- <td>
- <input type="password" size="50" name="ftp_password" id="ftp_password" style="width: 99%;" class="input_password" />
- <div style="font-size: smaller; margin-bottom: 3ex;">', $txt['ftp_password_info'], '</div>
- </td>
- </tr><tr>
- <td width="26%" valign="top" class="textbox"><label for="ftp_path">', $txt['ftp_path'], ':</label></td>
- <td style="padding-bottom: 1ex;">
- <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" />
- <div style="font-size: smaller; margin-bottom: 2ex;">', !empty($upcontext['chmod']['path']) ? $txt['ftp_path_found_info'] : $txt['ftp_path_info'], '</div>
- </td>
- </tr>
- </table>
- <div class="righttext" style="margin: 1ex;"><input type="submit" value="', $txt['ftp_connect'], '" class="button_submit" /></div>
- </div>';
- if (empty($upcontext['chmod_in_form']))
- echo '
- </form>';
- }
- function template_upgrade_above()
- {
- global $modSettings, $txt, $smfsite, $settings, $upcontext, $upgradeurl;
- echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml"', $upcontext['right_to_left'] ? ' dir="rtl"' : '', '>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=', isset($txt['lang_character_set']) ? $txt['lang_character_set'] : 'ISO-8859-1', '" />
- <meta name="robots" content="noindex" />
- <title>', $txt['upgrade_upgrade_utility'], '</title>
- <link rel="stylesheet" type="text/css" href="', $settings['default_theme_url'], '/css/index.css?alp21" />
- <link rel="stylesheet" type="text/css" href="', $settings['default_theme_url'], '/css/install.css?alp21" />
- <script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/script.js"></script>
- <script type="text/javascript"><!-- // --><![CDATA[
- var smf_scripturl = \'', $upgradeurl, '\';
- var smf_charset = \'', (empty($modSettings['global_character_set']) ? (empty($txt['lang_character_set']) ? 'ISO-8859-1' : $txt['lang_character_set']) : $modSettings['global_character_set']), '\';
- var startPercent = ', $upcontext['overall_percent'], ';
- // This function dynamically updates the step progress bar - and overall one as required.
- function updateStepProgress(current, max, overall_weight)
- {
- // What out the actual percent.
- var width = parseInt((current / max) * 100);
- if (document.getElementById(\'step_progress\'))
- {
- document.getElementById(\'step_progress\').style.width = width + "%";
- setInnerHTML(document.getElementById(\'step_text\'), width + "%");
- }
- if (overall_weight && document.getElementById(\'overall_progress\'))
- {
- overall_width = parseInt(startPercent + width * (overall_weight / 100));
- document.getElementById(\'overall_progress\').style.width = overall_width + "%";
- setInnerHTML(document.getElementById(\'overall_text\'), overall_width + "%");
- }
- }
- // ]]></script>
- </head>
- <body>
- <div id="header"><div class="frame">
- <div id="top_section">
- <h1 class="forumtitle">', $txt['upgrade_upgrade_utility'], '</h1>
- <img id="smflogo" src="Themes/default/images/smflogo.png" alt="Simple Machines Forum" title="Simple Machines Forum" />
- </div>
- <div id="upper_section" class="middletext flow_hidden">
- <div class="user"></div>
- <div class="news normaltext">
- </div>
- </div>
- </div></div>
- <div id="content_section"><div class="frame">
- <div id="main_content_section">
- <div id="main-steps">
- <h2>', $txt['upgrade_progress'], '</h2>
- <ul>';
- foreach ($upcontext['steps'] as $num => $step)
- echo '
- <li class="', $num < $upcontext['current_step'] ? 'stepdone' : ($num == $upcontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>';
- echo '
- </ul>
- </div>
- <div style="float: left; width: 40%;">
- <div style="font-size: 8pt; height: 12pt; border: 1px solid black; background-color: white; width: 50%; margin: auto;">
- <div id="overall_text" style="color: #000; position: absolute; margin-left: -5em;">', $upcontext['overall_percent'], '%</div>
- <div id="overall_progress" style="width: ', $upcontext['overall_percent'], '%; height: 12pt; z-index: 1; background-color: lime;"> </div>
- <div class="progress">', $txt['upgrade_overall_progress'], '</div>
- </div>
- ';
- if (isset($upcontext['step_progress']))
- echo '
- <div style="font-size: 8pt; height: 12pt; border: 1px solid black; background-color: white; width: 50%; margin: 5px auto; ">
- <div id="step_text" style="color: #000; position: absolute; margin-left: -5em;">', $upcontext['step_progress'], '%</div>
- <div id="step_progress" style="width: ', $upcontext['step_progress'], '%; height: 12pt; z-index: 1; background-color: #ffd000;"> </div>
- <div class="progress">', $txt['upgrade_step_progress'], '</div>
- </div>
- ';
- echo '
- <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>
- <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', ';">
- <div id="substep_text" style="color: #000; position: absolute; margin-left: -5em;">', isset($upcontext['substep_progress']) ? $upcontext['substep_progress'] : '', '%</div>
- <div id="substep_progress" style="width: ', isset($upcontext['substep_progress']) ? $upcontext['substep_progress'] : 0, '%; height: 12pt; z-index: 1; background-color: #eebaf4;"> </div>
- </div>';
-
- $elapsed = time() - $upcontext['started'];
- $mins = (int) ($elapsed / 60);
- $seconds = $elapsed - $mins * 60;
- echo '
- <div class="smalltext" style="padding: 5px; text-align: center;">', $txt['upgrade_time_elapsed'], ':
- <span id="mins_elapsed">', $mins, '</span> ', $txt['upgrade_time_mins'], ', <span id="secs_elapsed">', $seconds, '</span> ', $txt['upgrade_time_secs'], '.
- </div>';
- echo '
- </div>
- <div id="main_screen" class="clear">
- <h2>', $upcontext['page_title'], '</h2>
- <div class="panel">
- <div style="max-height: 360px; overflow: auto;">';
- }
- function template_upgrade_below()
- {
- global $upcontext, $txt;
- if (!empty($upcontext['pause']))
- echo '
- <em>', $txt['upgrade_incomplete'], '.</em><br />
- <h2 style="margin-top: 2ex;">', $txt['upgrade_not_quite_done'], '</h2>
- <h3>
- ', $txt['upgrade_paused_overload'], '
- </h3>';
- if (!empty($upcontext['custom_warning']))
- echo '
- <div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
- <div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
- <strong style="text-decoration: underline;">', $txt['upgrade_note'], '</strong><br />
- <div style="padding-left: 6ex;">', $upcontext['custom_warning'], '</div>
- </div>';
- echo '
- <div class="righttext" style="margin: 1ex;">';
- if (!empty($upcontext['continue']))
- echo '
- <input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '"', $upcontext['continue'] == 2 ? ' disabled="disabled"' : '', ' class="button_submit" />';
- if (!empty($upcontext['skip']))
- echo '
- <input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="dontSubmit = true; document.getElementById(\'contbutt\').disabled = \'disabled\'; return true;" class="button_submit" />';
- echo '
- </div>
- </form>
- </div>
- </div>
- </div>
- </div>
- </div></div>
- <div id="footer_section"><div class="frame" style="height: 40px;">
- <div class="smalltext"><a href="http://www.simplemachines.org/" title="Simple Machines Forum" target="_blank" class="new_win">SMF ©2011, Simple Machines</a></div>
- </div></div>
- </body>
- </html>';
-
- if (!empty($upcontext['pause']))
- {
- echo '
- <script type="text/javascript"><!-- // --><![CDATA[
- window.onload = doAutoSubmit;
- var countdown = 3;
- var dontSubmit = false;
- function doAutoSubmit()
- {
- if (countdown == 0 && !dontSubmit)
- document.upform.submit();
- else if (countdown == -1)
- return;
- document.getElementById(\'contbutt\').value = "', $txt['upgrade_continue'], ' (" + countdown + ")";
- countdown--;
- setTimeout("doAutoSubmit();", 1000);
- }
- // ]]></script>';
- }
- }
- function template_xml_above()
- {
- global $upcontext;
- echo '<', '?xml version="1.0" encoding="ISO-8859-1"?', '>
- <smf>';
- if (!empty($upcontext['get_data']))
- foreach ($upcontext['get_data'] as $k => $v)
- echo '
- <get key="', $k, '">', $v, '</get>';
- }
- function template_xml_below()
- {
- global $upcontext;
- echo '
- </smf>';
- }
- function template_error_message()
- {
- global $upcontext;
- echo '
- <div class="error_message">
- <div style="color: red;">
- ', $upcontext['error_msg'], '
- </div>
- <br />
- <a href="', $_SERVER['PHP_SELF'], '">Click here to try again.</a>
- </div>';
- }
- function template_welcome_message()
- {
- global $upcontext, $modSettings, $upgradeurl, $disable_security, $settings, $txt;
- echo '
- <script type="text/javascript" src="http://www.simplemachines.org/smf/current-version.js?version=' . SMF_VERSION . '"></script>
- <script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/sha1.js"></script>
- <h3>', sprintf($txt['upgrade_ready_proceed'], SMF_VERSION), '</h3>
- <form action="', $upcontext['form_url'], '" method="post" name="upform" id="upform" ', empty($upcontext['disable_login_hashing']) ? ' onsubmit="hashLoginPassword(this, \'' . $upcontext['rid'] . '\', \'' . (!empty($context['login_token']) ? $context['login_token'] : '') . '\');"' : '', '>
- <input type="hidden" name="', $context['login_token_var'], '" value="', $context['login_token'], '" />
- <div id="version_warning" style="margin: 2ex; padding: 2ex; border: 2px dashed #a92174; color: black; background-color: #fbbbe2; display: none;">
- <div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
- <strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br />
- <div style="padding-left: 6ex;">
- ', sprintf($txt['upgrade_warning_out_of_date'], SMF_VERSION), '
- </div>
- </div>';
- $upcontext['chmod_in_form'] = true;
- template_chmod();
-
- if ($upcontext['is_large_forum'])
- echo '
- <div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
- <div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
- <strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br />
- <div style="padding-left: 6ex;">
- ', $txt['upgrade_warning_lots_data'], '
- </div>
- </div>';
-
- if (!empty($upcontext['warning']))
- echo '
- <div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
- <div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
- <strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br />
- <div style="padding-left: 6ex;">
- ', $upcontext['warning'], '
- </div>
- </div>';
-
- echo '
- <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">
- <div style="float: left; width: 2ex; font-size: 2em; color: black;">!!</div>
- <strong style="text-decoration: underline;">', $txt['upgrade_critical_error'], '</strong><br />
- <div style="padding-left: 6ex;">
- ', $txt['upgrade_error_script_js'], '
- </div>
- </div>';
-
- if (!empty($upcontext['user']['id']) && (time() - $upcontext['started'] < 72600 || time() - $upcontext['updated'] < 3600))
- {
- $ago = time() - $upcontext['started'];
- if ($ago < 60)
- $ago = $ago . ' seconds';
- elseif ($ago < 3600)
- $ago = (int) ($ago / 60) . ' minutes';
- else
- $ago = (int) ($ago / 3600) . ' hours';
- $active = time() - $upcontext['updated'];
- if ($active < 60)
- $updated = $active . ' seconds';
- elseif ($active < 3600)
- $updated = (int) ($active / 60) . ' minutes';
- else
- $updated = (int) ($active / 3600) . ' hours';
- echo '
- <div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
- <div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
- <strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br />
- <div style="padding-left: 6ex;">
- "', $upcontext['user']['name'], '" has been running the upgrade script for the last ', $ago, ' - and was last active ', $updated, ' ago.';
- if ($active < 600)
- echo '
- We recommend that you do not run this script unless you are sure that ', $upcontext['user']['name'], ' has completed their upgrade.';
- if ($active > $upcontext['inactive_timeout'])
- echo '
- <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.';
- else
- echo '
- <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!');
- echo '
- </div>
- </div>';
- }
- echo '
- <strong>Admin Login: ', $disable_security ? '(DISABLED)' : '', '</strong>
- <h3>For security purposes please login with your admin account to proceed with the upgrade.</h3>
- <table>
- <tr valign="top">
- <td><strong ', $disable_security ? 'style="color: gray;"' : '', '>Username:</strong></td>
- <td>
- <input type="text" name="user" value="', !empty($upcontext['username']) ? $upcontext['username'] : '', '" ', $disable_security ? 'disabled="disabled"' : '', ' class="input_text" />';
- if (!empty($upcontext['username_incorrect']))
- echo '
- <div class="smalltext" style="color: red;">Username Incorrect</div>';
- echo '
- </td>
- </tr>
- <tr valign="top">
- <td><strong ', $disable_security ? 'style="color: gray;"' : '', '>Password:</strong></td>
- <td>
- <input type="password" name="passwrd" value=""', $disable_security ? ' disabled="disabled"' : '', ' class="input_password" />
- <input type="hidden" name="hash_passwrd" value="" />';
- if (!empty($upcontext['password_failed']))
- echo '
- <div class="smalltext" style="color: red;">Password Incorrect</div>';
- echo '
- </td>
- </tr>';
-
- if (!empty($upcontext['user']['id']) && time() - $upcontext['user']['updated'] >= $upcontext['inactive_timeout'] && $upcontext['user']['step'] > 1)
- {
- echo '
- <tr>
- <td colspan="2">
- <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>
- </td>
- </tr>';
- }
- echo '
- </table><br />
- <span class="smalltext">
- <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 "upgrade.php" in a text editor and replace "$disable_security = 0;" with "$disable_security = 1;" and refresh this page.
- </span>
- <input type="hidden" name="login_attempt" id="login_attempt" value="1" />
- <input type="hidden" name="js_works" id="js_works" value="0" />';
-
- $upcontext['continue'] = !empty($upcontext['user']['id']) && time() - $upcontext['user']['updated'] < $upcontext['inactive_timeout'] ? 2 : 1;
-
- echo '
- <script type="text/javascript"><!-- // --><![CDATA[
- if (\'XMLHttpRequest\' in window && document.getElementById(\'js_works\'))
- document.getElementById(\'js_works\').value = 1;
- // Latest version?
- function smfCurrentVersion()
- {
- var smfVer, yourVer;
- if (!(\'smfVersion\' in window))
- return;
- window.smfVersion = window.smfVersion.replace(/SMF\s?/g, \'\');
- smfVer = document.getElementById(\'smfVersion\');
- yourVer = document.getElementById(\'yourVersion\');
- setInnerHTML(smfVer, window.smfVersion);
- var currentVersion = getInnerHTML(yourVer);
- if (currentVersion < window.smfVersion)
- document.getElementById(\'version_warning\').style.display = \'\';
- }
- addLoadEvent(smfCurrentVersion);
- // This checks that the script file even exists!
- if (typeof(smfSelectText) == \'undefined\')
- document.getElementById(\'js_script_missing_error\').style.display = \'\';
- // ]]></script>';
- }
- function template_upgrade_options()
- {
- global $upcontext, $modSettings, $upgradeurl, $disable_security, $settings, $boarddir, $db_prefix, $mmessage, $mtitle, $db_type;
- echo '
- <h3>Before the upgrade gets underway please review the options below - and hit continue when you\'re ready to begin.</h3>
- <form action="', $upcontext['form_url'], '" method="post" name="upform" id="upform">';
-
- if (!empty($upcontext['upgrade_options_warning']))
- echo '
- <div style="margin: 1ex; padding: 1ex; border: 1px dashed #cc3344; color: black; background-color: #ffe4e9;">
- <div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
- <strong style="text-decoration: underline;">Warning!</strong><br />
- <div style="padding-left: 4ex;">
- ', $upcontext['upgrade_options_warning'], '
- </div>
- </div>';
- echo '
- <table cellpadding="1" cellspacing="0">
- <tr valign="top">
- <td width="2%">
- <input type="checkbox" name="backup" id="backup" value="1"', $db_type != 'mysql' && $db_type != 'postgresql' ? ' disabled="disabled"' : '', ' class="input_check" />
- </td>
- <td width="100%">
- <label for="backup">Backup tables in your database with the prefix "backup_' . $db_prefix . '".</label>', isset($modSettings['smfVersion']) ? '' : ' (recommended!)', '
- </td>
- </tr>
- <tr valign="top">
- <td width="2%">
- <input type="checkbox" name="maint" id="maint" value="1" checked="checked" class="input_check" />
- </td>
- <td width="100%">
- <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>
- <div id="mainmess" style="display: none;">
- <strong class="smalltext">Maintenance Title: </strong><br />
- <input type="text" name="maintitle" size="30" value="', htmlspecialchars($mtitle), '" class="input_text" /><br />
- <strong class="smalltext">Maintenance Message: </strong><br />
- <textarea name="mainmessage" rows="3" cols="50">', htmlspecialchars($mmessage), '</textarea>
- </div>
- </td>
- </tr>
- <tr valign="top">
- <td width="2%">
- <input type="checkbox" name="debug" id="debug" value="1" class="input_check" />
- </td>
- <td width="100%">
- <label for="debug">Output extra debugging information</label>
- </td>
- </tr>
- <tr valign="top">
- <td width="2%">
- <input type="checkbox" name="empty_error" id="empty_error" value="1" class="input_check" />
- </td>
- <td width="100%">
- <label for="empty_error">Empty error log before upgrading</label>
- </td>
- </tr>
- <tr valign="top">
- <td width="2%">
- <input type="checkbox" name="stats" id="stats" value="1"', empty($modSettings['allow_sm_stats']) ? '' : ' checked="checked"', ' class="input_check" />
- </td>
- <td width="100%">
- <label for="stats">
- Allow Simple Machines to Collect Basic Stats Monthly.<br />
- <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>
- </label>
- </td>
- </tr>
- </table>
- <input type="hidden" name="upcont" value="1" />';
-
- $upcontext['continue'] = 1;
- }
- function template_backup_database()
- {
- global $upcontext, $modSettings, $upgradeurl, $disable_security, $settings, $support_js, $is_debug;
- echo '
- <h3>Please wait while a backup is created. For large forums this may take some time!</h3>';
- echo '
- <form action="', $upcontext['form_url'], '" name="upform" id="upform" method="post">
- <input type="hidden" name="backup_done" id="backup_done" value="0" />
- <strong>Completed <span id="tab_done">', $upcontext['cur_table_num'], '</span> out of ', $upcontext['table_count'], ' tables.</strong>
- <span id="debuginfo"></span>';
-
- if (!empty($upcontext['previous_tables']))
- foreach ($upcontext['previous_tables'] as $table)
- echo '
- <br />Completed Table: "', $table, '".';
- echo '
- <h3 id="current_tab_div">Current Table: "<span id="current_table">', $upcontext['cur_table_name'], '</span>"</h3>
- <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>';
-
- $upcontext['continue'] = $support_js ? 2 : 1;
-
- if ($support_js)
- {
- echo '
- <script type="text/javascript"><!-- // --><![CDATA[
- var lastTable = ', $upcontext['cur_table_num'], ';
- function getNextTables()
- {
- getXMLDocument(\'', $upcontext['form_url'], '&xml&substep=\' + lastTable, onBackupUpdate);
- }
- // Got an update!
- function onBackupUpdate(oXMLDoc)
- {
- var sCurrentTableName = "";
- var iTableNum = 0;
- var sCompletedTableName = getInnerHTML(document.getElementById(\'current_table\'));
- for (var i = 0; i < oXMLDoc.getElementsByTagName("table")[0].childNodes.length; i++)
- sCurrentTableName += oXMLDoc.getElementsByTagName("table")[0].childNodes[i].nodeValue;
- iTableNum = oXMLDoc.getElementsByTagName("table")[0].getAttribute("num");
- // Update the page.
- setInnerHTML(document.getElementById(\'tab_done\'), iTableNum);
- setInnerHTML(document.getElementById(\'current_table\'), sCurrentTableName);
- lastTable = iTableNum;
- updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
-
- if ($is_debug)
- echo '
- setOuterHTML(document.getElementById(\'debuginfo\'), \'<br />Completed Table: "\' + sCompletedTableName + \'".<span id="debuginfo"><\' + \'/span>\');';
- echo '
- // Get the next update...
- if (iTableNum == ', $upcontext['table_count'], ')
- {
- document.getElementById(\'commess\').style.display = "";
- document.getElementById(\'current_tab_div\').style.display = "none";
- document.getElementById(\'contbutt\').disabled = 0;
- document.getElementById(\'backup_done\').value = 1;
- }
- else
- getNextTables();
- }
- getNextTables();
- // ]]></script>';
- }
- }
- function template_backup_xml()
- {
- global $upcontext, $settings, $options, $txt;
- echo '
- <table num="', $upcontext['cur_table_num'], '">', $upcontext['cur_table_name'], '</table>';
- }
- function template_database_changes()
- {
- global $upcontext, $modSettings, $upgradeurl, $disable_security, $settings, $support_js, $is_debug, $timeLimitThreshold;
- echo '
- <h3>Executing database changes</h3>
- <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>';
- echo '
- <form action="', $upcontext['form_url'], '&filecount=', $upcontext['file_count'], '" name="upform" id="upform" method="post">
- <input type="hidden" name="database_done" id="database_done" value="0" />';
-
- if (!$support_js)
- {
- foreach ($upcontext['actioned_items'] as $num => $item)
- {
- if ($num != 0)
- echo ' Successful!';
- echo '<br />' . $item;
- }
- if (!empty($upcontext['changes_complete']))
- echo ' Successful!<br /><br /><span id="commess" style="font-weight: bold;">Database Updates Complete! Click Continue to Proceed.</span><br />';
- }
- else
- {
-
- if ($upcontext['file_count'] > 1)
- echo '
- <strong id="info1">Executing upgrade script <span id="file_done">', $upcontext['cur_file_num'], '</span> of ', $upcontext['file_count'], '.</strong>';
- echo '
- <h3 id="info2"><strong>Executing:</strong> "<span id="cur_item_name">', $upcontext['current_item_name'], '</span>" (<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>
- <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>';
- if ($is_debug)
- {
- echo '
- <div id="debug_section" style="height: 200px; overflow: auto;">
- <span id="debuginfo"></span>
- </div>';
- }
- }
-
- echo '
- <div id="error_block" style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9; display: ', empty($upcontext['error_message']) ? 'none' : '', ';">
- <div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
- <strong style="text-decoration: underline;">Error!</strong><br />
- <div style="padding-left: 6ex;" id="error_message">', isset($upcontext['error_message']) ? $upcontext['error_message'] : 'Unknown Error!', '</div>
- </div>';
-
- $upcontext['continue'] = $support_js ? 2 : 1;
-
- if ($support_js)
- {
- echo '
- <script type="text/javascript"><!-- // --><![CDATA[
- var lastItem = ', $upcontext['current_debug_item_num'], ';
- var sLastString = "', strtr($upcontext['current_debug_item_name'], array('"' => '"')), '";
- var iLastSubStepProgress = -1;
- var curFile = ', $upcontext['cur_file_num'], ';
- var totalItems = 0;
- var prevFile = 0;
- var retryCount = 0;
- var testvar = 0;
- var timeOutID = 0;
- var getData = "";
- var debugItems = ', $upcontext['debug_items'], ';
- function getNextItem()
- {
- // We want to track this...
- if (timeOutID)
- clearTimeout(timeOutID);
- timeOutID = window.setTimeout("retTimeout()", ', (10 * $timeLimitThreshold), '000);
- getXMLDocument(\'', $upcontext['form_url'], '&xml&filecount=', $upcontext['file_count'], '&substep=\' + lastItem + getData, onItemUpdate);
- }
- // Got an update!
- function onItemUpdate(oXMLDoc)
- {
- var sItemName = "";
- var sDebugName = "";
- var iItemNum = 0;
- var iSubStepProgress = -1;
- var iDebugNum = 0;
- var bIsComplete = 0;
- getData = "";
- // We\'ve got something - so reset the timeout!
- if (timeOutID)
- clearTimeout(timeOutID);
- // Assume no error at this time...
- document.getElementById("error_block").style.display = "none";
- // Are we getting some duff info?
- if (!oXMLDoc.getElementsByTagName("item")[0])
- {
- // Too many errors?
- if (retryCount > 15)
- {
- document.getElementById("error_block").style.display = "";
- setInnerHTML(document.getElementById("error_message"), "Error retrieving information on step: " + (sDebugName == "" ? sLastString : sDebugName));';
- if ($is_debug)
- echo '
- setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
- echo '
- }
- else
- {
- retryCount++;
- getNextItem();
- }
- return false;
- }
- // Never allow loops.
- if (curFile == prevFile)
- {
- retryCount++;
- if (retryCount > 10)
- {
- document.getElementById("error_block").style.display = "";
- setInnerHTML(document.getElementById("error_message"), "Upgrade script appears to be going into a loop - step: " + sDebugName);';
- if ($is_debug)
- echo '
- setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
- echo '
- }
- }
- retryCount = 0;
- for (var i = 0; i < oXMLDoc.getElementsByTagName("item")[0].childNodes.length; i++)
- sItemName += oXMLDoc.getElementsByTagName("item")[0].childNodes[i].nodeValue;
- for (var i = 0; i < oXMLDoc.getElementsByTagName("debug")[0].childNodes.length; i++)
- sDebugName += oXMLDoc.getElementsByTagName("debug")[0].childNodes[i].nodeValue;
- for (var i = 0; i < oXMLDoc.getElementsByTagName("get").length; i++)
- {
- getData += "&" + oXMLDoc.getElementsByTagName("get")[i].getAttribute("key") + "=";
- for (var j = 0; j < oXMLDoc.getElementsByTagName("get")[i].childNodes.length; j++)
- {
- getData += oXMLDoc.getElementsByTagName("get")[i].childNodes[j].nodeValue;
- }
- }
- iItemNum = oXMLDoc.getElementsByTagName("item")[0].getAttribute("num");
- iDebugNum = parseInt(oXMLDoc.getElementsByTagName("debug")[0].getAttribute("num"));
- bIsComplete = parseInt(oXMLDoc.getElementsByTagName("debug")[0].getAttribute("complete"));
- iSubStepProgress = parseFloat(oXMLDoc.getElementsByTagName("debug")[0].getAttribute("percent"));
- sLastString = sDebugName + " (Item: " + iDebugNum + ")";
- curFile = parseInt(oXMLDoc.getElementsByTagName("file")[0].getAttribute("num"));
- debugItems = parseInt(oXMLDoc.getElementsByTagName("file")[0].getAttribute("debug_items"));
- totalItems = parseInt(oXMLDoc.getElementsByTagName("file")[0].getAttribute("items"));
- // If we have an error we haven\'t completed!
- if (oXMLDoc.getElementsByTagName("error")[0] && bIsComplete)
- iDebugNum = lastItem;
- // Do we have the additional progress bar?
- if (iSubStepProgress != -1)
- {
- document.getElementById("substep_bar_div").style.display = "";
- document.getElementById("substep_bar_div2").style.display = "";
- document.getElementById("substep_progress").style.width = iSubStepProgress + "%";
- setInnerHTML(document.getElementById("substep_text"), iSubStepProgress + "%");
- setInnerHTML(document.getElementById("substep_bar_div"), sDebugName.replace(/\./g, "") + ":");
- }
- else
- {
- document.getElementById("substep_bar_div").style.display = "none";
- document.getElementById("substep_bar_div2").style.display = "none";
- }
- // Move onto the next item?
- if (bIsComplete)
- lastItem = iDebugNum;
- else
- lastItem = iDebugNum - 1;
- // Are we finished?
- if (bIsComplete && iDebugNum == -1 && curFile >= ', $upcontext['file_count'], ')
- {';
- if ($is_debug)
- echo '
- document.getElementById(\'debug_section\').style.display = "none";';
- echo '
- document.getElementById(\'commess\').style.display = "";
- document.getElementById(\'contbutt\').disabled = 0;
- document.getElementById(\'database_done\').value = 1;';
- if ($upcontext['file_count'] > 1)
- echo '
- document.getElementById(\'info1\').style.display = "none";';
- echo '
- document.getElementById(\'info2\').style.display = "none";
- updateStepProgress(100, 100, ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');
- return true;
- }
- // Was it the last step in the file?
- else if (bIsComplete && iDebugNum == -1)
- {
- lastItem = 0;
- prevFile = curFile;';
- if ($is_debug)
- echo '
- setOuterHTML(document.getElementById(\'debuginfo\'), \'Moving to next script file...done<br /><span id="debuginfo"><\' + \'/span>\');';
- echo '
- getNextItem();
- return true;
- }';
-
- if ($is_debug)
- echo '
- if (iLastSubStepProgress == -1)
- {
- // Give it consistent dots.
- dots = sDebugName.match(/\./g);
- numDots = dots ? dots.length : 0;
- for (var i = numDots; i < 3; i++)
- sDebugName += ".";
- setOuterHTML(document.getElementById(\'debuginfo\'), sDebugName + \'<span id="debuginfo"><\' + \'/span>\');
- }
- iLastSubStepProgress = iSubStepProgress;
- if (bIsComplete)
- setOuterHTML(document.getElementById(\'debuginfo\'), \'done<br /><span id="debuginfo"><\' + \'/span>\');
- else
- setOuterHTML(document.getElementById(\'debuginfo\'), \'...<span id="debuginfo"><\' + \'/span>\');
- if (document.getElementById(\'debug_section\').scrollHeight)
- document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
- echo '
- // Update the page.
- setInnerHTML(document.getElementById(\'item_num\'), iItemNum);
- setInnerHTML(document.getElementById(\'cur_item_name\'), sItemName);';
- if ($upcontext['file_count'] > 1)
- {
- echo '
- setInnerHTML(document.getElementById(\'file_done\'), curFile);
- setInnerHTML(document.getElementById(\'item_count\'), totalItems);';
- }
- echo '
- // Is there an error?
- if (oXMLDoc.getElementsByTagName("error")[0])
- {
- var sErrorMsg = "";
- for (var i = 0; i < oXMLDoc.getElementsByTagName("error")[0].childNodes.length; i++)
- sErrorMsg += oXMLDoc.getElementsByTagName("error")[0].childNodes[i].nodeValue;
- document.getElementById("error_block").style.display = "";
- setInnerHTML(document.getElementById("error_message"), sErrorMsg);
- return false;
- }
- // Get the progress bar right.
- barTotal = debugItems * ', $upcontext['file_count'], ';
- barDone = (debugItems * (curFile - 1)) + lastItem;
- updateStepProgress(barDone, barTotal, ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');
- // Finally - update the time here as it shows the server is responding!
- curTime = new Date();
- iElapsed = (curTime.getTime() / 1000 - ', $upcontext['started'], ');
- mins = parseInt(iElapsed / 60);
- secs = parseInt(iElapsed - mins * 60);
- setInnerHTML(document.getElementById("mins_elapsed"), mins);
- setInnerHTML(document.getElementById("secs_elapsed"), secs);
- getNextItem();
- return true;
- }
- // What if we timeout?!
- function retTimeout(attemptAgain)
- {
- // Oh noes...
- if (!attemptAgain)
- {
- document.getElementById("error_block").style.display = "";
- 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");
- }
- else
- {
- document.getElementById("error_block").style.display = "none";
- getNextItem();
- }
- }';
-
- if (empty($upcontext['error_message']))
- echo '
- getNextItem();';
- echo '
- // ]]></script>';
- }
- return;
- }
- function template_database_xml()
- {
- global $upcontext, $settings, $options, $txt;
- echo '
- <file num="', $upcontext['cur_file_num'], '" items="', $upcontext['total_items'], '" debug_items="', $upcontext['debug_items'], '">', $upcontext['cur_file_name'], '</file>
- <item num="', $upcontext['current_item_num'], '">', $upcontext['current_item_name'], '</item>
- <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>';
- if (!empty($upcontext['error_message']))
- echo '
- <error>', $upcontext['error_message'], '</error>';
- }
- function template_clean_mods()
- {
- global $upcontext, $modSettings, $upgradeurl, $disable_security, $settings, $boarddir, $db_prefix, $boardurl;
- $upcontext['chmod_in_form'] = true;
- echo '
- <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>
- <form action="', $upcontext['form_url'], '&ssi=1" name="upform" id="upform" method="post">';
-
- template_chmod();
- echo '
- <table width="90%" align="center" cellspacing="1" cellpadding="2" style="background-color: black;">
- <tr style="background-color: #eeeeee;">
- <td width="40%"><strong>Modification Name</strong></td>
- <td width="10%" align="center"><strong>Version</strong></td>
- <td width="15%"><strong>Files Affected</strong></td>
- <td width="20%"><strong>Status</strong></td>
- <td width="5%" align="center"><strong>Fix?</strong></td>
- </tr>';
- foreach ($upcontext['packages'] as $package)
- {
- echo '
- <tr style="background-color: #cccccc;">
- <td width="40%">', $package['name'], '</td>
- <td width="10%">', $package['version'], '</td>
- <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>
- <td width="20%"><span style="font-weight: bold; color: ', $package['color'], '">', $package['status'], '</span></td>
- <td width="5%" align="center">
- <input type="hidden" name="remove[', $package['id'], ']" value="0" />
- <input type="checkbox" name="remove[', $package['id'], ']"', $package['color'] == 'green' ? ' disabled="disabled"' : '', ' class="input_check" />
- </td>
- </tr>';
- }
- echo '
- </table>
- <input type="hidden" name="cleandone" value="1" />';
-
- if (!empty($upcontext['writable_files']))
- echo '
- <input type="hidden" name="writable_files" value="', base64_encode(serialize($upcontext['writable_files'])), '" />';
-
- if (empty($upcontext['chmod']['files']))
- $upcontext['continue'] = 1;
- }
- function template_cleanup_done()
- {
- global $upcontext, $modSettings, $upgradeurl, $disable_security, $settings, $boarddir, $db_prefix, $boardurl;
- echo '
- <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>
- <form action="', $upcontext['form_url'], '&ssi=1" name="upform" id="upform" method="post">
- <table width="90%" align="center" cellspacing="1" cellpadding="2" style="background-color: black;">
- <tr style="background-color: #eeeeee;">
- <td width="100%"><strong>Actions Completed:</strong></td>
- </tr>';
- foreach ($upcontext['packages'] as $package)
- {
- echo '
- <tr style="background-color: #cccccc;">
- <td>', $package['name'], '... <span style="font-weight: bold; color: ', $package['color'], ';">', $package['result'], '</span></td>
- </tr>';
- }
- echo '
- </table>
- <input type="hidden" name="cleandone2" value="1" />';
-
- $upcontext['continue'] = 1;
- }
- function template_upgrade_templates()
- {
- global $upcontext, $modSettings, $upgradeurl, $disable_security, $settings, $boarddir, $db_prefix, $boardurl;
- echo '
- <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>
- <form action="', $upcontext['form_url'], '&ssi=1', $upcontext['is_test'] ? '' : ';forreal=1', '" name="upform" id="upform" method="post">';
-
- $upcontext['chmod_in_form'] = true;
- template_chmod();
-
- if ($upcontext['temp_progress'] == 0 && !$upcontext['is_test'] && (!empty($upcontext['languages']) || !empty($upcontext['themes'])))
- {
- echo '
- 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.
- <table width="90%" align="center" cellspacing="1" cellpadding="2" style="background-color: black;">
- <tr style="background-color: #eeeeee;">
- <td width="80%"><strong>Area</strong></td>
- <td width="20%" align="center"><strong>Changes Required</strong></td>
- </tr>';
- foreach ($upcontext['languages'] as $language)
- {
- echo '
- <tr style="background-color: #cccccc;">
- <td width="80%">
- "', $language['name'], '" Language Pack
- <div class="smalltext">(';
- foreach ($language['files'] as $k => $file)
- echo $file['name'], $k + 1 != count($language['files']) ? ', ' : ')';
- echo '
- </div>
- </td>
- <td width="20%" align="center">', $language['edit_count'] == 0 ? 1 : $language['edit_count'], '</td>
- </tr>';
- }
- foreach ($upcontext['themes'] as $theme)
- {
- echo '
- <tr style="background-color: #CCCCCC;">
- <td width="80%">
- "', $theme['name'], '" Theme
- <div class="smalltext">(';
- foreach ($theme['files'] as $k => $file)
- echo $file['name'], $k + 1 != count($theme['files']) ? ', ' : ')';
- echo '
- </div>
- </td>
- <td width="20%" align="center">', $theme['edit_count'] == 0 ? 1 : $theme['edit_count'], '</td>
- </tr>';
- }
- echo '
- </table>';
- }
- else
- {
- $langFiles = 0;
- $themeFiles = 0;
- if (!empty($upcontext['languages']))
- foreach ($upcontext['languages'] as $lang)
- $langFiles += count($lang['files']);
- if (!empty($upcontext['themes']))
- foreach ($upcontext['themes'] as $theme)
- $themeFiles += count($theme['files']);
- echo sprintf('Found <strong>%d</strong> language files and <strong>%d</strong> templates requiring an update so far.', $langFiles, $themeFiles) . '<br />';
-
- if (!empty($upcontext['current_message']))
- echo '
- ', $upcontext['current_message'];
- }
- echo '
- <input type="hidden" name="uptempdone" value="1" />';
- if (!empty($upcontext['languages']))
- echo '
- <input type="hidden" name="languages" value="', base64_encode(serialize($upcontext['languages'])), '" />';
- if (!empty($upcontext['themes']))
- echo '
- <input type="hidden" name="themes" value="', base64_encode(serialize($upcontext['themes'])), '" />';
- if (!empty($upcontext['writable_files']))
- echo '
- <input type="hidden" name="writable_files" value="', base64_encode(serialize($upcontext['writable_files'])), '" />';
-
- if (!empty($upcontext['can_upgrade_yabbse']))
- echo '
- <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 />';
-
- if (empty($upcontext['chmod']['files']) || $upcontext['is_test'])
- $upcontext['continue'] = 1;
- }
- function template_upgrade_complete()
- {
- global $upcontext, $modSettings, $upgradeurl, $disable_security, $settings, $boarddir, $db_prefix, $boardurl;
- echo '
- <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>
- <form action="', $boardurl, '/index.php">';
- if (!empty($upcontext['can_delete_script']))
- echo '
- <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>
- <script type="text/javascript"><!-- // --><![CDATA[
- function doTheDelete(theCheck)
- {
- var theImage = document.getElementById ? document.getElementById("delete_upgrader") : document.all.delete_upgrader;
- theImage.src = "', $upgradeurl, '?delete=1&ts_" + (new Date().getTime());
- theCheck.disabled = true;
- }
- // ]]></script>
- <img src="', $boardurl, '/Themes/default/images/blank.png" alt="" id="delete_upgrader" /><br />';
- echo '<br />
- 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 />
- <br />
- Best of luck,<br />
- Simple Machines';
- }
- ?>
|