phpDocumentor phpIcqBot
[ class tree: phpIcqBot ] [ index: phpIcqBot ] [ all elements ]

Source for file install.class.php

Documentation is available at install.class.php

  1. <?php
  2.  
  3. {
  4.     /**
  5.      * Do installing bot. True if install is not complete;
  6.      *
  7.      * @return bool 
  8.      */
  9.     public function work()
  10.     {
  11.         if (!yn("\r\nIt seems, that ".VER." not installed.\r\n\r\nWould you like to install it now (y,n)?: "))
  12.             return o("\r\nI can't go on. Sorry. Please, do install.\r\n");
  13.         
  14.         o("\r\nOk, Let's start.\r\n");
  15.         
  16.         // UIN
  17.         while (true)
  18.         {
  19.             o("\r\nFirstly, enter BOT's ICQ number (uin): ");
  20.             $uin i();
  21.             if (!is_numeric($uin|| ((strlen($uin)>9)) || (strlen($uin)<5))
  22.             {
  23.                 if ($uin=='')
  24.                 {
  25.                     if (yn("\r\nDo you want to exit installation (y,n)? "))
  26.                         return true;
  27.                 }
  28.                 else
  29.                     o("\r\nIt not seems, that you enter ICQ Number. UIN must be 5 to 9 numbers length. Try one more time or hit enter to exit\r\n");
  30.             }
  31.             else 
  32.                 break;
  33.         }
  34.         o("OKI write it downBOT's ICQ number is $uin\r\n");
  35.         
  36.         //PASS
  37.         while(true)
  38.         {
  39.             o("\r\nEnter BOT's ICQ password: ");
  40.             $pass i();
  41.             if (!$pass)
  42.             {
  43.                 if (yn("Are you sure, that you've got empty password (y,n)? "))
  44.                     break;
  45.             }
  46.             else
  47.                 break;
  48.         }
  49.         o(str_repeat("\r\n",40));
  50.         o("OK. I write BOT's password. Let's go on.\r\n");
  51.         
  52.         //ADMINICQ
  53.         while (true)
  54.         {
  55.             o("\r\nEnter BOT's Admin's ICQ number (adminuin): ");
  56.             $adminuin i();
  57.             if (!is_numeric($adminuin|| ((strlen($adminuin)>9)) || (strlen($adminuin)<5))
  58.             {
  59.                 if ($adminuin=='')
  60.                 {
  61.                     if (yn("\r\nDo you want to exit installation (y,n)? "))
  62.                         return true;
  63.                 }
  64.                 else
  65.                     o("\r\nIt not seems, that you enter ICQ Number. UIN must be 5 to 9 numbers length. Try one more time or hit enter to exit\r\n");
  66.             }
  67.             else 
  68.                 break;
  69.         }
  70.         o("OKI write it downBOT's Admin's ICQ number is $adminuin\r\n");
  71.         o("\r\nOK. Config done.\r\n");
  72.         o("Now I'll try to write down your information.\r\n\r\n");
  73.         if (file_exists('./config.inc.php'&& (!yn('Config file already exists. Overwrite (y,n)?')))
  74.             return o("\r\nSorry, we can't continue.\r\nConfig already exists, but it seems that it was corrupted.\r\nTry to edit config.inc.php manually or overwrite it with this installer.\r\n\r\n");
  75.         o("Saving to config.inc.php... ");
  76.         $fp=@fopen('./config.inc.php','w');
  77.         if (!$fp)
  78.             return o("error\r\nSorry, I can't write to config.inc.php. Check permissions.\r\n");
  79.         if (!@fputs($fp,"<?php
  80.  
  81. define('LOGLEVEL',    LOGLEVEL_1);
  82. define('UIN',          '$uin');
  83. define('PASSWORD',    '$pass');
  84. define('ADMINUIN',    '$adminuin');
  85.  
  86. define('STARTSTATUS', 'STATUS_FREE4CHAT');
  87.  
  88. define('CMD_PREF','!');"))
  89.             return o("error\r\nStrange, I can't write down configuration... Check permissions.\r\n");
  90.         
  91.         o("OK\r\nHmm.. We almost finished!\r\n");
  92.         o("Now I'm going to make $adminuin super user.\r\nGiving role ADMIN to$adminuin...");
  93.         $user IcqBot_Users::load($adminuin);
  94.         $user->addRoles('admin');
  95.         o("OK\r\n\r\nFinished\r\n");
  96.  
  97.         
  98.         if (!yn("\r\nDo you want to start BOT now (y,n)?"))
  99.             return o("\r\nOK, see you.\r\n");
  100.         o("Trying to start!\r\n\r\n");
  101.         return false;
  102.     }
  103. }
  104.  
  105. function o()
  106. {
  107.     $ar=func_get_args();
  108.     fputs(STDOUTimplode(' ',$ar));
  109.     return true;
  110. }
  111.  
  112. function i($nocase=false)
  113. {
  114.     $rtrim(fgets(STDIN));
  115.     if ($nocase)
  116.         $r=strtolower($r);
  117.     return $r;
  118. }
  119.  
  120. function yn()
  121. {
  122.     $ar func_get_args();
  123.     call_user_func_array('o',$ar);
  124.  
  125.     return substr(i(true),0,1== 'y'?true:false;
  126. }

Documentation generated on Mon, 24 Dec 2007 09:34:28 +0500 by phpDocumentor 1.4.0