A hint: This file contains one or more very long lines, so maybe it is better readable using the pure text view mode that shows the contents as wrapped lines within the browser window.
1 /* 2 * /giis/main.c The main procedure call. 3 * 4 * Copyright (C) 2005,2006,2007,2008,2009,2010,2011,2012 Lakshmipathi.G <lakshmipathi.g@giis.co.in>. 5 * This file may be redistributed under the terms of the GNU Public License. 6 * 7 */ 8 9 #include "giis.h" 10 11 /* 12 * main() Responds to user inputs and calls appropriate procedure. 13 */ 14 15 int main (int argc, char *argv[]) 16 { 17 int i, ans = -1, fp, line = 1; 18 char a, x; 19 char sumkey[] = "Enter Any key to Continue :-)"; 20 extern int rere; 21 extern int install_mode;/* 0 for prompting user and 1 for using config file */ 22 extern int date_mode,day,month,year; /* Time based recovery */ 23 date_mode=-1; 24 25 do 26 { 27 if (argc > 2) 28 { 29 printf ("giis : invalid option \n"); 30 printf ("Type 'giis -h' for help \n"); 31 return -1; 32 } 33 34 /* process command line */ 35 36 if (argc == 2) 37 { 38 if (strcmp (argv[1], "-m") == 0) /* menu */ 39 ans = 444; 40 if (strcmp (argv[1], "-i") == 0) {/* -i will prompt user during installation ,-c will use config file */ 41 ans = 0; 42 install_mode=0; 43 } 44 if (strcmp (argv[1], "-c") == 0){ 45 ans = 0; 46 install_mode=1; 47 }if (strcmp (argv[1], "-u") == 0) /* update */ 48 ans = 1; 49 if (strcmp (argv[1], "-g") == 0) /* recover */ 50 ans = 2; 51 if (strcmp (argv[1], "-d") == 0) /* System info. */ 52 ans = 3; 53 if (strcmp (argv[1], "-f") == 0) /* giis info. */ 54 ans = 4; 55 if (strcmp (argv[1], "-r") == 0) /* uninstall */ 56 ans = 5; 57 if (strcmp (argv[1], "-a") == 0) /* author */ 58 ans = 6; 59 if (strcmp (argv[1], "-t") == 0) /* quotes */ 60 ans = 7; 61 if (strcmp (argv[1], "-q") == 0) /* quits */ 62 ans = 8; 63 64 if (strcmp (argv[1], "-h") == 0) 65 { /* help */ 66 printf ("giis Version 4.6.2, 08 Nov 2012"); 67 printf ("\nBy Lakshmipathi.G (www.giis.co.in)"); 68 printf("\nThis software comes with ABSOLUTELY NO WARRANTY."); 69 printf ("\nUsage: giis [OPTION]\n"); 70 printf ("\nPossible options available with giis :"); 71 printf ("\n -a\t\t Info. about the author."); 72 printf ("\n -d\t\t Displays your file system informations."); 73 printf ("\n -f\t\t Displays giis system files."); 74 printf ("\n -g\t\t Recovers the Given or all deleted files."); 75 printf ("\n -h\t\t Prints this menu."); 76 printf ("\n -i\t\t Installation of giis in Interactive mode."); 77 printf ("\n -c\t\t Installation of giis using Configuation file."); 78 printf ("\n -m\t\t Menu based user interaction."); 79 printf ("\n -q\t\t Exit giis"); 80 printf ("\n -t\t\t Some quotes and thoughts."); 81 printf ("\n -u\t\t Updates giis to reflect current status."); 82 printf ("\n -r\t\t Uninstalls giis.\n"); 83 printf ("\nPlease report bugs to http://groups.google.com/group/giis-users\n"); 84 return 0; 85 } 86 if ((ans != 444) && (ans < 0 || ans > 8)) 87 { 88 printf ("giis : invalid option \n"); 89 printf ("Type 'giis -h' for help.\n"); 90 return -1; 91 } 92 93 94 } 95 if (argc == 1) /* default is menu. */ 96 ans = 444; 97 98 if (ans == 444) 99 { 100 system ("clear"); 101 printf ("\n\t\t ==================================================="); 102 printf ("\n\t\t gET iT i sAY. giis - Ext3/Ext2 File Undelete Tool "); 103 printf ("\n\t\t ===================================================\n"); 104 printf ("\n\tPress 0 : Install \n\tPress 1 : Update Now\n\tPress 2 : File Recovery"); 105 printf ("\n\tPress 3 : Your File System Details"); 106 printf ("\n\tPress 4 : giis File Details \n\tPress 5 : Uninstall"); 107 printf ("\n\tPress 6 : About giis "); 108 printf ("\n\tPress 7 : Quotes \n\tPress 8 : Exit"); 109 printf ("\n\n\t\tEnter Your choice : "); 110 scanf ("%d", &ans); 111 } 112 113 if (ans == 4) 114 { 115 fp = open (INSTALL_DIR1, 0); 116 if (errno == ENOENT) 117 { 118 printf ("\n\t\tgiis Not installed...\n"); 119 printf ("\t\t\t...So install giis and then try this..\n\n "); 120 close (fp); 121 return -1; 122 } 123 close (fp); 124 125 i = read_dir_info_file (); 126 if (i == -1) 127 { 128 perror (""); 129 printf ("Error Number:%d", errno); 130 return -1; 131 } 132 printf ("\n File Info File"); 133 i = read_file_info_file (); 134 if (i == -1) 135 { 136 perror (""); 137 printf ("Error Number:%d", errno); 138 return -1; 139 } 140 141 return 0; 142 } 143 144 145 if (ans == 8) 146 { 147 printf ("\n\t Quiting giis...."); 148 printf ("\n\n\t Bye...Bye...!!!\n\n"); 149 return 0; 150 } 151 152 if (ans == 5) 153 { 154 i = remove_giis (); 155 if (i == -1) 156 { 157 perror (""); 158 printf ("Error Number:%d", errno); 159 return -1; 160 } 161 return 0; 162 } 163 164 if (ans == 6) 165 { 166 167 system ("clear"); 168 fp = open ("/usr/share/giis/hai", 0); 169 if (fp == -1) 170 { 171 perror (""); 172 printf ("Error Number:%d", errno); 173 return -1; 174 } 175 i = read (fp, &a, 1); 176 if (i == -1) 177 { 178 perror (""); 179 printf ("Error Number:%d", errno); 180 return -1; 181 } 182 while (i > 0) 183 { 184 write (1, &a, 1); 185 i = read (fp, &a, 1); 186 } 187 close (fp); 188 return 0; 189 } 190 if (ans == 7) 191 { 192 193 system ("clear"); 194 fp = open ("/usr/share/giis/quotes", 0); 195 if (fp == -1) 196 { 197 perror (""); 198 printf ("Error Number:%d", errno); 199 return -1; 200 } 201 i = read (fp, &a, 1); 202 if (i == -1) 203 { 204 perror (""); 205 printf ("Error Number:%d", errno); 206 return -1; 207 } 208 while (i > 0) 209 { 210 if (a == '\n') 211 line++; 212 write (1, &a, 1); 213 i = read (fp, &a, 1); 214 if ((line % 24) == 0) 215 { 216 line++; 217 write (1, sumkey, strlen (sumkey)); 218 read (0, &x, 1); 219 } 220 } 221 close (fp); 222 return 0; 223 } 224 225 226 227 228 } 229 while (!(ans >= 0 && ans <= 8)); 230 231 /* Check for installation */ 232 if (ans == 0) 233 { 234 install = 1; 235 fp = open (INSTALL_DIR1, 0); 236 if (fp != -1) 237 { 238 printf ("\n\t\tgiis already installed in your system...\n"); 239 printf ("\t\tTry giis -r or manually delete /usr/share/giis to install freshly...\n "); 240 close (fp); 241 return -1; 242 } 243 } 244 245 if (ans == 1 || ans == 2 || ans == 3) 246 { 247 fp = open (INSTALL_DIR1, 0); 248 if (errno == ENOENT) 249 { 250 printf ("\n\t\tgiis Not installed...\n"); 251 printf ("\t\t\t...So install giis and then try this ;)\n "); 252 close (fp); 253 return -1; 254 } 255 close (fp); 256 } 257 258 printf ("\nSearching for file system...."); 259 if (init () == -1) 260 { 261 printf ("\n\nFile System not is Initialized....Aborting....\n"); 262 exit (1); 263 } 264 265 if (ans == 0) 266 { 267 install = 1; 268 update_file = 0; /* Used to call update_dir_info_file() */ 269 update_dir = 0; 270 fs.inode_number = ROOT_INODE; /* Get Root inode offset to fs.root_inode_offset.First. */ 271 i = find_inode_offset (); 272 if (i == -1) 273 { 274 perror (""); 275 printf ("Error Number:%d", errno); 276 return -1; 277 } 278 279 i = read_inode (); 280 if (i == -1) 281 { 282 perror (""); 283 printf ("Error Number:%d", errno); 284 return -1; 285 } 286 287 i = set_content_offset (); 288 if (i == -1) 289 { 290 perror (""); 291 printf ("Error Number:%d", errno); 292 return -1; 293 } 294 if (dir) 295 { /* If inode is a directory then Show its content */ 296 i = read_dir (); 297 if (i == -1) 298 { 299 perror (""); 300 printf ("Error Number:%d", errno); 301 return -1; 302 } 303 i = show_dir (); 304 if (i == -1) 305 { 306 perror (""); 307 printf ("Error Number:%d", errno); 308 return -1; 309 } 310 } 311 else 312 { 313 printf("\n **giis panic ** root inode not detected..exiting\n"); 314 exit(0); 315 } 316 return 0; 317 } 318 319 /* Display File System Details */ 320 321 if (ans == 3) 322 { 323 fs.inode_number = ROOT_INODE; /* Get Root inode offset */ 324 i = find_inode_offset (); 325 if (i == -1) 326 { 327 perror (""); 328 printf ("Error Number:%d", errno); 329 return -1; 330 } 331 i = fs_display (); 332 if (i == -1) 333 { 334 perror (""); 335 printf ("Error Number:%d", errno); 336 return -1; 337 } 338 return 0; 339 } 340 341 342 if (ans == 0 || ans == 1) 343 { 344 if (ans == 1) 345 { 346 printf("\n\tgiis update :Please wait this process may take some time to complete... \n"); 347 install = 0; 348 update_file = 1; 349 update_dir = 1; 350 } 351 352 i = search4dir (); /* searches for directory in DIR_INFO_FILE */ 353 if (i == -1) 354 { 355 perror (""); 356 printf ("Error Number:%d", errno); 357 return -1; 358 } 359 if (ans == 0) 360 { 361 //Set device name : 362 search4fs(); 363 printf("\n\t\t Extracting Sample data..."); 364 get_sample_data (); 365 366 printf ("\n\n\t\tgiis - Installation completed..."); 367 } 368 } 369 370 371 if (ans == 2) 372 { 373 374 printf ("\n\n\t *** Note : 'Recover and Restore Files' option will place recovered files into it's original\ parent directory and creates link under /usr/share/giis/got_it directory.If the original directory path not\ exists,then those files can be found under /usr/share/giis/got_it.See /usr/share/giis/restore_details.txt for restored files."); 375 printf("\n\n\t==>Recover and Restore Files : Press 1(Recommended) Else Press 0 : "); 376 377 scanf("%d",&rere); 378 379 380 printf ("\n\nHow do you want to recover files?"); 381 printf ("\n\t Press 0 : Get All User files "); 382 printf ("\n\t Press 1 : Get Specific User files"); 383 printf ("\n\t Press 2 : force giis - giis dump"); 384 printf ("\n\t Press 3 : Get By File Format"); 385 printf ("\n\t Press 4 : List Deleted files"); 386 printf ("\n\t Press 5 : Get files by Deleted date\n"); 387 printf ("\n\t\tEnter Your Choice : "); 388 scanf ("%d", &ans); 389 if(ans == 4){ 390 display_deleted_files(); 391 exit(0); 392 } 393 /* Get files by date */ 394 if(ans == 5){ 395 up: 396 printf("\n\nGet Files by Deleted Date:\n\tPress 0 : Deleted on\n\tPress 1 : Deleted After\n\tPress 2 : Deleted Before \n\tPress 3 : Deleted Between"); 397 printf("\n\n\t\tEnter Your Choice :"); 398 scanf("%d",&date_mode); 399 400 if((date_mode<0) || (date_mode>3)){ 401 printf("\n Please Enter Valid Choice."); 402 goto up; 403 } 404 405 if(date_mode == 0 || date_mode == 1 || date_mode == 2 ){ 406 printf("\n Enter the day (1..31) :"); 407 scanf("%d",&day); 408 printf("\n Enter the month (1..12) : "); 409 scanf("%d",&month); 410 printf("\n Enter the year (YYYY) :"); 411 scanf("%d",&year); 412 }else if(date_mode == 3){ 413 printf("\n Enter From-Date Details :"); 414 printf("\n Enter the day (1..31) :"); 415 scanf("%d",&day); 416 printf("\n Enter the month (1..12) : "); 417 scanf("%d",&month); 418 printf("\n Enter the year (YYYY) :"); 419 scanf("%d",&year); 420 421 printf("\n Enter To-Date Details :"); 422 printf("\n Enter the day (1..31) :"); 423 scanf("%d",&day1); 424 printf("\n Enter the month (1..12) : "); 425 scanf("%d",&month1); 426 printf("\n Enter the year (YYYY) :"); 427 scanf("%d",&year1); 428 429 } 430 // date validation 431 if(((day<=0 || day>31)||(month<=0 || month>12)||(year<1000))||((date_mode == 3)&&(day1<=0 || day1>31 || month1<=0 || month1>12|| year1<1000 ))) 432 { 433 printf("\n Please Enter Valid Date."); 434 goto up; 435 } 436 //Now recover all files 437 ans=0; 438 } 439 440 if (ans >= 0 && ans <= 3) 441 use_uid = ans; 442 else 443 { 444 printf ("\n\n\t\tPlease Enter correct Choice"); 445 return -1; 446 } 447 448 install = 0; 449 get_it (); /* Search for deleted file */ 450 451 /*giis 4.3 :Recover and restore */ 452 if(rere==1) 453 recover_restore(); 454 } 455 return 0; 456 }